mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 20:13:44 +02:00
Try prioritizing cluster-send over direct send in cluster mode -- may improve cluster relaying reliability.
This commit is contained in:
parent
badec136fc
commit
9490b1f136
2 changed files with 24 additions and 23 deletions
|
@ -616,15 +616,15 @@ void Switch::_handleRemotePacketFragment(const InetAddress &localAddr,const Inet
|
||||||
if (fragment.hops() < ZT_RELAY_MAX_HOPS) {
|
if (fragment.hops() < ZT_RELAY_MAX_HOPS) {
|
||||||
fragment.incrementHops();
|
fragment.incrementHops();
|
||||||
|
|
||||||
|
#ifdef ZT_ENABLE_CLUSTER
|
||||||
|
if ((RR->cluster)&&(RR->cluster->sendViaCluster(Address(),destination,fragment.data(),fragment.size(),false)))
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Note: we don't bother initiating NAT-t for fragments, since heads will set that off.
|
// Note: we don't bother initiating NAT-t for fragments, since heads will set that off.
|
||||||
// It wouldn't hurt anything, just redundant and unnecessary.
|
// It wouldn't hurt anything, just redundant and unnecessary.
|
||||||
SharedPtr<Peer> relayTo = RR->topology->getPeer(destination);
|
SharedPtr<Peer> relayTo = RR->topology->getPeer(destination);
|
||||||
if ((!relayTo)||(!relayTo->send(RR,fragment.data(),fragment.size(),RR->node->now()))) {
|
if ((!relayTo)||(!relayTo->send(RR,fragment.data(),fragment.size(),RR->node->now()))) {
|
||||||
#ifdef ZT_ENABLE_CLUSTER
|
|
||||||
if ((RR->cluster)&&(RR->cluster->sendViaCluster(Address(),destination,fragment.data(),fragment.size(),false)))
|
|
||||||
return; // sent by way of another member of this cluster
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Don't know peer or no direct path -- so relay via root server
|
// Don't know peer or no direct path -- so relay via root server
|
||||||
relayTo = RR->topology->getBestRoot();
|
relayTo = RR->topology->getBestRoot();
|
||||||
if (relayTo)
|
if (relayTo)
|
||||||
|
@ -702,16 +702,28 @@ void Switch::_handleRemotePacketHead(const InetAddress &localAddr,const InetAddr
|
||||||
if (packet->hops() < ZT_RELAY_MAX_HOPS) {
|
if (packet->hops() < ZT_RELAY_MAX_HOPS) {
|
||||||
packet->incrementHops();
|
packet->incrementHops();
|
||||||
|
|
||||||
SharedPtr<Peer> relayTo = RR->topology->getPeer(destination);
|
|
||||||
if ((relayTo)&&((relayTo->send(RR,packet->data(),packet->size(),now)))) {
|
|
||||||
if (_shouldTryUnite(now,source,destination))
|
|
||||||
unite(source,destination);
|
|
||||||
} else {
|
|
||||||
#ifdef ZT_ENABLE_CLUSTER
|
#ifdef ZT_ENABLE_CLUSTER
|
||||||
if ((RR->cluster)&&(RR->cluster->sendViaCluster(source,destination,packet->data(),packet->size(),_shouldTryUnite(now,source,destination))))
|
if (RR->cluster) {
|
||||||
return; // sent by way of another member of this cluster
|
Mutex::Lock _l(_lastUniteAttempt_m);
|
||||||
|
uint64_t &luts = _lastUniteAttempt[_LastUniteKey(source,destination)];
|
||||||
|
const bool shouldUnite = ((now - luts) >= ZT_MIN_UNITE_INTERVAL);
|
||||||
|
if (RR->cluster->sendViaCluster(source,destination,packet->data(),packet->size(),shouldUnite)) {
|
||||||
|
if (shouldUnite)
|
||||||
|
luts = now;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SharedPtr<Peer> relayTo = RR->topology->getPeer(destination);
|
||||||
|
if ((relayTo)&&((relayTo->send(RR,packet->data(),packet->size(),now)))) {
|
||||||
|
Mutex::Lock _l(_lastUniteAttempt_m);
|
||||||
|
uint64_t &luts = _lastUniteAttempt[_LastUniteKey(source,destination)];
|
||||||
|
if ((now - luts) >= ZT_MIN_UNITE_INTERVAL) {
|
||||||
|
luts = now;
|
||||||
|
unite(source,destination);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
relayTo = RR->topology->getBestRoot(&source,1,true);
|
relayTo = RR->topology->getBestRoot(&source,1,true);
|
||||||
if (relayTo)
|
if (relayTo)
|
||||||
relayTo->send(RR,packet->data(),packet->size(),now);
|
relayTo->send(RR,packet->data(),packet->size(),now);
|
||||||
|
@ -860,14 +872,4 @@ bool Switch::_trySend(const Packet &packet,bool encrypt,uint64_t nwid)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Switch::_shouldTryUnite(const uint64_t now,const Address &p1,const Address &p2)
|
|
||||||
{
|
|
||||||
Mutex::Lock _l(_lastUniteAttempt_m);
|
|
||||||
uint64_t &luts = _lastUniteAttempt[_LastUniteKey(p1,p2)];
|
|
||||||
if ((now - luts) < ZT_MIN_UNITE_INTERVAL)
|
|
||||||
return false;
|
|
||||||
luts = now;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
|
|
@ -180,7 +180,6 @@ private:
|
||||||
void _handleRemotePacketHead(const InetAddress &localAddr,const InetAddress &fromAddr,const void *data,unsigned int len);
|
void _handleRemotePacketHead(const InetAddress &localAddr,const InetAddress &fromAddr,const void *data,unsigned int len);
|
||||||
Address _sendWhoisRequest(const Address &addr,const Address *peersAlreadyConsulted,unsigned int numPeersAlreadyConsulted);
|
Address _sendWhoisRequest(const Address &addr,const Address *peersAlreadyConsulted,unsigned int numPeersAlreadyConsulted);
|
||||||
bool _trySend(const Packet &packet,bool encrypt,uint64_t nwid);
|
bool _trySend(const Packet &packet,bool encrypt,uint64_t nwid);
|
||||||
bool _shouldTryUnite(const uint64_t now,const Address &p1,const Address &p2);
|
|
||||||
|
|
||||||
const RuntimeEnvironment *const RR;
|
const RuntimeEnvironment *const RR;
|
||||||
uint64_t _lastBeaconResponse;
|
uint64_t _lastBeaconResponse;
|
||||||
|
|
Loading…
Add table
Reference in a new issue