libp2p 0.45.0 → 0.45.1

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 (190) hide show
  1. package/README.md +27 -30
  2. package/dist/index.min.js +27 -27
  3. package/dist/src/address-manager/index.d.ts +3 -3
  4. package/dist/src/address-manager/index.d.ts.map +1 -1
  5. package/dist/src/address-manager/index.js +8 -2
  6. package/dist/src/address-manager/index.js.map +1 -1
  7. package/dist/src/autonat/index.d.ts +1 -1
  8. package/dist/src/autonat/index.d.ts.map +1 -1
  9. package/dist/src/autonat/index.js +13 -4
  10. package/dist/src/autonat/index.js.map +1 -1
  11. package/dist/src/circuit-relay/index.d.ts +1 -1
  12. package/dist/src/circuit-relay/index.d.ts.map +1 -1
  13. package/dist/src/circuit-relay/server/advert-service.d.ts +2 -2
  14. package/dist/src/circuit-relay/server/advert-service.d.ts.map +1 -1
  15. package/dist/src/circuit-relay/server/advert-service.js +7 -3
  16. package/dist/src/circuit-relay/server/advert-service.js.map +1 -1
  17. package/dist/src/circuit-relay/server/index.d.ts +8 -8
  18. package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
  19. package/dist/src/circuit-relay/server/index.js +23 -10
  20. package/dist/src/circuit-relay/server/index.js.map +1 -1
  21. package/dist/src/circuit-relay/server/reservation-store.d.ts +5 -5
  22. package/dist/src/circuit-relay/server/reservation-store.d.ts.map +1 -1
  23. package/dist/src/circuit-relay/server/reservation-store.js +10 -3
  24. package/dist/src/circuit-relay/server/reservation-store.js.map +1 -1
  25. package/dist/src/circuit-relay/server/reservation-voucher.d.ts.map +1 -1
  26. package/dist/src/circuit-relay/server/reservation-voucher.js +5 -2
  27. package/dist/src/circuit-relay/server/reservation-voucher.js.map +1 -1
  28. package/dist/src/circuit-relay/transport/discovery.d.ts +4 -4
  29. package/dist/src/circuit-relay/transport/discovery.d.ts.map +1 -1
  30. package/dist/src/circuit-relay/transport/discovery.js +9 -3
  31. package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
  32. package/dist/src/circuit-relay/transport/index.d.ts +8 -9
  33. package/dist/src/circuit-relay/transport/index.d.ts.map +1 -1
  34. package/dist/src/circuit-relay/transport/index.js +25 -15
  35. package/dist/src/circuit-relay/transport/index.js.map +1 -1
  36. package/dist/src/circuit-relay/transport/listener.d.ts +1 -1
  37. package/dist/src/circuit-relay/transport/listener.d.ts.map +1 -1
  38. package/dist/src/circuit-relay/transport/listener.js +15 -19
  39. package/dist/src/circuit-relay/transport/listener.js.map +1 -1
  40. package/dist/src/circuit-relay/transport/reservation-store.d.ts +5 -5
  41. package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
  42. package/dist/src/circuit-relay/transport/reservation-store.js +55 -49
  43. package/dist/src/circuit-relay/transport/reservation-store.js.map +1 -1
  44. package/dist/src/circuit-relay/utils.d.ts.map +1 -1
  45. package/dist/src/circuit-relay/utils.js +3 -3
  46. package/dist/src/circuit-relay/utils.js.map +1 -1
  47. package/dist/src/components.d.ts +6 -6
  48. package/dist/src/components.d.ts.map +1 -1
  49. package/dist/src/components.js +2 -2
  50. package/dist/src/components.js.map +1 -1
  51. package/dist/src/config/connection-gater.browser.d.ts.map +1 -1
  52. package/dist/src/config/connection-gater.browser.js.map +1 -1
  53. package/dist/src/config.d.ts +2 -2
  54. package/dist/src/config.d.ts.map +1 -1
  55. package/dist/src/config.js +4 -7
  56. package/dist/src/config.js.map +1 -1
  57. package/dist/src/connection/index.d.ts +3 -3
  58. package/dist/src/connection/index.d.ts.map +1 -1
  59. package/dist/src/connection/index.js +38 -8
  60. package/dist/src/connection/index.js.map +1 -1
  61. package/dist/src/connection-manager/auto-dial.d.ts +3 -3
  62. package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
  63. package/dist/src/connection-manager/auto-dial.js +9 -1
  64. package/dist/src/connection-manager/auto-dial.js.map +1 -1
  65. package/dist/src/connection-manager/connection-pruner.d.ts +2 -2
  66. package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
  67. package/dist/src/connection-manager/connection-pruner.js +5 -0
  68. package/dist/src/connection-manager/connection-pruner.js.map +1 -1
  69. package/dist/src/connection-manager/dial-queue.d.ts +6 -6
  70. package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
  71. package/dist/src/connection-manager/dial-queue.js +25 -11
  72. package/dist/src/connection-manager/dial-queue.js.map +1 -1
  73. package/dist/src/connection-manager/index.d.ts +12 -12
  74. package/dist/src/connection-manager/index.d.ts.map +1 -1
  75. package/dist/src/connection-manager/index.js +21 -7
  76. package/dist/src/connection-manager/index.js.map +1 -1
  77. package/dist/src/connection-manager/utils.d.ts +2 -3
  78. package/dist/src/connection-manager/utils.d.ts.map +1 -1
  79. package/dist/src/connection-manager/utils.js +3 -3
  80. package/dist/src/connection-manager/utils.js.map +1 -1
  81. package/dist/src/content-routing/index.d.ts +2 -2
  82. package/dist/src/content-routing/index.d.ts.map +1 -1
  83. package/dist/src/content-routing/index.js +7 -4
  84. package/dist/src/content-routing/index.js.map +1 -1
  85. package/dist/src/content-routing/utils.d.ts +1 -1
  86. package/dist/src/content-routing/utils.d.ts.map +1 -1
  87. package/dist/src/fetch/index.d.ts +2 -2
  88. package/dist/src/fetch/index.d.ts.map +1 -1
  89. package/dist/src/fetch/index.js +12 -7
  90. package/dist/src/fetch/index.js.map +1 -1
  91. package/dist/src/get-peer.d.ts +1 -1
  92. package/dist/src/get-peer.d.ts.map +1 -1
  93. package/dist/src/get-peer.js +3 -3
  94. package/dist/src/get-peer.js.map +1 -1
  95. package/dist/src/identify/identify.d.ts +3 -3
  96. package/dist/src/identify/identify.d.ts.map +1 -1
  97. package/dist/src/identify/identify.js +91 -79
  98. package/dist/src/identify/identify.js.map +1 -1
  99. package/dist/src/identify/index.d.ts +5 -4
  100. package/dist/src/identify/index.d.ts.map +1 -1
  101. package/dist/src/identify/index.js +1 -1
  102. package/dist/src/identify/index.js.map +1 -1
  103. package/dist/src/index.d.ts +19 -15
  104. package/dist/src/index.d.ts.map +1 -1
  105. package/dist/src/index.js.map +1 -1
  106. package/dist/src/insecure/index.js +6 -8
  107. package/dist/src/insecure/index.js.map +1 -1
  108. package/dist/src/libp2p.d.ts +11 -11
  109. package/dist/src/libp2p.d.ts.map +1 -1
  110. package/dist/src/libp2p.js +58 -59
  111. package/dist/src/libp2p.js.map +1 -1
  112. package/dist/src/peer-routing.d.ts +2 -2
  113. package/dist/src/peer-routing.d.ts.map +1 -1
  114. package/dist/src/peer-routing.js +8 -6
  115. package/dist/src/peer-routing.js.map +1 -1
  116. package/dist/src/ping/index.d.ts +2 -2
  117. package/dist/src/ping/index.d.ts.map +1 -1
  118. package/dist/src/ping/index.js +14 -8
  119. package/dist/src/ping/index.js.map +1 -1
  120. package/dist/src/pnet/crypto.js +3 -3
  121. package/dist/src/pnet/crypto.js.map +1 -1
  122. package/dist/src/pnet/index.d.ts.map +1 -1
  123. package/dist/src/pnet/index.js +9 -6
  124. package/dist/src/pnet/index.js.map +1 -1
  125. package/dist/src/pnet/key-generator.js +1 -1
  126. package/dist/src/pnet/key-generator.js.map +1 -1
  127. package/dist/src/pubsub/dummy-pubsub.d.ts.map +1 -1
  128. package/dist/src/pubsub/dummy-pubsub.js +2 -5
  129. package/dist/src/pubsub/dummy-pubsub.js.map +1 -1
  130. package/dist/src/registrar.d.ts +3 -4
  131. package/dist/src/registrar.d.ts.map +1 -1
  132. package/dist/src/registrar.js +6 -3
  133. package/dist/src/registrar.js.map +1 -1
  134. package/dist/src/transport-manager.d.ts +5 -5
  135. package/dist/src/transport-manager.d.ts.map +1 -1
  136. package/dist/src/transport-manager.js +8 -3
  137. package/dist/src/transport-manager.js.map +1 -1
  138. package/dist/src/upgrader.d.ts +8 -8
  139. package/dist/src/upgrader.d.ts.map +1 -1
  140. package/dist/src/upgrader.js +11 -6
  141. package/dist/src/upgrader.js.map +1 -1
  142. package/dist/src/upnp-nat/index.d.ts +32 -3
  143. package/dist/src/upnp-nat/index.d.ts.map +1 -1
  144. package/dist/src/upnp-nat/index.js +13 -4
  145. package/dist/src/upnp-nat/index.js.map +1 -1
  146. package/dist/src/version.d.ts +1 -1
  147. package/dist/src/version.js +1 -1
  148. package/dist/typedoc-urls.json +2 -0
  149. package/package.json +6 -7
  150. package/src/address-manager/index.ts +6 -6
  151. package/src/autonat/index.ts +14 -14
  152. package/src/circuit-relay/index.ts +1 -1
  153. package/src/circuit-relay/server/advert-service.ts +4 -4
  154. package/src/circuit-relay/server/index.ts +18 -18
  155. package/src/circuit-relay/server/reservation-store.ts +5 -5
  156. package/src/circuit-relay/server/reservation-voucher.ts +1 -1
  157. package/src/circuit-relay/transport/discovery.ts +7 -7
  158. package/src/circuit-relay/transport/index.ts +26 -24
  159. package/src/circuit-relay/transport/listener.ts +8 -8
  160. package/src/circuit-relay/transport/reservation-store.ts +10 -10
  161. package/src/circuit-relay/utils.ts +6 -6
  162. package/src/components.ts +6 -6
  163. package/src/config/connection-gater.browser.ts +1 -1
  164. package/src/config.ts +8 -12
  165. package/src/connection/index.ts +6 -10
  166. package/src/connection-manager/auto-dial.ts +5 -5
  167. package/src/connection-manager/connection-pruner.ts +4 -4
  168. package/src/connection-manager/dial-queue.ts +18 -17
  169. package/src/connection-manager/index.ts +18 -18
  170. package/src/connection-manager/utils.ts +4 -5
  171. package/src/content-routing/index.ts +6 -6
  172. package/src/content-routing/utils.ts +1 -1
  173. package/src/fetch/index.ts +12 -12
  174. package/src/get-peer.ts +4 -4
  175. package/src/identify/identify.ts +27 -26
  176. package/src/identify/index.ts +6 -6
  177. package/src/index.ts +15 -15
  178. package/src/insecure/index.ts +6 -6
  179. package/src/libp2p.ts +35 -35
  180. package/src/peer-routing.ts +9 -9
  181. package/src/ping/index.ts +12 -12
  182. package/src/pnet/crypto.ts +3 -3
  183. package/src/pnet/index.ts +6 -6
  184. package/src/pnet/key-generator.ts +1 -1
  185. package/src/pubsub/dummy-pubsub.ts +2 -2
  186. package/src/registrar.ts +5 -6
  187. package/src/transport-manager.ts +8 -8
  188. package/src/upgrader.ts +17 -17
  189. package/src/upnp-nat/index.ts +9 -9
  190. package/src/version.ts +1 -1
@@ -1,29 +1,29 @@
1
- import { logger } from '@libp2p/logger'
1
+ import { setMaxListeners } from 'events'
2
2
  import { AbortError, CodeError } from '@libp2p/interfaces/errors'
3
- import { Multiaddr, Resolver, resolvers } from '@multiformats/multiaddr'
3
+ import { logger } from '@libp2p/logger'
4
4
  import { publicAddressesFirst } from '@libp2p/utils/address-sort'
5
+ import { type Multiaddr, type Resolver, resolvers } from '@multiformats/multiaddr'
6
+ import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'
7
+ import { type ClearableSignal, anySignal } from 'any-signal'
8
+ import pDefer from 'p-defer'
9
+ import PQueue from 'p-queue'
5
10
  import { codes } from '../errors.js'
11
+ import { getPeerAddress } from '../get-peer.js'
6
12
  import {
7
13
  DIAL_TIMEOUT,
8
14
  MAX_PARALLEL_DIALS_PER_PEER,
9
15
  MAX_PARALLEL_DIALS,
10
16
  MAX_PEER_ADDRS_TO_DIAL
11
17
  } from './constants.js'
18
+ import { combineSignals, resolveMultiaddrs } from './utils.js'
12
19
  import type { Connection } from '@libp2p/interface-connection'
13
- import type { AbortOptions } from '@libp2p/interfaces'
20
+ import type { ConnectionGater } from '@libp2p/interface-connection-gater'
21
+ import type { AddressSorter } from '@libp2p/interface-libp2p'
22
+ import type { Metric, Metrics } from '@libp2p/interface-metrics'
14
23
  import type { PeerId } from '@libp2p/interface-peer-id'
15
- import { getPeerAddress } from '../get-peer.js'
16
24
  import type { Address, PeerStore } from '@libp2p/interface-peer-store'
17
- import type { Metric, Metrics } from '@libp2p/interface-metrics'
18
25
  import type { TransportManager } from '@libp2p/interface-transport'
19
- import type { ConnectionGater } from '@libp2p/interface-connection-gater'
20
- import PQueue from 'p-queue'
21
- import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'
22
- import { combineSignals, resolveMultiaddrs } from './utils.js'
23
- import pDefer from 'p-defer'
24
- import { ClearableSignal, anySignal } from 'any-signal'
25
- import type { AddressSorter } from '@libp2p/interface-libp2p'
26
- import { setMaxListeners } from 'events'
26
+ import type { AbortOptions } from '@libp2p/interfaces'
27
27
 
28
28
  const log = logger('libp2p:connection-manager:dial-queue')
29
29
 
@@ -214,7 +214,7 @@ export class DialQueue {
214
214
  if (existingDial != null) {
215
215
  log('joining existing dial target for %p', peerId)
216
216
  signal.clear()
217
- return await existingDial.promise
217
+ return existingDial.promise
218
218
  }
219
219
 
220
220
  log('creating dial target for', addrsToDial.map(({ multiaddr }) => multiaddr.toString()))
@@ -252,7 +252,7 @@ export class DialQueue {
252
252
  // let other dials join this one
253
253
  this.pendingDials.push(pendingDial)
254
254
 
255
- return await pendingDial.promise
255
+ return pendingDial.promise
256
256
  }
257
257
 
258
258
  private createDialAbortControllers (userSignal?: AbortSignal): ClearableSignal {
@@ -272,6 +272,7 @@ export class DialQueue {
272
272
  return signal
273
273
  }
274
274
 
275
+ // eslint-disable-next-line complexity
275
276
  private async calculateMultiaddrs (peerId?: PeerId, addrs: Address[] = [], options: DialOptions = {}): Promise<Address[]> {
276
277
  // if a peer id or multiaddr(s) with a peer id, make sure it isn't our peer id and that we are allowed to dial it
277
278
  if (peerId != null) {
@@ -319,7 +320,7 @@ export class DialQueue {
319
320
  const filteredAddrs = resolvedAddresses.filter(addr => Boolean(this.transportManager.transportForMultiaddr(addr.multiaddr)))
320
321
 
321
322
  // deduplicate addresses
322
- const dedupedAddrs: Map<string, Address> = new Map()
323
+ const dedupedAddrs = new Map<string, Address>()
323
324
 
324
325
  for (const addr of filteredAddrs) {
325
326
  const maStr = addr.multiaddr.toString()
@@ -491,7 +492,7 @@ export class DialQueue {
491
492
  signal.clear()
492
493
  })
493
494
 
494
- return await deferred.promise
495
+ return deferred.promise
495
496
  }))
496
497
 
497
498
  // dial succeeded or failed
@@ -1,28 +1,28 @@
1
- import { logger } from '@libp2p/logger'
2
- import { CodeError } from '@libp2p/interfaces/errors'
3
- import type { AbortOptions } from '@libp2p/interfaces'
4
- import type { EventEmitter } from '@libp2p/interfaces/events'
5
- import type { Startable } from '@libp2p/interfaces/startable'
6
- import { codes } from '../errors.js'
7
- import type { PeerId } from '@libp2p/interface-peer-id'
8
- import type { Connection, MultiaddrConnection } from '@libp2p/interface-connection'
9
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
10
- import type { PeerStore } from '@libp2p/interface-peer-store'
11
- import { Multiaddr, Resolver, multiaddr } from '@multiformats/multiaddr'
12
1
  import { KEEP_ALIVE } from '@libp2p/interface-peer-store/tags'
2
+ import { CodeError } from '@libp2p/interfaces/errors'
3
+ import { logger } from '@libp2p/logger'
4
+ import { PeerMap } from '@libp2p/peer-collections'
5
+ import { publicAddressesFirst } from '@libp2p/utils/address-sort'
6
+ import { type Multiaddr, type Resolver, multiaddr } from '@multiformats/multiaddr'
7
+ import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'
13
8
  import { RateLimiterMemory } from 'rate-limiter-flexible'
14
- import type { Metrics } from '@libp2p/interface-metrics'
15
- import type { TransportManager } from '@libp2p/interface-transport'
9
+ import { codes } from '../errors.js'
16
10
  import { getPeerAddress } from '../get-peer.js'
17
11
  import { AutoDial } from './auto-dial.js'
18
- import { DialQueue } from './dial-queue.js'
19
12
  import { ConnectionPruner } from './connection-pruner.js'
20
- import type { ConnectionGater } from '@libp2p/interface-connection-gater'
21
- import { PeerMap } from '@libp2p/peer-collections'
22
- import { publicAddressesFirst } from '@libp2p/utils/address-sort'
23
13
  import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_PRIORITY, DIAL_TIMEOUT, INBOUND_CONNECTION_THRESHOLD, MAX_CONNECTIONS, MAX_INCOMING_PENDING_CONNECTIONS, MAX_PARALLEL_DIALS, MAX_PEER_ADDRS_TO_DIAL, MIN_CONNECTIONS } from './constants.js'
24
- import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'
14
+ import { DialQueue } from './dial-queue.js'
15
+ import type { Connection, MultiaddrConnection } from '@libp2p/interface-connection'
16
+ import type { ConnectionGater } from '@libp2p/interface-connection-gater'
17
+ import type { ConnectionManager } from '@libp2p/interface-connection-manager'
25
18
  import type { PendingDial, AddressSorter, Libp2pEvents } from '@libp2p/interface-libp2p'
19
+ import type { Metrics } from '@libp2p/interface-metrics'
20
+ import type { PeerId } from '@libp2p/interface-peer-id'
21
+ import type { PeerStore } from '@libp2p/interface-peer-store'
22
+ import type { TransportManager } from '@libp2p/interface-transport'
23
+ import type { AbortOptions } from '@libp2p/interfaces'
24
+ import type { EventEmitter } from '@libp2p/interfaces/events'
25
+ import type { Startable } from '@libp2p/interfaces/startable'
26
26
 
27
27
  const log = logger('libp2p:connection-manager')
28
28
 
@@ -1,8 +1,7 @@
1
- import { AbortOptions, multiaddr } from '@multiformats/multiaddr'
2
- import type { Multiaddr } from '@multiformats/multiaddr'
3
- import { logger } from '@libp2p/logger'
4
- import { ClearableSignal, anySignal } from 'any-signal'
5
1
  import { setMaxListeners } from 'events'
2
+ import { logger } from '@libp2p/logger'
3
+ import { type AbortOptions, multiaddr, type Multiaddr } from '@multiformats/multiaddr'
4
+ import { type ClearableSignal, anySignal } from 'any-signal'
6
5
 
7
6
  const log = logger('libp2p:connection-manager:utils')
8
7
 
@@ -21,7 +20,7 @@ export async function resolveMultiaddrs (ma: Multiaddr, options: AbortOptions):
21
20
 
22
21
  const resolvedMultiaddrs = await resolveRecord(ma, options)
23
22
  const recursiveMultiaddrs = await Promise.all(resolvedMultiaddrs.map(async (nm) => {
24
- return await resolveMultiaddrs(nm, options)
23
+ return resolveMultiaddrs(nm, options)
25
24
  }))
26
25
 
27
26
  const addrs = recursiveMultiaddrs.flat()
@@ -1,18 +1,18 @@
1
1
  import { CodeError } from '@libp2p/interfaces/errors'
2
+ import merge from 'it-merge'
3
+ import { pipe } from 'it-pipe'
2
4
  import { messages, codes } from '../errors.js'
3
5
  import {
4
6
  storeAddresses,
5
7
  uniquePeers,
6
8
  requirePeers
7
9
  } from './utils.js'
8
- import merge from 'it-merge'
9
- import { pipe } from 'it-pipe'
10
10
  import type { ContentRouting } from '@libp2p/interface-content-routing'
11
+ import type { PeerInfo } from '@libp2p/interface-peer-info'
12
+ import type { PeerStore } from '@libp2p/interface-peer-store'
11
13
  import type { AbortOptions } from '@libp2p/interfaces'
12
14
  import type { Startable } from '@libp2p/interfaces/startable'
13
15
  import type { CID } from 'multiformats/cid'
14
- import type { PeerStore } from '@libp2p/interface-peer-store'
15
- import type { PeerInfo } from '@libp2p/interface-peer-info'
16
16
 
17
17
  export interface CompoundContentRoutingInit {
18
18
  routers: ContentRouting[]
@@ -97,8 +97,8 @@ export class CompoundContentRouting implements ContentRouting, Startable {
97
97
  throw new CodeError(messages.NOT_STARTED_YET, codes.DHT_NOT_STARTED)
98
98
  }
99
99
 
100
- return await Promise.any(this.routers.map(async (router) => {
101
- return await router.get(key, options)
100
+ return Promise.any(this.routers.map(async (router) => {
101
+ return router.get(key, options)
102
102
  }))
103
103
  }
104
104
  }
@@ -1,9 +1,9 @@
1
1
  import { CodeError } from '@libp2p/interfaces/errors'
2
2
  import filter from 'it-filter'
3
3
  import map from 'it-map'
4
- import type { Source } from 'it-stream-types'
5
4
  import type { PeerInfo } from '@libp2p/interface-peer-info'
6
5
  import type { PeerStore } from '@libp2p/interface-peer-store'
6
+ import type { Source } from 'it-stream-types'
7
7
 
8
8
  /**
9
9
  * Store the multiaddrs from every peer in the passed peer store
@@ -1,21 +1,21 @@
1
- import { logger } from '@libp2p/logger'
1
+ import { setMaxListeners } from 'events'
2
2
  import { CodeError } from '@libp2p/interfaces/errors'
3
- import { codes } from '../errors.js'
4
- import * as lp from 'it-length-prefixed'
5
- import { FetchRequest, FetchResponse } from './pb/proto.js'
6
- import { PROTOCOL_NAME, PROTOCOL_VERSION } from './constants.js'
7
- import type { PeerId } from '@libp2p/interface-peer-id'
8
- import type { Startable } from '@libp2p/interfaces/startable'
9
- import type { Stream } from '@libp2p/interface-connection'
10
- import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
11
- import type { AbortOptions } from '@libp2p/interfaces'
3
+ import { logger } from '@libp2p/logger'
12
4
  import { abortableDuplex } from 'abortable-iterator'
13
- import { pipe } from 'it-pipe'
14
5
  import first from 'it-first'
15
- import { setMaxListeners } from 'events'
6
+ import * as lp from 'it-length-prefixed'
7
+ import { pipe } from 'it-pipe'
16
8
  import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
17
9
  import { toString as uint8arrayToString } from 'uint8arrays/to-string'
10
+ import { codes } from '../errors.js'
11
+ import { PROTOCOL_NAME, PROTOCOL_VERSION } from './constants.js'
12
+ import { FetchRequest, FetchResponse } from './pb/proto.js'
13
+ import type { Stream } from '@libp2p/interface-connection'
18
14
  import type { ConnectionManager } from '@libp2p/interface-connection-manager'
15
+ import type { PeerId } from '@libp2p/interface-peer-id'
16
+ import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
17
+ import type { AbortOptions } from '@libp2p/interfaces'
18
+ import type { Startable } from '@libp2p/interfaces/startable'
19
19
 
20
20
  const log = logger('libp2p:fetch')
21
21
 
package/src/get-peer.ts CHANGED
@@ -1,11 +1,11 @@
1
+ import { isPeerId } from '@libp2p/interface-peer-id'
2
+ import { CodeError } from '@libp2p/interfaces/errors'
3
+ import { logger } from '@libp2p/logger'
1
4
  import { peerIdFromString } from '@libp2p/peer-id'
2
- import type { Multiaddr } from '@multiformats/multiaddr'
3
5
  import { isMultiaddr } from '@multiformats/multiaddr'
4
- import { CodeError } from '@libp2p/interfaces/errors'
5
6
  import { codes } from './errors.js'
6
- import { isPeerId } from '@libp2p/interface-peer-id'
7
7
  import type { PeerId } from '@libp2p/interface-peer-id'
8
- import { logger } from '@libp2p/logger'
8
+ import type { Multiaddr } from '@multiformats/multiaddr'
9
9
 
10
10
  const log = logger('libp2p:get-peer')
11
11
 
@@ -1,12 +1,19 @@
1
- import { logger } from '@libp2p/logger'
1
+ import { setMaxListeners } from 'events'
2
2
  import { CodeError } from '@libp2p/interfaces/errors'
3
+ import { logger } from '@libp2p/logger'
4
+ import { peerIdFromKeys } from '@libp2p/peer-id'
5
+ import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
6
+ import { type Multiaddr, multiaddr, protocols } from '@multiformats/multiaddr'
7
+ import { abortableDuplex } from 'abortable-iterator'
8
+ import { anySignal } from 'any-signal'
9
+ import first from 'it-first'
3
10
  import * as lp from 'it-length-prefixed'
11
+ import { pbStream } from 'it-pb-stream'
4
12
  import { pipe } from 'it-pipe'
5
- import first from 'it-first'
6
13
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
7
- import { Multiaddr, multiaddr, protocols } from '@multiformats/multiaddr'
8
- import { Identify } from './pb/message.js'
9
- import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
14
+ import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
15
+ import { isNode, isBrowser, isWebWorker, isElectronMain, isElectronRenderer, isReactNative } from 'wherearewe'
16
+ import { codes } from '../errors.js'
10
17
  import {
11
18
  AGENT_VERSION,
12
19
  IDENTIFY_PROTOCOL_VERSION,
@@ -15,25 +22,18 @@ import {
15
22
  MULTICODEC_IDENTIFY_PROTOCOL_VERSION,
16
23
  MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION
17
24
  } from './consts.js'
18
- import { codes } from '../errors.js'
19
- import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
25
+ import { Identify } from './pb/message.js'
26
+ import type { IdentifyServiceComponents, IdentifyServiceInit } from './index.js'
27
+ import type { AddressManager } from '@libp2p/interface-address-manager'
20
28
  import type { Connection, Stream } from '@libp2p/interface-connection'
21
- import type { Startable } from '@libp2p/interfaces/startable'
22
- import { peerIdFromKeys } from '@libp2p/peer-id'
23
- import type { AbortOptions } from '@libp2p/interfaces'
24
- import { abortableDuplex } from 'abortable-iterator'
25
- import { setMaxListeners } from 'events'
26
29
  import type { ConnectionManager } from '@libp2p/interface-connection-manager'
30
+ import type { Libp2pEvents, IdentifyResult, SignedPeerRecord } from '@libp2p/interface-libp2p'
27
31
  import type { PeerId } from '@libp2p/interface-peer-id'
28
32
  import type { Peer, PeerStore } from '@libp2p/interface-peer-store'
29
- import type { AddressManager } from '@libp2p/interface-address-manager'
30
- import { anySignal } from 'any-signal'
31
- import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
32
- import { pbStream } from 'it-pb-stream'
33
- import { isNode, isBrowser, isWebWorker, isElectronMain, isElectronRenderer, isReactNative } from 'wherearewe'
34
- import type { IdentifyServiceComponents, IdentifyServiceInit } from './index.js'
35
- import type { Libp2pEvents, IdentifyResult, SignedPeerRecord } from '@libp2p/interface-libp2p'
33
+ import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
34
+ import type { AbortOptions } from '@libp2p/interfaces'
36
35
  import type { EventEmitter } from '@libp2p/interfaces/events'
36
+ import type { Startable } from '@libp2p/interfaces/startable'
37
37
 
38
38
  const log = logger('libp2p:identify')
39
39
 
@@ -277,7 +277,7 @@ export class DefaultIdentifyService implements Startable {
277
277
  (source) => lp.decode(source, {
278
278
  maxDataLength: this.maxIdentifyMessageSize ?? MAX_IDENTIFY_MESSAGE_SIZE
279
279
  }),
280
- async (source) => await first(source)
280
+ async (source) => first(source)
281
281
  )
282
282
 
283
283
  if (data == null) {
@@ -439,8 +439,9 @@ export class DefaultIdentifyService implements Startable {
439
439
  return
440
440
  }
441
441
 
442
- const envelope = await RecordEnvelope.openAndCertify(message.signedPeerRecord, PeerRecord.DOMAIN)
443
- const peerRecord = PeerRecord.createFromProtobuf(envelope.payload)
442
+ let peerRecordEnvelope = message.signedPeerRecord
443
+ const envelope = await RecordEnvelope.openAndCertify(peerRecordEnvelope, PeerRecord.DOMAIN)
444
+ let peerRecord = PeerRecord.createFromProtobuf(envelope.payload)
444
445
 
445
446
  // Verify peerId
446
447
  if (!peerRecord.peerId.equals(envelope.peerId)) {
@@ -463,7 +464,7 @@ export class DefaultIdentifyService implements Startable {
463
464
  }
464
465
 
465
466
  log('received signedPeerRecord in push from %p', remotePeer)
466
- let metadata = new Map()
467
+ const metadata = peer?.metadata ?? new Map()
467
468
 
468
469
  if (peer?.peerRecordEnvelope != null) {
469
470
  const storedEnvelope = await RecordEnvelope.createFromProtobuf(peer.peerRecordEnvelope)
@@ -472,9 +473,9 @@ export class DefaultIdentifyService implements Startable {
472
473
  // ensure seq is greater than, or equal to, the last received
473
474
  if (storedRecord.seqNumber >= peerRecord.seqNumber) {
474
475
  log('sequence number was lower or equal to existing sequence number - stored: %d received: %d', storedRecord.seqNumber, peerRecord.seqNumber)
476
+ peerRecord = storedRecord
477
+ peerRecordEnvelope = peer.peerRecordEnvelope
475
478
  }
476
-
477
- metadata = peer.metadata
478
479
  }
479
480
 
480
481
  if (message.agentVersion != null) {
@@ -486,7 +487,7 @@ export class DefaultIdentifyService implements Startable {
486
487
  }
487
488
 
488
489
  await this.peerStore.patch(peerRecord.peerId, {
489
- peerRecordEnvelope: message.signedPeerRecord,
490
+ peerRecordEnvelope,
490
491
  protocols: message.protocols,
491
492
  addresses: peerRecord.multiaddrs.map(multiaddr => ({
492
493
  isCertified: true,
@@ -1,16 +1,16 @@
1
- import { Identify } from './pb/message.js'
2
1
  import {
3
2
  MULTICODEC_IDENTIFY,
4
3
  MULTICODEC_IDENTIFY_PUSH
5
4
  } from './consts.js'
6
- import type { Registrar } from '@libp2p/interface-registrar'
5
+ import { DefaultIdentifyService } from './identify.js'
6
+ import { Identify } from './pb/message.js'
7
+ import type { AddressManager } from '@libp2p/interface-address-manager'
7
8
  import type { ConnectionManager } from '@libp2p/interface-connection-manager'
9
+ import type { Libp2pEvents } from '@libp2p/interface-libp2p'
8
10
  import type { PeerId } from '@libp2p/interface-peer-id'
9
11
  import type { PeerStore } from '@libp2p/interface-peer-store'
10
- import type { AddressManager } from '@libp2p/interface-address-manager'
12
+ import type { Registrar } from '@libp2p/interface-registrar'
11
13
  import type { EventEmitter } from '@libp2p/interfaces/events'
12
- import type { Libp2pEvents } from '@libp2p/interface-libp2p'
13
- import { DefaultIdentifyService } from './identify.js'
14
14
 
15
15
  export interface IdentifyServiceInit {
16
16
  /**
@@ -60,6 +60,6 @@ export const multicodecs = {
60
60
 
61
61
  export const Message = { Identify }
62
62
 
63
- export function identifyService (init: IdentifyServiceInit = {}): (components: IdentifyServiceComponents) => {} {
63
+ export function identifyService (init: IdentifyServiceInit = {}): (components: IdentifyServiceComponents) => DefaultIdentifyService {
64
64
  return (components) => new DefaultIdentifyService(components, init)
65
65
  }
package/src/index.ts CHANGED
@@ -15,25 +15,25 @@
15
15
  */
16
16
 
17
17
  import { createLibp2pNode } from './libp2p.js'
18
- import type { RecursivePartial } from '@libp2p/interfaces'
18
+ import type { AddressManagerInit } from './address-manager/index.js'
19
+ import type { Components } from './components.js'
20
+ import type { ConnectionManagerInit } from './connection-manager/index.js'
19
21
  import type { TransportManagerInit } from './transport-manager.js'
20
- import type { Datastore } from 'interface-datastore'
21
- import type { PeerId } from '@libp2p/interface-peer-id'
22
- import type { PeerDiscovery } from '@libp2p/interface-peer-discovery'
23
22
  import type { ConnectionProtector } from '@libp2p/interface-connection'
24
- import type { ConnectionGater } from '@libp2p/interface-connection-gater'
25
- import type { Transport } from '@libp2p/interface-transport'
26
- import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
27
23
  import type { ConnectionEncrypter } from '@libp2p/interface-connection-encrypter'
28
- import type { PeerRouting } from '@libp2p/interface-peer-routing'
24
+ import type { ConnectionGater } from '@libp2p/interface-connection-gater'
29
25
  import type { ContentRouting } from '@libp2p/interface-content-routing'
30
- import type { Metrics } from '@libp2p/interface-metrics'
31
- import type { Components } from './components.js'
32
26
  import type { Libp2p, ServiceMap } from '@libp2p/interface-libp2p'
27
+ import type { Metrics } from '@libp2p/interface-metrics'
28
+ import type { PeerDiscovery } from '@libp2p/interface-peer-discovery'
29
+ import type { PeerId } from '@libp2p/interface-peer-id'
30
+ import type { PeerRouting } from '@libp2p/interface-peer-routing'
31
+ import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
32
+ import type { Transport } from '@libp2p/interface-transport'
33
+ import type { RecursivePartial } from '@libp2p/interfaces'
33
34
  import type { KeyChainInit } from '@libp2p/keychain'
34
- import type { AddressManagerInit } from './address-manager/index.js'
35
- import type { ConnectionManagerInit } from './connection-manager/index.js'
36
35
  import type { PersistentPeerStoreInit } from '@libp2p/peer-store'
36
+ import type { Datastore } from 'interface-datastore'
37
37
 
38
38
  export type ServiceFactoryMap<T extends Record<string, unknown> = Record<string, unknown>> = {
39
39
  [Property in keyof T]: (components: Components) => T[Property]
@@ -42,7 +42,7 @@ export type ServiceFactoryMap<T extends Record<string, unknown> = Record<string,
42
42
  /**
43
43
  * For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
44
44
  */
45
- export interface Libp2pInit<T extends ServiceMap = {}> {
45
+ export interface Libp2pInit<T extends ServiceMap = { x: Record<string, unknown> }> {
46
46
  /**
47
47
  * peerId instance (it will be created if not provided)
48
48
  */
@@ -113,7 +113,7 @@ export interface Libp2pInit<T extends ServiceMap = {}> {
113
113
 
114
114
  export type { Libp2p }
115
115
 
116
- export type Libp2pOptions<T extends ServiceMap = {}> = RecursivePartial<Libp2pInit<T>> & { start?: boolean }
116
+ export type Libp2pOptions<T extends ServiceMap = Record<string, unknown>> = RecursivePartial<Libp2pInit<T>> & { start?: boolean }
117
117
 
118
118
  /**
119
119
  * Returns a new instance of the Libp2p interface, generating a new PeerId
@@ -141,7 +141,7 @@ export type Libp2pOptions<T extends ServiceMap = {}> = RecursivePartial<Libp2pIn
141
141
  * const libp2p = await createLibp2p(options)
142
142
  * ```
143
143
  */
144
- export async function createLibp2p <T extends ServiceMap = {}> (options: Libp2pOptions<T>): Promise<Libp2p<T>> {
144
+ export async function createLibp2p <T extends ServiceMap = { x: Record<string, unknown> }> (options: Libp2pOptions<T>): Promise<Libp2p<T>> {
145
145
  const node = await createLibp2pNode(options)
146
146
 
147
147
  if (options.start !== false) {
@@ -22,16 +22,16 @@
22
22
  * ```
23
23
  */
24
24
 
25
+ import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interface-connection-encrypter/errors'
25
26
  import { logger } from '@libp2p/logger'
27
+ import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
26
28
  import { handshake } from 'it-handshake'
27
29
  import * as lp from 'it-length-prefixed'
28
- import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interface-connection-encrypter/errors'
30
+ import map from 'it-map'
29
31
  import { Exchange, KeyType } from './pb/proto.js'
30
- import type { PeerId } from '@libp2p/interface-peer-id'
31
- import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
32
32
  import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter'
33
+ import type { PeerId } from '@libp2p/interface-peer-id'
33
34
  import type { Duplex, Source } from 'it-stream-types'
34
- import map from 'it-map'
35
35
  import type { Uint8ArrayList } from 'uint8arraylist'
36
36
 
37
37
  const log = logger('libp2p:plaintext')
@@ -125,11 +125,11 @@ class Plaintext implements ConnectionEncrypter {
125
125
  public protocol: string = PROTOCOL
126
126
 
127
127
  async secureInbound (localId: PeerId, conn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remoteId?: PeerId): Promise<SecuredConnection> {
128
- return await encrypt(localId, conn, remoteId)
128
+ return encrypt(localId, conn, remoteId)
129
129
  }
130
130
 
131
131
  async secureOutbound (localId: PeerId, conn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remoteId?: PeerId): Promise<SecuredConnection> {
132
- return await encrypt(localId, conn, remoteId)
132
+ return encrypt(localId, conn, remoteId)
133
133
  }
134
134
  }
135
135
 
package/src/libp2p.ts CHANGED
@@ -1,48 +1,48 @@
1
- import { logger } from '@libp2p/logger'
2
- import type { AbortOptions } from '@libp2p/interfaces'
1
+ import { setMaxListeners } from 'events'
2
+ import { unmarshalPublicKey } from '@libp2p/crypto/keys'
3
+ import { type ContentRouting, contentRouting } from '@libp2p/interface-content-routing'
4
+ import { peerDiscovery } from '@libp2p/interface-peer-discovery'
5
+ import { type PeerRouting, peerRouting } from '@libp2p/interface-peer-routing'
6
+ import { CodeError } from '@libp2p/interfaces/errors'
3
7
  import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
4
- import { isMultiaddr, Multiaddr } from '@multiformats/multiaddr'
8
+ import { DefaultKeyChain } from '@libp2p/keychain'
9
+ import { logger } from '@libp2p/logger'
10
+ import { PeerSet } from '@libp2p/peer-collections'
11
+ import { peerIdFromString } from '@libp2p/peer-id'
12
+ import { createEd25519PeerId } from '@libp2p/peer-id-factory'
13
+ import { PersistentPeerStore } from '@libp2p/peer-store'
14
+ import { isMultiaddr, type Multiaddr } from '@multiformats/multiaddr'
5
15
  import { MemoryDatastore } from 'datastore-core/memory'
6
- import { DefaultPeerRouting } from './peer-routing.js'
7
- import { CompoundContentRouting } from './content-routing/index.js'
8
- import { codes } from './errors.js'
16
+ import mergeOptions from 'merge-options'
17
+ import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
18
+ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
9
19
  import { DefaultAddressManager } from './address-manager/index.js'
20
+ import { defaultComponents } from './components.js'
21
+ import { connectionGater } from './config/connection-gater.js'
22
+ import { validateConfig } from './config.js'
10
23
  import { DefaultConnectionManager } from './connection-manager/index.js'
11
- import { DefaultKeyChain } from '@libp2p/keychain'
24
+ import { CompoundContentRouting } from './content-routing/index.js'
25
+ import { codes } from './errors.js'
26
+ import { DefaultPeerRouting } from './peer-routing.js'
27
+ import { DefaultRegistrar } from './registrar.js'
12
28
  import { DefaultTransportManager } from './transport-manager.js'
13
29
  import { DefaultUpgrader } from './upgrader.js'
14
- import { DefaultRegistrar } from './registrar.js'
15
- import { PersistentPeerStore } from '@libp2p/peer-store'
16
- import { defaultComponents } from './components.js'
17
30
  import type { Components } from './components.js'
18
- import type { PeerId } from '@libp2p/interface-peer-id'
19
- import type { Connection, Stream } from '@libp2p/interface-connection'
20
- import type { StreamHandler, StreamHandlerOptions, Topology } from '@libp2p/interface-registrar'
21
- import type { PeerInfo } from '@libp2p/interface-peer-info'
22
31
  import type { Libp2p, Libp2pInit, Libp2pOptions } from './index.js'
23
- import type { PeerStore } from '@libp2p/interface-peer-store'
24
- import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
25
- import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
26
- import { CodeError } from '@libp2p/interfaces/errors'
27
- import type { Metrics } from '@libp2p/interface-metrics'
28
- import { PeerSet } from '@libp2p/peer-collections'
32
+ import type { Connection, Stream } from '@libp2p/interface-connection'
29
33
  import type { KeyChain } from '@libp2p/interface-keychain'
30
34
  import type { Libp2pEvents, PendingDial, ServiceMap } from '@libp2p/interface-libp2p'
31
- import { setMaxListeners } from 'events'
32
- import { unmarshalPublicKey } from '@libp2p/crypto/keys'
33
- import { peerIdFromString } from '@libp2p/peer-id'
35
+ import type { Metrics } from '@libp2p/interface-metrics'
36
+ import type { PeerId } from '@libp2p/interface-peer-id'
37
+ import type { PeerInfo } from '@libp2p/interface-peer-info'
38
+ import type { PeerStore } from '@libp2p/interface-peer-store'
39
+ import type { StreamHandler, StreamHandlerOptions, Topology } from '@libp2p/interface-registrar'
40
+ import type { AbortOptions } from '@libp2p/interfaces'
34
41
  import type { Datastore } from 'interface-datastore'
35
- import mergeOptions from 'merge-options'
36
- import { createEd25519PeerId } from '@libp2p/peer-id-factory'
37
- import { validateConfig } from './config.js'
38
- import { ContentRouting, contentRouting } from '@libp2p/interface-content-routing'
39
- import { PeerRouting, peerRouting } from '@libp2p/interface-peer-routing'
40
- import { peerDiscovery } from '@libp2p/interface-peer-discovery'
41
- import { connectionGater } from './config/connection-gater.js'
42
42
 
43
43
  const log = logger('libp2p')
44
44
 
45
- export class Libp2pNode<T extends ServiceMap = {}> extends EventEmitter<Libp2pEvents> implements Libp2p<T> {
45
+ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends EventEmitter<Libp2pEvents> implements Libp2p<T> {
46
46
  public peerId: PeerId
47
47
  public peerStore: PeerStore
48
48
  public contentRouting: ContentRouting
@@ -277,7 +277,7 @@ export class Libp2pNode<T extends ServiceMap = {}> extends EventEmitter<Libp2pEv
277
277
  }
278
278
 
279
279
  async dial (peer: PeerId | Multiaddr | Multiaddr[], options: AbortOptions = {}): Promise<Connection> {
280
- return await this.components.connectionManager.openConnection(peer, options)
280
+ return this.components.connectionManager.openConnection(peer, options)
281
281
  }
282
282
 
283
283
  async dialProtocol (peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options: AbortOptions = {}): Promise<Stream> {
@@ -293,7 +293,7 @@ export class Libp2pNode<T extends ServiceMap = {}> extends EventEmitter<Libp2pEv
293
293
 
294
294
  const connection = await this.dial(peer, options)
295
295
 
296
- return await connection.newStream(protocols, options)
296
+ return connection.newStream(protocols, options)
297
297
  }
298
298
 
299
299
  getMultiaddrs (): Multiaddr[] {
@@ -370,7 +370,7 @@ export class Libp2pNode<T extends ServiceMap = {}> extends EventEmitter<Libp2pEv
370
370
  }
371
371
 
372
372
  async register (protocol: string, topology: Topology): Promise<string> {
373
- return await this.components.registrar.register(protocol, topology)
373
+ return this.components.registrar.register(protocol, topology)
374
374
  }
375
375
 
376
376
  unregister (id: string): void {
@@ -401,7 +401,7 @@ export class Libp2pNode<T extends ServiceMap = {}> extends EventEmitter<Libp2pEv
401
401
  * Returns a new Libp2pNode instance - this exposes more of the internals than the
402
402
  * libp2p interface and is useful for testing and debugging.
403
403
  */
404
- export async function createLibp2pNode <T extends ServiceMap = {}> (options: Libp2pOptions<T>): Promise<Libp2pNode<T>> {
404
+ export async function createLibp2pNode <T extends ServiceMap = Record<string, unknown>> (options: Libp2pOptions<T>): Promise<Libp2pNode<T>> {
405
405
  if (options.peerId == null) {
406
406
  const datastore = options.datastore as Datastore | undefined
407
407
 
@@ -1,20 +1,20 @@
1
- import { logger } from '@libp2p/logger'
2
1
  import { CodeError } from '@libp2p/interfaces/errors'
3
- import { codes, messages } from './errors.js'
2
+ import { logger } from '@libp2p/logger'
3
+ import filter from 'it-filter'
4
+ import first from 'it-first'
5
+ import merge from 'it-merge'
6
+ import { pipe } from 'it-pipe'
4
7
  import {
5
8
  storeAddresses,
6
9
  uniquePeers,
7
10
  requirePeers
8
11
  } from './content-routing/utils.js'
9
- import merge from 'it-merge'
10
- import { pipe } from 'it-pipe'
11
- import first from 'it-first'
12
- import filter from 'it-filter'
12
+ import { codes, messages } from './errors.js'
13
13
  import type { PeerId } from '@libp2p/interface-peer-id'
14
- import type { PeerRouting } from '@libp2p/interface-peer-routing'
15
- import type { AbortOptions } from '@libp2p/interfaces'
16
14
  import type { PeerInfo } from '@libp2p/interface-peer-info'
15
+ import type { PeerRouting } from '@libp2p/interface-peer-routing'
17
16
  import type { PeerStore } from '@libp2p/interface-peer-store'
17
+ import type { AbortOptions } from '@libp2p/interfaces'
18
18
 
19
19
  const log = logger('libp2p:peer-routing')
20
20
 
@@ -60,7 +60,7 @@ export class DefaultPeerRouting implements PeerRouting {
60
60
  ),
61
61
  (source) => filter(source, Boolean),
62
62
  (source) => storeAddresses(source, this.components.peerStore),
63
- async (source) => await first(source)
63
+ async (source) => first(source)
64
64
  )
65
65
 
66
66
  if (output != null) {