Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ping to the mix #48

Merged
merged 1 commit into from
Dec 1, 2016
Merged
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 @@
"pre-commit": "^1.1.1"
},
"dependencies": {
"libp2p-ping": "^0.3.0",
"libp2p-swarm": "^0.26.3",
"mafmt": "^2.1.2",
"multiaddr": "^2.1.1",
Expand All @@ -52,4 +53,4 @@
"Richard Littauer <richard.littauer@gmail.com>",
"greenkeeperio-bot <support@greenkeeper.io>"
]
}
}
25 changes: 25 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const multiaddr = require('multiaddr')
const mafmt = require('mafmt')
const EE = require('events').EventEmitter
const assert = require('assert')
const Ping = require('libp2p-ping')

exports = module.exports

Expand Down Expand Up @@ -70,6 +71,9 @@ class Node {
})
}

// Mount default protocols
Ping.mount(this.swarm)

// Not fully implemented in js-libp2p yet
this.routing = undefined
this.records = undefined
Expand Down Expand Up @@ -123,6 +127,27 @@ class Node {
this.swarm.close(callback)
}

//
// Ping
//

// TODO
pingById (id, callback) {
assert(this.isOnline, OFFLINE_ERROR_MESSAGE)
callback(new Error('not implemented yet'))
}

// TODO
pingByMultiaddr (maddr, callback) {
assert(this.isOnline, OFFLINE_ERROR_MESSAGE)
callback(new Error('not implemented yet'))
}

pingByPeerInfo (peerInfo, callback) {
assert(this.isOnline, OFFLINE_ERROR_MESSAGE)
callback(null, new Ping(this.swarm, peerInfo))
}

//
// Dialing methods
//
Expand Down