Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rsv1 error #225

Merged
merged 7 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ services:
build: .
container_name: nostream
environment:
SECRET: ${SECRET}
RELAY_PORT: 8008
# Master
NOSTR_CONFIG_DIR: /home/node/.nostr
Expand Down
8 changes: 7 additions & 1 deletion resources/default-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ payments:
amount: 1000000
whitelists:
pubkeys:
- replace-with-your-pubkey-in-hex
- replace-with-your-pubkey-in-hex
# Allow the following Zap providers:
# LightningTipBot by Calle
- "fcd720c38d9ee337188f47aac845dcd8f590ccdb4a928b76dde18187b4c9d37d"
paymentsProcessors:
zebedee:
baseURL: https://api.zebedee.io/
Expand All @@ -27,7 +30,10 @@ paymentsProcessors:
callbackBaseURL: https://nostream.your-domain.com/callbacks/lnbits
network:
maxPayloadSize: 524288
# Comment the next line if using CloudFlare proxy
remoteIpHeader: x-forwarded-for
# Uncomment the next line if using CloudFlare proxy
# remoteIpHeader: cf-connecting-ip
workers:
count: 0
mirroring:
Expand Down
14 changes: 6 additions & 8 deletions src/adapters/web-socket-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
.on('error', (error) => {
if (error.name === 'RangeError' && error.message === 'Max payload size exceeded') {
console.error(`web-socket-adapter: client ${this.clientId} (${this.getClientAddress()}) sent payload too large`)
} else if (error.name === 'RangeError' && error.message === 'Invalid WebSocket frame: RSV1 must be clear') {
debug(`client ${this.clientId} (${this.getClientAddress()}) enabled compression`)
} else {
console.error(`web-socket-adapter: client error ${this.clientId} (${this.getClientAddress()}):`, error)
}

this.client.close()
})
.on('message', this.onClientMessage.bind(this))
.on('close', this.onClientClose.bind(this))
Expand Down Expand Up @@ -125,9 +129,9 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
}

public onHeartbeat(): void {
if (!this.alive) {
if (!this.alive && !this.subscriptions.size) {
console.error(`web-socket-adapter: pong timeout for client ${this.clientId} (${this.getClientAddress()})`)
this.terminate()
this.client.close()
return
}

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

private terminate(): void {
debug('terminating client %s', this.clientId)
this.client.terminate()
debug('client %s terminated', this.clientId)
}

private async onClientMessage(raw: Buffer) {
this.alive = true
let abortable = false
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class App implements IRunnable {
MIRROR_INDEX: i.toString(),
})
}
logCentered(`${mirrors.length} maintenance worker started`, width)
logCentered(`${mirrors.length} static-mirroring worker started`, width)
}

debug('settings: %O', settings)
Expand Down
17 changes: 17 additions & 0 deletions src/factories/worker-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ export const workerFactory = (): AppWorker => {
const webSocketServer = new WebSocketServer({
server,
maxPayload: maxPayloadSize ?? 131072, // 128 kB
perMessageDeflate: {
zlibDeflateOptions: {
chunkSize: 1024,
memLevel: 7,
level: 3,
},
zlibInflateOptions: {
chunkSize: 10 * 1024,
},
clientNoContextTakeover: true, // Defaults to negotiated value.
serverNoContextTakeover: true, // Defaults to negotiated value.
serverMaxWindowBits: 10, // Defaults to negotiated value.
// Below options specified as default values.
concurrencyLimit: 10, // Limits zlib concurrency for perf.
threshold: 1024, // Size (in bytes) below which messages
// should not be compressed if context takeover is disabled.
},
})
const adapter = new WebSocketServerAdapter(
server,
Expand Down