mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 22:27:47 +00:00
[srp-server] allow any number of host addresses (use Heap::Array) (#7420)
This commit changes the `Srp::Server` definition to use `Heap::Array` to store the list of IPv6 addresses associated with a given `Host`. This makes the array length dynamic and removes the need for specifying a hard limit on the number of addresses and allow us to remove `OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM` config.
This commit is contained in:
committed by
Jonathan Hui
parent
4b31f57014
commit
9475bce07a
@@ -614,4 +614,9 @@
|
||||
#error "OPENTHREAD_CONFIG_LOG_PREPEND_REGION was removed and not longer supported"
|
||||
#endif
|
||||
|
||||
#ifdef OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM
|
||||
#error "OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM was removed. "\
|
||||
"SRP host uses dynamic heap array to store addresses so no need for config on max number of addresses".
|
||||
#endif
|
||||
|
||||
#endif // OPENTHREAD_CORE_CONFIG_CHECK_H_
|
||||
|
||||
@@ -109,14 +109,4 @@
|
||||
#define OPENTHREAD_CONFIG_SRP_SERVER_SERVICE_UPDATE_TIMEOUT ((4 * 250u) + 250u)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM
|
||||
*
|
||||
* Specifies the maximum number of addresses the SRP server can handle for a host.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM
|
||||
#define OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM 2
|
||||
#endif
|
||||
|
||||
#endif // CONFIG_SRP_SERVER_H_
|
||||
|
||||
@@ -1797,7 +1797,7 @@ void Server::Host::FreeAllServices(void)
|
||||
|
||||
void Server::Host::ClearResources(void)
|
||||
{
|
||||
mAddresses.Clear();
|
||||
mAddresses.Free();
|
||||
}
|
||||
|
||||
Error Server::Host::MergeServicesAndResourcesFrom(Host &aHost)
|
||||
@@ -1810,7 +1810,7 @@ Error Server::Host::MergeServicesAndResourcesFrom(Host &aHost)
|
||||
|
||||
LogInfo("update host %s", GetFullName());
|
||||
|
||||
mAddresses = aHost.mAddresses;
|
||||
mAddresses.TakeFrom(static_cast<Heap::Array<Ip6::Address> &&>(aHost.mAddresses));
|
||||
mKeyRecord = aHost.mKeyRecord;
|
||||
mLease = aHost.mLease;
|
||||
mKeyLease = aHost.mKeyLease;
|
||||
|
||||
@@ -58,12 +58,14 @@
|
||||
#include "common/clearable.hpp"
|
||||
#include "common/heap.hpp"
|
||||
#include "common/heap_allocatable.hpp"
|
||||
#include "common/heap_array.hpp"
|
||||
#include "common/heap_data.hpp"
|
||||
#include "common/heap_string.hpp"
|
||||
#include "common/linked_list.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/non_copyable.hpp"
|
||||
#include "common/notifier.hpp"
|
||||
#include "common/numeric_limits.hpp"
|
||||
#include "common/retain_ptr.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "crypto/ecdsa.hpp"
|
||||
@@ -432,8 +434,8 @@ public:
|
||||
*/
|
||||
const Ip6::Address *GetAddresses(uint8_t &aAddressesNum) const
|
||||
{
|
||||
aAddressesNum = mAddresses.GetLength();
|
||||
return mAddresses.Front();
|
||||
aAddressesNum = static_cast<uint8_t>(OT_MIN(mAddresses.GetLength(), NumericLimits<uint8_t>::kMax));
|
||||
return mAddresses.AsCArray();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -512,8 +514,6 @@ public:
|
||||
bool Matches(const char *aFullName) const;
|
||||
|
||||
private:
|
||||
static constexpr uint16_t kMaxAddresses = OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM;
|
||||
|
||||
Host(Instance &aInstance, TimeMilli aUpdateTime);
|
||||
~Host(void);
|
||||
|
||||
@@ -537,9 +537,9 @@ public:
|
||||
Service * FindService(const char *aServiceName, const char *aInstanceName);
|
||||
const Service * FindService(const char *aServiceName, const char *aInstanceName) const;
|
||||
|
||||
Host * mNext;
|
||||
Heap::String mFullName;
|
||||
Array<Ip6::Address, kMaxAddresses> mAddresses;
|
||||
Host * mNext;
|
||||
Heap::String mFullName;
|
||||
Heap::Array<Ip6::Address> mAddresses;
|
||||
|
||||
// TODO(wgtdkp): there is no necessary to save the entire resource
|
||||
// record, saving only the ECDSA-256 public key should be enough.
|
||||
|
||||
Reference in New Issue
Block a user