@@ -195,7 +195,7 @@ func New(ctx context.Context, h host.Host, options ...Option) (*IpfsDHT, error)
195195 return nil , err
196196 }
197197
198- dht , err := makeDHT (h , cfg )
198+ dht , err := makeDHT (ctx , h , cfg )
199199 if err != nil {
200200 return nil , fmt .Errorf ("failed to create DHT, err=%s" , err )
201201 }
@@ -280,7 +280,7 @@ func NewDHTClient(ctx context.Context, h host.Host, dstore ds.Batching) *IpfsDHT
280280 return dht
281281}
282282
283- func makeDHT (h host.Host , cfg dhtcfg.Config ) (* IpfsDHT , error ) {
283+ func makeDHT (ctx context. Context , h host.Host , cfg dhtcfg.Config ) (* IpfsDHT , error ) {
284284 var protocols , serverProtocols []protocol.ID
285285
286286 v1proto := cfg .ProtocolPrefix + kad1
@@ -352,20 +352,20 @@ func makeDHT(h host.Host, cfg dhtcfg.Config) (*IpfsDHT, error) {
352352 dht .optProvJobsPool = make (chan struct {}, cfg .OptimisticProvideJobsPoolSize )
353353 }
354354
355+ // create a tagged context derived from the original context
356+ // the DHT context should be done when the process is closed
357+ dht .ctx , dht .cancel = context .WithCancel (dht .newContextWithLocalTags (ctx ))
358+
355359 // rt refresh manager
356360 dht .rtRefreshManager , err = makeRtRefreshManager (dht , cfg , maxLastSuccessfulOutboundThreshold )
357361 if err != nil {
358362 return nil , fmt .Errorf ("failed to construct RT Refresh Manager,err=%s" , err )
359363 }
360364
361- // create a tagged context derived from the original context
362- // the DHT context should be done when the process is closed
363- dht .ctx , dht .cancel = context .WithCancel (dht .newContextWithLocalTags (context .Background ()))
364-
365365 if cfg .ProviderStore != nil {
366366 dht .providerStore = cfg .ProviderStore
367367 } else {
368- dht .providerStore , err = providers .NewProviderManager (h .ID (), dht .peerstore , cfg .Datastore )
368+ dht .providerStore , err = providers .NewProviderManager (dht . ctx , h .ID (), dht .peerstore , cfg .Datastore )
369369 if err != nil {
370370 return nil , fmt .Errorf ("initializing default provider manager (%v)" , err )
371371 }
@@ -402,6 +402,7 @@ func makeRtRefreshManager(dht *IpfsDHT, cfg dhtcfg.Config, maxLastSuccessfulOutb
402402 }
403403
404404 r , err := rtrefresh .NewRtRefreshManager (
405+ dht .ctx ,
405406 dht .host , dht .routingTable , cfg .RoutingTable .AutoRefresh ,
406407 keyGenFnc ,
407408 queryFnc ,
0 commit comments