Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CASESessionManager class #11703

Merged
merged 7 commits into from
Nov 16, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup
pan-apple committed Nov 16, 2021
commit d05654eb0512acd95591d0e770886b4892acec64
25 changes: 15 additions & 10 deletions src/app/CASESessionManager.cpp
Original file line number Diff line number Diff line change
@@ -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)
@@ -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);
pan-apple marked this conversation as resolved.
Show resolved Hide resolved
if (err != CHIP_NO_ERROR)
33 changes: 19 additions & 14 deletions src/app/OperationalDeviceProxy.h
Original file line number Diff line number Diff line change
@@ -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();
@@ -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)
pan-apple marked this conversation as resolved.
Show resolved Hide resolved
{
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.
*/
18 changes: 3 additions & 15 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
@@ -808,9 +808,6 @@ CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, RendezvousParam
// TODO maybe remove FreeRendezvousSession() since mNextKeyID is always persisted immediately
PersistNextKeyId();

mDeviceCommissioningInProgress = true;
mNodeIdBeingCommissioned = remoteDeviceId;

exit:
if (err != CHIP_NO_ERROR)
{
@@ -840,7 +837,6 @@ CHIP_ERROR DeviceCommissioner::StopPairing(NodeId remoteDeviceId)
FreeRendezvousSession();

ReleaseCommissioneeDevice(device);
mDeviceCommissioningInProgress = false;
return CHIP_NO_ERROR;
}

@@ -890,7 +886,6 @@ void DeviceCommissioner::OnSessionEstablishmentError(CHIP_ERROR err)
ReleaseCommissioneeDevice(mDeviceBeingCommissioned);
mDeviceBeingCommissioned = nullptr;
}
mDeviceCommissioningInProgress = false;
}

void DeviceCommissioner::OnSessionEstablished()
@@ -1538,12 +1533,8 @@ void DeviceCommissioner::OnNodeIdResolved(const chip::Dnssd::ResolvedNodeData &

mDNSCache.Insert(nodeData);

if (mDeviceCommissioningInProgress && mNodeIdBeingCommissioned == nodeData.mPeerId.GetNodeId())
{
mCASESessionManager->FindOrEstablishSession(nodeData.mPeerId.GetNodeId(), &mOnDeviceConnectedCallback,
&mOnDeviceConnectionFailureCallback);
}

mCASESessionManager->FindOrEstablishSession(nodeData.mPeerId.GetNodeId(), &mOnDeviceConnectedCallback,
&mOnDeviceConnectionFailureCallback);
DeviceController::OnNodeIdResolved(nodeData);
}

@@ -1585,7 +1576,6 @@ void DeviceCommissioner::OnDeviceConnectedFn(void * context, DeviceProxy * devic

VerifyOrReturn(commissioner->mPairingDelegate != nullptr,
ChipLogProgress(Controller, "Device connected callback with null pairing delegate. Ignoring"));
commissioner->mDeviceCommissioningInProgress = false;
commissioner->mPairingDelegate->OnCommissioningComplete(device->GetDeviceId(), CHIP_NO_ERROR);
}

@@ -1597,7 +1587,6 @@ void DeviceCommissioner::OnDeviceConnectionFailureFn(void * context, NodeId devi
ChipLogProgress(Controller, "Device connection failure callback with null context. Ignoring"));
VerifyOrReturn(commissioner->mPairingDelegate != nullptr,
ChipLogProgress(Controller, "Device connection failure callback with null pairing delegate. Ignoring"));
commissioner->mDeviceCommissioningInProgress = false;
commissioner->mPairingDelegate->OnCommissioningComplete(deviceId, error);
}

@@ -1795,8 +1784,7 @@ void DeviceCommissioner::AdvanceCommissioningStage(CHIP_ERROR err)
{
mPairingDelegate->OnCommissioningComplete(mDeviceOperational->GetDeviceId(), CHIP_NO_ERROR);
}
mDeviceOperational = nullptr;
mDeviceCommissioningInProgress = false;
mDeviceOperational = nullptr;
break;
case CommissioningStage::kSecurePairing:
case CommissioningStage::kError:
3 changes: 0 additions & 3 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
@@ -607,9 +607,6 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
persist the device list */
bool mPairedDevicesUpdated;

bool mDeviceCommissioningInProgress = false;
NodeId mNodeIdBeingCommissioned;

CommissioningStage mCommissioningStage = CommissioningStage::kSecurePairing;

BitMapObjectPool<CommissioneeDeviceProxy, kNumMaxActiveDevices> mCommissioneeDevicePool;