@@ -648,7 +648,7 @@ func (p *PortalProtocol) processContent(target *enode.Node, resp []byte) (byte,
648648 return 0xff , nil , err
649649 }
650650
651- p .log .Trace ("Received content response" , "id" , target .ID (), "connIdMsg" , connIdMsg )
651+ p .log .Trace ("Received returned content response" , "id" , target .ID (), "connIdMsg" , connIdMsg )
652652 p .setJustSeen (target )
653653 connctx , conncancel := context .WithTimeout (p .closeCtx , defaultUTPConnectTimeout )
654654 laddr := p .utp .Addr ().(* utp.Addr )
@@ -666,22 +666,13 @@ func (p *PortalProtocol) processContent(target *enode.Node, resp []byte) (byte,
666666 return 0xff , nil , err
667667 }
668668 // Read ALL the data from the connection until EOF and return it
669- data := make ([]byte , 0 )
670- buf := make ([]byte , 1024 )
671- for {
672- var read int
673- read , err = conn .Read (buf )
674- if err != nil {
675- if errors .Is (err , io .EOF ) {
676- p .log .Trace ("Received content response" , "id" , target .ID (), "data" , data , "size" , read )
677- return resp [1 ], data , nil
678- }
679-
680- p .log .Error ("failed to read from utp connection" , "err" , err )
681- return 0xff , nil , err
682- }
683- data = append (data , buf [:read ]... )
669+ data , err := io .ReadAll (conn )
670+ if err != nil {
671+ p .log .Error ("failed to read from utp connection" , "err" , err )
672+ return 0xff , nil , err
684673 }
674+ p .log .Trace ("Received content response" , "id" , target .ID (), "size" , len (data ), "data" , data )
675+ return resp [1 ], data , nil
685676 case portalwire .ContentEnrsSelector :
686677 enrs := & portalwire.Enrs {}
687678 err := enrs .UnmarshalSSZ (resp [2 :])
@@ -968,7 +959,7 @@ func (p *PortalProtocol) handleFindContent(id enode.ID, addr *net.UDPAddr, reque
968959 enrs := p .truncateNodes (closestNodes , maxPayloadSize , enrOverhead )
969960 // TODO fix when no content and no enrs found
970961 if len (enrs ) == 0 {
971- enrs = append ( enrs , [] byte {})
962+ enrs = nil
972963 }
973964
974965 enrsMsg := & portalwire.Enrs {
@@ -1160,22 +1151,13 @@ func (p *PortalProtocol) handleOffer(id enode.ID, addr *net.UDPAddr, request *po
11601151 return
11611152 }
11621153 // Read ALL the data from the connection until EOF and return it
1163- data := make ([]byte , 0 )
1164- buf := make ([]byte , 1024 )
1165- for {
1166- var n int
1167- n , err = conn .Read (buf )
1168- if err != nil {
1169- if errors .Is (err , io .EOF ) {
1170- p .log .Trace ("Received content response" , "id" , id , "data" , data , "size" , n )
1171- break
1172- }
1173-
1174- p .log .Error ("failed to read from utp connection" , "err" , err )
1175- return
1176- }
1177- data = append (data , buf [:n ]... )
1154+ var data []byte
1155+ data , err = io .ReadAll (conn )
1156+ if err != nil {
1157+ p .log .Error ("failed to read from utp connection" , "err" , err )
1158+ return
11781159 }
1160+ p .log .Trace ("Received offer content response" , "id" , id , "size" , len (data ), "data" , data )
11791161
11801162 err = p .handleOfferedContents (id , contentKeys , data )
11811163 if err != nil {
0 commit comments