diff options
Diffstat (limited to 'node/Network.cpp')
-rw-r--r-- | node/Network.cpp | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/node/Network.cpp b/node/Network.cpp index f0770610..d075bc7c 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -113,8 +113,24 @@ Network::Network(const RuntimeEnvironment *renv,uint64_t id) _destroyOnDelete(false) { if (controller() == _r->identity.address()) - throw std::runtime_error("configuration error: cannot add a network for which I am the netconf master"); + throw std::runtime_error("cannot add a network for which I am the netconf master"); +} +Network::~Network() +{ + if (_destroyOnDelete) { + std::string confPath(_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d" + ZT_PATH_SEPARATOR_S + toString() + ".conf"); + std::string mcdbPath(_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d" + ZT_PATH_SEPARATOR_S + toString() + ".mcerts"); + unlink(confPath.c_str()); + unlink(mcdbPath.c_str()); + } else { + // Causes flush of membership certs to disk + clean(); + } +} + +void Network::restoreState() +{ std::string confPath(_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d" + ZT_PATH_SEPARATOR_S + toString() + ".conf"); std::string confs; if (Utils::readFile(confPath.c_str(),confs)) { @@ -122,7 +138,7 @@ Network::Network(const RuntimeEnvironment *renv,uint64_t id) if (confs.length()) { Config conf(confs); if (conf.containsAllFields()) - setConfiguration(Config(conf)); + setConfiguration(conf); } } catch ( ... ) {} // ignore invalid config on disk, we will re-request } else { @@ -132,32 +148,20 @@ Network::Network(const RuntimeEnvironment *renv,uint64_t id) if (tmp) fclose(tmp); } - - requestConfiguration(); -} - -Network::~Network() -{ - if (_destroyOnDelete) { - std::string confPath(_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d" + ZT_PATH_SEPARATOR_S + toString() + ".conf"); - std::string mcdbPath(_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d" + ZT_PATH_SEPARATOR_S + toString() + ".mcerts"); - unlink(confPath.c_str()); - unlink(mcdbPath.c_str()); - } else { - // Causes flush of membership certs to disk - clean(); - } + // TODO: restore membership certs } void Network::setConfiguration(const Network::Config &conf) { Mutex::Lock _l(_lock); if ((conf.networkId() == _id)&&(conf.peerAddress() == _r->identity.address())) { // sanity check - TRACE("network %.16llx got netconf:\n%s",(unsigned long long)_id,conf.toString().c_str()); + //TRACE("network %.16llx got netconf:\n%s",(unsigned long long)_id,conf.toString().c_str()); _configuration = conf; _myCertificate = conf.certificateOfMembership(); _lastConfigUpdate = Utils::now(); + _tap.setIps(conf.staticAddresses()); + std::string confPath(_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d" + ZT_PATH_SEPARATOR_S + toString() + ".conf"); if (!Utils::writeFile(confPath.c_str(),conf.toString())) { LOG("error: unable to write network configuration file at: %s",confPath.c_str()); |