Add low-bandwidth mode
This commit is contained in:
parent
98b190c626
commit
3c9ea2b667
6 changed files with 42 additions and 10 deletions
|
@ -202,6 +202,14 @@ public:
|
|||
{
|
||||
const std::vector<InetAddress> *const alwaysContactEndpoints = _alwaysContact.get(p->address());
|
||||
if (alwaysContactEndpoints) {
|
||||
|
||||
// Contact upstream peers as infrequently as possible
|
||||
ZT_PeerRole role = RR->topology->role(p->address());
|
||||
int roleBasedTimerScale = (role == ZT_PEER_ROLE_LEAF) ? 2 : 16;
|
||||
if ((RR->node->now() - p->lastSentFullHello()) <= (ZT_PATH_HEARTBEAT_PERIOD * roleBasedTimerScale)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const unsigned int sent = p->doPingAndKeepalive(_tPtr,_now);
|
||||
bool contacted = (sent != 0);
|
||||
|
||||
|
@ -262,7 +270,7 @@ ZT_ResultCode Node::processBackgroundTasks(void *tptr,int64_t now,volatile int64
|
|||
}
|
||||
}
|
||||
|
||||
unsigned long timeUntilNextPingCheck = ZT_PING_CHECK_INVERVAL;
|
||||
unsigned long timeUntilNextPingCheck = _lowBandwidthMode ? (ZT_PING_CHECK_INVERVAL * 5) : ZT_PING_CHECK_INVERVAL;
|
||||
const int64_t timeSinceLastPingCheck = now - _lastPingCheck;
|
||||
if (timeSinceLastPingCheck >= timeUntilNextPingCheck) {
|
||||
try {
|
||||
|
@ -309,6 +317,7 @@ ZT_ResultCode Node::processBackgroundTasks(void *tptr,int64_t now,volatile int64
|
|||
|
||||
// Get peers we should stay connected to according to network configs
|
||||
// Also get networks and whether they need config so we only have to do one pass over networks
|
||||
int timerScale = _lowBandwidthMode ? 64 : 1;
|
||||
std::vector< std::pair< SharedPtr<Network>,bool > > networkConfigNeeded;
|
||||
{
|
||||
Mutex::Lock l(_networks_m);
|
||||
|
@ -317,7 +326,7 @@ ZT_ResultCode Node::processBackgroundTasks(void *tptr,int64_t now,volatile int64
|
|||
SharedPtr<Network> *network = (SharedPtr<Network> *)0;
|
||||
while (i.next(nwid,network)) {
|
||||
(*network)->config().alwaysContactAddresses(alwaysContact);
|
||||
networkConfigNeeded.push_back( std::pair< SharedPtr<Network>,bool >(*network,(((now - (*network)->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)||(!(*network)->hasConfig()))) );
|
||||
networkConfigNeeded.push_back( std::pair< SharedPtr<Network>,bool >(*network,(((now - (*network)->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY * timerScale)||(!(*network)->hasConfig()))) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -336,9 +345,12 @@ ZT_ResultCode Node::processBackgroundTasks(void *tptr,int64_t now,volatile int64
|
|||
|
||||
// Refresh network config or broadcast network updates to members as needed
|
||||
for(std::vector< std::pair< SharedPtr<Network>,bool > >::const_iterator n(networkConfigNeeded.begin());n!=networkConfigNeeded.end();++n) {
|
||||
if (n->second)
|
||||
if (n->second) {
|
||||
n->first->requestConfiguration(tptr);
|
||||
n->first->sendUpdatesToMembers(tptr);
|
||||
}
|
||||
if (! _lowBandwidthMode) {
|
||||
n->first->sendUpdatesToMembers(tptr);
|
||||
}
|
||||
}
|
||||
|
||||
// Update online status, post status change as event
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue