@libp2p/bootstrap 0.14.0 → 1.0.2

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 CHANGED
@@ -1,21 +1,16 @@
1
- js-libp2p-bootstrap
2
- =================
1
+ # js-libp2p-bootstrap
3
2
 
4
3
  [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
5
4
  [![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
6
5
  [![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
7
6
  [![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
8
7
  [![](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-bootstrap.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-bootstrap)
9
- [![](https://img.shields.io/travis/libp2p/js-libp2p-bootstrap.svg?style=flat-square)](https://travis-ci.com/libp2p/js-libp2p-bootstrap)
8
+ [![Build Status](https://github.com/libp2p/js-libp2p-bootstrap/actions/workflows/js-test-and-release.yml/badge.svg?branch=main)](https://github.com/libp2p/js-libp2p-bootstrap/actions/workflows/js-test-and-release.yml)
10
9
  [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
11
10
  ![](https://img.shields.io/badge/Node.js-%3E%3D14.0.0-orange.svg?style=flat-square)
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.
@@ -1,6 +1,5 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import type PeerDiscovery from '@libp2p/interfaces/peer-discovery';
1
+ import { EventEmitter } from '@libp2p/interfaces';
2
+ import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interfaces/peer-discovery';
4
3
  export interface BootstrapOptions {
5
4
  /**
6
5
  * The list of peer addresses in multi-address format
@@ -14,9 +13,9 @@ export interface BootstrapOptions {
14
13
  /**
15
14
  * Emits 'peer' events on a regular interval for each peer in the provided list.
16
15
  */
17
- export declare class Bootstrap extends EventEmitter implements PeerDiscovery {
16
+ export declare class Bootstrap extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery {
18
17
  static tag: string;
19
- private timer;
18
+ private timer?;
20
19
  private readonly list;
21
20
  private readonly interval;
22
21
  constructor(options?: BootstrapOptions);
@@ -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;AAMlE,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,CAAqB;IAClC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAU;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;gBAEpB,OAAO,GAAE,gBAA+B;IAWrD,SAAS;IAIT;;OAEG;IACH,KAAK;IAUL;;OAEG;IACH,uBAAuB;IA+BvB;;OAEG;IACH,IAAI;CAIL"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAE9D,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AAM3F,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,YAAY,CAAC,mBAAmB,CAAE,YAAW,aAAa;IACvF,MAAM,CAAC,GAAG,SAAc;IAExB,OAAO,CAAC,KAAK,CAAC,CAAgC;IAC9C,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
@@ -1,11 +1,9 @@
1
- import { PeerId } from '@libp2p/peer-id';
2
1
  import { Multiaddr } from '@multiformats/multiaddr';
3
2
  import { P2P } from '@multiformats/mafmt';
4
- import { EventEmitter } from 'events';
5
- import debug from 'debug';
6
- const log = Object.assign(debug('libp2p:bootstrap'), {
7
- error: debug('libp2p:bootstrap:error')
8
- });
3
+ import { CustomEvent, EventEmitter } from '@libp2p/interfaces';
4
+ import { logger } from '@libp2p/logger';
5
+ import { peerIdFromString } from '@libp2p/peer-id';
6
+ const log = logger('libp2p:bootstrap');
9
7
  /**
10
8
  * Emits 'peer' events on a regular interval for each peer in the provided list.
11
9
  */
@@ -15,9 +13,26 @@ export class Bootstrap extends EventEmitter {
15
13
  throw new Error('Bootstrap requires a list of peer addresses');
16
14
  }
17
15
  super();
18
- this.list = options.list;
19
16
  this.interval = options.interval ?? 10000;
20
- this.timer = null;
17
+ this.list = [];
18
+ for (const candidate of options.list) {
19
+ if (!P2P.matches(candidate)) {
20
+ log.error('Invalid multiaddr');
21
+ continue;
22
+ }
23
+ const ma = new Multiaddr(candidate);
24
+ const peerIdStr = ma.getPeerId();
25
+ if (peerIdStr == null) {
26
+ log.error('Invalid bootstrap multiaddr without peer id');
27
+ continue;
28
+ }
29
+ const peerData = {
30
+ id: peerIdFromString(peerIdStr),
31
+ multiaddrs: [ma],
32
+ protocols: []
33
+ };
34
+ this.list.push(peerData);
35
+ }
21
36
  }
22
37
  isStarted() {
23
38
  return Boolean(this.timer);
@@ -40,35 +55,18 @@ export class Bootstrap extends EventEmitter {
40
55
  if (this.timer == null) {
41
56
  return;
42
57
  }
43
- this.list.forEach((candidate) => {
44
- if (!P2P.matches(candidate)) {
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
- }
58
+ this.list.forEach((peerData) => {
59
+ this.dispatchEvent(new CustomEvent('peer', { detail: peerData }));
63
60
  });
64
61
  }
65
62
  /**
66
63
  * Stop emitting events
67
64
  */
68
65
  stop() {
69
- if (this.timer != null)
66
+ if (this.timer != null) {
70
67
  clearInterval(this.timer);
71
- this.timer = null;
68
+ }
69
+ this.timer = undefined;
72
70
  }
73
71
  }
74
72
  Bootstrap.tag = 'bootstrap';
@@ -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;AAGzB,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,Y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;QAED,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC7B,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAW,MAAM,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAA;QAC7E,CAAC,CAAC,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.14.0",
3
+ "version": "1.0.2",
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",
@@ -133,15 +133,14 @@
133
133
  "release": "semantic-release"
134
134
  },
135
135
  "dependencies": {
136
- "@libp2p/peer-id": "^1.0.4",
136
+ "@libp2p/interfaces": "^1.3.18",
137
+ "@libp2p/logger": "^1.1.2",
138
+ "@libp2p/peer-id": "^1.1.8",
137
139
  "@multiformats/mafmt": "^11.0.2",
138
- "@multiformats/multiaddr": "^10.1.2",
139
- "debug": "^4.3.1"
140
+ "@multiformats/multiaddr": "^10.1.7"
140
141
  },
141
142
  "devDependencies": {
142
- "@libp2p/interface-compliance-tests": "^1.0.8",
143
- "@libp2p/interfaces": "^1.1.1",
144
- "@types/debug": "^4.1.5",
143
+ "@libp2p/interface-compliance-tests": "^1.1.20",
145
144
  "aegir": "^36.1.3"
146
145
  }
147
146
  }
package/src/index.ts CHANGED
@@ -1,13 +1,12 @@
1
- import { PeerId } from '@libp2p/peer-id'
2
1
  import { Multiaddr } from '@multiformats/multiaddr'
3
2
  import { P2P } from '@multiformats/mafmt'
4
- import { EventEmitter } from 'events'
5
- import debug from 'debug'
6
- import type PeerDiscovery from '@libp2p/interfaces/peer-discovery'
3
+ import { CustomEvent, EventEmitter } from '@libp2p/interfaces'
4
+ import { logger } from '@libp2p/logger'
5
+ import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interfaces/peer-discovery'
6
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info'
7
+ import { peerIdFromString } from '@libp2p/peer-id'
7
8
 
8
- const log = Object.assign(debug('libp2p:bootstrap'), {
9
- error: debug('libp2p:bootstrap:error')
10
- })
9
+ const log = logger('libp2p:bootstrap')
11
10
 
12
11
  export interface BootstrapOptions {
13
12
  /**
@@ -24,11 +23,11 @@ export interface BootstrapOptions {
24
23
  /**
25
24
  * Emits 'peer' events on a regular interval for each peer in the provided list.
26
25
  */
27
- export class Bootstrap extends EventEmitter implements PeerDiscovery {
26
+ export class Bootstrap extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery {
28
27
  static tag = 'bootstrap'
29
28
 
30
- private timer: NodeJS.Timer | null
31
- private readonly list: string[]
29
+ private timer?: ReturnType<typeof setInterval>
30
+ private readonly list: PeerInfo[]
32
31
  private readonly interval: number
33
32
 
34
33
  constructor (options: BootstrapOptions = { list: [] }) {
@@ -37,9 +36,31 @@ export class Bootstrap extends EventEmitter implements PeerDiscovery {
37
36
  }
38
37
  super()
39
38
 
40
- this.list = options.list
41
39
  this.interval = options.interval ?? 10000
42
- this.timer = null
40
+ this.list = []
41
+
42
+ for (const candidate of options.list) {
43
+ if (!P2P.matches(candidate)) {
44
+ log.error('Invalid multiaddr')
45
+ continue
46
+ }
47
+
48
+ const ma = new Multiaddr(candidate)
49
+ const peerIdStr = ma.getPeerId()
50
+
51
+ if (peerIdStr == null) {
52
+ log.error('Invalid bootstrap multiaddr without peer id')
53
+ continue
54
+ }
55
+
56
+ const peerData: PeerInfo = {
57
+ id: peerIdFromString(peerIdStr),
58
+ multiaddrs: [ma],
59
+ protocols: []
60
+ }
61
+
62
+ this.list.push(peerData)
63
+ }
43
64
  }
44
65
 
45
66
  isStarted () {
@@ -67,29 +88,8 @@ export class Bootstrap extends EventEmitter implements PeerDiscovery {
67
88
  return
68
89
  }
69
90
 
70
- this.list.forEach((candidate) => {
71
- if (!P2P.matches(candidate)) {
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
- }
91
+ this.list.forEach((peerData) => {
92
+ this.dispatchEvent(new CustomEvent<PeerInfo>('peer', { detail: peerData }))
93
93
  })
94
94
  }
95
95
 
@@ -97,7 +97,10 @@ export class Bootstrap extends EventEmitter implements PeerDiscovery {
97
97
  * Stop emitting events
98
98
  */
99
99
  stop () {
100
- if (this.timer != null) clearInterval(this.timer)
101
- this.timer = null
100
+ if (this.timer != null) {
101
+ clearInterval(this.timer)
102
+ }
103
+
104
+ this.timer = undefined
102
105
  }
103
106
  }