Browse Source

Remove I2P support from netbase

I2P apparently needs 256 bits to store a fully routable address. Garlicat
requires a centralized lookup service to map the 80-bit addresses to fully
routable ones (as far as I understood), so that's not really usable in our
situation.

To support I2P routing and peer exchange for it, another solution is needed.
This will most likely imply a network protocol change, and extension of the
'addr' message.
0.8
Pieter Wuille 12 years ago
parent
commit
4e882b7960
  1. 41
      src/netbase.cpp
  2. 6
      src/netbase.h

41
src/netbase.cpp

@ -29,7 +29,6 @@ enum Network ParseNetwork(std::string net) {
if (net == "ipv4") return NET_IPV4; if (net == "ipv4") return NET_IPV4;
if (net == "ipv6") return NET_IPV6; if (net == "ipv6") return NET_IPV6;
if (net == "tor") return NET_TOR; if (net == "tor") return NET_TOR;
if (net == "i2p") return NET_I2P;
return NET_UNROUTABLE; return NET_UNROUTABLE;
} }
@ -540,7 +539,6 @@ void CNetAddr::SetIP(const CNetAddr& ipIn)
} }
static const unsigned char pchOnionCat[] = {0xFD,0x87,0xD8,0x7E,0xEB,0x43}; static const unsigned char pchOnionCat[] = {0xFD,0x87,0xD8,0x7E,0xEB,0x43};
static const unsigned char pchGarliCat[] = {0xFD,0x60,0xDB,0x4D,0xDD,0xB5};
bool CNetAddr::SetSpecial(const std::string &strName) bool CNetAddr::SetSpecial(const std::string &strName)
{ {
@ -553,15 +551,6 @@ bool CNetAddr::SetSpecial(const std::string &strName)
ip[i + sizeof(pchOnionCat)] = vchAddr[i]; ip[i + sizeof(pchOnionCat)] = vchAddr[i];
return true; return true;
} }
if (strName.size()>11 && strName.substr(strName.size() - 11, 11) == ".oc.b32.i2p") {
std::vector<unsigned char> vchAddr = DecodeBase32(strName.substr(0, strName.size() - 11).c_str());
if (vchAddr.size() != 16-sizeof(pchGarliCat))
return false;
memcpy(ip, pchOnionCat, sizeof(pchGarliCat));
for (unsigned int i=0; i<16-sizeof(pchGarliCat); i++)
ip[i + sizeof(pchGarliCat)] = vchAddr[i];
return true;
}
return false; return false;
} }
@ -611,7 +600,7 @@ bool CNetAddr::IsIPv4() const
bool CNetAddr::IsIPv6() const bool CNetAddr::IsIPv6() const
{ {
return (!IsIPv4() && !IsTor() && !IsI2P()); return (!IsIPv4() && !IsTor());
} }
bool CNetAddr::IsRFC1918() const bool CNetAddr::IsRFC1918() const
@ -675,11 +664,6 @@ bool CNetAddr::IsTor() const
return (memcmp(ip, pchOnionCat, sizeof(pchOnionCat)) == 0); return (memcmp(ip, pchOnionCat, sizeof(pchOnionCat)) == 0);
} }
bool CNetAddr::IsI2P() const
{
return (memcmp(ip, pchGarliCat, sizeof(pchGarliCat)) == 0);
}
bool CNetAddr::IsLocal() const bool CNetAddr::IsLocal() const
{ {
// IPv4 loopback // IPv4 loopback
@ -738,7 +722,7 @@ bool CNetAddr::IsValid() const
bool CNetAddr::IsRoutable() const bool CNetAddr::IsRoutable() const
{ {
return IsValid() && !(IsRFC1918() || IsRFC3927() || IsRFC4862() || (IsRFC4193() && !IsTor() && !IsI2P()) || IsRFC4843() || IsLocal()); return IsValid() && !(IsRFC1918() || IsRFC3927() || IsRFC4862() || (IsRFC4193() && !IsTor()) || IsRFC4843() || IsLocal());
} }
enum Network CNetAddr::GetNetwork() const enum Network CNetAddr::GetNetwork() const
@ -752,9 +736,6 @@ enum Network CNetAddr::GetNetwork() const
if (IsTor()) if (IsTor())
return NET_TOR; return NET_TOR;
if (IsI2P())
return NET_I2P;
return NET_IPV6; return NET_IPV6;
} }
@ -762,8 +743,6 @@ std::string CNetAddr::ToStringIP() const
{ {
if (IsTor()) if (IsTor())
return EncodeBase32(&ip[6], 10) + ".onion"; return EncodeBase32(&ip[6], 10) + ".onion";
if (IsI2P())
return EncodeBase32(&ip[6], 10) + ".oc.b32.i2p";
CService serv(*this, 0); CService serv(*this, 0);
#ifdef USE_IPV6 #ifdef USE_IPV6
struct sockaddr_storage sockaddr; struct sockaddr_storage sockaddr;
@ -871,12 +850,6 @@ std::vector<unsigned char> CNetAddr::GetGroup() const
nStartByte = 6; nStartByte = 6;
nBits = 4; nBits = 4;
} }
else if (IsI2P())
{
nClass = NET_I2P;
nStartByte = 6;
nBits = 4;
}
// for he.net, use /36 groups // for he.net, use /36 groups
else if (GetByte(15) == 0x20 && GetByte(14) == 0x11 && GetByte(13) == 0x04 && GetByte(12) == 0x70) else if (GetByte(15) == 0x20 && GetByte(14) == 0x11 && GetByte(13) == 0x04 && GetByte(12) == 0x70)
nBits = 36; nBits = 36;
@ -962,11 +935,6 @@ int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const
case NET_IPV4: return REACH_IPV4; // Tor users can connect to IPv4 as well case NET_IPV4: return REACH_IPV4; // Tor users can connect to IPv4 as well
case NET_TOR: return REACH_PRIVATE; case NET_TOR: return REACH_PRIVATE;
} }
case NET_I2P:
switch(ourNet) {
default: return REACH_DEFAULT;
case NET_I2P: return REACH_PRIVATE;
}
case NET_TEREDO: case NET_TEREDO:
switch(ourNet) { switch(ourNet) {
default: return REACH_DEFAULT; default: return REACH_DEFAULT;
@ -982,8 +950,7 @@ int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const
case NET_TEREDO: return REACH_TEREDO; case NET_TEREDO: return REACH_TEREDO;
case NET_IPV6: return REACH_IPV6_WEAK; case NET_IPV6: return REACH_IPV6_WEAK;
case NET_IPV4: return REACH_IPV4; case NET_IPV4: return REACH_IPV4;
case NET_I2P: return REACH_PRIVATE; // assume connections from unroutable addresses are case NET_TOR: return REACH_PRIVATE; // either from Tor, or don't care about our address
case NET_TOR: return REACH_PRIVATE; // either from Tor/I2P, or don't care about our address
} }
} }
} }
@ -1140,7 +1107,7 @@ std::string CService::ToStringPort() const
std::string CService::ToStringIPPort() const std::string CService::ToStringIPPort() const
{ {
if (IsIPv4() || IsTor() || IsI2P()) { if (IsIPv4() || IsTor()) {
return ToStringIP() + ":" + ToStringPort(); return ToStringIP() + ":" + ToStringPort();
} else { } else {
return "[" + ToStringIP() + "]:" + ToStringPort(); return "[" + ToStringIP() + "]:" + ToStringPort();

6
src/netbase.h

@ -23,7 +23,6 @@ enum Network
NET_IPV4, NET_IPV4,
NET_IPV6, NET_IPV6,
NET_TOR, NET_TOR,
NET_I2P,
NET_MAX, NET_MAX,
}; };
@ -44,9 +43,9 @@ class CNetAddr
explicit CNetAddr(const std::string &strIp, bool fAllowLookup = false); explicit CNetAddr(const std::string &strIp, bool fAllowLookup = false);
void Init(); void Init();
void SetIP(const CNetAddr& ip); void SetIP(const CNetAddr& ip);
bool SetSpecial(const std::string &strName); // for Tor and I2P addresses bool SetSpecial(const std::string &strName); // for Tor addresses
bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0) bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor/I2P) bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor)
bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12) bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32) bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32)
bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16) bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16)
@ -58,7 +57,6 @@ class CNetAddr
bool IsRFC6052() const; // IPv6 well-known prefix (64:FF9B::/96) bool IsRFC6052() const; // IPv6 well-known prefix (64:FF9B::/96)
bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96)
bool IsTor() const; bool IsTor() const;
bool IsI2P() const;
bool IsLocal() const; bool IsLocal() const;
bool IsRoutable() const; bool IsRoutable() const;
bool IsValid() const; bool IsValid() const;

Loading…
Cancel
Save