summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--node/Node.cpp26
-rw-r--r--node/PacketDecoder.hpp2
-rw-r--r--node/Peer.cpp12
-rw-r--r--node/Peer.hpp5
-rw-r--r--node/Switch.hpp2
5 files changed, 26 insertions, 21 deletions
diff --git a/node/Node.cpp b/node/Node.cpp
index 6d748798..ffd7568f 100644
--- a/node/Node.cpp
+++ b/node/Node.cpp
@@ -76,6 +76,7 @@
#include "SHA512.hpp"
#include "Service.hpp"
#include "SoftwareUpdater.hpp"
+#include "Buffer.hpp"
#include "../version.h"
@@ -84,15 +85,20 @@ namespace ZeroTier {
struct _LocalClientImpl
{
unsigned char key[32];
- UdpSocket *sock;
+ int sock;
void (*resultHandler)(void *,unsigned long,const char *);
void *arg;
unsigned int controlPort;
InetAddress localDestAddr;
Mutex inUseLock;
+
+ void threadMain()
+ throw()
+ {
+ }
};
-static void _CBlocalClientHandler(UdpSocket *sock,void *arg,const InetAddress &remoteAddr,const void *data,unsigned int len)
+static void _CBlocalClientHandler(const SharedPtr<Socket> &sock,void *arg,const InetAddress &from,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> &data)
{
_LocalClientImpl *impl = (_LocalClientImpl *)arg;
if (!impl)
@@ -100,11 +106,10 @@ static void _CBlocalClientHandler(UdpSocket *sock,void *arg,const InetAddress &r
if (!impl->resultHandler)
return; // sanity check
Mutex::Lock _l(impl->inUseLock);
-
try {
unsigned long convId = 0;
std::vector<std::string> results;
- if (!NodeConfig::decodeControlMessagePacket(impl->key,data,len,convId,results))
+ if (!NodeConfig::decodeControlMessagePacket(impl->key,data.data(),data.size(),convId,results))
return;
for(std::vector<std::string>::iterator r(results.begin());r!=results.end();++r)
impl->resultHandler(impl->arg,convId,r->c_str());
@@ -117,18 +122,19 @@ Node::LocalClient::LocalClient(const char *authToken,unsigned int controlPort,vo
{
_LocalClientImpl *impl = new _LocalClientImpl;
- UdpSocket *sock = (UdpSocket *)0;
+ impl->sock =
+
+ SocketManager *sm = (SocketManager *)0;
for(unsigned int i=0;i<5000;++i) {
try {
- sock = new UdpSocket(true,32768 + (rand() % 20000),false,&_CBlocalClientHandler,impl);
+ sm = new SocketManager(0,32768 + (rand() % 20000),&_CBlocalClientHandler,impl);
break;
} catch ( ... ) {
- sock = (UdpSocket *)0;
+ sm = (SocketManager *)0;
}
}
- // If socket fails to bind, there's a big problem like missing IPv4 stack
- if (sock) {
+ if (sm) {
{
unsigned int csk[64];
SHA512::hash(csk,authToken,(unsigned int)strlen(authToken));
@@ -142,7 +148,7 @@ Node::LocalClient::LocalClient(const char *authToken,unsigned int controlPort,vo
impl->localDestAddr = InetAddress::LO4;
impl->localDestAddr.setPort(impl->controlPort);
_impl = impl;
- } else delete impl;
+ } else delete impl; // big problem, no ports?
}
Node::LocalClient::~LocalClient()
diff --git a/node/PacketDecoder.hpp b/node/PacketDecoder.hpp
index 3c0588bc..26aa85ce 100644
--- a/node/PacketDecoder.hpp
+++ b/node/PacketDecoder.hpp
@@ -31,7 +31,7 @@
#include <stdexcept>
#include "Packet.hpp"
-#include "Demarc.hpp"
+#include "SocketManager.hpp"
#include "InetAddress.hpp"
#include "Utils.hpp"
#include "SharedPtr.hpp"
diff --git a/node/Peer.cpp b/node/Peer.cpp
index 67b9db23..bd2e7e43 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -98,23 +98,23 @@ void Peer::onReceive(
}
}
-Demarc::Port Peer::send(const RuntimeEnvironment *_r,const void *data,unsigned int len,uint64_t now)
+bool Peer::send(const RuntimeEnvironment *_r,const void *data,unsigned int len,uint64_t now)
{
if ((_ipv6p.isActive(now))||((!(_ipv4p.addr))&&(_ipv6p.addr))) {
- if (_r->demarc->send(_ipv6p.localPort,_ipv6p.addr,data,len,-1)) {
+ if (_r->demarc->send(_ipv6p.addr,data,len,-1)) {
_ipv6p.lastSend = now;
- return _ipv6p.localPort;
+ return true;
}
}
if (_ipv4p.addr) {
- if (_r->demarc->send(_ipv4p.localPort,_ipv4p.addr,data,len,-1)) {
+ if (_r->sm->send(_ipv4p.addr,data,len,-1)) {
_ipv4p.lastSend = now;
- return _ipv4p.localPort;
+ return true;
}
}
- return Demarc::NULL_PORT;
+ return false;
}
bool Peer::sendFirewallOpener(const RuntimeEnvironment *_r,uint64_t now)
diff --git a/node/Peer.hpp b/node/Peer.hpp
index f7c81cb0..ac56401a 100644
--- a/node/Peer.hpp
+++ b/node/Peer.hpp
@@ -118,7 +118,6 @@ public:
*/
void onReceive(
const RuntimeEnvironment *_r,
- Demarc::Port localPort,
const InetAddress &remoteAddr,
unsigned int hops,
uint64_t packetId,
@@ -134,9 +133,9 @@ public:
* @param data Data to send
* @param len Length of packet
* @param now Current time
- * @return NULL_PORT or port packet was sent from
+ * @return True if packet appears to have been sent
*/
- Demarc::Port send(const RuntimeEnvironment *_r,const void *data,unsigned int len,uint64_t now);
+ bool send(const RuntimeEnvironment *_r,const void *data,unsigned int len,uint64_t now);
/**
* Send firewall opener to active link
diff --git a/node/Switch.hpp b/node/Switch.hpp
index dbde2d1d..ca55ae94 100644
--- a/node/Switch.hpp
+++ b/node/Switch.hpp
@@ -44,7 +44,7 @@
#include "Array.hpp"
#include "Network.hpp"
#include "SharedPtr.hpp"
-#include "Demarc.hpp"
+#include "SocketManager.hpp"
#include "Multicaster.hpp"
#include "PacketDecoder.hpp"