Browse Source

use reference instead naked pointer to tunnel in tunnel gateway

pull/2101/merge
orignal 5 days ago
parent
commit
fcc70025fd
  1. 2
      libi2pd/TransitTunnel.h
  2. 2
      libi2pd/Tunnel.h
  3. 8
      libi2pd/TunnelGateway.cpp
  4. 4
      libi2pd/TunnelGateway.h

2
libi2pd/TransitTunnel.h

@ -73,7 +73,7 @@ namespace tunnel
const i2p::data::IdentHash& nextIdent, uint32_t nextTunnelID, const i2p::data::IdentHash& nextIdent, uint32_t nextTunnelID,
const i2p::crypto::AESKey& layerKey, const i2p::crypto::AESKey& ivKey): const i2p::crypto::AESKey& layerKey, const i2p::crypto::AESKey& ivKey):
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID,
layerKey, ivKey), m_Gateway(this) {}; layerKey, ivKey), m_Gateway(*this) {};
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) override; void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) override;
void FlushTunnelDataMsgs () override; void FlushTunnelDataMsgs () override;

2
libi2pd/Tunnel.h

@ -139,7 +139,7 @@ namespace tunnel
public: public:
OutboundTunnel (std::shared_ptr<const TunnelConfig> config): OutboundTunnel (std::shared_ptr<const TunnelConfig> config):
Tunnel (config), m_Gateway (this), m_EndpointIdentHash (config->GetLastIdentHash ()) {}; Tunnel (config), m_Gateway (*this), m_EndpointIdentHash (config->GetLastIdentHash ()) {};
void SendTunnelDataMsgTo (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr<i2p::I2NPMessage> msg); void SendTunnelDataMsgTo (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr<i2p::I2NPMessage> msg);
virtual void SendTunnelDataMsgs (const std::vector<TunnelMessageBlock>& msgs); // multiple messages virtual void SendTunnelDataMsgs (const std::vector<TunnelMessageBlock>& msgs); // multiple messages

8
libi2pd/TunnelGateway.cpp

@ -227,8 +227,8 @@ namespace tunnel
for (auto& tunnelMsg : tunnelDataMsgs) for (auto& tunnelMsg : tunnelDataMsgs)
{ {
auto newMsg = CreateEmptyTunnelDataMsg (false); auto newMsg = CreateEmptyTunnelDataMsg (false);
m_Tunnel->EncryptTunnelMsg (tunnelMsg, newMsg); m_Tunnel.EncryptTunnelMsg (tunnelMsg, newMsg);
htobe32buf (newMsg->GetPayload (), m_Tunnel->GetNextTunnelID ()); htobe32buf (newMsg->GetPayload (), m_Tunnel.GetNextTunnelID ());
newMsg->FillI2NPMessageHeader (eI2NPTunnelData); newMsg->FillI2NPMessageHeader (eI2NPTunnelData);
if (tunnelMsg->onDrop) newMsg->onDrop = tunnelMsg->onDrop; if (tunnelMsg->onDrop) newMsg->onDrop = tunnelMsg->onDrop;
newTunnelMsgs.push_back (newMsg); newTunnelMsgs.push_back (newMsg);
@ -254,7 +254,7 @@ namespace tunnel
else // still pending else // still pending
{ {
// send through transports, but don't update pedning transport // send through transports, but don't update pedning transport
i2p::transport::transports.SendMessages (m_Tunnel->GetNextIdentHash (), std::move (newTunnelMsgs)); i2p::transport::transports.SendMessages (m_Tunnel.GetNextIdentHash (), std::move (newTunnelMsgs));
return; return;
} }
} }
@ -264,7 +264,7 @@ namespace tunnel
m_CurrentTransport->SendI2NPMessages (newTunnelMsgs); m_CurrentTransport->SendI2NPMessages (newTunnelMsgs);
else // no session yet else // no session yet
// send through transports // send through transports
m_PendingTransport = i2p::transport::transports.SendMessages (m_Tunnel->GetNextIdentHash (), std::move (newTunnelMsgs)); m_PendingTransport = i2p::transport::transports.SendMessages (m_Tunnel.GetNextIdentHash (), std::move (newTunnelMsgs));
} }
} }
} }

4
libi2pd/TunnelGateway.h

@ -47,7 +47,7 @@ namespace tunnel
{ {
public: public:
TunnelGateway (TunnelBase * tunnel): TunnelGateway (TunnelBase& tunnel):
m_Tunnel (tunnel), m_NumSentBytes (0) {}; m_Tunnel (tunnel), m_NumSentBytes (0) {};
void SendTunnelDataMsg (const TunnelMessageBlock& block); void SendTunnelDataMsg (const TunnelMessageBlock& block);
void PutTunnelDataMsg (const TunnelMessageBlock& block); void PutTunnelDataMsg (const TunnelMessageBlock& block);
@ -56,7 +56,7 @@ namespace tunnel
private: private:
TunnelBase * m_Tunnel; TunnelBase& m_Tunnel;
TunnelGatewayBuffer m_Buffer; TunnelGatewayBuffer m_Buffer;
size_t m_NumSentBytes; size_t m_NumSentBytes;
std::shared_ptr<i2p::transport::TransportSession> m_CurrentTransport; std::shared_ptr<i2p::transport::TransportSession> m_CurrentTransport;

Loading…
Cancel
Save