@@ -564,88 +564,78 @@ void ResolveContext::DispatchSuccess()
564
564
};
565
565
#endif // TARGET_OS_TV
566
566
567
- for (auto interfaceIndex : priorityInterfaceIndices)
567
+ std::vector<InterfaceKey> interfacesOrder;
568
+ for (auto priorityInterfaceIndex : priorityInterfaceIndices)
568
569
{
569
- if (interfaceIndex == 0 )
570
+ if (priorityInterfaceIndex == 0 )
570
571
{
571
572
// Not actually an interface we have, since if_nametoindex
572
573
// returned 0.
573
574
continue ;
574
575
}
575
576
576
- if ( TryReportingResultsForInterfaceIndex ( static_cast < uint32_t >(interfaceIndex)) )
577
+ for ( auto & interface : interfaces )
577
578
{
578
- return ;
579
+ if (interface.second .HasAddresses () && priorityInterfaceIndex == interface.first .interfaceId )
580
+ {
581
+ interfacesOrder.push_back (interface.first );
582
+ }
579
583
}
580
584
}
581
585
582
586
for (auto & interface : interfaces)
583
587
{
584
- if (TryReportingResultsForInterfaceIndex (interface.first .interfaceId , interface.first .hostname ,
585
- interface.first .isSRPResult ))
588
+ // Skip interfaces that have already been prioritized to avoid duplicate results
589
+ auto interfaceKey = std::find (std::begin (interfacesOrder), std::end (interfacesOrder), interface.first );
590
+ if (interfaceKey != std::end (interfacesOrder))
586
591
{
587
- return ;
592
+ continue ;
588
593
}
589
- }
590
594
591
- ChipLogError (Discovery, " Successfully finalizing resolve for %s without finding any actual IP addresses." ,
592
- instanceName.c_str ());
593
- }
594
-
595
- bool ResolveContext::TryReportingResultsForInterfaceIndex (uint32_t interfaceIndex, const std::string & hostname, bool isSRPResult)
596
- {
597
- InterfaceKey interfaceKey = { interfaceIndex, hostname, isSRPResult };
598
- auto & interface = interfaces[interfaceKey];
599
- auto & ips = interface.addresses ;
595
+ // Some interface may not have any ips, just ignore them.
596
+ if (!interface.second .HasAddresses ())
597
+ {
598
+ continue ;
599
+ }
600
600
601
- // Some interface may not have any ips, just ignore them.
602
- if (ips.size () == 0 )
603
- {
604
- return false ;
601
+ interfacesOrder.push_back (interface.first );
605
602
}
606
603
607
- ChipLogProgress (Discovery, " Mdns: Resolve success on interface %" PRIu32, interfaceIndex);
608
-
609
- auto & service = interface.service ;
610
- auto addresses = Span<Inet::IPAddress>(ips.data (), ips.size ());
611
- if (nullptr == callback)
604
+ for (auto & interfaceKey : interfacesOrder)
612
605
{
613
- auto delegate = static_cast <DiscoverNodeDelegate *>(context);
614
- DiscoveredNodeData nodeData;
606
+ auto & interfaceInfo = interfaces[interfaceKey];
607
+ auto & service = interfaceInfo.service ;
608
+ auto & ips = interfaceInfo.addresses ;
609
+ auto addresses = Span<Inet::IPAddress>(ips.data (), ips.size ());
615
610
616
- // Check whether mType (service name) exactly matches with operational service name
617
- if (strcmp (service.mType , kOperationalServiceName ) == 0 )
611
+ ChipLogProgress (Discovery, " Mdns: Resolve success on interface %" PRIu32, interfaceKey.interfaceId );
612
+
613
+ if (nullptr == callback)
618
614
{
619
- service.ToDiscoveredOperationalNodeBrowseData (nodeData);
615
+ auto delegate = static_cast <DiscoverNodeDelegate *>(context);
616
+ DiscoveredNodeData nodeData;
617
+
618
+ // Check whether mType (service name) exactly matches with operational service name
619
+ if (strcmp (service.mType , kOperationalServiceName ) == 0 )
620
+ {
621
+ service.ToDiscoveredOperationalNodeBrowseData (nodeData);
622
+ }
623
+ else
624
+ {
625
+ service.ToDiscoveredCommissionNodeData (addresses, nodeData);
626
+ }
627
+ delegate->OnNodeDiscovered (nodeData);
620
628
}
621
629
else
622
630
{
623
- service.ToDiscoveredCommissionNodeData (addresses, nodeData);
631
+ CHIP_ERROR error = &interfaceKey == &interfacesOrder.back () ? CHIP_NO_ERROR : CHIP_ERROR_IN_PROGRESS;
632
+ callback (context, &service, addresses, error);
624
633
}
625
- delegate->OnNodeDiscovered (nodeData);
626
634
}
627
- else
628
- {
629
- callback (context, &service, addresses, CHIP_NO_ERROR);
630
- }
631
-
632
- return true ;
633
- }
634
635
635
- bool ResolveContext::TryReportingResultsForInterfaceIndex (uint32_t interfaceIndex)
636
- {
637
- for (auto & interface : interfaces)
638
- {
639
- if (interface.first .interfaceId == interfaceIndex)
640
- {
641
- if (TryReportingResultsForInterfaceIndex (interface.first .interfaceId , interface.first .hostname ,
642
- interface.first .isSRPResult ))
643
- {
644
- return true ;
645
- }
646
- }
647
- }
648
- return false ;
636
+ VerifyOrDo (interfacesOrder.size (),
637
+ ChipLogError (Discovery, " Successfully finalizing resolve for %s without finding any actual IP addresses." ,
638
+ instanceName.c_str ()));
649
639
}
650
640
651
641
void ResolveContext::SRPTimerExpiredCallback (chip::System::Layer * systemLayer, void * callbackContext)
0 commit comments