Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: libp2p/go-libp2p-kad-dht
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3ab49923a8b4646c06b16316601b2a34bd271e87
Choose a base ref
..
head repository: libp2p/go-libp2p-kad-dht
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c09554503d1d36167537e3821433097c224a72c4
Choose a head ref
Showing with 7 additions and 5 deletions.
  1. +7 −5 providers/providers.go
12 changes: 7 additions & 5 deletions providers/providers.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ import (
logging "github.com/ipfs/go-log"
goprocess "github.com/jbenet/goprocess"
goprocessctx "github.com/jbenet/goprocess/context"
periodicproc "github.com/jbenet/goprocess/periodic"
peer "github.com/libp2p/go-libp2p-peer"
base32 "github.com/whyrusleeping/base32"
)
@@ -70,7 +69,6 @@ func NewProviderManager(ctx context.Context, local peer.ID, dstore ds.Batching)
pm.proc = goprocessctx.WithContext(ctx)
pm.cleanupInterval = defaultCleanupInterval
pm.proc.Go(pm.run)
pm.proc.AddChild(periodicproc.Tick(pm.cleanupInterval, pm.gc))

return pm
}
@@ -140,7 +138,7 @@ func loadProvSet(dstore ds.Datastore, k cid.Cid) (*providerSet, error) {
case now.Sub(t) > ProvideValidity:
// or just expired
err = dstore.Delete(ds.RawKey(e.Key))
if err != nil {
if err != nil && err != ds.ErrNotFound {
log.Warning("failed to remove provider record from disk: ", err)
}
continue
@@ -151,7 +149,10 @@ func loadProvSet(dstore ds.Datastore, k cid.Cid) (*providerSet, error) {
decstr, err := base32.RawStdEncoding.DecodeString(e.Key[lix+1:])
if err != nil {
log.Error("base32 decoding error: ", err)
dstore.Delete(ds.RawKey(e.Key))
err = dstore.Delete(ds.RawKey(e.Key))
if err != nil && err != ds.ErrNotFound {
log.Warning("failed to remove provider record from disk: ", err)
}
continue
}

@@ -190,7 +191,7 @@ func writeProviderEntry(dstore ds.Datastore, k cid.Cid, p peer.ID, t time.Time)
return dstore.Put(ds.NewKey(dsk), buf[:n])
}

func (pm *ProviderManager) gc(proc goprocess.Process) {
func (pm *ProviderManager) gc() {
res, err := pm.dstore.Query(dsq.Query{
KeysOnly: true,
Prefix: providersKeyPrefix,
@@ -255,6 +256,7 @@ func (pm *ProviderManager) run(proc goprocess.Process) {
//
// Much faster than GCing.
pm.providers.Purge()
pm.gc()
case <-proc.Closing():
return
}