From 285e01a31ebea4ec13457557f12a07f3ad6f4ad2 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 8 Feb 2024 09:56:55 -0500 Subject: [PATCH] Add files from `src/lib/dnssd` to be tracked by BUILD.gn files (#31976) * Make sure dnssd constants and browsedelegate is tracked by gn * Add more minmdns sources to be known to gn * Move more things into Types to make sure that platform Dnssd knows about them * Fix system layer dependency in linux dnssd impl * Remove dnssd files from lint * Add Delegate to Types as well ... it seems required for platform * Remove duplicate source * Restyle --------- Co-authored-by: Andrei Litvin --- .github/workflows/lint.yml | 6 - src/app/server/BUILD.gn | 1 + src/lib/dnssd/BUILD.gn | 41 ++- src/lib/dnssd/Resolver.h | 303 +------------------ src/lib/dnssd/ServiceNaming.h | 2 +- src/lib/dnssd/Types.h | 337 ++++++++++++++++++++++ src/lib/dnssd/minimal_mdns/BUILD.gn | 1 + src/lib/dnssd/minimal_mdns/core/BUILD.gn | 2 + src/lib/dnssd/minimal_mdns/tests/BUILD.gn | 2 + src/platform/Linux/DnssdImpl.h | 3 +- 10 files changed, 386 insertions(+), 312 deletions(-) create mode 100644 src/lib/dnssd/Types.h diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 46716422048bd3..f889f9a637a371 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -158,12 +158,6 @@ jobs: --known-failure app/WriteHandler.h \ --known-failure inet/tests/TestInetLayerCommon.hpp \ --known-failure lib/core/CHIPVendorIdentifiers.hpp \ - --known-failure lib/dnssd/Constants.h \ - --known-failure lib/dnssd/minimal_mdns/core/FlatAllocatedQName.h \ - --known-failure lib/dnssd/minimal_mdns/core/HeapQName.h \ - --known-failure lib/dnssd/minimal_mdns/ListenIterator.h \ - --known-failure lib/dnssd/minimal_mdns/tests/CheckOnlyServer.h \ - --known-failure lib/dnssd/platform/DnssdBrowseDelegate.h \ --known-failure lib/support/CHIPArgParser.hpp \ --known-failure messaging/tests/echo/common.h \ --known-failure platform/DeviceSafeQueue.cpp \ diff --git a/src/app/server/BUILD.gn b/src/app/server/BUILD.gn index 7e441518c9b133..4d63afda77ad42 100644 --- a/src/app/server/BUILD.gn +++ b/src/app/server/BUILD.gn @@ -55,6 +55,7 @@ static_library("server") { "${chip_root}/src/app/icd/server:observer", "${chip_root}/src/lib/address_resolve", "${chip_root}/src/lib/dnssd", + "${chip_root}/src/lib/dnssd:naming", "${chip_root}/src/messaging", "${chip_root}/src/platform", "${chip_root}/src/protocols", diff --git a/src/lib/dnssd/BUILD.gn b/src/lib/dnssd/BUILD.gn index 1561a395aa28f9..405c499b18d14e 100644 --- a/src/lib/dnssd/BUILD.gn +++ b/src/lib/dnssd/BUILD.gn @@ -16,13 +16,50 @@ import("//build_overrides/chip.gni") import("//build_overrides/nlunit_test.gni") import("${chip_root}/src/platform/device.gni") +source_set("constants") { + sources = [ "Constants.h" ] + + public_deps = [ "${chip_root}/src/lib/support" ] +} + +source_set("types") { + sources = [ "Types.h" ] +} + +source_set("naming") { + sources = [ + "ServiceNaming.cpp", + "ServiceNaming.h", + ] + + public_deps = [ + ":constants", + ":types", + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/core:error", + "${chip_root}/src/lib/support:span", + ] +} + source_set("platform_header") { - sources = [ "platform/Dnssd.h" ] + sources = [ + "platform/Dnssd.h", + "platform/DnssdBrowseDelegate.h", + ] + public_deps = [ + ":constants", + ":naming", + "${chip_root}/src/inet", + "${chip_root}/src/lib/core", + "${chip_root}/src/system", + ] } static_library("dnssd") { public_deps = [ + ":constants", ":platform_header", + ":types", "${chip_root}/src/app/icd/server:icd-server-config", "${chip_root}/src/crypto", "${chip_root}/src/lib/core", @@ -37,8 +74,6 @@ static_library("dnssd") { "Resolver.h", "ResolverProxy.cpp", "ResolverProxy.h", - "ServiceNaming.cpp", - "ServiceNaming.h", "TxtFields.cpp", "TxtFields.h", ] diff --git a/src/lib/dnssd/Resolver.h b/src/lib/dnssd/Resolver.h index 03e68e22df0c4a..d2541205bafd6d 100644 --- a/src/lib/dnssd/Resolver.h +++ b/src/lib/dnssd/Resolver.h @@ -21,7 +21,6 @@ #include #include -#include "lib/support/logging/CHIPLogging.h" #include #include #include @@ -30,295 +29,13 @@ #include #include #include -#include -#include +#include +#include namespace chip { namespace Dnssd { /// Node resolution data common to both operational and commissionable discovery -struct CommonResolutionData -{ - static constexpr unsigned kMaxIPAddresses = CHIP_DEVICE_CONFIG_MAX_DISCOVERED_IP_ADDRESSES; - - Inet::InterfaceId interfaceId; - - size_t numIPs = 0; // number of valid IP addresses - Inet::IPAddress ipAddress[kMaxIPAddresses]; - - uint16_t port = 0; - char hostName[kHostNameMaxLength + 1] = {}; - bool supportsTcp = false; - Optional isICDOperatingAsLIT; - Optional mrpRetryIntervalIdle; - Optional mrpRetryIntervalActive; - Optional mrpRetryActiveThreshold; - - CommonResolutionData() { Reset(); } - - bool IsValid() const { return !IsHost("") && (numIPs > 0) && (ipAddress[0] != chip::Inet::IPAddress::Any); } - - ReliableMessageProtocolConfig GetRemoteMRPConfig() const - { - const ReliableMessageProtocolConfig defaultConfig = GetDefaultMRPConfig(); - return ReliableMessageProtocolConfig(GetMrpRetryIntervalIdle().ValueOr(defaultConfig.mIdleRetransTimeout), - GetMrpRetryIntervalActive().ValueOr(defaultConfig.mActiveRetransTimeout), - GetMrpRetryActiveThreshold().ValueOr(defaultConfig.mActiveThresholdTime)); - } - Optional GetMrpRetryIntervalIdle() const { return mrpRetryIntervalIdle; } - Optional GetMrpRetryIntervalActive() const { return mrpRetryIntervalActive; } - Optional GetMrpRetryActiveThreshold() const { return mrpRetryActiveThreshold; } - - bool IsDeviceTreatedAsSleepy(const ReliableMessageProtocolConfig * defaultMRPConfig) const - { - // If either sleepy interval (Idle - SII, Active - SAI) has a value and that value is greater - // than the value passed to this function, then the peer device will be treated as if it is - // a Sleepy End Device (SED) - return (mrpRetryIntervalIdle.HasValue() && (mrpRetryIntervalIdle.Value() > defaultMRPConfig->mIdleRetransTimeout)) || - (mrpRetryIntervalActive.HasValue() && (mrpRetryIntervalActive.Value() > defaultMRPConfig->mActiveRetransTimeout)); - } - - bool IsHost(const char * host) const { return strcmp(host, hostName) == 0; } - - void Reset() - { - memset(hostName, 0, sizeof(hostName)); - mrpRetryIntervalIdle = NullOptional; - mrpRetryIntervalActive = NullOptional; - mrpRetryActiveThreshold = NullOptional; - isICDOperatingAsLIT = NullOptional; - numIPs = 0; - port = 0; - supportsTcp = false; - interfaceId = Inet::InterfaceId::Null(); - for (auto & addr : ipAddress) - { - addr = chip::Inet::IPAddress::Any; - } - } - - void LogDetail() const - { - if (!IsHost("")) - { - ChipLogDetail(Discovery, "\tHostname: %s", hostName); - } -#if CHIP_DETAIL_LOGGING - for (unsigned j = 0; j < numIPs; j++) - { - char buf[Inet::IPAddress::kMaxStringLength]; - char * ipAddressOut = ipAddress[j].ToString(buf); - ChipLogDetail(Discovery, "\tIP Address #%d: %s", j + 1, ipAddressOut); - } -#endif // CHIP_DETAIL_LOGGING - if (port > 0) - { - ChipLogDetail(Discovery, "\tPort: %u", port); - } - if (mrpRetryIntervalIdle.HasValue()) - { - ChipLogDetail(Discovery, "\tMrp Interval idle: %" PRIu32 " ms", mrpRetryIntervalIdle.Value().count()); - } - else - { - ChipLogDetail(Discovery, "\tMrp Interval idle: not present"); - } - if (mrpRetryIntervalActive.HasValue()) - { - ChipLogDetail(Discovery, "\tMrp Interval active: %" PRIu32 " ms", mrpRetryIntervalActive.Value().count()); - } - else - { - ChipLogDetail(Discovery, "\tMrp Interval active: not present"); - } - if (mrpRetryActiveThreshold.HasValue()) - { - ChipLogDetail(Discovery, "\tMrp Active Threshold: %u ms", mrpRetryActiveThreshold.Value().count()); - } - else - { - ChipLogDetail(Discovery, "\tMrp Active Threshold: not present"); - } - ChipLogDetail(Discovery, "\tTCP Supported: %d", supportsTcp); - if (isICDOperatingAsLIT.HasValue()) - { - ChipLogDetail(Discovery, "\tThe ICD operates in %s", isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); - } - else - { - ChipLogDetail(Discovery, "\tICD: not present"); - } - } -}; - -/// Data that is specific to Operational Discovery of nodes -struct OperationalNodeData -{ - PeerId peerId; - - void Reset() { peerId = PeerId(); } -}; - -inline constexpr size_t kMaxDeviceNameLen = 32; -inline constexpr size_t kMaxRotatingIdLen = 50; -inline constexpr size_t kMaxPairingInstructionLen = 128; - -/// Data that is specific to commisionable/commissioning node discovery -struct CommissionNodeData -{ - char instanceName[Commission::kInstanceNameMaxLength + 1] = {}; - uint16_t longDiscriminator = 0; - uint16_t vendorId = 0; - uint16_t productId = 0; - uint8_t commissioningMode = 0; - uint32_t deviceType = 0; - char deviceName[kMaxDeviceNameLen + 1] = {}; - uint8_t rotatingId[kMaxRotatingIdLen] = {}; - size_t rotatingIdLen = 0; - uint16_t pairingHint = 0; - char pairingInstruction[kMaxPairingInstructionLen + 1] = {}; - uint8_t commissionerPasscode = 0; - - CommissionNodeData() {} - - void Reset() - { - // Let constructor clear things as default - this->~CommissionNodeData(); - new (this) CommissionNodeData(); - } - - bool IsInstanceName(const char * instance) const { return strcmp(instance, instanceName) == 0; } - - void LogDetail() const - { - if (rotatingIdLen > 0) - { - char rotatingIdString[chip::Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(rotatingId, rotatingIdLen, rotatingIdString, sizeof(rotatingIdString)); - ChipLogDetail(Discovery, "\tRotating ID: %s", rotatingIdString); - } - if (strlen(deviceName) != 0) - { - ChipLogDetail(Discovery, "\tDevice Name: %s", deviceName); - } - if (vendorId > 0) - { - ChipLogDetail(Discovery, "\tVendor ID: %u", vendorId); - } - if (productId > 0) - { - ChipLogDetail(Discovery, "\tProduct ID: %u", productId); - } - if (deviceType > 0) - { - ChipLogDetail(Discovery, "\tDevice Type: %" PRIu32, deviceType); - } - if (longDiscriminator > 0) - { - ChipLogDetail(Discovery, "\tLong Discriminator: %u", longDiscriminator); - } - if (strlen(pairingInstruction) != 0) - { - ChipLogDetail(Discovery, "\tPairing Instruction: %s", pairingInstruction); - } - if (pairingHint > 0) - { - ChipLogDetail(Discovery, "\tPairing Hint: %u", pairingHint); - } - if (!IsInstanceName("")) - { - ChipLogDetail(Discovery, "\tInstance Name: %s", instanceName); - } - ChipLogDetail(Discovery, "\tCommissioning Mode: %u", commissioningMode); - if (commissionerPasscode > 0) - { - ChipLogDetail(Discovery, "\tCommissioner Passcode: %u", commissionerPasscode); - } - } -}; - -struct ResolvedNodeData -{ - CommonResolutionData resolutionData; - OperationalNodeData operationalData; - - void LogNodeIdResolved() const - { -#if CHIP_PROGRESS_LOGGING - // Would be nice to log the interface id, but sorting out how to do so - // across our different InterfaceId implementations is a pain. - ChipLogProgress(Discovery, "Node ID resolved for " ChipLogFormatX64 ":" ChipLogFormatX64, - ChipLogValueX64(operationalData.peerId.GetCompressedFabricId()), - ChipLogValueX64(operationalData.peerId.GetNodeId())); - resolutionData.LogDetail(); -#endif // CHIP_PROGRESS_LOGGING - } -}; - -struct DiscoveredNodeData -{ - CommonResolutionData resolutionData; - CommissionNodeData commissionData; - - void Reset() - { - resolutionData.Reset(); - commissionData.Reset(); - } - DiscoveredNodeData() { Reset(); } - - void LogDetail() const - { - ChipLogDetail(Discovery, "Discovered node:"); - resolutionData.LogDetail(); - commissionData.LogDetail(); - } -}; - -enum class DiscoveryFilterType : uint8_t -{ - kNone, - kShortDiscriminator, - kLongDiscriminator, - kVendorId, - kDeviceType, - kCommissioningMode, - kInstanceName, - kCommissioner, - kCompressedFabricId, -}; -struct DiscoveryFilter -{ - DiscoveryFilterType type; - uint64_t code = 0; - const char * instanceName = nullptr; - DiscoveryFilter() : type(DiscoveryFilterType::kNone), code(0) {} - DiscoveryFilter(const DiscoveryFilterType newType) : type(newType) {} - DiscoveryFilter(const DiscoveryFilterType newType, uint64_t newCode) : type(newType), code(newCode) {} - DiscoveryFilter(const DiscoveryFilterType newType, const char * newInstanceName) : type(newType), instanceName(newInstanceName) - {} - bool operator==(const DiscoveryFilter & other) const - { - if (type != other.type) - { - return false; - } - if (type == DiscoveryFilterType::kInstanceName) - { - return (instanceName != nullptr) && (other.instanceName != nullptr) && (strcmp(instanceName, other.instanceName) == 0); - } - - return code == other.code; - } -}; -enum class DiscoveryType -{ - kUnknown, - kOperational, - kCommissionableNode, - kCommissionerNode -}; /// Callbacks for resolving operational node resolution class OperationalResolveDelegate @@ -342,22 +59,6 @@ class OperationalResolveDelegate virtual void OnOperationalNodeResolutionFailed(const PeerId & peerId, CHIP_ERROR error) = 0; }; -/// Callbacks for discovering nodes advertising non-operational status: -/// - Commissioners -/// - Nodes in commissioning modes over IP (e.g. ethernet devices, devices already -/// connected to thread/wifi or devices with a commissioning window open) -class CommissioningResolveDelegate -{ -public: - virtual ~CommissioningResolveDelegate() = default; - - /// Called within the CHIP event loop once a node is discovered. - /// - /// May be called multiple times as more nodes send their answer to a - /// multicast discovery query - virtual void OnNodeDiscovered(const DiscoveredNodeData & nodeData) = 0; -}; - /** * Node discovery context class. * diff --git a/src/lib/dnssd/ServiceNaming.h b/src/lib/dnssd/ServiceNaming.h index 5f4c2e6c2ea948..1ea1105522fab9 100644 --- a/src/lib/dnssd/ServiceNaming.h +++ b/src/lib/dnssd/ServiceNaming.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/lib/dnssd/Types.h b/src/lib/dnssd/Types.h new file mode 100644 index 00000000000000..5d78c7631223cf --- /dev/null +++ b/src/lib/dnssd/Types.h @@ -0,0 +1,337 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace chip { +namespace Dnssd { + +enum class DiscoveryFilterType : uint8_t +{ + kNone, + kShortDiscriminator, + kLongDiscriminator, + kVendorId, + kDeviceType, + kCommissioningMode, + kInstanceName, + kCommissioner, + kCompressedFabricId, +}; + +struct DiscoveryFilter +{ + DiscoveryFilterType type; + uint64_t code = 0; + const char * instanceName = nullptr; + DiscoveryFilter() : type(DiscoveryFilterType::kNone), code(0) {} + DiscoveryFilter(const DiscoveryFilterType newType) : type(newType) {} + DiscoveryFilter(const DiscoveryFilterType newType, uint64_t newCode) : type(newType), code(newCode) {} + DiscoveryFilter(const DiscoveryFilterType newType, const char * newInstanceName) : type(newType), instanceName(newInstanceName) + {} + bool operator==(const DiscoveryFilter & other) const + { + if (type != other.type) + { + return false; + } + if (type == DiscoveryFilterType::kInstanceName) + { + return (instanceName != nullptr) && (other.instanceName != nullptr) && (strcmp(instanceName, other.instanceName) == 0); + } + + return code == other.code; + } +}; + +enum class DiscoveryType +{ + kUnknown, + kOperational, + kCommissionableNode, + kCommissionerNode +}; + +struct CommonResolutionData +{ + static constexpr unsigned kMaxIPAddresses = CHIP_DEVICE_CONFIG_MAX_DISCOVERED_IP_ADDRESSES; + + Inet::InterfaceId interfaceId; + + size_t numIPs = 0; // number of valid IP addresses + Inet::IPAddress ipAddress[kMaxIPAddresses]; + + uint16_t port = 0; + char hostName[kHostNameMaxLength + 1] = {}; + bool supportsTcp = false; + Optional isICDOperatingAsLIT; + Optional mrpRetryIntervalIdle; + Optional mrpRetryIntervalActive; + Optional mrpRetryActiveThreshold; + + CommonResolutionData() { Reset(); } + + bool IsValid() const { return !IsHost("") && (numIPs > 0) && (ipAddress[0] != chip::Inet::IPAddress::Any); } + + ReliableMessageProtocolConfig GetRemoteMRPConfig() const + { + const ReliableMessageProtocolConfig defaultConfig = GetDefaultMRPConfig(); + return ReliableMessageProtocolConfig(GetMrpRetryIntervalIdle().ValueOr(defaultConfig.mIdleRetransTimeout), + GetMrpRetryIntervalActive().ValueOr(defaultConfig.mActiveRetransTimeout), + GetMrpRetryActiveThreshold().ValueOr(defaultConfig.mActiveThresholdTime)); + } + Optional GetMrpRetryIntervalIdle() const { return mrpRetryIntervalIdle; } + Optional GetMrpRetryIntervalActive() const { return mrpRetryIntervalActive; } + Optional GetMrpRetryActiveThreshold() const { return mrpRetryActiveThreshold; } + + bool IsDeviceTreatedAsSleepy(const ReliableMessageProtocolConfig * defaultMRPConfig) const + { + // If either sleepy interval (Idle - SII, Active - SAI) has a value and that value is greater + // than the value passed to this function, then the peer device will be treated as if it is + // a Sleepy End Device (SED) + return (mrpRetryIntervalIdle.HasValue() && (mrpRetryIntervalIdle.Value() > defaultMRPConfig->mIdleRetransTimeout)) || + (mrpRetryIntervalActive.HasValue() && (mrpRetryIntervalActive.Value() > defaultMRPConfig->mActiveRetransTimeout)); + } + + bool IsHost(const char * host) const { return strcmp(host, hostName) == 0; } + + void Reset() + { + memset(hostName, 0, sizeof(hostName)); + mrpRetryIntervalIdle = NullOptional; + mrpRetryIntervalActive = NullOptional; + mrpRetryActiveThreshold = NullOptional; + isICDOperatingAsLIT = NullOptional; + numIPs = 0; + port = 0; + supportsTcp = false; + interfaceId = Inet::InterfaceId::Null(); + for (auto & addr : ipAddress) + { + addr = chip::Inet::IPAddress::Any; + } + } + + void LogDetail() const + { + if (!IsHost("")) + { + ChipLogDetail(Discovery, "\tHostname: %s", hostName); + } +#if CHIP_DETAIL_LOGGING + for (unsigned j = 0; j < numIPs; j++) + { + char buf[Inet::IPAddress::kMaxStringLength]; + char * ipAddressOut = ipAddress[j].ToString(buf); + ChipLogDetail(Discovery, "\tIP Address #%d: %s", j + 1, ipAddressOut); + } +#endif // CHIP_DETAIL_LOGGING + if (port > 0) + { + ChipLogDetail(Discovery, "\tPort: %u", port); + } + if (mrpRetryIntervalIdle.HasValue()) + { + ChipLogDetail(Discovery, "\tMrp Interval idle: %" PRIu32 " ms", mrpRetryIntervalIdle.Value().count()); + } + else + { + ChipLogDetail(Discovery, "\tMrp Interval idle: not present"); + } + if (mrpRetryIntervalActive.HasValue()) + { + ChipLogDetail(Discovery, "\tMrp Interval active: %" PRIu32 " ms", mrpRetryIntervalActive.Value().count()); + } + else + { + ChipLogDetail(Discovery, "\tMrp Interval active: not present"); + } + if (mrpRetryActiveThreshold.HasValue()) + { + ChipLogDetail(Discovery, "\tMrp Active Threshold: %u ms", mrpRetryActiveThreshold.Value().count()); + } + else + { + ChipLogDetail(Discovery, "\tMrp Active Threshold: not present"); + } + ChipLogDetail(Discovery, "\tTCP Supported: %d", supportsTcp); + if (isICDOperatingAsLIT.HasValue()) + { + ChipLogDetail(Discovery, "\tThe ICD operates in %s", isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); + } + else + { + ChipLogDetail(Discovery, "\tICD: not present"); + } + } +}; + +/// Data that is specific to Operational Discovery of nodes +struct OperationalNodeData +{ + PeerId peerId; + + void Reset() { peerId = PeerId(); } +}; + +inline constexpr size_t kMaxDeviceNameLen = 32; +inline constexpr size_t kMaxRotatingIdLen = 50; +inline constexpr size_t kMaxPairingInstructionLen = 128; + +/// Data that is specific to commisionable/commissioning node discovery +struct CommissionNodeData +{ + char instanceName[Commission::kInstanceNameMaxLength + 1] = {}; + uint16_t longDiscriminator = 0; + uint16_t vendorId = 0; + uint16_t productId = 0; + uint8_t commissioningMode = 0; + uint32_t deviceType = 0; + char deviceName[kMaxDeviceNameLen + 1] = {}; + uint8_t rotatingId[kMaxRotatingIdLen] = {}; + size_t rotatingIdLen = 0; + uint16_t pairingHint = 0; + char pairingInstruction[kMaxPairingInstructionLen + 1] = {}; + uint8_t commissionerPasscode = 0; + + CommissionNodeData() {} + + void Reset() + { + // Let constructor clear things as default + this->~CommissionNodeData(); + new (this) CommissionNodeData(); + } + + bool IsInstanceName(const char * instance) const { return strcmp(instance, instanceName) == 0; } + + void LogDetail() const + { + if (rotatingIdLen > 0) + { + char rotatingIdString[chip::Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; + Encoding::BytesToUppercaseHexString(rotatingId, rotatingIdLen, rotatingIdString, sizeof(rotatingIdString)); + ChipLogDetail(Discovery, "\tRotating ID: %s", rotatingIdString); + } + if (strlen(deviceName) != 0) + { + ChipLogDetail(Discovery, "\tDevice Name: %s", deviceName); + } + if (vendorId > 0) + { + ChipLogDetail(Discovery, "\tVendor ID: %u", vendorId); + } + if (productId > 0) + { + ChipLogDetail(Discovery, "\tProduct ID: %u", productId); + } + if (deviceType > 0) + { + ChipLogDetail(Discovery, "\tDevice Type: %" PRIu32, deviceType); + } + if (longDiscriminator > 0) + { + ChipLogDetail(Discovery, "\tLong Discriminator: %u", longDiscriminator); + } + if (strlen(pairingInstruction) != 0) + { + ChipLogDetail(Discovery, "\tPairing Instruction: %s", pairingInstruction); + } + if (pairingHint > 0) + { + ChipLogDetail(Discovery, "\tPairing Hint: %u", pairingHint); + } + if (!IsInstanceName("")) + { + ChipLogDetail(Discovery, "\tInstance Name: %s", instanceName); + } + ChipLogDetail(Discovery, "\tCommissioning Mode: %u", commissioningMode); + if (commissionerPasscode > 0) + { + ChipLogDetail(Discovery, "\tCommissioner Passcode: %u", commissionerPasscode); + } + } +}; + +struct ResolvedNodeData +{ + CommonResolutionData resolutionData; + OperationalNodeData operationalData; + + void LogNodeIdResolved() const + { +#if CHIP_PROGRESS_LOGGING + // Would be nice to log the interface id, but sorting out how to do so + // across our different InterfaceId implementations is a pain. + ChipLogProgress(Discovery, "Node ID resolved for " ChipLogFormatX64 ":" ChipLogFormatX64, + ChipLogValueX64(operationalData.peerId.GetCompressedFabricId()), + ChipLogValueX64(operationalData.peerId.GetNodeId())); + resolutionData.LogDetail(); +#endif // CHIP_PROGRESS_LOGGING + } +}; + +struct DiscoveredNodeData +{ + CommonResolutionData resolutionData; + CommissionNodeData commissionData; + + void Reset() + { + resolutionData.Reset(); + commissionData.Reset(); + } + DiscoveredNodeData() { Reset(); } + + void LogDetail() const + { + ChipLogDetail(Discovery, "Discovered node:"); + resolutionData.LogDetail(); + commissionData.LogDetail(); + } +}; + +/// Callbacks for discovering nodes advertising non-operational status: +/// - Commissioners +/// - Nodes in commissioning modes over IP (e.g. ethernet devices, devices already +/// connected to thread/wifi or devices with a commissioning window open) +class CommissioningResolveDelegate +{ +public: + virtual ~CommissioningResolveDelegate() = default; + + /// Called within the CHIP event loop once a node is discovered. + /// + /// May be called multiple times as more nodes send their answer to a + /// multicast discovery query + virtual void OnNodeDiscovered(const DiscoveredNodeData & nodeData) = 0; +}; + +} // namespace Dnssd +} // namespace chip diff --git a/src/lib/dnssd/minimal_mdns/BUILD.gn b/src/lib/dnssd/minimal_mdns/BUILD.gn index bf0ae8abef3ae4..af74ce381fa7fc 100644 --- a/src/lib/dnssd/minimal_mdns/BUILD.gn +++ b/src/lib/dnssd/minimal_mdns/BUILD.gn @@ -73,6 +73,7 @@ source_set("address_policy") { sources = [ "AddressPolicy.cpp", "AddressPolicy.h", + "ListenIterator.h", "ServerIPAddresses.h", ] diff --git a/src/lib/dnssd/minimal_mdns/core/BUILD.gn b/src/lib/dnssd/minimal_mdns/core/BUILD.gn index c0be6ef0680f9d..909f2c2df7c9a6 100644 --- a/src/lib/dnssd/minimal_mdns/core/BUILD.gn +++ b/src/lib/dnssd/minimal_mdns/core/BUILD.gn @@ -19,6 +19,8 @@ static_library("core") { "BytesRange.h", "Constants.h", "DnsHeader.h", + "FlatAllocatedQName.h", + "HeapQName.h", "QName.cpp", "QName.h", "QNameString.cpp", diff --git a/src/lib/dnssd/minimal_mdns/tests/BUILD.gn b/src/lib/dnssd/minimal_mdns/tests/BUILD.gn index bea28e8b95e50e..8d99854046e307 100644 --- a/src/lib/dnssd/minimal_mdns/tests/BUILD.gn +++ b/src/lib/dnssd/minimal_mdns/tests/BUILD.gn @@ -22,6 +22,8 @@ import("${chip_root}/build/chip/fuzz_test.gni") chip_test_suite_using_nltest("tests") { output_name = "libMinimalMdnstests" + sources = [ "CheckOnlyServer.h" ] + test_sources = [ "TestMinimalMdnsAllocator.cpp", "TestQueryReplyFilter.cpp", diff --git a/src/platform/Linux/DnssdImpl.h b/src/platform/Linux/DnssdImpl.h index 483ac50d9128a0..c66a8c23f700b6 100644 --- a/src/platform/Linux/DnssdImpl.h +++ b/src/platform/Linux/DnssdImpl.h @@ -35,7 +35,8 @@ #include #include -#include "lib/dnssd/platform/Dnssd.h" +#include +#include struct AvahiWatch {