reuse list of addresses

This commit is contained in:
orignal 2022-11-28 19:16:21 -05:00
parent 2a6f906177
commit 949c38f5f0
2 changed files with 9 additions and 6 deletions

View File

@ -206,10 +206,9 @@ namespace data
s.read ((char *)&m_Timestamp, sizeof (m_Timestamp));
m_Timestamp = be64toh (m_Timestamp);
// read addresses
auto addresses = boost::make_shared<Addresses>();
if (!m_NewAddresses) m_NewAddresses = boost::make_shared<Addresses>();
uint8_t numAddresses;
s.read ((char *)&numAddresses, sizeof (numAddresses));
addresses->reserve (numAddresses);
for (int i = 0; i < numAddresses; i++)
{
uint8_t supportedTransports = 0;
@ -418,15 +417,19 @@ namespace data
if (supportedTransports)
{
if (!(m_SupportedTransports & supportedTransports)) // avoid duplicates
addresses->push_back(address);
m_NewAddresses->push_back(address);
m_SupportedTransports |= supportedTransports;
}
}
// update addresses
auto prev = m_Addresses;
#if (BOOST_VERSION >= 105300)
boost::atomic_store (&m_Addresses, addresses);
boost::atomic_store (&m_Addresses, m_NewAddresses);
#else
m_Addresses = addresses; // race condition
m_Addresses = m_NewAddresses; // race condition
#endif
if (prev) prev->clear ();
m_NewAddresses = prev;
// read peers
uint8_t numPeers;
s.read ((char *)&numPeers, sizeof (numPeers)); if (!s) return;

View File

@ -282,7 +282,7 @@ namespace data
std::shared_ptr<Buffer> m_Buffer;
size_t m_BufferLen;
uint64_t m_Timestamp;
boost::shared_ptr<Addresses> m_Addresses; // TODO: use std::shared_ptr and std::atomic_store for gcc >= 4.9
boost::shared_ptr<Addresses> m_Addresses, m_NewAddresses; // TODO: use std::shared_ptr and std::atomic_store for gcc >= 4.9
bool m_IsUpdated, m_IsUnreachable;
CompatibleTransports m_SupportedTransports, m_ReachableTransports;
uint8_t m_Caps;