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: implement dialById #66

Closed
wants to merge 2 commits into from
Closed
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
23 changes: 18 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,32 @@ class Node {
// Dialing methods
//

// TODO
/**
* Dial a given node by peer id.
* It will try to find a multiaddr in the peerbook and fail
* if none is found.
*
* @param {PeerId} id
* @param {string} [protocol]
* @param {function(Error, Connection)} callback
* @returns {void}
*/
dialById (id, protocol, callback) {
// NOTE: dialById only works if a previous dial was made. This will
// change once we have PeerRouting

assert(this.isOnline, OFFLINE_ERROR_MESSAGE)

if (typeof protocol === 'function') {
callback = protocol
protocol = undefined
}

callback(new Error('not implemented yet'))
let peer
try {
peer = this.peerBook.getByB58String(id.toB58String())
} catch (err) {
return callback(new Error('No multiaddr found for this id'))
}

this.dialByPeerInfo(peer, protocol, callback)
}

dialByMultiaddr (maddr, protocol, callback) {
Expand Down