mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
print raw in discv5 and resend the cached encoded challenge raw
This commit is contained in:
parent
046793b6fa
commit
e050c6283c
3 changed files with 16 additions and 4 deletions
|
|
@ -30,6 +30,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/common/mclock"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover/v5wire"
|
||||
|
|
@ -763,7 +764,7 @@ func (t *UDPv5) send(toID enode.ID, toAddr netip.AddrPort, packet v5wire.Packet,
|
|||
t.log.Warn(">> "+packet.Name(), t.logcontext...)
|
||||
return nonce, err
|
||||
}
|
||||
|
||||
t.logcontext = append(t.logcontext, "rawpacket", hexutil.Encode(enc))
|
||||
_, err = t.conn.WriteToUDPAddrPort(enc, toAddr)
|
||||
t.log.Trace(">> "+packet.Name(), t.logcontext...)
|
||||
return nonce, err
|
||||
|
|
@ -808,6 +809,7 @@ func (t *UDPv5) dispatchReadPacket(from netip.AddrPort, content []byte) bool {
|
|||
// handlePacket decodes and processes an incoming packet from the network.
|
||||
func (t *UDPv5) handlePacket(rawpacket []byte, fromAddr netip.AddrPort) error {
|
||||
addr := fromAddr.String()
|
||||
t.log.Trace("<< "+addr, "rawPacket", hexutil.Encode(rawpacket))
|
||||
fromID, fromNode, packet, err := t.codec.Decode(rawpacket, addr)
|
||||
if err != nil {
|
||||
if t.unhandled != nil && v5wire.IsInvalidHeader(err) {
|
||||
|
|
|
|||
|
|
@ -189,6 +189,9 @@ func (c *Codec) Encode(id enode.ID, addr string, packet Packet, challenge *Whoar
|
|||
)
|
||||
switch {
|
||||
case packet.Kind() == WhoareyouPacket:
|
||||
if sentWhoareyou := c.sc.getHandshake(id, addr); sentWhoareyou != nil {
|
||||
return sentWhoareyou.encoded, sentWhoareyou.Nonce, nil
|
||||
}
|
||||
head, err = c.encodeWhoareyou(id, packet.(*Whoareyou))
|
||||
case challenge != nil:
|
||||
// We have an unanswered challenge, send handshake.
|
||||
|
|
@ -215,10 +218,17 @@ func (c *Codec) Encode(id enode.ID, addr string, packet Packet, challenge *Whoar
|
|||
// Encode header data.
|
||||
c.writeHeaders(&head)
|
||||
|
||||
var enc []byte
|
||||
// Store sent WHOAREYOU challenges.
|
||||
if challenge, ok := packet.(*Whoareyou); ok {
|
||||
challenge.ChallengeData = bytesCopy(&c.buf)
|
||||
enc, err = c.EncodeRaw(id, head, msgData)
|
||||
if err != nil {
|
||||
return nil, Nonce{}, err
|
||||
}
|
||||
challenge.encoded = enc
|
||||
c.sc.storeSentHandshake(id, addr, challenge)
|
||||
return enc, head.Nonce, err
|
||||
} else if msgData == nil {
|
||||
headerData := c.buf.Bytes()
|
||||
msgData, err = c.encryptMessage(session, packet, &head, headerData)
|
||||
|
|
@ -226,8 +236,7 @@ func (c *Codec) Encode(id enode.ID, addr string, packet Packet, challenge *Whoar
|
|||
return nil, Nonce{}, err
|
||||
}
|
||||
}
|
||||
|
||||
enc, err := c.EncodeRaw(id, head, msgData)
|
||||
enc, err = c.EncodeRaw(id, head, msgData)
|
||||
return enc, head.Nonce, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,8 @@ type (
|
|||
// This must be set by the caller of Encode.
|
||||
Node *enode.Node
|
||||
|
||||
sent mclock.AbsTime // for handshake GC.
|
||||
sent mclock.AbsTime // for handshake GC.
|
||||
encoded []byte // Encoded packet raw data for sending out
|
||||
}
|
||||
|
||||
// PING is sent during liveness checks.
|
||||
|
|
|
|||
Loading…
Reference in a new issue