Add agent flag to net peers

This commit is contained in:
Łukasz Magiera 2020-09-04 01:35:53 +02:00
parent 021f4a881c
commit ce8bcf7932
5 changed files with 97 additions and 18 deletions

View File

@ -30,6 +30,7 @@ type Common interface {
NetFindPeer(context.Context, peer.ID) (peer.AddrInfo, error) NetFindPeer(context.Context, peer.ID) (peer.AddrInfo, error)
NetPubsubScores(context.Context) ([]PubsubScore, error) NetPubsubScores(context.Context) ([]PubsubScore, error)
NetAutoNatStatus(context.Context) (NatInfo, error) NetAutoNatStatus(context.Context) (NatInfo, error)
NetAgentVersion(ctx context.Context, p peer.ID) (string, error)
// NetBandwidthStats returns statistics about the nodes total bandwidth // NetBandwidthStats returns statistics about the nodes total bandwidth
// usage and current rate across all peers and protocols. // usage and current rate across all peers and protocols.

View File

@ -55,6 +55,7 @@ type CommonStruct struct {
NetBandwidthStats func(ctx context.Context) (metrics.Stats, error) `perm:"read"` NetBandwidthStats func(ctx context.Context) (metrics.Stats, error) `perm:"read"`
NetBandwidthStatsByPeer func(ctx context.Context) (map[string]metrics.Stats, error) `perm:"read"` NetBandwidthStatsByPeer func(ctx context.Context) (map[string]metrics.Stats, error) `perm:"read"`
NetBandwidthStatsByProtocol func(ctx context.Context) (map[protocol.ID]metrics.Stats, error) `perm:"read"` NetBandwidthStatsByProtocol func(ctx context.Context) (map[protocol.ID]metrics.Stats, error) `perm:"read"`
NetAgentVersion func(ctx context.Context, p peer.ID) (string, error) `perm:"read"`
ID func(context.Context) (peer.ID, error) `perm:"read"` ID func(context.Context) (peer.ID, error) `perm:"read"`
Version func(context.Context) (api.Version, error) `perm:"read"` Version func(context.Context) (api.Version, error) `perm:"read"`
@ -389,6 +390,10 @@ func (c *CommonStruct) NetBandwidthStatsByProtocol(ctx context.Context) (map[pro
return c.Internal.NetBandwidthStatsByProtocol(ctx) return c.Internal.NetBandwidthStatsByProtocol(ctx)
} }
func (c *CommonStruct) NetAgentVersion(ctx context.Context, p peer.ID) (string, error) {
return c.Internal.NetAgentVersion(ctx, p)
}
// ID implements API.ID // ID implements API.ID
func (c *CommonStruct) ID(ctx context.Context) (peer.ID, error) { func (c *CommonStruct) ID(ctx context.Context) (peer.ID, error) {
return c.Internal.ID(ctx) return c.Internal.ID(ctx)

View File

@ -35,6 +35,13 @@ var netCmd = &cli.Command{
var NetPeers = &cli.Command{ var NetPeers = &cli.Command{
Name: "peers", Name: "peers",
Usage: "Print peers", Usage: "Print peers",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "agent",
Aliases: []string{"a"},
Usage: "Print agent name",
},
},
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := GetAPI(cctx) api, closer, err := GetAPI(cctx)
if err != nil { if err != nil {
@ -52,7 +59,17 @@ var NetPeers = &cli.Command{
}) })
for _, peer := range peers { for _, peer := range peers {
fmt.Printf("%s, %s\n", peer.ID, peer.Addrs) var agent string
if cctx.Bool("agent") {
agent, err = api.NetAgentVersion(ctx, peer.ID)
if err != nil {
log.Warnf("getting agent version: %s", err)
} else {
agent = ", " + agent
}
}
fmt.Printf("%s, %s%s\n", peer.ID, peer.Addrs, agent)
} }
return nil return nil

View File

@ -84,6 +84,7 @@
* [MsigSwapPropose](#MsigSwapPropose) * [MsigSwapPropose](#MsigSwapPropose)
* [Net](#Net) * [Net](#Net)
* [NetAddrsListen](#NetAddrsListen) * [NetAddrsListen](#NetAddrsListen)
* [NetAgentVersion](#NetAgentVersion)
* [NetAutoNatStatus](#NetAutoNatStatus) * [NetAutoNatStatus](#NetAutoNatStatus)
* [NetBandwidthStats](#NetBandwidthStats) * [NetBandwidthStats](#NetBandwidthStats)
* [NetBandwidthStatsByPeer](#NetBandwidthStatsByPeer) * [NetBandwidthStatsByPeer](#NetBandwidthStatsByPeer)
@ -96,6 +97,7 @@
* [NetPubsubScores](#NetPubsubScores) * [NetPubsubScores](#NetPubsubScores)
* [Paych](#Paych) * [Paych](#Paych)
* [PaychAllocateLane](#PaychAllocateLane) * [PaychAllocateLane](#PaychAllocateLane)
* [PaychAvailableFunds](#PaychAvailableFunds)
* [PaychCollect](#PaychCollect) * [PaychCollect](#PaychCollect)
* [PaychGet](#PaychGet) * [PaychGet](#PaychGet)
* [PaychGetWaitReady](#PaychGetWaitReady) * [PaychGetWaitReady](#PaychGetWaitReady)
@ -2047,6 +2049,20 @@ Response:
} }
``` ```
### NetAgentVersion
Perms: read
Inputs:
```json
[
"12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf"
]
```
Response: `"string value"`
### NetAutoNatStatus ### NetAutoNatStatus
@ -2218,6 +2234,30 @@ Inputs:
Response: `42` Response: `42`
### PaychAvailableFunds
There are not yet any comments for this method.
Perms: sign
Inputs:
```json
[
"t01234"
]
```
Response:
```json
{
"Channel": "\u003cempty\u003e",
"ConfirmedAmt": "0",
"PendingAmt": "0",
"PendingWaitSentinel": null,
"QueuedAmt": "0",
"VoucherReedeemedAmt": "0"
}
```
### PaychCollect ### PaychCollect
There are not yet any comments for this method. There are not yet any comments for this method.
@ -2473,24 +2513,27 @@ Inputs:
Response: Response:
```json ```json
{ {
"ChannelAddr": "t01234", "Voucher": {
"TimeLockMin": 10101, "ChannelAddr": "t01234",
"TimeLockMax": 10101, "TimeLockMin": 10101,
"SecretPreimage": "Ynl0ZSBhcnJheQ==", "TimeLockMax": 10101,
"Extra": { "SecretPreimage": "Ynl0ZSBhcnJheQ==",
"Actor": "t01234", "Extra": {
"Method": 1, "Actor": "t01234",
"Data": "Ynl0ZSBhcnJheQ==" "Method": 1,
"Data": "Ynl0ZSBhcnJheQ=="
},
"Lane": 42,
"Nonce": 42,
"Amount": "0",
"MinSettleHeight": 10101,
"Merges": null,
"Signature": {
"Type": 2,
"Data": "Ynl0ZSBhcnJheQ=="
}
}, },
"Lane": 42, "Shortfall": "0"
"Nonce": 42,
"Amount": "0",
"MinSettleHeight": 10101,
"Merges": null,
"Signature": {
"Type": 2,
"Data": "Ynl0ZSBhcnJheQ=="
}
} }
``` ```

View File

@ -136,6 +136,19 @@ func (a *CommonAPI) NetAutoNatStatus(ctx context.Context) (i api.NatInfo, err er
}, nil }, nil
} }
func (a *CommonAPI) NetAgentVersion(ctx context.Context, p peer.ID) (string, error) {
ag, err := a.Host.Peerstore().Get(p, "AgentVersion")
if err != nil {
return "", err
}
if ag == nil {
return "unknown", nil
}
return ag.(string), nil
}
func (a *CommonAPI) NetBandwidthStats(ctx context.Context) (metrics.Stats, error) { func (a *CommonAPI) NetBandwidthStats(ctx context.Context) (metrics.Stats, error) {
return a.Reporter.GetBandwidthTotals(), nil return a.Reporter.GetBandwidthTotals(), nil
} }