Skip to content

Commit d4dde24

Browse files
committed
net: Add CNode::m_inbound_onion data member
1 parent 54fc96f commit d4dde24

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/net.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed");
4242
#endif
4343

44+
#include <algorithm>
4445
#include <cstdint>
4546
#include <unordered_map>
4647

@@ -1118,7 +1119,9 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
11181119
if (NetPermissions::HasFlag(permissionFlags, PF_BLOOMFILTER)) {
11191120
nodeServices = static_cast<ServiceFlags>(nodeServices | NODE_BLOOM);
11201121
}
1121-
CNode* pnode = new CNode(id, nodeServices, GetBestHeight(), hSocket, addr, CalculateKeyedNetGroup(addr), nonce, addr_bind, "", ConnectionType::INBOUND);
1122+
1123+
const bool inbound_onion = std::find(m_onion_binds.begin(), m_onion_binds.end(), addr_bind) != m_onion_binds.end();
1124+
CNode* pnode = new CNode(id, nodeServices, GetBestHeight(), hSocket, addr, CalculateKeyedNetGroup(addr), nonce, addr_bind, "", ConnectionType::INBOUND, inbound_onion);
11221125
pnode->AddRef();
11231126
pnode->m_permissionFlags = permissionFlags;
11241127
// If this flag is present, the user probably expect that RPC and QT report it as whitelisted (backward compatibility)
@@ -2859,7 +2862,7 @@ int CConnman::GetBestHeight() const
28592862

28602863
unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; }
28612864

2862-
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in)
2865+
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion)
28632866
: nTimeConnected(GetSystemTimeInSeconds()),
28642867
addr(addrIn),
28652868
addrBind(addrBindIn),
@@ -2871,7 +2874,8 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
28712874
nLocalHostNonce(nLocalHostNonceIn),
28722875
m_conn_type(conn_type_in),
28732876
nLocalServices(nLocalServicesIn),
2874-
nMyStartingHeight(nMyStartingHeightIn)
2877+
nMyStartingHeight(nMyStartingHeightIn),
2878+
m_inbound_onion(inbound_onion)
28752879
{
28762880
hSocket = hSocketIn;
28772881
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;

src/net.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class CConnman
253253
LOCK(cs_vAddedNodes);
254254
vAddedNodes = connOptions.m_added_nodes;
255255
}
256+
m_onion_binds = connOptions.onion_binds;
256257
}
257258

258259
CConnman(uint64_t seed0, uint64_t seed1, bool network_active = true);
@@ -586,6 +587,12 @@ class CConnman
586587

587588
std::atomic<int64_t> m_next_send_inv_to_incoming{0};
588589

590+
/**
591+
* A vector of -bind=<address>:<port>=onion arguments each of which is
592+
* an address and port that are designated for incoming Tor connections.
593+
*/
594+
std::vector<CService> m_onion_binds;
595+
589596
friend struct CConnmanTest;
590597
friend struct ConnmanTestMsg;
591598
};
@@ -1035,7 +1042,7 @@ class CNode
10351042

10361043
std::set<uint256> orphan_work_set;
10371044

1038-
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn, ConnectionType conn_type_in);
1045+
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn, ConnectionType conn_type_in, bool inbound_onion = false);
10391046
~CNode();
10401047
CNode(const CNode&) = delete;
10411048
CNode& operator=(const CNode&) = delete;
@@ -1073,6 +1080,10 @@ class CNode
10731080
// Our address, as reported by the peer
10741081
CService addrLocal GUARDED_BY(cs_addrLocal);
10751082
mutable RecursiveMutex cs_addrLocal;
1083+
1084+
//! Whether this peer connected via our Tor onion service.
1085+
const bool m_inbound_onion{false};
1086+
10761087
public:
10771088

10781089
NodeId GetId() const {

0 commit comments

Comments
 (0)