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