libp2p 0.45.0-752db6d6 → 0.45.0-e93d258d

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 +27 -30
  2. package/dist/index.min.js +26 -26
  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 +20 -14
  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 -81
  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/package.json +4 -5
  149. package/src/address-manager/index.ts +6 -6
  150. package/src/autonat/index.ts +14 -14
  151. package/src/circuit-relay/index.ts +1 -1
  152. package/src/circuit-relay/server/advert-service.ts +4 -4
  153. package/src/circuit-relay/server/index.ts +18 -18
  154. package/src/circuit-relay/server/reservation-store.ts +5 -5
  155. package/src/circuit-relay/server/reservation-voucher.ts +1 -1
  156. package/src/circuit-relay/transport/discovery.ts +7 -7
  157. package/src/circuit-relay/transport/index.ts +18 -23
  158. package/src/circuit-relay/transport/listener.ts +8 -8
  159. package/src/circuit-relay/transport/reservation-store.ts +10 -10
  160. package/src/circuit-relay/utils.ts +6 -6
  161. package/src/components.ts +6 -6
  162. package/src/config/connection-gater.browser.ts +1 -1
  163. package/src/config.ts +8 -12
  164. package/src/connection/index.ts +6 -10
  165. package/src/connection-manager/auto-dial.ts +5 -5
  166. package/src/connection-manager/connection-pruner.ts +4 -4
  167. package/src/connection-manager/dial-queue.ts +18 -17
  168. package/src/connection-manager/index.ts +18 -18
  169. package/src/connection-manager/utils.ts +4 -5
  170. package/src/content-routing/index.ts +6 -6
  171. package/src/content-routing/utils.ts +1 -1
  172. package/src/fetch/index.ts +12 -12
  173. package/src/get-peer.ts +4 -4
  174. package/src/identify/identify.ts +20 -20
  175. package/src/identify/index.ts +6 -6
  176. package/src/index.ts +15 -15
  177. package/src/insecure/index.ts +6 -6
  178. package/src/libp2p.ts +35 -35
  179. package/src/peer-routing.ts +9 -9
  180. package/src/ping/index.ts +12 -12
  181. package/src/pnet/crypto.ts +3 -3
  182. package/src/pnet/index.ts +6 -6
  183. package/src/pnet/key-generator.ts +1 -1
  184. package/src/pubsub/dummy-pubsub.ts +2 -2
  185. package/src/registrar.ts +5 -6
  186. package/src/transport-manager.ts +8 -8
  187. package/src/upgrader.ts +17 -17
  188. package/src/upnp-nat/index.ts +9 -9
  189. package/src/version.ts +1 -1
@@ -1,13 +1,13 @@
1
- import type { Multiaddr } from '@multiformats/multiaddr'
2
- import { multiaddr } from '@multiformats/multiaddr'
1
+ import { logger } from '@libp2p/logger'
3
2
  import { peerIdFromString } from '@libp2p/peer-id'
3
+ import { multiaddr } from '@multiformats/multiaddr'
4
+ import { debounce } from './utils.js'
5
+ import type { Libp2pEvents } from '@libp2p/interface-libp2p'
4
6
  import type { PeerId } from '@libp2p/interface-peer-id'
5
- import type { TransportManager } from '@libp2p/interface-transport'
6
7
  import type { PeerStore } from '@libp2p/interface-peer-store'
7
- import { logger } from '@libp2p/logger'
8
+ import type { TransportManager } from '@libp2p/interface-transport'
8
9
  import type { EventEmitter } from '@libp2p/interfaces/dist/src/events'
9
- import type { Libp2pEvents } from '@libp2p/interface-libp2p'
10
- import { debounce } from './utils.js'
10
+ import type { Multiaddr } from '@multiformats/multiaddr'
11
11
 
12
12
  const log = logger('libp2p:address-manager')
13
13
 
@@ -1,18 +1,10 @@
1
- import type { AddressManager } from '@libp2p/interface-address-manager'
2
- import type { Connection } from '@libp2p/interface-connection'
3
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
4
- import type { PeerId } from '@libp2p/interface-peer-id'
5
- import type { PeerInfo } from '@libp2p/interface-peer-info'
6
- import type { PeerRouting } from '@libp2p/interface-peer-routing'
7
- import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
8
- import type { TransportManager } from '@libp2p/interface-transport'
9
- import type { Startable } from '@libp2p/interfaces/startable'
1
+ import { setMaxListeners } from 'events'
10
2
  import { logger } from '@libp2p/logger'
11
3
  import { peerIdFromBytes } from '@libp2p/peer-id'
12
4
  import { createEd25519PeerId } from '@libp2p/peer-id-factory'
13
5
  import { multiaddr, protocols } from '@multiformats/multiaddr'
14
6
  import { abortableDuplex } from 'abortable-iterator'
15
- import { setMaxListeners } from 'events'
7
+ import { anySignal } from 'any-signal'
16
8
  import first from 'it-first'
17
9
  import * as lp from 'it-length-prefixed'
18
10
  import map from 'it-map'
@@ -25,7 +17,15 @@ import {
25
17
  PROTOCOL_NAME, PROTOCOL_PREFIX, PROTOCOL_VERSION, REFRESH_INTERVAL, STARTUP_DELAY, TIMEOUT
26
18
  } from './constants.js'
27
19
  import { Message } from './pb/index.js'
28
- import { anySignal } from 'any-signal'
20
+ import type { AddressManager } from '@libp2p/interface-address-manager'
21
+ import type { Connection } from '@libp2p/interface-connection'
22
+ import type { ConnectionManager } from '@libp2p/interface-connection-manager'
23
+ import type { PeerId } from '@libp2p/interface-peer-id'
24
+ import type { PeerInfo } from '@libp2p/interface-peer-info'
25
+ import type { PeerRouting } from '@libp2p/interface-peer-routing'
26
+ import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
27
+ import type { TransportManager } from '@libp2p/interface-transport'
28
+ import type { Startable } from '@libp2p/interfaces/startable'
29
29
 
30
30
  const log = logger('libp2p:autonat')
31
31
 
@@ -452,7 +452,7 @@ class DefaultAutoNATService implements Startable {
452
452
  (source) => lp.encode(source),
453
453
  source,
454
454
  (source) => lp.decode(source),
455
- async (stream) => await first(stream)
455
+ async (stream) => first(stream)
456
456
  )
457
457
  if (buf == null) {
458
458
  log('No response received from %s', connection.remotePeer)
@@ -497,7 +497,7 @@ class DefaultAutoNATService implements Startable {
497
497
 
498
498
  for await (const dialResponse of parallel(map(this.components.peerRouting.getClosestPeers(randomCid, {
499
499
  signal
500
- }), (peer) => async () => await verifyAddress(peer)), {
500
+ }), (peer) => async () => verifyAddress(peer)), {
501
501
  concurrency: REQUIRED_SUCCESSFUL_DIALS
502
502
  })) {
503
503
  try {
@@ -565,7 +565,7 @@ class DefaultAutoNATService implements Startable {
565
565
  }
566
566
  }
567
567
 
568
- export function autoNATService (init: AutoNATServiceInit = {}): (components: AutoNATComponents) => {} {
568
+ export function autoNATService (init: AutoNATServiceInit = {}): (components: AutoNATComponents) => unknown {
569
569
  return (components) => {
570
570
  return new DefaultAutoNATService(components, init)
571
571
  }
@@ -1,6 +1,6 @@
1
+ import type { Limit } from './pb/index.js'
1
2
  import type { EventEmitter } from '@libp2p/interfaces/events'
2
3
  import type { PeerMap } from '@libp2p/peer-collections'
3
- import type { Limit } from './pb/index.js'
4
4
  import type { Multiaddr } from '@multiformats/multiaddr'
5
5
 
6
6
  export interface RelayReservation {
@@ -1,14 +1,14 @@
1
+ import { EventEmitter } from '@libp2p/interfaces/events'
1
2
  import { logger } from '@libp2p/logger'
3
+ import pRetry from 'p-retry'
2
4
  import { codes } from '../../errors.js'
3
- import { namespaceToCid } from '../utils.js'
4
5
  import {
5
6
  DEFAULT_ADVERT_BOOT_DELAY,
6
7
  RELAY_RENDEZVOUS_NS
7
8
  } from '../constants.js'
8
- import type { Startable } from '@libp2p/interfaces/startable'
9
+ import { namespaceToCid } from '../utils.js'
9
10
  import type { ContentRouting } from '@libp2p/interface-content-routing'
10
- import { EventEmitter } from '@libp2p/interfaces/events'
11
- import pRetry from 'p-retry'
11
+ import type { Startable } from '@libp2p/interfaces/startable'
12
12
 
13
13
  const log = logger('libp2p:circuit-relay:advert-service')
14
14
 
@@ -1,31 +1,31 @@
1
+ import { setMaxListeners } from 'events'
2
+ import { EventEmitter } from '@libp2p/interfaces/events'
1
3
  import { logger } from '@libp2p/logger'
2
- import { createLimitedRelay } from '../utils.js'
4
+ import { peerIdFromBytes } from '@libp2p/peer-id'
5
+ import { RecordEnvelope } from '@libp2p/peer-record'
6
+ import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
7
+ import { pbStream, type ProtobufStream } from 'it-pb-stream'
8
+ import pDefer from 'p-defer'
3
9
  import {
4
10
  CIRCUIT_PROTO_CODE,
5
11
  DEFAULT_HOP_TIMEOUT,
6
12
  RELAY_SOURCE_TAG
7
13
  , RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC
8
14
  } from '../constants.js'
9
- import type { PeerStore } from '@libp2p/interface-peer-store'
10
- import type { Startable } from '@libp2p/interfaces/startable'
11
- import { ReservationStore, ReservationStoreInit } from './reservation-store.js'
12
- import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
13
- import { AdvertService, AdvertServiceComponents, AdvertServiceInit } from './advert-service.js'
14
- import pDefer from 'p-defer'
15
- import { pbStream, ProtobufStream } from 'it-pb-stream'
16
- import { HopMessage, Reservation, Status, StopMessage } from '../pb/index.js'
17
- import { Multiaddr, multiaddr } from '@multiformats/multiaddr'
18
- import type { Connection, Stream } from '@libp2p/interface-connection'
19
- import type { ConnectionGater } from '@libp2p/interface-connection-gater'
20
- import { peerIdFromBytes } from '@libp2p/peer-id'
21
- import type { PeerId } from '@libp2p/interface-peer-id'
22
- import { RecordEnvelope } from '@libp2p/peer-record'
15
+ import { HopMessage, type Reservation, Status, StopMessage } from '../pb/index.js'
16
+ import { createLimitedRelay } from '../utils.js'
17
+ import { AdvertService, type AdvertServiceComponents, type AdvertServiceInit } from './advert-service.js'
18
+ import { ReservationStore, type ReservationStoreInit } from './reservation-store.js'
23
19
  import { ReservationVoucherRecord } from './reservation-voucher.js'
20
+ import type { CircuitRelayService, RelayReservation } from '../index.js'
24
21
  import type { AddressManager } from '@libp2p/interface-address-manager'
22
+ import type { Connection, Stream } from '@libp2p/interface-connection'
23
+ import type { ConnectionGater } from '@libp2p/interface-connection-gater'
25
24
  import type { ConnectionManager } from '@libp2p/interface-connection-manager'
26
- import type { CircuitRelayService, RelayReservation } from '../index.js'
27
- import { EventEmitter } from '@libp2p/interfaces/events'
28
- import { setMaxListeners } from 'events'
25
+ import type { PeerId } from '@libp2p/interface-peer-id'
26
+ import type { PeerStore } from '@libp2p/interface-peer-store'
27
+ import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
28
+ import type { Startable } from '@libp2p/interfaces/startable'
29
29
  import type { PeerMap } from '@libp2p/peer-collections'
30
30
 
31
31
  const log = logger('libp2p:circuit-relay:server')
@@ -1,11 +1,11 @@
1
- import { Limit, Status } from '../pb/index.js'
2
- import type { Multiaddr } from '@multiformats/multiaddr'
3
- import type { PeerId } from '@libp2p/interface-peer-id'
4
- import type { Startable } from '@libp2p/interfaces/startable'
5
1
  import { PeerMap } from '@libp2p/peer-collections'
6
- import type { RecursivePartial } from '@libp2p/interfaces'
7
2
  import { DEFAULT_DATA_LIMIT, DEFAULT_DURATION_LIMIT, DEFAULT_MAX_RESERVATION_CLEAR_INTERVAL, DEFAULT_MAX_RESERVATION_STORE_SIZE, DEFAULT_MAX_RESERVATION_TTL } from '../constants.js'
3
+ import { type Limit, Status } from '../pb/index.js'
8
4
  import type { RelayReservation } from '../index.js'
5
+ import type { PeerId } from '@libp2p/interface-peer-id'
6
+ import type { RecursivePartial } from '@libp2p/interfaces'
7
+ import type { Startable } from '@libp2p/interfaces/startable'
8
+ import type { Multiaddr } from '@multiformats/multiaddr'
9
9
 
10
10
  export type ReservationStatus = Status.OK | Status.PERMISSION_DENIED | Status.RESERVATION_REFUSED
11
11
 
@@ -1,6 +1,6 @@
1
+ import { ReservationVoucher } from '../pb/index.js'
1
2
  import type { PeerId } from '@libp2p/interface-peer-id'
2
3
  import type { Record } from '@libp2p/interface-record'
3
- import { ReservationVoucher } from '../pb/index.js'
4
4
 
5
5
  export interface ReservationVoucherOptions {
6
6
  relay: PeerId
@@ -1,18 +1,18 @@
1
+ import { EventEmitter } from '@libp2p/interfaces/events'
1
2
  import { logger } from '@libp2p/logger'
2
- import { namespaceToCid } from '../utils.js'
3
+ import { createTopology } from '@libp2p/topology'
3
4
  import {
4
5
  RELAY_RENDEZVOUS_NS,
5
6
  RELAY_V2_HOP_CODEC
6
7
  } from '../constants.js'
7
- import type { PeerId } from '@libp2p/interface-peer-id'
8
- import type { PeerStore } from '@libp2p/interface-peer-store'
9
- import { EventEmitter } from '@libp2p/interfaces/events'
10
- import type { Startable } from '@libp2p/interfaces/startable'
8
+ import { namespaceToCid } from '../utils.js'
11
9
  import type { ConnectionManager } from '@libp2p/interface-connection-manager'
12
- import type { TransportManager } from '@libp2p/interface-transport'
13
10
  import type { ContentRouting } from '@libp2p/interface-content-routing'
11
+ import type { PeerId } from '@libp2p/interface-peer-id'
12
+ import type { PeerStore } from '@libp2p/interface-peer-store'
14
13
  import type { Registrar } from '@libp2p/interface-registrar'
15
- import { createTopology } from '@libp2p/topology'
14
+ import type { TransportManager } from '@libp2p/interface-transport'
15
+ import type { Startable } from '@libp2p/interfaces/startable'
16
16
 
17
17
  const log = logger('libp2p:circuit-relay:discover-relays')
18
18
 
@@ -1,30 +1,29 @@
1
- import { StopMessage, HopMessage, Status } from '../pb/index.js'
1
+ import { symbol, type Upgrader, type Listener, type Transport, type CreateListenerOptions } from '@libp2p/interface-transport'
2
+ import { CodeError } from '@libp2p/interfaces/errors'
2
3
  import { logger } from '@libp2p/logger'
4
+ import { peerIdFromBytes, peerIdFromString } from '@libp2p/peer-id'
5
+ import { streamToMaConnection } from '@libp2p/utils/stream-to-ma-conn'
3
6
  import * as mafmt from '@multiformats/mafmt'
4
7
  import { multiaddr } from '@multiformats/multiaddr'
8
+ import { pbStream } from 'it-pb-stream'
5
9
  import { codes } from '../../errors.js'
6
- import { streamToMaConnection } from '@libp2p/utils/stream-to-ma-conn'
10
+ import { CIRCUIT_PROTO_CODE, RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from '../constants.js'
11
+ import { StopMessage, HopMessage, Status } from '../pb/index.js'
12
+ import { RelayDiscovery, type RelayDiscoveryComponents } from './discovery.js'
7
13
  import { createListener } from './listener.js'
8
- import { symbol, Upgrader } from '@libp2p/interface-transport'
9
- import { peerIdFromBytes, peerIdFromString } from '@libp2p/peer-id'
10
- import type { AbortOptions } from '@libp2p/interfaces'
11
- import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
12
- import type { Listener, Transport, CreateListenerOptions } from '@libp2p/interface-transport'
14
+ import { type RelayStoreInit, ReservationStore } from './reservation-store.js'
15
+ import type { AddressManager } from '@libp2p/interface-address-manager'
13
16
  import type { Connection, Stream } from '@libp2p/interface-connection'
14
17
  import type { ConnectionGater } from '@libp2p/interface-connection-gater'
15
- import type { PeerId } from '@libp2p/interface-peer-id'
16
- import type { Multiaddr } from '@multiformats/multiaddr'
17
- import type { PeerStore } from '@libp2p/interface-peer-store'
18
18
  import type { ConnectionManager } from '@libp2p/interface-connection-manager'
19
- import type { AddressManager } from '@libp2p/interface-address-manager'
20
- import { pbStream } from 'it-pb-stream'
21
19
  import type { ContentRouting } from '@libp2p/interface-content-routing'
22
- import { CIRCUIT_PROTO_CODE, RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from '../constants.js'
23
- import { RelayStoreInit, ReservationStore } from './reservation-store.js'
24
- import { RelayDiscovery, RelayDiscoveryComponents } from './discovery.js'
25
- import { CodeError } from '@libp2p/interfaces/errors'
26
- import type { EventEmitter } from '@libp2p/interfaces/events'
27
20
  import type { Libp2pEvents } from '@libp2p/interface-libp2p'
21
+ import type { PeerId } from '@libp2p/interface-peer-id'
22
+ import type { PeerStore } from '@libp2p/interface-peer-store'
23
+ import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
24
+ import type { AbortOptions } from '@libp2p/interfaces'
25
+ import type { EventEmitter } from '@libp2p/interfaces/events'
26
+ import type { Multiaddr } from '@multiformats/multiaddr'
28
27
 
29
28
  const log = logger('libp2p:circuit-relay:transport')
30
29
 
@@ -142,13 +141,9 @@ class CircuitRelayTransport implements Transport {
142
141
  this.started = false
143
142
  }
144
143
 
145
- get [symbol] (): true {
146
- return true
147
- }
144
+ readonly [symbol] = true
148
145
 
149
- get [Symbol.toStringTag] (): 'libp2p/circuit-relay-v2' {
150
- return 'libp2p/circuit-relay-v2'
151
- }
146
+ readonly [Symbol.toStringTag] = 'libp2p/circuit-relay-v2'
152
147
 
153
148
  /**
154
149
  * Dial a peer over a relay
@@ -1,15 +1,15 @@
1
+ import { CodeError } from '@libp2p/interfaces/errors'
1
2
  import { EventEmitter } from '@libp2p/interfaces/events'
2
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
3
- import type { Listener, ListenerEvents } from '@libp2p/interface-transport'
4
- import type { Multiaddr } from '@multiformats/multiaddr'
5
- import { multiaddr } from '@multiformats/multiaddr'
6
- import type { ReservationStore } from './reservation-store.js'
7
- import type { PeerId } from '@libp2p/interface-peer-id'
8
- import { PeerMap } from '@libp2p/peer-collections'
9
3
  import { logger } from '@libp2p/logger'
4
+ import { PeerMap } from '@libp2p/peer-collections'
10
5
  import { peerIdFromString } from '@libp2p/peer-id'
6
+ import { multiaddr } from '@multiformats/multiaddr'
7
+ import type { ReservationStore } from './reservation-store.js'
11
8
  import type { Connection } from '@libp2p/interface-connection'
12
- import { CodeError } from '@libp2p/interfaces/errors'
9
+ import type { ConnectionManager } from '@libp2p/interface-connection-manager'
10
+ import type { PeerId } from '@libp2p/interface-peer-id'
11
+ import type { Listener, ListenerEvents } from '@libp2p/interface-transport'
12
+ import type { Multiaddr } from '@multiformats/multiaddr'
13
13
 
14
14
  const log = logger('libp2p:circuit-relay:transport:listener')
15
15
 
@@ -1,20 +1,20 @@
1
- import type { PeerId } from '@libp2p/interface-peer-id'
1
+ import { EventEmitter } from '@libp2p/interfaces/events'
2
+ import { logger } from '@libp2p/logger'
2
3
  import { PeerMap } from '@libp2p/peer-collections'
4
+ import { multiaddr } from '@multiformats/multiaddr'
5
+ import { pbStream } from 'it-pb-stream'
3
6
  import PQueue from 'p-queue'
4
7
  import { DEFAULT_RESERVATION_CONCURRENCY, RELAY_TAG, RELAY_V2_HOP_CODEC } from '../constants.js'
5
- import { logger } from '@libp2p/logger'
6
- import { pbStream } from 'it-pb-stream'
7
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
8
- import type { Connection } from '@libp2p/interface-connection'
9
- import type { Reservation } from '../pb/index.js'
10
8
  import { HopMessage, Status } from '../pb/index.js'
11
9
  import { getExpirationMilliseconds } from '../utils.js'
10
+ import type { Reservation } from '../pb/index.js'
11
+ import type { Connection } from '@libp2p/interface-connection'
12
+ import type { ConnectionManager } from '@libp2p/interface-connection-manager'
13
+ import type { Libp2pEvents } from '@libp2p/interface-libp2p'
14
+ import type { PeerId } from '@libp2p/interface-peer-id'
15
+ import type { PeerStore } from '@libp2p/interface-peer-store'
12
16
  import type { TransportManager } from '@libp2p/interface-transport'
13
17
  import type { Startable } from '@libp2p/interfaces/startable'
14
- import { EventEmitter } from '@libp2p/interfaces/events'
15
- import type { PeerStore } from '@libp2p/interface-peer-store'
16
- import { multiaddr } from '@multiformats/multiaddr'
17
- import type { Libp2pEvents } from '@libp2p/interface-libp2p'
18
18
 
19
19
  const log = logger('libp2p:circuit-relay:transport:reservation-store')
20
20
 
@@ -1,13 +1,13 @@
1
+ import { logger } from '@libp2p/logger'
2
+ import { abortableSource } from 'abortable-iterator'
3
+ import { anySignal } from 'any-signal'
1
4
  import { CID } from 'multiformats/cid'
2
5
  import { sha256 } from 'multiformats/hashes/sha2'
3
- import type { Source } from 'it-stream-types'
4
- import type { Uint8ArrayList } from 'uint8arraylist'
6
+ import { DEFAULT_DATA_LIMIT, DEFAULT_DURATION_LIMIT } from './constants.js'
5
7
  import type { Limit } from './pb/index.js'
6
- import { logger } from '@libp2p/logger'
7
8
  import type { Stream } from '@libp2p/interface-connection'
8
- import { DEFAULT_DATA_LIMIT, DEFAULT_DURATION_LIMIT } from './constants.js'
9
- import { abortableSource } from 'abortable-iterator'
10
- import { anySignal } from 'any-signal'
9
+ import type { Source } from 'it-stream-types'
10
+ import type { Uint8ArrayList } from 'uint8arraylist'
11
11
 
12
12
  const log = logger('libp2p:circuit-relay:utils')
13
13
 
package/src/components.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  import { CodeError } from '@libp2p/interfaces/errors'
2
+ import { isStartable, type Startable } from '@libp2p/interfaces/startable'
3
+ import type { AddressManager } from '@libp2p/interface-address-manager'
2
4
  import type { ConnectionProtector } from '@libp2p/interface-connection'
5
+ import type { ConnectionGater } from '@libp2p/interface-connection-gater'
6
+ import type { ConnectionManager } from '@libp2p/interface-connection-manager'
3
7
  import type { ContentRouting } from '@libp2p/interface-content-routing'
4
- import type { AddressManager } from '@libp2p/interface-address-manager'
5
- import { isStartable, Startable } from '@libp2p/interfaces/startable'
8
+ import type { Libp2pEvents } from '@libp2p/interface-libp2p'
6
9
  import type { Metrics } from '@libp2p/interface-metrics'
7
10
  import type { PeerId } from '@libp2p/interface-peer-id'
8
11
  import type { PeerRouting } from '@libp2p/interface-peer-routing'
9
12
  import type { PeerStore } from '@libp2p/interface-peer-store'
10
13
  import type { Registrar } from '@libp2p/interface-registrar'
11
14
  import type { TransportManager, Upgrader } from '@libp2p/interface-transport'
12
- import type { Datastore } from 'interface-datastore'
13
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
14
- import type { ConnectionGater } from '@libp2p/interface-connection-gater'
15
- import type { Libp2pEvents } from '@libp2p/interface-libp2p'
16
15
  import type { EventEmitter } from '@libp2p/interfaces/events'
16
+ import type { Datastore } from 'interface-datastore'
17
17
 
18
18
  export interface Components extends Record<string, any>, Startable {
19
19
  peerId: PeerId
@@ -1,6 +1,6 @@
1
+ import isPrivate from 'private-ip'
1
2
  import type { ConnectionGater } from '@libp2p/interface-connection-gater'
2
3
  import type { Multiaddr } from '@multiformats/multiaddr'
3
- import isPrivate from 'private-ip'
4
4
 
5
5
  /**
6
6
  * Returns a connection gater that disallows dialling private addresses by
package/src/config.ts CHANGED
@@ -1,13 +1,13 @@
1
- import mergeOptions from 'merge-options'
2
- import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'
3
- import { publicAddressesFirst } from '@libp2p/utils/address-sort'
4
1
  import { FaultTolerance } from '@libp2p/interface-transport'
5
- import type { Multiaddr } from '@multiformats/multiaddr'
6
- import type { Libp2pInit } from './index.js'
7
- import { codes, messages } from './errors.js'
8
2
  import { CodeError } from '@libp2p/interfaces/errors'
9
- import type { RecursivePartial } from '@libp2p/interfaces'
3
+ import { publicAddressesFirst } from '@libp2p/utils/address-sort'
4
+ import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'
5
+ import mergeOptions from 'merge-options'
6
+ import { codes, messages } from './errors.js'
7
+ import type { Libp2pInit } from './index.js'
10
8
  import type { ServiceMap } from '@libp2p/interface-libp2p'
9
+ import type { RecursivePartial } from '@libp2p/interfaces'
10
+ import type { Multiaddr } from '@multiformats/multiaddr'
11
11
 
12
12
  const DefaultConfig: Partial<Libp2pInit> = {
13
13
  addresses: {
@@ -27,17 +27,13 @@ const DefaultConfig: Partial<Libp2pInit> = {
27
27
  }
28
28
  }
29
29
 
30
- export function validateConfig <T extends ServiceMap = {}> (opts: RecursivePartial<Libp2pInit<T>>): Libp2pInit<T> {
30
+ export function validateConfig <T extends ServiceMap = Record<string, unknown>> (opts: RecursivePartial<Libp2pInit<T>>): Libp2pInit<T> {
31
31
  const resultingOptions: Libp2pInit<T> = mergeOptions(DefaultConfig, opts)
32
32
 
33
33
  if (resultingOptions.transports == null || resultingOptions.transports.length < 1) {
34
34
  throw new CodeError(messages.ERR_TRANSPORTS_REQUIRED, codes.ERR_TRANSPORTS_REQUIRED)
35
35
  }
36
36
 
37
- if (resultingOptions.connectionEncryption == null || resultingOptions.connectionEncryption.length === 0) {
38
- throw new CodeError(messages.CONN_ENCRYPTION_REQUIRED, codes.CONN_ENCRYPTION_REQUIRED)
39
- }
40
-
41
37
  if (resultingOptions.connectionProtector === null && globalThis.process?.env?.LIBP2P_FORCE_PNET != null) { // eslint-disable-line no-undef
42
38
  throw new CodeError(messages.ERR_PROTECTOR_REQUIRED, codes.ERR_PROTECTOR_REQUIRED)
43
39
  }
@@ -1,11 +1,11 @@
1
- import type { Multiaddr } from '@multiformats/multiaddr'
2
- import { CodeError } from '@libp2p/interfaces/errors'
3
- import { OPEN, CLOSING, CLOSED } from '@libp2p/interface-connection/status'
4
1
  import { symbol } from '@libp2p/interface-connection'
2
+ import { OPEN, CLOSING, CLOSED } from '@libp2p/interface-connection/status'
3
+ import { CodeError } from '@libp2p/interfaces/errors'
4
+ import { logger } from '@libp2p/logger'
5
5
  import type { Connection, ConnectionStat, Stream } from '@libp2p/interface-connection'
6
6
  import type { PeerId } from '@libp2p/interface-peer-id'
7
- import { logger } from '@libp2p/logger'
8
7
  import type { AbortOptions } from '@libp2p/interfaces'
8
+ import type { Multiaddr } from '@multiformats/multiaddr'
9
9
 
10
10
  const log = logger('libp2p:connection')
11
11
 
@@ -87,13 +87,9 @@ export class ConnectionImpl implements Connection {
87
87
  this._closing = false
88
88
  }
89
89
 
90
- get [Symbol.toStringTag] (): 'Connection' {
91
- return 'Connection'
92
- }
90
+ readonly [Symbol.toStringTag] = 'Connection'
93
91
 
94
- get [symbol] (): true {
95
- return true
96
- }
92
+ readonly [symbol] = true
97
93
 
98
94
  /**
99
95
  * Get all the streams of the muxer
@@ -1,12 +1,12 @@
1
1
  import { logger } from '@libp2p/logger'
2
- import type { PeerStore } from '@libp2p/interface-peer-store'
3
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
4
2
  import { PeerMap, PeerSet } from '@libp2p/peer-collections'
5
3
  import PQueue from 'p-queue'
6
4
  import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_INTERVAL, AUTO_DIAL_PRIORITY, MIN_CONNECTIONS } from './constants.js'
7
- import type { Startable } from '@libp2p/interfaces/startable'
8
- import type { EventEmitter } from '@libp2p/interfaces/events'
5
+ import type { ConnectionManager } from '@libp2p/interface-connection-manager'
9
6
  import type { Libp2pEvents } from '@libp2p/interface-libp2p'
7
+ import type { PeerStore } from '@libp2p/interface-peer-store'
8
+ import type { EventEmitter } from '@libp2p/interfaces/events'
9
+ import type { Startable } from '@libp2p/interfaces/startable'
10
10
 
11
11
  const log = logger('libp2p:connection-manager:auto-dial')
12
12
 
@@ -112,7 +112,7 @@ export class AutoDial implements Startable {
112
112
 
113
113
  // Already has enough connections
114
114
  if (numConnections >= this.minConnections) {
115
- log('have enough connections %d/%d', numConnections, this.minConnections)
115
+ log.trace('have enough connections %d/%d', numConnections, this.minConnections)
116
116
  return
117
117
  }
118
118
 
@@ -1,11 +1,11 @@
1
1
  import { logger } from '@libp2p/logger'
2
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
3
- import type { PeerStore } from '@libp2p/interface-peer-store'
4
2
  import { PeerMap } from '@libp2p/peer-collections'
5
- import type { Multiaddr } from '@multiformats/multiaddr'
6
3
  import { MAX_CONNECTIONS } from './constants.js'
7
- import type { EventEmitter } from '@libp2p/interfaces/events'
4
+ import type { ConnectionManager } from '@libp2p/interface-connection-manager'
8
5
  import type { Libp2pEvents } from '@libp2p/interface-libp2p'
6
+ import type { PeerStore } from '@libp2p/interface-peer-store'
7
+ import type { EventEmitter } from '@libp2p/interfaces/events'
8
+ import type { Multiaddr } from '@multiformats/multiaddr'
9
9
 
10
10
  const log = logger('libp2p:connection-manager:connection-pruner')
11
11
 
@@ -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