Skip to content

Commit 26b1b05

Browse files
authored
Merge pull request stars-labs#66 from stars-labs/fix/p2p-discreason
p2p: define DiscReason as uint8.
2 parents e788e45 + 406535c commit 26b1b05

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

p2p/peer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ func (p *Peer) handle(msg Msg) error {
324324
msg.Discard()
325325
go SendItems(p.rw, pongMsg)
326326
case msg.Code == discMsg:
327-
var reason [1]DiscReason
328327
// This is the last message. We don't need to discard or
329328
// check errors because, the connection will be closed after it.
330-
rlp.Decode(msg.Payload, &reason)
331-
return reason[0]
329+
var m struct{ R DiscReason }
330+
rlp.Decode(msg.Payload, &m)
331+
return m.R
332332
case msg.Code < baseProtocolLength:
333333
// ignore other base protocol messages
334334
return msg.Discard()

p2p/peer_error.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (pe *peerError) Error() string {
5454

5555
var errProtocolReturned = errors.New("protocol returned")
5656

57-
type DiscReason uint
57+
type DiscReason uint8
5858

5959
const (
6060
DiscRequested DiscReason = iota
@@ -69,7 +69,7 @@ const (
6969
DiscUnexpectedIdentity
7070
DiscSelf
7171
DiscReadTimeout
72-
DiscSubprotocolError = 0x10
72+
DiscSubprotocolError = DiscReason(0x10)
7373
)
7474

7575
var discReasonToString = [...]string{

0 commit comments

Comments
 (0)