summaryrefslogtreecommitdiff
path: root/controller/EmbeddedNetworkController.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2016-08-25 11:26:45 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2016-08-25 11:26:45 -0700
commit1814016eb75b87d6f28711f41ecdafab69e556ee (patch)
tree5d5aa17afaa886c74ee6a0033971439eac6f15e1 /controller/EmbeddedNetworkController.hpp
parent6ecb42b031b25531757a34cf9f327b30d1329c4e (diff)
downloadinfinitytier-1814016eb75b87d6f28711f41ecdafab69e556ee.tar.gz
infinitytier-1814016eb75b87d6f28711f41ecdafab69e556ee.zip
Add daemon thread to controller and move network member cache refreshes there.
Diffstat (limited to 'controller/EmbeddedNetworkController.hpp')
-rw-r--r--controller/EmbeddedNetworkController.hpp45
1 files changed, 24 insertions, 21 deletions
diff --git a/controller/EmbeddedNetworkController.hpp b/controller/EmbeddedNetworkController.hpp
index 47419f52..b7a40a4c 100644
--- a/controller/EmbeddedNetworkController.hpp
+++ b/controller/EmbeddedNetworkController.hpp
@@ -25,21 +25,21 @@
#include <map>
#include <vector>
#include <set>
+#include <list>
#include "../node/Constants.hpp"
#include "../node/NetworkController.hpp"
#include "../node/Mutex.hpp"
#include "../node/Utils.hpp"
+#include "../node/Address.hpp"
#include "../node/InetAddress.hpp"
#include "../osdep/OSUtils.hpp"
+#include "../osdep/Thread.hpp"
#include "../ext/json/json.hpp"
-// Expiration time for network member cache entries in ms
-#define ZT_NETCONF_NETWORK_MEMBER_CACHE_EXPIRE 30000
-
namespace ZeroTier {
class Node;
@@ -50,6 +50,10 @@ public:
EmbeddedNetworkController(Node *node,const char *dbPath);
virtual ~EmbeddedNetworkController();
+ // Thread main method -- do not call directly
+ void threadMain()
+ throw();
+
virtual NetworkController::ResultCode doNetworkConfigRequest(
const InetAddress &fromAddr,
const Identity &signingId,
@@ -83,22 +87,6 @@ public:
private:
static void _circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report);
- // JSON blob I/O
- inline nlohmann::json _readJson(const std::string &path)
- {
- std::string buf;
- if (OSUtils::readFile(path.c_str(),buf)) {
- try {
- return nlohmann::json::parse(buf);
- } catch ( ... ) {}
- }
- return nlohmann::json::object();
- }
- inline bool _writeJson(const std::string &path,const nlohmann::json &obj)
- {
- return OSUtils::writeFile(path.c_str(),obj.dump(2));
- }
-
// Network base path and network JSON path
inline std::string _networkBP(const uint64_t nwid,bool create)
{
@@ -133,8 +121,8 @@ private:
return (_memberBP(nwid,member,create) + ZT_PATH_SEPARATOR + "config.json");
}
- // We cache the members of networks in memory to avoid having to scan the filesystem so much
- std::map< uint64_t,std::pair< std::map< Address,nlohmann::json >,uint64_t > > _networkMemberCache;
+ // In-memory cache of network members
+ std::map< uint64_t,std::map< Address,nlohmann::json > > _networkMemberCache;
Mutex _networkMemberCache_m;
// Gathers a bunch of statistics about members of a network, IP assignments, etc. that we need in various places
@@ -211,6 +199,21 @@ private:
// Last request time by address, for rate limitation
std::map< std::pair<uint64_t,uint64_t>,uint64_t > _lastRequestTime;
Mutex _lastRequestTime_m;
+
+ // Queue of network member refreshes to be pushed
+ struct _Refresh
+ {
+ Address dest;
+ uint64_t nwid;
+ uint64_t blacklistAddresses[64];
+ uint64_t blacklistThresholds[64];
+ unsigned int numBlacklistEntries;
+ };
+ std::list< _Refresh > _refreshQueue;
+ Mutex _refreshQueue_m;
+
+ Thread _daemon;
+ volatile bool _daemonRun;
};
} // namespace ZeroTier