mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
use atomic_store for addresses' list re-assignment
This commit is contained in:
parent
2ad927b677
commit
dba355eccd
|
@ -3,6 +3,8 @@
|
||||||
#include "I2PEndian.h"
|
#include "I2PEndian.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/atomic.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "Crypto.h"
|
#include "Crypto.h"
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
|
@ -17,14 +19,14 @@ namespace data
|
||||||
{
|
{
|
||||||
RouterInfo::RouterInfo (): m_Buffer (nullptr)
|
RouterInfo::RouterInfo (): m_Buffer (nullptr)
|
||||||
{
|
{
|
||||||
m_Addresses = std::make_shared<Addresses>(); // create empty list
|
m_Addresses = boost::make_shared<Addresses>(); // create empty list
|
||||||
}
|
}
|
||||||
|
|
||||||
RouterInfo::RouterInfo (const std::string& fullPath):
|
RouterInfo::RouterInfo (const std::string& fullPath):
|
||||||
m_FullPath (fullPath), m_IsUpdated (false), m_IsUnreachable (false),
|
m_FullPath (fullPath), m_IsUpdated (false), m_IsUnreachable (false),
|
||||||
m_SupportedTransports (0), m_Caps (0)
|
m_SupportedTransports (0), m_Caps (0)
|
||||||
{
|
{
|
||||||
m_Addresses = std::make_shared<Addresses>(); // create empty list
|
m_Addresses = boost::make_shared<Addresses>(); // create empty list
|
||||||
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE];
|
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE];
|
||||||
ReadFromFile ();
|
ReadFromFile ();
|
||||||
}
|
}
|
||||||
|
@ -32,7 +34,7 @@ namespace data
|
||||||
RouterInfo::RouterInfo (const uint8_t * buf, int len):
|
RouterInfo::RouterInfo (const uint8_t * buf, int len):
|
||||||
m_IsUpdated (true), m_IsUnreachable (false), m_SupportedTransports (0), m_Caps (0)
|
m_IsUpdated (true), m_IsUnreachable (false), m_SupportedTransports (0), m_Caps (0)
|
||||||
{
|
{
|
||||||
m_Addresses = std::make_shared<Addresses>(); // create empty list
|
m_Addresses = boost::make_shared<Addresses>(); // create empty list
|
||||||
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE];
|
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE];
|
||||||
memcpy (m_Buffer, buf, len);
|
memcpy (m_Buffer, buf, len);
|
||||||
m_BufferLen = len;
|
m_BufferLen = len;
|
||||||
|
@ -154,7 +156,7 @@ namespace data
|
||||||
s.read ((char *)&m_Timestamp, sizeof (m_Timestamp));
|
s.read ((char *)&m_Timestamp, sizeof (m_Timestamp));
|
||||||
m_Timestamp = be64toh (m_Timestamp);
|
m_Timestamp = be64toh (m_Timestamp);
|
||||||
// read addresses
|
// read addresses
|
||||||
auto addresses = std::make_shared<Addresses>();
|
auto addresses = boost::make_shared<Addresses>();
|
||||||
uint8_t numAddresses;
|
uint8_t numAddresses;
|
||||||
s.read ((char *)&numAddresses, sizeof (numAddresses)); if (!s) return;
|
s.read ((char *)&numAddresses, sizeof (numAddresses)); if (!s) return;
|
||||||
bool introducers = false;
|
bool introducers = false;
|
||||||
|
@ -255,7 +257,7 @@ namespace data
|
||||||
m_SupportedTransports |= supportedTransports;
|
m_SupportedTransports |= supportedTransports;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_Addresses = addresses;
|
boost::atomic_store (&m_Addresses, addresses);
|
||||||
// read peers
|
// read peers
|
||||||
uint8_t numPeers;
|
uint8_t numPeers;
|
||||||
s.read ((char *)&numPeers, sizeof (numPeers)); if (!s) return;
|
s.read ((char *)&numPeers, sizeof (numPeers)); if (!s) return;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "Profiling.h"
|
#include "Profiling.h"
|
||||||
|
|
||||||
|
@ -201,7 +202,7 @@ namespace data
|
||||||
uint8_t * m_Buffer;
|
uint8_t * m_Buffer;
|
||||||
size_t m_BufferLen;
|
size_t m_BufferLen;
|
||||||
uint64_t m_Timestamp;
|
uint64_t m_Timestamp;
|
||||||
std::shared_ptr<Addresses> m_Addresses;
|
boost::shared_ptr<Addresses> m_Addresses; // TODO: use std::shared_ptr and std::atomic_store for gcc >= 4.9
|
||||||
std::map<std::string, std::string> m_Properties;
|
std::map<std::string, std::string> m_Properties;
|
||||||
bool m_IsUpdated, m_IsUnreachable;
|
bool m_IsUpdated, m_IsUnreachable;
|
||||||
uint8_t m_SupportedTransports, m_Caps;
|
uint8_t m_SupportedTransports, m_Caps;
|
||||||
|
|
Loading…
Reference in a new issue