Skip to content

Commit

Permalink
Improve logging for minMdns (#10319)
Browse files Browse the repository at this point in the history
* Improve logging for minMdns

- Remove duplicate log lines that falsely indicated
  sending when it was just building responses
- When responding, clarify the identity of the querier
  that caused the response to be generated and sent

Testing done:

- Ran unit tests and all-clusters-app commissioning on Linux

* Restyled
  • Loading branch information
tcarmelveilleux authored and pull[bot] committed Oct 27, 2021
1 parent ab58e36 commit 5664420
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/lib/mdns/Advertiser_ImplMinimalMdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ class AdvertiserMinMdns : public ServiceAdvertiser,
void AdvertiserMinMdns::OnMdnsPacketData(const BytesRange & data, const chip::Inet::IPPacketInfo * info)
{
#ifdef DETAIL_LOGGING
ChipLogDetail(Discovery, "MinMdns received a query.");
char srcAddressString[chip::Inet::kMaxIPAddressStringLength];
VerifyOrDie(info->SrcAddress.ToString(srcAddressString) != nullptr);
ChipLogDetail(Discovery, "Received an mDNS query from %s", srcAddressString);
#endif

mCurrentSource = info;
Expand Down
7 changes: 5 additions & 2 deletions src/lib/mdns/minimal/ResponseSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,19 @@ CHIP_ERROR ResponseSender::FlushReply()

if (mResponseBuilder.HasResponseRecords())
{
char srcAddressString[chip::Inet::kMaxIPAddressStringLength];
VerifyOrDie(mSendState.GetSourceAddress().ToString(srcAddressString) != nullptr);

if (mSendState.SendUnicast())
{
ChipLogProgress(Discovery, "Directly sending mDns reply to peer on port %d", mSendState.GetSourcePort());
ChipLogProgress(Discovery, "Directly sending mDns reply to peer %s on port %d", srcAddressString,
mSendState.GetSourcePort());
ReturnErrorOnFailure(mServer->DirectSend(mResponseBuilder.ReleasePacket(), mSendState.GetSourceAddress(),
mSendState.GetSourcePort(), mSendState.GetSourceInterfaceId()));
}
else
{
ChipLogProgress(Discovery, "Broadcasting mDns reply");
ChipLogProgress(Discovery, "Broadcasting mDns reply for query from %s", srcAddressString);
ReturnErrorOnFailure(
mServer->BroadcastSend(mResponseBuilder.ReleasePacket(), kMdnsStandardPort, mSendState.GetSourceInterfaceId()));
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib/mdns/minimal/responders/QueryResponder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ void QueryResponderBase::MarkAdditionalRepliesFor(QueryResponderIterator it)

void QueryResponderBase::AddAllResponses(const chip::Inet::IPPacketInfo * source, ResponderDelegate * delegate)
{
ChipLogProgress(Discovery, "Replying to DNS-SD service listing request");

// reply to dns-sd service list request
for (size_t i = 0; i < mResponderInfoSize; i++)
{
Expand Down

0 comments on commit 5664420

Please sign in to comment.