From d05654eb0512acd95591d0e770886b4892acec64 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Mon, 15 Nov 2021 17:07:52 -0800 Subject: [PATCH] cleanup --- src/app/CASESessionManager.cpp | 25 +++++++++++-------- src/app/OperationalDeviceProxy.h | 33 ++++++++++++++----------- src/controller/CHIPDeviceController.cpp | 18 +++----------- src/controller/CHIPDeviceController.h | 3 --- 4 files changed, 37 insertions(+), 42 deletions(-) diff --git a/src/app/CASESessionManager.cpp b/src/app/CASESessionManager.cpp index aa7be9ef58476d..7f964f2b7d96c3 100644 --- a/src/app/CASESessionManager.cpp +++ b/src/app/CASESessionManager.cpp @@ -24,19 +24,20 @@ CHIP_ERROR CASESessionManager::FindOrEstablishSession(NodeId nodeId, Callback::C Callback::Callback * 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); if (err != CHIP_NO_ERROR) diff --git a/src/app/OperationalDeviceProxy.h b/src/app/OperationalDeviceProxy.h index 77c21180012d08..c7c0e456312806 100644 --- a/src/app/OperationalDeviceProxy.h +++ b/src/app/OperationalDeviceProxy.h @@ -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) + { + 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. */ diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index f8fc27c413cbdd..c7b2f76c39a577 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -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: diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index b4c90f7fb0cebf..8cf10ea0f8dbb8 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -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 mCommissioneeDevicePool;