summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-01 14:59:44 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-01 14:59:44 -0700
commit8130848020d901893e7af2963b3a5fbea3abb74c (patch)
treebade0f7b9668f7ecfc4de5bd2198dee39b2536b0 /node
parent7ff0cab1b7b6a9bfe5880dd4fefbd947c6eb78e2 (diff)
downloadinfinitytier-8130848020d901893e7af2963b3a5fbea3abb74c.tar.gz
infinitytier-8130848020d901893e7af2963b3a5fbea3abb74c.zip
More refactoring... and update the API a bit... turns out my strategy for reducing indirect function calls also increased memcpy()s which are more expensive. This is simpler and faster.
Diffstat (limited to 'node')
-rw-r--r--node/Constants.hpp24
-rw-r--r--node/Node.cpp38
-rw-r--r--node/Node.hpp108
3 files changed, 62 insertions, 108 deletions
diff --git a/node/Constants.hpp b/node/Constants.hpp
index ff91417c..21227682 100644
--- a/node/Constants.hpp
+++ b/node/Constants.hpp
@@ -28,6 +28,8 @@
#ifndef ZT_CONSTANTS_HPP
#define ZT_CONSTANTS_HPP
+#include "../include/ZeroTierOne.h"
+
//
// This include file also auto-detects and canonicalizes some environment
// information defines:
@@ -154,28 +156,8 @@
/**
* Default MTU used for Ethernet tap device
- *
- * This is pretty much an unchangeable global constant. To make it change
- * across nodes would require logic to send ICMP packet too big messages,
- * which would complicate things. 1500 has been good enough on most LANs
- * for ages, so a larger MTU should be fine for the forseeable future. This
- * typically results in two UDP packets per single large frame. Experimental
- * results seem to show that this is good. Larger MTUs resulting in more
- * fragments seemed too brittle on slow/crummy links for no benefit.
- *
- * If this does change, also change it in tap.h in the tuntaposx code under
- * mac-tap.
- *
- * Overhead for a normal frame split into two packets:
- *
- * 1414 = 1444 (typical UDP MTU) - 28 (packet header) - 2 (ethertype)
- * 1428 = 1444 (typical UDP MTU) - 16 (fragment header)
- * SUM: 2842
- *
- * We use 2800, which leaves some room for other payload in other types of
- * messages such as multicast propagation or future support for bridging.
*/
-#define ZT_IF_MTU 2800
+#define ZT_IF_MTU ZT1_MAX_MTU
/**
* Default interface metric for ZeroTier taps -- should be higher than physical ports
diff --git a/node/Node.cpp b/node/Node.cpp
index 7b51d3bd..0808062f 100644
--- a/node/Node.cpp
+++ b/node/Node.cpp
@@ -44,19 +44,15 @@ namespace ZeroTier {
Node::Node(
ZT1_DataStoreGetFunction *dataStoreGetFunction,
ZT1_DataStorePutFunction *dataStorePutFunction,
+ ZT1_WirePacketSendFunction *wirePacketSendFunction,
+ ZT1_VirtualNetworkFrameFunction *virtualNetworkFrameFunction,
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),
+ _wirePacketSendFunction(wirePacketSendFunction),
+ _virtualNetworkFrameFunction(virtualNetworkFrameFunction),
_networkConfigCallback(networkConfigCallback),
_statusCallback(statusCallback),
_networks(),
@@ -67,16 +63,12 @@ Node::Node(
_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;
@@ -90,8 +82,6 @@ Node::Node(
Node::~Node()
{
- delete [] _outputFrames;
- delete [] _outputWireMessages;
delete RR->topology;
delete RR->antiRec;
delete RR->mc;
@@ -101,25 +91,19 @@ Node::~Node()
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::join(uint64_t nwid)
+ZT1_ResultCode Node::leave(uint64_t nwid)
{
}
-ZT1_ResultCode Node::leave(uint64_t nwid)
+ZT1_ResultCode Node::multicastSubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
+{
+}
+
+ZT1_ResultCode Node::multicastUnsubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
{
}
diff --git a/node/Node.hpp b/node/Node.hpp
index 6986cc5f..0f11f3b7 100644
--- a/node/Node.hpp
+++ b/node/Node.hpp
@@ -58,6 +58,8 @@ public:
Node(
ZT1_DataStoreGetFunction *dataStoreGetFunction,
ZT1_DataStorePutFunction *dataStorePutFunction,
+ ZT1_WirePacketSendFunction *wirePacketSendFunction,
+ ZT1_VirtualNetworkFrameFunction *virtualNetworkFrameFunction,
ZT1_VirtualNetworkConfigCallback *networkConfigCallback,
ZT1_StatusCallback *statusCallback);
@@ -65,32 +67,38 @@ public:
// Public API Functions ----------------------------------------------------
- ZT1_ResultCode run(
+ ZT1_ResultCode processWirePacket(
+ ZT1_Node *node,
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);
-
+ const struct sockaddr_storage *remoteAddress,
+ int linkDesperation,
+ const void *packetData,
+ unsigned int packetLength,
+ uint64_t *nextCallDeadline);
+ ZT1_ResultCode processVirtualNetworkFrame(
+ ZT1_Node *node,
+ uint64_t now,
+ uint64_t nwid,
+ uint64_t sourceMac,
+ uint64_t destMac,
+ unsigned int etherType,
+ unsigned int vlanId,
+ const void *frameData,
+ unsigned int frameLength,
+ uint64_t *nextCallDeadline);
+ ZT1_Resultcode processNothing(
+ ZT1_Node *node,
+ uint64_t now,
+ uint64_t *nextCallDeadline);
ZT1_ResultCode join(uint64_t nwid);
-
ZT1_ResultCode leave(uint64_t nwid);
-
+ ZT1_ResultCode multicastSubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi = 0);
+ ZT1_ResultCode multicastUnsubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi = 0);
void status(ZT1_NodeStatus *status);
-
ZT1_PeerList *peers();
-
ZT1_VirtualNetworkConfig *networkConfig(uint64_t nwid);
-
ZT1_VirtualNetworkList *listNetworks();
-
void freeQueryResult(void *qr);
-
void setNetconfMaster(void *networkConfigMasterInstance);
// Internal functions ------------------------------------------------------
@@ -114,19 +122,13 @@ public:
*/
inline void putPacket(const InetAddress &addr,const void *data,unsigned int len)
{
- Mutex::Lock _l(_outputWireMessages_m);
- if (_outputWireMessageCount >= _outputWireMessageCapacity) {
- ZT1_WireMessage *old = _outputWireMessages;
- _outputWireMessages = new ZT1_WireMessage[_outputWireMessageCapacity *= 2];
- memcpy(_outputWireMessages,old,sizeof(ZT1_WireMessage) * _outputWireMessageCount);
- delete [] old;
- }
- ZT1_WireMessage &wm = _outputWireMessages[_outputWireMessageCount++];
- 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);
- wm.packetLength = len;
+ _wirePacketSendFunction(
+ reinterpret_cast<ZT1_Node *>(this),
+ reinterpret_cast<const struct sockaddr_storage *>(&addr),
+ this->desperation(),
+ (int)((++_spamCounter % ZT_DESPERATION_SPAM_EVERY) == 0),
+ data,
+ len);
}
/**
@@ -142,21 +144,15 @@ public:
*/
inline void putFrame(uint64_t nwid,const MAC &source,const MAC &dest,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len)
{
- Mutex::Lock _l(_outputFrames_m);
- if (_outputFrameCount >= _outputFrameCapacity) {
- ZT1_VirtualNetworkFrame *old = _outputFrames;
- _outputFrames = new ZT1_VirtualNetworkFrame[_outputFrameCapacity *= 2];
- memcpy(_outputFrames,old,sizeof(ZT1_VirtualNetworkFrame) * _outputFrameCount);
- delete [] old;
- }
- ZT1_VirtualNetworkFrame &f = _outputFrames[_outputFrameCount++];
- f.nwid = nwid;
- f.sourceMac = source.toInt();
- f.destMac = dest.toInt();
- f.etherType = etherType;
- f.vlanId = vlanId;
- memcpy(f.frameData,data,len);
- f.frameLength = len;
+ _virtualNetworkFrameFunction(
+ reinterpret_cast<ZT1_Node *>(this),
+ nwid,
+ source.toInt(),
+ dest.toInt(),
+ etherType,
+ vlanId,
+ data,
+ len);
}
/**
@@ -173,18 +169,10 @@ public:
private:
RuntimeEnvironment *RR;
- ZT1_WireMessage *_outputWireMessages;
- unsigned long _outputWireMessageCount;
- unsigned long _outputWireMessageCapacity;
- Mutex _outputWireMessages_m;
-
- ZT1_VirtualNetworkFrame *_outputFrames;
- unsigned long _outputFrameCount;
- unsigned long _outputFrameCapacity;
- Mutex _outputFrames_m;
-
ZT1_DataStoreGetFunction *_dataStoreGetFunction;
ZT1_DataStorePutFunction *_dataStorePutFunction;
+ ZT1_WirePacketSendFunction *_wirePacketSendFunction;
+ ZT1_VirtualNetworkFrameFunction *_virtualNetworkFrameFunction;
ZT1_VirtualNetworkConfigCallback *_networkConfigCallback;
ZT1_StatusCallback *_statusCallback;
@@ -194,10 +182,10 @@ private:
std::map< uint64_t,Network * > _networks;
Mutex _networks_m;
- uint64_t _now; // time of last run()
- uint64_t _timeOfLastPacketReceived;
- uint64_t _timeOfLastPrivilgedPacket;
- unsigned int _spamCounter; // used to "spam" every Nth packet
+ volatile uint64_t _now; // time of last run()
+ volatile uint64_t _timeOfLastPacketReceived;
+ volatile _timeOfLastPrivilgedPacket;
+ volatile unsigned int _spamCounter; // used to "spam" every Nth packet
};
} // namespace ZeroTier