diff --git a/build.sh b/build.sh index 5bf08a767..3857f3a31 100755 --- a/build.sh +++ b/build.sh @@ -26,6 +26,7 @@ print_usage() { echo " --clean cleans build artifacts" echo " --aos-service specifies services (e.g., sm,mp,iam)" echo " --ci uses build-wrapper for CI analysis (SonarQube)" + echo " --parallel specifies number of parallel jobs for build (default: all available cores)" echo } @@ -77,11 +78,11 @@ build_project() { if [ "$ARG_CI_FLAG" == "true" ]; then print_next_step "Run build-wrapper and build (CI mode)" - build-wrapper-linux-x86-64 --out-dir "$BUILD_WRAPPER_OUT_DIR" cmake --build ./build/ --config Debug --parallel + build-wrapper-linux-x86-64 --out-dir "$BUILD_WRAPPER_OUT_DIR" cmake --build ./build/ --config Debug --parallel ${ARG_PARALLEL_JOBS} else print_next_step "Run build" - cmake --build ./build/ --config Debug --parallel + cmake --build ./build/ --config Debug --parallel ${ARG_PARALLEL_JOBS} fi echo @@ -101,6 +102,11 @@ parse_arguments() { shift ;; + --parallel) + ARG_PARALLEL_JOBS="$2" + shift 2 + ;; + *) error_with_usage "Unknown option: $1" ;; @@ -172,6 +178,7 @@ shift ARG_CLEAN_FLAG=false ARG_AOS_SERVICES="" ARG_CI_FLAG=false +ARG_PARALLEL_JOBS=$(nproc) case "$command" in build) diff --git a/include/aos/cm/communication/communication.hpp b/include/aos/cm/communication/communication.hpp index 5d0e6b188..3608a1e44 100644 --- a/include/aos/cm/communication/communication.hpp +++ b/include/aos/cm/communication/communication.hpp @@ -7,7 +7,7 @@ #ifndef AOS_CM_COMMUNICATION_HPP_ #define AOS_CM_COMMUNICATION_HPP_ -#include "aos/common/cloudprotocol/state.hpp" +#include "aos/common/cloudprotocol/cloudmessage.hpp" #include "aos/common/types.hpp" namespace aos::cm::communication { @@ -17,25 +17,36 @@ namespace aos::cm::communication { */ /** - * Communication interface. + * Message handler interface to handle received message. */ -class CommunicationItf { +class MessageHandlerItf { public: /** - * Sends instances new state. + * Handles received message. * - * @param newState new state to send. + * @param message received message. * @return Error. */ - virtual Error SendInstanceNewState(const cloudprotocol::NewState& newState) = 0; + virtual Error HandleMessage(const cloudprotocol::MessageVariant& message) = 0; + + /** + * Destructor. + */ + virtual ~MessageHandlerItf() = default; +}; +/** + * Communication interface. + */ +class CommunicationItf { +public: /** - * Sends instances update state. + * Sends cloud message. * - * @param updateState update state to send. + * @param body cloud message body to send. * @return Error. */ - virtual Error SendInstanceStateRequest(const cloudprotocol::StateRequest& stateRequest) = 0; + virtual Error SendMessage(const cloudprotocol::MessageVariant& body) = 0; /** * Destructor. diff --git a/include/aos/cm/launcher/nodemanager.hpp b/include/aos/cm/launcher/nodemanager.hpp index c3211bb0e..4f34961df 100644 --- a/include/aos/cm/launcher/nodemanager.hpp +++ b/include/aos/cm/launcher/nodemanager.hpp @@ -28,7 +28,7 @@ struct InstanceStatus : public aos::InstanceStatus { /** * Service state checksum. */ - StaticString mStateChecksum; + StaticString<2 * cSHA3_224Size> mStateChecksum; /** * Compares instance status. diff --git a/include/aos/common/cloudprotocol/alerts.hpp b/include/aos/common/cloudprotocol/alerts.hpp index 04d40127b..e3062b82f 100644 --- a/include/aos/common/cloudprotocol/alerts.hpp +++ b/include/aos/common/cloudprotocol/alerts.hpp @@ -38,6 +38,11 @@ constexpr auto cAlertParameterLen = AOS_CONFIG_CLOUDPROTOCOL_ALERT_PARAMETER_LEN */ constexpr auto cAlertResourceErrorsSize = AOS_CONFIG_CLOUDPROTOCOL_ALERT_RESOURCE_ERRORS_SIZE; +/** + * Alert items count. + */ +constexpr auto cAlertItemsCount = AOS_CONFIG_CLOUDPROTOCOL_ALERT_ITEMS_COUNT; + /** * Alert tag. */ @@ -645,6 +650,31 @@ struct ServiceInstanceAlert : AlertItem { using AlertVariant = Variant; +using AlertVariantStaticArray = StaticArray; + +/** + * Alerts message structure. + */ +struct Alerts { + AlertVariantStaticArray mItems; + + /** + * Compares alerts. + * + * @param alerts alerts to compare with. + * @return bool. + */ + bool operator==(const Alerts& alerts) const { return mItems == alerts.mItems; } + + /** + * Compares alerts. + * + * @param alerts alerts to compare with. + * @return bool. + */ + bool operator!=(const Alerts& alerts) const { return !operator==(alerts); } +}; + } // namespace aos::cloudprotocol #endif diff --git a/include/aos/common/cloudprotocol/certificates.hpp b/include/aos/common/cloudprotocol/certificates.hpp new file mode 100644 index 000000000..0f0891161 --- /dev/null +++ b/include/aos/common/cloudprotocol/certificates.hpp @@ -0,0 +1,318 @@ +/* + * Copyright (C) 2025 EPAM Systems, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef AOS_CLOUDPROTOCOL_CERTIFICATES_HPP_ +#define AOS_CLOUDPROTOCOL_CERTIFICATES_HPP_ + +#include "aos/common/cloudprotocol/cloudprotocol.hpp" +#include "aos/common/crypto/crypto.hpp" +#include "aos/common/tools/map.hpp" +#include "aos/common/tools/optional.hpp" +#include "aos/common/types.hpp" + +namespace aos::cloudprotocol { + +/** + * Supported version of UnitSecret message. + */ +static constexpr auto cUnitSecretVersion = "2.0.0"; + +/** + * Certificate installation description size. + */ +static constexpr auto cCertInstallationDescriptionSize + = AOS_CONFIG_CLOUDPROTOCOL_CERTIFICATE_INSTALLATION_DESCRIPTION_SIZE; + +/** + * Certificate secret size. + */ +static constexpr auto cCertSecretSize = AOS_CONFIG_CLOUDPROTOCOL_CERTIFICATE_SECRET_SIZE; + +/** + * Cert type type. + */ +class CertTypeType { +public: + enum class Enum { + eOffline, + eOnline, + eUM, + eSM, + eCM, + eIAM, + eNumCertificates, + }; + + static const Array GetStrings() + { + static const char* const sStrings[] = { + "offline", + "online", + "um", + "sm", + "cm", + "iam", + "unknown", + }; + + return Array(sStrings, ArraySize(sStrings)); + }; +}; + +using CertTypeEnum = CertTypeType::Enum; +using CertType = EnumStringer; + +/** + * Maximum number of certificates per node. + */ +static constexpr auto cCertificatesPerNodeCount = static_cast(CertTypeEnum::eNumCertificates); + +/** + * Maximum number of certificates per unit. + */ +static constexpr auto cCertsPerUnitCount = cMaxNumNodes * cCertificatesPerNodeCount; + +/** + * IssuedCertData issued unit certificate data. + */ +struct IssuedCertData { + CertType mType; + StaticString mNodeID; + StaticString mCertificateChain; + + /** + * Compares issued certificate data. + * + * @param other object to compare with. + * @return bool. + */ + bool operator==(const IssuedCertData& other) const + { + return mType == other.mType && mNodeID == other.mNodeID && mCertificateChain == other.mCertificateChain; + } + + /** + * Compares issued certificate data. + * + * @param other object to compare with. + * @return bool. + */ + bool operator!=(const IssuedCertData& other) const { return !operator==(other); } +}; + +/** + * InstallCertData install certificate data. + */ +struct InstallCertData { + CertType mType; + StaticString mNodeID; + StaticString mSerial; + ItemStatus mStatus {ItemStatusEnum::eInstalled}; + StaticString mDescription; + + /** + * Compares install certificate data. + * + * @param other object to compare with. + * @return bool. + */ + bool operator==(const InstallCertData& other) const + { + return mType == other.mType && mNodeID == other.mNodeID && mSerial == other.mSerial && mStatus == other.mStatus + && mDescription == other.mDescription; + } + + /** + * Compares install certificate data. + * + * @param other object to compare with. + * @return bool. + */ + bool operator!=(const InstallCertData& other) const { return !operator==(other); } +}; + +/** + * RenewCertData renew certificate data. + */ +struct RenewCertData { + CertType mType; + StaticString mNodeID; + StaticString mSerial; + Optional