Browse Source

send response to recived datagram from ECIESX25519AEADRatchet session

pull/1514/head
orignal 5 years ago
parent
commit
0b1cfb2102
  1. 9
      libi2pd/Datagram.cpp
  2. 21
      libi2pd/ECIESX25519AEADRatchetSession.cpp

9
libi2pd/Datagram.cpp

@ -247,6 +247,8 @@ namespace datagram
auto path = GetSharedRoutingPath(); auto path = GetSharedRoutingPath();
if(path) if(path)
path->updateTime = i2p::util::GetSecondsSinceEpoch (); path->updateTime = i2p::util::GetSecondsSinceEpoch ();
if (m_RoutingSession && m_RoutingSession->IsRatchets ())
SendMsg (nullptr); // send empty message in case if we have some data to send
} }
std::shared_ptr<i2p::garlic::GarlicRoutingPath> DatagramSession::GetSharedRoutingPath () std::shared_ptr<i2p::garlic::GarlicRoutingPath> DatagramSession::GetSharedRoutingPath ()
@ -352,14 +354,14 @@ namespace datagram
void DatagramSession::HandleSend(std::shared_ptr<I2NPMessage> msg) void DatagramSession::HandleSend(std::shared_ptr<I2NPMessage> msg)
{ {
m_SendQueue.push_back(msg); if (msg || m_SendQueue.empty ())
m_SendQueue.push_back(msg);
// flush queue right away if full // flush queue right away if full
if(m_SendQueue.size() >= DATAGRAM_SEND_QUEUE_MAX_SIZE) FlushSendQueue(); if(m_SendQueue.size() >= DATAGRAM_SEND_QUEUE_MAX_SIZE) FlushSendQueue();
} }
void DatagramSession::FlushSendQueue () void DatagramSession::FlushSendQueue ()
{ {
std::vector<i2p::tunnel::TunnelMessageBlock> send; std::vector<i2p::tunnel::TunnelMessageBlock> send;
auto routingPath = GetSharedRoutingPath(); auto routingPath = GetSharedRoutingPath();
// if we don't have a routing path we will drop all queued messages // if we don't have a routing path we will drop all queued messages
@ -368,7 +370,8 @@ namespace datagram
for (const auto & msg : m_SendQueue) for (const auto & msg : m_SendQueue)
{ {
auto m = m_RoutingSession->WrapSingleMessage(msg); auto m = m_RoutingSession->WrapSingleMessage(msg);
send.push_back(i2p::tunnel::TunnelMessageBlock{i2p::tunnel::eDeliveryTypeTunnel,routingPath->remoteLease->tunnelGateway, routingPath->remoteLease->tunnelID, m}); if (m)
send.push_back(i2p::tunnel::TunnelMessageBlock{i2p::tunnel::eDeliveryTypeTunnel,routingPath->remoteLease->tunnelGateway, routingPath->remoteLease->tunnelID, m});
} }
routingPath->outboundTunnel->SendTunnelDataMsg(send); routingPath->outboundTunnel->SendTunnelDataMsg(send);
} }

21
libi2pd/ECIESX25519AEADRatchetSession.cpp

@ -641,6 +641,7 @@ namespace garlic
{ {
auto payload = CreatePayload (msg, m_State != eSessionStateEstablished); auto payload = CreatePayload (msg, m_State != eSessionStateEstablished);
size_t len = payload.size (); size_t len = payload.size ();
if (!len) return nullptr;
auto m = NewI2NPMessage (len + 100); // 96 + 4 auto m = NewI2NPMessage (len + 100); // 96 + 4
m->Align (12); // in order to get buf aligned to 16 (12 + 4) m->Align (12); // in order to get buf aligned to 16 (12 + 4)
uint8_t * buf = m->GetPayload () + 4; // 4 bytes for length uint8_t * buf = m->GetPayload () + 4; // 4 bytes for length
@ -708,11 +709,14 @@ namespace garlic
{ {
payloadLen += 6; payloadLen += 6;
if (m_NextSendRatchet->newKey) payloadLen += 32; if (m_NextSendRatchet->newKey) payloadLen += 32;
}
uint8_t paddingSize = 0;
if (payloadLen)
{
RAND_bytes (&paddingSize, 1);
paddingSize &= 0x0F; paddingSize++; // 1 - 16
payloadLen += paddingSize + 3;
} }
uint8_t paddingSize;
RAND_bytes (&paddingSize, 1);
paddingSize &= 0x0F; paddingSize++; // 1 - 16
payloadLen += paddingSize + 3;
std::vector<uint8_t> v(payloadLen); std::vector<uint8_t> v(payloadLen);
size_t offset = 0; size_t offset = 0;
// DateTime // DateTime
@ -785,9 +789,12 @@ namespace garlic
} }
} }
// padding // padding
v[offset] = eECIESx25519BlkPadding; offset++; if (paddingSize)
htobe16buf (v.data () + offset, paddingSize); offset += 2; {
memset (v.data () + offset, 0, paddingSize); offset += paddingSize; v[offset] = eECIESx25519BlkPadding; offset++;
htobe16buf (v.data () + offset, paddingSize); offset += 2;
memset (v.data () + offset, 0, paddingSize); offset += paddingSize;
}
return v; return v;
} }

Loading…
Cancel
Save