mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-23 12:31:57 +00:00
Compare commits
12 Commits
v0.25.2
...
docs/deleg
Author | SHA1 | Date | |
---|---|---|---|
|
8c4dbe2766 | ||
|
27af24ffc1 | ||
|
10811e9ced | ||
|
9c2789bc15 | ||
|
24be691bc1 | ||
|
9433c6c398 | ||
|
04faf1806c | ||
|
b06ca1b3c7 | ||
|
bde30cac45 | ||
|
28c054c21e | ||
|
c346e8066b | ||
|
40978a1940 |
19
.aegir.js
19
.aegir.js
@@ -22,13 +22,12 @@ const before = (done) => {
|
|||||||
sigServer.start({
|
sigServer.start({
|
||||||
port: WRTC_RENDEZVOUS_MULTIADDR.nodeAddress().port
|
port: WRTC_RENDEZVOUS_MULTIADDR.nodeAddress().port
|
||||||
// cryptoChallenge: true TODO: needs https://github.com/libp2p/js-libp2p-webrtc-star/issues/128
|
// cryptoChallenge: true TODO: needs https://github.com/libp2p/js-libp2p-webrtc-star/issues/128
|
||||||
}, (err, server) => {
|
})
|
||||||
if (err) {
|
.then(server => {
|
||||||
return cb(err)
|
|
||||||
}
|
|
||||||
wrtcRendezvous = server
|
wrtcRendezvous = server
|
||||||
cb()
|
cb()
|
||||||
})
|
})
|
||||||
|
.catch(cb)
|
||||||
},
|
},
|
||||||
(cb) => {
|
(cb) => {
|
||||||
WebSocketStarRendezvous.start({
|
WebSocketStarRendezvous.start({
|
||||||
@@ -72,14 +71,16 @@ const before = (done) => {
|
|||||||
|
|
||||||
const after = (done) => {
|
const after = (done) => {
|
||||||
setTimeout(() =>
|
setTimeout(() =>
|
||||||
parallel(
|
parallel([
|
||||||
[node, wrtcRendezvous, wsRendezvous].map((s) => (cb) => s.stop(cb)),
|
(cb) => wrtcRendezvous.stop().then(cb).catch(cb),
|
||||||
done),
|
...[node, wsRendezvous].map((s) => (cb) => s.stop(cb)),
|
||||||
2000)
|
], done),
|
||||||
|
2000
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
bundlesize: { maxSize: '218kB' },
|
bundlesize: { maxSize: '220kB' },
|
||||||
hooks: {
|
hooks: {
|
||||||
pre: before,
|
pre: before,
|
||||||
post: after
|
post: after
|
||||||
|
@@ -7,6 +7,7 @@ stages:
|
|||||||
|
|
||||||
node_js:
|
node_js:
|
||||||
- '10'
|
- '10'
|
||||||
|
- '12'
|
||||||
|
|
||||||
os:
|
os:
|
||||||
- linux
|
- linux
|
||||||
@@ -20,7 +21,6 @@ jobs:
|
|||||||
- stage: check
|
- stage: check
|
||||||
script:
|
script:
|
||||||
- npx aegir build --bundlesize
|
- npx aegir build --bundlesize
|
||||||
- npx aegir commitlint --travis
|
|
||||||
- npx aegir dep-check -- -i wrtc -i electron-webrtc
|
- npx aegir dep-check -- -i wrtc -i electron-webrtc
|
||||||
- npm run lint
|
- npm run lint
|
||||||
|
|
||||||
|
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,3 +1,24 @@
|
|||||||
|
<a name="0.25.4"></a>
|
||||||
|
## [0.25.4](https://github.com/libp2p/js-libp2p/compare/v0.25.3...v0.25.4) (2019-06-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add createLibp2p to generate a PeerInfo instance ([#367](https://github.com/libp2p/js-libp2p/issues/367)) ([04faf18](https://github.com/libp2p/js-libp2p/commit/04faf18))
|
||||||
|
* pass libp2p as option to transport creation ([#363](https://github.com/libp2p/js-libp2p/issues/363)) ([b06ca1b](https://github.com/libp2p/js-libp2p/commit/b06ca1b))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.25.3"></a>
|
||||||
|
## [0.25.3](https://github.com/libp2p/js-libp2p/compare/v0.25.2...v0.25.3) (2019-05-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* sign pubsub messages ([#362](https://github.com/libp2p/js-libp2p/issues/362)) ([40978a1](https://github.com/libp2p/js-libp2p/commit/40978a1))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="0.25.2"></a>
|
<a name="0.25.2"></a>
|
||||||
## [0.25.2](https://github.com/libp2p/js-libp2p/compare/v0.25.1...v0.25.2) (2019-04-17)
|
## [0.25.2](https://github.com/libp2p/js-libp2p/compare/v0.25.1...v0.25.2) (2019-04-17)
|
||||||
|
|
||||||
|
26
README.md
26
README.md
@@ -111,7 +111,7 @@ The libp2p module acts as a glue for every libp2p module that you can use to cre
|
|||||||
// crypto-channel: secio
|
// crypto-channel: secio
|
||||||
// discovery: multicast-dns
|
// discovery: multicast-dns
|
||||||
|
|
||||||
const libp2p = require('libp2p')
|
const Libp2p = require('libp2p')
|
||||||
const TCP = require('libp2p-tcp')
|
const TCP = require('libp2p-tcp')
|
||||||
const WS = require('libp2p-websockets')
|
const WS = require('libp2p-websockets')
|
||||||
const SPDY = require('libp2p-spdy')
|
const SPDY = require('libp2p-spdy')
|
||||||
@@ -124,7 +124,7 @@ const Protector = require('libp2p-pnet')
|
|||||||
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
|
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
|
||||||
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
|
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
|
||||||
|
|
||||||
class Node extends libp2p {
|
class Node extends Libp2p {
|
||||||
constructor (_options) {
|
constructor (_options) {
|
||||||
const peerInfo = _options.peerInfo
|
const peerInfo = _options.peerInfo
|
||||||
const defaults = {
|
const defaults = {
|
||||||
@@ -204,13 +204,31 @@ class Node extends libp2p {
|
|||||||
|
|
||||||
### API
|
### API
|
||||||
|
|
||||||
#### Create a Node - `new libp2p.Node(options)`
|
#### Create a Node - `Libp2p.createLibp2p(options, callback)`
|
||||||
|
|
||||||
> Creates an instance of the libp2p.Node.
|
> Behaves exactly like `new Libp2p(options)`, but doesn't require a PeerInfo. One will be generated instead
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { createLibp2p } = require('libp2p')
|
||||||
|
createLibp2p(options, (err, libp2p) => {
|
||||||
|
if (err) throw err
|
||||||
|
libp2p.start((err) => {
|
||||||
|
if (err) throw err
|
||||||
|
})
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
- `options`: Object of libp2p configuration options
|
||||||
|
- `callback`: Function with signature `function (Error, Libp2p) {}`
|
||||||
|
|
||||||
|
#### Create a Node alternative - `new Libp2p(options)`
|
||||||
|
|
||||||
|
> Creates an instance of Libp2p with a custom `PeerInfo` provided via `options.peerInfo`.
|
||||||
|
|
||||||
Required keys in the `options` object:
|
Required keys in the `options` object:
|
||||||
|
|
||||||
- `peerInfo`: instance of [PeerInfo][] that contains the [PeerId][], Keys and [multiaddrs][multiaddr] of the libp2p Node.
|
- `peerInfo`: instance of [PeerInfo][] that contains the [PeerId][], Keys and [multiaddrs][multiaddr] of the libp2p Node.
|
||||||
|
- `modules.transport`: An array that must include at least 1 transport, such as `libp2p-tcp`.
|
||||||
|
|
||||||
#### `libp2p.start(callback)`
|
#### `libp2p.start(callback)`
|
||||||
|
|
||||||
|
@@ -10,18 +10,17 @@ The starting [Libp2p Bundle](./src/libp2p-bundle.js) in this example starts by d
|
|||||||
Once you've completed the example, you should try enabled the DHT and see what kind of results you get! You can also enable the
|
Once you've completed the example, you should try enabled the DHT and see what kind of results you get! You can also enable the
|
||||||
various Peer Discovery modules and see the impact it has on your Peer count.
|
various Peer Discovery modules and see the impact it has on your Peer count.
|
||||||
|
|
||||||
## Prerequisite
|
|
||||||
**NOTE**: This example is currently dependent on a clone of the [delegated routing support branch of go-ipfs](https://github.com/ipfs/go-ipfs/pull/4595).
|
|
||||||
|
|
||||||
## Running this example
|
## Running this example
|
||||||
|
|
||||||
1. Install IPFS locally if you dont already have it. [Install Guide](https://docs.ipfs.io/introduction/install/)
|
1. Install go-ipfs locally if you dont already have it. [Install Guide](https://docs.ipfs.io/introduction/install/).
|
||||||
2. Run the IPFS daemon: `ipfs daemon`
|
1. Run the IPFS daemon: `ipfs daemon`.
|
||||||
3. The daemon will output a line about its API address, like `API server listening on /ip4/127.0.0.1/tcp/8080`
|
1. The daemon will output a line about its API address, like `API server listening on /ip4/127.0.0.1/tcp/8080`.
|
||||||
4. In another window output the addresses of the node: `ipfs id`. Make note of the websocket address, it will contain `/ws/` in the address.
|
1. In another window, while the daemon is running, Configure the IPFS Gateway to support delegate routing `ipfs config Gateway.APICommands --json '["dht/findprovs", "dht/findpeer", "refs", "swarm/connect"]'`.
|
||||||
5. In `./src/libp2p-bundle.js` check if the host and port of your node are correct, according to the previous step. If they are different, replace them.
|
1. In the same window, output the addresses of the node: `ipfs id`. Make note of the websocket address, it will contain `/ws` in the address, like `/ip4/127.0.0.1/tcp/8081/ws`.
|
||||||
6. In `./src/App.js` replace `BootstrapNode` with your nodes Websocket address from step 4.
|
1. In `./src/libp2p-bundle.js` check if the host and port of your node are correct, according to the previous step. If they are different, replace them.
|
||||||
7. Start this example:
|
1. In `./src/App.js` replace `BootstrapNode` with your nodes Websocket address from step 3. **Also**, in `./src/App.js` set BootstrapNodeID to your nodes id, which is displayed when running `ipfs id` in the `ID` property.
|
||||||
|
1. Start this example:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm install
|
npm install
|
||||||
@@ -47,3 +46,12 @@ This will do a few things:
|
|||||||
2. Copy one of the CIDs from the list of peer addresses, this will be the last portion of the address and will look something like `QmdoG8DpzYUZMVP5dGmgmigZwR1RE8Cf6SxMPg1SBXJAQ8`.
|
2. Copy one of the CIDs from the list of peer addresses, this will be the last portion of the address and will look something like `QmdoG8DpzYUZMVP5dGmgmigZwR1RE8Cf6SxMPg1SBXJAQ8`.
|
||||||
3. In your browser, paste the CID into the *Peer* field and hit `Find`.
|
3. In your browser, paste the CID into the *Peer* field and hit `Find`.
|
||||||
4. You should see information about the peer including its addresses.
|
4. You should see information about the peer including its addresses.
|
||||||
|
|
||||||
|
### Adding Content via the Delegate
|
||||||
|
1. In one browser, such as Firefox, enter some text in the `Add Data` field and click `Add`.
|
||||||
|
2. Once added, JSON will be printed in the browser. Copy the value of `"hash"`.
|
||||||
|
3. Close your Firefox tab. Open a new browser window in a **different** browser, such as Chrome.
|
||||||
|
4. In the new window, copy the hash from step 2 into the `Hash` field and click `Find`.
|
||||||
|
5. The text you entered in step 1 should display.
|
||||||
|
|
||||||
|
**Note**: By closing the first window before fetching the content, you are ensuring that data cannot be retrieved from it, and instead the delegate must be relied on.
|
||||||
|
@@ -3,16 +3,16 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ipfs": "~0.34.4",
|
"ipfs": "~0.36.1",
|
||||||
"libp2p": "github:libp2p/js-libp2p#master",
|
"libp2p": "github:libp2p/js-libp2p#master",
|
||||||
"libp2p-delegated-content-routing": "~0.2.2",
|
"libp2p-delegated-content-routing": "~0.2.2",
|
||||||
"libp2p-delegated-peer-routing": "~0.2.2",
|
"libp2p-delegated-peer-routing": "~0.2.2",
|
||||||
"libp2p-kad-dht": "~0.14.12",
|
"libp2p-kad-dht": "~0.15.0",
|
||||||
"libp2p-mplex": "~0.8.5",
|
|
||||||
"libp2p-secio": "~0.11.1",
|
"libp2p-secio": "~0.11.1",
|
||||||
"libp2p-webrtc-star": "~0.15.8",
|
"libp2p-webrtc-star": "~0.16.1",
|
||||||
"libp2p-websocket-star": "~0.10.2",
|
"libp2p-websocket-star": "~0.10.2",
|
||||||
"libp2p-websockets": "~0.12.2",
|
"libp2p-websockets": "~0.12.2",
|
||||||
|
"pull-mplex": "~0.1.2",
|
||||||
"react": "^16.8.6",
|
"react": "^16.8.6",
|
||||||
"react-dom": "^16.8.6",
|
"react-dom": "^16.8.6",
|
||||||
"react-scripts": "2.1.8"
|
"react-scripts": "2.1.8"
|
||||||
|
@@ -6,7 +6,10 @@ import Ipfs from 'ipfs'
|
|||||||
import libp2pBundle from './libp2p-bundle'
|
import libp2pBundle from './libp2p-bundle'
|
||||||
const Component = React.Component
|
const Component = React.Component
|
||||||
|
|
||||||
const BootstrapNode = '/ip4/127.0.0.1/tcp/8081/ws/p2p/QmdoG8DpzYUZMVP5dGmgmigZwR1RE8Cf6SxMPg1SBXJAQ8'
|
/* TODO: Add your go IPFS nodes ID here by running `ipfs id` */
|
||||||
|
const BootstrapNodeID = 'Qm...'
|
||||||
|
/* TODO: Ensure the IP and port match your nodes Websocket address shown when running the daemon `ipfs daemon` */
|
||||||
|
const BootstrapNode = `/ip4/127.0.0.1/tcp/8081/ws/p2p/${BootstrapNodeID}`
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
@@ -17,6 +20,7 @@ class App extends Component {
|
|||||||
hash: 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB',
|
hash: 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB',
|
||||||
// This peer is one of the Bootstrap nodes for IPFS
|
// This peer is one of the Bootstrap nodes for IPFS
|
||||||
peer: 'QmV6kA2fB8kTr6jc3pL5zbNsjKbmPUHAPKKHRBYe1kDEyc',
|
peer: 'QmV6kA2fB8kTr6jc3pL5zbNsjKbmPUHAPKKHRBYe1kDEyc',
|
||||||
|
data: '',
|
||||||
isLoading: 0
|
isLoading: 0
|
||||||
}
|
}
|
||||||
this.peerInterval = null
|
this.peerInterval = null
|
||||||
@@ -25,6 +29,8 @@ class App extends Component {
|
|||||||
this.handleHashSubmit = this.handleHashSubmit.bind(this)
|
this.handleHashSubmit = this.handleHashSubmit.bind(this)
|
||||||
this.handlePeerChange = this.handlePeerChange.bind(this)
|
this.handlePeerChange = this.handlePeerChange.bind(this)
|
||||||
this.handlePeerSubmit = this.handlePeerSubmit.bind(this)
|
this.handlePeerSubmit = this.handlePeerSubmit.bind(this)
|
||||||
|
this.handleDataChange = this.handleDataChange.bind(this)
|
||||||
|
this.handleDataSubmit = this.handleDataSubmit.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleHashChange (event) {
|
handleHashChange (event) {
|
||||||
@@ -37,6 +43,11 @@ class App extends Component {
|
|||||||
peer: event.target.value
|
peer: event.target.value
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
handleDataChange (event) {
|
||||||
|
this.setState({
|
||||||
|
data: event.target.value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
handleHashSubmit (event) {
|
handleHashSubmit (event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@@ -44,7 +55,7 @@ class App extends Component {
|
|||||||
isLoading: this.state.isLoading + 1
|
isLoading: this.state.isLoading + 1
|
||||||
})
|
})
|
||||||
|
|
||||||
this.ipfs.files.cat(this.state.hash, (err, data) => {
|
this.ipfs.cat(this.state.hash, (err, data) => {
|
||||||
if (err) console.log('Error', err)
|
if (err) console.log('Error', err)
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -59,7 +70,22 @@ class App extends Component {
|
|||||||
isLoading: this.state.isLoading + 1
|
isLoading: this.state.isLoading + 1
|
||||||
})
|
})
|
||||||
|
|
||||||
this.ipfs.dht.findpeer(this.state.peer, (err, results) => {
|
this.ipfs.dht.findPeer(this.state.peer, (err, results) => {
|
||||||
|
if (err) console.log('Error', err)
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
response: JSON.stringify(results, null, 2),
|
||||||
|
isLoading: this.state.isLoading - 1
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
handleDataSubmit (event) {
|
||||||
|
event.preventDefault()
|
||||||
|
this.setState({
|
||||||
|
isLoading: this.state.isLoading + 1
|
||||||
|
})
|
||||||
|
|
||||||
|
this.ipfs.add(Buffer.from(this.state.data), (err, results) => {
|
||||||
if (err) console.log('Error', err)
|
if (err) console.log('Error', err)
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -135,6 +161,13 @@ class App extends Component {
|
|||||||
<input type="submit" value="Find" />
|
<input type="submit" value="Find" />
|
||||||
</label>
|
</label>
|
||||||
</form>
|
</form>
|
||||||
|
<form onSubmit={this.handleDataSubmit}>
|
||||||
|
<label>
|
||||||
|
Add Data:
|
||||||
|
<input type="text" value={this.state.data} onChange={this.handleDataChange} />
|
||||||
|
<input type="submit" value="Add" />
|
||||||
|
</label>
|
||||||
|
</form>
|
||||||
</section>
|
</section>
|
||||||
<section className={[this.state.isLoading > 0 ? 'loading' : '', 'loader'].join(' ')}>
|
<section className={[this.state.isLoading > 0 ? 'loading' : '', 'loader'].join(' ')}>
|
||||||
<div className="lds-ripple"><div></div><div></div></div>
|
<div className="lds-ripple"><div></div><div></div></div>
|
||||||
|
@@ -5,7 +5,7 @@ const Libp2p = require('libp2p')
|
|||||||
const Websockets = require('libp2p-websockets')
|
const Websockets = require('libp2p-websockets')
|
||||||
const WebSocketStar = require('libp2p-websocket-star')
|
const WebSocketStar = require('libp2p-websocket-star')
|
||||||
const WebRTCStar = require('libp2p-webrtc-star')
|
const WebRTCStar = require('libp2p-webrtc-star')
|
||||||
const MPLEX = require('libp2p-mplex')
|
const MPLEX = require('pull-mplex')
|
||||||
const SECIO = require('libp2p-secio')
|
const SECIO = require('libp2p-secio')
|
||||||
const KadDHT = require('libp2p-kad-dht')
|
const KadDHT = require('libp2p-kad-dht')
|
||||||
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
|
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
|
||||||
@@ -14,8 +14,9 @@ const DelegatedContentRouter = require('libp2p-delegated-content-routing')
|
|||||||
export default function Libp2pBundle ({peerInfo, peerBook}) {
|
export default function Libp2pBundle ({peerInfo, peerBook}) {
|
||||||
const wrtcstar = new WebRTCStar({id: peerInfo.id})
|
const wrtcstar = new WebRTCStar({id: peerInfo.id})
|
||||||
const wsstar = new WebSocketStar({id: peerInfo.id})
|
const wsstar = new WebSocketStar({id: peerInfo.id})
|
||||||
|
/* TODO: Ensure the delegatedApiOptions match your IPFS nodes API server */
|
||||||
const delegatedApiOptions = {
|
const delegatedApiOptions = {
|
||||||
host: '0.0.0.0',
|
host: '127.0.0.1',
|
||||||
protocol: 'http',
|
protocol: 'http',
|
||||||
port: '8080'
|
port: '8080'
|
||||||
}
|
}
|
||||||
@@ -25,7 +26,8 @@ export default function Libp2pBundle ({peerInfo, peerBook}) {
|
|||||||
peerBook,
|
peerBook,
|
||||||
// Lets limit the connection managers peers and have it check peer health less frequently
|
// Lets limit the connection managers peers and have it check peer health less frequently
|
||||||
connectionManager: {
|
connectionManager: {
|
||||||
maxPeers: 10,
|
minPeers: 20,
|
||||||
|
maxPeers: 50,
|
||||||
pollInterval: 5000
|
pollInterval: 5000
|
||||||
},
|
},
|
||||||
modules: {
|
modules: {
|
||||||
|
80
package.json
80
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "libp2p",
|
"name": "libp2p",
|
||||||
"version": "0.25.2",
|
"version": "0.25.4",
|
||||||
"description": "JavaScript base class for libp2p bundles",
|
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
||||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
@@ -23,68 +23,73 @@
|
|||||||
"url": "https://github.com/libp2p/js-libp2p.git"
|
"url": "https://github.com/libp2p/js-libp2p.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
"libp2p",
|
||||||
|
"network",
|
||||||
|
"p2p",
|
||||||
|
"peer",
|
||||||
|
"peer-to-peer",
|
||||||
"IPFS"
|
"IPFS"
|
||||||
],
|
],
|
||||||
"engines": {
|
|
||||||
"node": ">=6.0.0",
|
|
||||||
"npm": ">=3.0.0"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/libp2p/js-libp2p/issues"
|
"url": "https://github.com/libp2p/js-libp2p/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/libp2p/js-libp2p",
|
"homepage": "https://libp2p.io",
|
||||||
|
"license": "MIT",
|
||||||
"browser": {
|
"browser": {
|
||||||
"./test/utils/bundle-nodejs": "./test/utils/bundle-browser"
|
"./test/utils/bundle-nodejs": "./test/utils/bundle-browser"
|
||||||
},
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0",
|
||||||
|
"npm": ">=6.0.0"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.6.2",
|
"async": "^2.6.2",
|
||||||
"debug": "^4.1.1",
|
"debug": "^4.1.1",
|
||||||
"err-code": "^1.1.2",
|
"err-code": "^1.1.2",
|
||||||
"fsm-event": "^2.1.0",
|
"fsm-event": "^2.1.0",
|
||||||
"libp2p-connection-manager": "~0.1.0",
|
"libp2p-connection-manager": "^0.1.0",
|
||||||
"libp2p-floodsub": "~0.15.8",
|
"libp2p-floodsub": "^0.16.1",
|
||||||
"libp2p-ping": "~0.8.5",
|
"libp2p-ping": "^0.8.5",
|
||||||
"libp2p-switch": "~0.42.9",
|
"libp2p-switch": "^0.42.12",
|
||||||
"libp2p-websockets": "~0.12.2",
|
"libp2p-websockets": "^0.12.2",
|
||||||
"mafmt": "^6.0.7",
|
"mafmt": "^6.0.7",
|
||||||
"multiaddr": "^6.0.6",
|
"multiaddr": "^6.1.0",
|
||||||
"once": "^1.4.0",
|
"once": "^1.4.0",
|
||||||
"peer-book": "~0.9.1",
|
"peer-book": "^0.9.1",
|
||||||
"peer-id": "~0.12.2",
|
"peer-id": "^0.12.2",
|
||||||
"peer-info": "~0.15.1",
|
"peer-info": "^0.15.1",
|
||||||
"superstruct": "~0.6.0"
|
"superstruct": "^0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nodeutils/defaults-deep": "^1.1.0",
|
"@nodeutils/defaults-deep": "^1.1.0",
|
||||||
"aegir": "^18.2.1",
|
"aegir": "^19.0.3",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"chai-checkmark": "^1.0.1",
|
"chai-checkmark": "^1.0.1",
|
||||||
"cids": "~0.5.8",
|
"cids": "^0.7.1",
|
||||||
"dirty-chai": "^2.0.1",
|
"dirty-chai": "^2.0.1",
|
||||||
"electron-webrtc": "~0.3.0",
|
"electron-webrtc": "^0.3.0",
|
||||||
"interface-datastore": "~0.6.0",
|
"interface-datastore": "^0.6.0",
|
||||||
"libp2p-bootstrap": "~0.9.7",
|
"libp2p-bootstrap": "^0.9.7",
|
||||||
"libp2p-circuit": "~0.3.6",
|
"libp2p-circuit": "^0.3.7",
|
||||||
"libp2p-delegated-content-routing": "~0.2.2",
|
"libp2p-delegated-content-routing": "^0.2.2",
|
||||||
"libp2p-delegated-peer-routing": "~0.2.2",
|
"libp2p-delegated-peer-routing": "^0.2.2",
|
||||||
"libp2p-kad-dht": "~0.14.8",
|
"libp2p-kad-dht": "^0.15.2",
|
||||||
"libp2p-mdns": "~0.12.2",
|
"libp2p-mdns": "^0.12.3",
|
||||||
"libp2p-mplex": "~0.8.4",
|
"libp2p-mplex": "^0.8.4",
|
||||||
"libp2p-secio": "~0.11.1",
|
"libp2p-secio": "^0.11.1",
|
||||||
"libp2p-spdy": "~0.13.2",
|
"libp2p-spdy": "^0.13.2",
|
||||||
"libp2p-tcp": "~0.13.0",
|
"libp2p-tcp": "^0.13.0",
|
||||||
"libp2p-webrtc-star": "~0.15.8",
|
"libp2p-webrtc-star": "^0.16.1",
|
||||||
"libp2p-websocket-star": "~0.10.2",
|
"libp2p-websocket-star": "~0.10.2",
|
||||||
"libp2p-websocket-star-rendezvous": "~0.3.0",
|
"libp2p-websocket-star-rendezvous": "~0.3.0",
|
||||||
"lodash.times": "^4.3.2",
|
"lodash.times": "^4.3.2",
|
||||||
"nock": "^10.0.6",
|
"nock": "^10.0.6",
|
||||||
"pull-goodbye": "0.0.2",
|
"pull-goodbye": "0.0.2",
|
||||||
"pull-mplex": "~0.1.2",
|
"pull-mplex": "^0.1.2",
|
||||||
"pull-serializer": "~0.3.2",
|
"pull-serializer": "^0.3.2",
|
||||||
"pull-stream": "^3.6.9",
|
"pull-stream": "^3.6.12",
|
||||||
"sinon": "^7.2.7",
|
"sinon": "^7.2.7",
|
||||||
"wrtc": "~0.3.5"
|
"wrtc": "^0.4.1"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Aditya Bose <13054902+adbose@users.noreply.github.com>",
|
"Aditya Bose <13054902+adbose@users.noreply.github.com>",
|
||||||
@@ -101,6 +106,7 @@
|
|||||||
"Florian-Merle <florian.david.merle@gmail.com>",
|
"Florian-Merle <florian.david.merle@gmail.com>",
|
||||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||||
"Giovanni T. Parra <fiatjaf@gmail.com>",
|
"Giovanni T. Parra <fiatjaf@gmail.com>",
|
||||||
|
"Guy Sviry <32539816+guysv@users.noreply.github.com>",
|
||||||
"Henrique Dias <hacdias@gmail.com>",
|
"Henrique Dias <hacdias@gmail.com>",
|
||||||
"Hugo Dias <mail@hugodias.me>",
|
"Hugo Dias <mail@hugodias.me>",
|
||||||
"Hugo Dias <hugomrdias@gmail.com>",
|
"Hugo Dias <hugomrdias@gmail.com>",
|
||||||
|
37
src/index.js
37
src/index.js
@@ -10,8 +10,10 @@ const errCode = require('err-code')
|
|||||||
const each = require('async/each')
|
const each = require('async/each')
|
||||||
const series = require('async/series')
|
const series = require('async/series')
|
||||||
const parallel = require('async/parallel')
|
const parallel = require('async/parallel')
|
||||||
|
const nextTick = require('async/nextTick')
|
||||||
|
|
||||||
const PeerBook = require('peer-book')
|
const PeerBook = require('peer-book')
|
||||||
|
const PeerInfo = require('peer-info')
|
||||||
const Switch = require('libp2p-switch')
|
const Switch = require('libp2p-switch')
|
||||||
const Ping = require('libp2p-ping')
|
const Ping = require('libp2p-ping')
|
||||||
const WebSockets = require('libp2p-websockets')
|
const WebSockets = require('libp2p-websockets')
|
||||||
@@ -34,14 +36,14 @@ const notStarted = (action, state) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fires Node#error Emitted when an error occurs
|
* @fires Libp2p#error Emitted when an error occurs
|
||||||
* @fires Node#peer:connect Emitted when a peer is connected to this node
|
* @fires Libp2p#peer:connect Emitted when a peer is connected to this node
|
||||||
* @fires Node#peer:disconnect Emitted when a peer disconnects from this node
|
* @fires Libp2p#peer:disconnect Emitted when a peer disconnects from this node
|
||||||
* @fires Node#peer:discovery Emitted when a peer is discovered
|
* @fires Libp2p#peer:discovery Emitted when a peer is discovered
|
||||||
* @fires Node#start Emitted when the node and its services has started
|
* @fires Libp2p#start Emitted when the node and its services has started
|
||||||
* @fires Node#stop Emitted when the node and its services has stopped
|
* @fires Libp2p#stop Emitted when the node and its services has stopped
|
||||||
*/
|
*/
|
||||||
class Node extends EventEmitter {
|
class Libp2p extends EventEmitter {
|
||||||
constructor (_options) {
|
constructor (_options) {
|
||||||
super()
|
super()
|
||||||
// validateConfig will ensure the config is correct,
|
// validateConfig will ensure the config is correct,
|
||||||
@@ -345,7 +347,7 @@ class Node extends EventEmitter {
|
|||||||
let t
|
let t
|
||||||
|
|
||||||
if (typeof Transport === 'function') {
|
if (typeof Transport === 'function') {
|
||||||
t = new Transport()
|
t = new Transport({ libp2p: this })
|
||||||
} else {
|
} else {
|
||||||
t = Transport
|
t = Transport
|
||||||
}
|
}
|
||||||
@@ -547,4 +549,21 @@ class Node extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Node
|
module.exports = Libp2p
|
||||||
|
/**
|
||||||
|
* Like `new Libp2p(options)` except it will create a `PeerInfo`
|
||||||
|
* instance if one is not provided in options.
|
||||||
|
* @param {object} options Libp2p configuration options
|
||||||
|
* @param {function(Error, Libp2p)} callback
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
module.exports.createLibp2p = (options, callback) => {
|
||||||
|
if (options.peerInfo) {
|
||||||
|
return nextTick(callback, null, new Libp2p(options))
|
||||||
|
}
|
||||||
|
PeerInfo.create((err, peerInfo) => {
|
||||||
|
if (err) return callback(err)
|
||||||
|
options.peerInfo = peerInfo
|
||||||
|
callback(null, new Libp2p(options))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -63,9 +63,7 @@ module.exports = (node) => {
|
|||||||
return nextTick(callback, errCode(new Error('data must be a Buffer'), 'ERR_DATA_IS_NOT_A_BUFFER'))
|
return nextTick(callback, errCode(new Error('data must be a Buffer'), 'ERR_DATA_IS_NOT_A_BUFFER'))
|
||||||
}
|
}
|
||||||
|
|
||||||
floodSub.publish(topic, data)
|
floodSub.publish(topic, data, callback)
|
||||||
|
|
||||||
nextTick(() => callback())
|
|
||||||
},
|
},
|
||||||
|
|
||||||
ls: (callback) => {
|
ls: (callback) => {
|
||||||
|
@@ -7,8 +7,15 @@ const expect = chai.expect
|
|||||||
const series = require('async/series')
|
const series = require('async/series')
|
||||||
const createNode = require('./utils/create-node')
|
const createNode = require('./utils/create-node')
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
|
const { createLibp2p } = require('../src')
|
||||||
|
const WS = require('libp2p-websockets')
|
||||||
|
const PeerInfo = require('peer-info')
|
||||||
|
|
||||||
describe('libp2p creation', () => {
|
describe('libp2p creation', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
sinon.restore()
|
||||||
|
})
|
||||||
|
|
||||||
it('should be able to start and stop successfully', (done) => {
|
it('should be able to start and stop successfully', (done) => {
|
||||||
createNode([], {
|
createNode([], {
|
||||||
config: {
|
config: {
|
||||||
@@ -101,4 +108,36 @@ describe('libp2p creation', () => {
|
|||||||
node._switch.emit('error', error)
|
node._switch.emit('error', error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('createLibp2p should create a peerInfo instance', function (done) {
|
||||||
|
this.timeout(10e3)
|
||||||
|
createLibp2p({
|
||||||
|
modules: {
|
||||||
|
transport: [ WS ]
|
||||||
|
}
|
||||||
|
}, (err, libp2p) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
expect(libp2p).to.exist()
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('createLibp2p should allow for a provided peerInfo instance', function (done) {
|
||||||
|
this.timeout(10e3)
|
||||||
|
PeerInfo.create((err, peerInfo) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
sinon.spy(PeerInfo, 'create')
|
||||||
|
createLibp2p({
|
||||||
|
peerInfo,
|
||||||
|
modules: {
|
||||||
|
transport: [ WS ]
|
||||||
|
}
|
||||||
|
}, (err, libp2p) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
expect(libp2p).to.exist()
|
||||||
|
expect(PeerInfo.create.callCount).to.eql(0)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@@ -5,34 +5,24 @@ const chai = require('chai')
|
|||||||
chai.use(require('dirty-chai'))
|
chai.use(require('dirty-chai'))
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
const signalling = require('libp2p-webrtc-star/src/sig-server')
|
|
||||||
const parallel = require('async/parallel')
|
const parallel = require('async/parallel')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
|
|
||||||
const createNode = require('./utils/create-node')
|
const createNode = require('./utils/create-node')
|
||||||
const echo = require('./utils/echo')
|
const echo = require('./utils/echo')
|
||||||
|
const { WRTC_RENDEZVOUS_MULTIADDR } = require('./utils/constants')
|
||||||
|
|
||||||
describe('peer discovery', () => {
|
describe('peer discovery', () => {
|
||||||
let nodeA
|
let nodeA
|
||||||
let nodeB
|
let nodeB
|
||||||
let nodeC
|
let nodeC
|
||||||
let port = 24642
|
|
||||||
let ss
|
|
||||||
|
|
||||||
function setup (options) {
|
function setup (options) {
|
||||||
before((done) => {
|
before((done) => {
|
||||||
port++
|
|
||||||
parallel([
|
parallel([
|
||||||
(cb) => {
|
|
||||||
signalling.start({ port: port }, (err, server) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
ss = server
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
(cb) => createNode([
|
(cb) => createNode([
|
||||||
'/ip4/0.0.0.0/tcp/0',
|
'/ip4/0.0.0.0/tcp/0',
|
||||||
`/ip4/127.0.0.1/tcp/${port}/ws/p2p-webrtc-star`
|
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
|
||||||
], options, (err, node) => {
|
], options, (err, node) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
nodeA = node
|
nodeA = node
|
||||||
@@ -41,7 +31,7 @@ describe('peer discovery', () => {
|
|||||||
}),
|
}),
|
||||||
(cb) => createNode([
|
(cb) => createNode([
|
||||||
'/ip4/0.0.0.0/tcp/0',
|
'/ip4/0.0.0.0/tcp/0',
|
||||||
`/ip4/127.0.0.1/tcp/${port}/ws/p2p-webrtc-star`
|
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
|
||||||
], options, (err, node) => {
|
], options, (err, node) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
nodeB = node
|
nodeB = node
|
||||||
@@ -50,7 +40,7 @@ describe('peer discovery', () => {
|
|||||||
}),
|
}),
|
||||||
(cb) => createNode([
|
(cb) => createNode([
|
||||||
'/ip4/0.0.0.0/tcp/0',
|
'/ip4/0.0.0.0/tcp/0',
|
||||||
`/ip4/127.0.0.1/tcp/${port}/ws/p2p-webrtc-star`
|
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
|
||||||
], options, (err, node) => {
|
], options, (err, node) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
nodeC = node
|
nodeC = node
|
||||||
@@ -64,8 +54,7 @@ describe('peer discovery', () => {
|
|||||||
parallel([
|
parallel([
|
||||||
(cb) => nodeA.stop(cb),
|
(cb) => nodeA.stop(cb),
|
||||||
(cb) => nodeB.stop(cb),
|
(cb) => nodeB.stop(cb),
|
||||||
(cb) => nodeC.stop(cb),
|
(cb) => nodeC.stop(cb)
|
||||||
(cb) => ss.stop(cb)
|
|
||||||
], done)
|
], done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -423,6 +412,7 @@ describe('peer discovery', () => {
|
|||||||
randomWalk: {
|
randomWalk: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
queriesPerPeriod: 1,
|
queriesPerPeriod: 1,
|
||||||
|
delay: 100,
|
||||||
interval: 200, // start the query sooner
|
interval: 200, // start the query sooner
|
||||||
timeout: 3000
|
timeout: 3000
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,6 @@ chai.use(require('dirty-chai'))
|
|||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
const parallel = require('async/parallel')
|
const parallel = require('async/parallel')
|
||||||
const series = require('async/series')
|
const series = require('async/series')
|
||||||
const signalling = require('libp2p-webrtc-star/src/sig-server')
|
|
||||||
const rendezvous = require('libp2p-websocket-star-rendezvous')
|
const rendezvous = require('libp2p-websocket-star-rendezvous')
|
||||||
const TCP = require('libp2p-tcp')
|
const TCP = require('libp2p-tcp')
|
||||||
const WS = require('libp2p-websockets')
|
const WS = require('libp2p-websockets')
|
||||||
@@ -18,6 +17,8 @@ const createNode = require('./utils/create-node.js')
|
|||||||
const tryEcho = require('./utils/try-echo')
|
const tryEcho = require('./utils/try-echo')
|
||||||
const echo = require('./utils/echo')
|
const echo = require('./utils/echo')
|
||||||
|
|
||||||
|
const { WRTC_RENDEZVOUS_MULTIADDR } = require('./utils/constants')
|
||||||
|
|
||||||
describe('transports', () => {
|
describe('transports', () => {
|
||||||
describe('TCP only', () => {
|
describe('TCP only', () => {
|
||||||
let nodeA
|
let nodeA
|
||||||
@@ -409,24 +410,17 @@ describe('transports', () => {
|
|||||||
let nodeWS
|
let nodeWS
|
||||||
let nodeWebRTCStar
|
let nodeWebRTCStar
|
||||||
|
|
||||||
let ss
|
|
||||||
|
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
this.timeout(5 * 1000)
|
this.timeout(5 * 1000)
|
||||||
|
|
||||||
parallel([
|
parallel([
|
||||||
(cb) => signalling.start({ port: 24642 }, (err, server) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
ss = server
|
|
||||||
cb()
|
|
||||||
}),
|
|
||||||
(cb) => {
|
(cb) => {
|
||||||
const wstar = new WRTCStar({ wrtc: wrtc })
|
const wstar = new WRTCStar({ wrtc: wrtc })
|
||||||
|
|
||||||
createNode([
|
createNode([
|
||||||
'/ip4/0.0.0.0/tcp/0',
|
'/ip4/0.0.0.0/tcp/0',
|
||||||
'/ip4/127.0.0.1/tcp/25011/ws',
|
'/ip4/127.0.0.1/tcp/25011/ws',
|
||||||
'/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'
|
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
|
||||||
], {
|
], {
|
||||||
modules: {
|
modules: {
|
||||||
transport: [
|
transport: [
|
||||||
@@ -479,12 +473,11 @@ describe('transports', () => {
|
|||||||
node.handle('/echo/1.0.0', echo)
|
node.handle('/echo/1.0.0', echo)
|
||||||
node.start(cb)
|
node.start(cb)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
(cb) => {
|
(cb) => {
|
||||||
const wstar = new WRTCStar({ wrtc: wrtc })
|
const wstar = new WRTCStar({ wrtc: wrtc })
|
||||||
|
|
||||||
createNode([
|
createNode([
|
||||||
'/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'
|
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
|
||||||
], {
|
], {
|
||||||
modules: {
|
modules: {
|
||||||
transport: [wstar],
|
transport: [wstar],
|
||||||
@@ -515,8 +508,7 @@ describe('transports', () => {
|
|||||||
(cb) => nodeAll.stop(cb),
|
(cb) => nodeAll.stop(cb),
|
||||||
(cb) => nodeTCP.stop(cb),
|
(cb) => nodeTCP.stop(cb),
|
||||||
(cb) => nodeWS.stop(cb),
|
(cb) => nodeWS.stop(cb),
|
||||||
(cb) => nodeWebRTCStar.stop(cb),
|
(cb) => nodeWebRTCStar.stop(cb)
|
||||||
(cb) => ss.stop(cb)
|
|
||||||
], done)
|
], done)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user