From 370a347ff22c030a20301f648e417c3c312ff2b0 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 2 Jul 2021 10:51:58 +1000 Subject: [PATCH] Actually disable keep alive if set to 0 --- CHANGELOG.md | 3 +++ src/lib/waku.ts | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60700660f5..e844c4308c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Breaking**: Auto select peer if none provided for store and light push protocols. - Upgrade to `libp2p@0.31.7` and `libp2p-gossipsub@0.10.0` to avoid `TextEncoder` errors in ReactJS tests. +### Fixed +- Disable `keepAlive` if set to `0`. + ## [0.7.0] - 2021-06-15 ### Changed diff --git a/src/lib/waku.ts b/src/lib/waku.ts index 0d3b663e3e..093192217f 100644 --- a/src/lib/waku.ts +++ b/src/lib/waku.ts @@ -76,15 +76,20 @@ export class Waku { this.lightPush = lightPush; this.keepAliveTimers = {}; - const keepAlive = options.keepAlive ? options.keepAlive : 10; + const keepAlive = options.keepAlive !== undefined ? options.keepAlive : 10; - libp2p.connectionManager.on('peer:connect', (connection: Connection) => { - this.startKeepAlive(connection.remotePeer, keepAlive); - }); + if (keepAlive !== 0) { + libp2p.connectionManager.on('peer:connect', (connection: Connection) => { + this.startKeepAlive(connection.remotePeer, keepAlive); + }); - libp2p.connectionManager.on('peer:disconnect', (connection: Connection) => { - this.stopKeepAlive(connection.remotePeer); - }); + libp2p.connectionManager.on( + 'peer:disconnect', + (connection: Connection) => { + this.stopKeepAlive(connection.remotePeer); + } + ); + } } /**