Skip to content

Commit c34ad33

Browse files
net, rpc: Enable AddrFetch connections for functional testing
Co-authored-by: Amiti Uttarwar <[email protected]>
1 parent 533500d commit c34ad33

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/net.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,16 +1166,29 @@ void CConnman::CreateNodeFromAcceptedSocket(SOCKET hSocket,
11661166

11671167
bool CConnman::AddConnection(const std::string& address, ConnectionType conn_type)
11681168
{
1169-
if (conn_type != ConnectionType::OUTBOUND_FULL_RELAY && conn_type != ConnectionType::BLOCK_RELAY) return false;
1170-
1171-
const int max_connections = conn_type == ConnectionType::OUTBOUND_FULL_RELAY ? m_max_outbound_full_relay : m_max_outbound_block_relay;
1169+
std::optional<int> max_connections;
1170+
switch (conn_type) {
1171+
case ConnectionType::INBOUND:
1172+
case ConnectionType::MANUAL:
1173+
case ConnectionType::FEELER:
1174+
return false;
1175+
case ConnectionType::OUTBOUND_FULL_RELAY:
1176+
max_connections = m_max_outbound_full_relay;
1177+
break;
1178+
case ConnectionType::BLOCK_RELAY:
1179+
max_connections = m_max_outbound_block_relay;
1180+
break;
1181+
// no limit for ADDR_FETCH because -seednode has no limit either
1182+
case ConnectionType::ADDR_FETCH:
1183+
break;
1184+
} // no default case, so the compiler can warn about missing cases
11721185

11731186
// Count existing connections
11741187
int existing_connections = WITH_LOCK(cs_vNodes,
11751188
return std::count_if(vNodes.begin(), vNodes.end(), [conn_type](CNode* node) { return node->m_conn_type == conn_type; }););
11761189

11771190
// Max connections of specified type already exist
1178-
if (existing_connections >= max_connections) return false;
1191+
if (max_connections != std::nullopt && existing_connections >= max_connections) return false;
11791192

11801193
// Max total outbound connections already exist
11811194
CSemaphoreGrant grant(*semOutbound, true);

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ class CConnman
890890
*
891891
* @param[in] address Address of node to try connecting to
892892
* @param[in] conn_type ConnectionType::OUTBOUND or ConnectionType::BLOCK_RELAY
893+
* or ConnectionType::ADDR_FETCH
893894
* @return bool Returns false if there are no available
894895
* slots for this connection:
895896
* - conn_type not a supported ConnectionType

src/rpc/net.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static RPCHelpMan addconnection()
337337
"\nOpen an outbound connection to a specified node. This RPC is for testing only.\n",
338338
{
339339
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address and port to attempt connecting to."},
340-
{"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of connection to open, either \"outbound-full-relay\" or \"block-relay-only\"."},
340+
{"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of connection to open (\"outbound-full-relay\", \"block-relay-only\" or \"addr-fetch\")."},
341341
},
342342
RPCResult{
343343
RPCResult::Type::OBJ, "", "",
@@ -363,6 +363,8 @@ static RPCHelpMan addconnection()
363363
conn_type = ConnectionType::OUTBOUND_FULL_RELAY;
364364
} else if (conn_type_in == "block-relay-only") {
365365
conn_type = ConnectionType::BLOCK_RELAY;
366+
} else if (conn_type_in == "addr-fetch") {
367+
conn_type = ConnectionType::ADDR_FETCH;
366368
} else {
367369
throw JSONRPCError(RPC_INVALID_PARAMETER, self.ToString());
368370
}

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,8 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs):
557557
return p2p_conn
558558

559559
def add_outbound_p2p_connection(self, p2p_conn, *, p2p_idx, connection_type="outbound-full-relay", **kwargs):
560-
"""Add an outbound p2p connection from node. Either
561-
full-relay("outbound-full-relay") or
562-
block-relay-only("block-relay-only") connection.
560+
"""Add an outbound p2p connection from node. Must be an
561+
"outbound-full-relay", "block-relay-only" or "addr-fetch" connection.
563562
564563
This method adds the p2p connection to the self.p2ps list and returns
565564
the connection to the caller.

0 commit comments

Comments
 (0)