Skip to content

Commit

Permalink
feat: remove bad peers based on dial errors for lightmode
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyaprem committed Oct 15, 2024
1 parent caf98f4 commit ac9241b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion waku/v2/peermanager/peer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ const (
const maxFailedAttempts = 5
const prunePeerStoreInterval = 10 * time.Minute
const peerConnectivityLoopSecs = 15
const maxConnsToPeerRatio = 5
const maxConnsToPeerRatio = 3
const badPeersCleanupInterval = 1 * time.Minute

// 80% relay peers 20% service peers
func relayAndServicePeers(maxConnections int) (int, int) {
Expand Down Expand Up @@ -256,16 +257,31 @@ func (pm *PeerManager) Start(ctx context.Context) {
}
}

func (pm *PeerManager) removeBadPeers() {
if !pm.RelayEnabled {
for _, peerID := range pm.host.Peerstore().Peers() {
if pm.host.Peerstore().(wps.WakuPeerstore).ConnFailures(peerID) > 5 {
//delete peer from peerStore
pm.RemovePeer(peerID)
}
}
}
}

func (pm *PeerManager) peerStoreLoop(ctx context.Context) {
defer utils.LogOnPanic()
t := time.NewTicker(prunePeerStoreInterval)
t1 := time.NewTicker(badPeersCleanupInterval)
defer t.Stop()
defer t1.Stop()
for {
select {
case <-ctx.Done():
return
case <-t.C:
pm.prunePeerStore()
case <-t1.C:
pm.removeBadPeers()
}
}
}
Expand Down

0 comments on commit ac9241b

Please sign in to comment.