MCPcopy Create free account
hub / github.com/LUX-Core/lux / GetReachabilityFrom

Method GetReachabilityFrom

src/netbase.cpp:982–1056  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

980
981/** Calculates a metric for how reachable (*this) is from a given partner */
982int CNetAddr::GetReachabilityFrom(const CNetAddr* paddrPartner) const
983{
984 enum Reachability {
985 REACH_UNREACHABLE,
986 REACH_DEFAULT,
987 REACH_TEREDO,
988 REACH_IPV6_WEAK,
989 REACH_IPV4,
990 REACH_IPV6_STRONG,
991 REACH_PRIVATE
992 };
993
994 if (!IsRoutable())
995 return REACH_UNREACHABLE;
996
997 int ourNet = GetExtNetwork(this);
998 int theirNet = GetExtNetwork(paddrPartner);
999 bool fTunnel = IsRFC3964() || IsRFC6052() || IsRFC6145();
1000
1001 switch (theirNet) {
1002 case NET_IPV4:
1003 switch (ourNet) {
1004 default:
1005 return REACH_DEFAULT;
1006 case NET_IPV4:
1007 return REACH_IPV4;
1008 }
1009 case NET_IPV6:
1010 switch (ourNet) {
1011 default:
1012 return REACH_DEFAULT;
1013 case NET_TEREDO:
1014 return REACH_TEREDO;
1015 case NET_IPV4:
1016 return REACH_IPV4;
1017 case NET_IPV6:
1018 return fTunnel ? REACH_IPV6_WEAK : REACH_IPV6_STRONG; // only prefer giving our IPv6 address if it's not tunnelled
1019 }
1020 case NET_TOR:
1021 switch (ourNet) {
1022 default:
1023 return REACH_DEFAULT;
1024 case NET_IPV4:
1025 return REACH_IPV4; // Tor users can connect to IPv4 as well
1026 case NET_TOR:
1027 return REACH_PRIVATE;
1028 }
1029 case NET_TEREDO:
1030 switch (ourNet) {
1031 default:
1032 return REACH_DEFAULT;
1033 case NET_TEREDO:
1034 return REACH_TEREDO;
1035 case NET_IPV6:
1036 return REACH_IPV6_WEAK;
1037 case NET_IPV4:
1038 return REACH_IPV4;
1039 }

Callers 1

GetLocalFunction · 0.80

Calls 1

GetExtNetworkFunction · 0.85

Tested by

no test coverage detected