Browse Source

send PeerTest to Charlie

pull/95/head
orignal 10 years ago
parent
commit
ebe73491c6
  1. 27
      SSU.cpp
  2. 2
      SSU.h

27
SSU.cpp

@ -761,12 +761,16 @@ namespace ssu
else else
{ {
LogPrint ("SSU peer test from Alice. We are Bob"); 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 buf[80 + 18];
uint8_t iv[16]; uint8_t iv[16];
@ -777,16 +781,25 @@ namespace ssu
payload++; // size payload++; // size
*(uint32_t *)payload = htobe32 (address); *(uint32_t *)payload = htobe32 (address);
payload += 4; // address payload += 4; // address
*(uint16_t *)payload = htobe32 (port); *(uint16_t *)payload = htobe16 (port);
payload += 2; // port payload += 2; // port
memcpy (payload, introKey, 32); // intro key memcpy (payload, introKey, 32); // intro key
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
rnd.GenerateBlock (iv, 16); // random iv rnd.GenerateBlock (iv, 16); // random iv
// encrypt message with specified intro key if (toAddress)
FillHeaderAndEncrypt (PAYLOAD_TYPE_PEER_TEST, buf, 80, introKey, iv, introKey); {
boost::asio::ip::udp::endpoint e (boost::asio::ip::address_v4 (address), port); // encrypt message with specified intro key
m_Server.Send (buf, 80, e); 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 () void SSUSession::SendPeerTest ()

2
SSU.h

@ -99,7 +99,7 @@ namespace ssu
void Failed (); void Failed ();
void HandleConnectTimer (const boost::system::error_code& ecode); void HandleConnectTimer (const boost::system::error_code& ecode);
void ProcessPeerTest (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint); 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 ProcessData (uint8_t * buf, size_t len);
void SendSesionDestroyed (); void SendSesionDestroyed ();
void Send (uint8_t type, const uint8_t * payload, size_t len); // with session key void Send (uint8_t type, const uint8_t * payload, size_t len); // with session key

Loading…
Cancel
Save