Skip to content

Commit

Permalink
Move chip tool resolve command to address_resolver (#15544)
Browse files Browse the repository at this point in the history
* Add MRP data for address resolution

* Also add TCP support as an operational discovery thing

* Switch chip-tool resolve command to use the address resolver interface
  • Loading branch information
andy31415 authored and pull[bot] committed Aug 8, 2023
1 parent f112136 commit 4401152
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
50 changes: 20 additions & 30 deletions examples/chip-tool/commands/discover/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,47 @@
#include "DiscoverCommissionablesCommand.h"
#include "DiscoverCommissionersCommand.h"
#include <controller/DeviceAddressUpdateDelegate.h>
#include <lib/dnssd/Resolver.h>
#include <lib/address_resolve/AddressResolve.h>

class Resolve : public DiscoverCommand, public chip::Dnssd::OperationalResolveDelegate
class Resolve : public DiscoverCommand, public chip::AddressResolve::NodeListener
{
public:
Resolve(CredentialIssuerCommands * credsIssuerConfig) : DiscoverCommand("resolve", credsIssuerConfig) {}
Resolve(CredentialIssuerCommands * credsIssuerConfig) : DiscoverCommand("resolve", credsIssuerConfig)
{
mNodeLookupHandle.SetListener(this);
}

/////////// DiscoverCommand Interface /////////
CHIP_ERROR RunCommand(NodeId remoteId, uint64_t fabricId) override
{
ReturnErrorOnFailure(mDNSResolver.Init(chip::DeviceLayer::UDPEndPointManager()));
mDNSResolver.SetOperationalDelegate(this);
ChipLogProgress(chipTool, "Dnssd: Searching for NodeId: %" PRIx64 " FabricId: %" PRIx64 " ...", remoteId, fabricId);
return mDNSResolver.ResolveNodeId(chip::PeerId().SetNodeId(remoteId).SetCompressedFabricId(fabricId),
chip::Inet::IPAddressType::kAny);
ReturnErrorOnFailure(chip::AddressResolve::Resolver::Instance().Init(&chip::DeviceLayer::SystemLayer()));

return chip::AddressResolve::Resolver::Instance().LookupNode(
chip::AddressResolve::NodeLookupRequest(chip::PeerId().SetNodeId(remoteId).SetCompressedFabricId(fabricId)),
mNodeLookupHandle);
}

void OnOperationalNodeResolved(const chip::Dnssd::ResolvedNodeData & nodeData) override
void OnNodeAddressResolved(const PeerId & peerId, const chip::AddressResolve::ResolveResult & result) override
{
char addrBuffer[chip::Transport::PeerAddress::kMaxToStringSize];

ChipLogProgress(chipTool, "NodeId Resolution: %" PRIu64 " Port: %" PRIu16, nodeData.mPeerId.GetNodeId(), nodeData.mPort);
ChipLogProgress(chipTool, " Hostname: %s", nodeData.mHostName);
for (size_t i = 0; i < nodeData.mNumIPs; ++i)
{
nodeData.mAddress[i].ToString(addrBuffer);
ChipLogProgress(chipTool, " addr %zu: %s", i, addrBuffer);
}

auto retryInterval = nodeData.GetMrpRetryIntervalIdle();

if (retryInterval.HasValue())
ChipLogProgress(chipTool, " MRP retry interval (idle): %" PRIu32 "ms", retryInterval.Value().count());

retryInterval = nodeData.GetMrpRetryIntervalActive();

if (retryInterval.HasValue())
ChipLogProgress(chipTool, " MRP retry interval (active): %" PRIu32 "ms", retryInterval.Value().count());
result.address.ToString(addrBuffer);

ChipLogProgress(chipTool, " Supports TCP: %s", nodeData.mSupportsTcp ? "yes" : "no");
ChipLogProgress(chipTool, "NodeId Resolution: %" PRIu64 " at %s", peerId.GetNodeId(), addrBuffer);
ChipLogProgress(chipTool, " MRP retry interval (idle): %" PRIu32 "ms", result.mrpConfig.mIdleRetransTimeout.count());
ChipLogProgress(chipTool, " MRP retry interval (active): %" PRIu32 "ms", result.mrpConfig.mActiveRetransTimeout.count());
ChipLogProgress(chipTool, " Supports TCP: %s", result.supportsTcp ? "yes" : "no");
SetCommandExitStatus(CHIP_NO_ERROR);
}

void OnOperationalNodeResolutionFailed(const chip::PeerId & peerId, CHIP_ERROR error) override
void OnNodeAddressResolutionFailed(const chip::PeerId & peerId, CHIP_ERROR error) override
{
ChipLogProgress(chipTool, "NodeId Resolution: failed!");
ChipLogProgress(chipTool, "NodeId %" PRIu64 " Resolution: failed!", peerId.GetNodeId());
SetCommandExitStatus(CHIP_ERROR_INTERNAL);
}

private:
chip::Dnssd::ResolverProxy mDNSResolver;
chip::AddressResolve::NodeLookupHandle mNodeLookupHandle;
};

class Update : public DiscoverCommand
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/suites/commands/discovery/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static_library("discovery") {
cflags = [ "-Wconversion" ]

public_deps = [
"${chip_root}/src/lib/dnssd",
"${chip_root}/src/lib/address_resolve",
"${chip_root}/src/lib/support",
]
}

0 comments on commit 4401152

Please sign in to comment.