Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Integrate libp2p-ping
Browse files Browse the repository at this point in the history
  • Loading branch information
fbaiodias committed Sep 13, 2016
1 parent 3ec7435 commit d3a8691
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"run-parallel": "^1.1.6"
},
"dependencies": {
"libp2p-ping": "^0.2.0",
"libp2p-secio": "^0.5.0",
"libp2p-spdy": "^0.9.0",
"libp2p-swarm": "^0.23.0",
Expand Down Expand Up @@ -67,4 +68,4 @@
"Stephen Whitmore <stephen.whitmore@gmail.com>",
"dignifiedquire <dignifiedquire@gmail.com>"
]
}
}
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const secio = require('libp2p-secio')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const PeerBook = require('peer-book')
const Ping = require('libp2p-ping')
const multiaddr = require('multiaddr')
const mafmt = require('mafmt')
const EE = require('events').EventEmitter
Expand Down Expand Up @@ -197,6 +198,12 @@ exports.Node = function Node (pInfo, pBook) {
return this.swarm.unhandle(protocol)
}

Ping.attach(this.swarm) // Enable this peer to echo Ping requests

this.ping = (peerDst) => {
return new Ping(this.swarm, peerDst) // Ping peerDst, peerDst must be a peer-info object
}

this.discovery = new EE()
this.routing = null
this.records = null
Expand Down
9 changes: 9 additions & 0 deletions test/libp2p.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ describe('libp2p-ipfs', () => {
}
})

it('nodeE ping to nodeF', (done) => {
const p = nodeE.ping(nodeF.peerInfo)

p.once('ping', (time) => {
p.stop()
done()
})
})

it('stop', (done) => {
parallel([
nodeA.stop,
Expand Down

0 comments on commit d3a8691

Please sign in to comment.