mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-07 07:44:13 +00:00
introducers in local RouterInfo
This commit is contained in:
parent
da9c281d9a
commit
30ffda7708
@ -80,6 +80,22 @@ namespace i2p
|
|||||||
UpdateRouterInfo ();
|
UpdateRouterInfo ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RouterContext::AddIntroducer (const i2p::data::RouterInfo& routerInfo, uint32_t tag)
|
||||||
|
{
|
||||||
|
auto address = routerInfo.GetSSUAddress ();
|
||||||
|
if (address)
|
||||||
|
{
|
||||||
|
if (m_RouterInfo.AddIntroducer (address, tag))
|
||||||
|
UpdateRouterInfo ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RouterContext::RemoveIntroducer (uint32_t tag)
|
||||||
|
{
|
||||||
|
if (m_RouterInfo.RemoveIntroducer (tag))
|
||||||
|
UpdateRouterInfo ();
|
||||||
|
}
|
||||||
|
|
||||||
bool RouterContext::Load ()
|
bool RouterContext::Load ()
|
||||||
{
|
{
|
||||||
std::ifstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ifstream::binary | std::ofstream::in);
|
std::ifstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ifstream::binary | std::ofstream::in);
|
||||||
|
@ -27,6 +27,8 @@ namespace i2p
|
|||||||
|
|
||||||
void OverrideNTCPAddress (const char * host, int port); // temporary
|
void OverrideNTCPAddress (const char * host, int port); // temporary
|
||||||
void UpdateAddress (const char * host); // called from SSU
|
void UpdateAddress (const char * host); // called from SSU
|
||||||
|
void AddIntroducer (const i2p::data::RouterInfo& routerInfo, uint32_t tag);
|
||||||
|
void RemoveIntroducer (uint32_t tag);
|
||||||
|
|
||||||
// implements LocalDestination
|
// implements LocalDestination
|
||||||
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };
|
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };
|
||||||
|
@ -316,7 +316,50 @@ namespace data
|
|||||||
properties << ';';
|
properties << ';';
|
||||||
if (address.transportStyle == eTransportSSU)
|
if (address.transportStyle == eTransportSSU)
|
||||||
{
|
{
|
||||||
// wtite intro key
|
// write introducers if any
|
||||||
|
if (address.introducers.size () > 0)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for (auto introducer: address.introducers)
|
||||||
|
{
|
||||||
|
WriteString ("ihost" + boost::lexical_cast<std::string>(i), properties);
|
||||||
|
properties << '=';
|
||||||
|
WriteString (introducer.iHost.to_string (), properties);
|
||||||
|
properties << ';';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
for (auto introducer: address.introducers)
|
||||||
|
{
|
||||||
|
WriteString ("ikey" + boost::lexical_cast<std::string>(i), properties);
|
||||||
|
properties << '=';
|
||||||
|
char value[64];
|
||||||
|
size_t l = ByteStreamToBase64 (introducer.iKey, 32, value, 64);
|
||||||
|
value[l] = 0;
|
||||||
|
WriteString (value, properties);
|
||||||
|
properties << ';';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
for (auto introducer: address.introducers)
|
||||||
|
{
|
||||||
|
WriteString ("iport" + boost::lexical_cast<std::string>(i), properties);
|
||||||
|
properties << '=';
|
||||||
|
WriteString (boost::lexical_cast<std::string>(introducer.iPort), properties);
|
||||||
|
properties << ';';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
for (auto introducer: address.introducers)
|
||||||
|
{
|
||||||
|
WriteString ("itag" + boost::lexical_cast<std::string>(i), properties);
|
||||||
|
properties << '=';
|
||||||
|
WriteString (boost::lexical_cast<std::string>(introducer.iTag), properties);
|
||||||
|
properties << ';';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// write intro key
|
||||||
WriteString ("key", properties);
|
WriteString ("key", properties);
|
||||||
properties << '=';
|
properties << '=';
|
||||||
char value[64];
|
char value[64];
|
||||||
@ -431,6 +474,50 @@ namespace data
|
|||||||
m_Caps |= eSSUTesting;
|
m_Caps |= eSSUTesting;
|
||||||
m_Caps |= eSSUIntroducer;
|
m_Caps |= eSSUIntroducer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RouterInfo::AddIntroducer (const Address * address, uint32_t tag)
|
||||||
|
{
|
||||||
|
for (auto& addr : m_Addresses)
|
||||||
|
{
|
||||||
|
if (addr.transportStyle == eTransportSSU && addr.host.is_v4 ())
|
||||||
|
{
|
||||||
|
for (auto intro: addr.introducers)
|
||||||
|
if (intro.iTag == tag) return false; // already presented
|
||||||
|
Introducer x;
|
||||||
|
x.iHost = address->host;
|
||||||
|
x.iPort = address->port;
|
||||||
|
x.iTag = tag;
|
||||||
|
memcpy (x.iKey, address->key, 32); // TODO: replace to Tag<32>
|
||||||
|
addr.introducers.push_back (x);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RouterInfo::RemoveIntroducer (uint32_t tag)
|
||||||
|
{
|
||||||
|
for (auto& addr : m_Addresses)
|
||||||
|
{
|
||||||
|
if (addr.transportStyle == eTransportSSU && addr.host.is_v4 ())
|
||||||
|
{
|
||||||
|
for (std::vector<Introducer>::iterator it = addr.introducers.begin (); it != addr.introducers.begin (); it++)
|
||||||
|
if (it->iTag == tag)
|
||||||
|
{
|
||||||
|
addr.introducers.erase (it);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RouterInfo::SetCaps (const char * caps)
|
||||||
|
{
|
||||||
|
SetProperty ("caps", caps);
|
||||||
|
m_Caps = 0;
|
||||||
|
ExtractCaps (caps);
|
||||||
|
}
|
||||||
|
|
||||||
void RouterInfo::SetProperty (const char * key, const char * value)
|
void RouterInfo::SetProperty (const char * key, const char * value)
|
||||||
{
|
{
|
||||||
|
@ -83,6 +83,8 @@ namespace data
|
|||||||
|
|
||||||
void AddNTCPAddress (const char * host, int port);
|
void AddNTCPAddress (const char * host, int port);
|
||||||
void AddSSUAddress (const char * host, int port, const uint8_t * key);
|
void AddSSUAddress (const char * host, int port, const uint8_t * key);
|
||||||
|
bool AddIntroducer (const Address * address, uint32_t tag);
|
||||||
|
bool RemoveIntroducer (uint32_t tag);
|
||||||
void SetProperty (const char * key, const char * value);
|
void SetProperty (const char * key, const char * value);
|
||||||
const char * GetProperty (const char * key) const;
|
const char * GetProperty (const char * key) const;
|
||||||
bool IsFloodfill () const;
|
bool IsFloodfill () const;
|
||||||
@ -94,7 +96,8 @@ namespace data
|
|||||||
bool IsPeerTesting () const { return m_Caps & eSSUTesting; };
|
bool IsPeerTesting () const { return m_Caps & eSSUTesting; };
|
||||||
bool IsHidden () const { return m_Caps & eHidden; };
|
bool IsHidden () const { return m_Caps & eHidden; };
|
||||||
|
|
||||||
uint8_t GetCaps () const { return m_Caps; };
|
uint8_t GetCaps () const { return m_Caps; };
|
||||||
|
void SetCaps (const char * caps);
|
||||||
|
|
||||||
void SetUnreachable (bool unreachable) { m_IsUnreachable = unreachable; };
|
void SetUnreachable (bool unreachable) { m_IsUnreachable = unreachable; };
|
||||||
bool IsUnreachable () const { return m_IsUnreachable; };
|
bool IsUnreachable () const { return m_IsUnreachable; };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user