@@ -201,7 +201,7 @@ func defaultContentIdFunc(contentKey []byte) []byte {
201201 return digest [:]
202202}
203203
204- func NewPortalProtocol (config * PortalProtocolConfig , protocolId portalwire.ProtocolId , privateKey * ecdsa.PrivateKey , conn UDPConn , localNode * enode.LocalNode , discV5 * UDPv5 , storage storage.ContentStorage , contentQueue chan * ContentElement , opts ... PortalProtocolOption ) (* PortalProtocol , error ) {
204+ func NewPortalProtocol (config * PortalProtocolConfig , protocolId portalwire.ProtocolId , privateKey * ecdsa.PrivateKey , conn UDPConn , localNode * enode.LocalNode , discV5 * UDPv5 , utp * PortalUtp , storage storage.ContentStorage , contentQueue chan * ContentElement , opts ... PortalProtocolOption ) (* PortalProtocol , error ) {
205205 closeCtx , cancelCloseCtx := context .WithCancel (context .Background ())
206206
207207 protocol := & PortalProtocol {
@@ -222,6 +222,7 @@ func NewPortalProtocol(config *PortalProtocolConfig, protocolId portalwire.Proto
222222 offerQueue : make (chan * OfferRequestWithNode , concurrentOffers ),
223223 conn : conn ,
224224 DiscV5 : discV5 ,
225+ Utp : utp ,
225226 NAT : config .NAT ,
226227 clock : config .clock ,
227228 connIdGen : libutp .NewConnIdGenerator (),
@@ -247,7 +248,9 @@ func (p *PortalProtocol) Start() error {
247248 }
248249
249250 p .DiscV5 .RegisterTalkHandler (p .protocolId , p .handleTalkRequest )
250- err = p .Utp .Start ()
251+ if p .Utp != nil {
252+ err = p .Utp .Start ()
253+ }
251254 if err != nil {
252255 return err
253256 }
@@ -268,7 +271,9 @@ func (p *PortalProtocol) Stop() {
268271 p .cancelCloseCtx ()
269272 p .table .close ()
270273 p .DiscV5 .Close ()
271- p .Utp .Stop ()
274+ if p .Utp != nil {
275+ p .Utp .Stop ()
276+ }
272277}
273278func (p * PortalProtocol ) RoutingTableInfo () [][]string {
274279 p .table .mutex .Lock ()
@@ -1146,7 +1151,7 @@ func (p *PortalProtocol) handleFindContent(id enode.ID, addr *net.UDPAddr, reque
11461151 }(p .closeCtx , connectionId )
11471152
11481153 idBuffer := make ([]byte , 2 )
1149- binary .BigEndian .PutUint16 (idBuffer , uint16 ( connectionId .SendId () ))
1154+ binary .BigEndian .PutUint16 (idBuffer , connectionId .SendId ())
11501155 connIdMsg := & portalwire.ConnectionId {
11511156 Id : idBuffer ,
11521157 }
@@ -1286,7 +1291,7 @@ func (p *PortalProtocol) handleOffer(id enode.ID, addr *net.UDPAddr, request *po
12861291 }
12871292 }(p .closeCtx , connectionId )
12881293
1289- binary .BigEndian .PutUint16 (idBuffer , uint16 ( connectionId .SendId () ))
1294+ binary .BigEndian .PutUint16 (idBuffer , connectionId .SendId ())
12901295 } else {
12911296 binary .BigEndian .PutUint16 (idBuffer , uint16 (0 ))
12921297 }
0 commit comments