Skip to content

Commit 3a8d51c

Browse files
authored
Merge pull request #48 from libp2p/feat/add-ping
feat: add ping to the mix
2 parents ee801c9 + f8c09db commit 3a8d51c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"pre-commit": "^1.1.1"
4040
},
4141
"dependencies": {
42+
"libp2p-ping": "^0.3.0",
4243
"libp2p-swarm": "^0.26.3",
4344
"mafmt": "^2.1.2",
4445
"multiaddr": "^2.1.1",
@@ -52,4 +53,4 @@
5253
"Richard Littauer <[email protected]>",
5354
"greenkeeperio-bot <[email protected]>"
5455
]
55-
}
56+
}

src/index.js

+25
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const multiaddr = require('multiaddr')
88
const mafmt = require('mafmt')
99
const EE = require('events').EventEmitter
1010
const assert = require('assert')
11+
const Ping = require('libp2p-ping')
1112

1213
exports = module.exports
1314

@@ -70,6 +71,9 @@ class Node {
7071
})
7172
}
7273

74+
// Mount default protocols
75+
Ping.mount(this.swarm)
76+
7377
// Not fully implemented in js-libp2p yet
7478
this.routing = undefined
7579
this.records = undefined
@@ -123,6 +127,27 @@ class Node {
123127
this.swarm.close(callback)
124128
}
125129

130+
//
131+
// Ping
132+
//
133+
134+
// TODO
135+
pingById (id, callback) {
136+
assert(this.isOnline, OFFLINE_ERROR_MESSAGE)
137+
callback(new Error('not implemented yet'))
138+
}
139+
140+
// TODO
141+
pingByMultiaddr (maddr, callback) {
142+
assert(this.isOnline, OFFLINE_ERROR_MESSAGE)
143+
callback(new Error('not implemented yet'))
144+
}
145+
146+
pingByPeerInfo (peerInfo, callback) {
147+
assert(this.isOnline, OFFLINE_ERROR_MESSAGE)
148+
callback(null, new Ping(this.swarm, peerInfo))
149+
}
150+
126151
//
127152
// Dialing methods
128153
//

0 commit comments

Comments
 (0)