mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-09 05:41:33 +00:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
7068aae527 | |||
d632451f92 | |||
8047e3fe64 | |||
35af31023c | |||
078956b310 | |||
4f44158889 | |||
3a8d51c142 | |||
f8c09db20f | |||
ee801c9be2 | |||
03349d7caf | |||
0c87dbc8f3 |
@ -41,7 +41,7 @@ To sum up, libp2p is a "network stack" -- a protocol suite -- that cleanly separ
|
|||||||
|
|
||||||
With its modular nature, libp2p can be found being used in different projects with different sets of features, while perserving the same top level API. `js-libp2p` is only a skelleton and should not be installed directly, if you are looking for a prebundled libp2p stack, please check:
|
With its modular nature, libp2p can be found being used in different projects with different sets of features, while perserving the same top level API. `js-libp2p` is only a skelleton and should not be installed directly, if you are looking for a prebundled libp2p stack, please check:
|
||||||
|
|
||||||
- [libp2p-ipfs](https://github.com/ipfs/js-libp2p-ipfs) - The libp2p build used by js-ipfs when run in Node.js
|
- [libp2p-ipfs-nodejs](https://github.com/ipfs/js-libp2p-ipfs-nodejs) - The libp2p build used by js-ipfs when run in Node.js
|
||||||
- [libp2p-ipfs-browser](https://github.com/ipfs/js-libp2p-ipfs-browser) - The libp2p build used by js-ipfs when run in a Browser (that supports WebRTC)
|
- [libp2p-ipfs-browser](https://github.com/ipfs/js-libp2p-ipfs-browser) - The libp2p build used by js-ipfs when run in a Browser (that supports WebRTC)
|
||||||
|
|
||||||
If you have developed a libp2p bundle, please consider submitting it to this list so that it can be found easily by the users of libp2p.
|
If you have developed a libp2p bundle, please consider submitting it to this list so that it can be found easily by the users of libp2p.
|
||||||
@ -81,7 +81,7 @@ Defined by [interface-libp2p](https://github.com/libp2p/interface-libp2p)
|
|||||||
| Package | Version | Dependencies | DevDependencies |
|
| Package | Version | Dependencies | DevDependencies |
|
||||||
|---------|---------|--------------|-----------------|
|
|---------|---------|--------------|-----------------|
|
||||||
| **Bundles** |
|
| **Bundles** |
|
||||||
| [`libp2p-ipfs`](//github.com/ipfs/js-libp2p-ipfs) | [](//github.com/ipfs/js-libp2p-ipfs/releases) | [](https://david-dm.org/ipfs/js-libp2p-ipfs) | [](https://david-dm.org/ipfs/js-libp2p-ipfs?type=dev) |
|
| [`libp2p-ipfs-nodejs`](//github.com/ipfs/js-libp2p-ipfs-nodejs) | [](//github.com/ipfs/js-libp2p-ipfs-nodejs/releases) | [](https://david-dm.org/ipfs/js-libp2p-ipfs-nodejs) | [](https://david-dm.org/ipfs/js-libp2p-ipfs-nodejs?type=dev) |
|
||||||
| [`libp2p-ipfs-browser`](//github.com/ipfs/js-libp2p-ipfs-browser) | [](//github.com/ipfs/js-libp2p-ipfs-browser/releases) | [](https://david-dm.org/ipfs/js-libp2p-ipfs-browser) | [](https://david-dm.org/ipfs/js-libp2p-ipfs-browser?type=dev) |
|
| [`libp2p-ipfs-browser`](//github.com/ipfs/js-libp2p-ipfs-browser) | [](//github.com/ipfs/js-libp2p-ipfs-browser/releases) | [](https://david-dm.org/ipfs/js-libp2p-ipfs-browser) | [](https://david-dm.org/ipfs/js-libp2p-ipfs-browser?type=dev) |
|
||||||
| **Transports** |
|
| **Transports** |
|
||||||
| [`libp2p-utp`](//github.com/libp2p/js-libp2p-utp) | [](//github.com/libp2p/js-libp2p-utp/releases) | [](https://david-dm.org/libp2p/js-libp2p-utp) | [](https://david-dm.org/libp2p/js-libp2p-utp?type=dev) |
|
| [`libp2p-utp`](//github.com/libp2p/js-libp2p-utp) | [](//github.com/libp2p/js-libp2p-utp/releases) | [](https://david-dm.org/libp2p/js-libp2p-utp) | [](https://david-dm.org/libp2p/js-libp2p-utp?type=dev) |
|
||||||
|
17
package.json
17
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "libp2p",
|
"name": "libp2p",
|
||||||
"version": "0.2.1",
|
"version": "0.4.0",
|
||||||
"description": "JavaScript Skeleton for libp2p bundles",
|
"description": "JavaScript Skeleton for libp2p bundles",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -35,16 +35,17 @@
|
|||||||
"homepage": "https://github.com/diasdavid/js-libp2p",
|
"homepage": "https://github.com/diasdavid/js-libp2p",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"aegir": "^9.1.2",
|
"aegir": "^9.4.0",
|
||||||
"pre-commit": "^1.1.1"
|
"pre-commit": "^1.2.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"libp2p-swarm": "^0.26.3",
|
"libp2p-ping": "^0.3.0",
|
||||||
"mafmt": "^2.1.2",
|
"libp2p-swarm": "^0.26.13",
|
||||||
"multiaddr": "^2.1.1",
|
"mafmt": "^2.1.6",
|
||||||
|
"multiaddr": "^2.2.0",
|
||||||
"peer-book": "^0.3.0",
|
"peer-book": "^0.3.0",
|
||||||
"peer-id": "^0.8.0",
|
"peer-id": "^0.8.1",
|
||||||
"peer-info": "^0.8.1"
|
"peer-info": "^0.8.2"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"David Dias <daviddias.p@gmail.com>",
|
"David Dias <daviddias.p@gmail.com>",
|
||||||
|
46
src/index.js
46
src/index.js
@ -8,6 +8,7 @@ const multiaddr = require('multiaddr')
|
|||||||
const mafmt = require('mafmt')
|
const mafmt = require('mafmt')
|
||||||
const EE = require('events').EventEmitter
|
const EE = require('events').EventEmitter
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
|
const Ping = require('libp2p-ping')
|
||||||
|
|
||||||
exports = module.exports
|
exports = module.exports
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ class Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attach discovery mechanisms
|
// Attach discovery mechanisms
|
||||||
if (this.discovery) {
|
if (this.modules.discovery) {
|
||||||
let discoveries = this.modules.discovery
|
let discoveries = this.modules.discovery
|
||||||
discoveries = Array.isArray(discoveries) ? discoveries : [discoveries]
|
discoveries = Array.isArray(discoveries) ? discoveries : [discoveries]
|
||||||
discoveries.forEach((discovery) => {
|
discoveries.forEach((discovery) => {
|
||||||
@ -70,6 +71,9 @@ class Node {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mount default protocols
|
||||||
|
Ping.mount(this.swarm)
|
||||||
|
|
||||||
// Not fully implemented in js-libp2p yet
|
// Not fully implemented in js-libp2p yet
|
||||||
this.routing = undefined
|
this.routing = undefined
|
||||||
this.records = undefined
|
this.records = undefined
|
||||||
@ -111,6 +115,13 @@ class Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.isOnline = true
|
this.isOnline = true
|
||||||
|
|
||||||
|
if (this.modules.discovery) {
|
||||||
|
this.modules.discovery.forEach((discovery) => {
|
||||||
|
setImmediate(() => discovery.start(() => {}))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
callback()
|
callback()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -120,9 +131,38 @@ class Node {
|
|||||||
*/
|
*/
|
||||||
stop (callback) {
|
stop (callback) {
|
||||||
this.isOnline = false
|
this.isOnline = false
|
||||||
|
|
||||||
|
if (this.modules.discovery) {
|
||||||
|
this.modules.discovery.forEach((discovery) => {
|
||||||
|
console.log(discovery)
|
||||||
|
setImmediate(() => discovery.stop(() => {}))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
this.swarm.close(callback)
|
this.swarm.close(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Ping
|
||||||
|
//
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
pingById (id, callback) {
|
||||||
|
assert(this.isOnline, OFFLINE_ERROR_MESSAGE)
|
||||||
|
callback(new Error('not implemented yet'))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
pingByMultiaddr (maddr, callback) {
|
||||||
|
assert(this.isOnline, OFFLINE_ERROR_MESSAGE)
|
||||||
|
callback(new Error('not implemented yet'))
|
||||||
|
}
|
||||||
|
|
||||||
|
pingByPeerInfo (peerInfo, callback) {
|
||||||
|
assert(this.isOnline, OFFLINE_ERROR_MESSAGE)
|
||||||
|
callback(null, new Ping(this.swarm, peerInfo))
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Dialing methods
|
// Dialing methods
|
||||||
//
|
//
|
||||||
@ -247,6 +287,4 @@ class Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = Node
|
||||||
Node: Node
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user