1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-31 04:44:13 +00:00

send peer test by Alice

This commit is contained in:
orignal 2014-04-07 16:19:33 -04:00
parent 654fe138a8
commit 45d1571559
2 changed files with 31 additions and 3 deletions

27
SSU.cpp
View File

@ -731,6 +731,33 @@ namespace ssu
m_Server.Send (buf, 80, e); m_Server.Send (buf, 80, e);
} }
void SSUSession::SendPeerTest ()
{
auto introKey = GetIntroKey ();
if (!introKey)
{
LogPrint ("SSU is not supported. Can't send peer test");
return;
}
uint8_t buf[80 + 18];
uint8_t * payload = buf + sizeof (SSUHeader);
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
uint32_t nonce = 0;
rnd.GenerateWord32 (nonce);
*(uint32_t *)payload = htobe32 (nonce);
payload += 4; // nonce
*payload = 4;
payload++; // size
memset (payload, 0, 6); // address and port always zero for Alice
payload += 6; // address and port
memcpy (payload, introKey, 32); // intro key
uint8_t iv[16];
rnd.GenerateBlock (iv, 16); // random iv
// encrypt message with session key
FillHeaderAndEncrypt (PAYLOAD_TYPE_PEER_TEST, buf, 80, m_SessionKey, iv, m_MacKey);
m_Server.Send (buf, 80, m_RemoteEndpoint);
}
void SSUSession::SendMsgAck (uint32_t msgID) void SSUSession::SendMsgAck (uint32_t msgID)
{ {
uint8_t buf[48 + 18]; // actual length is 44 = 37 + 7 but pad it to multiple of 16 uint8_t buf[48 + 18]; // actual length is 44 = 37 + 7 but pad it to multiple of 16

1
SSU.h
View File

@ -80,6 +80,7 @@ namespace ssu
boost::asio::ip::udp::endpoint& GetRemoteEndpoint () { return m_RemoteEndpoint; }; boost::asio::ip::udp::endpoint& GetRemoteEndpoint () { return m_RemoteEndpoint; };
const i2p::data::RouterInfo * GetRemoteRouter () const { return m_RemoteRouter; }; const i2p::data::RouterInfo * GetRemoteRouter () const { return m_RemoteRouter; };
void SendI2NPMessage (I2NPMessage * msg); void SendI2NPMessage (I2NPMessage * msg);
void SendPeerTest (); // Alice
private: private: