mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-05-01 13:32:14 +00:00
chore: do not use peerstore.put on get-peer-info
This commit is contained in:
parent
d3e4ad2d69
commit
eb27b8db03
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user