mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
create SSU address
This commit is contained in:
parent
fc59b1fcd8
commit
a73014a629
@ -25,11 +25,16 @@ namespace i2p
|
|||||||
m_Keys = i2p::data::CreateRandomKeys ();
|
m_Keys = i2p::data::CreateRandomKeys ();
|
||||||
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
|
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
|
||||||
CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
|
CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
|
||||||
|
UpdateRouterInfo ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RouterContext::UpdateRouterInfo ()
|
||||||
|
{
|
||||||
i2p::data::Identity ident;
|
i2p::data::Identity ident;
|
||||||
ident = m_Keys;
|
ident = m_Keys;
|
||||||
m_RouterInfo.SetRouterIdentity (ident);
|
m_RouterInfo.SetRouterIdentity (ident);
|
||||||
|
|
||||||
|
//m_RouterInfo.AddSSUAddress ("127.0.0.1", 17007, m_RouterInfo.GetIdentHash ());
|
||||||
m_RouterInfo.AddNTCPAddress ("127.0.0.1", 17007); // TODO:
|
m_RouterInfo.AddNTCPAddress ("127.0.0.1", 17007); // TODO:
|
||||||
m_RouterInfo.SetProperty ("caps", "LR");
|
m_RouterInfo.SetProperty ("caps", "LR");
|
||||||
m_RouterInfo.SetProperty ("coreVersion", "0.9.8.1");
|
m_RouterInfo.SetProperty ("coreVersion", "0.9.8.1");
|
||||||
@ -38,8 +43,8 @@ namespace i2p
|
|||||||
m_RouterInfo.SetProperty ("start_uptime", "90m");
|
m_RouterInfo.SetProperty ("start_uptime", "90m");
|
||||||
|
|
||||||
m_RouterInfo.CreateBuffer ();
|
m_RouterInfo.CreateBuffer ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::OverrideNTCPAddress (const char * host, int port)
|
void RouterContext::OverrideNTCPAddress (const char * host, int port)
|
||||||
{
|
{
|
||||||
m_RouterInfo.CreateBuffer ();
|
m_RouterInfo.CreateBuffer ();
|
||||||
@ -51,6 +56,7 @@ namespace i2p
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_RouterInfo.CreateBuffer ();
|
m_RouterInfo.CreateBuffer ();
|
||||||
|
Save (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::UpdateAddress (const char * host)
|
void RouterContext::UpdateAddress (const char * host)
|
||||||
@ -91,7 +97,7 @@ namespace i2p
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::Save ()
|
void RouterContext::Save (bool infoOnly)
|
||||||
{
|
{
|
||||||
std::string dataDir = i2p::util::filesystem::GetDataDir ().string ();
|
std::string dataDir = i2p::util::filesystem::GetDataDir ().string ();
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@ -104,9 +110,12 @@ namespace i2p
|
|||||||
std::string router_info = dataDir;
|
std::string router_info = dataDir;
|
||||||
router_info.append (ROUTER_INFO);
|
router_info.append (ROUTER_INFO);
|
||||||
|
|
||||||
std::ofstream fk (router_keys.c_str (), std::ofstream::binary | std::ofstream::out);
|
if (!infoOnly)
|
||||||
fk.write ((char *)&m_Keys, sizeof (m_Keys));
|
{
|
||||||
|
std::ofstream fk (router_keys.c_str (), std::ofstream::binary | std::ofstream::out);
|
||||||
|
fk.write ((char *)&m_Keys, sizeof (m_Keys));
|
||||||
|
}
|
||||||
|
|
||||||
std::ofstream fi (router_info.c_str (), std::ofstream::binary | std::ofstream::out);
|
std::ofstream fi (router_info.c_str (), std::ofstream::binary | std::ofstream::out);
|
||||||
fi.write ((char *)m_RouterInfo.GetBuffer (), m_RouterInfo.GetBufferLen ());
|
fi.write ((char *)m_RouterInfo.GetBuffer (), m_RouterInfo.GetBufferLen ());
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,9 @@ namespace i2p
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void CreateNewRouter ();
|
void CreateNewRouter ();
|
||||||
|
void UpdateRouterInfo ();
|
||||||
bool Load ();
|
bool Load ();
|
||||||
void Save ();
|
void Save (bool infoOnly = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -208,14 +208,23 @@ namespace data
|
|||||||
{
|
{
|
||||||
s.write ((char *)&address.cost, sizeof (address.cost));
|
s.write ((char *)&address.cost, sizeof (address.cost));
|
||||||
s.write ((char *)&address.date, sizeof (address.date));
|
s.write ((char *)&address.date, sizeof (address.date));
|
||||||
|
std::stringstream properties;
|
||||||
if (address.transportStyle == eTransportNTCP)
|
if (address.transportStyle == eTransportNTCP)
|
||||||
WriteString ("NTCP", s);
|
WriteString ("NTCP", s);
|
||||||
else if (address.transportStyle == eTransportSSU)
|
else if (address.transportStyle == eTransportSSU)
|
||||||
|
{
|
||||||
WriteString ("SSU", s);
|
WriteString ("SSU", s);
|
||||||
|
// wtite intro key
|
||||||
|
WriteString ("key", properties);
|
||||||
|
properties << '=';
|
||||||
|
char value[64];
|
||||||
|
ByteStreamToBase64 (address.key, 32, value, 64);
|
||||||
|
WriteString (value, properties);
|
||||||
|
properties << ';';
|
||||||
|
}
|
||||||
else
|
else
|
||||||
WriteString ("", s);
|
WriteString ("", s);
|
||||||
|
|
||||||
std::stringstream properties;
|
|
||||||
WriteString ("host", properties);
|
WriteString ("host", properties);
|
||||||
properties << '=';
|
properties << '=';
|
||||||
WriteString (address.host.to_string (), properties);
|
WriteString (address.host.to_string (), properties);
|
||||||
@ -287,6 +296,18 @@ namespace data
|
|||||||
m_Addresses.push_back(addr);
|
m_Addresses.push_back(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RouterInfo::AddSSUAddress (const char * host, int port, const uint8_t * key)
|
||||||
|
{
|
||||||
|
Address addr;
|
||||||
|
addr.host = boost::asio::ip::address::from_string (host);
|
||||||
|
addr.port = port;
|
||||||
|
addr.transportStyle = eTransportSSU;
|
||||||
|
addr.cost = 10; // NTCP should have prioprity over SSU
|
||||||
|
addr.date = 0;
|
||||||
|
memcpy (addr.key, key, 32);
|
||||||
|
m_Addresses.push_back(addr);
|
||||||
|
}
|
||||||
|
|
||||||
void RouterInfo::SetProperty (const char * key, const char * value)
|
void RouterInfo::SetProperty (const char * key, const char * value)
|
||||||
{
|
{
|
||||||
m_Properties[key] = value;
|
m_Properties[key] = value;
|
||||||
|
@ -69,6 +69,7 @@ namespace data
|
|||||||
const RoutingKey& GetRoutingKey () const { return m_RoutingKey; };
|
const RoutingKey& GetRoutingKey () const { return m_RoutingKey; };
|
||||||
|
|
||||||
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 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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user