mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-06 11:10:13 +00:00
Final std::map<> from Switch, and add some smallish default values for hash size.
This commit is contained in:
parent
3dba016a93
commit
85b90f122a
@ -67,7 +67,10 @@ static const char *etherTypeName(const unsigned int etherType)
|
|||||||
|
|
||||||
Switch::Switch(const RuntimeEnvironment *renv) :
|
Switch::Switch(const RuntimeEnvironment *renv) :
|
||||||
RR(renv),
|
RR(renv),
|
||||||
_lastBeaconResponse(0)
|
_lastBeaconResponse(0),
|
||||||
|
_outstandingWhoisRequests(32),
|
||||||
|
_defragQueue(32),
|
||||||
|
_lastUniteAttempt(8) // only really used on root servers and upstreams, and it'll grow there just fine
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,10 +392,13 @@ void Switch::requestWhois(const Address &addr)
|
|||||||
bool inserted = false;
|
bool inserted = false;
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_outstandingWhoisRequests_m);
|
Mutex::Lock _l(_outstandingWhoisRequests_m);
|
||||||
std::pair< std::map< Address,WhoisRequest >::iterator,bool > entry(_outstandingWhoisRequests.insert(std::pair<Address,WhoisRequest>(addr,WhoisRequest())));
|
WhoisRequest &r = _outstandingWhoisRequests[addr];
|
||||||
if ((inserted = entry.second))
|
if (r.lastSent) {
|
||||||
entry.first->second.lastSent = RR->node->now();
|
r.retries = 0; // reset retry count if entry already existed, but keep waiting and retry again after normal timeout
|
||||||
entry.first->second.retries = 0; // reset retry count if entry already existed
|
} else {
|
||||||
|
r.lastSent = RR->node->now();
|
||||||
|
inserted = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (inserted)
|
if (inserted)
|
||||||
_sendWhoisRequest(addr,(const Address *)0,0);
|
_sendWhoisRequest(addr,(const Address *)0,0);
|
||||||
@ -474,24 +480,25 @@ unsigned long Switch::doTimerTasks(uint64_t now)
|
|||||||
|
|
||||||
{ // Retry outstanding WHOIS requests
|
{ // Retry outstanding WHOIS requests
|
||||||
Mutex::Lock _l(_outstandingWhoisRequests_m);
|
Mutex::Lock _l(_outstandingWhoisRequests_m);
|
||||||
for(std::map< Address,WhoisRequest >::iterator i(_outstandingWhoisRequests.begin());i!=_outstandingWhoisRequests.end();) {
|
Hashtable< Address,WhoisRequest >::Iterator i(_outstandingWhoisRequests);
|
||||||
unsigned long since = (unsigned long)(now - i->second.lastSent);
|
Address *a = (Address *)0;
|
||||||
|
WhoisRequest *r = (WhoisRequest *)0;
|
||||||
|
while (i.next(a,r)) {
|
||||||
|
const unsigned long since = (unsigned long)(now - r->lastSent);
|
||||||
if (since >= ZT_WHOIS_RETRY_DELAY) {
|
if (since >= ZT_WHOIS_RETRY_DELAY) {
|
||||||
if (i->second.retries >= ZT_MAX_WHOIS_RETRIES) {
|
if (r->retries >= ZT_MAX_WHOIS_RETRIES) {
|
||||||
TRACE("WHOIS %s timed out",i->first.toString().c_str());
|
TRACE("WHOIS %s timed out",a->toString().c_str());
|
||||||
_outstandingWhoisRequests.erase(i++);
|
_outstandingWhoisRequests.erase(*a);
|
||||||
continue;
|
|
||||||
} else {
|
} else {
|
||||||
i->second.lastSent = now;
|
r->lastSent = now;
|
||||||
i->second.peersConsulted[i->second.retries] = _sendWhoisRequest(i->first,i->second.peersConsulted,i->second.retries);
|
r->peersConsulted[r->retries] = _sendWhoisRequest(*a,r->peersConsulted,r->retries);
|
||||||
++i->second.retries;
|
++r->retries;
|
||||||
TRACE("WHOIS %s (retry %u)",i->first.toString().c_str(),i->second.retries);
|
TRACE("WHOIS %s (retry %u)",a->toString().c_str(),r->retries);
|
||||||
nextDelay = std::min(nextDelay,(unsigned long)ZT_WHOIS_RETRY_DELAY);
|
nextDelay = std::min(nextDelay,(unsigned long)ZT_WHOIS_RETRY_DELAY);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nextDelay = std::min(nextDelay,ZT_WHOIS_RETRY_DELAY - since);
|
nextDelay = std::min(nextDelay,ZT_WHOIS_RETRY_DELAY - since);
|
||||||
}
|
}
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,7 +531,7 @@ unsigned long Switch::doTimerTasks(uint64_t now)
|
|||||||
DefragQueueEntry *qe = (DefragQueueEntry *)0;
|
DefragQueueEntry *qe = (DefragQueueEntry *)0;
|
||||||
while (i.next(packetId,qe)) {
|
while (i.next(packetId,qe)) {
|
||||||
if ((now - qe->creationTime) > ZT_FRAGMENTED_PACKET_RECEIVE_TIMEOUT) {
|
if ((now - qe->creationTime) > ZT_FRAGMENTED_PACKET_RECEIVE_TIMEOUT) {
|
||||||
TRACE("incomplete fragmented packet %.16llx timed out, fragments discarded",i->first);
|
TRACE("incomplete fragmented packet %.16llx timed out, fragments discarded",*packetId);
|
||||||
_defragQueue.erase(*packetId);
|
_defragQueue.erase(*packetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,11 +190,12 @@ private:
|
|||||||
// Outsanding WHOIS requests and how many retries they've undergone
|
// Outsanding WHOIS requests and how many retries they've undergone
|
||||||
struct WhoisRequest
|
struct WhoisRequest
|
||||||
{
|
{
|
||||||
|
WhoisRequest() : lastSent(0),retries(0) {}
|
||||||
uint64_t lastSent;
|
uint64_t lastSent;
|
||||||
Address peersConsulted[ZT_MAX_WHOIS_RETRIES]; // by retry
|
Address peersConsulted[ZT_MAX_WHOIS_RETRIES]; // by retry
|
||||||
unsigned int retries; // 0..ZT_MAX_WHOIS_RETRIES
|
unsigned int retries; // 0..ZT_MAX_WHOIS_RETRIES
|
||||||
};
|
};
|
||||||
std::map< Address,WhoisRequest > _outstandingWhoisRequests;
|
Hashtable< Address,WhoisRequest > _outstandingWhoisRequests;
|
||||||
Mutex _outstandingWhoisRequests_m;
|
Mutex _outstandingWhoisRequests_m;
|
||||||
|
|
||||||
// Packet defragmentation queue -- comes before RX queue in path
|
// Packet defragmentation queue -- comes before RX queue in path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user