[mdns] restart probing on Register() if in conflict state (#12128)

This commit enhances mDNS to allow reprobing for registrations
currently in a conflict state. Upon an explicit `Register()` call,
the mDNS module will now restart the probing process. This allows the
device to attempt to claim the name again if the conflict has been
resolved on the network.

Unit tests are updated to verify this behavior.
This commit is contained in:
Abtin Keshavarzian
2025-11-10 23:39:48 +01:00
committed by GitHub
parent ce1887a597
commit bbf2588a56
3 changed files with 25 additions and 46 deletions
+22 -12
View File
@@ -1215,10 +1215,7 @@ void Core::Entry::SetState(State aState)
void Core::Entry::Register(const Key &aKey, const Callback &aCallback)
{
if (GetState() == kRemoving)
{
StartProbing();
}
DecideToProbeOnRegister();
mKeyRecord.UpdateTtl(DetermineTtl(aKey.mTtl, kDefaultKeyTtl));
mKeyRecord.UpdateProperty(mKeyData, aKey.mKeyData, aKey.mKeyDataLength);
@@ -1322,6 +1319,25 @@ void Core::Entry::InvokeCallbacks(void)
}
}
void Core::Entry::DecideToProbeOnRegister(void)
{
// Checks whether we should start probing when `Register()` is
// called. If a conflict was previously detected, we send a probe
// again upon an explicit `Register()` request.
switch (mState)
{
case kRegistered:
case kProbing:
break;
case kRemoving:
case kConflict:
StartProbing();
break;
}
}
void Core::Entry::StartProbing(void)
{
SetState(kProbing);
@@ -1951,10 +1967,7 @@ exit:
void Core::HostEntry::Register(const Host &aHost, const Callback &aCallback)
{
if (GetState() == kRemoving)
{
StartProbing();
}
DecideToProbeOnRegister();
SetCallback(aCallback);
@@ -2543,10 +2556,7 @@ void Core::ServiceEntry::Register(const Service &aService, const Callback &aCall
const char *hostName;
uint32_t ttl = DetermineTtl(aService.mTtl, kDefaultServiceTtl);
if (GetState() == kRemoving)
{
StartProbing();
}
DecideToProbeOnRegister();
SetCallback(aCallback);
+1
View File
@@ -1172,6 +1172,7 @@ private:
void SetCallback(const Callback &aCallback);
void ClearCallback(void) { mCallback.Clear(); }
void MarkToInvokeCallbackUnconditionally(void);
void DecideToProbeOnRegister(void);
void StartProbing(void);
void SetStateToConflict(void);
void SetStateToRemoving(void);
+2 -34
View File
@@ -5319,23 +5319,7 @@ void TestHostConflict(void)
VerifyOrQuit(!sConflictCallback.mWasCalled);
Log("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
Log("Register the conflicted `HostEntry` again, and make sure no probes are sent");
sRegCallbacks[1].Reset();
sConflictCallback.Reset();
sDnsMessages.Clear();
SuccessOrQuit(mdns->RegisterHost(host, 1, HandleCallback));
AdvanceTime(5000);
VerifyOrQuit(sRegCallbacks[1].mWasCalled);
VerifyOrQuit(sRegCallbacks[1].mError == kErrorDuplicated);
VerifyOrQuit(!sConflictCallback.mWasCalled);
Log("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
Log("Unregister the conflicted host and register it again immediately, make sure we see probes");
SuccessOrQuit(mdns->UnregisterHost(host));
Log("Register the conflicted `HostEntry` again, and make sure probes are sent");
sConflictCallback.Reset();
sRegCallbacks[0].Reset();
@@ -5481,23 +5465,7 @@ void TestServiceConflict(void)
VerifyOrQuit(!sConflictCallback.mWasCalled);
Log("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
Log("Register the conflicted `ServiceEntry` again, and make sure no probes are sent");
sRegCallbacks[1].Reset();
sConflictCallback.Reset();
sDnsMessages.Clear();
SuccessOrQuit(mdns->RegisterService(service, 1, HandleCallback));
AdvanceTime(5000);
VerifyOrQuit(sRegCallbacks[1].mWasCalled);
VerifyOrQuit(sRegCallbacks[1].mError == kErrorDuplicated);
VerifyOrQuit(!sConflictCallback.mWasCalled);
Log("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
Log("Unregister the conflicted host and register it again immediately, make sure we see probes");
SuccessOrQuit(mdns->UnregisterService(service));
Log("Register the conflicted `ServiceEntry` again, and make sure probes are sent");
sConflictCallback.Reset();
sRegCallbacks[0].Reset();