|
@@ -34,13 +34,13 @@ namespace {
|
|
|
// Structure containing all the core objects for a ZeroTier node to reduce memory allocations.
|
|
|
struct _NodeObjects
|
|
|
{
|
|
|
- ZT_INLINE _NodeObjects(RuntimeEnvironment *const RR,void *const tPtr) :
|
|
|
+ ZT_INLINE _NodeObjects(RuntimeEnvironment *const RR, void *const tPtr) :
|
|
|
t(RR),
|
|
|
expect(),
|
|
|
vl2(RR),
|
|
|
vl1(RR),
|
|
|
sa(RR),
|
|
|
- topology(RR,tPtr)
|
|
|
+ topology(RR, tPtr)
|
|
|
{
|
|
|
RR->t = &t;
|
|
|
RR->expect = &expect;
|
|
@@ -49,6 +49,7 @@ struct _NodeObjects
|
|
|
RR->sa = &sa;
|
|
|
RR->topology = &topology;
|
|
|
}
|
|
|
+
|
|
|
Trace t;
|
|
|
Expect expect;
|
|
|
VL2 vl2;
|
|
@@ -59,12 +60,13 @@ struct _NodeObjects
|
|
|
|
|
|
struct _sortPeerPtrsByAddress
|
|
|
{
|
|
|
- ZT_INLINE bool operator()(const SharedPtr<Peer> &a,const SharedPtr<Peer> &b) const { return (a->address() < b->address()); }
|
|
|
+ ZT_INLINE bool operator()(const SharedPtr<Peer> &a, const SharedPtr<Peer> &b) const
|
|
|
+ { return (a->address() < b->address()); }
|
|
|
};
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
-Node::Node(void *uPtr,void *tPtr,const struct ZT_Node_Callbacks *callbacks,int64_t now) :
|
|
|
+Node::Node(void *uPtr, void *tPtr, const struct ZT_Node_Callbacks *callbacks, int64_t now) :
|
|
|
m_RR(this),
|
|
|
RR(&m_RR),
|
|
|
m_objects(nullptr),
|
|
@@ -79,14 +81,16 @@ Node::Node(void *uPtr,void *tPtr,const struct ZT_Node_Callbacks *callbacks,int64
|
|
|
m_online(false)
|
|
|
{
|
|
|
// Load this node's identity.
|
|
|
- uint64_t idtmp[2]; idtmp[0] = 0; idtmp[1] = 0;
|
|
|
- Vector<uint8_t> data(stateObjectGet(tPtr,ZT_STATE_OBJECT_IDENTITY_SECRET,idtmp));
|
|
|
+ uint64_t idtmp[2];
|
|
|
+ idtmp[0] = 0;
|
|
|
+ idtmp[1] = 0;
|
|
|
+ Vector<uint8_t> data(stateObjectGet(tPtr, ZT_STATE_OBJECT_IDENTITY_SECRET, idtmp));
|
|
|
bool haveIdentity = false;
|
|
|
if (!data.empty()) {
|
|
|
data.push_back(0); // zero-terminate string
|
|
|
- if (RR->identity.fromString((const char *)data.data())) {
|
|
|
- RR->identity.toString(false,RR->publicIdentityStr);
|
|
|
- RR->identity.toString(true,RR->secretIdentityStr);
|
|
|
+ if (RR->identity.fromString((const char *) data.data())) {
|
|
|
+ RR->identity.toString(false, RR->publicIdentityStr);
|
|
|
+ RR->identity.toString(true, RR->secretIdentityStr);
|
|
|
haveIdentity = true;
|
|
|
}
|
|
|
}
|
|
@@ -94,16 +98,18 @@ Node::Node(void *uPtr,void *tPtr,const struct ZT_Node_Callbacks *callbacks,int64
|
|
|
// Generate a new identity if we don't have one.
|
|
|
if (!haveIdentity) {
|
|
|
RR->identity.generate(Identity::C25519);
|
|
|
- RR->identity.toString(false,RR->publicIdentityStr);
|
|
|
- RR->identity.toString(true,RR->secretIdentityStr);
|
|
|
- idtmp[0] = RR->identity.address().toInt(); idtmp[1] = 0;
|
|
|
- stateObjectPut(tPtr,ZT_STATE_OBJECT_IDENTITY_SECRET,idtmp,RR->secretIdentityStr,(unsigned int)strlen(RR->secretIdentityStr));
|
|
|
- stateObjectPut(tPtr,ZT_STATE_OBJECT_IDENTITY_PUBLIC,idtmp,RR->publicIdentityStr,(unsigned int)strlen(RR->publicIdentityStr));
|
|
|
+ RR->identity.toString(false, RR->publicIdentityStr);
|
|
|
+ RR->identity.toString(true, RR->secretIdentityStr);
|
|
|
+ idtmp[0] = RR->identity.address();
|
|
|
+ idtmp[1] = 0;
|
|
|
+ stateObjectPut(tPtr, ZT_STATE_OBJECT_IDENTITY_SECRET, idtmp, RR->secretIdentityStr, (unsigned int) strlen(RR->secretIdentityStr));
|
|
|
+ stateObjectPut(tPtr, ZT_STATE_OBJECT_IDENTITY_PUBLIC, idtmp, RR->publicIdentityStr, (unsigned int) strlen(RR->publicIdentityStr));
|
|
|
} else {
|
|
|
- idtmp[0] = RR->identity.address().toInt(); idtmp[1] = 0;
|
|
|
- data = stateObjectGet(tPtr,ZT_STATE_OBJECT_IDENTITY_PUBLIC,idtmp);
|
|
|
- if ((data.empty())||(memcmp(data.data(),RR->publicIdentityStr,strlen(RR->publicIdentityStr)) != 0))
|
|
|
- stateObjectPut(tPtr,ZT_STATE_OBJECT_IDENTITY_PUBLIC,idtmp,RR->publicIdentityStr,(unsigned int)strlen(RR->publicIdentityStr));
|
|
|
+ idtmp[0] = RR->identity.address();
|
|
|
+ idtmp[1] = 0;
|
|
|
+ data = stateObjectGet(tPtr, ZT_STATE_OBJECT_IDENTITY_PUBLIC, idtmp);
|
|
|
+ if ((data.empty()) || (memcmp(data.data(), RR->publicIdentityStr, strlen(RR->publicIdentityStr)) != 0))
|
|
|
+ stateObjectPut(tPtr, ZT_STATE_OBJECT_IDENTITY_PUBLIC, idtmp, RR->publicIdentityStr, (unsigned int) strlen(RR->publicIdentityStr));
|
|
|
}
|
|
|
|
|
|
uint8_t tmph[ZT_SHA384_DIGEST_SIZE];
|
|
@@ -126,7 +132,7 @@ Node::~Node()
|
|
|
m_networks_l.unlock();
|
|
|
|
|
|
if (m_objects)
|
|
|
- delete (_NodeObjects *)m_objects;
|
|
|
+ delete (_NodeObjects *) m_objects;
|
|
|
|
|
|
// Let go of cached Buf objects. If other nodes happen to be running in this
|
|
|
// same process space new Bufs will be allocated as needed, but this is almost
|
|
@@ -137,6 +143,7 @@ Node::~Node()
|
|
|
|
|
|
void Node::shutdown(void *tPtr)
|
|
|
{
|
|
|
+ postEvent(tPtr, ZT_EVENT_DOWN);
|
|
|
if (RR->topology)
|
|
|
RR->topology->saveAll(tPtr);
|
|
|
}
|
|
@@ -151,7 +158,7 @@ ZT_ResultCode Node::processWirePacket(
|
|
|
volatile int64_t *nextBackgroundTaskDeadline)
|
|
|
{
|
|
|
m_now = now;
|
|
|
- RR->vl1->onRemotePacket(tPtr,localSocket,(remoteAddress) ? InetAddress::NIL : *asInetAddress(remoteAddress),packetData,packetLength);
|
|
|
+ RR->vl1->onRemotePacket(tPtr, localSocket, (remoteAddress) ? InetAddress::NIL : *asInetAddress(remoteAddress), packetData, packetLength);
|
|
|
return ZT_RESULT_OK;
|
|
|
}
|
|
|
|
|
@@ -170,7 +177,7 @@ ZT_ResultCode Node::processVirtualNetworkFrame(
|
|
|
m_now = now;
|
|
|
SharedPtr<Network> nw(this->network(nwid));
|
|
|
if (nw) {
|
|
|
- RR->vl2->onLocalEthernet(tPtr,nw,MAC(sourceMac),MAC(destMac),etherType,vlanId,frameData,frameLength);
|
|
|
+ RR->vl2->onLocalEthernet(tPtr, nw, MAC(sourceMac), MAC(destMac), etherType, vlanId, frameData, frameLength);
|
|
|
return ZT_RESULT_OK;
|
|
|
} else {
|
|
|
return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
|
|
@@ -179,20 +186,22 @@ ZT_ResultCode Node::processVirtualNetworkFrame(
|
|
|
|
|
|
struct _processBackgroundTasks_eachPeer
|
|
|
{
|
|
|
- ZT_INLINE _processBackgroundTasks_eachPeer(const int64_t now_,Node *const parent_,void *const tPtr_) noexcept :
|
|
|
+ ZT_INLINE _processBackgroundTasks_eachPeer(const int64_t now_, Node *const parent_, void *const tPtr_) noexcept:
|
|
|
now(now_),
|
|
|
parent(parent_),
|
|
|
tPtr(tPtr_),
|
|
|
online(false),
|
|
|
- rootsNotOnline() {}
|
|
|
+ rootsNotOnline()
|
|
|
+ {}
|
|
|
+
|
|
|
const int64_t now;
|
|
|
Node *const parent;
|
|
|
void *const tPtr;
|
|
|
bool online;
|
|
|
- Vector< SharedPtr<Peer> > rootsNotOnline;
|
|
|
- ZT_INLINE void operator()(const SharedPtr<Peer> &peer,const bool isRoot) noexcept
|
|
|
+ Vector<SharedPtr<Peer> > rootsNotOnline;
|
|
|
+ ZT_INLINE void operator()(const SharedPtr<Peer> &peer, const bool isRoot) noexcept
|
|
|
{
|
|
|
- peer->pulse(tPtr,now,isRoot);
|
|
|
+ peer->pulse(tPtr, now, isRoot);
|
|
|
if (isRoot) {
|
|
|
if (peer->directlyConnected(now)) {
|
|
|
online = true;
|
|
@@ -202,7 +211,8 @@ struct _processBackgroundTasks_eachPeer
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
-ZT_ResultCode Node::processBackgroundTasks(void *tPtr,int64_t now,volatile int64_t *nextBackgroundTaskDeadline)
|
|
|
+
|
|
|
+ZT_ResultCode Node::processBackgroundTasks(void *tPtr, int64_t now, volatile int64_t *nextBackgroundTaskDeadline)
|
|
|
{
|
|
|
m_now = now;
|
|
|
Mutex::Lock bl(m_backgroundTasksLock);
|
|
@@ -212,7 +222,7 @@ ZT_ResultCode Node::processBackgroundTasks(void *tPtr,int64_t now,volatile int64
|
|
|
if ((now - m_lastPeerPulse) >= ZT_PEER_PULSE_INTERVAL) {
|
|
|
m_lastPeerPulse = now;
|
|
|
try {
|
|
|
- _processBackgroundTasks_eachPeer pf(now,this,tPtr);
|
|
|
+ _processBackgroundTasks_eachPeer pf(now, this, tPtr);
|
|
|
RR->topology->eachPeerWithRoot<_processBackgroundTasks_eachPeer &>(pf);
|
|
|
|
|
|
if (pf.online != m_online) {
|
|
@@ -228,7 +238,7 @@ ZT_ResultCode Node::processBackgroundTasks(void *tPtr,int64_t now,volatile int64
|
|
|
//for (Vector<Address>::const_iterator r(pf.rootsNotOnline.begin()); r != pf.rootsNotOnline.end(); ++r)
|
|
|
// RR->sw->requestWhois(tPtr,now,*r);
|
|
|
}
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
}
|
|
@@ -238,8 +248,8 @@ ZT_ResultCode Node::processBackgroundTasks(void *tPtr,int64_t now,volatile int64
|
|
|
m_lastHousekeepingRun = now;
|
|
|
{
|
|
|
RWMutex::RLock l(m_networks_l);
|
|
|
- for(Map< uint64_t,SharedPtr<Network> >::const_iterator i(m_networks.begin());i != m_networks.end();++i)
|
|
|
- i->second->doPeriodicTasks(tPtr,now);
|
|
|
+ for (Map<uint64_t, SharedPtr<Network> >::const_iterator i(m_networks.begin());i != m_networks.end();++i)
|
|
|
+ i->second->doPeriodicTasks(tPtr, now);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -251,7 +261,7 @@ ZT_ResultCode Node::processBackgroundTasks(void *tPtr,int64_t now,volatile int64
|
|
|
// optimization for network controllers to know whether to accept
|
|
|
// or trust nodes without doing an extra cert check.
|
|
|
m_localControllerAuthorizations_l.lock();
|
|
|
- for(Map<p_LocalControllerAuth,int64_t>::iterator i(m_localControllerAuthorizations.begin());i != m_localControllerAuthorizations.end();) { // NOLINT(hicpp-use-auto,modernize-use-auto)
|
|
|
+ for (Map<p_LocalControllerAuth, int64_t>::iterator i(m_localControllerAuthorizations.begin());i != m_localControllerAuthorizations.end();) { // NOLINT(hicpp-use-auto,modernize-use-auto)
|
|
|
if ((i->second - now) > (ZT_NETWORK_AUTOCONF_DELAY * 3))
|
|
|
m_localControllerAuthorizations.erase(i++);
|
|
|
else ++i;
|
|
@@ -260,40 +270,40 @@ ZT_ResultCode Node::processBackgroundTasks(void *tPtr,int64_t now,volatile int64
|
|
|
|
|
|
RR->topology->doPeriodicTasks(tPtr, now);
|
|
|
RR->sa->clean(now);
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
*nextBackgroundTaskDeadline = now + ZT_TIMER_TASK_INTERVAL;
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
|
|
|
return ZT_RESULT_OK;
|
|
|
}
|
|
|
|
|
|
-ZT_ResultCode Node::join(uint64_t nwid,const ZT_Fingerprint *controllerFingerprint,void *uptr,void *tptr)
|
|
|
+ZT_ResultCode Node::join(uint64_t nwid, const ZT_Fingerprint *controllerFingerprint, void *uptr, void *tptr)
|
|
|
{
|
|
|
Fingerprint fp;
|
|
|
if (controllerFingerprint)
|
|
|
- Utils::copy<sizeof(ZT_Fingerprint)>(fp.apiFingerprint(),controllerFingerprint);
|
|
|
+ Utils::copy<sizeof(ZT_Fingerprint)>(fp.apiFingerprint(), controllerFingerprint);
|
|
|
|
|
|
RWMutex::Lock l(m_networks_l);
|
|
|
SharedPtr<Network> &nw = m_networks[nwid];
|
|
|
if (nw)
|
|
|
return ZT_RESULT_OK;
|
|
|
- nw.set(new Network(RR,tptr,nwid,fp,uptr,nullptr));
|
|
|
+ nw.set(new Network(RR, tptr, nwid, fp, uptr, nullptr));
|
|
|
|
|
|
return ZT_RESULT_OK;
|
|
|
}
|
|
|
|
|
|
-ZT_ResultCode Node::leave(uint64_t nwid,void **uptr,void *tptr)
|
|
|
+ZT_ResultCode Node::leave(uint64_t nwid, void **uptr, void *tptr)
|
|
|
{
|
|
|
ZT_VirtualNetworkConfig ctmp;
|
|
|
|
|
|
m_networks_l.lock();
|
|
|
- Map< uint64_t,SharedPtr<Network> >::iterator nwi(m_networks.find(nwid)); // NOLINT(hicpp-use-auto,modernize-use-auto)
|
|
|
+ Map<uint64_t, SharedPtr<Network> >::iterator nwi(m_networks.find(nwid)); // NOLINT(hicpp-use-auto,modernize-use-auto)
|
|
|
if (nwi == m_networks.end()) {
|
|
|
m_networks_l.unlock();
|
|
|
return ZT_RESULT_OK;
|
|
@@ -306,53 +316,50 @@ ZT_ResultCode Node::leave(uint64_t nwid,void **uptr,void *tptr)
|
|
|
*uptr = *nw->userPtr();
|
|
|
nw->externalConfig(&ctmp);
|
|
|
|
|
|
- RR->node->configureVirtualNetworkPort(tptr,nwid,uptr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY,&ctmp);
|
|
|
+ RR->node->configureVirtualNetworkPort(tptr, nwid, uptr, ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY, &ctmp);
|
|
|
|
|
|
nw->destroy();
|
|
|
nw.zero();
|
|
|
|
|
|
uint64_t tmp[2];
|
|
|
- tmp[0] = nwid; tmp[1] = 0;
|
|
|
- RR->node->stateObjectDelete(tptr,ZT_STATE_OBJECT_NETWORK_CONFIG,tmp);
|
|
|
+ tmp[0] = nwid;
|
|
|
+ tmp[1] = 0;
|
|
|
+ RR->node->stateObjectDelete(tptr, ZT_STATE_OBJECT_NETWORK_CONFIG, tmp);
|
|
|
|
|
|
return ZT_RESULT_OK;
|
|
|
}
|
|
|
|
|
|
-ZT_ResultCode Node::multicastSubscribe(void *tPtr,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
|
|
+ZT_ResultCode Node::multicastSubscribe(void *tPtr, uint64_t nwid, uint64_t multicastGroup, unsigned long multicastAdi)
|
|
|
{
|
|
|
const SharedPtr<Network> nw(this->network(nwid));
|
|
|
if (nw) {
|
|
|
- nw->multicastSubscribe(tPtr,MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
|
|
|
+ nw->multicastSubscribe(tPtr, MulticastGroup(MAC(multicastGroup), (uint32_t) (multicastAdi & 0xffffffff)));
|
|
|
return ZT_RESULT_OK;
|
|
|
} else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
|
|
|
}
|
|
|
|
|
|
-ZT_ResultCode Node::multicastUnsubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
|
|
+ZT_ResultCode Node::multicastUnsubscribe(uint64_t nwid, uint64_t multicastGroup, unsigned long multicastAdi)
|
|
|
{
|
|
|
const SharedPtr<Network> nw(this->network(nwid));
|
|
|
if (nw) {
|
|
|
- nw->multicastUnsubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
|
|
|
+ nw->multicastUnsubscribe(MulticastGroup(MAC(multicastGroup), (uint32_t) (multicastAdi & 0xffffffff)));
|
|
|
return ZT_RESULT_OK;
|
|
|
} else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
|
|
|
}
|
|
|
|
|
|
-ZT_ResultCode Node::addRoot(void *tPtr,const void *rdef,unsigned int rdeflen,uint64_t *address)
|
|
|
+ZT_ResultCode Node::addRoot(void *tPtr, const ZT_Identity *id, const ZT_Locator *loc)
|
|
|
{
|
|
|
- if ((!rdef)||(rdeflen == 0))
|
|
|
+ if ((!id)||(!loc))
|
|
|
return ZT_RESULT_ERROR_BAD_PARAMETER;
|
|
|
- std::pair<Identity,Locator> r(Locator::parseRootSpecification(rdef,rdeflen));
|
|
|
- if (address)
|
|
|
- *address = r.first.address().toInt();
|
|
|
- return ((r.first)&&(RR->topology->addRoot(tPtr,r.first,r.second))) ? ZT_RESULT_OK : ZT_RESULT_ERROR_BAD_PARAMETER;
|
|
|
+ const SharedPtr<const Locator> locator(new Locator(*reinterpret_cast<const Locator *>(loc)));
|
|
|
+ // SECURITY: locator credential validation happens in Topology.cpp in addRoot().
|
|
|
+ return RR->topology->addRoot(tPtr, *reinterpret_cast<const Identity *>(id), locator) ? ZT_RESULT_OK : ZT_RESULT_ERROR_INVALID_CREDENTIAL;
|
|
|
}
|
|
|
|
|
|
-ZT_ResultCode Node::removeRoot(void *tPtr,const ZT_Fingerprint *fp)
|
|
|
+ZT_ResultCode Node::removeRoot(void *tPtr, const uint64_t address)
|
|
|
{
|
|
|
- if (fp) {
|
|
|
- RR->topology->removeRoot(tPtr,Fingerprint(*fp));
|
|
|
- return ZT_RESULT_OK;
|
|
|
- }
|
|
|
- return ZT_RESULT_ERROR_BAD_PARAMETER;
|
|
|
+ RR->topology->removeRoot(tPtr, Address(address));
|
|
|
+ return ZT_RESULT_OK;
|
|
|
}
|
|
|
|
|
|
uint64_t Node::address() const
|
|
@@ -371,31 +378,45 @@ void Node::status(ZT_NodeStatus *status) const
|
|
|
|
|
|
ZT_PeerList *Node::peers() const
|
|
|
{
|
|
|
- Vector< SharedPtr<Peer> > peers;
|
|
|
+ Vector<SharedPtr<Peer> > peers;
|
|
|
RR->topology->getAllPeers(peers);
|
|
|
- std::sort(peers.begin(),peers.end(),_sortPeerPtrsByAddress());
|
|
|
-
|
|
|
- char *buf = (char *)::malloc(sizeof(ZT_PeerList) + (sizeof(ZT_Peer) * peers.size()) + (sizeof(Identity) * peers.size()));
|
|
|
+ std::sort(peers.begin(), peers.end(), _sortPeerPtrsByAddress());
|
|
|
+
|
|
|
+ const unsigned int bufSize =
|
|
|
+ sizeof(ZT_PeerList) +
|
|
|
+ (sizeof(ZT_Peer) * peers.size()) +
|
|
|
+ ((sizeof(ZT_Path) * ZT_MAX_PEER_NETWORK_PATHS) * peers.size()) +
|
|
|
+ (sizeof(Identity) * peers.size()) +
|
|
|
+ ((sizeof(ZT_Endpoint) * ZT_LOCATOR_MAX_ENDPOINTS) * peers.size());
|
|
|
+ char *buf = (char *) malloc(bufSize);
|
|
|
if (!buf)
|
|
|
return nullptr;
|
|
|
- ZT_PeerList *pl = (ZT_PeerList *)buf; // NOLINT(modernize-use-auto,hicpp-use-auto)
|
|
|
- pl->peers = (ZT_Peer *)(buf + sizeof(ZT_PeerList));
|
|
|
- Identity *identities = (Identity *)(buf + sizeof(ZT_PeerList) + (sizeof(ZT_Peer) * peers.size())); // NOLINT(modernize-use-auto,hicpp-use-auto)
|
|
|
+ Utils::zero(buf, bufSize);
|
|
|
+ ZT_PeerList *pl = reinterpret_cast<ZT_PeerList *>(buf);
|
|
|
+ buf += sizeof(ZT_PeerList);
|
|
|
+ pl->peers = reinterpret_cast<ZT_Peer *>(buf);
|
|
|
+ buf += sizeof(ZT_Peer) * peers.size();
|
|
|
+ ZT_Path *peerPath = reinterpret_cast<ZT_Path *>(buf);
|
|
|
+ buf += (sizeof(ZT_Path) * ZT_MAX_PEER_NETWORK_PATHS) * peers.size();
|
|
|
+ Identity *identities = reinterpret_cast<Identity *>(buf);
|
|
|
+ buf += sizeof(Identity) * peers.size();
|
|
|
+ ZT_Endpoint *locatorEndpoint = reinterpret_cast<ZT_Endpoint *>(buf);
|
|
|
|
|
|
const int64_t now = m_now;
|
|
|
+
|
|
|
pl->peerCount = 0;
|
|
|
- for(Vector< SharedPtr<Peer> >::iterator pi(peers.begin());pi!=peers.end();++pi) { // NOLINT(modernize-use-auto,modernize-loop-convert,hicpp-use-auto)
|
|
|
- ZT_Peer *const p = &(pl->peers[pl->peerCount]);
|
|
|
+ for (Vector<SharedPtr<Peer> >::iterator pi(peers.begin());pi != peers.end();++pi) {
|
|
|
+ ZT_Peer *const p = pl->peers + pl->peerCount;
|
|
|
|
|
|
p->address = (*pi)->address().toInt();
|
|
|
identities[pl->peerCount] = (*pi)->identity(); // need to make a copy in case peer gets deleted
|
|
|
- p->identity = &identities[pl->peerCount];
|
|
|
+ p->identity = identities + pl->peerCount;
|
|
|
p->fingerprint.address = p->address;
|
|
|
- Utils::copy<ZT_FINGERPRINT_HASH_SIZE>(p->fingerprint.hash,(*pi)->identity().fingerprint().hash());
|
|
|
+ Utils::copy<ZT_FINGERPRINT_HASH_SIZE>(p->fingerprint.hash, (*pi)->identity().fingerprint().hash);
|
|
|
if ((*pi)->remoteVersionKnown()) {
|
|
|
- p->versionMajor = (int)(*pi)->remoteVersionMajor();
|
|
|
- p->versionMinor = (int)(*pi)->remoteVersionMinor();
|
|
|
- p->versionRev = (int)(*pi)->remoteVersionRevision();
|
|
|
+ p->versionMajor = (int) (*pi)->remoteVersionMajor();
|
|
|
+ p->versionMinor = (int) (*pi)->remoteVersionMinor();
|
|
|
+ p->versionRev = (int) (*pi)->remoteVersionRevision();
|
|
|
} else {
|
|
|
p->versionMajor = -1;
|
|
|
p->versionMinor = -1;
|
|
@@ -404,25 +425,30 @@ ZT_PeerList *Node::peers() const
|
|
|
p->latency = (*pi)->latency();
|
|
|
p->root = RR->topology->isRoot((*pi)->identity()) ? 1 : 0;
|
|
|
|
|
|
- {
|
|
|
- FCV<Endpoint,ZT_MAX_PEER_NETWORK_PATHS> bs((*pi)->bootstrap());
|
|
|
- p->bootstrapAddressCount = 0;
|
|
|
- for (FCV<Endpoint,ZT_MAX_PEER_NETWORK_PATHS>::const_iterator i(bs.begin());i!=bs.end();++i) // NOLINT(modernize-loop-convert)
|
|
|
- Utils::copy<sizeof(sockaddr_storage)>(&(p->bootstrap[p->bootstrapAddressCount++]),&(*i));
|
|
|
- }
|
|
|
+ p->networkCount = 0;
|
|
|
+ // TODO: enumerate network memberships
|
|
|
|
|
|
- Vector< SharedPtr<Path> > paths;
|
|
|
+ Vector<SharedPtr<Path> > paths;
|
|
|
(*pi)->getAllPaths(paths);
|
|
|
- p->pathCount = 0;
|
|
|
- for(Vector< SharedPtr<Path> >::iterator path(paths.begin());path!=paths.end();++path) { // NOLINT(modernize-use-auto,modernize-loop-convert,hicpp-use-auto)
|
|
|
- Utils::copy<sizeof(sockaddr_storage)>(&(p->paths[p->pathCount].address),&((*path)->address()));
|
|
|
- p->paths[p->pathCount].lastSend = (*path)->lastOut();
|
|
|
- p->paths[p->pathCount].lastReceive = (*path)->lastIn();
|
|
|
- // TODO
|
|
|
- //p->paths[p->pathCount].trustedPathId = RR->topology->getOutboundPathTrust((*path)->address());
|
|
|
- p->paths[p->pathCount].alive = (*path)->alive(now) ? 1 : 0;
|
|
|
- p->paths[p->pathCount].preferred = (p->pathCount == 0) ? 1 : 0;
|
|
|
- ++p->pathCount;
|
|
|
+ p->pathCount = (unsigned int) paths.size();
|
|
|
+ p->paths = peerPath;
|
|
|
+ for (Vector<SharedPtr<Path> >::iterator path(paths.begin());path != paths.end();++path) {
|
|
|
+ ZT_Path *const pp = peerPath++;
|
|
|
+ pp->endpoint.type = ZT_ENDPOINT_TYPE_IP_UDP; // only type supported right now
|
|
|
+ Utils::copy<sizeof(sockaddr_storage)>(&pp->endpoint.value.ss, &((*path)->address().as.ss));
|
|
|
+ pp->lastSend = (*path)->lastOut();
|
|
|
+ pp->lastReceive = (*path)->lastIn();
|
|
|
+ pp->alive = (*path)->alive(now) ? 1 : 0;
|
|
|
+ pp->preferred = (p->pathCount == 0) ? 1 : 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ const SharedPtr<const Locator> loc((*pi)->locator());
|
|
|
+ if (loc) {
|
|
|
+ p->locatorTimestamp = loc->timestamp();
|
|
|
+ p->locatorEndpointCount = (unsigned int)loc->endpoints().size();
|
|
|
+ p->locatorEndpoints = locatorEndpoint;
|
|
|
+ for(Vector<Endpoint>::const_iterator ep(loc->endpoints().begin());ep!=loc->endpoints().end();++ep)
|
|
|
+ *(locatorEndpoint++) = *ep;
|
|
|
}
|
|
|
|
|
|
++pl->peerCount;
|
|
@@ -435,7 +461,7 @@ ZT_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid) const
|
|
|
{
|
|
|
SharedPtr<Network> nw(network(nwid));
|
|
|
if (nw) {
|
|
|
- ZT_VirtualNetworkConfig *const nc = (ZT_VirtualNetworkConfig *)::malloc(sizeof(ZT_VirtualNetworkConfig)); // NOLINT(modernize-use-auto,hicpp-use-auto)
|
|
|
+ ZT_VirtualNetworkConfig *const nc = (ZT_VirtualNetworkConfig *) ::malloc(sizeof(ZT_VirtualNetworkConfig));
|
|
|
nw->externalConfig(nc);
|
|
|
return nc;
|
|
|
}
|
|
@@ -446,39 +472,33 @@ ZT_VirtualNetworkList *Node::networks() const
|
|
|
{
|
|
|
RWMutex::RLock l(m_networks_l);
|
|
|
|
|
|
- char *const buf = (char *)::malloc(sizeof(ZT_VirtualNetworkList) + (sizeof(ZT_VirtualNetworkConfig) * m_networks.size()));
|
|
|
+ char *const buf = (char *) ::malloc(sizeof(ZT_VirtualNetworkList) + (sizeof(ZT_VirtualNetworkConfig) * m_networks.size()));
|
|
|
if (!buf)
|
|
|
return nullptr;
|
|
|
- ZT_VirtualNetworkList *nl = (ZT_VirtualNetworkList *)buf; // NOLINT(modernize-use-auto,hicpp-use-auto)
|
|
|
- nl->networks = (ZT_VirtualNetworkConfig *)(buf + sizeof(ZT_VirtualNetworkList));
|
|
|
+ ZT_VirtualNetworkList *nl = (ZT_VirtualNetworkList *) buf; // NOLINT(modernize-use-auto,hicpp-use-auto)
|
|
|
+ nl->networks = (ZT_VirtualNetworkConfig *) (buf + sizeof(ZT_VirtualNetworkList));
|
|
|
|
|
|
nl->networkCount = 0;
|
|
|
- for(Map< uint64_t,SharedPtr<Network> >::const_iterator i(m_networks.begin());i != m_networks.end();++i) // NOLINT(modernize-use-auto,modernize-loop-convert,hicpp-use-auto)
|
|
|
+ for (Map<uint64_t, SharedPtr<Network> >::const_iterator i(m_networks.begin());i != m_networks.end();++i) // NOLINT(modernize-use-auto,modernize-loop-convert,hicpp-use-auto)
|
|
|
i->second->externalConfig(&(nl->networks[nl->networkCount++]));
|
|
|
|
|
|
return nl;
|
|
|
}
|
|
|
|
|
|
-void Node::setNetworkUserPtr(uint64_t nwid,void *ptr)
|
|
|
+void Node::setNetworkUserPtr(uint64_t nwid, void *ptr)
|
|
|
{
|
|
|
SharedPtr<Network> nw(network(nwid));
|
|
|
if (nw)
|
|
|
*(nw->userPtr()) = ptr;
|
|
|
}
|
|
|
|
|
|
-void Node::freeQueryResult(void *qr)
|
|
|
-{
|
|
|
- if (qr)
|
|
|
- ::free(qr);
|
|
|
-}
|
|
|
-
|
|
|
-void Node::setInterfaceAddresses(const ZT_InterfaceAddress *addrs,unsigned int addrCount)
|
|
|
+void Node::setInterfaceAddresses(const ZT_InterfaceAddress *addrs, unsigned int addrCount)
|
|
|
{
|
|
|
Mutex::Lock _l(m_localInterfaceAddresses_m);
|
|
|
m_localInterfaceAddresses.clear();
|
|
|
- for(unsigned int i=0;i<addrCount;++i) {
|
|
|
+ for (unsigned int i = 0;i < addrCount;++i) {
|
|
|
bool dupe = false;
|
|
|
- for(unsigned int j=0;j<i;++j) {
|
|
|
+ for (unsigned int j = 0;j < i;++j) {
|
|
|
if (*(reinterpret_cast<const InetAddress *>(&addrs[j].address)) == *(reinterpret_cast<const InetAddress *>(&addrs[i].address))) {
|
|
|
dupe = true;
|
|
|
break;
|
|
@@ -489,7 +509,7 @@ void Node::setInterfaceAddresses(const ZT_InterfaceAddress *addrs,unsigned int a
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int Node::sendUserMessage(void *tptr,uint64_t dest,uint64_t typeId,const void *data,unsigned int len)
|
|
|
+int Node::sendUserMessage(void *tptr, uint64_t dest, uint64_t typeId, const void *data, unsigned int len)
|
|
|
{
|
|
|
try {
|
|
|
if (RR->identity.address().toInt() != dest) {
|
|
@@ -503,7 +523,7 @@ int Node::sendUserMessage(void *tptr,uint64_t dest,uint64_t typeId,const void *d
|
|
|
*/
|
|
|
return 1;
|
|
|
}
|
|
|
- } catch ( ... ) {}
|
|
|
+ } catch (...) {}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -511,12 +531,12 @@ void Node::setController(void *networkControllerInstance)
|
|
|
{
|
|
|
RR->localNetworkController = reinterpret_cast<NetworkController *>(networkControllerInstance);
|
|
|
if (networkControllerInstance)
|
|
|
- RR->localNetworkController->init(RR->identity,this);
|
|
|
+ RR->localNetworkController->init(RR->identity, this);
|
|
|
}
|
|
|
|
|
|
// Methods used only within the core ----------------------------------------------------------------------------------
|
|
|
|
|
|
-Vector<uint8_t> Node::stateObjectGet(void *const tPtr,ZT_StateObjectType type,const uint64_t id[2])
|
|
|
+Vector<uint8_t> Node::stateObjectGet(void *const tPtr, ZT_StateObjectType type, const uint64_t id[2])
|
|
|
{
|
|
|
Vector<uint8_t> r;
|
|
|
if (m_cb.stateGetFunction) {
|
|
@@ -530,20 +550,20 @@ Vector<uint8_t> Node::stateObjectGet(void *const tPtr,ZT_StateObjectType type,co
|
|
|
id,
|
|
|
&data,
|
|
|
&freeFunc);
|
|
|
- if ((l > 0)&&(data)&&(freeFunc)) {
|
|
|
- r.assign(reinterpret_cast<const uint8_t *>(data),reinterpret_cast<const uint8_t *>(data) + l);
|
|
|
+ if ((l > 0) && (data) && (freeFunc)) {
|
|
|
+ r.assign(reinterpret_cast<const uint8_t *>(data), reinterpret_cast<const uint8_t *>(data) + l);
|
|
|
freeFunc(data);
|
|
|
}
|
|
|
}
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
-bool Node::shouldUsePathForZeroTierTraffic(void *tPtr,const Identity &id,const int64_t localSocket,const InetAddress &remoteAddress)
|
|
|
+bool Node::shouldUsePathForZeroTierTraffic(void *tPtr, const Identity &id, const int64_t localSocket, const InetAddress &remoteAddress)
|
|
|
{
|
|
|
{
|
|
|
RWMutex::RLock l(m_networks_l);
|
|
|
- for(Map< uint64_t,SharedPtr<Network> >::iterator i(m_networks.begin());i != m_networks.end();++i) { // NOLINT(hicpp-use-auto,modernize-use-auto,modernize-loop-convert)
|
|
|
- for (unsigned int k = 0,j = i->second->config().staticIpCount; k < j; ++k) {
|
|
|
+ for (Map<uint64_t, SharedPtr<Network> >::iterator i(m_networks.begin());i != m_networks.end();++i) { // NOLINT(hicpp-use-auto,modernize-use-auto,modernize-loop-convert)
|
|
|
+ for (unsigned int k = 0, j = i->second->config().staticIpCount;k < j;++k) {
|
|
|
if (i->second->config().staticIps[k].containsAddress(remoteAddress))
|
|
|
return false;
|
|
|
}
|
|
@@ -556,7 +576,7 @@ bool Node::shouldUsePathForZeroTierTraffic(void *tPtr,const Identity &id,const i
|
|
|
m_uPtr,
|
|
|
tPtr,
|
|
|
id.address().toInt(),
|
|
|
- (const ZT_Identity *)&id,
|
|
|
+ (const ZT_Identity *) &id,
|
|
|
localSocket,
|
|
|
reinterpret_cast<const struct sockaddr_storage *>(&remoteAddress)) != 0);
|
|
|
}
|
|
@@ -564,7 +584,7 @@ bool Node::shouldUsePathForZeroTierTraffic(void *tPtr,const Identity &id,const i
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool Node::externalPathLookup(void *tPtr,const Identity &id,int family,InetAddress &addr)
|
|
|
+bool Node::externalPathLookup(void *tPtr, const Identity &id, int family, InetAddress &addr)
|
|
|
{
|
|
|
if (m_cb.pathLookupFunction) {
|
|
|
return (m_cb.pathLookupFunction(
|
|
@@ -579,7 +599,7 @@ bool Node::externalPathLookup(void *tPtr,const Identity &id,int family,InetAddre
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-bool Node::localControllerHasAuthorized(const int64_t now,const uint64_t nwid,const Address &addr) const
|
|
|
+bool Node::localControllerHasAuthorized(const int64_t now, const uint64_t nwid, const Address &addr) const
|
|
|
{
|
|
|
m_localControllerAuthorizations_l.lock();
|
|
|
const int64_t *const at = m_localControllerAuthorizations.get(p_LocalControllerAuth(nwid, addr));
|
|
@@ -591,7 +611,7 @@ bool Node::localControllerHasAuthorized(const int64_t now,const uint64_t nwid,co
|
|
|
|
|
|
// Implementation of NetworkController::Sender ------------------------------------------------------------------------
|
|
|
|
|
|
-void Node::ncSendConfig(uint64_t nwid,uint64_t requestPacketId,const Address &destination,const NetworkConfig &nc,bool sendLegacyFormatConfig)
|
|
|
+void Node::ncSendConfig(uint64_t nwid, uint64_t requestPacketId, const Address &destination, const NetworkConfig &nc, bool sendLegacyFormatConfig)
|
|
|
{
|
|
|
m_localControllerAuthorizations_l.lock();
|
|
|
m_localControllerAuthorizations[p_LocalControllerAuth(nwid, destination)] = now();
|
|
@@ -601,7 +621,7 @@ void Node::ncSendConfig(uint64_t nwid,uint64_t requestPacketId,const Address &de
|
|
|
SharedPtr<Network> n(network(nwid));
|
|
|
if (!n)
|
|
|
return;
|
|
|
- n->setConfiguration((void *)0,nc,true);
|
|
|
+ n->setConfiguration((void *) 0, nc, true);
|
|
|
} else {
|
|
|
Dictionary dconf;
|
|
|
if (nc.toDictionary(dconf)) {
|
|
@@ -647,12 +667,12 @@ void Node::ncSendConfig(uint64_t nwid,uint64_t requestPacketId,const Address &de
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Node::ncSendRevocation(const Address &destination,const Revocation &rev)
|
|
|
+void Node::ncSendRevocation(const Address &destination, const Revocation &rev)
|
|
|
{
|
|
|
if (destination == RR->identity.address()) {
|
|
|
SharedPtr<Network> n(network(rev.networkId()));
|
|
|
if (!n) return;
|
|
|
- n->addCredential(nullptr,RR->identity,rev);
|
|
|
+ n->addCredential(nullptr, RR->identity, rev);
|
|
|
} else {
|
|
|
// TODO
|
|
|
/*
|
|
@@ -668,12 +688,12 @@ void Node::ncSendRevocation(const Address &destination,const Revocation &rev)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Node::ncSendError(uint64_t nwid,uint64_t requestPacketId,const Address &destination,NetworkController::ErrorCode errorCode)
|
|
|
+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) {
|
|
|
+ switch (errorCode) {
|
|
|
case NetworkController::NC_ERROR_OBJECT_NOT_FOUND:
|
|
|
case NetworkController::NC_ERROR_INTERNAL_SERVER_ERROR:
|
|
|
n->setNotFound();
|
|
@@ -682,7 +702,8 @@ void Node::ncSendError(uint64_t nwid,uint64_t requestPacketId,const Address &des
|
|
|
n->setAccessDenied();
|
|
|
break;
|
|
|
|
|
|
- default: break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
} else if (requestPacketId) {
|
|
|
// TODO
|
|
@@ -727,38 +748,44 @@ void *ZT_getBuffer()
|
|
|
// wrapped in a SharedPtr<> to be passed into the core.
|
|
|
try {
|
|
|
return _ZT_BUFTOPTR(new ZeroTier::Buf());
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return nullptr; // can only happen on out of memory condition
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-ZT_SDK_API void ZT_freeBuffer(void *b)
|
|
|
+void ZT_freeBuffer(void *b)
|
|
|
{
|
|
|
if (b)
|
|
|
delete _ZT_PTRTOBUF(b);
|
|
|
}
|
|
|
|
|
|
-enum ZT_ResultCode ZT_Node_new(ZT_Node **node,void *uptr,void *tptr,const struct ZT_Node_Callbacks *callbacks,int64_t now)
|
|
|
+void ZT_freeQueryResult(void *qr)
|
|
|
{
|
|
|
- *node = (ZT_Node *)0;
|
|
|
+ if (qr)
|
|
|
+ free(qr);
|
|
|
+}
|
|
|
+
|
|
|
+enum ZT_ResultCode ZT_Node_new(ZT_Node **node, void *uptr, void *tptr, const struct ZT_Node_Callbacks *callbacks, int64_t now)
|
|
|
+{
|
|
|
+ *node = (ZT_Node *) 0;
|
|
|
try {
|
|
|
- *node = reinterpret_cast<ZT_Node *>(new ZeroTier::Node(uptr,tptr,callbacks,now));
|
|
|
+ *node = reinterpret_cast<ZT_Node *>(new ZeroTier::Node(uptr, tptr, callbacks, now));
|
|
|
return ZT_RESULT_OK;
|
|
|
} catch (std::bad_alloc &exc) {
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
|
|
} catch (std::runtime_error &exc) {
|
|
|
return ZT_RESULT_FATAL_ERROR_DATA_STORE_FAILED;
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void ZT_Node_delete(ZT_Node *node,void *tPtr)
|
|
|
+void ZT_Node_delete(ZT_Node *node, void *tPtr)
|
|
|
{
|
|
|
try {
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->shutdown(tPtr);
|
|
|
delete (reinterpret_cast<ZeroTier::Node *>(node));
|
|
|
- } catch ( ... ) {}
|
|
|
+ } catch (...) {}
|
|
|
}
|
|
|
|
|
|
enum ZT_ResultCode ZT_Node_processWirePacket(
|
|
@@ -773,11 +800,11 @@ enum ZT_ResultCode ZT_Node_processWirePacket(
|
|
|
volatile int64_t *nextBackgroundTaskDeadline)
|
|
|
{
|
|
|
try {
|
|
|
- ZeroTier::SharedPtr<ZeroTier::Buf> buf((isZtBuffer) ? _ZT_PTRTOBUF(packetData) : new ZeroTier::Buf(packetData,packetLength & ZT_BUF_MEM_MASK));
|
|
|
- return reinterpret_cast<ZeroTier::Node *>(node)->processWirePacket(tptr,now,localSocket,remoteAddress,buf,packetLength,nextBackgroundTaskDeadline);
|
|
|
+ ZeroTier::SharedPtr<ZeroTier::Buf> buf((isZtBuffer) ? _ZT_PTRTOBUF(packetData) : new ZeroTier::Buf(packetData, packetLength & ZT_BUF_MEM_MASK));
|
|
|
+ return reinterpret_cast<ZeroTier::Node *>(node)->processWirePacket(tptr, now, localSocket, remoteAddress, buf, packetLength, nextBackgroundTaskDeadline);
|
|
|
} catch (std::bad_alloc &exc) {
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_OK; // "OK" since invalid packets are simply dropped, but the system is still up
|
|
|
}
|
|
|
}
|
|
@@ -797,88 +824,88 @@ enum ZT_ResultCode ZT_Node_processVirtualNetworkFrame(
|
|
|
volatile int64_t *nextBackgroundTaskDeadline)
|
|
|
{
|
|
|
try {
|
|
|
- ZeroTier::SharedPtr<ZeroTier::Buf> buf((isZtBuffer) ? _ZT_PTRTOBUF(frameData) : new ZeroTier::Buf(frameData,frameLength & ZT_BUF_MEM_MASK));
|
|
|
- return reinterpret_cast<ZeroTier::Node *>(node)->processVirtualNetworkFrame(tptr,now,nwid,sourceMac,destMac,etherType,vlanId,buf,frameLength,nextBackgroundTaskDeadline);
|
|
|
+ ZeroTier::SharedPtr<ZeroTier::Buf> buf((isZtBuffer) ? _ZT_PTRTOBUF(frameData) : new ZeroTier::Buf(frameData, frameLength & ZT_BUF_MEM_MASK));
|
|
|
+ return reinterpret_cast<ZeroTier::Node *>(node)->processVirtualNetworkFrame(tptr, now, nwid, sourceMac, destMac, etherType, vlanId, buf, frameLength, nextBackgroundTaskDeadline);
|
|
|
} catch (std::bad_alloc &exc) {
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-enum ZT_ResultCode ZT_Node_processBackgroundTasks(ZT_Node *node,void *tptr,int64_t now,volatile int64_t *nextBackgroundTaskDeadline)
|
|
|
+enum ZT_ResultCode ZT_Node_processBackgroundTasks(ZT_Node *node, void *tptr, int64_t now, volatile int64_t *nextBackgroundTaskDeadline)
|
|
|
{
|
|
|
try {
|
|
|
- return reinterpret_cast<ZeroTier::Node *>(node)->processBackgroundTasks(tptr,now,nextBackgroundTaskDeadline);
|
|
|
+ return reinterpret_cast<ZeroTier::Node *>(node)->processBackgroundTasks(tptr, now, nextBackgroundTaskDeadline);
|
|
|
} catch (std::bad_alloc &exc) {
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-enum ZT_ResultCode ZT_Node_join(ZT_Node *node,uint64_t nwid,const ZT_Fingerprint *controllerFingerprint,void *uptr,void *tptr)
|
|
|
+enum ZT_ResultCode ZT_Node_join(ZT_Node *node, uint64_t nwid, const ZT_Fingerprint *controllerFingerprint, void *uptr, void *tptr)
|
|
|
{
|
|
|
try {
|
|
|
- return reinterpret_cast<ZeroTier::Node *>(node)->join(nwid,controllerFingerprint,uptr,tptr);
|
|
|
+ return reinterpret_cast<ZeroTier::Node *>(node)->join(nwid, controllerFingerprint, uptr, tptr);
|
|
|
} catch (std::bad_alloc &exc) {
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-enum ZT_ResultCode ZT_Node_leave(ZT_Node *node,uint64_t nwid,void **uptr,void *tptr)
|
|
|
+enum ZT_ResultCode ZT_Node_leave(ZT_Node *node, uint64_t nwid, void **uptr, void *tptr)
|
|
|
{
|
|
|
try {
|
|
|
- return reinterpret_cast<ZeroTier::Node *>(node)->leave(nwid,uptr,tptr);
|
|
|
+ return reinterpret_cast<ZeroTier::Node *>(node)->leave(nwid, uptr, tptr);
|
|
|
} catch (std::bad_alloc &exc) {
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-enum ZT_ResultCode ZT_Node_multicastSubscribe(ZT_Node *node,void *tptr,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
|
|
+enum ZT_ResultCode ZT_Node_multicastSubscribe(ZT_Node *node, void *tptr, uint64_t nwid, uint64_t multicastGroup, unsigned long multicastAdi)
|
|
|
{
|
|
|
try {
|
|
|
- return reinterpret_cast<ZeroTier::Node *>(node)->multicastSubscribe(tptr,nwid,multicastGroup,multicastAdi);
|
|
|
+ return reinterpret_cast<ZeroTier::Node *>(node)->multicastSubscribe(tptr, nwid, multicastGroup, multicastAdi);
|
|
|
} catch (std::bad_alloc &exc) {
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-enum ZT_ResultCode ZT_Node_multicastUnsubscribe(ZT_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
|
|
+enum ZT_ResultCode ZT_Node_multicastUnsubscribe(ZT_Node *node, uint64_t nwid, uint64_t multicastGroup, unsigned long multicastAdi)
|
|
|
{
|
|
|
try {
|
|
|
- return reinterpret_cast<ZeroTier::Node *>(node)->multicastUnsubscribe(nwid,multicastGroup,multicastAdi);
|
|
|
+ return reinterpret_cast<ZeroTier::Node *>(node)->multicastUnsubscribe(nwid, multicastGroup, multicastAdi);
|
|
|
} catch (std::bad_alloc &exc) {
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-enum ZT_ResultCode ZT_Node_addRoot(ZT_Node *node,void *tptr,const void *rdef,unsigned int rdeflen,uint64_t *address)
|
|
|
+enum ZT_ResultCode ZT_Node_addRoot(ZT_Node *node, void *tptr, const ZT_Identity *id, const ZT_Locator *loc)
|
|
|
{
|
|
|
try {
|
|
|
- return reinterpret_cast<ZeroTier::Node *>(node)->addRoot(tptr,rdef,rdeflen,address);
|
|
|
+ return reinterpret_cast<ZeroTier::Node *>(node)->addRoot(tptr, id, loc);
|
|
|
} catch (std::bad_alloc &exc) {
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-enum ZT_ResultCode ZT_Node_removeRoot(ZT_Node *node,void *tptr,const ZT_Fingerprint *fp)
|
|
|
+enum ZT_ResultCode ZT_Node_removeRoot(ZT_Node *node, void *tptr, const uint64_t address)
|
|
|
{
|
|
|
try {
|
|
|
- return reinterpret_cast<ZeroTier::Node *>(node)->removeRoot(tptr,fp);
|
|
|
+ return reinterpret_cast<ZeroTier::Node *>(node)->removeRoot(tptr, address);
|
|
|
} catch (std::bad_alloc &exc) {
|
|
|
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
|
|
- } catch ( ... ) {
|
|
|
+ } catch (...) {
|
|
|
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
|
|
}
|
|
|
}
|
|
@@ -890,31 +917,31 @@ uint64_t ZT_Node_address(ZT_Node *node)
|
|
|
|
|
|
const ZT_Identity *ZT_Node_identity(ZT_Node *node)
|
|
|
{
|
|
|
- return (const ZT_Identity *)(&(reinterpret_cast<ZeroTier::Node *>(node)->identity()));
|
|
|
+ return (const ZT_Identity *) (&(reinterpret_cast<ZeroTier::Node *>(node)->identity()));
|
|
|
}
|
|
|
|
|
|
-void ZT_Node_status(ZT_Node *node,ZT_NodeStatus *status)
|
|
|
+void ZT_Node_status(ZT_Node *node, ZT_NodeStatus *status)
|
|
|
{
|
|
|
try {
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->status(status);
|
|
|
- } catch ( ... ) {}
|
|
|
+ } catch (...) {}
|
|
|
}
|
|
|
|
|
|
ZT_PeerList *ZT_Node_peers(ZT_Node *node)
|
|
|
{
|
|
|
try {
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->peers();
|
|
|
- } catch ( ... ) {
|
|
|
- return (ZT_PeerList *)0;
|
|
|
+ } catch (...) {
|
|
|
+ return (ZT_PeerList *) 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-ZT_VirtualNetworkConfig *ZT_Node_networkConfig(ZT_Node *node,uint64_t nwid)
|
|
|
+ZT_VirtualNetworkConfig *ZT_Node_networkConfig(ZT_Node *node, uint64_t nwid)
|
|
|
{
|
|
|
try {
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->networkConfig(nwid);
|
|
|
- } catch ( ... ) {
|
|
|
- return (ZT_VirtualNetworkConfig *)0;
|
|
|
+ } catch (...) {
|
|
|
+ return (ZT_VirtualNetworkConfig *) 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -922,49 +949,42 @@ ZT_VirtualNetworkList *ZT_Node_networks(ZT_Node *node)
|
|
|
{
|
|
|
try {
|
|
|
return reinterpret_cast<ZeroTier::Node *>(node)->networks();
|
|
|
- } catch ( ... ) {
|
|
|
- return (ZT_VirtualNetworkList *)0;
|
|
|
+ } catch (...) {
|
|
|
+ return (ZT_VirtualNetworkList *) 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void ZT_Node_setNetworkUserPtr(ZT_Node *node,uint64_t nwid,void *ptr)
|
|
|
-{
|
|
|
- try {
|
|
|
- reinterpret_cast<ZeroTier::Node *>(node)->setNetworkUserPtr(nwid,ptr);
|
|
|
- } catch ( ... ) {}
|
|
|
-}
|
|
|
-
|
|
|
-void ZT_Node_freeQueryResult(ZT_Node *node,void *qr)
|
|
|
+void ZT_Node_setNetworkUserPtr(ZT_Node *node, uint64_t nwid, void *ptr)
|
|
|
{
|
|
|
try {
|
|
|
- reinterpret_cast<ZeroTier::Node *>(node)->freeQueryResult(qr);
|
|
|
- } catch ( ... ) {}
|
|
|
+ reinterpret_cast<ZeroTier::Node *>(node)->setNetworkUserPtr(nwid, ptr);
|
|
|
+ } catch (...) {}
|
|
|
}
|
|
|
|
|
|
-void ZT_Node_setInterfaceAddresses(ZT_Node *node,const ZT_InterfaceAddress *addrs,unsigned int addrCount)
|
|
|
+void ZT_Node_setInterfaceAddresses(ZT_Node *node, const ZT_InterfaceAddress *addrs, unsigned int addrCount)
|
|
|
{
|
|
|
try {
|
|
|
- reinterpret_cast<ZeroTier::Node *>(node)->setInterfaceAddresses(addrs,addrCount);
|
|
|
- } catch ( ... ) {}
|
|
|
+ reinterpret_cast<ZeroTier::Node *>(node)->setInterfaceAddresses(addrs, addrCount);
|
|
|
+ } catch (...) {}
|
|
|
}
|
|
|
|
|
|
-int ZT_Node_sendUserMessage(ZT_Node *node,void *tptr,uint64_t dest,uint64_t typeId,const void *data,unsigned int len)
|
|
|
+int ZT_Node_sendUserMessage(ZT_Node *node, void *tptr, uint64_t dest, uint64_t typeId, const void *data, unsigned int len)
|
|
|
{
|
|
|
try {
|
|
|
- return reinterpret_cast<ZeroTier::Node *>(node)->sendUserMessage(tptr,dest,typeId,data,len);
|
|
|
- } catch ( ... ) {
|
|
|
+ return reinterpret_cast<ZeroTier::Node *>(node)->sendUserMessage(tptr, dest, typeId, data, len);
|
|
|
+ } catch (...) {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void ZT_Node_setController(ZT_Node *node,void *networkControllerInstance)
|
|
|
+void ZT_Node_setController(ZT_Node *node, void *networkControllerInstance)
|
|
|
{
|
|
|
try {
|
|
|
reinterpret_cast<ZeroTier::Node *>(node)->setController(networkControllerInstance);
|
|
|
- } catch ( ... ) {}
|
|
|
+ } catch (...) {}
|
|
|
}
|
|
|
|
|
|
-void ZT_version(int *major,int *minor,int *revision,int *build)
|
|
|
+void ZT_version(int *major, int *minor, int *revision, int *build)
|
|
|
{
|
|
|
if (major)
|
|
|
*major = ZEROTIER_VERSION_MAJOR;
|