diff --git a/src/init.cpp b/src/init.cpp index 078c63c4..bce3bc15 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -201,7 +201,7 @@ std::string HelpMessage() strUsage += " -connect= " + _("Connect only to the specified node(s)") + "\n"; strUsage += " -seednode= " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n"; strUsage += " -externalip= " + _("Specify your own public address") + "\n"; - strUsage += " -onlynet= " + _("Only connect to nodes in network (IPv4, IPv6 or Tor)") + "\n"; + strUsage += " -onlynet= " + _("Only connect to nodes in network (IPv4, IPv6, Tor, Ygg or Yggdrasil)") + "\n"; strUsage += " -multiconnperip " + _("Enable libtorrent multiple connections per ip (default: 0)") + "\n"; strUsage += " -discover " + _("Discover own IP address (default: 1 when listening and no -externalip)") + "\n"; strUsage += " -checkpoints " + _("Only accept block chain matching built-in checkpoints (default: 1)") + "\n"; diff --git a/src/netbase.cpp b/src/netbase.cpp index 7f63b27d..be8052f6 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -38,6 +38,7 @@ enum Network ParseNetwork(std::string net) { if (net == "ipv4") return NET_IPV4; if (net == "ipv6") return NET_IPV6; if (net == "tor") return NET_TOR; + if (net == "ygg" || net == "yggdrasil") return NET_YGGDRASIL; return NET_UNROUTABLE; } @@ -687,6 +688,12 @@ bool CNetAddr::IsTor() const return (memcmp(ip, pchOnionCat, sizeof(pchOnionCat)) == 0); } +// https://yggdrasil-network.github.io/2018/07/28/addressing.html#addressing-in-yggdrasil +bool CNetAddr::IsYggdrasil() const +{ + return IsIPv6() && (ip[0] & 0xFE) == 0x02; // @TODO wants revision +} + bool CNetAddr::IsLocal() const { // IPv4 loopback @@ -759,6 +766,9 @@ enum Network CNetAddr::GetNetwork() const if (IsTor()) return NET_TOR; + if (IsYggdrasil()) + return NET_YGGDRASIL; + return NET_IPV6; } @@ -873,6 +883,11 @@ std::vector CNetAddr::GetGroup() const nStartByte = 6; nBits = 4; } + // for yggdrasil, use /7 groups + else if (IsYggdrasil()) + { + nClass = NET_YGGDRASIL; + } // for he.net, use /36 groups else if (GetByte(15) == 0x20 && GetByte(14) == 0x11 && GetByte(13) == 0x04 && GetByte(12) == 0x70) nBits = 36; @@ -973,6 +988,11 @@ int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const case NET_IPV4: return REACH_IPV4; // Tor users can connect to IPv4 as well case NET_TOR: return REACH_PRIVATE; } + case NET_YGGDRASIL: // by NET_CJDNS https://github.com/bitcoin/bitcoin/blob/master/src/netaddress.cpp#L760 + switch(ourNet) { + case NET_YGGDRASIL: return REACH_PRIVATE; + default: return REACH_DEFAULT; + } case NET_TEREDO: switch(ourNet) { default: return REACH_DEFAULT; @@ -1112,7 +1132,7 @@ bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const return true; } #ifdef USE_IPV6 - if (IsIPv6()) { + if (IsIPv6() || IsYggdrasil()) { if (*addrlen < (socklen_t)sizeof(struct sockaddr_in6)) return false; *addrlen = sizeof(struct sockaddr_in6); diff --git a/src/netbase.h b/src/netbase.h index 5fcdaf86..9d3afc96 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -23,6 +23,7 @@ enum Network NET_IPV4, NET_IPV6, NET_TOR, + NET_YGGDRASIL, NET_MAX, }; @@ -56,6 +57,7 @@ class CNetAddr bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64) bool IsRFC6052() const; // IPv6 well-known prefix (64:FF9B::/96) bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) + bool IsYggdrasil() const; // IPv6 Yggdrasil (0200::/7) bool IsTor() const; bool IsLocal() const; bool IsRoutable() const; diff --git a/src/test/netbase_tests.cpp b/src/test/netbase_tests.cpp index e5a7562d..6300719c 100644 --- a/src/test/netbase_tests.cpp +++ b/src/test/netbase_tests.cpp @@ -16,6 +16,8 @@ BOOST_AUTO_TEST_CASE(netbase_networks) BOOST_CHECK(CNetAddr("8.8.8.8").GetNetwork() == NET_IPV4); BOOST_CHECK(CNetAddr("2001::8888").GetNetwork() == NET_IPV6); BOOST_CHECK(CNetAddr("FD87:D87E:EB43:edb1:8e4:3588:e546:35ca").GetNetwork() == NET_TOR); + BOOST_CHECK(CNetAddr("300:17a8:aabf:108f::33").GetNetwork() == NET_YGGDRASIL); + BOOST_CHECK(CNetAddr("200:17a8:aabf:108f:5581:3d0d:c2a:4f06").GetNetwork() == NET_YGGDRASIL); } BOOST_AUTO_TEST_CASE(netbase_properties) @@ -35,6 +37,8 @@ BOOST_AUTO_TEST_CASE(netbase_properties) BOOST_CHECK(CNetAddr("FE80::").IsRFC4862()); BOOST_CHECK(CNetAddr("64:FF9B::").IsRFC6052()); BOOST_CHECK(CNetAddr("FD87:D87E:EB43:edb1:8e4:3588:e546:35ca").IsTor()); + BOOST_CHECK(CNetAddr("300:17a8:aabf:108f::33").IsYggdrasil()); + BOOST_CHECK(CNetAddr("200:17a8:aabf:108f:5581:3d0d:c2a:4f06").IsYggdrasil()); BOOST_CHECK(CNetAddr("127.0.0.1").IsLocal()); BOOST_CHECK(CNetAddr("::1").IsLocal()); BOOST_CHECK(CNetAddr("8.8.8.8").IsRoutable());