Add 'providing' back to the ipfs add command

上级 31099e88
......@@ -144,6 +144,11 @@ You can now check what blocks have been created by:
return err
}
node, err := cmdenv.GetNode(env)
if err != nil {
return err
}
progress, _ := req.Options[progressOptionName].(bool)
trickle, _ := req.Options[trickleOptionName].(bool)
wrap, _ := req.Options[wrapOptionName].(bool)
......@@ -209,7 +214,8 @@ You can now check what blocks have been created by:
var err error
defer func() { errCh <- err }()
defer close(events)
_, err = api.Unixfs().Add(req.Context, req.Files, opts...)
resolvePath, err := api.Unixfs().Add(req.Context, req.Files, opts...)
_ = node.Reprovider.Provide(resolvePath.Cid())
}()
err = res.Emit(events)
......
......@@ -84,27 +84,39 @@ func (rp *Reprovider) Reprovide() error {
return fmt.Errorf("failed to get key chan: %s", err)
}
for c := range keychan {
// hash security
if err := verifcid.ValidateCid(c); err != nil {
log.Errorf("insecure hash in reprovider, %s (%s)", c, err)
continue
}
op := func() error {
err := rp.rsys.Provide(rp.ctx, c, true)
if err != nil {
log.Debugf("Failed to provide key: %s", err)
}
if err := rp.Provide(c); err != nil {
return err
}
}
return nil
}
func (rp *Reprovider) Provide(c cid.Cid) error {
// hash security
if err := verifcid.ValidateCid(c); err != nil {
log.Errorf("insecure hash in reprovider, %s (%s)", c, err)
// TODO: maybe returning nil here isn't great as it idiomatically
// indicates there was no error, even though overall it has
// the same effect
return nil
}
// TODO: this backoff library does not respect our context, we should
// eventually work contexts into it. low priority.
err := backoff.Retry(op, backoff.NewExponentialBackOff())
op := func() error {
err := rp.rsys.Provide(rp.ctx, c, true)
if err != nil {
log.Debugf("Providing failed after number of retries: %s", err)
return err
log.Debugf("Failed to provide key: %s", err)
}
return err
}
// TODO: this backoff library does not respect our context, we should
// eventually work contexts into it. low priority.
err := backoff.Retry(op, backoff.NewExponentialBackOff())
if err != nil {
log.Debugf("Providing failed after number of retries: %s", err)
return err
}
return nil
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论