提交 96648f27 作者: vyzo 提交者: Łukasz Magiera

namecache: post-rebase updates

License: MIT
Signed-off-by: 's avatarvyzo <vyzo@hackzen.org>
上级 36a1eb6f
...@@ -289,7 +289,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment ...@@ -289,7 +289,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
ipnsps, _ := req.Options[enableIPNSPubSubKwd].(bool) ipnsps, _ := req.Options[enableIPNSPubSubKwd].(bool)
pubsub, _ := req.Options[enablePubSubKwd].(bool) pubsub, _ := req.Options[enablePubSubKwd].(bool)
mplex, _ := req.Options[enableMultiplexKwd].(bool) mplex, _ := req.Options[enableMultiplexKwd].(bool)
follow, _ := req.Option(enableFollowKwd).Bool() follow, _ := req.Options[enableFollowKwd].(bool)
// Start assembling node config // Start assembling node config
ncfg := &core.BuildCfg{ ncfg := &core.BuildCfg{
......
...@@ -256,7 +256,11 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error { ...@@ -256,7 +256,11 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
if cfg.Online { if cfg.Online {
do := setupDiscoveryOption(rcfg.Discovery) do := setupDiscoveryOption(rcfg.Discovery)
if err := n.startOnlineServices(ctx, cfg.Routing, hostOption, do, cfg.getOpt("pubsub"), cfg.getOpt("ipnsps"), cfg.getOpt("mplex"), cfg.getOpt("follow")); err != nil { pubsub := cfg.getOpt("pubsub")
ipnsps := cfg.getOpt("ipnsps")
mplex := cfg.getOpt("mplex")
follow := cfg.getOpt("follow")
if err := n.startOnlineServices(ctx, cfg.Routing, hostOption, do, pubsub, ipnsps, mplex, follow); err != nil {
return err return err
} }
} else { } else {
......
...@@ -43,7 +43,7 @@ Follows an IPNS name by periodically resolving in the backround. ...@@ -43,7 +43,7 @@ Follows an IPNS name by periodically resolving in the backround.
}, },
Options: []cmdkit.Option{ Options: []cmdkit.Option{
cmdkit.BoolOption("pin", "Recursively pin the resolved pointer"), cmdkit.BoolOption("pin", "Recursively pin the resolved pointer"),
cmdkit.StringOption("refresh-interval", "Follow refresh interval."), cmdkit.StringOption("refresh-interval", "Follow refresh interval; defaults to 1hr."),
}, },
Run: func(req cmds.Request, res cmds.Response) { Run: func(req cmds.Request, res cmds.Response) {
...@@ -66,10 +66,8 @@ Follows an IPNS name by periodically resolving in the backround. ...@@ -66,10 +66,8 @@ Follows an IPNS name by periodically resolving in the backround.
return return
} }
var refr time.Duration refr := nc.DefaultFollowInterval
if refrS == "" { if refrS != "" {
refr = nc.DefaultFollowInterval
} else {
refr, err = time.ParseDuration(refrS) refr, err = time.ParseDuration(refrS)
if err != nil { if err != nil {
res.SetError(err, cmdkit.ErrNormal) res.SetError(err, cmdkit.ErrNormal)
......
...@@ -29,8 +29,8 @@ var log = logging.Logger("namecache") ...@@ -29,8 +29,8 @@ var log = logging.Logger("namecache")
// NameCache represents a following cache of names // NameCache represents a following cache of names
type NameCache interface { type NameCache interface {
// Follow starts following name, pinning it if pinit is true // Follow starts following name, pinning it if dopin is true
Follow(name string, pinit bool, followInterval time.Duration) error Follow(name string, dopin bool, followInterval time.Duration) error
// Unofollow cancels a follow // Unofollow cancels a follow
Unfollow(name string) error Unfollow(name string) error
// ListFollows returns a list of followed names // ListFollows returns a list of followed names
...@@ -40,7 +40,7 @@ type NameCache interface { ...@@ -40,7 +40,7 @@ type NameCache interface {
type nameCache struct { type nameCache struct {
nsys namesys.NameSystem nsys namesys.NameSystem
pinning pin.Pinner pinning pin.Pinner
dag ipld.DAGService dag ipld.NodeGetter
bstore bstore.GCBlockstore bstore bstore.GCBlockstore
ctx context.Context ctx context.Context
...@@ -48,7 +48,7 @@ type nameCache struct { ...@@ -48,7 +48,7 @@ type nameCache struct {
mx sync.Mutex mx sync.Mutex
} }
func NewNameCache(ctx context.Context, nsys namesys.NameSystem, pinning pin.Pinner, dag ipld.DAGService, bstore bstore.GCBlockstore) NameCache { func NewNameCache(ctx context.Context, nsys namesys.NameSystem, pinning pin.Pinner, dag ipld.NodeGetter, bstore bstore.GCBlockstore) NameCache {
return &nameCache{ return &nameCache{
ctx: ctx, ctx: ctx,
nsys: nsys, nsys: nsys,
...@@ -60,8 +60,8 @@ func NewNameCache(ctx context.Context, nsys namesys.NameSystem, pinning pin.Pinn ...@@ -60,8 +60,8 @@ func NewNameCache(ctx context.Context, nsys namesys.NameSystem, pinning pin.Pinn
} }
// Follow spawns a goroutine that periodically resolves a name // Follow spawns a goroutine that periodically resolves a name
// and (when pinit is true) pins it in the background // and (when dopin is true) pins it in the background
func (nc *nameCache) Follow(name string, pinit bool, followInterval time.Duration) error { func (nc *nameCache) Follow(name string, dopin bool, followInterval time.Duration) error {
nc.mx.Lock() nc.mx.Lock()
defer nc.mx.Unlock() defer nc.mx.Unlock()
...@@ -74,7 +74,7 @@ func (nc *nameCache) Follow(name string, pinit bool, followInterval time.Duratio ...@@ -74,7 +74,7 @@ func (nc *nameCache) Follow(name string, pinit bool, followInterval time.Duratio
} }
ctx, cancel := context.WithCancel(nc.ctx) ctx, cancel := context.WithCancel(nc.ctx)
go nc.followName(ctx, name, pinit, followInterval) go nc.followName(ctx, name, dopin, followInterval)
nc.follows[name] = cancel nc.follows[name] = cancel
return nil return nil
...@@ -112,10 +112,10 @@ func (nc *nameCache) ListFollows() []string { ...@@ -112,10 +112,10 @@ func (nc *nameCache) ListFollows() []string {
return follows return follows
} }
func (nc *nameCache) followName(ctx context.Context, name string, pinit bool, followInterval time.Duration) { func (nc *nameCache) followName(ctx context.Context, name string, dopin bool, followInterval time.Duration) {
// if cid != nil, we have created a new pin that is updated on changes and // if cid != nil, we have created a new pin that is updated on changes and
// unpinned on cancel // unpinned on cancel
c, err := nc.resolveAndPin(ctx, name, pinit) c, err := nc.resolveAndPin(ctx, name, dopin)
if err != nil { if err != nil {
log.Errorf("Error following %s: %s", name, err.Error()) log.Errorf("Error following %s: %s", name, err.Error())
} }
...@@ -129,7 +129,7 @@ func (nc *nameCache) followName(ctx context.Context, name string, pinit bool, fo ...@@ -129,7 +129,7 @@ func (nc *nameCache) followName(ctx context.Context, name string, pinit bool, fo
if c != cid.Undef { if c != cid.Undef {
c, err = nc.resolveAndUpdate(ctx, name, c) c, err = nc.resolveAndUpdate(ctx, name, c)
} else { } else {
c, err = nc.resolveAndPin(ctx, name, pinit) c, err = nc.resolveAndPin(ctx, name, dopin)
} }
if err != nil { if err != nil {
...@@ -148,13 +148,13 @@ func (nc *nameCache) followName(ctx context.Context, name string, pinit bool, fo ...@@ -148,13 +148,13 @@ func (nc *nameCache) followName(ctx context.Context, name string, pinit bool, fo
} }
} }
func (nc *nameCache) resolveAndPin(ctx context.Context, name string, pinit bool) (cid.Cid, error) { func (nc *nameCache) resolveAndPin(ctx context.Context, name string, dopin bool) (cid.Cid, error) {
ptr, err := nc.resolve(ctx, name) ptr, err := nc.resolve(ctx, name)
if err != nil { if err != nil {
return cid.Undef, err return cid.Undef, err
} }
if !pinit { if !dopin {
return cid.Undef, nil return cid.Undef, nil
} }
...@@ -187,34 +187,34 @@ func (nc *nameCache) resolveAndPin(ctx context.Context, name string, pinit bool) ...@@ -187,34 +187,34 @@ func (nc *nameCache) resolveAndPin(ctx context.Context, name string, pinit bool)
return c, err return c, err
} }
func (nc *nameCache) resolveAndUpdate(ctx context.Context, name string, c cid.Cid) (cid.Cid, error) { func (nc *nameCache) resolveAndUpdate(ctx context.Context, name string, oldcid cid.Cid) (cid.Cid, error) {
ptr, err := nc.resolve(ctx, name) ptr, err := nc.resolve(ctx, name)
if err != nil { if err != nil {
return cid.Undef, err return cid.Undef, err
} }
ncid, err := pathToCid(ptr) newcid, err := pathToCid(ptr)
if err != nil { if err != nil {
return cid.Undef, err return cid.Undef, err
} }
if ncid.Equals(c) { if newcid.Equals(oldcid) {
return c, nil return oldcid, nil
} }
defer nc.bstore.PinLock().Unlock() defer nc.bstore.PinLock().Unlock()
log.Debugf("Updating pin %s -> %s", c.String(), ncid.String()) log.Debugf("Updating pin %s -> %s", oldcid.String(), newcid.String())
err = nc.pinning.Update(ctx, c, ncid, true) err = nc.pinning.Update(ctx, oldcid, newcid, true)
if err != nil { if err != nil {
return c, err return oldcid, err
} }
err = nc.pinning.Flush() err = nc.pinning.Flush()
return ncid, err return newcid, err
} }
func (nc *nameCache) unpin(cid cid.Cid) error { func (nc *nameCache) unpin(cid cid.Cid) error {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论