From 1dc166f0f8334b935fa1070cb4a438753f882cf8 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 23 Jan 2015 22:05:33 -0500 Subject: [PATCH] transit tunnel gateway batching --- I2NPProtocol.cpp | 23 ++++++++++++++++------- I2NPProtocol.h | 2 +- TransitTunnel.cpp | 8 +++++++- TransitTunnel.h | 1 + 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index d0466e75..dc058d33 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -560,13 +560,17 @@ namespace i2p { if (msg) { - if (msg->GetTypeID () == eI2NPTunnelData) - { - LogPrint ("TunnelData"); - m_TunnelMsgs.push_back (msg); - } - else - HandleI2NPMessage (msg); + switch (msg->GetTypeID ()) + { + case eI2NPTunnelData: + LogPrint ("TunnelData"); + m_TunnelMsgs.push_back (msg); + break; + LogPrint ("TunnelGateway"); + m_TunnelGatewayMsgs.push_back (msg); + default: + HandleI2NPMessage (msg); + } } } @@ -577,5 +581,10 @@ namespace i2p i2p::tunnel::tunnels.PostTunnelData (m_TunnelMsgs); m_TunnelMsgs.clear (); } + if (!m_TunnelGatewayMsgs.empty ()) + { + i2p::tunnel::tunnels.PostTunnelData (m_TunnelMsgs); + m_TunnelGatewayMsgs.clear (); + } } } diff --git a/I2NPProtocol.h b/I2NPProtocol.h index 137f649f..9ae3998d 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -226,7 +226,7 @@ namespace tunnel private: - std::vector m_TunnelMsgs; + std::vector m_TunnelMsgs, m_TunnelGatewayMsgs; }; } diff --git a/TransitTunnel.cpp b/TransitTunnel.cpp index 66120c51..c1657930 100644 --- a/TransitTunnel.cpp +++ b/TransitTunnel.cpp @@ -70,9 +70,15 @@ namespace tunnel block.deliveryType = eDeliveryTypeLocal; block.data = msg; std::unique_lock l(m_SendMutex); - m_Gateway.SendTunnelDataMsg (block); + m_Gateway.PutTunnelDataMsg (block); } + void TransitTunnelGateway::FlushTunnelDataMsgs () + { + LogPrint (eLogDebug, "TransitTunnel: gateway flush"); + m_Gateway.SendBuffer (); + } + void TransitTunnelEndpoint::HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg) { EncryptTunnelMsg (tunnelMsg); diff --git a/TransitTunnel.h b/TransitTunnel.h index 1ac3be93..a2a0347f 100644 --- a/TransitTunnel.h +++ b/TransitTunnel.h @@ -73,6 +73,7 @@ namespace tunnel layerKey, ivKey), m_Gateway(this) {}; void SendTunnelDataMsg (i2p::I2NPMessage * msg); + void FlushTunnelDataMsgs (); size_t GetNumTransmittedBytes () const { return m_Gateway.GetNumSentBytes (); }; private: