Skip to content

Commit 1d60c4b

Browse files
feat: enable pinging connected peers by default (#1647)
* enable pinging peers by default * handle ping failure
1 parent 124a29e commit 1d60c4b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/core/src/lib/keep_alive_manager.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,24 @@ export class KeepAliveManager {
3737

3838
const peerIdStr = peerId.toString();
3939

40+
// Ping the peer every pingPeriodSecs seconds
41+
// if pingPeriodSecs is 0, don't ping the peer
4042
if (pingPeriodSecs !== 0) {
4143
const interval = setInterval(() => {
4244
void (async () => {
45+
let ping: number;
4346
try {
4447
// ping the peer for keep alive
4548
// also update the peer store with the latency
46-
const ping = await libp2pPing.ping(peerId);
47-
log(`Ping succeeded (${peerIdStr})`, ping);
49+
try {
50+
ping = await libp2pPing.ping(peerId);
51+
log(`Ping succeeded (${peerIdStr})`, ping);
52+
} catch (error) {
53+
log(`Ping failed for peer (${peerIdStr}).
54+
Next ping will be attempted in ${pingPeriodSecs} seconds.
55+
`);
56+
return;
57+
}
4858

4959
try {
5060
await peerStore.patch(peerId, {

packages/core/src/lib/waku.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import debug from "debug";
1515

1616
import { ConnectionManager } from "./connection_manager.js";
1717

18-
export const DefaultPingKeepAliveValueSecs = 0;
18+
export const DefaultPingKeepAliveValueSecs = 5 * 60;
1919
export const DefaultRelayKeepAliveValueSecs = 5 * 60;
2020
export const DefaultUserAgent = "js-waku";
2121

0 commit comments

Comments
 (0)