Skip to content

Commit 2f5b0d1

Browse files
cameribrandonrobinson5060
authored andcommitted
fix: rsv1 error (cameri#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 ffa86bc commit 2f5b0d1

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

docker-compose.yml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ services:
55
env_file:
66
- local.env
77
environment:
8-
SECRET: ${SECRET}
98
RELAY_PORT: 8008
109
# Master
1110
NOSTR_CONFIG_DIR: /home/node/.nostr

resources/default-settings.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ paymentsProcessors:
5050
callbackBaseURL: https://nostream.your-domain.com/callbacks/lnbits
5151
network:
5252
maxPayloadSize: 524288
53+
# Comment the next line if using CloudFlare proxy
5354
remoteIpHeader: x-forwarded-for
55+
# Uncomment the next line if using CloudFlare proxy
56+
# remoteIpHeader: cf-connecting-ip
5457
workers:
5558
count: 16
5659
mirroring:

src/adapters/web-socket-adapter.ts

+6-8
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

+1-1
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

+17
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)