Skip to content

Commit d321485

Browse files
committed
Preliminary support for Tor/I2P hidden services
There are plans to let Bitcoin function as Tor/I2P hidden service. To do so, we could use the established encoding provided by OnionCat and GarliCat (without actually using those tools) to embed Tor/I2P addresses in IPv6. This patch makes these addresses considered routable, so they can travel over the Bitcoin network in 'addr' messages. This will hopefully make it easier to deploy real hidden service support later.
1 parent 23aa78c commit d321485

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/netbase.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,18 @@ bool CNetAddr::IsRFC4843() const
615615
return (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x00 && (GetByte(12) & 0xF0) == 0x10);
616616
}
617617

618+
bool CNetAddr::IsOnionCat() const
619+
{
620+
static const unsigned char pchOnionCat[] = {0xFD,0x87,0xD8,0x7E,0xEB,0x43};
621+
return (memcmp(ip, pchOnionCat, sizeof(pchOnionCat)) == 0);
622+
}
623+
624+
bool CNetAddr::IsGarliCat() const
625+
{
626+
static const unsigned char pchGarliCat[] = {0xFD,0x60,0xDB,0x4D,0xDD,0xB5};
627+
return (memcmp(ip, pchGarliCat, sizeof(pchGarliCat)) == 0);
628+
}
629+
618630
bool CNetAddr::IsLocal() const
619631
{
620632
// IPv4 loopback
@@ -673,7 +685,7 @@ bool CNetAddr::IsValid() const
673685

674686
bool CNetAddr::IsRoutable() const
675687
{
676-
return IsValid() && !(IsRFC1918() || IsRFC3927() || IsRFC4862() || IsRFC4193() || IsRFC4843() || IsLocal());
688+
return IsValid() && !(IsRFC1918() || IsRFC3927() || IsRFC4862() || (IsRFC4193() && !IsOnionCat() && !IsGarliCat()) || IsRFC4843() || IsLocal());
677689
}
678690

679691
std::string CNetAddr::ToStringIP() const

src/netbase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class CNetAddr
4242
bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64)
4343
bool IsRFC6052() const; // IPv6 well-known prefix (64:FF9B::/96)
4444
bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96)
45+
bool IsOnionCat() const;
46+
bool IsGarliCat() const;
4547
bool IsLocal() const;
4648
bool IsRoutable() const;
4749
bool IsValid() const;

0 commit comments

Comments
 (0)