Skip to content

Commit 0954d84

Browse files
authored
fix: rsv1 error (#225)
* chore: remove secret * chore: allow lightningtipbot pubkey for zaps * chore: add cloudflare remoteipheader * chore: close client conn on error * chore: terminate conn w/o subs * chore: enable permessage-deflate * fix: start logs
1 parent 6335496 commit 0954d84

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ services:
33
build: .
44
container_name: nostream
55
environment:
6-
SECRET: ${SECRET}
76
RELAY_PORT: 8008
87
# Master
98
NOSTR_CONFIG_DIR: /home/node/.nostr

resources/default-settings.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ payments:
1414
amount: 1000000
1515
whitelists:
1616
pubkeys:
17-
- replace-with-your-pubkey-in-hex
17+
- replace-with-your-pubkey-in-hex
18+
# Allow the following Zap providers:
19+
# LightningTipBot by Calle
20+
- "fcd720c38d9ee337188f47aac845dcd8f590ccdb4a928b76dde18187b4c9d37d"
1821
paymentsProcessors:
1922
zebedee:
2023
baseURL: https://api.zebedee.io/
@@ -27,7 +30,10 @@ paymentsProcessors:
2730
callbackBaseURL: https://nostream.your-domain.com/callbacks/lnbits
2831
network:
2932
maxPayloadSize: 524288
33+
# Comment the next line if using CloudFlare proxy
3034
remoteIpHeader: x-forwarded-for
35+
# Uncomment the next line if using CloudFlare proxy
36+
# remoteIpHeader: cf-connecting-ip
3137
workers:
3238
count: 0
3339
mirroring:

src/adapters/web-socket-adapter.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
5858
.on('error', (error) => {
5959
if (error.name === 'RangeError' && error.message === 'Max payload size exceeded') {
6060
console.error(`web-socket-adapter: client ${this.clientId} (${this.getClientAddress()}) sent payload too large`)
61+
} else if (error.name === 'RangeError' && error.message === 'Invalid WebSocket frame: RSV1 must be clear') {
62+
debug(`client ${this.clientId} (${this.getClientAddress()}) enabled compression`)
6163
} else {
6264
console.error(`web-socket-adapter: client error ${this.clientId} (${this.getClientAddress()}):`, error)
6365
}
66+
67+
this.client.close()
6468
})
6569
.on('message', this.onClientMessage.bind(this))
6670
.on('close', this.onClientClose.bind(this))
@@ -125,9 +129,9 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
125129
}
126130

127131
public onHeartbeat(): void {
128-
if (!this.alive) {
132+
if (!this.alive && !this.subscriptions.size) {
129133
console.error(`web-socket-adapter: pong timeout for client ${this.clientId} (${this.getClientAddress()})`)
130-
this.terminate()
134+
this.client.close()
131135
return
132136
}
133137

@@ -140,12 +144,6 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
140144
return new Map(this.subscriptions)
141145
}
142146

143-
private terminate(): void {
144-
debug('terminating client %s', this.clientId)
145-
this.client.terminate()
146-
debug('client %s terminated', this.clientId)
147-
}
148-
149147
private async onClientMessage(raw: Buffer) {
150148
this.alive = true
151149
let abortable = false

src/app/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class App implements IRunnable {
101101
MIRROR_INDEX: i.toString(),
102102
})
103103
}
104-
logCentered(`${mirrors.length} maintenance worker started`, width)
104+
logCentered(`${mirrors.length} static-mirroring worker started`, width)
105105
}
106106

107107
debug('settings: %O', settings)

src/factories/worker-factory.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ export const workerFactory = (): AppWorker => {
3737
const webSocketServer = new WebSocketServer({
3838
server,
3939
maxPayload: maxPayloadSize ?? 131072, // 128 kB
40+
perMessageDeflate: {
41+
zlibDeflateOptions: {
42+
chunkSize: 1024,
43+
memLevel: 7,
44+
level: 3,
45+
},
46+
zlibInflateOptions: {
47+
chunkSize: 10 * 1024,
48+
},
49+
clientNoContextTakeover: true, // Defaults to negotiated value.
50+
serverNoContextTakeover: true, // Defaults to negotiated value.
51+
serverMaxWindowBits: 10, // Defaults to negotiated value.
52+
// Below options specified as default values.
53+
concurrencyLimit: 10, // Limits zlib concurrency for perf.
54+
threshold: 1024, // Size (in bytes) below which messages
55+
// should not be compressed if context takeover is disabled.
56+
},
4057
})
4158
const adapter = new WebSocketServerAdapter(
4259
server,

0 commit comments

Comments
 (0)