set correct statuc code for peer test

This commit is contained in:
orignal 2022-06-05 14:59:33 -04:00
parent 0176e5cf18
commit 55e4bf6b65
2 changed files with 34 additions and 7 deletions

View File

@ -1022,7 +1022,6 @@ namespace transport
break;
case eSSU2BlkRelayTagRequest:
LogPrint (eLogDebug, "SSU2: RelayTagRequest");
HandleRelayRequest (buf + offset, size);
if (!m_RelayTag)
{
RAND_bytes ((uint8_t *)&m_RelayTag, 4);
@ -1305,7 +1304,16 @@ namespace transport
switch (buf[0]) // msg
{
case 1: // Bob from Alice
{
// TODO: find Charlie
uint8_t payload[SSU2_MAX_PAYLOAD_SIZE], zeroHash[32] = {0};
size_t payloadSize = CreatePeerTestBlock (payload, SSU2_MAX_PAYLOAD_SIZE, 4,
eSSU2PeerTestCodeBobNoCharlieAvailable, zeroHash, buf + 3, len - 3);
if (payloadSize < SSU2_MAX_PAYLOAD_SIZE)
payloadSize += CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize);
SendData (payload, payloadSize);
break;
}
case 2: // Charlie from Bob
break;
case 3: // Bob from Charlie
@ -1314,7 +1322,8 @@ namespace transport
if (it != m_PeerTests.end () && it->second.first)
{
uint8_t payload[SSU2_MAX_PAYLOAD_SIZE];
size_t payloadSize = CreatePeerTestBlock (payload, SSU2_MAX_PAYLOAD_SIZE, 4, buf + 3, buf + 35, len -35);
size_t payloadSize = CreatePeerTestBlock (payload, SSU2_MAX_PAYLOAD_SIZE, 4,
(SSU2PeerTestCode)buf[1], GetRemoteIdentity ()->GetIdentHash (), buf + 3, len - 3);
if (payloadSize < SSU2_MAX_PAYLOAD_SIZE)
payloadSize += CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize);
it->second.first->SendData (payload, payloadSize);
@ -1589,7 +1598,7 @@ namespace transport
return payloadSize + 3;
}
size_t SSU2Session::CreatePeerTestBlock (uint8_t * buf, size_t len, uint8_t msg,
size_t SSU2Session::CreatePeerTestBlock (uint8_t * buf, size_t len, uint8_t msg, SSU2PeerTestCode code,
const uint8_t * routerHash, const uint8_t * signedData, size_t signedDataLen)
{
buf[0] = eSSU2BlkPeerTest;
@ -1598,7 +1607,7 @@ namespace transport
if (payloadSize + 3 > len) return 0;
htobe16buf (buf + 1, payloadSize); // size
buf[3] = msg; // msg
buf[4] = 0; // code, TODO:
buf[4] = (uint8_t)code; // code
buf[5] = 0; //flag
size_t offset = 6;
if (routerHash)
@ -1628,7 +1637,8 @@ namespace transport
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
s.Insert (signedData, 10 + asz); // ver, nonce, ts, asz, Alice's endpoint
s.Sign (i2p::context.GetPrivateKeys (), signedData + 10 + asz);
return CreatePeerTestBlock (buf, len, 1, nullptr, signedData, 10 + asz + i2p::context.GetIdentity ()->GetSignatureLen ());
return CreatePeerTestBlock (buf, len, 1, eSSU2PeerTestCodeAccept, nullptr,
signedData, 10 + asz + i2p::context.GetIdentity ()->GetSignatureLen ());
}
std::shared_ptr<const i2p::data::RouterInfo> SSU2Session::ExtractRouterInfo (const uint8_t * buf, size_t size)

View File

@ -86,6 +86,23 @@ namespace transport
eSSU2SessionStateFailed
};
enum SSU2PeerTestCode
{
eSSU2PeerTestCodeAccept = 0,
eSSU2PeerTestCodeBobReasonUnspecified = 1,
eSSU2PeerTestCodeBobNoCharlieAvailable = 2,
eSSU2PeerTestCodeBobLimitExceeded = 3,
eSSU2PeerTestCodeBobSignatureFailure = 4,
eSSU2PeerTestCodeCharlieReasonUnspecified = 64,
eSSU2PeerTestCodeCharlieUnsupportedAddress = 65,
eSSU2PeerTestCodeCharlieLimitExceeded = 66,
eSSU2PeerTestCodeCharlieSignatureFailure = 67,
eSSU2PeerTestCodeCharlieAliceIsAlreadyConnected = 68,
eSSU2PeerTestCodeCharlieAliceIsBanned = 69,
eSSU2PeerTestCodeCharlieAliceIsUnknown = 70,
eSSU2PeerTestCodeUnspecified = 128
};
struct SSU2IncompleteMessage
{
struct Fragment
@ -218,7 +235,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 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 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, 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
private: