libp2p 2.2.1 → 2.3.0-656db81cf
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 +9 -9
- package/dist/src/{address-manager/index.d.ts → address-manager.d.ts} +9 -5
- package/dist/src/address-manager.d.ts.map +1 -0
- package/dist/src/{address-manager/index.js → address-manager.js} +73 -12
- package/dist/src/address-manager.js.map +1 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/libp2p.js +2 -2
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/registrar.d.ts +1 -2
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/upgrader.d.ts +1 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +2 -2
- package/dist/src/upgrader.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 +17 -27
- package/src/{address-manager/index.ts → address-manager.ts} +111 -28
- package/src/index.ts +1 -1
- package/src/libp2p.ts +2 -2
- package/src/registrar.ts +1 -2
- package/src/upgrader.ts +3 -3
- package/src/version.ts +1 -1
- package/dist/src/address-manager/index.d.ts.map +0 -1
- package/dist/src/address-manager/index.js.map +0 -1
- package/dist/src/address-manager/utils.d.ts +0 -2
- package/dist/src/address-manager/utils.d.ts.map +0 -1
- package/dist/src/address-manager/utils.js +0 -12
- package/dist/src/address-manager/utils.js.map +0 -1
- package/dist/typedoc-urls.json +0 -19
- package/src/address-manager/README.md +0 -43
- package/src/address-manager/utils.ts +0 -13
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { debounce } from '@libp2p/utils/debounce'
|
|
3
|
+
import { multiaddr, protocols } from '@multiformats/multiaddr'
|
|
4
4
|
import type { ComponentLogger, Libp2pEvents, Logger, TypedEventTarget, PeerId, PeerStore } from '@libp2p/interface'
|
|
5
|
-
import type { TransportManager } from '@libp2p/interface-internal'
|
|
5
|
+
import type { AddressManager as AddressManagerInterface, TransportManager } from '@libp2p/interface-internal'
|
|
6
6
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
7
7
|
|
|
8
8
|
export interface AddressManagerInit {
|
|
@@ -28,7 +28,7 @@ export interface AddressManagerInit {
|
|
|
28
28
|
noAnnounce?: string[]
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export interface
|
|
31
|
+
export interface AddressManagerComponents {
|
|
32
32
|
peerId: PeerId
|
|
33
33
|
transportManager: TransportManager
|
|
34
34
|
peerStore: PeerStore
|
|
@@ -69,14 +69,22 @@ function stripPeerId (ma: Multiaddr, peerId: PeerId): Multiaddr {
|
|
|
69
69
|
return ma
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
const CODEC_IP4 = 0x04
|
|
73
|
+
const CODEC_IP6 = 0x29
|
|
74
|
+
const CODEC_DNS4 = 0x36
|
|
75
|
+
const CODEC_DNS6 = 0x37
|
|
76
|
+
|
|
77
|
+
export class AddressManager implements AddressManagerInterface {
|
|
73
78
|
private readonly log: Logger
|
|
74
|
-
private readonly components:
|
|
79
|
+
private readonly components: AddressManagerComponents
|
|
75
80
|
// this is an array to allow for duplicates, e.g. multiples of `/ip4/0.0.0.0/tcp/0`
|
|
76
81
|
private readonly listen: string[]
|
|
77
82
|
private readonly announce: Set<string>
|
|
78
83
|
private readonly observed: Map<string, ObservedAddressMetadata>
|
|
79
84
|
private readonly announceFilter: AddressFilter
|
|
85
|
+
private readonly ipDomainMappings: Map<string, string>
|
|
86
|
+
|
|
87
|
+
private readonly where: Error
|
|
80
88
|
|
|
81
89
|
/**
|
|
82
90
|
* Responsible for managing the peer addresses.
|
|
@@ -84,7 +92,7 @@ export class DefaultAddressManager {
|
|
|
84
92
|
* The listen addresses will be used by the libp2p transports to listen for new connections,
|
|
85
93
|
* while the announce addresses will be used for the peer addresses' to other peers in the network.
|
|
86
94
|
*/
|
|
87
|
-
constructor (components:
|
|
95
|
+
constructor (components: AddressManagerComponents, init: AddressManagerInit = {}) {
|
|
88
96
|
const { listen = [], announce = [] } = init
|
|
89
97
|
|
|
90
98
|
this.components = components
|
|
@@ -92,6 +100,7 @@ export class DefaultAddressManager {
|
|
|
92
100
|
this.listen = listen.map(ma => ma.toString())
|
|
93
101
|
this.announce = new Set(announce.map(ma => ma.toString()))
|
|
94
102
|
this.observed = new Map()
|
|
103
|
+
this.ipDomainMappings = new Map()
|
|
95
104
|
this.announceFilter = init.announceFilter ?? defaultAddressFilter
|
|
96
105
|
|
|
97
106
|
// this method gets called repeatedly on startup when transports start listening so
|
|
@@ -106,6 +115,8 @@ export class DefaultAddressManager {
|
|
|
106
115
|
components.events.addEventListener('transport:close', () => {
|
|
107
116
|
this._updatePeerStoreAddresses()
|
|
108
117
|
})
|
|
118
|
+
|
|
119
|
+
this.where = new Error('where')
|
|
109
120
|
}
|
|
110
121
|
|
|
111
122
|
readonly [Symbol.toStringTag] = '@libp2p/address-manager'
|
|
@@ -200,37 +211,109 @@ export class DefaultAddressManager {
|
|
|
200
211
|
}
|
|
201
212
|
|
|
202
213
|
getAddresses (): Multiaddr[] {
|
|
203
|
-
let
|
|
214
|
+
let multiaddrs = this.getAnnounceAddrs()
|
|
204
215
|
|
|
205
|
-
if (
|
|
216
|
+
if (multiaddrs.length === 0) {
|
|
206
217
|
// no configured announce addrs, add configured listen addresses
|
|
207
|
-
|
|
218
|
+
multiaddrs = this.components.transportManager.getAddrs()
|
|
208
219
|
}
|
|
209
220
|
|
|
210
221
|
// add observed addresses we are confident in
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
.
|
|
214
|
-
|
|
215
|
-
|
|
222
|
+
multiaddrs = multiaddrs
|
|
223
|
+
.concat(
|
|
224
|
+
Array.from(this.observed)
|
|
225
|
+
.filter(([ma, metadata]) => metadata.confident)
|
|
226
|
+
.map(([ma]) => multiaddr(ma))
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
const mappedMultiaddrs: Multiaddr[] = []
|
|
230
|
+
|
|
231
|
+
// add ip->domain mappings
|
|
232
|
+
for (const ma of multiaddrs) {
|
|
233
|
+
const tuples = [...ma.stringTuples()]
|
|
234
|
+
let mappedIp = false
|
|
235
|
+
|
|
236
|
+
for (const [ip, domain] of this.ipDomainMappings.entries()) {
|
|
237
|
+
for (let i = 0; i < tuples.length; i++) {
|
|
238
|
+
if (tuples[i][1] !== ip) {
|
|
239
|
+
continue
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (tuples[i][0] === CODEC_IP4) {
|
|
243
|
+
tuples[i][0] = CODEC_DNS4
|
|
244
|
+
tuples[i][1] = domain
|
|
245
|
+
mappedIp = true
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (tuples[i][0] === CODEC_IP6) {
|
|
249
|
+
tuples[i][0] = CODEC_DNS6
|
|
250
|
+
tuples[i][1] = domain
|
|
251
|
+
mappedIp = true
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (mappedIp) {
|
|
257
|
+
mappedMultiaddrs.push(
|
|
258
|
+
multiaddr(`/${
|
|
259
|
+
tuples.map(tuple => {
|
|
260
|
+
return [
|
|
261
|
+
protocols(tuple[0]).name,
|
|
262
|
+
tuple[1]
|
|
263
|
+
].join('/')
|
|
264
|
+
}).join('/')
|
|
265
|
+
}`)
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
multiaddrs = multiaddrs.concat(mappedMultiaddrs)
|
|
216
271
|
|
|
217
272
|
// dedupe multiaddrs
|
|
218
|
-
const addrSet = new Set(
|
|
273
|
+
const addrSet = new Set<string>()
|
|
274
|
+
multiaddrs = multiaddrs.filter(ma => {
|
|
275
|
+
const maStr = ma.toString()
|
|
276
|
+
|
|
277
|
+
if (addrSet.has(maStr)) {
|
|
278
|
+
return false
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
addrSet.add(maStr)
|
|
282
|
+
|
|
283
|
+
return true
|
|
284
|
+
})
|
|
219
285
|
|
|
220
286
|
// Create advertising list
|
|
221
|
-
return this.announceFilter(
|
|
222
|
-
.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
287
|
+
return this.announceFilter(
|
|
288
|
+
Array.from(addrSet)
|
|
289
|
+
.map(str => {
|
|
290
|
+
const ma = multiaddr(str)
|
|
291
|
+
|
|
292
|
+
// do not append our peer id to a path multiaddr as it will become invalid
|
|
293
|
+
if (ma.protos().pop()?.path === true) {
|
|
294
|
+
return ma
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (ma.getPeerId() === this.components.peerId.toString()) {
|
|
298
|
+
return ma
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return ma.encapsulate(`/p2p/${this.components.peerId.toString()}`)
|
|
302
|
+
})
|
|
303
|
+
)
|
|
304
|
+
}
|
|
228
305
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
306
|
+
addDNSMapping (domain: string, addresses: string[]): void {
|
|
307
|
+
addresses.forEach(ip => {
|
|
308
|
+
this.ipDomainMappings.set(ip, domain)
|
|
309
|
+
})
|
|
310
|
+
}
|
|
232
311
|
|
|
233
|
-
|
|
234
|
-
|
|
312
|
+
removeDNSMapping (domain: string): void {
|
|
313
|
+
for (const [key, value] of this.ipDomainMappings.entries()) {
|
|
314
|
+
if (value === domain) {
|
|
315
|
+
this.ipDomainMappings.delete(key)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
235
318
|
}
|
|
236
319
|
}
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { generateKeyPair } from '@libp2p/crypto/keys'
|
|
|
18
18
|
import { peerIdFromPrivateKey } from '@libp2p/peer-id'
|
|
19
19
|
import { validateConfig } from './config.js'
|
|
20
20
|
import { Libp2p as Libp2pClass } from './libp2p.js'
|
|
21
|
-
import type { AddressManagerInit, AddressFilter } from './address-manager
|
|
21
|
+
import type { AddressManagerInit, AddressFilter } from './address-manager.js'
|
|
22
22
|
import type { Components } from './components.js'
|
|
23
23
|
import type { ConnectionManagerInit } from './connection-manager/index.js'
|
|
24
24
|
import type { ConnectionMonitorInit } from './connection-monitor.js'
|
package/src/libp2p.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { isMultiaddr, type Multiaddr } from '@multiformats/multiaddr'
|
|
|
8
8
|
import { MemoryDatastore } from 'datastore-core/memory'
|
|
9
9
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
10
10
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
11
|
-
import {
|
|
11
|
+
import { AddressManager } from './address-manager.js'
|
|
12
12
|
import { checkServiceDependencies, defaultComponents } from './components.js'
|
|
13
13
|
import { connectionGater } from './config/connection-gater.js'
|
|
14
14
|
import { DefaultConnectionManager } from './connection-manager/index.js'
|
|
@@ -129,7 +129,7 @@ export class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEventEmitter
|
|
|
129
129
|
this.configureComponent('registrar', new DefaultRegistrar(this.components))
|
|
130
130
|
|
|
131
131
|
// Addresses {listen, announce, noAnnounce}
|
|
132
|
-
this.configureComponent('addressManager', new
|
|
132
|
+
this.configureComponent('addressManager', new AddressManager(this.components, init.addresses))
|
|
133
133
|
|
|
134
134
|
// Peer routers
|
|
135
135
|
const peerRouters: PeerRouting[] = (init.peerRouters ?? []).map((fn, index) => this.configureComponent(`peer-router-${index}`, fn(this.components)))
|
package/src/registrar.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { InvalidParametersError } from '@libp2p/interface'
|
|
|
2
2
|
import merge from 'merge-options'
|
|
3
3
|
import * as errorsJs from './errors.js'
|
|
4
4
|
import type { IdentifyResult, Libp2pEvents, Logger, PeerUpdate, TypedEventTarget, PeerId, PeerStore, Topology } from '@libp2p/interface'
|
|
5
|
-
import type {
|
|
5
|
+
import type { StreamHandlerOptions, StreamHandlerRecord, Registrar, StreamHandler } from '@libp2p/interface-internal'
|
|
6
6
|
import type { ComponentLogger } from '@libp2p/logger'
|
|
7
7
|
|
|
8
8
|
export const DEFAULT_MAX_INBOUND_STREAMS = 32
|
|
@@ -10,7 +10,6 @@ export const DEFAULT_MAX_OUTBOUND_STREAMS = 64
|
|
|
10
10
|
|
|
11
11
|
export interface RegistrarComponents {
|
|
12
12
|
peerId: PeerId
|
|
13
|
-
connectionManager: ConnectionManager
|
|
14
13
|
peerStore: PeerStore
|
|
15
14
|
events: TypedEventTarget<Libp2pEvents>
|
|
16
15
|
logger: ComponentLogger
|
package/src/upgrader.ts
CHANGED
|
@@ -181,7 +181,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
181
181
|
/**
|
|
182
182
|
* Upgrades an inbound connection
|
|
183
183
|
*/
|
|
184
|
-
async upgradeInbound (maConn: MultiaddrConnection, opts: UpgraderOptions = {}): Promise<
|
|
184
|
+
async upgradeInbound (maConn: MultiaddrConnection, opts: UpgraderOptions = {}): Promise<void> {
|
|
185
185
|
let accepted = false
|
|
186
186
|
|
|
187
187
|
try {
|
|
@@ -192,12 +192,12 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
192
192
|
accepted = await this.components.connectionManager.acceptIncomingConnection(maConn)
|
|
193
193
|
|
|
194
194
|
if (!accepted) {
|
|
195
|
-
throw new ConnectionDeniedError('
|
|
195
|
+
throw new ConnectionDeniedError('Connection denied')
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
await this.shouldBlockConnection('denyInboundConnection', maConn)
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
await this._performUpgrade(maConn, 'inbound', opts)
|
|
201
201
|
} catch (err) {
|
|
202
202
|
this.metrics.errors?.increment({
|
|
203
203
|
inbound: true
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.3.0-656db81cf'
|
|
2
2
|
export const name = 'libp2p'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/address-manager/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAU,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACnH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,cAAc,CAAC,EAAE,aAAa,CAAA;IAE9B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IAEjB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IAEnB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACtB;AAED,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAA;IACtC,MAAM,EAAE,eAAe,CAAA;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAAA;CAClC;AA2BD,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiC;IAE5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsC;IAC/D,OAAO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,CAAC,CAAA;QAE9B,0BAA0B;QAC1B,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;aAC3C,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;aAC3B,GAAG,CAAC,EAAE,CAAC,EAAE;YACR,0EAA0E;YAC1E,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,IAAI,KAAK,IAAI,EAAE,CAAC;gBACrC,OAAO,EAAE,CAAA;YACX,CAAC;YAED,IAAI,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;gBACzD,OAAO,EAAE,CAAA;YACX,CAAC;YAED,OAAO,EAAE,CAAC,WAAW,CAAC,QAAQ,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;QACpE,CAAC,CAAC,CAAA;IACN,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/address-manager/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAE,IAAI,EAAE,MAAM,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,IAAI,CAYpE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/address-manager/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,CAAE,IAAgB,EAAE,IAAY;IACtD,IAAI,OAAkD,CAAA;IAEtD,OAAO;QACL,MAAM,KAAK,GAAG;YACZ,OAAO,GAAG,SAAS,CAAA;YACnB,IAAI,EAAE,CAAA;QACR,CAAC,CAAA;QAED,YAAY,CAAC,OAAO,CAAC,CAAA;QACrB,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IACnC,CAAC,CAAA;AACH,CAAC"}
|
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
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# Address Manager
|
|
2
|
-
|
|
3
|
-
The Address manager is responsible for keeping an updated register of the peer's addresses. It includes 2 different types of Addresses: `Listen Addresses` and `Announce Addresses`.
|
|
4
|
-
|
|
5
|
-
These Addresses should be specified in your libp2p [configuration](../../../../doc/CONFIGURATION.md) when you create your node.
|
|
6
|
-
|
|
7
|
-
## Listen Addresses
|
|
8
|
-
|
|
9
|
-
A libp2p node should have a set of listen addresses, which will be used by libp2p underlying transports to listen for dials from other nodes in the network.
|
|
10
|
-
|
|
11
|
-
Before a libp2p node starts, its configured listen addresses will be passed to the AddressManager, so that during startup the libp2p transports can use them to listen for connections. Accordingly, listen addresses should be specified through the libp2p configuration, in order to have the `AddressManager` created with them.
|
|
12
|
-
|
|
13
|
-
It is important pointing out that libp2p accepts ephemeral listening addresses. In this context, the provided listen addresses might not be exactly the same as the ones used by the transports. For example TCP may replace `/ip4/0.0.0.0/tcp/0` with something like `/ip4/127.0.0.1/tcp/8989`. As a consequence, libp2p should take into account this when determining its advertised addresses.
|
|
14
|
-
|
|
15
|
-
## Announce Addresses
|
|
16
|
-
|
|
17
|
-
In some scenarios, a libp2p node will need to announce addresses that it is not listening on. In other words, Announce Addresses are an amendment to the Listen Addresses that aim to enable other nodes to achieve connectivity to this node.
|
|
18
|
-
|
|
19
|
-
Scenarios for Announce Addresses include:
|
|
20
|
-
- when you setup a libp2p node in your private network at home, but you need to announce your public IP Address to the outside world;
|
|
21
|
-
- when you want to announce a DNS address, which maps to your public IP Address.
|
|
22
|
-
|
|
23
|
-
## Implementation
|
|
24
|
-
|
|
25
|
-
When a libp2p node is created, the Address Manager will be populated from the provided addresses through the libp2p configuration. Once the node is started, the Transport Manager component will gather the listen addresses from the Address Manager, so that the libp2p transports can attempt to bind to them.
|
|
26
|
-
|
|
27
|
-
Libp2p will use the Address Manager as the source of truth when advertising the peers addresses. After all transports are ready, other libp2p components/subsystems will kickoff, namely the Identify Service and the DHT. Both of them will announce the node addresses to the other peers in the network. The announce addresses will have an important role here and will be gathered by libp2p to compute its current addresses to advertise everytime it is needed.
|
|
28
|
-
|
|
29
|
-
## Future Considerations
|
|
30
|
-
|
|
31
|
-
### Dynamic address modifications
|
|
32
|
-
|
|
33
|
-
In a future iteration, we can enable these addresses to be modified in runtime. For this, the Address Manager should be responsible for notifying interested subsystems of these changes, through an Event Emitter.
|
|
34
|
-
|
|
35
|
-
#### Modify Listen Addresses
|
|
36
|
-
|
|
37
|
-
While adding new addresses to listen on runtime should be trivial, removing a listen address might have bad implications for the node, since all the connections using that listen address will be closed. However, libp2p should provide a mechanism for both adding and removing listen addresses in the future.
|
|
38
|
-
|
|
39
|
-
Every time a new listen address is added, the Address Manager should emit an event with the new multiaddrs to listen. The Transport Manager should listen to this events and act accordingly.
|
|
40
|
-
|
|
41
|
-
#### Modify Announce Addresses
|
|
42
|
-
|
|
43
|
-
When the announce addresses are modified, the Address Manager should emit an event so that other subsystems can act accordingly. For example, libp2p identify service should use the libp2p push protocol to inform other peers about these changes.
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function debounce (func: () => void, wait: number): () => void {
|
|
2
|
-
let timeout: ReturnType<typeof setTimeout> | undefined
|
|
3
|
-
|
|
4
|
-
return function () {
|
|
5
|
-
const later = function (): void {
|
|
6
|
-
timeout = undefined
|
|
7
|
-
func()
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
clearTimeout(timeout)
|
|
11
|
-
timeout = setTimeout(later, wait)
|
|
12
|
-
}
|
|
13
|
-
}
|