libp2p 0.44.0-cd67b7d8 → 0.44.0-ceed8d89
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 +19 -19
- package/dist/src/address-manager/index.d.ts +4 -0
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +32 -4
- 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/index.d.ts +5 -5
- package/dist/src/autonat/index.js +4 -4
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dial.js +10 -1
- package/dist/src/connection-manager/auto-dial.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +7 -2
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/transport-manager.d.ts +0 -4
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +4 -20
- package/dist/src/transport-manager.js.map +1 -1
- 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/package.json +3 -3
- package/src/address-manager/index.ts +42 -4
- package/src/address-manager/utils.ts +14 -0
- package/src/autonat/index.ts +10 -10
- package/src/connection-manager/auto-dial.ts +12 -1
- package/src/connection-manager/dial-queue.ts +9 -2
- package/src/transport-manager.ts +4 -24
- package/src/version.ts +1 -1
package/src/autonat/index.ts
CHANGED
|
@@ -34,7 +34,7 @@ const log = logger('libp2p:autonat')
|
|
|
34
34
|
// https://github.com/libp2p/specs/blob/master/autonat/README.md#autonat-protocol
|
|
35
35
|
const REQUIRED_SUCCESSFUL_DIALS = 4
|
|
36
36
|
|
|
37
|
-
export interface
|
|
37
|
+
export interface AutoNATServiceInit {
|
|
38
38
|
/**
|
|
39
39
|
* Allows overriding the protocol prefix used
|
|
40
40
|
*/
|
|
@@ -56,17 +56,17 @@ export interface AutonatServiceInit {
|
|
|
56
56
|
refreshInterval?: number
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* How many parallel inbound
|
|
59
|
+
* How many parallel inbound autoNAT streams we allow per-connection
|
|
60
60
|
*/
|
|
61
61
|
maxInboundStreams?: number
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
* How many parallel outbound
|
|
64
|
+
* How many parallel outbound autoNAT streams we allow per-connection
|
|
65
65
|
*/
|
|
66
66
|
maxOutboundStreams?: number
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export interface
|
|
69
|
+
export interface AutoNATComponents {
|
|
70
70
|
registrar: Registrar
|
|
71
71
|
addressManager: AddressManager
|
|
72
72
|
transportManager: TransportManager
|
|
@@ -75,8 +75,8 @@ export interface AutonatComponents {
|
|
|
75
75
|
peerRouting: PeerRouting
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
class
|
|
79
|
-
private readonly components:
|
|
78
|
+
class DefaultAutoNATService implements Startable {
|
|
79
|
+
private readonly components: AutoNATComponents
|
|
80
80
|
private readonly startupDelay: number
|
|
81
81
|
private readonly refreshInterval: number
|
|
82
82
|
private readonly protocol: string
|
|
@@ -86,7 +86,7 @@ class DefaultAutonatService implements Startable {
|
|
|
86
86
|
private verifyAddressTimeout?: ReturnType<typeof setTimeout>
|
|
87
87
|
private started: boolean
|
|
88
88
|
|
|
89
|
-
constructor (components:
|
|
89
|
+
constructor (components: AutoNATComponents, init: AutoNATServiceInit) {
|
|
90
90
|
this.components = components
|
|
91
91
|
this.started = false
|
|
92
92
|
this.protocol = `/${init.protocolPrefix ?? PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`
|
|
@@ -130,7 +130,7 @@ class DefaultAutonatService implements Startable {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
|
-
* Handle an incoming
|
|
133
|
+
* Handle an incoming AutoNAT request
|
|
134
134
|
*/
|
|
135
135
|
async handleIncomingAutonatStream (data: IncomingStreamData): Promise<void> {
|
|
136
136
|
const signal = anySignal([AbortSignal.timeout(this.timeout)])
|
|
@@ -565,8 +565,8 @@ class DefaultAutonatService implements Startable {
|
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
567
|
|
|
568
|
-
export function
|
|
568
|
+
export function autoNATService (init: AutoNATServiceInit = {}): (components: AutoNATComponents) => {} {
|
|
569
569
|
return (components) => {
|
|
570
|
-
return new
|
|
570
|
+
return new DefaultAutoNATService(components, init)
|
|
571
571
|
}
|
|
572
572
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
2
|
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
3
3
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
4
|
-
import { PeerMap } from '@libp2p/peer-collections'
|
|
4
|
+
import { PeerMap, PeerSet } from '@libp2p/peer-collections'
|
|
5
5
|
import PQueue from 'p-queue'
|
|
6
6
|
import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_INTERVAL, AUTO_DIAL_PRIORITY, MIN_CONNECTIONS } from './constants.js'
|
|
7
7
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
@@ -103,6 +103,12 @@ export class AutoDial implements Startable {
|
|
|
103
103
|
|
|
104
104
|
const connections = this.connectionManager.getConnectionsMap()
|
|
105
105
|
const numConnections = connections.size
|
|
106
|
+
const dialQueue = new PeerSet(
|
|
107
|
+
// @ts-expect-error boolean filter removes falsy peer IDs
|
|
108
|
+
this.connectionManager.getDialQueue()
|
|
109
|
+
.map(queue => queue.peerId)
|
|
110
|
+
.filter(Boolean)
|
|
111
|
+
)
|
|
106
112
|
|
|
107
113
|
// Already has enough connections
|
|
108
114
|
if (numConnections >= this.minConnections) {
|
|
@@ -127,6 +133,11 @@ export class AutoDial implements Startable {
|
|
|
127
133
|
return false
|
|
128
134
|
}
|
|
129
135
|
|
|
136
|
+
// remove peers we are already dialling
|
|
137
|
+
if (dialQueue.has(peer.id)) {
|
|
138
|
+
return false
|
|
139
|
+
}
|
|
140
|
+
|
|
130
141
|
return true
|
|
131
142
|
})
|
|
132
143
|
|
|
@@ -238,7 +238,7 @@ export class DialQueue {
|
|
|
238
238
|
signal.clear()
|
|
239
239
|
})
|
|
240
240
|
.catch(err => {
|
|
241
|
-
log.error('dial failed to %s',
|
|
241
|
+
log.error('dial failed to %s', pendingDial.multiaddrs.map(ma => ma.toString()).join(', '), err)
|
|
242
242
|
|
|
243
243
|
// Error is a timeout
|
|
244
244
|
if (signal.aborted) {
|
|
@@ -384,7 +384,14 @@ export class DialQueue {
|
|
|
384
384
|
gatedAdrs.push(addr)
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
-
|
|
387
|
+
const sortedGatedAddrs = gatedAdrs.sort(this.addressSorter)
|
|
388
|
+
|
|
389
|
+
// make sure we actually have some addresses to dial
|
|
390
|
+
if (sortedGatedAddrs.length === 0) {
|
|
391
|
+
throw new CodeError('The connection gater denied all addresses in the dial request', codes.ERR_NO_VALID_ADDRESSES)
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return sortedGatedAddrs
|
|
388
395
|
}
|
|
389
396
|
|
|
390
397
|
private async performDial (pendingDial: PendingDial, options: DialOptions = {}): Promise<Connection> {
|
package/src/transport-manager.ts
CHANGED
|
@@ -12,8 +12,6 @@ import { trackedMap } from '@libp2p/tracked-map'
|
|
|
12
12
|
import type { Metrics } from '@libp2p/interface-metrics'
|
|
13
13
|
import type { AddressManager } from '@libp2p/interface-address-manager'
|
|
14
14
|
import type { Libp2pEvents } from '@libp2p/interface-libp2p'
|
|
15
|
-
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
16
|
-
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
17
15
|
|
|
18
16
|
const log = logger('libp2p:transports')
|
|
19
17
|
|
|
@@ -26,8 +24,6 @@ export interface DefaultTransportManagerComponents {
|
|
|
26
24
|
addressManager: AddressManager
|
|
27
25
|
upgrader: Upgrader
|
|
28
26
|
events: EventEmitter<Libp2pEvents>
|
|
29
|
-
peerId: PeerId
|
|
30
|
-
peerStore: PeerStore
|
|
31
27
|
}
|
|
32
28
|
|
|
33
29
|
export class DefaultTransportManager implements TransportManager, Startable {
|
|
@@ -210,17 +206,9 @@ export class DefaultTransportManager implements TransportManager, Startable {
|
|
|
210
206
|
|
|
211
207
|
// Track listen/close events
|
|
212
208
|
listener.addEventListener('listening', () => {
|
|
213
|
-
this.components.
|
|
214
|
-
|
|
209
|
+
this.components.events.safeDispatchEvent('transport:listening', {
|
|
210
|
+
detail: listener
|
|
215
211
|
})
|
|
216
|
-
.then(() => {
|
|
217
|
-
this.components.events.safeDispatchEvent('transport:listening', {
|
|
218
|
-
detail: listener
|
|
219
|
-
})
|
|
220
|
-
})
|
|
221
|
-
.catch(err => {
|
|
222
|
-
log.error('error while updating peer record after listener began listening', err)
|
|
223
|
-
})
|
|
224
212
|
})
|
|
225
213
|
listener.addEventListener('close', () => {
|
|
226
214
|
const index = listeners.findIndex(l => l === listener)
|
|
@@ -228,17 +216,9 @@ export class DefaultTransportManager implements TransportManager, Startable {
|
|
|
228
216
|
// remove the listener
|
|
229
217
|
listeners.splice(index, 1)
|
|
230
218
|
|
|
231
|
-
this.components.
|
|
232
|
-
|
|
219
|
+
this.components.events.safeDispatchEvent('transport:close', {
|
|
220
|
+
detail: listener
|
|
233
221
|
})
|
|
234
|
-
.then(() => {
|
|
235
|
-
this.components.events.safeDispatchEvent('transport:close', {
|
|
236
|
-
detail: listener
|
|
237
|
-
})
|
|
238
|
-
})
|
|
239
|
-
.catch(err => {
|
|
240
|
-
log.error('error while updating peer record after listener stopped listening', err)
|
|
241
|
-
})
|
|
242
222
|
})
|
|
243
223
|
|
|
244
224
|
// We need to attempt to listen on everything
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '0.44.0-
|
|
1
|
+
export const version = '0.44.0-ceed8d89'
|
|
2
2
|
export const name = 'libp2p'
|