Browse Source

eliminate extra pointers for tunnel hops

pull/1707/head
orignal 3 years ago
parent
commit
9abd383014
  1. 19
      libi2pd/Tunnel.cpp
  2. 2
      libi2pd/Tunnel.h

19
libi2pd/Tunnel.cpp

@ -156,6 +156,7 @@ namespace tunnel
} }
bool established = true; bool established = true;
size_t numHops = 0;
hop = m_Config->GetFirstHop (); hop = m_Config->GetFirstHop ();
while (hop) while (hop)
{ {
@ -168,18 +169,20 @@ namespace tunnel
// if any of participants declined the tunnel is not established // if any of participants declined the tunnel is not established
established = false; established = false;
hop = hop->next; hop = hop->next;
numHops++;
} }
if (established) if (established)
{ {
// create tunnel decryptions from layer and iv keys in reverse order // create tunnel decryptions from layer and iv keys in reverse order
m_Hops.resize (numHops);
hop = m_Config->GetLastHop (); hop = m_Config->GetLastHop ();
int i = 0;
while (hop) while (hop)
{ {
auto tunnelHop = new TunnelHop; m_Hops[i].ident = hop->ident;
tunnelHop->ident = hop->ident; m_Hops[i].decryption.SetKeys (hop->layerKey, hop->ivKey);
tunnelHop->decryption.SetKeys (hop->layerKey, hop->ivKey);
m_Hops.push_back (std::unique_ptr<TunnelHop>(tunnelHop));
hop = hop->prev; hop = hop->prev;
i++;
} }
m_IsShortBuildMessage = m_Config->IsShort (); m_IsShortBuildMessage = m_Config->IsShort ();
m_FarEndTransports = m_Config->GetFarEndTransports (); m_FarEndTransports = m_Config->GetFarEndTransports ();
@ -201,7 +204,7 @@ namespace tunnel
uint8_t * outPayload = out->GetPayload () + 4; uint8_t * outPayload = out->GetPayload () + 4;
for (auto& it: m_Hops) for (auto& it: m_Hops)
{ {
it->decryption.Decrypt (inPayload, outPayload); it.decryption.Decrypt (inPayload, outPayload);
inPayload = outPayload; inPayload = outPayload;
} }
} }
@ -222,8 +225,8 @@ namespace tunnel
{ {
// hops are in inverted order // hops are in inverted order
std::vector<std::shared_ptr<const i2p::data::IdentityEx> > ret; std::vector<std::shared_ptr<const i2p::data::IdentityEx> > ret;
for (auto& it: m_Hops) for (const auto& it: m_Hops)
ret.push_back (it->ident); ret.push_back (it.ident);
return ret; return ret;
} }
@ -239,7 +242,7 @@ namespace tunnel
for (auto it = m_Hops.rbegin (); it != m_Hops.rend (); it++) for (auto it = m_Hops.rbegin (); it != m_Hops.rend (); it++)
{ {
s << " &#8658; "; s << " &#8658; ";
s << i2p::data::GetIdentHashAbbreviation ((*it)->ident->GetIdentHash ()); s << i2p::data::GetIdentHashAbbreviation ((*it).ident->GetIdentHash ());
} }
} }

2
libi2pd/Tunnel.h

@ -114,7 +114,7 @@ namespace tunnel
private: private:
std::shared_ptr<const TunnelConfig> m_Config; std::shared_ptr<const TunnelConfig> m_Config;
std::vector<std::unique_ptr<TunnelHop> > m_Hops; std::vector<TunnelHop> m_Hops;
bool m_IsShortBuildMessage; bool m_IsShortBuildMessage;
std::shared_ptr<TunnelPool> m_Pool; // pool, tunnel belongs to, or null std::shared_ptr<TunnelPool> m_Pool; // pool, tunnel belongs to, or null
TunnelState m_State; TunnelState m_State;

Loading…
Cancel
Save