Skip to content

Commit

Permalink
p2p: disconnect itself will reset the disconnect list
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Jan 9, 2024
1 parent 5853329 commit f7c0aba
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ type Server struct {
checkpointAddPeer chan *conn

// State of run loop and listenLoop.
inboundHistory expHeap
disconnectEnodeSet map[enode.ID]struct{}
inboundHistory expHeap
disconnectEnodeSet map[enode.ID]struct{}
disconnectEnodeSetMu sync.Mutex
}

type peerOpFunc func(map[enode.ID]*Peer)
Expand Down Expand Up @@ -367,6 +368,16 @@ func (srv *Server) RemovePeer(node *enode.Node) {
ch chan *PeerEvent
sub event.Subscription
)

// Special case: sending a disconnect request with its own enode ID will reset the disconnect enode set
if node.ID() == srv.localnode.ID() {
srv.disconnectEnodeSetMu.Lock()
srv.disconnectEnodeSet = make(map[enode.ID]struct{})
srv.disconnectEnodeSetMu.Unlock()
srv.log.Debug("Reset disconnect enode set")
return
}

// Disconnect the peer on the main loop.
srv.doPeerOp(func(peers map[enode.ID]*Peer) {
srv.dialsched.removeStatic(node)
Expand Down Expand Up @@ -839,7 +850,9 @@ running:
// A peer disconnected.
d := common.PrettyDuration(mclock.Now() - pd.created)
if !pd.requested && pd.err == DiscRequested {
srv.disconnectEnodeSetMu.Lock()
srv.disconnectEnodeSet[pd.ID()] = struct{}{}
srv.disconnectEnodeSetMu.Unlock()
}
delete(peers, pd.ID())
srv.log.Debug("Removing p2p peer", "peercount", len(peers), "id", pd.ID(), "duration", d, "req", pd.requested, "err", pd.err)
Expand Down

0 comments on commit f7c0aba

Please sign in to comment.