@libp2p/bootstrap
Advanced tools
Comparing version
@@ -19,3 +19,3 @@ /// <reference types="node" /> | ||
static tag: string; | ||
private timer; | ||
private timer?; | ||
private readonly list; | ||
@@ -22,0 +22,0 @@ private readonly interval; |
@@ -18,5 +18,22 @@ import { PeerId } from '@libp2p/peer-id'; | ||
super(); | ||
this.list = options.list; | ||
this.interval = options.interval ?? 10000; | ||
this.timer = null; | ||
this.list = []; | ||
for (const candidate of options.list) { | ||
if (!P2P.matches(candidate)) { | ||
log.error('Invalid multiaddr'); | ||
continue; | ||
} | ||
const ma = new Multiaddr(candidate); | ||
const peerIdStr = ma.getPeerId(); | ||
if (peerIdStr == null) { | ||
log.error('Invalid bootstrap multiaddr without peer id'); | ||
continue; | ||
} | ||
const peerData = { | ||
id: PeerId.fromString(peerIdStr), | ||
multiaddrs: [ma], | ||
protocols: [] | ||
}; | ||
this.list.push(peerData); | ||
} | ||
} | ||
@@ -44,22 +61,4 @@ isStarted() { | ||
} | ||
this.list.forEach((candidate) => { | ||
if (!P2P.matches(candidate)) { | ||
return log.error('Invalid multiaddr'); | ||
} | ||
const ma = new Multiaddr(candidate); | ||
const peerIdStr = ma.getPeerId(); | ||
if (peerIdStr == null) { | ||
log.error('Invalid bootstrap multiaddr without peer id'); | ||
return; | ||
} | ||
const peerId = PeerId.fromString(peerIdStr); | ||
try { | ||
this.emit('peer', { | ||
id: peerId, | ||
multiaddrs: [ma] | ||
}); | ||
} | ||
catch (err) { | ||
log.error('Invalid bootstrap peer id', err); | ||
} | ||
this.list.forEach((peerData) => { | ||
this.emit('peer', peerData); | ||
}); | ||
@@ -71,5 +70,6 @@ } | ||
stop() { | ||
if (this.timer != null) | ||
if (this.timer != null) { | ||
clearInterval(this.timer); | ||
this.timer = null; | ||
} | ||
this.timer = undefined; | ||
} | ||
@@ -76,0 +76,0 @@ } |
{ | ||
"name": "@libp2p/bootstrap", | ||
"version": "0.14.0", | ||
"version": "1.0.0", | ||
"description": "Node.js IPFS Implementation of the railing process of a Node through a bootstrap peer list", | ||
@@ -123,3 +123,3 @@ "license": "Apache-2.0 OR MIT", | ||
"lint": "aegir lint", | ||
"dep-check": "aegir dep-check", | ||
"dep-check": "aegir dep-check dist/**/*.js", | ||
"build": "tsc", | ||
@@ -126,0 +126,0 @@ "pretest": "npm run build", |
@@ -1,3 +0,2 @@ | ||
js-libp2p-bootstrap | ||
================= | ||
# js-libp2p-bootstrap | ||
@@ -9,3 +8,3 @@ [](http://protocol.ai) | ||
[](https://codecov.io/gh/libp2p/js-libp2p-bootstrap) | ||
[](https://travis-ci.com/libp2p/js-libp2p-bootstrap) | ||
[](https://github.com/libp2p/js-libp2p-bootstrap/actions/workflows/js-test-and-release.yml) | ||
[](https://github.com/feross/standard) | ||
@@ -16,6 +15,2 @@  | ||
## Lead Maintainer | ||
[Vasco Santos](https://github.com/vasco-santos). | ||
## Usage | ||
@@ -43,3 +38,3 @@ | ||
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", | ||
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa" | ||
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa" | ||
], | ||
@@ -66,1 +61,19 @@ interval: 5000 // default is 10 ms, | ||
``` | ||
## Contribute | ||
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: | ||
- 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. | ||
- **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs. | ||
## License | ||
Licensed under either of | ||
* Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0) | ||
* MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT) | ||
### Contribution | ||
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. |
@@ -7,2 +7,3 @@ import { PeerId } from '@libp2p/peer-id' | ||
import type PeerDiscovery from '@libp2p/interfaces/peer-discovery' | ||
import type { PeerData } from '@libp2p/interfaces/peer-data' | ||
@@ -31,4 +32,4 @@ const log = Object.assign(debug('libp2p:bootstrap'), { | ||
private timer: NodeJS.Timer | null | ||
private readonly list: string[] | ||
private timer?: NodeJS.Timer | ||
private readonly list: PeerData[] | ||
private readonly interval: number | ||
@@ -42,5 +43,27 @@ | ||
this.list = options.list | ||
this.interval = options.interval ?? 10000 | ||
this.timer = null | ||
this.list = [] | ||
for (const candidate of options.list) { | ||
if (!P2P.matches(candidate)) { | ||
log.error('Invalid multiaddr') | ||
continue | ||
} | ||
const ma = new Multiaddr(candidate) | ||
const peerIdStr = ma.getPeerId() | ||
if (peerIdStr == null) { | ||
log.error('Invalid bootstrap multiaddr without peer id') | ||
continue | ||
} | ||
const peerData: PeerData = { | ||
id: PeerId.fromString(peerIdStr), | ||
multiaddrs: [ma], | ||
protocols: [] | ||
} | ||
this.list.push(peerData) | ||
} | ||
} | ||
@@ -73,25 +96,4 @@ | ||
this.list.forEach((candidate) => { | ||
if (!P2P.matches(candidate)) { | ||
return log.error('Invalid multiaddr') | ||
} | ||
const ma = new Multiaddr(candidate) | ||
const peerIdStr = ma.getPeerId() | ||
if (peerIdStr == null) { | ||
log.error('Invalid bootstrap multiaddr without peer id') | ||
return | ||
} | ||
const peerId = PeerId.fromString(peerIdStr) | ||
try { | ||
this.emit('peer', { | ||
id: peerId, | ||
multiaddrs: [ma] | ||
}) | ||
} catch (err) { | ||
log.error('Invalid bootstrap peer id', err) | ||
} | ||
this.list.forEach((peerData) => { | ||
this.emit('peer', peerData) | ||
}) | ||
@@ -104,5 +106,8 @@ } | ||
stop () { | ||
if (this.timer != null) clearInterval(this.timer) | ||
this.timer = null | ||
if (this.timer != null) { | ||
clearInterval(this.timer) | ||
} | ||
this.timer = undefined | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15524
7.81%199
1.53%0
-100%76
20.63%