Skip to content

Commit

Permalink
cmd/get-peer-list: allow filtering out lists
Browse files Browse the repository at this point in the history
Signed-off-by: Ciro S. Costa <[email protected]>
  • Loading branch information
cirocosta committed Aug 2, 2021
1 parent c23662a commit 42f30dc
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions cmd/monero/commands/daemon/get_peer_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (

type getPeerListCommand struct {
JSON bool

White bool
Gray bool
}

func (c *getPeerListCommand) Cmd() *cobra.Command {
Expand All @@ -27,6 +30,11 @@ func (c *getPeerListCommand) Cmd() *cobra.Command {
cmd.Flags().BoolVar(&c.JSON, "json",
false, "whether or not to output the result as json")

cmd.Flags().BoolVar(&c.White, "white",
true, "whether or not to show the white list")
cmd.Flags().BoolVar(&c.Gray, "gray",
false, "whether or not show gray list")

return cmd
}

Expand All @@ -39,6 +47,10 @@ func (c *getPeerListCommand) RunE(_ *cobra.Command, _ []string) error {
return fmt.Errorf("client: %w", err)
}

if !c.White && !c.Gray {
return fmt.Errorf("either white or gray (or both) must be set")
}

resp, err := client.GetPeerList(ctx)
if err != nil {
return fmt.Errorf("get block count: %w", err)
Expand All @@ -58,15 +70,27 @@ func (c *getPeerListCommand) pretty(v *daemon.GetPeerListResult) {

table.AddRow("TYPE", "HOST", "PORT ", "RPC", "SINCE")

for _, peer := range v.GrayList {
table.AddRow("GRAY", peer.Host, peer.Port, peer.RPCPort, "")
}

sort.Slice(v.WhiteList, func(i, j int) bool {
return v.WhiteList[i].LastSeen < v.WhiteList[j].LastSeen
})
for _, peer := range v.WhiteList {
table.AddRow("WHITE", peer.Host, peer.Port, peer.RPCPort, humanize.Time(time.Unix(peer.LastSeen, 0)))

if c.Gray {
for _, peer := range v.GrayList {
table.AddRow("gray",
peer.Host, peer.Port,
peer.RPCPort, "")
}
}

if c.White {
for _, peer := range v.WhiteList {
table.AddRow("white",
peer.Host, peer.Port,
peer.RPCPort,
humanize.Time(time.Unix(peer.LastSeen, 0)),
)
}

}

fmt.Println(table)
Expand Down

0 comments on commit 42f30dc

Please sign in to comment.