@@ -279,20 +279,19 @@ static void OnGetAddrInfo(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t i
279
279
auto contextWithType = reinterpret_cast <ResolveContextWithType *>(context);
280
280
VerifyOrReturn (contextWithType != nullptr , ChipLogError (Discovery, " ResolveContextWithType is null" ));
281
281
282
- auto sdCtx = reinterpret_cast <ResolveContext *>( contextWithType->context ) ;
282
+ auto sdCtx = contextWithType->context ;
283
283
ReturnOnFailure (MdnsContexts::GetInstance ().Has (sdCtx));
284
284
LogOnFailure (__func__, err);
285
285
286
286
if (kDNSServiceErr_NoError == err)
287
287
{
288
- InterfaceKey interfaceKey = { interfaceId, hostname, contextWithType->isSRP };
289
- sdCtx->OnNewAddress (interfaceKey, address);
288
+ InterfaceKey interfaceKey = { interfaceId, hostname, contextWithType->isSRPResolve };
289
+ CHIP_ERROR error = sdCtx->OnNewAddress (interfaceKey, address);
290
290
291
- // Set the flag to start the timer for resolve on SRP domain to complete if the key has the SRP type requested flag set to
292
- // true.
293
- if (interfaceKey.isSRPTypeRequested )
291
+ // If we saw an address resolved on the SRP domain, set the shouldStartSRPTimerForResolve to false.
292
+ if (error == CHIP_NO_ERROR && contextWithType->isSRPResolve )
294
293
{
295
- sdCtx->shoulStartSRPTimerForResolve = true ;
294
+ sdCtx->shouldStartSRPTimerForResolve = false ;
296
295
}
297
296
}
298
297
@@ -304,7 +303,7 @@ static void OnGetAddrInfo(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t i
304
303
VerifyOrReturn (sdCtx->HasAddress (), sdCtx->Finalize (kDNSServiceErr_BadState ));
305
304
306
305
// We should complete the resolve if we got a resolution on non SRP domain and no resolution on SRP domain was requested.
307
- if (!sdCtx->shoulStartSRPTimerForResolve )
306
+ if (!sdCtx->shouldStartSRPTimerForResolve )
308
307
{
309
308
sdCtx->Finalize ();
310
309
}
@@ -332,19 +331,21 @@ static void GetAddrInfo(ResolveContext * sdCtx)
332
331
333
332
for (auto & interface : sdCtx->interfaces )
334
333
{
334
+ if (interface.second .isDNSLookUpRequested )
335
+ {
336
+ continue ;
337
+ }
338
+
335
339
auto interfaceId = interface.first .interfaceId ;
336
340
auto hostname = interface.second .fullyQualifiedDomainName .c_str ();
337
341
auto sdRefCopy = sdCtx->serviceRef ; // Mandatory copy because of kDNSServiceFlagsShareConnection
338
342
339
- if (!interface.second .isDNSLookUpRequested )
340
- {
341
- ResolveContextWithType * contextWithType =
342
- (interface.first .isSRPResult ) ? &sdCtx->resolveContextWithSRPType : &sdCtx->resolveContextWithNonSRPType ;
343
- auto err = DNSServiceGetAddrInfo (&sdRefCopy, kGetAddrInfoFlags , interfaceId, protocol, hostname, OnGetAddrInfo,
344
- contextWithType);
345
- VerifyOrReturn (kDNSServiceErr_NoError == err, sdCtx->Finalize (err));
346
- interface.second .isDNSLookUpRequested = true ;
347
- }
343
+ ResolveContextWithType * contextWithType =
344
+ (interface.first .isSRPResult ) ? &sdCtx->resolveContextWithSRPType : &sdCtx->resolveContextWithNonSRPType ;
345
+ auto err = DNSServiceGetAddrInfo (&sdRefCopy, kGetAddrInfoFlags , interfaceId, protocol, hostname, OnGetAddrInfo,
346
+ contextWithType);
347
+ VerifyOrReturn (kDNSServiceErr_NoError == err, sdCtx->Finalize (err));
348
+ interface.second .isDNSLookUpRequested = true ;
348
349
}
349
350
}
350
351
@@ -358,13 +359,13 @@ static void OnResolve(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t inter
358
359
auto contextWithType = reinterpret_cast <ResolveContextWithType *>(context);
359
360
VerifyOrReturn (contextWithType != nullptr , ChipLogError (Discovery, " ResolveContextWithType is null" ));
360
361
361
- auto sdCtx = reinterpret_cast <ResolveContext *>( contextWithType->context ) ;
362
+ auto sdCtx = contextWithType->context ;
362
363
ReturnOnFailure (MdnsContexts::GetInstance ().Has (sdCtx));
363
364
LogOnFailure (__func__, err);
364
365
365
366
if (kDNSServiceErr_NoError == err)
366
367
{
367
- sdCtx->OnNewInterface (interfaceId, fullname, hostname, port, txtLen, txtRecord, contextWithType->isSRPType );
368
+ sdCtx->OnNewInterface (interfaceId, fullname, hostname, port, txtLen, txtRecord, contextWithType->isSRPResolve );
368
369
}
369
370
370
371
if (!(flags & kDNSServiceFlagsMoreComing ))
@@ -381,6 +382,12 @@ static CHIP_ERROR ResolveWithContext(ResolveContext * sdCtx, uint32_t interfaceI
381
382
382
383
auto err = DNSServiceResolve (&sdRef, kResolveFlags , interfaceId, name, type, domain, OnResolve, contextWithType);
383
384
VerifyOrReturnError (kDNSServiceErr_NoError == err, sdCtx->Finalize (err));
385
+
386
+ // Set the flag to start the timer for resolve on SRP domain to complete if a resolve has been requested on the SRP domain.
387
+ if (contextWithType->isSRPResolve )
388
+ {
389
+ sdCtx->shouldStartSRPTimerForResolve = true ;
390
+ }
384
391
return CHIP_NO_ERROR;
385
392
}
386
393
@@ -399,8 +406,8 @@ static CHIP_ERROR Resolve(ResolveContext * sdCtx, uint32_t interfaceId, chip::In
399
406
{
400
407
ReturnErrorOnFailure (
401
408
ResolveWithContext (sdCtx, interfaceId, type, name, domain,
402
- IsSRPType (domain) ? &sdCtx->resolveContextWithSRPType : &sdCtx->resolveContextWithNonSRPType ));
403
- sdCtx->shoulStartSRPTimerForResolve = false ;
409
+ IsSRPDomain (domain) ? &sdCtx->resolveContextWithSRPType : &sdCtx->resolveContextWithNonSRPType ));
410
+ sdCtx->shouldStartSRPTimerForResolve = false ;
404
411
}
405
412
else
406
413
{
0 commit comments