Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-apple committed Nov 16, 2021
1 parent f1cc790 commit e16dd45
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
25 changes: 15 additions & 10 deletions src/app/CASESessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ CHIP_ERROR CASESessionManager::FindOrEstablishSession(NodeId nodeId, Callback::C
Callback::Callback<OnDeviceConnectionFailure> * onFailure)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
OperationalDeviceProxy * session = FindExistingSession(nodeId);
if (session == nullptr)
{
Dnssd::ResolvedNodeData * nodeResolutionData = nullptr;
Dnssd::ResolvedNodeData cachedResolutionData;

PeerId peerId = GetFabricInfo()->GetPeerIdForNode(nodeId);
Dnssd::ResolvedNodeData * nodeResolutionData = nullptr;
Dnssd::ResolvedNodeData cachedResolutionData;

if (mConfig.dnsCache != nullptr && mConfig.dnsCache->Lookup(peerId, cachedResolutionData) == CHIP_NO_ERROR)
{
nodeResolutionData = &cachedResolutionData;
}
PeerId peerId = GetFabricInfo()->GetPeerIdForNode(nodeId);

if (mConfig.dnsCache != nullptr && mConfig.dnsCache->Lookup(peerId, cachedResolutionData) == CHIP_NO_ERROR)
{
nodeResolutionData = &cachedResolutionData;
}

OperationalDeviceProxy * session = FindExistingSession(nodeId);
if (session == nullptr)
{
// TODO - Implement LRU to evict least recently used session to handle mActiveSessions pool exhaustion
session = mActiveSessions.CreateObject(mConfig.sessionInitParams, peerId, nodeResolutionData);
if (session == nullptr)
Expand All @@ -45,6 +46,10 @@ CHIP_ERROR CASESessionManager::FindOrEstablishSession(NodeId nodeId, Callback::C
return CHIP_ERROR_NO_MEMORY;
}
}
else if (nodeResolutionData != nullptr)
{
session->OnNodeIdResolved(nodeResolutionData);
}

CHIP_ERROR err = session->Connect(onConnection, onFailure);
if (err != CHIP_NO_ERROR)
Expand Down
33 changes: 19 additions & 14 deletions src/app/OperationalDeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,8 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy, public SessionEsta
mInitParams = params;
mPeerId = peerId;

if (nodeResolutionData != nullptr)
{
mDeviceAddress = ToPeerAddress(*nodeResolutionData);

mMrpIdleInterval = nodeResolutionData->GetMrpRetryIntervalIdle().ValueOr(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL);
mMrpActiveInterval =
nodeResolutionData->GetMrpRetryIntervalActive().ValueOr(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL);

mState = State::Initialized;
}
else
{
mState = State::NeedsAddress;
}
mState = State::NeedsAddress;
OnNodeIdResolved(nodeResolutionData);
}

void Clear();
Expand Down Expand Up @@ -122,6 +110,23 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy, public SessionEsta
*/
void OnConnectionExpired(SessionHandle session) override;

void OnNodeIdResolved(const Dnssd::ResolvedNodeData * nodeResolutionData)
{
if (nodeResolutionData != nullptr)
{
mDeviceAddress = ToPeerAddress(*nodeResolutionData);

mMrpIdleInterval = nodeResolutionData->GetMrpRetryIntervalIdle().ValueOr(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL);
mMrpActiveInterval =
nodeResolutionData->GetMrpRetryIntervalActive().ValueOr(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL);

if (mState == State::NeedsAddress)
{
mState = State::Initialized;
}
}
}

/**
* Mark any open session with the device as expired.
*/
Expand Down

0 comments on commit e16dd45

Please sign in to comment.