Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost committed Dec 11, 2020
1 parent 465d3b4 commit b4a92f7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/controller/CHIPDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ void Device::OnNewConnection(SecureSessionHandle session, SecureSessionMgr * mgr
void Device::OnConnectionExpired(SecureSessionHandle session, SecureSessionMgr * mgr)
{
mState = ConnectionState::NotConnected;
mSecureSession = SecureSessionHandle{};
}

void Device::OnMessageReceived(const PacketHeader & header, const PayloadHeader & payloadHeader,
Expand Down
10 changes: 5 additions & 5 deletions src/controller/CHIPDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class DLL_EXPORT Device
* @brief
* Called when a new pairing is being established
*
* @param state connection state
* @param session A handle to the secure session
* @param mgr A pointer to the SecureSessionMgr
*/
void OnNewConnection(SecureSessionHandle session, SecureSessionMgr * mgr);
Expand All @@ -171,7 +171,7 @@ class DLL_EXPORT Device
*
* The receiver should release all resources associated with the connection.
*
* @param state connection state
* @param session A handle to the secure session
* @param mgr A pointer to the SecureSessionMgr
*/
void OnConnectionExpired(SecureSessionHandle session, SecureSessionMgr * mgr);
Expand All @@ -184,7 +184,7 @@ class DLL_EXPORT Device
*
* @param[in] header Reference to common packet header of the received message
* @param[in] payloadHeader Reference to payload header in the message
* @param[in] state Pointer to the peer connection state on which message is received
* @param[in] session A handle to the secure session
* @param[in] msgBuf The message buffer
* @param[in] mgr Pointer to secure session manager which received the message
*/
Expand Down Expand Up @@ -213,7 +213,7 @@ class DLL_EXPORT Device

NodeId GetDeviceId() const { return mDeviceId; }

SecureSessionHandle GetSecureSession() const { return mSecureSession; }
bool MatchSession(SecureSessionHandle session) const { return mSecureSession == session; }

void SetAddress(const Inet::IPAddress & deviceAddr) { mDeviceAddr = deviceAddr; }

Expand Down Expand Up @@ -266,7 +266,7 @@ class DLL_EXPORT Device

DeviceTransportMgr * mTransportMgr;

SecureSessionHandle mSecureSession;
SecureSessionHandle mSecureSession = {};

/* Track all outstanding response callbacks for this device. The callbacks are
registered when a command is sent to the device, to get notified with the results. */
Expand Down
3 changes: 1 addition & 2 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,7 @@ uint16_t DeviceController::FindDeviceIndex(SecureSessionHandle session)
uint16_t i = 0;
while (i < kNumMaxActiveDevices)
{
if (mActiveDevices[i].IsActive() && mActiveDevices[i].IsSecureConnected() &&
mActiveDevices[i].GetSecureSession() == session)
if (mActiveDevices[i].IsActive() && mActiveDevices[i].IsSecureConnected() && mActiveDevices[i].MatchSession(session))
{
return i;
}
Expand Down
2 changes: 1 addition & 1 deletion src/transport/SecureSessionMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void SecureSessionMgr::ExpiryTimerCallback(System::Layer * layer, void * param,

PeerConnectionState * SecureSessionMgr::GetPeerConnectionState(SecureSessionHandle session)
{
return mPeerConnections.FindPeerConnectionState(Optional<NodeId>::Value(std::get<0>(session)), std::get<1>(session), nullptr);
return mPeerConnections.FindPeerConnectionState(Optional<NodeId>::Value(session.mPeerNodeId), session.mPeerKeyId, nullptr);
}

} // namespace chip
18 changes: 17 additions & 1 deletion src/transport/SecureSessionMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,23 @@
namespace chip {

class SecureSessionMgr;
using SecureSessionHandle = std::tuple<NodeId, uint16_t>; // tuple<PeerNodeId, PeerKeyId>


class SecureSessionHandle
{
public:
SecureSessionHandle() : mPeerNodeId(kAnyNodeId), mPeerKeyId(0) {}
SecureSessionHandle(NodeId peerNodeId, uint16_t peerKeyId) : mPeerNodeId(peerNodeId), mPeerKeyId(peerKeyId) {}

bool operator==(const SecureSessionHandle & that) const
{
return mPeerNodeId == that.mPeerNodeId && mPeerKeyId == that.mPeerKeyId;
}
private:
friend class SecureSessionMgr;
NodeId mPeerNodeId;
uint16_t mPeerKeyId;
};

/**
* @brief
Expand Down

0 comments on commit b4a92f7

Please sign in to comment.