mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-06 11:10:13 +00:00
Eliminate a little copypasta.
This commit is contained in:
parent
dcb1233b0d
commit
d9e4ba1280
@ -225,18 +225,7 @@ void Switch::onRemotePacket(const InetAddress &localAddr,const InetAddress &from
|
|||||||
|
|
||||||
SharedPtr<Peer> relayTo = RR->topology->getPeer(destination);
|
SharedPtr<Peer> relayTo = RR->topology->getPeer(destination);
|
||||||
if ((relayTo)&&((relayTo->sendDirect(packet.data(),packet.size(),now,false)))) {
|
if ((relayTo)&&((relayTo->sendDirect(packet.data(),packet.size(),now,false)))) {
|
||||||
if (source != RR->identity.address()) { // don't send RENDEZVOUS for cluster frontplane relays
|
if ((source != RR->identity.address())&&(_shouldUnite(now,source,destination))) { // don't send RENDEZVOUS for cluster frontplane relays
|
||||||
|
|
||||||
bool shouldUnite;
|
|
||||||
{
|
|
||||||
Mutex::Lock _l(_lastUniteAttempt_m);
|
|
||||||
uint64_t &lastUniteAt = _lastUniteAttempt[_LastUniteKey(source,destination)];
|
|
||||||
shouldUnite = ((now - lastUniteAt) >= ZT_MIN_UNITE_INTERVAL);
|
|
||||||
if (shouldUnite)
|
|
||||||
lastUniteAt = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldUnite) {
|
|
||||||
const InetAddress *hintToSource = (InetAddress *)0;
|
const InetAddress *hintToSource = (InetAddress *)0;
|
||||||
const InetAddress *hintToDest = (InetAddress *)0;
|
const InetAddress *hintToDest = (InetAddress *)0;
|
||||||
|
|
||||||
@ -292,20 +281,10 @@ void Switch::onRemotePacket(const InetAddress &localAddr,const InetAddress &from
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
#ifdef ZT_ENABLE_CLUSTER
|
#ifdef ZT_ENABLE_CLUSTER
|
||||||
if ((RR->cluster)&&(source != RR->identity.address())) {
|
if ((RR->cluster)&&(source != RR->identity.address())) {
|
||||||
bool shouldUnite;
|
RR->cluster->relayViaCluster(source,destination,packet.data(),packet.size(),_shouldUnite(now,source,destination));
|
||||||
{
|
|
||||||
Mutex::Lock _l(_lastUniteAttempt_m);
|
|
||||||
uint64_t &luts = _lastUniteAttempt[_LastUniteKey(source,destination)];
|
|
||||||
shouldUnite = ((now - luts) >= ZT_MIN_UNITE_INTERVAL);
|
|
||||||
if (shouldUnite)
|
|
||||||
luts = now;
|
|
||||||
}
|
|
||||||
RR->cluster->relayViaCluster(source,destination,packet.data(),packet.size(),shouldUnite);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -747,6 +726,17 @@ unsigned long Switch::doTimerTasks(uint64_t now)
|
|||||||
return nextDelay;
|
return nextDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Switch::_shouldUnite(const uint64_t now,const Address &source,const Address &destination)
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_lastUniteAttempt_m);
|
||||||
|
uint64_t &ts = _lastUniteAttempt[_LastUniteKey(source,destination)];
|
||||||
|
if ((now - ts) >= ZT_MIN_UNITE_INTERVAL) {
|
||||||
|
ts = now;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Address Switch::_sendWhoisRequest(const Address &addr,const Address *peersAlreadyConsulted,unsigned int numPeersAlreadyConsulted)
|
Address Switch::_sendWhoisRequest(const Address &addr,const Address *peersAlreadyConsulted,unsigned int numPeersAlreadyConsulted)
|
||||||
{
|
{
|
||||||
SharedPtr<Peer> upstream(RR->topology->getUpstreamPeer(peersAlreadyConsulted,numPeersAlreadyConsulted,false));
|
SharedPtr<Peer> upstream(RR->topology->getUpstreamPeer(peersAlreadyConsulted,numPeersAlreadyConsulted,false));
|
||||||
|
@ -124,6 +124,7 @@ public:
|
|||||||
unsigned long doTimerTasks(uint64_t now);
|
unsigned long doTimerTasks(uint64_t now);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool _shouldUnite(const uint64_t now,const Address &source,const Address &destination);
|
||||||
Address _sendWhoisRequest(const Address &addr,const Address *peersAlreadyConsulted,unsigned int numPeersAlreadyConsulted);
|
Address _sendWhoisRequest(const Address &addr,const Address *peersAlreadyConsulted,unsigned int numPeersAlreadyConsulted);
|
||||||
bool _trySend(Packet &packet,bool encrypt); // packet is modified if return is true
|
bool _trySend(Packet &packet,bool encrypt); // packet is modified if return is true
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user