libp2p 0.45.9-d853d124 → 0.45.9-e9cafd3d
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.
- package/README.md +96 -77
- package/dist/index.min.js +28 -28
- package/dist/src/address-manager/index.d.ts +5 -5
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/autonat/index.d.ts +6 -6
- package/dist/src/autonat/index.d.ts.map +1 -1
- package/dist/src/autonat/index.js +3 -3
- package/dist/src/circuit-relay/index.d.ts +1 -1
- package/dist/src/circuit-relay/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.d.ts +3 -3
- package/dist/src/circuit-relay/server/advert-service.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.js +1 -1
- package/dist/src/circuit-relay/server/advert-service.js.map +1 -1
- package/dist/src/circuit-relay/server/index.d.ts +7 -7
- package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/index.js +9 -9
- package/dist/src/circuit-relay/server/index.js.map +1 -1
- package/dist/src/circuit-relay/server/reservation-store.d.ts +3 -3
- package/dist/src/circuit-relay/server/reservation-store.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/reservation-voucher.d.ts +2 -2
- package/dist/src/circuit-relay/transport/discovery.d.ts +8 -8
- package/dist/src/circuit-relay/transport/discovery.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.js +3 -4
- package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
- package/dist/src/circuit-relay/transport/index.d.ts +10 -10
- package/dist/src/circuit-relay/transport/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/index.js +7 -7
- package/dist/src/circuit-relay/transport/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/listener.d.ts +2 -2
- package/dist/src/circuit-relay/transport/listener.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/listener.js +3 -3
- package/dist/src/circuit-relay/transport/listener.js.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts +7 -7
- package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.js +2 -2
- package/dist/src/circuit-relay/transport/reservation-store.js.map +1 -1
- package/dist/src/circuit-relay/utils.d.ts +1 -1
- package/dist/src/components.d.ts +15 -14
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +2 -2
- package/dist/src/components.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts +1 -1
- package/dist/src/config/connection-gater.d.ts +1 -1
- package/dist/src/config.d.ts +1 -2
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +2 -2
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection/index.d.ts +14 -9
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +22 -20
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +5 -5
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/connection-pruner.d.ts +4 -4
- package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
- package/dist/src/connection-manager/connection-pruner.js +2 -2
- package/dist/src/connection-manager/connection-pruner.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts +7 -8
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +6 -6
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +10 -11
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +9 -9
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/content-routing/index.d.ts +5 -5
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +1 -1
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/content-routing/utils.d.ts +2 -2
- package/dist/src/content-routing/utils.js +1 -1
- package/dist/src/content-routing/utils.js.map +1 -1
- package/dist/src/fetch/index.d.ts +5 -5
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +1 -1
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/get-peer.d.ts +1 -1
- package/dist/src/get-peer.js +2 -2
- package/dist/src/get-peer.js.map +1 -1
- package/dist/src/identify/identify.d.ts +7 -7
- package/dist/src/identify/identify.d.ts.map +1 -1
- package/dist/src/identify/identify.js +13 -9
- package/dist/src/identify/identify.js.map +1 -1
- package/dist/src/identify/index.d.ts +24 -9
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +11 -12
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/insecure/index.d.ts +1 -1
- package/dist/src/insecure/index.js +1 -1
- package/dist/src/insecure/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +11 -11
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +5 -5
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +5 -5
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +1 -1
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/ping/index.d.ts +4 -4
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +1 -1
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/pnet/index.d.ts +1 -1
- package/dist/src/pnet/index.js +1 -1
- package/dist/src/pnet/index.js.map +1 -1
- package/dist/src/registrar.d.ts +7 -6
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +7 -11
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +9 -9
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +4 -4
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +12 -12
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +12 -14
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/upnp-nat/index.d.ts +4 -4
- package/dist/src/upnp-nat/index.d.ts.map +1 -1
- package/dist/src/upnp-nat/index.js +1 -1
- package/dist/src/upnp-nat/index.js.map +1 -1
- package/dist/src/utils/peer-job-queue.d.ts +1 -1
- package/dist/src/utils/peer-job-queue.js +1 -1
- package/dist/src/utils/peer-job-queue.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +35 -60
- package/src/address-manager/index.ts +5 -5
- package/src/autonat/index.ts +12 -12
- package/src/circuit-relay/index.ts +1 -1
- package/src/circuit-relay/server/advert-service.ts +3 -3
- package/src/circuit-relay/server/index.ts +17 -17
- package/src/circuit-relay/server/reservation-store.ts +3 -3
- package/src/circuit-relay/server/reservation-voucher.ts +2 -2
- package/src/circuit-relay/transport/discovery.ts +10 -11
- package/src/circuit-relay/transport/index.ts +17 -18
- package/src/circuit-relay/transport/listener.ts +7 -7
- package/src/circuit-relay/transport/reservation-store.ts +9 -9
- package/src/circuit-relay/utils.ts +1 -1
- package/src/components.ts +16 -15
- package/src/config/connection-gater.browser.ts +1 -1
- package/src/config/connection-gater.ts +1 -1
- package/src/config.ts +3 -4
- package/src/connection/index.ts +31 -24
- package/src/connection-manager/auto-dial.ts +5 -5
- package/src/connection-manager/connection-pruner.ts +6 -6
- package/src/connection-manager/dial-queue.ts +13 -14
- package/src/connection-manager/index.ts +19 -20
- package/src/content-routing/index.ts +6 -6
- package/src/content-routing/utils.ts +3 -3
- package/src/fetch/index.ts +7 -7
- package/src/get-peer.ts +3 -3
- package/src/identify/identify.ts +26 -22
- package/src/identify/index.ts +27 -8
- package/src/index.ts +11 -12
- package/src/insecure/index.ts +3 -3
- package/src/libp2p.ts +14 -14
- package/src/peer-routing.ts +6 -6
- package/src/ping/index.ts +7 -7
- package/src/pnet/index.ts +2 -2
- package/src/registrar.ts +14 -17
- package/src/transport-manager.ts +12 -12
- package/src/upgrader.ts +24 -27
- package/src/upnp-nat/index.ts +5 -5
- package/src/utils/peer-job-queue.ts +2 -2
- package/src/version.ts +1 -1
- package/dist/src/pubsub/dummy-pubsub.d.ts +0 -18
- package/dist/src/pubsub/dummy-pubsub.d.ts.map +0 -1
- package/dist/src/pubsub/dummy-pubsub.js +0 -38
- package/dist/src/pubsub/dummy-pubsub.js.map +0 -1
- package/src/pubsub/dummy-pubsub.ts +0 -53
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setMaxListeners } from 'events'
|
|
2
|
-
import { EventEmitter } from '@libp2p/
|
|
2
|
+
import { EventEmitter } from '@libp2p/interface/events'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import { peerIdFromBytes } from '@libp2p/peer-id'
|
|
5
5
|
import { RecordEnvelope } from '@libp2p/peer-record'
|
|
@@ -19,14 +19,14 @@ import { AdvertService, type AdvertServiceComponents, type AdvertServiceInit } f
|
|
|
19
19
|
import { ReservationStore, type ReservationStoreInit } from './reservation-store.js'
|
|
20
20
|
import { ReservationVoucherRecord } from './reservation-voucher.js'
|
|
21
21
|
import type { CircuitRelayService, RelayReservation } from '../index.js'
|
|
22
|
-
import type {
|
|
23
|
-
import type {
|
|
24
|
-
import type {
|
|
25
|
-
import type {
|
|
26
|
-
import type {
|
|
27
|
-
import type {
|
|
28
|
-
import type {
|
|
29
|
-
import type {
|
|
22
|
+
import type { Connection, Stream } from '@libp2p/interface/connection'
|
|
23
|
+
import type { ConnectionGater } from '@libp2p/interface/connection-gater'
|
|
24
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
25
|
+
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
26
|
+
import type { Startable } from '@libp2p/interface/startable'
|
|
27
|
+
import type { AddressManager } from '@libp2p/interface-internal/address-manager'
|
|
28
|
+
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
29
|
+
import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/registrar'
|
|
30
30
|
import type { PeerMap } from '@libp2p/peer-collections'
|
|
31
31
|
|
|
32
32
|
const log = logger('libp2p:circuit-relay:server')
|
|
@@ -193,7 +193,7 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> implements Star
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
async onHop ({ connection, stream }: IncomingStreamData): Promise<void> {
|
|
196
|
-
log('received circuit v2 hop protocol stream from %
|
|
196
|
+
log('received circuit v2 hop protocol stream from %p', connection.remotePeer)
|
|
197
197
|
|
|
198
198
|
const hopTimeoutPromise = pDefer<HopMessage>()
|
|
199
199
|
const timeout = setTimeout(() => {
|
|
@@ -239,7 +239,7 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> implements Star
|
|
|
239
239
|
case HopMessage.Type.RESERVE: await this.handleReserve({ stream, request, connection }); break
|
|
240
240
|
case HopMessage.Type.CONNECT: await this.handleConnect({ stream, request, connection }); break
|
|
241
241
|
default: {
|
|
242
|
-
log.error('invalid hop request type %s via peer %
|
|
242
|
+
log.error('invalid hop request type %s via peer %p', request.type, connection.remotePeer)
|
|
243
243
|
stream.pb(HopMessage).write({ type: HopMessage.Type.STATUS, status: Status.UNEXPECTED_MESSAGE })
|
|
244
244
|
}
|
|
245
245
|
}
|
|
@@ -247,7 +247,7 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> implements Star
|
|
|
247
247
|
|
|
248
248
|
async handleReserve ({ stream, request, connection }: HopProtocolOptions): Promise<void> {
|
|
249
249
|
const hopstr = stream.pb(HopMessage)
|
|
250
|
-
log('hop reserve request from %
|
|
250
|
+
log('hop reserve request from %p', connection.remotePeer)
|
|
251
251
|
|
|
252
252
|
if (isRelayAddr(connection.remoteAddr)) {
|
|
253
253
|
log.error('relay reservation over circuit connection denied for peer: %p', connection.remotePeer)
|
|
@@ -329,7 +329,7 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> implements Star
|
|
|
329
329
|
return
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
log('hop connect request from %
|
|
332
|
+
log('hop connect request from %p', connection.remotePeer)
|
|
333
333
|
|
|
334
334
|
let dstPeer: PeerId
|
|
335
335
|
|
|
@@ -381,7 +381,7 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> implements Star
|
|
|
381
381
|
})
|
|
382
382
|
|
|
383
383
|
if (destinationStream == null) {
|
|
384
|
-
log.error('failed to open stream to destination peer %
|
|
384
|
+
log.error('failed to open stream to destination peer %p', destinationConnection?.remotePeer)
|
|
385
385
|
hopstr.write({ type: HopMessage.Type.STATUS, status: Status.CONNECTION_FAILED })
|
|
386
386
|
return
|
|
387
387
|
}
|
|
@@ -414,17 +414,17 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> implements Star
|
|
|
414
414
|
try {
|
|
415
415
|
response = await stopstr.read()
|
|
416
416
|
} catch (err) {
|
|
417
|
-
log.error('error parsing stop message response from %
|
|
417
|
+
log.error('error parsing stop message response from %p', connection.remotePeer)
|
|
418
418
|
}
|
|
419
419
|
|
|
420
420
|
if (response == null) {
|
|
421
|
-
log.error('could not read response from %
|
|
421
|
+
log.error('could not read response from %p', connection.remotePeer)
|
|
422
422
|
stream.close()
|
|
423
423
|
return
|
|
424
424
|
}
|
|
425
425
|
|
|
426
426
|
if (response.status === Status.OK) {
|
|
427
|
-
log('stop request to %
|
|
427
|
+
log('stop request to %p was successful', connection.remotePeer)
|
|
428
428
|
return pbstr.unwrap()
|
|
429
429
|
}
|
|
430
430
|
|
|
@@ -2,9 +2,9 @@ import { PeerMap } from '@libp2p/peer-collections'
|
|
|
2
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
3
|
import { type Limit, Status } from '../pb/index.js'
|
|
4
4
|
import type { RelayReservation } from '../index.js'
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type { Startable } from '@libp2p/
|
|
5
|
+
import type { RecursivePartial } from '@libp2p/interface'
|
|
6
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
7
|
+
import type { Startable } from '@libp2p/interface/startable'
|
|
8
8
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
9
9
|
|
|
10
10
|
export type ReservationStatus = Status.OK | Status.PERMISSION_DENIED | Status.RESERVATION_REFUSED
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReservationVoucher } from '../pb/index.js'
|
|
2
|
-
import type { PeerId } from '@libp2p/interface
|
|
3
|
-
import type { Record } from '@libp2p/interface
|
|
2
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
3
|
+
import type { Record } from '@libp2p/interface/record'
|
|
4
4
|
|
|
5
5
|
export interface ReservationVoucherOptions {
|
|
6
6
|
relay: PeerId
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { EventEmitter } from '@libp2p/
|
|
1
|
+
import { EventEmitter } from '@libp2p/interface/events'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
|
-
import { createTopology } from '@libp2p/topology'
|
|
4
3
|
import {
|
|
5
4
|
RELAY_RENDEZVOUS_NS,
|
|
6
5
|
RELAY_V2_HOP_CODEC
|
|
7
6
|
} from '../constants.js'
|
|
8
7
|
import { namespaceToCid } from '../utils.js'
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
import type {
|
|
14
|
-
import type {
|
|
15
|
-
import type {
|
|
8
|
+
import type { ContentRouting } from '@libp2p/interface/content-routing'
|
|
9
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
10
|
+
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
11
|
+
import type { Startable } from '@libp2p/interface/startable'
|
|
12
|
+
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
13
|
+
import type { Registrar } from '@libp2p/interface-internal/registrar'
|
|
14
|
+
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
|
|
16
15
|
|
|
17
16
|
const log = logger('libp2p:circuit-relay:discover-relays')
|
|
18
17
|
|
|
@@ -57,11 +56,11 @@ export class RelayDiscovery extends EventEmitter<RelayDiscoveryEvents> implement
|
|
|
57
56
|
async start (): Promise<void> {
|
|
58
57
|
// register a topology listener for when new peers are encountered
|
|
59
58
|
// that support the hop protocol
|
|
60
|
-
this.topologyId = await this.registrar.register(RELAY_V2_HOP_CODEC,
|
|
59
|
+
this.topologyId = await this.registrar.register(RELAY_V2_HOP_CODEC, {
|
|
61
60
|
onConnect: (peerId) => {
|
|
62
61
|
this.safeDispatchEvent('relay:discover', { detail: peerId })
|
|
63
62
|
}
|
|
64
|
-
})
|
|
63
|
+
})
|
|
65
64
|
|
|
66
65
|
void this.discover()
|
|
67
66
|
.catch(err => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
+
import { symbol, type Transport, type CreateListenerOptions, type Listener, type Upgrader } from '@libp2p/interface/transport'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import { peerIdFromBytes, peerIdFromString } from '@libp2p/peer-id'
|
|
5
5
|
import { streamToMaConnection } from '@libp2p/utils/stream-to-ma-conn'
|
|
@@ -13,17 +13,16 @@ import { StopMessage, HopMessage, Status } from '../pb/index.js'
|
|
|
13
13
|
import { RelayDiscovery, type RelayDiscoveryComponents } from './discovery.js'
|
|
14
14
|
import { createListener } from './listener.js'
|
|
15
15
|
import { type RelayStoreInit, ReservationStore } from './reservation-store.js'
|
|
16
|
-
import type {
|
|
17
|
-
import type { Connection, Stream } from '@libp2p/interface
|
|
18
|
-
import type { ConnectionGater } from '@libp2p/interface
|
|
19
|
-
import type {
|
|
20
|
-
import type {
|
|
21
|
-
import type {
|
|
22
|
-
import type {
|
|
23
|
-
import type {
|
|
24
|
-
import type {
|
|
25
|
-
import type {
|
|
26
|
-
import type { EventEmitter } from '@libp2p/interfaces/events'
|
|
16
|
+
import type { Libp2pEvents, AbortOptions } from '@libp2p/interface'
|
|
17
|
+
import type { Connection, Stream } from '@libp2p/interface/connection'
|
|
18
|
+
import type { ConnectionGater } from '@libp2p/interface/connection-gater'
|
|
19
|
+
import type { ContentRouting } from '@libp2p/interface/content-routing'
|
|
20
|
+
import type { EventEmitter } from '@libp2p/interface/events'
|
|
21
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
22
|
+
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
23
|
+
import type { AddressManager } from '@libp2p/interface-internal/address-manager'
|
|
24
|
+
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
25
|
+
import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/registrar'
|
|
27
26
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
28
27
|
|
|
29
28
|
const log = logger('libp2p:circuit-relay:transport')
|
|
@@ -267,7 +266,7 @@ class CircuitRelayTransport implements Transport {
|
|
|
267
266
|
localAddr: relayAddr.encapsulate(`/p2p-circuit/p2p/${this.peerId.toString()}`)
|
|
268
267
|
})
|
|
269
268
|
|
|
270
|
-
log('new outbound connection %
|
|
269
|
+
log('new outbound connection %a', maConn.remoteAddr)
|
|
271
270
|
return await this.upgrader.upgradeOutbound(maConn)
|
|
272
271
|
} catch (err) {
|
|
273
272
|
log.error(`Circuit relay dial to destination ${destinationPeer.toString()} via relay ${connection.remotePeer.toString()} failed`, err)
|
|
@@ -313,17 +312,17 @@ class CircuitRelayTransport implements Transport {
|
|
|
313
312
|
}
|
|
314
313
|
|
|
315
314
|
const stopstr = pbstr.pb(StopMessage)
|
|
316
|
-
log('new circuit relay v2 stop stream from %
|
|
315
|
+
log('new circuit relay v2 stop stream from %p', connection.remotePeer)
|
|
317
316
|
|
|
318
317
|
// Validate the STOP request has the required input
|
|
319
318
|
if (request.type !== StopMessage.Type.CONNECT) {
|
|
320
|
-
log.error('invalid stop connect request via peer %
|
|
319
|
+
log.error('invalid stop connect request via peer %p', connection.remotePeer)
|
|
321
320
|
stopstr.write({ type: StopMessage.Type.STATUS, status: Status.UNEXPECTED_MESSAGE })
|
|
322
321
|
return
|
|
323
322
|
}
|
|
324
323
|
|
|
325
324
|
if (!isValidStop(request)) {
|
|
326
|
-
log.error('invalid stop connect request via peer %
|
|
325
|
+
log.error('invalid stop connect request via peer %p', connection.remotePeer)
|
|
327
326
|
stopstr.write({ type: StopMessage.Type.STATUS, status: Status.MALFORMED_MESSAGE })
|
|
328
327
|
return
|
|
329
328
|
}
|
|
@@ -347,7 +346,7 @@ class CircuitRelayTransport implements Transport {
|
|
|
347
346
|
|
|
348
347
|
log('new inbound connection %s', maConn.remoteAddr)
|
|
349
348
|
await this.upgrader.upgradeInbound(maConn)
|
|
350
|
-
log('%s connection %
|
|
349
|
+
log('%s connection %a upgraded', 'inbound', maConn.remoteAddr)
|
|
351
350
|
}
|
|
352
351
|
}
|
|
353
352
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/
|
|
2
|
-
import { EventEmitter } from '@libp2p/
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
+
import { EventEmitter } from '@libp2p/interface/events'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import { PeerMap } from '@libp2p/peer-collections'
|
|
5
5
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
6
6
|
import { multiaddr } from '@multiformats/multiaddr'
|
|
7
7
|
import type { ReservationStore } from './reservation-store.js'
|
|
8
|
-
import type { Connection } from '@libp2p/interface
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
8
|
+
import type { Connection } from '@libp2p/interface/connection'
|
|
9
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
10
|
+
import type { Listener, ListenerEvents } from '@libp2p/interface/transport'
|
|
11
|
+
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
12
12
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
13
13
|
|
|
14
14
|
const log = logger('libp2p:circuit-relay:transport:listener')
|
|
@@ -37,7 +37,7 @@ class CircuitRelayTransportListener extends EventEmitter<ListenerEvents> impleme
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
async listen (addr: Multiaddr): Promise<void> {
|
|
40
|
-
log('listen on %
|
|
40
|
+
log('listen on %a', addr)
|
|
41
41
|
|
|
42
42
|
const relayPeerStr = addr.getPeerId()
|
|
43
43
|
let relayConn: Connection | undefined
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventEmitter } from '@libp2p/
|
|
1
|
+
import { EventEmitter } from '@libp2p/interface/events'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
3
|
import { PeerMap } from '@libp2p/peer-collections'
|
|
4
4
|
import { multiaddr } from '@multiformats/multiaddr'
|
|
@@ -8,13 +8,13 @@ import { DEFAULT_RESERVATION_CONCURRENCY, RELAY_TAG, RELAY_V2_HOP_CODEC } from '
|
|
|
8
8
|
import { HopMessage, Status } from '../pb/index.js'
|
|
9
9
|
import { getExpirationMilliseconds } from '../utils.js'
|
|
10
10
|
import type { Reservation } from '../pb/index.js'
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
import type {
|
|
14
|
-
import type {
|
|
15
|
-
import type {
|
|
16
|
-
import type {
|
|
17
|
-
import type {
|
|
11
|
+
import type { Libp2pEvents } from '@libp2p/interface'
|
|
12
|
+
import type { Connection } from '@libp2p/interface/connection'
|
|
13
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
14
|
+
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
15
|
+
import type { Startable } from '@libp2p/interface/startable'
|
|
16
|
+
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
17
|
+
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
|
|
18
18
|
|
|
19
19
|
const log = logger('libp2p:circuit-relay:transport:reservation-store')
|
|
20
20
|
|
|
@@ -237,7 +237,7 @@ export class ReservationStore extends EventEmitter<ReservationStoreEvents> imple
|
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
async #createReservation (connection: Connection): Promise<Reservation> {
|
|
240
|
-
log('requesting reservation from %
|
|
240
|
+
log('requesting reservation from %p', connection.remotePeer)
|
|
241
241
|
const stream = await connection.newStream(RELAY_V2_HOP_CODEC)
|
|
242
242
|
const pbstr = pbStream(stream)
|
|
243
243
|
const hopstr = pbstr.pb(HopMessage)
|
|
@@ -5,7 +5,7 @@ import { CID } from 'multiformats/cid'
|
|
|
5
5
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
6
6
|
import { DEFAULT_DATA_LIMIT, DEFAULT_DURATION_LIMIT } from './constants.js'
|
|
7
7
|
import type { Limit } from './pb/index.js'
|
|
8
|
-
import type { Stream } from '@libp2p/interface
|
|
8
|
+
import type { Stream } from '@libp2p/interface/connection'
|
|
9
9
|
import type { Source } from 'it-stream-types'
|
|
10
10
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
11
11
|
|
package/src/components.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/
|
|
2
|
-
import { isStartable, type Startable } from '@libp2p/
|
|
3
|
-
import type {
|
|
4
|
-
import type { ConnectionProtector } from '@libp2p/interface
|
|
5
|
-
import type { ConnectionGater } from '@libp2p/interface
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
import type {
|
|
14
|
-
import type {
|
|
15
|
-
import type {
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
+
import { isStartable, type Startable } from '@libp2p/interface/startable'
|
|
3
|
+
import type { Libp2pEvents } from '@libp2p/interface'
|
|
4
|
+
import type { ConnectionProtector } from '@libp2p/interface/connection'
|
|
5
|
+
import type { ConnectionGater } from '@libp2p/interface/connection-gater'
|
|
6
|
+
import type { ContentRouting } from '@libp2p/interface/content-routing'
|
|
7
|
+
import type { EventEmitter } from '@libp2p/interface/events'
|
|
8
|
+
import type { Metrics } from '@libp2p/interface/metrics'
|
|
9
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
10
|
+
import type { PeerRouting } from '@libp2p/interface/peer-routing'
|
|
11
|
+
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
12
|
+
import type { Upgrader } from '@libp2p/interface/transport'
|
|
13
|
+
import type { AddressManager } from '@libp2p/interface-internal/address-manager'
|
|
14
|
+
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
15
|
+
import type { Registrar } from '@libp2p/interface-internal/registrar'
|
|
16
|
+
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
|
|
16
17
|
import type { Datastore } from 'interface-datastore'
|
|
17
18
|
|
|
18
19
|
export interface Components extends Record<string, any>, Startable {
|
package/src/config.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
+
import { FaultTolerance } from '@libp2p/interface/transport'
|
|
3
3
|
import { publicAddressesFirst } from '@libp2p/utils/address-sort'
|
|
4
4
|
import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'
|
|
5
5
|
import mergeOptions from 'merge-options'
|
|
6
6
|
import { codes, messages } from './errors.js'
|
|
7
7
|
import type { Libp2pInit } from './index.js'
|
|
8
|
-
import type { ServiceMap } from '@libp2p/interface
|
|
9
|
-
import type { RecursivePartial } from '@libp2p/interfaces'
|
|
8
|
+
import type { ServiceMap, RecursivePartial } from '@libp2p/interface'
|
|
10
9
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
11
10
|
|
|
12
11
|
const DefaultConfig: Partial<Libp2pInit> = {
|
package/src/connection/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { symbol } from '@libp2p/interface
|
|
2
|
-
import { OPEN, CLOSING, CLOSED } from '@libp2p/interface
|
|
3
|
-
import { CodeError } from '@libp2p/
|
|
1
|
+
import { type Direction, symbol, type Connection, type Stream, type ConnectionTimeline } from '@libp2p/interface/connection'
|
|
2
|
+
import { OPEN, CLOSING, CLOSED } from '@libp2p/interface/connection/status'
|
|
3
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
4
4
|
import { logger } from '@libp2p/logger'
|
|
5
|
-
import type {
|
|
6
|
-
import type
|
|
7
|
-
import type {
|
|
5
|
+
import type { AbortOptions } from '@libp2p/interface'
|
|
6
|
+
import type * as Status from '@libp2p/interface/connection/status'
|
|
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:connection')
|
|
@@ -15,7 +15,11 @@ interface ConnectionInit {
|
|
|
15
15
|
newStream: (protocols: string[], options?: AbortOptions) => Promise<Stream>
|
|
16
16
|
close: () => Promise<void>
|
|
17
17
|
getStreams: () => Stream[]
|
|
18
|
-
|
|
18
|
+
status: keyof typeof Status
|
|
19
|
+
direction: Direction
|
|
20
|
+
timeline: ConnectionTimeline
|
|
21
|
+
multiplexer?: string
|
|
22
|
+
encryption?: string
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
/**
|
|
@@ -38,10 +42,11 @@ export class ConnectionImpl implements Connection {
|
|
|
38
42
|
*/
|
|
39
43
|
public readonly remotePeer: PeerId
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
public
|
|
45
|
+
public direction: Direction
|
|
46
|
+
public timeline: ConnectionTimeline
|
|
47
|
+
public multiplexer?: string
|
|
48
|
+
public encryption?: string
|
|
49
|
+
public status: keyof typeof Status
|
|
45
50
|
|
|
46
51
|
/**
|
|
47
52
|
* User provided tags
|
|
@@ -71,15 +76,17 @@ export class ConnectionImpl implements Connection {
|
|
|
71
76
|
* Any libp2p transport should use an upgrader to return this connection.
|
|
72
77
|
*/
|
|
73
78
|
constructor (init: ConnectionInit) {
|
|
74
|
-
const { remoteAddr, remotePeer, newStream, close, getStreams
|
|
79
|
+
const { remoteAddr, remotePeer, newStream, close, getStreams } = init
|
|
75
80
|
|
|
76
81
|
this.id = `${(parseInt(String(Math.random() * 1e9))).toString(36)}${Date.now()}`
|
|
77
82
|
this.remoteAddr = remoteAddr
|
|
78
83
|
this.remotePeer = remotePeer
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
this.direction = init.direction
|
|
85
|
+
this.status = OPEN
|
|
86
|
+
this.timeline = init.timeline
|
|
87
|
+
this.multiplexer = init.multiplexer
|
|
88
|
+
this.encryption = init.encryption
|
|
89
|
+
|
|
83
90
|
this._newStream = newStream
|
|
84
91
|
this._close = close
|
|
85
92
|
this._getStreams = getStreams
|
|
@@ -102,11 +109,11 @@ export class ConnectionImpl implements Connection {
|
|
|
102
109
|
* Create a new stream from this connection
|
|
103
110
|
*/
|
|
104
111
|
async newStream (protocols: string | string[], options?: AbortOptions): Promise<Stream> {
|
|
105
|
-
if (this.
|
|
112
|
+
if (this.status === CLOSING) {
|
|
106
113
|
throw new CodeError('the connection is being closed', 'ERR_CONNECTION_BEING_CLOSED')
|
|
107
114
|
}
|
|
108
115
|
|
|
109
|
-
if (this.
|
|
116
|
+
if (this.status === CLOSED) {
|
|
110
117
|
throw new CodeError('the connection is closed', 'ERR_CONNECTION_CLOSED')
|
|
111
118
|
}
|
|
112
119
|
|
|
@@ -116,7 +123,7 @@ export class ConnectionImpl implements Connection {
|
|
|
116
123
|
|
|
117
124
|
const stream = await this._newStream(protocols, options)
|
|
118
125
|
|
|
119
|
-
stream.
|
|
126
|
+
stream.direction = 'outbound'
|
|
120
127
|
|
|
121
128
|
return stream
|
|
122
129
|
}
|
|
@@ -125,7 +132,7 @@ export class ConnectionImpl implements Connection {
|
|
|
125
132
|
* Add a stream when it is opened to the registry
|
|
126
133
|
*/
|
|
127
134
|
addStream (stream: Stream): void {
|
|
128
|
-
stream.
|
|
135
|
+
stream.direction = 'inbound'
|
|
129
136
|
}
|
|
130
137
|
|
|
131
138
|
/**
|
|
@@ -139,11 +146,11 @@ export class ConnectionImpl implements Connection {
|
|
|
139
146
|
* Close the connection
|
|
140
147
|
*/
|
|
141
148
|
async close (): Promise<void> {
|
|
142
|
-
if (this.
|
|
149
|
+
if (this.status === CLOSED || this._closing) {
|
|
143
150
|
return
|
|
144
151
|
}
|
|
145
152
|
|
|
146
|
-
this.
|
|
153
|
+
this.status = CLOSING
|
|
147
154
|
|
|
148
155
|
// close all streams - this can throw if we're not multiplexed
|
|
149
156
|
try {
|
|
@@ -157,8 +164,8 @@ export class ConnectionImpl implements Connection {
|
|
|
157
164
|
await this._close()
|
|
158
165
|
this._closing = false
|
|
159
166
|
|
|
160
|
-
this.
|
|
161
|
-
this.
|
|
167
|
+
this.timeline.close = Date.now()
|
|
168
|
+
this.status = CLOSED
|
|
162
169
|
}
|
|
163
170
|
}
|
|
164
171
|
|
|
@@ -2,11 +2,11 @@ import { logger } from '@libp2p/logger'
|
|
|
2
2
|
import { PeerMap, PeerSet } from '@libp2p/peer-collections'
|
|
3
3
|
import { PeerJobQueue } from '../utils/peer-job-queue.js'
|
|
4
4
|
import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_INTERVAL, AUTO_DIAL_MAX_QUEUE_LENGTH, AUTO_DIAL_PRIORITY, MIN_CONNECTIONS } from './constants.js'
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type { PeerStore } from '@libp2p/interface
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
5
|
+
import type { Libp2pEvents } from '@libp2p/interface'
|
|
6
|
+
import type { EventEmitter } from '@libp2p/interface/events'
|
|
7
|
+
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
8
|
+
import type { Startable } from '@libp2p/interface/startable'
|
|
9
|
+
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
10
10
|
|
|
11
11
|
const log = logger('libp2p:connection-manager:auto-dial')
|
|
12
12
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
2
|
import { PeerMap } from '@libp2p/peer-collections'
|
|
3
3
|
import { MAX_CONNECTIONS } from './constants.js'
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type { PeerStore } from '@libp2p/interface
|
|
7
|
-
import type {
|
|
4
|
+
import type { Libp2pEvents } from '@libp2p/interface'
|
|
5
|
+
import type { EventEmitter } from '@libp2p/interface/events'
|
|
6
|
+
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
7
|
+
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
8
8
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
9
9
|
|
|
10
10
|
const log = logger('libp2p:connection-manager:connection-pruner')
|
|
@@ -106,8 +106,8 @@ export class ConnectionPruner {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// if the peers have an equal tag value then we want to close short-lived connections first
|
|
109
|
-
const connectionALifespan = a.
|
|
110
|
-
const connectionBLifespan = b.
|
|
109
|
+
const connectionALifespan = a.timeline.open
|
|
110
|
+
const connectionBLifespan = b.timeline.open
|
|
111
111
|
|
|
112
112
|
if (connectionALifespan < connectionBLifespan) {
|
|
113
113
|
return 1
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setMaxListeners } from 'events'
|
|
2
|
-
import { AbortError, CodeError } from '@libp2p/
|
|
2
|
+
import { AbortError, CodeError } from '@libp2p/interface/errors'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import { publicAddressesFirst } from '@libp2p/utils/address-sort'
|
|
5
5
|
import { type Multiaddr, type Resolver, resolvers } from '@multiformats/multiaddr'
|
|
@@ -16,14 +16,13 @@ import {
|
|
|
16
16
|
MAX_PEER_ADDRS_TO_DIAL
|
|
17
17
|
} from './constants.js'
|
|
18
18
|
import { combineSignals, resolveMultiaddrs } from './utils.js'
|
|
19
|
-
import type {
|
|
20
|
-
import type {
|
|
21
|
-
import type {
|
|
22
|
-
import type { Metric, Metrics } from '@libp2p/interface
|
|
23
|
-
import type { PeerId } from '@libp2p/interface
|
|
24
|
-
import type { Address, PeerStore } from '@libp2p/interface
|
|
25
|
-
import type { TransportManager } from '@libp2p/interface-transport'
|
|
26
|
-
import type { AbortOptions } from '@libp2p/interfaces'
|
|
19
|
+
import type { AddressSorter, AbortOptions } from '@libp2p/interface'
|
|
20
|
+
import type { Connection } from '@libp2p/interface/connection'
|
|
21
|
+
import type { ConnectionGater } from '@libp2p/interface/connection-gater'
|
|
22
|
+
import type { Metric, Metrics } from '@libp2p/interface/metrics'
|
|
23
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
24
|
+
import type { Address, PeerStore } from '@libp2p/interface/peer-store'
|
|
25
|
+
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
|
|
27
26
|
|
|
28
27
|
const log = logger('libp2p:connection-manager:dial-queue')
|
|
29
28
|
|
|
@@ -419,13 +418,13 @@ export class DialQueue {
|
|
|
419
418
|
// let any signal abort the dial
|
|
420
419
|
const signal = combineSignals(controller.signal, options.signal)
|
|
421
420
|
signal.addEventListener('abort', () => {
|
|
422
|
-
log('dial to %
|
|
421
|
+
log('dial to %a aborted', addr)
|
|
423
422
|
})
|
|
424
423
|
const deferred = pDefer<Connection>()
|
|
425
424
|
|
|
426
425
|
await peerDialQueue.add(async () => {
|
|
427
426
|
if (signal.aborted) {
|
|
428
|
-
log('dial to %
|
|
427
|
+
log('dial to %a was aborted before reaching the head of the peer dial queue', addr)
|
|
429
428
|
deferred.reject(new AbortError())
|
|
430
429
|
return
|
|
431
430
|
}
|
|
@@ -434,7 +433,7 @@ export class DialQueue {
|
|
|
434
433
|
await this.queue.add(async () => {
|
|
435
434
|
try {
|
|
436
435
|
if (signal.aborted) {
|
|
437
|
-
log('dial to %
|
|
436
|
+
log('dial to %a was aborted before reaching the head of the dial queue', addr)
|
|
438
437
|
deferred.reject(new AbortError())
|
|
439
438
|
return
|
|
440
439
|
}
|
|
@@ -469,13 +468,13 @@ export class DialQueue {
|
|
|
469
468
|
}
|
|
470
469
|
})
|
|
471
470
|
|
|
472
|
-
log('dial to %
|
|
471
|
+
log('dial to %a succeeded', addr)
|
|
473
472
|
|
|
474
473
|
// resolve the connection promise
|
|
475
474
|
deferred.resolve(conn)
|
|
476
475
|
} catch (err: any) {
|
|
477
476
|
// something only went wrong if our signal was not aborted
|
|
478
|
-
log.error('error during dial of %
|
|
477
|
+
log.error('error during dial of %a', addr, err)
|
|
479
478
|
deferred.reject(err)
|
|
480
479
|
}
|
|
481
480
|
}, {
|