mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-23 21:44:15 +00:00
store relay tag if introducer
This commit is contained in:
parent
4341d285aa
commit
73d38f530f
34
SSU.cpp
34
SSU.cpp
@ -294,6 +294,7 @@ namespace ssu
|
|||||||
LogPrint ("SSU is not supported");
|
LogPrint ("SSU is not supported");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
||||||
uint8_t signedData[532]; // x,y, remote IP, remote port, our IP, our port, relayTag, signed on time
|
uint8_t signedData[532]; // x,y, remote IP, remote port, our IP, our port, relayTag, signed on time
|
||||||
memcpy (signedData, x, 256); // x
|
memcpy (signedData, x, 256); // x
|
||||||
|
|
||||||
@ -311,8 +312,14 @@ namespace ssu
|
|||||||
memcpy (signedData + 512, payload - 6, 6); // remote endpoint IP and port
|
memcpy (signedData + 512, payload - 6, 6); // remote endpoint IP and port
|
||||||
*(uint32_t *)(signedData + 518) = htobe32 (address->host.to_v4 ().to_ulong ()); // our IP
|
*(uint32_t *)(signedData + 518) = htobe32 (address->host.to_v4 ().to_ulong ()); // our IP
|
||||||
*(uint16_t *)(signedData + 522) = htobe16 (address->port); // our port
|
*(uint16_t *)(signedData + 522) = htobe16 (address->port); // our port
|
||||||
*(uint32_t *)(payload) = 0; // relay tag, always 0 for now
|
uint32_t relayTag = 0;
|
||||||
payload += 4;
|
if (i2p::context.GetRouterInfo ().IsIntroducer ())
|
||||||
|
{
|
||||||
|
rnd.GenerateWord32 (relayTag);
|
||||||
|
m_Server.AddRelay (relayTag, m_RemoteEndpoint);
|
||||||
|
}
|
||||||
|
*(uint32_t *)(payload) = relayTag;
|
||||||
|
payload += 4; // relay tag
|
||||||
*(uint32_t *)(payload) = htobe32 (i2p::util::GetSecondsSinceEpoch ()); // signed on time
|
*(uint32_t *)(payload) = htobe32 (i2p::util::GetSecondsSinceEpoch ()); // signed on time
|
||||||
payload += 4;
|
payload += 4;
|
||||||
memcpy (signedData + 524, payload - 8, 8); // relayTag and signed on time
|
memcpy (signedData + 524, payload - 8, 8); // relayTag and signed on time
|
||||||
@ -320,7 +327,6 @@ namespace ssu
|
|||||||
// TODO: fill padding with random data
|
// TODO: fill padding with random data
|
||||||
|
|
||||||
uint8_t iv[16];
|
uint8_t iv[16];
|
||||||
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
|
||||||
rnd.GenerateBlock (iv, 16); // random iv
|
rnd.GenerateBlock (iv, 16); // random iv
|
||||||
// encrypt signature and 8 bytes padding with newly created session key
|
// encrypt signature and 8 bytes padding with newly created session key
|
||||||
m_Encryption.SetKeyWithIV (m_SessionKey, 32, iv);
|
m_Encryption.SetKeyWithIV (m_SessionKey, 32, iv);
|
||||||
@ -929,6 +935,19 @@ namespace ssu
|
|||||||
m_Socket.close ();
|
m_Socket.close ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SSUServer::AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay)
|
||||||
|
{
|
||||||
|
m_Relays[tag] = relay;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSUSession * SSUServer::FindRelaySession (uint32_t tag)
|
||||||
|
{
|
||||||
|
auto it = m_Relays.find (tag);
|
||||||
|
if (it != m_Relays.end ())
|
||||||
|
return FindSession (it->second);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void SSUServer::Send (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& to)
|
void SSUServer::Send (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& to)
|
||||||
{
|
{
|
||||||
m_Socket.send_to (boost::asio::buffer (buf, len), to);
|
m_Socket.send_to (boost::asio::buffer (buf, len), to);
|
||||||
@ -968,12 +987,17 @@ namespace ssu
|
|||||||
if (!router) return nullptr;
|
if (!router) return nullptr;
|
||||||
auto address = router->GetSSUAddress ();
|
auto address = router->GetSSUAddress ();
|
||||||
if (!address) return nullptr;
|
if (!address) return nullptr;
|
||||||
auto it = m_Sessions.find (boost::asio::ip::udp::endpoint (address->host, address->port));
|
return FindSession (boost::asio::ip::udp::endpoint (address->host, address->port));
|
||||||
|
}
|
||||||
|
|
||||||
|
SSUSession * SSUServer::FindSession (const boost::asio::ip::udp::endpoint& e)
|
||||||
|
{
|
||||||
|
auto it = m_Sessions.find (e);
|
||||||
if (it != m_Sessions.end ())
|
if (it != m_Sessions.end ())
|
||||||
return it->second;
|
return it->second;
|
||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSUSession * SSUServer::GetSession (const i2p::data::RouterInfo * router, bool peerTest)
|
SSUSession * SSUServer::GetSession (const i2p::data::RouterInfo * router, bool peerTest)
|
||||||
{
|
{
|
||||||
|
4
SSU.h
4
SSU.h
@ -157,12 +157,15 @@ namespace ssu
|
|||||||
void Stop ();
|
void Stop ();
|
||||||
SSUSession * GetSession (const i2p::data::RouterInfo * router, bool peerTest = false);
|
SSUSession * GetSession (const i2p::data::RouterInfo * router, bool peerTest = false);
|
||||||
SSUSession * FindSession (const i2p::data::RouterInfo * router);
|
SSUSession * FindSession (const i2p::data::RouterInfo * router);
|
||||||
|
SSUSession * FindSession (const boost::asio::ip::udp::endpoint& e);
|
||||||
void DeleteSession (SSUSession * session);
|
void DeleteSession (SSUSession * session);
|
||||||
void DeleteAllSessions ();
|
void DeleteAllSessions ();
|
||||||
|
|
||||||
boost::asio::io_service& GetService () { return m_Socket.get_io_service(); };
|
boost::asio::io_service& GetService () { return m_Socket.get_io_service(); };
|
||||||
const boost::asio::ip::udp::endpoint& GetEndpoint () const { return m_Endpoint; };
|
const boost::asio::ip::udp::endpoint& GetEndpoint () const { return m_Endpoint; };
|
||||||
void Send (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& to);
|
void Send (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& to);
|
||||||
|
void AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay);
|
||||||
|
SSUSession * FindRelaySession (uint32_t tag);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -176,6 +179,7 @@ namespace ssu
|
|||||||
boost::asio::ip::udp::endpoint m_SenderEndpoint;
|
boost::asio::ip::udp::endpoint m_SenderEndpoint;
|
||||||
uint8_t m_ReceiveBuffer[2*SSU_MTU];
|
uint8_t m_ReceiveBuffer[2*SSU_MTU];
|
||||||
std::map<boost::asio::ip::udp::endpoint, SSUSession *> m_Sessions;
|
std::map<boost::asio::ip::udp::endpoint, SSUSession *> m_Sessions;
|
||||||
|
std::map<uint32_t, boost::asio::ip::udp::endpoint> m_Relays; // we are introducer
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// for HTTP only
|
// for HTTP only
|
||||||
|
Loading…
x
Reference in New Issue
Block a user