mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
local.conf in NodeConfig
This commit is contained in:
parent
e54a34d8dd
commit
cd339486b7
2 changed files with 32 additions and 2 deletions
|
@ -109,10 +109,13 @@ NodeConfig::NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsi
|
||||||
LOG("unable to create network %.16llx: (unknown exception)",(unsigned long long)*nwid);
|
LOG("unable to create network %.16llx: (unknown exception)",(unsigned long long)*nwid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_readLocalConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeConfig::~NodeConfig()
|
NodeConfig::~NodeConfig()
|
||||||
{
|
{
|
||||||
|
_writeLocalConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeConfig::clean()
|
void NodeConfig::clean()
|
||||||
|
@ -122,6 +125,9 @@ void NodeConfig::clean()
|
||||||
n->second->clean();
|
n->second->clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// UDP localhost control bus
|
||||||
|
|
||||||
// Macro used in execute() to push lines onto the return packet
|
// Macro used in execute() to push lines onto the return packet
|
||||||
#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__); }
|
||||||
|
@ -389,4 +395,21 @@ void NodeConfig::_CBcontrolPacketHandler(UdpSocket *sock,void *arg,const InetAdd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void NodeConfig::_readLocalConfig()
|
||||||
|
{
|
||||||
|
std::string localDotConf(_r->homePath + ZT_PATH_SEPARATOR_S + "local.conf");
|
||||||
|
std::string buf;
|
||||||
|
if (Utils::readFile(localDotConf.c_str(),buf)) {
|
||||||
|
Mutex::Lock _l(_localConfig_m);
|
||||||
|
_localConfig.fromString(buf.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeConfig::_writeLocalConfig()
|
||||||
|
{
|
||||||
|
Utils::writeFile(((_r->homePath + ZT_PATH_SEPARATOR_S + "local.conf")).c_str(),_localConfig.toString());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
#include "UdpSocket.hpp"
|
#include "UdpSocket.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
|
#include "Dictionary.hpp"
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a command
|
* Execute a control command (called when stuff comes in via control bus)
|
||||||
*
|
*
|
||||||
* @param command Command and arguments separated by whitespace (must already be trimmed of CR+LF, etc.)
|
* @param command Command and arguments separated by whitespace (must already be trimmed of CR+LF, etc.)
|
||||||
* @return One or more command results (lines of output)
|
* @return One or more command results (lines of output)
|
||||||
|
@ -159,12 +160,18 @@ public:
|
||||||
private:
|
private:
|
||||||
static void _CBcontrolPacketHandler(UdpSocket *sock,void *arg,const InetAddress &remoteAddr,const void *data,unsigned int len);
|
static void _CBcontrolPacketHandler(UdpSocket *sock,void *arg,const InetAddress &remoteAddr,const void *data,unsigned int len);
|
||||||
|
|
||||||
|
void _readLocalConfig();
|
||||||
|
void _writeLocalConfig();
|
||||||
|
|
||||||
const RuntimeEnvironment *_r;
|
const RuntimeEnvironment *_r;
|
||||||
|
|
||||||
unsigned char _controlSocketKey[32];
|
unsigned char _controlSocketKey[32];
|
||||||
UdpSocket _controlSocket;
|
UdpSocket _controlSocket;
|
||||||
|
|
||||||
std::map< uint64_t,SharedPtr<Network> > _networks;
|
Dictionary _localConfig; // persisted as local.conf
|
||||||
|
Mutex _localConfig_m;
|
||||||
|
|
||||||
|
std::map< uint64_t,SharedPtr<Network> > _networks; // persisted in networks.d/
|
||||||
Mutex _networks_m;
|
Mutex _networks_m;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue