mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
cmd/devp2p/v5test: relax findnode handshake test
This commit is contained in:
parent
e7e81cfce2
commit
ba64f9eb88
1 changed files with 24 additions and 10 deletions
|
|
@ -259,30 +259,44 @@ The remote node should challenge the second endpoint with WHOAREYOU instead of r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Suite) TestFindnodeHandshake(t *utesting.T) {
|
func (s *Suite) TestFindnodeHandshake(t *utesting.T) {
|
||||||
|
t.Log(`This test checks that the remote answers a FINDNODE request only after completing the WHOAREYOU handshake.`)
|
||||||
|
|
||||||
conn, l1 := s.listen1(t)
|
conn, l1 := s.listen1(t)
|
||||||
defer conn.close()
|
defer conn.close()
|
||||||
|
|
||||||
req := &v5wire.Findnode{ReqID: conn.nextReqID(), Distances: []uint{0}}
|
req := &v5wire.Findnode{ReqID: conn.nextReqID(), Distances: []uint{0}}
|
||||||
nonce := conn.write(l1, req, nil)
|
nonce := conn.write(l1, req, nil)
|
||||||
|
|
||||||
challenge, ok := conn.read(l1).(*v5wire.Whoareyou)
|
resp, from := conn.readFrom(l1)
|
||||||
|
challenge, ok := resp.(*v5wire.Whoareyou)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("expected WHOAREYOU before NODES")
|
t.Fatalf("expected WHOAREYOU before NODES, got %T (%v) from %v", resp, resp, from)
|
||||||
}
|
}
|
||||||
if challenge.Nonce != nonce {
|
if challenge.Nonce != nonce {
|
||||||
t.Fatalf("wrong nonce %x in WHOAREYOU (want %x)", challenge.Nonce[:], nonce[:])
|
t.Fatalf("wrong nonce %x in WHOAREYOU (want %x)", challenge.Nonce[:], nonce[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
challenge.Node = conn.remote
|
challenge.Node = conn.remote
|
||||||
conn.write(l1, req, challenge)
|
conn.writeTo(l1, req, challenge, from)
|
||||||
|
|
||||||
resp := conn.read(l1)
|
for {
|
||||||
nodes, ok := resp.(*v5wire.Nodes)
|
resp, from := conn.readFrom(l1)
|
||||||
if !ok {
|
switch resp := resp.(type) {
|
||||||
t.Fatal("expected NODES after completing handshake, got", resp)
|
case *v5wire.Ping:
|
||||||
}
|
conn.writeTo(l1, &v5wire.Pong{
|
||||||
if !bytes.Equal(nodes.ReqID, req.ReqID) {
|
ReqID: resp.ReqID,
|
||||||
t.Fatalf("wrong request ID %x in NODES, want %x", nodes.ReqID, req.ReqID)
|
ENRSeq: conn.localNode.Seq(),
|
||||||
|
ToIP: from.IP,
|
||||||
|
ToPort: uint16(from.Port),
|
||||||
|
}, nil, from)
|
||||||
|
case *v5wire.Nodes:
|
||||||
|
if !bytes.Equal(resp.ReqID, req.ReqID) {
|
||||||
|
t.Fatalf("wrong request ID %x in NODES, want %x", resp.ReqID, req.ReqID)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
t.Fatalf("expected NODES after completing handshake, got %T (%v) from %v", resp, resp, from)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue