Skip to content

Commit

Permalink
Replace PeerId -> ScopedNodeId where applicable. (project-chip#20896
Browse files Browse the repository at this point in the history
)

* Replace PeerId -> ScopedNodeId where applicable.

Lots of places were still using PeerId when they shouldn't be.

* Review feedback and build fixes

* Darwin build fix
  • Loading branch information
mrjerryjohns authored and isiu-apple committed Sep 16, 2022
1 parent e2620b6 commit dec947f
Show file tree
Hide file tree
Showing 36 changed files with 148 additions and 212 deletions.
7 changes: 4 additions & 3 deletions examples/all-clusters-app/esp32/main/include/ShellCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class CASECommands
GetInstance().SetOnConnecting(false);
}

static void OnConnectionFailure(void * context, PeerId peerId, CHIP_ERROR error)
static void OnConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
{
streamer_printf(streamer_get(), "Establish CASESession Failure!\r\n");
GetInstance().SetOnConnecting(false);
Expand All @@ -156,8 +156,9 @@ class CASECommands
ChipLogError(SecureChannel, "Can't get the CASESessionManager");
return;
}
caseSessionManager->FindOrEstablishSession(caseCommand->GetFabricInfo()->GetPeerIdForNode(caseCommand->GetNodeId()),
&sOnConnectedCallback, &sOnConnectionFailureCallback);
caseSessionManager->FindOrEstablishSession(
ScopedNodeId(caseCommand->GetNodeId(), caseCommand->GetFabricInfo()->GetFabricIndex()), &sOnConnectedCallback,
&sOnConnectionFailureCallback);
}

static CHIP_ERROR ConnectToNodeHandler(int argc, char ** argv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class CASECommands
GetInstance().SetOnConnecting(false);
}

static void OnConnectionFailure(void * context, PeerId peerId, CHIP_ERROR error)
static void OnConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
{
streamer_printf(streamer_get(), "Establish CASESession Failure!\r\n");
GetInstance().SetOnConnecting(false);
Expand All @@ -156,8 +156,9 @@ class CASECommands
ChipLogError(SecureChannel, "Can't get the CASESessionManager");
return;
}
caseSessionManager->FindOrEstablishSession(caseCommand->GetFabricInfo()->GetPeerIdForNode(caseCommand->GetNodeId()),
&sOnConnectedCallback, &sOnConnectionFailureCallback);
caseSessionManager->FindOrEstablishSession(
ScopedNodeId(caseCommand->GetNodeId(), caseCommand->GetFabricInfo()->GetFabricIndex()), &sOnConnectedCallback,
&sOnConnectionFailureCallback);
}

static CHIP_ERROR ConnectToNodeHandler(int argc, char ** argv)
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/clusters/ModelCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void ModelCommand::OnDeviceConnectedFn(void * context, chip::OperationalDevicePr
VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err));
}

void ModelCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR err)
void ModelCommand::OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR err)
{
LogErrorOnFailure(err);

Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/clusters/ModelCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ModelCommand : public CHIPCommand
std::vector<chip::EndpointId> mEndPointId;

static void OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device);
static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);
static void OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error);

chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void CloseSessionCommand::OnDeviceConnectedFn(void * context, OperationalDeviceP
VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err));
}

void CloseSessionCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR err)
void CloseSessionCommand::OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR err)
{
LogErrorOnFailure(err);

Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/pairing/CloseSessionCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CloseSessionCommand : public CHIPCommand
chip::Optional<uint16_t> mTimeoutSecs;

static void OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device);
static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);
static void OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error);

// Try to send the action CloseSession status report.
CHIP_ERROR CloseSession(chip::DeviceProxy * device);
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/tests/TestCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void TestCommand::OnDeviceConnectedFn(void * context, chip::OperationalDevicePro
LogErrorOnFailure(command->ContinueOnChipMainThread(CHIP_NO_ERROR));
}

void TestCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error)
void TestCommand::OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error)
{
ChipLogProgress(chipTool, " **** Test Setup: Device Connection Failure [deviceId=%" PRIu64 ". Error %" CHIP_ERROR_FORMAT "\n]",
peerId.GetNodeId(), error.Format());
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TestCommand : public TestRunner,
void OnResponse(const chip::app::StatusIB & status, chip::TLV::TLVReader * data) override{};

static void OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device);
static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);
static void OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error);

CHIP_ERROR ContinueOnChipMainThread(CHIP_ERROR err) override;

Expand Down
4 changes: 2 additions & 2 deletions examples/platform/linux/CommissionerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class PairingCommand : public Controller::DevicePairingDelegate
private:
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
static void OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device);
static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);
static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);

chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
Expand Down Expand Up @@ -333,7 +333,7 @@ void PairingCommand::OnDeviceConnectedFn(void * context, chip::OperationalDevice
}
}

void PairingCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR err)
void PairingCommand::OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR err)
{
ChipLogProgress(Controller, "OnDeviceConnectionFailureFn - attempt to get OperationalDeviceProxy failed");
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,8 @@ CHIP_ERROR ModelCommand::RunCommand()
return SendGroupCommand(GroupIdFromNodeId(mDestinationId), fabricIndex);
}

Server * server = &(chip::Server::GetInstance());
const FabricInfo * fabric = server->GetFabricTable().FindFabricWithIndex(fabricIndex);
if (fabric == nullptr)
{
ChipLogError(AppServer, "Did not find fabric for index %d", fabricIndex);
return CHIP_ERROR_INVALID_FABRIC_INDEX;
}

PeerId peerID = fabric->GetPeerIdForNode(mDestinationId);
server->GetCASESessionManager()->FindOrEstablishSession(peerID, &mOnDeviceConnectedCallback,
Server * server = &(chip::Server::GetInstance());
server->GetCASESessionManager()->FindOrEstablishSession(ScopedNodeId(mDestinationId, fabricIndex), &mOnDeviceConnectedCallback,
&mOnDeviceConnectionFailureCallback);
return CHIP_NO_ERROR;
}
Expand All @@ -71,7 +63,7 @@ void ModelCommand::OnDeviceConnectedFn(void * context, OperationalDeviceProxy *
VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err));
}

void ModelCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR err)
void ModelCommand::OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR err)
{
ChipLogProgress(chipTool, "ModelCommand::OnDeviceConnectionFailureFn");
LogErrorOnFailure(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TargetVideoPlayerInfo
ChipLogProgress(AppServer, "HandleDeviceConnected created an instance of OperationalDeviceProxy");
}

static void HandleDeviceConnectionFailure(void * context, chip::PeerId peerId, CHIP_ERROR error)
static void HandleDeviceConnectionFailure(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error)
{
TargetVideoPlayerInfo * _this = static_cast<TargetVideoPlayerInfo *>(context);
_this->mOperationalDeviceProxy = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,9 @@ CHIP_ERROR TargetVideoPlayerInfo::Initialize(NodeId nodeId, FabricIndex fabricIn
endpointInfo.Reset();
}

Server * server = &(chip::Server::GetInstance());
const FabricInfo * fabric = server->GetFabricTable().FindFabricWithIndex(fabricIndex);
if (fabric == nullptr)
{
ChipLogError(AppServer, "Did not find fabric for index %d", fabricIndex);
return CHIP_ERROR_INVALID_FABRIC_INDEX;
}

PeerId peerID = fabric->GetPeerIdForNode(nodeId);

server->GetCASESessionManager()->FindOrEstablishSession(peerID, &mOnConnectedCallback, &mOnConnectionFailureCallback);
Server * server = &(chip::Server::GetInstance());
server->GetCASESessionManager()->FindOrEstablishSession(ScopedNodeId(nodeId, fabricIndex), &mOnConnectedCallback,
&mOnConnectionFailureCallback);

if (mOperationalDeviceProxy == nullptr)
{
Expand Down
8 changes: 4 additions & 4 deletions src/app/CASEClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void CASEClient::SetRemoteMRPIntervals(const ReliableMessageProtocolConfig & rem
mCASESession.SetRemoteMRPConfig(remoteMRPConfig);
}

CHIP_ERROR CASEClient::EstablishSession(PeerId peer, const Transport::PeerAddress & peerAddress,
CHIP_ERROR CASEClient::EstablishSession(const ScopedNodeId & peer, const Transport::PeerAddress & peerAddress,
const ReliableMessageProtocolConfig & remoteMRPConfig,
SessionEstablishmentDelegate * delegate)
{
Expand All @@ -46,9 +46,9 @@ CHIP_ERROR CASEClient::EstablishSession(PeerId peer, const Transport::PeerAddres
VerifyOrReturnError(exchange != nullptr, CHIP_ERROR_INTERNAL);

mCASESession.SetGroupDataProvider(mInitParams.groupDataProvider);
ReturnErrorOnFailure(mCASESession.EstablishSession(
*mInitParams.sessionManager, mInitParams.fabricTable, ScopedNodeId{ peer.GetNodeId(), mInitParams.fabricIndex }, exchange,
mInitParams.sessionResumptionStorage, mInitParams.certificateValidityPolicy, delegate, mInitParams.mrpLocalConfig));
ReturnErrorOnFailure(mCASESession.EstablishSession(*mInitParams.sessionManager, mInitParams.fabricTable, peer, exchange,
mInitParams.sessionResumptionStorage, mInitParams.certificateValidityPolicy,
delegate, mInitParams.mrpLocalConfig));

return CHIP_NO_ERROR;
}
Expand Down
3 changes: 1 addition & 2 deletions src/app/CASEClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ struct CASEClientInitParams
Credentials::CertificateValidityPolicy * certificateValidityPolicy = nullptr;
Messaging::ExchangeManager * exchangeMgr = nullptr;
FabricTable * fabricTable = nullptr;
FabricIndex fabricIndex = kUndefinedFabricIndex;
Credentials::GroupDataProvider * groupDataProvider = nullptr;

Optional<ReliableMessageProtocolConfig> mrpLocalConfig = Optional<ReliableMessageProtocolConfig>::Missing();
Expand All @@ -46,7 +45,7 @@ class DLL_EXPORT CASEClient

void SetRemoteMRPIntervals(const ReliableMessageProtocolConfig & remoteMRPConfig);

CHIP_ERROR EstablishSession(PeerId peer, const Transport::PeerAddress & peerAddress,
CHIP_ERROR EstablishSession(const ScopedNodeId & peer, const Transport::PeerAddress & peerAddress,
const ReliableMessageProtocolConfig & remoteMRPConfig, SessionEstablishmentDelegate * delegate);

private:
Expand Down
12 changes: 6 additions & 6 deletions src/app/CASESessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ CHIP_ERROR CASESessionManager::Init(chip::System::Layer * systemLayer, const CAS
return AddressResolve::Resolver::Instance().Init(systemLayer);
}

void CASESessionManager::FindOrEstablishSession(PeerId peerId, Callback::Callback<OnDeviceConnected> * onConnection,
void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Callback::Callback<OnDeviceConnected> * onConnection,
Callback::Callback<OnDeviceConnectionFailure> * onFailure)
{
ChipLogDetail(CASESessionManager, "FindOrEstablishSession: PeerId = " ChipLogFormatX64 ":" ChipLogFormatX64,
ChipLogValueX64(peerId.GetCompressedFabricId()), ChipLogValueX64(peerId.GetNodeId()));
ChipLogDetail(CASESessionManager, "FindOrEstablishSession: PeerId = [%d:" ChipLogFormatX64 "]", peerId.GetFabricIndex(),
ChipLogValueX64(peerId.GetNodeId()));

OperationalDeviceProxy * session = FindExistingSession(peerId);
if (session == nullptr)
Expand Down Expand Up @@ -64,7 +64,7 @@ void CASESessionManager::FindOrEstablishSession(PeerId peerId, Callback::Callbac
}
}

void CASESessionManager::ReleaseSession(PeerId peerId)
void CASESessionManager::ReleaseSession(const ScopedNodeId & peerId)
{
ReleaseSession(FindExistingSession(peerId));
}
Expand All @@ -79,15 +79,15 @@ void CASESessionManager::ReleaseAllSessions()
mConfig.devicePool->ReleaseAllDevices();
}

CHIP_ERROR CASESessionManager::GetPeerAddress(PeerId peerId, Transport::PeerAddress & addr)
CHIP_ERROR CASESessionManager::GetPeerAddress(const ScopedNodeId & peerId, Transport::PeerAddress & addr)
{
OperationalDeviceProxy * session = FindExistingSession(peerId);
VerifyOrReturnError(session != nullptr, CHIP_ERROR_NOT_CONNECTED);
addr = session->GetPeerAddress();
return CHIP_NO_ERROR;
}

OperationalDeviceProxy * CASESessionManager::FindExistingSession(PeerId peerId) const
OperationalDeviceProxy * CASESessionManager::FindExistingSession(const ScopedNodeId & peerId) const
{
return mConfig.devicePool->FindDevice(peerId);
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/CASESessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ class CASESessionManager
* The `onFailure` callback may be called before the FindOrEstablishSession
* call returns, for error cases that are detected synchronously.
*/
void FindOrEstablishSession(PeerId peerId, Callback::Callback<OnDeviceConnected> * onConnection,
void FindOrEstablishSession(const ScopedNodeId & peerId, Callback::Callback<OnDeviceConnected> * onConnection,
Callback::Callback<OnDeviceConnectionFailure> * onFailure);

OperationalDeviceProxy * FindExistingSession(PeerId peerId) const;
OperationalDeviceProxy * FindExistingSession(const ScopedNodeId & peerId) const;

void ReleaseSession(PeerId peerId);
void ReleaseSession(const ScopedNodeId & peerId);

void ReleaseSessionsForFabric(FabricIndex fabricIndex);

Expand All @@ -87,7 +87,7 @@ class CASESessionManager
* an ongoing session with the peer node. If the session doesn't exist, the API will return
* `CHIP_ERROR_NOT_CONNECTED` error.
*/
CHIP_ERROR GetPeerAddress(PeerId peerId, Transport::PeerAddress & addr);
CHIP_ERROR GetPeerAddress(const ScopedNodeId & peerId, Transport::PeerAddress & addr);

private:
void ReleaseSession(OperationalDeviceProxy * device) const;
Expand Down
Loading

0 comments on commit dec947f

Please sign in to comment.