Skip to content

Commit

Permalink
Improve mdns logging a bit. (#7924)
Browse files Browse the repository at this point in the history
Log what we ended up resolving in minimal mdns also, not just platform mdns.

Log port, not just IP.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 31, 2021
1 parent 0badf43 commit 1177735
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/lib/mdns/Discovery_ImplPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,7 @@ void DiscoveryImplPlatform::HandleNodeIdResolve(void * context, MdnsService * re
nodeData.mAddress = result->mAddress.ValueOr({});
nodeData.mPort = result->mPort;

#if CHIP_PROGRESS_LOGGING
char addrBuffer[Inet::kMaxIPAddressStringLength + 1];
nodeData.mAddress.ToString(addrBuffer);
#endif // CHIP_PROGRESS_LOGGING
ChipLogProgress(Discovery, "Node ID resolved for 0x" ChipLogFormatX64 " to %s", ChipLogValueX64(nodeData.mPeerId.GetNodeId()),
addrBuffer);
nodeData.LogNodeIdResolved();
mgr->mResolverDelegate->OnNodeIdResolved(nodeData);
}

Expand Down
13 changes: 13 additions & 0 deletions src/lib/mdns/Resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <cstdint>

#include "lib/support/logging/CHIPLogging.h"
#include <core/CHIPError.h>
#include <core/PeerId.h>
#include <inet/IPAddress.h>
Expand All @@ -30,6 +31,18 @@ namespace Mdns {

struct ResolvedNodeData
{
void LogNodeIdResolved()
{
#if CHIP_PROGRESS_LOGGING
char addrBuffer[Inet::kMaxIPAddressStringLength + 1];
mAddress.ToString(addrBuffer);
// Would be nice to log the interface id, but sorting out how to do so
// across our differnet InterfaceId implementations is a pain.
ChipLogProgress(Discovery, "Node ID resolved for 0x" ChipLogFormatX64 " to [%s]:%" PRIu16,
ChipLogValueX64(mPeerId.GetNodeId()), addrBuffer, mPort);
#endif // CHIP_PROGRESS_LOGGING
}

PeerId mPeerId;
Inet::InterfaceId mInterfaceId;
Inet::IPAddress mAddress;
Expand Down
1 change: 1 addition & 0 deletions src/lib/mdns/Resolver_ImplMinimalMdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ void PacketDataReporter::OnComplete()
}
else if (mDiscoveryType == DiscoveryType::kOperational && mHasIP && mHasNodePort)
{
mNodeData.LogNodeIdResolved();
mDelegate->OnNodeIdResolved(mNodeData);
}
}
Expand Down

0 comments on commit 1177735

Please sign in to comment.