@@ -30,12 +30,6 @@ namespace {
30
30
31
31
constexpr uint8_t kDnssdKeyMaxSize = 32 ;
32
32
constexpr uint8_t kDnssdTxtRecordMaxEntries = 20 ;
33
- constexpr char kLocalDot [] = " local." ;
34
-
35
- bool IsLocalDomain (const char * domain)
36
- {
37
- return strcmp (kLocalDot , domain) == 0 ;
38
- }
39
33
40
34
std::string GetHostNameWithoutDomain (const char * hostnameWithDomain)
41
35
{
@@ -341,7 +335,8 @@ void RegisterContext::DispatchSuccess()
341
335
mHostNameRegistrar .Register ();
342
336
}
343
337
344
- BrowseContext * BrowseContext::sContextDispatchingSuccess = nullptr ;
338
+ BrowseContext * BrowseContext::sContextDispatchingSuccess = nullptr ;
339
+ std::vector<DnssdService> * BrowseContext::sDispatchedServices = nullptr ;
345
340
346
341
BrowseContext::BrowseContext (void * cbContext, DnssdBrowseCallback cb, DnssdServiceProtocol cbContextProtocol)
347
342
{
@@ -373,7 +368,10 @@ void BrowseContext::DispatchPartialSuccess()
373
368
{
374
369
dnsServices.push_back (std::move (iter.first ));
375
370
}
371
+
372
+ sDispatchedServices = &dnsServices;
376
373
callback (context, dnsServices.data (), dnsServices.size (), false , CHIP_NO_ERROR);
374
+ sDispatchedServices = nullptr ;
377
375
sContextDispatchingSuccess = nullptr ;
378
376
services.clear ();
379
377
}
@@ -393,7 +391,6 @@ void BrowseContext::OnBrowseAdd(const char * name, const char * type, const char
393
391
ChipLogProgress (Discovery, " Mdns: %s name: %s, type: %s, domain: %s, interface: %" PRIu32, __func__, StringOrNullMarker (name),
394
392
StringOrNullMarker (type), StringOrNullMarker (domain), interfaceId);
395
393
396
- VerifyOrReturn (IsLocalDomain (domain));
397
394
auto service = GetService (name, type, protocol, interfaceId);
398
395
services.push_back (std::make_pair (std::move (service), std::string (domain)));
399
396
}
@@ -404,13 +401,13 @@ void BrowseContext::OnBrowseRemove(const char * name, const char * type, const c
404
401
StringOrNullMarker (type), StringOrNullMarker (domain), interfaceId);
405
402
406
403
VerifyOrReturn (name != nullptr );
407
- VerifyOrReturn ( IsLocalDomain ( domain) );
404
+ std::string domain_str ( domain);
408
405
409
406
services.erase (std::remove_if (services.begin (), services.end (),
410
- [name, type, interfaceId, domain ](const auto & service) {
407
+ [name, type, interfaceId, &domain_str ](const auto & service) {
411
408
return strcmp (name, service.first .mName ) == 0 && type == GetFullType (&service.first ) &&
412
409
service.first .mInterface == chip::Inet::InterfaceId (interfaceId) &&
413
- strcmp (domain, service.second . c_str ()) == 0 ;
410
+ service.second == domain_str ;
414
411
}),
415
412
services.end ());
416
413
}
@@ -449,8 +446,6 @@ void BrowseWithDelegateContext::OnBrowseAdd(const char * name, const char * type
449
446
ChipLogProgress (Discovery, " Mdns: %s name: %s, type: %s, domain: %s, interface: %" PRIu32, __func__, StringOrNullMarker (name),
450
447
StringOrNullMarker (type), StringOrNullMarker (domain), interfaceId);
451
448
452
- VerifyOrReturn (IsLocalDomain (domain));
453
-
454
449
auto delegate = static_cast <DnssdBrowseDelegate *>(context);
455
450
auto service = GetService (name, type, protocol, interfaceId);
456
451
delegate->OnBrowseAdd (service);
@@ -462,7 +457,6 @@ void BrowseWithDelegateContext::OnBrowseRemove(const char * name, const char * t
462
457
StringOrNullMarker (type), StringOrNullMarker (domain), interfaceId);
463
458
464
459
VerifyOrReturn (name != nullptr );
465
- VerifyOrReturn (IsLocalDomain (domain));
466
460
467
461
auto delegate = static_cast <DnssdBrowseDelegate *>(context);
468
462
auto service = GetService (name, type, protocol, interfaceId);
@@ -494,7 +488,13 @@ ResolveContext::ResolveContext(CommissioningResolveDelegate * delegate, chip::In
494
488
consumerCounter = std::move (consumerCounterToUse);
495
489
}
496
490
497
- ResolveContext::~ResolveContext () {}
491
+ ResolveContext::~ResolveContext ()
492
+ {
493
+ if (isSRPTimerRunning)
494
+ {
495
+ CancelSRPTimer ();
496
+ }
497
+ }
498
498
499
499
void ResolveContext::DispatchFailure (const char * errorStr, CHIP_ERROR err)
500
500
{
@@ -554,7 +554,8 @@ void ResolveContext::DispatchSuccess()
554
554
555
555
for (auto & interface : interfaces)
556
556
{
557
- if (TryReportingResultsForInterfaceIndex (interface.first ))
557
+ if (TryReportingResultsForInterfaceIndex (interface.first .interfaceId , interface.first .hostname ,
558
+ interface.first .isSRPResult ))
558
559
{
559
560
break ;
560
561
}
@@ -566,16 +567,17 @@ void ResolveContext::DispatchSuccess()
566
567
}
567
568
}
568
569
569
- bool ResolveContext::TryReportingResultsForInterfaceIndex (uint32_t interfaceIndex)
570
+ bool ResolveContext::TryReportingResultsForInterfaceIndex (uint32_t interfaceIndex, const std::string & hostname, bool isSRPResult )
570
571
{
571
572
if (interfaceIndex == 0 )
572
573
{
573
574
// Not actually an interface we have.
574
575
return false ;
575
576
}
576
577
577
- auto & interface = interfaces[interfaceIndex];
578
- auto & ips = interface.addresses ;
578
+ InterfaceKey interfaceKey = { interfaceIndex, hostname, isSRPResult };
579
+ auto & interface = interfaces[interfaceKey];
580
+ auto & ips = interface.addresses ;
579
581
580
582
// Some interface may not have any ips, just ignore them.
581
583
if (ips.size () == 0 )
@@ -602,15 +604,45 @@ bool ResolveContext::TryReportingResultsForInterfaceIndex(uint32_t interfaceInde
602
604
return true ;
603
605
}
604
606
605
- CHIP_ERROR ResolveContext::OnNewAddress (uint32_t interfaceId, const struct sockaddr * address)
607
+ bool ResolveContext::TryReportingResultsForInterfaceIndex (uint32_t interfaceIndex)
608
+ {
609
+ for (auto & interface : interfaces)
610
+ {
611
+ if (interface.first .interfaceId == interfaceIndex)
612
+ {
613
+ if (TryReportingResultsForInterfaceIndex (interface.first .interfaceId , interface.first .hostname ,
614
+ interface.first .isSRPResult ))
615
+ {
616
+ return true ;
617
+ }
618
+ }
619
+ }
620
+ return false ;
621
+ }
622
+
623
+ void ResolveContext::SRPTimerExpiredCallback (chip::System::Layer * systemLayer, void * callbackContext)
624
+ {
625
+ auto sdCtx = static_cast <ResolveContext *>(callbackContext);
626
+ VerifyOrDie (sdCtx != nullptr );
627
+ sdCtx->Finalize ();
628
+ }
629
+
630
+ void ResolveContext::CancelSRPTimer ()
631
+ {
632
+ DeviceLayer::SystemLayer ().CancelTimer (SRPTimerExpiredCallback, static_cast <void *>(this ));
633
+ }
634
+
635
+ CHIP_ERROR ResolveContext::OnNewAddress (const InterfaceKey & interfaceKey, const struct sockaddr * address)
606
636
{
607
637
// If we don't have any information about this interfaceId, just ignore the
608
638
// address, since it won't be usable anyway without things like the port.
609
639
// This can happen if "local" is set up as a search domain in the DNS setup
610
640
// on the system, because the hostnames we are looking up all end in
611
641
// ".local". In other words, we can get regular DNS results in here, not
612
642
// just DNS-SD ones.
613
- if (interfaces.find (interfaceId) == interfaces.end ())
643
+ auto interfaceId = interfaceKey.interfaceId ;
644
+
645
+ if (interfaces.find (interfaceKey) == interfaces.end ())
614
646
{
615
647
return CHIP_NO_ERROR;
616
648
}
@@ -633,7 +665,7 @@ CHIP_ERROR ResolveContext::OnNewAddress(uint32_t interfaceId, const struct socka
633
665
return CHIP_NO_ERROR;
634
666
}
635
667
636
- interfaces[interfaceId ].addresses .push_back (ip);
668
+ interfaces[interfaceKey ].addresses .push_back (ip);
637
669
638
670
return CHIP_NO_ERROR;
639
671
}
@@ -652,7 +684,7 @@ bool ResolveContext::HasAddress()
652
684
}
653
685
654
686
void ResolveContext::OnNewInterface (uint32_t interfaceId, const char * fullname, const char * hostnameWithDomain, uint16_t port,
655
- uint16_t txtLen, const unsigned char * txtRecord)
687
+ uint16_t txtLen, const unsigned char * txtRecord, bool isFromSRPResolve )
656
688
{
657
689
#if CHIP_PROGRESS_LOGGING
658
690
std::string txtString;
@@ -715,7 +747,8 @@ void ResolveContext::OnNewInterface(uint32_t interfaceId, const char * fullname,
715
747
// resolving.
716
748
interface.fullyQualifiedDomainName = hostnameWithDomain;
717
749
718
- interfaces.insert (std::make_pair (interfaceId, std::move (interface)));
750
+ InterfaceKey interfaceKey = { interfaceId, hostnameWithDomain, isFromSRPResolve };
751
+ interfaces.insert (std::make_pair (std::move (interfaceKey), std::move (interface)));
719
752
}
720
753
721
754
bool ResolveContext::HasInterface ()
@@ -731,7 +764,7 @@ InterfaceInfo::InterfaceInfo()
731
764
732
765
InterfaceInfo::InterfaceInfo (InterfaceInfo && other) :
733
766
service (std::move(other.service)), addresses(std::move(other.addresses)),
734
- fullyQualifiedDomainName (std::move(other.fullyQualifiedDomainName))
767
+ fullyQualifiedDomainName (std::move(other.fullyQualifiedDomainName)), isDNSLookUpRequested(other.isDNSLookUpRequested)
735
768
{
736
769
// Make sure we're not trying to free any state from the other DnssdService,
737
770
// since we took over ownership of its allocated bits.
0 commit comments