diff --git a/TunnelGateway.cpp b/TunnelGateway.cpp index 9f13d84c..6ac709d2 100644 --- a/TunnelGateway.cpp +++ b/TunnelGateway.cpp @@ -10,8 +10,8 @@ namespace i2p { namespace tunnel { - TunnelGatewayBuffer::TunnelGatewayBuffer (uint32_t tunnelID): m_TunnelID (tunnelID), - m_CurrentTunnelDataMsg (nullptr), m_RemainingSize (0) + TunnelGatewayBuffer::TunnelGatewayBuffer (): + m_CurrentTunnelDataMsg (nullptr), m_RemainingSize (0) { RAND_bytes (m_NonZeroRandomBuffer, TUNNEL_DATA_MAX_PAYLOAD_SIZE); for (size_t i = 0; i < TUNNEL_DATA_MAX_PAYLOAD_SIZE; i++) @@ -165,7 +165,6 @@ namespace tunnel m_CurrentTunnelDataMsg->offset = m_CurrentTunnelDataMsg->len - TUNNEL_DATA_MSG_SIZE - I2NP_HEADER_SIZE; uint8_t * buf = m_CurrentTunnelDataMsg->GetPayload (); - htobe32buf (buf, m_TunnelID); RAND_bytes (buf + 4, 16); // original IV memcpy (payload + size, buf + 4, 16); // copy IV for checksum uint8_t hash[32]; @@ -203,15 +202,18 @@ namespace tunnel void TunnelGateway::SendBuffer () { m_Buffer.CompleteCurrentTunnelDataMessage (); - const auto & tunnelMsgs = m_Buffer.GetTunnelDataMsgs (); - for (auto& tunnelMsg : tunnelMsgs) + std::vector > newTunnelMsgs; + for (auto& tunnelMsg : m_Buffer.GetTunnelDataMsgs ()) { - m_Tunnel->EncryptTunnelMsg (tunnelMsg, tunnelMsg); - tunnelMsg->FillI2NPMessageHeader (eI2NPTunnelData); + auto newMsg = CreateEmptyTunnelDataMsg (); + m_Tunnel->EncryptTunnelMsg (tunnelMsg, newMsg); + htobe32buf (newMsg->GetPayload (), m_Tunnel->GetNextTunnelID ()); + newMsg->FillI2NPMessageHeader (eI2NPTunnelData); + newTunnelMsgs.push_back (newMsg); m_NumSentBytes += TUNNEL_DATA_MSG_SIZE; } - i2p::transport::transports.SendMessages (m_Tunnel->GetNextIdentHash (), tunnelMsgs); m_Buffer.ClearTunnelDataMsgs (); + i2p::transport::transports.SendMessages (m_Tunnel->GetNextIdentHash (), newTunnelMsgs); } } } diff --git a/TunnelGateway.h b/TunnelGateway.h index ea88317b..3642874c 100644 --- a/TunnelGateway.h +++ b/TunnelGateway.h @@ -14,10 +14,10 @@ namespace tunnel class TunnelGatewayBuffer { public: - TunnelGatewayBuffer (uint32_t tunnelID); + TunnelGatewayBuffer (); ~TunnelGatewayBuffer (); void PutI2NPMsg (const TunnelMessageBlock& block); - const std::vector >& GetTunnelDataMsgs () const { return m_TunnelDataMsgs; }; + const std::vector >& GetTunnelDataMsgs () const { return m_TunnelDataMsgs; }; void ClearTunnelDataMsgs (); void CompleteCurrentTunnelDataMessage (); @@ -27,8 +27,7 @@ namespace tunnel private: - uint32_t m_TunnelID; - std::vector > m_TunnelDataMsgs; + std::vector > m_TunnelDataMsgs; std::shared_ptr m_CurrentTunnelDataMsg; size_t m_RemainingSize; uint8_t m_NonZeroRandomBuffer[TUNNEL_DATA_MAX_PAYLOAD_SIZE]; @@ -39,7 +38,7 @@ namespace tunnel public: TunnelGateway (TunnelBase * tunnel): - m_Tunnel (tunnel), m_Buffer (tunnel->GetNextTunnelID ()), m_NumSentBytes (0) {}; + m_Tunnel (tunnel), m_NumSentBytes (0) {}; void SendTunnelDataMsg (const TunnelMessageBlock& block); void PutTunnelDataMsg (const TunnelMessageBlock& block); void SendBuffer ();