Browse Source

use SSU if NTCP is not available

pull/46/head
orignal 11 years ago
parent
commit
4862b594e8
  1. 19
      SSU.cpp
  2. 18
      Transports.cpp

19
SSU.cpp

@ -528,10 +528,13 @@ namespace ssu
uint32_t fragmentNum = 0; uint32_t fragmentNum = 0;
while (len > 0) while (len > 0)
{ {
uint8_t buf[SSU_MTU + 18], iv[16]; uint8_t buf[SSU_MTU + 18], iv[16], * payload = buf + sizeof (SSUHeader);
buf[0] = DATA_FLAG_WANT_REPLY; // for compatibility *payload = DATA_FLAG_WANT_REPLY; // for compatibility
buf[1] = 1; // always 1 message fragment per message payload++;
*(uint32_t *)(buf + 2) = msgID; *payload = 1; // always 1 message fragment per message
payload++;
*(uint32_t *)payload = msgID;
payload += 4;
bool isLast = (len <= payloadSize); bool isLast = (len <= payloadSize);
size_t size = isLast ? len : payloadSize; size_t size = isLast ? len : payloadSize;
uint32_t fragmentInfo = (fragmentNum << 17); uint32_t fragmentInfo = (fragmentNum << 17);
@ -540,10 +543,11 @@ namespace ssu
fragmentInfo |= size; fragmentInfo |= size;
fragmentInfo = htobe32 (fragmentInfo); fragmentInfo = htobe32 (fragmentInfo);
memcpy (buf + 6, (uint8_t *)(&fragmentInfo) + 1, 3); memcpy (payload, (uint8_t *)(&fragmentInfo) + 1, 3);
memcpy (buf + 9, msgBuf, size); payload += 3;
memcpy (payload, msgBuf, size);
size += sizeof (SSUHeader) + 9; size += payload - buf;
if (size % 16) // make sure 16 bytes boundary if (size % 16) // make sure 16 bytes boundary
size = (size/16 + 1)*16; size = (size/16 + 1)*16;
@ -584,6 +588,7 @@ namespace ssu
void SSUServer::Stop () void SSUServer::Stop ()
{ {
DeleteAllSessions ();
m_Socket.close (); m_Socket.close ();
} }

18
Transports.cpp

@ -168,7 +168,23 @@ namespace i2p
AddNTCPSession (session); AddNTCPSession (session);
} }
else else
LogPrint ("No NTCP addresses available"); {
// SSU always have lower prioprity than NTCP
// TODO: it shouldn't
LogPrint ("No NTCP addresses available. Trying SSU");
address = r->GetSSUAddress ();
if (address && m_SSUServer)
{
auto s = m_SSUServer->GetSession (r);
if (s)
{
s->SendI2NPMessage (msg);
return;
}
}
else
LogPrint ("No SSU addresses available");
}
} }
else else
{ {

Loading…
Cancel
Save