mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-10 19:38:28 +01:00
lazy creation of TunnelEnpoint for transit tunnel
This commit is contained in:
parent
dcd15cc244
commit
2a4403f1e0
2 changed files with 18 additions and 11 deletions
|
@ -131,27 +131,35 @@ namespace tunnel
|
|||
|
||||
LogPrint (eLogDebug, "TransitTunnel: handle msg for endpoint ", GetTunnelID ());
|
||||
std::lock_guard<std::mutex> l(m_HandleMutex);
|
||||
m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg);
|
||||
if (!m_Endpoint) m_Endpoint = std::make_unique<TunnelEndpoint>(false); // transit endpoint is always outbound
|
||||
m_Endpoint->HandleDecryptedTunnelDataMsg (newMsg);
|
||||
}
|
||||
|
||||
void TransitTunnelEndpoint::FlushTunnelDataMsgs ()
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_HandleMutex);
|
||||
m_Endpoint.FlushI2NPMsgs ();
|
||||
if (m_Endpoint)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_HandleMutex);
|
||||
m_Endpoint->FlushI2NPMsgs ();
|
||||
}
|
||||
}
|
||||
|
||||
void TransitTunnelEndpoint::Cleanup ()
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_HandleMutex);
|
||||
m_Endpoint.Cleanup ();
|
||||
if (m_Endpoint)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_HandleMutex);
|
||||
m_Endpoint->Cleanup ();
|
||||
}
|
||||
}
|
||||
|
||||
std::string TransitTunnelEndpoint::GetNextPeerName () const
|
||||
{
|
||||
auto hash = m_Endpoint.GetCurrentHash ();
|
||||
if (!m_Endpoint) return "";
|
||||
auto hash = m_Endpoint->GetCurrentHash ();
|
||||
if (hash)
|
||||
{
|
||||
const auto& sender = m_Endpoint.GetSender ();
|
||||
const auto& sender = m_Endpoint->GetSender ();
|
||||
if (sender)
|
||||
{
|
||||
auto transport = sender->GetCurrentTransport ();
|
||||
|
|
|
@ -97,20 +97,19 @@ namespace tunnel
|
|||
TransitTunnelEndpoint (uint32_t receiveTunnelID,
|
||||
const i2p::data::IdentHash& nextIdent, uint32_t nextTunnelID,
|
||||
const i2p::crypto::AESKey& layerKey, const i2p::crypto::AESKey& ivKey):
|
||||
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, layerKey, ivKey),
|
||||
m_Endpoint (false) {}; // transit endpoint is always outbound
|
||||
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, layerKey, ivKey) {};
|
||||
|
||||
void Cleanup () override;
|
||||
|
||||
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg) override;
|
||||
void FlushTunnelDataMsgs () override;
|
||||
size_t GetNumTransmittedBytes () const override { return m_Endpoint.GetNumReceivedBytes (); }
|
||||
size_t GetNumTransmittedBytes () const override { return m_Endpoint ? m_Endpoint->GetNumReceivedBytes () : 0; }
|
||||
std::string GetNextPeerName () const override;
|
||||
|
||||
private:
|
||||
|
||||
std::mutex m_HandleMutex;
|
||||
TunnelEndpoint m_Endpoint;
|
||||
std::unique_ptr<TunnelEndpoint> m_Endpoint;
|
||||
};
|
||||
|
||||
std::shared_ptr<TransitTunnel> CreateTransitTunnel (uint32_t receiveTunnelID,
|
||||
|
|
Loading…
Add table
Reference in a new issue