Merge "Simplify the burst time logic" into main
This commit is contained in:
commit
a906743bc7
2 changed files with 14 additions and 24 deletions
|
|
@ -159,8 +159,7 @@ public class QueryTaskConfig {
|
|||
}
|
||||
final int maxTimeBetweenBursts = queryMode == AGGRESSIVE_QUERY_MODE
|
||||
? MAX_TIME_BETWEEN_AGGRESSIVE_BURSTS_MS : MAX_TIME_BETWEEN_ACTIVE_PASSIVE_BURSTS_MS;
|
||||
return timeBetweenBurstsInMs < maxTimeBetweenBursts
|
||||
? Math.min(timeBetweenBurstsInMs * 2, maxTimeBetweenBursts) : timeBetweenBurstsInMs;
|
||||
return Math.min(timeBetweenBurstsInMs * 2, maxTimeBetweenBursts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -172,21 +171,19 @@ public class QueryTaskConfig {
|
|||
if (newTransactionId > UNSIGNED_SHORT_MAX_VALUE) {
|
||||
newTransactionId = 1;
|
||||
}
|
||||
boolean newIsFirstBurst = isFirstBurst;
|
||||
|
||||
int newQueriesPerBurst = queriesPerBurst;
|
||||
int newBurstCounter = burstCounter + 1;
|
||||
final boolean isFirstQueryInBurst = newBurstCounter == 1;
|
||||
final boolean isLastQueryInBurst = newBurstCounter == queriesPerBurst;
|
||||
boolean newIsFirstBurst = isFirstBurst && !isLastQueryInBurst;
|
||||
if (isLastQueryInBurst) {
|
||||
newBurstCounter = 0;
|
||||
if (isFirstBurst) {
|
||||
newIsFirstBurst = false;
|
||||
// In passive scan mode, sends a single burst of QUERIES_PER_BURST queries, and
|
||||
// then in each TIME_BETWEEN_BURSTS interval, sends QUERIES_PER_BURST_PASSIVE_MODE
|
||||
// queries.
|
||||
if (queryMode == PASSIVE_QUERY_MODE) {
|
||||
newQueriesPerBurst = QUERIES_PER_BURST_PASSIVE_MODE;
|
||||
}
|
||||
// In passive scan mode, sends a single burst of QUERIES_PER_BURST queries, and
|
||||
// then in each TIME_BETWEEN_BURSTS interval, sends QUERIES_PER_BURST_PASSIVE_MODE
|
||||
// queries.
|
||||
if (isFirstBurst && queryMode == PASSIVE_QUERY_MODE) {
|
||||
newQueriesPerBurst = QUERIES_PER_BURST_PASSIVE_MODE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1777,13 +1777,6 @@ public class MdnsServiceTypeClientTests {
|
|||
socketKey);
|
||||
}
|
||||
|
||||
private int getBetweenBurstTime(int burstCounter, int currentBetweenTime, int maxBetweenTime,
|
||||
int initialBetweenTime) {
|
||||
return currentBetweenTime < maxBetweenTime
|
||||
? Math.min(initialBetweenTime * (int) Math.pow(2, burstCounter), maxBetweenTime)
|
||||
: currentBetweenTime;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendQueries_aggressiveScanMode() {
|
||||
final MdnsSearchOptions searchOptions = MdnsSearchOptions.newBuilder()
|
||||
|
|
@ -1799,9 +1792,9 @@ public class MdnsServiceTypeClientTests {
|
|||
verifyAndSendQuery(i + 1, /* timeInMs= */ 0, /* expectsUnicastResponse= */ false);
|
||||
verifyAndSendQuery(i + 2, TIME_BETWEEN_RETRANSMISSION_QUERIES_IN_BURST_MS,
|
||||
/* expectsUnicastResponse= */ false);
|
||||
betweenBurstTime = getBetweenBurstTime(burstCounter, betweenBurstTime,
|
||||
MAX_TIME_BETWEEN_AGGRESSIVE_BURSTS_MS,
|
||||
INITIAL_AGGRESSIVE_TIME_BETWEEN_BURSTS_MS);
|
||||
betweenBurstTime = Math.min(
|
||||
INITIAL_AGGRESSIVE_TIME_BETWEEN_BURSTS_MS * (int) Math.pow(2, burstCounter),
|
||||
MAX_TIME_BETWEEN_AGGRESSIVE_BURSTS_MS);
|
||||
burstCounter++;
|
||||
}
|
||||
// Verify that Task is not removed before stopSendAndReceive was called.
|
||||
|
|
@ -1860,9 +1853,9 @@ public class MdnsServiceTypeClientTests {
|
|||
verifyAndSendQuery(i + 1, /* timeInMs= */ 0, /* expectsUnicastResponse= */ false);
|
||||
verifyAndSendQuery(i + 2, TIME_BETWEEN_RETRANSMISSION_QUERIES_IN_BURST_MS,
|
||||
/* expectsUnicastResponse= */ false);
|
||||
betweenBurstTime = getBetweenBurstTime(burstCounter, betweenBurstTime,
|
||||
MAX_TIME_BETWEEN_AGGRESSIVE_BURSTS_MS,
|
||||
INITIAL_AGGRESSIVE_TIME_BETWEEN_BURSTS_MS);
|
||||
betweenBurstTime = Math.min(
|
||||
INITIAL_AGGRESSIVE_TIME_BETWEEN_BURSTS_MS * (int) Math.pow(2, burstCounter),
|
||||
MAX_TIME_BETWEEN_AGGRESSIVE_BURSTS_MS);
|
||||
burstCounter++;
|
||||
}
|
||||
// In backoff mode, the current scheduled task will be canceled and reschedule if the
|
||||
|
|
|
|||
Loading…
Reference in a new issue