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: .
container_name: nostream
environment:
SECRET: ${SECRET}
RELAY_PORT: 8008
# Master
NOSTR_CONFIG_DIR: /home/node/.nostr

View File

@ -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/
@ -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:

View File

@ -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))
@ -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
}
@ -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

View File

@ -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)

View File

@ -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,