mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
extract caps
This commit is contained in:
parent
d938332db2
commit
b2fb466cde
3 changed files with 56 additions and 21 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue