mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
Service code builds now.
This commit is contained in:
parent
46ecad451c
commit
6615a70027
4 changed files with 35 additions and 22 deletions
|
@ -20,4 +20,7 @@ OBJS=\
|
||||||
node/SHA512.o \
|
node/SHA512.o \
|
||||||
node/Switch.o \
|
node/Switch.o \
|
||||||
node/Topology.o \
|
node/Topology.o \
|
||||||
node/Utils.o
|
node/Utils.o \
|
||||||
|
osdep/HttpClient.o \
|
||||||
|
osdep/OSUtils.o \
|
||||||
|
service/One.o
|
||||||
|
|
|
@ -743,7 +743,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void close(PhySocket *sock,bool callHandlers)
|
/**
|
||||||
|
* @param sock Socket to close
|
||||||
|
* @param callHandlers If true, call handlers for TCP connect (success: false) or close (default: true)
|
||||||
|
*/
|
||||||
|
inline void close(PhySocket *sock,bool callHandlers = true)
|
||||||
{
|
{
|
||||||
if (!sock)
|
if (!sock)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -64,7 +64,7 @@ class OneImpl : public One
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OneImpl(const char *hp,unsigned int port,NetworkConfigMaster *master,const char *overrideRootTopology) :
|
OneImpl(const char *hp,unsigned int port,NetworkConfigMaster *master,const char *overrideRootTopology) :
|
||||||
_phy(SphyOnDatagramFunction,SphyOnTcpWritableFunction,SphyOnTcpAcceptFunction,SphyOnTcpCloseFunction,SphyOnTcpDataFunction,SphyOnTcpWritableFunction,true),
|
_phy(SphyOnDatagramFunction,SphyOnTcpConnectFunction,SphyOnTcpAcceptFunction,SphyOnTcpCloseFunction,SphyOnTcpDataFunction,SphyOnTcpWritableFunction,true),
|
||||||
_master(master),
|
_master(master),
|
||||||
_overrideRootTopology((overrideRootTopology) ? overrideRootTopology : ""),
|
_overrideRootTopology((overrideRootTopology) ? overrideRootTopology : ""),
|
||||||
_node((Node *)0),
|
_node((Node *)0),
|
||||||
|
@ -75,7 +75,7 @@ public:
|
||||||
struct sockaddr_in in4;
|
struct sockaddr_in in4;
|
||||||
struct sockaddr_in6 in6;
|
struct sockaddr_in6 in6;
|
||||||
|
|
||||||
::memset(&in4,0,sizeof(in4));
|
::memset((void *)&in4,0,sizeof(in4));
|
||||||
in4.sin_family = AF_INET;
|
in4.sin_family = AF_INET;
|
||||||
in4.sin_port = Utils::hton(port);
|
in4.sin_port = Utils::hton(port);
|
||||||
_v4UdpSocket = _phy.udpBind((const struct sockaddr *)&in4,this,131072);
|
_v4UdpSocket = _phy.udpBind((const struct sockaddr *)&in4,this,131072);
|
||||||
|
@ -87,9 +87,9 @@ public:
|
||||||
throw std::runtime_error("cannot bind to port (TCP/IPv4)");
|
throw std::runtime_error("cannot bind to port (TCP/IPv4)");
|
||||||
}
|
}
|
||||||
|
|
||||||
::memset(in6,0,sizeof(in6));
|
::memset((void *)&in6,0,sizeof(in6));
|
||||||
in6.sin_family = AF_INET6;
|
in6.sin6_family = AF_INET6;
|
||||||
in6.sin_port = in4.sin_port;
|
in6.sin6_port = in4.sin_port;
|
||||||
_v6UdpSocket = _phy.udpBind((const struct sockaddr *)&in6,this,131072);
|
_v6UdpSocket = _phy.udpBind((const struct sockaddr *)&in6,this,131072);
|
||||||
_v6TcpListenSocket = _phy.tcpListen((const struct sockaddr *)&in6,this);
|
_v6TcpListenSocket = _phy.tcpListen((const struct sockaddr *)&in6,this);
|
||||||
|
|
||||||
|
@ -108,24 +108,24 @@ public:
|
||||||
_phy.close(_v6TcpListenSocket);
|
_phy.close(_v6TcpListenSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ReasonForTermination reasonForTermination()
|
virtual ReasonForTermination reasonForTermination() const
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_termReason_m);
|
Mutex::Lock _l(_termReason_m);
|
||||||
return _termReason;
|
return _termReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::string fatalErrorMessage() const
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_termReason_m);
|
||||||
|
return _fatalErrorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void waitForTermination()
|
virtual void waitForTermination()
|
||||||
{
|
{
|
||||||
if (reasonForTermination() == ONE_STILL_RUNNING)
|
if (reasonForTermination() == ONE_STILL_RUNNING)
|
||||||
Thread::join(_thread);
|
Thread::join(_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string fatalErrorMessage()
|
|
||||||
{
|
|
||||||
Mutex::Lock _l(_termReason_m);
|
|
||||||
return _fatalErrorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void terminate()
|
virtual void terminate()
|
||||||
{
|
{
|
||||||
_run_m.lock();
|
_run_m.lock();
|
||||||
|
@ -139,11 +139,17 @@ public:
|
||||||
inline void phyOnDatagramFunction(PhySocket *sock,const struct sockaddr *from,void *data,unsigned long len)
|
inline void phyOnDatagramFunction(PhySocket *sock,const struct sockaddr *from,void *data,unsigned long len)
|
||||||
{
|
{
|
||||||
InetAddress fromss(from);
|
InetAddress fromss(from);
|
||||||
ZT1_ResultCode rc = _node->processWirePacket(OSUtils::now(),(const struct sockaddr_storage *)&fromss,0,reinterpret_cast<uint64_t *>(&_nextBackgroundTaskDeadline));
|
ZT1_ResultCode rc = _node->processWirePacket(
|
||||||
|
OSUtils::now(),
|
||||||
|
(const struct sockaddr_storage *)&fromss,
|
||||||
|
0,
|
||||||
|
data,
|
||||||
|
len,
|
||||||
|
const_cast<uint64_t *>(&_nextBackgroundTaskDeadline));
|
||||||
if (ZT1_ResultCode_isFatal(rc)) {
|
if (ZT1_ResultCode_isFatal(rc)) {
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
Utils::snprintf(tmp,sizeof(tmp),"fatal error code from processWirePacket(%d)",(int)rc);
|
Utils::snprintf(tmp,sizeof(tmp),"fatal error code from processWirePacket(%d)",(int)rc);
|
||||||
Mutex::Lock _termReason_m;
|
Mutex::Lock _l(_termReason_m);
|
||||||
_termReason = ONE_UNRECOVERABLE_ERROR;
|
_termReason = ONE_UNRECOVERABLE_ERROR;
|
||||||
_fatalErrorMessage = tmp;
|
_fatalErrorMessage = tmp;
|
||||||
this->terminate();
|
this->terminate();
|
||||||
|
@ -178,7 +184,7 @@ public:
|
||||||
{
|
{
|
||||||
switch(event) {
|
switch(event) {
|
||||||
case ZT1_EVENT_FATAL_ERROR_IDENTITY_COLLISION: {
|
case ZT1_EVENT_FATAL_ERROR_IDENTITY_COLLISION: {
|
||||||
Mutex::Lock _termReason_m;
|
Mutex::Lock _l(_termReason_m);
|
||||||
_termReason = ONE_IDENTITY_COLLISION;
|
_termReason = ONE_IDENTITY_COLLISION;
|
||||||
_fatalErrorMessage = "identity/address collision";
|
_fatalErrorMessage = "identity/address collision";
|
||||||
this->terminate();
|
this->terminate();
|
||||||
|
@ -288,7 +294,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
static void SphyOnDatagramFunction(PhySocket *sock,void **uptr,const struct sockaddr *from,void *data,unsigned long len)
|
static void SphyOnDatagramFunction(PhySocket *sock,void **uptr,const struct sockaddr *from,void *data,unsigned long len)
|
||||||
{ reinterpret_cast<OneImpl *>(*uptr)->phyOnDatagramFunction(sock,data,len); }
|
{ reinterpret_cast<OneImpl *>(*uptr)->phyOnDatagramFunction(sock,from,data,len); }
|
||||||
static void SphyOnTcpConnectFunction(PhySocket *sock,void **uptr,bool success)
|
static void SphyOnTcpConnectFunction(PhySocket *sock,void **uptr,bool success)
|
||||||
{ reinterpret_cast<OneImpl *>(*uptr)->phyOnTcpConnectFunction(sock,success); }
|
{ reinterpret_cast<OneImpl *>(*uptr)->phyOnTcpConnectFunction(sock,success); }
|
||||||
static void SphyOnTcpAcceptFunction(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,const struct sockaddr *from)
|
static void SphyOnTcpAcceptFunction(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,const struct sockaddr *from)
|
||||||
|
|
|
@ -78,7 +78,7 @@ public:
|
||||||
static One *newInstance(
|
static One *newInstance(
|
||||||
const char *hp,
|
const char *hp,
|
||||||
unsigned int port,
|
unsigned int port,
|
||||||
NetworkConfigMaster *master = (NetworkConfigMaster *)0),
|
NetworkConfigMaster *master = (NetworkConfigMaster *)0,
|
||||||
const char *overrideRootTopology = (const char *)0);
|
const char *overrideRootTopology = (const char *)0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,12 +89,12 @@ public:
|
||||||
/**
|
/**
|
||||||
* @return Reason for terminating or ONE_STILL_RUNNING if running
|
* @return Reason for terminating or ONE_STILL_RUNNING if running
|
||||||
*/
|
*/
|
||||||
virtual ReasonForTermination reasonForTermination() = 0;
|
virtual ReasonForTermination reasonForTermination() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Fatal error message or empty string if none
|
* @return Fatal error message or empty string if none
|
||||||
*/
|
*/
|
||||||
virtual std::string fatalErrorMessage() = 0;
|
virtual std::string fatalErrorMessage() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block until service terminates
|
* Block until service terminates
|
||||||
|
@ -111,7 +111,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* @return True if service is still running
|
* @return True if service is still running
|
||||||
*/
|
*/
|
||||||
inline isRunning() const { return (this->reasonForTermination() == ONE_STILL_RUNNING); }
|
inline bool isRunning() const { return (this->reasonForTermination() == ONE_STILL_RUNNING); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
One() {}
|
One() {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue