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

Commit ac63816

Browse files
committed
Integrate libp2p-ping
1 parent c80b9c8 commit ac63816

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
},
4646
"dependencies": {
4747
"babel-runtime": "^6.11.6",
48+
"libp2p-ping": "^0.2.0",
4849
"libp2p-secio": "^0.5.0",
4950
"libp2p-spdy": "^0.9.0",
5051
"libp2p-swarm": "^0.23.0",
@@ -62,4 +63,4 @@
6263
"Richard Littauer <richard.littauer@gmail.com>",
6364
"greenkeeperio-bot <support@greenkeeper.io>"
6465
]
65-
}
66+
}

src/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const EE = require('events').EventEmitter
1111
const multiaddr = require('multiaddr')
1212
const PeerBook = require('peer-book')
1313
const mafmt = require('mafmt')
14+
const Ping = require('libp2p-ping')
1415

1516
exports = module.exports
1617

@@ -200,6 +201,12 @@ exports.Node = function Node (pInfo, pBook) {
200201
return this.swarm.unhandle(protocol)
201202
}
202203

204+
Ping.attach(this.swarm) // Enable this peer to echo Ping requests
205+
206+
this.ping = (peerDst) => {
207+
return new Ping(this.swarm, peerDst) // Ping peerDst, peerDst must be a peer-info object
208+
}
209+
203210
this.discovery = new EE()
204211
this.routing = null
205212
this.records = null

test/webrtc-star-only.js

+9
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,13 @@ describe('libp2p-ipfs-browser (webrtc only)', function () {
116116
}, 2000)
117117
})
118118
})
119+
120+
it('node1 ping to node2', (done) => {
121+
const p = node1.ping(node2.peerInfo)
122+
123+
p.once('ping', (time) => {
124+
p.stop()
125+
done()
126+
})
127+
})
119128
})

0 commit comments

Comments
 (0)