mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-19 01:09:58 +00:00
Merge remote-tracking branch 'purple/openssl'
This commit is contained in:
commit
88f9b69e2a
@ -12,8 +12,8 @@ namespace data
|
|||||||
{
|
{
|
||||||
i2p::fs::HashedStorage m_ProfilesStorage("peerProfiles", "p", "profile-", "txt");
|
i2p::fs::HashedStorage m_ProfilesStorage("peerProfiles", "p", "profile-", "txt");
|
||||||
|
|
||||||
RouterProfile::RouterProfile (const IdentHash& identHash):
|
RouterProfile::RouterProfile ():
|
||||||
m_IdentHash (identHash), m_LastUpdateTime (boost::posix_time::second_clock::local_time()),
|
m_LastUpdateTime (boost::posix_time::second_clock::local_time()),
|
||||||
m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0), m_NumTunnelsNonReplied (0),
|
m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0), m_NumTunnelsNonReplied (0),
|
||||||
m_NumTimesTaken (0), m_NumTimesRejected (0)
|
m_NumTimesTaken (0), m_NumTimesRejected (0)
|
||||||
{
|
{
|
||||||
@ -29,7 +29,7 @@ namespace data
|
|||||||
m_LastUpdateTime = GetTime ();
|
m_LastUpdateTime = GetTime ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterProfile::Save ()
|
void RouterProfile::Save (const IdentHash& identHash)
|
||||||
{
|
{
|
||||||
// fill sections
|
// fill sections
|
||||||
boost::property_tree::ptree participation;
|
boost::property_tree::ptree participation;
|
||||||
@ -46,7 +46,7 @@ namespace data
|
|||||||
pt.put_child (PEER_PROFILE_SECTION_USAGE, usage);
|
pt.put_child (PEER_PROFILE_SECTION_USAGE, usage);
|
||||||
|
|
||||||
// save to file
|
// save to file
|
||||||
std::string ident = m_IdentHash.ToBase64 ();
|
std::string ident = identHash.ToBase64 ();
|
||||||
std::string path = m_ProfilesStorage.Path(ident);
|
std::string path = m_ProfilesStorage.Path(ident);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -57,51 +57,64 @@ namespace data
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterProfile::Load ()
|
void RouterProfile::Load (const IdentHash& identHash)
|
||||||
{
|
{
|
||||||
std::string ident = m_IdentHash.ToBase64 ();
|
std::string ident = identHash.ToBase64 ();
|
||||||
std::string path = m_ProfilesStorage.Path(ident);
|
std::string path = m_ProfilesStorage.Path(ident);
|
||||||
boost::property_tree::ptree pt;
|
boost::property_tree::ptree pt;
|
||||||
|
|
||||||
if (!i2p::fs::Exists(path)) {
|
if (!i2p::fs::Exists(path))
|
||||||
|
{
|
||||||
LogPrint(eLogWarning, "Profiling: no profile yet for ", ident);
|
LogPrint(eLogWarning, "Profiling: no profile yet for ", ident);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
boost::property_tree::read_ini (path, pt);
|
boost::property_tree::read_ini (path, pt);
|
||||||
} catch (std::exception& ex) {
|
} catch (std::exception& ex)
|
||||||
|
{
|
||||||
/* boost exception verbose enough */
|
/* boost exception verbose enough */
|
||||||
LogPrint (eLogError, "Profiling: ", ex.what ());
|
LogPrint (eLogError, "Profiling: ", ex.what ());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
auto t = pt.get (PEER_PROFILE_LAST_UPDATE_TIME, "");
|
auto t = pt.get (PEER_PROFILE_LAST_UPDATE_TIME, "");
|
||||||
if (t.length () > 0)
|
if (t.length () > 0)
|
||||||
m_LastUpdateTime = boost::posix_time::time_from_string (t);
|
m_LastUpdateTime = boost::posix_time::time_from_string (t);
|
||||||
if ((GetTime () - m_LastUpdateTime).hours () < PEER_PROFILE_EXPIRATION_TIMEOUT) {
|
if ((GetTime () - m_LastUpdateTime).hours () < PEER_PROFILE_EXPIRATION_TIMEOUT)
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
// read participations
|
// read participations
|
||||||
auto participations = pt.get_child (PEER_PROFILE_SECTION_PARTICIPATION);
|
auto participations = pt.get_child (PEER_PROFILE_SECTION_PARTICIPATION);
|
||||||
m_NumTunnelsAgreed = participations.get (PEER_PROFILE_PARTICIPATION_AGREED, 0);
|
m_NumTunnelsAgreed = participations.get (PEER_PROFILE_PARTICIPATION_AGREED, 0);
|
||||||
m_NumTunnelsDeclined = participations.get (PEER_PROFILE_PARTICIPATION_DECLINED, 0);
|
m_NumTunnelsDeclined = participations.get (PEER_PROFILE_PARTICIPATION_DECLINED, 0);
|
||||||
m_NumTunnelsNonReplied = participations.get (PEER_PROFILE_PARTICIPATION_NON_REPLIED, 0);
|
m_NumTunnelsNonReplied = participations.get (PEER_PROFILE_PARTICIPATION_NON_REPLIED, 0);
|
||||||
} catch (boost::property_tree::ptree_bad_path& ex) {
|
}
|
||||||
|
catch (boost::property_tree::ptree_bad_path& ex)
|
||||||
|
{
|
||||||
LogPrint (eLogWarning, "Profiling: Missing section ", PEER_PROFILE_SECTION_PARTICIPATION, " in profile for ", ident);
|
LogPrint (eLogWarning, "Profiling: Missing section ", PEER_PROFILE_SECTION_PARTICIPATION, " in profile for ", ident);
|
||||||
}
|
}
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
// read usage
|
// read usage
|
||||||
auto usage = pt.get_child (PEER_PROFILE_SECTION_USAGE);
|
auto usage = pt.get_child (PEER_PROFILE_SECTION_USAGE);
|
||||||
m_NumTimesTaken = usage.get (PEER_PROFILE_USAGE_TAKEN, 0);
|
m_NumTimesTaken = usage.get (PEER_PROFILE_USAGE_TAKEN, 0);
|
||||||
m_NumTimesRejected = usage.get (PEER_PROFILE_USAGE_REJECTED, 0);
|
m_NumTimesRejected = usage.get (PEER_PROFILE_USAGE_REJECTED, 0);
|
||||||
} catch (boost::property_tree::ptree_bad_path& ex) {
|
}
|
||||||
|
catch (boost::property_tree::ptree_bad_path& ex)
|
||||||
|
{
|
||||||
LogPrint (eLogWarning, "Missing section ", PEER_PROFILE_SECTION_USAGE, " in profile for ", ident);
|
LogPrint (eLogWarning, "Missing section ", PEER_PROFILE_SECTION_USAGE, " in profile for ", ident);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
*this = RouterProfile (m_IdentHash);
|
else
|
||||||
}
|
*this = RouterProfile ();
|
||||||
} catch (std::exception& ex) {
|
}
|
||||||
|
catch (std::exception& ex)
|
||||||
|
{
|
||||||
LogPrint (eLogError, "Profiling: Can't read profile ", ident, " :", ex.what ());
|
LogPrint (eLogError, "Profiling: Can't read profile ", ident, " :", ex.what ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,8 +162,8 @@ namespace data
|
|||||||
|
|
||||||
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash)
|
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash)
|
||||||
{
|
{
|
||||||
auto profile = std::make_shared<RouterProfile> (identHash);
|
auto profile = std::make_shared<RouterProfile> ();
|
||||||
profile->Load (); // if possible
|
profile->Load (identHash); // if possible
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,11 +26,11 @@ namespace data
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RouterProfile (const IdentHash& identHash);
|
RouterProfile ();
|
||||||
RouterProfile& operator= (const RouterProfile& ) = default;
|
RouterProfile& operator= (const RouterProfile& ) = default;
|
||||||
|
|
||||||
void Save ();
|
void Save (const IdentHash& identHash);
|
||||||
void Load ();
|
void Load (const IdentHash& identHash);
|
||||||
|
|
||||||
bool IsBad ();
|
bool IsBad ();
|
||||||
|
|
||||||
@ -48,7 +48,6 @@ namespace data
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
IdentHash m_IdentHash;
|
|
||||||
boost::posix_time::ptime m_LastUpdateTime;
|
boost::posix_time::ptime m_LastUpdateTime;
|
||||||
// participation
|
// participation
|
||||||
uint32_t m_NumTunnelsAgreed;
|
uint32_t m_NumTunnelsAgreed;
|
||||||
|
@ -168,7 +168,7 @@ namespace data
|
|||||||
bool SaveToFile (const std::string& fullPath);
|
bool SaveToFile (const std::string& fullPath);
|
||||||
|
|
||||||
std::shared_ptr<RouterProfile> GetProfile () const;
|
std::shared_ptr<RouterProfile> GetProfile () const;
|
||||||
void SaveProfile () { if (m_Profile) m_Profile->Save (); };
|
void SaveProfile () { if (m_Profile) m_Profile->Save (GetIdentHash ()); };
|
||||||
|
|
||||||
void Update (const uint8_t * buf, int len);
|
void Update (const uint8_t * buf, int len);
|
||||||
void DeleteBuffer () { delete[] m_Buffer; m_Buffer = nullptr; };
|
void DeleteBuffer () { delete[] m_Buffer; m_Buffer = nullptr; };
|
||||||
|
9
SSU.cpp
9
SSU.cpp
@ -154,7 +154,7 @@ namespace transport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSUServer::AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay)
|
void SSUServer::AddRelay (uint32_t tag, std::shared_ptr<SSUSession> relay)
|
||||||
{
|
{
|
||||||
m_Relays[tag] = relay;
|
m_Relays[tag] = relay;
|
||||||
}
|
}
|
||||||
@ -168,7 +168,12 @@ namespace transport
|
|||||||
{
|
{
|
||||||
auto it = m_Relays.find (tag);
|
auto it = m_Relays.find (tag);
|
||||||
if (it != m_Relays.end ())
|
if (it != m_Relays.end ())
|
||||||
return FindSession (it->second);
|
{
|
||||||
|
if (it->second->GetState () == eSessionStateEstablished)
|
||||||
|
return it->second;
|
||||||
|
else
|
||||||
|
m_Relays.erase (it);
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
SSU.h
4
SSU.h
@ -57,7 +57,7 @@ namespace transport
|
|||||||
boost::asio::io_service& GetServiceV6 () { return m_ServiceV6; };
|
boost::asio::io_service& GetServiceV6 () { return m_ServiceV6; };
|
||||||
const boost::asio::ip::udp::endpoint& GetEndpoint () const { return m_Endpoint; };
|
const boost::asio::ip::udp::endpoint& GetEndpoint () const { return m_Endpoint; };
|
||||||
void Send (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& to);
|
void Send (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& to);
|
||||||
void AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay);
|
void AddRelay (uint32_t tag, std::shared_ptr<SSUSession> relay);
|
||||||
void RemoveRelay (uint32_t tag);
|
void RemoveRelay (uint32_t tag);
|
||||||
std::shared_ptr<SSUSession> FindRelaySession (uint32_t tag);
|
std::shared_ptr<SSUSession> FindRelaySession (uint32_t tag);
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ namespace transport
|
|||||||
m_TerminationTimer, m_TerminationTimerV6;
|
m_TerminationTimer, m_TerminationTimerV6;
|
||||||
std::list<boost::asio::ip::udp::endpoint> m_Introducers; // introducers we are connected to
|
std::list<boost::asio::ip::udp::endpoint> m_Introducers; // introducers we are connected to
|
||||||
std::map<boost::asio::ip::udp::endpoint, std::shared_ptr<SSUSession> > m_Sessions, m_SessionsV6;
|
std::map<boost::asio::ip::udp::endpoint, std::shared_ptr<SSUSession> > m_Sessions, m_SessionsV6;
|
||||||
std::map<uint32_t, boost::asio::ip::udp::endpoint> m_Relays; // we are introducer
|
std::map<uint32_t, std::shared_ptr<SSUSession> > m_Relays; // we are introducer
|
||||||
std::map<uint32_t, PeerTest> m_PeerTests; // nonce -> creation time in milliseconds
|
std::map<uint32_t, PeerTest> m_PeerTests; // nonce -> creation time in milliseconds
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -464,7 +464,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
RAND_bytes((uint8_t *)&m_SentRelayTag, 4);
|
RAND_bytes((uint8_t *)&m_SentRelayTag, 4);
|
||||||
if (!m_SentRelayTag) m_SentRelayTag = 1;
|
if (!m_SentRelayTag) m_SentRelayTag = 1;
|
||||||
m_Server.AddRelay (m_SentRelayTag, m_RemoteEndpoint);
|
m_Server.AddRelay (m_SentRelayTag, shared_from_this ());
|
||||||
}
|
}
|
||||||
htobe32buf (payload, m_SentRelayTag);
|
htobe32buf (payload, m_SentRelayTag);
|
||||||
payload += 4; // relay tag
|
payload += 4; // relay tag
|
||||||
|
@ -694,7 +694,7 @@ namespace transport
|
|||||||
if (profile)
|
if (profile)
|
||||||
{
|
{
|
||||||
profile->TunnelNonReplied();
|
profile->TunnelNonReplied();
|
||||||
profile->Save();
|
profile->Save(it->first);
|
||||||
}
|
}
|
||||||
std::unique_lock<std::mutex> l(m_PeersMutex);
|
std::unique_lock<std::mutex> l(m_PeersMutex);
|
||||||
it = m_Peers.erase (it);
|
it = m_Peers.erase (it);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user