mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
p2p: EIP-8 changes for protocol handshake
This commit is contained in:
parent
44fbc560c9
commit
fc11dbc6b8
3 changed files with 7 additions and 10 deletions
|
|
@ -56,6 +56,9 @@ type protoHandshake struct {
|
|||
Caps []Cap
|
||||
ListenPort uint64
|
||||
ID discover.NodeID
|
||||
|
||||
// Ignore additional fields (for forward compatibility).
|
||||
Rest []rlp.RawValue `rlp:".."`
|
||||
}
|
||||
|
||||
// Peer represents a connected remote node.
|
||||
|
|
|
|||
|
|
@ -151,10 +151,6 @@ func readProtocolHandshake(rw MsgReader, our *protoHandshake) (*protoHandshake,
|
|||
if err := msg.Decode(&hs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// validate handshake info
|
||||
if hs.Version != our.Version {
|
||||
return nil, DiscIncompatibleVersion
|
||||
}
|
||||
if (hs.ID == discover.NodeID{}) {
|
||||
return nil, DiscInvalidIdentity
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,6 +162,7 @@ func TestProtocolHandshake(t *testing.T) {
|
|||
wg.Add(2)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer fd1.Close()
|
||||
rlpx := newRLPX(fd0)
|
||||
remid, err := rlpx.doEncHandshake(prv0, node1)
|
||||
if err != nil {
|
||||
|
|
@ -178,6 +179,7 @@ func TestProtocolHandshake(t *testing.T) {
|
|||
t.Errorf("dial side proto handshake error: %v", err)
|
||||
return
|
||||
}
|
||||
phs.Rest = nil
|
||||
if !reflect.DeepEqual(phs, hs1) {
|
||||
t.Errorf("dial side proto handshake mismatch:\ngot: %s\nwant: %s\n", spew.Sdump(phs), spew.Sdump(hs1))
|
||||
return
|
||||
|
|
@ -186,6 +188,7 @@ func TestProtocolHandshake(t *testing.T) {
|
|||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer fd1.Close()
|
||||
rlpx := newRLPX(fd1)
|
||||
remid, err := rlpx.doEncHandshake(prv1, nil)
|
||||
if err != nil {
|
||||
|
|
@ -202,6 +205,7 @@ func TestProtocolHandshake(t *testing.T) {
|
|||
t.Errorf("listen side proto handshake error: %v", err)
|
||||
return
|
||||
}
|
||||
phs.Rest = nil
|
||||
if !reflect.DeepEqual(phs, hs0) {
|
||||
t.Errorf("listen side proto handshake mismatch:\ngot: %s\nwant: %s\n", spew.Sdump(phs), spew.Sdump(hs0))
|
||||
return
|
||||
|
|
@ -216,7 +220,6 @@ func TestProtocolHandshake(t *testing.T) {
|
|||
|
||||
func TestProtocolHandshakeErrors(t *testing.T) {
|
||||
our := &protoHandshake{Version: 3, Caps: []Cap{{"foo", 2}, {"bar", 3}}, Name: "quux"}
|
||||
id := randomID()
|
||||
tests := []struct {
|
||||
code uint64
|
||||
msg interface{}
|
||||
|
|
@ -242,11 +245,6 @@ func TestProtocolHandshakeErrors(t *testing.T) {
|
|||
msg: []byte{1, 2, 3},
|
||||
err: newPeerError(errInvalidMsg, "(code 0) (size 4) rlp: expected input list for p2p.protoHandshake"),
|
||||
},
|
||||
{
|
||||
code: handshakeMsg,
|
||||
msg: &protoHandshake{Version: 9944, ID: id},
|
||||
err: DiscIncompatibleVersion,
|
||||
},
|
||||
{
|
||||
code: handshakeMsg,
|
||||
msg: &protoHandshake{Version: 3},
|
||||
|
|
|
|||
Loading…
Reference in a new issue