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 connmgr metadata to NetPeerInfo #5749

Merged
merged 3 commits into from
Mar 9, 2021
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
2 changes: 2 additions & 0 deletions api/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ func init() {
addExample(retrievalmarket.DealStatusNew)
addExample(network.ReachabilityPublic)
addExample(build.NewestNetworkVersion)
addExample(map[string]int{"name": 42})
addExample(map[string]time.Time{"name": time.Unix(1615243938, 0).UTC()})
addExample(&types.ExecutionTrace{
Msg: exampleValue("init", reflect.TypeOf(&types.Message{}), nil).(*types.Message),
MsgRct: exampleValue("init", reflect.TypeOf(&types.MessageReceipt{}), nil).(*types.MessageReceipt),
Expand Down
17 changes: 13 additions & 4 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"encoding/json"
"fmt"
"time"

datatransfer "github.com/filecoin-project/go-data-transfer"
"github.com/filecoin-project/go-state-types/abi"
Expand Down Expand Up @@ -101,8 +102,16 @@ type NetBlockList struct {
}

type ExtendedPeerInfo struct {
ID peer.ID
Agent string
Addrs []string
Protocols []string
ID peer.ID
Agent string
Addrs []string
Protocols []string
ConnMgrMeta *ConnMgrInfo
}

type ConnMgrInfo struct {
FirstSeen time.Time
Value int
Tags map[string]int
Conns map[string]time.Time
}
12 changes: 11 additions & 1 deletion documentation/en/api-methods-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,17 @@ Response:
"ID": "12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf",
"Agent": "string value",
"Addrs": null,
"Protocols": null
"Protocols": null,
"ConnMgrMeta": {
"FirstSeen": "0001-01-01T00:00:00Z",
"Value": 123,
"Tags": {
"name": 42
},
"Conns": {
"name": "2021-03-08T22:52:18Z"
}
}
}
```

Expand Down
12 changes: 11 additions & 1 deletion documentation/en/api-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -2906,7 +2906,17 @@ Response:
"ID": "12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf",
"Agent": "string value",
"Addrs": null,
"Protocols": null
"Protocols": null,
"ConnMgrMeta": {
"FirstSeen": "0001-01-01T00:00:00Z",
"Value": 123,
"Tags": {
"name": 42
},
"Conns": {
"name": "2021-03-08T22:52:18Z"
}
}
}
```

Expand Down
16 changes: 14 additions & 2 deletions node/impl/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (

"github.com/gbrlsnchs/jwt/v3"
"github.com/google/uuid"
"go.uber.org/fx"
"golang.org/x/xerrors"

logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p-core/host"
metrics "github.com/libp2p/go-libp2p-core/metrics"
Expand All @@ -17,8 +20,6 @@ import (
basichost "github.com/libp2p/go-libp2p/p2p/host/basic"
"github.com/libp2p/go-libp2p/p2p/net/conngater"
ma "github.com/multiformats/go-multiaddr"
"go.uber.org/fx"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-jsonrpc/auth"

Expand Down Expand Up @@ -110,12 +111,23 @@ func (a *CommonAPI) NetPeerInfo(_ context.Context, p peer.ID) (*api.ExtendedPeer
for _, a := range a.Host.Peerstore().Addrs(p) {
info.Addrs = append(info.Addrs, a.String())
}
sort.Strings(info.Addrs)

protocols, err := a.Host.Peerstore().GetProtocols(p)
if err == nil {
sort.Strings(protocols)
info.Protocols = protocols
}

if cm := a.Host.ConnManager().GetTagInfo(p); cm != nil {
info.ConnMgrMeta = &api.ConnMgrInfo{
FirstSeen: cm.FirstSeen,
Value: cm.Value,
Tags: cm.Tags,
Conns: cm.Conns,
}
}

return info, nil
}

Expand Down