mirror of https://github.com/infosecn1nja/C3.git
Fix Query - related compilation warnings and errors
parent
34c73a078a
commit
a5e517f9f2
|
@ -76,7 +76,7 @@ namespace MWR::C3
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get proper map member for type T.
|
/// Get proper map member for type T.
|
||||||
template <typename T> auto& GetMap() { static_assert(false, "Template type not supported."); }
|
template <typename T> auto& GetMap() = delete;
|
||||||
template <> auto& GetMap<AbstractChannel>() { return m_Channels; }
|
template <> auto& GetMap<AbstractChannel>() { return m_Channels; }
|
||||||
template <> auto& GetMap<AbstractPeripheral>() { return m_Peripherals; }
|
template <> auto& GetMap<AbstractPeripheral>() { return m_Peripherals; }
|
||||||
template <> auto& GetMap<AbstractConnector>() { return m_Connectors; }
|
template <> auto& GetMap<AbstractConnector>() { return m_Connectors; }
|
||||||
|
|
|
@ -8,7 +8,6 @@ namespace MWR::C3::Core
|
||||||
// Typedefs and constants.
|
// Typedefs and constants.
|
||||||
using ProceduresUnderlyingType = std::int8_t; ///< Underlying type for Procedure number field.
|
using ProceduresUnderlyingType = std::int8_t; ///< Underlying type for Procedure number field.
|
||||||
using SequenceNumberFieldUnderlyingType = std::uint32_t; /// Underlying type for Query/Response sequence numbers (including type bits = 2 bits).
|
using SequenceNumberFieldUnderlyingType = std::uint32_t; /// Underlying type for Query/Response sequence numbers (including type bits = 2 bits).
|
||||||
static constexpr unsigned s_SequenceNumberBitLength = sizeof SequenceNumberFieldUnderlyingType * 8 - 2; ///< Number of bits sequence number occupy in the SequenceNumberType type.
|
|
||||||
|
|
||||||
/// Abstract class for all Queries.
|
/// Abstract class for all Queries.
|
||||||
struct BaseQuery
|
struct BaseQuery
|
||||||
|
@ -83,7 +82,7 @@ namespace MWR::C3::Core
|
||||||
using SequenceNumberFieldUnderlyingType = std::uint32_t;
|
using SequenceNumberFieldUnderlyingType = std::uint32_t;
|
||||||
|
|
||||||
/// Number of bits sequence number occupy in the SequenceNumberType type.
|
/// Number of bits sequence number occupy in the SequenceNumberType type.
|
||||||
static constexpr unsigned s_SequenceNumberBitLength = sizeof SequenceNumberFieldUnderlyingType * 8 - 2;
|
static constexpr unsigned s_SequenceNumberBitLength = sizeof(SequenceNumberFieldUnderlyingType) * 8 - 2;
|
||||||
|
|
||||||
/// Sequence number
|
/// Sequence number
|
||||||
const SequenceNumberFieldUnderlyingType m_SequenceNumber;
|
const SequenceNumberFieldUnderlyingType m_SequenceNumber;
|
||||||
|
|
|
@ -34,6 +34,10 @@ namespace MWR::C3::Core
|
||||||
virtual void OnPacketReceived(ByteView packet, std::shared_ptr<DeviceBridge> sender);
|
virtual void OnPacketReceived(ByteView packet, std::shared_ptr<DeviceBridge> sender);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// Expose all base classes `On` methods.
|
||||||
|
using ProceduresN2N::RequestHandler::On;
|
||||||
|
using ProceduresS2G::RequestHandler::On;
|
||||||
|
|
||||||
/// A protected ctor.
|
/// A protected ctor.
|
||||||
/// @param callbackOnLog callback fired whenever a new Log entry is being added.
|
/// @param callbackOnLog callback fired whenever a new Log entry is being added.
|
||||||
/// @param decryptionKey Relay's private asymmetric key.
|
/// @param decryptionKey Relay's private asymmetric key.
|
||||||
|
|
|
@ -284,7 +284,7 @@ void MWR::C3::Core::GateRelay::DetachDevice(DeviceId const& iidOfDeviceToDetach)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void MWR::C3::Core::GateRelay::On(ProceduresN2N::InitializeRouteQuery&& query)
|
void MWR::C3::Core::GateRelay::On(ProceduresN2N::InitializeRouteQuery query)
|
||||||
{
|
{
|
||||||
auto decryptedPacket = query.GetQueryPacket(this->m_AuthenticationKey, this->m_DecryptionKey);
|
auto decryptedPacket = query.GetQueryPacket(this->m_AuthenticationKey, this->m_DecryptionKey);
|
||||||
auto readView = ByteView{ decryptedPacket };
|
auto readView = ByteView{ decryptedPacket };
|
||||||
|
@ -308,7 +308,7 @@ void MWR::C3::Core::GateRelay::On(ProceduresN2N::InitializeRouteQuery&& query)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void MWR::C3::Core::GateRelay::On(ProceduresS2G::InitializeRouteQuery&& query)
|
void MWR::C3::Core::GateRelay::On(ProceduresS2G::InitializeRouteQuery query)
|
||||||
{
|
{
|
||||||
// whole message.
|
// whole message.
|
||||||
auto decryptedPacket = query.GetQueryPacket(m_AuthenticationKey, m_DecryptionKey);
|
auto decryptedPacket = query.GetQueryPacket(m_AuthenticationKey, m_DecryptionKey);
|
||||||
|
|
|
@ -104,13 +104,17 @@ namespace MWR::C3::Core
|
||||||
/// @param senderPeripheral Interface that is sending the Command.
|
/// @param senderPeripheral Interface that is sending the Command.
|
||||||
void PostCommandToConnector(ByteView command, std::shared_ptr<DeviceBridge> senderPeripheral) override;
|
void PostCommandToConnector(ByteView command, std::shared_ptr<DeviceBridge> senderPeripheral) override;
|
||||||
|
|
||||||
|
/// Expose all base classes `On` methods.
|
||||||
|
using ProceduresG2X::RequestHandler::On;
|
||||||
|
using Relay::On;
|
||||||
|
|
||||||
/// Handler fired when a N2N::InitializeRoute Procedure Query arrives.
|
/// Handler fired when a N2N::InitializeRoute Procedure Query arrives.
|
||||||
/// @param query object representing the Query.
|
/// @param query object representing the Query.
|
||||||
void On(ProceduresN2N::InitializeRouteQuery&& query) override;
|
void On(ProceduresN2N::InitializeRouteQuery query) override;
|
||||||
|
|
||||||
/// Handler fired when a S2G::InitializeRoute Procedure Query arrives.
|
/// Handler fired when a S2G::InitializeRoute Procedure Query arrives.
|
||||||
/// @param query object representing the Query.
|
/// @param query object representing the Query.
|
||||||
void On(ProceduresS2G::InitializeRouteQuery&& query) override;
|
void On(ProceduresS2G::InitializeRouteQuery query) override;
|
||||||
|
|
||||||
/// Handler fired when a N2N::ChannelIdExchangeStep1 Procedure Query arrives.
|
/// Handler fired when a N2N::ChannelIdExchangeStep1 Procedure Query arrives.
|
||||||
/// Gateway opens a new channel and sends parameters to relay.
|
/// Gateway opens a new channel and sends parameters to relay.
|
||||||
|
|
|
@ -188,7 +188,7 @@ void MWR::C3::Core::NodeRelay::NegotiateChannel(std::shared_ptr<DeviceBridge> co
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void MWR::C3::Core::NodeRelay::On(ProceduresN2N::InitializeRouteQuery&& query)
|
void MWR::C3::Core::NodeRelay::On(ProceduresN2N::InitializeRouteQuery query)
|
||||||
{
|
{
|
||||||
// Retrieve GRC.
|
// Retrieve GRC.
|
||||||
auto grc = GetGatewayReturnChannel();
|
auto grc = GetGatewayReturnChannel();
|
||||||
|
@ -201,7 +201,7 @@ void MWR::C3::Core::NodeRelay::On(ProceduresN2N::InitializeRouteQuery&& query)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void MWR::C3::Core::NodeRelay::On(ProceduresS2G::InitializeRouteQuery&& query)
|
void MWR::C3::Core::NodeRelay::On(ProceduresS2G::InitializeRouteQuery query)
|
||||||
{
|
{
|
||||||
throw std::logic_error{ OBF("Wrong recipient.") };
|
throw std::logic_error{ OBF("Wrong recipient.") };
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,13 +57,17 @@ namespace MWR::C3::Core
|
||||||
/// @param channel Interface that will be used to send the packet.
|
/// @param channel Interface that will be used to send the packet.
|
||||||
void PostCommandToConnector(ByteView command, std::shared_ptr<DeviceBridge> channel) override;
|
void PostCommandToConnector(ByteView command, std::shared_ptr<DeviceBridge> channel) override;
|
||||||
|
|
||||||
|
/// Expose all base classes `On` methods.
|
||||||
|
using Relay::On;
|
||||||
|
using ProceduresG2X::RequestHandler::On;
|
||||||
|
|
||||||
/// Handler fired when a N2N::InitializeRoute Procedure Query arrives.
|
/// Handler fired when a N2N::InitializeRoute Procedure Query arrives.
|
||||||
/// @param query object representing the Query.
|
/// @param query object representing the Query.
|
||||||
void On(ProceduresN2N::InitializeRouteQuery&& query) override;
|
void On(ProceduresN2N::InitializeRouteQuery query) override;
|
||||||
|
|
||||||
/// Handler fired when a N2N::InitializeRoute Procedure arrives.
|
/// Handler fired when a N2N::InitializeRoute Procedure arrives.
|
||||||
/// @param query object representing the Query.
|
/// @param query object representing the Query.
|
||||||
void On(ProceduresS2G::InitializeRouteQuery&& query) override;
|
void On(ProceduresS2G::InitializeRouteQuery query) override;
|
||||||
|
|
||||||
/// Handler fired when a G2X::AddRoute Procedure Query arrives.
|
/// Handler fired when a G2X::AddRoute Procedure Query arrives.
|
||||||
/// @param query object representing the Query.
|
/// @param query object representing the Query.
|
||||||
|
|
|
@ -184,7 +184,7 @@ namespace MWR::C3::Core
|
||||||
struct RequestHandler
|
struct RequestHandler
|
||||||
{
|
{
|
||||||
/// Declaration of support for InitializeRouteQuery Request.
|
/// Declaration of support for InitializeRouteQuery Request.
|
||||||
virtual void On(InitializeRouteQuery&&) = 0;
|
virtual void On(InitializeRouteQuery) = 0;
|
||||||
|
|
||||||
/// Declaration of support for ChannelIdExchangeStep1 Request.
|
/// Declaration of support for ChannelIdExchangeStep1 Request.
|
||||||
virtual void On(ChannelIdExchangeStep1) = 0;
|
virtual void On(ChannelIdExchangeStep1) = 0;
|
||||||
|
@ -461,7 +461,7 @@ namespace MWR::C3::Core
|
||||||
struct RequestHandler
|
struct RequestHandler
|
||||||
{
|
{
|
||||||
/// Declaration of support for InitializeRouteQuery Request.
|
/// Declaration of support for InitializeRouteQuery Request.
|
||||||
virtual void On(InitializeRouteQuery&&) = 0;
|
virtual void On(InitializeRouteQuery) = 0;
|
||||||
|
|
||||||
/// Default empty handler for AddDeviceResponse Request.
|
/// Default empty handler for AddDeviceResponse Request.
|
||||||
virtual void On(AddDeviceResponse) {};
|
virtual void On(AddDeviceResponse) {};
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace MWR::C3::Core::ProceduresG2X
|
||||||
: BaseQuery{ responseType }
|
: BaseQuery{ responseType }
|
||||||
, m_Propagation{ propagation }
|
, m_Propagation{ propagation }
|
||||||
, m_ReceiverRid{ receiverRid }
|
, m_ReceiverRid{ receiverRid }
|
||||||
, m_GatewayPrivateSignature{ gatewayPrivateSignature }
|
, m_GatewayPrivateSignature{ &gatewayPrivateSignature }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,11 +51,12 @@ namespace MWR::C3::Core::ProceduresG2X
|
||||||
/// @return buffer containing whole packet.
|
/// @return buffer containing whole packet.
|
||||||
ByteVector ComposeQueryPacket() const override
|
ByteVector ComposeQueryPacket() const override
|
||||||
{
|
{
|
||||||
return CompileProtocolHeader().Concat(Crypto::SignMessage(m_ReceiverRid.ToByteVector().Concat(GetQueryHeader()).Concat(m_QueryPacketBody), m_GatewayPrivateSignature));
|
assert(m_GatewayPrivateSignature);
|
||||||
|
return CompileProtocolHeader().Concat(Crypto::SignMessage(m_ReceiverRid.ToByteVector().Concat(GetQueryHeader()).Concat(m_QueryPacketBody), *m_GatewayPrivateSignature));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Crypto::PrivateSignature const& m_GatewayPrivateSignature; ///< Gateway signature used to sign the query.
|
const Crypto::PrivateSignature* const m_GatewayPrivateSignature; ///< Gateway signature used to sign the query.
|
||||||
ByteVector m_QueryPacketBody; ///< Whole Query packet along with all the headers.
|
ByteVector m_QueryPacketBody; ///< Whole Query packet along with all the headers.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -122,7 +123,7 @@ namespace MWR::C3::Core::ProceduresG2X
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Forwarded constructors.
|
/// Forwarded constructors.
|
||||||
using Query::Query;
|
using Query<ProcedureNumber>::Query;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Helper to template creating Queries to Route
|
/// Helper to template creating Queries to Route
|
||||||
|
@ -132,7 +133,7 @@ namespace MWR::C3::Core::ProceduresG2X
|
||||||
{
|
{
|
||||||
|
|
||||||
/// Forwarded constructors.
|
/// Forwarded constructors.
|
||||||
using Query::Query;
|
using Query<ProcedureNumber>::Query;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -21,6 +21,8 @@ namespace MWR::C3::Core
|
||||||
virtual void DetachDevice(DeviceId const& iidOfDeviceToDetach);
|
virtual void DetachDevice(DeviceId const& iidOfDeviceToDetach);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
using Distributor::On;
|
||||||
|
|
||||||
/// A protected constructor. @see Distributor::Distributor.
|
/// A protected constructor. @see Distributor::Distributor.
|
||||||
/// @param callbackOnLog callback fired whenever a new Log entry is being added.
|
/// @param callbackOnLog callback fired whenever a new Log entry is being added.
|
||||||
/// @param interfaceFactory reference to Interface factory.
|
/// @param interfaceFactory reference to Interface factory.
|
||||||
|
|
Loading…
Reference in New Issue