summaryrefslogtreecommitdiff
path: root/controller/JSONDB.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-24 09:09:04 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-24 09:09:04 -0700
commitf4feccc6265cc480b84c85f897b225714072d4ec (patch)
treea906659bb84d73ef6d3e618ae85a6e13ede78e49 /controller/JSONDB.hpp
parent44cb2f4efdb029b1ecfe8f3ce5b8722697b2c684 (diff)
downloadinfinitytier-f4feccc6265cc480b84c85f897b225714072d4ec.tar.gz
infinitytier-f4feccc6265cc480b84c85f897b225714072d4ec.zip
Do not serve controller requests until init is done.
Diffstat (limited to 'controller/JSONDB.hpp')
-rw-r--r--controller/JSONDB.hpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/controller/JSONDB.hpp b/controller/JSONDB.hpp
index c19112ed..beafbaf5 100644
--- a/controller/JSONDB.hpp
+++ b/controller/JSONDB.hpp
@@ -36,6 +36,7 @@
#include "../ext/json/json.hpp"
#include "../osdep/OSUtils.hpp"
#include "../osdep/Http.hpp"
+#include "../osdep/Thread.hpp"
namespace ZeroTier {
@@ -47,12 +48,6 @@ class JSONDB
public:
JSONDB(const std::string &basePath);
- inline void reload()
- {
- _db.clear();
- _reload(_basePath,std::string());
- }
-
bool writeRaw(const std::string &n,const std::string &obj);
bool put(const std::string &n,const nlohmann::json &obj);
@@ -79,6 +74,11 @@ public:
template<typename F>
inline void filter(const std::string &prefix,F func)
{
+ while (!_ready) {
+ Thread::sleep(250);
+ _ready = _reload(_basePath,std::string());
+ }
+
for(std::map<std::string,_E>::iterator i(_db.lower_bound(prefix));i!=_db.end();) {
if ((i->first.length() >= prefix.length())&&(!memcmp(i->first.data(),prefix.data(),prefix.length()))) {
if (!func(i->first,get(i->first))) {
@@ -94,7 +94,7 @@ public:
inline bool operator!=(const JSONDB &db) const { return (!(*this == db)); }
private:
- void _reload(const std::string &p,const std::string &b);
+ bool _reload(const std::string &p,const std::string &b);
bool _isValidObjectName(const std::string &n);
std::string _genPath(const std::string &n,bool create);
@@ -108,6 +108,7 @@ private:
InetAddress _httpAddr;
std::string _basePath;
std::map<std::string,_E> _db;
+ volatile bool _ready;
};
} // namespace ZeroTier