@@ -54,6 +54,11 @@ const (
5454 ntpFailureThreshold = 32 // Continuous timeouts after which to check NTP
5555 ntpWarningCooldown = 10 * time .Minute // Minimum amount of time to pass before repeating NTP warning
5656 driftThreshold = 10 * time .Second // Allowed clock drift before warning user
57+
58+ // Discovery packets are defined to be no larger than 1280 bytes.
59+ // Packets larger than this size will be cut at the end and treated
60+ // as invalid because their hash won't match.
61+ maxPacketSize = 1280
5762)
5863
5964// RPC packet types
@@ -496,7 +501,7 @@ var (
496501 headSpace = make ([]byte , headSize )
497502
498503 // Neighbors replies are sent across multiple packets to
499- // stay below the 1280 byte limit. We compute the maximum number
504+ // stay below the packet size limit. We compute the maximum number
500505 // of entries by stuffing a packet until it grows too large.
501506 maxNeighbors int
502507)
@@ -511,7 +516,7 @@ func init() {
511516 // If this ever happens, it will be caught by the unit tests.
512517 panic ("cannot encode: " + err .Error ())
513518 }
514- if headSize + size + 1 >= 1280 {
519+ if headSize + size + 1 >= maxPacketSize {
515520 maxNeighbors = n
516521 break
517522 }
@@ -562,10 +567,7 @@ func (t *udp) readLoop(unhandled chan<- ReadPacket) {
562567 defer close (unhandled )
563568 }
564569
565- // Discovery packets are defined to be no larger than 1280 bytes.
566- // Packets larger than this size will be cut at the end and treated
567- // as invalid because their hash won't match.
568- buf := make ([]byte , 1280 )
570+ buf := make ([]byte , maxPacketSize )
569571 for {
570572 nbytes , from , err := t .conn .ReadFromUDP (buf )
571573 if netutil .IsTemporaryError (err ) {
@@ -715,7 +717,7 @@ func (req *findnode) handle(t *udp, from *net.UDPAddr, fromID enode.ID, mac []by
715717 t .tab .mutex .Unlock ()
716718
717719 // Send neighbors in chunks with at most maxNeighbors per packet
718- // to stay below the 1280 byte limit.
720+ // to stay below the packet size limit.
719721 p := neighbors {Expiration : uint64 (time .Now ().Add (expiration ).Unix ())}
720722 var sent bool
721723 for _ , n := range closest {
0 commit comments