@@ -27,6 +27,7 @@ import (
2727 "errors"
2828 "fmt"
2929 "hash"
30+ "slices"
3031
3132 "github.com/CortexFoundation/CortexTheseus/common/mclock"
3233 "github.com/CortexFoundation/CortexTheseus/p2p/enode"
@@ -222,7 +223,7 @@ func (c *Codec) Encode(id enode.ID, addr string, packet Packet, challenge *Whoar
222223
223224 // Store sent WHOAREYOU challenges.
224225 if challenge , ok := packet .(* Whoareyou ); ok {
225- challenge .ChallengeData = bytesCopy ( & c .buf )
226+ challenge .ChallengeData = slices . Clone ( c .buf . Bytes () )
226227 enc , err := c .EncodeRaw (id , head , msgData )
227228 if err != nil {
228229 return nil , Nonce {}, err
@@ -325,7 +326,7 @@ func (c *Codec) encodeWhoareyou(toID enode.ID, packet *Whoareyou) (Header, error
325326
326327 // Create header.
327328 head := c .makeHeader (toID , flagWhoareyou , 0 )
328- head .AuthData = bytesCopy ( & c .buf )
329+ head .AuthData = slices . Clone ( c .buf . Bytes () )
329330 head .Nonce = packet .Nonce
330331
331332 // Encode auth data.
@@ -430,7 +431,7 @@ func (c *Codec) encodeMessageHeader(toID enode.ID, s *session) (Header, error) {
430431 auth := messageAuthData {SrcID : c .localnode .ID ()}
431432 c .buf .Reset ()
432433 binary .Write (& c .buf , binary .BigEndian , & auth )
433- head .AuthData = bytesCopy ( & c .buf )
434+ head .AuthData = slices . Clone ( c .buf . Bytes () )
434435 head .Nonce = nonce
435436 return head , err
436437}
@@ -686,9 +687,3 @@ func (h *Header) mask(destID enode.ID) cipher.Stream {
686687 }
687688 return cipher .NewCTR (block , h .IV [:])
688689}
689-
690- func bytesCopy (r * bytes.Buffer ) []byte {
691- b := make ([]byte , r .Len ())
692- copy (b , r .Bytes ())
693- return b
694- }
0 commit comments