Actually disable keep alive if set to 0

This commit is contained in:
Franck Royer 2021-07-02 10:51:58 +10:00
parent 75297b9987
commit 370a347ff2
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 15 additions and 7 deletions

View File

@ -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. - **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. - 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 ## [0.7.0] - 2021-06-15
### Changed ### Changed

View File

@ -76,15 +76,20 @@ export class Waku {
this.lightPush = lightPush; this.lightPush = lightPush;
this.keepAliveTimers = {}; this.keepAliveTimers = {};
const keepAlive = options.keepAlive ? options.keepAlive : 10; const keepAlive = options.keepAlive !== undefined ? options.keepAlive : 10;
libp2p.connectionManager.on('peer:connect', (connection: Connection) => { if (keepAlive !== 0) {
this.startKeepAlive(connection.remotePeer, keepAlive); libp2p.connectionManager.on('peer:connect', (connection: Connection) => {
}); this.startKeepAlive(connection.remotePeer, keepAlive);
});
libp2p.connectionManager.on('peer:disconnect', (connection: Connection) => { libp2p.connectionManager.on(
this.stopKeepAlive(connection.remotePeer); 'peer:disconnect',
}); (connection: Connection) => {
this.stopKeepAlive(connection.remotePeer);
}
);
}
} }
/** /**