|
|
|
@ -280,7 +280,7 @@ namespace transport
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -478,7 +478,7 @@ namespace transport
|
|
|
|
|
size_t payloadSize = CreateRouterInfoBlock (payload, maxPayloadSize, i2p::context.GetSharedRouterInfo ());
|
|
|
|
|
// TODO: check is RouterInfo doesn't fit and split by two fragments
|
|
|
|
|
if (payloadSize < maxPayloadSize)
|
|
|
|
|
payloadSize += CreatePaddingBlock (payload + payloadSize, maxPayloadSize - payloadSize);
|
|
|
|
|
payloadSize += CreatePaddingBlock (payload + payloadSize, maxPayloadSize - payloadSize);
|
|
|
|
|
// KDF for Session Confirmed part 1
|
|
|
|
|
m_NoiseState->MixHash (header.buf, 16); // h = SHA256(h || header)
|
|
|
|
|
// Encrypt part 1
|
|
|
|
@ -515,7 +515,7 @@ namespace transport
|
|
|
|
|
header.ll[1] ^= CreateHeaderMask (kh2, buf + (len - 12));
|
|
|
|
|
if (header.h.type != eSSU2SessionConfirmed)
|
|
|
|
|
{
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// check if fragmented
|
|
|
|
@ -722,7 +722,7 @@ namespace transport
|
|
|
|
|
header.ll[1] ^= CreateHeaderMask (m_Address->i, buf + (len - 12));
|
|
|
|
|
if (header.h.type != eSSU2Retry)
|
|
|
|
|
{
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
uint8_t nonce[12] = {0};
|
|
|
|
@ -795,7 +795,7 @@ namespace transport
|
|
|
|
|
header.ll[1] ^= CreateHeaderMask (i2p::context.GetSSU2IntroKey (), buf + (len - 12));
|
|
|
|
|
if (header.h.type != eSSU2HolePunch)
|
|
|
|
|
{
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
uint8_t nonce[12] = {0};
|
|
|
|
@ -835,7 +835,7 @@ namespace transport
|
|
|
|
|
header.ll[1] ^= CreateHeaderMask (i2p::context.GetSSU2IntroKey (), buf + (len - 12));
|
|
|
|
|
if (header.h.type != eSSU2PeerTest)
|
|
|
|
|
{
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
uint8_t nonce[12] = {0};
|
|
|
|
@ -891,7 +891,7 @@ namespace transport
|
|
|
|
|
header.ll[1] ^= CreateHeaderMask (m_KeyDataReceive + 32, buf + (len - 12));
|
|
|
|
|
if (header.h.type != eSSU2Data)
|
|
|
|
|
{
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uint8_t payload[SSU2_MTU];
|
|
|
|
@ -1260,7 +1260,7 @@ namespace transport
|
|
|
|
|
{
|
|
|
|
|
// update Charlie's endpoint and connect
|
|
|
|
|
if (it->second.first->m_State == eSSU2SessionStateIntroduced &&
|
|
|
|
|
ExtractEndpoint (buf + 12, csz, it->second.first->m_RemoteEndpoint))
|
|
|
|
|
ExtractEndpoint (buf + 12, csz, it->second.first->m_RemoteEndpoint))
|
|
|
|
|
{
|
|
|
|
|
it->second.first->m_State = eSSU2SessionStateUnknown;
|
|
|
|
|
it->second.first->Connect ();
|
|
|
|
@ -1523,7 +1523,7 @@ namespace transport
|
|
|
|
|
{
|
|
|
|
|
buf[0] = eSSU2BlkRelayResponse;
|
|
|
|
|
buf[3] = 0; // flag
|
|
|
|
|
buf[4] = 0; // code, accept
|
|
|
|
|
buf[4] = 0; // code, accept
|
|
|
|
|
htobe32buf (buf + 5, nonce); // nonce
|
|
|
|
|
htobe32buf (buf + 9, i2p::util::GetSecondsSinceEpoch ()); // timestamp
|
|
|
|
|
buf[13] = 2; // ver
|
|
|
|
@ -1710,7 +1710,7 @@ namespace transport
|
|
|
|
|
found = true;
|
|
|
|
|
OpenSocket (boost::asio::ip::udp::endpoint (boost::asio::ip::udp::v4(), port));
|
|
|
|
|
m_ReceiveService.GetService ().post(
|
|
|
|
|
[this]()
|
|
|
|
|
[this]()
|
|
|
|
|
{
|
|
|
|
|
Receive (m_SocketV4);
|
|
|
|
|
});
|
|
|
|
@ -1720,7 +1720,7 @@ namespace transport
|
|
|
|
|
found = true;
|
|
|
|
|
OpenSocket (boost::asio::ip::udp::endpoint (boost::asio::ip::udp::v6(), port));
|
|
|
|
|
m_ReceiveService.GetService ().post(
|
|
|
|
|
[this]()
|
|
|
|
|
[this]()
|
|
|
|
|
{
|
|
|
|
|
Receive (m_SocketV6);
|
|
|
|
|
});
|
|
|
|
@ -1762,7 +1762,7 @@ namespace transport
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception& ex )
|
|
|
|
|
{
|
|
|
|
|
LogPrint (eLogError, "SSU2: Failed to bind to ", localEndpoint, ": ", ex.what());
|
|
|
|
|
LogPrint (eLogError, "SSU2: Failed to bind to ", localEndpoint, ": ", ex.what());
|
|
|
|
|
ThrowFatal ("Unable to start SSU2 transport on ", localEndpoint, ": ", ex.what ());
|
|
|
|
|
}
|
|
|
|
|
return socket;
|
|
|
|
@ -1866,7 +1866,7 @@ namespace transport
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SSU2Server::AddSessionByRouterHash (std::shared_ptr<SSU2Session> session)
|
|
|
|
|
void SSU2Server::AddSessionByRouterHash (std::shared_ptr<SSU2Session> session)
|
|
|
|
|
{
|
|
|
|
|
if (session)
|
|
|
|
|
{
|
|
|
|
@ -2065,7 +2065,7 @@ namespace transport
|
|
|
|
|
{
|
|
|
|
|
if (relayTag)
|
|
|
|
|
{
|
|
|
|
|
// introducer and tag found connect to it through SSU2
|
|
|
|
|
// introducer and tag found connect to it through SSU2
|
|
|
|
|
auto addr = address->IsV6 () ? r->GetSSU2V6Address () : r->GetSSU2V4Address ();
|
|
|
|
|
if (addr)
|
|
|
|
|
{
|
|
|
|
@ -2117,7 +2117,7 @@ namespace transport
|
|
|
|
|
if (it->second->IsEstablished ())
|
|
|
|
|
it->second->TerminateByTimeout ();
|
|
|
|
|
if (it->second == m_LastSession)
|
|
|
|
|
m_LastSession = nullptr;
|
|
|
|
|
m_LastSession = nullptr;
|
|
|
|
|
it = m_Sessions.erase (it);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|