diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-03-31 18:17:11 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-03-31 18:17:11 -0700 |
commit | b7238557515bcc12360eaf9d6e048542714250e5 (patch) | |
tree | ae9f4f45bb5edc7c8e934655f27ed818395b0909 | |
parent | 36eab4f1a9905e6bc128221d8e59e9f9489c291f (diff) | |
download | infinitytier-b7238557515bcc12360eaf9d6e048542714250e5.tar.gz infinitytier-b7238557515bcc12360eaf9d6e048542714250e5.zip |
Refactoring... lalalala...
-rw-r--r-- | include/ZeroTierOne.h | 8 | ||||
-rw-r--r-- | node/Node.cpp | 123 | ||||
-rw-r--r-- | node/Node.hpp | 27 | ||||
-rw-r--r-- | node/RuntimeEnvironment.hpp | 12 |
4 files changed, 145 insertions, 25 deletions
diff --git a/include/ZeroTierOne.h b/include/ZeroTierOne.h index 61cee72e..3ba98d28 100644 --- a/include/ZeroTierOne.h +++ b/include/ZeroTierOne.h @@ -203,7 +203,7 @@ typedef struct /** * Packet data */ - const char packetData[ZT1_MAX_WIRE_MESSAGE_LENGTH]; + char packetData[ZT1_MAX_WIRE_MESSAGE_LENGTH]; /** * Length of packet @@ -244,7 +244,7 @@ typedef struct /** * Ethernet frame data */ - const char frameData[ZT1_MAX_MTU]; + char frameData[ZT1_MAX_MTU]; /** * Ethernet frame length @@ -717,9 +717,7 @@ void ZT1_Node_freeQueryResult(void *qr); * @param networkConfigMasterInstance Instance of NetworkConfigMaster C++ class or NULL to disable * @return OK (0) or error code if a fatal error condition has occurred */ -enum ZT1_ResultCode ZT1_Node_setNetconfMaster( - ZT1_Node *node, - void *networkConfigMasterInstance); +void ZT1_Node_setNetconfMaster(ZT1_Node *node,void *networkConfigMasterInstance); /** * Get ZeroTier One version diff --git a/node/Node.cpp b/node/Node.cpp index dcf1d657..7b51d3bd 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -27,4 +27,127 @@ #include "Node.hpp" #include "RuntimeEnvironment.hpp" +#include "NetworkConfigMaster.hpp" +#include "CMWC4096.hpp" +#include "Switch.hpp" +#include "Multicaster.hpp" +#include "AntiRecursion.hpp" +#include "Topology.hpp" +#include "Buffer.hpp" +#include "Packet.hpp" +#include "Logger.hpp" +#include "Address.hpp" +#include "Identity.hpp" +namespace ZeroTier { + +Node::Node( + ZT1_DataStoreGetFunction *dataStoreGetFunction, + ZT1_DataStorePutFunction *dataStorePutFunction, + ZT1_VirtualNetworkConfigCallback *networkConfigCallback, + ZT1_StatusCallback *statusCallback) : + RR(new RuntimeEnvironment(this)), + _outputWireMessages((ZT1_WireMessage *)0), + _outputWireMessageCount(0), + _outputWireMessageCapacity(8), + _outputWireMessages_m(), + _outputFrames((ZT1_VirtualNetworkFrame *)0), + _outputFrameCount(0), + _outputFrameCapacity(8), + _outputFrames_m(), + _dataStoreGetFunction(dataStoreGetFunction), + _dataStorePutFunction(dataStorePutFunction), + _networkConfigCallback(networkConfigCallback), + _statusCallback(statusCallback), + _networks(), + _networks_m(), + _now(0), + _timeOfLastPacketReceived(0), + _timeOfLastPrivilegedPacket(0), + _spamCounter(0) +{ + try { + _outputWireMessages = new ZT1_WireMessage[_outputWireMessageCapacity]; + _outputFrames = new ZT1_VirtualNetworkFrame[_outputFrameCapacity]; + RR->prng = new CMWC4096(); + RR->sw = new Switch(RR); + RR->mc = new Multicaster(RR); + RR->antiRec = new AntiRecursion(RR); + RR->topology = new Topology(RR); + } catch ( ... ) { + delete [] _outputFrames; + delete [] _outputWireMessages; + delete RR->topology; + delete RR->antiRec; + delete RR->mc; + delete RR->sw; + delete RR->prng; + delete RR->log; + delete RR; + throw; + } +} + +Node::~Node() +{ + delete [] _outputFrames; + delete [] _outputWireMessages; + delete RR->topology; + delete RR->antiRec; + delete RR->mc; + delete RR->sw; + delete RR->prng; + delete RR->log; + delete RR; +} + +ZT1_ResultCode Node::run( + uint64_t now, + const ZT1_WireMessage *inputWireMessages, + unsigned int inputWireMessageCount, + const ZT1_VirtualNetworkFrame *inputFrames, + unsigned int inputFrameCount, + const ZT1_WireMessage **outputWireMessages, + unsigned int *outputWireMessageCount, + const ZT1_VirtualNetworkFrame **outputFrames, + unsigned int *outputLanFrameCount, + unsigned long *maxNextInterval) +{ +} + +ZT1_ResultCode Node::join(uint64_t nwid) +{ +} + +ZT1_ResultCode Node::leave(uint64_t nwid) +{ +} + +void Node::status(ZT1_NodeStatus *status) +{ +} + +ZT1_PeerList *Node::peers() +{ +} + +ZT1_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid) +{ +} + +ZT1_VirtualNetworkList *Node::listNetworks() +{ +} + +void Node::freeQueryResult(void *qr) +{ + if (qr) + ::free(qr); +} + +void Node::setNetconfMaster(void *networkConfigMasterInstance) +{ + RR->netconfMaster = reinterpret_cast<NetworkConfigMaster *>(networkConfigMasterInstance); +} + +} // namespace ZeroTier diff --git a/node/Node.hpp b/node/Node.hpp index fc78fd80..6986cc5f 100644 --- a/node/Node.hpp +++ b/node/Node.hpp @@ -45,6 +45,7 @@ namespace ZeroTier { class RuntimeEnvironment; +class Network; /** * Implementation of Node object as defined in CAPI @@ -68,8 +69,8 @@ public: uint64_t now, const ZT1_WireMessage *inputWireMessages, unsigned int inputWireMessageCount, - const ZT1_VirtualLanFrame *inputLanFrames, - unsigned int inputLanFrameCount, + const ZT1_VirtualNetworkFrame *inputFrames, + unsigned int inputFrameCount, const ZT1_WireMessage **outputWireMessages, unsigned int *outputWireMessageCount, const ZT1_VirtualNetworkFrame **outputFrames, @@ -90,9 +91,7 @@ public: void freeQueryResult(void *qr); - ZT1_ResultCode setNetconfMaster( - ZT1_Node *node, - void *networkConfigMasterInstance); + void setNetconfMaster(void *networkConfigMasterInstance); // Internal functions ------------------------------------------------------ @@ -123,7 +122,7 @@ public: delete [] old; } ZT1_WireMessage &wm = _outputWireMessages[_outputWireMessageCount++]; - memcpy(&(wm.address),&addr,sizeof(ZT_SOCKADDR_STORAGE)); + memcpy(&(wm.address),&addr,sizeof(struct sockaddr_storage)); wm.desperation = this->desperation(); wm.spam = (int)((++_spamCounter % ZT_DESPERATION_SPAM_EVERY) == 0); memcpy(wm.packetData,data,len); @@ -164,11 +163,11 @@ public: * @param nwid Network ID * @return Network instance */ - inline SharedPtr<Network> network(uint64_t nwid) + inline Network *network(uint64_t nwid) { Mutex::Lock _l(_networks_m); - std::map< uint64_t,Network >::iterator nw(_networks.find(nwid)); - return ((nw == _networks.end()) ? SharedPtr<Network>() : nw->second); + std::map< uint64_t,Network * >::iterator nw(_networks.find(nwid)); + return ((nw == _networks.end()) ? (Network *)0 : nw->second); } private: @@ -184,15 +183,15 @@ private: unsigned long _outputFrameCapacity; Mutex _outputFrames_m; - ZT1_DataStoreGetFunction *_dataStoreGetFunction, - ZT1_DataStorePutFunction *_dataStorePutFunction, - ZT1_VirtualPortConfigCallback *_portConfigCallback, - ZT1_StatusCallback *_statusCallback); + ZT1_DataStoreGetFunction *_dataStoreGetFunction; + ZT1_DataStorePutFunction *_dataStorePutFunction; + ZT1_VirtualNetworkConfigCallback *_networkConfigCallback; + ZT1_StatusCallback *_statusCallback; //Dictionary _localConfig; // persisted as local.conf //Mutex _localConfig_m; - std::map< uint64_t,SharedPtr<Network> > _networks; + std::map< uint64_t,Network * > _networks; Mutex _networks_m; uint64_t _now; // time of last run() diff --git a/node/RuntimeEnvironment.hpp b/node/RuntimeEnvironment.hpp index 4e3a75c3..9600b9dc 100644 --- a/node/RuntimeEnvironment.hpp +++ b/node/RuntimeEnvironment.hpp @@ -60,7 +60,8 @@ class NetworkConfigMaster; class RuntimeEnvironment { public: - RuntimeEnvironment() : + RuntimeEnvironment(Node *n) : + node(n), identity(), netconfMaster((NetworkConfigMaster *)0), log((Logger *)0), @@ -68,12 +69,13 @@ public: sw((Switch *)0), mc((Multicaster *)0), antiRec((AntiRecursion *)0), - topology((Topology *)0), - nc((NodeConfig *)0), - node((Node *)0) + topology((Topology *)0) { } + // Node instance that owns this RuntimeEnvironment + Node *const node; + // This node's identity Identity identity; @@ -94,8 +96,6 @@ public: Multicaster *mc; AntiRecursion *antiRec; Topology *topology; - NodeConfig *nc; - Node *node; }; } // namespace ZeroTier |