diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-04-09 18:22:04 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-04-09 18:22:04 -0700 |
commit | 6615a70027003a3896e51f713b109839dea03bfc (patch) | |
tree | f430fd0e6bca0f3b32e5a08f9734cbe2535b60f7 | |
parent | 46ecad451c2d7c305f1ca14be2be6786909dd8ff (diff) | |
download | infinitytier-6615a70027003a3896e51f713b109839dea03bfc.tar.gz infinitytier-6615a70027003a3896e51f713b109839dea03bfc.zip |
Service code builds now.
-rw-r--r-- | objects.mk | 5 | ||||
-rw-r--r-- | osdep/Phy.hpp | 6 | ||||
-rw-r--r-- | service/One.cpp | 38 | ||||
-rw-r--r-- | service/One.hpp | 8 |
4 files changed, 35 insertions, 22 deletions
@@ -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 diff --git a/osdep/Phy.hpp b/osdep/Phy.hpp index 6abdf8ad..688514f6 100644 --- a/osdep/Phy.hpp +++ b/osdep/Phy.hpp @@ -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; diff --git a/service/One.cpp b/service/One.cpp index f6d2f08d..c34f8f57 100644 --- a/service/One.cpp +++ b/service/One.cpp @@ -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,22 +108,22 @@ public: _phy.close(_v6TcpListenSocket); } - virtual ReasonForTermination reasonForTermination() + virtual ReasonForTermination reasonForTermination() const { Mutex::Lock _l(_termReason_m); return _termReason; } - virtual void waitForTermination() + virtual std::string fatalErrorMessage() const { - if (reasonForTermination() == ONE_STILL_RUNNING) - Thread::join(_thread); + Mutex::Lock _l(_termReason_m); + return _fatalErrorMessage; } - virtual std::string fatalErrorMessage() + virtual void waitForTermination() { - Mutex::Lock _l(_termReason_m); - return _fatalErrorMessage; + if (reasonForTermination() == ONE_STILL_RUNNING) + Thread::join(_thread); } virtual void terminate() @@ -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) diff --git a/service/One.hpp b/service/One.hpp index 78d32e36..3992ae39 100644 --- a/service/One.hpp +++ b/service/One.hpp @@ -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() {} |