diff --git a/docker-compose.yml b/docker-compose.yml index ec6d8d04..0e236225 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,6 @@ services: build: . container_name: nostream environment: - SECRET: ${SECRET} RELAY_PORT: 8008 # Master NOSTR_CONFIG_DIR: /home/node/.nostr diff --git a/resources/default-settings.yaml b/resources/default-settings.yaml index e7c96066..4f76cecf 100755 --- a/resources/default-settings.yaml +++ b/resources/default-settings.yaml @@ -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: diff --git a/src/adapters/web-socket-adapter.ts b/src/adapters/web-socket-adapter.ts index 4e584f6b..92e29e08 100644 --- a/src/adapters/web-socket-adapter.ts +++ b/src/adapters/web-socket-adapter.ts @@ -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 diff --git a/src/app/app.ts b/src/app/app.ts index 90305cba..34673b09 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -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) diff --git a/src/factories/worker-factory.ts b/src/factories/worker-factory.ts index 4d484786..123e59d2 100644 --- a/src/factories/worker-factory.ts +++ b/src/factories/worker-factory.ts @@ -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,