mirror of
https://github.com/espressif/openthread.git
synced 2026-09-18 15:10:12 +00:00
[dns-client] service discovery (DNS-SD) support and enhancements (#6116)
This commit re-designs the `Dns::Client` module enhancing the address resolution implementation and also adding support for DNS-Based Service Discovery (DNS-SD). With regards to address resolution query the new model relaxes the requirements of the public OT APIs such that caller does not need to persist the query info (e.g., the host name string buffer can be a temporary variable and does not need to persist during the query) and it is all managed by the `Dns::Client` core implementation itself. The new model also supports the case where the response contains multiple IPv6 addresses providing new APIs to allow the user to iterate through the list of addresses and retrieve them one by one. The implementation also handles the case where the DNS query response contains CNAME record mapping the queried host name to a canonical name for which a list of addresses are then provided. The core implementation is also simplified, instead of cloning a query message and saving it for possible retx, the new code saves the query related info from which it can re-construct the query message for retx if/when needed. This commit also adds support for DNS-SD in `Dns::Client`. The config `OPENTHREAD_CONFIG_DNS_CLIENT_SERVICE_DISCOVERY_ENABLE` can be used to disable service discovery feature. The implementation supports "service instance enumeration" which is referred to as "browsing" and "service instance resolution". Callbacks are used to notify the user when a response is received. In the callback a pointer to an opaque response object is given to the user which can then be used with the new set of APIs to get more info about the response, such as the list of discovered service instances or more details about a specific service instance (e.g., port number, host name and its address) or iterate through address lists. This provides a flexible and scalable solution to handle larger lists in the response without adding memory overhead in the implementation.
This commit is contained in:
committed by
Jonathan Hui
parent
159efe77c0
commit
7084422a0e
@@ -42,9 +42,8 @@ void TestDnsName(void)
|
||||
{
|
||||
enum
|
||||
{
|
||||
kMaxSize = 300,
|
||||
kLabelSize = 64,
|
||||
kNameSize = 256,
|
||||
kMaxSize = 300,
|
||||
kMaxNameLength = Dns::Name::kMaxNameSize - 1,
|
||||
};
|
||||
|
||||
struct TestName
|
||||
@@ -62,9 +61,9 @@ void TestDnsName(void)
|
||||
uint8_t buffer[kMaxSize];
|
||||
uint16_t len;
|
||||
uint16_t offset;
|
||||
char label[kLabelSize];
|
||||
char label[Dns::Name::kMaxLabelSize];
|
||||
uint8_t labelLength;
|
||||
char name[kNameSize];
|
||||
char name[Dns::Name::kMaxNameSize];
|
||||
|
||||
static const uint8_t kEncodedName1[] = {7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'c', 'o', 'm', 0};
|
||||
static const uint8_t kEncodedName2[] = {3, 'f', 'o', 'o', 1, 'a', 2, 'b', 'b', 3, 'e', 'd', 'u', 0};
|
||||
@@ -297,11 +296,11 @@ void TestDnsName(void)
|
||||
{
|
||||
if (maxLengthName[strlen(maxLengthName) - 1] == '.')
|
||||
{
|
||||
VerifyOrQuit(strlen(maxLengthName) == Dns::Name::kMaxLength, "invalid max length string");
|
||||
VerifyOrQuit(strlen(maxLengthName) == kMaxNameLength, "invalid max length string");
|
||||
}
|
||||
else
|
||||
{
|
||||
VerifyOrQuit(strlen(maxLengthName) == Dns::Name::kMaxLength - 1, "invalid max length string");
|
||||
VerifyOrQuit(strlen(maxLengthName) == kMaxNameLength - 1, "invalid max length string");
|
||||
}
|
||||
|
||||
IgnoreError(message->SetLength(0));
|
||||
@@ -742,8 +741,8 @@ void TestHeaderAndResourceRecords(void)
|
||||
Dns::ResourceRecord record;
|
||||
Ip6::Address hostAddress;
|
||||
|
||||
char label[Dns::Name::kMaxLabelLength + 1];
|
||||
char name[Dns::Name::kMaxLength];
|
||||
char label[Dns::Name::kMaxLabelSize];
|
||||
char name[Dns::Name::kMaxNameSize];
|
||||
uint8_t buffer[kMaxSize];
|
||||
|
||||
printf("================================================================\n");
|
||||
|
||||
Reference in New Issue
Block a user