Browse Source

copy peer test block

pull/1756/head
orignal 3 years ago
parent
commit
2cd3ebbdb3
  1. 21
      libi2pd/SSU2.cpp
  2. 1
      libi2pd/SSU2.h

21
libi2pd/SSU2.cpp

@ -1292,7 +1292,11 @@ namespace transport
auto it = m_PeerTests.find (nonce); auto it = m_PeerTests.find (nonce);
if (it != m_PeerTests.end () && it->second.first) if (it != m_PeerTests.end () && it->second.first)
{ {
// TODO uint8_t payload[SSU2_MAX_PAYLOAD_SIZE];
size_t payloadSize = CreatePeerTestBlock (payload, SSU2_MAX_PAYLOAD_SIZE, 4, buf + 3, buf + 35, len -35);
if (payloadSize < SSU2_MAX_PAYLOAD_SIZE)
payloadSize += CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize);
it->second.first->SendData (payload, payloadSize);
} }
break; break;
} }
@ -1536,6 +1540,21 @@ namespace transport
htobe16buf (buf + 1, payloadSize); // size htobe16buf (buf + 1, payloadSize); // size
return payloadSize + 3; return payloadSize + 3;
} }
size_t SSU2Session::CreatePeerTestBlock (uint8_t * buf, size_t len, uint8_t msg,
const uint8_t * routerHash, const uint8_t * signedData, size_t signedDataLen)
{
buf[0] = eSSU2BlkPeerTest;
size_t payloadSize = 3/* msg, code, flag */ + 32/* router hash */ + signedDataLen;
if (payloadSize + 3 > len) return 0;
htobe16buf (buf + 1, payloadSize); // size
buf[3] = msg; // msg
buf[4] = 0; // code, TODO:
buf[5] = 0; //flag
memcpy (buf + 6, routerHash, 32); // router hash
memcpy (buf + 38, signedData, signedDataLen);
return payloadSize + 3;
}
std::shared_ptr<const i2p::data::RouterInfo> SSU2Session::ExtractRouterInfo (const uint8_t * buf, size_t size) std::shared_ptr<const i2p::data::RouterInfo> SSU2Session::ExtractRouterInfo (const uint8_t * buf, size_t size)
{ {

1
libi2pd/SSU2.h

@ -216,6 +216,7 @@ namespace transport
size_t CreateFollowOnFragmentBlock (uint8_t * buf, size_t len, std::shared_ptr<I2NPMessage> msg, uint8_t& fragmentNum, uint32_t msgID); size_t CreateFollowOnFragmentBlock (uint8_t * buf, size_t len, std::shared_ptr<I2NPMessage> msg, uint8_t& fragmentNum, uint32_t msgID);
size_t CreateRelayIntroBlock (uint8_t * buf, size_t len, const uint8_t * introData, size_t introDataLen); size_t CreateRelayIntroBlock (uint8_t * buf, size_t len, const uint8_t * introData, size_t introDataLen);
size_t CreateRelayResponseBlock (uint8_t * buf, size_t len, uint32_t nonce); // Charlie size_t CreateRelayResponseBlock (uint8_t * buf, size_t len, uint32_t nonce); // Charlie
size_t CreatePeerTestBlock (uint8_t * buf, size_t len, uint8_t msg, const uint8_t * routerHash, const uint8_t * signedData, size_t signedDataLen);
private: private:

Loading…
Cancel
Save