libp2p 0.44.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +30 -30
- package/dist/src/address-manager/index.d.ts +8 -4
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +37 -6
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/address-manager/utils.d.ts +2 -0
- package/dist/src/address-manager/utils.d.ts.map +1 -0
- package/dist/src/address-manager/utils.js +12 -0
- package/dist/src/address-manager/utils.js.map +1 -0
- package/dist/src/autonat/constants.d.ts +16 -2
- package/dist/src/autonat/constants.d.ts.map +1 -1
- package/dist/src/autonat/constants.js +16 -2
- package/dist/src/autonat/constants.js.map +1 -1
- package/dist/src/autonat/index.d.ts +12 -33
- package/dist/src/autonat/index.d.ts.map +1 -1
- package/dist/src/autonat/index.js +36 -30
- package/dist/src/autonat/index.js.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.js +2 -2
- package/dist/src/circuit-relay/server/advert-service.js.map +1 -1
- package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/index.js +10 -3
- package/dist/src/circuit-relay/server/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.js +4 -2
- package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
- package/dist/src/circuit-relay/transport/index.d.ts +3 -0
- package/dist/src/circuit-relay/transport/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/index.js +6 -4
- package/dist/src/circuit-relay/transport/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/listener.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/listener.js +30 -26
- package/dist/src/circuit-relay/transport/listener.js.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts +5 -4
- package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.js +37 -30
- package/dist/src/circuit-relay/transport/reservation-store.js.map +1 -1
- package/dist/src/components.d.ts +6 -63
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +60 -164
- package/dist/src/components.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts +8 -0
- package/dist/src/config/connection-gater.browser.d.ts.map +1 -0
- package/dist/src/config/connection-gater.browser.js +27 -0
- package/dist/src/config/connection-gater.browser.js.map +1 -0
- package/dist/src/config/connection-gater.d.ts +6 -0
- package/dist/src/config/connection-gater.d.ts.map +1 -0
- package/dist/src/config/connection-gater.js +18 -0
- package/dist/src/config/connection-gater.js.map +1 -0
- package/dist/src/config.d.ts +2 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +0 -62
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +3 -0
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dial.js +36 -13
- package/dist/src/connection-manager/auto-dial.js.map +1 -1
- package/dist/src/connection-manager/connection-pruner.d.ts +4 -0
- package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
- package/dist/src/connection-manager/connection-pruner.js +23 -8
- package/dist/src/connection-manager/connection-pruner.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts +2 -1
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +36 -14
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +8 -7
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +23 -34
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/content-routing/index.d.ts +0 -10
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +7 -42
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +3 -1
- package/dist/src/content-routing/utils.js.map +1 -1
- package/dist/src/fetch/index.d.ts +13 -35
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +7 -9
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/identify/identify.d.ts +53 -0
- package/dist/src/identify/identify.d.ts.map +1 -0
- package/dist/src/identify/identify.js +405 -0
- package/dist/src/identify/identify.js.map +1 -0
- package/dist/src/identify/index.d.ts +12 -58
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +5 -388
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +13 -68
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/insecure/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +11 -42
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +137 -196
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -38
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +0 -59
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/ping/constants.d.ts +4 -0
- package/dist/src/ping/constants.d.ts.map +1 -1
- package/dist/src/ping/constants.js +10 -0
- package/dist/src/ping/constants.js.map +1 -1
- package/dist/src/ping/index.d.ts +10 -27
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +18 -21
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/registrar.d.ts +5 -2
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +27 -25
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +11 -4
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +19 -10
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +15 -10
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +39 -48
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/upnp-nat/index.d.ts +42 -0
- package/dist/src/upnp-nat/index.d.ts.map +1 -0
- package/dist/src/{nat-manager.js → upnp-nat/index.js} +11 -7
- package/dist/src/upnp-nat/index.js.map +1 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/typedoc-urls.json +25 -10
- package/package.json +61 -45
- package/src/address-manager/index.ts +50 -8
- package/src/address-manager/utils.ts +14 -0
- package/src/autonat/constants.ts +17 -2
- package/src/autonat/index.ts +53 -45
- package/src/circuit-relay/server/advert-service.ts +2 -2
- package/src/circuit-relay/server/index.ts +11 -3
- package/src/circuit-relay/transport/discovery.ts +5 -3
- package/src/circuit-relay/transport/index.ts +9 -4
- package/src/circuit-relay/transport/listener.ts +38 -28
- package/src/circuit-relay/transport/reservation-store.ts +34 -20
- package/src/components.ts +71 -234
- package/src/config/connection-gater.browser.ts +31 -0
- package/src/config/connection-gater.ts +19 -0
- package/src/config.ts +3 -64
- package/src/connection-manager/auto-dial.ts +44 -15
- package/src/connection-manager/connection-pruner.ts +28 -8
- package/src/connection-manager/dial-queue.ts +41 -21
- package/src/connection-manager/index.ts +31 -43
- package/src/content-routing/index.ts +7 -55
- package/src/content-routing/utils.ts +3 -1
- package/src/fetch/index.ts +51 -14
- package/src/identify/identify.ts +518 -0
- package/src/identify/index.ts +17 -507
- package/src/index.ts +14 -77
- package/src/insecure/index.ts +4 -4
- package/src/libp2p.ts +139 -260
- package/src/peer-routing.ts +1 -101
- package/src/ping/constants.ts +11 -0
- package/src/ping/index.ts +32 -28
- package/src/registrar.ts +31 -27
- package/src/transport-manager.ts +27 -13
- package/src/upgrader.ts +62 -58
- package/src/{nat-manager.ts → upnp-nat/index.ts} +16 -17
- package/src/version.ts +1 -1
- package/dist/src/dht/dht-content-routing.d.ts +0 -17
- package/dist/src/dht/dht-content-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-content-routing.js +0 -32
- package/dist/src/dht/dht-content-routing.js.map +0 -1
- package/dist/src/dht/dht-peer-routing.d.ts +0 -15
- package/dist/src/dht/dht-peer-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-peer-routing.js +0 -26
- package/dist/src/dht/dht-peer-routing.js.map +0 -1
- package/dist/src/dht/dummy-dht.d.ts +0 -20
- package/dist/src/dht/dummy-dht.d.ts.map +0 -1
- package/dist/src/dht/dummy-dht.js +0 -46
- package/dist/src/dht/dummy-dht.js.map +0 -1
- package/dist/src/nat-manager.d.ts +0 -74
- package/dist/src/nat-manager.d.ts.map +0 -1
- package/dist/src/nat-manager.js.map +0 -1
- package/dist/src/peer-record-updater.d.ts +0 -24
- package/dist/src/peer-record-updater.d.ts.map +0 -1
- package/dist/src/peer-record-updater.js +0 -44
- package/dist/src/peer-record-updater.js.map +0 -1
- package/src/dht/dht-content-routing.ts +0 -44
- package/src/dht/dht-peer-routing.ts +0 -36
- package/src/dht/dummy-dht.ts +0 -60
- package/src/peer-record-updater.ts +0 -65
package/src/upgrader.ts
CHANGED
|
@@ -3,18 +3,17 @@ import { CodeError } from '@libp2p/interfaces/errors'
|
|
|
3
3
|
import * as mss from '@libp2p/multistream-select'
|
|
4
4
|
import { codes } from './errors.js'
|
|
5
5
|
import { createConnection } from './connection/index.js'
|
|
6
|
-
import {
|
|
6
|
+
import type { EventEmitter } from '@libp2p/interfaces/events'
|
|
7
7
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
8
8
|
import type { MultiaddrConnection, Connection, Stream, ConnectionProtector } from '@libp2p/interface-connection'
|
|
9
9
|
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter'
|
|
10
10
|
import type { StreamMuxer, StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
|
|
11
11
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
12
|
-
import type { Upgrader,
|
|
13
|
-
import type { Duplex } from 'it-stream-types'
|
|
12
|
+
import type { Upgrader, UpgraderOptions } from '@libp2p/interface-transport'
|
|
13
|
+
import type { Duplex, Source } from 'it-stream-types'
|
|
14
14
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
15
15
|
import type { Registrar } from '@libp2p/interface-registrar'
|
|
16
16
|
import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js'
|
|
17
|
-
import { TimeoutController } from 'timeout-abort-controller'
|
|
18
17
|
import { abortableDuplex } from 'abortable-iterator'
|
|
19
18
|
import { setMaxListeners } from 'events'
|
|
20
19
|
import type { Metrics } from '@libp2p/interface-metrics'
|
|
@@ -22,14 +21,16 @@ import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
|
22
21
|
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
23
22
|
import type { ConnectionGater } from '@libp2p/interface-connection-gater'
|
|
24
23
|
import { INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js'
|
|
24
|
+
import { anySignal } from 'any-signal'
|
|
25
|
+
import type { Libp2pEvents } from '@libp2p/interface-libp2p'
|
|
25
26
|
|
|
26
27
|
const log = logger('libp2p:upgrader')
|
|
27
28
|
|
|
28
|
-
interface
|
|
29
|
+
interface CreateConnectionOptions {
|
|
29
30
|
cryptoProtocol: string
|
|
30
31
|
direction: 'inbound' | 'outbound'
|
|
31
32
|
maConn: MultiaddrConnection
|
|
32
|
-
upgradedConn: Duplex<Uint8Array
|
|
33
|
+
upgradedConn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>
|
|
33
34
|
remotePeer: PeerId
|
|
34
35
|
muxerFactory?: StreamMuxerFactory
|
|
35
36
|
}
|
|
@@ -72,7 +73,6 @@ function findIncomingStreamLimit (protocol: string, registrar: Registrar): numbe
|
|
|
72
73
|
function findOutgoingStreamLimit (protocol: string, registrar: Registrar): number | undefined {
|
|
73
74
|
try {
|
|
74
75
|
const { options } = registrar.getHandler(protocol)
|
|
75
|
-
|
|
76
76
|
return options.maxOutboundStreams
|
|
77
77
|
} catch (err: any) {
|
|
78
78
|
if (err.code !== codes.ERR_NO_HANDLER_FOR_PROTOCOL) {
|
|
@@ -103,17 +103,21 @@ export interface DefaultUpgraderComponents {
|
|
|
103
103
|
connectionProtector?: ConnectionProtector
|
|
104
104
|
registrar: Registrar
|
|
105
105
|
peerStore: PeerStore
|
|
106
|
+
events: EventEmitter<Libp2pEvents>
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
|
|
109
|
+
type EncryptedConn = Duplex<AsyncGenerator<Uint8Array, any, unknown>, Source<Uint8Array>, Promise<void>>
|
|
110
|
+
|
|
111
|
+
type ConnectionDeniedType = keyof Pick<ConnectionGater, 'denyOutboundConnection' | 'denyInboundEncryptedConnection' | 'denyOutboundEncryptedConnection' | 'denyInboundUpgradedConnection' | 'denyOutboundUpgradedConnection'>
|
|
112
|
+
|
|
113
|
+
export class DefaultUpgrader implements Upgrader {
|
|
109
114
|
private readonly components: DefaultUpgraderComponents
|
|
110
115
|
private readonly connectionEncryption: Map<string, ConnectionEncrypter>
|
|
111
116
|
private readonly muxers: Map<string, StreamMuxerFactory>
|
|
112
117
|
private readonly inboundUpgradeTimeout: number
|
|
118
|
+
private readonly events: EventEmitter<Libp2pEvents>
|
|
113
119
|
|
|
114
120
|
constructor (components: DefaultUpgraderComponents, init: UpgraderInit) {
|
|
115
|
-
super()
|
|
116
|
-
|
|
117
121
|
this.components = components
|
|
118
122
|
this.connectionEncryption = new Map()
|
|
119
123
|
|
|
@@ -128,6 +132,17 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
128
132
|
})
|
|
129
133
|
|
|
130
134
|
this.inboundUpgradeTimeout = init.inboundUpgradeTimeout ?? INBOUND_UPGRADE_TIMEOUT
|
|
135
|
+
this.events = components.events
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async shouldBlockConnection (remotePeer: PeerId, maConn: MultiaddrConnection, connectionType: ConnectionDeniedType): Promise<void> {
|
|
139
|
+
const connectionGater = this.components.connectionGater[connectionType]
|
|
140
|
+
|
|
141
|
+
if (connectionGater !== undefined) {
|
|
142
|
+
if (await connectionGater(remotePeer, maConn)) {
|
|
143
|
+
throw new CodeError(`The multiaddr connection is blocked by gater.${connectionType}`, codes.ERR_CONNECTION_INTERCEPTED)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
131
146
|
}
|
|
132
147
|
|
|
133
148
|
/**
|
|
@@ -140,21 +155,21 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
140
155
|
throw new CodeError('connection denied', codes.ERR_CONNECTION_DENIED)
|
|
141
156
|
}
|
|
142
157
|
|
|
143
|
-
let encryptedConn
|
|
158
|
+
let encryptedConn: EncryptedConn
|
|
144
159
|
let remotePeer
|
|
145
|
-
let upgradedConn: Duplex<Uint8Array
|
|
160
|
+
let upgradedConn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>
|
|
146
161
|
let muxerFactory: StreamMuxerFactory | undefined
|
|
147
162
|
let cryptoProtocol
|
|
148
163
|
|
|
149
|
-
const
|
|
164
|
+
const signal = anySignal([AbortSignal.timeout(this.inboundUpgradeTimeout)])
|
|
150
165
|
|
|
151
166
|
try {
|
|
152
167
|
// fails on node < 15.4
|
|
153
|
-
setMaxListeners?.(Infinity,
|
|
168
|
+
setMaxListeners?.(Infinity, signal)
|
|
154
169
|
} catch { }
|
|
155
170
|
|
|
156
171
|
try {
|
|
157
|
-
const abortableStream = abortableDuplex(maConn,
|
|
172
|
+
const abortableStream = abortableDuplex(maConn, signal)
|
|
158
173
|
maConn.source = abortableStream.source
|
|
159
174
|
maConn.sink = abortableStream.sink
|
|
160
175
|
|
|
@@ -188,12 +203,12 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
188
203
|
protocol: cryptoProtocol
|
|
189
204
|
} = await this._encryptInbound(protectedConn))
|
|
190
205
|
|
|
191
|
-
|
|
206
|
+
const maConn: MultiaddrConnection = {
|
|
192
207
|
...protectedConn,
|
|
193
208
|
...encryptedConn
|
|
194
|
-
})) === true) {
|
|
195
|
-
throw new CodeError('The multiaddr connection is blocked by gater.acceptEncryptedConnection', codes.ERR_CONNECTION_INTERCEPTED)
|
|
196
209
|
}
|
|
210
|
+
|
|
211
|
+
await this.shouldBlockConnection(remotePeer, maConn, 'denyInboundEncryptedConnection')
|
|
197
212
|
} else {
|
|
198
213
|
const idStr = maConn.remoteAddr.getPeerId()
|
|
199
214
|
|
|
@@ -224,12 +239,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
224
239
|
throw err
|
|
225
240
|
}
|
|
226
241
|
|
|
227
|
-
|
|
228
|
-
...protectedConn,
|
|
229
|
-
...encryptedConn
|
|
230
|
-
})) === true) {
|
|
231
|
-
throw new CodeError('The multiaddr connection is blocked by gater.acceptEncryptedConnection', codes.ERR_CONNECTION_INTERCEPTED)
|
|
232
|
-
}
|
|
242
|
+
await this.shouldBlockConnection(remotePeer, maConn, 'denyInboundUpgradedConnection')
|
|
233
243
|
|
|
234
244
|
log('Successfully upgraded inbound connection')
|
|
235
245
|
|
|
@@ -243,7 +253,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
243
253
|
})
|
|
244
254
|
} finally {
|
|
245
255
|
this.components.connectionManager.afterUpgradeInbound()
|
|
246
|
-
|
|
256
|
+
signal.clear()
|
|
247
257
|
}
|
|
248
258
|
}
|
|
249
259
|
|
|
@@ -257,14 +267,12 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
257
267
|
if (idStr != null) {
|
|
258
268
|
remotePeerId = peerIdFromString(idStr)
|
|
259
269
|
|
|
260
|
-
|
|
261
|
-
throw new CodeError('The multiaddr connection is blocked by connectionGater.denyOutboundConnection', codes.ERR_CONNECTION_INTERCEPTED)
|
|
262
|
-
}
|
|
270
|
+
await this.shouldBlockConnection(remotePeerId, maConn, 'denyOutboundConnection')
|
|
263
271
|
}
|
|
264
272
|
|
|
265
273
|
let encryptedConn
|
|
266
274
|
let remotePeer: PeerId
|
|
267
|
-
let upgradedConn
|
|
275
|
+
let upgradedConn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>
|
|
268
276
|
let cryptoProtocol
|
|
269
277
|
let muxerFactory
|
|
270
278
|
|
|
@@ -295,12 +303,12 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
295
303
|
protocol: cryptoProtocol
|
|
296
304
|
} = await this._encryptOutbound(protectedConn, remotePeerId))
|
|
297
305
|
|
|
298
|
-
|
|
306
|
+
const maConn: MultiaddrConnection = {
|
|
299
307
|
...protectedConn,
|
|
300
308
|
...encryptedConn
|
|
301
|
-
})) === true) {
|
|
302
|
-
throw new CodeError('The multiaddr connection is blocked by gater.acceptEncryptedConnection', codes.ERR_CONNECTION_INTERCEPTED)
|
|
303
309
|
}
|
|
310
|
+
|
|
311
|
+
await this.shouldBlockConnection(remotePeer, maConn, 'denyOutboundEncryptedConnection')
|
|
304
312
|
} else {
|
|
305
313
|
if (remotePeerId == null) {
|
|
306
314
|
throw new CodeError('Encryption was skipped but no peer id was passed', codes.ERR_INVALID_PEER)
|
|
@@ -328,12 +336,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
328
336
|
throw err
|
|
329
337
|
}
|
|
330
338
|
|
|
331
|
-
|
|
332
|
-
...protectedConn,
|
|
333
|
-
...encryptedConn
|
|
334
|
-
})) === true) {
|
|
335
|
-
throw new CodeError('The multiaddr connection is blocked by gater.acceptEncryptedConnection', codes.ERR_CONNECTION_INTERCEPTED)
|
|
336
|
-
}
|
|
339
|
+
await this.shouldBlockConnection(remotePeer, maConn, 'denyOutboundUpgradedConnection')
|
|
337
340
|
|
|
338
341
|
log('Successfully upgraded outbound connection')
|
|
339
342
|
|
|
@@ -350,7 +353,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
350
353
|
/**
|
|
351
354
|
* A convenience method for generating a new `Connection`
|
|
352
355
|
*/
|
|
353
|
-
_createConnection (opts:
|
|
356
|
+
_createConnection (opts: CreateConnectionOptions): Connection {
|
|
354
357
|
const {
|
|
355
358
|
cryptoProtocol,
|
|
356
359
|
direction,
|
|
@@ -388,9 +391,10 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
388
391
|
const streamCount = countStreams(protocol, 'inbound', connection)
|
|
389
392
|
|
|
390
393
|
if (streamCount === incomingLimit) {
|
|
391
|
-
|
|
394
|
+
const err = new CodeError(`Too many inbound protocol streams for protocol "${protocol}" - limit ${incomingLimit}`, codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS)
|
|
395
|
+
muxedStream.abort(err)
|
|
392
396
|
|
|
393
|
-
|
|
397
|
+
throw err
|
|
394
398
|
}
|
|
395
399
|
|
|
396
400
|
// after the handshake the returned stream can have early data so override
|
|
@@ -401,7 +405,9 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
401
405
|
|
|
402
406
|
// If a protocol stream has been successfully negotiated and is to be passed to the application,
|
|
403
407
|
// the peerstore should ensure that the peer is registered with that protocol
|
|
404
|
-
this.components.peerStore.
|
|
408
|
+
await this.components.peerStore.merge(remotePeer, {
|
|
409
|
+
protocols: [protocol]
|
|
410
|
+
})
|
|
405
411
|
|
|
406
412
|
connection.addStream(muxedStream)
|
|
407
413
|
this.components.metrics?.trackProtocolStream(muxedStream, connection)
|
|
@@ -429,18 +435,16 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
429
435
|
|
|
430
436
|
log('%s: starting new stream on %s', direction, protocols)
|
|
431
437
|
const muxedStream = await muxer.newStream()
|
|
432
|
-
let controller: TimeoutController | undefined
|
|
433
438
|
|
|
434
439
|
try {
|
|
435
440
|
if (options.signal == null) {
|
|
436
441
|
log('No abort signal was passed while trying to negotiate protocols %s falling back to default timeout', protocols)
|
|
437
442
|
|
|
438
|
-
|
|
439
|
-
options.signal = controller.signal
|
|
443
|
+
options.signal = AbortSignal.timeout(30000)
|
|
440
444
|
|
|
441
445
|
try {
|
|
442
446
|
// fails on node < 15.4
|
|
443
|
-
setMaxListeners?.(Infinity,
|
|
447
|
+
setMaxListeners?.(Infinity, options.signal)
|
|
444
448
|
} catch { }
|
|
445
449
|
}
|
|
446
450
|
|
|
@@ -458,7 +462,9 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
458
462
|
|
|
459
463
|
// If a protocol stream has been successfully negotiated and is to be passed to the application,
|
|
460
464
|
// the peerstore should ensure that the peer is registered with that protocol
|
|
461
|
-
this.components.peerStore.
|
|
465
|
+
await this.components.peerStore.merge(remotePeer, {
|
|
466
|
+
protocols: [protocol]
|
|
467
|
+
})
|
|
462
468
|
|
|
463
469
|
// after the handshake the returned stream can have early data so override
|
|
464
470
|
// the souce/sink
|
|
@@ -481,10 +487,6 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
481
487
|
}
|
|
482
488
|
|
|
483
489
|
throw new CodeError(String(err), codes.ERR_UNSUPPORTED_PROTOCOL)
|
|
484
|
-
} finally {
|
|
485
|
-
if (controller != null) {
|
|
486
|
-
controller.clear()
|
|
487
|
-
}
|
|
488
490
|
}
|
|
489
491
|
}
|
|
490
492
|
|
|
@@ -510,9 +512,9 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
510
512
|
} catch (err: any) {
|
|
511
513
|
log.error(err)
|
|
512
514
|
} finally {
|
|
513
|
-
this.
|
|
515
|
+
this.events.safeDispatchEvent('connection:close', {
|
|
514
516
|
detail: connection
|
|
515
|
-
})
|
|
517
|
+
})
|
|
516
518
|
}
|
|
517
519
|
})().catch(err => {
|
|
518
520
|
log.error(err)
|
|
@@ -550,9 +552,9 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
550
552
|
}
|
|
551
553
|
})
|
|
552
554
|
|
|
553
|
-
this.
|
|
555
|
+
this.events.safeDispatchEvent('connection:open', {
|
|
554
556
|
detail: connection
|
|
555
|
-
})
|
|
557
|
+
})
|
|
556
558
|
|
|
557
559
|
return connection
|
|
558
560
|
}
|
|
@@ -570,7 +572,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
570
572
|
/**
|
|
571
573
|
* Attempts to encrypt the incoming `connection` with the provided `cryptos`
|
|
572
574
|
*/
|
|
573
|
-
async _encryptInbound (connection: Duplex<Uint8Array
|
|
575
|
+
async _encryptInbound (connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>>): Promise<CryptoResult> {
|
|
574
576
|
const protocols = Array.from(this.connectionEncryption.keys())
|
|
575
577
|
log('handling inbound crypto protocol selection', protocols)
|
|
576
578
|
|
|
@@ -628,7 +630,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
628
630
|
* Selects one of the given muxers via multistream-select. That
|
|
629
631
|
* muxer will be used for all future streams on the connection.
|
|
630
632
|
*/
|
|
631
|
-
async _multiplexOutbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<Uint8Array>, muxerFactory?: StreamMuxerFactory }> {
|
|
633
|
+
async _multiplexOutbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, muxerFactory?: StreamMuxerFactory }> {
|
|
632
634
|
const protocols = Array.from(muxers.keys())
|
|
633
635
|
log('outbound selecting muxer %s', protocols)
|
|
634
636
|
try {
|
|
@@ -637,6 +639,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
637
639
|
})
|
|
638
640
|
log('%s selected as muxer protocol', protocol)
|
|
639
641
|
const muxerFactory = muxers.get(protocol)
|
|
642
|
+
|
|
640
643
|
return { stream, muxerFactory }
|
|
641
644
|
} catch (err: any) {
|
|
642
645
|
log.error('error multiplexing outbound stream', err)
|
|
@@ -648,7 +651,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
648
651
|
* Registers support for one of the given muxers via multistream-select. The
|
|
649
652
|
* selected muxer will be used for all future streams on the connection.
|
|
650
653
|
*/
|
|
651
|
-
async _multiplexInbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<Uint8Array>, muxerFactory?: StreamMuxerFactory }> {
|
|
654
|
+
async _multiplexInbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, muxerFactory?: StreamMuxerFactory }> {
|
|
652
655
|
const protocols = Array.from(muxers.keys())
|
|
653
656
|
log('inbound handling muxers %s', protocols)
|
|
654
657
|
try {
|
|
@@ -656,6 +659,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
656
659
|
writeBytes: true
|
|
657
660
|
})
|
|
658
661
|
const muxerFactory = muxers.get(protocol)
|
|
662
|
+
|
|
659
663
|
return { stream, muxerFactory }
|
|
660
664
|
} catch (err: any) {
|
|
661
665
|
log.error('error multiplexing inbound stream', err)
|
|
@@ -3,16 +3,16 @@ import { logger } from '@libp2p/logger'
|
|
|
3
3
|
import { fromNodeAddress } from '@multiformats/multiaddr'
|
|
4
4
|
import { isBrowser } from 'wherearewe'
|
|
5
5
|
import isPrivateIp from 'private-ip'
|
|
6
|
-
import * as pkg from '
|
|
6
|
+
import * as pkg from '../version.js'
|
|
7
7
|
import { CodeError } from '@libp2p/interfaces/errors'
|
|
8
|
-
import { codes } from '
|
|
8
|
+
import { codes } from '../errors.js'
|
|
9
9
|
import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback'
|
|
10
10
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
11
11
|
import type { TransportManager } from '@libp2p/interface-transport'
|
|
12
12
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
13
13
|
import type { AddressManager } from '@libp2p/interface-address-manager'
|
|
14
14
|
|
|
15
|
-
const log = logger('libp2p:nat')
|
|
15
|
+
const log = logger('libp2p:upnp-nat')
|
|
16
16
|
const DEFAULT_TTL = 7200
|
|
17
17
|
|
|
18
18
|
function highPort (min = 1024, max = 65535): number {
|
|
@@ -26,12 +26,7 @@ export interface PMPOptions {
|
|
|
26
26
|
enabled?: boolean
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export interface
|
|
30
|
-
/**
|
|
31
|
-
* Whether to enable the NAT manager
|
|
32
|
-
*/
|
|
33
|
-
enabled: boolean
|
|
34
|
-
|
|
29
|
+
export interface UPnPNATInit {
|
|
35
30
|
/**
|
|
36
31
|
* Pass a value to use instead of auto-detection
|
|
37
32
|
*/
|
|
@@ -55,7 +50,7 @@ export interface NatManagerInit {
|
|
|
55
50
|
/**
|
|
56
51
|
* Whether to automatically refresh UPnP port mappings when their TTL is reached
|
|
57
52
|
*/
|
|
58
|
-
keepAlive
|
|
53
|
+
keepAlive?: boolean
|
|
59
54
|
|
|
60
55
|
/**
|
|
61
56
|
* Pass a value to use instead of auto-detection
|
|
@@ -63,15 +58,14 @@ export interface NatManagerInit {
|
|
|
63
58
|
gateway?: string
|
|
64
59
|
}
|
|
65
60
|
|
|
66
|
-
export interface
|
|
61
|
+
export interface UPnPNATComponents {
|
|
67
62
|
peerId: PeerId
|
|
68
63
|
transportManager: TransportManager
|
|
69
64
|
addressManager: AddressManager
|
|
70
65
|
}
|
|
71
66
|
|
|
72
|
-
|
|
73
|
-
private readonly components:
|
|
74
|
-
private readonly enabled: boolean
|
|
67
|
+
class UPnPNAT implements Startable {
|
|
68
|
+
private readonly components: UPnPNATComponents
|
|
75
69
|
private readonly externalAddress?: string
|
|
76
70
|
private readonly localAddress?: string
|
|
77
71
|
private readonly description: string
|
|
@@ -81,11 +75,10 @@ export class NatManager implements Startable {
|
|
|
81
75
|
private started: boolean
|
|
82
76
|
private client?: NatAPI
|
|
83
77
|
|
|
84
|
-
constructor (components:
|
|
78
|
+
constructor (components: UPnPNATComponents, init: UPnPNATInit) {
|
|
85
79
|
this.components = components
|
|
86
80
|
|
|
87
81
|
this.started = false
|
|
88
|
-
this.enabled = init.enabled
|
|
89
82
|
this.externalAddress = init.externalAddress
|
|
90
83
|
this.localAddress = init.localAddress
|
|
91
84
|
this.description = init.description ?? `${pkg.name}@${pkg.version} ${this.components.peerId.toString()}`
|
|
@@ -112,7 +105,7 @@ export class NatManager implements Startable {
|
|
|
112
105
|
* Run after start to ensure the transport manager has all addresses configured.
|
|
113
106
|
*/
|
|
114
107
|
afterStart (): void {
|
|
115
|
-
if (isBrowser ||
|
|
108
|
+
if (isBrowser || this.started) {
|
|
116
109
|
return
|
|
117
110
|
}
|
|
118
111
|
|
|
@@ -211,3 +204,9 @@ export class NatManager implements Startable {
|
|
|
211
204
|
}
|
|
212
205
|
}
|
|
213
206
|
}
|
|
207
|
+
|
|
208
|
+
export function uPnPNATService (init: UPnPNATInit = {}): (components: UPnPNATComponents) => {} {
|
|
209
|
+
return (components: UPnPNATComponents) => {
|
|
210
|
+
return new UPnPNAT(components, init)
|
|
211
|
+
}
|
|
212
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '0.
|
|
1
|
+
export const version = '0.45.0'
|
|
2
2
|
export const name = 'libp2p'
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { DHT } from '@libp2p/interface-dht';
|
|
2
|
-
import type { ContentRouting } from '@libp2p/interface-content-routing';
|
|
3
|
-
import type { CID } from 'multiformats/cid';
|
|
4
|
-
import type { AbortOptions } from '@libp2p/interfaces';
|
|
5
|
-
import type { PeerInfo } from '@libp2p/interface-peer-info';
|
|
6
|
-
/**
|
|
7
|
-
* Wrapper class to convert events into returned values
|
|
8
|
-
*/
|
|
9
|
-
export declare class DHTContentRouting implements ContentRouting {
|
|
10
|
-
private readonly dht;
|
|
11
|
-
constructor(dht: DHT);
|
|
12
|
-
provide(cid: CID): Promise<void>;
|
|
13
|
-
findProviders(cid: CID, options?: AbortOptions): AsyncGenerator<PeerInfo, void, undefined>;
|
|
14
|
-
put(key: Uint8Array, value: Uint8Array, options?: AbortOptions): Promise<void>;
|
|
15
|
-
get(key: Uint8Array, options?: AbortOptions): Promise<Uint8Array>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=dht-content-routing.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dht-content-routing.d.ts","sourceRoot":"","sources":["../../../src/dht/dht-content-routing.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAE3D;;GAEG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IACtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEZ,GAAG,EAAE,GAAG;IAIf,OAAO,CAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/B,aAAa,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAiB,GAAG,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAC;IAQjG,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/E,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;CASzE"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import drain from 'it-drain';
|
|
2
|
-
import { CodeError } from '@libp2p/interfaces/errors';
|
|
3
|
-
/**
|
|
4
|
-
* Wrapper class to convert events into returned values
|
|
5
|
-
*/
|
|
6
|
-
export class DHTContentRouting {
|
|
7
|
-
constructor(dht) {
|
|
8
|
-
this.dht = dht;
|
|
9
|
-
}
|
|
10
|
-
async provide(cid) {
|
|
11
|
-
await drain(this.dht.provide(cid));
|
|
12
|
-
}
|
|
13
|
-
async *findProviders(cid, options = {}) {
|
|
14
|
-
for await (const event of this.dht.findProviders(cid, options)) {
|
|
15
|
-
if (event.name === 'PROVIDER') {
|
|
16
|
-
yield* event.providers;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
async put(key, value, options) {
|
|
21
|
-
await drain(this.dht.put(key, value, options));
|
|
22
|
-
}
|
|
23
|
-
async get(key, options) {
|
|
24
|
-
for await (const event of this.dht.get(key, options)) {
|
|
25
|
-
if (event.name === 'VALUE') {
|
|
26
|
-
return event.value;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
throw new CodeError('Not found', 'ERR_NOT_FOUND');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=dht-content-routing.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dht-content-routing.js","sourceRoot":"","sources":["../../../src/dht/dht-content-routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAOrD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAG5B,YAAa,GAAQ;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,KAAK,CAAC,OAAO,CAAE,GAAQ;QACrB,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,CAAE,aAAa,CAAE,GAAQ,EAAE,UAAwB,EAAE;QACzD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE;YAC9D,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE;gBAC7B,KAAM,CAAC,CAAC,KAAK,CAAC,SAAS,CAAA;aACxB;SACF;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,GAAe,EAAE,KAAiB,EAAE,OAAsB;QACnE,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAA;IAChD,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,GAAe,EAAE,OAAsB;QAChD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE;YACpD,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;gBAC1B,OAAO,KAAK,CAAC,KAAK,CAAA;aACnB;SACF;QAED,MAAM,IAAI,SAAS,CAAC,WAAW,EAAE,eAAe,CAAC,CAAA;IACnD,CAAC;CACF"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { PeerRouting } from '@libp2p/interface-peer-routing';
|
|
2
|
-
import type { DHT } from '@libp2p/interface-dht';
|
|
3
|
-
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
4
|
-
import type { AbortOptions } from '@libp2p/interfaces';
|
|
5
|
-
import type { PeerInfo } from '@libp2p/interface-peer-info';
|
|
6
|
-
/**
|
|
7
|
-
* Wrapper class to convert events into returned values
|
|
8
|
-
*/
|
|
9
|
-
export declare class DHTPeerRouting implements PeerRouting {
|
|
10
|
-
private readonly dht;
|
|
11
|
-
constructor(dht: DHT);
|
|
12
|
-
findPeer(peerId: PeerId, options?: AbortOptions): Promise<PeerInfo>;
|
|
13
|
-
getClosestPeers(key: Uint8Array, options?: AbortOptions): AsyncIterable<PeerInfo>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=dht-peer-routing.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dht-peer-routing.d.ts","sourceRoot":"","sources":["../../../src/dht/dht-peer-routing.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAE3D;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEZ,GAAG,EAAE,GAAG;IAIf,QAAQ,CAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAUtE,eAAe,CAAE,GAAG,EAAE,UAAU,EAAE,OAAO,GAAE,YAAiB,GAAG,aAAa,CAAC,QAAQ,CAAC;CAO/F"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interfaces/errors';
|
|
2
|
-
import { messages, codes } from '../errors.js';
|
|
3
|
-
/**
|
|
4
|
-
* Wrapper class to convert events into returned values
|
|
5
|
-
*/
|
|
6
|
-
export class DHTPeerRouting {
|
|
7
|
-
constructor(dht) {
|
|
8
|
-
this.dht = dht;
|
|
9
|
-
}
|
|
10
|
-
async findPeer(peerId, options = {}) {
|
|
11
|
-
for await (const event of this.dht.findPeer(peerId, options)) {
|
|
12
|
-
if (event.name === 'FINAL_PEER') {
|
|
13
|
-
return event.peer;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
throw new CodeError(messages.NOT_FOUND, codes.ERR_NOT_FOUND);
|
|
17
|
-
}
|
|
18
|
-
async *getClosestPeers(key, options = {}) {
|
|
19
|
-
for await (const event of this.dht.getClosestPeers(key, options)) {
|
|
20
|
-
if (event.name === 'FINAL_PEER') {
|
|
21
|
-
yield event.peer;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=dht-peer-routing.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dht-peer-routing.js","sourceRoot":"","sources":["../../../src/dht/dht-peer-routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAO9C;;GAEG;AACH,MAAM,OAAO,cAAc;IAGzB,YAAa,GAAQ;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAE,MAAc,EAAE,UAAwB,EAAE;QACxD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;YAC5D,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;gBAC/B,OAAO,KAAK,CAAC,IAAI,CAAA;aAClB;SACF;QAED,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IAC9D,CAAC;IAED,KAAK,CAAC,CAAE,eAAe,CAAE,GAAe,EAAE,UAAwB,EAAE;QAClE,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE;YAChE,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;gBAC/B,MAAM,KAAK,CAAC,IAAI,CAAA;aACjB;SACF;IACH,CAAC;CACF"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { DualDHT, QueryEvent, SingleDHT } from '@libp2p/interface-dht';
|
|
2
|
-
import type { PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery';
|
|
3
|
-
import { EventEmitter } from '@libp2p/interfaces/events';
|
|
4
|
-
import { symbol } from '@libp2p/interface-peer-discovery';
|
|
5
|
-
export declare class DummyDHT extends EventEmitter<PeerDiscoveryEvents> implements DualDHT {
|
|
6
|
-
get [symbol](): true;
|
|
7
|
-
get [Symbol.toStringTag](): '@libp2p/dummy-dht';
|
|
8
|
-
get wan(): SingleDHT;
|
|
9
|
-
get lan(): SingleDHT;
|
|
10
|
-
get(): AsyncIterable<QueryEvent>;
|
|
11
|
-
findProviders(): AsyncIterable<QueryEvent>;
|
|
12
|
-
findPeer(): AsyncIterable<QueryEvent>;
|
|
13
|
-
getClosestPeers(): AsyncIterable<QueryEvent>;
|
|
14
|
-
provide(): AsyncIterable<QueryEvent>;
|
|
15
|
-
put(): AsyncIterable<QueryEvent>;
|
|
16
|
-
getMode(): Promise<'client' | 'server'>;
|
|
17
|
-
setMode(): Promise<void>;
|
|
18
|
-
refreshRoutingTable(): Promise<void>;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=dummy-dht.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dummy-dht.d.ts","sourceRoot":"","sources":["../../../src/dht/dummy-dht.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAG3E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AAEzD,qBAAa,QAAS,SAAQ,YAAY,CAAC,mBAAmB,CAAE,YAAW,OAAO;IAChF,IAAI,CAAC,MAAM,CAAC,IAAK,IAAI,CAEpB;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAK,mBAAmB,CAE/C;IAED,IAAI,GAAG,IAAK,SAAS,CAEpB;IAED,IAAI,GAAG,IAAK,SAAS,CAEpB;IAED,GAAG,IAAK,aAAa,CAAC,UAAU,CAAC;IAIjC,aAAa,IAAK,aAAa,CAAC,UAAU,CAAC;IAI3C,QAAQ,IAAK,aAAa,CAAC,UAAU,CAAC;IAItC,eAAe,IAAK,aAAa,CAAC,UAAU,CAAC;IAI7C,OAAO,IAAK,aAAa,CAAC,UAAU,CAAC;IAIrC,GAAG,IAAK,aAAa,CAAC,UAAU,CAAC;IAI3B,OAAO,IAAK,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAIxC,OAAO,IAAK,OAAO,CAAC,IAAI,CAAC;IAIzB,mBAAmB,IAAK,OAAO,CAAC,IAAI,CAAC;CAG5C"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interfaces/errors';
|
|
2
|
-
import { messages, codes } from '../errors.js';
|
|
3
|
-
import { EventEmitter } from '@libp2p/interfaces/events';
|
|
4
|
-
import { symbol } from '@libp2p/interface-peer-discovery';
|
|
5
|
-
export class DummyDHT extends EventEmitter {
|
|
6
|
-
get [symbol]() {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
get [Symbol.toStringTag]() {
|
|
10
|
-
return '@libp2p/dummy-dht';
|
|
11
|
-
}
|
|
12
|
-
get wan() {
|
|
13
|
-
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED);
|
|
14
|
-
}
|
|
15
|
-
get lan() {
|
|
16
|
-
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED);
|
|
17
|
-
}
|
|
18
|
-
get() {
|
|
19
|
-
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED);
|
|
20
|
-
}
|
|
21
|
-
findProviders() {
|
|
22
|
-
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED);
|
|
23
|
-
}
|
|
24
|
-
findPeer() {
|
|
25
|
-
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED);
|
|
26
|
-
}
|
|
27
|
-
getClosestPeers() {
|
|
28
|
-
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED);
|
|
29
|
-
}
|
|
30
|
-
provide() {
|
|
31
|
-
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED);
|
|
32
|
-
}
|
|
33
|
-
put() {
|
|
34
|
-
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED);
|
|
35
|
-
}
|
|
36
|
-
async getMode() {
|
|
37
|
-
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED);
|
|
38
|
-
}
|
|
39
|
-
async setMode() {
|
|
40
|
-
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED);
|
|
41
|
-
}
|
|
42
|
-
async refreshRoutingTable() {
|
|
43
|
-
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=dummy-dht.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dummy-dht.js","sourceRoot":"","sources":["../../../src/dht/dummy-dht.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AAEzD,MAAM,OAAO,QAAS,SAAQ,YAAiC;IAC7D,IAAI,CAAC,MAAM,CAAC;QACV,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,mBAAmB,CAAA;IAC5B,CAAC;IAED,IAAI,GAAG;QACL,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAChE,CAAC;IAED,IAAI,GAAG;QACL,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAChE,CAAC;IAED,GAAG;QACD,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAChE,CAAC;IAED,aAAa;QACX,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAChE,CAAC;IAED,QAAQ;QACN,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAChE,CAAC;IAED,eAAe;QACb,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAChE,CAAC;IAED,OAAO;QACL,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAChE,CAAC;IAED,GAAG;QACD,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAChE,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAChE,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAChE,CAAC;IAED,KAAK,CAAC,mBAAmB;QACvB,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAChE,CAAC;CACF"}
|