Skip to content

Commit c930561

Browse files
authored
Add GetNewSessionHandlingPolicy callback (#18085)
* Add OnSessionUpdated callback * Resolve comment: rename a lot
1 parent 00ccf44 commit c930561

File tree

10 files changed

+35
-19
lines changed

10 files changed

+35
-19
lines changed

src/app/CASEClient.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ CHIP_ERROR CASEClient::EstablishSession(PeerId peer, const Transport::PeerAddres
3131
SessionEstablishmentDelegate * delegate)
3232
{
3333
// Create a UnauthenticatedSession for CASE pairing.
34-
// Don't use mSecureSession here, because mSecureSession is for encrypted communication.
3534
Optional<SessionHandle> session = mInitParams.sessionManager->CreateUnauthenticatedSession(peerAddress, remoteMRPConfig);
3635
VerifyOrReturnError(session.HasValue(), CHIP_ERROR_NO_MEMORY);
3736

src/app/OperationalDeviceProxy.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ typedef void (*OnDeviceConnectionFailure)(void * context, PeerId peerId, CHIP_ER
8585
* - Expose to consumers the secure session for talking to the device.
8686
*/
8787
class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy,
88-
public SessionReleaseDelegate,
88+
public SessionDelegate,
8989
public SessionEstablishmentDelegate,
9090
public AddressResolve::NodeListener
9191
{

src/controller/CommissioneeDeviceProxy.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct ControllerDeviceInitParams
5555
Messaging::ExchangeManager * exchangeMgr = nullptr;
5656
};
5757

58-
class CommissioneeDeviceProxy : public DeviceProxy, public SessionReleaseDelegate
58+
class CommissioneeDeviceProxy : public DeviceProxy, public SessionDelegate
5959
{
6060
public:
6161
~CommissioneeDeviceProxy() override;

src/messaging/ExchangeContext.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ExchangeContextDeletor
5757
*/
5858
class DLL_EXPORT ExchangeContext : public ReliableMessageContext,
5959
public ReferenceCounted<ExchangeContext, ExchangeContextDeletor>,
60-
public SessionReleaseDelegate
60+
public SessionDelegate
6161
{
6262
friend class ExchangeManager;
6363
friend class ExchangeContextDeletor;
@@ -81,7 +81,8 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext,
8181

8282
bool IsGroupExchangeContext() const { return mSession && mSession->IsGroupSession(); }
8383

84-
// Implement SessionReleaseDelegate
84+
// Implement SessionDelegate
85+
NewSessionHandlingPolicy GetNewSessionHandlingPolicy() override { return NewSessionHandlingPolicy::kStayAtOldSession; }
8586
void OnSessionReleased() override;
8687

8788
/**

src/protocols/secure_channel/CASESession.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler,
154154
void OnResponseTimeout(Messaging::ExchangeContext * ec) override;
155155
Messaging::ExchangeMessageDispatch & GetMessageDispatch() override { return SessionEstablishmentExchangeDispatch::Instance(); }
156156

157-
//// SessionReleaseDelegate ////
157+
//// SessionDelegate ////
158158
void OnSessionReleased() override;
159159

160160
FabricIndex GetFabricIndex() const { return mFabricInfo != nullptr ? mFabricInfo->GetFabricIndex() : kUndefinedFabricIndex; }

src/protocols/secure_channel/PASESession.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class DLL_EXPORT PASESession : public Messaging::UnsolicitedMessageHandler,
178178

179179
Messaging::ExchangeMessageDispatch & GetMessageDispatch() override { return SessionEstablishmentExchangeDispatch::Instance(); }
180180

181-
//// SessionReleaseDelegate ////
181+
//// SessionDelegate ////
182182
void OnSessionReleased() override;
183183

184184
private:

src/protocols/secure_channel/PairingSession.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace chip {
3838

3939
class SessionManager;
4040

41-
class DLL_EXPORT PairingSession : public SessionReleaseDelegate
41+
class DLL_EXPORT PairingSession : public SessionDelegate
4242
{
4343
public:
4444
PairingSession() : mSecureSessionHolder(*this) {}
@@ -49,6 +49,9 @@ class DLL_EXPORT PairingSession : public SessionReleaseDelegate
4949
virtual ScopedNodeId GetLocalScopedNodeId() const = 0;
5050
virtual CATValues GetPeerCATs() const = 0;
5151

52+
// Implement SessionDelegate
53+
NewSessionHandlingPolicy GetNewSessionHandlingPolicy() override { return NewSessionHandlingPolicy::kStayAtOldSession; }
54+
5255
Optional<uint16_t> GetLocalSessionId() const
5356
{
5457
Optional<uint16_t> localSessionId;

src/transport/SessionDelegate.h

+18-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,26 @@
2020

2121
namespace chip {
2222

23-
class DLL_EXPORT SessionReleaseDelegate
23+
class DLL_EXPORT SessionDelegate
2424
{
2525
public:
26-
virtual ~SessionReleaseDelegate() {}
26+
virtual ~SessionDelegate() {}
27+
28+
enum class NewSessionHandlingPolicy : uint8_t
29+
{
30+
kShiftToNewSession,
31+
kStayAtOldSession,
32+
};
33+
34+
/**
35+
* @brief
36+
* Called when a new secure session to the same peer is established, over the delegate of SessionHolderWithDelegate object. It
37+
* is suggested to shift to the newly created session.
38+
*
39+
* Note: the default implementation orders shifting to the new session, it should be fine for all users, unless the
40+
* SessionHolder object is expected to be sticky to a specified session.
41+
*/
42+
virtual NewSessionHandlingPolicy GetNewSessionHandlingPolicy() { return NewSessionHandlingPolicy::kShiftToNewSession; }
2743

2844
/**
2945
* @brief

src/transport/SessionHolder.h

+5-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace chip {
2828
* released when the underlying session is released. One must verify it is available before use. The object can be
2929
* created using SessionHandle.Grab()
3030
*/
31-
class SessionHolder : public SessionReleaseDelegate, public IntrusiveListNodeBase
31+
class SessionHolder : public SessionDelegate, public IntrusiveListNodeBase
3232
{
3333
public:
3434
SessionHolder() {}
@@ -39,7 +39,7 @@ class SessionHolder : public SessionReleaseDelegate, public IntrusiveListNodeBas
3939
SessionHolder & operator=(const SessionHolder &);
4040
SessionHolder & operator=(SessionHolder && that);
4141

42-
// Implement SessionReleaseDelegate
42+
// Implement SessionDelegate
4343
void OnSessionReleased() override { Release(); }
4444

4545
bool Contains(const SessionHandle & session) const
@@ -67,11 +67,8 @@ class SessionHolder : public SessionReleaseDelegate, public IntrusiveListNodeBas
6767
class SessionHolderWithDelegate : public SessionHolder
6868
{
6969
public:
70-
SessionHolderWithDelegate(SessionReleaseDelegate & delegate) : mDelegate(delegate) {}
71-
SessionHolderWithDelegate(const SessionHandle & handle, SessionReleaseDelegate & delegate) : mDelegate(delegate)
72-
{
73-
Grab(handle);
74-
}
70+
SessionHolderWithDelegate(SessionDelegate & delegate) : mDelegate(delegate) {}
71+
SessionHolderWithDelegate(const SessionHandle & handle, SessionDelegate & delegate) : mDelegate(delegate) { Grab(handle); }
7572
operator bool() const { return SessionHolder::operator bool(); }
7673

7774
void OnSessionReleased() override
@@ -83,7 +80,7 @@ class SessionHolderWithDelegate : public SessionHolder
8380
}
8481

8582
private:
86-
SessionReleaseDelegate & mDelegate;
83+
SessionDelegate & mDelegate;
8784
};
8885

8986
} // namespace chip

src/transport/tests/TestSessionManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const char PAYLOAD[] = "Hello!";
5959

6060
const char LARGE_PAYLOAD[kMaxAppMessageLen + 1] = "test message";
6161

62-
class TestSessionReleaseCallback : public SessionReleaseDelegate
62+
class TestSessionReleaseCallback : public SessionDelegate
6363
{
6464
public:
6565
void OnSessionReleased() override { mOldConnectionDropped = true; }

0 commit comments

Comments
 (0)