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 // start the reporting thread
try 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) catch(const std::exception& e)
{ {
@ -323,10 +323,12 @@ void CReflector::RouterThread(const char ThisModule)
#define XML_UPDATE_PERIOD 10 #define XML_UPDATE_PERIOD 10
void CReflector::XmlReportThread() void CReflector::StateReportThread()
{ {
std::string xmlpath, jsonpath; std::string xmlpath, jsonpath;
#ifndef NO_DHT
peers_changed = clients_changed = users_changed = true;
#endif
if (g_Configure.Contains(g_Keys.files.xml)) if (g_Configure.Contains(g_Keys.files.xml))
xmlpath.assign(g_Configure.GetString(g_Keys.files.xml)); xmlpath.assign(g_Configure.GetString(g_Keys.files.xml));
if (g_Configure.Contains(g_Keys.files.json)) 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++) 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)); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
} }
} }
@ -382,32 +404,24 @@ void CReflector::XmlReportThread()
void CReflector::OnPeersChanged(void) void CReflector::OnPeersChanged(void)
{ {
#ifndef NO_DHT #ifndef NO_DHT
PutDHTPeers(); peers_changed = true;
#endif #endif
} }
void CReflector::OnClientsChanged(void) void CReflector::OnClientsChanged(void)
{ {
#ifndef NO_DHT #ifndef NO_DHT
PutDHTClients(); clients_changed = true;
#endif #endif
} }
void CReflector::OnUsersChanged(void) void CReflector::OnUsersChanged(void)
{ {
#ifndef NO_DHT #ifndef NO_DHT
PutDHTUsers(); users_changed = true;
#endif #endif
} }
// void CReflector::OnStreamOpen(const CCallsign &callsign)
// {
// }
// void CReflector::OnStreamClose(const CCallsign &callsign)
// {
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// modules & queues // modules & queues

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

Loading…
Cancel
Save

Powered by TurnKey Linux.