Skip to content

Commit

Permalink
fix: remove peer as well as addresses from peerstore (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 authored Sep 16, 2024
1 parent d292ca0 commit fca7423
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions comm/p2p/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func NewHost(privKey crypto.PrivKey, networkTopology *topology.NetworkTopology,
// LoadPeers clears out peerstore and loads new peers into it
func LoadPeers(h host.Host, peers []*peer.AddrInfo) {
for _, p := range h.Peerstore().Peers() {
h.Peerstore().RemovePeer(p)
h.Peerstore().ClearAddrs(p)
}

Expand Down
5 changes: 2 additions & 3 deletions comm/p2p/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ func (s *HostTestSuite) TestHost_NewHost_Success() {
)
s.Nil(err)
s.NotNil(host)
// 2 peers + host
s.Len(host.Peerstore().Peers(), 3)
s.Len(host.Peerstore().Peers(), 2)
}

func (s *HostTestSuite) TestHost_NewHost_InvalidPrivKey() {
Expand Down Expand Up @@ -117,5 +116,5 @@ func (s *LoadPeersTestSuite) Test_LoadPeers_RemovesOldAndSetsNewPeers() {

s.Equal(peerInSlice(newP1.ID, s.host.Peerstore().Peers()), true)
s.Equal(peerInSlice(newP2.ID, s.host.Peerstore().Peers()), true)
s.Equal(len(s.host.Peerstore().Peers()), 3)
s.Equal(len(s.host.Peerstore().Peers()), 2)
}

0 comments on commit fca7423

Please sign in to comment.