mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
fix test case
This commit is contained in:
parent
9e10bab51a
commit
713d0b1a90
2 changed files with 23 additions and 25 deletions
|
|
@ -52,7 +52,7 @@ func (s *Suite) AllTests() []utesting.Test {
|
||||||
{Name: "Ping", Fn: s.TestPing},
|
{Name: "Ping", Fn: s.TestPing},
|
||||||
{Name: "PingLargeRequestID", Fn: s.TestPingLargeRequestID},
|
{Name: "PingLargeRequestID", Fn: s.TestPingLargeRequestID},
|
||||||
{Name: "PingMultiIP", Fn: s.TestPingMultiIP},
|
{Name: "PingMultiIP", Fn: s.TestPingMultiIP},
|
||||||
{Name: "PingHandshakeInterrupted", Fn: s.TestPingHandshakeInterrupted},
|
{Name: "HandshakeResend", Fn: s.TestHandshakeResend},
|
||||||
{Name: "TalkRequest", Fn: s.TestTalkRequest},
|
{Name: "TalkRequest", Fn: s.TestTalkRequest},
|
||||||
{Name: "FindnodeZeroDistance", Fn: s.TestFindnodeZeroDistance},
|
{Name: "FindnodeZeroDistance", Fn: s.TestFindnodeZeroDistance},
|
||||||
{Name: "FindnodeResults", Fn: s.TestFindnodeResults},
|
{Name: "FindnodeResults", Fn: s.TestFindnodeResults},
|
||||||
|
|
@ -158,22 +158,20 @@ the attempt from a different IP.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestPingHandshakeInterrupted starts a handshake, but doesn't finish it and sends a second ordinary message
|
// TestHandshakeResend starts a handshake, but doesn't finish it and sends a second ordinary message
|
||||||
// packet instead of a handshake message packet. The remote node should respond with
|
// packet instead of a handshake message packet. The remote node should repeat the previous WHOAREYOU
|
||||||
// another WHOAREYOU challenge for the second packet.
|
// challenge for the first PING.
|
||||||
func (s *Suite) TestPingHandshakeInterrupted(t *utesting.T) {
|
func (s *Suite) TestHandshakeResend(t *utesting.T) {
|
||||||
t.Log(`TestPingHandshakeInterrupted starts a handshake, but doesn't finish it and sends a second ordinary message
|
|
||||||
packet instead of a handshake message packet. The remote node should respond with
|
|
||||||
another WHOAREYOU challenge for the second packet.`)
|
|
||||||
|
|
||||||
conn, l1 := s.listen1(t)
|
conn, l1 := s.listen1(t)
|
||||||
defer conn.close()
|
defer conn.close()
|
||||||
|
|
||||||
// First PING triggers challenge.
|
// First PING triggers challenge.
|
||||||
ping := &v5wire.Ping{ReqID: conn.nextReqID()}
|
ping := &v5wire.Ping{ReqID: conn.nextReqID()}
|
||||||
conn.write(l1, ping, nil)
|
conn.write(l1, ping, nil)
|
||||||
|
var challenge1 *v5wire.Whoareyou
|
||||||
switch resp := conn.read(l1).(type) {
|
switch resp := conn.read(l1).(type) {
|
||||||
case *v5wire.Whoareyou:
|
case *v5wire.Whoareyou:
|
||||||
|
challenge1 = resp
|
||||||
t.Logf("got WHOAREYOU for PING")
|
t.Logf("got WHOAREYOU for PING")
|
||||||
default:
|
default:
|
||||||
t.Fatal("expected WHOAREYOU, got", resp)
|
t.Fatal("expected WHOAREYOU, got", resp)
|
||||||
|
|
@ -181,9 +179,16 @@ another WHOAREYOU challenge for the second packet.`)
|
||||||
|
|
||||||
// Send second PING.
|
// Send second PING.
|
||||||
ping2 := &v5wire.Ping{ReqID: conn.nextReqID()}
|
ping2 := &v5wire.Ping{ReqID: conn.nextReqID()}
|
||||||
switch resp := conn.reqresp(l1, ping2).(type) {
|
conn.write(l1, ping2, nil)
|
||||||
case *v5wire.Pong:
|
switch resp := conn.read(l1).(type) {
|
||||||
checkPong(t, resp, ping2, l1)
|
case *v5wire.Whoareyou:
|
||||||
|
if resp.Nonce != challenge1.Nonce {
|
||||||
|
t.Fatalf("wrong nonce %x in WHOAREYOU (want %x)", resp.Nonce[:], challenge1.Nonce[:])
|
||||||
|
}
|
||||||
|
if !bytes.Equal(resp.ChallengeData, challenge1.ChallengeData) {
|
||||||
|
t.Fatalf("wrong ChallengeData in resent WHOAREYOU (want %x)", resp.ChallengeData, challenge1.ChallengeData)
|
||||||
|
}
|
||||||
|
resp.Node = conn.remote
|
||||||
default:
|
default:
|
||||||
t.Fatal("expected WHOAREYOU, got", resp)
|
t.Fatal("expected WHOAREYOU, got", resp)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -790,20 +790,13 @@ func (t *UDPv5) writeLoop() {
|
||||||
defer t.wg.Done()
|
defer t.wg.Done()
|
||||||
for pw := range t.writeCh { // Loop continues until writeCh is closed and empty.
|
for pw := range t.writeCh { // Loop continues until writeCh is closed and empty.
|
||||||
_, err := t.conn.WriteToUDPAddrPort(pw.data, pw.toAddr)
|
_, err := t.conn.WriteToUDPAddrPort(pw.data, pw.toAddr)
|
||||||
if err != nil {
|
if netutil.IsTemporaryError(err) {
|
||||||
// Generic error logging, as we don't have packetName or rich context here.
|
t.log.Debug("Temporary UDP write error", "addr", pw.toAddr, "err", err)
|
||||||
select {
|
} else if err != nil {
|
||||||
case <-t.closeCtx.Done():
|
if !errors.Is(err, net.ErrClosed) || !errors.Is(err, io.EOF) {
|
||||||
// Log trace level if error occurs during or after shutdown initiation.
|
t.log.Warn("UDP write error", "addr", pw.toAddr, "err", err)
|
||||||
t.log.Trace("UDP write error during/after shutdown", "addr", pw.toAddr, "err", err)
|
|
||||||
default:
|
|
||||||
// Not closing, so it's a more unexpected error.
|
|
||||||
if netutil.IsTemporaryError(err) {
|
|
||||||
t.log.Debug("Temporary UDP write error", "addr", pw.toAddr, "err", err)
|
|
||||||
} else if !errors.Is(err, net.ErrClosed) && !errors.Is(err, io.EOF) { // Avoid logging common "closed" errors if not caught by closeCtx.
|
|
||||||
t.log.Warn("UDP write error", "addr", pw.toAddr, "err", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue