Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add agent flag to net peers #3534

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/api_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Common interface {
NetFindPeer(context.Context, peer.ID) (peer.AddrInfo, error)
NetPubsubScores(context.Context) ([]PubsubScore, error)
NetAutoNatStatus(context.Context) (NatInfo, error)
NetAgentVersion(ctx context.Context, p peer.ID) (string, error)

// NetBandwidthStats returns statistics about the nodes total bandwidth
// usage and current rate across all peers and protocols.
Expand Down
5 changes: 5 additions & 0 deletions api/apistruct/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type CommonStruct struct {
NetBandwidthStats func(ctx context.Context) (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"`
NetAgentVersion func(ctx context.Context, p peer.ID) (string, error) `perm:"read"`

ID func(context.Context) (peer.ID, error) `perm:"read"`
Version func(context.Context) (api.Version, error) `perm:"read"`
Expand Down Expand Up @@ -389,6 +390,10 @@ func (c *CommonStruct) NetBandwidthStatsByProtocol(ctx context.Context) (map[pro
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
func (c *CommonStruct) ID(ctx context.Context) (peer.ID, error) {
return c.Internal.ID(ctx)
Expand Down
19 changes: 18 additions & 1 deletion cli/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ var netCmd = &cli.Command{
var NetPeers = &cli.Command{
Name: "peers",
Usage: "Print peers",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "agent",
Aliases: []string{"a"},
Usage: "Print agent name",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetAPI(cctx)
if err != nil {
Expand All @@ -52,7 +59,17 @@ var NetPeers = &cli.Command{
})

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
Expand Down
77 changes: 60 additions & 17 deletions documentation/en/api-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
* [MsigSwapPropose](#MsigSwapPropose)
* [Net](#Net)
* [NetAddrsListen](#NetAddrsListen)
* [NetAgentVersion](#NetAgentVersion)
* [NetAutoNatStatus](#NetAutoNatStatus)
* [NetBandwidthStats](#NetBandwidthStats)
* [NetBandwidthStatsByPeer](#NetBandwidthStatsByPeer)
Expand All @@ -96,6 +97,7 @@
* [NetPubsubScores](#NetPubsubScores)
* [Paych](#Paych)
* [PaychAllocateLane](#PaychAllocateLane)
* [PaychAvailableFunds](#PaychAvailableFunds)
* [PaychCollect](#PaychCollect)
* [PaychGet](#PaychGet)
* [PaychGetWaitReady](#PaychGetWaitReady)
Expand Down Expand Up @@ -2047,6 +2049,20 @@ Response:
}
```

### NetAgentVersion


Perms: read

Inputs:
```json
[
"12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf"
]
```

Response: `"string value"`

### NetAutoNatStatus


Expand Down Expand Up @@ -2218,6 +2234,30 @@ Inputs:

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
There are not yet any comments for this method.

Expand Down Expand Up @@ -2473,24 +2513,27 @@ Inputs:
Response:
```json
{
"ChannelAddr": "t01234",
"TimeLockMin": 10101,
"TimeLockMax": 10101,
"SecretPreimage": "Ynl0ZSBhcnJheQ==",
"Extra": {
"Actor": "t01234",
"Method": 1,
"Data": "Ynl0ZSBhcnJheQ=="
"Voucher": {
"ChannelAddr": "t01234",
"TimeLockMin": 10101,
"TimeLockMax": 10101,
"SecretPreimage": "Ynl0ZSBhcnJheQ==",
"Extra": {
"Actor": "t01234",
"Method": 1,
"Data": "Ynl0ZSBhcnJheQ=="
},
"Lane": 42,
"Nonce": 42,
"Amount": "0",
"MinSettleHeight": 10101,
"Merges": null,
"Signature": {
"Type": 2,
"Data": "Ynl0ZSBhcnJheQ=="
}
},
"Lane": 42,
"Nonce": 42,
"Amount": "0",
"MinSettleHeight": 10101,
"Merges": null,
"Signature": {
"Type": 2,
"Data": "Ynl0ZSBhcnJheQ=="
}
"Shortfall": "0"
}
```

Expand Down
13 changes: 13 additions & 0 deletions node/impl/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ func (a *CommonAPI) NetAutoNatStatus(ctx context.Context) (i api.NatInfo, err er
}, 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) {
return a.Reporter.GetBandwidthTotals(), nil
}
Expand Down