mirror of https://github.com/waku-org/js-waku.git
feat: enable pinging connected peers by default (#1647)
* enable pinging peers by default * handle ping failure
This commit is contained in:
parent
124a29ebba
commit
1d60c4ba44
|
@ -37,14 +37,24 @@ export class KeepAliveManager {
|
|||
|
||||
const peerIdStr = peerId.toString();
|
||||
|
||||
// Ping the peer every pingPeriodSecs seconds
|
||||
// if pingPeriodSecs is 0, don't ping the peer
|
||||
if (pingPeriodSecs !== 0) {
|
||||
const interval = setInterval(() => {
|
||||
void (async () => {
|
||||
let ping: number;
|
||||
try {
|
||||
// ping the peer for keep alive
|
||||
// also update the peer store with the latency
|
||||
const ping = await libp2pPing.ping(peerId);
|
||||
log(`Ping succeeded (${peerIdStr})`, ping);
|
||||
try {
|
||||
ping = await libp2pPing.ping(peerId);
|
||||
log(`Ping succeeded (${peerIdStr})`, ping);
|
||||
} catch (error) {
|
||||
log(`Ping failed for peer (${peerIdStr}).
|
||||
Next ping will be attempted in ${pingPeriodSecs} seconds.
|
||||
`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await peerStore.patch(peerId, {
|
||||
|
|
|
@ -15,7 +15,7 @@ import debug from "debug";
|
|||
|
||||
import { ConnectionManager } from "./connection_manager.js";
|
||||
|
||||
export const DefaultPingKeepAliveValueSecs = 0;
|
||||
export const DefaultPingKeepAliveValueSecs = 5 * 60;
|
||||
export const DefaultRelayKeepAliveValueSecs = 5 * 60;
|
||||
export const DefaultUserAgent = "js-waku";
|
||||
|
||||
|
|
Loading…
Reference in New Issue