mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-03 07:54:14 +00:00
save updated local RouterInfo in separate thread
This commit is contained in:
parent
5d7a062f1b
commit
daeb177579
@ -78,6 +78,8 @@ namespace i2p
|
|||||||
m_Service->Stop ();
|
m_Service->Stop ();
|
||||||
CleanUp (); // GarlicDestination
|
CleanUp (); // GarlicDestination
|
||||||
}
|
}
|
||||||
|
if (m_SavingRouterInfo.valid ())
|
||||||
|
m_SavingRouterInfo.wait ();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<i2p::data::RouterInfo::Buffer> RouterContext::CopyRouterInfoBuffer () const
|
std::shared_ptr<i2p::data::RouterInfo::Buffer> RouterContext::CopyRouterInfoBuffer () const
|
||||||
@ -254,12 +256,25 @@ namespace i2p
|
|||||||
|
|
||||||
void RouterContext::UpdateRouterInfo ()
|
void RouterContext::UpdateRouterInfo ()
|
||||||
{
|
{
|
||||||
|
std::shared_ptr<i2p::data::RouterInfo::Buffer> buffer;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> l(m_RouterInfoMutex);
|
std::lock_guard<std::mutex> l(m_RouterInfoMutex);
|
||||||
m_RouterInfo.CreateBuffer (m_Keys);
|
m_RouterInfo.CreateBuffer (m_Keys);
|
||||||
|
buffer = m_RouterInfo.CopyBuffer ();
|
||||||
}
|
}
|
||||||
m_RouterInfo.SaveToFile (i2p::fs::DataDirPath (ROUTER_INFO));
|
|
||||||
m_LastUpdateTime = i2p::util::GetSecondsSinceEpoch ();
|
m_LastUpdateTime = i2p::util::GetSecondsSinceEpoch ();
|
||||||
|
// defer saving buffer to disk
|
||||||
|
if (m_SavingRouterInfo.valid ())
|
||||||
|
{
|
||||||
|
// wait until previous update complete
|
||||||
|
m_SavingRouterInfo.wait ();
|
||||||
|
m_SavingRouterInfo.get ();
|
||||||
|
}
|
||||||
|
m_SavingRouterInfo = std::async (std::launch::async,
|
||||||
|
[buffer = std::move(buffer)]()
|
||||||
|
{
|
||||||
|
i2p::data::RouterInfo::SaveToFile (i2p::fs::DataDirPath (ROUTER_INFO), buffer);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::NewNTCP2Keys ()
|
void RouterContext::NewNTCP2Keys ()
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <future>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
@ -266,6 +267,7 @@ namespace garlic
|
|||||||
bool m_IsHiddenMode; // not publish
|
bool m_IsHiddenMode; // not publish
|
||||||
mutable std::mutex m_RouterInfoMutex;
|
mutable std::mutex m_RouterInfoMutex;
|
||||||
std::mt19937 m_Rng;
|
std::mt19937 m_Rng;
|
||||||
|
std::future<void> m_SavingRouterInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern RouterContext context;
|
extern RouterContext context;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user