libp2p 2.3.0 → 2.3.1-06f79b646
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 +9 -25
- package/dist/index.min.js +16 -13
- package/dist/src/address-manager.d.ts +23 -4
- package/dist/src/address-manager.d.ts.map +1 -1
- package/dist/src/address-manager.js +119 -21
- package/dist/src/address-manager.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts +7 -3
- package/dist/src/config/connection-gater.browser.d.ts.map +1 -1
- package/dist/src/config/connection-gater.browser.js +16 -4
- package/dist/src/config/connection-gater.browser.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts +3 -3
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +6 -13
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/version.d.ts +2 -2
- package/dist/src/version.d.ts.map +1 -1
- package/dist/src/version.js +2 -2
- package/dist/src/version.js.map +1 -1
- package/package.json +26 -25
- package/src/address-manager.ts +164 -29
- package/src/config/connection-gater.browser.ts +18 -4
- package/src/connection-manager/dial-queue.ts +12 -19
- package/src/version.ts +2 -2
- package/LICENSE +0 -4
- package/dist/typedoc-urls.json +0 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1-06f79b646",
|
|
4
4
|
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/libp2p#readme",
|
|
@@ -85,46 +85,47 @@
|
|
|
85
85
|
"test:webkit": "aegir test -t browser -- --browser webkit"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@
|
|
89
|
-
"@libp2p/
|
|
90
|
-
"@libp2p/interface
|
|
91
|
-
"@libp2p/
|
|
92
|
-
"@libp2p/
|
|
93
|
-
"@libp2p/
|
|
94
|
-
"@libp2p/peer-
|
|
95
|
-
"@libp2p/peer-
|
|
96
|
-
"@libp2p/
|
|
88
|
+
"@chainsafe/is-ip": "^2.0.2",
|
|
89
|
+
"@libp2p/crypto": "5.0.7-06f79b646",
|
|
90
|
+
"@libp2p/interface": "2.2.1-06f79b646",
|
|
91
|
+
"@libp2p/interface-internal": "2.1.1-06f79b646",
|
|
92
|
+
"@libp2p/logger": "5.1.4-06f79b646",
|
|
93
|
+
"@libp2p/multistream-select": "6.0.9-06f79b646",
|
|
94
|
+
"@libp2p/peer-collections": "6.0.12-06f79b646",
|
|
95
|
+
"@libp2p/peer-id": "5.0.8-06f79b646",
|
|
96
|
+
"@libp2p/peer-store": "11.0.12-06f79b646",
|
|
97
|
+
"@libp2p/utils": "6.2.1-06f79b646",
|
|
97
98
|
"@multiformats/dns": "^1.0.6",
|
|
98
|
-
"@multiformats/multiaddr": "^12.
|
|
99
|
-
"@multiformats/multiaddr-matcher": "^1.
|
|
99
|
+
"@multiformats/multiaddr": "^12.3.3",
|
|
100
|
+
"@multiformats/multiaddr-matcher": "^1.6.0",
|
|
100
101
|
"any-signal": "^4.1.1",
|
|
101
|
-
"datastore-core": "^10.0.
|
|
102
|
-
"interface-datastore": "^8.3.
|
|
103
|
-
"it-byte-stream": "^1.0
|
|
102
|
+
"datastore-core": "^10.0.2",
|
|
103
|
+
"interface-datastore": "^8.3.1",
|
|
104
|
+
"it-byte-stream": "^1.1.0",
|
|
104
105
|
"it-merge": "^3.0.5",
|
|
105
|
-
"it-parallel": "^3.0.
|
|
106
|
+
"it-parallel": "^3.0.8",
|
|
106
107
|
"merge-options": "^3.0.4",
|
|
107
|
-
"multiformats": "^13.1
|
|
108
|
+
"multiformats": "^13.3.1",
|
|
108
109
|
"p-defer": "^4.0.1",
|
|
109
|
-
"p-retry": "^6.2.
|
|
110
|
-
"progress-events": "^1.0.
|
|
110
|
+
"p-retry": "^6.2.1",
|
|
111
|
+
"progress-events": "^1.0.1",
|
|
111
112
|
"race-event": "^1.3.0",
|
|
112
|
-
"race-signal": "^1.0
|
|
113
|
+
"race-signal": "^1.1.0",
|
|
113
114
|
"uint8arrays": "^5.1.0"
|
|
114
115
|
},
|
|
115
116
|
"devDependencies": {
|
|
116
|
-
"aegir": "^
|
|
117
|
+
"aegir": "^45.0.5",
|
|
117
118
|
"delay": "^6.0.0",
|
|
118
119
|
"it-all": "^3.0.6",
|
|
119
120
|
"it-drain": "^3.0.7",
|
|
120
121
|
"it-length-prefixed": "^9.1.0",
|
|
121
|
-
"it-map": "^3.1.
|
|
122
|
+
"it-map": "^3.1.1",
|
|
122
123
|
"it-pair": "^2.0.6",
|
|
123
|
-
"it-stream-types": "^2.0.
|
|
124
|
-
"it-take": "^3.0.
|
|
124
|
+
"it-stream-types": "^2.0.2",
|
|
125
|
+
"it-take": "^3.0.6",
|
|
125
126
|
"p-event": "^6.0.1",
|
|
126
127
|
"p-wait-for": "^5.0.2",
|
|
127
|
-
"sinon": "^
|
|
128
|
+
"sinon": "^19.0.2",
|
|
128
129
|
"sinon-ts": "^2.0.0",
|
|
129
130
|
"uint8arraylist": "^2.4.8"
|
|
130
131
|
},
|
package/src/address-manager.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isIPv4 } from '@chainsafe/is-ip'
|
|
1
2
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
2
3
|
import { debounce } from '@libp2p/utils/debounce'
|
|
3
4
|
import { multiaddr, protocols } from '@multiformats/multiaddr'
|
|
@@ -5,6 +6,10 @@ import type { ComponentLogger, Libp2pEvents, Logger, TypedEventTarget, PeerId, P
|
|
|
5
6
|
import type { AddressManager as AddressManagerInterface, TransportManager } from '@libp2p/interface-internal'
|
|
6
7
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
7
8
|
|
|
9
|
+
export const defaultValues = {
|
|
10
|
+
maxObservedAddresses: 10
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
export interface AddressManagerInit {
|
|
9
14
|
/**
|
|
10
15
|
* Pass an function in this field to override the list of addresses
|
|
@@ -13,19 +18,29 @@ export interface AddressManagerInit {
|
|
|
13
18
|
announceFilter?: AddressFilter
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
|
-
* list of
|
|
21
|
+
* A list of string multiaddrs to listen on
|
|
17
22
|
*/
|
|
18
23
|
listen?: string[]
|
|
19
24
|
|
|
20
25
|
/**
|
|
21
|
-
* list of
|
|
26
|
+
* A list of string multiaddrs to use instead of those reported by transports
|
|
22
27
|
*/
|
|
23
28
|
announce?: string[]
|
|
24
29
|
|
|
25
30
|
/**
|
|
26
|
-
* list of multiaddrs string
|
|
31
|
+
* A list of string multiaddrs string to never announce
|
|
27
32
|
*/
|
|
28
33
|
noAnnounce?: string[]
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A list of string multiaddrs to add to the list of announced addresses
|
|
37
|
+
*/
|
|
38
|
+
appendAnnounce?: string[]
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Limits the number of observed addresses we will store
|
|
42
|
+
*/
|
|
43
|
+
maxObservedAddresses?: number
|
|
29
44
|
}
|
|
30
45
|
|
|
31
46
|
export interface AddressManagerComponents {
|
|
@@ -73,6 +88,18 @@ const CODEC_IP4 = 0x04
|
|
|
73
88
|
const CODEC_IP6 = 0x29
|
|
74
89
|
const CODEC_DNS4 = 0x36
|
|
75
90
|
const CODEC_DNS6 = 0x37
|
|
91
|
+
const CODEC_TCP = 0x06
|
|
92
|
+
const CODEC_UDP = 0x0111
|
|
93
|
+
|
|
94
|
+
interface PublicAddressMapping {
|
|
95
|
+
externalIp: string
|
|
96
|
+
externalPort: number
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface DNSMapping {
|
|
100
|
+
domain: string
|
|
101
|
+
confident: boolean
|
|
102
|
+
}
|
|
76
103
|
|
|
77
104
|
export class AddressManager implements AddressManagerInterface {
|
|
78
105
|
private readonly log: Logger
|
|
@@ -80,11 +107,12 @@ export class AddressManager implements AddressManagerInterface {
|
|
|
80
107
|
// this is an array to allow for duplicates, e.g. multiples of `/ip4/0.0.0.0/tcp/0`
|
|
81
108
|
private readonly listen: string[]
|
|
82
109
|
private readonly announce: Set<string>
|
|
110
|
+
private readonly appendAnnounce: Set<string>
|
|
83
111
|
private readonly observed: Map<string, ObservedAddressMetadata>
|
|
84
112
|
private readonly announceFilter: AddressFilter
|
|
85
|
-
private readonly ipDomainMappings: Map<string,
|
|
86
|
-
|
|
87
|
-
private readonly
|
|
113
|
+
private readonly ipDomainMappings: Map<string, DNSMapping>
|
|
114
|
+
private readonly publicAddressMappings: Map<string, PublicAddressMapping[]>
|
|
115
|
+
private readonly maxObservedAddresses: number
|
|
88
116
|
|
|
89
117
|
/**
|
|
90
118
|
* Responsible for managing the peer addresses.
|
|
@@ -93,15 +121,18 @@ export class AddressManager implements AddressManagerInterface {
|
|
|
93
121
|
* while the announce addresses will be used for the peer addresses' to other peers in the network.
|
|
94
122
|
*/
|
|
95
123
|
constructor (components: AddressManagerComponents, init: AddressManagerInit = {}) {
|
|
96
|
-
const { listen = [], announce = [] } = init
|
|
124
|
+
const { listen = [], announce = [], appendAnnounce = [] } = init
|
|
97
125
|
|
|
98
126
|
this.components = components
|
|
99
127
|
this.log = components.logger.forComponent('libp2p:address-manager')
|
|
100
128
|
this.listen = listen.map(ma => ma.toString())
|
|
101
129
|
this.announce = new Set(announce.map(ma => ma.toString()))
|
|
130
|
+
this.appendAnnounce = new Set(appendAnnounce.map(ma => ma.toString()))
|
|
102
131
|
this.observed = new Map()
|
|
103
132
|
this.ipDomainMappings = new Map()
|
|
133
|
+
this.publicAddressMappings = new Map()
|
|
104
134
|
this.announceFilter = init.announceFilter ?? defaultAddressFilter
|
|
135
|
+
this.maxObservedAddresses = init.maxObservedAddresses ?? defaultValues.maxObservedAddresses
|
|
105
136
|
|
|
106
137
|
// this method gets called repeatedly on startup when transports start listening so
|
|
107
138
|
// debounce it so we don't cause multiple self:peer:update events to be emitted
|
|
@@ -115,8 +146,6 @@ export class AddressManager implements AddressManagerInterface {
|
|
|
115
146
|
components.events.addEventListener('transport:close', () => {
|
|
116
147
|
this._updatePeerStoreAddresses()
|
|
117
148
|
})
|
|
118
|
-
|
|
119
|
-
this.where = new Error('where')
|
|
120
149
|
}
|
|
121
150
|
|
|
122
151
|
readonly [Symbol.toStringTag] = '@libp2p/address-manager'
|
|
@@ -124,13 +153,8 @@ export class AddressManager implements AddressManagerInterface {
|
|
|
124
153
|
_updatePeerStoreAddresses (): void {
|
|
125
154
|
// if announce addresses have been configured, ensure they make it into our peer
|
|
126
155
|
// record for things like identify
|
|
127
|
-
const addrs = this.
|
|
128
|
-
.
|
|
129
|
-
.concat(
|
|
130
|
-
[...this.observed.entries()]
|
|
131
|
-
.filter(([_, metadata]) => metadata.confident)
|
|
132
|
-
.map(([str]) => multiaddr(str))
|
|
133
|
-
).map(ma => {
|
|
156
|
+
const addrs = this.getAddresses()
|
|
157
|
+
.map(ma => {
|
|
134
158
|
// strip our peer id if it is present
|
|
135
159
|
if (ma.getPeerId() === this.components.peerId.toString()) {
|
|
136
160
|
return ma.decapsulate(`/p2p/${this.components.peerId.toString()}`)
|
|
@@ -142,7 +166,9 @@ export class AddressManager implements AddressManagerInterface {
|
|
|
142
166
|
this.components.peerStore.patch(this.components.peerId, {
|
|
143
167
|
multiaddrs: addrs
|
|
144
168
|
})
|
|
145
|
-
.catch(err => {
|
|
169
|
+
.catch(err => {
|
|
170
|
+
this.log.error('error updating addresses', err)
|
|
171
|
+
})
|
|
146
172
|
}
|
|
147
173
|
|
|
148
174
|
/**
|
|
@@ -159,6 +185,13 @@ export class AddressManager implements AddressManagerInterface {
|
|
|
159
185
|
return Array.from(this.announce).map((a) => multiaddr(a))
|
|
160
186
|
}
|
|
161
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Get peer announcing multiaddrs
|
|
190
|
+
*/
|
|
191
|
+
getAppendAnnounceAddrs (): Multiaddr[] {
|
|
192
|
+
return Array.from(this.appendAnnounce).map((a) => multiaddr(a))
|
|
193
|
+
}
|
|
194
|
+
|
|
162
195
|
/**
|
|
163
196
|
* Get observed multiaddrs
|
|
164
197
|
*/
|
|
@@ -170,6 +203,10 @@ export class AddressManager implements AddressManagerInterface {
|
|
|
170
203
|
* Add peer observed addresses
|
|
171
204
|
*/
|
|
172
205
|
addObservedAddr (addr: Multiaddr): void {
|
|
206
|
+
if (this.observed.size === this.maxObservedAddresses) {
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
|
|
173
210
|
addr = stripPeerId(addr, this.components.peerId)
|
|
174
211
|
const addrString = addr.toString()
|
|
175
212
|
|
|
@@ -218,22 +255,70 @@ export class AddressManager implements AddressManagerInterface {
|
|
|
218
255
|
multiaddrs = this.components.transportManager.getAddrs()
|
|
219
256
|
}
|
|
220
257
|
|
|
221
|
-
// add observed addresses we are confident in
|
|
222
258
|
multiaddrs = multiaddrs
|
|
223
259
|
.concat(
|
|
260
|
+
// add additional announce addresses
|
|
261
|
+
...this.getAppendAnnounceAddrs(),
|
|
262
|
+
|
|
263
|
+
// add observed addresses we are confident in
|
|
224
264
|
Array.from(this.observed)
|
|
225
265
|
.filter(([ma, metadata]) => metadata.confident)
|
|
226
266
|
.map(([ma]) => multiaddr(ma))
|
|
227
267
|
)
|
|
228
268
|
|
|
229
|
-
|
|
269
|
+
// add public addresses
|
|
270
|
+
const ipMappedMultiaddrs: Multiaddr[] = []
|
|
271
|
+
multiaddrs.forEach(ma => {
|
|
272
|
+
const tuples = ma.stringTuples()
|
|
273
|
+
let tuple: string | undefined
|
|
274
|
+
|
|
275
|
+
// see if the internal host/port/protocol tuple has been mapped externally
|
|
276
|
+
if ((tuples[0][0] === CODEC_IP4 || tuples[0][0] === CODEC_IP6) && tuples[1][0] === CODEC_TCP) {
|
|
277
|
+
tuple = `${tuples[0][1]}-${tuples[1][1]}-tcp`
|
|
278
|
+
} else if ((tuples[0][0] === CODEC_IP4 || tuples[0][0] === CODEC_IP6) && tuples[1][0] === CODEC_UDP) {
|
|
279
|
+
tuple = `${tuples[0][1]}-${tuples[1][1]}-udp`
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (tuple == null) {
|
|
283
|
+
return
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const mappings = this.publicAddressMappings.get(tuple)
|
|
287
|
+
|
|
288
|
+
if (mappings == null) {
|
|
289
|
+
return
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
for (const mapping of mappings) {
|
|
293
|
+
tuples[0][0] = isIPv4(mapping.externalIp) ? CODEC_IP4 : CODEC_IP6
|
|
294
|
+
tuples[0][1] = mapping.externalIp
|
|
295
|
+
tuples[1][1] = `${mapping.externalPort}`
|
|
296
|
+
|
|
297
|
+
ipMappedMultiaddrs.push(
|
|
298
|
+
multiaddr(`/${
|
|
299
|
+
tuples.map(tuple => {
|
|
300
|
+
return [
|
|
301
|
+
protocols(tuple[0]).name,
|
|
302
|
+
tuple[1]
|
|
303
|
+
].join('/')
|
|
304
|
+
}).join('/')
|
|
305
|
+
}`)
|
|
306
|
+
)
|
|
307
|
+
}
|
|
308
|
+
})
|
|
309
|
+
multiaddrs = multiaddrs.concat(ipMappedMultiaddrs)
|
|
230
310
|
|
|
231
311
|
// add ip->domain mappings
|
|
312
|
+
const dnsMappedMultiaddrs: Multiaddr[] = []
|
|
232
313
|
for (const ma of multiaddrs) {
|
|
233
|
-
const tuples =
|
|
314
|
+
const tuples = ma.stringTuples()
|
|
234
315
|
let mappedIp = false
|
|
235
316
|
|
|
236
|
-
for (const [ip,
|
|
317
|
+
for (const [ip, mapping] of this.ipDomainMappings.entries()) {
|
|
318
|
+
if (!mapping.confident) {
|
|
319
|
+
continue
|
|
320
|
+
}
|
|
321
|
+
|
|
237
322
|
for (let i = 0; i < tuples.length; i++) {
|
|
238
323
|
if (tuples[i][1] !== ip) {
|
|
239
324
|
continue
|
|
@@ -241,20 +326,20 @@ export class AddressManager implements AddressManagerInterface {
|
|
|
241
326
|
|
|
242
327
|
if (tuples[i][0] === CODEC_IP4) {
|
|
243
328
|
tuples[i][0] = CODEC_DNS4
|
|
244
|
-
tuples[i][1] = domain
|
|
329
|
+
tuples[i][1] = mapping.domain
|
|
245
330
|
mappedIp = true
|
|
246
331
|
}
|
|
247
332
|
|
|
248
333
|
if (tuples[i][0] === CODEC_IP6) {
|
|
249
334
|
tuples[i][0] = CODEC_DNS6
|
|
250
|
-
tuples[i][1] = domain
|
|
335
|
+
tuples[i][1] = mapping.domain
|
|
251
336
|
mappedIp = true
|
|
252
337
|
}
|
|
253
338
|
}
|
|
254
339
|
}
|
|
255
340
|
|
|
256
341
|
if (mappedIp) {
|
|
257
|
-
|
|
342
|
+
dnsMappedMultiaddrs.push(
|
|
258
343
|
multiaddr(`/${
|
|
259
344
|
tuples.map(tuple => {
|
|
260
345
|
return [
|
|
@@ -266,8 +351,7 @@ export class AddressManager implements AddressManagerInterface {
|
|
|
266
351
|
)
|
|
267
352
|
}
|
|
268
353
|
}
|
|
269
|
-
|
|
270
|
-
multiaddrs = multiaddrs.concat(mappedMultiaddrs)
|
|
354
|
+
multiaddrs = multiaddrs.concat(dnsMappedMultiaddrs)
|
|
271
355
|
|
|
272
356
|
// dedupe multiaddrs
|
|
273
357
|
const addrSet = new Set<string>()
|
|
@@ -305,15 +389,66 @@ export class AddressManager implements AddressManagerInterface {
|
|
|
305
389
|
|
|
306
390
|
addDNSMapping (domain: string, addresses: string[]): void {
|
|
307
391
|
addresses.forEach(ip => {
|
|
308
|
-
this.
|
|
392
|
+
this.log('add DNS mapping %s to %s', ip, domain)
|
|
393
|
+
|
|
394
|
+
// check ip/public ip mappings to see if we think we are contactable
|
|
395
|
+
const confident = [...this.publicAddressMappings.entries()].some(([key, mappings]) => {
|
|
396
|
+
return mappings.some(mapping => mapping.externalIp === ip)
|
|
397
|
+
})
|
|
398
|
+
|
|
399
|
+
this.ipDomainMappings.set(ip, {
|
|
400
|
+
domain,
|
|
401
|
+
confident
|
|
402
|
+
})
|
|
309
403
|
})
|
|
404
|
+
this._updatePeerStoreAddresses()
|
|
310
405
|
}
|
|
311
406
|
|
|
312
407
|
removeDNSMapping (domain: string): void {
|
|
313
|
-
for (const [key,
|
|
314
|
-
if (
|
|
408
|
+
for (const [key, mapping] of this.ipDomainMappings.entries()) {
|
|
409
|
+
if (mapping.domain === domain) {
|
|
410
|
+
this.log('remove DNS mapping for %s', domain)
|
|
315
411
|
this.ipDomainMappings.delete(key)
|
|
316
412
|
}
|
|
317
413
|
}
|
|
414
|
+
this._updatePeerStoreAddresses()
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
addPublicAddressMapping (internalIp: string, internalPort: number, externalIp: string, externalPort: number = internalPort, protocol: 'tcp' | 'udp' = 'tcp'): void {
|
|
418
|
+
const key = `${internalIp}-${internalPort}-${protocol}`
|
|
419
|
+
const mappings = this.publicAddressMappings.get(key) ?? []
|
|
420
|
+
mappings.push({
|
|
421
|
+
externalIp,
|
|
422
|
+
externalPort
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
this.publicAddressMappings.set(key, mappings)
|
|
426
|
+
|
|
427
|
+
// update domain mappings to indicate we are now confident that any matching
|
|
428
|
+
// ip/domain combination can now be resolved externally
|
|
429
|
+
for (const [key, mapping] of this.ipDomainMappings.entries()) {
|
|
430
|
+
if (key === externalIp) {
|
|
431
|
+
mapping.confident = true
|
|
432
|
+
|
|
433
|
+
this.ipDomainMappings.set(key, mapping)
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
this._updatePeerStoreAddresses()
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
removePublicAddressMapping (internalIp: string, internalPort: number, externalIp: string, externalPort: number = internalPort, protocol: 'tcp' | 'udp' = 'tcp'): void {
|
|
441
|
+
const key = `${internalIp}-${internalPort}-${protocol}`
|
|
442
|
+
const mappings = (this.publicAddressMappings.get(key) ?? []).filter(mapping => {
|
|
443
|
+
return mapping.externalIp !== externalIp && mapping.externalPort !== externalPort
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
if (mappings.length === 0) {
|
|
447
|
+
this.publicAddressMappings.delete(key)
|
|
448
|
+
} else {
|
|
449
|
+
this.publicAddressMappings.set(key, mappings)
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
this._updatePeerStoreAddresses()
|
|
318
453
|
}
|
|
319
454
|
}
|
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
import { isPrivateIp } from '@libp2p/utils/private-ip'
|
|
2
|
+
import { WebSockets } from '@multiformats/multiaddr-matcher'
|
|
2
3
|
import type { ConnectionGater } from '@libp2p/interface'
|
|
3
4
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
4
5
|
|
|
6
|
+
const CODEC_IP4 = 0x04
|
|
7
|
+
const CODEC_IP6 = 0x29
|
|
8
|
+
|
|
5
9
|
/**
|
|
6
|
-
* Returns a connection gater that disallows dialling private addresses
|
|
7
|
-
*
|
|
8
|
-
*
|
|
10
|
+
* Returns a connection gater that disallows dialling private addresses or
|
|
11
|
+
* insecure websockets by default.
|
|
12
|
+
*
|
|
13
|
+
* Browsers are severely limited in their resource usage so don't waste time
|
|
14
|
+
* trying to dial undiallable addresses, and they also print verbose error
|
|
15
|
+
* messages when making connections over insecure transports which causes
|
|
16
|
+
* confusion.
|
|
9
17
|
*/
|
|
10
18
|
export function connectionGater (gater: ConnectionGater = {}): ConnectionGater {
|
|
11
19
|
return {
|
|
12
20
|
denyDialPeer: async () => false,
|
|
13
21
|
denyDialMultiaddr: async (multiaddr: Multiaddr) => {
|
|
22
|
+
// do not connect to insecure websockets by default
|
|
23
|
+
if (WebSockets.matches(multiaddr)) {
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
|
|
14
27
|
const tuples = multiaddr.stringTuples()
|
|
15
28
|
|
|
16
|
-
|
|
29
|
+
// do not connect to private addresses by default
|
|
30
|
+
if (tuples[0][0] === CODEC_IP4 || tuples[0][0] === CODEC_IP6) {
|
|
17
31
|
return Boolean(isPrivateIp(`${tuples[0][1]}`))
|
|
18
32
|
}
|
|
19
33
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* eslint-disable max-depth */
|
|
2
2
|
import { TimeoutError, DialError, setMaxListeners, AbortError } from '@libp2p/interface'
|
|
3
3
|
import { PeerMap } from '@libp2p/peer-collections'
|
|
4
|
-
import { PriorityQueue
|
|
5
|
-
import {
|
|
4
|
+
import { PriorityQueue } from '@libp2p/utils/priority-queue'
|
|
5
|
+
import { resolvers, multiaddr } from '@multiformats/multiaddr'
|
|
6
6
|
import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'
|
|
7
7
|
import { Circuit } from '@multiformats/multiaddr-matcher'
|
|
8
|
-
import {
|
|
8
|
+
import { anySignal } from 'any-signal'
|
|
9
9
|
import { CustomProgressEvent } from 'progress-events'
|
|
10
10
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
11
11
|
import { DialDeniedError, NoValidAddressesError } from '../errors.js'
|
|
@@ -23,7 +23,9 @@ import { resolveMultiaddrs } from './utils.js'
|
|
|
23
23
|
import { DEFAULT_DIAL_PRIORITY } from './index.js'
|
|
24
24
|
import type { AddressSorter, ComponentLogger, Logger, Connection, ConnectionGater, Metrics, PeerId, Address, PeerStore, PeerRouting, IsDialableOptions, OpenConnectionProgressEvents } from '@libp2p/interface'
|
|
25
25
|
import type { OpenConnectionOptions, TransportManager } from '@libp2p/interface-internal'
|
|
26
|
+
import type { PriorityQueueJobOptions } from '@libp2p/utils/priority-queue'
|
|
26
27
|
import type { DNS } from '@multiformats/dns'
|
|
28
|
+
import type { Multiaddr, Resolver } from '@multiformats/multiaddr'
|
|
27
29
|
import type { ProgressOptions } from 'progress-events'
|
|
28
30
|
|
|
29
31
|
export interface PendingDialTarget {
|
|
@@ -204,7 +206,12 @@ export class DialQueue {
|
|
|
204
206
|
options?.onProgress?.(new CustomProgressEvent('dial-queue:start-dial'))
|
|
205
207
|
// create abort conditions - need to do this before `calculateMultiaddrs` as
|
|
206
208
|
// we may be about to resolve a dns addr which can time out
|
|
207
|
-
const signal =
|
|
209
|
+
const signal = anySignal([
|
|
210
|
+
this.shutDownController.signal,
|
|
211
|
+
options.signal
|
|
212
|
+
])
|
|
213
|
+
setMaxListeners(Infinity, signal)
|
|
214
|
+
|
|
208
215
|
let addrsToDial: Address[]
|
|
209
216
|
|
|
210
217
|
try {
|
|
@@ -299,25 +306,11 @@ export class DialQueue {
|
|
|
299
306
|
peerId,
|
|
300
307
|
priority: options.priority ?? DEFAULT_DIAL_PRIORITY,
|
|
301
308
|
multiaddrs: new Set(multiaddrs.map(ma => ma.toString())),
|
|
302
|
-
signal: options.signal,
|
|
309
|
+
signal: options.signal ?? AbortSignal.timeout(this.dialTimeout),
|
|
303
310
|
onProgress: options.onProgress
|
|
304
311
|
})
|
|
305
312
|
}
|
|
306
313
|
|
|
307
|
-
private createDialAbortController (userSignal?: AbortSignal): ClearableSignal {
|
|
308
|
-
// let any signal abort the dial
|
|
309
|
-
const signal = anySignal([
|
|
310
|
-
AbortSignal.timeout(this.dialTimeout),
|
|
311
|
-
this.shutDownController.signal,
|
|
312
|
-
userSignal
|
|
313
|
-
])
|
|
314
|
-
|
|
315
|
-
// This emitter gets listened to a lot
|
|
316
|
-
setMaxListeners(Infinity, signal)
|
|
317
|
-
|
|
318
|
-
return signal
|
|
319
|
-
}
|
|
320
|
-
|
|
321
314
|
// eslint-disable-next-line complexity
|
|
322
315
|
private async calculateMultiaddrs (peerId?: PeerId, multiaddrs: Set<string> = new Set<string>(), options: OpenConnectionOptions = {}): Promise<Address[]> {
|
|
323
316
|
const addrs: Address[] = [...multiaddrs].map(ma => ({
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '2.3.
|
|
2
|
-
export const name = 'libp2p'
|
|
1
|
+
export const version = '2.3.1-06f79b646'
|
|
2
|
+
export const name = 'js-libp2p'
|
package/LICENSE
DELETED
package/dist/typedoc-urls.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"AddressFilter": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.AddressFilter.html",
|
|
3
|
-
"AddressManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.AddressManagerInit.html",
|
|
4
|
-
"ConnectionManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.ConnectionManagerInit.html",
|
|
5
|
-
"ConnectionMonitorInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.ConnectionMonitorInit.html",
|
|
6
|
-
"Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
7
|
-
".:Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
8
|
-
"TransportManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.TransportManagerInit.html",
|
|
9
|
-
"Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
10
|
-
".:Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
11
|
-
"ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
12
|
-
".:ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
13
|
-
"createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
14
|
-
".:createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
15
|
-
"name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
16
|
-
"./version:name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
17
|
-
"version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html",
|
|
18
|
-
"./version:version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html"
|
|
19
|
-
}
|