4949
5050var pingCid = "bafkqaaa" // identity CID
5151
52+ const http2proto = "HTTP/2.0"
53+
5254// Option allows to configure the Network.
5355type Option func (net * Network )
5456
@@ -167,7 +169,6 @@ type Network struct {
167169func New (host host.Host , opts ... Option ) network.BitSwapNetwork {
168170 htnet := & Network {
169171 host : host ,
170- pinger : newPinger (host ),
171172 userAgent : defaultUserAgent (),
172173 maxBlockSize : DefaultMaxBlockSize ,
173174 dialTimeout : DefaultDialTimeout ,
@@ -236,10 +237,13 @@ func New(host host.Host, opts ...Option) network.BitSwapNetwork {
236237 }
237238
238239 c := & http.Client {
239- Transport : newTransport ( t ) ,
240+ Transport : t ,
240241 }
241242 htnet .client = c
242243
244+ pinger := newPinger (host , htnet .client , pingCid , htnet .userAgent )
245+ htnet .pinger = pinger
246+
243247 return htnet
244248}
245249
@@ -353,7 +357,7 @@ func (ht *Network) Connect(ctx context.Context, p peer.AddrInfo) error {
353357 // on success.
354358 var workingAddrs []multiaddr.Multiaddr
355359 for i , u := range urls {
356- req , err := ht . buildRequest (ctx , u , "GET" , pingCid )
360+ req , err := buildRequest (ctx , u , "GET" , pingCid , ht . userAgent )
357361 if err != nil {
358362 log .Debug (err )
359363 return err
@@ -370,7 +374,7 @@ func (ht *Network) Connect(ctx context.Context, p peer.AddrInfo) error {
370374 continue
371375 }
372376
373- if resp .Proto != "HTTP/2.0" {
377+ if resp .Proto != http2proto {
374378 log .Warnf ("%s://%q is not using HTTP/2 (%s)" , req .URL .Scheme , req .URL .Host , resp .Proto )
375379 }
376380
@@ -452,7 +456,7 @@ func (ht *Network) Stats() network.Stats {
452456}
453457
454458// buildRequests sets up common settings for making a requests.
455- func ( ht * Network ) buildRequest (ctx context.Context , u network.ParsedURL , method string , cid string ) (* http.Request , error ) {
459+ func buildRequest (ctx context.Context , u network.ParsedURL , method string , cid string , userAgent string ) (* http.Request , error ) {
456460 // copy url
457461 sendURL , _ := url .Parse (u .URL .String ())
458462 sendURL .RawQuery = "format=raw"
@@ -470,7 +474,7 @@ func (ht *Network) buildRequest(ctx context.Context, u network.ParsedURL, method
470474
471475 headers := make (http.Header )
472476 headers .Add ("Accept" , "application/vnd.ipld.raw" )
473- headers .Add ("User-Agent" , ht . userAgent )
477+ headers .Add ("User-Agent" , userAgent )
474478 if u .SNI != "" {
475479 headers .Add ("Host" , u .SNI )
476480 }
0 commit comments