diff --git a/src/config.ts b/src/config.ts index 35b39547de..1b94d5004f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -22,7 +22,6 @@ export const DefaultConfig: Partial = { connectionManagerConfig: { maxConnections: 300, minConnections: 50, - resolvers: { dnsaddr: dnsaddrResolver } diff --git a/src/connection-manager/dialer/index.ts b/src/connection-manager/dialer/index.ts index 58b7a02a4c..e475636704 100644 --- a/src/connection-manager/dialer/index.ts +++ b/src/connection-manager/dialer/index.ts @@ -58,7 +58,7 @@ export interface DialerInit { * How long to wait between attempting to keep our number of concurrent connections * above minConnections */ - autoDialInterval: number + autoDialInterval?: number /** * How long a dial attempt is allowed to take @@ -69,7 +69,7 @@ export interface DialerInit { * When a new inbound connection is opened, the upgrade process (e.g. protect, * encrypt, multiplex etc) must complete within this number of ms. */ - inboundUpgradeTimeout: number + inboundUpgradeTimeout?: number /** * Number of max concurrent dials diff --git a/src/libp2p.ts b/src/libp2p.ts index cc207075a2..3450952250 100644 --- a/src/libp2p.ts +++ b/src/libp2p.ts @@ -130,7 +130,7 @@ export class Libp2pNode extends EventEmitter implements Libp2p { this.components.upgrader = new DefaultUpgrader(this.components, { connectionEncryption: (init.connectionEncryption ?? []).map(fn => this.configureComponent(fn(this.components))), muxers: (init.streamMuxers ?? []).map(fn => this.configureComponent(fn(this.components))), - inboundUpgradeTimeout: init.dialer.inboundUpgradeTimeout + inboundUpgradeTimeout: init.dialer.inboundUpgradeTimeout ?? 10000 }) // Create the dialer diff --git a/test/connection-manager/index.node.ts b/test/connection-manager/index.node.ts index 8de955eeb1..df2c739033 100644 --- a/test/connection-manager/index.node.ts +++ b/test/connection-manager/index.node.ts @@ -13,12 +13,13 @@ import { stubInterface } from 'sinon-ts' import type { KeyBook, PeerStore } from '@libp2p/interface-peer-store' import sinon from 'sinon' import pWaitFor from 'p-wait-for' -import type { Connection } from '@libp2p/interface-connection' +import type { Connection, ConnectionGater } from '@libp2p/interface-connection' import delay from 'delay' import type { Libp2pNode } from '../../src/libp2p.js' import { codes } from '../../src/errors.js' import { start } from '@libp2p/interfaces/startable' -import type { Dialer } from '@libp2p/interface-connection-manager' +import { DefaultDialer } from '../../src/connection-manager/dialer/index.js' +import type { TransportManager } from '@libp2p/interface-transport' describe('Connection Manager', () => { let libp2p: Libp2p @@ -49,18 +50,28 @@ describe('Connection Manager', () => { it('should filter connections on disconnect, removing the closed one', async () => { const upgrader = mockUpgrader() const peerStore = stubInterface() + const peerId = peerIds[0] peerStore.keyBook = stubInterface() + const dialer = new DefaultDialer({ + peerId, + peerStore, + transportManager: stubInterface(), + connectionGater: stubInterface() + }, + { + autoDialInterval: 1000, + inboundUpgradeTimeout: 1000 + }) + const connectionManager = new DefaultConnectionManager({ - peerId: peerIds[0], - dialer: stubInterface(), + peerId, + dialer, upgrader, peerStore }, { maxConnections: 1000, - minConnections: 50, - autoDialInterval: 1000, - inboundUpgradeTimeout: 1000 + minConnections: 5 }) await start(connectionManager) @@ -89,18 +100,28 @@ describe('Connection Manager', () => { it('should close connections on stop', async () => { const upgrader = mockUpgrader() const peerStore = stubInterface() + const peerId = peerIds[0] peerStore.keyBook = stubInterface() + const dialer = new DefaultDialer({ + peerId, + peerStore, + transportManager: stubInterface(), + connectionGater: stubInterface() + }, + { + autoDialInterval: 1000, + inboundUpgradeTimeout: 1000 + }) + const connectionManager = new DefaultConnectionManager({ peerId: peerIds[0], - dialer: stubInterface(), + dialer, upgrader, peerStore }, { maxConnections: 1000, - minConnections: 50, - autoDialInterval: 1000, - inboundUpgradeTimeout: 1000 + minConnections: 50 }) await start(connectionManager) diff --git a/test/dialing/direct.node.ts b/test/dialing/direct.node.ts index 86ff236db8..f947244050 100644 --- a/test/dialing/direct.node.ts +++ b/test/dialing/direct.node.ts @@ -78,12 +78,14 @@ describe('Dialing (direct, TCP)', () => { connectionGater: mockConnectionGater() }) localComponents.peerStore = new PersistentPeerStore(localComponents) - localComponents.connectionManager = new DefaultConnectionManager(localComponents, { - maxConnections: 100, - minConnections: 50, + localComponents.dialer = new DefaultDialer(localComponents, { autoDialInterval: 1000, inboundUpgradeTimeout: 1000 }) + localComponents.connectionManager = new DefaultConnectionManager(localComponents, { + maxConnections: 100, + minConnections: 50 + }) localTM = new DefaultTransportManager(localComponents) localTM.add(tcp()()) diff --git a/test/dialing/direct.spec.ts b/test/dialing/direct.spec.ts index 1084db1270..bb12647026 100644 --- a/test/dialing/direct.spec.ts +++ b/test/dialing/direct.spec.ts @@ -50,12 +50,14 @@ describe('Dialing (direct, WebSockets)', () => { localComponents.peerStore = new PersistentPeerStore(localComponents, { addressFilter: localComponents.connectionGater.filterMultiaddrForPeer }) - localComponents.connectionManager = new DefaultConnectionManager(localComponents, { - maxConnections: 100, - minConnections: 50, + localComponents.dialer = new DefaultDialer(localComponents, { autoDialInterval: 1000, inboundUpgradeTimeout: 1000 }) + localComponents.connectionManager = new DefaultConnectionManager(localComponents, { + maxConnections: 100, + minConnections: 50 + }) localTM = new DefaultTransportManager(localComponents) localTM.add(webSockets({ filter: filters.all })()) diff --git a/test/fetch/index.spec.ts b/test/fetch/index.spec.ts index 27a7e80db3..9c75c40b79 100644 --- a/test/fetch/index.spec.ts +++ b/test/fetch/index.spec.ts @@ -15,6 +15,7 @@ import { pipe } from 'it-pipe' import { PersistentPeerStore } from '@libp2p/peer-store' import { MemoryDatastore } from 'datastore-core' import { DefaultComponents } from '../../src/components.js' +import { DefaultDialer } from '../../src/connection-manager/dialer/index.js' const defaultInit: FetchServiceInit = { protocolPrefix: 'ipfs', @@ -33,12 +34,15 @@ async function createComponents (index: number) { datastore: new MemoryDatastore() }) components.peerStore = new PersistentPeerStore(components) - components.connectionManager = new DefaultConnectionManager(components, { - minConnections: 50, - maxConnections: 1000, + components.dialer = new DefaultDialer(components, { autoDialInterval: 1000, inboundUpgradeTimeout: 1000 }) + components.connectionManager = new DefaultConnectionManager(components, { + minConnections: 50, + maxConnections: 1000 + + }) return components } diff --git a/test/identify/index.spec.ts b/test/identify/index.spec.ts index 5a5f0b247e..4bb78815e2 100644 --- a/test/identify/index.spec.ts +++ b/test/identify/index.spec.ts @@ -29,6 +29,7 @@ import { TimeoutController } from 'timeout-abort-controller' import { CustomEvent } from '@libp2p/interfaces/events' import pDefer from 'p-defer' import { DefaultComponents } from '../../src/components.js' +import { DefaultDialer } from '../../src/connection-manager/dialer/index.js' const listenMaddrs = [multiaddr('/ip4/127.0.0.1/tcp/15002/ws')] @@ -59,7 +60,9 @@ async function createComponents (index: number) { components.peerStore = new PersistentPeerStore(components) components.connectionManager = new DefaultConnectionManager(components, { minConnections: 50, - maxConnections: 1000, + maxConnections: 1000 + }) + components.dialer = new DefaultDialer(components, { autoDialInterval: 1000, inboundUpgradeTimeout: 1000 }) diff --git a/test/identify/push.spec.ts b/test/identify/push.spec.ts index c6482aecce..e612e6ede4 100644 --- a/test/identify/push.spec.ts +++ b/test/identify/push.spec.ts @@ -26,6 +26,7 @@ import { start, stop } from '@libp2p/interfaces/startable' import { stubInterface } from 'sinon-ts' import type { Dialer } from '@libp2p/interface-connection-manager' import { DefaultComponents } from '../../src/components.js' +import { DefaultDialer } from '../../src/connection-manager/dialer/index.js' const listenMaddrs = [multiaddr('/ip4/127.0.0.1/tcp/15002/ws')] @@ -57,7 +58,9 @@ async function createComponents (index: number): Promise { components.peerStore = new PersistentPeerStore(components) components.connectionManager = new DefaultConnectionManager(components, { minConnections: 50, - maxConnections: 1000, + maxConnections: 1000 + }) + components.dialer = new DefaultDialer(components, { autoDialInterval: 1000, inboundUpgradeTimeout: 1000 }) diff --git a/test/ping/index.spec.ts b/test/ping/index.spec.ts index 4fedd39806..808be0b713 100644 --- a/test/ping/index.spec.ts +++ b/test/ping/index.spec.ts @@ -15,6 +15,7 @@ import { pipe } from 'it-pipe' import { PersistentPeerStore } from '@libp2p/peer-store' import { MemoryDatastore } from 'datastore-core' import { DefaultComponents } from '../../src/components.js' +import { DefaultDialer } from '../../src/connection-manager/dialer/index.js' const defaultInit: PingServiceInit = { protocolPrefix: 'ipfs', @@ -33,12 +34,14 @@ async function createComponents (index: number): Promise { datastore: new MemoryDatastore() }) components.peerStore = new PersistentPeerStore(components) - components.connectionManager = new DefaultConnectionManager(components, { - minConnections: 50, - maxConnections: 1000, + components.dialer = new DefaultDialer(components, { autoDialInterval: 1000, inboundUpgradeTimeout: 1000 }) + components.connectionManager = new DefaultConnectionManager(components, { + minConnections: 50, + maxConnections: 1000 + }) return components } diff --git a/test/registrar/registrar.spec.ts b/test/registrar/registrar.spec.ts index d9fac96a4f..09fe237a27 100644 --- a/test/registrar/registrar.spec.ts +++ b/test/registrar/registrar.spec.ts @@ -43,9 +43,7 @@ describe('registrar', () => { components.peerStore = new PersistentPeerStore(components) components.connectionManager = new DefaultConnectionManager(components, { minConnections: 50, - maxConnections: 1000, - autoDialInterval: 1000, - inboundUpgradeTimeout: 1000 + maxConnections: 1000 }) registrar = new DefaultRegistrar(components) })