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
This commit is contained in:
Ricardo Arturo Cabral Mejía 2023-02-21 00:37:55 -05:00 committed by GitHub
parent 6335496bf9
commit 0954d8426c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 11 deletions

View File

@ -3,7 +3,6 @@ services:
build: . build: .
container_name: nostream container_name: nostream
environment: environment:
SECRET: ${SECRET}
RELAY_PORT: 8008 RELAY_PORT: 8008
# Master # Master
NOSTR_CONFIG_DIR: /home/node/.nostr NOSTR_CONFIG_DIR: /home/node/.nostr

View File

@ -15,6 +15,9 @@ payments:
whitelists: whitelists:
pubkeys: pubkeys:
- replace-with-your-pubkey-in-hex - replace-with-your-pubkey-in-hex
# Allow the following Zap providers:
# LightningTipBot by Calle
- "fcd720c38d9ee337188f47aac845dcd8f590ccdb4a928b76dde18187b4c9d37d"
paymentsProcessors: paymentsProcessors:
zebedee: zebedee:
baseURL: https://api.zebedee.io/ baseURL: https://api.zebedee.io/
@ -27,7 +30,10 @@ paymentsProcessors:
callbackBaseURL: https://nostream.your-domain.com/callbacks/lnbits callbackBaseURL: https://nostream.your-domain.com/callbacks/lnbits
network: network:
maxPayloadSize: 524288 maxPayloadSize: 524288
# Comment the next line if using CloudFlare proxy
remoteIpHeader: x-forwarded-for remoteIpHeader: x-forwarded-for
# Uncomment the next line if using CloudFlare proxy
# remoteIpHeader: cf-connecting-ip
workers: workers:
count: 0 count: 0
mirroring: mirroring:

View File

@ -58,9 +58,13 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
.on('error', (error) => { .on('error', (error) => {
if (error.name === 'RangeError' && error.message === 'Max payload size exceeded') { if (error.name === 'RangeError' && error.message === 'Max payload size exceeded') {
console.error(`web-socket-adapter: client ${this.clientId} (${this.getClientAddress()}) sent payload too large`) 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 { } else {
console.error(`web-socket-adapter: client error ${this.clientId} (${this.getClientAddress()}):`, error) console.error(`web-socket-adapter: client error ${this.clientId} (${this.getClientAddress()}):`, error)
} }
this.client.close()
}) })
.on('message', this.onClientMessage.bind(this)) .on('message', this.onClientMessage.bind(this))
.on('close', this.onClientClose.bind(this)) .on('close', this.onClientClose.bind(this))
@ -125,9 +129,9 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
} }
public onHeartbeat(): void { 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()})`) console.error(`web-socket-adapter: pong timeout for client ${this.clientId} (${this.getClientAddress()})`)
this.terminate() this.client.close()
return return
} }
@ -140,12 +144,6 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
return new Map(this.subscriptions) 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) { private async onClientMessage(raw: Buffer) {
this.alive = true this.alive = true
let abortable = false let abortable = false

View File

@ -101,7 +101,7 @@ export class App implements IRunnable {
MIRROR_INDEX: i.toString(), MIRROR_INDEX: i.toString(),
}) })
} }
logCentered(`${mirrors.length} maintenance worker started`, width) logCentered(`${mirrors.length} static-mirroring worker started`, width)
} }
debug('settings: %O', settings) debug('settings: %O', settings)

View File

@ -37,6 +37,23 @@ export const workerFactory = (): AppWorker => {
const webSocketServer = new WebSocketServer({ const webSocketServer = new WebSocketServer({
server, server,
maxPayload: maxPayloadSize ?? 131072, // 128 kB 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( const adapter = new WebSocketServerAdapter(
server, server,