chore: do not use peerstore.put on get-peer-info

This commit is contained in:
Vasco Santos 2020-04-01 11:12:34 +02:00
parent d3e4ad2d69
commit eb27b8db03
3 changed files with 9 additions and 4 deletions

View File

@ -38,7 +38,12 @@ function getPeerInfo (peer, peerStore) {
addr && peer.multiaddrs.add(addr) addr && peer.multiaddrs.add(addr)
return peerStore ? peerStore.put(peer, { replace: false }) : peer if (peerStore) {
peerStore.addressBook.set(peer.id, peer.multiaddrs.toArray(), { replace: false })
peerStore.protoBook.set(peer.id, Array.from(peer.protocols), { replace: false })
}
return peer
} }
/** /**

View File

@ -109,7 +109,7 @@ class AddressBook extends Book {
// Already knows the peer // Already knows the peer
if (rec && rec.length === multiaddrInfos.length) { if (rec && rec.length === multiaddrInfos.length) {
const intersection = rec.filter((mi) => multiaddrInfos.some((newMi) => mi.multiaddr === newMi.multiaddr)) const intersection = rec.filter((mi) => multiaddrInfos.some((newMi) => mi.multiaddr.equals(newMi.multiaddr)))
// Are new addresses equal to the old ones? // Are new addresses equal to the old ones?
// If yes, no changes needed! // If yes, no changes needed!
@ -154,7 +154,7 @@ class AddressBook extends Book {
// Add recorded uniquely to the new array (Union) // Add recorded uniquely to the new array (Union)
rec && rec.forEach((mi) => { rec && rec.forEach((mi) => {
if (!multiaddrInfos.find(r => r.multiaddr === mi.multiaddr)) { if (!multiaddrInfos.find(r => r.multiaddr.equals(mi.multiaddr))) {
multiaddrInfos.push(mi) multiaddrInfos.push(mi)
} }
}) })

View File

@ -123,7 +123,7 @@ describe('Dialing (direct, TCP)', () => {
const peerId = await PeerId.createFromJSON(Peers[0]) const peerId = await PeerId.createFromJSON(Peers[0])
const peerInfo = new PeerInfo(peerId) const peerInfo = new PeerInfo(peerId)
peerInfo.multiaddrs.add(remoteAddr) peerInfo.multiaddrs.add(remoteAddr)
peerStore.put(peerInfo) peerStore.addressBook.set(peerInfo.id, peerInfo.multiaddrs.toArray())
const connection = await dialer.connectToPeer(peerInfo) const connection = await dialer.connectToPeer(peerInfo)
expect(connection).to.exist() expect(connection).to.exist()