diff --git a/Src/Common/MWR/C3/Internals/InterfaceFactory.h b/Src/Common/MWR/C3/Internals/InterfaceFactory.h index 00f8781..cf54b93 100644 --- a/Src/Common/MWR/C3/Internals/InterfaceFactory.h +++ b/Src/Common/MWR/C3/Internals/InterfaceFactory.h @@ -76,7 +76,7 @@ namespace MWR::C3 } /// Get proper map member for type T. - template auto& GetMap() { static_assert(false, "Template type not supported."); } + template auto& GetMap() = delete; template <> auto& GetMap() { return m_Channels; } template <> auto& GetMap() { return m_Peripherals; } template <> auto& GetMap() { return m_Connectors; } diff --git a/Src/Core/BaseQuery.h b/Src/Core/BaseQuery.h index 3e1403a..1f1cd6f 100644 --- a/Src/Core/BaseQuery.h +++ b/Src/Core/BaseQuery.h @@ -8,7 +8,6 @@ namespace MWR::C3::Core // Typedefs and constants. 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). - static constexpr unsigned s_SequenceNumberBitLength = sizeof SequenceNumberFieldUnderlyingType * 8 - 2; ///< Number of bits sequence number occupy in the SequenceNumberType type. /// Abstract class for all Queries. struct BaseQuery @@ -83,7 +82,7 @@ namespace MWR::C3::Core using SequenceNumberFieldUnderlyingType = std::uint32_t; /// 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 const SequenceNumberFieldUnderlyingType m_SequenceNumber; diff --git a/Src/Core/Distributor.h b/Src/Core/Distributor.h index 1f8f13d..463f967 100644 --- a/Src/Core/Distributor.h +++ b/Src/Core/Distributor.h @@ -34,6 +34,10 @@ namespace MWR::C3::Core virtual void OnPacketReceived(ByteView packet, std::shared_ptr sender); protected: + /// Expose all base classes `On` methods. + using ProceduresN2N::RequestHandler::On; + using ProceduresS2G::RequestHandler::On; + /// A protected ctor. /// @param callbackOnLog callback fired whenever a new Log entry is being added. /// @param decryptionKey Relay's private asymmetric key. diff --git a/Src/Core/GateRelay.cpp b/Src/Core/GateRelay.cpp index a9415ba..23416ff 100644 --- a/Src/Core/GateRelay.cpp +++ b/Src/Core/GateRelay.cpp @@ -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 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. auto decryptedPacket = query.GetQueryPacket(m_AuthenticationKey, m_DecryptionKey); diff --git a/Src/Core/GateRelay.h b/Src/Core/GateRelay.h index cf1a50a..44c1bab 100644 --- a/Src/Core/GateRelay.h +++ b/Src/Core/GateRelay.h @@ -104,13 +104,17 @@ namespace MWR::C3::Core /// @param senderPeripheral Interface that is sending the Command. void PostCommandToConnector(ByteView command, std::shared_ptr senderPeripheral) override; + /// Expose all base classes `On` methods. + using ProceduresG2X::RequestHandler::On; + using Relay::On; + /// Handler fired when a N2N::InitializeRoute Procedure Query arrives. /// @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. /// @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. /// Gateway opens a new channel and sends parameters to relay. diff --git a/Src/Core/NodeRelay.cpp b/Src/Core/NodeRelay.cpp index 020a818..4f0d416 100644 --- a/Src/Core/NodeRelay.cpp +++ b/Src/Core/NodeRelay.cpp @@ -188,7 +188,7 @@ void MWR::C3::Core::NodeRelay::NegotiateChannel(std::shared_ptr co } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void MWR::C3::Core::NodeRelay::On(ProceduresN2N::InitializeRouteQuery&& query) +void MWR::C3::Core::NodeRelay::On(ProceduresN2N::InitializeRouteQuery query) { // Retrieve GRC. 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.") }; } diff --git a/Src/Core/NodeRelay.h b/Src/Core/NodeRelay.h index 1bacbd3..7f70940 100644 --- a/Src/Core/NodeRelay.h +++ b/Src/Core/NodeRelay.h @@ -57,13 +57,17 @@ namespace MWR::C3::Core /// @param channel Interface that will be used to send the packet. void PostCommandToConnector(ByteView command, std::shared_ptr channel) override; + /// Expose all base classes `On` methods. + using Relay::On; + using ProceduresG2X::RequestHandler::On; + /// Handler fired when a N2N::InitializeRoute Procedure Query arrives. /// @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. /// @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. /// @param query object representing the Query. diff --git a/Src/Core/Procedures.h b/Src/Core/Procedures.h index 48923e4..cf53add 100644 --- a/Src/Core/Procedures.h +++ b/Src/Core/Procedures.h @@ -184,7 +184,7 @@ namespace MWR::C3::Core struct RequestHandler { /// Declaration of support for InitializeRouteQuery Request. - virtual void On(InitializeRouteQuery&&) = 0; + virtual void On(InitializeRouteQuery) = 0; /// Declaration of support for ChannelIdExchangeStep1 Request. virtual void On(ChannelIdExchangeStep1) = 0; @@ -461,7 +461,7 @@ namespace MWR::C3::Core struct RequestHandler { /// Declaration of support for InitializeRouteQuery Request. - virtual void On(InitializeRouteQuery&&) = 0; + virtual void On(InitializeRouteQuery) = 0; /// Default empty handler for AddDeviceResponse Request. virtual void On(AddDeviceResponse) {}; diff --git a/Src/Core/ProceduresG2X.h b/Src/Core/ProceduresG2X.h index a49115c..0561b65 100644 --- a/Src/Core/ProceduresG2X.h +++ b/Src/Core/ProceduresG2X.h @@ -31,7 +31,7 @@ namespace MWR::C3::Core::ProceduresG2X : BaseQuery{ responseType } , m_Propagation{ propagation } , m_ReceiverRid{ receiverRid } - , m_GatewayPrivateSignature{ gatewayPrivateSignature } + , m_GatewayPrivateSignature{ &gatewayPrivateSignature } { } @@ -51,11 +51,12 @@ namespace MWR::C3::Core::ProceduresG2X /// @return buffer containing whole packet. 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: - 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. private: @@ -122,7 +123,7 @@ namespace MWR::C3::Core::ProceduresG2X } /// Forwarded constructors. - using Query::Query; + using Query::Query; }; /// Helper to template creating Queries to Route @@ -132,7 +133,7 @@ namespace MWR::C3::Core::ProceduresG2X { /// Forwarded constructors. - using Query::Query; + using Query::Query; }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Src/Core/Relay.h b/Src/Core/Relay.h index f5c7f44..1356268 100644 --- a/Src/Core/Relay.h +++ b/Src/Core/Relay.h @@ -21,6 +21,8 @@ namespace MWR::C3::Core virtual void DetachDevice(DeviceId const& iidOfDeviceToDetach); protected: + using Distributor::On; + /// A protected constructor. @see Distributor::Distributor. /// @param callbackOnLog callback fired whenever a new Log entry is being added. /// @param interfaceFactory reference to Interface factory.