mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
Jigger with shutdown method to avoid a crash on CTRL+C in Windows. Feels a big hacky, might revisit later.
This commit is contained in:
parent
0afcf4877c
commit
01a70d09db
4 changed files with 27 additions and 31 deletions
|
@ -210,7 +210,8 @@ Demarc::Port Demarc::send(Demarc::Port fromPort,const InetAddress &to,const void
|
||||||
|
|
||||||
void Demarc::_CBudpSocketPacketHandler(UdpSocket *sock,void *arg,const InetAddress &from,const void *data,unsigned int len)
|
void Demarc::_CBudpSocketPacketHandler(UdpSocket *sock,void *arg,const InetAddress &from,const void *data,unsigned int len)
|
||||||
{
|
{
|
||||||
((DemarcPortObj *)arg)->parent->_r->sw->onRemotePacket(((DemarcPortObj *)arg)->port,from,Buffer<4096>(data,len));
|
if (!((DemarcPortObj *)arg)->parent->_r->shutdownInProgress)
|
||||||
|
((DemarcPortObj *)arg)->parent->_r->sw->onRemotePacket(((DemarcPortObj *)arg)->port,from,Buffer<4096>(data,len));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
|
|
@ -282,6 +282,8 @@ void Network::_CBhandleTapData(void *arg,const MAC &from,const MAC &to,unsigned
|
||||||
if (!((Network *)arg)->_ready)
|
if (!((Network *)arg)->_ready)
|
||||||
return;
|
return;
|
||||||
const RuntimeEnvironment *_r = ((Network *)arg)->_r;
|
const RuntimeEnvironment *_r = ((Network *)arg)->_r;
|
||||||
|
if (_r->shutdownInProgress)
|
||||||
|
return;
|
||||||
try {
|
try {
|
||||||
_r->sw->onLocalEthernet(SharedPtr<Network>((Network *)arg),from,to,etherType,data);
|
_r->sw->onLocalEthernet(SharedPtr<Network>((Network *)arg),from,to,etherType,data);
|
||||||
} catch (std::exception &exc) {
|
} catch (std::exception &exc) {
|
||||||
|
|
|
@ -188,15 +188,31 @@ struct _NodeImpl
|
||||||
volatile bool running;
|
volatile bool running;
|
||||||
volatile bool terminateNow;
|
volatile bool terminateNow;
|
||||||
|
|
||||||
// Helper used to rapidly terminate from run()
|
// run() calls this on all return paths
|
||||||
inline Node::ReasonForTermination terminateBecause(Node::ReasonForTermination r,const char *rstr)
|
inline Node::ReasonForTermination terminateBecause(Node::ReasonForTermination r,const char *rstr)
|
||||||
{
|
{
|
||||||
RuntimeEnvironment *_r = &renv;
|
RuntimeEnvironment *_r = &renv;
|
||||||
LOG("terminating: %s",rstr);
|
LOG("terminating: %s",rstr);
|
||||||
|
|
||||||
|
renv.shutdownInProgress = true;
|
||||||
|
Thread::sleep(500);
|
||||||
|
|
||||||
|
#ifndef __WINDOWS__
|
||||||
|
delete renv.netconfService;
|
||||||
|
#endif
|
||||||
|
delete renv.nc;
|
||||||
|
delete renv.sysEnv;
|
||||||
|
delete renv.topology;
|
||||||
|
delete renv.demarc;
|
||||||
|
delete renv.sw;
|
||||||
|
delete renv.multicaster;
|
||||||
|
delete renv.prng;
|
||||||
|
delete renv.log;
|
||||||
|
|
||||||
reasonForTerminationStr = rstr;
|
reasonForTerminationStr = rstr;
|
||||||
reasonForTermination = r;
|
reasonForTermination = r;
|
||||||
running = false;
|
running = false;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -257,7 +273,6 @@ Node::Node(const char *hp)
|
||||||
_impl(new _NodeImpl)
|
_impl(new _NodeImpl)
|
||||||
{
|
{
|
||||||
_NodeImpl *impl = (_NodeImpl *)_impl;
|
_NodeImpl *impl = (_NodeImpl *)_impl;
|
||||||
|
|
||||||
if ((hp)&&(strlen(hp) > 0))
|
if ((hp)&&(strlen(hp) > 0))
|
||||||
impl->renv.homePath = hp;
|
impl->renv.homePath = hp;
|
||||||
else impl->renv.homePath = ZT_DEFAULTS.defaultHomePath;
|
else impl->renv.homePath = ZT_DEFAULTS.defaultHomePath;
|
||||||
|
@ -269,34 +284,9 @@ Node::Node(const char *hp)
|
||||||
|
|
||||||
Node::~Node()
|
Node::~Node()
|
||||||
{
|
{
|
||||||
_NodeImpl *impl = (_NodeImpl *)_impl;
|
delete (_NodeImpl *)_impl;
|
||||||
|
|
||||||
#ifndef __WINDOWS__
|
|
||||||
delete impl->renv.netconfService;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
delete impl->renv.nc;
|
|
||||||
delete impl->renv.sysEnv;
|
|
||||||
delete impl->renv.topology;
|
|
||||||
delete impl->renv.sw;
|
|
||||||
delete impl->renv.multicaster;
|
|
||||||
delete impl->renv.demarc;
|
|
||||||
delete impl->renv.prng;
|
|
||||||
delete impl->renv.log;
|
|
||||||
|
|
||||||
delete impl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute node in current thread
|
|
||||||
*
|
|
||||||
* This does not return until the node shuts down. Shutdown may be caused
|
|
||||||
* by an internally detected condition such as a new upgrade being
|
|
||||||
* available or a fatal error, or it may be signaled externally using
|
|
||||||
* the terminate() method.
|
|
||||||
*
|
|
||||||
* @return Reason for termination
|
|
||||||
*/
|
|
||||||
Node::ReasonForTermination Node::run()
|
Node::ReasonForTermination Node::run()
|
||||||
throw()
|
throw()
|
||||||
{
|
{
|
||||||
|
@ -375,9 +365,9 @@ Node::ReasonForTermination Node::run()
|
||||||
// Create the core objects in RuntimeEnvironment: node config, demarcation
|
// Create the core objects in RuntimeEnvironment: node config, demarcation
|
||||||
// point, switch, network topology database, and system environment
|
// point, switch, network topology database, and system environment
|
||||||
// watcher.
|
// watcher.
|
||||||
_r->demarc = new Demarc(_r);
|
|
||||||
_r->multicaster = new Multicaster();
|
_r->multicaster = new Multicaster();
|
||||||
_r->sw = new Switch(_r);
|
_r->sw = new Switch(_r);
|
||||||
|
_r->demarc = new Demarc(_r);
|
||||||
_r->topology = new Topology(_r,(_r->homePath + ZT_PATH_SEPARATOR_S + "peer.db").c_str());
|
_r->topology = new Topology(_r,(_r->homePath + ZT_PATH_SEPARATOR_S + "peer.db").c_str());
|
||||||
_r->sysEnv = new SysEnv(_r);
|
_r->sysEnv = new SysEnv(_r);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -61,6 +61,7 @@ class RuntimeEnvironment
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RuntimeEnvironment() :
|
RuntimeEnvironment() :
|
||||||
|
shutdownInProgress(false),
|
||||||
log((Logger *)0),
|
log((Logger *)0),
|
||||||
prng((CMWC4096 *)0),
|
prng((CMWC4096 *)0),
|
||||||
demarc((Demarc *)0),
|
demarc((Demarc *)0),
|
||||||
|
@ -82,14 +83,16 @@ public:
|
||||||
|
|
||||||
Identity identity;
|
Identity identity;
|
||||||
|
|
||||||
|
volatile bool shutdownInProgress;
|
||||||
|
|
||||||
// Order matters a bit here. These are constructed in this order
|
// Order matters a bit here. These are constructed in this order
|
||||||
// and then deleted in the opposite order on Node exit.
|
// and then deleted in the opposite order on Node exit.
|
||||||
|
|
||||||
Logger *log; // may be null
|
Logger *log; // may be null
|
||||||
CMWC4096 *prng;
|
CMWC4096 *prng;
|
||||||
Demarc *demarc;
|
|
||||||
Multicaster *multicaster;
|
Multicaster *multicaster;
|
||||||
Switch *sw;
|
Switch *sw;
|
||||||
|
Demarc *demarc;
|
||||||
Topology *topology;
|
Topology *topology;
|
||||||
SysEnv *sysEnv;
|
SysEnv *sysEnv;
|
||||||
NodeConfig *nc;
|
NodeConfig *nc;
|
||||||
|
|
Loading…
Add table
Reference in a new issue