2015-04-01 00:53:34 +00:00
|
|
|
/*
|
|
|
|
* ZeroTier One - Network Virtualization Everywhere
|
2016-01-12 22:04:55 +00:00
|
|
|
* Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
|
2015-04-01 00:53:34 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-05-01 03:40:33 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2015-04-01 23:27:14 +00:00
|
|
|
#include "../version.h"
|
|
|
|
|
|
|
|
#include "Constants.hpp"
|
2015-04-01 00:53:34 +00:00
|
|
|
#include "Node.hpp"
|
|
|
|
#include "RuntimeEnvironment.hpp"
|
2015-04-15 22:12:09 +00:00
|
|
|
#include "NetworkController.hpp"
|
2015-04-01 01:17:11 +00:00
|
|
|
#include "Switch.hpp"
|
|
|
|
#include "Multicaster.hpp"
|
|
|
|
#include "Topology.hpp"
|
|
|
|
#include "Buffer.hpp"
|
|
|
|
#include "Packet.hpp"
|
|
|
|
#include "Address.hpp"
|
|
|
|
#include "Identity.hpp"
|
2015-04-07 03:17:21 +00:00
|
|
|
#include "SelfAwareness.hpp"
|
2015-10-20 22:27:53 +00:00
|
|
|
#include "Cluster.hpp"
|
2015-04-01 00:53:34 +00:00
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
const struct sockaddr_storage ZT_SOCKADDR_NULL = {0};
|
|
|
|
|
2015-04-01 01:17:11 +00:00
|
|
|
namespace ZeroTier {
|
|
|
|
|
2015-04-06 21:50:53 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Public Node interface (C++, exposed via CAPI bindings) */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
2016-11-22 18:54:58 +00:00
|
|
|
Node::Node(void *uptr,const struct ZT_Node_Callbacks *callbacks,uint64_t now) :
|
2015-04-30 23:03:44 +00:00
|
|
|
_RR(this),
|
|
|
|
RR(&_RR),
|
2015-04-24 20:35:17 +00:00
|
|
|
_uPtr(uptr),
|
2015-07-07 17:49:50 +00:00
|
|
|
_prngStreamPtr(0),
|
2015-04-08 02:31:11 +00:00
|
|
|
_now(now),
|
|
|
|
_lastPingCheck(0),
|
2017-01-27 22:05:09 +00:00
|
|
|
_lastHousekeepingRun(0)
|
2015-04-01 01:17:11 +00:00
|
|
|
{
|
2016-11-22 18:54:58 +00:00
|
|
|
if (callbacks->version != 0)
|
|
|
|
throw std::runtime_error("callbacks struct version mismatch");
|
|
|
|
memcpy(&_cb,callbacks,sizeof(ZT_Node_Callbacks));
|
|
|
|
|
2015-04-09 00:10:21 +00:00
|
|
|
_online = false;
|
2015-04-06 21:50:53 +00:00
|
|
|
|
2016-09-09 15:43:58 +00:00
|
|
|
memset(_expectingRepliesToBucketPtr,0,sizeof(_expectingRepliesToBucketPtr));
|
|
|
|
memset(_expectingRepliesTo,0,sizeof(_expectingRepliesTo));
|
2016-11-18 20:59:04 +00:00
|
|
|
memset(_lastIdentityVerification,0,sizeof(_lastIdentityVerification));
|
2016-09-09 15:43:58 +00:00
|
|
|
|
2015-07-07 17:49:50 +00:00
|
|
|
// Use Salsa20 alone as a high-quality non-crypto PRNG
|
2016-11-22 18:54:58 +00:00
|
|
|
char foo[32];
|
|
|
|
Utils::getSecureRandom(foo,32);
|
|
|
|
_prng.init(foo,256,foo);
|
|
|
|
memset(_prngStream,0,sizeof(_prngStream));
|
2017-02-06 00:19:03 +00:00
|
|
|
_prng.crypt12(_prngStream,_prngStream,sizeof(_prngStream));
|
2016-11-22 18:54:58 +00:00
|
|
|
|
|
|
|
std::string idtmp(dataStoreGet("identity.secret"));
|
|
|
|
if ((!idtmp.length())||(!RR->identity.fromString(idtmp))||(!RR->identity.hasPrivate())) {
|
|
|
|
TRACE("identity.secret not found, generating...");
|
|
|
|
RR->identity.generate();
|
|
|
|
idtmp = RR->identity.toString(true);
|
|
|
|
if (!dataStorePut("identity.secret",idtmp,true))
|
|
|
|
throw std::runtime_error("unable to write identity.secret");
|
2015-07-07 17:49:50 +00:00
|
|
|
}
|
2016-11-22 18:54:58 +00:00
|
|
|
RR->publicIdentityStr = RR->identity.toString(false);
|
|
|
|
RR->secretIdentityStr = RR->identity.toString(true);
|
|
|
|
idtmp = dataStoreGet("identity.public");
|
|
|
|
if (idtmp != RR->publicIdentityStr) {
|
|
|
|
if (!dataStorePut("identity.public",RR->publicIdentityStr,false))
|
|
|
|
throw std::runtime_error("unable to write identity.public");
|
2015-04-30 23:03:44 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 01:17:11 +00:00
|
|
|
try {
|
|
|
|
RR->sw = new Switch(RR);
|
|
|
|
RR->mc = new Multicaster(RR);
|
|
|
|
RR->topology = new Topology(RR);
|
2015-04-07 03:17:21 +00:00
|
|
|
RR->sa = new SelfAwareness(RR);
|
2015-04-01 01:17:11 +00:00
|
|
|
} catch ( ... ) {
|
2015-04-07 03:17:21 +00:00
|
|
|
delete RR->sa;
|
2015-04-01 01:17:11 +00:00
|
|
|
delete RR->topology;
|
|
|
|
delete RR->mc;
|
|
|
|
delete RR->sw;
|
|
|
|
throw;
|
|
|
|
}
|
2015-04-07 23:41:56 +00:00
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
postEvent(ZT_EVENT_UP);
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node::~Node()
|
|
|
|
{
|
2015-04-20 22:12:31 +00:00
|
|
|
Mutex::Lock _l(_networks_m);
|
2015-11-05 20:22:58 +00:00
|
|
|
|
|
|
|
_networks.clear(); // ensure that networks are destroyed before shutdow
|
|
|
|
|
2015-04-07 03:17:21 +00:00
|
|
|
delete RR->sa;
|
2015-04-01 01:17:11 +00:00
|
|
|
delete RR->topology;
|
|
|
|
delete RR->mc;
|
|
|
|
delete RR->sw;
|
2016-09-13 21:27:18 +00:00
|
|
|
|
2015-10-20 22:27:53 +00:00
|
|
|
#ifdef ZT_ENABLE_CLUSTER
|
|
|
|
delete RR->cluster;
|
|
|
|
#endif
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_ResultCode Node::processWirePacket(
|
2015-04-01 23:27:14 +00:00
|
|
|
uint64_t now,
|
2015-09-24 23:21:36 +00:00
|
|
|
const struct sockaddr_storage *localAddress,
|
2015-04-01 23:27:14 +00:00
|
|
|
const struct sockaddr_storage *remoteAddress,
|
|
|
|
const void *packetData,
|
|
|
|
unsigned int packetLength,
|
2015-04-15 20:09:20 +00:00
|
|
|
volatile uint64_t *nextBackgroundTaskDeadline)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
2015-04-15 20:09:20 +00:00
|
|
|
_now = now;
|
2015-09-24 23:21:36 +00:00
|
|
|
RR->sw->onRemotePacket(*(reinterpret_cast<const InetAddress *>(localAddress)),*(reinterpret_cast<const InetAddress *>(remoteAddress)),packetData,packetLength);
|
|
|
|
return ZT_RESULT_OK;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_ResultCode Node::processVirtualNetworkFrame(
|
2015-04-01 23:27:14 +00:00
|
|
|
uint64_t now,
|
|
|
|
uint64_t nwid,
|
|
|
|
uint64_t sourceMac,
|
|
|
|
uint64_t destMac,
|
|
|
|
unsigned int etherType,
|
|
|
|
unsigned int vlanId,
|
|
|
|
const void *frameData,
|
|
|
|
unsigned int frameLength,
|
2015-04-15 20:09:20 +00:00
|
|
|
volatile uint64_t *nextBackgroundTaskDeadline)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
2015-04-15 20:09:20 +00:00
|
|
|
_now = now;
|
|
|
|
SharedPtr<Network> nw(this->network(nwid));
|
|
|
|
if (nw) {
|
2015-04-08 23:49:21 +00:00
|
|
|
RR->sw->onLocalEthernet(nw,MAC(sourceMac),MAC(destMac),etherType,vlanId,frameData,frameLength);
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_OK;
|
|
|
|
} else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 00:04:01 +00:00
|
|
|
// Closure used to ping upstream and active/online peers
|
2015-04-08 02:31:11 +00:00
|
|
|
class _PingPeersThatNeedPing
|
|
|
|
{
|
|
|
|
public:
|
2017-02-13 17:03:48 +00:00
|
|
|
_PingPeersThatNeedPing(const RuntimeEnvironment *renv,Hashtable< Address,std::vector<InetAddress> > &upstreamsToContact,uint64_t now) :
|
2015-04-09 00:10:21 +00:00
|
|
|
lastReceiveFromUpstream(0),
|
2015-04-08 02:31:11 +00:00
|
|
|
RR(renv),
|
2017-02-13 17:03:48 +00:00
|
|
|
_upstreamsToContact(upstreamsToContact),
|
2017-01-28 00:16:06 +00:00
|
|
|
_now(now),
|
|
|
|
_bestCurrentUpstream(RR->topology->getUpstreamPeer())
|
2015-06-01 23:53:58 +00:00
|
|
|
{
|
|
|
|
}
|
2015-04-08 02:31:11 +00:00
|
|
|
|
2015-10-13 19:10:44 +00:00
|
|
|
uint64_t lastReceiveFromUpstream; // tracks last time we got a packet from an 'upstream' peer like a root or a relay
|
2015-04-08 02:31:11 +00:00
|
|
|
|
|
|
|
inline void operator()(Topology &t,const SharedPtr<Peer> &p)
|
|
|
|
{
|
2017-02-13 17:03:48 +00:00
|
|
|
const std::vector<InetAddress> *const upstreamStableEndpoints = _upstreamsToContact.get(p->address());
|
2017-01-27 23:27:26 +00:00
|
|
|
if (upstreamStableEndpoints) {
|
|
|
|
bool contacted = false;
|
|
|
|
|
2017-02-13 17:03:48 +00:00
|
|
|
// Upstreams must be pinged constantly over both IPv4 and IPv6 to allow
|
|
|
|
// them to perform three way handshake introductions for both stacks.
|
|
|
|
|
2017-01-27 21:27:52 +00:00
|
|
|
if (!p->doPingAndKeepalive(_now,AF_INET)) {
|
|
|
|
for(unsigned long k=0,ptr=(unsigned long)RR->node->prng();k<(unsigned long)upstreamStableEndpoints->size();++k) {
|
|
|
|
const InetAddress &addr = (*upstreamStableEndpoints)[ptr++ % upstreamStableEndpoints->size()];
|
|
|
|
if (addr.ss_family == AF_INET) {
|
|
|
|
p->sendHELLO(InetAddress(),addr,_now);
|
2017-01-27 23:27:26 +00:00
|
|
|
contacted = true;
|
2017-01-27 21:27:52 +00:00
|
|
|
break;
|
2015-10-19 21:04:36 +00:00
|
|
|
}
|
2015-10-16 17:10:12 +00:00
|
|
|
}
|
2017-01-27 23:27:26 +00:00
|
|
|
} else contacted = true;
|
2017-01-27 21:27:52 +00:00
|
|
|
if (!p->doPingAndKeepalive(_now,AF_INET6)) {
|
|
|
|
for(unsigned long k=0,ptr=(unsigned long)RR->node->prng();k<(unsigned long)upstreamStableEndpoints->size();++k) {
|
|
|
|
const InetAddress &addr = (*upstreamStableEndpoints)[ptr++ % upstreamStableEndpoints->size()];
|
|
|
|
if (addr.ss_family == AF_INET6) {
|
|
|
|
p->sendHELLO(InetAddress(),addr,_now);
|
2017-01-27 23:27:26 +00:00
|
|
|
contacted = true;
|
2017-01-27 21:27:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-10-19 21:04:36 +00:00
|
|
|
}
|
2017-01-27 23:27:26 +00:00
|
|
|
} else contacted = true;
|
|
|
|
|
2017-01-28 00:16:06 +00:00
|
|
|
if ((!contacted)&&(_bestCurrentUpstream)) {
|
|
|
|
const SharedPtr<Path> up(_bestCurrentUpstream->getBestPath(_now,true));
|
|
|
|
if (up)
|
|
|
|
p->sendHELLO(up->localAddress(),up->address(),_now);
|
|
|
|
}
|
2017-01-27 23:27:26 +00:00
|
|
|
|
2015-10-13 19:10:44 +00:00
|
|
|
lastReceiveFromUpstream = std::max(p->lastReceive(),lastReceiveFromUpstream);
|
2017-02-13 17:03:48 +00:00
|
|
|
_upstreamsToContact.erase(p->address()); // erase from upstreams to contact so that we can WHOIS those that remain
|
2016-09-21 04:21:34 +00:00
|
|
|
} else if (p->isActive(_now)) {
|
2016-09-03 22:39:05 +00:00
|
|
|
p->doPingAndKeepalive(_now,-1);
|
2015-10-16 17:10:12 +00:00
|
|
|
}
|
2015-04-08 02:31:11 +00:00
|
|
|
}
|
2015-06-01 23:53:58 +00:00
|
|
|
|
2015-04-08 02:31:11 +00:00
|
|
|
private:
|
|
|
|
const RuntimeEnvironment *RR;
|
2017-02-13 17:03:48 +00:00
|
|
|
Hashtable< Address,std::vector<InetAddress> > &_upstreamsToContact;
|
2017-01-28 00:16:06 +00:00
|
|
|
const uint64_t _now;
|
|
|
|
const SharedPtr<Peer> _bestCurrentUpstream;
|
2015-04-08 02:31:11 +00:00
|
|
|
};
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *nextBackgroundTaskDeadline)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
_now = now;
|
2015-04-08 02:31:11 +00:00
|
|
|
Mutex::Lock bl(_backgroundTasksLock);
|
|
|
|
|
2015-09-23 21:01:41 +00:00
|
|
|
unsigned long timeUntilNextPingCheck = ZT_PING_CHECK_INVERVAL;
|
|
|
|
const uint64_t timeSinceLastPingCheck = now - _lastPingCheck;
|
|
|
|
if (timeSinceLastPingCheck >= ZT_PING_CHECK_INVERVAL) {
|
2015-04-08 02:31:11 +00:00
|
|
|
try {
|
2015-06-02 02:05:27 +00:00
|
|
|
_lastPingCheck = now;
|
|
|
|
|
2017-01-27 23:35:21 +00:00
|
|
|
// Get networks that need config without leaving mutex locked
|
2015-06-02 02:05:27 +00:00
|
|
|
std::vector< SharedPtr<Network> > needConfig;
|
|
|
|
{
|
|
|
|
Mutex::Lock _l(_networks_m);
|
2015-06-26 18:38:31 +00:00
|
|
|
for(std::vector< std::pair< uint64_t,SharedPtr<Network> > >::const_iterator n(_networks.begin());n!=_networks.end();++n) {
|
2016-09-07 22:15:52 +00:00
|
|
|
if (((now - n->second->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)||(!n->second->hasConfig()))
|
2015-06-26 18:38:31 +00:00
|
|
|
needConfig.push_back(n->second);
|
2016-09-09 18:36:10 +00:00
|
|
|
n->second->sendUpdatesToMembers();
|
2015-06-02 02:05:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for(std::vector< SharedPtr<Network> >::const_iterator n(needConfig.begin());n!=needConfig.end();++n)
|
|
|
|
(*n)->requestConfiguration();
|
2015-06-02 02:12:20 +00:00
|
|
|
|
2015-11-02 23:15:20 +00:00
|
|
|
// Do pings and keepalives
|
2017-02-13 17:03:48 +00:00
|
|
|
Hashtable< Address,std::vector<InetAddress> > upstreamsToContact;
|
|
|
|
RR->topology->getUpstreamsToContact(upstreamsToContact);
|
|
|
|
_PingPeersThatNeedPing pfunc(RR,upstreamsToContact,now);
|
2015-04-08 02:31:11 +00:00
|
|
|
RR->topology->eachPeer<_PingPeersThatNeedPing &>(pfunc);
|
|
|
|
|
2017-02-13 17:03:48 +00:00
|
|
|
// Run WHOIS to create Peer for any upstreams we could not contact (including pending moon seeds)
|
|
|
|
Hashtable< Address,std::vector<InetAddress> >::Iterator i(upstreamsToContact);
|
|
|
|
Address *upstreamAddress = (Address *)0;
|
|
|
|
std::vector<InetAddress> *upstreamStableEndpoints = (std::vector<InetAddress> *)0;
|
|
|
|
while (i.next(upstreamAddress,upstreamStableEndpoints))
|
|
|
|
RR->sw->requestWhois(*upstreamAddress);
|
|
|
|
|
2015-06-02 02:05:27 +00:00
|
|
|
// Update online status, post status change as event
|
2015-10-27 19:21:57 +00:00
|
|
|
const bool oldOnline = _online;
|
|
|
|
_online = (((now - pfunc.lastReceiveFromUpstream) < ZT_PEER_ACTIVITY_TIMEOUT)||(RR->topology->amRoot()));
|
2015-04-09 00:10:21 +00:00
|
|
|
if (oldOnline != _online)
|
2015-09-24 23:21:36 +00:00
|
|
|
postEvent(_online ? ZT_EVENT_ONLINE : ZT_EVENT_OFFLINE);
|
2015-04-08 02:31:11 +00:00
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-08 02:31:11 +00:00
|
|
|
}
|
2015-09-23 21:01:41 +00:00
|
|
|
} else {
|
|
|
|
timeUntilNextPingCheck -= (unsigned long)timeSinceLastPingCheck;
|
2015-04-08 02:31:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((now - _lastHousekeepingRun) >= ZT_HOUSEKEEPING_PERIOD) {
|
|
|
|
try {
|
2015-06-02 02:05:27 +00:00
|
|
|
_lastHousekeepingRun = now;
|
2015-04-08 02:31:11 +00:00
|
|
|
RR->topology->clean(now);
|
2015-05-05 01:34:30 +00:00
|
|
|
RR->sa->clean(now);
|
2015-04-08 02:31:11 +00:00
|
|
|
RR->mc->clean(now);
|
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-08 02:31:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2015-10-20 22:27:53 +00:00
|
|
|
#ifdef ZT_ENABLE_CLUSTER
|
|
|
|
// If clustering is enabled we have to call cluster->doPeriodicTasks() very often, so we override normal timer deadline behavior
|
|
|
|
if (RR->cluster) {
|
|
|
|
RR->sw->doTimerTasks(now);
|
|
|
|
RR->cluster->doPeriodicTasks();
|
|
|
|
*nextBackgroundTaskDeadline = now + ZT_CLUSTER_PERIODIC_TASK_PERIOD; // this is really short so just tick at this rate
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
*nextBackgroundTaskDeadline = now + (uint64_t)std::max(std::min(timeUntilNextPingCheck,RR->sw->doTimerTasks(now)),(unsigned long)ZT_CORE_TIMER_TASK_GRANULARITY);
|
|
|
|
#ifdef ZT_ENABLE_CLUSTER
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-08 02:31:11 +00:00
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-08 02:31:11 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_OK;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 19:04:35 +00:00
|
|
|
ZT_ResultCode Node::join(uint64_t nwid,void *uptr)
|
2015-04-01 01:17:11 +00:00
|
|
|
{
|
2015-04-01 23:27:14 +00:00
|
|
|
Mutex::Lock _l(_networks_m);
|
2015-06-20 14:32:48 +00:00
|
|
|
SharedPtr<Network> nw = _network(nwid);
|
2015-06-26 18:38:31 +00:00
|
|
|
if(!nw)
|
2016-01-12 19:04:35 +00:00
|
|
|
_networks.push_back(std::pair< uint64_t,SharedPtr<Network> >(nwid,SharedPtr<Network>(new Network(RR,nwid,uptr))));
|
2015-06-26 18:38:31 +00:00
|
|
|
std::sort(_networks.begin(),_networks.end()); // will sort by nwid since it's the first in a pair<>
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_OK;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 19:04:35 +00:00
|
|
|
ZT_ResultCode Node::leave(uint64_t nwid,void **uptr)
|
2015-04-01 01:17:11 +00:00
|
|
|
{
|
2015-06-26 18:38:31 +00:00
|
|
|
std::vector< std::pair< uint64_t,SharedPtr<Network> > > newn;
|
2015-04-01 23:27:14 +00:00
|
|
|
Mutex::Lock _l(_networks_m);
|
2015-06-26 18:38:31 +00:00
|
|
|
for(std::vector< std::pair< uint64_t,SharedPtr<Network> > >::const_iterator n(_networks.begin());n!=_networks.end();++n) {
|
|
|
|
if (n->first != nwid)
|
|
|
|
newn.push_back(*n);
|
2016-01-12 19:04:35 +00:00
|
|
|
else {
|
|
|
|
if (uptr)
|
|
|
|
*uptr = n->second->userPtr();
|
|
|
|
n->second->destroy();
|
|
|
|
}
|
2015-04-02 02:09:18 +00:00
|
|
|
}
|
2015-06-26 18:38:31 +00:00
|
|
|
_networks.swap(newn);
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_OK;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_ResultCode Node::multicastSubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
2015-04-01 21:59:44 +00:00
|
|
|
{
|
2015-04-15 20:09:20 +00:00
|
|
|
SharedPtr<Network> nw(this->network(nwid));
|
|
|
|
if (nw) {
|
|
|
|
nw->multicastSubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_OK;
|
|
|
|
} else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
|
2015-04-01 21:59:44 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_ResultCode Node::multicastUnsubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
2015-04-01 01:17:11 +00:00
|
|
|
{
|
2015-04-15 20:09:20 +00:00
|
|
|
SharedPtr<Network> nw(this->network(nwid));
|
|
|
|
if (nw) {
|
|
|
|
nw->multicastUnsubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_OK;
|
|
|
|
} else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 17:03:48 +00:00
|
|
|
ZT_ResultCode Node::orbit(uint64_t moonWorldId,uint64_t moonSeed)
|
2017-01-27 23:27:26 +00:00
|
|
|
{
|
2017-02-13 17:03:48 +00:00
|
|
|
RR->topology->addMoon(moonWorldId,Address(moonSeed));
|
2017-01-27 23:27:26 +00:00
|
|
|
return ZT_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZT_ResultCode Node::deorbit(uint64_t moonWorldId)
|
|
|
|
{
|
|
|
|
RR->topology->removeMoon(moonWorldId);
|
|
|
|
return ZT_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-14 01:12:45 +00:00
|
|
|
uint64_t Node::address() const
|
|
|
|
{
|
|
|
|
return RR->identity.address().toInt();
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
void Node::status(ZT_NodeStatus *status) const
|
2015-04-01 01:17:11 +00:00
|
|
|
{
|
2015-04-09 01:25:40 +00:00
|
|
|
status->address = RR->identity.address().toInt();
|
|
|
|
status->publicIdentity = RR->publicIdentityStr.c_str();
|
|
|
|
status->secretIdentity = RR->secretIdentityStr.c_str();
|
|
|
|
status->online = _online ? 1 : 0;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_PeerList *Node::peers() const
|
2015-04-01 01:17:11 +00:00
|
|
|
{
|
2015-09-04 19:14:21 +00:00
|
|
|
std::vector< std::pair< Address,SharedPtr<Peer> > > peers(RR->topology->allPeers());
|
|
|
|
std::sort(peers.begin(),peers.end());
|
2015-04-09 01:45:21 +00:00
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
char *buf = (char *)::malloc(sizeof(ZT_PeerList) + (sizeof(ZT_Peer) * peers.size()));
|
2015-04-09 01:45:21 +00:00
|
|
|
if (!buf)
|
2015-09-24 23:21:36 +00:00
|
|
|
return (ZT_PeerList *)0;
|
|
|
|
ZT_PeerList *pl = (ZT_PeerList *)buf;
|
|
|
|
pl->peers = (ZT_Peer *)(buf + sizeof(ZT_PeerList));
|
2015-04-09 01:45:21 +00:00
|
|
|
|
|
|
|
pl->peerCount = 0;
|
2015-09-04 19:14:21 +00:00
|
|
|
for(std::vector< std::pair< Address,SharedPtr<Peer> > >::iterator pi(peers.begin());pi!=peers.end();++pi) {
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_Peer *p = &(pl->peers[pl->peerCount++]);
|
2015-04-09 01:45:21 +00:00
|
|
|
p->address = pi->second->address().toInt();
|
|
|
|
if (pi->second->remoteVersionKnown()) {
|
|
|
|
p->versionMajor = pi->second->remoteVersionMajor();
|
|
|
|
p->versionMinor = pi->second->remoteVersionMinor();
|
|
|
|
p->versionRev = pi->second->remoteVersionRevision();
|
|
|
|
} else {
|
|
|
|
p->versionMajor = -1;
|
|
|
|
p->versionMinor = -1;
|
|
|
|
p->versionRev = -1;
|
|
|
|
}
|
|
|
|
p->latency = pi->second->latency();
|
2017-01-27 21:27:52 +00:00
|
|
|
p->role = RR->topology->role(pi->second->identity().address());
|
2015-04-09 01:45:21 +00:00
|
|
|
|
2016-09-07 18:13:17 +00:00
|
|
|
std::vector< std::pair< SharedPtr<Path>,bool > > paths(pi->second->paths(_now));
|
|
|
|
SharedPtr<Path> bestp(pi->second->getBestPath(_now,false));
|
2015-04-09 01:45:21 +00:00
|
|
|
p->pathCount = 0;
|
2016-09-07 18:13:17 +00:00
|
|
|
for(std::vector< std::pair< SharedPtr<Path>,bool > >::iterator path(paths.begin());path!=paths.end();++path) {
|
|
|
|
memcpy(&(p->paths[p->pathCount].address),&(path->first->address()),sizeof(struct sockaddr_storage));
|
|
|
|
p->paths[p->pathCount].lastSend = path->first->lastOut();
|
|
|
|
p->paths[p->pathCount].lastReceive = path->first->lastIn();
|
|
|
|
p->paths[p->pathCount].expired = path->second;
|
|
|
|
p->paths[p->pathCount].preferred = (path->first == bestp) ? 1 : 0;
|
|
|
|
p->paths[p->pathCount].trustedPathId = RR->topology->getOutboundPathTrust(path->first->address());
|
2015-04-09 01:45:21 +00:00
|
|
|
++p->pathCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pl;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid) const
|
2015-04-01 01:17:11 +00:00
|
|
|
{
|
2015-04-07 01:27:24 +00:00
|
|
|
Mutex::Lock _l(_networks_m);
|
2015-06-20 14:32:48 +00:00
|
|
|
SharedPtr<Network> nw = _network(nwid);
|
|
|
|
if(nw) {
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_VirtualNetworkConfig *nc = (ZT_VirtualNetworkConfig *)::malloc(sizeof(ZT_VirtualNetworkConfig));
|
2015-06-20 14:32:48 +00:00
|
|
|
nw->externalConfig(nc);
|
2015-04-07 01:27:24 +00:00
|
|
|
return nc;
|
|
|
|
}
|
2015-09-24 23:21:36 +00:00
|
|
|
return (ZT_VirtualNetworkConfig *)0;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_VirtualNetworkList *Node::networks() const
|
2015-04-01 01:17:11 +00:00
|
|
|
{
|
2015-04-09 01:25:40 +00:00
|
|
|
Mutex::Lock _l(_networks_m);
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
char *buf = (char *)::malloc(sizeof(ZT_VirtualNetworkList) + (sizeof(ZT_VirtualNetworkConfig) * _networks.size()));
|
2015-04-09 01:25:40 +00:00
|
|
|
if (!buf)
|
2015-09-24 23:21:36 +00:00
|
|
|
return (ZT_VirtualNetworkList *)0;
|
|
|
|
ZT_VirtualNetworkList *nl = (ZT_VirtualNetworkList *)buf;
|
|
|
|
nl->networks = (ZT_VirtualNetworkConfig *)(buf + sizeof(ZT_VirtualNetworkList));
|
2015-04-09 01:25:40 +00:00
|
|
|
|
|
|
|
nl->networkCount = 0;
|
2015-06-26 18:38:31 +00:00
|
|
|
for(std::vector< std::pair< uint64_t,SharedPtr<Network> > >::const_iterator n(_networks.begin());n!=_networks.end();++n)
|
|
|
|
n->second->externalConfig(&(nl->networks[nl->networkCount++]));
|
2015-04-09 01:25:40 +00:00
|
|
|
|
|
|
|
return nl;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Node::freeQueryResult(void *qr)
|
|
|
|
{
|
|
|
|
if (qr)
|
|
|
|
::free(qr);
|
|
|
|
}
|
|
|
|
|
2015-10-29 16:42:15 +00:00
|
|
|
int Node::addLocalInterfaceAddress(const struct sockaddr_storage *addr)
|
2015-07-07 15:54:48 +00:00
|
|
|
{
|
|
|
|
if (Path::isAddressValidForPath(*(reinterpret_cast<const InetAddress *>(addr)))) {
|
|
|
|
Mutex::Lock _l(_directPaths_m);
|
2016-04-06 18:50:00 +00:00
|
|
|
if (std::find(_directPaths.begin(),_directPaths.end(),*(reinterpret_cast<const InetAddress *>(addr))) == _directPaths.end()) {
|
|
|
|
_directPaths.push_back(*(reinterpret_cast<const InetAddress *>(addr)));
|
|
|
|
return 1;
|
|
|
|
}
|
2015-07-07 15:54:48 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2015-07-06 22:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Node::clearLocalInterfaceAddresses()
|
|
|
|
{
|
|
|
|
Mutex::Lock _l(_directPaths_m);
|
|
|
|
_directPaths.clear();
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:55:07 +00:00
|
|
|
int Node::sendUserMessage(uint64_t dest,uint64_t typeId,const void *data,unsigned int len)
|
|
|
|
{
|
|
|
|
try {
|
2017-01-12 01:46:52 +00:00
|
|
|
if (RR->identity.address().toInt() != dest) {
|
|
|
|
Packet outp(Address(dest),RR->identity.address(),Packet::VERB_USER_MESSAGE);
|
|
|
|
outp.append(typeId);
|
|
|
|
outp.append(data,len);
|
|
|
|
outp.compress();
|
|
|
|
RR->sw->send(outp,true);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} catch ( ... ) {}
|
|
|
|
return 0;
|
2017-01-09 23:55:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 22:12:09 +00:00
|
|
|
void Node::setNetconfMaster(void *networkControllerInstance)
|
2015-04-01 01:17:11 +00:00
|
|
|
{
|
2015-04-15 22:12:09 +00:00
|
|
|
RR->localNetworkController = reinterpret_cast<NetworkController *>(networkControllerInstance);
|
2016-11-10 19:54:47 +00:00
|
|
|
RR->localNetworkController->init(RR->identity,this);
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 21:42:51 +00:00
|
|
|
ZT_ResultCode Node::circuitTestBegin(ZT_CircuitTest *test,void (*reportCallback)(ZT_Node *,ZT_CircuitTest *,const ZT_CircuitTestReport *))
|
|
|
|
{
|
2015-10-06 22:16:41 +00:00
|
|
|
if (test->hopCount > 0) {
|
|
|
|
try {
|
|
|
|
Packet outp(Address(),RR->identity.address(),Packet::VERB_CIRCUIT_TEST);
|
|
|
|
RR->identity.address().appendTo(outp);
|
|
|
|
outp.append((uint16_t)((test->reportAtEveryHop != 0) ? 0x03 : 0x02));
|
|
|
|
outp.append((uint64_t)test->timestamp);
|
|
|
|
outp.append((uint64_t)test->testId);
|
|
|
|
outp.append((uint16_t)0); // originator credential length, updated later
|
|
|
|
if (test->credentialNetworkId) {
|
|
|
|
outp.append((uint8_t)0x01);
|
|
|
|
outp.append((uint64_t)test->credentialNetworkId);
|
|
|
|
outp.setAt<uint16_t>(ZT_PACKET_IDX_PAYLOAD + 23,(uint16_t)9);
|
|
|
|
}
|
|
|
|
outp.append((uint16_t)0);
|
|
|
|
C25519::Signature sig(RR->identity.sign(reinterpret_cast<const char *>(outp.data()) + ZT_PACKET_IDX_PAYLOAD,outp.size() - ZT_PACKET_IDX_PAYLOAD));
|
|
|
|
outp.append((uint16_t)sig.size());
|
2015-11-13 00:51:33 +00:00
|
|
|
outp.append(sig.data,(unsigned int)sig.size());
|
2015-10-06 22:16:41 +00:00
|
|
|
outp.append((uint16_t)0); // originator doesn't need an extra credential, since it's the originator
|
|
|
|
for(unsigned int h=1;h<test->hopCount;++h) {
|
|
|
|
outp.append((uint8_t)0);
|
|
|
|
outp.append((uint8_t)(test->hops[h].breadth & 0xff));
|
|
|
|
for(unsigned int a=0;a<test->hops[h].breadth;++a)
|
|
|
|
Address(test->hops[h].addresses[a]).appendTo(outp);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int a=0;a<test->hops[0].breadth;++a) {
|
|
|
|
outp.newInitializationVector();
|
|
|
|
outp.setDestination(Address(test->hops[0].addresses[a]));
|
2016-08-09 22:45:26 +00:00
|
|
|
RR->sw->send(outp,true);
|
2015-10-06 22:16:41 +00:00
|
|
|
}
|
|
|
|
} catch ( ... ) {
|
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL; // probably indicates FIFO too big for packet
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 21:42:51 +00:00
|
|
|
{
|
|
|
|
test->_internalPtr = reinterpret_cast<void *>(reportCallback);
|
|
|
|
Mutex::Lock _l(_circuitTests_m);
|
|
|
|
if (std::find(_circuitTests.begin(),_circuitTests.end(),test) == _circuitTests.end())
|
|
|
|
_circuitTests.push_back(test);
|
|
|
|
}
|
2015-10-06 22:16:41 +00:00
|
|
|
|
2015-10-06 21:42:51 +00:00
|
|
|
return ZT_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::circuitTestEnd(ZT_CircuitTest *test)
|
|
|
|
{
|
|
|
|
Mutex::Lock _l(_circuitTests_m);
|
|
|
|
for(;;) {
|
|
|
|
std::vector< ZT_CircuitTest * >::iterator ct(std::find(_circuitTests.begin(),_circuitTests.end(),test));
|
|
|
|
if (ct == _circuitTests.end())
|
|
|
|
break;
|
|
|
|
else _circuitTests.erase(ct);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 22:27:53 +00:00
|
|
|
ZT_ResultCode Node::clusterInit(
|
|
|
|
unsigned int myId,
|
|
|
|
const struct sockaddr_storage *zeroTierPhysicalEndpoints,
|
|
|
|
unsigned int numZeroTierPhysicalEndpoints,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int z,
|
|
|
|
void (*sendFunction)(void *,unsigned int,const void *,unsigned int),
|
|
|
|
void *sendFunctionArg,
|
|
|
|
int (*addressToLocationFunction)(void *,const struct sockaddr_storage *,int *,int *,int *),
|
|
|
|
void *addressToLocationFunctionArg)
|
|
|
|
{
|
|
|
|
#ifdef ZT_ENABLE_CLUSTER
|
|
|
|
if (RR->cluster)
|
|
|
|
return ZT_RESULT_ERROR_BAD_PARAMETER;
|
|
|
|
|
|
|
|
std::vector<InetAddress> eps;
|
|
|
|
for(unsigned int i=0;i<numZeroTierPhysicalEndpoints;++i)
|
|
|
|
eps.push_back(InetAddress(zeroTierPhysicalEndpoints[i]));
|
|
|
|
std::sort(eps.begin(),eps.end());
|
|
|
|
RR->cluster = new Cluster(RR,myId,eps,x,y,z,sendFunction,sendFunctionArg,addressToLocationFunction,addressToLocationFunctionArg);
|
|
|
|
|
|
|
|
return ZT_RESULT_OK;
|
|
|
|
#else
|
|
|
|
return ZT_RESULT_ERROR_UNSUPPORTED_OPERATION;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
ZT_ResultCode Node::clusterAddMember(unsigned int memberId)
|
|
|
|
{
|
|
|
|
#ifdef ZT_ENABLE_CLUSTER
|
|
|
|
if (!RR->cluster)
|
|
|
|
return ZT_RESULT_ERROR_BAD_PARAMETER;
|
|
|
|
RR->cluster->addMember((uint16_t)memberId);
|
|
|
|
return ZT_RESULT_OK;
|
|
|
|
#else
|
|
|
|
return ZT_RESULT_ERROR_UNSUPPORTED_OPERATION;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::clusterRemoveMember(unsigned int memberId)
|
|
|
|
{
|
|
|
|
#ifdef ZT_ENABLE_CLUSTER
|
|
|
|
if (RR->cluster)
|
|
|
|
RR->cluster->removeMember((uint16_t)memberId);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::clusterHandleIncomingMessage(const void *msg,unsigned int len)
|
|
|
|
{
|
|
|
|
#ifdef ZT_ENABLE_CLUSTER
|
|
|
|
if (RR->cluster)
|
|
|
|
RR->cluster->handleIncomingStateMessage(msg,len);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-10-26 19:49:17 +00:00
|
|
|
void Node::clusterStatus(ZT_ClusterStatus *cs)
|
|
|
|
{
|
|
|
|
if (!cs)
|
|
|
|
return;
|
|
|
|
#ifdef ZT_ENABLE_CLUSTER
|
|
|
|
if (RR->cluster)
|
|
|
|
RR->cluster->status(*cs);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
memset(cs,0,sizeof(ZT_ClusterStatus));
|
|
|
|
}
|
|
|
|
|
2015-04-06 21:50:53 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Node methods used only within node/ */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
std::string Node::dataStoreGet(const char *name)
|
|
|
|
{
|
2015-11-13 20:14:28 +00:00
|
|
|
char buf[1024];
|
2015-04-07 21:11:47 +00:00
|
|
|
std::string r;
|
|
|
|
unsigned long olen = 0;
|
|
|
|
do {
|
2016-11-22 18:54:58 +00:00
|
|
|
long n = _cb.dataStoreGetFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,name,buf,sizeof(buf),(unsigned long)r.length(),&olen);
|
2015-04-07 21:11:47 +00:00
|
|
|
if (n <= 0)
|
|
|
|
return std::string();
|
|
|
|
r.append(buf,n);
|
|
|
|
} while (r.length() < olen);
|
|
|
|
return r;
|
2015-04-06 21:50:53 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 18:54:58 +00:00
|
|
|
bool Node::shouldUsePathForZeroTierTraffic(const Address &ztaddr,const InetAddress &localAddress,const InetAddress &remoteAddress)
|
2016-01-11 18:17:44 +00:00
|
|
|
{
|
2016-02-23 00:01:35 +00:00
|
|
|
if (!Path::isAddressValidForPath(remoteAddress))
|
|
|
|
return false;
|
|
|
|
|
2016-12-06 00:09:42 +00:00
|
|
|
if (RR->topology->isProhibitedEndpoint(ztaddr,remoteAddress))
|
|
|
|
return false;
|
|
|
|
|
2016-01-11 18:17:44 +00:00
|
|
|
{
|
|
|
|
Mutex::Lock _l(_networks_m);
|
|
|
|
for(std::vector< std::pair< uint64_t, SharedPtr<Network> > >::const_iterator i=_networks.begin();i!=_networks.end();++i) {
|
2016-04-12 19:26:10 +00:00
|
|
|
if (i->second->hasConfig()) {
|
2016-05-06 23:13:11 +00:00
|
|
|
for(unsigned int k=0;k<i->second->config().staticIpCount;++k) {
|
|
|
|
if (i->second->config().staticIps[k].containsAddress(remoteAddress))
|
2016-01-11 18:17:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 18:54:58 +00:00
|
|
|
return ( (_cb.pathCheckFunction) ? (_cb.pathCheckFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,ztaddr.toInt(),reinterpret_cast<const struct sockaddr_storage *>(&localAddress),reinterpret_cast<const struct sockaddr_storage *>(&remoteAddress)) != 0) : true);
|
2016-01-11 18:17:44 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 23:49:21 +00:00
|
|
|
#ifdef ZT_TRACE
|
|
|
|
void Node::postTrace(const char *module,unsigned int line,const char *fmt,...)
|
|
|
|
{
|
|
|
|
static Mutex traceLock;
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
char tmp1[1024],tmp2[1024],tmp3[256];
|
|
|
|
|
|
|
|
Mutex::Lock _l(traceLock);
|
|
|
|
|
2015-04-24 22:05:28 +00:00
|
|
|
time_t now = (time_t)(_now / 1000ULL);
|
2015-04-08 23:49:21 +00:00
|
|
|
#ifdef __WINDOWS__
|
|
|
|
ctime_s(tmp3,sizeof(tmp3),&now);
|
2015-04-10 03:54:00 +00:00
|
|
|
char *nowstr = tmp3;
|
2015-04-08 23:49:21 +00:00
|
|
|
#else
|
2015-04-10 03:54:00 +00:00
|
|
|
char *nowstr = ctime_r(&now,tmp3);
|
2015-04-08 23:49:21 +00:00
|
|
|
#endif
|
2015-04-24 22:05:28 +00:00
|
|
|
unsigned long nowstrlen = (unsigned long)strlen(nowstr);
|
2015-04-10 03:54:00 +00:00
|
|
|
if (nowstr[nowstrlen-1] == '\n')
|
|
|
|
nowstr[--nowstrlen] = (char)0;
|
|
|
|
if (nowstr[nowstrlen-1] == '\r')
|
|
|
|
nowstr[--nowstrlen] = (char)0;
|
2015-04-08 23:49:21 +00:00
|
|
|
|
|
|
|
va_start(ap,fmt);
|
|
|
|
vsnprintf(tmp2,sizeof(tmp2),fmt,ap);
|
|
|
|
va_end(ap);
|
|
|
|
tmp2[sizeof(tmp2)-1] = (char)0;
|
|
|
|
|
|
|
|
Utils::snprintf(tmp1,sizeof(tmp1),"[%s] %s:%u %s",nowstr,module,line,tmp2);
|
2015-09-24 23:21:36 +00:00
|
|
|
postEvent(ZT_EVENT_TRACE,tmp1);
|
2015-04-08 23:49:21 +00:00
|
|
|
}
|
|
|
|
#endif // ZT_TRACE
|
|
|
|
|
2015-07-07 17:49:50 +00:00
|
|
|
uint64_t Node::prng()
|
|
|
|
{
|
2016-11-22 22:23:13 +00:00
|
|
|
unsigned int p = (++_prngStreamPtr % ZT_NODE_PRNG_BUF_SIZE);
|
2015-07-07 17:49:50 +00:00
|
|
|
if (!p)
|
2017-02-06 00:19:03 +00:00
|
|
|
_prng.crypt12(_prngStream,_prngStream,sizeof(_prngStream));
|
2015-07-07 17:49:50 +00:00
|
|
|
return _prngStream[p];
|
|
|
|
}
|
|
|
|
|
2015-10-06 21:42:51 +00:00
|
|
|
void Node::postCircuitTestReport(const ZT_CircuitTestReport *report)
|
|
|
|
{
|
|
|
|
std::vector< ZT_CircuitTest * > toNotify;
|
|
|
|
{
|
|
|
|
Mutex::Lock _l(_circuitTests_m);
|
|
|
|
for(std::vector< ZT_CircuitTest * >::iterator i(_circuitTests.begin());i!=_circuitTests.end();++i) {
|
|
|
|
if ((*i)->testId == report->testId)
|
|
|
|
toNotify.push_back(*i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(std::vector< ZT_CircuitTest * >::iterator i(toNotify.begin());i!=toNotify.end();++i)
|
|
|
|
(reinterpret_cast<void (*)(ZT_Node *,ZT_CircuitTest *,const ZT_CircuitTestReport *)>((*i)->_internalPtr))(reinterpret_cast<ZT_Node *>(this),*i,report);
|
|
|
|
}
|
|
|
|
|
2016-07-12 15:29:50 +00:00
|
|
|
void Node::setTrustedPaths(const struct sockaddr_storage *networks,const uint64_t *ids,unsigned int count)
|
|
|
|
{
|
|
|
|
RR->topology->setTrustedPaths(reinterpret_cast<const InetAddress *>(networks),ids,count);
|
|
|
|
}
|
|
|
|
|
2017-02-13 22:27:08 +00:00
|
|
|
World Node::planet() const
|
|
|
|
{
|
|
|
|
return RR->topology->planet();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<World> Node::moons() const
|
|
|
|
{
|
|
|
|
return RR->topology->moons();
|
|
|
|
}
|
|
|
|
|
2016-11-10 19:54:47 +00:00
|
|
|
void Node::ncSendConfig(uint64_t nwid,uint64_t requestPacketId,const Address &destination,const NetworkConfig &nc,bool sendLegacyFormatConfig)
|
|
|
|
{
|
|
|
|
if (destination == RR->identity.address()) {
|
|
|
|
SharedPtr<Network> n(network(nwid));
|
|
|
|
if (!n) return;
|
|
|
|
n->setConfiguration(nc,true);
|
|
|
|
} else {
|
|
|
|
Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY> *dconf = new Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY>();
|
|
|
|
try {
|
|
|
|
if (nc.toDictionary(*dconf,sendLegacyFormatConfig)) {
|
|
|
|
uint64_t configUpdateId = prng();
|
|
|
|
if (!configUpdateId) ++configUpdateId;
|
|
|
|
|
|
|
|
const unsigned int totalSize = dconf->sizeBytes();
|
|
|
|
unsigned int chunkIndex = 0;
|
|
|
|
while (chunkIndex < totalSize) {
|
|
|
|
const unsigned int chunkLen = std::min(totalSize - chunkIndex,(unsigned int)(ZT_UDP_DEFAULT_PAYLOAD_MTU - (ZT_PACKET_IDX_PAYLOAD + 256)));
|
2016-11-10 19:57:45 +00:00
|
|
|
Packet outp(destination,RR->identity.address(),(requestPacketId) ? Packet::VERB_OK : Packet::VERB_NETWORK_CONFIG);
|
|
|
|
if (requestPacketId) {
|
|
|
|
outp.append((unsigned char)Packet::VERB_NETWORK_CONFIG_REQUEST);
|
|
|
|
outp.append(requestPacketId);
|
|
|
|
}
|
2016-11-10 19:54:47 +00:00
|
|
|
|
|
|
|
const unsigned int sigStart = outp.size();
|
|
|
|
outp.append(nwid);
|
|
|
|
outp.append((uint16_t)chunkLen);
|
|
|
|
outp.append((const void *)(dconf->data() + chunkIndex),chunkLen);
|
|
|
|
|
|
|
|
outp.append((uint8_t)0); // no flags
|
|
|
|
outp.append((uint64_t)configUpdateId);
|
|
|
|
outp.append((uint32_t)totalSize);
|
|
|
|
outp.append((uint32_t)chunkIndex);
|
|
|
|
|
|
|
|
C25519::Signature sig(RR->identity.sign(reinterpret_cast<const uint8_t *>(outp.data()) + sigStart,outp.size() - sigStart));
|
|
|
|
outp.append((uint8_t)1);
|
|
|
|
outp.append((uint16_t)ZT_C25519_SIGNATURE_LEN);
|
|
|
|
outp.append(sig.data,ZT_C25519_SIGNATURE_LEN);
|
|
|
|
|
|
|
|
outp.compress();
|
|
|
|
RR->sw->send(outp,true);
|
|
|
|
chunkIndex += chunkLen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete dconf;
|
|
|
|
} catch ( ... ) {
|
|
|
|
delete dconf;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::ncSendError(uint64_t nwid,uint64_t requestPacketId,const Address &destination,NetworkController::ErrorCode errorCode)
|
|
|
|
{
|
|
|
|
if (destination == RR->identity.address()) {
|
|
|
|
SharedPtr<Network> n(network(nwid));
|
|
|
|
if (!n) return;
|
|
|
|
switch(errorCode) {
|
|
|
|
case NetworkController::NC_ERROR_OBJECT_NOT_FOUND:
|
|
|
|
case NetworkController::NC_ERROR_INTERNAL_SERVER_ERROR:
|
|
|
|
n->setNotFound();
|
|
|
|
break;
|
|
|
|
case NetworkController::NC_ERROR_ACCESS_DENIED:
|
|
|
|
n->setAccessDenied();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
} else if (requestPacketId) {
|
|
|
|
Packet outp(destination,RR->identity.address(),Packet::VERB_ERROR);
|
|
|
|
outp.append((unsigned char)Packet::VERB_NETWORK_CONFIG_REQUEST);
|
|
|
|
outp.append(requestPacketId);
|
|
|
|
switch(errorCode) {
|
|
|
|
//case NetworkController::NC_ERROR_OBJECT_NOT_FOUND:
|
|
|
|
//case NetworkController::NC_ERROR_INTERNAL_SERVER_ERROR:
|
|
|
|
default:
|
|
|
|
outp.append((unsigned char)Packet::ERROR_OBJ_NOT_FOUND);
|
|
|
|
break;
|
|
|
|
case NetworkController::NC_ERROR_ACCESS_DENIED:
|
|
|
|
outp.append((unsigned char)Packet::ERROR_NETWORK_ACCESS_DENIED_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
outp.append(nwid);
|
|
|
|
RR->sw->send(outp,true);
|
2016-11-10 19:57:45 +00:00
|
|
|
} // else we can't send an ERROR() in response to nothing, so discard
|
2016-11-10 19:54:47 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 01:17:11 +00:00
|
|
|
} // namespace ZeroTier
|
2015-04-01 23:27:14 +00:00
|
|
|
|
2015-04-06 21:50:53 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* CAPI bindings */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
2015-04-01 23:27:14 +00:00
|
|
|
extern "C" {
|
|
|
|
|
2016-11-22 18:54:58 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_new(ZT_Node **node,void *uptr,const struct ZT_Node_Callbacks *callbacks,uint64_t now)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
2015-09-24 23:21:36 +00:00
|
|
|
*node = (ZT_Node *)0;
|
2015-04-01 23:27:14 +00:00
|
|
|
try {
|
2016-11-22 18:54:58 +00:00
|
|
|
*node = reinterpret_cast<ZT_Node *>(new ZeroTier::Node(uptr,callbacks,now));
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_OK;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch (std::runtime_error &exc) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_DATA_STORE_FAILED;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
void ZT_Node_delete(ZT_Node *node)
|
2015-04-06 21:50:53 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
delete (reinterpret_cast<ZeroTier::Node *>(node));
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_processWirePacket(
|
|
|
|
ZT_Node *node,
|
2015-04-01 23:27:14 +00:00
|
|
|
uint64_t now,
|
2015-09-24 23:21:36 +00:00
|
|
|
const struct sockaddr_storage *localAddress,
|
2015-04-01 23:27:14 +00:00
|
|
|
const struct sockaddr_storage *remoteAddress,
|
|
|
|
const void *packetData,
|
|
|
|
unsigned int packetLength,
|
2015-04-15 20:09:20 +00:00
|
|
|
volatile uint64_t *nextBackgroundTaskDeadline)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
2015-09-24 23:21:36 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->processWirePacket(now,localAddress,remoteAddress,packetData,packetLength,nextBackgroundTaskDeadline);
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-10-07 16:38:33 +00:00
|
|
|
return ZT_RESULT_OK; // "OK" since invalid packets are simply dropped, but the system is still up
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_processVirtualNetworkFrame(
|
|
|
|
ZT_Node *node,
|
2015-04-01 23:27:14 +00:00
|
|
|
uint64_t now,
|
|
|
|
uint64_t nwid,
|
|
|
|
uint64_t sourceMac,
|
|
|
|
uint64_t destMac,
|
|
|
|
unsigned int etherType,
|
|
|
|
unsigned int vlanId,
|
|
|
|
const void *frameData,
|
|
|
|
unsigned int frameLength,
|
2015-04-15 20:09:20 +00:00
|
|
|
volatile uint64_t *nextBackgroundTaskDeadline)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
2015-04-08 02:31:11 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->processVirtualNetworkFrame(now,nwid,sourceMac,destMac,etherType,vlanId,frameData,frameLength,nextBackgroundTaskDeadline);
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_processBackgroundTasks(ZT_Node *node,uint64_t now,volatile uint64_t *nextBackgroundTaskDeadline)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
2015-04-08 02:31:11 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->processBackgroundTasks(now,nextBackgroundTaskDeadline);
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-12 19:04:35 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_join(ZT_Node *node,uint64_t nwid,void *uptr)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
2016-01-12 19:04:35 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->join(nwid,uptr);
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-12 19:04:35 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_leave(ZT_Node *node,uint64_t nwid,void **uptr)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
2016-01-12 19:04:35 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->leave(nwid,uptr);
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_multicastSubscribe(ZT_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->multicastSubscribe(nwid,multicastGroup,multicastAdi);
|
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_multicastUnsubscribe(ZT_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->multicastUnsubscribe(nwid,multicastGroup,multicastAdi);
|
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 17:03:48 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_orbit(ZT_Node *node,uint64_t moonWorldId,uint64_t moonSeed)
|
2017-01-27 23:27:26 +00:00
|
|
|
{
|
|
|
|
try {
|
2017-02-13 17:03:48 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->orbit(moonWorldId,moonSeed);
|
2017-01-27 23:27:26 +00:00
|
|
|
} catch ( ... ) {
|
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ZT_ResultCode ZT_Node_deorbit(ZT_Node *node,uint64_t moonWorldId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->deorbit(moonWorldId);
|
|
|
|
} catch ( ... ) {
|
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
uint64_t ZT_Node_address(ZT_Node *node)
|
2015-04-14 01:12:45 +00:00
|
|
|
{
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->address();
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
void ZT_Node_status(ZT_Node *node,ZT_NodeStatus *status)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->status(status);
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_PeerList *ZT_Node_peers(ZT_Node *node)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
2015-04-07 21:11:47 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->peers();
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return (ZT_PeerList *)0;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_VirtualNetworkConfig *ZT_Node_networkConfig(ZT_Node *node,uint64_t nwid)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->networkConfig(nwid);
|
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return (ZT_VirtualNetworkConfig *)0;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
ZT_VirtualNetworkList *ZT_Node_networks(ZT_Node *node)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
2015-04-07 21:11:47 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->networks();
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-09-24 23:21:36 +00:00
|
|
|
return (ZT_VirtualNetworkList *)0;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
void ZT_Node_freeQueryResult(ZT_Node *node,void *qr)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->freeQueryResult(qr);
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2015-10-29 16:42:15 +00:00
|
|
|
int ZT_Node_addLocalInterfaceAddress(ZT_Node *node,const struct sockaddr_storage *addr)
|
2015-10-20 22:27:53 +00:00
|
|
|
{
|
|
|
|
try {
|
2015-10-29 16:42:15 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->addLocalInterfaceAddress(addr);
|
2015-10-20 22:27:53 +00:00
|
|
|
} catch ( ... ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZT_Node_clearLocalInterfaceAddresses(ZT_Node *node)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->clearLocalInterfaceAddresses();
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:55:07 +00:00
|
|
|
int ZT_Node_sendUserMessage(ZT_Node *node,uint64_t dest,uint64_t typeId,const void *data,unsigned int len)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->sendUserMessage(dest,typeId,data,len);
|
|
|
|
} catch ( ... ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:21:36 +00:00
|
|
|
void ZT_Node_setNetconfMaster(ZT_Node *node,void *networkControllerInstance)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
try {
|
2015-04-15 22:12:09 +00:00
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->setNetconfMaster(networkControllerInstance);
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2015-10-08 01:04:40 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_circuitTestBegin(ZT_Node *node,ZT_CircuitTest *test,void (*reportCallback)(ZT_Node *,ZT_CircuitTest *,const ZT_CircuitTestReport *))
|
2015-10-06 21:42:51 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->circuitTestBegin(test,reportCallback);
|
|
|
|
} catch ( ... ) {
|
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZT_Node_circuitTestEnd(ZT_Node *node,ZT_CircuitTest *test)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->circuitTestEnd(test);
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2015-10-20 22:27:53 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_clusterInit(
|
|
|
|
ZT_Node *node,
|
|
|
|
unsigned int myId,
|
|
|
|
const struct sockaddr_storage *zeroTierPhysicalEndpoints,
|
|
|
|
unsigned int numZeroTierPhysicalEndpoints,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int z,
|
|
|
|
void (*sendFunction)(void *,unsigned int,const void *,unsigned int),
|
|
|
|
void *sendFunctionArg,
|
|
|
|
int (*addressToLocationFunction)(void *,const struct sockaddr_storage *,int *,int *,int *),
|
|
|
|
void *addressToLocationFunctionArg)
|
2015-07-06 22:51:04 +00:00
|
|
|
{
|
|
|
|
try {
|
2015-10-20 22:27:53 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->clusterInit(myId,zeroTierPhysicalEndpoints,numZeroTierPhysicalEndpoints,x,y,z,sendFunction,sendFunctionArg,addressToLocationFunction,addressToLocationFunctionArg);
|
2015-07-07 15:54:48 +00:00
|
|
|
} catch ( ... ) {
|
2015-10-20 22:27:53 +00:00
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
2015-07-07 15:54:48 +00:00
|
|
|
}
|
2015-07-06 22:51:04 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 22:27:53 +00:00
|
|
|
enum ZT_ResultCode ZT_Node_clusterAddMember(ZT_Node *node,unsigned int memberId)
|
2015-07-06 22:51:04 +00:00
|
|
|
{
|
|
|
|
try {
|
2015-10-20 22:27:53 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->clusterAddMember(memberId);
|
|
|
|
} catch ( ... ) {
|
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZT_Node_clusterRemoveMember(ZT_Node *node,unsigned int memberId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->clusterRemoveMember(memberId);
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZT_Node_clusterHandleIncomingMessage(ZT_Node *node,const void *msg,unsigned int len)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->clusterHandleIncomingMessage(msg,len);
|
2015-07-06 22:51:04 +00:00
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2015-10-26 19:49:17 +00:00
|
|
|
void ZT_Node_clusterStatus(ZT_Node *node,ZT_ClusterStatus *cs)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->clusterStatus(cs);
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2016-07-12 15:29:50 +00:00
|
|
|
void ZT_Node_setTrustedPaths(ZT_Node *node,const struct sockaddr_storage *networks,const uint64_t *ids,unsigned int count)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->setTrustedPaths(networks,ids,count);
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2016-05-06 18:13:34 +00:00
|
|
|
void ZT_version(int *major,int *minor,int *revision)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
if (major) *major = ZEROTIER_ONE_VERSION_MAJOR;
|
|
|
|
if (minor) *minor = ZEROTIER_ONE_VERSION_MINOR;
|
|
|
|
if (revision) *revision = ZEROTIER_ONE_VERSION_REVISION;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|