Skip to content

Commit

Permalink
feat(cmds): hide peers info default in bitswap stat
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Overbool <overbool.xu@gmail.com>
  • Loading branch information
overbool committed Dec 5, 2018
1 parent 18fb10b commit eff877f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/commands/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,18 @@ Print out all blocks currently on the bitswap wantlist for the local peer.`,
},
}

const (
bitswapVerboseOptionName = "verbose"
)

var bitswapStatCmd = &cmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "Show some diagnostic information on the bitswap agent.",
ShortDescription: ``,
},
Options: []cmdkit.Option{
cmdkit.BoolOption(bitswapVerboseOptionName, "v", "print extra information"),
},
Type: bitswap.Stat{},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
nd, err := cmdenv.GetNode(env)
Expand All @@ -115,6 +122,8 @@ var bitswapStatCmd = &cmds.Command{
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, s *bitswap.Stat) error {
verbose, _ := req.Options[bitswapVerboseOptionName].(bool)

fmt.Fprintln(w, "bitswap status")
fmt.Fprintf(w, "\tprovides buffer: %d / %d\n", s.ProvideBufLen, bitswap.HasBlockBufferSize)
fmt.Fprintf(w, "\tblocks received: %d\n", s.BlocksReceived)
Expand All @@ -127,9 +136,12 @@ var bitswapStatCmd = &cmds.Command{
for _, k := range s.Wantlist {
fmt.Fprintf(w, "\t\t%s\n", k.String())
}

fmt.Fprintf(w, "\tpartners [%d]\n", len(s.Peers))
for _, p := range s.Peers {
fmt.Fprintf(w, "\t\t%s\n", p)
if verbose {
for _, p := range s.Peers {
fmt.Fprintf(w, "\t\t%s\n", p)
}
}

return nil
Expand Down

0 comments on commit eff877f

Please sign in to comment.