Skip to content

Commit

Permalink
Exchange handles SecureSession closing (#3897)
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost authored and pull[bot] committed Dec 8, 2020
1 parent e3346e9 commit 2911121
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/messaging/ExchangeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ void ExchangeManager::OnMessageReceived(const PacketHeader & packetHeader, const
DispatchMessage(packetHeader, payloadHeader, msgBuf);
}

void ExchangeManager::OnConnectionExpired(const Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr)
{
for (auto & ec : ContextPool)
{
if (ec.GetReferenceCount() > 0 && ec.mPeerNodeId == state->GetPeerNodeId())
{
ec.Close();
// Continue iterate because there can be multiple contexts associated with the connection.
}
}
}

void ExchangeManager::IncrementContextsInUse()
{
mContextsInUse++;
Expand Down
2 changes: 2 additions & 0 deletions src/messaging/ExchangeMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ class DLL_EXPORT ExchangeManager : public SecureSessionMgrDelegate
void OnMessageReceived(const PacketHeader & packetHeader, const PayloadHeader & payloadHeader,
Transport::PeerConnectionState * state, System::PacketBuffer * msgBuf,
SecureSessionMgrBase * msgLayer) override;

void OnConnectionExpired(const Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr) override;
};

} // namespace chip
5 changes: 5 additions & 0 deletions src/transport/SecureSessionMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ void SecureSessionMgrBase::HandleConnectionExpired(const Transport::PeerConnecti

ChipLogDetail(Inet, "Connection from '%s' expired", addr);

if (mgr->mCB != nullptr)
{
mgr->mCB->OnConnectionExpired(&state, mgr);
}

mgr->mTransport->Disconnect(state.GetPeerAddress());
}

Expand Down
9 changes: 9 additions & 0 deletions src/transport/SecureSessionMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ class DLL_EXPORT SecureSessionMgrDelegate
*/
virtual void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr) {}

/**
* @brief
* Called when a new connection is closing
*
* @param state connection state
* @param mgr A pointer to the SecureSessionMgr
*/
virtual void OnConnectionExpired(const Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr) {}

/**
* @brief
* Called when the peer address is resolved from NodeID.
Expand Down

0 comments on commit 2911121

Please sign in to comment.