Browse Source

extract caps

pull/48/head
orignal 11 years ago
parent
commit
b2fb466cde
  1. 40
      RouterInfo.cpp
  2. 16
      RouterInfo.h
  3. 21
      SSU.cpp

40
RouterInfo.cpp

@ -18,13 +18,13 @@ namespace i2p @@ -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 @@ -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 @@ -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 @@ -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 @@ -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

16
RouterInfo.h

@ -20,11 +20,18 @@ namespace data @@ -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 @@ -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 @@ -117,7 +125,7 @@ namespace data
std::vector<Address> m_Addresses;
std::map<std::string, std::string> m_Properties;
bool m_IsUpdated, m_IsUnreachable;
uint8_t m_SupportedTransports;
uint8_t m_SupportedTransports, m_Caps;
};
}
}

21
SSU.cpp

@ -822,14 +822,19 @@ namespace ssu @@ -822,14 +822,19 @@ namespace ssu
}
else
{
// connect to introducer
auto& introducer = address->introducers[0]; // TODO:
boost::asio::ip::udp::endpoint introducerEndpoint (introducer.iHost, introducer.iPort);
session = new SSUSession (this, introducerEndpoint, router);
m_Sessions[introducerEndpoint] = session;
LogPrint ("New SSU session to [", router->GetIdentHashAbbreviation (),
"] created through introducer ", introducerEndpoint.address ().to_string (), ":", introducerEndpoint.port ());
session->ConnectThroughIntroducer (introducer);
// connect through introducer
if (address->introducers.size () > 0)
{
auto& introducer = address->introducers[0]; // TODO:
boost::asio::ip::udp::endpoint introducerEndpoint (introducer.iHost, introducer.iPort);
session = new SSUSession (this, introducerEndpoint, router);
m_Sessions[introducerEndpoint] = session;
LogPrint ("New SSU session to [", router->GetIdentHashAbbreviation (),
"] through introducer ", introducerEndpoint.address ().to_string (), ":", introducerEndpoint.port ());
session->ConnectThroughIntroducer (introducer);
}
else
LogPrint ("Router is unreachable, but not introducers presentd. Ignored");
}
}
}

Loading…
Cancel
Save