mirror of
https://github.com/espressif/openthread.git
synced 2026-09-02 23:30:07 +00:00
[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:
+22
-12
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user