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

Method GetReachabilityFrom

src/netaddress.cpp:406–462  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

404
405/** Calculates a metric for how reachable (*this) is from a given partner */
406int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const
407{
408 enum Reachability {
409 REACH_UNREACHABLE,
410 REACH_DEFAULT,
411 REACH_TEREDO,
412 REACH_IPV6_WEAK,
413 REACH_IPV4,
414 REACH_IPV6_STRONG,
415 REACH_PRIVATE
416 };
417
418 if (!IsRoutable() || IsInternal())
419 return REACH_UNREACHABLE;
420
421 int ourNet = GetExtNetwork(this);
422 int theirNet = GetExtNetwork(paddrPartner);
423 bool fTunnel = IsRFC3964() || IsRFC6052() || IsRFC6145();
424
425 switch(theirNet) {
426 case NET_IPV4:
427 switch(ourNet) {
428 default: return REACH_DEFAULT;
429 case NET_IPV4: return REACH_IPV4;
430 }
431 case NET_IPV6:
432 switch(ourNet) {
433 default: return REACH_DEFAULT;
434 case NET_TEREDO: return REACH_TEREDO;
435 case NET_IPV4: return REACH_IPV4;
436 case NET_IPV6: return fTunnel ? REACH_IPV6_WEAK : REACH_IPV6_STRONG; // only prefer giving our IPv6 address if it's not tunnelled
437 }
438 case NET_ONION:
439 switch(ourNet) {
440 default: return REACH_DEFAULT;
441 case NET_IPV4: return REACH_IPV4; // Tor users can connect to IPv4 as well
442 case NET_ONION: return REACH_PRIVATE;
443 }
444 case NET_TEREDO:
445 switch(ourNet) {
446 default: return REACH_DEFAULT;
447 case NET_TEREDO: return REACH_TEREDO;
448 case NET_IPV6: return REACH_IPV6_WEAK;
449 case NET_IPV4: return REACH_IPV4;
450 }
451 case NET_UNKNOWN:
452 case NET_UNROUTABLE:
453 default:
454 switch(ourNet) {
455 default: return REACH_DEFAULT;
456 case NET_TEREDO: return REACH_TEREDO;
457 case NET_IPV6: return REACH_IPV6_WEAK;
458 case NET_IPV4: return REACH_IPV4;
459 case NET_ONION: return REACH_PRIVATE; // either from Tor, or don't care about our address
460 }
461 }
462}
463

Callers 1

GetLocalFunction · 0.80

Calls 1

GetExtNetworkFunction · 0.85

Tested by

no test coverage detected