dht publication functions now called in StateReportThread

pull/2/head
Tom Early 3 years ago
parent dc12fd748e
commit 86e4e4c9b2

@ -120,7 +120,7 @@ bool CReflector::Start(void)
// start the reporting thread
try
{
m_XmlReportFuture = std::async(std::launch::async, &CReflector::XmlReportThread, this);
m_XmlReportFuture = std::async(std::launch::async, &CReflector::StateReportThread, this);
}
catch(const std::exception& e)
{
@ -323,10 +323,12 @@ void CReflector::RouterThread(const char ThisModule)
#define XML_UPDATE_PERIOD 10
void CReflector::XmlReportThread()
void CReflector::StateReportThread()
{
std::string xmlpath, jsonpath;
#ifndef NO_DHT
peers_changed = clients_changed = users_changed = true;
#endif
if (g_Configure.Contains(g_Keys.files.xml))
xmlpath.assign(g_Configure.GetString(g_Keys.files.xml));
if (g_Configure.Contains(g_Keys.files.json))
@ -370,9 +372,29 @@ void CReflector::XmlReportThread()
}
}
// and wait a bit
// and wait a bit and do something useful at the same time
for (int i=0; i< XML_UPDATE_PERIOD && keep_running; i++)
{
#ifndef NO_DHT
// update the dht data, if needed
if (peers_changed)
{
PutDHTPeers();
peers_changed = false;
}
if (clients_changed)
{
PutDHTClients();
clients_changed = false;
}
if (users_changed)
{
PutDHTUsers();
users_changed = false;
}
#endif
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
}
@ -382,32 +404,24 @@ void CReflector::XmlReportThread()
void CReflector::OnPeersChanged(void)
{
#ifndef NO_DHT
PutDHTPeers();
peers_changed = true;
#endif
}
void CReflector::OnClientsChanged(void)
{
#ifndef NO_DHT
PutDHTClients();
clients_changed = true;
#endif
}
void CReflector::OnUsersChanged(void)
{
#ifndef NO_DHT
PutDHTUsers();
users_changed = true;
#endif
}
// void CReflector::OnStreamOpen(const CCallsign &callsign)
// {
// }
// void CReflector::OnStreamClose(const CCallsign &callsign)
// {
////////////////////////////////////////////////////////////////////////////////////////
// modules & queues

@ -79,22 +79,22 @@ public:
void OnPeersChanged(void);
void OnClientsChanged(void);
void OnUsersChanged(void);
// void OnStreamOpen(const CCallsign &);
// void OnStreamClose(const CCallsign &);
#ifndef NO_DHT
void GetDHTConfig(const std::string &cs);
#endif
protected:
#ifndef NO_DHT
// Publish DHT
void PutDHTConfig();
void PutDHTPeers();
void PutDHTClients();
void PutDHTUsers();
void GetDHTConfig(const std::string &cs);
#endif
protected:
// threads
void RouterThread(const char);
void XmlReportThread(void);
void StateReportThread(void);
// streams
std::shared_ptr<CPacketStream> GetStream(char);
@ -128,6 +128,6 @@ protected:
dht::DhtRunner node;
dht::InfoHash refhash;
unsigned int peers_put_count, clients_put_count, users_put_count;
std::atomic<bool> peers_changed, clients_changed, users_changed;
#endif
};

Loading…
Cancel
Save

Powered by TurnKey Linux.