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

Integrate libp2p-ping #98

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 @@ -45,6 +45,7 @@
},
"dependencies": {
"babel-runtime": "^6.11.6",
"libp2p-ping": "^0.2.0",
"libp2p-secio": "^0.5.0",
"libp2p-spdy": "^0.9.0",
"libp2p-swarm": "^0.23.0",
Expand All @@ -62,4 +63,4 @@
"Richard Littauer <richard.littauer@gmail.com>",
"greenkeeperio-bot <support@greenkeeper.io>"
]
}
}
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const EE = require('events').EventEmitter
const multiaddr = require('multiaddr')
const PeerBook = require('peer-book')
const mafmt = require('mafmt')
const Ping = require('libp2p-ping')

exports = module.exports

Expand Down Expand Up @@ -200,6 +201,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/webrtc-star-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,13 @@ describe('libp2p-ipfs-browser (webrtc only)', function () {
}, 2000)
})
})

it('node1 ping to node2', (done) => {
const p = node1.ping(node2.peerInfo)

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