|
@@ -40,7 +40,7 @@
|
|
#include "../include/ZeroTierOne.h"
|
|
#include "../include/ZeroTierOne.h"
|
|
|
|
|
|
#include "RuntimeEnvironment.hpp"
|
|
#include "RuntimeEnvironment.hpp"
|
|
-#include "Path.hpp"
|
|
|
|
|
|
+#include "RemotePath.hpp"
|
|
#include "Address.hpp"
|
|
#include "Address.hpp"
|
|
#include "Utils.hpp"
|
|
#include "Utils.hpp"
|
|
#include "Identity.hpp"
|
|
#include "Identity.hpp"
|
|
@@ -53,11 +53,7 @@
|
|
namespace ZeroTier {
|
|
namespace ZeroTier {
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Peer on P2P Network
|
|
|
|
- *
|
|
|
|
- * This struture is not locked, volatile, and memcpy-able. NonCopyable
|
|
|
|
- * semantics are just there to prevent bugs, not because it isn't safe
|
|
|
|
- * to copy.
|
|
|
|
|
|
+ * Peer on P2P Network (virtual layer 1)
|
|
*/
|
|
*/
|
|
class Peer : NonCopyable
|
|
class Peer : NonCopyable
|
|
{
|
|
{
|
|
@@ -130,9 +126,9 @@ public:
|
|
* @param now Current time
|
|
* @param now Current time
|
|
* @return Best path or NULL if there are no active (or fixed) direct paths
|
|
* @return Best path or NULL if there are no active (or fixed) direct paths
|
|
*/
|
|
*/
|
|
- inline Path *getBestPath(uint64_t now)
|
|
|
|
|
|
+ inline RemotePath *getBestPath(uint64_t now)
|
|
{
|
|
{
|
|
- Path *bestPath = (Path *)0;
|
|
|
|
|
|
+ RemotePath *bestPath = (RemotePath *)0;
|
|
uint64_t lrMax = 0;
|
|
uint64_t lrMax = 0;
|
|
for(unsigned int p=0,np=_numPaths;p<np;++p) {
|
|
for(unsigned int p=0,np=_numPaths;p<np;++p) {
|
|
if ((_paths[p].active(now))&&(_paths[p].lastReceived() >= lrMax)) {
|
|
if ((_paths[p].active(now))&&(_paths[p].lastReceived() >= lrMax)) {
|
|
@@ -152,14 +148,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 Path *send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now)
|
|
|
|
|
|
+ inline RemotePath *send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now)
|
|
{
|
|
{
|
|
- Path *bestPath = getBestPath(now);
|
|
|
|
|
|
+ RemotePath *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 (Path *)0;
|
|
|
|
|
|
+ return (RemotePath *)0;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -182,12 +178,21 @@ public:
|
|
*/
|
|
*/
|
|
void doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now);
|
|
void doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now);
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Push direct paths (if within rate limit)
|
|
|
|
+ *
|
|
|
|
+ * @param dps Direct paths to me to push to this peer
|
|
|
|
+ * @param now Current time
|
|
|
|
+ * @param force If true, force regardless of when we pushed direct paths last
|
|
|
|
+ */
|
|
|
|
+ void pushDirectPaths(const std::vector<InetAddress> &dps,uint64_t now,bool force);
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @return All known direct paths to this peer
|
|
* @return All known direct paths to this peer
|
|
*/
|
|
*/
|
|
- inline std::vector<Path> paths() const
|
|
|
|
|
|
+ inline std::vector<RemotePath> paths() const
|
|
{
|
|
{
|
|
- std::vector<Path> pp;
|
|
|
|
|
|
+ std::vector<RemotePath> pp;
|
|
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]);
|
|
return pp;
|
|
return pp;
|
|
@@ -295,7 +300,7 @@ public:
|
|
*
|
|
*
|
|
* @param p New path to add
|
|
* @param p New path to add
|
|
*/
|
|
*/
|
|
- void addPath(const Path &newp);
|
|
|
|
|
|
+ void addPath(const RemotePath &newp);
|
|
|
|
|
|
/**
|
|
/**
|
|
* Clear paths
|
|
* Clear paths
|
|
@@ -412,12 +417,13 @@ private:
|
|
uint64_t _lastMulticastFrame;
|
|
uint64_t _lastMulticastFrame;
|
|
uint64_t _lastAnnouncedTo;
|
|
uint64_t _lastAnnouncedTo;
|
|
uint64_t _lastPathConfirmationSent;
|
|
uint64_t _lastPathConfirmationSent;
|
|
|
|
+ uint64_t _lastDirectPathPush;
|
|
uint16_t _vProto;
|
|
uint16_t _vProto;
|
|
uint16_t _vMajor;
|
|
uint16_t _vMajor;
|
|
uint16_t _vMinor;
|
|
uint16_t _vMinor;
|
|
uint16_t _vRevision;
|
|
uint16_t _vRevision;
|
|
Identity _id;
|
|
Identity _id;
|
|
- Path _paths[ZT1_MAX_PEER_NETWORK_PATHS];
|
|
|
|
|
|
+ RemotePath _paths[ZT1_MAX_PEER_NETWORK_PATHS];
|
|
unsigned int _numPaths;
|
|
unsigned int _numPaths;
|
|
unsigned int _latency;
|
|
unsigned int _latency;
|
|
|
|
|