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

Integrate libp2p-ping #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does only send one ping? Something tells me this event will be fired up a bunch of times and the only thing preventing the test from failing is that it is the last test, so it closes soon enough


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