mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
p2p: revert decoding changes
This commit is contained in:
parent
9aa76a692d
commit
78b3b9206d
2 changed files with 3 additions and 18 deletions
|
|
@ -343,11 +343,11 @@ func (p *Peer) handle(msg Msg) error {
|
||||||
case <-p.closed:
|
case <-p.closed:
|
||||||
}
|
}
|
||||||
case msg.Code == discMsg:
|
case msg.Code == discMsg:
|
||||||
var reason [1]DiscReason
|
|
||||||
// This is the last message. We don't need to discard or
|
// This is the last message. We don't need to discard or
|
||||||
// check errors because, the connection will be closed after it.
|
// check errors because, the connection will be closed after it.
|
||||||
rlp.Decode(msg.Payload, &reason)
|
var m struct{ R DiscReason }
|
||||||
return reason[0]
|
rlp.Decode(msg.Payload, &m)
|
||||||
|
return m.R
|
||||||
case msg.Code < baseProtocolLength:
|
case msg.Code < baseProtocolLength:
|
||||||
// ignore other base protocol messages
|
// ignore other base protocol messages
|
||||||
return msg.Discard()
|
return msg.Discard()
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,9 @@
|
||||||
package p2p
|
package p2p
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -363,15 +360,3 @@ func TestMatchProtocols(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDiscReasonDecoding(t *testing.T) {
|
|
||||||
// as it is encoded func (t *rlpxTransport) close(err error) in transport.go
|
|
||||||
var payload bytes.Buffer
|
|
||||||
err := rlp.Encode(&payload, []DiscReason{DiscQuitting})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
p := &Peer{}
|
|
||||||
err = p.handle(Msg{Code: discMsg, Payload: bytes.NewReader(payload.Bytes())})
|
|
||||||
t.Log(err)
|
|
||||||
require.True(t, errors.Is(err, DiscQuitting))
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue