diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index 1905361570f6f8..b2aec812597a88 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -237,7 +237,8 @@ void PairingCommand::OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData.resolutionData.ipAddress[0].ToString(buf); ChipLogProgress(chipTool, "Discovered Device: %s:%u", buf, port); - // Stop Mdns discovery. Is it the right method ? + // Stop Mdns discovery. + CurrentCommissioner().StopCommissionableDiscovery(); CurrentCommissioner().RegisterDeviceDiscoveryDelegate(nullptr); Inet::InterfaceId interfaceId = diff --git a/src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp b/src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp index d1ae4d1fc25be8..7cf0dde53f525e 100644 --- a/src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp +++ b/src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp @@ -125,6 +125,7 @@ CHIP_ERROR DiscoveryCommands::SetupDiscoveryCommands() CHIP_ERROR DiscoveryCommands::TearDownDiscoveryCommands() { + mDNSResolver.StopDiscovery(); mDNSResolver.SetOperationalDelegate(nullptr); mDNSResolver.SetCommissioningDelegate(nullptr); return CHIP_NO_ERROR; diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 7ac27332ee0f38..6b71c9fbbd9fcd 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1431,6 +1431,11 @@ CHIP_ERROR DeviceCommissioner::DiscoverCommissionableNodes(Dnssd::DiscoveryFilte return mDNSResolver.DiscoverCommissionableNodes(filter); } +CHIP_ERROR DeviceCommissioner::StopCommissionableDiscovery() +{ + return mDNSResolver.StopDiscovery(); +} + const Dnssd::DiscoveredNodeData * DeviceCommissioner::GetDiscoveredDevice(int idx) { return GetDiscoveredNode(idx); diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index 3b40612e6f4ae2..aa5e2936216604 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -597,6 +597,12 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, */ CHIP_ERROR DiscoverCommissionableNodes(Dnssd::DiscoveryFilter filter); + /** + * Stop commissionable discovery triggered by a previous + * DiscoverCommissionableNodes call. + */ + CHIP_ERROR StopCommissionableDiscovery(); + /** * @brief * Returns information about discovered devices. diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index ddd0f8fe6d01f6..3a7f218ea4821b 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -187,6 +187,8 @@ CHIP_ERROR SetUpCodePairer::StopConnectOverIP() mWaitingForDiscovery[kIPTransport] = false; currentFilter.type = Dnssd::DiscoveryFilterType::kNone; + + mCommissioner->StopCommissionableDiscovery(); return CHIP_NO_ERROR; } diff --git a/src/controller/tests/TestCommissionableNodeController.cpp b/src/controller/tests/TestCommissionableNodeController.cpp index 258be7225469c4..41d5663bafb0b6 100644 --- a/src/controller/tests/TestCommissionableNodeController.cpp +++ b/src/controller/tests/TestCommissionableNodeController.cpp @@ -42,6 +42,7 @@ class MockResolver : public Resolver { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR StopDiscovery() override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR InitStatus = CHIP_NO_ERROR; CHIP_ERROR ResolveNodeIdStatus = CHIP_NO_ERROR; diff --git a/src/lib/dnssd/ActiveResolveAttempts.cpp b/src/lib/dnssd/ActiveResolveAttempts.cpp index aa08abdb7deff2..9e458207aeb3f7 100644 --- a/src/lib/dnssd/ActiveResolveAttempts.cpp +++ b/src/lib/dnssd/ActiveResolveAttempts.cpp @@ -79,6 +79,19 @@ void ActiveResolveAttempts::CompleteIpResolution(SerializedQNameIterator targetH } } +CHIP_ERROR ActiveResolveAttempts::CompleteAllBrowses() +{ + for (auto & item : mRetryQueue) + { + if (item.attempt.IsBrowse()) + { + item.attempt.Clear(); + } + } + + return CHIP_NO_ERROR; +} + void ActiveResolveAttempts::MarkPending(const chip::PeerId & peerId) { MarkPending(ScheduledAttempt(peerId, /* firstSend */ true)); diff --git a/src/lib/dnssd/ActiveResolveAttempts.h b/src/lib/dnssd/ActiveResolveAttempts.h index 7ce121319ce3f2..6ba51cb151e7b5 100644 --- a/src/lib/dnssd/ActiveResolveAttempts.h +++ b/src/lib/dnssd/ActiveResolveAttempts.h @@ -204,6 +204,10 @@ class ActiveResolveAttempts void Complete(const chip::Dnssd::DiscoveredNodeData & data); void CompleteIpResolution(SerializedQNameIterator targetHostName); + /// Mark all browse-type scheduled attemptes as a success, removing them + /// from the internal list. + CHIP_ERROR CompleteAllBrowses(); + /// Mark that a resolution is pending, adding it to the internal list /// /// Once this complete, this peer id will be returned immediately diff --git a/src/lib/dnssd/Discovery_ImplPlatform.cpp b/src/lib/dnssd/Discovery_ImplPlatform.cpp index a7347122f6f20f..6a6bc64aea3e77 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.cpp +++ b/src/lib/dnssd/Discovery_ImplPlatform.cpp @@ -153,6 +153,14 @@ static void HandleNodeBrowse(void * context, DnssdService * services, size_t ser if (error != CHIP_NO_ERROR) { + // We don't have access to the ResolverProxy here to clear out its + // mDiscoveryContext. The underlying implementation of + // ChipDnssdStopBrowse needs to handle a possibly-stale reference + // safely, so this won't lead to crashes, but it can lead to + // mis-behavior if a stale mDiscoveryContext happens to match a newer + // browse operation. + // + // TODO: Have a way to clear that state here. proxy->Release(); return; } @@ -174,6 +182,14 @@ static void HandleNodeBrowse(void * context, DnssdService * services, size_t ser if (finalBrowse) { + // We don't have access to the ResolverProxy here to clear out its + // mDiscoveryContext. The underlying implementation of + // ChipDnssdStopBrowse needs to handle a possibly-stale reference + // safely, so this won't lead to crashes, but it can lead to + // mis-behavior if a stale mDiscoveryContext happens to match a newer + // browse operation. + // + // TODO: Have a way to clear that state here. proxy->Release(); } } @@ -616,6 +632,12 @@ CHIP_ERROR DiscoveryImplPlatform::DiscoverCommissioners(DiscoveryFilter filter) return mResolverProxy.DiscoverCommissioners(filter); } +CHIP_ERROR DiscoveryImplPlatform::StopDiscovery() +{ + ReturnErrorOnFailure(InitImpl()); + return mResolverProxy.StopDiscovery(); +} + DiscoveryImplPlatform & DiscoveryImplPlatform::GetInstance() { return sManager; @@ -656,6 +678,8 @@ ResolverProxy::~ResolverProxy() CHIP_ERROR ResolverProxy::DiscoverCommissionableNodes(DiscoveryFilter filter) { + StopDiscovery(); + VerifyOrReturnError(mDelegate != nullptr, CHIP_ERROR_INCORRECT_STATE); mDelegate->Retain(); @@ -674,12 +698,17 @@ CHIP_ERROR ResolverProxy::DiscoverCommissionableNodes(DiscoveryFilter filter) char serviceName[kMaxCommissionableServiceNameSize]; ReturnErrorOnFailure(MakeServiceTypeName(serviceName, sizeof(serviceName), filter, DiscoveryType::kCommissionableNode)); - return ChipDnssdBrowse(serviceName, DnssdServiceProtocol::kDnssdProtocolUdp, Inet::IPAddressType::kAny, - Inet::InterfaceId::Null(), HandleNodeBrowse, mDelegate); + intptr_t browseIdentifier; + ReturnErrorOnFailure(ChipDnssdBrowse(serviceName, DnssdServiceProtocol::kDnssdProtocolUdp, Inet::IPAddressType::kAny, + Inet::InterfaceId::Null(), HandleNodeBrowse, mDelegate, &browseIdentifier)); + mDiscoveryContext.Emplace(browseIdentifier); + return CHIP_NO_ERROR; } CHIP_ERROR ResolverProxy::DiscoverCommissioners(DiscoveryFilter filter) { + StopDiscovery(); + VerifyOrReturnError(mDelegate != nullptr, CHIP_ERROR_INCORRECT_STATE); mDelegate->Retain(); @@ -698,8 +727,24 @@ CHIP_ERROR ResolverProxy::DiscoverCommissioners(DiscoveryFilter filter) char serviceName[kMaxCommissionerServiceNameSize]; ReturnErrorOnFailure(MakeServiceTypeName(serviceName, sizeof(serviceName), filter, DiscoveryType::kCommissionerNode)); - return ChipDnssdBrowse(serviceName, DnssdServiceProtocol::kDnssdProtocolUdp, Inet::IPAddressType::kAny, - Inet::InterfaceId::Null(), HandleNodeBrowse, mDelegate); + intptr_t browseIdentifier; + ReturnErrorOnFailure(ChipDnssdBrowse(serviceName, DnssdServiceProtocol::kDnssdProtocolUdp, Inet::IPAddressType::kAny, + Inet::InterfaceId::Null(), HandleNodeBrowse, mDelegate, &browseIdentifier)); + mDiscoveryContext.Emplace(browseIdentifier); + return CHIP_NO_ERROR; +} + +CHIP_ERROR ResolverProxy::StopDiscovery() +{ + if (!mDiscoveryContext.HasValue()) + { + // No discovery going on. + return CHIP_NO_ERROR; + } + + CHIP_ERROR err = ChipDnssdStopBrowse(mDiscoveryContext.Value()); + mDiscoveryContext.ClearValue(); + return err; } } // namespace Dnssd diff --git a/src/lib/dnssd/Discovery_ImplPlatform.h b/src/lib/dnssd/Discovery_ImplPlatform.h index 1bf677d44ee501..dcee5bc0974f7c 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.h +++ b/src/lib/dnssd/Discovery_ImplPlatform.h @@ -57,6 +57,7 @@ class DiscoveryImplPlatform : public ServiceAdvertiser, public Resolver CHIP_ERROR ResolveNodeId(const PeerId & peerId, Inet::IPAddressType type) override; CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter = DiscoveryFilter()) override; CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()) override; + CHIP_ERROR StopDiscovery() override; static DiscoveryImplPlatform & GetInstance(); diff --git a/src/lib/dnssd/Resolver.h b/src/lib/dnssd/Resolver.h index 140a71617645b5..dddbed07625ebe 100644 --- a/src/lib/dnssd/Resolver.h +++ b/src/lib/dnssd/Resolver.h @@ -390,6 +390,14 @@ class Resolver */ virtual CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()) = 0; + /** + * Stop discovery (of commissionable or commissioner nodes). + * + * Some back ends may not support stopping discovery, so consumers should + * not assume they will stop getting callbacks after calling this. + */ + virtual CHIP_ERROR StopDiscovery() = 0; + /** * Provides the system-wide implementation of the service resolver */ diff --git a/src/lib/dnssd/ResolverProxy.h b/src/lib/dnssd/ResolverProxy.h index 38ac51c07eb537..36ada23a486dcf 100644 --- a/src/lib/dnssd/ResolverProxy.h +++ b/src/lib/dnssd/ResolverProxy.h @@ -152,11 +152,16 @@ class ResolverProxy : public Resolver CHIP_ERROR ResolveNodeId(const PeerId & peerId, Inet::IPAddressType type) override; CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter = DiscoveryFilter()) override; CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()) override; + CHIP_ERROR StopDiscovery() override; private: ResolverDelegateProxy * mDelegate = nullptr; OperationalResolveDelegate * mPreInitOperationalDelegate = nullptr; CommissioningResolveDelegate * mPreInitCommissioningDelegate = nullptr; + + // While discovery (commissionable or commissioner) is ongoing, + // mDiscoveryContext may have a value to allow StopDiscovery to work. + Optional mDiscoveryContext; }; } // namespace Dnssd diff --git a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp index 76aef704be593f..cf168d78139c9d 100644 --- a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp @@ -281,6 +281,7 @@ class MinMdnsResolver : public Resolver, public MdnsPacketDelegate CHIP_ERROR ResolveNodeId(const PeerId & peerId, Inet::IPAddressType type) override; CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter = DiscoveryFilter()) override; CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()) override; + CHIP_ERROR StopDiscovery() override; private: OperationalResolveDelegate * mOperationalDelegate = nullptr; @@ -633,6 +634,11 @@ CHIP_ERROR MinMdnsResolver::DiscoverCommissioners(DiscoveryFilter filter) return BrowseNodes(DiscoveryType::kCommissionerNode, filter); } +CHIP_ERROR MinMdnsResolver::StopDiscovery() +{ + return mActiveResolves.CompleteAllBrowses(); +} + CHIP_ERROR MinMdnsResolver::BrowseNodes(DiscoveryType type, DiscoveryFilter filter) { mActiveResolves.MarkPending(filter, type); @@ -712,5 +718,10 @@ CHIP_ERROR ResolverProxy::DiscoverCommissioners(DiscoveryFilter filter) return chip::Dnssd::Resolver::Instance().DiscoverCommissioners(filter); } +CHIP_ERROR ResolverProxy::StopDiscovery() +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + } // namespace Dnssd } // namespace chip diff --git a/src/lib/dnssd/Resolver_ImplNone.cpp b/src/lib/dnssd/Resolver_ImplNone.cpp index fad00bc1fdfada..5fe429f8a62444 100644 --- a/src/lib/dnssd/Resolver_ImplNone.cpp +++ b/src/lib/dnssd/Resolver_ImplNone.cpp @@ -42,6 +42,7 @@ class NoneResolver : public Resolver return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR StopDiscovery() override { return CHIP_ERROR_NOT_IMPLEMENTED; } }; NoneResolver gResolver; @@ -73,5 +74,10 @@ CHIP_ERROR ResolverProxy::DiscoverCommissioners(DiscoveryFilter filter) return CHIP_ERROR_NOT_IMPLEMENTED; } +CHIP_ERROR ResolverProxy::StopDiscovery() +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + } // namespace Dnssd } // namespace chip diff --git a/src/lib/dnssd/platform/Dnssd.h b/src/lib/dnssd/platform/Dnssd.h index 4ccd4d7e03aef6..1bce362b400782 100644 --- a/src/lib/dnssd/platform/Dnssd.h +++ b/src/lib/dnssd/platform/Dnssd.h @@ -203,6 +203,11 @@ CHIP_ERROR ChipDnssdFinalizeServiceUpdate(); * @param[in] interface The interface to send queries. * @param[in] callback The callback for found services. * @param[in] context The user context. + * @param[out] browseIdentifier an identifier for this browse operation. This + * can be used to call ChipDnssdStopBrowse. Only + * set on success. This value remains valid until + * the browse callback is called with an error or + * is called with finalBrowse set to true. * * @retval CHIP_NO_ERROR The browse succeeds. * @retval CHIP_ERROR_INVALID_ARGUMENT The type or callback is nullptr. @@ -210,7 +215,19 @@ CHIP_ERROR ChipDnssdFinalizeServiceUpdate(); * */ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chip::Inet::IPAddressType addressType, - chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context); + chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context, + intptr_t * browseIdentifier); + +/** + * Stop an ongoing browse, if supported by this backend. If successful, this + * will trigger a final callback, with either an error status or finalBrowse set + * to true, to the DnssdBrowseCallback that was passed to the ChipDnssdBrowse + * call that handed back this browseIdentifier. + * + * @param browseIdentifier an identifier for a browse operation that came from + * ChipDnssdBrowse. + */ +CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier); /** * This function resolves the services published by mDNS diff --git a/src/platform/Ameba/DnssdImpl.cpp b/src/platform/Ameba/DnssdImpl.cpp old mode 100755 new mode 100644 index 9d885676abd488..d12f006e5834b6 --- a/src/platform/Ameba/DnssdImpl.cpp +++ b/src/platform/Ameba/DnssdImpl.cpp @@ -97,7 +97,13 @@ CHIP_ERROR ChipDnssdStopPublish() } CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chip::Inet::IPAddressType addressType, - chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context); + chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context, + intptr_t * browseIdentifier); +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier) { return CHIP_ERROR_NOT_IMPLEMENTED; } diff --git a/src/platform/Darwin/DnssdContexts.cpp b/src/platform/Darwin/DnssdContexts.cpp index 4128bfa24e431c..2f2ae01e5e6bd8 100644 --- a/src/platform/Darwin/DnssdContexts.cpp +++ b/src/platform/Darwin/DnssdContexts.cpp @@ -299,6 +299,12 @@ void BrowseContext::DispatchSuccess() MdnsContexts::GetInstance().Remove(this); } +void BrowseContext::DispatchPartialSuccess() +{ + callback(context, services.data(), services.size(), false, CHIP_NO_ERROR); + services.clear(); +} + ResolveContext::ResolveContext(void * cbContext, DnssdResolveCallback cb, chip::Inet::IPAddressType cbAddressType) { type = ContextType::Resolve; diff --git a/src/platform/Darwin/DnssdImpl.cpp b/src/platform/Darwin/DnssdImpl.cpp index c8c94ca174baa7..a955941a8c633c 100644 --- a/src/platform/Darwin/DnssdImpl.cpp +++ b/src/platform/Darwin/DnssdImpl.cpp @@ -256,12 +256,12 @@ static void OnBrowse(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interf if (!(flags & kDNSServiceFlagsMoreComing)) { - sdCtx->Finalize(); + sdCtx->DispatchPartialSuccess(); } } CHIP_ERROR Browse(void * context, DnssdBrowseCallback callback, uint32_t interfaceId, const char * type, - DnssdServiceProtocol protocol) + DnssdServiceProtocol protocol, intptr_t * browseIdentifier) { auto sdCtx = chip::Platform::New(context, callback, protocol); VerifyOrReturnError(nullptr != sdCtx, CHIP_ERROR_NO_MEMORY); @@ -271,7 +271,9 @@ CHIP_ERROR Browse(void * context, DnssdBrowseCallback callback, uint32_t interfa auto err = DNSServiceBrowse(&sdRef, kBrowseFlags, interfaceId, type, kLocalDot, OnBrowse, sdCtx); VerifyOrReturnError(kDNSServiceErr_NoError == err, sdCtx->Finalize(err)); - return MdnsContexts::GetInstance().Add(sdCtx, sdRef); + ReturnErrorOnFailure(MdnsContexts::GetInstance().Add(sdCtx, sdRef)); + *browseIdentifier = reinterpret_cast(sdCtx); + return CHIP_NO_ERROR; } static void OnGetAddrInfo(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceId, DNSServiceErrorType err, @@ -398,7 +400,8 @@ CHIP_ERROR ChipDnssdFinalizeServiceUpdate() } CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chip::Inet::IPAddressType addressType, - chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context) + chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context, + intptr_t * browseIdentifier) { VerifyOrReturnError(type != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(callback != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -406,7 +409,30 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chi auto regtype = GetFullTypeWithSubTypes(type, protocol); auto interfaceId = GetInterfaceId(interface); - return Browse(context, callback, interfaceId, regtype.c_str(), protocol); + return Browse(context, callback, interfaceId, regtype.c_str(), protocol, browseIdentifier); +} + +CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier) +{ + auto ctx = reinterpret_cast(browseIdentifier); + if (MdnsContexts::GetInstance().Has(ctx) != CHIP_NO_ERROR) + { + return CHIP_ERROR_NOT_FOUND; + } + + // We know this is an actual context now, so can check the type. + if (ctx->type != ContextType::Browse) + { + // stale pointer that got reallocated. + return CHIP_ERROR_NOT_FOUND; + } + + // Just treat this as a timeout error. Don't bother delivering the partial + // results we have queued up in the BrowseContext, if any. In practice + // there shouldn't be anything there long-term anyway. + auto browseCtx = static_cast(ctx); + browseCtx->Finalize(kDNSServiceErr_Timeout); + return CHIP_NO_ERROR; } CHIP_ERROR ChipDnssdResolve(DnssdService * service, chip::Inet::InterfaceId interface, DnssdResolveCallback callback, diff --git a/src/platform/Darwin/DnssdImpl.h b/src/platform/Darwin/DnssdImpl.h index b60a8c97c6bc90..2c4e5c84a2618e 100644 --- a/src/platform/Darwin/DnssdImpl.h +++ b/src/platform/Darwin/DnssdImpl.h @@ -117,6 +117,9 @@ struct BrowseContext : public GenericContext void DispatchFailure(DNSServiceErrorType err) override; void DispatchSuccess() override; + + // Dispatch what we have found so far, but don't stop browsing. + void DispatchPartialSuccess(); }; struct InterfaceInfo diff --git a/src/platform/ESP32/DnssdImpl.cpp b/src/platform/ESP32/DnssdImpl.cpp index 9dab2999bca927..342ce11a8c3015 100644 --- a/src/platform/ESP32/DnssdImpl.cpp +++ b/src/platform/ESP32/DnssdImpl.cpp @@ -459,7 +459,8 @@ void MdnsQueryNotifier(mdns_search_once_t * searchHandle) } CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chip::Inet::IPAddressType addressType, - chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context) + chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context, + intptr_t * browseIdentifier) { CHIP_ERROR error = CHIP_NO_ERROR; mdns_search_once_t * searchHandle = @@ -477,9 +478,18 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chi { chip::Platform::Delete(ctx); } + else + { + *browseIdentifier = reinterpret_cast(nullptr); + } return error; } +CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + CHIP_ERROR ChipDnssdResolve(DnssdService * service, chip::Inet::InterfaceId interface, DnssdResolveCallback callback, void * context) { diff --git a/src/platform/Linux/DnssdImpl.cpp b/src/platform/Linux/DnssdImpl.cpp index 04e2eecc6165f7..758fa1569dd8a9 100644 --- a/src/platform/Linux/DnssdImpl.cpp +++ b/src/platform/Linux/DnssdImpl.cpp @@ -850,11 +850,18 @@ CHIP_ERROR ChipDnssdFinalizeServiceUpdate() } CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chip::Inet::IPAddressType addressType, - chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context) + chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context, + intptr_t * browseIdentifier) { + *browseIdentifier = reinterpret_cast(nullptr); return MdnsAvahi::GetInstance().Browse(type, protocol, addressType, interface, callback, context); } +CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId interface, DnssdResolveCallback callback, void * context) diff --git a/src/platform/OpenThread/DnssdImpl.cpp b/src/platform/OpenThread/DnssdImpl.cpp index 0a0f3e47d0939f..654b7cab5054b4 100644 --- a/src/platform/OpenThread/DnssdImpl.cpp +++ b/src/platform/OpenThread/DnssdImpl.cpp @@ -86,7 +86,7 @@ CHIP_ERROR ChipDnssdFinalizeServiceUpdate() } CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, Inet::IPAddressType addressType, - Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context) + Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context, intptr_t * browseIdentifier) { #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT if (type == nullptr || callback == nullptr) @@ -95,12 +95,18 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, Ine char serviceType[Dnssd::kDnssdFullTypeAndProtocolMaxSize + 1]; // +1 for null-terminator snprintf(serviceType, sizeof(serviceType), "%s.%s", type, GetProtocolString(protocol)); + *browseIdentifier = reinterpret_cast(nullptr); return ThreadStackMgr().DnsBrowse(serviceType, callback, context); #else return CHIP_ERROR_NOT_IMPLEMENTED; #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT } +CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, Inet::InterfaceId interface, DnssdResolveCallback callback, void * context) { #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT diff --git a/src/platform/Tizen/DnssdImpl.cpp b/src/platform/Tizen/DnssdImpl.cpp index 40a3e23e4f9b49..68cf37e058faf4 100644 --- a/src/platform/Tizen/DnssdImpl.cpp +++ b/src/platform/Tizen/DnssdImpl.cpp @@ -783,12 +783,15 @@ CHIP_ERROR ChipDnssdFinalizeServiceUpdate() } CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chip::Inet::IPAddressType addressType, - chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context) + chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context, + intptr_t * browseIdentifier) { VerifyOrReturnError(type != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(IsSupportedProtocol(protocol), CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(callback != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + *browseIdentifier = reinterpret_cast(nullptr); + #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT if (DeviceLayer::ThreadStackMgr().IsThreadEnabled()) { @@ -800,6 +803,11 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chi return DnssdTizen::GetInstance().Browse(type, protocol, addressType, interface, callback, context); } +CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId interface, DnssdResolveCallback callback, void * context) { diff --git a/src/platform/android/DnssdImpl.cpp b/src/platform/android/DnssdImpl.cpp index aadd0ba5468819..58183120b5f815 100644 --- a/src/platform/android/DnssdImpl.cpp +++ b/src/platform/android/DnssdImpl.cpp @@ -143,7 +143,7 @@ CHIP_ERROR ChipDnssdFinalizeServiceUpdate() } CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, Inet::IPAddressType addressType, - Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context) + Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context, intptr_t * browseIdentifier) { VerifyOrReturnError(type != nullptr && callback != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(sBrowserObject != nullptr && sBrowseMethod != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -167,9 +167,15 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, Ine return CHIP_JNI_ERROR_EXCEPTION_THROWN; } + *browseIdentifier = reinterpret_cast(nullptr); return CHIP_NO_ERROR; } +CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + CHIP_ERROR ChipDnssdResolve(DnssdService * service, Inet::InterfaceId interface, DnssdResolveCallback callback, void * context) { VerifyOrReturnError(service != nullptr && callback != nullptr, CHIP_ERROR_INVALID_ARGUMENT); diff --git a/src/platform/bouffalolab/BL602/DnssdImpl.cpp b/src/platform/bouffalolab/BL602/DnssdImpl.cpp index 398bfbfa5caf65..143d19eb5cb374 100644 --- a/src/platform/bouffalolab/BL602/DnssdImpl.cpp +++ b/src/platform/bouffalolab/BL602/DnssdImpl.cpp @@ -296,7 +296,13 @@ CHIP_ERROR ChipDnssdFinalizeServiceUpdate() } CHIP_ERROR ChipDnssdBrowse(const char * /*type*/, DnssdServiceProtocol /*protocol*/, chip::Inet::IPAddressType addressType, - chip::Inet::InterfaceId /*interface*/, DnssdBrowseCallback /*callback*/, void * /*context*/) + chip::Inet::InterfaceId /*interface*/, DnssdBrowseCallback /*callback*/, void * /*context*/, + intptr_t * /*browseIdentifier*/) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR ChipDnssdStopBrowse(intptr_t /*browseIdentifier*/) { return CHIP_ERROR_NOT_IMPLEMENTED; } diff --git a/src/platform/fake/DnssdImpl.cpp b/src/platform/fake/DnssdImpl.cpp index 8886d99bfab918..7fcc82c7bc8931 100644 --- a/src/platform/fake/DnssdImpl.cpp +++ b/src/platform/fake/DnssdImpl.cpp @@ -114,7 +114,13 @@ CHIP_ERROR ChipDnssdFinalizeServiceUpdate() } CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chip::Inet::IPAddressType addressType, - chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context) + chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context, + intptr_t * browseIdentifier) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier) { return CHIP_ERROR_NOT_IMPLEMENTED; } diff --git a/src/platform/mt793x/DnssdImpl.cpp b/src/platform/mt793x/DnssdImpl.cpp index 2934bce9184161..a88eeac1c62463 100644 --- a/src/platform/mt793x/DnssdImpl.cpp +++ b/src/platform/mt793x/DnssdImpl.cpp @@ -212,7 +212,8 @@ void ChipDNSServiceBrowseReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint3 } CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chip::Inet::IPAddressType addressType, - chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context) + chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context, + intptr_t * browseIdentifier) { CHIP_ERROR error = CHIP_NO_ERROR; DNSServiceErrorType err; @@ -229,9 +230,18 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chi { error = CHIP_ERROR_INTERNAL; } + else + { + *browseIdentifier = reinterpret_cast(nullptr); + } return error; } +CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + static DNSServiceRef ResolveClient = NULL; void ChipDNSServiceResolveReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, diff --git a/src/platform/tests/TestDnssd.cpp b/src/platform/tests/TestDnssd.cpp index 75fc48537b8231..fe7312fff8d7c9 100644 --- a/src/platform/tests/TestDnssd.cpp +++ b/src/platform/tests/TestDnssd.cpp @@ -96,8 +96,9 @@ static void InitCallback(void * context, CHIP_ERROR error) service.mSubTypeSize = 0; NL_TEST_ASSERT(suite, ChipDnssdPublishService(&service, HandlePublish) == CHIP_NO_ERROR); + intptr_t browseIdentifier; ChipDnssdBrowse("_mock", DnssdServiceProtocol::kDnssdProtocolTcp, chip::Inet::IPAddressType::kAny, - chip::Inet::InterfaceId::Null(), HandleBrowse, suite); + chip::Inet::InterfaceId::Null(), HandleBrowse, suite, &browseIdentifier); } static void ErrorCallback(void * context, CHIP_ERROR error) diff --git a/src/platform/webos/DnssdImpl.cpp b/src/platform/webos/DnssdImpl.cpp index f6dca795bf28da..043d6bb01c7020 100644 --- a/src/platform/webos/DnssdImpl.cpp +++ b/src/platform/webos/DnssdImpl.cpp @@ -847,11 +847,18 @@ CHIP_ERROR ChipDnssdFinalizeServiceUpdate() } CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chip::Inet::IPAddressType addressType, - chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context) + chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context, + intptr_t * browseIdentifier) { + *browseIdentifier = reinterpret_cast(nullptr); return MdnsAvahi::GetInstance().Browse(type, protocol, addressType, interface, callback, context); } +CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId interface, DnssdResolveCallback callback, void * context)