Skip to content

Commit

Permalink
p2p: reset disconnect set with magic enode ID (#2144)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann authored Jan 22, 2024
1 parent a6a9562 commit d102001
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ var (
errServerStopped = errors.New("server stopped")
errEncHandshakeError = errors.New("rlpx enc error")
errProtoHandshakeError = errors.New("rlpx proto error")

// magicEnodeID is a special enode ID that can be used to disconnect all peers
// enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439
magicEnodeID = enode.ID{52, 49, 195, 147, 158, 30, 226, 166, 52, 94, 151, 106, 130, 52, 249, 135, 1, 82, 214, 72, 121, 243, 11, 194, 114, 160, 116, 246, 133, 158, 117, 232}
)

// Config holds Server options.
Expand Down Expand Up @@ -367,8 +371,16 @@ func (srv *Server) RemovePeer(node *enode.Node) {
ch chan *PeerEvent
sub event.Subscription
)

// Disconnect the peer on the main loop.
srv.doPeerOp(func(peers map[enode.ID]*Peer) {
// Special case: sending a disconnect request with a hardcoded enode ID will reset the disconnect enode set
if node.ID() == magicEnodeID {
srv.disconnectEnodeSet = make(map[enode.ID]struct{})
srv.log.Debug("Reset disconnect enode set")
return
}

srv.dialsched.removeStatic(node)
if peer := peers[node.ID()]; peer != nil {
ch = make(chan *PeerEvent, 1)
Expand Down

0 comments on commit d102001

Please sign in to comment.