2015-04-01 00:53:34 +00:00
|
|
|
/*
|
|
|
|
* ZeroTier One - Network Virtualization Everywhere
|
|
|
|
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* --
|
|
|
|
*
|
|
|
|
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
|
|
|
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
*
|
|
|
|
* If you would like to embed ZeroTier into a commercial application or
|
|
|
|
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
|
|
|
* LLC. Start here: http://www.zerotier.com/
|
|
|
|
*/
|
|
|
|
|
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 "CMWC4096.hpp"
|
|
|
|
#include "Switch.hpp"
|
|
|
|
#include "Multicaster.hpp"
|
|
|
|
#include "AntiRecursion.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-04-08 02:31:11 +00:00
|
|
|
#include "Defaults.hpp"
|
2015-04-01 00:53:34 +00:00
|
|
|
|
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) */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
2015-04-01 01:17:11 +00:00
|
|
|
Node::Node(
|
2015-04-02 02:09:18 +00:00
|
|
|
uint64_t now,
|
2015-04-10 01:14:27 +00:00
|
|
|
void *uptr,
|
2015-04-03 20:14:37 +00:00
|
|
|
ZT1_DataStoreGetFunction dataStoreGetFunction,
|
|
|
|
ZT1_DataStorePutFunction dataStorePutFunction,
|
|
|
|
ZT1_WirePacketSendFunction wirePacketSendFunction,
|
|
|
|
ZT1_VirtualNetworkFrameFunction virtualNetworkFrameFunction,
|
2015-04-06 23:52:52 +00:00
|
|
|
ZT1_VirtualNetworkConfigFunction virtualNetworkConfigFunction,
|
2015-04-08 23:07:47 +00:00
|
|
|
ZT1_EventCallback eventCallback,
|
2015-04-08 02:31:11 +00:00
|
|
|
const char *overrideRootTopology) :
|
2015-04-30 23:03:44 +00:00
|
|
|
_RR(this),
|
|
|
|
RR(&_RR),
|
2015-04-24 20:35:17 +00:00
|
|
|
_uPtr(uptr),
|
2015-04-01 01:17:11 +00:00
|
|
|
_dataStoreGetFunction(dataStoreGetFunction),
|
|
|
|
_dataStorePutFunction(dataStorePutFunction),
|
2015-04-01 21:59:44 +00:00
|
|
|
_wirePacketSendFunction(wirePacketSendFunction),
|
|
|
|
_virtualNetworkFrameFunction(virtualNetworkFrameFunction),
|
2015-04-06 23:52:52 +00:00
|
|
|
_virtualNetworkConfigFunction(virtualNetworkConfigFunction),
|
2015-04-08 23:07:47 +00:00
|
|
|
_eventCallback(eventCallback),
|
2015-04-01 01:17:11 +00:00
|
|
|
_networks(),
|
|
|
|
_networks_m(),
|
2015-04-08 02:31:11 +00:00
|
|
|
_now(now),
|
|
|
|
_lastPingCheck(0),
|
2015-07-06 22:28:48 +00:00
|
|
|
_lastHousekeepingRun(0)
|
2015-04-01 01:17:11 +00:00
|
|
|
{
|
2015-04-06 21:50:53 +00:00
|
|
|
_newestVersionSeen[0] = ZEROTIER_ONE_VERSION_MAJOR;
|
|
|
|
_newestVersionSeen[1] = ZEROTIER_ONE_VERSION_MINOR;
|
|
|
|
_newestVersionSeen[2] = ZEROTIER_ONE_VERSION_REVISION;
|
2015-04-09 00:10:21 +00:00
|
|
|
_online = false;
|
2015-04-06 21:50:53 +00:00
|
|
|
|
2015-04-07 23:41:56 +00:00
|
|
|
std::string idtmp(dataStoreGet("identity.secret"));
|
|
|
|
if ((!idtmp.length())||(!RR->identity.fromString(idtmp))||(!RR->identity.hasPrivate())) {
|
2015-04-10 03:54:00 +00:00
|
|
|
TRACE("identity.secret not found, generating...");
|
2015-04-07 23:41:56 +00:00
|
|
|
RR->identity.generate();
|
|
|
|
idtmp = RR->identity.toString(true);
|
2015-04-30 23:03:44 +00:00
|
|
|
if (!dataStorePut("identity.secret",idtmp,true))
|
2015-04-07 23:41:56 +00:00
|
|
|
throw std::runtime_error("unable to write identity.secret");
|
|
|
|
}
|
2015-04-09 01:25:40 +00:00
|
|
|
RR->publicIdentityStr = RR->identity.toString(false);
|
|
|
|
RR->secretIdentityStr = RR->identity.toString(true);
|
2015-04-07 23:41:56 +00:00
|
|
|
|
2015-04-30 23:03:44 +00:00
|
|
|
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-01 01:17:11 +00:00
|
|
|
try {
|
|
|
|
RR->prng = new CMWC4096();
|
|
|
|
RR->sw = new Switch(RR);
|
|
|
|
RR->mc = new Multicaster(RR);
|
2015-04-06 21:55:40 +00:00
|
|
|
RR->antiRec = new AntiRecursion();
|
2015-04-01 01:17:11 +00:00
|
|
|
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->antiRec;
|
|
|
|
delete RR->mc;
|
|
|
|
delete RR->sw;
|
|
|
|
delete RR->prng;
|
|
|
|
throw;
|
|
|
|
}
|
2015-04-07 23:41:56 +00:00
|
|
|
|
2015-04-08 02:31:11 +00:00
|
|
|
Dictionary rt;
|
|
|
|
if (overrideRootTopology) {
|
|
|
|
rt.fromString(std::string(overrideRootTopology));
|
|
|
|
} else {
|
|
|
|
std::string rttmp(dataStoreGet("root-topology"));
|
|
|
|
if (rttmp.length() > 0) {
|
|
|
|
rt.fromString(rttmp);
|
|
|
|
if (!Topology::authenticateRootTopology(rt))
|
|
|
|
rt.clear();
|
|
|
|
}
|
|
|
|
if (!rt.size())
|
|
|
|
rt.fromString(ZT_DEFAULTS.defaultRootTopology);
|
|
|
|
}
|
2015-06-19 17:23:25 +00:00
|
|
|
RR->topology->setRootServers(Dictionary(rt.get("rootservers","")));
|
2015-04-08 02:31:11 +00:00
|
|
|
|
2015-04-07 23:41:56 +00:00
|
|
|
postEvent(ZT1_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-06-26 18:38:31 +00:00
|
|
|
_networks.clear(); // ensure that networks are destroyed before shutdown
|
2015-04-07 03:17:21 +00:00
|
|
|
delete RR->sa;
|
2015-04-01 01:17:11 +00:00
|
|
|
delete RR->topology;
|
|
|
|
delete RR->antiRec;
|
|
|
|
delete RR->mc;
|
|
|
|
delete RR->sw;
|
|
|
|
delete RR->prng;
|
|
|
|
}
|
|
|
|
|
2015-04-01 23:27:14 +00:00
|
|
|
ZT1_ResultCode Node::processWirePacket(
|
|
|
|
uint64_t now,
|
|
|
|
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-05-21 22:58:26 +00:00
|
|
|
RR->sw->onRemotePacket(*(reinterpret_cast<const InetAddress *>(remoteAddress)),packetData,packetLength);
|
2015-04-08 02:31:11 +00:00
|
|
|
return ZT1_RESULT_OK;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ZT1_ResultCode Node::processVirtualNetworkFrame(
|
|
|
|
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-04-15 20:09:20 +00:00
|
|
|
return ZT1_RESULT_OK;
|
|
|
|
} else return ZT1_RESULT_ERROR_NETWORK_NOT_FOUND;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 02:31:11 +00:00
|
|
|
class _PingPeersThatNeedPing
|
|
|
|
{
|
|
|
|
public:
|
2015-06-02 02:05:27 +00:00
|
|
|
_PingPeersThatNeedPing(const RuntimeEnvironment *renv,uint64_t now,const std::vector< std::pair<Address,InetAddress> > &relays) :
|
2015-04-09 00:10:21 +00:00
|
|
|
lastReceiveFromUpstream(0),
|
2015-04-08 02:31:11 +00:00
|
|
|
RR(renv),
|
|
|
|
_now(now),
|
2015-06-02 02:05:27 +00:00
|
|
|
_relays(relays),
|
2015-06-19 17:23:25 +00:00
|
|
|
_rootAddresses(RR->topology->rootAddresses())
|
2015-06-01 23:53:58 +00:00
|
|
|
{
|
|
|
|
}
|
2015-04-08 02:31:11 +00:00
|
|
|
|
2015-04-09 00:10:21 +00:00
|
|
|
uint64_t lastReceiveFromUpstream;
|
2015-04-08 02:31:11 +00:00
|
|
|
|
|
|
|
inline void operator()(Topology &t,const SharedPtr<Peer> &p)
|
|
|
|
{
|
2015-06-02 02:05:27 +00:00
|
|
|
bool isRelay = false;
|
|
|
|
for(std::vector< std::pair<Address,InetAddress> >::const_iterator r(_relays.begin());r!=_relays.end();++r) {
|
|
|
|
if (r->first == p->address()) {
|
|
|
|
isRelay = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 17:23:25 +00:00
|
|
|
if ((isRelay)||(std::find(_rootAddresses.begin(),_rootAddresses.end(),p->address()) != _rootAddresses.end())) {
|
2015-04-08 02:31:11 +00:00
|
|
|
p->doPingAndKeepalive(RR,_now);
|
2015-04-09 00:10:21 +00:00
|
|
|
if (p->lastReceive() > lastReceiveFromUpstream)
|
|
|
|
lastReceiveFromUpstream = p->lastReceive();
|
2015-06-01 23:53:58 +00:00
|
|
|
} else {
|
|
|
|
if (p->alive(_now))
|
2015-06-02 02:05:27 +00:00
|
|
|
p->doPingAndKeepalive(RR,_now);
|
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;
|
|
|
|
uint64_t _now;
|
2015-06-02 02:05:27 +00:00
|
|
|
const std::vector< std::pair<Address,InetAddress> > &_relays;
|
2015-06-19 17:23:25 +00:00
|
|
|
std::vector<Address> _rootAddresses;
|
2015-04-08 02:31:11 +00:00
|
|
|
};
|
|
|
|
|
2015-04-15 20:09:20 +00:00
|
|
|
ZT1_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);
|
|
|
|
|
|
|
|
if ((now - _lastPingCheck) >= ZT_PING_CHECK_INVERVAL) {
|
|
|
|
try {
|
2015-06-02 02:05:27 +00:00
|
|
|
_lastPingCheck = now;
|
|
|
|
|
|
|
|
// Get relays and networks that need config without leaving the mutex locked
|
|
|
|
std::vector< std::pair<Address,InetAddress> > networkRelays;
|
|
|
|
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) {
|
|
|
|
SharedPtr<NetworkConfig> nc(n->second->config2());
|
|
|
|
if (((now - n->second->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)||(!nc))
|
|
|
|
needConfig.push_back(n->second);
|
2015-06-02 02:05:27 +00:00
|
|
|
if (nc)
|
|
|
|
networkRelays.insert(networkRelays.end(),nc->relays().begin(),nc->relays().end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Request updated configuration for networks that need it
|
|
|
|
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-06-02 02:05:27 +00:00
|
|
|
// Attempt to contact network preferred relays that we don't have direct links to
|
|
|
|
std::sort(networkRelays.begin(),networkRelays.end());
|
2015-06-29 17:21:28 +00:00
|
|
|
networkRelays.erase(std::unique(networkRelays.begin(),networkRelays.end()),networkRelays.end());
|
2015-06-02 02:05:27 +00:00
|
|
|
for(std::vector< std::pair<Address,InetAddress> >::const_iterator nr(networkRelays.begin());nr!=networkRelays.end();++nr) {
|
|
|
|
if (nr->second) {
|
|
|
|
SharedPtr<Peer> rp(RR->topology->getPeer(nr->first));
|
|
|
|
if ((rp)&&(!rp->hasActiveDirectPath(now)))
|
|
|
|
rp->attemptToContactAt(RR,nr->second,now);
|
|
|
|
}
|
|
|
|
}
|
2015-06-02 02:12:20 +00:00
|
|
|
|
2015-06-19 17:23:25 +00:00
|
|
|
// Ping living or root server/relay peers
|
2015-06-02 02:05:27 +00:00
|
|
|
_PingPeersThatNeedPing pfunc(RR,now,networkRelays);
|
2015-04-08 02:31:11 +00:00
|
|
|
RR->topology->eachPeer<_PingPeersThatNeedPing &>(pfunc);
|
|
|
|
|
2015-06-02 02:05:27 +00:00
|
|
|
// Update online status, post status change as event
|
2015-04-09 00:10:21 +00:00
|
|
|
bool oldOnline = _online;
|
2015-05-22 21:52:23 +00:00
|
|
|
_online = ((now - pfunc.lastReceiveFromUpstream) < ZT_PEER_ACTIVITY_TIMEOUT);
|
2015-04-09 00:10:21 +00:00
|
|
|
if (oldOnline != _online)
|
|
|
|
postEvent(_online ? ZT1_EVENT_ONLINE : ZT1_EVENT_OFFLINE);
|
2015-04-08 02:31:11 +00:00
|
|
|
} catch ( ... ) {
|
|
|
|
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ( ... ) {
|
|
|
|
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
*nextBackgroundTaskDeadline = now + (uint64_t)std::max(std::min((unsigned long)ZT_PING_CHECK_INVERVAL,RR->sw->doTimerTasks(now)),(unsigned long)ZT_CORE_TIMER_TASK_GRANULARITY);
|
|
|
|
} catch ( ... ) {
|
|
|
|
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ZT1_RESULT_OK;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 21:59:44 +00:00
|
|
|
ZT1_ResultCode Node::join(uint64_t nwid)
|
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)
|
|
|
|
_networks.push_back(std::pair< uint64_t,SharedPtr<Network> >(nwid,SharedPtr<Network>(new Network(RR,nwid))));
|
|
|
|
std::sort(_networks.begin(),_networks.end()); // will sort by nwid since it's the first in a pair<>
|
2015-04-01 23:27:14 +00:00
|
|
|
return ZT1_RESULT_OK;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 21:59:44 +00:00
|
|
|
ZT1_ResultCode Node::leave(uint64_t nwid)
|
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);
|
2015-04-02 02:09:18 +00:00
|
|
|
}
|
2015-06-26 18:38:31 +00:00
|
|
|
_networks.swap(newn);
|
2015-04-09 01:25:40 +00:00
|
|
|
return ZT1_RESULT_OK;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 21:55:40 +00:00
|
|
|
ZT1_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)));
|
|
|
|
return ZT1_RESULT_OK;
|
|
|
|
} else return ZT1_RESULT_ERROR_NETWORK_NOT_FOUND;
|
2015-04-01 21:59:44 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 21:55:40 +00:00
|
|
|
ZT1_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)));
|
|
|
|
return ZT1_RESULT_OK;
|
|
|
|
} else return ZT1_RESULT_ERROR_NETWORK_NOT_FOUND;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 01:12:45 +00:00
|
|
|
uint64_t Node::address() const
|
|
|
|
{
|
|
|
|
return RR->identity.address().toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::status(ZT1_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-04-14 01:12:45 +00:00
|
|
|
ZT1_PeerList *Node::peers() const
|
2015-04-01 01:17:11 +00:00
|
|
|
{
|
2015-04-09 01:45:21 +00:00
|
|
|
std::map< Address,SharedPtr<Peer> > peers(RR->topology->allPeers());
|
|
|
|
|
|
|
|
char *buf = (char *)::malloc(sizeof(ZT1_PeerList) + (sizeof(ZT1_Peer) * peers.size()));
|
|
|
|
if (!buf)
|
|
|
|
return (ZT1_PeerList *)0;
|
|
|
|
ZT1_PeerList *pl = (ZT1_PeerList *)buf;
|
|
|
|
pl->peers = (ZT1_Peer *)(buf + sizeof(ZT1_PeerList));
|
|
|
|
|
|
|
|
pl->peerCount = 0;
|
|
|
|
for(std::map< Address,SharedPtr<Peer> >::iterator pi(peers.begin());pi!=peers.end();++pi) {
|
|
|
|
ZT1_Peer *p = &(pl->peers[pl->peerCount++]);
|
|
|
|
p->address = pi->second->address().toInt();
|
2015-04-16 02:00:26 +00:00
|
|
|
p->lastUnicastFrame = pi->second->lastUnicastFrame();
|
|
|
|
p->lastMulticastFrame = pi->second->lastMulticastFrame();
|
2015-04-09 01:45:21 +00:00
|
|
|
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();
|
2015-06-19 17:23:25 +00:00
|
|
|
p->role = RR->topology->isRoot(pi->second->identity()) ? ZT1_PEER_ROLE_ROOT : ZT1_PEER_ROLE_LEAF;
|
2015-04-09 01:45:21 +00:00
|
|
|
|
2015-07-06 21:08:13 +00:00
|
|
|
std::vector<RemotePath> paths(pi->second->paths());
|
|
|
|
RemotePath *bestPath = pi->second->getBestPath(_now);
|
2015-04-09 01:45:21 +00:00
|
|
|
p->pathCount = 0;
|
2015-07-06 21:08:13 +00:00
|
|
|
for(std::vector<RemotePath>::iterator path(paths.begin());path!=paths.end();++path) {
|
2015-04-09 01:45:21 +00:00
|
|
|
memcpy(&(p->paths[p->pathCount].address),&(path->address()),sizeof(struct sockaddr_storage));
|
|
|
|
p->paths[p->pathCount].lastSend = path->lastSend();
|
|
|
|
p->paths[p->pathCount].lastReceive = path->lastReceived();
|
|
|
|
p->paths[p->pathCount].fixed = path->fixed() ? 1 : 0;
|
2015-04-14 20:56:28 +00:00
|
|
|
p->paths[p->pathCount].active = path->active(_now) ? 1 : 0;
|
|
|
|
p->paths[p->pathCount].preferred = ((bestPath)&&(*path == *bestPath)) ? 1 : 0;
|
2015-04-09 01:45:21 +00:00
|
|
|
++p->pathCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pl;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 01:12:45 +00:00
|
|
|
ZT1_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-04-07 01:27:24 +00:00
|
|
|
ZT1_VirtualNetworkConfig *nc = (ZT1_VirtualNetworkConfig *)::malloc(sizeof(ZT1_VirtualNetworkConfig));
|
2015-06-20 14:32:48 +00:00
|
|
|
nw->externalConfig(nc);
|
2015-04-07 01:27:24 +00:00
|
|
|
return nc;
|
|
|
|
}
|
|
|
|
return (ZT1_VirtualNetworkConfig *)0;
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 01:12:45 +00:00
|
|
|
ZT1_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);
|
|
|
|
|
|
|
|
char *buf = (char *)::malloc(sizeof(ZT1_VirtualNetworkList) + (sizeof(ZT1_VirtualNetworkConfig) * _networks.size()));
|
|
|
|
if (!buf)
|
|
|
|
return (ZT1_VirtualNetworkList *)0;
|
|
|
|
ZT1_VirtualNetworkList *nl = (ZT1_VirtualNetworkList *)buf;
|
|
|
|
nl->networks = (ZT1_VirtualNetworkConfig *)(buf + sizeof(ZT1_VirtualNetworkList));
|
|
|
|
|
|
|
|
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-07-06 22:51:04 +00:00
|
|
|
void Node::addLocalInterfaceAddress(const struct sockaddr_storage *addr,int metric,ZT1_LocalInterfaceAddressTrust trust,int reliable)
|
|
|
|
{
|
|
|
|
Mutex::Lock _l(_directPaths_m);
|
|
|
|
_directPaths.push_back(Path(*(reinterpret_cast<const InetAddress *>(addr)),metric,(Path::Trust)trust,reliable != 0));
|
|
|
|
std::sort(_directPaths.begin(),_directPaths.end());
|
|
|
|
_directPaths.erase(std::unique(_directPaths.begin(),_directPaths.end()),_directPaths.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::clearLocalInterfaceAddresses()
|
|
|
|
{
|
|
|
|
Mutex::Lock _l(_directPaths_m);
|
|
|
|
_directPaths.clear();
|
|
|
|
}
|
|
|
|
|
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);
|
2015-04-01 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 21:50:53 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Node methods used only within node/ */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
std::string Node::dataStoreGet(const char *name)
|
|
|
|
{
|
2015-04-07 21:11:47 +00:00
|
|
|
char buf[16384];
|
|
|
|
std::string r;
|
|
|
|
unsigned long olen = 0;
|
|
|
|
do {
|
2015-04-24 22:05:28 +00:00
|
|
|
long n = _dataStoreGetFunction(reinterpret_cast<ZT1_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
|
|
|
}
|
|
|
|
|
|
|
|
void Node::postNewerVersionIfNewer(unsigned int major,unsigned int minor,unsigned int rev)
|
|
|
|
{
|
2015-05-21 02:38:49 +00:00
|
|
|
if (Utils::compareVersion(major,minor,rev,_newestVersionSeen[0],_newestVersionSeen[1],_newestVersionSeen[2]) > 0) {
|
2015-04-06 21:50:53 +00:00
|
|
|
_newestVersionSeen[0] = major;
|
|
|
|
_newestVersionSeen[1] = minor;
|
|
|
|
_newestVersionSeen[2] = rev;
|
2015-04-08 23:49:21 +00:00
|
|
|
this->postEvent(ZT1_EVENT_SAW_MORE_RECENT_VERSION,(const void *)_newestVersionSeen);
|
2015-04-06 21:50:53 +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);
|
|
|
|
postEvent(ZT1_EVENT_TRACE,tmp1);
|
|
|
|
}
|
|
|
|
#endif // ZT_TRACE
|
|
|
|
|
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" {
|
|
|
|
|
|
|
|
enum ZT1_ResultCode ZT1_Node_new(
|
|
|
|
ZT1_Node **node,
|
2015-04-10 01:14:27 +00:00
|
|
|
void *uptr,
|
2015-04-02 02:09:18 +00:00
|
|
|
uint64_t now,
|
2015-04-03 20:14:37 +00:00
|
|
|
ZT1_DataStoreGetFunction dataStoreGetFunction,
|
|
|
|
ZT1_DataStorePutFunction dataStorePutFunction,
|
|
|
|
ZT1_WirePacketSendFunction wirePacketSendFunction,
|
|
|
|
ZT1_VirtualNetworkFrameFunction virtualNetworkFrameFunction,
|
2015-04-06 23:52:52 +00:00
|
|
|
ZT1_VirtualNetworkConfigFunction virtualNetworkConfigFunction,
|
2015-04-08 23:07:47 +00:00
|
|
|
ZT1_EventCallback eventCallback,
|
2015-04-08 02:31:11 +00:00
|
|
|
const char *overrideRootTopology)
|
2015-04-01 23:27:14 +00:00
|
|
|
{
|
|
|
|
*node = (ZT1_Node *)0;
|
|
|
|
try {
|
2015-04-10 01:14:27 +00:00
|
|
|
*node = reinterpret_cast<ZT1_Node *>(new ZeroTier::Node(now,uptr,dataStoreGetFunction,dataStorePutFunction,wirePacketSendFunction,virtualNetworkFrameFunction,virtualNetworkConfigFunction,eventCallback,overrideRootTopology));
|
2015-04-01 23:27:14 +00:00
|
|
|
return ZT1_RESULT_OK;
|
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-04-06 21:50:53 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch (std::runtime_error &exc) {
|
2015-04-06 21:50:53 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_DATA_STORE_FAILED;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-04-06 21:50:53 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-06 21:50:53 +00:00
|
|
|
void ZT1_Node_delete(ZT1_Node *node)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
delete (reinterpret_cast<ZeroTier::Node *>(node));
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2015-04-01 23:27:14 +00:00
|
|
|
enum ZT1_ResultCode ZT1_Node_processWirePacket(
|
|
|
|
ZT1_Node *node,
|
|
|
|
uint64_t now,
|
|
|
|
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-05-21 22:58:26 +00:00
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->processWirePacket(now,remoteAddress,packetData,packetLength,nextBackgroundTaskDeadline);
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-04-06 21:50:53 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-04-08 23:49:21 +00:00
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->postEvent(ZT1_EVENT_INVALID_PACKET,(const void *)remoteAddress);
|
|
|
|
return ZT1_RESULT_OK;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ZT1_ResultCode ZT1_Node_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,
|
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-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-15 20:09:20 +00:00
|
|
|
enum ZT1_ResultCode ZT1_Node_processBackgroundTasks(ZT1_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-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ZT1_ResultCode ZT1_Node_join(ZT1_Node *node,uint64_t nwid)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->join(nwid);
|
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ZT1_ResultCode ZT1_Node_leave(ZT1_Node *node,uint64_t nwid)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->leave(nwid);
|
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ZT1_ResultCode ZT1_Node_multicastSubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->multicastSubscribe(nwid,multicastGroup,multicastAdi);
|
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ZT1_ResultCode ZT1_Node_multicastUnsubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->multicastUnsubscribe(nwid,multicastGroup,multicastAdi);
|
|
|
|
} catch (std::bad_alloc &exc) {
|
2015-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
2015-04-01 23:27:14 +00:00
|
|
|
} catch ( ... ) {
|
2015-04-06 21:55:40 +00:00
|
|
|
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-14 01:12:45 +00:00
|
|
|
uint64_t ZT1_Node_address(ZT1_Node *node)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->address();
|
|
|
|
}
|
|
|
|
|
2015-04-01 23:27:14 +00:00
|
|
|
void ZT1_Node_status(ZT1_Node *node,ZT1_NodeStatus *status)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->status(status);
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
ZT1_PeerList *ZT1_Node_peers(ZT1_Node *node)
|
|
|
|
{
|
|
|
|
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 ( ... ) {
|
|
|
|
return (ZT1_PeerList *)0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ZT1_VirtualNetworkConfig *ZT1_Node_networkConfig(ZT1_Node *node,uint64_t nwid)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->networkConfig(nwid);
|
|
|
|
} catch ( ... ) {
|
|
|
|
return (ZT1_VirtualNetworkConfig *)0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 01:27:24 +00:00
|
|
|
ZT1_VirtualNetworkList *ZT1_Node_networks(ZT1_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 ( ... ) {
|
|
|
|
return (ZT1_VirtualNetworkList *)0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZT1_Node_freeQueryResult(ZT1_Node *node,void *qr)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->freeQueryResult(qr);
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2015-04-15 22:12:09 +00:00
|
|
|
void ZT1_Node_setNetconfMaster(ZT1_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-07-06 22:51:04 +00:00
|
|
|
void ZT1_Node_addLocalInterfaceAddress(ZT1_Node *node,const struct sockaddr_storage *addr,int metric,ZT1_LocalInterfaceAddressTrust trust,int reliable)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->addLocalInterfaceAddress(addr,metric,trust,reliable);
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZT1_Node_clearLocalInterfaceAddresses(ZT1_Node *node)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->clearLocalInterfaceAddresses();
|
|
|
|
} catch ( ... ) {}
|
|
|
|
}
|
|
|
|
|
2015-04-01 23:27:14 +00:00
|
|
|
void ZT1_version(int *major,int *minor,int *revision,unsigned long *featureFlags)
|
|
|
|
{
|
|
|
|
if (major) *major = ZEROTIER_ONE_VERSION_MAJOR;
|
|
|
|
if (minor) *minor = ZEROTIER_ONE_VERSION_MINOR;
|
|
|
|
if (revision) *revision = ZEROTIER_ONE_VERSION_REVISION;
|
|
|
|
if (featureFlags) {
|
2015-04-06 21:55:40 +00:00
|
|
|
*featureFlags = (
|
|
|
|
ZT1_FEATURE_FLAG_THREAD_SAFE
|
|
|
|
);
|
2015-04-01 23:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|