mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-19 21:17:52 +00:00
Refactoring... lalalala...
This commit is contained in:
parent
36eab4f1a9
commit
b723855751
@ -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
|
||||
|
123
node/Node.cpp
123
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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user