@libp2p/bootstrap 3.0.0 → 5.0.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/src/index.d.ts +6 -32
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -8
- package/dist/src/index.js.map +1 -1
- package/package.json +5 -4
- package/src/index.ts +17 -11
package/dist/src/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
import { Components, Initializable } from '@libp2p/components';
|
|
5
|
-
export interface BootstrapOptions {
|
|
1
|
+
import type { PeerDiscovery } from '@libp2p/interface-peer-discovery';
|
|
2
|
+
import type { PeerStore } from '@libp2p/interface-peer-store';
|
|
3
|
+
export interface BootstrapInit {
|
|
6
4
|
/**
|
|
7
5
|
* The list of peer addresses in multi-address format
|
|
8
6
|
*/
|
|
@@ -24,32 +22,8 @@ export interface BootstrapOptions {
|
|
|
24
22
|
*/
|
|
25
23
|
tagTTL?: number;
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
export declare class Bootstrap extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Initializable {
|
|
31
|
-
static tag: string;
|
|
32
|
-
private timer?;
|
|
33
|
-
private readonly list;
|
|
34
|
-
private readonly timeout;
|
|
35
|
-
private components;
|
|
36
|
-
private readonly _init;
|
|
37
|
-
constructor(options?: BootstrapOptions);
|
|
38
|
-
init(components: Components): void;
|
|
39
|
-
get [symbol](): true;
|
|
40
|
-
get [Symbol.toStringTag](): string;
|
|
41
|
-
isStarted(): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Start emitting events
|
|
44
|
-
*/
|
|
45
|
-
start(): void;
|
|
46
|
-
/**
|
|
47
|
-
* Emit each address in the list as a PeerInfo
|
|
48
|
-
*/
|
|
49
|
-
_discoverBootstrapPeers(): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Stop emitting events
|
|
52
|
-
*/
|
|
53
|
-
stop(): void;
|
|
25
|
+
export interface BootstrapComponents {
|
|
26
|
+
peerStore: PeerStore;
|
|
54
27
|
}
|
|
28
|
+
export declare function bootstrap(init: BootstrapInit): (components: BootstrapComponents) => PeerDiscovery;
|
|
55
29
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAuB,MAAM,kCAAkC,CAAA;AAK1F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAS7D,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,EAAE,CAAA;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,SAAS,CAAA;CACrB;AAkHD,wBAAgB,SAAS,CAAE,IAAI,EAAE,aAAa,GAAG,CAAC,UAAU,EAAE,mBAAmB,KAAK,aAAa,CAElG"}
|
package/dist/src/index.js
CHANGED
|
@@ -4,7 +4,6 @@ import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events';
|
|
|
4
4
|
import { logger } from '@libp2p/logger';
|
|
5
5
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
6
6
|
import { symbol } from '@libp2p/interface-peer-discovery';
|
|
7
|
-
import { Components } from '@libp2p/components';
|
|
8
7
|
const log = logger('libp2p:bootstrap');
|
|
9
8
|
const DEFAULT_BOOTSTRAP_TAG_NAME = 'bootstrap';
|
|
10
9
|
const DEFAULT_BOOTSTRAP_TAG_VALUE = 50;
|
|
@@ -13,13 +12,13 @@ const DEFAULT_BOOTSTRAP_DISCOVERY_TIMEOUT = 1000;
|
|
|
13
12
|
/**
|
|
14
13
|
* Emits 'peer' events on a regular interval for each peer in the provided list.
|
|
15
14
|
*/
|
|
16
|
-
|
|
17
|
-
constructor(options = { list: [] }) {
|
|
15
|
+
class Bootstrap extends EventEmitter {
|
|
16
|
+
constructor(components, options = { list: [] }) {
|
|
18
17
|
if (options.list == null || options.list.length === 0) {
|
|
19
18
|
throw new Error('Bootstrap requires a list of peer addresses');
|
|
20
19
|
}
|
|
21
20
|
super();
|
|
22
|
-
this.components =
|
|
21
|
+
this.components = components;
|
|
23
22
|
this.timeout = options.timeout ?? DEFAULT_BOOTSTRAP_DISCOVERY_TIMEOUT;
|
|
24
23
|
this.list = [];
|
|
25
24
|
for (const candidate of options.list) {
|
|
@@ -42,9 +41,6 @@ export class Bootstrap extends EventEmitter {
|
|
|
42
41
|
}
|
|
43
42
|
this._init = options;
|
|
44
43
|
}
|
|
45
|
-
init(components) {
|
|
46
|
-
this.components = components;
|
|
47
|
-
}
|
|
48
44
|
get [symbol]() {
|
|
49
45
|
return true;
|
|
50
46
|
}
|
|
@@ -77,7 +73,7 @@ export class Bootstrap extends EventEmitter {
|
|
|
77
73
|
return;
|
|
78
74
|
}
|
|
79
75
|
for (const peerData of this.list) {
|
|
80
|
-
await this.components.
|
|
76
|
+
await this.components.peerStore.tagPeer(peerData.id, this._init.tagName ?? DEFAULT_BOOTSTRAP_TAG_NAME, {
|
|
81
77
|
value: this._init.tagValue ?? DEFAULT_BOOTSTRAP_TAG_VALUE,
|
|
82
78
|
ttl: this._init.tagTTL ?? DEFAULT_BOOTSTRAP_TAG_TTL
|
|
83
79
|
});
|
|
@@ -99,4 +95,7 @@ export class Bootstrap extends EventEmitter {
|
|
|
99
95
|
}
|
|
100
96
|
}
|
|
101
97
|
Bootstrap.tag = 'bootstrap';
|
|
98
|
+
export function bootstrap(init) {
|
|
99
|
+
return (components) => new Bootstrap(components, init);
|
|
100
|
+
}
|
|
102
101
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AAIzD,MAAM,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAEtC,MAAM,0BAA0B,GAAG,WAAW,CAAA;AAC9C,MAAM,2BAA2B,GAAG,EAAE,CAAA;AACtC,MAAM,yBAAyB,GAAG,MAAM,CAAA;AACxC,MAAM,mCAAmC,GAAG,IAAI,CAAA;AAiChD;;GAEG;AACH,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K,CAAC,CAAA;SACzB;QAED,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;IACxB,CAAC;;AAzGM,aAAG,GAAG,WAAW,CAAA;AA4G1B,MAAM,UAAU,SAAS,CAAE,IAAmB;IAC5C,OAAO,CAAC,UAA+B,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAC7E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/bootstrap",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Node.js IPFS Implementation of the railing process of a Node through a bootstrap peer list",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p-bootstrap#readme",
|
|
@@ -138,9 +138,9 @@
|
|
|
138
138
|
"release": "aegir release"
|
|
139
139
|
},
|
|
140
140
|
"dependencies": {
|
|
141
|
-
"@libp2p/components": "^2.0.0",
|
|
142
141
|
"@libp2p/interface-peer-discovery": "^1.0.1",
|
|
143
142
|
"@libp2p/interface-peer-info": "^1.0.3",
|
|
143
|
+
"@libp2p/interface-peer-store": "^1.2.2",
|
|
144
144
|
"@libp2p/interfaces": "^3.0.3",
|
|
145
145
|
"@libp2p/logger": "^2.0.1",
|
|
146
146
|
"@libp2p/peer-id": "^1.1.15",
|
|
@@ -148,9 +148,10 @@
|
|
|
148
148
|
"@multiformats/multiaddr": "^11.0.0"
|
|
149
149
|
},
|
|
150
150
|
"devDependencies": {
|
|
151
|
-
"@libp2p/interface-peer-discovery-compliance-tests": "^
|
|
151
|
+
"@libp2p/interface-peer-discovery-compliance-tests": "^2.0.0",
|
|
152
152
|
"@libp2p/interface-peer-id": "^1.0.4",
|
|
153
|
-
"@libp2p/peer-
|
|
153
|
+
"@libp2p/peer-id-factory": "^1.0.18",
|
|
154
|
+
"@libp2p/peer-store": "^5.0.0",
|
|
154
155
|
"aegir": "^37.5.3",
|
|
155
156
|
"datastore-core": "^8.0.1",
|
|
156
157
|
"delay": "^5.0.0"
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,8 @@ import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface-peer-
|
|
|
6
6
|
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
7
7
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
8
8
|
import { symbol } from '@libp2p/interface-peer-discovery'
|
|
9
|
-
import {
|
|
9
|
+
import type { Startable } from '@libp2p/interfaces/dist/src/startable'
|
|
10
|
+
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
10
11
|
|
|
11
12
|
const log = logger('libp2p:bootstrap')
|
|
12
13
|
|
|
@@ -15,7 +16,7 @@ const DEFAULT_BOOTSTRAP_TAG_VALUE = 50
|
|
|
15
16
|
const DEFAULT_BOOTSTRAP_TAG_TTL = 120000
|
|
16
17
|
const DEFAULT_BOOTSTRAP_DISCOVERY_TIMEOUT = 1000
|
|
17
18
|
|
|
18
|
-
export interface
|
|
19
|
+
export interface BootstrapInit {
|
|
19
20
|
/**
|
|
20
21
|
* The list of peer addresses in multi-address format
|
|
21
22
|
*/
|
|
@@ -42,24 +43,29 @@ export interface BootstrapOptions {
|
|
|
42
43
|
tagTTL?: number
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
export interface BootstrapComponents {
|
|
47
|
+
peerStore: PeerStore
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
/**
|
|
46
51
|
* Emits 'peer' events on a regular interval for each peer in the provided list.
|
|
47
52
|
*/
|
|
48
|
-
|
|
53
|
+
class Bootstrap extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Startable {
|
|
49
54
|
static tag = 'bootstrap'
|
|
50
55
|
|
|
51
56
|
private timer?: ReturnType<typeof setTimeout>
|
|
52
57
|
private readonly list: PeerInfo[]
|
|
53
58
|
private readonly timeout: number
|
|
54
|
-
private components:
|
|
55
|
-
private readonly _init:
|
|
59
|
+
private readonly components: BootstrapComponents
|
|
60
|
+
private readonly _init: BootstrapInit
|
|
56
61
|
|
|
57
|
-
constructor (options:
|
|
62
|
+
constructor (components: BootstrapComponents, options: BootstrapInit = { list: [] }) {
|
|
58
63
|
if (options.list == null || options.list.length === 0) {
|
|
59
64
|
throw new Error('Bootstrap requires a list of peer addresses')
|
|
60
65
|
}
|
|
61
66
|
super()
|
|
62
67
|
|
|
68
|
+
this.components = components
|
|
63
69
|
this.timeout = options.timeout ?? DEFAULT_BOOTSTRAP_DISCOVERY_TIMEOUT
|
|
64
70
|
this.list = []
|
|
65
71
|
|
|
@@ -89,10 +95,6 @@ export class Bootstrap extends EventEmitter<PeerDiscoveryEvents> implements Peer
|
|
|
89
95
|
this._init = options
|
|
90
96
|
}
|
|
91
97
|
|
|
92
|
-
init (components: Components) {
|
|
93
|
-
this.components = components
|
|
94
|
-
}
|
|
95
|
-
|
|
96
98
|
get [symbol] (): true {
|
|
97
99
|
return true
|
|
98
100
|
}
|
|
@@ -131,7 +133,7 @@ export class Bootstrap extends EventEmitter<PeerDiscoveryEvents> implements Peer
|
|
|
131
133
|
}
|
|
132
134
|
|
|
133
135
|
for (const peerData of this.list) {
|
|
134
|
-
await this.components.
|
|
136
|
+
await this.components.peerStore.tagPeer(peerData.id, this._init.tagName ?? DEFAULT_BOOTSTRAP_TAG_NAME, {
|
|
135
137
|
value: this._init.tagValue ?? DEFAULT_BOOTSTRAP_TAG_VALUE,
|
|
136
138
|
ttl: this._init.tagTTL ?? DEFAULT_BOOTSTRAP_TAG_TTL
|
|
137
139
|
})
|
|
@@ -156,3 +158,7 @@ export class Bootstrap extends EventEmitter<PeerDiscoveryEvents> implements Peer
|
|
|
156
158
|
this.timer = undefined
|
|
157
159
|
}
|
|
158
160
|
}
|
|
161
|
+
|
|
162
|
+
export function bootstrap (init: BootstrapInit): (components: BootstrapComponents) => PeerDiscovery {
|
|
163
|
+
return (components: BootstrapComponents) => new Bootstrap(components, init)
|
|
164
|
+
}
|