Skip to content

Commit 95cb010

Browse files
committedFeb 26, 2024
TCP connection setup/management and CASESession association.
Add ConnectToPeer() API for explicit connection setup. Currently, connecting to a peer is coupled with sending a message to the peer. This decouples the two and creates a clear API for connecting to a peer address. Goes along with the existing Disconnect() API. This would be essential during activation of retained sessions by solely connecting to the peer and associating with the retained session. Surface Connection completion and Closure callbacks and hook them through SessionManager(TransportMgr delegate) and CASESession. Mark SecureSession as defunct on connection closures. Modify ActiveConnectionState in TCPBase to hold state for each connection, so that it is able to handle the various control flow paths. Associate a session with a connection object. Associate the PeerAddress with the session early. Pass the PeerAddress in the Find APIs. This helps check against the correct TransportType when searching for a Sesssion in the SessionTable. Add a `large payload` flag in EstablishSession() and Session lookup functions to create/associate with the correct session and transport. Have default configurations for TCP in a separate TCPConfig.h. Refactor echo_requester.cpp and echo_responder.cpp to use the session associated with the connection. Handle Connection closure at ExchangeMgr and uplevel to corresponding ExchangeContext using the corresponding session handle. Add tests around connection establishment in TestTCP.
1 parent de43a78 commit 95cb010

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1917
-289
lines changed
 

‎examples/shell/shell_common/include/Globals.h

+2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
#include <protocols/secure_channel/MessageCounterManager.h>
2525
#include <transport/SessionHolder.h>
2626
#include <transport/SessionManager.h>
27+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
2728
#include <transport/raw/TCP.h>
29+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
2830
#include <transport/raw/UDP.h>
2931

3032
#if INET_CONFIG_ENABLE_TCP_ENDPOINT

‎src/app/CASESessionManager.cpp

+30-13
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Cal
3535
,
3636
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry
3737
#endif // CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
38-
)
38+
,
39+
TransportPayloadCapability transportPayloadCapability)
3940
{
4041
FindOrEstablishSessionHelper(peerId, onConnection, onFailure, nullptr
4142
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
4243
,
4344
attemptCount, onRetry
4445
#endif
45-
);
46+
,
47+
transportPayloadCapability);
4648
}
4749

4850
void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Callback::Callback<OnDeviceConnected> * onConnection,
@@ -51,14 +53,16 @@ void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Cal
5153
,
5254
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry
5355
#endif
54-
)
56+
,
57+
TransportPayloadCapability transportPayloadCapability)
5558
{
5659
FindOrEstablishSessionHelper(peerId, onConnection, nullptr, onSetupFailure
5760
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
5861
,
5962
attemptCount, onRetry
6063
#endif
61-
);
64+
,
65+
transportPayloadCapability);
6266
}
6367

6468
void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Callback::Callback<OnDeviceConnected> * onConnection,
@@ -67,14 +71,16 @@ void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Cal
6771
,
6872
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry
6973
#endif
70-
)
74+
,
75+
TransportPayloadCapability transportPayloadCapability)
7176
{
7277
FindOrEstablishSessionHelper(peerId, onConnection, nullptr, nullptr
7378
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
7479
,
7580
attemptCount, onRetry
7681
#endif
77-
);
82+
,
83+
transportPayloadCapability);
7884
}
7985

8086
void CASESessionManager::FindOrEstablishSessionHelper(const ScopedNodeId & peerId,
@@ -85,7 +91,8 @@ void CASESessionManager::FindOrEstablishSessionHelper(const ScopedNodeId & peerI
8591
,
8692
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry
8793
#endif
88-
)
94+
,
95+
TransportPayloadCapability transportPayloadCapability)
8996
{
9097
ChipLogDetail(CASESessionManager, "FindOrEstablishSession: PeerId = [%d:" ChipLogFormatX64 "]", peerId.GetFabricIndex(),
9198
ChipLogValueX64(peerId.GetNodeId()));
@@ -124,12 +131,12 @@ void CASESessionManager::FindOrEstablishSessionHelper(const ScopedNodeId & peerI
124131

125132
if (onFailure != nullptr)
126133
{
127-
session->Connect(onConnection, onFailure);
134+
session->Connect(onConnection, onFailure, transportPayloadCapability);
128135
}
129136

130137
if (onSetupFailure != nullptr)
131138
{
132-
session->Connect(onConnection, onSetupFailure);
139+
session->Connect(onConnection, onSetupFailure, transportPayloadCapability);
133140
}
134141
}
135142

@@ -146,7 +153,16 @@ void CASESessionManager::ReleaseAllSessions()
146153
CHIP_ERROR CASESessionManager::GetPeerAddress(const ScopedNodeId & peerId, Transport::PeerAddress & addr)
147154
{
148155
ReturnErrorOnFailure(mConfig.sessionInitParams.Validate());
149-
auto optionalSessionHandle = FindExistingSession(peerId);
156+
auto optionalSessionHandle = FindExistingSession(peerId, TransportPayloadCapability::kDefault);
157+
ReturnErrorCodeIf(!optionalSessionHandle.HasValue(), CHIP_ERROR_NOT_CONNECTED);
158+
addr = optionalSessionHandle.Value()->AsSecureSession()->GetPeerAddress();
159+
return CHIP_NO_ERROR;
160+
}
161+
162+
CHIP_ERROR CASESessionManager::GetPeerAddressForLargePayloadSession(const ScopedNodeId & peerId, Transport::PeerAddress & addr)
163+
{
164+
ReturnErrorOnFailure(mConfig.sessionInitParams.Validate());
165+
auto optionalSessionHandle = FindExistingSession(peerId, TransportPayloadCapability::kLarge);
150166
ReturnErrorCodeIf(!optionalSessionHandle.HasValue(), CHIP_ERROR_NOT_CONNECTED);
151167
addr = optionalSessionHandle.Value()->AsSecureSession()->GetPeerAddress();
152168
return CHIP_NO_ERROR;
@@ -182,10 +198,11 @@ OperationalSessionSetup * CASESessionManager::FindExistingSessionSetup(const Sco
182198
return mConfig.sessionSetupPool->FindSessionSetup(peerId, forAddressUpdate);
183199
}
184200

185-
Optional<SessionHandle> CASESessionManager::FindExistingSession(const ScopedNodeId & peerId) const
201+
Optional<SessionHandle> CASESessionManager::FindExistingSession(const ScopedNodeId & peerId,
202+
const TransportPayloadCapability transportPayloadCapability) const
186203
{
187-
return mConfig.sessionInitParams.sessionManager->FindSecureSessionForNode(peerId,
188-
MakeOptional(Transport::SecureSession::Type::kCASE));
204+
return mConfig.sessionInitParams.sessionManager->FindSecureSessionForNode(
205+
peerId, MakeOptional(Transport::SecureSession::Type::kCASE), transportPayloadCapability);
189206
}
190207

191208
void CASESessionManager::ReleaseSession(OperationalSessionSetup * session)

0 commit comments

Comments
 (0)