提交 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
ipnsps, _ := req.Options[enableIPNSPubSubKwd].(bool)
pubsub, _ := req.Options[enablePubSubKwd].(bool)
mplex, _ := req.Options[enableMultiplexKwd].(bool)
follow, _ := req.Option(enableFollowKwd).Bool()
follow, _ := req.Options[enableFollowKwd].(bool)
// Start assembling node config
ncfg := &core.BuildCfg{
......
......@@ -256,7 +256,11 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
if cfg.Online {
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
}
} else {
......
......@@ -43,7 +43,7 @@ Follows an IPNS name by periodically resolving in the backround.
},
Options: []cmdkit.Option{
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) {
......@@ -66,10 +66,8 @@ Follows an IPNS name by periodically resolving in the backround.
return
}
var refr time.Duration
if refrS == "" {
refr = nc.DefaultFollowInterval
} else {
refr := nc.DefaultFollowInterval
if refrS != "" {
refr, err = time.ParseDuration(refrS)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
......
......@@ -29,8 +29,8 @@ var log = logging.Logger("namecache")
// NameCache represents a following cache of names
type NameCache interface {
// Follow starts following name, pinning it if pinit is true
Follow(name string, pinit bool, followInterval time.Duration) error
// Follow starts following name, pinning it if dopin is true
Follow(name string, dopin bool, followInterval time.Duration) error
// Unofollow cancels a follow
Unfollow(name string) error
// ListFollows returns a list of followed names
......@@ -40,7 +40,7 @@ type NameCache interface {
type nameCache struct {
nsys namesys.NameSystem
pinning pin.Pinner
dag ipld.DAGService
dag ipld.NodeGetter
bstore bstore.GCBlockstore
ctx context.Context
......@@ -48,7 +48,7 @@ type nameCache struct {
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{
ctx: ctx,
nsys: nsys,
......@@ -60,8 +60,8 @@ func NewNameCache(ctx context.Context, nsys namesys.NameSystem, pinning pin.Pinn
}
// Follow spawns a goroutine that periodically resolves a name
// and (when pinit is true) pins it in the background
func (nc *nameCache) Follow(name string, pinit bool, followInterval time.Duration) error {
// and (when dopin is true) pins it in the background
func (nc *nameCache) Follow(name string, dopin bool, followInterval time.Duration) error {
nc.mx.Lock()
defer nc.mx.Unlock()
......@@ -74,7 +74,7 @@ func (nc *nameCache) Follow(name string, pinit bool, followInterval time.Duratio
}
ctx, cancel := context.WithCancel(nc.ctx)
go nc.followName(ctx, name, pinit, followInterval)
go nc.followName(ctx, name, dopin, followInterval)
nc.follows[name] = cancel
return nil
......@@ -112,10 +112,10 @@ func (nc *nameCache) ListFollows() []string {
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
// unpinned on cancel
c, err := nc.resolveAndPin(ctx, name, pinit)
c, err := nc.resolveAndPin(ctx, name, dopin)
if err != nil {
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
if c != cid.Undef {
c, err = nc.resolveAndUpdate(ctx, name, c)
} else {
c, err = nc.resolveAndPin(ctx, name, pinit)
c, err = nc.resolveAndPin(ctx, name, dopin)
}
if err != nil {
......@@ -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)
if err != nil {
return cid.Undef, err
}
if !pinit {
if !dopin {
return cid.Undef, nil
}
......@@ -187,34 +187,34 @@ func (nc *nameCache) resolveAndPin(ctx context.Context, name string, pinit bool)
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)
if err != nil {
return cid.Undef, err
}
ncid, err := pathToCid(ptr)
newcid, err := pathToCid(ptr)
if err != nil {
return cid.Undef, err
}
if ncid.Equals(c) {
return c, nil
if newcid.Equals(oldcid) {
return oldcid, nil
}
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 {
return c, err
return oldcid, err
}
err = nc.pinning.Flush()
return ncid, err
return newcid, err
}
func (nc *nameCache) unpin(cid cid.Cid) error {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论