Skip to content

Commit 2b45fee

Browse files
vasco-santosjacobheun
authored andcommitted
fix: onConnect should not add addr to the addressBook
1 parent 8bf5a70 commit 2b45fee

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

src/connection-manager/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ class ConnectionManager extends EventEmitter {
182182
this.emit('peer:connect', connection)
183183
}
184184

185-
this._libp2p.peerStore.addressBook.add(peerId, [connection.remoteAddr])
186185
this._libp2p.peerStore.keyBook.set(peerId, peerId.pubKey)
187186

188187
if (!this._peerValues.has(peerIdStr)) {

test/identify/index.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ describe('Identify', () => {
242242
expect(connection).to.exist()
243243

244244
// Wait for peer store to be updated
245-
// Dialer._createDialTarget (add), Connected (add), Identify (replace)
246-
await pWaitFor(() => peerStoreSpySet.callCount === 1 && peerStoreSpyAdd.callCount === 2)
245+
// Dialer._createDialTarget (add), Identify (replace)
246+
await pWaitFor(() => peerStoreSpySet.callCount === 1 && peerStoreSpyAdd.callCount === 1)
247247
expect(libp2p.identifyService.identify.callCount).to.equal(1)
248248

249249
// The connection should have no open streams

test/peer-store/peer-store.node.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ describe('libp2p.peerStore', () => {
2424
})
2525

2626
it('adds peer address to AddressBook and keys to the keybook when establishing connection', async () => {
27-
const idStr = libp2p.peerId.toB58String()
2827
const remoteIdStr = remoteLibp2p.peerId.toB58String()
2928

3029
const spyAddressBook = sinon.spy(libp2p.peerStore.addressBook, 'add')
@@ -44,9 +43,7 @@ describe('libp2p.peerStore', () => {
4443
// const publicKeyInLocalPeer = localPeers.get(remoteIdStr).id.pubKey
4544
// expect(publicKeyInLocalPeer.bytes).to.equalBytes(remoteLibp2p.peerId.pubKey.bytes)
4645

47-
const remotePeers = remoteLibp2p.peerStore.peers
48-
expect(remotePeers.size).to.equal(1)
49-
const publicKeyInRemotePeer = remotePeers.get(idStr).id.pubKey
46+
const publicKeyInRemotePeer = remoteLibp2p.peerStore.keyBook.get(libp2p.peerId)
5047
expect(publicKeyInRemotePeer).to.exist()
5148
expect(publicKeyInRemotePeer.bytes).to.equalBytes(libp2p.peerId.pubKey.bytes)
5249
})

0 commit comments

Comments
 (0)