libp2p 0.37.3 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/README.md +1 -2
  2. package/dist/src/address-manager/index.d.ts +2 -2
  3. package/dist/src/address-manager/index.d.ts.map +1 -1
  4. package/dist/src/circuit/auto-relay.d.ts +4 -4
  5. package/dist/src/circuit/auto-relay.d.ts.map +1 -1
  6. package/dist/src/circuit/circuit/hop.d.ts +7 -5
  7. package/dist/src/circuit/circuit/hop.d.ts.map +1 -1
  8. package/dist/src/circuit/circuit/hop.js +8 -4
  9. package/dist/src/circuit/circuit/hop.js.map +1 -1
  10. package/dist/src/circuit/circuit/stop.d.ts +6 -4
  11. package/dist/src/circuit/circuit/stop.d.ts.map +1 -1
  12. package/dist/src/circuit/circuit/stop.js +4 -2
  13. package/dist/src/circuit/circuit/stop.js.map +1 -1
  14. package/dist/src/circuit/circuit/stream-handler.d.ts +3 -2
  15. package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
  16. package/dist/src/circuit/circuit/stream-handler.js +2 -2
  17. package/dist/src/circuit/circuit/stream-handler.js.map +1 -1
  18. package/dist/src/circuit/index.d.ts +4 -12
  19. package/dist/src/circuit/index.d.ts.map +1 -1
  20. package/dist/src/circuit/index.js.map +1 -1
  21. package/dist/src/circuit/listener.d.ts +3 -3
  22. package/dist/src/circuit/listener.d.ts.map +1 -1
  23. package/dist/src/circuit/pb/index.d.ts +5 -4
  24. package/dist/src/circuit/pb/index.d.ts.map +1 -1
  25. package/dist/src/circuit/pb/index.js +107 -11
  26. package/dist/src/circuit/pb/index.js.map +1 -1
  27. package/dist/src/circuit/transport.d.ts +8 -5
  28. package/dist/src/circuit/transport.d.ts.map +1 -1
  29. package/dist/src/circuit/transport.js +81 -59
  30. package/dist/src/circuit/transport.js.map +1 -1
  31. package/dist/src/config.d.ts.map +1 -1
  32. package/dist/src/config.js +27 -4
  33. package/dist/src/config.js.map +1 -1
  34. package/dist/src/connection-manager/auto-dialler.d.ts +1 -1
  35. package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
  36. package/dist/src/connection-manager/dialer/auto-dialer.d.ts +2 -2
  37. package/dist/src/connection-manager/dialer/auto-dialer.d.ts.map +1 -1
  38. package/dist/src/connection-manager/dialer/auto-dialer.js +6 -0
  39. package/dist/src/connection-manager/dialer/auto-dialer.js.map +1 -1
  40. package/dist/src/connection-manager/dialer/dial-request.d.ts +1 -1
  41. package/dist/src/connection-manager/dialer/dial-request.d.ts.map +1 -1
  42. package/dist/src/connection-manager/dialer/index.d.ts +9 -9
  43. package/dist/src/connection-manager/dialer/index.d.ts.map +1 -1
  44. package/dist/src/connection-manager/dialer/index.js +11 -11
  45. package/dist/src/connection-manager/dialer/index.js.map +1 -1
  46. package/dist/src/connection-manager/index.d.ts +20 -16
  47. package/dist/src/connection-manager/index.d.ts.map +1 -1
  48. package/dist/src/connection-manager/index.js +185 -65
  49. package/dist/src/connection-manager/index.js.map +1 -1
  50. package/dist/src/constants.d.ts +4 -0
  51. package/dist/src/constants.d.ts.map +1 -1
  52. package/dist/src/constants.js +4 -0
  53. package/dist/src/constants.js.map +1 -1
  54. package/dist/src/content-routing/index.d.ts +4 -4
  55. package/dist/src/content-routing/index.d.ts.map +1 -1
  56. package/dist/src/content-routing/utils.d.ts +2 -2
  57. package/dist/src/content-routing/utils.d.ts.map +1 -1
  58. package/dist/src/dht/dht-content-routing.d.ts +3 -3
  59. package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
  60. package/dist/src/dht/dht-peer-routing.d.ts +5 -5
  61. package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
  62. package/dist/src/dht/dummy-dht.d.ts +3 -3
  63. package/dist/src/dht/dummy-dht.d.ts.map +1 -1
  64. package/dist/src/dht/dummy-dht.js +1 -1
  65. package/dist/src/dht/dummy-dht.js.map +1 -1
  66. package/dist/src/errors.d.ts +4 -1
  67. package/dist/src/errors.d.ts.map +1 -1
  68. package/dist/src/errors.js +3 -0
  69. package/dist/src/errors.js.map +1 -1
  70. package/dist/src/fetch/index.d.ts +11 -4
  71. package/dist/src/fetch/index.d.ts.map +1 -1
  72. package/dist/src/fetch/index.js +82 -41
  73. package/dist/src/fetch/index.js.map +1 -1
  74. package/dist/src/fetch/pb/proto.d.ts +4 -3
  75. package/dist/src/fetch/pb/proto.d.ts.map +1 -1
  76. package/dist/src/fetch/pb/proto.js +88 -8
  77. package/dist/src/fetch/pb/proto.js.map +1 -1
  78. package/dist/src/get-peer.d.ts +2 -2
  79. package/dist/src/get-peer.d.ts.map +1 -1
  80. package/dist/src/get-peer.js +1 -1
  81. package/dist/src/get-peer.js.map +1 -1
  82. package/dist/src/identify/index.d.ts +8 -8
  83. package/dist/src/identify/index.d.ts.map +1 -1
  84. package/dist/src/identify/index.js +49 -34
  85. package/dist/src/identify/index.js.map +1 -1
  86. package/dist/src/identify/pb/message.d.ts +2 -1
  87. package/dist/src/identify/pb/message.d.ts.map +1 -1
  88. package/dist/src/identify/pb/message.js +94 -10
  89. package/dist/src/identify/pb/message.js.map +1 -1
  90. package/dist/src/index.d.ts +18 -17
  91. package/dist/src/index.d.ts.map +1 -1
  92. package/dist/src/index.js.map +1 -1
  93. package/dist/src/insecure/index.d.ts +2 -2
  94. package/dist/src/insecure/index.d.ts.map +1 -1
  95. package/dist/src/insecure/index.js +8 -4
  96. package/dist/src/insecure/index.js.map +1 -1
  97. package/dist/src/insecure/pb/proto.d.ts +4 -3
  98. package/dist/src/insecure/pb/proto.d.ts.map +1 -1
  99. package/dist/src/insecure/pb/proto.js +89 -9
  100. package/dist/src/insecure/pb/proto.js.map +1 -1
  101. package/dist/src/keychain/index.d.ts +2 -2
  102. package/dist/src/keychain/index.d.ts.map +1 -1
  103. package/dist/src/libp2p.d.ts +14 -14
  104. package/dist/src/libp2p.d.ts.map +1 -1
  105. package/dist/src/libp2p.js +17 -17
  106. package/dist/src/libp2p.js.map +1 -1
  107. package/dist/src/metrics/index.d.ts +4 -5
  108. package/dist/src/metrics/index.d.ts.map +1 -1
  109. package/dist/src/metrics/index.js +9 -6
  110. package/dist/src/metrics/index.js.map +1 -1
  111. package/dist/src/metrics/moving-average.d.ts +1 -1
  112. package/dist/src/metrics/moving-average.d.ts.map +1 -1
  113. package/dist/src/metrics/stats.d.ts +1 -1
  114. package/dist/src/metrics/stats.d.ts.map +1 -1
  115. package/dist/src/nat-manager.d.ts +1 -1
  116. package/dist/src/nat-manager.d.ts.map +1 -1
  117. package/dist/src/peer-record-updater.d.ts +1 -1
  118. package/dist/src/peer-record-updater.d.ts.map +1 -1
  119. package/dist/src/peer-routing.d.ts +4 -4
  120. package/dist/src/peer-routing.d.ts.map +1 -1
  121. package/dist/src/ping/index.d.ts +10 -3
  122. package/dist/src/ping/index.d.ts.map +1 -1
  123. package/dist/src/ping/index.js +32 -9
  124. package/dist/src/ping/index.js.map +1 -1
  125. package/dist/src/pnet/index.d.ts +1 -2
  126. package/dist/src/pnet/index.d.ts.map +1 -1
  127. package/dist/src/pnet/index.js +2 -1
  128. package/dist/src/pnet/index.js.map +1 -1
  129. package/dist/src/pubsub/dummy-pubsub.d.ts +2 -2
  130. package/dist/src/pubsub/dummy-pubsub.d.ts.map +1 -1
  131. package/dist/src/registrar.d.ts +10 -8
  132. package/dist/src/registrar.d.ts.map +1 -1
  133. package/dist/src/registrar.js +63 -44
  134. package/dist/src/registrar.js.map +1 -1
  135. package/dist/src/transport-manager.d.ts +3 -3
  136. package/dist/src/transport-manager.d.ts.map +1 -1
  137. package/dist/src/upgrader.d.ts +12 -6
  138. package/dist/src/upgrader.d.ts.map +1 -1
  139. package/dist/src/upgrader.js +183 -82
  140. package/dist/src/upgrader.js.map +1 -1
  141. package/dist/src/version.d.ts.map +1 -1
  142. package/dist/src/version.js.map +1 -1
  143. package/package.json +66 -42
  144. package/src/address-manager/index.ts +2 -2
  145. package/src/circuit/README.md +2 -2
  146. package/src/circuit/auto-relay.ts +4 -4
  147. package/src/circuit/circuit/hop.ts +20 -11
  148. package/src/circuit/circuit/stop.ts +10 -5
  149. package/src/circuit/circuit/stream-handler.ts +6 -5
  150. package/src/circuit/index.ts +4 -13
  151. package/src/circuit/listener.ts +3 -3
  152. package/src/circuit/pb/index.ts +133 -15
  153. package/src/circuit/transport.ts +92 -63
  154. package/src/config.ts +27 -4
  155. package/src/connection-manager/auto-dialler.ts +1 -1
  156. package/src/connection-manager/dialer/auto-dialer.ts +8 -2
  157. package/src/connection-manager/dialer/dial-request.ts +1 -1
  158. package/src/connection-manager/dialer/index.ts +15 -15
  159. package/src/connection-manager/index.ts +239 -82
  160. package/src/constants.ts +5 -0
  161. package/src/content-routing/index.ts +2 -2
  162. package/src/content-routing/utils.ts +2 -2
  163. package/src/dht/dht-content-routing.ts +2 -2
  164. package/src/dht/dht-peer-routing.ts +3 -3
  165. package/src/dht/dummy-dht.ts +3 -3
  166. package/src/errors.ts +4 -1
  167. package/src/fetch/index.ts +120 -53
  168. package/src/fetch/pb/proto.ts +109 -11
  169. package/src/get-peer.ts +3 -3
  170. package/src/identify/index.ts +64 -47
  171. package/src/identify/pb/message.ts +111 -11
  172. package/src/index.ts +18 -17
  173. package/src/insecure/index.ts +11 -6
  174. package/src/insecure/pb/proto.ts +111 -12
  175. package/src/keychain/index.ts +2 -2
  176. package/src/libp2p.ts +34 -29
  177. package/src/metrics/index.ts +13 -12
  178. package/src/metrics/moving-average.ts +1 -1
  179. package/src/metrics/stats.ts +1 -1
  180. package/src/nat-manager.ts +1 -1
  181. package/src/peer-record-updater.ts +1 -1
  182. package/src/peer-routing.ts +4 -4
  183. package/src/ping/index.ts +48 -15
  184. package/src/pnet/index.ts +3 -2
  185. package/src/pubsub/dummy-pubsub.ts +2 -2
  186. package/src/registrar.ts +79 -55
  187. package/src/transport-manager.ts +3 -3
  188. package/src/upgrader.ts +223 -93
  189. package/src/version.ts +1 -2
@@ -10,19 +10,30 @@ import { createListener } from './listener.js'
10
10
  import { handleCanHop, handleHop, hop } from './circuit/hop.js'
11
11
  import { handleStop } from './circuit/stop.js'
12
12
  import { StreamHandler } from './circuit/stream-handler.js'
13
- import { symbol } from '@libp2p/interfaces/transport'
13
+ import { symbol } from '@libp2p/interface-transport'
14
14
  import { peerIdFromString } from '@libp2p/peer-id'
15
- import { Components, Initializable } from '@libp2p/interfaces/components'
15
+ import { Components, Initializable } from '@libp2p/components'
16
16
  import type { AbortOptions } from '@libp2p/interfaces'
17
- import type { IncomingStreamData } from '@libp2p/interfaces/registrar'
18
- import type { Listener, Transport, CreateListenerOptions, ConnectionHandler } from '@libp2p/interfaces/transport'
19
- import type { Connection } from '@libp2p/interfaces/connection'
17
+ import type { IncomingStreamData } from '@libp2p/interface-registrar'
18
+ import type { Listener, Transport, CreateListenerOptions, ConnectionHandler } from '@libp2p/interface-transport'
19
+ import type { Connection } from '@libp2p/interface-connection'
20
+ import type { RelayConfig } from '../index.js'
21
+ import { abortableDuplex } from 'abortable-iterator'
22
+ import { TimeoutController } from 'timeout-abort-controller'
23
+ import { setMaxListeners } from 'events'
24
+ import type { Uint8ArrayList } from 'uint8arraylist'
25
+ import type { Duplex } from 'it-stream-types'
20
26
 
21
27
  const log = logger('libp2p:circuit')
22
28
 
23
29
  export class Circuit implements Transport, Initializable {
24
30
  private handler?: ConnectionHandler
25
31
  private components: Components = new Components()
32
+ private readonly _init: RelayConfig
33
+
34
+ constructor (init: RelayConfig) {
35
+ this._init = init
36
+ }
26
37
 
27
38
  init (components: Components): void {
28
39
  this.components = components
@@ -54,49 +65,25 @@ export class Circuit implements Transport, Initializable {
54
65
 
55
66
  async _onProtocol (data: IncomingStreamData) {
56
67
  const { connection, stream } = data
57
- const streamHandler = new StreamHandler({ stream })
58
- const request = await streamHandler.read()
59
-
60
- if (request == null) {
61
- log('request was invalid, could not read from stream')
62
- streamHandler.write({
63
- type: CircuitPB.Type.STATUS,
64
- code: CircuitPB.Status.MALFORMED_MESSAGE
65
- })
66
- streamHandler.close()
67
- return
68
- }
68
+ const controller = new TimeoutController(this._init.hop.timeout)
69
69
 
70
- let virtualConnection
70
+ try {
71
+ // fails on node < 15.4
72
+ setMaxListeners?.(Infinity, controller.signal)
73
+ } catch {}
71
74
 
72
- switch (request.type) {
73
- case CircuitPB.Type.CAN_HOP: {
74
- log('received CAN_HOP request from %p', connection.remotePeer)
75
- await handleCanHop({ circuit: this, connection, streamHandler })
76
- break
77
- }
78
- case CircuitPB.Type.HOP: {
79
- log('received HOP request from %p', connection.remotePeer)
80
- virtualConnection = await handleHop({
81
- connection,
82
- request,
83
- streamHandler,
84
- circuit: this,
85
- connectionManager: this.components.getConnectionManager()
86
- })
87
- break
88
- }
89
- case CircuitPB.Type.STOP: {
90
- log('received STOP request from %p', connection.remotePeer)
91
- virtualConnection = await handleStop({
92
- connection,
93
- request,
94
- streamHandler
95
- })
96
- break
97
- }
98
- default: {
99
- log('Request of type %s not supported', request.type)
75
+ try {
76
+ const source = abortableDuplex(stream, controller.signal)
77
+ const streamHandler = new StreamHandler({
78
+ stream: {
79
+ ...stream,
80
+ ...source
81
+ }
82
+ })
83
+ const request = await streamHandler.read()
84
+
85
+ if (request == null) {
86
+ log('request was invalid, could not read from stream')
100
87
  streamHandler.write({
101
88
  type: CircuitPB.Type.STATUS,
102
89
  code: CircuitPB.Status.MALFORMED_MESSAGE
@@ -104,27 +91,68 @@ export class Circuit implements Transport, Initializable {
104
91
  streamHandler.close()
105
92
  return
106
93
  }
107
- }
108
94
 
109
- if (virtualConnection != null) {
110
- // @ts-expect-error dst peer will not be undefined
111
- const remoteAddr = new Multiaddr(request.dstPeer.addrs[0])
112
- // @ts-expect-error dst peer will not be undefined
113
- const localAddr = new Multiaddr(request.srcPeer.addrs[0])
114
- const maConn = streamToMaConnection({
115
- stream: virtualConnection,
116
- remoteAddr,
117
- localAddr
118
- })
119
- const type = request.type === CircuitPB.Type.HOP ? 'relay' : 'inbound'
120
- log('new %s connection %s', type, maConn.remoteAddr)
95
+ let virtualConnection: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array> | undefined
96
+
97
+ switch (request.type) {
98
+ case CircuitPB.Type.CAN_HOP: {
99
+ log('received CAN_HOP request from %p', connection.remotePeer)
100
+ await handleCanHop({ circuit: this, connection, streamHandler })
101
+ break
102
+ }
103
+ case CircuitPB.Type.HOP: {
104
+ log('received HOP request from %p', connection.remotePeer)
105
+ await handleHop({
106
+ connection,
107
+ request,
108
+ streamHandler,
109
+ circuit: this,
110
+ connectionManager: this.components.getConnectionManager()
111
+ })
112
+ break
113
+ }
114
+ case CircuitPB.Type.STOP: {
115
+ log('received STOP request from %p', connection.remotePeer)
116
+ virtualConnection = await handleStop({
117
+ connection,
118
+ request,
119
+ streamHandler
120
+ })
121
+ break
122
+ }
123
+ default: {
124
+ log('Request of type %s not supported', request.type)
125
+ streamHandler.write({
126
+ type: CircuitPB.Type.STATUS,
127
+ code: CircuitPB.Status.MALFORMED_MESSAGE
128
+ })
129
+ streamHandler.close()
130
+ return
131
+ }
132
+ }
121
133
 
122
- const conn = await this.components.getUpgrader().upgradeInbound(maConn)
123
- log('%s connection %s upgraded', type, maConn.remoteAddr)
134
+ if (virtualConnection != null) {
135
+ const remoteAddr = connection.remoteAddr
136
+ .encapsulate('/p2p-circuit')
137
+ .encapsulate(new Multiaddr(request.dstPeer?.addrs[0]))
138
+ const localAddr = new Multiaddr(request.srcPeer?.addrs[0])
139
+ const maConn = streamToMaConnection({
140
+ stream: virtualConnection,
141
+ remoteAddr,
142
+ localAddr
143
+ })
144
+ const type = request.type === CircuitPB.Type.HOP ? 'relay' : 'inbound'
145
+ log('new %s connection %s', type, maConn.remoteAddr)
146
+
147
+ const conn = await this.components.getUpgrader().upgradeInbound(maConn)
148
+ log('%s connection %s upgraded', type, maConn.remoteAddr)
124
149
 
125
- if (this.handler != null) {
126
- this.handler(conn)
150
+ if (this.handler != null) {
151
+ this.handler(conn)
152
+ }
127
153
  }
154
+ } finally {
155
+ controller.clear()
128
156
  }
129
157
  }
130
158
 
@@ -160,6 +188,7 @@ export class Circuit implements Transport, Initializable {
160
188
 
161
189
  try {
162
190
  const virtualConnection = await hop({
191
+ ...options,
163
192
  connection: relayConnection,
164
193
  request: {
165
194
  type: CircuitPB.Type.HOP,
package/src/config.ts CHANGED
@@ -10,6 +10,7 @@ import type { Libp2pInit } from './index.js'
10
10
  import { codes, messages } from './errors.js'
11
11
  import errCode from 'err-code'
12
12
  import type { RecursivePartial } from '@libp2p/interfaces'
13
+ import { isNode, isBrowser, isWebWorker, isElectronMain, isElectronRenderer, isReactNative } from 'wherearewe'
13
14
 
14
15
  const DefaultConfig: Partial<Libp2pInit> = {
15
16
  addresses: {
@@ -26,6 +27,7 @@ const DefaultConfig: Partial<Libp2pInit> = {
26
27
  maxParallelDials: Constants.MAX_PARALLEL_DIALS,
27
28
  maxDialsPerPeer: Constants.MAX_PER_PEER_DIALS,
28
29
  dialTimeout: Constants.DIAL_TIMEOUT,
30
+ inboundUpgradeTimeout: Constants.INBOUND_UPGRADE_TIMEOUT,
29
31
  resolvers: {
30
32
  dnsaddr: dnsaddrResolver
31
33
  },
@@ -67,7 +69,8 @@ const DefaultConfig: Partial<Libp2pInit> = {
67
69
  },
68
70
  hop: {
69
71
  enabled: false,
70
- active: false
72
+ active: false,
73
+ timeout: 30000
71
74
  },
72
75
  autoRelay: {
73
76
  enabled: false,
@@ -79,13 +82,24 @@ const DefaultConfig: Partial<Libp2pInit> = {
79
82
  host: {
80
83
  agentVersion: AGENT_VERSION
81
84
  },
82
- timeout: 30000
85
+ // https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/identify/id.go#L48
86
+ timeout: 60000,
87
+ maxInboundStreams: 1,
88
+ maxOutboundStreams: 1,
89
+ maxPushIncomingStreams: 1,
90
+ maxPushOutgoingStreams: 1
83
91
  },
84
92
  ping: {
85
- protocolPrefix: 'ipfs'
93
+ protocolPrefix: 'ipfs',
94
+ maxInboundStreams: 1,
95
+ maxOutboundStreams: 1,
96
+ timeout: 10000
86
97
  },
87
98
  fetch: {
88
- protocolPrefix: 'libp2p'
99
+ protocolPrefix: 'libp2p',
100
+ maxInboundStreams: 1,
101
+ maxOutboundStreams: 1,
102
+ timeout: 10000
89
103
  }
90
104
  }
91
105
 
@@ -104,5 +118,14 @@ export function validateConfig (opts: RecursivePartial<Libp2pInit>): Libp2pInit
104
118
  throw errCode(new Error(messages.ERR_PROTECTOR_REQUIRED), codes.ERR_PROTECTOR_REQUIRED)
105
119
  }
106
120
 
121
+ // Append user agent version to default AGENT_VERSION depending on the environment
122
+ if (resultingOptions.identify.host.agentVersion === AGENT_VERSION) {
123
+ if (isNode || isElectronMain) {
124
+ resultingOptions.identify.host.agentVersion += ` UserAgent=${globalThis.process.version}`
125
+ } else if (isBrowser || isWebWorker || isElectronRenderer || isReactNative) {
126
+ resultingOptions.identify.host.agentVersion += ` UserAgent=${globalThis.navigator.userAgent}`
127
+ }
128
+ }
129
+
107
130
  return resultingOptions
108
131
  }
@@ -7,7 +7,7 @@ import { pipe } from 'it-pipe'
7
7
  import filter from 'it-filter'
8
8
  import sort from 'it-sort'
9
9
  import type { Startable } from '@libp2p/interfaces/startable'
10
- import type { Components } from '@libp2p/interfaces/components'
10
+ import type { Components } from '@libp2p/components'
11
11
 
12
12
  const log = logger('libp2p:connection-manager:auto-dialler')
13
13
 
@@ -1,7 +1,8 @@
1
- import type { PeerInfo } from '@libp2p/interfaces/peer-info'
1
+ import type { PeerInfo } from '@libp2p/interface-peer-info'
2
2
  import { logger } from '@libp2p/logger'
3
- import type { Components } from '@libp2p/interfaces/components'
3
+ import type { Components } from '@libp2p/components'
4
4
  import { TimeoutController } from 'timeout-abort-controller'
5
+ import { setMaxListeners } from 'events'
5
6
 
6
7
  const log = logger('libp2p:dialer:auto-dialer')
7
8
 
@@ -44,6 +45,11 @@ export class AutoDialer {
44
45
 
45
46
  const controller = new TimeoutController(this.dialTimeout)
46
47
 
48
+ try {
49
+ // fails on node < 15.4
50
+ setMaxListeners?.(Infinity, controller.signal)
51
+ } catch {}
52
+
47
53
  void this.components.getConnectionManager().openConnection(peer.id, {
48
54
  signal: controller.signal
49
55
  })
@@ -5,7 +5,7 @@ import { setMaxListeners } from 'events'
5
5
  import { codes } from '../../errors.js'
6
6
  import { logger } from '@libp2p/logger'
7
7
  import type { Multiaddr } from '@multiformats/multiaddr'
8
- import type { Connection } from '@libp2p/interfaces/connection'
8
+ import type { Connection } from '@libp2p/interface-connection'
9
9
  import type { AbortOptions } from '@libp2p/interfaces'
10
10
  import type { Dialer } from './index.js'
11
11
 
@@ -18,16 +18,16 @@ import {
18
18
  MAX_PER_PEER_DIALS,
19
19
  MAX_ADDRS_TO_DIAL
20
20
  } from '../../constants.js'
21
- import type { Connection } from '@libp2p/interfaces/connection'
21
+ import type { Connection } from '@libp2p/interface-connection'
22
22
  import type { AbortOptions } from '@libp2p/interfaces'
23
23
  import type { Startable } from '@libp2p/interfaces/startable'
24
- import type { PeerId } from '@libp2p/interfaces/peer-id'
24
+ import type { PeerId } from '@libp2p/interface-peer-id'
25
25
  import { getPeer } from '../../get-peer.js'
26
26
  import sort from 'it-sort'
27
- import { Components, Initializable } from '@libp2p/interfaces/components'
27
+ import { Components, Initializable } from '@libp2p/components'
28
28
  import map from 'it-map'
29
- import type { AddressSorter } from '@libp2p/interfaces/peer-store'
30
- import type { ComponentMetricsTracker } from '@libp2p/interfaces/metrics'
29
+ import type { AddressSorter } from '@libp2p/interface-peer-store'
30
+ import type { ComponentMetricsTracker } from '@libp2p/interface-metrics'
31
31
 
32
32
  const log = logger('libp2p:dialer')
33
33
 
@@ -177,7 +177,7 @@ export class Dialer implements Startable, Initializable {
177
177
 
178
178
  log('creating dial target for %p', id)
179
179
 
180
- const dialTarget = await this._createCancellableDialTarget(id)
180
+ const dialTarget = await this._createCancellableDialTarget(id, options)
181
181
 
182
182
  if (dialTarget.addrs.length === 0) {
183
183
  throw errCode(new Error('The dial request has no valid addresses'), codes.ERR_NO_VALID_ADDRESSES)
@@ -207,7 +207,7 @@ export class Dialer implements Startable, Initializable {
207
207
  * The dial to the first address that is successfully able to upgrade a connection
208
208
  * will be used.
209
209
  */
210
- async _createCancellableDialTarget (peer: PeerId): Promise<DialTarget> {
210
+ async _createCancellableDialTarget (peer: PeerId, options: AbortOptions): Promise<DialTarget> {
211
211
  // Make dial target promise cancellable
212
212
  const id = `${(parseInt(String(Math.random() * 1e9), 10)).toString()}${Date.now()}`
213
213
  const cancellablePromise = new Promise<DialTarget>((resolve, reject) => {
@@ -216,7 +216,7 @@ export class Dialer implements Startable, Initializable {
216
216
 
217
217
  try {
218
218
  const dialTarget = await Promise.race([
219
- this._createDialTarget(peer),
219
+ this._createDialTarget(peer, options),
220
220
  cancellablePromise
221
221
  ])
222
222
 
@@ -232,7 +232,7 @@ export class Dialer implements Startable, Initializable {
232
232
  * If a multiaddr is received it should be the first address attempted.
233
233
  * Multiaddrs not supported by the available transports will be filtered out.
234
234
  */
235
- async _createDialTarget (peer: PeerId): Promise<DialTarget> {
235
+ async _createDialTarget (peer: PeerId, options: AbortOptions): Promise<DialTarget> {
236
236
  const knownAddrs = await pipe(
237
237
  await this.components.getPeerStore().addressBook.get(peer),
238
238
  (source) => filter(source, async (address) => {
@@ -253,7 +253,7 @@ export class Dialer implements Startable, Initializable {
253
253
 
254
254
  const addrs: Multiaddr[] = []
255
255
  for (const a of knownAddrs) {
256
- const resolvedAddrs = await this._resolve(a)
256
+ const resolvedAddrs = await this._resolve(a, options)
257
257
  resolvedAddrs.forEach(ra => addrs.push(ra))
258
258
  }
259
259
 
@@ -341,7 +341,7 @@ export class Dialer implements Startable, Initializable {
341
341
  /**
342
342
  * Resolve multiaddr recursively
343
343
  */
344
- async _resolve (ma: Multiaddr): Promise<Multiaddr[]> {
344
+ async _resolve (ma: Multiaddr, options: AbortOptions): Promise<Multiaddr[]> {
345
345
  // TODO: recursive logic should live in multiaddr once dns4/dns6 support is in place
346
346
  // Now only supporting resolve for dnsaddr
347
347
  const resolvableProto = ma.protoNames().includes('dnsaddr')
@@ -351,9 +351,9 @@ export class Dialer implements Startable, Initializable {
351
351
  return [ma]
352
352
  }
353
353
 
354
- const resolvedMultiaddrs = await this._resolveRecord(ma)
354
+ const resolvedMultiaddrs = await this._resolveRecord(ma, options)
355
355
  const recursiveMultiaddrs = await Promise.all(resolvedMultiaddrs.map(async (nm) => {
356
- return await this._resolve(nm)
356
+ return await this._resolve(nm, options)
357
357
  }))
358
358
 
359
359
  const addrs = recursiveMultiaddrs.flat()
@@ -368,10 +368,10 @@ export class Dialer implements Startable, Initializable {
368
368
  /**
369
369
  * Resolve a given multiaddr. If this fails, an empty array will be returned
370
370
  */
371
- async _resolveRecord (ma: Multiaddr): Promise<Multiaddr[]> {
371
+ async _resolveRecord (ma: Multiaddr, options: AbortOptions): Promise<Multiaddr[]> {
372
372
  try {
373
373
  ma = new Multiaddr(ma.toString()) // Use current multiaddr module
374
- const multiaddrs = await ma.resolve()
374
+ const multiaddrs = await ma.resolve(options)
375
375
  return multiaddrs
376
376
  } catch (err) {
377
377
  log.error(`multiaddr ${ma.toString()} could not be resolved`, err)