Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve discovery logging a bit. #21056

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib/dnssd/Discovery_ImplPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ static void HandleNodeResolve(void * context, DnssdService * result, const Span<

nodeData.resolutionData.port = result->mPort;

ChipLogDetail(Discovery, "Node with instance name %s discovered. TXT:", nodeData.commissionData.instanceName);
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
for (size_t i = 0; i < result->mTextEntrySize; ++i)
{
ChipLogDetail(Discovery, " %s: %.*s", result->mTextEntries[i].mKey, static_cast<int>(result->mTextEntries[i].mDataSize),
result->mTextEntries[i].mData);
ByteSpan key(reinterpret_cast<const uint8_t *>(result->mTextEntries[i].mKey), strlen(result->mTextEntries[i].mKey));
ByteSpan val(result->mTextEntries[i].mData, result->mTextEntries[i].mDataSize);
FillNodeDataFromTxt(key, val, nodeData.resolutionData);
Expand Down Expand Up @@ -134,8 +137,11 @@ static void HandleNodeIdResolve(void * context, DnssdService * result, const Spa
}
nodeData.resolutionData.numIPs = addressesFound;

ChipLogDetail(Discovery, "Node with operational ID %s resolved. TXT:", result->mName);
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
for (size_t i = 0; i < result->mTextEntrySize; ++i)
{
ChipLogDetail(Discovery, " %s: %.*s", result->mTextEntries[i].mKey, static_cast<int>(result->mTextEntries[i].mDataSize),
result->mTextEntries[i].mData);
ByteSpan key(reinterpret_cast<const uint8_t *>(result->mTextEntries[i].mKey), strlen(result->mTextEntries[i].mKey));
ByteSpan val(result->mTextEntries[i].mData, result->mTextEntries[i].mDataSize);
FillNodeDataFromTxt(key, val, nodeData.resolutionData);
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