@@ -25,8 +25,8 @@ import (
2525 dht_pb "github.com/libp2p/go-libp2p-kad-dht/pb"
2626 dhtprovider "github.com/libp2p/go-libp2p-kad-dht/provider"
2727 "github.com/libp2p/go-libp2p-kad-dht/provider/buffered"
28- rds "github.com/libp2p/go-libp2p-kad-dht/provider/datastore"
2928 ddhtprovider "github.com/libp2p/go-libp2p-kad-dht/provider/dual"
29+ "github.com/libp2p/go-libp2p-kad-dht/provider/keystore"
3030 routinghelpers "github.com/libp2p/go-libp2p-routing-helpers"
3131 "github.com/libp2p/go-libp2p/core/host"
3232 peer "github.com/libp2p/go-libp2p/core/peer"
@@ -85,7 +85,7 @@ type DHTProvider interface {
8585 // The keys are not deleted from the keystore, so they will continue to be
8686 // reprovided as scheduled.
8787 Clear () int
88- // RefreshSchedule scans the KeyStore for any keys that are not currently
88+ // RefreshSchedule scans the Keystore for any keys that are not currently
8989 // scheduled for reproviding. If such keys are found, it schedules their
9090 // associated keyspace region to be reprovided.
9191 //
@@ -303,12 +303,12 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
303303 DHT routing.Routing `name:"dhtc"`
304304 Repo repo.Repo
305305 }
306- sweepingReprovider := fx .Provide (func (in providerInput ) (DHTProvider , * rds. ResettableKeyStore , error ) {
306+ sweepingReprovider := fx .Provide (func (in providerInput ) (DHTProvider , * keystore. ResettableKeystore , error ) {
307307 ds := in .Repo .Datastore ()
308- keyStore , err := rds . NewResettableKeyStore (ds ,
309- rds .WithPrefixBits (16 ),
310- rds . WithDatastorePrefix ("/provider/keystore" ),
311- rds .WithBatchSize (int (cfg .Reprovider .Sweep .KeyStoreBatchSize .WithDefault (config .DefaultReproviderSweepKeyStoreBatchSize ))),
308+ ks , err := keystore . NewResettableKeystore (ds ,
309+ keystore .WithPrefixBits (16 ),
310+ keystore . WithDatastorePath ("/provider/keystore" ),
311+ keystore .WithBatchSize (int (cfg .Reprovider .Sweep .KeyStoreBatchSize .WithDefault (config .DefaultReproviderSweepKeyStoreBatchSize ))),
312312 )
313313 if err != nil {
314314 return & NoopProvider {}, nil , err
@@ -329,7 +329,7 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
329329 case * dual.DHT :
330330 if inDht != nil {
331331 prov , err := ddhtprovider .New (inDht ,
332- ddhtprovider .WithKeyStore ( keyStore ),
332+ ddhtprovider .WithKeystore ( ks ),
333333
334334 ddhtprovider .WithReprovideInterval (reprovideInterval ),
335335 ddhtprovider .WithMaxReprovideDelay (time .Hour ),
@@ -344,7 +344,7 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
344344 if err != nil {
345345 return nil , nil , err
346346 }
347- return buffered .New (prov , ds , bufferedProviderOpts ... ), keyStore , nil
347+ return buffered .New (prov , ds , bufferedProviderOpts ... ), ks , nil
348348 }
349349 case * fullrt.FullRT :
350350 if inDht != nil {
@@ -362,7 +362,7 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
362362 selfAddrsFunc = func () []ma.Multiaddr { return impl .Host ().Addrs () }
363363 }
364364 opts := []dhtprovider.Option {
365- dhtprovider .WithKeyStore ( keyStore ),
365+ dhtprovider .WithKeystore ( ks ),
366366 dhtprovider .WithPeerID (impl .Host ().ID ()),
367367 dhtprovider .WithRouter (impl ),
368368 dhtprovider .WithMessageSender (impl .MessageSender ()),
@@ -387,27 +387,27 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
387387 if err != nil {
388388 return & NoopProvider {}, nil , err
389389 }
390- return buffered .New (prov , ds , bufferedProviderOpts ... ), keyStore , nil
390+ return buffered .New (prov , ds , bufferedProviderOpts ... ), ks , nil
391391 })
392392
393393 type keystoreInput struct {
394394 fx.In
395395 Provider DHTProvider
396- KeyStore * rds. ResettableKeyStore
396+ Keystore * keystore. ResettableKeystore
397397 KeyProvider provider.KeyChanFunc
398398 }
399- initKeyStore := fx .Invoke (func (lc fx.Lifecycle , in keystoreInput ) {
399+ initKeystore := fx .Invoke (func (lc fx.Lifecycle , in keystoreInput ) {
400400 var (
401401 cancel context.CancelFunc
402402 done = make (chan struct {})
403403 )
404404
405- syncKeyStore := func (ctx context.Context ) error {
405+ syncKeystore := func (ctx context.Context ) error {
406406 kcf , err := in .KeyProvider (ctx )
407407 if err != nil {
408408 return err
409409 }
410- if err := in .KeyStore .ResetCids (ctx , kcf ); err != nil {
410+ if err := in .Keystore .ResetCids (ctx , kcf ); err != nil {
411411 return err
412412 }
413413 if err := in .Provider .RefreshSchedule (); err != nil {
@@ -418,15 +418,15 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
418418
419419 lc .Append (fx.Hook {
420420 OnStart : func (ctx context.Context ) error {
421- if in .Provider == nil || in .KeyStore == nil {
421+ if in .Provider == nil || in .Keystore == nil {
422422 return nil
423423 }
424424 // Set the KeyProvider as a garbage collection function for the
425- // keystore. Periodically purge the KeyStore from all its keys and
425+ // keystore. Periodically purge the Keystore from all its keys and
426426 // replace them with the keys that needs to be reprovided, coming from
427427 // the KeyChanFunc. So far, this is the less worse way to remove CIDs
428428 // that shouldn't be reprovided from the provider's state.
429- if err := syncKeyStore (ctx ); err != nil {
429+ if err := syncKeystore (ctx ); err != nil {
430430 return err
431431 }
432432
@@ -443,7 +443,7 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
443443 case <- gcCtx .Done ():
444444 return
445445 case <- ticker .C :
446- if err := syncKeyStore (gcCtx ); err != nil {
446+ if err := syncKeystore (gcCtx ); err != nil {
447447 logger .Errorw ("provider keystore sync" , "err" , err )
448448 }
449449 }
@@ -452,12 +452,11 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
452452 return nil
453453 },
454454 OnStop : func (ctx context.Context ) error {
455- if in .Provider == nil || in .KeyStore == nil {
455+ if in .Provider == nil || in .Keystore == nil {
456456 return nil
457457 }
458-
459458 if cancel != nil {
460- // Cancel KeyStore garbage collection loop
459+ // Cancel Keystore garbage collection loop
461460 cancel ()
462461 }
463462 select {
@@ -466,15 +465,15 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
466465 return ctx .Err ()
467466 }
468467
469- // KeyStore state isn't be persisted across restarts.
470- return in .KeyStore .Empty (ctx )
468+ // Keystore state isn't be persisted across restarts.
469+ return in .Keystore .Empty (ctx )
471470 },
472471 })
473472 })
474473
475474 return fx .Options (
476475 sweepingReprovider ,
477- initKeyStore ,
476+ initKeystore ,
478477 )
479478}
480479
0 commit comments