Browse Source

const buffer for ProcessPeerTest

pull/168/head
orignal 9 years ago
parent
commit
4831e9705c
  1. 10
      SSUSession.cpp
  2. 2
      SSUSession.h

10
SSUSession.cpp

@ -880,9 +880,9 @@ namespace transport
} }
} }
void SSUSession::ProcessPeerTest (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint) void SSUSession::ProcessPeerTest (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint)
{ {
uint8_t * buf1 = buf; const uint8_t * buf1 = buf;
uint32_t nonce = bufbe32toh (buf); uint32_t nonce = bufbe32toh (buf);
buf += 4; // nonce buf += 4; // nonce
uint8_t size = *buf; uint8_t size = *buf;
@ -892,7 +892,7 @@ namespace transport
buf += size; // address buf += size; // address
uint16_t port = buf16toh(buf); // use it as is uint16_t port = buf16toh(buf); // use it as is
buf += 2; // port buf += 2; // port
uint8_t * introKey = buf; const uint8_t * introKey = buf;
if (port && !address) if (port && !address)
{ {
LogPrint (eLogWarning, "Address of ", size, " bytes not supported"); LogPrint (eLogWarning, "Address of ", size, " bytes not supported");
@ -935,19 +935,19 @@ namespace transport
case ePeerTestParticipantBob: case ePeerTestParticipantBob:
{ {
LogPrint (eLogDebug, "SSU peer test from Charlie. We are Bob"); LogPrint (eLogDebug, "SSU peer test from Charlie. We are Bob");
m_Server.RemovePeerTest (nonce); // nonce has been used
boost::asio::ip::udp::endpoint ep (boost::asio::ip::address_v4 (be32toh (address)), be16toh (port)); // Alice's address/port boost::asio::ip::udp::endpoint ep (boost::asio::ip::address_v4 (be32toh (address)), be16toh (port)); // Alice's address/port
auto session = m_Server.FindSession (ep); // find session with Alice auto session = m_Server.FindSession (ep); // find session with Alice
if (session) if (session)
session->Send (PAYLOAD_TYPE_PEER_TEST, buf1, len); // back to Alice session->Send (PAYLOAD_TYPE_PEER_TEST, buf1, len); // back to Alice
m_Server.RemovePeerTest (nonce); // nonce has been used
break; break;
} }
case ePeerTestParticipantCharlie: case ePeerTestParticipantCharlie:
{ {
LogPrint (eLogDebug, "SSU peer test from Alice. We are Charlie"); LogPrint (eLogDebug, "SSU peer test from Alice. We are Charlie");
m_Server.RemovePeerTest (nonce); // nonce has been used
SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (), SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (),
senderEndpoint.port (), introKey); // to Alice with her actual address senderEndpoint.port (), introKey); // to Alice with her actual address
m_Server.RemovePeerTest (nonce); // nonce has been used
break; break;
} }
// test not found // test not found

2
SSUSession.h

@ -115,7 +115,7 @@ namespace transport
void Failed (); void Failed ();
void ScheduleConnectTimer (); void ScheduleConnectTimer ();
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 (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint);
void SendPeerTest (uint32_t nonce, uint32_t address, uint16_t port, const uint8_t * introKey, bool toAddress = true, bool sendAddress = true); void SendPeerTest (uint32_t nonce, uint32_t address, uint16_t port, const uint8_t * introKey, bool toAddress = true, bool sendAddress = true);
void ProcessData (uint8_t * buf, size_t len); void ProcessData (uint8_t * buf, size_t len);
void SendSesionDestroyed (); void SendSesionDestroyed ();

Loading…
Cancel
Save