Improve connection check with peers by retrying ping on failures (#330)

* Improve connection check with peers by retrying ping on failures

* Use DEFAULT_PING_INTERVAL in cli

* Log only error message

* Add config option to pass peer id file path

* Finish retrying pings before connection check interval duration

* Handle duplicate connections to relay nodes

* Increase default max dial retries from one relay to another

* Update connection manager config for relay nodes

* Use debug for logs in relay node

---------

Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
This commit is contained in:
2023-02-27 12:47:49 +05:30
committed by GitHub
co-authored by prathamesh
parent 888199b717
commit 90d60f54a6
10 changed files with 143 additions and 53 deletions
+10 -3
View File
@@ -154,7 +154,8 @@ export class ServerCmd {
RELAY_DEFAULT_PORT,
RELAY_DEFAULT_MAX_DIAL_RETRY,
RELAY_REDIAL_INTERVAL,
PING_INTERVAL
DEFAULT_PING_INTERVAL,
DIAL_TIMEOUT
} = await import('@cerc-io/peer');
// Run the relay node if enabled
@@ -172,7 +173,8 @@ export class ServerCmd {
port: relayConfig.port ?? RELAY_DEFAULT_PORT,
announceDomain: relayConfig.announce,
relayPeers: relayConfig.relayPeers ?? [],
pingInterval: relayConfig.pingInterval ?? PING_INTERVAL,
dialTimeout: relayConfig.dialTimeout ?? DIAL_TIMEOUT,
pingInterval: relayConfig.pingInterval ?? DEFAULT_PING_INTERVAL,
redialInterval: relayConfig.redialInterval ?? RELAY_REDIAL_INTERVAL,
maxDialRetry: relayConfig.maxDialRetry ?? RELAY_DEFAULT_MAX_DIAL_RETRY,
peerIdObj
@@ -185,6 +187,11 @@ export class ServerCmd {
const peerConfig = p2pConfig.peer;
assert(peerConfig, 'Peer config not set');
let peerIdObj: PeerIdObj | undefined;
if (peerConfig.peerIdFile) {
peerIdObj = readPeerId(peerConfig.peerIdFile);
}
const peer = new Peer(peerConfig.relayMultiaddr, true);
const peerNodeInit: PeerInitConfig = {
@@ -195,7 +202,7 @@ export class ServerCmd {
maxConnections: peerConfig.maxConnections,
dialTimeout: peerConfig.dialTimeout
};
await peer.init(peerNodeInit);
await peer.init(peerNodeInit, peerIdObj);
peer.subscribeTopic(peerConfig.pubSubTopic, (peerId, data) => {
if (parseLibp2pMessage) {