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
|
Caps []Cap
|
||||||
ListenPort uint64
|
ListenPort uint64
|
||||||
ID discover.NodeID
|
ID discover.NodeID
|
||||||
|
|
||||||
|
// Ignore additional fields (for forward compatibility).
|
||||||
|
Rest []rlp.RawValue `rlp:".."`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peer represents a connected remote node.
|
// Peer represents a connected remote node.
|
||||||
|
|
|
||||||
|
|
@ -151,10 +151,6 @@ func readProtocolHandshake(rw MsgReader, our *protoHandshake) (*protoHandshake,
|
||||||
if err := msg.Decode(&hs); err != nil {
|
if err := msg.Decode(&hs); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// validate handshake info
|
|
||||||
if hs.Version != our.Version {
|
|
||||||
return nil, DiscIncompatibleVersion
|
|
||||||
}
|
|
||||||
if (hs.ID == discover.NodeID{}) {
|
if (hs.ID == discover.NodeID{}) {
|
||||||
return nil, DiscInvalidIdentity
|
return nil, DiscInvalidIdentity
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,7 @@ func TestProtocolHandshake(t *testing.T) {
|
||||||
wg.Add(2)
|
wg.Add(2)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
defer fd1.Close()
|
||||||
rlpx := newRLPX(fd0)
|
rlpx := newRLPX(fd0)
|
||||||
remid, err := rlpx.doEncHandshake(prv0, node1)
|
remid, err := rlpx.doEncHandshake(prv0, node1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -178,6 +179,7 @@ func TestProtocolHandshake(t *testing.T) {
|
||||||
t.Errorf("dial side proto handshake error: %v", err)
|
t.Errorf("dial side proto handshake error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
phs.Rest = nil
|
||||||
if !reflect.DeepEqual(phs, hs1) {
|
if !reflect.DeepEqual(phs, hs1) {
|
||||||
t.Errorf("dial side proto handshake mismatch:\ngot: %s\nwant: %s\n", spew.Sdump(phs), spew.Sdump(hs1))
|
t.Errorf("dial side proto handshake mismatch:\ngot: %s\nwant: %s\n", spew.Sdump(phs), spew.Sdump(hs1))
|
||||||
return
|
return
|
||||||
|
|
@ -186,6 +188,7 @@ func TestProtocolHandshake(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
defer fd1.Close()
|
||||||
rlpx := newRLPX(fd1)
|
rlpx := newRLPX(fd1)
|
||||||
remid, err := rlpx.doEncHandshake(prv1, nil)
|
remid, err := rlpx.doEncHandshake(prv1, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -202,6 +205,7 @@ func TestProtocolHandshake(t *testing.T) {
|
||||||
t.Errorf("listen side proto handshake error: %v", err)
|
t.Errorf("listen side proto handshake error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
phs.Rest = nil
|
||||||
if !reflect.DeepEqual(phs, hs0) {
|
if !reflect.DeepEqual(phs, hs0) {
|
||||||
t.Errorf("listen side proto handshake mismatch:\ngot: %s\nwant: %s\n", spew.Sdump(phs), spew.Sdump(hs0))
|
t.Errorf("listen side proto handshake mismatch:\ngot: %s\nwant: %s\n", spew.Sdump(phs), spew.Sdump(hs0))
|
||||||
return
|
return
|
||||||
|
|
@ -216,7 +220,6 @@ func TestProtocolHandshake(t *testing.T) {
|
||||||
|
|
||||||
func TestProtocolHandshakeErrors(t *testing.T) {
|
func TestProtocolHandshakeErrors(t *testing.T) {
|
||||||
our := &protoHandshake{Version: 3, Caps: []Cap{{"foo", 2}, {"bar", 3}}, Name: "quux"}
|
our := &protoHandshake{Version: 3, Caps: []Cap{{"foo", 2}, {"bar", 3}}, Name: "quux"}
|
||||||
id := randomID()
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
code uint64
|
code uint64
|
||||||
msg interface{}
|
msg interface{}
|
||||||
|
|
@ -242,11 +245,6 @@ func TestProtocolHandshakeErrors(t *testing.T) {
|
||||||
msg: []byte{1, 2, 3},
|
msg: []byte{1, 2, 3},
|
||||||
err: newPeerError(errInvalidMsg, "(code 0) (size 4) rlp: expected input list for p2p.protoHandshake"),
|
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,
|
code: handshakeMsg,
|
||||||
msg: &protoHandshake{Version: 3},
|
msg: &protoHandshake{Version: 3},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue