From 2b45fee0ed25035796de4c21d477fdbcbe3dbda7 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 13 May 2020 10:30:57 +0200 Subject: [PATCH] fix: onConnect should not add addr to the addressBook --- src/connection-manager/index.js | 1 - test/identify/index.spec.js | 4 ++-- test/peer-store/peer-store.node.js | 5 +---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/connection-manager/index.js b/src/connection-manager/index.js index cc64468d..5d661088 100644 --- a/src/connection-manager/index.js +++ b/src/connection-manager/index.js @@ -182,7 +182,6 @@ class ConnectionManager extends EventEmitter { this.emit('peer:connect', connection) } - this._libp2p.peerStore.addressBook.add(peerId, [connection.remoteAddr]) this._libp2p.peerStore.keyBook.set(peerId, peerId.pubKey) if (!this._peerValues.has(peerIdStr)) { diff --git a/test/identify/index.spec.js b/test/identify/index.spec.js index abcbbeb3..9ca892ff 100644 --- a/test/identify/index.spec.js +++ b/test/identify/index.spec.js @@ -242,8 +242,8 @@ describe('Identify', () => { expect(connection).to.exist() // Wait for peer store to be updated - // Dialer._createDialTarget (add), Connected (add), Identify (replace) - await pWaitFor(() => peerStoreSpySet.callCount === 1 && peerStoreSpyAdd.callCount === 2) + // Dialer._createDialTarget (add), Identify (replace) + await pWaitFor(() => peerStoreSpySet.callCount === 1 && peerStoreSpyAdd.callCount === 1) expect(libp2p.identifyService.identify.callCount).to.equal(1) // The connection should have no open streams diff --git a/test/peer-store/peer-store.node.js b/test/peer-store/peer-store.node.js index c6b34eb5..e15b3cb3 100644 --- a/test/peer-store/peer-store.node.js +++ b/test/peer-store/peer-store.node.js @@ -24,7 +24,6 @@ describe('libp2p.peerStore', () => { }) it('adds peer address to AddressBook and keys to the keybook when establishing connection', async () => { - const idStr = libp2p.peerId.toB58String() const remoteIdStr = remoteLibp2p.peerId.toB58String() const spyAddressBook = sinon.spy(libp2p.peerStore.addressBook, 'add') @@ -44,9 +43,7 @@ describe('libp2p.peerStore', () => { // const publicKeyInLocalPeer = localPeers.get(remoteIdStr).id.pubKey // expect(publicKeyInLocalPeer.bytes).to.equalBytes(remoteLibp2p.peerId.pubKey.bytes) - const remotePeers = remoteLibp2p.peerStore.peers - expect(remotePeers.size).to.equal(1) - const publicKeyInRemotePeer = remotePeers.get(idStr).id.pubKey + const publicKeyInRemotePeer = remoteLibp2p.peerStore.keyBook.get(libp2p.peerId) expect(publicKeyInRemotePeer).to.exist() expect(publicKeyInRemotePeer.bytes).to.equalBytes(libp2p.peerId.pubKey.bytes) })