@libp2p/bootstrap 0.14.0 → 1.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/README.md +21 -8
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +24 -24
- package/dist/src/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +34 -29
package/README.md
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
js-libp2p-bootstrap
|
|
2
|
-
=================
|
|
1
|
+
# js-libp2p-bootstrap
|
|
3
2
|
|
|
4
3
|
[](http://protocol.ai)
|
|
5
4
|
[](http://libp2p.io/)
|
|
6
5
|
[](http://webchat.freenode.net/?channels=%23libp2p)
|
|
7
6
|
[](https://discuss.libp2p.io)
|
|
8
7
|
[](https://codecov.io/gh/libp2p/js-libp2p-bootstrap)
|
|
9
|
-
[](https://github.com/libp2p/js-libp2p-bootstrap/actions/workflows/js-test-and-release.yml)
|
|
10
9
|
[](https://github.com/feross/standard)
|
|
11
10
|

|
|
12
11
|
|
|
13
12
|
> JavaScript libp2p Implementation of the railing process of a Node through a bootstrap peer list
|
|
14
13
|
|
|
15
|
-
## Lead Maintainer
|
|
16
|
-
|
|
17
|
-
[Vasco Santos](https://github.com/vasco-santos).
|
|
18
|
-
|
|
19
14
|
## Usage
|
|
20
15
|
|
|
21
16
|
```JavaScript
|
|
@@ -38,7 +33,7 @@ let options = {
|
|
|
38
33
|
list: [ // a list of bootstrap peer multiaddrs to connect to on node startup
|
|
39
34
|
"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
|
|
40
35
|
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
|
|
41
|
-
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa"
|
|
36
|
+
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa"
|
|
42
37
|
],
|
|
43
38
|
interval: 5000 // default is 10 ms,
|
|
44
39
|
enabled: true
|
|
@@ -60,3 +55,21 @@ async function start () {
|
|
|
60
55
|
|
|
61
56
|
start()
|
|
62
57
|
```
|
|
58
|
+
|
|
59
|
+
## Contribute
|
|
60
|
+
|
|
61
|
+
The libp2p implementation in JavaScript is a work in progress. As such, there are a few things you can do right now to help out:
|
|
62
|
+
|
|
63
|
+
- Go through the modules and **check out existing issues**. This is especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
|
|
64
|
+
- **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
Licensed under either of
|
|
69
|
+
|
|
70
|
+
* Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
|
|
71
|
+
* MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT)
|
|
72
|
+
|
|
73
|
+
### Contribution
|
|
74
|
+
|
|
75
|
+
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
package/dist/src/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface BootstrapOptions {
|
|
|
16
16
|
*/
|
|
17
17
|
export declare class Bootstrap extends EventEmitter implements PeerDiscovery {
|
|
18
18
|
static tag: string;
|
|
19
|
-
private timer
|
|
19
|
+
private timer?;
|
|
20
20
|
private readonly list;
|
|
21
21
|
private readonly interval;
|
|
22
22
|
constructor(options?: BootstrapOptions);
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAA;AAOlE,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,MAAM,EAAE,CAAA;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,YAAa,YAAW,aAAa;IAClE,MAAM,CAAC,GAAG,SAAc;IAExB,OAAO,CAAC,KAAK,CAAC,CAAc;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAY;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;gBAEpB,OAAO,GAAE,gBAA+B;IAiCrD,SAAS;IAIT;;OAEG;IACH,KAAK;IAUL;;OAEG;IACH,uBAAuB;IAUvB;;OAEG;IACH,IAAI;CAOL"}
|
package/dist/src/index.js
CHANGED
|
@@ -15,9 +15,26 @@ export class Bootstrap extends EventEmitter {
|
|
|
15
15
|
throw new Error('Bootstrap requires a list of peer addresses');
|
|
16
16
|
}
|
|
17
17
|
super();
|
|
18
|
-
this.list = options.list;
|
|
19
18
|
this.interval = options.interval ?? 10000;
|
|
20
|
-
this.
|
|
19
|
+
this.list = [];
|
|
20
|
+
for (const candidate of options.list) {
|
|
21
|
+
if (!P2P.matches(candidate)) {
|
|
22
|
+
log.error('Invalid multiaddr');
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const ma = new Multiaddr(candidate);
|
|
26
|
+
const peerIdStr = ma.getPeerId();
|
|
27
|
+
if (peerIdStr == null) {
|
|
28
|
+
log.error('Invalid bootstrap multiaddr without peer id');
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const peerData = {
|
|
32
|
+
id: PeerId.fromString(peerIdStr),
|
|
33
|
+
multiaddrs: [ma],
|
|
34
|
+
protocols: []
|
|
35
|
+
};
|
|
36
|
+
this.list.push(peerData);
|
|
37
|
+
}
|
|
21
38
|
}
|
|
22
39
|
isStarted() {
|
|
23
40
|
return Boolean(this.timer);
|
|
@@ -40,35 +57,18 @@ export class Bootstrap extends EventEmitter {
|
|
|
40
57
|
if (this.timer == null) {
|
|
41
58
|
return;
|
|
42
59
|
}
|
|
43
|
-
this.list.forEach((
|
|
44
|
-
|
|
45
|
-
return log.error('Invalid multiaddr');
|
|
46
|
-
}
|
|
47
|
-
const ma = new Multiaddr(candidate);
|
|
48
|
-
const peerIdStr = ma.getPeerId();
|
|
49
|
-
if (peerIdStr == null) {
|
|
50
|
-
log.error('Invalid bootstrap multiaddr without peer id');
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const peerId = PeerId.fromString(peerIdStr);
|
|
54
|
-
try {
|
|
55
|
-
this.emit('peer', {
|
|
56
|
-
id: peerId,
|
|
57
|
-
multiaddrs: [ma]
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
log.error('Invalid bootstrap peer id', err);
|
|
62
|
-
}
|
|
60
|
+
this.list.forEach((peerData) => {
|
|
61
|
+
this.emit('peer', peerData);
|
|
63
62
|
});
|
|
64
63
|
}
|
|
65
64
|
/**
|
|
66
65
|
* Stop emitting events
|
|
67
66
|
*/
|
|
68
67
|
stop() {
|
|
69
|
-
if (this.timer != null)
|
|
68
|
+
if (this.timer != null) {
|
|
70
69
|
clearInterval(this.timer);
|
|
71
|
-
|
|
70
|
+
}
|
|
71
|
+
this.timer = undefined;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
Bootstrap.tag = 'bootstrap';
|
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,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE;IACnD,KAAK,EAAE,KAAK,CAAC,wBAAwB,CAAC;CACvC,CAAC,CAAA;AAcF;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,YAAY;IAOzC,YAAa,UAA4B,EAAE,IAAI,EAAE,EAAE,EAAE;QACnD,IAAI,OAAO,CAAC,IAAI,IAAI,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;SAC/D;QACD,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,KAAK,CAAA;QACzC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAA;QAEd,KAAK,MAAM,SA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,CAAA;IACJ,CAAC;IAED;;OAEG;IACH,IAAI;QACF,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE;YACtB,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC1B;QAED,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;IACxB,CAAC;;AA9EM,aAAG,GAAG,WAAW,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/bootstrap",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.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",
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
},
|
|
121
121
|
"scripts": {
|
|
122
122
|
"lint": "aegir lint",
|
|
123
|
-
"dep-check": "aegir dep-check",
|
|
123
|
+
"dep-check": "aegir dep-check dist/**/*.js",
|
|
124
124
|
"build": "tsc",
|
|
125
125
|
"pretest": "npm run build",
|
|
126
126
|
"test": "aegir test -f ./dist/test",
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { P2P } from '@multiformats/mafmt'
|
|
|
4
4
|
import { EventEmitter } from 'events'
|
|
5
5
|
import debug from 'debug'
|
|
6
6
|
import type PeerDiscovery from '@libp2p/interfaces/peer-discovery'
|
|
7
|
+
import type { PeerData } from '@libp2p/interfaces/peer-data'
|
|
7
8
|
|
|
8
9
|
const log = Object.assign(debug('libp2p:bootstrap'), {
|
|
9
10
|
error: debug('libp2p:bootstrap:error')
|
|
@@ -27,8 +28,8 @@ export interface BootstrapOptions {
|
|
|
27
28
|
export class Bootstrap extends EventEmitter implements PeerDiscovery {
|
|
28
29
|
static tag = 'bootstrap'
|
|
29
30
|
|
|
30
|
-
private timer
|
|
31
|
-
private readonly list:
|
|
31
|
+
private timer?: NodeJS.Timer
|
|
32
|
+
private readonly list: PeerData[]
|
|
32
33
|
private readonly interval: number
|
|
33
34
|
|
|
34
35
|
constructor (options: BootstrapOptions = { list: [] }) {
|
|
@@ -37,9 +38,31 @@ export class Bootstrap extends EventEmitter implements PeerDiscovery {
|
|
|
37
38
|
}
|
|
38
39
|
super()
|
|
39
40
|
|
|
40
|
-
this.list = options.list
|
|
41
41
|
this.interval = options.interval ?? 10000
|
|
42
|
-
this.
|
|
42
|
+
this.list = []
|
|
43
|
+
|
|
44
|
+
for (const candidate of options.list) {
|
|
45
|
+
if (!P2P.matches(candidate)) {
|
|
46
|
+
log.error('Invalid multiaddr')
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const ma = new Multiaddr(candidate)
|
|
51
|
+
const peerIdStr = ma.getPeerId()
|
|
52
|
+
|
|
53
|
+
if (peerIdStr == null) {
|
|
54
|
+
log.error('Invalid bootstrap multiaddr without peer id')
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const peerData: PeerData = {
|
|
59
|
+
id: PeerId.fromString(peerIdStr),
|
|
60
|
+
multiaddrs: [ma],
|
|
61
|
+
protocols: []
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.list.push(peerData)
|
|
65
|
+
}
|
|
43
66
|
}
|
|
44
67
|
|
|
45
68
|
isStarted () {
|
|
@@ -67,29 +90,8 @@ export class Bootstrap extends EventEmitter implements PeerDiscovery {
|
|
|
67
90
|
return
|
|
68
91
|
}
|
|
69
92
|
|
|
70
|
-
this.list.forEach((
|
|
71
|
-
|
|
72
|
-
return log.error('Invalid multiaddr')
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const ma = new Multiaddr(candidate)
|
|
76
|
-
const peerIdStr = ma.getPeerId()
|
|
77
|
-
|
|
78
|
-
if (peerIdStr == null) {
|
|
79
|
-
log.error('Invalid bootstrap multiaddr without peer id')
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const peerId = PeerId.fromString(peerIdStr)
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
this.emit('peer', {
|
|
87
|
-
id: peerId,
|
|
88
|
-
multiaddrs: [ma]
|
|
89
|
-
})
|
|
90
|
-
} catch (err) {
|
|
91
|
-
log.error('Invalid bootstrap peer id', err)
|
|
92
|
-
}
|
|
93
|
+
this.list.forEach((peerData) => {
|
|
94
|
+
this.emit('peer', peerData)
|
|
93
95
|
})
|
|
94
96
|
}
|
|
95
97
|
|
|
@@ -97,7 +99,10 @@ export class Bootstrap extends EventEmitter implements PeerDiscovery {
|
|
|
97
99
|
* Stop emitting events
|
|
98
100
|
*/
|
|
99
101
|
stop () {
|
|
100
|
-
if (this.timer != null)
|
|
101
|
-
|
|
102
|
+
if (this.timer != null) {
|
|
103
|
+
clearInterval(this.timer)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.timer = undefined
|
|
102
107
|
}
|
|
103
108
|
}
|