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

chore: remove peer-info from api #25

Merged
merged 2 commits into from
Jun 8, 2020
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
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@
"err-code": "^2.0.0",
"it-handshake": "^1.0.1",
"it-length-prefixed": "^3.0.0",
"libp2p-daemon": "^0.3.0",
"libp2p-daemon": "^0.4.0",
"libp2p-tcp": "^0.14.2",
"multiaddr": "^7.2.1",
"peer-id": "~0.13.3",
"peer-info": "~0.17.0"
"peer-id": "~0.13.3"
},
"contributors": [
"Arve Knudsen <arve.knudsen@gmail.com>",
Expand Down
31 changes: 9 additions & 22 deletions src/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const CID = require('cids')
const PeerID = require('peer-id')
const PeerInfo = require('peer-info')
const multiaddr = require('multiaddr')
const errcode = require('err-code')

Expand Down Expand Up @@ -112,16 +111,10 @@ class DHT {
throw errcode(new Error(response.error.msg), 'ERR_DHT_FIND_PEER_FAILED')
}

const receivedPeerId = PeerID.createFromBytes(response.dht.peer.id)
const peerInfo = new PeerInfo(receivedPeerId)

response.dht.peer.addrs.forEach((addr) => {
const ma = multiaddr(addr)

peerInfo.multiaddrs.add(ma)
})

return peerInfo
return {
id: PeerID.createFromBytes(response.dht.peer.id),
addrs: response.dht.peer.addrs.map((a) => multiaddr(a))
}
}

/**
Expand Down Expand Up @@ -193,16 +186,10 @@ class DHT {

// Stream values
if (response.type === DHTResponse.Type.VALUE) {
const peerId = PeerID.createFromBytes(response.peer.id)
const peerInfo = new PeerInfo(peerId)

response.peer.addrs.forEach((addr) => {
const ma = multiaddr(addr)

peerInfo.multiaddrs.add(ma)
})

yield peerInfo
yield {
id: PeerID.createFromBytes(response.peer.id),
addrs: response.peer.addrs.map((a) => multiaddr(a))
}
} else {
// Unexpected message received
await sh.close()
Expand Down Expand Up @@ -252,7 +239,7 @@ class DHT {
if (response.type === DHTResponse.Type.VALUE) {
const peerId = PeerID.createFromBytes(response.value)

yield new PeerInfo(peerId)
yield { id: peerId }
} else {
// Unexpected message received
await sh.close()
Expand Down