diff --git a/RouterInfo.cpp b/RouterInfo.cpp index adae686c..56c05591 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -18,13 +18,13 @@ namespace i2p namespace data { RouterInfo::RouterInfo (const char * filename): - m_IsUpdated (false), m_IsUnreachable (false), m_SupportedTransports (0) + m_IsUpdated (false), m_IsUnreachable (false), m_SupportedTransports (0), m_Caps (0) { ReadFromFile (filename); } RouterInfo::RouterInfo (const uint8_t * buf, int len): - m_IsUpdated (true), m_IsUnreachable (false), m_SupportedTransports (0) + m_IsUpdated (true), m_IsUnreachable (false), m_SupportedTransports (0), m_Caps (0) { memcpy (m_Buffer, buf, len); m_BufferLen = len; @@ -175,6 +175,10 @@ namespace data r += ReadString (value, s); s.seekg (1, std::ios_base::cur); r++; // ; m_Properties[key] = value; + + // extract caps + if (strcmp (key, "caps")) + ExtractCaps (value); } CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&m_RouterIdentity, sizeof (m_RouterIdentity)); @@ -185,6 +189,29 @@ namespace data SetUnreachable (true); } + void RouterInfo::ExtractCaps (const char * value) + { + m_Caps = 0; + const char * cap = value; + while (*cap) + { + switch (*cap) + { + case 'f': + m_Caps |= Caps::eFloodfill; + break; + case 'O': + m_Caps |= Caps::eHighBanwidth; + break; + case 'R': + m_Caps |= Caps::eReachable; + break; + default: ; + } + cap++; + } + } + void RouterInfo::UpdateIdentHashBase64 () { size_t l = i2p::data::ByteStreamToBase64 (m_IdentHash, 32, m_IdentHashBase64, 48); @@ -337,10 +364,7 @@ namespace data bool RouterInfo::IsFloodfill () const { - const char * caps = GetProperty ("caps"); - if (caps) - return strchr (caps, 'f'); - return false; + return m_Caps & Caps::eFloodfill; } bool RouterInfo::IsNTCP (bool v4only) const @@ -361,9 +385,7 @@ namespace data bool RouterInfo::UsesIntroducer () const { - if (!IsSSU ()) return false; - auto address = GetSSUAddress (true); // no introducers for v6 - return address && !address->introducers.empty (); + return !(m_Caps & Caps::eReachable); // non-reachable } const RouterInfo::Address * RouterInfo::GetNTCPAddress (bool v4only) const diff --git a/RouterInfo.h b/RouterInfo.h index 52a8d9e9..afde30bc 100644 --- a/RouterInfo.h +++ b/RouterInfo.h @@ -20,11 +20,18 @@ namespace data enum SupportedTranports { eNTCPV4 = 0x01, - eNTCPV6 = 0x20, - eSSUV4 = 0x40, - eSSUV6 = 0x80 + eNTCPV6 = 0x02, + eSSUV4 = 0x04, + eSSUV6 = 0x08 }; + enum Caps + { + eFloodfill = 0x01, + eHighBanwidth = 0x02, + eReachable = 0x04 + }; + enum TransportStyle { eTransportUnknown = 0, @@ -102,6 +109,7 @@ namespace data void WriteToStream (std::ostream& s); size_t ReadString (char * str, std::istream& s); void WriteString (const std::string& str, std::ostream& s); + void ExtractCaps (const char * value); void UpdateIdentHashBase64 (); const Address * GetAddress (TransportStyle s, bool v4only) const; @@ -117,7 +125,7 @@ namespace data std::vector
m_Addresses; std::map