Everything but the local config bus... blech.

This commit is contained in:
Adam Ierymenko 2014-03-18 14:33:57 -07:00
parent 91fef21973
commit 0b75992737
5 changed files with 26 additions and 21 deletions

View File

@ -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()

View File

@ -31,7 +31,7 @@
#include <stdexcept>
#include "Packet.hpp"
#include "Demarc.hpp"
#include "SocketManager.hpp"
#include "InetAddress.hpp"
#include "Utils.hpp"
#include "SharedPtr.hpp"

View File

@ -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)

View File

@ -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

View File

@ -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"