mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-22 06:26:43 +02:00
[rpc] Add connection type to getpeerinfo RPC, update tests
This commit is contained in:
parent
49c10a9ca4
commit
395acfa83a
@ -602,6 +602,8 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
|
||||
// Leave string empty if addrLocal invalid (not filled in yet)
|
||||
CService addrLocalUnlocked = GetAddrLocal();
|
||||
stats.addrLocal = addrLocalUnlocked.IsValid() ? addrLocalUnlocked.ToString() : "";
|
||||
|
||||
stats.m_conn_type_string = ConnectionTypeAsString();
|
||||
}
|
||||
#undef X
|
||||
|
||||
|
@ -114,6 +114,14 @@ struct CSerializedNetMsg
|
||||
std::string m_type;
|
||||
};
|
||||
|
||||
const std::vector<std::string> CONNECTION_TYPE_DOC{
|
||||
"outbound-full-relay (default automatic connections)",
|
||||
"block-relay-only (does not relay transactions or addresses)",
|
||||
"inbound (initiated by the peer)",
|
||||
"manual (added via addnode RPC or -addnode/-connect configuration options)",
|
||||
"addr-fetch (short-lived automatic connection for soliciting addresses)",
|
||||
"feeler (short-lived automatic connection for testing addresses)"};
|
||||
|
||||
/** Different types of connections to a peer. This enum encapsulates the
|
||||
* information we have available at the time of opening or accepting the
|
||||
* connection. Aside from INBOUND, all types are initiated by us. */
|
||||
@ -692,6 +700,7 @@ public:
|
||||
// Bind address of our side of the connection
|
||||
CAddress addrBind;
|
||||
uint32_t m_mapped_as;
|
||||
std::string m_conn_type_string;
|
||||
};
|
||||
|
||||
|
||||
|
@ -113,6 +113,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
|
||||
{RPCResult::Type::STR, "subver", "The string version"},
|
||||
{RPCResult::Type::BOOL, "inbound", "Inbound (true) or Outbound (false)"},
|
||||
{RPCResult::Type::BOOL, "addnode", "Whether connection was due to addnode/-connect or if it was an automatic/inbound connection"},
|
||||
{RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + "."},
|
||||
{RPCResult::Type::NUM, "startingheight", "The starting height (block) of the peer"},
|
||||
{RPCResult::Type::NUM, "banscore", "The ban score (DEPRECATED, returned only if config option -deprecatedrpc=banscore is passed)"},
|
||||
{RPCResult::Type::NUM, "synced_headers", "The last header we have in common with this peer"},
|
||||
@ -228,6 +229,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
|
||||
recvPerMsgCmd.pushKV(i.first, i.second);
|
||||
}
|
||||
obj.pushKV("bytesrecv_per_msg", recvPerMsgCmd);
|
||||
obj.pushKV("connection_type", stats.m_conn_type_string);
|
||||
|
||||
ret.push_back(obj);
|
||||
}
|
||||
|
@ -175,6 +175,12 @@ class NetTest(BitcoinTestFramework):
|
||||
for info in peer_info:
|
||||
assert_net_servicesnames(int(info[0]["services"], 0x10), info[0]["servicesnames"])
|
||||
|
||||
assert_equal(peer_info[0][0]['connection_type'], 'inbound')
|
||||
assert_equal(peer_info[0][1]['connection_type'], 'manual')
|
||||
|
||||
assert_equal(peer_info[1][0]['connection_type'], 'manual')
|
||||
assert_equal(peer_info[1][1]['connection_type'], 'inbound')
|
||||
|
||||
def test_service_flags(self):
|
||||
self.log.info("Test service flags")
|
||||
self.nodes[0].add_p2p_connection(P2PInterface(), services=(1 << 4) | (1 << 63))
|
||||
|
Loading…
x
Reference in New Issue
Block a user