mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 20:44:39 +00:00
send token in relay response block
This commit is contained in:
parent
28db337166
commit
d375299fa9
@ -887,7 +887,8 @@ namespace transport
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSU2Session::SendHolePunch (uint32_t nonce, const boost::asio::ip::udp::endpoint& ep, const uint8_t * introKey)
|
void SSU2Session::SendHolePunch (uint32_t nonce, const boost::asio::ip::udp::endpoint& ep,
|
||||||
|
const uint8_t * introKey, uint64_t token)
|
||||||
{
|
{
|
||||||
// we are Charlie
|
// we are Charlie
|
||||||
Header header;
|
Header header;
|
||||||
@ -910,7 +911,7 @@ namespace transport
|
|||||||
size_t payloadSize = 7;
|
size_t payloadSize = 7;
|
||||||
payloadSize += CreateAddressBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize, ep);
|
payloadSize += CreateAddressBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize, ep);
|
||||||
payloadSize += CreateRelayResponseBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize,
|
payloadSize += CreateRelayResponseBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize,
|
||||||
eSSU2RelayResponseCodeAccept ,nonce, true);
|
eSSU2RelayResponseCodeAccept, nonce, true, token);
|
||||||
payloadSize += CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize);
|
payloadSize += CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize);
|
||||||
// encrypt
|
// encrypt
|
||||||
uint8_t n[12];
|
uint8_t n[12];
|
||||||
@ -1365,7 +1366,7 @@ namespace transport
|
|||||||
// send relay response back to Alice
|
// send relay response back to Alice
|
||||||
uint8_t payload[SSU2_MAX_PAYLOAD_SIZE];
|
uint8_t payload[SSU2_MAX_PAYLOAD_SIZE];
|
||||||
size_t payloadSize = CreateRelayResponseBlock (payload, SSU2_MAX_PAYLOAD_SIZE,
|
size_t payloadSize = CreateRelayResponseBlock (payload, SSU2_MAX_PAYLOAD_SIZE,
|
||||||
eSSU2RelayResponseCodeBobRelayTagNotFound, bufbe32toh (buf + 1), false);
|
eSSU2RelayResponseCodeBobRelayTagNotFound, bufbe32toh (buf + 1), false, 0);
|
||||||
payloadSize += CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize);
|
payloadSize += CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize);
|
||||||
SendData (payload, payloadSize);
|
SendData (payload, payloadSize);
|
||||||
return;
|
return;
|
||||||
@ -1393,6 +1394,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
// we are Charlie
|
// we are Charlie
|
||||||
SSU2RelayResponseCode code = eSSU2RelayResponseCodeAccept;
|
SSU2RelayResponseCode code = eSSU2RelayResponseCodeAccept;
|
||||||
|
uint64_t token = 0;
|
||||||
auto r = i2p::data::netdb.FindRouter (buf + 1); // Alice
|
auto r = i2p::data::netdb.FindRouter (buf + 1); // Alice
|
||||||
if (r)
|
if (r)
|
||||||
{
|
{
|
||||||
@ -1413,7 +1415,10 @@ namespace transport
|
|||||||
if (addr)
|
if (addr)
|
||||||
{
|
{
|
||||||
if (m_Server.IsSupported (ep.address ()))
|
if (m_Server.IsSupported (ep.address ()))
|
||||||
SendHolePunch (bufbe32toh (buf + 33), ep, addr->i);
|
{
|
||||||
|
token = m_Server.GetIncomingToken (ep);
|
||||||
|
SendHolePunch (bufbe32toh (buf + 33), ep, addr->i, token);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
code = eSSU2RelayResponseCodeCharlieUnsupportedAddress;
|
code = eSSU2RelayResponseCodeCharlieUnsupportedAddress;
|
||||||
}
|
}
|
||||||
@ -1438,7 +1443,7 @@ namespace transport
|
|||||||
// send relay response to Bob
|
// send relay response to Bob
|
||||||
uint8_t payload[SSU2_MAX_PAYLOAD_SIZE];
|
uint8_t payload[SSU2_MAX_PAYLOAD_SIZE];
|
||||||
size_t payloadSize = CreateRelayResponseBlock (payload, SSU2_MAX_PAYLOAD_SIZE,
|
size_t payloadSize = CreateRelayResponseBlock (payload, SSU2_MAX_PAYLOAD_SIZE,
|
||||||
code, bufbe32toh (buf + 33), true);
|
code, bufbe32toh (buf + 33), true, token);
|
||||||
payloadSize += CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize);
|
payloadSize += CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize);
|
||||||
SendData (payload, payloadSize);
|
SendData (payload, payloadSize);
|
||||||
}
|
}
|
||||||
@ -1959,7 +1964,7 @@ namespace transport
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t SSU2Session::CreateRelayResponseBlock (uint8_t * buf, size_t len,
|
size_t SSU2Session::CreateRelayResponseBlock (uint8_t * buf, size_t len,
|
||||||
SSU2RelayResponseCode code, uint32_t nonce, bool endpoint)
|
SSU2RelayResponseCode code, uint32_t nonce, bool endpoint, uint64_t token)
|
||||||
{
|
{
|
||||||
buf[0] = eSSU2BlkRelayResponse;
|
buf[0] = eSSU2BlkRelayResponse;
|
||||||
buf[3] = 0; // flag
|
buf[3] = 0; // flag
|
||||||
@ -1981,6 +1986,11 @@ namespace transport
|
|||||||
s.Insert (buf + 5, 10 + csz); // nonce, timestamp, ver, csz and Charlie's endpoint
|
s.Insert (buf + 5, 10 + csz); // nonce, timestamp, ver, csz and Charlie's endpoint
|
||||||
s.Sign (i2p::context.GetPrivateKeys (), buf + 15 + csz);
|
s.Sign (i2p::context.GetPrivateKeys (), buf + 15 + csz);
|
||||||
size_t payloadSize = 12 + csz + i2p::context.GetIdentity ()->GetSignatureLen ();
|
size_t payloadSize = 12 + csz + i2p::context.GetIdentity ()->GetSignatureLen ();
|
||||||
|
if (!code)
|
||||||
|
{
|
||||||
|
memcpy (buf + payloadSize, &token, 8);
|
||||||
|
payloadSize += 8;
|
||||||
|
}
|
||||||
htobe16buf (buf + 1, payloadSize); // size
|
htobe16buf (buf + 1, payloadSize); // size
|
||||||
return payloadSize + 3;
|
return payloadSize + 3;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ namespace transport
|
|||||||
uint32_t SendData (const uint8_t * buf, size_t len); // returns packet num
|
uint32_t SendData (const uint8_t * buf, size_t len); // returns packet num
|
||||||
void SendQuickAck ();
|
void SendQuickAck ();
|
||||||
void SendTermination ();
|
void SendTermination ();
|
||||||
void SendHolePunch (uint32_t nonce, const boost::asio::ip::udp::endpoint& ep, const uint8_t * introKey);
|
void SendHolePunch (uint32_t nonce, const boost::asio::ip::udp::endpoint& ep, const uint8_t * introKey, uint64_t token);
|
||||||
void SendPeerTest (uint8_t msg, const uint8_t * signedData, size_t signedDataLen, const uint8_t * introKey); // PeerTest message
|
void SendPeerTest (uint8_t msg, const uint8_t * signedData, size_t signedDataLen, const uint8_t * introKey); // PeerTest message
|
||||||
|
|
||||||
void HandlePayload (const uint8_t * buf, size_t len);
|
void HandlePayload (const uint8_t * buf, size_t len);
|
||||||
@ -257,7 +257,7 @@ namespace transport
|
|||||||
size_t CreateFirstFragmentBlock (uint8_t * buf, size_t len, std::shared_ptr<I2NPMessage> msg);
|
size_t CreateFirstFragmentBlock (uint8_t * buf, size_t len, std::shared_ptr<I2NPMessage> msg);
|
||||||
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, SSU2RelayResponseCode code, uint32_t nonce, bool endpoint); // add endpoint for Chralie and no endpoint for Bob
|
size_t CreateRelayResponseBlock (uint8_t * buf, size_t len, SSU2RelayResponseCode code, uint32_t nonce, bool endpoint, uint64_t token); // add endpoint for Chralie and no endpoint for Bob
|
||||||
size_t CreatePeerTestBlock (uint8_t * buf, size_t len, uint8_t msg, SSU2PeerTestCode code, const uint8_t * routerHash, const uint8_t * signedData, size_t signedDataLen);
|
size_t CreatePeerTestBlock (uint8_t * buf, size_t len, uint8_t msg, SSU2PeerTestCode code, const uint8_t * routerHash, const uint8_t * signedData, size_t signedDataLen);
|
||||||
size_t CreatePeerTestBlock (uint8_t * buf, size_t len, uint32_t nonce); // Alice
|
size_t CreatePeerTestBlock (uint8_t * buf, size_t len, uint32_t nonce); // Alice
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user