diff options
author | Amiti Uttarwar <amiti@uttarwar.org> | 2020-08-12 13:57:13 -0700 |
---|---|---|
committer | Amiti Uttarwar <amiti@uttarwar.org> | 2020-09-21 19:01:29 -0700 |
commit | 395acfa83a5436790c1a722a5609ac9d48df235f (patch) | |
tree | 523f1a77f69da9ff7e44f4bc602bbaf2dc14aa2b /src | |
parent | 49c10a9ca40967d28ae16dfea9cccc6f3a6624a1 (diff) | |
download | bitcoin-395acfa83a5436790c1a722a5609ac9d48df235f.tar.xz |
[rpc] Add connection type to getpeerinfo RPC, update tests
Diffstat (limited to 'src')
-rw-r--r-- | src/net.cpp | 2 | ||||
-rw-r--r-- | src/net.h | 9 | ||||
-rw-r--r-- | src/rpc/net.cpp | 2 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp index 15675a68ad..5b533d7d17 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -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; }; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 5af4389857..e480bd2a40 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -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); } |