aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmiti Uttarwar <amiti@uttarwar.org>2020-08-12 13:57:13 -0700
committerAmiti Uttarwar <amiti@uttarwar.org>2020-09-21 19:01:29 -0700
commit395acfa83a5436790c1a722a5609ac9d48df235f (patch)
tree523f1a77f69da9ff7e44f4bc602bbaf2dc14aa2b
parent49c10a9ca40967d28ae16dfea9cccc6f3a6624a1 (diff)
downloadbitcoin-395acfa83a5436790c1a722a5609ac9d48df235f.tar.xz
[rpc] Add connection type to getpeerinfo RPC, update tests
-rw-r--r--src/net.cpp2
-rw-r--r--src/net.h9
-rw-r--r--src/rpc/net.cpp2
-rwxr-xr-xtest/functional/rpc_net.py6
4 files changed, 19 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
diff --git a/src/net.h b/src/net.h
index 61a208802c..5e134ca7c8 100644
--- a/src/net.h
+++ b/src/net.h
@@ -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);
}
diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py
index bc0e5b458e..b8a04f494d 100755
--- a/test/functional/rpc_net.py
+++ b/test/functional/rpc_net.py
@@ -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))