From b3a7c9b6917d957cc9a8c48d156de9cab79f58a4 Mon Sep 17 00:00:00 2001 From: iczc Date: Wed, 12 Oct 2022 20:05:56 +0800 Subject: [PATCH] p2p: define DiscReason as uint8 (#164) p2p: define DiscReason as uint8 (#24507) All other implementations store disconnect reasons as a single byte, so go-ethereum should do it too. Co-authored-by: Felix Lange --- p2p/peer.go | 6 +++--- p2p/peer_error.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/p2p/peer.go b/p2p/peer.go index ad6aa54f10..1c3484fa54 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -324,11 +324,11 @@ func (p *Peer) handle(msg Msg) error { msg.Discard() go SendItems(p.rw, pongMsg) case msg.Code == discMsg: - var reason [1]DiscReason // This is the last message. We don't need to discard or // check errors because, the connection will be closed after it. - rlp.Decode(msg.Payload, &reason) - return reason[0] + var m struct{ R DiscReason } + rlp.Decode(msg.Payload, &m) + return m.R case msg.Code < baseProtocolLength: // ignore other base protocol messages return msg.Discard() diff --git a/p2p/peer_error.go b/p2p/peer_error.go index 393cc86b09..aad1a65c7a 100644 --- a/p2p/peer_error.go +++ b/p2p/peer_error.go @@ -54,7 +54,7 @@ func (pe *peerError) Error() string { var errProtocolReturned = errors.New("protocol returned") -type DiscReason uint +type DiscReason uint8 const ( DiscRequested DiscReason = iota