mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-20 17:52:46 +00:00
Service code builds now.
This commit is contained in:
parent
46ecad451c
commit
6615a70027
@ -20,4 +20,7 @@ OBJS=\
|
||||
node/SHA512.o \
|
||||
node/Switch.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)
|
||||
return;
|
||||
|
@ -64,7 +64,7 @@ class OneImpl : public One
|
||||
{
|
||||
public:
|
||||
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),
|
||||
_overrideRootTopology((overrideRootTopology) ? overrideRootTopology : ""),
|
||||
_node((Node *)0),
|
||||
@ -75,7 +75,7 @@ public:
|
||||
struct sockaddr_in in4;
|
||||
struct sockaddr_in6 in6;
|
||||
|
||||
::memset(&in4,0,sizeof(in4));
|
||||
::memset((void *)&in4,0,sizeof(in4));
|
||||
in4.sin_family = AF_INET;
|
||||
in4.sin_port = Utils::hton(port);
|
||||
_v4UdpSocket = _phy.udpBind((const struct sockaddr *)&in4,this,131072);
|
||||
@ -87,9 +87,9 @@ public:
|
||||
throw std::runtime_error("cannot bind to port (TCP/IPv4)");
|
||||
}
|
||||
|
||||
::memset(in6,0,sizeof(in6));
|
||||
in6.sin_family = AF_INET6;
|
||||
in6.sin_port = in4.sin_port;
|
||||
::memset((void *)&in6,0,sizeof(in6));
|
||||
in6.sin6_family = AF_INET6;
|
||||
in6.sin6_port = in4.sin_port;
|
||||
_v6UdpSocket = _phy.udpBind((const struct sockaddr *)&in6,this,131072);
|
||||
_v6TcpListenSocket = _phy.tcpListen((const struct sockaddr *)&in6,this);
|
||||
|
||||
@ -108,24 +108,24 @@ public:
|
||||
_phy.close(_v6TcpListenSocket);
|
||||
}
|
||||
|
||||
virtual ReasonForTermination reasonForTermination()
|
||||
virtual ReasonForTermination reasonForTermination() const
|
||||
{
|
||||
Mutex::Lock _l(_termReason_m);
|
||||
return _termReason;
|
||||
}
|
||||
|
||||
virtual std::string fatalErrorMessage() const
|
||||
{
|
||||
Mutex::Lock _l(_termReason_m);
|
||||
return _fatalErrorMessage;
|
||||
}
|
||||
|
||||
virtual void waitForTermination()
|
||||
{
|
||||
if (reasonForTermination() == ONE_STILL_RUNNING)
|
||||
Thread::join(_thread);
|
||||
}
|
||||
|
||||
virtual std::string fatalErrorMessage()
|
||||
{
|
||||
Mutex::Lock _l(_termReason_m);
|
||||
return _fatalErrorMessage;
|
||||
}
|
||||
|
||||
virtual void terminate()
|
||||
{
|
||||
_run_m.lock();
|
||||
@ -139,11 +139,17 @@ public:
|
||||
inline void phyOnDatagramFunction(PhySocket *sock,const struct sockaddr *from,void *data,unsigned long len)
|
||||
{
|
||||
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)) {
|
||||
char tmp[256];
|
||||
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;
|
||||
_fatalErrorMessage = tmp;
|
||||
this->terminate();
|
||||
@ -178,7 +184,7 @@ public:
|
||||
{
|
||||
switch(event) {
|
||||
case ZT1_EVENT_FATAL_ERROR_IDENTITY_COLLISION: {
|
||||
Mutex::Lock _termReason_m;
|
||||
Mutex::Lock _l(_termReason_m);
|
||||
_termReason = ONE_IDENTITY_COLLISION;
|
||||
_fatalErrorMessage = "identity/address collision";
|
||||
this->terminate();
|
||||
@ -288,7 +294,7 @@ private:
|
||||
};
|
||||
|
||||
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)
|
||||
{ reinterpret_cast<OneImpl *>(*uptr)->phyOnTcpConnectFunction(sock,success); }
|
||||
static void SphyOnTcpAcceptFunction(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,const struct sockaddr *from)
|
||||
|
@ -78,7 +78,7 @@ public:
|
||||
static One *newInstance(
|
||||
const char *hp,
|
||||
unsigned int port,
|
||||
NetworkConfigMaster *master = (NetworkConfigMaster *)0),
|
||||
NetworkConfigMaster *master = (NetworkConfigMaster *)0,
|
||||
const char *overrideRootTopology = (const char *)0);
|
||||
|
||||
/**
|
||||
@ -89,12 +89,12 @@ public:
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
virtual std::string fatalErrorMessage() = 0;
|
||||
virtual std::string fatalErrorMessage() const = 0;
|
||||
|
||||
/**
|
||||
* Block until service terminates
|
||||
@ -111,7 +111,7 @@ public:
|
||||
/**
|
||||
* @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:
|
||||
One() {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user