mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-13 08:17:38 +01: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
|
namespace data
|
||||||
{
|
{
|
||||||
RouterInfo::RouterInfo (const char * filename):
|
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);
|
ReadFromFile (filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
RouterInfo::RouterInfo (const uint8_t * buf, int len):
|
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);
|
memcpy (m_Buffer, buf, len);
|
||||||
m_BufferLen = len;
|
m_BufferLen = len;
|
||||||
|
@ -175,6 +175,10 @@ namespace data
|
||||||
r += ReadString (value, s);
|
r += ReadString (value, s);
|
||||||
s.seekg (1, std::ios_base::cur); r++; // ;
|
s.seekg (1, std::ios_base::cur); r++; // ;
|
||||||
m_Properties[key] = value;
|
m_Properties[key] = value;
|
||||||
|
|
||||||
|
// extract caps
|
||||||
|
if (strcmp (key, "caps"))
|
||||||
|
ExtractCaps (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&m_RouterIdentity, sizeof (m_RouterIdentity));
|
CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&m_RouterIdentity, sizeof (m_RouterIdentity));
|
||||||
|
@ -185,6 +189,29 @@ namespace data
|
||||||
SetUnreachable (true);
|
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 ()
|
void RouterInfo::UpdateIdentHashBase64 ()
|
||||||
{
|
{
|
||||||
size_t l = i2p::data::ByteStreamToBase64 (m_IdentHash, 32, m_IdentHashBase64, 48);
|
size_t l = i2p::data::ByteStreamToBase64 (m_IdentHash, 32, m_IdentHashBase64, 48);
|
||||||
|
@ -337,10 +364,7 @@ namespace data
|
||||||
|
|
||||||
bool RouterInfo::IsFloodfill () const
|
bool RouterInfo::IsFloodfill () const
|
||||||
{
|
{
|
||||||
const char * caps = GetProperty ("caps");
|
return m_Caps & Caps::eFloodfill;
|
||||||
if (caps)
|
|
||||||
return strchr (caps, 'f');
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RouterInfo::IsNTCP (bool v4only) const
|
bool RouterInfo::IsNTCP (bool v4only) const
|
||||||
|
@ -361,9 +385,7 @@ namespace data
|
||||||
|
|
||||||
bool RouterInfo::UsesIntroducer () const
|
bool RouterInfo::UsesIntroducer () const
|
||||||
{
|
{
|
||||||
if (!IsSSU ()) return false;
|
return !(m_Caps & Caps::eReachable); // non-reachable
|
||||||
auto address = GetSSUAddress (true); // no introducers for v6
|
|
||||||
return address && !address->introducers.empty ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const RouterInfo::Address * RouterInfo::GetNTCPAddress (bool v4only) const
|
const RouterInfo::Address * RouterInfo::GetNTCPAddress (bool v4only) const
|
||||||
|
|
16
RouterInfo.h
16
RouterInfo.h
|
@ -20,9 +20,16 @@ namespace data
|
||||||
enum SupportedTranports
|
enum SupportedTranports
|
||||||
{
|
{
|
||||||
eNTCPV4 = 0x01,
|
eNTCPV4 = 0x01,
|
||||||
eNTCPV6 = 0x20,
|
eNTCPV6 = 0x02,
|
||||||
eSSUV4 = 0x40,
|
eSSUV4 = 0x04,
|
||||||
eSSUV6 = 0x80
|
eSSUV6 = 0x08
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Caps
|
||||||
|
{
|
||||||
|
eFloodfill = 0x01,
|
||||||
|
eHighBanwidth = 0x02,
|
||||||
|
eReachable = 0x04
|
||||||
};
|
};
|
||||||
|
|
||||||
enum TransportStyle
|
enum TransportStyle
|
||||||
|
@ -102,6 +109,7 @@ namespace data
|
||||||
void WriteToStream (std::ostream& s);
|
void WriteToStream (std::ostream& s);
|
||||||
size_t ReadString (char * str, std::istream& s);
|
size_t ReadString (char * str, std::istream& s);
|
||||||
void WriteString (const std::string& str, std::ostream& s);
|
void WriteString (const std::string& str, std::ostream& s);
|
||||||
|
void ExtractCaps (const char * value);
|
||||||
void UpdateIdentHashBase64 ();
|
void UpdateIdentHashBase64 ();
|
||||||
const Address * GetAddress (TransportStyle s, bool v4only) const;
|
const Address * GetAddress (TransportStyle s, bool v4only) const;
|
||||||
|
|
||||||
|
@ -117,7 +125,7 @@ namespace data
|
||||||
std::vector<Address> m_Addresses;
|
std::vector<Address> m_Addresses;
|
||||||
std::map<std::string, std::string> m_Properties;
|
std::map<std::string, std::string> m_Properties;
|
||||||
bool m_IsUpdated, m_IsUnreachable;
|
bool m_IsUpdated, m_IsUnreachable;
|
||||||
uint8_t m_SupportedTransports;
|
uint8_t m_SupportedTransports, m_Caps;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
9
SSU.cpp
9
SSU.cpp
|
@ -822,15 +822,20 @@ namespace ssu
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// connect to introducer
|
// connect through introducer
|
||||||
|
if (address->introducers.size () > 0)
|
||||||
|
{
|
||||||
auto& introducer = address->introducers[0]; // TODO:
|
auto& introducer = address->introducers[0]; // TODO:
|
||||||
boost::asio::ip::udp::endpoint introducerEndpoint (introducer.iHost, introducer.iPort);
|
boost::asio::ip::udp::endpoint introducerEndpoint (introducer.iHost, introducer.iPort);
|
||||||
session = new SSUSession (this, introducerEndpoint, router);
|
session = new SSUSession (this, introducerEndpoint, router);
|
||||||
m_Sessions[introducerEndpoint] = session;
|
m_Sessions[introducerEndpoint] = session;
|
||||||
LogPrint ("New SSU session to [", router->GetIdentHashAbbreviation (),
|
LogPrint ("New SSU session to [", router->GetIdentHashAbbreviation (),
|
||||||
"] created through introducer ", introducerEndpoint.address ().to_string (), ":", introducerEndpoint.port ());
|
"] through introducer ", introducerEndpoint.address ().to_string (), ":", introducerEndpoint.port ());
|
||||||
session->ConnectThroughIntroducer (introducer);
|
session->ConnectThroughIntroducer (introducer);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
LogPrint ("Router is unreachable, but not introducers presentd. Ignored");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue