Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/cellframe-node
  • evseev/cellframe-node
  • dmitry.puzyrkov/cellframe-node
  • MIKA83/cellframe-node
4 results
Show changes
Commits on Source (1863)
Showing
with 1535 additions and 299 deletions
# Prerequisites
build/*
debug/*
build_stretch/*
test/build
*.txt.user
*.txt.user.*
*.autosave
*.user
.vscode/
.devcontainer/
# Object files
*.o
*.ko
......@@ -67,4 +71,6 @@ Makefile
cmake_install.cmake
# Editor's temp files
*~
\ No newline at end of file
*~
cmake-build-*
.idea
variables:
GIT_SUBMODULE_STRATEGY: recursive
GIT_SUBMODULE_UPDATE_FLAGS: --force
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
stages:
- prepare
- test_build
- diagnostic_builds
- build
- test
- post_build
- publish
- deploy
- update
variables:
GIT_SUBMODULE_STRATEGY: normal
.ci-polygon:
tags:
- ci-polygon
.ci-ansible:
tags:
- ci-ansible
.ci-test:
tags:
- ci-test
cellframe-node_stretch:
stage: build
only:
- develop
- master
- /^release.*$/
- /^bugfix.*$/
- /^hotfix.*$/
- /^feature.*$/
- /^support.*$/
tags:
- cellframe-node
script: ~/production-docker/integration/gitlab-CI/build_all_handler.sh cellframe-node stretch
cellframe-node_bullseye:
.build:
extends: .ci-polygon
stage: build
timeout: 3 hours 30 minutes
dependencies: []
interruptible: true
variables:
PATCH_NUM_MAIN: "${master_PATCH_NUM}"
rules:
- if: $CI_COMMIT_REF_NAME =~ /.*$/
variables:
DUMMY_VAR_FOR_ALLOW_JOB: "1"
artifacts:
paths:
- build_*/*.deb
.publish:
extends: .ci-polygon
image: demlabs/amd64/debian-buster:linuxbuilder
stage: publish
before_script: /opt/buildtools/prepare_environment.sh
.deploy:
extends: .ci-ansible
stage: deploy
rules:
- if: $CI_COMMIT_REF_NAME == "master"
when: manual
allow_failure: true
allow_failure: true
.fill_version_mk: &fill_version_mk
- PATCH_NUM_VAR_NAME=$(echo "${CI_COMMIT_REF_SLUG}" | tr "-" _)_PATCH_NUM
- echo ${PATCH_NUM_VAR_NAME}
- 'PATCH_NUM=$(curl -s --header "PRIVATE-TOKEN: ${ACCESS_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/variables/${PATCH_NUM_VAR_NAME}" | jq -r ".value // empty")'
- echo "Gitlab var patch number for ${PATCH_NUM_VAR_NAME} is ${PATCH_NUM}."
- '[ -z "${PATCH_NUM}" ] && PATCH_NUM=${PATCH_NUM_MAIN}'
- source ./version.mk
- '[ -z "${PATCH_NUM}" ] && PATCH_NUM=${VERSION_PATCH}'
#re-create version.mk based on current data
- echo "VERSION_MAJOR=$VERSION_MAJOR" > ./version.mk
- echo "VERSION_MINOR=$VERSION_MINOR" >> ./version.mk
- echo "VERSION_PATCH=$PATCH_NUM" >> ./version.mk
- cat ./version.mk
#create var
- 'curl -s --request POST --header "PRIVATE-TOKEN: ${ACCESS_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/variables" --form "key=$PATCH_NUM_VAR_NAME" --form "value=${PATCH_NUM}" || true'
- 'PIPLINE_NAME="Build $PATCH_NUM: $CI_COMMIT_MESSAGE"'
- 'curl -H "Job-Token: $CI_JOB_TOKEN" -X PUT --data "name=$PIPLINE_NAME" $CI_API_V4_URL/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/metadata'
amd64:linux.rwd.bld:
extends: .build
stage: test_build
image: demlabs/debian/amd64:qt5
before_script:
- /opt/buildtools/prepare_environment.sh amd64-linux
- *fill_version_mk
script:
- echo "Do hard work"
- ./prod_build/build.sh --target linux rwd -DBUILD_WITH_PYTHON_ENV=ON
- ./prod_build/pack.sh --target linux rwd
autotests:
extends: .ci-test
interruptible: true
stage: diagnostic_builds
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: manual
allow_failure: true
variables:
GIT_STRATEGY: none
dependencies:
- amd64:linux.rwd.bld
script:
- /opt/tests-in-docker/artifacts.sh build_*/*.deb
asan_build:
extends: .build
stage: diagnostic_builds
variables:
DAP_ASAN: "1"
dependencies:
- amd64:linux.rwd.bld
image: demlabs/debian/amd64:qt5
rules:
- when: manual
allow_failure: true
before_script:
- /opt/buildtools/prepare_environment.sh arm64-linux
- *fill_version_mk
script:
- ./prod_build/build.sh --target linux rwd
- ./prod_build/pack.sh --target linux rwd
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
ubsan_build:
extends: .build
stage: diagnostic_builds
variables:
DAP_UBSAN: "1"
dependencies:
- amd64:linux.rwd.bld
image: demlabs/debian/amd64:qt5
rules:
- when: manual
allow_failure: true
before_script:
- /opt/buildtools/prepare_environment.sh arm64-linux
- *fill_version_mk
script:
- ./prod_build/build.sh --target linux rwd
- ./prod_build/pack.sh --target linux rwd
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
tsan_build:
extends: .build
stage: diagnostic_builds
variables:
DAP_TSAN: "1"
dependencies:
- amd64:linux.rwd.bld
image: demlabs/debian/amd64:qt5
rules:
- when: manual
allow_failure: true
before_script:
- /opt/buildtools/prepare_environment.sh arm64-linux
- *fill_version_mk
script:
- ./prod_build/build.sh --target linux rwd
- ./prod_build/pack.sh --target linux rwd
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
amd64:linux.rwd:
extends: .build
stage: build
only:
- develop
- master
- /^release.*$/
- /^bugfix.*$/
- /^hotfix.*$/
- /^feature.*$/
- /^support.*$/
tags:
- cellframe-node
script: ~/production-docker/integration/gitlab-CI/build_all_handler.sh cellframe-node bullseye
cellframe-dashboard_update:
stage: update
only:
- master
tags:
- cellframe-node
script: ~/production-docker/integration/gitlab-CI/update_dashboard.sh
\ No newline at end of file
dependencies:
- amd64:linux.rwd.bld
image: demlabs/debian/amd64:qt5
before_script:
- /opt/buildtools/prepare_environment.sh amd64-linux
- *fill_version_mk
script:
- echo "Do hard work"
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb --redirect-with-link linux/cellframe-node/$CI_COMMIT_REF_NAME/latest-amd64 --just-redirect
amd64:linux.release:
extends: .build
image: demlabs/debian/amd64:qt5
before_script:
- /opt/buildtools/prepare_environment.sh amd64-linux
- *fill_version_mk
script:
- echo "Do hard work"
- ./prod_build/build.sh --target linux release -DBUILD_WITH_PYTHON_ENV=ON
- ./prod_build/pack.sh --target linux release
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
amd64:windows.rwd:
extends: .build
image: demlabs/windows/amd64:qt5
before_script:
- /opt/buildtools/prepare_environment.sh amd64-linux
- *fill_version_mk
script:
- echo "Do hard work"
- ./prod_build/build.sh --target windows rwd
- ./prod_build/pack.sh --target windows rwd
- /opt/buildtools/deploy_files.sh pub_cellframe windows/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.exe
- /opt/buildtools/deploy_files.sh pub_cellframe windows/cellframe-node/$CI_COMMIT_REF_NAME/ build_windows_rwd/*.exe --redirect-with-link windows/cellframe-node/$CI_COMMIT_REF_NAME/latest-amd64 --just-redirect
amd64:macos.release:
extends: .build
image: demlabs/macos/amd64:qt5
before_script:
- /opt/buildtools/prepare_environment.sh amd64-osx
- *fill_version_mk
script:
- echo "Do hard work"
- ./prod_build/build.sh --target osx release
- ./prod_build/pack.sh --target osx release --sign /opt/buildtools/sign/macos/demlabs.sh
- /opt/buildtools/deploy_files.sh pub_cellframe macos/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.pkg
- /opt/buildtools/deploy_files.sh pub_cellframe macos/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*-signed.pkg --redirect-with-link macos/cellframe-node/$CI_COMMIT_REF_NAME/latest-amd64 --just-redirect
artifacts:
paths:
- build_*/*.pkg
amd64:linux.debug:
extends: .build
image: demlabs/debian/amd64:qt5
before_script:
- /opt/buildtools/prepare_environment.sh amd64-linux
- *fill_version_mk
script:
- echo "Do hard work"
- ./prod_build/build.sh --target linux debug -DBUILD_WITH_PYTHON_ENV=ON
- ./prod_build/pack.sh --target linux debug
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
amd64:linux.rwd.opt:
extends: .build
image: demlabs/debian/amd64:qt5
before_script:
- /opt/buildtools/prepare_environment.sh amd64-linux
- *fill_version_mk
script:
- echo "Do hard work"
- ./prod_build/build.sh --target linux rwd -DBUILD_WITH_PYTHON_ENV=ON -DCELLFRAME_NO_OPTIMIZATION=OFF
- ./prod_build/pack.sh --target linux rwd
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb --redirect-with-link linux/cellframe-node/$CI_COMMIT_REF_NAME/latest-amd64.opt --just-redirect
amd64:linux.tps:
extends: .build
image: demlabs/debian/amd64:qt5
before_script:
- /opt/buildtools/prepare_environment.sh amd64-linux
- *fill_version_mk
when: manual
script:
- ./prod_build/build.sh --target linux release -DBUILD_WITH_TPS_TEST=ON
- ./prod_build/pack.sh --target linux release
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
.amd64:linux.updtr:
extends: .build
image: demlabs/debian/amd64:qt5
before_script:
- /opt/buildtools/prepare_environment.sh amd64-linux
- *fill_version_mk
script:
- echo "Do hard work"
- ./prod_build/build.sh --target linux release -DBUILD_WITH_PYTHON_ENV=ON -DADD_UPDATER=ON
- ./prod_build/pack.sh --target linux release
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
.amd64:linux.release:
extends: .build
image: demlabs/debian/amd64:qt5
before_script:
- /opt/buildtools/prepare_environment.sh amd64-linux
- *fill_version_mk
script:
- echo "Do hard work"
- ./prod_build/build.sh --target linux release -DBUILD_WITH_PYTHON_ENV=ON
- ./prod_build/pack.sh --target linux release
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_linux_release/*-amd64.deb --redirect-from linux/cellframe-node/$CI_COMMIT_REF_NAME/latest-amd64
- anybadge -l "node version" -v "$(source version.mk; echo "$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH")" -f node-version-badge.svg -c blue
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ ./node-version-badge.svg || true
armhf:linux.release:
extends: .build
image: demlabs/debian/arm32:qt5
before_script:
- /opt/buildtools/prepare_environment.sh armhf-linux
- *fill_version_mk
script:
- echo "Do hard work"
- ./prod_build/build.sh --target linux release
- ./prod_build/pack.sh --target linux release
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*armhf*.deb --redirect-with-link linux/cellframe-node/$CI_COMMIT_REF_NAME/latest-armhf --just-redirect
arm64:linux.release:
extends: .build
image: demlabs/debian/arm64:qt5
before_script:
- /opt/buildtools/prepare_environment.sh arm64-linux
- *fill_version_mk
script:
- echo "Do hard work"
- ./prod_build/build.sh --target linux release
- ./prod_build/pack.sh --target linux release
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb
- /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*arm64*.deb --redirect-with-link linux/cellframe-node/$CI_COMMIT_REF_NAME/latest-arm64 --just-redirect
any:android.release:
extends: .build
image: demlabs/android/any:qt5
before_script:
- /opt/buildtools/prepare_environment.sh arm64-linux
- 'apt install -y openjdk-17-jdk'
- 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/'
- *fill_version_mk
script:
- ./prod_build/pack.sh --target android release --sign /opt/buildtools/sign/android/default.sh
- /opt/buildtools/deploy_files.sh pub_cellframe android/cellframe-node/$CI_COMMIT_REF_NAME/ *.apk
version:up:
stage: post_build
tags:
- ansible-runner
variables:
GIT_STRATEGY: none
rules:
- when: on_success
script:
- PATCH_NUM_VAR_NAME=$(echo "${CI_COMMIT_REF_SLUG}" | tr "-" _)_PATCH_NUM
- echo ${PATCH_NUM_VAR_NAME}
- 'PATCH_NUM=$(curl -s --header "PRIVATE-TOKEN: ${ACCESS_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/variables/${PATCH_NUM_VAR_NAME}" | jq -r ".value // empty")'
- PATCH_NUM=$((PATCH_NUM + 1))
- 'echo "New patch version: ${PATCH_NUM}"'
- 'curl -s --request PUT --header "PRIVATE-TOKEN: ${ACCESS_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/variables/$PATCH_NUM_VAR_NAME" --form "key=$PATCH_NUM_VAR_NAME" --form "value=${PATCH_NUM}" || true'
[submodule "test/libdap-test"]
path = test/libdap-test
url = ../libdap-test.git
branch = master
[submodule "python-cellframe"]
path = python-cellframe
url = ../python-cellframe.git
......@@ -12,8 +8,11 @@
branch = develop
[submodule "prod_build"]
path = prod_build
url = ../prod_build_cellframe-node
url = ../prod_build_cellframe-node.git
[submodule "dap-sdk"]
path = dap-sdk
url = https://gitlab.demlabs.net/dap/dap-sdk
url = ../../dap/dap-sdk.git
branch = develop
[submodule "diagtool"]
path = diagtool
url = https://gitlab.demlabs.net/cellframe/cellframe-node-diagtool.git
sudo: required
language: c
compiler: gcc
dist: xenial
notifications:
email: false
before_install:
- git submodule init
- git submodule update
- cd cellframe-sdk
- git submodule init
- git submodule update
- cd ..
script:
- mkdir build
- cd build
- cmake -DBUILD_CELLFRAME_NODE_TESTS=ON ../
- make
- ctest
- cpack
- sudo dpkg -i *.deb
- ls -laR /opt/cellframe-node
- sudo /opt/cellframe-node/bin/cellframe-node-tool cert create cert0 sig_tesla
- sudo service cellframe-node start
- sudo systemctl status cellframe-node
- sudo /opt/cellframe-node/bin/cellframe-node-cli wallet new -w wallet0
- sudo /opt/cellframe-node/bin/cellframe-node-cli token_decl -net private -chain gdb token TOK1 total_supply 1000000000000000000000000 signs_total 1 signs_emission 1 certs cert0
- sudo /opt/cellframe-node/bin/cellframe-node-cli token_emit -net private -chain_emission gdb -chain_base_tx gdb -addr $(sudo /opt/cellframe-node/bin/cellframe-node-cli wallet list| grep addr | awk '{print $2}' |tr -d "\n") -token TOK1 -certs cert0 -emission_value 123000000000000
- sudo /opt/cellframe-node/bin/cellframe-node-cli mempool_proc -net private -chain gdb
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- libjson-c-dev
- libev-dev
- libmagic-dev
- libldb-dev
- libtevent-dev
- libcurl4-gnutls-dev
- debconf-utils
- dconf-cli
- pv
- libpython3-dev
project(cellframe-node C)
cmake_minimum_required(VERSION 3.10)
project(cellframe-node C)
include(cellframe-sdk/cmake/ReadMKFile.cmake)
include(FetchContent)
set(CMAKE_ENABLE_EXPORTS ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_C_STANDARD 11)
# Predefine project
SET( CPACK_PACKAGE_NAME "${PROJECT_NAME}")
SET( CPACK_PACKAGE_VERSION_MAJOR 5)
SET( CPACK_PACKAGE_VERSION_MINOR 1)
SET( CPACK_PACKAGE_VERSION_PATCH 10)
ReadVariables(version.mk)
SET( CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
SET( CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
SET( CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
if (CMAKE_TARGET_ARCH MATCHES arm)
SET( CPACK_PACKAGE_ARCHITECTURE "${CMAKE_TARGET_ARCH}")
SET( CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CMAKE_TARGET_ARCH}")
endif()
#enable for diagtool
#set(BUILD_DIAGTOOL OFF)
# Crossbuild configs
SET(CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
SET(CPACK_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
SET(DESTDIR "/opt/${PROJECT_NAME}")
if (CMAKE_TARGET_ARCH MATCHES arm)
set(CMAKE_SYSTEM_PROCESSOR arm)
if (CMAKE_TARGET_ARCH MATCHES armhf)
set(CMAKE_C_COMPILER "/usr/bin/arm-linux-gnueabihf-gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/arm-linux-gnueabihf-g++")
set(CMAKE_SYSROOT "/raspi-sysroot/")
else()
set(CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/aarch64-linux-gnu-g++")
set(CMAKE_SYSROOT "/arm64-sysroot/")
endif()
endif()
string(TIMESTAMP BUILD_TIMESTAMP "%d.%m.%Y")
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message("Build date: ${BUILD_TIMESTAMP}")
message("Git SHA: ${GIT_COMMIT_HASH}")
#SET(DAP_PQLR OFF)
#possible need be setted during crosscompily
#by default it uses dpkg --print-architecture
#we ok with it on native builds.
#SET( CPACK_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")
#SET( CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")
# init CellFrame SDK
add_definitions("-DDAP_VERSION=\"${CPACK_PACKAGE_VERSION_MAJOR}-${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}\"")
add_definitions("-DDAP_VERSION=\"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-${CPACK_PACKAGE_VERSION_PATCH}\"")
add_definitions("-DBUILD_TS=\"${BUILD_TIMESTAMP}\"")
add_definitions("-DBUILD_HASH=\"${GIT_COMMIT_HASH}\"")
set(SUBMODULES_NO_BUILD ON)
include (cellframe-sdk/cmake/OS_Detection.cmake)
option(CELLFRAME_NO_OPTIMIZATION "Build without BMI BMI2 CPU instruction." ON)
#set(BUILD_WITH_GDB_DRIVER_PGSQL ON)
#set(BUILD_CRYPTO_TESTS ON)
if( CELLFRAME_NO_OPTIMIZATION )
set(DAP_CRYPTO_XKCP_PLAINC ON)
endif()
if(BUILD_WITH_GDB_DRIVER_MDBX)
add_subdirectory(3rdparty/libmdbx)
include (dap-sdk/cmake/OS_Detection.cmake)
set(BUILD_WITH_GDB_DRIVER_MDBX ON)
if (NOT ANDROID)
set(BUILD_WITH_GDB_DRIVER_SQLITE ON)
#set(BUILD_WITH_GDB_DRIVER_PGSQL ON)
endif()
#set(BUILD_CELLFRAME_NODE_TESTS ON)
#set (BUILD_WITH_TPS_TEST ON)
if (BUILD_WITH_TPS_TEST)
add_definitions("-DDAP_TPS_TEST")
endif()
set(BUILD_WITH_ZIP OFF)
option(SUPPORT_PYTHON_PLUGINS DEFAULT OFF)
option(ADD_UPDATER OFF)
#if(MACOS)
# if(SUPPORT_PYTHON_PLUGINS)
# set(BUILD_WITH_PYTHON_ENV ON)
# endif()
#endif()
option(DAP_USE_RPMALLOC "Use 'rpmalloc' instead of std allocator" OFF)
if(LINUX)
set(SUPPORT_PYTHON_PLUGINS ON)
set(BUILD_WITH_PYTHON_ENV ON)
set(SUPPORT_PYTHON_PLUGINS ON)
endif()
if (WIN32)
set(CELLFRAME_MODULES "core chains mining network srv cs-dag-poa cs-block-poa cs-dag-pos cs-block-pos cs-none srv-app srv-app-db srv-datum srv-stake srv-xchange")
elseif(BSD)
set(CELLFRAME_MODULES "core chains mining network srv cs-dag-poa cs-block-poa cs-dag-pos cs-block-pos cs-none srv-app srv-app-db srv-datum srv-stake srv-xchange")
elseif(DARWIN)
set(CELLFRAME_MODULES "core chains mining network srv cs-dag-poa cs-block-poa cs-dag-pos cs-block-pos cs-none srv-app srv-app-db srv-datum srv-stake srv-xchange")
elseif(ANDROID)
set(CELLFRAME_MODULES "core chains mining network srv cs-dag-poa cs-block-poa cs-dag-pos cs-block-pos cs-none srv-app srv-app-db srv-datum srv-stake srv-xchange")
elseif(LINUX)
set(CELLFRAME_MODULES "core chains mining network srv cs-dag-poa cs-block-poa cs-dag-pos cs-block-pos cs-none srv-app srv-app-db srv-datum srv-stake srv-xchange modules-dynamic srv-vpn")
set(CELLFRAME_MODULES "core chains mining network srv cs-dag-poa cs-esbocs cs-none
srv-app srv-app-db srv-datum srv-stake srv-xchange srv-bridge srv-voting srv-emit-delegate")
if(LINUX OR DARWIN)
set(CELLFRAME_MODULES "${CELLFRAME_MODULES} srv-vpn")
endif()
add_subdirectory(cellframe-sdk)
if(BUILD_CELLFRAME_NODE_TESTS)
set(DAPSDK_MODULES ${DAPSDK_MODULES} "test-framework")
set(BUILD_CELLFRAME_SDK_TESTS ON)
endif()
# activate sphincsplus flexible option
set(SPHINCSPLUS_FLEX ON)
add_subdirectory(dap-sdk)
add_subdirectory(cellframe-sdk)
if(UNIX)
if(DARWIN)
SET(CMAKE_INSTALL_PREFIX "${USERDIR_PATH}/Applications/Cellframe.app")
SET(CPACK_INSTALL_PREFIX "${USERDIR_PATH}/Applications/Cellframe.app")
SET(DESTDIR "${USERDIR_PATH}/Applications/Cellframe.app")
SET(CMAKE_INSTALL_PREFIX "/Applications/CellframeNode.app")
SET(CPACK_INSTALL_PREFIX "/Applications/CellframeNode.app")
SET(DESTDIR "/Applications/CellframeNode.app")
set(BUNDLE_NAME "Cellframe.app")
set(BUNDLE_NAME "CellframeNode.app")
set(BUNDLE_PATH "${CMAKE_INSTALL_PREFIX}")
set(BINDIR ${BUNDLE_PATH}/Contents/MacOS)
set(CONTENTSDIR ${BUNDLE_PATH}/Contents/)
set(LIBDIR ${BUNDLE_PATH})
set(RLIBDIR ${BUNDLE_PATH}/Contents/Frameworks)
set(SHAREDIR ${BUNDLE_PATH}/Contents/Resources)
......@@ -77,10 +117,7 @@ if(UNIX)
set(IMPORTSDIR ${BINDIR})
add_definitions("-DDAP_DARWIN_LIBRARY")
else()
SET(CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
SET(CPACK_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
SET(DESTDIR "/opt/${PROJECT_NAME}")
endif()
......@@ -89,39 +126,90 @@ if(UNIX)
message("[*] Linux package setup")
SET( CPACK_GENERATOR "DEB")
SET( CPACK_SYSTEM_TYPE "Debian")
SET( CPACK_SYSTEM_TYPE "${DEBIAN_OS_RELEASE_NAME}")
SET( CPACK_SYSTEM_VERSION "${DEBIAN_OS_VERSION}")
if (CMAKE_TARGET_ARCH MATCHES arm)
SET( CPACK_SYSTEM_ARCH ${CMAKE_TARGET_ARCH})
SET( CPACK_SYSTEM_CODENAME "${DEBIAN_OS_NAME}")
# set architecture
find_program(DPKG_CMD dpkg)
if(NOT CPACK_TARGET_ARCHITECTURE)
if(NOT DPKG_CMD)
message(WARNING "DEB Generator: Can't find dpkg in your path. Setting CPACK_DEBIAN_PACKAGE_ARCHITECTURE to amd64.")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE amd64)
else()
execute_process(COMMAND "${DPKG_CMD}" --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
else()
SET( CPACK_SYSTEM_ARCH "amd64")
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CPACK_TARGET_ARCHITECTURE})
endif()
SET( CPACK_SYSTEM_CODENAME "${DEBIAN_OS_NAME}")
SET( CPACK_SYSTEM_NAME "${CPACK_SYSTEM_TYPE}-${CPACK_SYSTEM_VERSION}-${CPACK_SYSTEM_ARCH}-${CPACK_SYSTEM_CODENAME}")
if(BUILD_WITH_GDB_DRIVER_PGSQL)
SET( CPACK_SYSTEM_NAME "${CPACK_SYSTEM_NAME}-pgsql" )
#if ( CPACK_DEBIAN_PACKAGE_ARCHITECTURE MATCHES "arm")
# SET( BUILD_WITH_PYTHON_ENV OFF )
#endif()
if(NOT CPACK_SYSTEM_NAME)
set(CPACK_SYSTEM_NAME ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
endif()
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-${CPACK_PACKAGE_VERSION_PATCH}")
if(CMAKE_BUILD_TYPE MATCHES Debug)
SET( CPACK_SYSTEM_NAME "${CPACK_SYSTEM_NAME}-dbg" )
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-dbg" )
endif()
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-${CPACK_PACKAGE_VERSION_PATCH}")
if(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
if(ADD_UPDATER)
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-updtr" )
elseif(BUILD_WITH_TPS_TEST)
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-tps" )
else()
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-rwd" )
endif()
if (NOT CELLFRAME_NO_OPTIMIZATION)
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-opt" )
endif()
else() #to use -updtr postfix in rwd build without rwd
if(ADD_UPDATER)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-updtr" )
elseif(BUILD_WITH_TPS_TEST)
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-tps" )
endif()
endif()
if (DEFINED ENV{DAP_ASAN})
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-asan" )
endif()
if (DEFINED ENV{DAP_UBSAN})
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-ubsan" )
endif()
if (DEFINED ENV{DAP_TSAN})
SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-tsan" )
endif()
SET( CPACK_DEBIAN_PACKAGE_MAINTAINER "Dmitriy Gerasimov <naeper@demlabs.net>" )
SET( CPACK_DEBIAN_PACKAGE_DESCRIPTION_SUMMARY "CellFrame Node software https://cellframe.net" )
SET( CPACK_DEBIAN_PACKAGE_DESCRIPTION "CellFrame Node" )
SET( CPACK_DEBIAN_PACKAGE_SECTION "extra")
SET( CPACK_DEBIAN_PACKAGE_DEPENDS "debconf (>=1.5), dpkg (>=1.17), bash (>=4), debconf-utils, dconf-cli, less, pv, psmisc, logrotate, irqbalance")
if (CMAKE_TARGET_ARCH MATCHES arm)
SET( CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libmagic1, libpython3.9" )
SET( CPACK_DEBIAN_PACKAGE_DEPENDS "dpkg (>=1.17), bash (>=4), less, pv, psmisc, logrotate, irqbalance, xz-utils")
#have to figure out how to use it properly with custom RPATH for python plugins...
if (NOT SUPPORT_PYTHON_PLUGINS)
SET( CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
endif()
SET( CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
message("[*] Debian package setup pkgarch=${CPACK_DEBIAN_PACKAGE_ARCHITECTURE} version=${CPACK_PACKAGE_VERSION}")
SET( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
"${CMAKE_CURRENT_SOURCE_DIR}/debian/postinst;${CMAKE_CURRENT_SOURCE_DIR}/debian/postrm;${CMAKE_CURRENT_SOURCE_DIR}/debian/templates;${CMAKE_CURRENT_SOURCE_DIR}/debian/config;")
"${CMAKE_CURRENT_SOURCE_DIR}/os/debian/postinst;${CMAKE_CURRENT_SOURCE_DIR}/os/debian/prerm;${CMAKE_CURRENT_SOURCE_DIR}/os/debian/postrm;${CMAKE_CURRENT_SOURCE_DIR}/os/debian/templates;${CMAKE_CURRENT_SOURCE_DIR}/os/debian/config;")
elseif(BSD)
message("[*] BSD family system ${CMAKE_SYSTEM} ")
elseif(DARWIN)
message("[*] Darwin kernel (MacOS/iOS) ")
message("[*] Darwin kernel (MacOS/iOS) ")
else()
message("[!] Unknown UNIX")
endif()
......@@ -129,19 +217,19 @@ else()
message("[ ] Not UNIX")
endif()
if (CPACK_DEBIAN_PACKAGE_ARCHITECTURE MATCHES "armhf")
message("[*] ArmHF - no python")
set(SUPPORT_PYTHON_PLUGINS OFF)
set(BUILD_WITH_PYTHON_ENV OFF)
endif()
set(NODE_TARGET "${PROJECT_NAME}" )
set(NODE_CLI_TARGET "${PROJECT_NAME}-cli" )
set(NODE_TOOL_TARGET "${PROJECT_NAME}-tool")
if(BUILD_CELLFRAME_NODE_TESTS)
enable_testing()
add_subdirectory(test)
endif()
set( NODE_SOURCES
sources/main.c
sources/cellframe-node.c
sources/sig_unix_handler.c
)
set( NODE_CLI_SOURCES
......@@ -157,8 +245,9 @@ if(UNIX)
${NODE_SOURCES}
${NODE_CLI_SOURCES}
${NODE_TOOL_SOURCES}
sources/cellframe_node.h
)
add_subdirectory(sources/android)
else()
add_executable(${PROJECT_NAME} ${NODE_SOURCES})
add_executable(${NODE_CLI_TARGET} ${NODE_CLI_SOURCES})
......@@ -167,21 +256,23 @@ if(UNIX)
endif()
if(WIN32)
add_executable(${PROJECT_NAME} "sources/main.c" "sources/exh_win32.c" "sources/sig_win32_handler.c")
add_executable(${PROJECT_NAME} "sources/cellframe-node.c" "sources/exh_win32.c" "sources/sig_win32_handler.c")
add_executable(${NODE_CLI_TARGET} "sources/main_node_cli.c" )
add_executable(${NODE_TOOL_TARGET} "sources/main_node_tool.c" )
target_link_libraries(${NODE_CLI_TARGET} dap_chain_net dap_app_cli z pthread
KERNEL32 USER32 SHELL32 WINMM GDI32 ADVAPI32 Ole32 Version Imm32
OleAut32 ws2_32 ntdll psapi Shlwapi Bcrypt Crypt32 Secur32 userenv )
kernel32 user32 shell32 winmm gdi32 advapi32 ole32 version imm32
oleaut32 ws2_32 ntdll psapi shlwapi bcrypt crypt32 secur32 userenv )
set_property(TARGET ${NODE_CLI_TARGET} APPEND_STRING PROPERTY LINK_FLAGS "-mconsole")
target_link_libraries(${NODE_TOOL_TARGET} cellframe-sdk )
set_property(TARGET ${NODE_TOOL_TARGET} APPEND_STRING PROPERTY LINK_FLAGS "-mconsole")
target_link_libraries(${PROJECT_NAME} cellframe-sdk json-c )
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS "-mwindows")
#dap_chain_net_srv_vpn dap_server_http_db_auth
target_link_libraries(${PROJECT_NAME} cellframe-sdk dap_json-c )
if ((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (DAP_DEBUG))
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS "-mconsole")
else()
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS "-mwindows")
endif()
endif()
if(BSD)
......@@ -189,64 +280,12 @@ if(BSD)
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -L /usr/local/lib")
endif()
#if(DARWIN)
## 3rd party
# include_directories(cellframe-sdk/3rdparty/cuttdb/src)
# include_directories(cellframe-sdk/3rdparty/json-c/)
# include_directories(cellframe-sdk/3rdparty/libmagic/file)
# include_directories(cellframe-sdk/3rdparty/uthash/src)
# include_directories(cellframe-sdk/dap-sdk/crypto/src/XKCP/lib/high/Keccak/FIPS202)
## DAP SDK
# include_directories(cellframe-sdk/dap-sdk/core/include)
# include_directories(cellframe-sdk/dap-sdk/crypto/include)
# include_directories(cellframe-sdk/dap-sdk/net/include)
# include_directories(cellframe-sdk/dap-sdk/core/src/common)
# include_directories(cellframe-sdk/dap-sdk/core/src/darwin/macos)
# include_directories(cellframe-sdk/dap-sdk/core/src/unix)
# include_directories(cellframe-sdk/dap-sdk/net/core/include)
# include_directories(cellframe-sdk/dap-sdk/net/client/include)
# include_directories(cellframe-sdk/dap-sdk/net/server/enc_server/include)
# include_directories(cellframe-sdk/dap-sdk/net/server/http_server/include)
# include_directories(cellframe-sdk/dap-sdk/net/server/http_server/http_client/include)
# include_directories(cellframe-sdk/dap-sdk/net/server/json_rpc/)
# include_directories(cellframe-sdk/dap-sdk/net/server/notify_server/include)
# include_directories(cellframe-sdk/dap-sdk/stream/ch/include)
# include_directories(cellframe-sdk/dap-sdk/stream/session/include)
# include_directories(cellframe-sdk/dap-sdk/stream/stream/include)
##CellFrame SDK
# include_directories(cellframe-sdk/modules/app-cli/include)
# include_directories(cellframe-sdk/modules/chain/include)
# include_directories(cellframe-sdk/modules/chain/btc_rpc/include)
# include_directories(cellframe-sdk/modules/channel/chain/include)
# include_directories(cellframe-sdk/modules/channel/chain-net/include)
# include_directories(cellframe-sdk/modules/channel/chain-net-srv/include)
# include_directories(cellframe-sdk/modules/common/include)
# include_directories(cellframe-sdk/modules/consensus/block-poa/include)
# include_directories(cellframe-sdk/modules/consensus/block-pow/include)
# include_directories(cellframe-sdk/modules/consensus/dag-poa/include)
# include_directories(cellframe-sdk/modules/consensus/dag-pos/include)
# include_directories(cellframe-sdk/modules/consensus/none/include)
# include_directories(cellframe-sdk/modules/global-db/include)
# include_directories(cellframe-sdk/modules/mempool/include)
# include_directories(cellframe-sdk/modules/mining/include)
# include_directories(cellframe-sdk/modules/modules_dynamic/cdb/include)
# include_directories(cellframe-sdk/modules/net/include)
# include_directories(cellframe-sdk/modules/net/srv/include)
# include_directories(cellframe-sdk/modules/service/app/include)
# include_directories(cellframe-sdk/modules/service/app-db/include)
# include_directories(cellframe-sdk/modules/service/datum/include)
# include_directories(cellframe-sdk/modules/service/mining-pool/include)
# include_directories(cellframe-sdk/modules/service/stake/include)
# include_directories(cellframe-sdk/modules/service/vpn/include)
# include_directories(cellframe-sdk/modules/service/xchange/include)
# include_directories(cellframe-sdk/modules/service/type/blocks/include)
# include_directories(cellframe-sdk/modules/service/type/dag/include)
# include_directories(cellframe-sdk/modules/service/wallet/include)
#endif()
if(BUILD_DIAGTOOL)
message("[*] Diagtool build on")
add_subdirectory(diagtool)
endif()
#add_executable(${PROJECT_NAME}-cli "sources/main_node_cli.c" "sources/main_node_cli_shell.c" "sources/main_node_cli_net.c" )
#add_executable(${PROJECT_NAME}-tool "sources/main_node_tool.c" )
add_subdirectory(conftool)
if(UNIX AND NOT WIN32)
message ("[*] Unix library set")
......@@ -258,21 +297,84 @@ if(UNIX AND NOT WIN32)
set(NODE_TOOL_LIBRARIES m cellframe-sdk)
if (SUPPORT_PYTHON_PLUGINS)
add_definitions("-DDAP_SUPPORT_PYTHON_PLUGINS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDAP_SUPPORT_PYTHON_PLUGINS")
message("[+] Build with python plugins support")
set(Python_ADDITIONAL_VERSION 3.9 3.8 3.7 3.6 3.5 3.4)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIR} include/)
add_subdirectory(python-cellframe)
set(NODE_LIBRARIES ${NODE_LIBRARIES} ${PYTHON_LIBRARIES} dap_plugins_python)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDAP_SUPPORT_PYTHON_PLUGINS")
add_definitions("-DDAP_SUPPORT_PYTHON_PLUGINS")
if (BUILD_WITH_PYTHON_ENV)
set(PYTHON_URL "https://pub.cellframe.net/3rdparty/python/cpython310.tar.xz")
if ( CPACK_DEBIAN_PACKAGE_ARCHITECTURE MATCHES "arm")
set(PYTHON_URL "https://pub.cellframe.net/3rdparty/python/python-3.11.11-jammy-aarch64.tar.xz")
add_definitions("-DPYTHON_VERSION=\"python3.11\"")
else()
add_definitions("-DPYTHON_VERSION=\"python3.10\"")
endif()
message("[+] Build with python environment")
message(" Downloading static prebuild cpython ${PYTHON_URL}")
#this python was build by compiling and installing static python distrip to /opt/cellframe-node/ and
# installing pip in it, then tared all back.
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
cmake_policy(SET CMP0135 NEW)
endif()
FetchContent_Declare(
CPythonStatic
URL ${PYTHON_URL}
)
FetchContent_MakeAvailable(CPythonStatic)
set(cpythonstatic_SOURCE_DIR ${cpythonstatic_SOURCE_DIR})
set(SAVED_CMAKE_MESSAGE_LOG_LEVEL ${CMAKE_MESSAGE_LOG_LEVEL})
set(CMAKE_MESSAGE_LOG_LEVEL ERROR)
set(CMAKE_MESSAGE_LOG_LEVEL ${SAVED_CMAKE_MESSAGE_LOG_LEVEL})
list(APPEND CMAKE_PREFIX_PATH ${cpythonstatic_SOURCE_DIR})
if ( CPACK_DEBIAN_PACKAGE_ARCHITECTURE MATCHES "arm")
find_package(Python EXACT 3.11 COMPONENTS Interpreter Development REQUIRED)
else()
find_package(Python EXACT 3.10 COMPONENTS Interpreter Development REQUIRED)
endif()
target_link_options(${NODE_TARGET} PUBLIC "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/python/lib/")
add_definitions("-DDAP_BUILD_WITH_PYTHON_ENV")
else()
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.15")
cmake_policy(SET CMP0094 NEW)
endif()
find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED)
if(MACOS OR IOS)
list(APPEND Python_LIBRARIES ssl crypto z util expat)
elseif(LINUX OR BSD)
if ( CPACK_DEBIAN_PACKAGE_ARCHITECTURE MATCHES "arm")
list(APPEND Python_LIBRARIES crypt nsl z util expat)
else()
list(APPEND Python_LIBRARIES ssl crypto crypt nsl z util expat)
endif()
endif()
endif()
message("[*] Python version: " ${Python_VERSION})
message("[*] Python path: " ${Python_EXECUTABLE})
message("[*] Python includes path: " ${Python_INCLUDE_DIRS})
message("[*] Python library path: " ${Python_LIBRARY_DIRS})
message("[*] Python libraries: " "${Python_LIBRARIES}")
include_directories(${Python_INCLUDE_DIRS} include/)
add_subdirectory(python-cellframe)
list(APPEND NODE_LIBRARIES dap_plugins_python ${Python_LIBRARIES})
endif()
if(ANDROID )
set(ALL_LIBRARIES ${NODE_LIBRARIES} ${NODE_CLI_LIBRARIES} ${NODE_TOOL_LIBRARIES} log)
set(ALL_LIBRARIES ${NODE_LIBRARIES} ${NODE_CLI_LIBRARIES} ${NODE_TOOL_LIBRARIES} log )
list(REMOVE_DUPLICATES ALL_LIBRARIES)
target_link_libraries(${NODE_TARGET} ${ALL_LIBRARIES})
else()
target_link_libraries(${NODE_TARGET} ${NODE_LIBRARIES} pthread )
......@@ -290,31 +392,94 @@ endif()
if(DARWIN)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/ DESTINATION ${SHAREDIR} FILES_MATCHING PATTERN "*" PATTERN "*")
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.darwin/ DESTINATION ${SHAREDIR} FILES_MATCHING PATTERN "*" PATTERN "*")
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR} )
INSTALL(TARGETS ${NODE_CLI_TARGET} DESTINATION ${BINDIR} )
INSTALL(TARGETS ${NODE_TOOL_TARGET} DESTINATION ${BINDIR} )
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/ DESTINATION ${BINDIR} FILES_MATCHING PATTERN "*" PATTERN "*" PERMISSIONS OWNER_EXECUTE;OWNER_READ;OWNER_WRITE;WORLD_READ;GROUP_READ )
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts.darwin/ DESTINATION ${BINDIR} FILES_MATCHING PATTERN "*" PATTERN "*" PERMISSIONS OWNER_EXECUTE;OWNER_READ;OWNER_WRITE;WORLD_READ;GROUP_READ )
INSTALL(TARGETS cellframe-node-config DESTINATION ${BINDIR} )
if(BUILD_DIAGTOOL)
INSTALL(TARGETS cellframe-diagtool DESTINATION ${BINDIR})
endif()
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/os/macos/com.demlabs.cellframe-node.plist DESTINATION ${SHAREDIR} )
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/os/macos/com.demlabs.cellframe-diagtool.plist DESTINATION ${SHAREDIR} )
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/os/macos/Info.plist DESTINATION ${CONTENTSDIR} )
else()
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*")
if(LINUX)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.linux/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*")
elseif(DARWIN)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.darwin/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*")
#install all from dist.linux/share except updater files and node-serivice
if(NOT ADD_UPDATER)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.linux/ DESTINATION ${CMAKE_INSTALL_PREFIX} PATTERN "*cellframe-updater*" EXCLUDE PATTERN "*cellframe-node*service*" EXCLUDE )
else()
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.linux/ DESTINATION ${CMAKE_INSTALL_PREFIX} PATTERN "*cellframe-node*service*" EXCLUDE)
endif()
#install node service depends on sanitasizes values
if (DEFINED ENV{DAP_ASAN})
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dist.linux/share/cellframe-node.asan.service DESTINATION ${CMAKE_INSTALL_PREFIX}/share/ RENAME cellframe-node.service )
elseif(DEFINED ENV{DAP_UBSAN})
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dist.linux/share/cellframe-node.ubsan.service DESTINATION ${CMAKE_INSTALL_PREFIX}/share/ RENAME cellframe-node.service )
elseif(DEFINED ENV{DAP_TSAN})
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dist.linux/share/cellframe-node.tsan.service DESTINATION ${CMAKE_INSTALL_PREFIX}/share/ RENAME cellframe-node.service )
else()
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dist.linux/share/cellframe-node.service DESTINATION ${CMAKE_INSTALL_PREFIX}/share/ RENAME cellframe-node.service )
endif()
elseif(BSD)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.bsd/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*")
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.bsd/ DESTINATION ${CMAKE_INSTALL_PREFIX} )
endif()
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
if(WIN32)
INSTALL(FILES os/windows/cellframe-node.nsis DESTINATION ${CMAKE_INSTALL_ROOT}/ )
INSTALL(FILES resources/cellframe.ico DESTINATION ${CMAKE_INSTALL_ROOT}/ )
INSTALL(FILES resources/cellframe.bmp DESTINATION ${CMAKE_INSTALL_ROOT}/ )
endif()
if(UNIX AND NOT ANDROID)
INSTALL(TARGETS ${NODE_CLI_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
INSTALL(TARGETS ${NODE_TOOL_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
if (NOT ANDROID)
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
INSTALL(TARGETS ${NODE_CLI_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
INSTALL(TARGETS ${NODE_TOOL_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
endif()
if (BUILD_DIAGTOOL)
INSTALL(TARGETS cellframe-diagtool DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
endif()
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/ DESTINATION ${CMAKE_INSTALL_PREFIX}/sbin FILES_MATCHING PATTERN "*" PATTERN "*" PERMISSIONS OWNER_EXECUTE;OWNER_READ;OWNER_WRITE;WORLD_READ;GROUP_READ )
if (NOT ANDROID)
INSTALL(TARGETS cellframe-node-config DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
endif()
if(NOT ANDROID)
#install all python-specific files back to its original location
if (SUPPORT_PYTHON_PLUGINS AND BUILD_WITH_PYTHON_ENV)
set(PYTHON_PIP "${cpythonstatic_SOURCE_DIR}/bin/pip3")
set(PYTHON_BIN "${cpythonstatic_SOURCE_DIR}/bin/python3.10")
set(PYTHON_LIB "${cpythonstatic_SOURCE_DIR}/lib/libpython3.10.so.1.0")
set(PYTHON_LIB_DIR "${cpythonstatic_SOURCE_DIR}/lib/python3.10")
set(PYTHON_LIB_DIR_PRFX "python3.10")
if ( CPACK_DEBIAN_PACKAGE_ARCHITECTURE MATCHES "arm")
set(PYTHON_PIP "${cpythonstatic_SOURCE_DIR}/bin/pip3")
set(PYTHON_BIN "${cpythonstatic_SOURCE_DIR}/bin/python3.11")
set(PYTHON_LIB "${cpythonstatic_SOURCE_DIR}/lib/libpython3.11.so.1.0")
set(PYTHON_LIB_DIR "${cpythonstatic_SOURCE_DIR}/lib/python3.11")
set(PYTHON_LIB_DIR_PRFX "python3.11")
endif()
INSTALL(FILES ${PYTHON_PIP} DESTINATION ${CMAKE_INSTALL_PREFIX}/python/bin/ )
INSTALL(FILES ${PYTHON_BIN} DESTINATION ${CMAKE_INSTALL_PREFIX}/python/bin/ )
INSTALL(FILES ${PYTHON_LIB} DESTINATION ${CMAKE_INSTALL_PREFIX}/python/lib/ )
INSTALL(DIRECTORY ${PYTHON_LIB_DIR} DESTINATION ${CMAKE_INSTALL_PREFIX}/python/lib/ USE_SOURCE_PERMISSIONS)
#install python-modules
INSTALL(DIRECTORY python-cellframe/dists/python-modules/pycfhelpers DESTINATION ${CMAKE_INSTALL_PREFIX}/python/lib/${PYTHON_LIB_DIR_PRFX}/site-packages USE_SOURCE_PERMISSIONS)
INSTALL(DIRECTORY python-cellframe/dists/python-modules/pycftools DESTINATION ${CMAKE_INSTALL_PREFIX}/python/lib/${PYTHON_LIB_DIR_PRFX}/site-packages USE_SOURCE_PERMISSIONS)
INSTALL(DIRECTORY python-cellframe/dists/interfaces DESTINATION ${CMAKE_INSTALL_PREFIX}/python/lib/ USE_SOURCE_PERMISSIONS)
endif()
endif()
endif()
INCLUDE(CPack)
......@@ -11,15 +11,19 @@
To successfully complete of the build, you need to have the following packages to be installed
(packages are named as in Debian GNU/Linux 10 "buster", please found the corresponding packages for your distribution):
* libjson-c-dev
* libsqlite3-dev
* libmagic-dev
* libpython3-dev
* libz-dev
* traceroute
* build-essential
* cmake
* dpkg-dev
* debconf-utils
Please use the command below to install dependencies listed above
```
sudo apt-get install build-essential cmake dpkg-dev libpython3-dev libjson-c-dev libsqlite3-dev libmemcached-dev libev-dev libmagic-dev libcurl4-gnutls-dev libldb-dev libtalloc-dev libtevent-dev traceroute debconf-utils pv
sudo apt-get install build-essential cmake dpkg-dev libz-dev libmagic-dev libsqlite3-dev traceroute debconf-utils xsltproc libpq-dev
```
#### MacOS Prerequsites
......@@ -28,7 +32,7 @@ Install latest XCode from App Store or directly from official Apple site.
Install Homebrew from brew.sh, if you have Apple Sillicon chipset pls setup it to /opt/homebrew as recommendent on the Homebrew site.
Then install cmake and sqlite
```
brew install cmake sqlite3
brew install cmake sqlite3 zlib
```
Generaly thats all what you need
......@@ -53,17 +57,21 @@ Get into directory with cellframe-node and execute the following commands
As a result, you should be able to fine make files in your build folder which will be used by cpack command to create an installation package.
#### Build cellframe-node packages for MacOS
Right now you can't, just type ```make install``` and it will install all the files in your system at /Users/<your username>/Applications/CellFrame.app
Right now you can just type ```make install``` and it will install all the files in your system at /Applications/CellFrameNode.app
#### Build cellframe-node package for Linux
Use the following command ```cpack``` from the build directory to create cellframe-node installation package.
Use the following command ```cpack``` from the build directory to create cellframe-node installation package:
```
cpack
```
##### Install from local package
If everyting went well you should be able to find the following file in your build folder ```cellframe-node-5.0-8-Debian-21.10-amd64-impish-dbg.deb```
If everyting went well you should be able to find the following file in your build folder ```cellframe-node-5.2-0-Debian-21.10-amd64-impish-dbg.deb```
Please use ```dpkg``` command to install it:
```
sudo dpkg -i ./cellframe-node-5.0-8-Debian-21.10-amd64-impish-dbg.deb
sudo dpkg -i ./cellframe-node-5.2-0-Debian-21.10-amd64-impish-dbg.deb
```
In some cases there is a following command required to be executed
......@@ -126,23 +134,21 @@ Network address used for listentning. Set ```0.0.0.0``` if you want to listen al
* Server port (optional, usually don't ask)
Server port, 8079 by default but sometimes better to set it to ```80``` or ```443``` to masquarade service as web service.
* Core-testnet: Enable network
Set ```true``` if you want to connect your node with ```Core-T testnet```
* Subzero: Enable network
Set ```true``` if you want to connect your node with ```Subzero``` (testnet)
* Core-testnet: Node type (role)
Select node type (or node role) from suggested list with short descriptions. By default suggested to select ```full```
* Mileena: Node type (role)
Select node type (or node role) from suggested list with short descriptions. By default suggested to select ```full``` (testnet)
* Kelvin-testnet: Enable network
Set ```true``` if you want to connect your node with ```kelvin-testnet```
* Minkowski: Enable network
Set ```true``` if you want to connect your node with ```Minkowski``` (KelVPN testnet)
* SubZero: Enable network
Set ```true``` if you want to connect your node with ```subzero```
* Bacbone: Enable network
Set ```true``` if you want to connect your node with ```Backbone``` (Mainnet)
* SubZero: Node role
Select node type (or node role) from suggested list with short descriptions. By default suggested to select ```full```
### How to configure VPN service share
To share VPN service you must have a node with master role.
#### Node base configuration
Open ```/opt/cellframe-node/etc/cellframe-node.cfg``` with command ```sudo nano /opt/cellframe-node/etc/cellframe-node.cfg``` and find next section:
......@@ -150,28 +156,23 @@ Open ```/opt/cellframe-node/etc/cellframe-node.cfg``` with command ```sudo nano
# VPN stream channel processing module
[srv_vpn]
# Turn to true if you want to share VPN service from you node
enabled=false
# List of loca security access groups. Built in: expats,admins,services,nobody,everybody
enabled=true
# List of local security access groups. Built in: expats,admins,services,nobody,everybody
network_address=10.11.12.0
network_mask=255.255.255.0
#pricelist=[kelvin-testnet:0.00001:KELT:3600:SEC:mywallet0,kelvin-testnet:0.00001:cETH:3600:SEC:mywallet1,private:1:WOOD:10:SEC:mywallet0]
net=KelVPN
wallet_addr=
receipt_sign_cert=my_awesome_cert
```
Turn ```enabled``` parameter to ```true``` thats enable VPN service on your node. Then, the next lines ```network_address``` and ```network_mask``` usually you don't need to touch. Default configuration reserves network addresses for 254 connections at one time, if you have more - change network mask to smth like ```255.255.0.0``` and network address to ```10.11.0.0``` thats gives you 4095 local addresses.
Thats important - all the addresses are local and used only inside virtual private network (VPN). For this address and mask also should be configured OS - should be present DNS server, switched on IP4 forwarding and configured NAT. Example of such configurations are below:
Next line ```pricelist``` if commented out it shares service for free.
Thats important - all the addresses are local and used only inside virtual private network (VPN). For this address and mask also should be configured OS - should be present DNS server, switched on IP4 forwarding and configured NAT. Example of such configurations are below.
The next line ```net``` sets the name of the network on which the service will be shared.
Line ```wallet_addr``` sets the address of the wallet to which the payment for the service sharing will be sent.
Line ```receipt_sign_cert``` sets the name of the certificate for signing receipts. Must match the master node certificate.
#### Pricelist config
Pricelist line has list of values, splitted with ```:``` symbol. What it means lets see in example ```kelvin-testnet:0.00001:KELT:3600:SEC:mywallet0```:
1. ```kelvin-testnet``` thats the chain network name where the price token issued
2. ```0.00001``` price per units. Important: not for one unit but for all the units, in our example - for 1 hour.
3. ```KELT``` token ticker thats will be used for payments
4. ```3600``` units number thats costs price `0.00001`
5. ```SEC``` unit type, could be ```SEC``` for seconds, ```DAY``` for days, ```MB``` for megabyte. IMPORTANT: if selected ```MB``` accounting would be not by time but by used traffic amount
6.```mywallet``` wallet name for payments accommodation, should be created before with ```cellframe-node-cli```. Used for signing conditioned transactions with receipts therefore they pass values to the selected wallet.
You could enter any number of such prices
To set the price for VPN services, you need to create an order with the corresponding values. An example of creating an order will be presented below. If you do not create an order and enable VPN sharing the service will not start. To share service for free turn ```allow_free_srv``` parameter in ```[srv_vpn]``` section to ```true``` and create order with zero price.
#### DNS server install
......@@ -246,19 +247,19 @@ To stop it use the next command:
First you need to publish you public IPv4 and/or IPv6 addresses (for current moment we support only IPv4)
```
sudo /opt/cellframe-node/bin/cellframe-node-cli net -net kelvin-testnet get status
sudo /opt/cellframe-node/bin/cellframe-node-cli net -net minkowski get status
```
It should print smth like this
```
Network "kelvin-testnet" has state NET_STATE_SYNC_CHAINS (target state NET_STATE_ONLINE), active links 3 from 4, cur node address 374C::CEB5::6740::D93B
Network "minkowski" has state NET_STATE_SYNC_CHAINS (target state NET_STATE_ONLINE), active links 3 from 4, cur node address 374C::CEB5::6740::D93B
```
#### Publish IP address in nodelist
Look at the end of address, thats you node address, ```374C::CEB5::6740::D93B``` use it to update information about your node, as in example below:
```
sudo /opt/cellframe-node/bin/cellframe-node-cli node add -net kelvin-testnet -addr 374C::CEB5::6740::D93B -cell 0x0000000000000001 -ipv4 5.89.17.176
sudo /opt/cellframe-node/bin/cellframe-node-cli node add -net minkowski -addr 374C::CEB5::6740::D93B -cell 0x0000000000000001 -ipv4 5.89.17.176
```
Here is cell `0x0000000000000001` used by default until we haven't finished cell autoselection. Then ipv4 address is `5.89.17.176` replace it with your public IPv4 address. Same could be added ipv6 address with argument `-ipv6`
......@@ -268,24 +269,28 @@ Here is cell `0x0000000000000001` used by default until we haven't finished cell
To say world that you have VPN service you need to place order. First lets see the market, what orders are already present:
```
sudo /opt/cellframe-node/bin/cellframe-node-cli net_srv -net kelvin-testnet order find -srv_uid 0x0000000000000001 -direction sell
sudo /opt/cellframe-node/bin/cellframe-node-cli net_srv -net KelVPN order find -srv_uid 0x0000000000000001 -direction sell
```
It should print list if you've syncronized well before (should happens automatically by default)
Anyway, lets create our order, changing price in it and in ```cellframe-node.cfg``` if you see in list thats market changed and you need to change prices as well.
Anyway, lets create our order, changing price in it if you see in list thats market changed and you need to change prices as well.
Here is exmaple based on our pricelist in previous examples:
```sudo /opt/cellframe-node/bin/cellframe-node-cli net_srv -net kelvin-testnet order create -direction sell -srv_uid 1 -srv_class PERM -price_unit 2 -price_token KELT -price 100```
```sudo /opt/cellframe-node/bin/cellframe-node-cli net_srv -net KelVPN order create -direction sell -srv_uid 1 -price_unit SEC -price_token KEL -price 100 -units 3600 -node_addr 374C::CEB5::6740::D93B -cert my_awesome_cert -region Russia -continent Europe```
And then you just wait some for network synchronisation and your order will see everybody. Next restart your node. Provide the hash of your order to the network administrator so that your node appears in the clients list of servers.
And then you just wait some for network synchronisation and your order will see everybody.
Description of arguments
* ```-direction``` buy or sell, for VPN service publishing it must be ```sell```
* ```-srv_uid``` Service UID, for VPN service set ```1```
* ```-price_unit``` Set 2 for Seconds, 1 for Megabytes
* ```-price_unit``` Set SEC for Seconds
* ```-price_token``` Token ticker
* ```-price``` Price for one unit, price for one second in our example
Important: if you set price in configs for units set, 3600 in our example - here you set price for your single one unit, for one second in example.
* ```-units``` The number of units in one portion of the service, in this example 3600 seconds
* ```-price``` Price for the number of units specified in the parameter -units. In this example 100 datoshi for 3600 seconds of service. To share VPN service for free set this field to 0.
* ```-node_addr``` Address of node
* ```-cert``` Certificate of master node
* ```-region``` The region in which the node is located
* ```-continent``` The continent in which the node is located
More details about order operations you could find with call ```sudo /opt/cellframe-node/bin/cellframe-node-cli help net_srv```
More details about cellframe node commands in call ```sudo /opt/cellframe-node/bin/cellframe-node-cli help```
......
Subproject commit 48c778917accea702f76a61b3c1ff18159616750
Subproject commit 4e60740ab04af8be5550c7e07317d425c3cf453e
cmake_minimum_required(VERSION 3.10)
include(FetchContent)
project(cellframe-node-config)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
SET (CONFTOOL_SRC ./main.cpp
./commands/AbstractCommand.cpp
./commands/NetworkCommand.cpp
./commands/ConditionCommand.cpp
./commands/StorageCommand.cpp
./commands/ConfigCommand.cpp
./commands/ServiceCommand.cpp
./commands/FromTemplateCommand.cpp
./commands/NetworkListCommand.cpp
./config/CellframeConfigFile.cpp
./service/service_win.cpp
./service/service_linux.cpp)
if (ANDROID)
add_library(${PROJECT_NAME} SHARED ${CONFTOOL_SRC})
else ()
add_executable(${PROJECT_NAME} ${CONFTOOL_SRC})
endif ()
if (LINUX OR WIN32 )
target_link_libraries(cellframe-node-config PRIVATE stdc++fs )
endif()
if (APPLE)
target_link_libraries(cellframe-node-config PUBLIC "-framework Security -framework Foundation")
add_library(conftool_osx_ctrl STATIC ./service/service_macos.cpp ./service/macos_auth.m)
set_target_properties(conftool_osx_ctrl PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(cellframe-node-config PUBLIC conftool_osx_ctrl)
endif()
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
#if (ANDROID)
# add_definitions("-DANDROID_STL=c++_static")
#endif()
IF (WIN32)
target_link_libraries(cellframe-node-config PRIVATE ws2_32)
ENDIF()
#ifdef __linux__
#define HOST_OS "Linux"
#endif
#ifdef WIN32
#define HOST_OS "Windows"
#endif
#ifdef __APPLE__
#define HOST_OS "Macos"
#endif
\ No newline at end of file
//
// Created by dpuzyrkov on 9/17/24.
//
#ifndef NODE_CELLFRAME_NODE_CONFIG_H
#define NODE_CELLFRAME_NODE_CONFIG_H
#include "commands/AbstractCommand.h"
namespace conftool {
void populate_variables(std::string basepath);//must be specificly called befor init_configs
int init_configs(std::string init_file_name, int flags, int non_interactive);
std::unique_ptr<CAbstractScriptCommand> parse_line_to_cmd(std::string line, int line_no, int flags);
bool run_commands(std::vector <std::unique_ptr<CAbstractScriptCommand>> &commands, int interactive, int flags);
}
#endif //NODE_CELLFRAME_NODE_CONFIG_H
#include "AbstractCommand.h"
#include "NetworkCommand.h"
#include <string>
std::vector<std::string> tokenize(const std::string &str, const std::regex re)
{
std::regex_token_iterator it{ str.begin(), str.end(), re, -1 };
std::vector<std::string> tokenized{ it, {} };
tokenized.erase(
std::remove_if(tokenized.begin(),
tokenized.end(),
[](std::string const& s) {
return s.size() == 0;
}),
tokenized.end());
return tokenized;
}
std::string string_join(const std::vector<std::string>& vec, const char* delim)
{
std::stringstream res;
copy(vec.begin(), vec.end(), std::ostream_iterator<std::string>(res, delim));
return res.str();
}
CAbstractScriptCommand::CAbstractScriptCommand(std::vector<std::string> tokens)
{
this->cmd_tokens = tokens;
}
std::unordered_map<std::string, CAbstractScriptCommand::create_f *> & CAbstractScriptCommand::registry()
{
static std::unordered_map<std::string, CAbstractScriptCommand::create_f *> impl;
return impl;
}
std::unique_ptr<CAbstractScriptCommand> CAbstractScriptCommand::build(const std::string &line)
{
auto tokens = tokenize(line, std::regex("\\s+"));
auto cmd = tokens[0];
if (!CAbstractScriptCommand::exists(cmd)) return NULL;
return CAbstractScriptCommand::instantiate(cmd, tokens);
}
std::string CAbstractScriptCommand::represent()
{
return string_join(this->cmd_tokens, " ");
}
bool CAbstractScriptCommand::is_condition_open(){
return false;
}
bool CAbstractScriptCommand::is_condition_close(){
return false;
}
std::map<std::string, std::string> variable_storage;
\ No newline at end of file
#pragma once
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <vector>
#include <regex>
#include <unordered_map>
#include <memory>
#include <string>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iterator>
#include <numeric>
#include <map>
#include "../build_config.h"
enum E_FLAGS {
F_VERBOSE = 1 << 0,
F_FORCE = 1 << 1,
F_DRYRUN = 1 << 2
};
template<typename ... Args>
std::string string_format( const std::string& format, Args ... args )
{
int size_s = std::snprintf( nullptr, 0, format.c_str(), args ... ) + 1; // Extra space for '\0'
if( size_s <= 0 ){ throw std::runtime_error( "Error during formatting." ); }
auto size = static_cast<size_t>( size_s );
std::unique_ptr<char[]> buf( new char[ size ] );
std::snprintf( buf.get(), size, format.c_str(), args ... );
return std::string( buf.get(), buf.get() + size - 1 ); // We don't want the '\0' inside
}
// trim from start (in place)
inline void ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
return !std::isspace(ch);
}));
}
// trim from end (in place)
inline void rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
return !std::isspace(ch);
}).base(), s.end());
}
inline void trim(std::string &s) {
rtrim(s);
ltrim(s);
}
std::string string_join(const std::vector<std::string>& vec, const char* delim);
std::vector<std::string> tokenize(const std::string &str, const std::regex re);
struct CAbstractScriptCommand {
CAbstractScriptCommand(std::vector<std::string> tokens);
virtual ~CAbstractScriptCommand() = default;
using create_f = std::unique_ptr<CAbstractScriptCommand>(std::vector <std::string> cmd_tokens);
static void registrate(std::string const & name, create_f * fp)
{
registry()[name] = fp;
}
static bool exists(std::string const & name)
{
auto it = registry().find(name);
return it != registry().end();
}
static std::unique_ptr<CAbstractScriptCommand> instantiate(std::string const & name, std::vector <std::string> cmd_tokens)
{
auto it = registry().find(name);
return it == registry().end() ? nullptr : (it->second)(cmd_tokens);
}
template <typename D>
struct Registrar
{
explicit Registrar(std::string const & name)
{
CAbstractScriptCommand::registrate(name, &D::create);
}
// make non-copyable, etc.
};
private:
static std::unordered_map<std::string, create_f *> & registry();
CAbstractScriptCommand();
std::vector<std::string> cmd_tokens;
public:
virtual bool execute(bool non_interactive, int flags) = 0;
static std::unique_ptr<CAbstractScriptCommand> build(const std::string &line);
virtual bool is_condition_open();
virtual bool is_condition_close();
virtual std::string represent();
};
extern std::map<std::string, std::string> variable_storage;
\ No newline at end of file
#include "ConditionCommand.h"
#include <sstream>
#include <iostream>
#include <iterator>
#include <numeric>
#include "../config/CellframeConfigFile.h"
CAbstractScriptCommand::Registrar<CConditionOpenCommand> if_registrar("if");
CAbstractScriptCommand::Registrar<CConditionCloseCommand> endif_registrar("endif");
bool CConditionOpenCommand::is_condition_open() {return true;}
bool CConditionCloseCommand::is_condition_close() {return true;}
CConditionOpenCommand::CConditionOpenCommand(std::vector <std::string> cmd_tokens):CAbstractScriptCommand(cmd_tokens)
{
std::string joined_condition = string_join(std::vector<std::string>(cmd_tokens.begin()+1,cmd_tokens.end()), "");
auto eq_token = joined_condition.find("==");
auto neq_token = joined_condition.find("!=");
if (eq_token != std::string::npos)
this->cond_op = COND_EQUAL;
if (neq_token != std::string::npos)
this->cond_op = COND_NOT_EQUAL;
if (eq_token == std::string::npos && neq_token == std::string::npos)
this->cond_op = COND_IS_SET;
std::vector < std::string> tokens = tokenize(joined_condition, std::regex("==|!="));
if (this->cond_op == COND_IS_SET && tokens.size() != 1)
throw std::invalid_argument("IS_SET condition requre only one variable for check");
if (this->cond_op != COND_IS_SET && tokens.size() != 2)
throw std::invalid_argument("CONDITION EQ | NEQ requre only two tokens");
this->arg1 = tokens[0];
if (this->cond_op != COND_IS_SET)
this->arg2 = tokens[1];
//auto neq_token = std::find(joined_condition.begin(), joined_condition.end(), "!=");
}
CConditionCloseCommand::CConditionCloseCommand(std::vector <std::string> cmd_tokens):CAbstractScriptCommand(cmd_tokens)
{
}
bool CConditionOpenCommand::execute(bool non_intercative, int flags)
{
std::string a1val = this->arg1;
std::string a2val = this->arg2;
if (flags & F_VERBOSE) std::cout << "[VE] Condition exec: " << a1val << " " << this->cond_op << " "<<a2val << " -> ";
a1val = substitute_variables(arg1);
a2val = substitute_variables(arg2);
bool res = false;
std::string opsym = "";
switch (this->cond_op)
{
case COND_EQUAL:
{
opsym = "==";
res = a1val == a2val;
break;
}
case COND_NOT_EQUAL:
{
opsym = "!=";
res = a1val != a2val;
break;
}
case COND_IS_SET:
{
opsym = "exists";
res = a1val.empty();
break;
}
default:
throw std::invalid_argument("Unknown condition type");
}
if (flags & F_VERBOSE) std::cout << a1val << " " << opsym << " " <<a2val << " -> " << res << std::endl;
return res;
}
bool CConditionCloseCommand::execute(bool non_intercative, int flags)
{
return true;
}
#pragma once
#include "AbstractCommand.h"
enum E_COND_OPS {
COND_EQUAL,
COND_NOT_EQUAL,
COND_IS_SET
};
class CConditionOpenCommand : public CAbstractScriptCommand {
public:
CConditionOpenCommand(std::vector <std::string> cmd_tokens);
static std::unique_ptr<CAbstractScriptCommand> create(std::vector <std::string> cmd_tokens) { return std::make_unique<CConditionOpenCommand>(cmd_tokens); }
bool execute(bool non_interactive, int flags);
bool is_condition_open();
E_COND_OPS cond_op;
std::string arg1;
std::string arg2;
};
class CConditionCloseCommand : public CAbstractScriptCommand {
public:
CConditionCloseCommand(std::vector <std::string> cmd_tokens);
static std::unique_ptr<CAbstractScriptCommand> create(std::vector <std::string> cmd_tokens) { return std::make_unique<CConditionCloseCommand>(cmd_tokens); }
bool execute(bool non_interactive, int flags);
bool is_condition_close();
};
\ No newline at end of file
#include "ConfigCommand.h"
#include "../config/CellframeConfigFile.h"
CAbstractScriptCommand::Registrar<CConfigCommand> cfg_registrar("config");
/*
config cellframe-node general auto_online default true
config cellframe-node general debug_mode default false
config cellframe-node server enabled default false
config cellframe-node server listen_address default 127.0.0.1
config cellframe-node server listen_port_tcp default 8079
config cellframe-node notify_server listen_address default 127.0.0.1
config cellframe-node notify_server listen_port default 8080
if MacOS == $HOST_OS
config cellframe-node global_db driver ensure $DB_DRIVER
endif
config Backbone general node-role default full
config KelVPN general node-role default full
config raiden general node-role default full
config riemann general node-role default full
config mileena general node-role default full
config subzero general node-role default full
*/
std::vector<std::string> allowed_actions{"default", "ensure", "get"};
CConfigCommand::CConfigCommand(std::vector <std::string> cmd_tokens):CAbstractScriptCommand(cmd_tokens)
{
//zero token is always a command (config)
if (cmd_tokens.size() <= 4)
throw std::invalid_argument("config command invalid numbers of arguments");
this->cfg_name = cmd_tokens[1];
//check if config name accetable
//net should exist
fs::path net_cfg_template_path = config_path(this->cfg_name, CFG_GENERAL, CFG_TEMPLATE);
if (this->cfg_name != "cellframe-node" && !fs::exists(net_cfg_template_path))
throw std::invalid_argument(string_format("config_cmd: config for [%s] not exitst",
this->cfg_name.c_str()));
this->group = cmd_tokens[2];
this->param = cmd_tokens[3];
this->action = cmd_tokens[4];
if (allowed_actions.end() == std::find(allowed_actions.begin(), allowed_actions.end(), this->action))
{
throw std::invalid_argument(string_format("config_cmd: allowed actions are get|ensure|default, not %s",
this->action.c_str()));
}
if (cmd_tokens.size() > 5)
this->value = cmd_tokens[5];
}
bool is_placeholder(const std::string &val)
{
if (val.empty()) return true;
return val[0]=='$' && val[val.size()-1]=='}';
}
bool CConfigCommand::execute(bool non_intercative, int flags)
{
//can't do this in ctr, cause storage-cmds can be not executed yet.
this->value = substitute_variables(this->value);
auto cfg_on_path = config_path(this->cfg_name, CFG_GENERAL, CFG_ON );
auto cfg_off_path = config_path(this->cfg_name, CFG_GENERAL, CFG_OFF );
fs::path cfg_path = cfg_on_path;
if (this->cfg_name != "cellframe-node")
{
if (fs::exists(cfg_off_path))
cfg_path = cfg_off_path;
if (fs::exists(cfg_on_path))
cfg_path = cfg_on_path;
if (fs::exists(cfg_on_path) && fs::exists(cfg_off_path))
{
std::cout << "[C][config] " << "cfg " << this->cfg_name
<< " is in both on&off states, use enabled cfg for modifications" << std::endl;
}
}
std::map <std::string, std::function<bool ()>> actions;
CellframeConfigurationFile cfg(cfg_path, flags);
//check for default net state
//default means
//set if - no parameter defined
//set if value is placeholder ({CFG})
//if exists - skip
actions["default"] = [*this, &cfg]() {
std::string cfg_val;
bool param_exists = cfg.exists(this->group, this->param, &cfg_val);
if (param_exists && !is_placeholder(cfg_val)){
//skip
std::cout << "[C][config default] " << "[" << this->cfg_name<<"] "
<< "[" << this->group<<"] "
<< this->param << "==" <<cfg_val
<< ", skip altering"<<std::endl;
return false;
}
std::cout << "[C][config default] " << "[" << this->cfg_name<<"]"
<< " [" << this->group<<"] set "
<< this->param << "=" <<this->value
<< std::endl;
cfg.set(this->group, this->param, this->value);
return true;
};
//force net state
actions["ensure"] = [*this, &cfg]() {
std::cout << "[C][config ensure] " << "[" << this->cfg_name<<"] "
<< "[" << this->group<<"] set "
<< this->param << "=" <<this->value
<< std::endl;
cfg.set(this->group, this->param, this->value);
return true;
};
actions["get"] = [*this, &cfg]() {
std::string cfg_val;
bool param_exists = cfg.exists(this->group, this->param, &cfg_val);
std::cout << this->cfg_name << ": ["<<this->group<<"] " << this->param+"="+cfg_val<<std::endl;
return false;
};
//actions return true if config was altered and need to be saved
bool res = actions[this->action]();
if (res) cfg.save();
return true;
}
#pragma once
#include "AbstractCommand.h"
class CConfigCommand : public CAbstractScriptCommand {
public:
CConfigCommand(std::vector <std::string> cmd_tokens);
static std::unique_ptr<CAbstractScriptCommand> create(std::vector <std::string> cmd_tokens) { return std::make_unique<CConfigCommand>(cmd_tokens); }
bool execute(bool non_interactive, int flags);
private:
std::string cfg_name;
std::string group;
std::string param;
std::string value;
std::string action;
};
#include "FromTemplateCommand.h"
#include <stdexcept>
#include <filesystem>
#include "../build_config.h"
#include "../config/CellframeConfigFile.h"
namespace fs = std::filesystem;
CAbstractScriptCommand::Registrar<CFromTemplateCommand> tmplt_registrar("fromtemplate");
CFromTemplateCommand::CFromTemplateCommand(std::vector <std::string> cmd_tokens): CAbstractScriptCommand(cmd_tokens)
{
if (cmd_tokens.size() <= 2)
throw std::invalid_argument("config command invalid numbers of arguments");
this->cfg_name = cmd_tokens[1];
//check if config name accetable
fs::path net_cfg_template_path = config_path(this->cfg_name, CFG_GENERAL, CFG_TEMPLATE);
if (this->cfg_name != "cellframe-node" && !fs::exists(net_cfg_template_path))
throw std::invalid_argument("config_cmd: config not exitst");
this->action = cmd_tokens[2];
}
bool CFromTemplateCommand::execute(bool non_intercative, int flags)
{
auto path_from = config_path(this->cfg_name, CFG_GENERAL, CFG_TEMPLATE);
auto path_to = config_path(this->cfg_name, CFG_GENERAL, CFG_ON);
if (this->action == "default")
{
if (fs::exists(path_to))
{
std::cout << "[C][fromtemplate default] " << " [" << this->cfg_name<<"]"
<< " exists, skip altering"<<std::endl;
return true;
}
std::cout <<"[C] [fromtemplate default] "
<<"copy "<< path_from << " to "<< path_to << std::endl;
if (!(flags & F_DRYRUN)) fs::copy_file(path_from, path_to);
}
if (this->action == "ensure")
{
std::cout <<"[C] [fromtemplate ensure] "
<<"copy "<< path_from << " to "<< path_to << std::endl;
if (!(flags & F_DRYRUN)) fs::copy_file(path_from, path_to, fs::copy_options::overwrite_existing);
}
//populate
CellframeConfigurationFile cfg(path_to, flags);
cfg.replace_placeholders(variable_storage);
cfg.save();
return true;
}
\ No newline at end of file
#pragma once
#include "AbstractCommand.h"
class CFromTemplateCommand : public CAbstractScriptCommand {
public:
CFromTemplateCommand(std::vector <std::string> cmd_tokens);
static std::unique_ptr<CAbstractScriptCommand> create(std::vector <std::string> cmd_tokens) { return std::make_unique<CFromTemplateCommand>(cmd_tokens); }
bool execute(bool non_interactive, int flags);
private:
std::string cfg_name;
std::string action;
};
#include "NetworkCommand.h"
#include <stdexcept>
#include <filesystem>
#include "../build_config.h"
#include "../config/CellframeConfigFile.h"
namespace fs = std::filesystem;
CAbstractScriptCommand::Registrar<CNetworkCommand> registrar("network");
/*
Network Command syntax:
network {netname} default on
network {netname} default off
network {netname} ensure off
network {netname} ensure on
*/
std::vector<std::string> allowed_states{"on", "off"};
CNetworkCommand::CNetworkCommand(std::vector <std::string> cmd_tokens): CAbstractScriptCommand(cmd_tokens)
{
//zero token is always a command (network)
if (cmd_tokens.size() <= 2)
throw std::invalid_argument("network command has no command arguments");
this->net_name = cmd_tokens[1];
//check such net is available: lookup for config files in share dir
fs::path net_cfg_template_path = config_path(this->net_name, CFG_GENERAL, CFG_TEMPLATE);
if (!fs::exists(net_cfg_template_path))
throw std::invalid_argument("network_cmd: template not found in share config path");
std::map <std::string, std::function<void ()>> actions;
actions["default"] = [this, &cmd_tokens](){
if (cmd_tokens.size() < 4 || allowed_states.end() == std::find(allowed_states.begin(), allowed_states.end(), cmd_tokens[3]))
throw std::invalid_argument("network_cmd: [default] require 'on or off' state for net");
this->default_val = cmd_tokens[3];
};
actions["ensure"] = [this, &cmd_tokens](){
if (cmd_tokens.size() < 4 || allowed_states.end() == std::find(allowed_states.begin(), allowed_states.end(), cmd_tokens[3]))
throw std::invalid_argument("network_cmd: [ensure] require 'on or off' state for net" );
this->default_val = cmd_tokens[3];
};
actions["check"] = [this, &cmd_tokens](){};
this->action = cmd_tokens[2];
if (actions.find(this->action) == actions.end())
throw std::invalid_argument("network_cmd: unknown action for network_cmd");
actions[this->action]();
}
bool CNetworkCommand::execute(bool non_intercative, int flags)
{
std::map <std::string, std::function<bool ()>> actions;
//check for default net state
actions["default"] = [&]() {
//validity of default_value ensured by constructor
fs::path check_exist_path;
fs::path template_copy_dest;
fs::path template_path = config_path(this->net_name, CFG_GENERAL, CFG_TEMPLATE);
if (fs::exists(config_path(this->net_name, CFG_GENERAL, CFG_OFF)) &&
fs::exists(config_path(this->net_name, CFG_GENERAL, CFG_ON)) )
{
std::cout << "[C][network default] you have both enabled and disabled files for network [" << this->net_name << "], skip this step"<<std::endl;
return false;
}
//default requested net on
if (this->default_val == "on")
{
check_exist_path = config_path(this->net_name, CFG_GENERAL, CFG_OFF);
template_copy_dest = config_path(this->net_name, CFG_GENERAL, CFG_ON);
} else if (this->default_val == "off")
{
check_exist_path = config_path(this->net_name, CFG_GENERAL, CFG_ON);
template_copy_dest = config_path(this->net_name, CFG_GENERAL, CFG_OFF);
} else { std::cout << "wtf" << std::endl; return false; }
//skip default if net already exists in any state
if (fs::exists(template_copy_dest)) {
std::cout << "[C][network default " << this->default_val<<"] Network [" << this->net_name << "] already "<< this->default_val << ", skip this step" <<std::endl;
return true;
}
if (fs::exists(check_exist_path))
{
if (flags & F_VERBOSE) std::cout << "[VE][network default] File " << check_exist_path << " exists, but default state requested [" << this->default_val << "]";
std::cout << "[C}[network default] Skip altering state for newtwork [" << this->net_name<<"] due to it was user-configured" << std::endl;
return false;
}
// default on: net exists, not on, and not disabled -> copy network config as enabled
std::cout << "[C][network default] Set-up net [" << this->net_name << "] as ["<< (this->default_val == "on" ? "ENABLED" : "DISABLED")
<< "] from template " << template_path << std::endl;
if (flags & F_VERBOSE) std::cout << "[VE][network default] copy file from " << template_path << " to " << template_copy_dest << std::endl;
if (!(flags & F_DRYRUN)) fs::copy(template_path, template_copy_dest);
return true;
};
//force net state
actions["ensure"] = [&]() {
//check for disabled
bool net_enabled = fs::exists(config_path(this->net_name, CFG_GENERAL, CFG_ON));
if (this->default_val == "on" && net_enabled)
{
std::cout << "[C][network ensure on]: Network [" << this->net_name << "] already enabled"<<std::endl;
return false;
}
if (this->default_val == "off" && !net_enabled && fs::exists(config_path(this->net_name, CFG_GENERAL, CFG_OFF)))
{
std::cout << "[C][network ensure off]: Network [" << this->net_name << "] already disabled"<<std::endl;
return false;
}
ENetworkConfigState requested_state, oposite_state;
if (this->default_val == "on") {
requested_state = CFG_ON;
oposite_state = CFG_OFF;
}
if (this->default_val == "off")
{
requested_state = CFG_OFF;
oposite_state = CFG_ON;
}
//move from oposite if exists
if (fs::exists(config_path(this->net_name, CFG_GENERAL, oposite_state))){
std::cout << "[C][network ensure " << this->default_val << "] move file from "
<< config_path(this->net_name, CFG_GENERAL, oposite_state)
<< " to " << config_path(this->net_name, CFG_GENERAL, requested_state)
<< std::endl;
if (!(flags & F_DRYRUN)) fs::rename(config_path(this->net_name, CFG_GENERAL, oposite_state),
config_path(this->net_name, CFG_GENERAL, requested_state));
} else { //copy from template if oposite side of config not exits
std::cout << "[C][network ensure "<<this->default_val << "] copy file from "
<< config_path(this->net_name, CFG_GENERAL, CFG_TEMPLATE)
<< " to " << config_path(this->net_name, CFG_GENERAL, requested_state)
<< std::endl;
if (!(flags & F_DRYRUN)) fs::copy(config_path(this->net_name, CFG_GENERAL, CFG_TEMPLATE),
config_path(this->net_name, CFG_GENERAL, requested_state));
}
return true;
};
//force net state
actions["check"] = [&]() {
//check for disabled
bool net_enabled = fs::exists(config_path(this->net_name, CFG_GENERAL, CFG_ON));
std::cout << "[C][network check]: Network [" << this->net_name << "] " << (net_enabled ? "on" : "off") << std::endl;
return true;
};
return actions[this->action]();
}
#include "AbstractCommand.h"
class CNetworkCommand : public CAbstractScriptCommand {
public:
CNetworkCommand(std::vector <std::string> cmd_tokens);
static std::unique_ptr<CAbstractScriptCommand> create(std::vector <std::string> cmd_tokens) { return std::make_unique<CNetworkCommand>(cmd_tokens); }
bool execute(bool non_interactive, int flags);
private:
std::string net_name;
std::string action;
std::string default_val;
};