mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-23 17:36:37 +02:00
create SSU2 session for peer test msgs 5-7
This commit is contained in:
parent
a04abd304a
commit
0cf9478cd4
2 changed files with 15 additions and 6 deletions
|
@ -109,8 +109,19 @@ namespace transport
|
||||||
void SSU2Session::SendPeerTest ()
|
void SSU2Session::SendPeerTest ()
|
||||||
{
|
{
|
||||||
// we are Alice
|
// we are Alice
|
||||||
|
uint32_t nonce;
|
||||||
|
RAND_bytes ((uint8_t *)&nonce, 4);
|
||||||
|
auto ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
|
// session for message 5
|
||||||
|
auto session = std::make_shared<SSU2Session> (m_Server);
|
||||||
|
session->SetState (eSSU2SessionStatePeerTest);
|
||||||
|
m_PeerTests.emplace (nonce, std::make_pair (session, ts));
|
||||||
|
session->m_SourceConnID = htobe64 (((uint64_t)nonce << 32) | nonce);
|
||||||
|
session->m_DestConnID = ~session->m_SourceConnID;
|
||||||
|
m_Server.AddSession (session);
|
||||||
|
// peer test block
|
||||||
uint8_t payload[SSU2_MAX_PAYLOAD_SIZE];
|
uint8_t payload[SSU2_MAX_PAYLOAD_SIZE];
|
||||||
size_t payloadSize = CreatePeerTestBlock (payload, SSU2_MAX_PAYLOAD_SIZE);
|
size_t payloadSize = CreatePeerTestBlock (payload, SSU2_MAX_PAYLOAD_SIZE, nonce);
|
||||||
payloadSize += CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize);
|
payloadSize += CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize);
|
||||||
SendData (payload, payloadSize);
|
SendData (payload, payloadSize);
|
||||||
}
|
}
|
||||||
|
@ -1316,7 +1327,7 @@ namespace transport
|
||||||
auto it = m_PeerTests.find (nonce);
|
auto it = m_PeerTests.find (nonce);
|
||||||
if (it != m_PeerTests.end ())
|
if (it != m_PeerTests.end ())
|
||||||
{
|
{
|
||||||
// TODO: send to Charlie
|
// TODO: update Charlie's session RouterInfo
|
||||||
m_PeerTests.erase (it);
|
m_PeerTests.erase (it);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1593,13 +1604,11 @@ namespace transport
|
||||||
return payloadSize + 3;
|
return payloadSize + 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SSU2Session::CreatePeerTestBlock (uint8_t * buf, size_t len)
|
size_t SSU2Session::CreatePeerTestBlock (uint8_t * buf, size_t len, uint32_t nonce)
|
||||||
{
|
{
|
||||||
auto localAddress = FindLocalAddress ();
|
auto localAddress = FindLocalAddress ();
|
||||||
if (!localAddress) return 0;
|
if (!localAddress) return 0;
|
||||||
// signed data
|
// signed data
|
||||||
uint32_t nonce;
|
|
||||||
RAND_bytes ((uint8_t *)&nonce, 4);
|
|
||||||
auto ts = i2p::util::GetSecondsSinceEpoch ();
|
auto ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
uint8_t signedData[96];
|
uint8_t signedData[96];
|
||||||
signedData[0] = 2; // ver
|
signedData[0] = 2; // ver
|
||||||
|
|
|
@ -219,7 +219,7 @@ namespace transport
|
||||||
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);
|
size_t CreatePeerTestBlock (uint8_t * buf, size_t len, uint8_t msg, const uint8_t * routerHash, const uint8_t * signedData, size_t signedDataLen);
|
||||||
size_t CreatePeerTestBlock (uint8_t * buf, size_t len); // Alice
|
size_t CreatePeerTestBlock (uint8_t * buf, size_t len, uint32_t nonce); // Alice
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue