summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-10-21 15:18:50 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-10-21 15:18:50 -0700
commit2436e22f46b97b281e5fcf861ba091c9cb70a76f (patch)
tree874024c3033711788ea0e6733f1f909c4a2e65ba /node
parent128a13107023075a8167bfdfb8ed9d404bd1dccd (diff)
downloadinfinitytier-2436e22f46b97b281e5fcf861ba091c9cb70a76f.tar.gz
infinitytier-2436e22f46b97b281e5fcf861ba091c9cb70a76f.zip
More work on abstracting socket manager.
Diffstat (limited to 'node')
-rw-r--r--node/Node.cpp12
-rw-r--r--node/Node.hpp7
-rw-r--r--node/RuntimeEnvironment.hpp4
-rw-r--r--node/SocketManager.hpp15
4 files changed, 15 insertions, 23 deletions
diff --git a/node/Node.cpp b/node/Node.cpp
index 1633d416..5990b83a 100644
--- a/node/Node.cpp
+++ b/node/Node.cpp
@@ -84,8 +84,6 @@ struct _NodeImpl
{
RuntimeEnvironment renv;
- unsigned int udpPort,tcpPort;
-
std::string reasonForTerminationStr;
volatile Node::ReasonForTermination reasonForTermination;
@@ -112,7 +110,6 @@ struct _NodeImpl
delete renv.updater; renv.updater = (SoftwareUpdater *)0;
delete renv.nc; renv.nc = (NodeConfig *)0; // shut down all networks, close taps, etc.
delete renv.topology; renv.topology = (Topology *)0; // now we no longer need routing info
- delete renv.sm; renv.sm = (SocketManager *)0; // close all sockets
delete renv.sw; renv.sw = (Switch *)0; // order matters less from here down
delete renv.mc; renv.mc = (Multicaster *)0;
delete renv.antiRec; renv.antiRec = (AntiRecursion *)0;
@@ -222,8 +219,7 @@ Node::Node(
const char *hp,
EthernetTapFactory *tf,
RoutingTable *rt,
- unsigned int udpPort,
- unsigned int tcpPort,
+ SocketManager *sm,
bool resetIdentity,
const char *overrideRootTopology) throw() :
_impl(new _NodeImpl)
@@ -236,6 +232,7 @@ Node::Node(
impl->renv.tapFactory = tf;
impl->renv.routingTable = rt;
+ impl->renv.sm = sm;
if (resetIdentity) {
// Forget identity and peer database, peer keys, etc.
@@ -255,8 +252,6 @@ Node::Node(
}
}
- impl->udpPort = udpPort & 0xffff;
- impl->tcpPort = tcpPort & 0xffff;
impl->reasonForTermination = Node::NODE_RUNNING;
impl->started = false;
impl->running = false;
@@ -400,7 +395,6 @@ Node::ReasonForTermination Node::run()
RR->antiRec = new AntiRecursion();
RR->mc = new Multicaster(RR);
RR->sw = new Switch(RR);
- RR->sm = new SocketManager(impl->udpPort,impl->tcpPort,&_CBztTraffic,RR);
RR->topology = new Topology(RR);
try {
RR->nc = new NodeConfig(RR);
@@ -666,7 +660,7 @@ Node::ReasonForTermination Node::run()
try {
unsigned long delay = std::min((unsigned long)ZT_MAX_SERVICE_LOOP_INTERVAL,RR->sw->doTimerTasks());
uint64_t start = Utils::now();
- RR->sm->poll(delay);
+ RR->sm->poll(delay,&_CBztTraffic,RR);
lastDelayDelta = (long)(Utils::now() - start) - (long)delay; // used to detect sleep/wake
} catch (std::exception &exc) {
LOG("unexpected exception running Switch doTimerTasks: %s",exc.what());
diff --git a/node/Node.hpp b/node/Node.hpp
index 259cdea2..1b338b22 100644
--- a/node/Node.hpp
+++ b/node/Node.hpp
@@ -36,6 +36,7 @@ namespace ZeroTier {
class EthernetTapFactory;
class RoutingTable;
+class SocketManager;
/**
* A ZeroTier One node
@@ -85,8 +86,7 @@ public:
* @param hp Home directory path or NULL for system-wide default for this platform
* @param tf Ethernet tap factory for platform network stack
* @param rt Routing table interface for platform network stack
- * @param udpPort UDP port or 0 to disable
- * @param tcpPort TCP port or 0 to disable
+ * @param sm Socket manager for physical network I/O
* @param resetIdentity If true, delete identity before starting and regenerate
* @param overrideRootTopology Override root topology with this dictionary (in string serialized format) and do not update (default: NULL for none)
*/
@@ -94,8 +94,7 @@ public:
const char *hp,
EthernetTapFactory *tf,
RoutingTable *rt,
- unsigned int udpPort,
- unsigned int tcpPort,
+ SocketManager *sm,
bool resetIdentity,
const char *overrideRootTopology = (const char *)0) throw();
diff --git a/node/RuntimeEnvironment.hpp b/node/RuntimeEnvironment.hpp
index 26c8da76..1061c452 100644
--- a/node/RuntimeEnvironment.hpp
+++ b/node/RuntimeEnvironment.hpp
@@ -75,13 +75,13 @@ public:
timeOfLastPacketReceived(0),
tapFactory((EthernetTapFactory *)0),
routingTable((RoutingTable *)0),
+ sm((SocketManager *)0),
log((Logger *)0),
prng((CMWC4096 *)0),
http((HttpClient *)0),
antiRec((AntiRecursion *)0),
mc((Multicaster *)0),
sw((Switch *)0),
- sm((SocketManager *)0),
topology((Topology *)0),
nc((NodeConfig *)0),
node((Node *)0),
@@ -117,6 +117,7 @@ public:
// These are passed in from outside and are not created or deleted by the ZeroTier node core
EthernetTapFactory *tapFactory;
RoutingTable *routingTable;
+ SocketManager *sm;
/*
* Order matters a bit here. These are constructed in this order
@@ -132,7 +133,6 @@ public:
AntiRecursion *antiRec;
Multicaster *mc;
Switch *sw;
- SocketManager *sm;
Topology *topology;
NodeConfig *nc;
Node *node;
diff --git a/node/SocketManager.hpp b/node/SocketManager.hpp
index 3ac53e3d..29cc94bf 100644
--- a/node/SocketManager.hpp
+++ b/node/SocketManager.hpp
@@ -48,9 +48,7 @@ namespace ZeroTier {
class SocketManager : NonCopyable
{
public:
- SocketManager(void (*packetHandler)(const SharedPtr<Socket> &,void *,const InetAddress &,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> &),void *arg) :
- _packetHandler(packetHandler),
- _arg(arg) {}
+ SocketManager() {}
virtual ~SocketManager() {}
/**
@@ -87,8 +85,13 @@ public:
* If called concurrently, one will block until the other completes.
*
* @param timeout Timeout in milliseconds, may return sooner if whack() is called
+ * @param handler Packet data handler
+ * @param arg Void argument to packet data handler
*/
- virtual void poll(unsigned long timeout) = 0;
+ virtual void poll(
+ unsigned long timeout,
+ void (*handler)(const SharedPtr<Socket> &,void *,const InetAddress &,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> &),
+ void *arg);
/**
* Cause current or next blocking poll() operation to timeout immediately
@@ -99,10 +102,6 @@ public:
* Close TCP sockets
*/
virtual void closeTcpSockets() = 0;
-
-protected:
- void (*_packetHandler)(const SharedPtr<Socket> &,void *,const InetAddress &,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> &);
- void *_arg;
};
} // namespace ZeroTier