Skip to content

Commit

Permalink
Remove peer if there is an when creating a stream
Browse files Browse the repository at this point in the history
Co-authored-by: Kirill <[email protected]>
  • Loading branch information
IronGauntlets and kirugan committed Jan 25, 2024
1 parent 0cf9b12 commit ee3bf94
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions p2p/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,18 @@ func (s *syncService) randomPeerStream(ctx context.Context, pids ...protocol.ID)
randPeer := s.randomPeer()
stream, err := s.host.NewStream(ctx, randPeer, pids...)
if err != nil {
fmt.Println("Removing peer", randPeer)
s.host.Peerstore().RemovePeer(randPeer)
s.removePeer(randPeer)
return nil, err
}
return stream, err
}

func (s *syncService) removePeer(id peer.ID) {
fmt.Println("Removing peer", id)
s.host.Peerstore().RemovePeer(id)
s.host.Peerstore().ClearAddrs(id)
}

func (s *syncService) createIterator(start, limit uint64) *spec.Iteration {
if limit == 0 {
limit = 1
Expand Down

0 comments on commit ee3bf94

Please sign in to comment.