Skip to content

Commit

Permalink
Some fixes to ipfs#1887
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Johan Kiviniemi <devel@johan.kiviniemi.name>
  • Loading branch information
ion1 committed Nov 1, 2015
1 parent 948c5d4 commit 95fd983
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion fuse/ipns/ipns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 15 additions & 9 deletions namesys/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/sharness/t0240-republisher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
'

Expand Down

0 comments on commit 95fd983

Please sign in to comment.