diff --git a/doc/release-notes.md b/doc/release-notes.md
--- a/doc/release-notes.md
+++ b/doc/release-notes.md
@@ -5,3 +5,7 @@
This release includes the following features and fixes:
+
+- The `getpeerinfo` RPC now returns a `connection_type` field. This indicates
+ the type of connection established with the peer. It will return one of six
+ options. For more information, see the `getpeerinfo` help documentation.
diff --git a/src/net.h b/src/net.h
--- a/src/net.h
+++ b/src/net.h
@@ -138,6 +138,14 @@
std::string m_type;
};
+const std::vector 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
@@ -747,6 +755,7 @@
// 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/net.cpp b/src/net.cpp
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -631,6 +631,8 @@
CService addrLocalUnlocked = GetAddrLocal();
stats.addrLocal =
addrLocalUnlocked.IsValid() ? addrLocalUnlocked.ToString() : "";
+
+ stats.m_conn_type_string = ConnectionTypeAsString();
}
bool CNode::ReceiveMsgBytes(const Config &config, const char *pch,
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -152,6 +152,9 @@
{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",
@@ -298,6 +301,7 @@
}
}
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
--- a/test/functional/rpc_net.py
+++ b/test/functional/rpc_net.py
@@ -215,6 +215,12 @@
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(