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

Plumb Peer DNS-SD advertisement for TCP support into SessionSetup context #30392 #33481

Merged
merged 34 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
80d7889
Merge pull request #9 from project-chip/master
hnnajh Jan 7, 2021
b387cc2
Merge pull request #10 from project-chip/master
hnnajh Jan 14, 2021
4a5aa89
Merge pull request #14 from project-chip/master
hnnajh Jan 15, 2021
fc45893
Merge pull request #18 from project-chip/master
hnnajh Feb 12, 2021
6ae55ad
Merge pull request #23 from project-chip/master
hnnajh Feb 19, 2021
113723c
Merge pull request #24 from project-chip/master
hnnajh Feb 25, 2021
4e2090e
Merge pull request #26 from project-chip/master
hnnajh Mar 6, 2021
ebb3d8a
Merge pull request #28 from project-chip/master
hnnajh Mar 29, 2021
05df01e
Merge pull request #48 from project-chip/master
hnnajh Apr 8, 2022
1211c4f
Merge pull request #196 from project-chip/master
hnnajh May 13, 2024
274c135
Plumb Peer DNS-SD advertisement for TCP support into SessionSetup con…
hnnajh May 16, 2024
6dbcf24
Merge branch 'master' into tcp_mdns_new
hnnajh May 16, 2024
3617481
Restyled by clang-format
restyled-commits May 16, 2024
c61be5c
Fix unit tests
hnnajh May 16, 2024
09b1774
Merge pull request #197 from project-chip/master
hnnajh May 16, 2024
d34ed79
Merge pull request #198 from hnnajh/local-master
hnnajh May 16, 2024
1373fb4
Fix build error
hnnajh May 16, 2024
a76de01
address Boris comments
hnnajh May 16, 2024
4e79b91
reflect mdns tcp support in session estabishment
hnnajh May 17, 2024
bc9c12d
Restyled by clang-format
restyled-commits May 17, 2024
534f138
Update src/app/OperationalSessionSetup.cpp
hnnajh Jun 12, 2024
416154e
Update src/app/OperationalSessionSetup.cpp
hnnajh Jun 12, 2024
23fa6b1
Merge branch 'master' into tcp_mdns_new
hnnajh Jun 12, 2024
4b9c92a
fixing minor comments
hnnajh Jun 12, 2024
c965316
Restyled by clang-format
restyled-commits Jun 12, 2024
d57c688
add an extra check on tcp support
hnnajh Jul 3, 2024
a2b50ae
Restyled by clang-format
restyled-commits Jul 3, 2024
4680b90
Merge branch 'master' into tcp_mdns_new
hnnajh Jul 3, 2024
334bfcd
add a check on tcp server enablement
hnnajh Jul 3, 2024
f7770d8
Merge branch 'master' into tcp_mdns_new
hnnajh Jul 3, 2024
d6f6530
Merge branch 'master' into tcp_mdns_new
hnnajh Jul 3, 2024
77fb026
add peer info in log
hnnajh Jul 4, 2024
af4e693
Restyled by clang-format
restyled-commits Jul 4, 2024
f9ef895
update log message
hnnajh Jul 4, 2024
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
3 changes: 2 additions & 1 deletion examples/chip-tool/commands/common/RemoteDataModelLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::CommissionNodeData & nodeDat
value["rotatingIdLen"] = static_cast<uint64_t>(commissionData.rotatingIdLen);
value["pairingHint"] = commissionData.pairingHint;
value["pairingInstruction"] = commissionData.pairingInstruction;
value["supportsTcp"] = resolutionData.supportsTcp;
value["supportsTcpClient"] = resolutionData.supportsTcpClient;
value["supportsTcpServer"] = resolutionData.supportsTcpServer;
value["port"] = resolutionData.port;
value["numIPs"] = static_cast<uint8_t>(resolutionData.numIPs);

Expand Down
3 changes: 2 additions & 1 deletion examples/chip-tool/commands/discover/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class Resolve : public DiscoverCommand, public chip::AddressResolve::NodeListene
result.mrpRemoteConfig.mIdleRetransTimeout.count());
ChipLogProgress(chipTool, " MRP retry interval (active): %" PRIu32 "ms",
result.mrpRemoteConfig.mActiveRetransTimeout.count());
ChipLogProgress(chipTool, " Supports TCP: %s", result.supportsTcp ? "yes" : "no");
ChipLogProgress(chipTool, " Supports TCP Client: %s", result.supportsTcpClient ? "yes" : "no");
ChipLogProgress(chipTool, " Supports TCP Server: %s", result.supportsTcpServer ? "yes" : "no");
ChipLogProgress(chipTool, " ICD is operating as: %s", result.isICDOperatingAsLIT ? "LIT" : "SIT");
SetCommandExitStatus(CHIP_NO_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::CommissionNodeData & nodeDat
value["rotatingIdLen"] = static_cast<uint64_t>(commissionData.rotatingIdLen);
value["pairingHint"] = commissionData.pairingHint;
value["pairingInstruction"] = commissionData.pairingInstruction;
value["supportsTcp"] = resolutionData.supportsTcp;
value["supportsTcpClient"] = resolutionData.supportsTcpClient;
value["supportsTcpServer"] = resolutionData.supportsTcpServer;
value["port"] = resolutionData.port;
value["numIPs"] = static_cast<uint8_t>(resolutionData.numIPs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
<arg name="rotatingIdLen" type="int64u"/>
<arg name="pairingHint" type="int16u"/>
<arg name="pairingInstruction" type="char_string"/>
<arg name="supportsTcp" type="boolean"/>
<arg name="supportsTcpClient" type="boolean"/>
<arg name="supportsTcpServer" type="boolean"/>
<arg name="numIPs" type="int8u"/>
<arg name="port" type="int16u"/>
<arg name="mrpRetryIntervalIdle" type="int32u" optional="true"/>
Expand Down
29 changes: 21 additions & 8 deletions src/app/OperationalSessionSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ void OperationalSessionSetup::Connect(Callback::Callback<OnDeviceConnected> * on
Connect(onConnection, nullptr, onSetupFailure, transportPayloadCapability);
}

void OperationalSessionSetup::UpdateDeviceData(const Transport::PeerAddress & addr, const ReliableMessageProtocolConfig & config)
hnnajh marked this conversation as resolved.
Show resolved Hide resolved
void OperationalSessionSetup::UpdateDeviceData(const ResolveResult & result)
{
auto & config = result.mrpRemoteConfig;
auto addr = result.address;
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
// Make sure to clear out our reason for trying the next result first thing,
// so it does not stick around in various error cases.
Expand Down Expand Up @@ -248,7 +250,7 @@ void OperationalSessionSetup::UpdateDeviceData(const Transport::PeerAddress & ad
return;
}

CHIP_ERROR err = EstablishConnection(config);
CHIP_ERROR err = EstablishConnection(result);
LogErrorOnFailure(err);
if (err == CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -292,15 +294,26 @@ void OperationalSessionSetup::UpdateDeviceData(const Transport::PeerAddress & ad
// Do not touch `this` instance anymore; it has been destroyed in DequeueConnectionCallbacks.
}

CHIP_ERROR OperationalSessionSetup::EstablishConnection(const ReliableMessageProtocolConfig & config)
CHIP_ERROR OperationalSessionSetup::EstablishConnection(const ResolveResult & result)
{
auto & config = result.mrpRemoteConfig;
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
// TODO: Combine LargePayload flag with DNS-SD advertisements from peer.
// Issue #32348.
if (mTransportPayloadCapability == TransportPayloadCapability::kLargePayload)
{
// Set the transport type for carrying large payloads
mDeviceAddress.SetTransportType(chip::Transport::Type::kTcp);
if (result.supportsTcpServer)
{
// Set the transport type for carrying large payloads
mDeviceAddress.SetTransportType(chip::Transport::Type::kTcp);
}
else
{
// we should not set the large payload while the TCP support is not enabled
ChipLogError(
Discovery,
"LargePayload session requested but peer does not support TCP server, PeerNodeId=" ChipLogFormatScopedNodeId,
ChipLogValueScopedNodeId(mPeerId));
return CHIP_ERROR_INTERNAL;
}
}
#endif

Expand Down Expand Up @@ -627,7 +640,7 @@ void OperationalSessionSetup::PerformAddressUpdate()

void OperationalSessionSetup::OnNodeAddressResolved(const PeerId & peerId, const ResolveResult & result)
{
UpdateDeviceData(result.address, result.mrpRemoteConfig);
UpdateDeviceData(result);
}

void OperationalSessionSetup::OnNodeAddressResolutionFailed(const PeerId & peerId, CHIP_ERROR reason)
Expand Down
4 changes: 2 additions & 2 deletions src/app/OperationalSessionSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class DLL_EXPORT OperationalSessionSetup : public SessionEstablishmentDelegate,

void MoveToState(State aTargetState);

CHIP_ERROR EstablishConnection(const ReliableMessageProtocolConfig & config);
CHIP_ERROR EstablishConnection(const AddressResolve::ResolveResult & result);

/*
* This checks to see if an existing CASE session exists to the peer within the SessionManager
Expand Down Expand Up @@ -419,7 +419,7 @@ class DLL_EXPORT OperationalSessionSetup : public SessionEstablishmentDelegate,
/**
* This function will set new IP address, port and MRP retransmission intervals of the device.
*/
void UpdateDeviceData(const Transport::PeerAddress & addr, const ReliableMessageProtocolConfig & config);
void UpdateDeviceData(const AddressResolve::ResolveResult & result);

#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners(
{
ChipLogProgress(Discovery, "\tMrp Interval active\tNot present");
}
ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->supportsTcp);

ChipLogProgress(Discovery, "\tSupports TCP Client\t\t%d", dnsSdInfo->supportsTcpClient);
ChipLogProgress(Discovery, "\tSupports TCP Server\t\t%d", dnsSdInfo->supportsTcpServer);

if (dnsSdInfo->isICDOperatingAsLIT.has_value())
{
Expand Down
4 changes: 3 additions & 1 deletion src/controller/python/ChipDeviceController-Discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ void pychip_DeviceController_IterateDiscoveredCommissionableNodes(Controller::De
{
jsonVal["mrpRetryActiveThreshold"] = activeThreshold->count();
}
jsonVal["supportsTcp"] = dnsSdInfo->supportsTcp;

jsonVal["supportsTcpClient"] = dnsSdInfo->supportsTcpClient;
jsonVal["supportsTcpServer"] = dnsSdInfo->supportsTcpServer;
{
Json::Value addresses;
for (unsigned j = 0; j < dnsSdInfo->numIPs; ++j)
Expand Down
3 changes: 2 additions & 1 deletion src/controller/python/chip/discovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class CommissionableNode():
mrpRetryIntervalIdle: int = None
mrpRetryIntervalActive: int = None
mrpRetryActiveThreshold: int = None
supportsTcp: bool = None
supportsTcpClient: bool = None
supportsTcpServer: bool = None
isICDOperatingAsLIT: bool = None
addresses: List[str] = None
rotatingId: Optional[str] = None
Expand Down
3 changes: 2 additions & 1 deletion src/controller/python/chip/yaml/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,8 @@ def decode(self, result: _ActionResult):
'mrpRetryIntervalIdle': response.mrpRetryIntervalIdle,
'mrpRetryIntervalActive': response.mrpRetryIntervalActive,
'mrpRetryActiveThreshold': response.mrpRetryActiveThreshold,
'supportsTcp': response.supportsTcp,
'supportsTcpClient': response.supportsTcpClient,
'supportsTcpServer': response.supportsTcpServer,
'isICDOperatingAsLIT': response.isICDOperatingAsLIT,
'addresses': response.addresses,
'rotatingId': response.rotatingId,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/address_resolve/AddressResolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ struct ResolveResult
{
Transport::PeerAddress address;
ReliableMessageProtocolConfig mrpRemoteConfig;
bool supportsTcp = false;
bool supportsTcpServer = false;
bool supportsTcpClient = false;
bool isICDOperatingAsLIT = false;

ResolveResult() : address(Transport::Type::kUdp), mrpRemoteConfig(GetDefaultMRPConfig()) {}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/address_resolve/AddressResolve_DefaultImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ void Resolver::OnOperationalNodeResolved(const Dnssd::ResolvedNodeData & nodeDat

result.address.SetPort(nodeData.resolutionData.port);
result.address.SetInterface(nodeData.resolutionData.interfaceId);
result.mrpRemoteConfig = nodeData.resolutionData.GetRemoteMRPConfig();
result.supportsTcp = nodeData.resolutionData.supportsTcp;
result.mrpRemoteConfig = nodeData.resolutionData.GetRemoteMRPConfig();
result.supportsTcpClient = nodeData.resolutionData.supportsTcpClient;
result.supportsTcpServer = nodeData.resolutionData.supportsTcpServer;

if (nodeData.resolutionData.isICDOperatingAsLIT.has_value())
{
Expand Down
3 changes: 2 additions & 1 deletion src/lib/address_resolve/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class PrintOutNodeListener : public chip::AddressResolve::NodeListener
result.address.ToString(addr_string);

ChipLogProgress(Discovery, "Resolve completed: %s", addr_string);
ChipLogProgress(Discovery, " Supports TCP: %s", result.supportsTcp ? "YES" : "NO");
ChipLogProgress(Discovery, " Supports TCP Client: %s", result.supportsTcpClient ? "YES" : "NO");
ChipLogProgress(Discovery, " Supports TCP Server: %s", result.supportsTcpServer ? "YES" : "NO");
ChipLogProgress(Discovery, " MRP IDLE retransmit timeout: %u ms", result.mrpRemoteConfig.mIdleRetransTimeout.count());
ChipLogProgress(Discovery, " MRP ACTIVE retransmit timeout: %u ms", result.mrpRemoteConfig.mActiveRetransTimeout.count());
ChipLogProgress(Discovery, " MRP ACTIVE Threshold time: %u ms", result.mrpRemoteConfig.mActiveThresholdTime.count());
Expand Down
11 changes: 9 additions & 2 deletions src/lib/dnssd/TxtFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ namespace Dnssd {

namespace Internal {

constexpr uint8_t kTCPClient = 1;
constexpr uint8_t kTCPServer = 2;

namespace {

char SafeToLower(uint8_t ch)
Expand Down Expand Up @@ -276,9 +279,13 @@ void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & value, CommonRes
case TxtFieldKey::kSessionActiveThreshold:
nodeData.mrpRetryActiveThreshold = Internal::GetRetryActiveThreshold(value);
break;
case TxtFieldKey::kTcpSupported:
nodeData.supportsTcp = Internal::MakeBoolFromAsciiDecimal(value);
case TxtFieldKey::kTcpSupported: {
// bit 0 is reserved and deprecated
uint8_t support = Internal::MakeU8FromAsciiDecimal(value);
nodeData.supportsTcpClient = (support & (1 << Internal::kTCPClient)) != 0;
nodeData.supportsTcpServer = (support & (1 << Internal::kTCPServer)) != 0;
break;
}
case TxtFieldKey::kLongIdleTimeICD:
nodeData.isICDOperatingAsLIT = Internal::MakeOptionalBoolFromAsciiDecimal(value);
break;
Expand Down
9 changes: 6 additions & 3 deletions src/lib/dnssd/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ struct CommonResolutionData

uint16_t port = 0;
char hostName[kHostNameMaxLength + 1] = {};
bool supportsTcp = false;
bool supportsTcpClient = false;
bool supportsTcpServer = false;
std::optional<bool> isICDOperatingAsLIT;
std::optional<System::Clock::Milliseconds32> mrpRetryIntervalIdle;
std::optional<System::Clock::Milliseconds32> mrpRetryIntervalActive;
Expand Down Expand Up @@ -131,7 +132,8 @@ struct CommonResolutionData
isICDOperatingAsLIT = std::nullopt;
numIPs = 0;
port = 0;
supportsTcp = false;
supportsTcpClient = false;
supportsTcpServer = false;
interfaceId = Inet::InterfaceId::Null();
for (auto & addr : ipAddress)
{
Expand Down Expand Up @@ -181,7 +183,8 @@ struct CommonResolutionData
{
ChipLogDetail(Discovery, "\tMrp Active Threshold: not present");
}
ChipLogDetail(Discovery, "\tTCP Supported: %d", supportsTcp);
ChipLogDetail(Discovery, "\tTCP Client Supported: %d", supportsTcpClient);
ChipLogDetail(Discovery, "\tTCP Server Supported: %d", supportsTcpServer);
if (isICDOperatingAsLIT.has_value())
{
ChipLogDetail(Discovery, "\tThe ICD operates in %s", *isICDOperatingAsLIT ? "LIT" : "SIT");
Expand Down
6 changes: 4 additions & 2 deletions src/lib/dnssd/tests/TestIncrementalResolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ TEST(TestIncrementalResolve, TestParseOperational)
EXPECT_FALSE(nodeData.operationalData.hasZeroTTL);
EXPECT_EQ(nodeData.resolutionData.numIPs, 1u);
EXPECT_EQ(nodeData.resolutionData.port, 0x1234);
EXPECT_FALSE(nodeData.resolutionData.supportsTcp);
EXPECT_FALSE(nodeData.resolutionData.supportsTcpServer);
EXPECT_FALSE(nodeData.resolutionData.supportsTcpClient);
EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().has_value());
EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalIdle(), std::make_optional(chip::System::Clock::Milliseconds32(23)));

Expand Down Expand Up @@ -396,7 +397,8 @@ TEST(TestIncrementalResolve, TestParseCommissionable)
// validate data as it was passed in
EXPECT_EQ(nodeData.numIPs, 2u);
EXPECT_EQ(nodeData.port, 0x1234);
EXPECT_FALSE(nodeData.supportsTcp);
EXPECT_FALSE(nodeData.supportsTcpClient);
EXPECT_FALSE(nodeData.supportsTcpServer);
EXPECT_EQ(nodeData.GetMrpRetryIntervalActive(), std::make_optional(chip::System::Clock::Milliseconds32(321)));
EXPECT_FALSE(nodeData.GetMrpRetryIntervalIdle().has_value());

Expand Down
Loading
Loading