Skip to content

Commit 49fba9c

Browse files
committed
net: Add CNode::ConnectedThroughNetwork member function
1 parent d4dde24 commit 49fba9c

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/net.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,11 @@ void CNode::SetAddrLocal(const CService& addrLocalIn) {
539539
}
540540
}
541541

542+
Network CNode::ConnectedThroughNetwork() const
543+
{
544+
return IsInboundConn() && m_inbound_onion ? NET_ONION : addr.GetNetClass();
545+
}
546+
542547
#undef X
543548
#define X(name) stats.name = name
544549
void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)

src/net.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,18 @@ class CNode
961961
assert(false);
962962
}
963963

964+
/**
965+
* Get network the peer connected through.
966+
*
967+
* Returns Network::NET_ONION for *inbound* onion connections,
968+
* and CNetAddr::GetNetClass() otherwise. The latter cannot be used directly
969+
* because it doesn't detect the former, and it's not the responsibility of
970+
* the CNetAddr class to know the actual network a peer is connected through.
971+
*
972+
* @return network the peer connected through.
973+
*/
974+
Network ConnectedThroughNetwork() const;
975+
964976
protected:
965977
mapMsgCmdSize mapSendBytesPerMsgCmd;
966978
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);

src/netaddress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ uint32_t CNetAddr::GetLinkedIPv4() const
629629
assert(false);
630630
}
631631

632-
uint32_t CNetAddr::GetNetClass() const
632+
Network CNetAddr::GetNetClass() const
633633
{
634634
// Make sure that if we return NET_IPV6, then IsIPv6() is true. The callers expect that.
635635

src/netaddress.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class CNetAddr
182182
std::string ToStringIP() const;
183183
uint64_t GetHash() const;
184184
bool GetInAddr(struct in_addr* pipv4Addr) const;
185-
uint32_t GetNetClass() const;
185+
Network GetNetClass() const;
186186

187187
//! For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv4 address as a uint32.
188188
uint32_t GetLinkedIPv4() const;

0 commit comments

Comments
 (0)