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

p2p: reset disconnect set with magic enode ID #2144

Merged
merged 1 commit into from
Jan 22, 2024
Merged
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
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