mirror of
https://github.com/espressif/openthread.git
synced 2026-06-06 05:24:51 +00:00
[srp-server] introduce LeaseTracker base class for Host and Service (#12628)
This commit extracts the common lease tracking variables (`mLease`, `mKeyLease`, `mTtl`, and `mUpdateTime`) and their associated methods from the `Srp::Server::Host` and `Srp::Server::Service` classes into a new shared base class, `LeaseTracker`. By having both `Host` and `Service` inherit from `LeaseTracker`, we eliminate duplicated logic for calculating expiration times, handling lease info, and processing TTL updates. This refactoring simplifies the SRP server codebase and ensures consistent lease management behavior across both entities.
This commit is contained in:
committed by
GitHub
parent
08f7b370b3
commit
9b887f6bd1
@@ -259,7 +259,7 @@ void AdvertisingProxy::AdvertiseRemovalOf(Host &aHost)
|
|||||||
{
|
{
|
||||||
service->mShouldAdvertise = true;
|
service->mShouldAdvertise = true;
|
||||||
|
|
||||||
if (aHost.mKeyLease == 0)
|
if (aHost.GetKeyLease() == 0)
|
||||||
{
|
{
|
||||||
advService.mIsKeyRegistered = false;
|
advService.mIsKeyRegistered = false;
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ void AdvertisingProxy::AdvertiseRemovalOf(Host &aHost)
|
|||||||
advService.mIsReplaced = true;
|
advService.mIsReplaced = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aHost.mKeyLease == 0)
|
if (aHost.GetKeyLease() == 0)
|
||||||
{
|
{
|
||||||
advHost.mIsKeyRegistered = false;
|
advHost.mIsKeyRegistered = false;
|
||||||
}
|
}
|
||||||
@@ -291,7 +291,7 @@ void AdvertisingProxy::AdvertiseRemovalOf(Host &aHost)
|
|||||||
UnregisterService(service);
|
UnregisterService(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aHost.mKeyLease == 0)
|
if (aHost.GetKeyLease() == 0)
|
||||||
{
|
{
|
||||||
UnregisterKey(service);
|
UnregisterKey(service);
|
||||||
}
|
}
|
||||||
@@ -302,7 +302,7 @@ void AdvertisingProxy::AdvertiseRemovalOf(Host &aHost)
|
|||||||
UnregisterHost(aHost);
|
UnregisterHost(aHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aHost.mKeyLease == 0)
|
if (aHost.GetKeyLease() == 0)
|
||||||
{
|
{
|
||||||
UnregisterKey(aHost);
|
UnregisterKey(aHost);
|
||||||
}
|
}
|
||||||
@@ -352,7 +352,7 @@ void AdvertisingProxy::AdvertiseRemovalOf(Service &aService)
|
|||||||
UnregisterService(aService);
|
UnregisterService(aService);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aService.mKeyLease == 0)
|
if (aService.GetKeyLease() == 0)
|
||||||
{
|
{
|
||||||
UnregisterKey(aService);
|
UnregisterKey(aService);
|
||||||
}
|
}
|
||||||
@@ -473,7 +473,7 @@ exit:
|
|||||||
void AdvertisingProxy::Advertise(Host &aHost)
|
void AdvertisingProxy::Advertise(Host &aHost)
|
||||||
{
|
{
|
||||||
bool shouldUnregisterHostAndServices = aHost.IsDeleted();
|
bool shouldUnregisterHostAndServices = aHost.IsDeleted();
|
||||||
bool shouldUnregisterKeys = (aHost.mKeyLease == 0);
|
bool shouldUnregisterKeys = (aHost.GetKeyLease() == 0);
|
||||||
|
|
||||||
DecideToAdvertise(aHost, shouldUnregisterHostAndServices, shouldUnregisterKeys);
|
DecideToAdvertise(aHost, shouldUnregisterHostAndServices, shouldUnregisterKeys);
|
||||||
|
|
||||||
@@ -817,7 +817,7 @@ bool AdvertisingProxy::CompareAndUpdateHost(Host &aHost, Host &aExistingHost)
|
|||||||
// we need to unregister keys for any services on
|
// we need to unregister keys for any services on
|
||||||
// existing host that are not present in `aHost`.
|
// existing host that are not present in `aHost`.
|
||||||
|
|
||||||
if (aHost.mKeyLease == 0)
|
if (aHost.GetKeyLease() == 0)
|
||||||
{
|
{
|
||||||
for (Service &existingService : aExistingHost.mServices)
|
for (Service &existingService : aExistingHost.mServices)
|
||||||
{
|
{
|
||||||
|
|||||||
+60
-94
@@ -454,7 +454,7 @@ void Server::RemoveHost(Host *aHost, RetainName aRetainName)
|
|||||||
{
|
{
|
||||||
VerifyOrExit(aHost != nullptr);
|
VerifyOrExit(aHost != nullptr);
|
||||||
|
|
||||||
aHost->mLease = 0;
|
aHost->SetLease(0);
|
||||||
aHost->ClearResources();
|
aHost->ClearResources();
|
||||||
|
|
||||||
if (aRetainName)
|
if (aRetainName)
|
||||||
@@ -463,7 +463,7 @@ void Server::RemoveHost(Host *aHost, RetainName aRetainName)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
aHost->mKeyLease = 0;
|
aHost->SetKeyLease(0);
|
||||||
IgnoreError(mHosts.Remove(*aHost));
|
IgnoreError(mHosts.Remove(*aHost));
|
||||||
LogInfo("Fully remove host %s", aHost->GetFullName());
|
LogInfo("Fully remove host %s", aHost->GetFullName());
|
||||||
}
|
}
|
||||||
@@ -642,9 +642,10 @@ void Server::CommitSrpUpdate(Error aError,
|
|||||||
|
|
||||||
for (Service &service : aHost.mServices)
|
for (Service &service : aHost.mServices)
|
||||||
{
|
{
|
||||||
service.mLease = grantedLease;
|
service.SetLease(service.mIsDeleted ? 0 : grantedLease);
|
||||||
service.mKeyLease = grantedKeyLease;
|
service.SetKeyLease(grantedKeyLease);
|
||||||
service.mTtl = grantedTtl;
|
service.SetTtl(grantedTtl);
|
||||||
|
|
||||||
service.mIsCommitted = true;
|
service.mIsCommitted = true;
|
||||||
|
|
||||||
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
|
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
|
||||||
@@ -1311,7 +1312,7 @@ Error Server::ProcessServiceDescriptionInstructions(Host &aHost,
|
|||||||
VerifyOrExit(!service->mParsedSrv, error = kErrorParse);
|
VerifyOrExit(!service->mParsedSrv, error = kErrorParse);
|
||||||
service->mParsedSrv = true;
|
service->mParsedSrv = true;
|
||||||
|
|
||||||
service->mTtl = srvRecord.GetTtl();
|
service->SetTtl(srvRecord.GetTtl());
|
||||||
service->mPriority = srvRecord.GetPriority();
|
service->mPriority = srvRecord.GetPriority();
|
||||||
service->mWeight = srvRecord.GetWeight();
|
service->mWeight = srvRecord.GetWeight();
|
||||||
service->mPort = srvRecord.GetPort();
|
service->mPort = srvRecord.GetPort();
|
||||||
@@ -1395,8 +1396,8 @@ Error Server::ProcessAdditionalSection(Host *aHost, const Message &aMessage, Mes
|
|||||||
service.mIsDeleted = true;
|
service.mIsDeleted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
service.mLease = service.mIsDeleted ? 0 : leaseOption.GetLeaseInterval();
|
service.SetLease(service.mIsDeleted ? 0 : leaseOption.GetLeaseInterval());
|
||||||
service.mKeyLease = leaseOption.GetKeyLeaseInterval();
|
service.SetKeyLease(leaseOption.GetKeyLeaseInterval());
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the client included the short variant of Lease Option,
|
// If the client included the short variant of Lease Option,
|
||||||
@@ -1525,7 +1526,7 @@ void Server::HandleUpdate(Host &aHost, const MessageMetadata &aMetadata)
|
|||||||
|
|
||||||
SuccessOrExit(error = service->mServiceName.Set(existingService.GetServiceName()));
|
SuccessOrExit(error = service->mServiceName.Set(existingService.GetServiceName()));
|
||||||
service->mIsDeleted = true;
|
service->mIsDeleted = true;
|
||||||
service->mKeyLease = existingService.mKeyLease;
|
service->SetKeyLease(existingService.GetKeyLease());
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -1940,6 +1941,51 @@ exit:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Server::LeaseTracker
|
||||||
|
|
||||||
|
void Server::LeaseTracker::Init(TimeMilli aUpdateTime)
|
||||||
|
{
|
||||||
|
mLease = 0;
|
||||||
|
mKeyLease = 0;
|
||||||
|
mTtl = 0;
|
||||||
|
mUpdateTime = aUpdateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeMilli Server::LeaseTracker::GetExpireTime(void) const { return mUpdateTime + Time::SecToMsec(mLease); }
|
||||||
|
|
||||||
|
TimeMilli Server::LeaseTracker::GetKeyExpireTime(void) const { return mUpdateTime + Time::SecToMsec(mKeyLease); }
|
||||||
|
|
||||||
|
void Server::LeaseTracker::GetLeaseInfo(LeaseInfo &aLeaseInfo) const
|
||||||
|
{
|
||||||
|
TimeMilli now = TimerMilli::GetNow();
|
||||||
|
|
||||||
|
aLeaseInfo.mLease = Time::SecToMsec(mLease);
|
||||||
|
aLeaseInfo.mKeyLease = Time::SecToMsec(mKeyLease);
|
||||||
|
aLeaseInfo.mRemainingLease = (mLease != 0) ? GetExpireTime().DetermineRemainingDurationFrom(now) : 0;
|
||||||
|
aLeaseInfo.mRemainingKeyLease = GetKeyExpireTime().DetermineRemainingDurationFrom(now);
|
||||||
|
}
|
||||||
|
|
||||||
|
Error Server::LeaseTracker::ProcessTtl(uint32_t aTtl)
|
||||||
|
{
|
||||||
|
// This method processes the TTL value received in a resource record.
|
||||||
|
//
|
||||||
|
// If no TTL value is stored, this method will set the stored value to @p aTtl and return `kErrorNone`.
|
||||||
|
// If a TTL value is stored and @p aTtl equals the stored value, this method returns `kErrorNone`.
|
||||||
|
// Otherwise, this method returns `kErrorRejected`.
|
||||||
|
|
||||||
|
Error error = kErrorRejected;
|
||||||
|
|
||||||
|
VerifyOrExit(aTtl && (mTtl == 0 || mTtl == aTtl));
|
||||||
|
|
||||||
|
mTtl = aTtl;
|
||||||
|
|
||||||
|
error = kErrorNone;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
// Server::Service
|
// Server::Service
|
||||||
|
|
||||||
@@ -1947,15 +1993,13 @@ Error Server::Service::Init(const char *aInstanceName, const char *aInstanceLabe
|
|||||||
{
|
{
|
||||||
Error error;
|
Error error;
|
||||||
|
|
||||||
|
LeaseTracker::Init(aUpdateTime);
|
||||||
|
|
||||||
mNext = nullptr;
|
mNext = nullptr;
|
||||||
mHost = &aHost;
|
mHost = &aHost;
|
||||||
mPriority = 0;
|
mPriority = 0;
|
||||||
mWeight = 0;
|
mWeight = 0;
|
||||||
mTtl = 0;
|
|
||||||
mPort = 0;
|
mPort = 0;
|
||||||
mLease = 0;
|
|
||||||
mKeyLease = 0;
|
|
||||||
mUpdateTime = aUpdateTime;
|
|
||||||
mIsDeleted = false;
|
mIsDeleted = false;
|
||||||
mIsCommitted = false;
|
mIsCommitted = false;
|
||||||
#if OPENTHREAD_CONFIG_SRP_SERVER_ADVERTISING_PROXY_ENABLE
|
#if OPENTHREAD_CONFIG_SRP_SERVER_ADVERTISING_PROXY_ENABLE
|
||||||
@@ -2014,34 +2058,6 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeMilli Server::Service::GetExpireTime(void) const
|
|
||||||
{
|
|
||||||
OT_ASSERT(!mIsDeleted);
|
|
||||||
OT_ASSERT(!GetHost().IsDeleted());
|
|
||||||
|
|
||||||
return mUpdateTime + Time::SecToMsec(mLease);
|
|
||||||
}
|
|
||||||
|
|
||||||
TimeMilli Server::Service::GetKeyExpireTime(void) const { return mUpdateTime + Time::SecToMsec(mKeyLease); }
|
|
||||||
|
|
||||||
void Server::Service::GetLeaseInfo(LeaseInfo &aLeaseInfo) const
|
|
||||||
{
|
|
||||||
TimeMilli now = TimerMilli::GetNow();
|
|
||||||
|
|
||||||
aLeaseInfo.mLease = Time::SecToMsec(GetLease());
|
|
||||||
aLeaseInfo.mKeyLease = Time::SecToMsec(GetKeyLease());
|
|
||||||
aLeaseInfo.mRemainingKeyLease = GetKeyExpireTime().DetermineRemainingDurationFrom(now);
|
|
||||||
|
|
||||||
if (!mIsDeleted)
|
|
||||||
{
|
|
||||||
aLeaseInfo.mRemainingLease = GetExpireTime().DetermineRemainingDurationFrom(now);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
aLeaseInfo.mRemainingLease = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Server::Service::MatchesInstanceName(const char *aInstanceName) const { return Matches(aInstanceName); }
|
bool Server::Service::MatchesInstanceName(const char *aInstanceName) const { return Matches(aInstanceName); }
|
||||||
|
|
||||||
bool Server::Service::MatchesServiceName(const char *aServiceName) const
|
bool Server::Service::MatchesServiceName(const char *aServiceName) const
|
||||||
@@ -2129,10 +2145,6 @@ exit:
|
|||||||
Server::Host::Host(Instance &aInstance, TimeMilli aUpdateTime)
|
Server::Host::Host(Instance &aInstance, TimeMilli aUpdateTime)
|
||||||
: InstanceLocator(aInstance)
|
: InstanceLocator(aInstance)
|
||||||
, mNext(nullptr)
|
, mNext(nullptr)
|
||||||
, mTtl(0)
|
|
||||||
, mLease(0)
|
|
||||||
, mKeyLease(0)
|
|
||||||
, mUpdateTime(aUpdateTime)
|
|
||||||
, mParsedKey(false)
|
, mParsedKey(false)
|
||||||
, mUseShortLeaseOption(false)
|
, mUseShortLeaseOption(false)
|
||||||
#if OPENTHREAD_CONFIG_SRP_SERVER_ADVERTISING_PROXY_ENABLE
|
#if OPENTHREAD_CONFIG_SRP_SERVER_ADVERTISING_PROXY_ENABLE
|
||||||
@@ -2145,6 +2157,7 @@ Server::Host::Host(Instance &aInstance, TimeMilli aUpdateTime)
|
|||||||
, mKeyAdvId(kInvalidRequestId)
|
, mKeyAdvId(kInvalidRequestId)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
LeaseTracker::Init(aUpdateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
Server::Host::~Host(void) { FreeAllServices(); }
|
Server::Host::~Host(void) { FreeAllServices(); }
|
||||||
@@ -2174,53 +2187,6 @@ bool Server::Host::Matches(const char *aFullName) const
|
|||||||
return StringMatch(mFullName.AsCString(), aFullName, kStringCaseInsensitiveMatch);
|
return StringMatch(mFullName.AsCString(), aFullName, kStringCaseInsensitiveMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeMilli Server::Host::GetExpireTime(void) const
|
|
||||||
{
|
|
||||||
OT_ASSERT(!IsDeleted());
|
|
||||||
|
|
||||||
return mUpdateTime + Time::SecToMsec(mLease);
|
|
||||||
}
|
|
||||||
|
|
||||||
TimeMilli Server::Host::GetKeyExpireTime(void) const { return mUpdateTime + Time::SecToMsec(mKeyLease); }
|
|
||||||
|
|
||||||
void Server::Host::GetLeaseInfo(LeaseInfo &aLeaseInfo) const
|
|
||||||
{
|
|
||||||
TimeMilli now = TimerMilli::GetNow();
|
|
||||||
|
|
||||||
aLeaseInfo.mLease = Time::SecToMsec(GetLease());
|
|
||||||
aLeaseInfo.mKeyLease = Time::SecToMsec(GetKeyLease());
|
|
||||||
aLeaseInfo.mRemainingKeyLease = GetKeyExpireTime().DetermineRemainingDurationFrom(now);
|
|
||||||
|
|
||||||
if (!IsDeleted())
|
|
||||||
{
|
|
||||||
aLeaseInfo.mRemainingLease = GetExpireTime().DetermineRemainingDurationFrom(now);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
aLeaseInfo.mRemainingLease = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Error Server::Host::ProcessTtl(uint32_t aTtl)
|
|
||||||
{
|
|
||||||
// This method processes the TTL value received in a resource record.
|
|
||||||
//
|
|
||||||
// If no TTL value is stored, this method will set the stored value to @p aTtl and return `kErrorNone`.
|
|
||||||
// If a TTL value is stored and @p aTtl equals the stored value, this method returns `kErrorNone`.
|
|
||||||
// Otherwise, this method returns `kErrorRejected`.
|
|
||||||
|
|
||||||
Error error = kErrorRejected;
|
|
||||||
|
|
||||||
VerifyOrExit(aTtl && (mTtl == 0 || mTtl == aTtl));
|
|
||||||
|
|
||||||
mTtl = aTtl;
|
|
||||||
|
|
||||||
error = kErrorNone;
|
|
||||||
|
|
||||||
exit:
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Server::Service *Server::Host::GetNextService(const Service *aPrevService) const
|
const Server::Service *Server::Host::GetNextService(const Service *aPrevService) const
|
||||||
{
|
{
|
||||||
return (aPrevService == nullptr) ? mServices.GetHead() : aPrevService->GetNext();
|
return (aPrevService == nullptr) ? mServices.GetHead() : aPrevService->GetNext();
|
||||||
@@ -2252,11 +2218,11 @@ void Server::Host::RemoveService(Service *aService, RetainName aRetainName, Noti
|
|||||||
VerifyOrExit(aService != nullptr);
|
VerifyOrExit(aService != nullptr);
|
||||||
|
|
||||||
aService->mIsDeleted = true;
|
aService->mIsDeleted = true;
|
||||||
aService->mLease = 0;
|
aService->SetLease(0);
|
||||||
|
|
||||||
if (!aRetainName)
|
if (!aRetainName)
|
||||||
{
|
{
|
||||||
aService->mKeyLease = 0;
|
aService->SetKeyLease(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
aService->Log(aRetainName ? Service::kRemoveButRetainName : Service::kFullyRemove);
|
aService->Log(aRetainName ? Service::kRemoveButRetainName : Service::kFullyRemove);
|
||||||
|
|||||||
+67
-99
@@ -177,10 +177,75 @@ public:
|
|||||||
kStateStopped = OT_SRP_SERVER_STATE_STOPPED, ///< Server is enabled but stopped.
|
kStateStopped = OT_SRP_SERVER_STATE_STOPPED, ///< Server is enabled but stopped.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for `Host` and `Service`, tracking lease, key-lease, and expiration times.
|
||||||
|
*/
|
||||||
|
class LeaseTracker
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Returns the LEASE time.
|
||||||
|
*
|
||||||
|
* @returns The LEASE time in seconds.
|
||||||
|
*/
|
||||||
|
uint32_t GetLease(void) const { return mLease; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the KEY-LEASE time.
|
||||||
|
*
|
||||||
|
* @returns The KEY-LEASE time in seconds.
|
||||||
|
*/
|
||||||
|
uint32_t GetKeyLease(void) const { return mKeyLease; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the TTL.
|
||||||
|
*
|
||||||
|
* @returns The TTL.
|
||||||
|
*/
|
||||||
|
uint32_t GetTtl(void) const { return mTtl; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the expire time.
|
||||||
|
*
|
||||||
|
* @returns The expire time
|
||||||
|
*/
|
||||||
|
TimeMilli GetExpireTime(void) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the key expire time.
|
||||||
|
*
|
||||||
|
* @returns The service key expire time.
|
||||||
|
*/
|
||||||
|
TimeMilli GetKeyExpireTime(void) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the LEASE and KEY-LEASE information.
|
||||||
|
*
|
||||||
|
* @param[out] aLeaseInfo A reference to a LeaseInfo instance to populate
|
||||||
|
*/
|
||||||
|
void GetLeaseInfo(LeaseInfo &aLeaseInfo) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
LeaseTracker(void) = default;
|
||||||
|
|
||||||
|
void Init(TimeMilli aUpdateTime);
|
||||||
|
void SetTtl(uint32_t aTtl) { mTtl = aTtl; }
|
||||||
|
void SetLease(uint32_t aLease) { mLease = aLease; }
|
||||||
|
void SetKeyLease(uint32_t aKeyLease) { mKeyLease = aKeyLease; }
|
||||||
|
Error ProcessTtl(uint32_t aTtl);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t mLease;
|
||||||
|
uint32_t mKeyLease;
|
||||||
|
uint32_t mTtl;
|
||||||
|
TimeMilli mUpdateTime;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements a server-side SRP service.
|
* Implements a server-side SRP service.
|
||||||
*/
|
*/
|
||||||
class Service : public otSrpServerService,
|
class Service : public otSrpServerService,
|
||||||
|
public LeaseTracker,
|
||||||
public LinkedListEntry<Service>,
|
public LinkedListEntry<Service>,
|
||||||
private Heap::Allocatable<Service>,
|
private Heap::Allocatable<Service>,
|
||||||
private NonCopyable
|
private NonCopyable
|
||||||
@@ -268,13 +333,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
static Error ParseSubTypeServiceName(const char *aSubTypeServiceName, char *aLabel, uint8_t aLabelSize);
|
static Error ParseSubTypeServiceName(const char *aSubTypeServiceName, char *aLabel, uint8_t aLabelSize);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the TTL of the service instance.
|
|
||||||
*
|
|
||||||
* @returns The TTL of the service instance.
|
|
||||||
*/
|
|
||||||
uint32_t GetTtl(void) const { return mTtl; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the port of the service instance.
|
* Returns the port of the service instance.
|
||||||
*
|
*
|
||||||
@@ -317,42 +375,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
const Host &GetHost(void) const { return *mHost; }
|
const Host &GetHost(void) const { return *mHost; }
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the LEASE time of the service.
|
|
||||||
*
|
|
||||||
* @returns The LEASE time in seconds.
|
|
||||||
*/
|
|
||||||
uint32_t GetLease(void) const { return mLease; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the KEY-LEASE time of the key of the service.
|
|
||||||
*
|
|
||||||
* @returns The KEY-LEASE time in seconds.
|
|
||||||
*/
|
|
||||||
uint32_t GetKeyLease(void) const { return mKeyLease; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the expire time (in milliseconds) of the service.
|
|
||||||
*
|
|
||||||
* @returns The service expire time in milliseconds.
|
|
||||||
*/
|
|
||||||
TimeMilli GetExpireTime(void) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the key expire time (in milliseconds) of the service.
|
|
||||||
*
|
|
||||||
* @returns The service key expire time in milliseconds.
|
|
||||||
*/
|
|
||||||
TimeMilli GetKeyExpireTime(void) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the LEASE and KEY-LEASE information of a given service.
|
|
||||||
*
|
|
||||||
* @param[out] aLeaseInfo A reference to a LeaseInfo instance. It contains the LEASE time, KEY-LEASE time,
|
|
||||||
* remaining LEASE time and the remaining KEY-LEASE time.
|
|
||||||
*/
|
|
||||||
void GetLeaseInfo(LeaseInfo &aLeaseInfo) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether this service matches a given service instance name.
|
* Indicates whether this service matches a given service instance name.
|
||||||
*
|
*
|
||||||
@@ -406,10 +428,6 @@ public:
|
|||||||
uint16_t mPriority;
|
uint16_t mPriority;
|
||||||
uint16_t mWeight;
|
uint16_t mWeight;
|
||||||
uint16_t mPort;
|
uint16_t mPort;
|
||||||
uint32_t mTtl; // In seconds
|
|
||||||
uint32_t mLease; // In seconds
|
|
||||||
uint32_t mKeyLease; // In seconds
|
|
||||||
TimeMilli mUpdateTime;
|
|
||||||
bool mIsDeleted : 1;
|
bool mIsDeleted : 1;
|
||||||
bool mIsCommitted : 1;
|
bool mIsCommitted : 1;
|
||||||
bool mParsedDeleteAllRrset : 1;
|
bool mParsedDeleteAllRrset : 1;
|
||||||
@@ -431,6 +449,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class Host : public otSrpServerHost,
|
class Host : public otSrpServerHost,
|
||||||
public InstanceLocator,
|
public InstanceLocator,
|
||||||
|
public LeaseTracker,
|
||||||
public LinkedListEntry<Host>,
|
public LinkedListEntry<Host>,
|
||||||
private Heap::Allocatable<Host>,
|
private Heap::Allocatable<Host>,
|
||||||
private NonCopyable
|
private NonCopyable
|
||||||
@@ -451,7 +470,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @returns TRUE if the host is deleted, FALSE if the host is not deleted.
|
* @returns TRUE if the host is deleted, FALSE if the host is not deleted.
|
||||||
*/
|
*/
|
||||||
bool IsDeleted(void) const { return (mLease == 0); }
|
bool IsDeleted(void) const { return (GetLease() == 0); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the full name of the host.
|
* Returns the full name of the host.
|
||||||
@@ -474,35 +493,6 @@ public:
|
|||||||
return mAddresses.AsCArray();
|
return mAddresses.AsCArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the TTL of the host.
|
|
||||||
*
|
|
||||||
* @returns The TTL of the host.
|
|
||||||
*/
|
|
||||||
uint32_t GetTtl(void) const { return mTtl; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the LEASE time of the host.
|
|
||||||
*
|
|
||||||
* @returns The LEASE time in seconds.
|
|
||||||
*/
|
|
||||||
uint32_t GetLease(void) const { return mLease; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the KEY-LEASE time of the key of the host.
|
|
||||||
*
|
|
||||||
* @returns The KEY-LEASE time in seconds.
|
|
||||||
*/
|
|
||||||
uint32_t GetKeyLease(void) const { return mKeyLease; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the LEASE and KEY-LEASE information of a given host.
|
|
||||||
*
|
|
||||||
* @param[out] aLeaseInfo A reference to a LeaseInfo instance. It contains the LEASE time, KEY-LEASE time,
|
|
||||||
* remaining LEASE time and the remaining KEY-LEASE time.
|
|
||||||
*/
|
|
||||||
void GetLeaseInfo(LeaseInfo &aLeaseInfo) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the key associated with this host.
|
* Returns the key associated with this host.
|
||||||
*
|
*
|
||||||
@@ -510,20 +500,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
const Key &GetKey(void) const { return mKey; }
|
const Key &GetKey(void) const { return mKey; }
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the expire time (in milliseconds) of the host.
|
|
||||||
*
|
|
||||||
* @returns The expire time in milliseconds.
|
|
||||||
*/
|
|
||||||
TimeMilli GetExpireTime(void) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the expire time (in milliseconds) of the key of the host.
|
|
||||||
*
|
|
||||||
* @returns The expire time of the key in milliseconds.
|
|
||||||
*/
|
|
||||||
TimeMilli GetKeyExpireTime(void) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the `Service` linked list associated with the host.
|
* Returns the `Service` linked list associated with the host.
|
||||||
*
|
*
|
||||||
@@ -554,12 +530,8 @@ public:
|
|||||||
~Host(void);
|
~Host(void);
|
||||||
|
|
||||||
Error SetFullName(const char *aFullName);
|
Error SetFullName(const char *aFullName);
|
||||||
void SetTtl(uint32_t aTtl) { mTtl = aTtl; }
|
|
||||||
void SetLease(uint32_t aLease) { mLease = aLease; }
|
|
||||||
void SetKeyLease(uint32_t aKeyLease) { mKeyLease = aKeyLease; }
|
|
||||||
void SetUseShortLeaseOption(bool aUse) { mUseShortLeaseOption = aUse; }
|
void SetUseShortLeaseOption(bool aUse) { mUseShortLeaseOption = aUse; }
|
||||||
bool ShouldUseShortLeaseOption(void) const { return mUseShortLeaseOption; }
|
bool ShouldUseShortLeaseOption(void) const { return mUseShortLeaseOption; }
|
||||||
Error ProcessTtl(uint32_t aTtl);
|
|
||||||
|
|
||||||
Service *AddNewService(const char *aInstanceName, const char *aInstanceLabel, TimeMilli aUpdateTime);
|
Service *AddNewService(const char *aInstanceName, const char *aInstanceLabel, TimeMilli aUpdateTime);
|
||||||
void AddService(Service &aService);
|
void AddService(Service &aService);
|
||||||
@@ -575,10 +547,6 @@ public:
|
|||||||
Heap::String mFullName;
|
Heap::String mFullName;
|
||||||
Heap::Array<Ip6::Address> mAddresses;
|
Heap::Array<Ip6::Address> mAddresses;
|
||||||
Key mKey;
|
Key mKey;
|
||||||
uint32_t mTtl; // The TTL in seconds.
|
|
||||||
uint32_t mLease; // The LEASE time in seconds.
|
|
||||||
uint32_t mKeyLease; // The KEY-LEASE time in seconds.
|
|
||||||
TimeMilli mUpdateTime;
|
|
||||||
LinkedList<Service> mServices;
|
LinkedList<Service> mServices;
|
||||||
bool mParsedKey : 1;
|
bool mParsedKey : 1;
|
||||||
bool mUseShortLeaseOption : 1; // Use short lease option (lease only 4 bytes).
|
bool mUseShortLeaseOption : 1; // Use short lease option (lease only 4 bytes).
|
||||||
|
|||||||
Reference in New Issue
Block a user