mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-16 00:12:43 +00:00
send PeerTest to Charlie
This commit is contained in:
parent
f4afaca937
commit
ebe73491c6
27
SSU.cpp
27
SSU.cpp
@ -761,12 +761,16 @@ namespace ssu
|
||||
else
|
||||
{
|
||||
LogPrint ("SSU peer test from Alice. We are Bob");
|
||||
// TODO: find Charlie
|
||||
auto session = m_Server.GetRandomEstablishedSession (); // charlie
|
||||
if (session)
|
||||
session->SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (),
|
||||
senderEndpoint.port (), introKey, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SSUSession::SendPeerTest (uint32_t nonce, uint32_t address, uint16_t port, uint8_t * introKey)
|
||||
void SSUSession::SendPeerTest (uint32_t nonce, uint32_t address, uint16_t port,
|
||||
uint8_t * introKey, bool toAddress)
|
||||
{
|
||||
uint8_t buf[80 + 18];
|
||||
uint8_t iv[16];
|
||||
@ -777,16 +781,25 @@ namespace ssu
|
||||
payload++; // size
|
||||
*(uint32_t *)payload = htobe32 (address);
|
||||
payload += 4; // address
|
||||
*(uint16_t *)payload = htobe32 (port);
|
||||
*(uint16_t *)payload = htobe16 (port);
|
||||
payload += 2; // port
|
||||
memcpy (payload, introKey, 32); // intro key
|
||||
|
||||
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
||||
rnd.GenerateBlock (iv, 16); // random iv
|
||||
// encrypt message with specified intro key
|
||||
FillHeaderAndEncrypt (PAYLOAD_TYPE_PEER_TEST, buf, 80, introKey, iv, introKey);
|
||||
boost::asio::ip::udp::endpoint e (boost::asio::ip::address_v4 (address), port);
|
||||
m_Server.Send (buf, 80, e);
|
||||
if (toAddress)
|
||||
{
|
||||
// encrypt message with specified intro key
|
||||
FillHeaderAndEncrypt (PAYLOAD_TYPE_PEER_TEST, buf, 80, introKey, iv, introKey);
|
||||
boost::asio::ip::udp::endpoint e (boost::asio::ip::address_v4 (address), port);
|
||||
m_Server.Send (buf, 80, e);
|
||||
}
|
||||
else
|
||||
{
|
||||
// encrypt message with session key
|
||||
FillHeaderAndEncrypt (PAYLOAD_TYPE_PEER_TEST, buf, 80);
|
||||
Send (buf, 80);
|
||||
}
|
||||
}
|
||||
|
||||
void SSUSession::SendPeerTest ()
|
||||
|
2
SSU.h
2
SSU.h
@ -99,7 +99,7 @@ namespace ssu
|
||||
void Failed ();
|
||||
void HandleConnectTimer (const boost::system::error_code& ecode);
|
||||
void ProcessPeerTest (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint);
|
||||
void SendPeerTest (uint32_t nonce, uint32_t address, uint16_t port, uint8_t * introKey); // Charlie to Alice
|
||||
void SendPeerTest (uint32_t nonce, uint32_t address, uint16_t port, uint8_t * introKey, bool toAddress = true);
|
||||
void ProcessData (uint8_t * buf, size_t len);
|
||||
void SendSesionDestroyed ();
|
||||
void Send (uint8_t type, const uint8_t * payload, size_t len); // with session key
|
||||
|
Loading…
Reference in New Issue
Block a user