|
@@ -152,7 +152,7 @@ public:
|
|
*/
|
|
*/
|
|
inline Path *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)
|
|
{
|
|
{
|
|
- Path *bestPath = getBestPath(now);
|
|
|
|
|
|
+ Path *const 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;
|
|
@@ -185,7 +185,7 @@ public:
|
|
bool doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now,int inetAddressFamily);
|
|
bool doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now,int inetAddressFamily);
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Push direct paths if we haven't done so in [rate limit] milliseconds
|
|
|
|
|
|
+ * Push direct paths back to self if we haven't done so in the configured timeout
|
|
*
|
|
*
|
|
* @param RR Runtime environment
|
|
* @param RR Runtime environment
|
|
* @param path Remote path to use to send the push
|
|
* @param path Remote path to use to send the push
|
|
@@ -232,7 +232,7 @@ public:
|
|
inline uint64_t lastAnnouncedTo() const throw() { return _lastAnnouncedTo; }
|
|
inline uint64_t lastAnnouncedTo() const throw() { return _lastAnnouncedTo; }
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @return True if this peer is actively sending real network frames
|
|
|
|
|
|
+ * @return True if this peer has sent us real network traffic recently
|
|
*/
|
|
*/
|
|
inline uint64_t activelyTransferringFrames(uint64_t now) const throw() { return ((now - lastFrame()) < ZT_PEER_ACTIVITY_TIMEOUT); }
|
|
inline uint64_t activelyTransferringFrames(uint64_t now) const throw() { return ((now - lastFrame()) < ZT_PEER_ACTIVITY_TIMEOUT); }
|
|
|
|
|
|
@@ -283,7 +283,7 @@ public:
|
|
inline bool hasActiveDirectPath(uint64_t now) const
|
|
inline bool hasActiveDirectPath(uint64_t now) const
|
|
{
|
|
{
|
|
Mutex::Lock _l(_lock);
|
|
Mutex::Lock _l(_lock);
|
|
- for(unsigned int p=0,np=_numPaths;p<np;++p) {
|
|
|
|
|
|
+ for(unsigned int p=0;p<_numPaths;++p) {
|
|
if (_paths[p].active(now))
|
|
if (_paths[p].active(now))
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -306,6 +306,21 @@ public:
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param now Current time
|
|
|
|
+ * @param addr Remote address
|
|
|
|
+ * @return True if peer currently has an active direct path to addr
|
|
|
|
+ */
|
|
|
|
+ inline bool hasActivePathTo(uint64_t now,const InetAddress &addr) const
|
|
|
|
+ {
|
|
|
|
+ Mutex::Lock _l(_lock);
|
|
|
|
+ for(unsigned int p=0;p<_numPaths;++p) {
|
|
|
|
+ if ((_paths[p].active(now))&&(_paths[p].address() == addr))
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Reset paths within a given scope
|
|
* Reset paths within a given scope
|
|
*
|
|
*
|
|
@@ -341,6 +356,7 @@ public:
|
|
inline unsigned int remoteVersionMajor() const throw() { return _vMajor; }
|
|
inline unsigned int remoteVersionMajor() const throw() { return _vMajor; }
|
|
inline unsigned int remoteVersionMinor() const throw() { return _vMinor; }
|
|
inline unsigned int remoteVersionMinor() const throw() { return _vMinor; }
|
|
inline unsigned int remoteVersionRevision() const throw() { return _vRevision; }
|
|
inline unsigned int remoteVersionRevision() const throw() { return _vRevision; }
|
|
|
|
+
|
|
inline bool remoteVersionKnown() const throw() { return ((_vMajor > 0)||(_vMinor > 0)||(_vRevision > 0)); }
|
|
inline bool remoteVersionKnown() const throw() { return ((_vMajor > 0)||(_vMinor > 0)||(_vRevision > 0)); }
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -386,25 +402,6 @@ public:
|
|
*/
|
|
*/
|
|
void clean(const RuntimeEnvironment *RR,uint64_t now);
|
|
void clean(const RuntimeEnvironment *RR,uint64_t now);
|
|
|
|
|
|
- /**
|
|
|
|
- * Remove all paths with this remote address
|
|
|
|
- *
|
|
|
|
- * @param addr Remote address to remove
|
|
|
|
- */
|
|
|
|
- inline void removePathByAddress(const InetAddress &addr)
|
|
|
|
- {
|
|
|
|
- Mutex::Lock _l(_lock);
|
|
|
|
- unsigned int np = _numPaths;
|
|
|
|
- unsigned int x = 0;
|
|
|
|
- unsigned int y = 0;
|
|
|
|
- while (x < np) {
|
|
|
|
- if (_paths[x].address() != addr)
|
|
|
|
- _paths[y++] = _paths[x];
|
|
|
|
- ++x;
|
|
|
|
- }
|
|
|
|
- _numPaths = y;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Update direct path push stats and return true if we should respond
|
|
* Update direct path push stats and return true if we should respond
|
|
*
|
|
*
|
|
@@ -454,7 +451,7 @@ public:
|
|
const unsigned int recSizePos = b.size();
|
|
const unsigned int recSizePos = b.size();
|
|
b.addSize(4); // space for uint32_t field length
|
|
b.addSize(4); // space for uint32_t field length
|
|
|
|
|
|
- b.append((uint16_t)0); // version of serialized Peer data
|
|
|
|
|
|
+ b.append((uint16_t)1); // version of serialized Peer data
|
|
|
|
|
|
_id.serialize(b,false);
|
|
_id.serialize(b,false);
|
|
|
|
|
|
@@ -463,7 +460,6 @@ public:
|
|
b.append((uint64_t)_lastUnicastFrame);
|
|
b.append((uint64_t)_lastUnicastFrame);
|
|
b.append((uint64_t)_lastMulticastFrame);
|
|
b.append((uint64_t)_lastMulticastFrame);
|
|
b.append((uint64_t)_lastAnnouncedTo);
|
|
b.append((uint64_t)_lastAnnouncedTo);
|
|
- b.append((uint64_t)_lastPathConfirmationSent);
|
|
|
|
b.append((uint64_t)_lastDirectPathPushSent);
|
|
b.append((uint64_t)_lastDirectPathPushSent);
|
|
b.append((uint64_t)_lastDirectPathPushReceive);
|
|
b.append((uint64_t)_lastDirectPathPushReceive);
|
|
b.append((uint64_t)_lastPathSort);
|
|
b.append((uint64_t)_lastPathSort);
|
|
@@ -518,7 +514,7 @@ public:
|
|
const unsigned int recSize = b.template at<uint32_t>(p); p += 4;
|
|
const unsigned int recSize = b.template at<uint32_t>(p); p += 4;
|
|
if ((p + recSize) > b.size())
|
|
if ((p + recSize) > b.size())
|
|
return SharedPtr<Peer>(); // size invalid
|
|
return SharedPtr<Peer>(); // size invalid
|
|
- if (b.template at<uint16_t>(p) != 0)
|
|
|
|
|
|
+ if (b.template at<uint16_t>(p) != 1)
|
|
return SharedPtr<Peer>(); // version mismatch
|
|
return SharedPtr<Peer>(); // version mismatch
|
|
p += 2;
|
|
p += 2;
|
|
|
|
|
|
@@ -534,7 +530,6 @@ public:
|
|
np->_lastUnicastFrame = b.template at<uint64_t>(p); p += 8;
|
|
np->_lastUnicastFrame = b.template at<uint64_t>(p); p += 8;
|
|
np->_lastMulticastFrame = b.template at<uint64_t>(p); p += 8;
|
|
np->_lastMulticastFrame = b.template at<uint64_t>(p); p += 8;
|
|
np->_lastAnnouncedTo = b.template at<uint64_t>(p); p += 8;
|
|
np->_lastAnnouncedTo = b.template at<uint64_t>(p); p += 8;
|
|
- np->_lastPathConfirmationSent = b.template at<uint64_t>(p); p += 8;
|
|
|
|
np->_lastDirectPathPushSent = b.template at<uint64_t>(p); p += 8;
|
|
np->_lastDirectPathPushSent = b.template at<uint64_t>(p); p += 8;
|
|
np->_lastDirectPathPushReceive = b.template at<uint64_t>(p); p += 8;
|
|
np->_lastDirectPathPushReceive = b.template at<uint64_t>(p); p += 8;
|
|
np->_lastPathSort = b.template at<uint64_t>(p); p += 8;
|
|
np->_lastPathSort = b.template at<uint64_t>(p); p += 8;
|
|
@@ -574,7 +569,6 @@ public:
|
|
}
|
|
}
|
|
|
|
|
|
private:
|
|
private:
|
|
- void _sortPaths(const uint64_t now);
|
|
|
|
Path *_getBestPath(const uint64_t now);
|
|
Path *_getBestPath(const uint64_t now);
|
|
Path *_getBestPath(const uint64_t now,int inetAddressFamily);
|
|
Path *_getBestPath(const uint64_t now,int inetAddressFamily);
|
|
|
|
|
|
@@ -585,7 +579,6 @@ private:
|
|
uint64_t _lastUnicastFrame;
|
|
uint64_t _lastUnicastFrame;
|
|
uint64_t _lastMulticastFrame;
|
|
uint64_t _lastMulticastFrame;
|
|
uint64_t _lastAnnouncedTo;
|
|
uint64_t _lastAnnouncedTo;
|
|
- uint64_t _lastPathConfirmationSent;
|
|
|
|
uint64_t _lastDirectPathPushSent;
|
|
uint64_t _lastDirectPathPushSent;
|
|
uint64_t _lastDirectPathPushReceive;
|
|
uint64_t _lastDirectPathPushReceive;
|
|
uint64_t _lastPathSort;
|
|
uint64_t _lastPathSort;
|