use list instead vector for addresses

This commit is contained in:
orignal 2016-07-14 14:10:38 -04:00
parent 562f320198
commit d98d091c43
3 changed files with 22 additions and 49 deletions

View File

@ -224,11 +224,11 @@ namespace i2p
m_RouterInfo.SetCaps (i2p::data::RouterInfo::eUnreachable | i2p::data::RouterInfo::eSSUTesting); // LU, B
// remove NTCP address
auto& addresses = m_RouterInfo.GetAddresses ();
for (size_t i = 0; i < addresses.size (); i++)
for (auto it = addresses.begin (); it != addresses.end (); it++)
{
if (addresses[i]->transportStyle == i2p::data::RouterInfo::eTransportNTCP)
if ((*it)->transportStyle == i2p::data::RouterInfo::eTransportNTCP)
{
addresses.erase (addresses.begin () + i);
addresses.erase (it);
break;
}
}
@ -253,12 +253,12 @@ namespace i2p
// insert NTCP back
auto& addresses = m_RouterInfo.GetAddresses ();
for (size_t i = 0; i < addresses.size (); i++)
for (auto addr : addresses)
{
if (addresses[i]->transportStyle == i2p::data::RouterInfo::eTransportSSU)
if (addr->transportStyle == i2p::data::RouterInfo::eTransportSSU)
{
// insert NTCP address with host/port from SSU
m_RouterInfo.AddNTCPAddress (addresses[i]->host.to_string ().c_str (), addresses[i]->port);
m_RouterInfo.AddNTCPAddress (addr->host.to_string ().c_str (), addr->port);
break;
}
}

View File

@ -700,28 +700,14 @@ namespace data
{
if (IsV6 ())
{
// NTCP
m_SupportedTransports &= ~eNTCPV6;
for (size_t i = 0; i < m_Addresses->size (); i++)
m_SupportedTransports &= ~(eNTCPV6 | eSSUV6);
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
{
if ((*m_Addresses)[i]->transportStyle == i2p::data::RouterInfo::eTransportNTCP &&
(*m_Addresses)[i]->host.is_v6 ())
{
m_Addresses->erase (m_Addresses->begin () + i);
break;
}
}
// SSU
m_SupportedTransports &= ~eSSUV6;
for (size_t i = 0; i < m_Addresses->size (); i++)
{
if ((*m_Addresses)[i]->transportStyle == i2p::data::RouterInfo::eTransportSSU &&
(*m_Addresses)[i]->host.is_v6 ())
{
m_Addresses->erase (m_Addresses->begin () + i);
break;
}
auto addr = *it;
if (addr->host.is_v6 ())
it = m_Addresses->erase (it);
else
it++;
}
}
}
@ -730,28 +716,14 @@ namespace data
{
if (IsV4 ())
{
// NTCP
m_SupportedTransports &= ~eNTCPV4;
for (size_t i = 0; i < m_Addresses->size (); i++)
m_SupportedTransports &= ~(eNTCPV4 | eSSUV4);
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
{
if ((*m_Addresses)[i]->transportStyle == i2p::data::RouterInfo::eTransportNTCP &&
(*m_Addresses)[i]->host.is_v4 ())
{
m_Addresses->erase (m_Addresses->begin () + i);
break;
}
}
// SSU
m_SupportedTransports &= ~eSSUV4;
for (size_t i = 0; i < m_Addresses->size (); i++)
{
if ((*m_Addresses)[i]->transportStyle == i2p::data::RouterInfo::eTransportSSU &&
(*m_Addresses)[i]->host.is_v4 ())
{
m_Addresses->erase (m_Addresses->begin () + i);
break;
}
auto addr = *it;
if (addr->host.is_v4 ())
it = m_Addresses->erase (it);
else
it++;
}
}
}

View File

@ -5,6 +5,7 @@
#include <string>
#include <map>
#include <vector>
#include <list>
#include <iostream>
#include <boost/asio.hpp>
#include "Identity.h"
@ -105,7 +106,7 @@ namespace data
return !(*this == other);
}
};
typedef std::vector<std::shared_ptr<Address> > Addresses;
typedef std::list<std::shared_ptr<Address> > Addresses;
RouterInfo ();
RouterInfo (const std::string& fullPath);