diff --git a/package.json b/package.json index 2a62eb561e..eb4e43de93 100644 --- a/package.json +++ b/package.json @@ -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", @@ -52,4 +53,4 @@ "Richard Littauer ", "greenkeeperio-bot " ] -} \ No newline at end of file +} diff --git a/src/index.js b/src/index.js index 4f5253efeb..236fa22f08 100644 --- a/src/index.js +++ b/src/index.js @@ -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 @@ -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 @@ -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 //