Add ipfs provider tracking

License: MIT
Signed-off-by: 's avatarMichael Avila <davidmichaelavila@gmail.com>
上级 3008266e
package commands
import (
"fmt"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-ipfs-cmdkit"
"github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
"io"
)
var ProviderCmd = &cmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "Interact with the provider subsystem",
ShortDescription: "",
},
Subcommands: map[string]*cmds.Command{
"tracking": trackingProviderCmd,
},
}
var trackingProviderCmd = &cmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "List the cids being tracked by the provider system.",
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
node, err := cmdenv.GetNode(env)
if err != nil {
return nil
}
cids, err := node.Provider.Tracking()
if err != nil {
res.CloseWithError(err)
return err
}
for c := range cids {
res.Emit(c)
}
res.Close()
return nil
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, c cid.Cid) error {
fmt.Fprintf(w, "%s\n", c.String())
return nil
}),
},
Type: cid.Cid{},
}
\ No newline at end of file
......@@ -56,6 +56,7 @@ ADVANCED COMMANDS
repo Manipulate the IPFS repository
stats Various operational stats
p2p Libp2p stream mounting
provider Interact withh the provider system
filestore Manage the filestore (experimental)
NETWORK COMMANDS
......@@ -140,6 +141,7 @@ var rootSubcommands = map[string]*cmds.Command{
"pin": PinCmd,
"ping": PingCmd,
"p2p": P2PCmd,
"provider": ProviderCmd,
"refs": RefsCmd,
"resolve": ResolveCmd,
"swarm": SwarmCmd,
......
......@@ -22,6 +22,8 @@ type Provider interface {
Provide(cid.Cid)
// Close stops the provider
Close() error
// Tracking returns the cids being tracked by the provider system
Tracking() (<-chan cid.Cid, error)
}
type provider struct {
......@@ -60,6 +62,10 @@ func (p *provider) Provide(root cid.Cid) {
p.queue.Enqueue(root)
}
func (p *provider) Tracking() (<-chan cid.Cid, error) {
return p.tracker.Tracking(p.ctx)
}
// Handle all outgoing cids by providing (announcing) them
func (p *provider) handleAnnouncements() {
for workers := 0; workers < provideOutgoingWorkerLimit; workers++ {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论