MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / GetReachabilityFrom

Method GetReachabilityFrom

src/netbase.cpp:1013–1069  ·  view source on GitHub ↗

Calculates a metric for how reachable (*this) is from a given partner */

Source from the content-addressed store, hash-verified

1011
1012/** Calculates a metric for how reachable (*this) is from a given partner */
1013int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const
1014{
1015 enum Reachability {
1016 REACH_UNREACHABLE,
1017 REACH_DEFAULT,
1018 REACH_TEREDO,
1019 REACH_IPV6_WEAK,
1020 REACH_IPV4,
1021 REACH_IPV6_STRONG,
1022 REACH_PRIVATE
1023 };
1024
1025 if (!IsRoutable())
1026 return REACH_UNREACHABLE;
1027
1028 int ourNet = GetExtNetwork(this);
1029 int theirNet = GetExtNetwork(paddrPartner);
1030 bool fTunnel = IsRFC3964() || IsRFC6052() || IsRFC6145();
1031
1032 switch(theirNet) {
1033 case NET_IPV4:
1034 switch(ourNet) {
1035 default: return REACH_DEFAULT;
1036 case NET_IPV4: return REACH_IPV4;
1037 }
1038 case NET_IPV6:
1039 switch(ourNet) {
1040 default: return REACH_DEFAULT;
1041 case NET_TEREDO: return REACH_TEREDO;
1042 case NET_IPV4: return REACH_IPV4;
1043 case NET_IPV6: return fTunnel ? REACH_IPV6_WEAK : REACH_IPV6_STRONG; // only prefer giving our IPv6 address if it's not tunnelled
1044 }
1045 case NET_TOR:
1046 switch(ourNet) {
1047 default: return REACH_DEFAULT;
1048 case NET_IPV4: return REACH_IPV4; // Tor users can connect to IPv4 as well
1049 case NET_TOR: return REACH_PRIVATE;
1050 }
1051 case NET_TEREDO:
1052 switch(ourNet) {
1053 default: return REACH_DEFAULT;
1054 case NET_TEREDO: return REACH_TEREDO;
1055 case NET_IPV6: return REACH_IPV6_WEAK;
1056 case NET_IPV4: return REACH_IPV4;
1057 }
1058 case NET_UNKNOWN:
1059 case NET_UNROUTABLE:
1060 default:
1061 switch(ourNet) {
1062 default: return REACH_DEFAULT;
1063 case NET_TEREDO: return REACH_TEREDO;
1064 case NET_IPV6: return REACH_IPV6_WEAK;
1065 case NET_IPV4: return REACH_IPV4;
1066 case NET_TOR: return REACH_PRIVATE; // either from Tor, or don't care about our address
1067 }
1068 }
1069}
1070

Callers 1

GetLocalFunction · 0.80

Calls 1

GetExtNetworkFunction · 0.85

Tested by

no test coverage detected