aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/net.cpp5
-rw-r--r--src/net.h12
-rw-r--r--src/netaddress.cpp2
-rw-r--r--src/netaddress.h2
4 files changed, 19 insertions, 2 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 9f8c827741..54d572c68c 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -539,6 +539,11 @@ void CNode::SetAddrLocal(const CService& addrLocalIn) {
}
}
+Network CNode::ConnectedThroughNetwork() const
+{
+ return IsInboundConn() && m_inbound_onion ? NET_ONION : addr.GetNetClass();
+}
+
#undef X
#define X(name) stats.name = name
void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
diff --git a/src/net.h b/src/net.h
index e702c13db3..a8b13124c3 100644
--- a/src/net.h
+++ b/src/net.h
@@ -961,6 +961,18 @@ public:
assert(false);
}
+ /**
+ * Get network the peer connected through.
+ *
+ * Returns Network::NET_ONION for *inbound* onion connections,
+ * and CNetAddr::GetNetClass() otherwise. The latter cannot be used directly
+ * because it doesn't detect the former, and it's not the responsibility of
+ * the CNetAddr class to know the actual network a peer is connected through.
+ *
+ * @return network the peer connected through.
+ */
+ Network ConnectedThroughNetwork() const;
+
protected:
mapMsgCmdSize mapSendBytesPerMsgCmd;
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
diff --git a/src/netaddress.cpp b/src/netaddress.cpp
index 0c4c0a339b..d460d0139f 100644
--- a/src/netaddress.cpp
+++ b/src/netaddress.cpp
@@ -629,7 +629,7 @@ uint32_t CNetAddr::GetLinkedIPv4() const
assert(false);
}
-uint32_t CNetAddr::GetNetClass() const
+Network CNetAddr::GetNetClass() const
{
// Make sure that if we return NET_IPV6, then IsIPv6() is true. The callers expect that.
diff --git a/src/netaddress.h b/src/netaddress.h
index 78e7e1b4b3..fe99f41c6a 100644
--- a/src/netaddress.h
+++ b/src/netaddress.h
@@ -182,7 +182,7 @@ class CNetAddr
std::string ToStringIP() const;
uint64_t GetHash() const;
bool GetInAddr(struct in_addr* pipv4Addr) const;
- uint32_t GetNetClass() const;
+ Network GetNetClass() const;
//! For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv4 address as a uint32.
uint32_t GetLinkedIPv4() const;