Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0dde9d0

Browse files
committedMar 14, 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 645aa39 commit 0dde9d0

Some content is hidden

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

44 files changed

+1863
-319
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

+29-32
Original file line numberDiff line numberDiff line change
@@ -30,62 +30,57 @@ CHIP_ERROR CASESessionManager::Init(chip::System::Layer * systemLayer, const CAS
3030
}
3131

3232
void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Callback::Callback<OnDeviceConnected> * onConnection,
33-
Callback::Callback<OnDeviceConnectionFailure> * onFailure
33+
Callback::Callback<OnDeviceConnectionFailure> * onFailure,
3434
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
35-
,
36-
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry
35+
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry,
3736
#endif // CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
38-
)
37+
TransportPayloadCapability transportPayloadCapability)
3938
{
4039
FindOrEstablishSessionHelper(peerId, onConnection, onFailure, nullptr
4140
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
4241
,
4342
attemptCount, onRetry
4443
#endif
45-
);
44+
,
45+
transportPayloadCapability);
4646
}
4747

4848
void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Callback::Callback<OnDeviceConnected> * onConnection,
49-
Callback::Callback<OperationalSessionSetup::OnSetupFailure> * onSetupFailure
49+
Callback::Callback<OperationalSessionSetup::OnSetupFailure> * onSetupFailure,
5050
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
51-
,
52-
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry
51+
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry,
5352
#endif
54-
)
53+
TransportPayloadCapability transportPayloadCapability)
5554
{
56-
FindOrEstablishSessionHelper(peerId, onConnection, nullptr, onSetupFailure
55+
FindOrEstablishSessionHelper(peerId, onConnection, nullptr, onSetupFailure,
5756
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
58-
,
59-
attemptCount, onRetry
57+
attemptCount, onRetry,
6058
#endif
61-
);
59+
transportPayloadCapability);
6260
}
6361

6462
void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Callback::Callback<OnDeviceConnected> * onConnection,
65-
nullptr_t
63+
nullptr_t,
6664
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
67-
,
68-
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry
65+
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry,
6966
#endif
70-
)
67+
TransportPayloadCapability transportPayloadCapability)
7168
{
72-
FindOrEstablishSessionHelper(peerId, onConnection, nullptr, nullptr
69+
FindOrEstablishSessionHelper(peerId, onConnection, nullptr, nullptr,
7370
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
74-
,
75-
attemptCount, onRetry
71+
attemptCount, onRetry,
7672
#endif
77-
);
73+
transportPayloadCapability);
7874
}
7975

8076
void CASESessionManager::FindOrEstablishSessionHelper(const ScopedNodeId & peerId,
8177
Callback::Callback<OnDeviceConnected> * onConnection,
8278
Callback::Callback<OnDeviceConnectionFailure> * onFailure,
83-
Callback::Callback<OperationalSessionSetup::OnSetupFailure> * onSetupFailure
79+
Callback::Callback<OperationalSessionSetup::OnSetupFailure> * onSetupFailure,
8480
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
85-
,
86-
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry
81+
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry,
8782
#endif
88-
)
83+
TransportPayloadCapability transportPayloadCapability)
8984
{
9085
ChipLogDetail(CASESessionManager, "FindOrEstablishSession: PeerId = [%d:" ChipLogFormatX64 "]", peerId.GetFabricIndex(),
9186
ChipLogValueX64(peerId.GetNodeId()));
@@ -124,12 +119,12 @@ void CASESessionManager::FindOrEstablishSessionHelper(const ScopedNodeId & peerI
124119

125120
if (onFailure != nullptr)
126121
{
127-
session->Connect(onConnection, onFailure);
122+
session->Connect(onConnection, onFailure, transportPayloadCapability);
128123
}
129124

130125
if (onSetupFailure != nullptr)
131126
{
132-
session->Connect(onConnection, onSetupFailure);
127+
session->Connect(onConnection, onSetupFailure, transportPayloadCapability);
133128
}
134129
}
135130

@@ -143,10 +138,11 @@ void CASESessionManager::ReleaseAllSessions()
143138
mConfig.sessionSetupPool->ReleaseAllSessionSetup();
144139
}
145140

146-
CHIP_ERROR CASESessionManager::GetPeerAddress(const ScopedNodeId & peerId, Transport::PeerAddress & addr)
141+
CHIP_ERROR CASESessionManager::GetPeerAddress(const ScopedNodeId & peerId, Transport::PeerAddress & addr,
142+
TransportPayloadCapability transportPayloadCapability)
147143
{
148144
ReturnErrorOnFailure(mConfig.sessionInitParams.Validate());
149-
auto optionalSessionHandle = FindExistingSession(peerId);
145+
auto optionalSessionHandle = FindExistingSession(peerId, transportPayloadCapability);
150146
ReturnErrorCodeIf(!optionalSessionHandle.HasValue(), CHIP_ERROR_NOT_CONNECTED);
151147
addr = optionalSessionHandle.Value()->AsSecureSession()->GetPeerAddress();
152148
return CHIP_NO_ERROR;
@@ -182,10 +178,11 @@ OperationalSessionSetup * CASESessionManager::FindExistingSessionSetup(const Sco
182178
return mConfig.sessionSetupPool->FindSessionSetup(peerId, forAddressUpdate);
183179
}
184180

185-
Optional<SessionHandle> CASESessionManager::FindExistingSession(const ScopedNodeId & peerId) const
181+
Optional<SessionHandle> CASESessionManager::FindExistingSession(const ScopedNodeId & peerId,
182+
const TransportPayloadCapability transportPayloadCapability) const
186183
{
187-
return mConfig.sessionInitParams.sessionManager->FindSecureSessionForNode(peerId,
188-
MakeOptional(Transport::SecureSession::Type::kCASE));
184+
return mConfig.sessionInitParams.sessionManager->FindSecureSessionForNode(
185+
peerId, MakeOptional(Transport::SecureSession::Type::kCASE), transportPayloadCapability);
189186
}
190187

191188
void CASESessionManager::ReleaseSession(OperationalSessionSetup * session)

0 commit comments

Comments
 (0)
Please sign in to comment.