MCPcopy Create free account
hub / github.com/ReversecLabs/C3 / PostCommandToPeripheral

Method PostCommandToPeripheral

Src/Core/GateRelay.cpp:87–112  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

85
86////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87void FSecure::C3::Core::GateRelay::PostCommandToPeripheral(ByteView command, RouteId routeId)
88{
89 // Check if Peripheral is attached to Gateway.
90 if (routeId.GetAgentId() == GetAgentId())
91 {
92 if (auto peripheral = m_Devices.Find([&](auto const& e) {auto sp = e.lock(); return sp && sp->GetDid() == routeId.GetInterfaceId(); }).lock(); peripheral)
93 return peripheral->OnCommandFromConnector(command);
94 else
95 throw std::runtime_error{ "Couldn't find Gateway's recipient Peripheral." };
96 }
97
98 auto route = FindRoute(routeId.GetAgentId());
99 if (!route)
100 throw std::runtime_error{ "Unknown route." };
101
102 auto device = route->m_Channel.lock();
103 if (!device)
104 throw std::runtime_error{ "Route was unexpectedly closed." };
105
106 auto agent = m_Profiler->Get().m_Gateway.m_Agents.Find(routeId.GetAgentId());
107 if (!agent)
108 throw std::runtime_error{ "Unknown agent." };
109
110 auto query = ProceduresG2X::DeliverToBinder::Create(route->m_RouteId, m_Signature, agent->m_EncryptionKey, m_DecryptionKey, routeId.GetInterfaceId(), command);
111 LockAndSendPacket(query->ComposeQueryPacket(), device);
112}
113
114////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
115void FSecure::C3::Core::GateRelay::RunApiBrige(std::string_view apiBrigdeIp, std::uint16_t apiBrigdePort) noexcept

Callers 1

PostCommandToBinderMethod · 0.80

Calls 8

GetDidMethod · 0.80
GetInterfaceIdMethod · 0.80
GetAgentIdMethod · 0.45
lockMethod · 0.45
FindMethod · 0.45
GetMethod · 0.45
ComposeQueryPacketMethod · 0.45

Tested by

no test coverage detected