Skip to content

Commit

Permalink
Improve discovery logging a bit. (#21056)
Browse files Browse the repository at this point in the history
1) In shared "platform" discovery code, log when we discovered an operational id
   or a commissionable instance and what the TXT records were.
2) In Darwin code, do Discovery, not DeviceLayer logging and improve some of the
   log messages.

The intent is to make it a little clearer on failure where in the pipeline
things stop propagating information.
  • Loading branch information
bzbarsky-apple authored Jul 21, 2022
1 parent e15af6f commit 4ce818e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/lib/dnssd/Discovery_ImplPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static void HandleNodeResolve(void * context, DnssdService * result, const Span<
FillNodeDataFromTxt(key, val, nodeData.commissionData);
}

nodeData.LogDetail();
proxy->OnNodeDiscovered(nodeData);
proxy->Release();
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/dnssd/Resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ struct CommonResolutionData
{
ChipLogDetail(Discovery, "\tMrp Interval active: not present");
}
ChipLogDetail(Discovery, "\tTCP Supported: %d", supportsTcp);
}
};

Expand Down Expand Up @@ -243,6 +244,7 @@ struct DiscoveredNodeData

void LogDetail() const
{
ChipLogDetail(Discovery, "Discovered node:");
resolutionData.LogDetail();
commissionData.LogDetail();
}
Expand Down
11 changes: 6 additions & 5 deletions src/platform/Darwin/DnssdContexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ RegisterContext::RegisterContext(const char * sType, DnssdPublishCallback cb, vo

void RegisterContext::DispatchFailure(DNSServiceErrorType err)
{
ChipLogError(DeviceLayer, "Register (%s)", Error::ToString(err));
ChipLogError(Discovery, "Mdns: Register failure (%s)", Error::ToString(err));
callback(context, nullptr, CHIP_ERROR_INTERNAL);
MdnsContexts::GetInstance().Remove(this);
}
Expand All @@ -283,7 +283,7 @@ BrowseContext::BrowseContext(void * cbContext, DnssdBrowseCallback cb, DnssdServ

void BrowseContext::DispatchFailure(DNSServiceErrorType err)
{
ChipLogError(DeviceLayer, "Browse (%s)", Error::ToString(err));
ChipLogError(Discovery, "Mdns: Browse failure (%s)", Error::ToString(err));
callback(context, nullptr, 0, CHIP_ERROR_INTERNAL);
MdnsContexts::GetInstance().Remove(this);
}
Expand All @@ -309,7 +309,7 @@ ResolveContext::~ResolveContext()

void ResolveContext::DispatchFailure(DNSServiceErrorType err)
{
ChipLogError(DeviceLayer, "Resolve (%s)", Error::ToString(err));
ChipLogError(Discovery, "Mdns: Resolve failure (%s)", Error::ToString(err));
callback(context, nullptr, Span<Inet::IPAddress>(), CHIP_ERROR_INTERNAL);
MdnsContexts::GetInstance().Remove(this);
}
Expand All @@ -326,6 +326,7 @@ void ResolveContext::DispatchSuccess()
continue;
}

ChipLogDetail(Discovery, "Mdns: Resolve success on interface %" PRIu32, interface.first);
callback(context, &interface.second.service, Span<Inet::IPAddress>(ips.data(), ips.size()), CHIP_NO_ERROR);
break;
}
Expand All @@ -342,7 +343,7 @@ CHIP_ERROR ResolveContext::OnNewAddress(uint32_t interfaceId, const struct socka
#ifdef CHIP_DETAIL_LOGGING
char addrStr[INET6_ADDRSTRLEN];
ip.ToString(addrStr, sizeof(addrStr));
ChipLogDetail(DeviceLayer, "Mdns: %s interface: %" PRIu32 " ip:%s", __func__, interfaceId, addrStr);
ChipLogDetail(Discovery, "Mdns: %s interface: %" PRIu32 " ip:%s", __func__, interfaceId, addrStr);
#endif // CHIP_DETAIL_LOGGING

return CHIP_NO_ERROR;
Expand Down Expand Up @@ -376,7 +377,7 @@ bool ResolveContext::HasAddress()
void ResolveContext::OnNewInterface(uint32_t interfaceId, const char * fullname, const char * hostnameWithDomain, uint16_t port,
uint16_t txtLen, const unsigned char * txtRecord)
{
ChipLogDetail(DeviceLayer, "Mdns : %s hostname:%s fullname:%s interface: %" PRIu32, __func__, hostnameWithDomain, fullname,
ChipLogDetail(Discovery, "Mdns : %s hostname:%s fullname:%s interface: %" PRIu32, __func__, hostnameWithDomain, fullname,
interfaceId);

InterfaceInfo interface;
Expand Down
14 changes: 7 additions & 7 deletions src/platform/Darwin/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void LogOnFailure(const char * name, DNSServiceErrorType err)
{
if (kDNSServiceErr_NoError != err)
{
ChipLogError(DeviceLayer, "%s (%s)", name, Error::ToString(err));
ChipLogError(Discovery, "%s (%s)", name, Error::ToString(err));
}
}

Expand Down Expand Up @@ -165,7 +165,7 @@ namespace {
static void OnRegister(DNSServiceRef sdRef, DNSServiceFlags flags, DNSServiceErrorType err, const char * name, const char * type,
const char * domain, void * context)
{
ChipLogDetail(DeviceLayer, "Mdns: %s name: %s, type: %s, domain: %s, flags: %d", __func__, name, type, domain, flags);
ChipLogDetail(Discovery, "Mdns: %s name: %s, type: %s, domain: %s, flags: %d", __func__, name, type, domain, flags);

auto sdCtx = reinterpret_cast<RegisterContext *>(context);
sdCtx->Finalize(err);
Expand All @@ -174,7 +174,7 @@ static void OnRegister(DNSServiceRef sdRef, DNSServiceFlags flags, DNSServiceErr
CHIP_ERROR Register(void * context, DnssdPublishCallback callback, uint32_t interfaceId, const char * type, const char * name,
uint16_t port, ScopedTXTRecord & record)
{
ChipLogProgress(DeviceLayer, "Publishing service %s on port %u with type: %s on interface id: %" PRIu32, name, port, type,
ChipLogProgress(Discovery, "Publishing service %s on port %u with type: %s on interface id: %" PRIu32, name, port, type,
interfaceId);

RegisterContext * sdCtx = nullptr;
Expand All @@ -198,7 +198,7 @@ CHIP_ERROR Register(void * context, DnssdPublishCallback callback, uint32_t inte

void OnBrowseAdd(BrowseContext * context, const char * name, const char * type, const char * domain, uint32_t interfaceId)
{
ChipLogDetail(DeviceLayer, "Mdns: %s name: %s, type: %s, domain: %s, interface: %" PRIu32, __func__, name, type, domain,
ChipLogDetail(Discovery, "Mdns: %s name: %s, type: %s, domain: %s, interface: %" PRIu32, __func__, name, type, domain,
interfaceId);

VerifyOrReturn(strcmp(kLocalDot, domain) == 0);
Expand All @@ -225,7 +225,7 @@ void OnBrowseAdd(BrowseContext * context, const char * name, const char * type,

void OnBrowseRemove(BrowseContext * context, const char * name, const char * type, const char * domain, uint32_t interfaceId)
{
ChipLogDetail(DeviceLayer, "Mdns: %s name: %s, type: %s, domain: %s, interface: %" PRIu32, __func__, name, type, domain,
ChipLogDetail(Discovery, "Mdns: %s name: %s, type: %s, domain: %s, interface: %" PRIu32, __func__, name, type, domain,
interfaceId);

VerifyOrReturn(strcmp(kLocalDot, domain) == 0);
Expand Down Expand Up @@ -259,7 +259,7 @@ CHIP_ERROR Browse(void * context, DnssdBrowseCallback callback, uint32_t interfa
auto sdCtx = chip::Platform::New<BrowseContext>(context, callback, protocol);
VerifyOrReturnError(nullptr != sdCtx, CHIP_ERROR_NO_MEMORY);

ChipLogProgress(DeviceLayer, "Browsing for: %s", type);
ChipLogProgress(Discovery, "Browsing for: %s", type);
DNSServiceRef sdRef;
auto err = DNSServiceBrowse(&sdRef, kBrowseFlags, interfaceId, type, kLocalDot, OnBrowse, sdCtx);
VerifyOrReturnError(kDNSServiceErr_NoError == err, sdCtx->Finalize(err));
Expand Down Expand Up @@ -329,7 +329,7 @@ static void OnResolve(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t inter
static CHIP_ERROR Resolve(void * context, DnssdResolveCallback callback, uint32_t interfaceId,
chip::Inet::IPAddressType addressType, const char * type, const char * name)
{
ChipLogDetail(DeviceLayer, "Resolve type=%s name=%s interface=%" PRIu32, type, name, interfaceId);
ChipLogDetail(Discovery, "Resolve type=%s name=%s interface=%" PRIu32, type, name, interfaceId);

auto sdCtx = chip::Platform::New<ResolveContext>(context, callback, addressType);
VerifyOrReturnError(nullptr != sdCtx, CHIP_ERROR_NO_MEMORY);
Expand Down

0 comments on commit 4ce818e

Please sign in to comment.