Call clean on all networks periodically, generalize Topology clean cycle to an overall clean cycle.

This commit is contained in:
Adam Ierymenko 2013-07-30 11:14:53 -04:00
parent e4c5ad9f43
commit 7e156b2622
6 changed files with 40 additions and 9 deletions

View file

@ -183,9 +183,9 @@ error_no_ZT_ARCH_defined;
#define ZT_MAC_FIRST_OCTET 0x32 #define ZT_MAC_FIRST_OCTET 0x32
/** /**
* How often Topology::clean() is called in ms * How often Topology::clean() and Network::clean() are called in ms
*/ */
#define ZT_TOPOLOGY_CLEAN_PERIOD 300000 #define ZT_DB_CLEAN_PERIOD 300000
/** /**
* Delay between WHOIS retries in ms * Delay between WHOIS retries in ms

View file

@ -34,6 +34,7 @@
#include "NodeConfig.hpp" #include "NodeConfig.hpp"
#include "Network.hpp" #include "Network.hpp"
#include "Switch.hpp" #include "Switch.hpp"
#include "Packet.hpp"
namespace ZeroTier { namespace ZeroTier {
@ -103,6 +104,7 @@ Network::Network(const RuntimeEnvironment *renv,uint64_t id)
throw(std::runtime_error) : throw(std::runtime_error) :
_r(renv), _r(renv),
_tap(renv,renv->identity.address().toMAC(),ZT_IF_MTU,&_CBhandleTapData,this), _tap(renv,renv->identity.address().toMAC(),ZT_IF_MTU,&_CBhandleTapData,this),
_lastConfigUpdate(0),
_id(id) _id(id)
{ {
} }
@ -114,16 +116,23 @@ Network::~Network()
void Network::setConfiguration(const Network::Config &conf) void Network::setConfiguration(const Network::Config &conf)
{ {
Mutex::Lock _l(_lock); Mutex::Lock _l(_lock);
_configuration = conf; if ((conf.networkId() == _id)&&(conf.peerAddress() == _r->identity.address())) { // sanity check
_myCertificate = conf.certificateOfMembership(); _configuration = conf;
_myCertificate = conf.certificateOfMembership();
_lastConfigUpdate = Utils::now();
}
} }
void Network::requestConfiguration() void Network::requestConfiguration()
{ {
Packet outp(controller(),_r->identity.address(),Packet::VERB_NETWORK_CONFIG_REQUEST);
outp.append((uint64_t)_id);
_r->sw->send(outp,true);
} }
bool Network::isAllowed(const Address &peer) const bool Network::isAllowed(const Address &peer) const
{ {
// Exceptions can occur if we do not yet have *our* configuration.
try { try {
Mutex::Lock _l(_lock); Mutex::Lock _l(_lock);
if (_configuration.isOpen()) if (_configuration.isOpen())

View file

@ -392,6 +392,15 @@ public:
*/ */
void clean(); void clean();
/**
* @return Time of last updated configuration or 0 if none
*/
inline uint64_t lastConfigUpdate() const
throw()
{
return _lastConfigUpdate;
}
private: private:
static void _CBhandleTapData(void *arg,const MAC &from,const MAC &to,unsigned int etherType,const Buffer<4096> &data); static void _CBhandleTapData(void *arg,const MAC &from,const MAC &to,unsigned int etherType,const Buffer<4096> &data);
@ -402,7 +411,7 @@ private:
std::map<Address,Certificate> _membershipCertificates; std::map<Address,Certificate> _membershipCertificates;
Config _configuration; Config _configuration;
Certificate _myCertificate; Certificate _myCertificate;
uint64_t _lastCertificateUpdate; uint64_t _lastConfigUpdate;
uint64_t _id; uint64_t _id;
Mutex _lock; Mutex _lock;

View file

@ -339,7 +339,7 @@ Node::ReasonForTermination Node::run()
try { try {
uint64_t lastPingCheck = 0; uint64_t lastPingCheck = 0;
uint64_t lastTopologyClean = Utils::now(); // don't need to do this immediately uint64_t lastClean = Utils::now(); // don't need to do this immediately
uint64_t lastNetworkFingerprintCheck = 0; uint64_t lastNetworkFingerprintCheck = 0;
uint64_t lastAutoconfigureCheck = 0; uint64_t lastAutoconfigureCheck = 0;
uint64_t networkConfigurationFingerprint = _r->sysEnv->getNetworkConfigurationFingerprint(); uint64_t networkConfigurationFingerprint = _r->sysEnv->getNetworkConfigurationFingerprint();
@ -459,9 +459,10 @@ Node::ReasonForTermination Node::run()
} }
} }
if ((now - lastTopologyClean) >= ZT_TOPOLOGY_CLEAN_PERIOD) { if ((now - lastClean) >= ZT_DB_CLEAN_PERIOD) {
lastTopologyClean = now; lastClean = now;
_r->topology->clean(); // happens in background _r->topology->clean();
_r->nc->cleanAllNetworks();
} }
try { try {

View file

@ -72,6 +72,13 @@ void NodeConfig::whackAllTaps()
n->second->tap().whack(); n->second->tap().whack();
} }
void NodeConfig::cleanAllNetworks()
{
Mutex::Lock _l(_networks_m);
for(std::map< uint64_t,SharedPtr<Network> >::const_iterator n(_networks.begin());n!=_networks.end();++n)
n->second->clean();
}
// Macro used in execute() // Macro used in execute()
#undef _P #undef _P
#define _P(f,...) { r.push_back(std::string()); Utils::stdsprintf(r.back(),(f),##__VA_ARGS__); } #define _P(f,...) { r.push_back(std::string()); Utils::stdsprintf(r.back(),(f),##__VA_ARGS__); }

View file

@ -107,6 +107,11 @@ public:
*/ */
void whackAllTaps(); void whackAllTaps();
/**
* Call clean() on all networks
*/
void cleanAllNetworks();
/** /**
* @param nwid Network ID * @param nwid Network ID
* @return True if this network exists * @return True if this network exists