net: Add CNode::m_inbound_onion data member

This commit is contained in:
Hennadii Stepanov 2020-09-30 19:07:36 +03:00
parent 54fc96ffa7
commit d4dde24034
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
2 changed files with 19 additions and 4 deletions

View file

@ -41,6 +41,7 @@
static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed"); static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed");
#endif #endif
#include <algorithm>
#include <cstdint> #include <cstdint>
#include <unordered_map> #include <unordered_map>
@ -1118,7 +1119,9 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
if (NetPermissions::HasFlag(permissionFlags, PF_BLOOMFILTER)) { if (NetPermissions::HasFlag(permissionFlags, PF_BLOOMFILTER)) {
nodeServices = static_cast<ServiceFlags>(nodeServices | NODE_BLOOM); nodeServices = static_cast<ServiceFlags>(nodeServices | NODE_BLOOM);
} }
CNode* pnode = new CNode(id, nodeServices, GetBestHeight(), hSocket, addr, CalculateKeyedNetGroup(addr), nonce, addr_bind, "", ConnectionType::INBOUND);
const bool inbound_onion = std::find(m_onion_binds.begin(), m_onion_binds.end(), addr_bind) != m_onion_binds.end();
CNode* pnode = new CNode(id, nodeServices, GetBestHeight(), hSocket, addr, CalculateKeyedNetGroup(addr), nonce, addr_bind, "", ConnectionType::INBOUND, inbound_onion);
pnode->AddRef(); pnode->AddRef();
pnode->m_permissionFlags = permissionFlags; pnode->m_permissionFlags = permissionFlags;
// If this flag is present, the user probably expect that RPC and QT report it as whitelisted (backward compatibility) // 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
unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; } unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; }
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) 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)
: nTimeConnected(GetSystemTimeInSeconds()), : nTimeConnected(GetSystemTimeInSeconds()),
addr(addrIn), addr(addrIn),
addrBind(addrBindIn), addrBind(addrBindIn),
@ -2871,7 +2874,8 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
nLocalHostNonce(nLocalHostNonceIn), nLocalHostNonce(nLocalHostNonceIn),
m_conn_type(conn_type_in), m_conn_type(conn_type_in),
nLocalServices(nLocalServicesIn), nLocalServices(nLocalServicesIn),
nMyStartingHeight(nMyStartingHeightIn) nMyStartingHeight(nMyStartingHeightIn),
m_inbound_onion(inbound_onion)
{ {
hSocket = hSocketIn; hSocket = hSocketIn;
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn; addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;

View file

@ -253,6 +253,7 @@ public:
LOCK(cs_vAddedNodes); LOCK(cs_vAddedNodes);
vAddedNodes = connOptions.m_added_nodes; vAddedNodes = connOptions.m_added_nodes;
} }
m_onion_binds = connOptions.onion_binds;
} }
CConnman(uint64_t seed0, uint64_t seed1, bool network_active = true); CConnman(uint64_t seed0, uint64_t seed1, bool network_active = true);
@ -586,6 +587,12 @@ private:
std::atomic<int64_t> m_next_send_inv_to_incoming{0}; std::atomic<int64_t> m_next_send_inv_to_incoming{0};
/**
* A vector of -bind=<address>:<port>=onion arguments each of which is
* an address and port that are designated for incoming Tor connections.
*/
std::vector<CService> m_onion_binds;
friend struct CConnmanTest; friend struct CConnmanTest;
friend struct ConnmanTestMsg; friend struct ConnmanTestMsg;
}; };
@ -1035,7 +1042,7 @@ public:
std::set<uint256> orphan_work_set; std::set<uint256> orphan_work_set;
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); 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);
~CNode(); ~CNode();
CNode(const CNode&) = delete; CNode(const CNode&) = delete;
CNode& operator=(const CNode&) = delete; CNode& operator=(const CNode&) = delete;
@ -1073,6 +1080,10 @@ private:
// Our address, as reported by the peer // Our address, as reported by the peer
CService addrLocal GUARDED_BY(cs_addrLocal); CService addrLocal GUARDED_BY(cs_addrLocal);
mutable RecursiveMutex cs_addrLocal; mutable RecursiveMutex cs_addrLocal;
//! Whether this peer connected via our Tor onion service.
const bool m_inbound_onion{false};
public: public:
NodeId GetId() const { NodeId GetId() const {