@@ -17,7 +17,7 @@ import { Connection, isConnection } from '@libp2p/interface-connection'
1717import { AbortError } from '@libp2p/interfaces/errors'
1818import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
1919import { MemoryDatastore } from 'datastore-core/memory'
20- import { Dialer } from '../../src/connection-manager/dialer/index.js'
20+ import { DefaultDialer } from '../../src/connection-manager/dialer/index.js'
2121import { DefaultAddressManager } from '../../src/address-manager/index.js'
2222import { PersistentPeerStore } from '@libp2p/peer-store'
2323import { DefaultTransportManager } from '../../src/transport-manager.js'
@@ -95,26 +95,23 @@ describe('Dialing (direct, TCP)', () => {
9595 } )
9696
9797 it ( 'should be able to connect to a remote node via its multiaddr' , async ( ) => {
98- const dialer = new Dialer ( )
99- dialer . init ( localComponents )
98+ const dialer = new DefaultDialer ( localComponents )
10099
101100 const connection = await dialer . dial ( remoteAddr )
102101 expect ( connection ) . to . exist ( )
103102 await connection . close ( )
104103 } )
105104
106105 it ( 'should fail to connect to an unsupported multiaddr' , async ( ) => {
107- const dialer = new Dialer ( )
108- dialer . init ( localComponents )
106+ const dialer = new DefaultDialer ( localComponents )
109107
110108 await expect ( dialer . dial ( unsupportedAddr ) )
111109 . to . eventually . be . rejectedWith ( Error )
112110 . and . to . have . nested . property ( '.code' , ErrorCodes . ERR_NO_VALID_ADDRESSES )
113111 } )
114112
115113 it ( 'should fail to connect if peer has no known addresses' , async ( ) => {
116- const dialer = new Dialer ( )
117- dialer . init ( localComponents )
114+ const dialer = new DefaultDialer ( localComponents )
118115 const peerId = await createFromJSON ( Peers [ 1 ] )
119116
120117 await expect ( dialer . dial ( peerId ) )
@@ -125,8 +122,7 @@ describe('Dialing (direct, TCP)', () => {
125122 it ( 'should be able to connect to a given peer id' , async ( ) => {
126123 await localComponents . getPeerStore ( ) . addressBook . set ( remoteComponents . getPeerId ( ) , remoteTM . getAddrs ( ) )
127124
128- const dialer = new Dialer ( )
129- dialer . init ( localComponents )
125+ const dialer = new DefaultDialer ( localComponents )
130126
131127 const connection = await dialer . dial ( remoteComponents . getPeerId ( ) )
132128 expect ( connection ) . to . exist ( )
@@ -136,8 +132,7 @@ describe('Dialing (direct, TCP)', () => {
136132 it ( 'should fail to connect to a given peer with unsupported addresses' , async ( ) => {
137133 await localComponents . getPeerStore ( ) . addressBook . add ( remoteComponents . getPeerId ( ) , [ unsupportedAddr ] )
138134
139- const dialer = new Dialer ( )
140- dialer . init ( localComponents )
135+ const dialer = new DefaultDialer ( localComponents )
141136
142137 await expect ( dialer . dial ( remoteComponents . getPeerId ( ) ) )
143138 . to . eventually . be . rejectedWith ( Error )
@@ -150,8 +145,7 @@ describe('Dialing (direct, TCP)', () => {
150145 const peerId = await createFromJSON ( Peers [ 1 ] )
151146 await localComponents . getPeerStore ( ) . addressBook . add ( peerId , [ ...remoteAddrs , unsupportedAddr ] )
152147
153- const dialer = new Dialer ( )
154- dialer . init ( localComponents )
148+ const dialer = new DefaultDialer ( localComponents )
155149
156150 sinon . spy ( localTM , 'dial' )
157151 const connection = await dialer . dial ( peerId )
@@ -162,10 +156,9 @@ describe('Dialing (direct, TCP)', () => {
162156 } )
163157
164158 it ( 'should abort dials on queue task timeout' , async ( ) => {
165- const dialer = new Dialer ( {
159+ const dialer = new DefaultDialer ( localComponents , {
166160 dialTimeout : 50
167161 } )
168- dialer . init ( localComponents )
169162
170163 sinon . stub ( localTM , 'dial' ) . callsFake ( async ( addr , options = { } ) => {
171164 expect ( options . signal ) . to . exist ( )
@@ -191,10 +184,9 @@ describe('Dialing (direct, TCP)', () => {
191184
192185 await localComponents . getPeerStore ( ) . addressBook . add ( peerId , addrs )
193186
194- const dialer = new Dialer ( {
187+ const dialer = new DefaultDialer ( localComponents , {
195188 maxParallelDials : 2
196189 } )
197- dialer . init ( localComponents )
198190
199191 expect ( dialer . tokens ) . to . have . lengthOf ( 2 )
200192
0 commit comments