From d50d78ed17b94b3d59ef84e2404796f940650abc Mon Sep 17 00:00:00 2001 From: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Date: Fri, 17 Feb 2023 18:39:47 +0530 Subject: [PATCH] Reduce dial timeout to 10 seconds (#325) --- packages/peer/src/constants.ts | 5 ++++- packages/peer/src/peer.ts | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/peer/src/constants.ts b/packages/peer/src/constants.ts index 184cf431..f1e05a2c 100644 --- a/packages/peer/src/constants.ts +++ b/packages/peer/src/constants.ts @@ -30,7 +30,7 @@ export const CONN_CHECK_INTERVAL = 10000; // 10 seconds export const PING_TIMEOUT = 5000; // 5 seconds // Delay time in ms to redial relay node on failing to connect -export const RELAY_REDIAL_DELAY = 5000; // 5 sconds +export const RELAY_REDIAL_DELAY = 5000; // 5 seconds // Max number of relay node connections for a peer after which it starts igoring them export const DEFAULT_MAX_RELAY_CONNECTIONS = 2; @@ -52,3 +52,6 @@ export const MAX_CONNECTIONS = 10; // Min number of connections for a peer below which autodial triggers (if enabled) export const MIN_CONNECTIONS = 0; + +// How long a dial is allowed to take before it's aborted +export const DIAL_TIMEOUT = 10000; // 10 seconds diff --git a/packages/peer/src/peer.ts b/packages/peer/src/peer.ts index ae17d279..386ba4cc 100644 --- a/packages/peer/src/peer.ts +++ b/packages/peer/src/peer.ts @@ -27,7 +27,18 @@ import { multiaddr, Multiaddr } from '@multiformats/multiaddr'; import { floodsub } from '@libp2p/floodsub'; import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery'; -import { MAX_CONCURRENT_DIALS_PER_PEER, MAX_CONNECTIONS, MIN_CONNECTIONS, PUBSUB_DISCOVERY_INTERVAL, PUBSUB_SIGNATURE_POLICY, RELAY_TAG, RELAY_REDIAL_DELAY, PING_TIMEOUT, DEFAULT_MAX_RELAY_CONNECTIONS } from './constants.js'; +import { + MAX_CONCURRENT_DIALS_PER_PEER, + MAX_CONNECTIONS, + MIN_CONNECTIONS, + DIAL_TIMEOUT, + PUBSUB_DISCOVERY_INTERVAL, + PUBSUB_SIGNATURE_POLICY, + RELAY_TAG, + RELAY_REDIAL_DELAY, + DEFAULT_MAX_RELAY_CONNECTIONS, + PING_TIMEOUT +} from './constants.js'; import { PeerHearbeatChecker } from './peer-heartbeat-checker.js'; import { dialWithRetry } from './utils/index.js'; @@ -119,6 +130,7 @@ export class Peer { autoDial: false, maxConnections: MAX_CONNECTIONS, minConnections: MIN_CONNECTIONS, + dialTimeout: DIAL_TIMEOUT, keepMultipleConnections: true // Set true to get connections with multiple multiaddr }, ping: {