From 95fd9832179ecbd36d24ead61d7f9f96079f2b93 Mon Sep 17 00:00:00 2001 From: Johan Kiviniemi Date: Sun, 1 Nov 2015 17:56:05 +0200 Subject: [PATCH] Some fixes to #1887 License: MIT Signed-off-by: Johan Kiviniemi --- fuse/ipns/ipns_test.go | 2 +- namesys/routing.go | 24 +++++++++++++++--------- test/sharness/t0240-republisher.sh | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/fuse/ipns/ipns_test.go b/fuse/ipns/ipns_test.go index f65dd42fddf3..fdee5741883f 100644 --- a/fuse/ipns/ipns_test.go +++ b/fuse/ipns/ipns_test.go @@ -113,7 +113,7 @@ func setupIpnsTest(t *testing.T, node *core.IpfsNode) (*core.IpfsNode, *fstest.M } node.Routing = offroute.NewOfflineRouter(node.Repo.Datastore(), node.PrivateKey) - node.Namesys = namesys.NewNameSystem(node.Routing, node.Repo.Datastore()) + node.Namesys = namesys.NewNameSystem(node.Routing, node.Repo.Datastore(), 0) ipnsfs, err := nsfs.NewFilesystem(context.Background(), node.DAG, node.Namesys, node.Pinning, node.PrivateKey) if err != nil { diff --git a/namesys/routing.go b/namesys/routing.go index cea90f6230ae..c37c76fc6cfc 100644 --- a/namesys/routing.go +++ b/namesys/routing.go @@ -23,8 +23,7 @@ var log = logging.Logger("namesys") type routingResolver struct { routing routing.IpfsRouting - cache *lru.Cache - cachelife time.Duration + cache *lru.Cache } func (r *routingResolver) cacheGet(name string) (path.Path, bool) { @@ -40,7 +39,7 @@ func (r *routingResolver) cacheGet(name string) (path.Path, bool) { entry, ok := ientry.(cacheEntry) if !ok { // should never happen, purely for sanity - log.Panicf("unexpected type %T in cache.", ientry) + log.Panicf("unexpected type %T in cache for %q.", ientry, name) } if time.Now().Before(entry.eol) { @@ -53,25 +52,32 @@ func (r *routingResolver) cacheGet(name string) (path.Path, bool) { } func (r *routingResolver) cacheSet(name string, val path.Path, rec *pb.IpnsEntry) { - if r.cache == nil { - return - } - // if completely unspecified, just use one minute ttl := DefaultResolverCacheTTL if rec.Ttl != nil { recttl := time.Duration(rec.GetTtl()) - if recttl < ttl { + if recttl >= 0 { ttl = recttl } } - cacheTil := time.Now().Add(ttl) + now := time.Now() + cacheTil := now.Add(ttl) eol, ok := checkEOL(rec) if ok && eol.Before(cacheTil) { cacheTil = eol } + if cacheTil.Before(now) { + // Already EOL, do not cache. + log.Warningf("%q expired on %v", name, eol) + return + } + + if r.cache == nil { + return + } + r.cache.Add(name, cacheEntry{ val: val, eol: cacheTil, diff --git a/test/sharness/t0240-republisher.sh b/test/sharness/t0240-republisher.sh index c005f957c455..c1db0fbd3da9 100755 --- a/test/sharness/t0240-republisher.sh +++ b/test/sharness/t0240-republisher.sh @@ -26,7 +26,7 @@ setup_iptb() { for i in $(test_seq 0 3) do ipfsi $i config Ipns.RepublishPeriod 20s - ipfsi $i config Ipns.ResolveCacheTime 0s + ipfsi $i config --json Ipns.ResolveCacheSize 0 done '