-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,3 @@ build/Release | |
node_modules | ||
|
||
dist | ||
lib |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
const Id = require('peer-id') | ||
const multiaddr = require('multiaddr') | ||
|
||
exports = module.exports = Peer | ||
exports = module.exports = PeerInfo | ||
|
||
function ensureMultiaddr (addr) { | ||
if (multiaddr.isMultiaddr(addr)) { | ||
|
@@ -14,17 +14,17 @@ function ensureMultiaddr (addr) { | |
} | ||
|
||
// Peer represents a peer on the IPFS network | ||
function Peer (peerId) { | ||
if (!(this instanceof Peer)) { | ||
return new Peer(peerId) | ||
function PeerInfo (peerId) { | ||
if (!(this instanceof PeerInfo)) { | ||
return new PeerInfo(peerId) | ||
} | ||
|
||
if (!peerId) { | ||
this.id = Id.create() | ||
} else { | ||
this.id = peerId | ||
throw new Error('Missing peerId. Use Peer.create(cb) to create one') | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
parkan
|
||
} | ||
|
||
this.id = peerId | ||
|
||
this.multiaddrs = [] | ||
const observedMultiaddrs = [] | ||
|
||
|
@@ -91,3 +91,21 @@ function Peer (peerId) { | |
// TODO: add features to fetch multiaddr using filters | ||
// look at https://github.com/whyrusleeping/js-mafmt/blob/master/src/index.js | ||
} | ||
|
||
PeerInfo.create = (id, callback) => { | ||
if (typeof id === 'function') { | ||
callback = id | ||
id = null | ||
|
||
Id.create((err, id) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
|
||
callback(null, new PeerInfo(id)) | ||
}) | ||
return | ||
} | ||
|
||
callback(null, new PeerInfo(id)) | ||
} |
I am guessing this was changed because this function would need to be made async otherwise (breaks docs here: https://github.com/libp2p/js-peer-info#usage)
However, that surfaced a potentially bigger issue. What are the semantics of adding a multiaddr containing a public key to a PeerInfo? I previously assumed, based on the API, that
Would populate the pubkey on the peerInfo. However, at least with the current version this doesn't seem to be the case:
What's the correct way to inflate a multiaddr into a PeerInfo?