Skip to content

Commit

Permalink
Add GetNewSessionHandlingPolicy callback (#18085)
Browse files Browse the repository at this point in the history
* Add OnSessionUpdated callback

* Resolve comment: rename a lot
  • Loading branch information
kghost authored and pull[bot] committed Aug 4, 2023
1 parent 7f4807f commit 470cc4b
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/app/CASEClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ CHIP_ERROR CASEClient::EstablishSession(PeerId peer, const Transport::PeerAddres
SessionEstablishmentDelegate * delegate)
{
// Create a UnauthenticatedSession for CASE pairing.
// Don't use mSecureSession here, because mSecureSession is for encrypted communication.
Optional<SessionHandle> session = mInitParams.sessionManager->CreateUnauthenticatedSession(peerAddress, remoteMRPConfig);
VerifyOrReturnError(session.HasValue(), CHIP_ERROR_NO_MEMORY);

Expand Down
2 changes: 1 addition & 1 deletion src/app/OperationalDeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ typedef void (*OnDeviceConnectionFailure)(void * context, PeerId peerId, CHIP_ER
* - Expose to consumers the secure session for talking to the device.
*/
class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy,
public SessionReleaseDelegate,
public SessionDelegate,
public SessionEstablishmentDelegate,
public AddressResolve::NodeListener
{
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CommissioneeDeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct ControllerDeviceInitParams
Messaging::ExchangeManager * exchangeMgr = nullptr;
};

class CommissioneeDeviceProxy : public DeviceProxy, public SessionReleaseDelegate
class CommissioneeDeviceProxy : public DeviceProxy, public SessionDelegate
{
public:
~CommissioneeDeviceProxy() override;
Expand Down
5 changes: 3 additions & 2 deletions src/messaging/ExchangeContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ExchangeContextDeletor
*/
class DLL_EXPORT ExchangeContext : public ReliableMessageContext,
public ReferenceCounted<ExchangeContext, ExchangeContextDeletor>,
public SessionReleaseDelegate
public SessionDelegate
{
friend class ExchangeManager;
friend class ExchangeContextDeletor;
Expand All @@ -81,7 +81,8 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext,

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

// Implement SessionReleaseDelegate
// Implement SessionDelegate
NewSessionHandlingPolicy GetNewSessionHandlingPolicy() override { return NewSessionHandlingPolicy::kStayAtOldSession; }
void OnSessionReleased() override;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/secure_channel/CASESession.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler,
void OnResponseTimeout(Messaging::ExchangeContext * ec) override;
Messaging::ExchangeMessageDispatch & GetMessageDispatch() override { return SessionEstablishmentExchangeDispatch::Instance(); }

//// SessionReleaseDelegate ////
//// SessionDelegate ////
void OnSessionReleased() override;

FabricIndex GetFabricIndex() const { return mFabricInfo != nullptr ? mFabricInfo->GetFabricIndex() : kUndefinedFabricIndex; }
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/secure_channel/PASESession.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class DLL_EXPORT PASESession : public Messaging::UnsolicitedMessageHandler,

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

//// SessionReleaseDelegate ////
//// SessionDelegate ////
void OnSessionReleased() override;

private:
Expand Down
5 changes: 4 additions & 1 deletion src/protocols/secure_channel/PairingSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace chip {

class SessionManager;

class DLL_EXPORT PairingSession : public SessionReleaseDelegate
class DLL_EXPORT PairingSession : public SessionDelegate
{
public:
PairingSession() : mSecureSessionHolder(*this) {}
Expand All @@ -49,6 +49,9 @@ class DLL_EXPORT PairingSession : public SessionReleaseDelegate
virtual ScopedNodeId GetLocalScopedNodeId() const = 0;
virtual CATValues GetPeerCATs() const = 0;

// Implement SessionDelegate
NewSessionHandlingPolicy GetNewSessionHandlingPolicy() override { return NewSessionHandlingPolicy::kStayAtOldSession; }

Optional<uint16_t> GetLocalSessionId() const
{
Optional<uint16_t> localSessionId;
Expand Down
20 changes: 18 additions & 2 deletions src/transport/SessionDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,26 @@

namespace chip {

class DLL_EXPORT SessionReleaseDelegate
class DLL_EXPORT SessionDelegate
{
public:
virtual ~SessionReleaseDelegate() {}
virtual ~SessionDelegate() {}

enum class NewSessionHandlingPolicy : uint8_t
{
kShiftToNewSession,
kStayAtOldSession,
};

/**
* @brief
* Called when a new secure session to the same peer is established, over the delegate of SessionHolderWithDelegate object. It
* is suggested to shift to the newly created session.
*
* Note: the default implementation orders shifting to the new session, it should be fine for all users, unless the
* SessionHolder object is expected to be sticky to a specified session.
*/
virtual NewSessionHandlingPolicy GetNewSessionHandlingPolicy() { return NewSessionHandlingPolicy::kShiftToNewSession; }

/**
* @brief
Expand Down
13 changes: 5 additions & 8 deletions src/transport/SessionHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace chip {
* released when the underlying session is released. One must verify it is available before use. The object can be
* created using SessionHandle.Grab()
*/
class SessionHolder : public SessionReleaseDelegate, public IntrusiveListNodeBase
class SessionHolder : public SessionDelegate, public IntrusiveListNodeBase
{
public:
SessionHolder() {}
Expand All @@ -39,7 +39,7 @@ class SessionHolder : public SessionReleaseDelegate, public IntrusiveListNodeBas
SessionHolder & operator=(const SessionHolder &);
SessionHolder & operator=(SessionHolder && that);

// Implement SessionReleaseDelegate
// Implement SessionDelegate
void OnSessionReleased() override { Release(); }

bool Contains(const SessionHandle & session) const
Expand Down Expand Up @@ -67,11 +67,8 @@ class SessionHolder : public SessionReleaseDelegate, public IntrusiveListNodeBas
class SessionHolderWithDelegate : public SessionHolder
{
public:
SessionHolderWithDelegate(SessionReleaseDelegate & delegate) : mDelegate(delegate) {}
SessionHolderWithDelegate(const SessionHandle & handle, SessionReleaseDelegate & delegate) : mDelegate(delegate)
{
Grab(handle);
}
SessionHolderWithDelegate(SessionDelegate & delegate) : mDelegate(delegate) {}
SessionHolderWithDelegate(const SessionHandle & handle, SessionDelegate & delegate) : mDelegate(delegate) { Grab(handle); }
operator bool() const { return SessionHolder::operator bool(); }

void OnSessionReleased() override
Expand All @@ -83,7 +80,7 @@ class SessionHolderWithDelegate : public SessionHolder
}

private:
SessionReleaseDelegate & mDelegate;
SessionDelegate & mDelegate;
};

} // namespace chip
2 changes: 1 addition & 1 deletion src/transport/tests/TestSessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const char PAYLOAD[] = "Hello!";

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

class TestSessionReleaseCallback : public SessionReleaseDelegate
class TestSessionReleaseCallback : public SessionDelegate
{
public:
void OnSessionReleased() override { mOldConnectionDropped = true; }
Expand Down

0 comments on commit 470cc4b

Please sign in to comment.