rpc/net_info: change RemoteIP type from net.IP to String (#3309)

* rpc/net_info: change RemoteIP type from net.IP to String

Before:
"AAAAAAAAAAAAAP//rB8ktw=="
which is amino-encoded net.IP byte slice

After:
"192.0.2.1"

Fixes #3251

* rpc/net_info: non-empty response in docs
This commit is contained in:
Anton Kaliaev
2019-02-16 09:46:02 +04:00
committed by GitHub
parent af3ba5145a
commit 7ced9e416b
3 changed files with 131 additions and 18 deletions

View File

@@ -24,6 +24,8 @@ Special thanks to external contributors on this release:
* [consensus] \#3297 Flush WAL on stop to prevent data corruption during * [consensus] \#3297 Flush WAL on stop to prevent data corruption during
graceful shutdown graceful shutdown
- [rpc] \#3251 Fix /net_info#peers#remote_ip format. New format spec:
* dotted decimal ("192.0.2.1"), if ip is an IPv4 or IP4-mapped IPv6 address
* IPv6 ("2001:db8::1"), if ip is a valid IPv6 address
* [cmd] \#3314 Return an * [cmd] \#3314 Return an
error on `show_validator` when the private validator file does not exist. error on `show_validator` when the private validator file does not exist

View File

@@ -29,21 +29,133 @@ import (
// //
// ```json // ```json
// { // {
// "error": "", // "jsonrpc": "2.0",
// "result": { // "id": "",
// "n_peers": "0", // "result": {
// "peers": [], // "listening": true,
// "listeners": [ // "listeners": [
// "Listener(@10.0.2.15:26656)" // "Listener(@)"
// ], // ],
// "listening": true // "n_peers": "3",
// }, // "peers": [
// "id": "", // {
// "jsonrpc": "2.0" // "node_info": {
// } // "protocol_version": {
// "p2p": "7",
// "block": "8",
// "app": "1"
// },
// "id": "93529da3435c090d02251a050342b6a488d4ab56",
// "listen_addr": "tcp://0.0.0.0:26656",
// "network": "chain-RFo6qC",
// "version": "0.30.0",
// "channels": "4020212223303800",
// "moniker": "fc89e4ed23f2",
// "other": {
// "tx_index": "on",
// "rpc_address": "tcp://0.0.0.0:26657"
// }
// },
// "is_outbound": true,
// "connection_status": {
// "Duration": "3475230558",
// "SendMonitor": {
// "Active": true,
// "Start": "2019-02-14T12:40:47.52Z",
// "Duration": "3480000000",
// "Idle": "240000000",
// "Bytes": "4512",
// "Samples": "9",
// "InstRate": "1338",
// "CurRate": "2046",
// "AvgRate": "1297",
// "PeakRate": "6570",
// "BytesRem": "0",
// "TimeRem": "0",
// "Progress": 0
// },
// "RecvMonitor": {
// "Active": true,
// "Start": "2019-02-14T12:40:47.52Z",
// "Duration": "3480000000",
// "Idle": "280000000",
// "Bytes": "4489",
// "Samples": "10",
// "InstRate": "1821",
// "CurRate": "1663",
// "AvgRate": "1290",
// "PeakRate": "5512",
// "BytesRem": "0",
// "TimeRem": "0",
// "Progress": 0
// },
// "Channels": [
// {
// "ID": 48,
// "SendQueueCapacity": "1",
// "SendQueueSize": "0",
// "Priority": "5",
// "RecentlySent": "0"
// },
// {
// "ID": 64,
// "SendQueueCapacity": "1000",
// "SendQueueSize": "0",
// "Priority": "10",
// "RecentlySent": "14"
// },
// {
// "ID": 32,
// "SendQueueCapacity": "100",
// "SendQueueSize": "0",
// "Priority": "5",
// "RecentlySent": "619"
// },
// {
// "ID": 33,
// "SendQueueCapacity": "100",
// "SendQueueSize": "0",
// "Priority": "10",
// "RecentlySent": "1363"
// },
// {
// "ID": 34,
// "SendQueueCapacity": "100",
// "SendQueueSize": "0",
// "Priority": "5",
// "RecentlySent": "2145"
// },
// {
// "ID": 35,
// "SendQueueCapacity": "2",
// "SendQueueSize": "0",
// "Priority": "1",
// "RecentlySent": "0"
// },
// {
// "ID": 56,
// "SendQueueCapacity": "1",
// "SendQueueSize": "0",
// "Priority": "5",
// "RecentlySent": "0"
// },
// {
// "ID": 0,
// "SendQueueCapacity": "10",
// "SendQueueSize": "0",
// "Priority": "1",
// "RecentlySent": "10"
// }
// ]
// },
// "remote_ip": "192.167.10.3"
// },
// ...
// }
// ``` // ```
func NetInfo() (*ctypes.ResultNetInfo, error) { func NetInfo() (*ctypes.ResultNetInfo, error) {
peers := []ctypes.Peer{} out, in, _ := p2pPeers.NumPeers()
peers := make([]ctypes.Peer, 0, out+in)
for _, peer := range p2pPeers.Peers().List() { for _, peer := range p2pPeers.Peers().List() {
nodeInfo, ok := peer.NodeInfo().(p2p.DefaultNodeInfo) nodeInfo, ok := peer.NodeInfo().(p2p.DefaultNodeInfo)
if !ok { if !ok {
@@ -53,7 +165,7 @@ func NetInfo() (*ctypes.ResultNetInfo, error) {
NodeInfo: nodeInfo, NodeInfo: nodeInfo,
IsOutbound: peer.IsOutbound(), IsOutbound: peer.IsOutbound(),
ConnectionStatus: peer.Status(), ConnectionStatus: peer.Status(),
RemoteIP: peer.RemoteIP(), RemoteIP: peer.RemoteIP().String(),
}) })
} }
// TODO: Should we include PersistentPeers and Seeds in here? // TODO: Should we include PersistentPeers and Seeds in here?

View File

@@ -2,7 +2,6 @@ package core_types
import ( import (
"encoding/json" "encoding/json"
"net"
"time" "time"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
@@ -111,7 +110,7 @@ type Peer struct {
NodeInfo p2p.DefaultNodeInfo `json:"node_info"` NodeInfo p2p.DefaultNodeInfo `json:"node_info"`
IsOutbound bool `json:"is_outbound"` IsOutbound bool `json:"is_outbound"`
ConnectionStatus p2p.ConnectionStatus `json:"connection_status"` ConnectionStatus p2p.ConnectionStatus `json:"connection_status"`
RemoteIP net.IP `json:"remote_ip"` RemoteIP string `json:"remote_ip"`
} }
// Validators for a height // Validators for a height