From 5388f3e6f8164bdc0acd5f229e52057627f10f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 8 Mar 2021 23:49:53 +0100 Subject: [PATCH 1/3] Add connmgr metadata to NetPeerInfo --- api/types.go | 17 +++++++++++++---- node/impl/common/common.go | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/api/types.go b/api/types.go index 45be570c5..a463dd36e 100644 --- a/api/types.go +++ b/api/types.go @@ -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" @@ -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 } diff --git a/node/impl/common/common.go b/node/impl/common/common.go index 5e02117b7..0a7e01eca 100644 --- a/node/impl/common/common.go +++ b/node/impl/common/common.go @@ -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" @@ -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" @@ -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 } From 9f2015e85030c6def23ba595546f6787bf846804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 9 Mar 2021 00:03:10 +0100 Subject: [PATCH 2/3] docsgen --- api/docgen/docgen.go | 2 ++ documentation/en/api-methods-miner.md | 12 +++++++++++- documentation/en/api-methods.md | 12 +++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index 7d3ac4bcf..8aca1d754 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -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)}) addExample(&types.ExecutionTrace{ Msg: exampleValue("init", reflect.TypeOf(&types.Message{}), nil).(*types.Message), MsgRct: exampleValue("init", reflect.TypeOf(&types.MessageReceipt{}), nil).(*types.MessageReceipt), diff --git a/documentation/en/api-methods-miner.md b/documentation/en/api-methods-miner.md index 247270af2..01a05b418 100644 --- a/documentation/en/api-methods-miner.md +++ b/documentation/en/api-methods-miner.md @@ -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-08T23:52:18+01:00" + } + } } ``` diff --git a/documentation/en/api-methods.md b/documentation/en/api-methods.md index 75b78b15c..c6a481f2b 100644 --- a/documentation/en/api-methods.md +++ b/documentation/en/api-methods.md @@ -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-08T23:52:18+01:00" + } + } } ``` From 4231e4396dbb877917b71335efcaf3d957472550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 9 Mar 2021 00:24:03 +0100 Subject: [PATCH 3/3] docsgen funtimes --- api/docgen/docgen.go | 2 +- documentation/en/api-methods-miner.md | 2 +- documentation/en/api-methods.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index 8aca1d754..487f65706 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -124,7 +124,7 @@ func init() { addExample(network.ReachabilityPublic) addExample(build.NewestNetworkVersion) addExample(map[string]int{"name": 42}) - addExample(map[string]time.Time{"name": time.Unix(1615243938, 0)}) + 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), diff --git a/documentation/en/api-methods-miner.md b/documentation/en/api-methods-miner.md index 01a05b418..1582b115c 100644 --- a/documentation/en/api-methods-miner.md +++ b/documentation/en/api-methods-miner.md @@ -1072,7 +1072,7 @@ Response: "name": 42 }, "Conns": { - "name": "2021-03-08T23:52:18+01:00" + "name": "2021-03-08T22:52:18Z" } } } diff --git a/documentation/en/api-methods.md b/documentation/en/api-methods.md index c6a481f2b..49afeeb1a 100644 --- a/documentation/en/api-methods.md +++ b/documentation/en/api-methods.md @@ -2914,7 +2914,7 @@ Response: "name": 42 }, "Conns": { - "name": "2021-03-08T23:52:18+01:00" + "name": "2021-03-08T22:52:18Z" } } }