mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Factor out RemotePath subclass of Path -- no longer needed, just cruft.
This commit is contained in:
parent
40976c02a4
commit
16bc3e0398
16 changed files with 208 additions and 211 deletions
|
@ -1356,11 +1356,10 @@ void ZT_Node_freeQueryResult(ZT_Node *node,void *qr);
|
||||||
* reject bad, empty, and unusable addresses.
|
* reject bad, empty, and unusable addresses.
|
||||||
*
|
*
|
||||||
* @param addr Local interface address
|
* @param addr Local interface address
|
||||||
* @param metric Local interface metric
|
|
||||||
* @param trust How much do you trust the local network under this interface?
|
* @param trust How much do you trust the local network under this interface?
|
||||||
* @return Boolean: non-zero if address was accepted and added
|
* @return Boolean: non-zero if address was accepted and added
|
||||||
*/
|
*/
|
||||||
int ZT_Node_addLocalInterfaceAddress(ZT_Node *node,const struct sockaddr_storage *addr,int metric, enum ZT_LocalInterfaceAddressTrust trust);
|
int ZT_Node_addLocalInterfaceAddress(ZT_Node *node,const struct sockaddr_storage *addr,enum ZT_LocalInterfaceAddressTrust trust);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear local interface addresses
|
* Clear local interface addresses
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#include "Topology.hpp"
|
#include "Topology.hpp"
|
||||||
#include "Packet.hpp"
|
#include "Packet.hpp"
|
||||||
#include "Switch.hpp"
|
#include "Switch.hpp"
|
||||||
|
#include "Node.hpp"
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include "SHA512.hpp"
|
#include "SHA512.hpp"
|
||||||
#include "World.hpp"
|
#include "World.hpp"
|
||||||
#include "Cluster.hpp"
|
#include "Cluster.hpp"
|
||||||
|
#include "Node.hpp"
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
|
@ -888,7 +889,7 @@ bool IncomingPacket::_doPUSH_DIRECT_PATHS(const RuntimeEnvironment *RR,const Sha
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
const uint64_t now = RR->node->now();
|
const uint64_t now = RR->node->now();
|
||||||
const RemotePath *currentBest = peer->getBestPath(now);
|
const Path *currentBest = peer->getBestPath(now);
|
||||||
|
|
||||||
unsigned int count = at<uint16_t>(ZT_PACKET_IDX_PAYLOAD);
|
unsigned int count = at<uint16_t>(ZT_PACKET_IDX_PAYLOAD);
|
||||||
unsigned int ptr = ZT_PACKET_IDX_PAYLOAD + 2;
|
unsigned int ptr = ZT_PACKET_IDX_PAYLOAD + 2;
|
||||||
|
@ -1036,7 +1037,7 @@ bool IncomingPacket::_doCIRCUIT_TEST(const RuntimeEnvironment *RR,const SharedPt
|
||||||
remainingHopsPtr += ZT_ADDRESS_LENGTH;
|
remainingHopsPtr += ZT_ADDRESS_LENGTH;
|
||||||
SharedPtr<Peer> nhp(RR->topology->getPeer(nextHop[h]));
|
SharedPtr<Peer> nhp(RR->topology->getPeer(nextHop[h]));
|
||||||
if (nhp) {
|
if (nhp) {
|
||||||
RemotePath *const rp = nhp->getBestPath(now);
|
Path *const rp = nhp->getBestPath(now);
|
||||||
if (rp)
|
if (rp)
|
||||||
nextHopBestPathAddress[h] = rp->address();
|
nextHopBestPathAddress[h] = rp->address();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "Peer.hpp"
|
#include "Peer.hpp"
|
||||||
#include "C25519.hpp"
|
#include "C25519.hpp"
|
||||||
#include "CertificateOfMembership.hpp"
|
#include "CertificateOfMembership.hpp"
|
||||||
|
#include "Node.hpp"
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "Packet.hpp"
|
#include "Packet.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "NetworkController.hpp"
|
#include "NetworkController.hpp"
|
||||||
|
#include "Node.hpp"
|
||||||
|
|
||||||
#include "../version.h"
|
#include "../version.h"
|
||||||
|
|
||||||
|
|
|
@ -448,10 +448,10 @@ ZT_PeerList *Node::peers() const
|
||||||
p->latency = pi->second->latency();
|
p->latency = pi->second->latency();
|
||||||
p->role = RR->topology->isRoot(pi->second->identity()) ? ZT_PEER_ROLE_ROOT : ZT_PEER_ROLE_LEAF;
|
p->role = RR->topology->isRoot(pi->second->identity()) ? ZT_PEER_ROLE_ROOT : ZT_PEER_ROLE_LEAF;
|
||||||
|
|
||||||
std::vector<RemotePath> paths(pi->second->paths());
|
std::vector<Path> paths(pi->second->paths());
|
||||||
RemotePath *bestPath = pi->second->getBestPath(_now);
|
Path *bestPath = pi->second->getBestPath(_now);
|
||||||
p->pathCount = 0;
|
p->pathCount = 0;
|
||||||
for(std::vector<RemotePath>::iterator path(paths.begin());path!=paths.end();++path) {
|
for(std::vector<Path>::iterator path(paths.begin());path!=paths.end();++path) {
|
||||||
memcpy(&(p->paths[p->pathCount].address),&(path->address()),sizeof(struct sockaddr_storage));
|
memcpy(&(p->paths[p->pathCount].address),&(path->address()),sizeof(struct sockaddr_storage));
|
||||||
p->paths[p->pathCount].lastSend = path->lastSend();
|
p->paths[p->pathCount].lastSend = path->lastSend();
|
||||||
p->paths[p->pathCount].lastReceive = path->lastReceived();
|
p->paths[p->pathCount].lastReceive = path->lastReceived();
|
||||||
|
@ -499,11 +499,11 @@ void Node::freeQueryResult(void *qr)
|
||||||
::free(qr);
|
::free(qr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Node::addLocalInterfaceAddress(const struct sockaddr_storage *addr,int metric,ZT_LocalInterfaceAddressTrust trust)
|
int Node::addLocalInterfaceAddress(const struct sockaddr_storage *addr,ZT_LocalInterfaceAddressTrust trust)
|
||||||
{
|
{
|
||||||
if (Path::isAddressValidForPath(*(reinterpret_cast<const InetAddress *>(addr)))) {
|
if (Path::isAddressValidForPath(*(reinterpret_cast<const InetAddress *>(addr)))) {
|
||||||
Mutex::Lock _l(_directPaths_m);
|
Mutex::Lock _l(_directPaths_m);
|
||||||
_directPaths.push_back(Path(*(reinterpret_cast<const InetAddress *>(addr)),metric,(Path::Trust)trust));
|
_directPaths.push_back(*(reinterpret_cast<const InetAddress *>(addr)));
|
||||||
std::sort(_directPaths.begin(),_directPaths.end());
|
std::sort(_directPaths.begin(),_directPaths.end());
|
||||||
_directPaths.erase(std::unique(_directPaths.begin(),_directPaths.end()),_directPaths.end());
|
_directPaths.erase(std::unique(_directPaths.begin(),_directPaths.end()),_directPaths.end());
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -900,10 +900,10 @@ void ZT_Node_freeQueryResult(ZT_Node *node,void *qr)
|
||||||
} catch ( ... ) {}
|
} catch ( ... ) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZT_Node_addLocalInterfaceAddress(ZT_Node *node,const struct sockaddr_storage *addr,int metric, enum ZT_LocalInterfaceAddressTrust trust)
|
int ZT_Node_addLocalInterfaceAddress(ZT_Node *node,const struct sockaddr_storage *addr,enum ZT_LocalInterfaceAddressTrust trust)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return reinterpret_cast<ZeroTier::Node *>(node)->addLocalInterfaceAddress(addr,metric,trust);
|
return reinterpret_cast<ZeroTier::Node *>(node)->addLocalInterfaceAddress(addr,trust);
|
||||||
} catch ( ... ) {
|
} catch ( ... ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ public:
|
||||||
ZT_VirtualNetworkConfig *networkConfig(uint64_t nwid) const;
|
ZT_VirtualNetworkConfig *networkConfig(uint64_t nwid) const;
|
||||||
ZT_VirtualNetworkList *networks() const;
|
ZT_VirtualNetworkList *networks() const;
|
||||||
void freeQueryResult(void *qr);
|
void freeQueryResult(void *qr);
|
||||||
int addLocalInterfaceAddress(const struct sockaddr_storage *addr,int metric,ZT_LocalInterfaceAddressTrust trust);
|
int addLocalInterfaceAddress(const struct sockaddr_storage *addr,ZT_LocalInterfaceAddressTrust trust);
|
||||||
void clearLocalInterfaceAddresses();
|
void clearLocalInterfaceAddresses();
|
||||||
void setNetconfMaster(void *networkControllerInstance);
|
void setNetconfMaster(void *networkControllerInstance);
|
||||||
ZT_ResultCode circuitTestBegin(ZT_CircuitTest *test,void (*reportCallback)(ZT_Node *,ZT_CircuitTest *,const ZT_CircuitTestReport *));
|
ZT_ResultCode circuitTestBegin(ZT_CircuitTest *test,void (*reportCallback)(ZT_Node *,ZT_CircuitTest *,const ZT_CircuitTestReport *));
|
||||||
|
@ -207,7 +207,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* @return Potential direct paths to me a.k.a. local interface addresses
|
* @return Potential direct paths to me a.k.a. local interface addresses
|
||||||
*/
|
*/
|
||||||
inline std::vector<Path> directPaths() const
|
inline std::vector<InetAddress> directPaths() const
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_directPaths_m);
|
Mutex::Lock _l(_directPaths_m);
|
||||||
return _directPaths;
|
return _directPaths;
|
||||||
|
@ -285,7 +285,7 @@ private:
|
||||||
std::vector< ZT_CircuitTest * > _circuitTests;
|
std::vector< ZT_CircuitTest * > _circuitTests;
|
||||||
Mutex _circuitTests_m;
|
Mutex _circuitTests_m;
|
||||||
|
|
||||||
std::vector<Path> _directPaths;
|
std::vector<InetAddress> _directPaths;
|
||||||
Mutex _directPaths_m;
|
Mutex _directPaths_m;
|
||||||
|
|
||||||
Mutex _backgroundTasksLock;
|
Mutex _backgroundTasksLock;
|
||||||
|
|
45
node/Path.cpp
Normal file
45
node/Path.cpp
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* 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/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Path.hpp"
|
||||||
|
#include "AntiRecursion.hpp"
|
||||||
|
#include "RuntimeEnvironment.hpp"
|
||||||
|
#include "Node.hpp"
|
||||||
|
|
||||||
|
namespace ZeroTier {
|
||||||
|
|
||||||
|
bool Path::send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now)
|
||||||
|
{
|
||||||
|
if (RR->node->putPacket(_localAddress,address(),data,len)) {
|
||||||
|
sent(now);
|
||||||
|
RR->antiRec->logOutgoingZT(data,len);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ZeroTier
|
117
node/Path.hpp
117
node/Path.hpp
|
@ -28,12 +28,19 @@
|
||||||
#ifndef ZT_PATH_HPP
|
#ifndef ZT_PATH_HPP
|
||||||
#define ZT_PATH_HPP
|
#define ZT_PATH_HPP
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "InetAddress.hpp"
|
#include "InetAddress.hpp"
|
||||||
#include "Utils.hpp"
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
|
class RuntimeEnvironment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for paths
|
* Base class for paths
|
||||||
*
|
*
|
||||||
|
@ -67,19 +74,87 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
Path() :
|
Path() :
|
||||||
|
_lastSend(0),
|
||||||
|
_lastReceived(0),
|
||||||
_addr(),
|
_addr(),
|
||||||
|
_localAddress(),
|
||||||
_ipScope(InetAddress::IP_SCOPE_NONE),
|
_ipScope(InetAddress::IP_SCOPE_NONE),
|
||||||
_trust(TRUST_NORMAL)
|
_trust(TRUST_NORMAL),
|
||||||
|
_flags(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Path(const InetAddress &addr,int metric,Trust trust) :
|
Path(const InetAddress &localAddress,const InetAddress &addr,Trust trust) :
|
||||||
|
_lastSend(0),
|
||||||
|
_lastReceived(0),
|
||||||
_addr(addr),
|
_addr(addr),
|
||||||
|
_localAddress(localAddress),
|
||||||
_ipScope(addr.ipScope()),
|
_ipScope(addr.ipScope()),
|
||||||
_trust(trust)
|
_trust(trust),
|
||||||
|
_flags(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a packet is sent to this remote path
|
||||||
|
*
|
||||||
|
* This is called automatically by Path::send().
|
||||||
|
*
|
||||||
|
* @param t Time of send
|
||||||
|
*/
|
||||||
|
inline void sent(uint64_t t)
|
||||||
|
throw()
|
||||||
|
{
|
||||||
|
_lastSend = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a packet is received from this remote path
|
||||||
|
*
|
||||||
|
* @param t Time of receive
|
||||||
|
*/
|
||||||
|
inline void received(uint64_t t)
|
||||||
|
throw()
|
||||||
|
{
|
||||||
|
_lastReceived = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param now Current time
|
||||||
|
* @return True if this path appears active
|
||||||
|
*/
|
||||||
|
inline bool active(uint64_t now) const
|
||||||
|
throw()
|
||||||
|
{
|
||||||
|
return ((now - _lastReceived) < ZT_PEER_ACTIVITY_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a packet via this path
|
||||||
|
*
|
||||||
|
* @param RR Runtime environment
|
||||||
|
* @param data Packet data
|
||||||
|
* @param len Packet length
|
||||||
|
* @param now Current time
|
||||||
|
* @return True if transport reported success
|
||||||
|
*/
|
||||||
|
bool send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Address of local side of this path or NULL if unspecified
|
||||||
|
*/
|
||||||
|
inline const InetAddress &localAddress() const throw() { return _localAddress; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Time of last send to this path
|
||||||
|
*/
|
||||||
|
inline uint64_t lastSend() const throw() { return _lastSend; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Time of last receive from this path
|
||||||
|
*/
|
||||||
|
inline uint64_t lastReceived() const throw() { return _lastReceived; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Physical address
|
* @return Physical address
|
||||||
*/
|
*/
|
||||||
|
@ -157,10 +232,42 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
template<unsigned int C>
|
||||||
|
inline void serialize(Buffer<C> &b) const
|
||||||
|
{
|
||||||
|
b.append((uint8_t)0); // version
|
||||||
|
b.append((uint64_t)_lastSend);
|
||||||
|
b.append((uint64_t)_lastReceived);
|
||||||
|
_addr.serialize(b);
|
||||||
|
_localAddress.serialize(b);
|
||||||
|
b.append((uint8_t)_trust);
|
||||||
|
b.append((uint16_t)_flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<unsigned int C>
|
||||||
|
inline unsigned int deserialize(const Buffer<C> &b,unsigned int startAt = 0)
|
||||||
|
{
|
||||||
|
unsigned int p = startAt;
|
||||||
|
if (b[p++] != 0)
|
||||||
|
throw std::invalid_argument("invalid serialized Path");
|
||||||
|
_lastSend = b.template at<uint64_t>(p); p += 8;
|
||||||
|
_lastReceived = b.template at<uint64_t>(p); p += 8;
|
||||||
|
p += _addr.deserialize(b,p);
|
||||||
|
p += _localAddress.deserialize(b,p);
|
||||||
|
_ipScope = _addr.ipScope();
|
||||||
|
_trust = (Path::Trust)b[p++];
|
||||||
|
_flags = b.template at<uint16_t>(p); p += 2;
|
||||||
|
return (p - startAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint64_t _lastSend;
|
||||||
|
uint64_t _lastReceived;
|
||||||
InetAddress _addr;
|
InetAddress _addr;
|
||||||
|
InetAddress _localAddress;
|
||||||
InetAddress::IpScope _ipScope; // memoize this since it's a computed value checked often
|
InetAddress::IpScope _ipScope; // memoize this since it's a computed value checked often
|
||||||
Trust _trust;
|
Trust _trust;
|
||||||
|
uint16_t _flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
|
|
@ -169,7 +169,7 @@ void Peer::received(
|
||||||
if (!pathIsConfirmed) {
|
if (!pathIsConfirmed) {
|
||||||
if (verb == Packet::VERB_OK) {
|
if (verb == Packet::VERB_OK) {
|
||||||
|
|
||||||
RemotePath *slot = (RemotePath *)0;
|
Path *slot = (Path *)0;
|
||||||
if (np < ZT_MAX_PEER_NETWORK_PATHS) {
|
if (np < ZT_MAX_PEER_NETWORK_PATHS) {
|
||||||
slot = &(_paths[np++]);
|
slot = &(_paths[np++]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -182,7 +182,7 @@ void Peer::received(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (slot) {
|
if (slot) {
|
||||||
*slot = RemotePath(localAddr,remoteAddr);
|
*slot = Path(localAddr,remoteAddr,Path::TRUST_NORMAL);
|
||||||
slot->received(now);
|
slot->received(now);
|
||||||
_numPaths = np;
|
_numPaths = np;
|
||||||
pathIsConfirmed = true;
|
pathIsConfirmed = true;
|
||||||
|
@ -240,7 +240,7 @@ void Peer::attemptToContactAt(const RuntimeEnvironment *RR,const InetAddress &lo
|
||||||
|
|
||||||
bool Peer::doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now,int inetAddressFamily)
|
bool Peer::doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now,int inetAddressFamily)
|
||||||
{
|
{
|
||||||
RemotePath *p = (RemotePath *)0;
|
Path *p = (Path *)0;
|
||||||
|
|
||||||
Mutex::Lock _l(_lock);
|
Mutex::Lock _l(_lock);
|
||||||
if (inetAddressFamily != 0) {
|
if (inetAddressFamily != 0) {
|
||||||
|
@ -268,7 +268,7 @@ bool Peer::doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now,int inet
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::pushDirectPaths(const RuntimeEnvironment *RR,RemotePath *path,uint64_t now,bool force)
|
void Peer::pushDirectPaths(const RuntimeEnvironment *RR,Path *path,uint64_t now,bool force)
|
||||||
{
|
{
|
||||||
#ifdef ZT_ENABLE_CLUSTER
|
#ifdef ZT_ENABLE_CLUSTER
|
||||||
// Cluster mode disables normal PUSH_DIRECT_PATHS in favor of cluster-based peer redirection
|
// Cluster mode disables normal PUSH_DIRECT_PATHS in favor of cluster-based peer redirection
|
||||||
|
@ -281,7 +281,7 @@ void Peer::pushDirectPaths(const RuntimeEnvironment *RR,RemotePath *path,uint64_
|
||||||
if (((now - _lastDirectPathPushSent) >= ZT_DIRECT_PATH_PUSH_INTERVAL)||(force)) {
|
if (((now - _lastDirectPathPushSent) >= ZT_DIRECT_PATH_PUSH_INTERVAL)||(force)) {
|
||||||
_lastDirectPathPushSent = now;
|
_lastDirectPathPushSent = now;
|
||||||
|
|
||||||
std::vector<Path> dps(RR->node->directPaths());
|
std::vector<InetAddress> dps(RR->node->directPaths());
|
||||||
if (dps.empty())
|
if (dps.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -291,13 +291,13 @@ void Peer::pushDirectPaths(const RuntimeEnvironment *RR,RemotePath *path,uint64_
|
||||||
for(std::vector<Path>::const_iterator p(dps.begin());p!=dps.end();++p) {
|
for(std::vector<Path>::const_iterator p(dps.begin());p!=dps.end();++p) {
|
||||||
if (ps.length() > 0)
|
if (ps.length() > 0)
|
||||||
ps.push_back(',');
|
ps.push_back(',');
|
||||||
ps.append(p->address().toString());
|
ps.append(p->toString());
|
||||||
}
|
}
|
||||||
TRACE("pushing %u direct paths to %s: %s",(unsigned int)dps.size(),_id.address().toString().c_str(),ps.c_str());
|
TRACE("pushing %u direct paths to %s: %s",(unsigned int)dps.size(),_id.address().toString().c_str(),ps.c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::vector<Path>::const_iterator p(dps.begin());
|
std::vector<InetAddress>::const_iterator p(dps.begin());
|
||||||
while (p != dps.end()) {
|
while (p != dps.end()) {
|
||||||
Packet outp(_id.address(),RR->identity.address(),Packet::VERB_PUSH_DIRECT_PATHS);
|
Packet outp(_id.address(),RR->identity.address(),Packet::VERB_PUSH_DIRECT_PATHS);
|
||||||
outp.addSize(2); // leave room for count
|
outp.addSize(2); // leave room for count
|
||||||
|
@ -305,7 +305,7 @@ void Peer::pushDirectPaths(const RuntimeEnvironment *RR,RemotePath *path,uint64_
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
while ((p != dps.end())&&((outp.size() + 24) < ZT_PROTO_MAX_PACKET_LENGTH)) {
|
while ((p != dps.end())&&((outp.size() + 24) < ZT_PROTO_MAX_PACKET_LENGTH)) {
|
||||||
uint8_t addressType = 4;
|
uint8_t addressType = 4;
|
||||||
switch(p->address().ss_family) {
|
switch(p->ss_family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
break;
|
break;
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
|
@ -317,6 +317,7 @@ void Peer::pushDirectPaths(const RuntimeEnvironment *RR,RemotePath *path,uint64_
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t flags = 0;
|
uint8_t flags = 0;
|
||||||
|
/* TODO: path trust is not implemented yet
|
||||||
switch(p->trust()) {
|
switch(p->trust()) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -327,13 +328,14 @@ void Peer::pushDirectPaths(const RuntimeEnvironment *RR,RemotePath *path,uint64_
|
||||||
flags |= (0x04 | 0x08); // no encryption, no authentication (redundant but go ahead and set both)
|
flags |= (0x04 | 0x08); // no encryption, no authentication (redundant but go ahead and set both)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
outp.append(flags);
|
outp.append(flags);
|
||||||
outp.append((uint16_t)0); // no extensions
|
outp.append((uint16_t)0); // no extensions
|
||||||
outp.append(addressType);
|
outp.append(addressType);
|
||||||
outp.append((uint8_t)((addressType == 4) ? 6 : 18));
|
outp.append((uint8_t)((addressType == 4) ? 6 : 18));
|
||||||
outp.append(p->address().rawIpData(),((addressType == 4) ? 4 : 16));
|
outp.append(p->rawIpData(),((addressType == 4) ? 4 : 16));
|
||||||
outp.append((uint16_t)p->address().port());
|
outp.append((uint16_t)p->port());
|
||||||
|
|
||||||
++count;
|
++count;
|
||||||
++p;
|
++p;
|
||||||
|
@ -506,7 +508,7 @@ struct _SortPathsByQuality
|
||||||
{
|
{
|
||||||
uint64_t _now;
|
uint64_t _now;
|
||||||
_SortPathsByQuality(const uint64_t now) : _now(now) {}
|
_SortPathsByQuality(const uint64_t now) : _now(now) {}
|
||||||
inline bool operator()(const RemotePath &a,const RemotePath &b) const
|
inline bool operator()(const Path &a,const Path &b) const
|
||||||
{
|
{
|
||||||
const uint64_t qa = (
|
const uint64_t qa = (
|
||||||
((uint64_t)a.active(_now) << 63) |
|
((uint64_t)a.active(_now) << 63) |
|
||||||
|
@ -526,7 +528,7 @@ void Peer::_sortPaths(const uint64_t now)
|
||||||
std::sort(&(_paths[0]),&(_paths[_numPaths]),_SortPathsByQuality(now));
|
std::sort(&(_paths[0]),&(_paths[_numPaths]),_SortPathsByQuality(now));
|
||||||
}
|
}
|
||||||
|
|
||||||
RemotePath *Peer::_getBestPath(const uint64_t now)
|
Path *Peer::_getBestPath(const uint64_t now)
|
||||||
{
|
{
|
||||||
// assumes _lock is locked
|
// assumes _lock is locked
|
||||||
if ((now - _lastPathSort) >= ZT_PEER_PATH_SORT_INTERVAL)
|
if ((now - _lastPathSort) >= ZT_PEER_PATH_SORT_INTERVAL)
|
||||||
|
@ -538,10 +540,10 @@ RemotePath *Peer::_getBestPath(const uint64_t now)
|
||||||
if (_paths[0].active(now))
|
if (_paths[0].active(now))
|
||||||
return &(_paths[0]);
|
return &(_paths[0]);
|
||||||
}
|
}
|
||||||
return (RemotePath *)0;
|
return (Path *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemotePath *Peer::_getBestPath(const uint64_t now,int inetAddressFamily)
|
Path *Peer::_getBestPath(const uint64_t now,int inetAddressFamily)
|
||||||
{
|
{
|
||||||
// assumes _lock is locked
|
// assumes _lock is locked
|
||||||
if ((now - _lastPathSort) >= ZT_PEER_PATH_SORT_INTERVAL)
|
if ((now - _lastPathSort) >= ZT_PEER_PATH_SORT_INTERVAL)
|
||||||
|
@ -553,7 +555,7 @@ RemotePath *Peer::_getBestPath(const uint64_t now,int inetAddressFamily)
|
||||||
}
|
}
|
||||||
_sortPaths(now);
|
_sortPaths(now);
|
||||||
}
|
}
|
||||||
return (RemotePath *)0;
|
return (Path *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
|
|
||||||
#include "RuntimeEnvironment.hpp"
|
#include "RuntimeEnvironment.hpp"
|
||||||
#include "CertificateOfMembership.hpp"
|
#include "CertificateOfMembership.hpp"
|
||||||
#include "RemotePath.hpp"
|
#include "Path.hpp"
|
||||||
#include "Address.hpp"
|
#include "Address.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
#include "Identity.hpp"
|
#include "Identity.hpp"
|
||||||
|
@ -135,7 +135,7 @@ public:
|
||||||
* @param now Current time
|
* @param now Current time
|
||||||
* @return Best path or NULL if there are no active direct paths
|
* @return Best path or NULL if there are no active direct paths
|
||||||
*/
|
*/
|
||||||
inline RemotePath *getBestPath(uint64_t now)
|
inline Path *getBestPath(uint64_t now)
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_lock);
|
Mutex::Lock _l(_lock);
|
||||||
return _getBestPath(now);
|
return _getBestPath(now);
|
||||||
|
@ -150,14 +150,14 @@ public:
|
||||||
* @param now Current time
|
* @param now Current time
|
||||||
* @return Path used on success or NULL on failure
|
* @return Path used on success or NULL on failure
|
||||||
*/
|
*/
|
||||||
inline RemotePath *send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now)
|
inline Path *send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now)
|
||||||
{
|
{
|
||||||
RemotePath *bestPath = getBestPath(now);
|
Path *bestPath = getBestPath(now);
|
||||||
if (bestPath) {
|
if (bestPath) {
|
||||||
if (bestPath->send(RR,data,len,now))
|
if (bestPath->send(RR,data,len,now))
|
||||||
return bestPath;
|
return bestPath;
|
||||||
}
|
}
|
||||||
return (RemotePath *)0;
|
return (Path *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -191,14 +191,14 @@ public:
|
||||||
* @param now Current time
|
* @param now Current time
|
||||||
* @param force If true, push regardless of rate limit
|
* @param force If true, push regardless of rate limit
|
||||||
*/
|
*/
|
||||||
void pushDirectPaths(const RuntimeEnvironment *RR,RemotePath *path,uint64_t now,bool force);
|
void pushDirectPaths(const RuntimeEnvironment *RR,Path *path,uint64_t now,bool force);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return All known direct paths to this peer
|
* @return All known direct paths to this peer
|
||||||
*/
|
*/
|
||||||
inline std::vector<RemotePath> paths() const
|
inline std::vector<Path> paths() const
|
||||||
{
|
{
|
||||||
std::vector<RemotePath> pp;
|
std::vector<Path> pp;
|
||||||
Mutex::Lock _l(_lock);
|
Mutex::Lock _l(_lock);
|
||||||
for(unsigned int p=0,np=_numPaths;p<np;++p)
|
for(unsigned int p=0,np=_numPaths;p<np;++p)
|
||||||
pp.push_back(_paths[p]);
|
pp.push_back(_paths[p]);
|
||||||
|
@ -533,7 +533,7 @@ public:
|
||||||
p += np->_paths[np->_numPaths++].deserialize(b,p);
|
p += np->_paths[np->_numPaths++].deserialize(b,p);
|
||||||
} else {
|
} else {
|
||||||
// Skip any paths beyond max, but still read stream
|
// Skip any paths beyond max, but still read stream
|
||||||
RemotePath foo;
|
Path foo;
|
||||||
p += foo.deserialize(b,p);
|
p += foo.deserialize(b,p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -557,8 +557,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _sortPaths(const uint64_t now);
|
void _sortPaths(const uint64_t now);
|
||||||
RemotePath *_getBestPath(const uint64_t now);
|
Path *_getBestPath(const uint64_t now);
|
||||||
RemotePath *_getBestPath(const uint64_t now,int inetAddressFamily);
|
Path *_getBestPath(const uint64_t now,int inetAddressFamily);
|
||||||
|
|
||||||
unsigned char _key[ZT_PEER_SECRET_KEY_LENGTH]; // computed with key agreement, not serialized
|
unsigned char _key[ZT_PEER_SECRET_KEY_LENGTH]; // computed with key agreement, not serialized
|
||||||
|
|
||||||
|
@ -575,7 +575,7 @@ private:
|
||||||
uint16_t _vMinor;
|
uint16_t _vMinor;
|
||||||
uint16_t _vRevision;
|
uint16_t _vRevision;
|
||||||
Identity _id;
|
Identity _id;
|
||||||
RemotePath _paths[ZT_MAX_PEER_NETWORK_PATHS];
|
Path _paths[ZT_MAX_PEER_NETWORK_PATHS];
|
||||||
unsigned int _numPaths;
|
unsigned int _numPaths;
|
||||||
unsigned int _latency;
|
unsigned int _latency;
|
||||||
|
|
||||||
|
|
|
@ -1,161 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZT_REMOTEPATH_HPP
|
|
||||||
#define ZT_REMOTEPATH_HPP
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "Path.hpp"
|
|
||||||
#include "Node.hpp"
|
|
||||||
#include "AntiRecursion.hpp"
|
|
||||||
#include "RuntimeEnvironment.hpp"
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Path to a remote peer
|
|
||||||
*
|
|
||||||
* This extends Path to include status information about path activity.
|
|
||||||
*/
|
|
||||||
class RemotePath : public Path
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RemotePath() :
|
|
||||||
Path(),
|
|
||||||
_lastSend(0),
|
|
||||||
_lastReceived(0),
|
|
||||||
_localAddress(),
|
|
||||||
_flags(0) {}
|
|
||||||
|
|
||||||
RemotePath(const InetAddress &localAddress,const InetAddress &addr) :
|
|
||||||
Path(addr,0,TRUST_NORMAL),
|
|
||||||
_lastSend(0),
|
|
||||||
_lastReceived(0),
|
|
||||||
_localAddress(localAddress),
|
|
||||||
_flags(0) {}
|
|
||||||
|
|
||||||
inline const InetAddress &localAddress() const throw() { return _localAddress; }
|
|
||||||
|
|
||||||
inline uint64_t lastSend() const throw() { return _lastSend; }
|
|
||||||
inline uint64_t lastReceived() const throw() { return _lastReceived; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a packet is sent to this remote path
|
|
||||||
*
|
|
||||||
* This is called automatically by RemotePath::send().
|
|
||||||
*
|
|
||||||
* @param t Time of send
|
|
||||||
*/
|
|
||||||
inline void sent(uint64_t t)
|
|
||||||
throw()
|
|
||||||
{
|
|
||||||
_lastSend = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a packet is received from this remote path
|
|
||||||
*
|
|
||||||
* @param t Time of receive
|
|
||||||
*/
|
|
||||||
inline void received(uint64_t t)
|
|
||||||
throw()
|
|
||||||
{
|
|
||||||
_lastReceived = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param now Current time
|
|
||||||
* @return True if this path appears active
|
|
||||||
*/
|
|
||||||
inline bool active(uint64_t now) const
|
|
||||||
throw()
|
|
||||||
{
|
|
||||||
return ((now - _lastReceived) < ZT_PEER_ACTIVITY_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a packet via this path
|
|
||||||
*
|
|
||||||
* @param RR Runtime environment
|
|
||||||
* @param data Packet data
|
|
||||||
* @param len Packet length
|
|
||||||
* @param now Current time
|
|
||||||
* @return True if transport reported success
|
|
||||||
*/
|
|
||||||
inline bool send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now)
|
|
||||||
{
|
|
||||||
if (RR->node->putPacket(_localAddress,address(),data,len)) {
|
|
||||||
sent(now);
|
|
||||||
RR->antiRec->logOutgoingZT(data,len);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<unsigned int C>
|
|
||||||
inline void serialize(Buffer<C> &b) const
|
|
||||||
{
|
|
||||||
b.append((uint8_t)1); // version
|
|
||||||
_addr.serialize(b);
|
|
||||||
b.append((uint8_t)_trust);
|
|
||||||
b.append((uint64_t)_lastSend);
|
|
||||||
b.append((uint64_t)_lastReceived);
|
|
||||||
_localAddress.serialize(b);
|
|
||||||
b.append((uint16_t)_flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<unsigned int C>
|
|
||||||
inline unsigned int deserialize(const Buffer<C> &b,unsigned int startAt = 0)
|
|
||||||
{
|
|
||||||
unsigned int p = startAt;
|
|
||||||
if (b[p++] != 1)
|
|
||||||
throw std::invalid_argument("invalid serialized RemotePath");
|
|
||||||
p += _addr.deserialize(b,p);
|
|
||||||
_ipScope = _addr.ipScope();
|
|
||||||
_trust = (Path::Trust)b[p++];
|
|
||||||
_lastSend = b.template at<uint64_t>(p); p += 8;
|
|
||||||
_lastReceived = b.template at<uint64_t>(p); p += 8;
|
|
||||||
p += _localAddress.deserialize(b,p);
|
|
||||||
_flags = b.template at<uint16_t>(p); p += 2;
|
|
||||||
return (p - startAt);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
uint64_t _lastSend;
|
|
||||||
uint64_t _lastReceived;
|
|
||||||
InetAddress _localAddress;
|
|
||||||
uint16_t _flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -125,7 +125,7 @@ void SelfAwareness::iam(const Address &reporter,const InetAddress &reporterPhysi
|
||||||
// they are still considered alive so that we will re-establish direct links.
|
// they are still considered alive so that we will re-establish direct links.
|
||||||
SharedPtr<Peer> r(RR->topology->getBestRoot());
|
SharedPtr<Peer> r(RR->topology->getBestRoot());
|
||||||
if (r) {
|
if (r) {
|
||||||
RemotePath *rp = r->getBestPath(now);
|
Path *rp = r->getBestPath(now);
|
||||||
if (rp) {
|
if (rp) {
|
||||||
for(std::vector< SharedPtr<Peer> >::const_iterator p(rset.peersReset.begin());p!=rset.peersReset.end();++p) {
|
for(std::vector< SharedPtr<Peer> >::const_iterator p(rset.peersReset.begin());p!=rset.peersReset.end();++p) {
|
||||||
if ((*p)->alive(now)) {
|
if ((*p)->alive(now)) {
|
||||||
|
|
|
@ -736,7 +736,7 @@ bool Switch::_trySend(const Packet &packet,bool encrypt,uint64_t nwid)
|
||||||
return false; // sanity check: unconfigured network? why are we trying to talk to it?
|
return false; // sanity check: unconfigured network? why are we trying to talk to it?
|
||||||
}
|
}
|
||||||
|
|
||||||
RemotePath *viaPath = peer->getBestPath(now);
|
Path *viaPath = peer->getBestPath(now);
|
||||||
SharedPtr<Peer> relay;
|
SharedPtr<Peer> relay;
|
||||||
if (!viaPath) {
|
if (!viaPath) {
|
||||||
// See if this network has a preferred relay (if packet has an associated network)
|
// See if this network has a preferred relay (if packet has an associated network)
|
||||||
|
|
|
@ -15,6 +15,7 @@ OBJS=\
|
||||||
node/Node.o \
|
node/Node.o \
|
||||||
node/OutboundMulticast.o \
|
node/OutboundMulticast.o \
|
||||||
node/Packet.o \
|
node/Packet.o \
|
||||||
|
node/Path.o \
|
||||||
node/Peer.o \
|
node/Peer.o \
|
||||||
node/Poly1305.o \
|
node/Poly1305.o \
|
||||||
node/Salsa20.o \
|
node/Salsa20.o \
|
||||||
|
|
|
@ -731,7 +731,7 @@ public:
|
||||||
#ifdef ZT_USE_MINIUPNPC
|
#ifdef ZT_USE_MINIUPNPC
|
||||||
std::vector<InetAddress> upnpAddresses(_upnpClient->get());
|
std::vector<InetAddress> upnpAddresses(_upnpClient->get());
|
||||||
for(std::vector<InetAddress>::const_iterator ext(upnpAddresses.begin());ext!=upnpAddresses.end();++ext)
|
for(std::vector<InetAddress>::const_iterator ext(upnpAddresses.begin());ext!=upnpAddresses.end();++ext)
|
||||||
_node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&(*ext)),0,ZT_LOCAL_INTERFACE_ADDRESS_TRUST_NORMAL);
|
_node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&(*ext)),ZT_LOCAL_INTERFACE_ADDRESS_TRUST_NORMAL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct ifaddrs *ifatbl = (struct ifaddrs *)0;
|
struct ifaddrs *ifatbl = (struct ifaddrs *)0;
|
||||||
|
@ -749,7 +749,7 @@ public:
|
||||||
if (!isZT) {
|
if (!isZT) {
|
||||||
InetAddress ip(ifa->ifa_addr);
|
InetAddress ip(ifa->ifa_addr);
|
||||||
ip.setPort(_port);
|
ip.setPort(_port);
|
||||||
_node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&ip),0,ZT_LOCAL_INTERFACE_ADDRESS_TRUST_NORMAL);
|
_node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&ip),ZT_LOCAL_INTERFACE_ADDRESS_TRUST_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ifa = ifa->ifa_next;
|
ifa = ifa->ifa_next;
|
||||||
|
|
Loading…
Add table
Reference in a new issue