mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 12:24:19 +00:00
parse '4' and '6' address caps
This commit is contained in:
parent
1d7639b3f4
commit
b60ebfe1c6
@ -186,6 +186,7 @@ namespace data
|
|||||||
|
|
||||||
void RouterInfo::ReadFromStream (std::istream& s)
|
void RouterInfo::ReadFromStream (std::istream& s)
|
||||||
{
|
{
|
||||||
|
m_Caps = 0;
|
||||||
s.read ((char *)&m_Timestamp, sizeof (m_Timestamp));
|
s.read ((char *)&m_Timestamp, sizeof (m_Timestamp));
|
||||||
m_Timestamp = be64toh (m_Timestamp);
|
m_Timestamp = be64toh (m_Timestamp);
|
||||||
// read addresses
|
// read addresses
|
||||||
@ -251,7 +252,7 @@ namespace data
|
|||||||
LogPrint (eLogWarning, "RouterInfo: Unexpected field 'key' for NTCP");
|
LogPrint (eLogWarning, "RouterInfo: Unexpected field 'key' for NTCP");
|
||||||
}
|
}
|
||||||
else if (!strcmp (key, "caps"))
|
else if (!strcmp (key, "caps"))
|
||||||
address->caps = ExtractCaps (value);
|
address->caps = ExtractAddressCaps (value);
|
||||||
else if (!strcmp (key, "s")) // ntcp2 static key
|
else if (!strcmp (key, "s")) // ntcp2 static key
|
||||||
{
|
{
|
||||||
Base64ToByteStream (value, strlen (value), address->ntcp2->staticKey, 32);
|
Base64ToByteStream (value, strlen (value), address->ntcp2->staticKey, 32);
|
||||||
@ -354,7 +355,7 @@ namespace data
|
|||||||
|
|
||||||
// extract caps
|
// extract caps
|
||||||
if (!strcmp (key, "caps"))
|
if (!strcmp (key, "caps"))
|
||||||
m_Caps = ExtractCaps (value);
|
ExtractCaps (value);
|
||||||
// extract version
|
// extract version
|
||||||
else if (!strcmp (key, ROUTER_INFO_PROPERTY_VERSION))
|
else if (!strcmp (key, ROUTER_INFO_PROPERTY_VERSION))
|
||||||
{
|
{
|
||||||
@ -403,7 +404,41 @@ namespace data
|
|||||||
return m_Family == fam;
|
return m_Family == fam;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t RouterInfo::ExtractCaps (const char * value)
|
void RouterInfo::ExtractCaps (const char * value)
|
||||||
|
{
|
||||||
|
const char * cap = value;
|
||||||
|
while (*cap)
|
||||||
|
{
|
||||||
|
switch (*cap)
|
||||||
|
{
|
||||||
|
case CAPS_FLAG_FLOODFILL:
|
||||||
|
m_Caps |= Caps::eFloodfill;
|
||||||
|
break;
|
||||||
|
case CAPS_FLAG_HIGH_BANDWIDTH1:
|
||||||
|
case CAPS_FLAG_HIGH_BANDWIDTH2:
|
||||||
|
case CAPS_FLAG_HIGH_BANDWIDTH3:
|
||||||
|
m_Caps |= Caps::eHighBandwidth;
|
||||||
|
break;
|
||||||
|
case CAPS_FLAG_EXTRA_BANDWIDTH1:
|
||||||
|
case CAPS_FLAG_EXTRA_BANDWIDTH2:
|
||||||
|
m_Caps |= Caps::eExtraBandwidth | Caps::eHighBandwidth;
|
||||||
|
break;
|
||||||
|
case CAPS_FLAG_HIDDEN:
|
||||||
|
m_Caps |= Caps::eHidden;
|
||||||
|
break;
|
||||||
|
case CAPS_FLAG_REACHABLE:
|
||||||
|
m_Caps |= Caps::eReachable;
|
||||||
|
break;
|
||||||
|
case CAPS_FLAG_UNREACHABLE:
|
||||||
|
m_Caps |= Caps::eUnreachable;
|
||||||
|
break;
|
||||||
|
default: ;
|
||||||
|
}
|
||||||
|
cap++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t RouterInfo::ExtractAddressCaps (const char * value) const
|
||||||
{
|
{
|
||||||
uint8_t caps = 0;
|
uint8_t caps = 0;
|
||||||
const char * cap = value;
|
const char * cap = value;
|
||||||
@ -411,32 +446,17 @@ namespace data
|
|||||||
{
|
{
|
||||||
switch (*cap)
|
switch (*cap)
|
||||||
{
|
{
|
||||||
case CAPS_FLAG_FLOODFILL:
|
case CAPS_FLAG_V4:
|
||||||
caps |= Caps::eFloodfill;
|
caps |= AddressCaps::eV4;
|
||||||
break;
|
break;
|
||||||
case CAPS_FLAG_HIGH_BANDWIDTH1:
|
case CAPS_FLAG_V6:
|
||||||
case CAPS_FLAG_HIGH_BANDWIDTH2:
|
caps |= AddressCaps::eV6;
|
||||||
case CAPS_FLAG_HIGH_BANDWIDTH3:
|
break;
|
||||||
caps |= Caps::eHighBandwidth;
|
|
||||||
break;
|
|
||||||
case CAPS_FLAG_EXTRA_BANDWIDTH1:
|
|
||||||
case CAPS_FLAG_EXTRA_BANDWIDTH2:
|
|
||||||
caps |= Caps::eExtraBandwidth | Caps::eHighBandwidth;
|
|
||||||
break;
|
|
||||||
case CAPS_FLAG_HIDDEN:
|
|
||||||
caps |= Caps::eHidden;
|
|
||||||
break;
|
|
||||||
case CAPS_FLAG_REACHABLE:
|
|
||||||
caps |= Caps::eReachable;
|
|
||||||
break;
|
|
||||||
case CAPS_FLAG_UNREACHABLE:
|
|
||||||
caps |= Caps::eUnreachable;
|
|
||||||
break;
|
|
||||||
case CAPS_FLAG_SSU_TESTING:
|
case CAPS_FLAG_SSU_TESTING:
|
||||||
caps |= Caps::eSSUTesting;
|
caps |= AddressCaps::eSSUTesting;
|
||||||
break;
|
break;
|
||||||
case CAPS_FLAG_SSU_INTRODUCER:
|
case CAPS_FLAG_SSU_INTRODUCER:
|
||||||
caps |= Caps::eSSUIntroducer;
|
caps |= AddressCaps::eSSUIntroducer;
|
||||||
break;
|
break;
|
||||||
default: ;
|
default: ;
|
||||||
}
|
}
|
||||||
@ -444,7 +464,7 @@ namespace data
|
|||||||
}
|
}
|
||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterInfo::UpdateCapsProperty ()
|
void RouterInfo::UpdateCapsProperty ()
|
||||||
{
|
{
|
||||||
std::string caps;
|
std::string caps;
|
||||||
@ -799,7 +819,8 @@ namespace data
|
|||||||
void RouterInfo::SetCaps (const char * caps)
|
void RouterInfo::SetCaps (const char * caps)
|
||||||
{
|
{
|
||||||
SetProperty ("caps", caps);
|
SetProperty ("caps", caps);
|
||||||
m_Caps = ExtractCaps (caps);
|
m_Caps = 0;
|
||||||
|
ExtractCaps (caps);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterInfo::SetProperty (const std::string& key, const std::string& value)
|
void RouterInfo::SetProperty (const std::string& key, const std::string& value)
|
||||||
|
@ -44,6 +44,8 @@ namespace data
|
|||||||
const char CAPS_FLAG_EXTRA_BANDWIDTH1 = 'P'; /* 256-2000 KBps */
|
const char CAPS_FLAG_EXTRA_BANDWIDTH1 = 'P'; /* 256-2000 KBps */
|
||||||
const char CAPS_FLAG_EXTRA_BANDWIDTH2 = 'X'; /* > 2000 KBps */
|
const char CAPS_FLAG_EXTRA_BANDWIDTH2 = 'X'; /* > 2000 KBps */
|
||||||
|
|
||||||
|
const char CAPS_FLAG_V4 = '4';
|
||||||
|
const char CAPS_FLAG_V6 = '6';
|
||||||
const char CAPS_FLAG_SSU_TESTING = 'B';
|
const char CAPS_FLAG_SSU_TESTING = 'B';
|
||||||
const char CAPS_FLAG_SSU_INTRODUCER = 'C';
|
const char CAPS_FLAG_SSU_INTRODUCER = 'C';
|
||||||
|
|
||||||
@ -67,12 +69,18 @@ namespace data
|
|||||||
eHighBandwidth = 0x02,
|
eHighBandwidth = 0x02,
|
||||||
eExtraBandwidth = 0x04,
|
eExtraBandwidth = 0x04,
|
||||||
eReachable = 0x08,
|
eReachable = 0x08,
|
||||||
eSSUTesting = 0x10,
|
eHidden = 0x10,
|
||||||
eSSUIntroducer = 0x20,
|
eUnreachable = 0x20
|
||||||
eHidden = 0x40,
|
|
||||||
eUnreachable = 0x80
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum AddressCaps
|
||||||
|
{
|
||||||
|
eV4 = 0x01,
|
||||||
|
eV6 = 0x02,
|
||||||
|
eSSUTesting = 0x04,
|
||||||
|
eSSUIntroducer = 0x08
|
||||||
|
};
|
||||||
|
|
||||||
enum TransportStyle
|
enum TransportStyle
|
||||||
{
|
{
|
||||||
eTransportUnknown = 0,
|
eTransportUnknown = 0,
|
||||||
@ -234,7 +242,8 @@ namespace data
|
|||||||
void WriteToStream (std::ostream& s) const;
|
void WriteToStream (std::ostream& s) const;
|
||||||
size_t ReadString (char* str, size_t len, std::istream& s) const;
|
size_t ReadString (char* str, size_t len, std::istream& s) const;
|
||||||
void WriteString (const std::string& str, std::ostream& s) const;
|
void WriteString (const std::string& str, std::ostream& s) const;
|
||||||
uint8_t ExtractCaps (const char * value);
|
void ExtractCaps (const char * value);
|
||||||
|
uint8_t ExtractAddressCaps (const char * value) const;
|
||||||
template<typename Filter>
|
template<typename Filter>
|
||||||
std::shared_ptr<const Address> GetAddress (Filter filter) const;
|
std::shared_ptr<const Address> GetAddress (Filter filter) const;
|
||||||
void UpdateCapsProperty ();
|
void UpdateCapsProperty ();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user