Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove peer as well as addresses from peerstore #359

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading