libp2p 0.45.8 → 0.45.9-06f4901a

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 (173) hide show
  1. package/README.md +96 -77
  2. package/dist/index.min.js +28 -28
  3. package/dist/src/address-manager/index.d.ts +5 -5
  4. package/dist/src/address-manager/index.d.ts.map +1 -1
  5. package/dist/src/autonat/index.d.ts +6 -6
  6. package/dist/src/autonat/index.d.ts.map +1 -1
  7. package/dist/src/autonat/index.js +3 -3
  8. package/dist/src/circuit-relay/index.d.ts +1 -1
  9. package/dist/src/circuit-relay/index.d.ts.map +1 -1
  10. package/dist/src/circuit-relay/server/advert-service.d.ts +3 -3
  11. package/dist/src/circuit-relay/server/advert-service.d.ts.map +1 -1
  12. package/dist/src/circuit-relay/server/advert-service.js +1 -1
  13. package/dist/src/circuit-relay/server/advert-service.js.map +1 -1
  14. package/dist/src/circuit-relay/server/index.d.ts +12 -7
  15. package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
  16. package/dist/src/circuit-relay/server/index.js +18 -10
  17. package/dist/src/circuit-relay/server/index.js.map +1 -1
  18. package/dist/src/circuit-relay/server/reservation-store.d.ts +3 -3
  19. package/dist/src/circuit-relay/server/reservation-store.d.ts.map +1 -1
  20. package/dist/src/circuit-relay/server/reservation-voucher.d.ts +2 -2
  21. package/dist/src/circuit-relay/transport/discovery.d.ts +8 -8
  22. package/dist/src/circuit-relay/transport/discovery.d.ts.map +1 -1
  23. package/dist/src/circuit-relay/transport/discovery.js +3 -4
  24. package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
  25. package/dist/src/circuit-relay/transport/index.d.ts +12 -12
  26. package/dist/src/circuit-relay/transport/index.d.ts.map +1 -1
  27. package/dist/src/circuit-relay/transport/index.js +10 -9
  28. package/dist/src/circuit-relay/transport/index.js.map +1 -1
  29. package/dist/src/circuit-relay/transport/listener.d.ts +2 -2
  30. package/dist/src/circuit-relay/transport/listener.d.ts.map +1 -1
  31. package/dist/src/circuit-relay/transport/listener.js +3 -3
  32. package/dist/src/circuit-relay/transport/listener.js.map +1 -1
  33. package/dist/src/circuit-relay/transport/reservation-store.d.ts +7 -7
  34. package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
  35. package/dist/src/circuit-relay/transport/reservation-store.js +2 -2
  36. package/dist/src/circuit-relay/transport/reservation-store.js.map +1 -1
  37. package/dist/src/circuit-relay/utils.d.ts +1 -1
  38. package/dist/src/components.d.ts +15 -14
  39. package/dist/src/components.d.ts.map +1 -1
  40. package/dist/src/components.js +2 -2
  41. package/dist/src/components.js.map +1 -1
  42. package/dist/src/config/connection-gater.browser.d.ts +1 -1
  43. package/dist/src/config/connection-gater.d.ts +1 -1
  44. package/dist/src/config.d.ts +1 -2
  45. package/dist/src/config.d.ts.map +1 -1
  46. package/dist/src/config.js +2 -2
  47. package/dist/src/config.js.map +1 -1
  48. package/dist/src/connection/index.d.ts +4 -4
  49. package/dist/src/connection/index.d.ts.map +1 -1
  50. package/dist/src/connection/index.js +3 -3
  51. package/dist/src/connection/index.js.map +1 -1
  52. package/dist/src/connection-manager/auto-dial.d.ts +5 -5
  53. package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
  54. package/dist/src/connection-manager/connection-pruner.d.ts +4 -4
  55. package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
  56. package/dist/src/connection-manager/dial-queue.d.ts +7 -8
  57. package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
  58. package/dist/src/connection-manager/dial-queue.js +6 -6
  59. package/dist/src/connection-manager/dial-queue.js.map +1 -1
  60. package/dist/src/connection-manager/index.d.ts +10 -11
  61. package/dist/src/connection-manager/index.d.ts.map +1 -1
  62. package/dist/src/connection-manager/index.js +6 -6
  63. package/dist/src/connection-manager/index.js.map +1 -1
  64. package/dist/src/content-routing/index.d.ts +5 -5
  65. package/dist/src/content-routing/index.d.ts.map +1 -1
  66. package/dist/src/content-routing/index.js +1 -1
  67. package/dist/src/content-routing/index.js.map +1 -1
  68. package/dist/src/content-routing/utils.d.ts +2 -2
  69. package/dist/src/content-routing/utils.js +1 -1
  70. package/dist/src/content-routing/utils.js.map +1 -1
  71. package/dist/src/fetch/index.d.ts +5 -5
  72. package/dist/src/fetch/index.d.ts.map +1 -1
  73. package/dist/src/fetch/index.js +1 -1
  74. package/dist/src/fetch/index.js.map +1 -1
  75. package/dist/src/get-peer.d.ts +1 -1
  76. package/dist/src/get-peer.js +2 -2
  77. package/dist/src/get-peer.js.map +1 -1
  78. package/dist/src/identify/identify.d.ts +7 -7
  79. package/dist/src/identify/identify.d.ts.map +1 -1
  80. package/dist/src/identify/identify.js +13 -9
  81. package/dist/src/identify/identify.js.map +1 -1
  82. package/dist/src/identify/index.d.ts +24 -9
  83. package/dist/src/identify/index.d.ts.map +1 -1
  84. package/dist/src/identify/index.js.map +1 -1
  85. package/dist/src/index.d.ts +11 -12
  86. package/dist/src/index.d.ts.map +1 -1
  87. package/dist/src/index.js.map +1 -1
  88. package/dist/src/insecure/index.d.ts +1 -1
  89. package/dist/src/insecure/index.js +1 -1
  90. package/dist/src/insecure/index.js.map +1 -1
  91. package/dist/src/libp2p.d.ts +11 -11
  92. package/dist/src/libp2p.d.ts.map +1 -1
  93. package/dist/src/libp2p.js +5 -5
  94. package/dist/src/libp2p.js.map +1 -1
  95. package/dist/src/peer-routing.d.ts +5 -5
  96. package/dist/src/peer-routing.d.ts.map +1 -1
  97. package/dist/src/peer-routing.js +1 -1
  98. package/dist/src/peer-routing.js.map +1 -1
  99. package/dist/src/ping/index.d.ts +4 -4
  100. package/dist/src/ping/index.d.ts.map +1 -1
  101. package/dist/src/ping/index.js +1 -1
  102. package/dist/src/ping/index.js.map +1 -1
  103. package/dist/src/pnet/index.d.ts +1 -1
  104. package/dist/src/pnet/index.js +1 -1
  105. package/dist/src/pnet/index.js.map +1 -1
  106. package/dist/src/registrar.d.ts +7 -6
  107. package/dist/src/registrar.d.ts.map +1 -1
  108. package/dist/src/registrar.js +7 -11
  109. package/dist/src/registrar.js.map +1 -1
  110. package/dist/src/transport-manager.d.ts +9 -9
  111. package/dist/src/transport-manager.d.ts.map +1 -1
  112. package/dist/src/transport-manager.js +4 -4
  113. package/dist/src/transport-manager.js.map +1 -1
  114. package/dist/src/upgrader.d.ts +12 -12
  115. package/dist/src/upgrader.d.ts.map +1 -1
  116. package/dist/src/upgrader.js +8 -6
  117. package/dist/src/upgrader.js.map +1 -1
  118. package/dist/src/upnp-nat/index.d.ts +4 -4
  119. package/dist/src/upnp-nat/index.d.ts.map +1 -1
  120. package/dist/src/upnp-nat/index.js +1 -1
  121. package/dist/src/upnp-nat/index.js.map +1 -1
  122. package/dist/src/utils/peer-job-queue.d.ts +1 -1
  123. package/dist/src/utils/peer-job-queue.js +1 -1
  124. package/dist/src/utils/peer-job-queue.js.map +1 -1
  125. package/dist/src/version.d.ts +1 -1
  126. package/dist/src/version.d.ts.map +1 -1
  127. package/dist/src/version.js +1 -1
  128. package/dist/src/version.js.map +1 -1
  129. package/package.json +45 -74
  130. package/src/address-manager/index.ts +5 -5
  131. package/src/autonat/index.ts +12 -12
  132. package/src/circuit-relay/index.ts +1 -1
  133. package/src/circuit-relay/server/advert-service.ts +3 -3
  134. package/src/circuit-relay/server/index.ts +33 -18
  135. package/src/circuit-relay/server/reservation-store.ts +3 -3
  136. package/src/circuit-relay/server/reservation-voucher.ts +2 -2
  137. package/src/circuit-relay/transport/discovery.ts +10 -11
  138. package/src/circuit-relay/transport/index.ts +22 -22
  139. package/src/circuit-relay/transport/listener.ts +7 -7
  140. package/src/circuit-relay/transport/reservation-store.ts +9 -9
  141. package/src/circuit-relay/utils.ts +1 -1
  142. package/src/components.ts +16 -15
  143. package/src/config/connection-gater.browser.ts +1 -1
  144. package/src/config/connection-gater.ts +1 -1
  145. package/src/config.ts +3 -4
  146. package/src/connection/index.ts +6 -6
  147. package/src/connection-manager/auto-dial.ts +5 -5
  148. package/src/connection-manager/connection-pruner.ts +4 -4
  149. package/src/connection-manager/dial-queue.ts +13 -14
  150. package/src/connection-manager/index.ts +16 -17
  151. package/src/content-routing/index.ts +6 -6
  152. package/src/content-routing/utils.ts +3 -3
  153. package/src/fetch/index.ts +7 -7
  154. package/src/get-peer.ts +3 -3
  155. package/src/identify/identify.ts +26 -22
  156. package/src/identify/index.ts +27 -8
  157. package/src/index.ts +11 -12
  158. package/src/insecure/index.ts +3 -3
  159. package/src/libp2p.ts +14 -14
  160. package/src/peer-routing.ts +6 -6
  161. package/src/ping/index.ts +7 -7
  162. package/src/pnet/index.ts +2 -2
  163. package/src/registrar.ts +14 -17
  164. package/src/transport-manager.ts +12 -12
  165. package/src/upgrader.ts +22 -20
  166. package/src/upnp-nat/index.ts +5 -5
  167. package/src/utils/peer-job-queue.ts +2 -2
  168. package/src/version.ts +1 -1
  169. package/dist/src/pubsub/dummy-pubsub.d.ts +0 -18
  170. package/dist/src/pubsub/dummy-pubsub.d.ts.map +0 -1
  171. package/dist/src/pubsub/dummy-pubsub.js +0 -38
  172. package/dist/src/pubsub/dummy-pubsub.js.map +0 -1
  173. package/src/pubsub/dummy-pubsub.ts +0 -53
@@ -1,5 +1,5 @@
1
- import { KEEP_ALIVE } from '@libp2p/interface-peer-store/tags'
2
- import { CodeError } from '@libp2p/interfaces/errors'
1
+ import { CodeError } from '@libp2p/interface/errors'
2
+ import { KEEP_ALIVE } from '@libp2p/interface/peer-store/tags'
3
3
  import { logger } from '@libp2p/logger'
4
4
  import { PeerMap } from '@libp2p/peer-collections'
5
5
  import { publicAddressesFirst } from '@libp2p/utils/address-sort'
@@ -12,17 +12,16 @@ import { AutoDial } from './auto-dial.js'
12
12
  import { ConnectionPruner } from './connection-pruner.js'
13
13
  import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_MAX_QUEUE_LENGTH, 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'
14
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'
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 { Peer, 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'
15
+ import type { PendingDial, AddressSorter, Libp2pEvents, AbortOptions } from '@libp2p/interface'
16
+ import type { Connection, MultiaddrConnection } from '@libp2p/interface/connection'
17
+ import type { ConnectionGater } from '@libp2p/interface/connection-gater'
18
+ import type { EventEmitter } from '@libp2p/interface/events'
19
+ import type { Metrics } from '@libp2p/interface/metrics'
20
+ import type { PeerId } from '@libp2p/interface/peer-id'
21
+ import type { Peer, PeerStore } from '@libp2p/interface/peer-store'
22
+ import type { Startable } from '@libp2p/interface/startable'
23
+ import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
24
+ import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
26
25
 
27
26
  const log = logger('libp2p:connection-manager')
28
27
 
@@ -548,7 +547,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
548
547
  })
549
548
 
550
549
  if (denyConnection) {
551
- log('connection from %s refused - connection remote address was in deny list', maConn.remoteAddr)
550
+ log('connection from %a refused - connection remote address was in deny list', maConn.remoteAddr)
552
551
  return false
553
552
  }
554
553
 
@@ -565,7 +564,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
565
564
 
566
565
  // check pending connections
567
566
  if (this.incomingPendingConnections === this.maxIncomingPendingConnections) {
568
- log('connection from %s refused - incomingPendingConnections exceeded by peer %s', maConn.remoteAddr)
567
+ log('connection from %a refused - incomingPendingConnections exceeded by host', maConn.remoteAddr)
569
568
  return false
570
569
  }
571
570
 
@@ -575,7 +574,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
575
574
  try {
576
575
  await this.inboundConnectionRateLimiter.consume(host, 1)
577
576
  } catch {
578
- log('connection from %s refused - inboundConnectionThreshold exceeded by host %s', host, maConn.remoteAddr)
577
+ log('connection from %a refused - inboundConnectionThreshold exceeded by host %s', maConn.remoteAddr, host)
579
578
  return false
580
579
  }
581
580
  }
@@ -586,7 +585,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
586
585
  return true
587
586
  }
588
587
 
589
- log('connection from %s refused - maxConnections exceeded', maConn.remoteAddr)
588
+ log('connection from %a refused - maxConnections exceeded', maConn.remoteAddr)
590
589
  return false
591
590
  }
592
591
 
@@ -1,4 +1,4 @@
1
- import { CodeError } from '@libp2p/interfaces/errors'
1
+ import { CodeError } from '@libp2p/interface/errors'
2
2
  import merge from 'it-merge'
3
3
  import { pipe } from 'it-pipe'
4
4
  import { messages, codes } from '../errors.js'
@@ -7,11 +7,11 @@ import {
7
7
  uniquePeers,
8
8
  requirePeers
9
9
  } from './utils.js'
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'
13
- import type { AbortOptions } from '@libp2p/interfaces'
14
- import type { Startable } from '@libp2p/interfaces/startable'
10
+ import type { AbortOptions } from '@libp2p/interface'
11
+ import type { ContentRouting } from '@libp2p/interface/content-routing'
12
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
13
+ import type { PeerStore } from '@libp2p/interface/peer-store'
14
+ import type { Startable } from '@libp2p/interface/startable'
15
15
  import type { CID } from 'multiformats/cid'
16
16
 
17
17
  export interface CompoundContentRoutingInit {
@@ -1,8 +1,8 @@
1
- import { CodeError } from '@libp2p/interfaces/errors'
1
+ import { CodeError } from '@libp2p/interface/errors'
2
2
  import filter from 'it-filter'
3
3
  import map from 'it-map'
4
- import type { PeerInfo } from '@libp2p/interface-peer-info'
5
- import type { PeerStore } from '@libp2p/interface-peer-store'
4
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
5
+ import type { PeerStore } from '@libp2p/interface/peer-store'
6
6
  import type { Source } from 'it-stream-types'
7
7
 
8
8
  /**
@@ -1,5 +1,5 @@
1
1
  import { setMaxListeners } from 'events'
2
- import { CodeError } from '@libp2p/interfaces/errors'
2
+ import { CodeError } from '@libp2p/interface/errors'
3
3
  import { logger } from '@libp2p/logger'
4
4
  import { abortableDuplex } from 'abortable-iterator'
5
5
  import first from 'it-first'
@@ -10,12 +10,12 @@ import { toString as uint8arrayToString } from 'uint8arrays/to-string'
10
10
  import { codes } from '../errors.js'
11
11
  import { PROTOCOL_NAME, PROTOCOL_VERSION } from './constants.js'
12
12
  import { FetchRequest, FetchResponse } from './pb/proto.js'
13
- import type { Stream } from '@libp2p/interface-connection'
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'
13
+ import type { AbortOptions } from '@libp2p/interface'
14
+ import type { Stream } from '@libp2p/interface/connection'
15
+ import type { PeerId } from '@libp2p/interface/peer-id'
16
+ import type { Startable } from '@libp2p/interface/startable'
17
+ import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
18
+ import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/registrar'
19
19
 
20
20
  const log = logger('libp2p:fetch')
21
21
 
package/src/get-peer.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { isPeerId } from '@libp2p/interface-peer-id'
2
- import { CodeError } from '@libp2p/interfaces/errors'
1
+ import { CodeError } from '@libp2p/interface/errors'
2
+ import { isPeerId } from '@libp2p/interface/peer-id'
3
3
  import { logger } from '@libp2p/logger'
4
4
  import { peerIdFromString } from '@libp2p/peer-id'
5
5
  import { isMultiaddr } from '@multiformats/multiaddr'
6
6
  import { codes } from './errors.js'
7
- import type { PeerId } from '@libp2p/interface-peer-id'
7
+ import type { PeerId } from '@libp2p/interface/peer-id'
8
8
  import type { Multiaddr } from '@multiformats/multiaddr'
9
9
 
10
10
  const log = logger('libp2p:get-peer')
@@ -1,5 +1,5 @@
1
1
  import { setMaxListeners } from 'events'
2
- import { CodeError } from '@libp2p/interfaces/errors'
2
+ import { CodeError } from '@libp2p/interface/errors'
3
3
  import { logger } from '@libp2p/logger'
4
4
  import { peerIdFromKeys } from '@libp2p/peer-id'
5
5
  import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
@@ -23,17 +23,16 @@ import {
23
23
  MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION
24
24
  } from './consts.js'
25
25
  import { Identify } from './pb/message.js'
26
- import type { IdentifyServiceComponents, IdentifyServiceInit } from './index.js'
27
- import type { AddressManager } from '@libp2p/interface-address-manager'
28
- import type { Connection, Stream } from '@libp2p/interface-connection'
29
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
30
- import type { Libp2pEvents, IdentifyResult, SignedPeerRecord } from '@libp2p/interface-libp2p'
31
- import type { PeerId } from '@libp2p/interface-peer-id'
32
- import type { Peer, PeerStore } from '@libp2p/interface-peer-store'
33
- import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
34
- import type { AbortOptions } from '@libp2p/interfaces'
35
- import type { EventEmitter } from '@libp2p/interfaces/events'
36
- import type { Startable } from '@libp2p/interfaces/startable'
26
+ import type { IdentifyService, IdentifyServiceComponents, IdentifyServiceInit } from './index.js'
27
+ import type { Libp2pEvents, IdentifyResult, SignedPeerRecord, AbortOptions } from '@libp2p/interface'
28
+ import type { Connection, Stream } from '@libp2p/interface/connection'
29
+ import type { EventEmitter } from '@libp2p/interface/events'
30
+ import type { PeerId } from '@libp2p/interface/peer-id'
31
+ import type { Peer, PeerStore } from '@libp2p/interface/peer-store'
32
+ import type { Startable } from '@libp2p/interface/startable'
33
+ import type { AddressManager } from '@libp2p/interface-internal/address-manager'
34
+ import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
35
+ import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/registrar'
37
36
 
38
37
  const log = logger('libp2p:identify')
39
38
 
@@ -50,10 +49,11 @@ const defaultValues = {
50
49
  maxPushIncomingStreams: 1,
51
50
  maxPushOutgoingStreams: 1,
52
51
  maxObservedAddresses: 10,
53
- maxIdentifyMessageSize: 8192
52
+ maxIdentifyMessageSize: 8192,
53
+ runOnConnectionOpen: true
54
54
  }
55
55
 
56
- export class DefaultIdentifyService implements Startable {
56
+ export class DefaultIdentifyService implements Startable, IdentifyService {
57
57
  private readonly identifyProtocolStr: string
58
58
  private readonly identifyPushProtocolStr: string
59
59
  public readonly host: {
@@ -101,11 +101,13 @@ export class DefaultIdentifyService implements Startable {
101
101
  agentVersion: init.agentVersion ?? defaultValues.agentVersion
102
102
  }
103
103
 
104
- // When a new connection happens, trigger identify
105
- components.events.addEventListener('connection:open', (evt) => {
106
- const connection = evt.detail
107
- this.identify(connection).catch(err => { log.error('error during identify trigged by connection:open', err) })
108
- })
104
+ if (init.runOnConnectionOpen ?? defaultValues.runOnConnectionOpen) {
105
+ // When a new connection happens, trigger identify
106
+ components.events.addEventListener('connection:open', (evt) => {
107
+ const connection = evt.detail
108
+ this.identify(connection).catch(err => { log.error('error during identify trigged by connection:open', err) })
109
+ })
110
+ }
109
111
 
110
112
  // When self peer record changes, trigger identify-push
111
113
  components.events.addEventListener('self:peer:update', (evt) => {
@@ -297,7 +299,7 @@ export class DefaultIdentifyService implements Startable {
297
299
  }
298
300
  }
299
301
 
300
- async identify (connection: Connection, options: AbortOptions = {}): Promise<void> {
302
+ async identify (connection: Connection, options: AbortOptions = {}): Promise<IdentifyResult> {
301
303
  const message = await this._identify(connection, options)
302
304
  const {
303
305
  publicKey,
@@ -323,11 +325,11 @@ export class DefaultIdentifyService implements Startable {
323
325
  const cleanObservedAddr = getCleanMultiaddr(observedAddr)
324
326
 
325
327
  log('identify completed for peer %p and protocols %o', id, protocols)
326
- log('our observed address is %s', cleanObservedAddr)
328
+ log('our observed address is %a', cleanObservedAddr)
327
329
 
328
330
  if (cleanObservedAddr != null &&
329
331
  this.addressManager.getObservedAddrs().length < (this.maxObservedAddresses ?? Infinity)) {
330
- log('storing our observed address %s', cleanObservedAddr?.toString())
332
+ log('storing our observed address %a', cleanObservedAddr)
331
333
  this.addressManager.addObservedAddr(cleanObservedAddr)
332
334
  }
333
335
 
@@ -345,6 +347,8 @@ export class DefaultIdentifyService implements Startable {
345
347
  }
346
348
 
347
349
  this.events.safeDispatchEvent('peer:identify', { detail: result })
350
+
351
+ return result
348
352
  }
349
353
 
350
354
  /**
@@ -4,13 +4,14 @@ import {
4
4
  } from './consts.js'
5
5
  import { DefaultIdentifyService } from './identify.js'
6
6
  import { Identify } from './pb/message.js'
7
- import type { AddressManager } from '@libp2p/interface-address-manager'
8
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
9
- import type { Libp2pEvents } from '@libp2p/interface-libp2p'
10
- import type { PeerId } from '@libp2p/interface-peer-id'
11
- import type { PeerStore } from '@libp2p/interface-peer-store'
12
- import type { Registrar } from '@libp2p/interface-registrar'
13
- import type { EventEmitter } from '@libp2p/interfaces/events'
7
+ import type { AbortOptions, IdentifyResult, Libp2pEvents } from '@libp2p/interface'
8
+ import type { EventEmitter } from '@libp2p/interface/events'
9
+ import type { PeerId } from '@libp2p/interface/peer-id'
10
+ import type { PeerStore } from '@libp2p/interface/peer-store'
11
+ import type { Connection } from '@libp2p/interface/src/connection/index.js'
12
+ import type { AddressManager } from '@libp2p/interface-internal/address-manager'
13
+ import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
14
+ import type { Registrar } from '@libp2p/interface-internal/registrar'
14
15
 
15
16
  export interface IdentifyServiceInit {
16
17
  /**
@@ -39,6 +40,11 @@ export interface IdentifyServiceInit {
39
40
  maxPushIncomingStreams?: number
40
41
  maxPushOutgoingStreams?: number
41
42
  maxObservedAddresses?: number
43
+
44
+ /**
45
+ * Whether to automatically dial identify on newly opened connections (default: true)
46
+ */
47
+ runOnConnectionOpen?: boolean
42
48
  }
43
49
 
44
50
  export interface IdentifyServiceComponents {
@@ -60,6 +66,19 @@ export const multicodecs = {
60
66
 
61
67
  export const Message = { Identify }
62
68
 
63
- export function identifyService (init: IdentifyServiceInit = {}): (components: IdentifyServiceComponents) => DefaultIdentifyService {
69
+ export interface IdentifyService {
70
+ /**
71
+ * due to the default limits on inbound/outbound streams for this protocol,
72
+ * invoking this method when runOnConnectionOpen is true can lead to unpredictable results
73
+ * as streams may be closed by the local or the remote node.
74
+ * Please use with caution. If you find yourself needing to call this method to discover other peers that support your protocol,
75
+ * you may be better off configuring a topology to be notified instead.
76
+ */
77
+ identify: (connection: Connection, options?: AbortOptions) => Promise<IdentifyResult>
78
+
79
+ push: () => Promise<void>
80
+ }
81
+
82
+ export function identifyService (init: IdentifyServiceInit = {}): (components: IdentifyServiceComponents) => IdentifyService {
64
83
  return (components) => new DefaultIdentifyService(components, init)
65
84
  }
package/src/index.ts CHANGED
@@ -19,18 +19,17 @@ import type { AddressManagerInit } from './address-manager/index.js'
19
19
  import type { Components } from './components.js'
20
20
  import type { ConnectionManagerInit } from './connection-manager/index.js'
21
21
  import type { TransportManagerInit } from './transport-manager.js'
22
- import type { ConnectionProtector } from '@libp2p/interface-connection'
23
- import type { ConnectionEncrypter } from '@libp2p/interface-connection-encrypter'
24
- import type { ConnectionGater } from '@libp2p/interface-connection-gater'
25
- import type { ContentRouting } from '@libp2p/interface-content-routing'
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'
22
+ import type { Libp2p, ServiceMap, RecursivePartial } from '@libp2p/interface'
23
+ import type { ConnectionProtector } from '@libp2p/interface/connection'
24
+ import type { ConnectionEncrypter } from '@libp2p/interface/connection-encrypter'
25
+ import type { ConnectionGater } from '@libp2p/interface/connection-gater'
26
+ import type { ContentRouting } from '@libp2p/interface/content-routing'
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'
34
33
  import type { KeyChainInit } from '@libp2p/keychain'
35
34
  import type { PersistentPeerStoreInit } from '@libp2p/peer-store'
36
35
  import type { Datastore } from 'interface-datastore'
@@ -22,15 +22,15 @@
22
22
  * ```
23
23
  */
24
24
 
25
- import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interface-connection-encrypter/errors'
25
+ import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interface/errors'
26
26
  import { logger } from '@libp2p/logger'
27
27
  import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
28
28
  import { handshake } from 'it-handshake'
29
29
  import * as lp from 'it-length-prefixed'
30
30
  import map from 'it-map'
31
31
  import { Exchange, KeyType } from './pb/proto.js'
32
- import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter'
33
- import type { PeerId } from '@libp2p/interface-peer-id'
32
+ import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface/connection-encrypter'
33
+ import type { PeerId } from '@libp2p/interface/peer-id'
34
34
  import type { Duplex, Source } from 'it-stream-types'
35
35
  import type { Uint8ArrayList } from 'uint8arraylist'
36
36
 
package/src/libp2p.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { setMaxListeners } from 'events'
2
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'
7
- import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
3
+ import { type ContentRouting, contentRouting } from '@libp2p/interface/content-routing'
4
+ import { CodeError } from '@libp2p/interface/errors'
5
+ import { EventEmitter, CustomEvent } from '@libp2p/interface/events'
6
+ import { peerDiscovery } from '@libp2p/interface/peer-discovery'
7
+ import { type PeerRouting, peerRouting } from '@libp2p/interface/peer-routing'
8
8
  import { DefaultKeyChain } from '@libp2p/keychain'
9
9
  import { logger } from '@libp2p/logger'
10
10
  import { PeerSet } from '@libp2p/peer-collections'
@@ -29,15 +29,15 @@ import { DefaultTransportManager } from './transport-manager.js'
29
29
  import { DefaultUpgrader } from './upgrader.js'
30
30
  import type { Components } from './components.js'
31
31
  import type { Libp2p, Libp2pInit, Libp2pOptions } from './index.js'
32
- import type { Connection, Stream } from '@libp2p/interface-connection'
33
- import type { KeyChain } from '@libp2p/interface-keychain'
34
- import type { Libp2pEvents, PendingDial, ServiceMap } from '@libp2p/interface-libp2p'
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'
32
+ import type { Libp2pEvents, PendingDial, ServiceMap, AbortOptions } from '@libp2p/interface'
33
+ import type { Connection, Stream } from '@libp2p/interface/connection'
34
+ import type { KeyChain } from '@libp2p/interface/keychain'
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 { Topology } from '@libp2p/interface/topology'
40
+ import type { StreamHandler, StreamHandlerOptions } from '@libp2p/interface-internal/registrar'
41
41
  import type { Datastore } from 'interface-datastore'
42
42
 
43
43
  const log = logger('libp2p')
@@ -1,4 +1,4 @@
1
- import { CodeError } from '@libp2p/interfaces/errors'
1
+ import { CodeError } from '@libp2p/interface/errors'
2
2
  import { logger } from '@libp2p/logger'
3
3
  import filter from 'it-filter'
4
4
  import first from 'it-first'
@@ -10,11 +10,11 @@ import {
10
10
  requirePeers
11
11
  } from './content-routing/utils.js'
12
12
  import { codes, messages } from './errors.js'
13
- import type { PeerId } from '@libp2p/interface-peer-id'
14
- import type { PeerInfo } from '@libp2p/interface-peer-info'
15
- import type { PeerRouting } from '@libp2p/interface-peer-routing'
16
- import type { PeerStore } from '@libp2p/interface-peer-store'
17
- import type { AbortOptions } from '@libp2p/interfaces'
13
+ import type { AbortOptions } from '@libp2p/interface'
14
+ import type { PeerId } from '@libp2p/interface/peer-id'
15
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
16
+ import type { PeerRouting } from '@libp2p/interface/peer-routing'
17
+ import type { PeerStore } from '@libp2p/interface/peer-store'
18
18
 
19
19
  const log = logger('libp2p:peer-routing')
20
20
 
package/src/ping/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { setMaxListeners } from 'events'
2
2
  import { randomBytes } from '@libp2p/crypto'
3
- import { CodeError } from '@libp2p/interfaces/errors'
3
+ import { CodeError } from '@libp2p/interface/errors'
4
4
  import { logger } from '@libp2p/logger'
5
5
  import { abortableDuplex } from 'abortable-iterator'
6
6
  import { anySignal } from 'any-signal'
@@ -9,12 +9,12 @@ import { pipe } from 'it-pipe'
9
9
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
10
10
  import { codes } from '../errors.js'
11
11
  import { PROTOCOL_PREFIX, PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION, TIMEOUT, MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS } from './constants.js'
12
- import type { Stream } from '@libp2p/interface-connection'
13
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
14
- import type { PeerId } from '@libp2p/interface-peer-id'
15
- import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
16
- import type { AbortOptions } from '@libp2p/interfaces'
17
- import type { Startable } from '@libp2p/interfaces/startable'
12
+ import type { AbortOptions } from '@libp2p/interface'
13
+ import type { Stream } from '@libp2p/interface/connection'
14
+ import type { PeerId } from '@libp2p/interface/peer-id'
15
+ import type { Startable } from '@libp2p/interface/startable'
16
+ import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
17
+ import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/registrar'
18
18
  import type { Multiaddr } from '@multiformats/multiaddr'
19
19
 
20
20
  const log = logger('libp2p:ping')
package/src/pnet/index.ts CHANGED
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  import { randomBytes } from '@libp2p/crypto'
26
- import { CodeError } from '@libp2p/interfaces/errors'
26
+ import { CodeError } from '@libp2p/interface/errors'
27
27
  import { logger } from '@libp2p/logger'
28
28
  import { handshake } from 'it-handshake'
29
29
  import map from 'it-map'
@@ -37,7 +37,7 @@ import {
37
37
  } from './crypto.js'
38
38
  import * as Errors from './errors.js'
39
39
  import { NONCE_LENGTH } from './key-generator.js'
40
- import type { ConnectionProtector, MultiaddrConnection } from '@libp2p/interface-connection'
40
+ import type { ConnectionProtector, MultiaddrConnection } from '@libp2p/interface/connection'
41
41
 
42
42
  const log = logger('libp2p:pnet')
43
43
 
package/src/registrar.ts CHANGED
@@ -1,13 +1,14 @@
1
- import { isTopology, type StreamHandlerOptions, type StreamHandlerRecord, type Registrar, type StreamHandler, type Topology } from '@libp2p/interface-registrar'
2
- import { CodeError } from '@libp2p/interfaces/errors'
1
+ import { CodeError } from '@libp2p/interface/errors'
3
2
  import { logger } from '@libp2p/logger'
4
3
  import merge from 'merge-options'
5
4
  import { codes } from './errors.js'
6
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
7
- import type { Libp2pEvents, PeerUpdate } from '@libp2p/interface-libp2p'
8
- import type { PeerId } from '@libp2p/interface-peer-id'
9
- import type { PeerStore } from '@libp2p/interface-peer-store'
10
- import type { EventEmitter } from '@libp2p/interfaces/events'
5
+ import type { Libp2pEvents, PeerUpdate } from '@libp2p/interface'
6
+ import type { EventEmitter } from '@libp2p/interface/events'
7
+ import type { PeerId } from '@libp2p/interface/peer-id'
8
+ import type { PeerStore } from '@libp2p/interface/peer-store'
9
+ import type { Topology } from '@libp2p/interface/topology'
10
+ import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
11
+ import type { StreamHandlerOptions, StreamHandlerRecord, Registrar, StreamHandler } from '@libp2p/interface-internal/registrar'
11
12
 
12
13
  const log = logger('libp2p:registrar')
13
14
 
@@ -116,9 +117,8 @@ export class DefaultRegistrar implements Registrar {
116
117
  * Register handlers for a set of multicodecs given
117
118
  */
118
119
  async register (protocol: string, topology: Topology): Promise<string> {
119
- if (!isTopology(topology)) {
120
- log.error('topology must be an instance of interfaces/topology')
121
- throw new CodeError('topology must be an instance of interfaces/topology', codes.ERR_INVALID_PARAMETERS)
120
+ if (topology == null) {
121
+ throw new CodeError('invalid topology', codes.ERR_INVALID_PARAMETERS)
122
122
  }
123
123
 
124
124
  // Create topology
@@ -133,9 +133,6 @@ export class DefaultRegistrar implements Registrar {
133
133
 
134
134
  topologies.set(id, topology)
135
135
 
136
- // Set registrar
137
- await topology.setRegistrar(this)
138
-
139
136
  return id
140
137
  }
141
138
 
@@ -171,7 +168,7 @@ export class DefaultRegistrar implements Registrar {
171
168
  }
172
169
 
173
170
  for (const topology of topologies.values()) {
174
- topology.onDisconnect(remotePeer)
171
+ topology.onDisconnect?.(remotePeer)
175
172
  }
176
173
  }
177
174
  })
@@ -211,7 +208,7 @@ export class DefaultRegistrar implements Registrar {
211
208
  }
212
209
 
213
210
  for (const topology of topologies.values()) {
214
- topology.onConnect(remotePeer, connection)
211
+ topology.onConnect?.(remotePeer, connection)
215
212
  }
216
213
  }
217
214
  })
@@ -242,7 +239,7 @@ export class DefaultRegistrar implements Registrar {
242
239
  }
243
240
 
244
241
  for (const topology of topologies.values()) {
245
- topology.onDisconnect(peer.id)
242
+ topology.onDisconnect?.(peer.id)
246
243
  }
247
244
  }
248
245
 
@@ -260,7 +257,7 @@ export class DefaultRegistrar implements Registrar {
260
257
  if (connection == null) {
261
258
  continue
262
259
  }
263
- topology.onConnect(peer.id, connection)
260
+ topology.onConnect?.(peer.id, connection)
264
261
  }
265
262
  }
266
263
  }
@@ -1,16 +1,16 @@
1
- import { FaultTolerance } from '@libp2p/interface-transport'
2
- import { CodeError } from '@libp2p/interfaces/errors'
1
+ import { CodeError } from '@libp2p/interface/errors'
2
+ import { trackedMap } from '@libp2p/interface/metrics/tracked-map'
3
+ import { FaultTolerance } from '@libp2p/interface/transport'
3
4
  import { logger } from '@libp2p/logger'
4
- import { trackedMap } from '@libp2p/tracked-map'
5
5
  import { codes } from './errors.js'
6
- import type { AddressManager } from '@libp2p/interface-address-manager'
7
- import type { Connection } from '@libp2p/interface-connection'
8
- import type { Libp2pEvents } from '@libp2p/interface-libp2p'
9
- import type { Metrics } from '@libp2p/interface-metrics'
10
- import type { Listener, Transport, TransportManager, Upgrader } from '@libp2p/interface-transport'
11
- import type { AbortOptions } from '@libp2p/interfaces'
12
- import type { EventEmitter } from '@libp2p/interfaces/events'
13
- import type { Startable } from '@libp2p/interfaces/startable'
6
+ import type { Libp2pEvents, AbortOptions } from '@libp2p/interface'
7
+ import type { Connection } from '@libp2p/interface/connection'
8
+ import type { EventEmitter } from '@libp2p/interface/events'
9
+ import type { Metrics } from '@libp2p/interface/metrics'
10
+ import type { Startable } from '@libp2p/interface/startable'
11
+ import type { Listener, Transport, Upgrader } from '@libp2p/interface/transport'
12
+ import type { AddressManager } from '@libp2p/interface-internal/address-manager'
13
+ import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
14
14
  import type { Multiaddr } from '@multiformats/multiaddr'
15
15
 
16
16
  const log = logger('libp2p:transports')
@@ -190,7 +190,7 @@ export class DefaultTransportManager implements TransportManager, Startable {
190
190
 
191
191
  // For each supported multiaddr, create a listener
192
192
  for (const addr of supportedAddrs) {
193
- log('creating listener for %s on %s', key, addr)
193
+ log('creating listener for %s on %a', key, addr)
194
194
  const listener = transport.createListener({
195
195
  upgrader: this.components.upgrader
196
196
  })