Merge "Remove the transactionId field" into main
This commit is contained in:
commit
8231494aaa
3 changed files with 17 additions and 21 deletions
|
|
@ -730,7 +730,7 @@ public class MdnsServiceTypeClient {
|
|||
serviceType,
|
||||
subtypes,
|
||||
taskArgs.config.expectUnicastResponse,
|
||||
taskArgs.config.transactionId,
|
||||
taskArgs.config.getTransactionId(),
|
||||
socketKey,
|
||||
onlyUseIpv6OnIpv6OnlyNetworks,
|
||||
sendDiscoveryQueries,
|
||||
|
|
|
|||
|
|
@ -29,21 +29,18 @@ public class QueryTaskConfig {
|
|||
private final boolean alwaysAskForUnicastResponse =
|
||||
MdnsConfigs.alwaysAskForUnicastResponseInEachBurst();
|
||||
@VisibleForTesting
|
||||
final int transactionId;
|
||||
@VisibleForTesting
|
||||
final boolean expectUnicastResponse;
|
||||
final int queryIndex;
|
||||
final int queryMode;
|
||||
|
||||
QueryTaskConfig(int queryMode, int queryIndex, int transactionId) {
|
||||
QueryTaskConfig(int queryMode, int queryIndex) {
|
||||
this.queryMode = queryMode;
|
||||
this.transactionId = transactionId;
|
||||
this.queryIndex = queryIndex;
|
||||
this.expectUnicastResponse = getExpectUnicastResponse();
|
||||
}
|
||||
|
||||
QueryTaskConfig(int queryMode) {
|
||||
this(queryMode, 0, 1);
|
||||
this(queryMode, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -51,12 +48,11 @@ public class QueryTaskConfig {
|
|||
*/
|
||||
public QueryTaskConfig getConfigForNextRun(int queryMode) {
|
||||
final int newQueryIndex = queryIndex + 1;
|
||||
int newTransactionId = transactionId + 1;
|
||||
if (newTransactionId > UNSIGNED_SHORT_MAX_VALUE) {
|
||||
newTransactionId = 1;
|
||||
}
|
||||
return new QueryTaskConfig(queryMode, newQueryIndex);
|
||||
}
|
||||
|
||||
return new QueryTaskConfig(queryMode, newQueryIndex, newTransactionId);
|
||||
public int getTransactionId() {
|
||||
return (queryIndex % (UNSIGNED_SHORT_MAX_VALUE - 1)) + 1;
|
||||
}
|
||||
|
||||
private boolean getExpectUnicastResponse() {
|
||||
|
|
|
|||
|
|
@ -566,21 +566,21 @@ public class MdnsServiceTypeClientTests {
|
|||
|
||||
// This is the first query. We will ask for unicast response.
|
||||
assertTrue(config.expectUnicastResponse);
|
||||
assertEquals(config.transactionId, 1);
|
||||
assertEquals(config.getTransactionId(), 1);
|
||||
|
||||
// For the rest of queries in this burst, we will NOT ask for unicast response.
|
||||
for (int i = 1; i < MdnsConfigs.queriesPerBurst(); i++) {
|
||||
int oldTransactionId = config.transactionId;
|
||||
int oldTransactionId = config.getTransactionId();
|
||||
config = config.getConfigForNextRun(ACTIVE_QUERY_MODE);
|
||||
assertFalse(config.expectUnicastResponse);
|
||||
assertEquals(config.transactionId, oldTransactionId + 1);
|
||||
assertEquals(config.getTransactionId(), oldTransactionId + 1);
|
||||
}
|
||||
|
||||
// This is the first query of a new burst. We will ask for unicast response.
|
||||
int oldTransactionId = config.transactionId;
|
||||
int oldTransactionId = config.getTransactionId();
|
||||
config = config.getConfigForNextRun(ACTIVE_QUERY_MODE);
|
||||
assertTrue(config.expectUnicastResponse);
|
||||
assertEquals(config.transactionId, oldTransactionId + 1);
|
||||
assertEquals(config.getTransactionId(), oldTransactionId + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -591,21 +591,21 @@ public class MdnsServiceTypeClientTests {
|
|||
|
||||
// This is the first query. We will ask for unicast response.
|
||||
assertTrue(config.expectUnicastResponse);
|
||||
assertEquals(config.transactionId, 1);
|
||||
assertEquals(config.getTransactionId(), 1);
|
||||
|
||||
// For the rest of queries in this burst, we will NOT ask for unicast response.
|
||||
for (int i = 1; i < MdnsConfigs.queriesPerBurst(); i++) {
|
||||
int oldTransactionId = config.transactionId;
|
||||
int oldTransactionId = config.getTransactionId();
|
||||
config = config.getConfigForNextRun(ACTIVE_QUERY_MODE);
|
||||
assertFalse(config.expectUnicastResponse);
|
||||
assertEquals(config.transactionId, oldTransactionId + 1);
|
||||
assertEquals(config.getTransactionId(), oldTransactionId + 1);
|
||||
}
|
||||
|
||||
// This is the first query of a new burst. We will NOT ask for unicast response.
|
||||
int oldTransactionId = config.transactionId;
|
||||
int oldTransactionId = config.getTransactionId();
|
||||
config = config.getConfigForNextRun(ACTIVE_QUERY_MODE);
|
||||
assertFalse(config.expectUnicastResponse);
|
||||
assertEquals(config.transactionId, oldTransactionId + 1);
|
||||
assertEquals(config.getTransactionId(), oldTransactionId + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in a new issue