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 (3271)
Showing
with 2159 additions and 101 deletions
# Prerequisites
build/*
*.d
debug/*
build_stretch/*
test/build
*.txt.user
*.txt.user.*
*.autosave
*.user
.vscode/
.devcontainer/
# Object files
*.o
*.ko
*.obj
*.elf
.DS_Store
# Linker output
*.ilk
*.map
......@@ -23,7 +29,7 @@ build/*
*.a
*.la
*.lo
*.autosave
# Shared objects (inc. Windows DLLs)
*.dll
*.so
......@@ -46,9 +52,25 @@ build/*
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
/.project
/.cproject
/kelvin-node_logs.txt
/build*/
# Autogenerated CMake files
CMakeCache.txt
CMakeFiles/
CPackConfig.cmake
CPackSourceConfig.cmake
Makefile
cmake_install.cmake
# Editor's temp files
*~
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:
- test_build
- diagnostic_builds
- build
- post_build
- publish
- deploy
.ci-polygon:
tags:
- ci-polygon
.ci-ansible:
tags:
- ci-ansible
.ci-test:
tags:
- ci-test
.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
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 "libdap"]
path = libdap
url = https://github.com/kelvinblockchain/libdap.git
branch = master
[submodule "libdap-server"]
path = libdap-server
url = https://github.com/kelvinblockchain/libdap-server.git
branch = master
[submodule "libdap-chain"]
path = libdap-chain
url = https://github.com/kelvinblockchain/libdap-chain.git
branch = master
[submodule "libdap-stream"]
path = libdap-stream
url = https://github.com/kelvinblockchain/libdap-stream.git
branch = master
[submodule "libdap-stream-ch-vpn"]
path = libdap-stream-ch-vpn
url = https://github.com/kelvinblockchain/libdap-stream-ch-vpn.git
branch = master
[submodule "libdap-stream-ch-av"]
path = libdap-stream-ch-av
url = https://github.com/kelvinblockchain/libdap-stream-ch-av
branch = master
[submodule "libdap-stream-ch-chat"]
path = libdap-stream-ch-chat
url = https://github.com/kelvinblockchain/libdap-stream-ch-chat
branch = master
[submodule "libdap-server-core"]
path = libdap-server-core
url = https://github.com/kelvinblockchain/libdap-server-core
branch = master
[submodule "libdap-stream-ch-chain"]
path = libdap-stream-ch-chain
url = https://github.com/kelvinblockchain/libdap-stream-ch-chain
branch = master
[submodule "python-cellframe"]
path = python-cellframe
url = ../python-cellframe.git
branch = develop
[submodule "cellframe-sdk"]
path = cellframe-sdk
url = ../cellframe-sdk.git
branch = develop
[submodule "prod_build"]
path = prod_build
url = ../prod_build_cellframe-node.git
[submodule "dap-sdk"]
path = dap-sdk
url = ../../dap/dap-sdk.git
branch = develop
[submodule "diagtool"]
path = diagtool
url = https://gitlab.demlabs.net/cellframe/cellframe-node-diagtool.git
## Cellframe-node [3.5-12] - 2020-07-31
### Fixed
- #4220 Fix countries in Kelvin orders
- #4221 Node sometimes crashing during stream close
## Cellframe-node [3.5-7] - 2020-07-17
### Added
- #4218 Brand CDB nodes
- #4046 Private network mode with auth via certificate
### Fixed
- #4073 Minor issues with epolling
## Cellframe-node [3.5-4] - 2020-07-08
### Fixed
- #4157 Segmentation fault when executing commands: token_update, token_decl_sign, tx_history
## Cellframe-node [3.5-3] - 2020-06-29
### Fixed
- #4028 VPN nodes stop working at some point (restarting required)
## Cellframe-node [3.4-6] - 2020-06-17
### Added
- #3975 Delegated Stake service
- #3977 Signed orders (Add signature to expanded order to allow signature by key for all orders during creation)
### Fixed
- #4013 VPN nodes stop working at some point
## Cellframe-node [3.4-4] - 2020-06-03
### Update
- #2844 Create exchange service for tokens inside the network
## Cellframe-node [3.4-2] - 2020-06-01
### Added
- #3600 Regional rebalancing for CDB
## Cellframe-node [3.4-2] - 2020-05-30
### Fixed
- #3951 Change sent back to client key with service use
## Cellframe-node [3.4-1] - 2020-05-29
### Added
- #2844 Create exchange service for tokens inside the network
## Cellframe-node [3.3-8] - 2020-05-28
### Added
- #3927 Add additional checks to dap_chain_ledger_tx_cache_check()
## Cellframe-node [3.3-6] - 2020-05-26
### Added
- feature-autoproc
## Cellframe-node [3.3-5] - 2020-05-25
### Fixed
- #3903 server core blocks event loop у nodejs
### Added
- #3844 emit DAPT and KELT tokens to core-t, move their basic transactions into kelvin-testnet zerochains’ genesis events
## Cellframe-node [3.3-4] - 2020-05-21
### Fixed
- #3895 Network offline while auto_online=true
## Cellframe-node [3.3-2] - 2020-05-18
### Added
- #3782 Launch plasma for core-t сети
## Cellframe-node [3.2-17] - 2020-05-15
### Update
- Static event for genesis for zerochain in core-t network updated
## Cellframe-node [3.2-16] - 2020-05-13
### Added
- #3584 instantiate addition, serialization and deserialization for certificates metadata
## Cellframe-node [3.2-13] - 2020-05-08
### Added
- #3707 dap interval timer support for MacOS added
## Cellframe-node [3.2-8] - 2020-05-07
### Fixed
- #3757 Service freeze, unending wait for PVT(l_dag)->events_rwlock resource deallocation
### Added
- #3650 Addition and sending news, newsticker
## Cellframe-node [3.2-1] - 2020-05-01
### Fixed
- #3666 Error dap_client_http callback does not happen if timeout data was not received
## Cellframe-node [0.0-00] - 2020-04-29
### Update
- Updated README.md
### Added
- #3617 support for receiving and reading bugreports is added to CDB node
## Cellframe-node [0.0-00] - 2020-04-27
### Fixed
- #3427 Make sure that sync with all nodes is done consequently.
## Cellframe-node [0.0-00] - 2020-04-24
### Fixed
- #3560 Mempool chains processing is done incorrectly
## Cellframe-node [0.0-00] - 2020-04-23
### Added
- #2703 Mempool auto processing mode in Master Node role
## Cellframe-node [0.0-00] - 2020-04-20
### Update
- Updated README.md
## Cellframe-node [0.0-00] - 2020-04-20
### Update
- Updated README.md
## Cellframe-node [0.0-00] - 2020-04-11
### Fixed
- #3380 Mistake in libdap-crypto
## Cellframe-node [0.0-00] - 2020-04-08
### Fixed
- Order creation command example fixed in README.md
## Cellframe-node [0.0-00] - 2020-04-02
### Added
- #3330 Add-in DNS server added
project(kelvin-node C)
cmake_minimum_required(VERSION 2.8)
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_CXX_STANDARD 11)
SET (CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
SET (CPACK_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
SET (DESTDIR "/opt/${PROJECT_NAME}")
set(CMAKE_C_STANDARD 11)
SET( CPACK_GENERATOR "DEB")
# Predefine project
SET( CPACK_PACKAGE_NAME "${PROJECT_NAME}")
SET( CPACK_PACKAGE_VERSION_MAJOR 0)
SET( CPACK_PACKAGE_VERSION_MINOR 1)
SET( CPACK_PACKAGE_VERSION_PATCH 1)
ReadVariables(version.mk)
SET( CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
SET( CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
SET( CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
#enable for diagtool
#set(BUILD_DIAGTOOL OFF)
SET(CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
SET(CPACK_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
SET(DESTDIR "/opt/${PROJECT_NAME}")
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("-DBUILD_TS=\"${BUILD_TIMESTAMP}\"")
add_definitions("-DBUILD_HASH=\"${GIT_COMMIT_HASH}\"")
set(SUBMODULES_NO_BUILD ON)
option(CELLFRAME_NO_OPTIMIZATION "Build without BMI BMI2 CPU instruction." ON)
if( CELLFRAME_NO_OPTIMIZATION )
set(DAP_CRYPTO_XKCP_PLAINC ON)
endif()
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(BUILD_WITH_PYTHON_ENV ON)
set(SUPPORT_PYTHON_PLUGINS ON)
endif()
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()
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 "/Applications/CellframeNode.app")
SET(CPACK_INSTALL_PREFIX "/Applications/CellframeNode.app")
SET(DESTDIR "/Applications/CellframeNode.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)
set(PLUGINSDIR ${BUNDLE_PATH}/Contents/PlugIns)
set(IMPORTSDIR ${BINDIR})
add_definitions("-DDAP_DARWIN_LIBRARY")
endif()
if(LINUX)
message("[*] Linux package setup")
SET( CPACK_GENERATOR "DEB")
SET( CPACK_SYSTEM_TYPE "${DEBIAN_OS_RELEASE_NAME}")
SET( CPACK_SYSTEM_VERSION "${DEBIAN_OS_VERSION}")
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_DEBIAN_PACKAGE_ARCHITECTURE ${CPACK_TARGET_ARCHITECTURE})
endif()
#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_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-dbg" )
endif()
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 "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()
message("[*] Debian package setup pkgarch=${CPACK_DEBIAN_PACKAGE_ARCHITECTURE} version=${CPACK_PACKAGE_VERSION}")
SET( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
"${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) ")
else()
message("[!] Unknown UNIX")
endif()
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")
set( NODE_SOURCES
sources/cellframe-node.c
sources/sig_unix_handler.c
)
set( NODE_CLI_SOURCES
sources/main_node_cli.c
)
set( NODE_TOOL_SOURCES
sources/main_node_tool.c
)
if(UNIX)
if(ANDROID)
add_library(${PROJECT_NAME} SHARED
${NODE_SOURCES}
${NODE_CLI_SOURCES}
${NODE_TOOL_SOURCES}
)
add_subdirectory(sources/android)
else()
add_executable(${PROJECT_NAME} ${NODE_SOURCES})
add_executable(${NODE_CLI_TARGET} ${NODE_CLI_SOURCES})
add_executable(${NODE_TOOL_TARGET} ${NODE_TOOL_SOURCES})
endif()
endif()
if(WIN32)
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 )
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 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)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -L /usr/local/lib ")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -L /usr/local/lib")
endif()
if(BUILD_DIAGTOOL)
message("[*] Diagtool build on")
add_subdirectory(diagtool)
endif()
add_subdirectory(conftool)
if(UNIX AND NOT WIN32)
message ("[*] Unix library set")
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS "-D_GNU_SOURCE")
set(NODE_LIBRARIES cellframe-sdk )
set(NODE_CLI_LIBRARIES m cellframe-sdk)
set(NODE_TOOL_LIBRARIES m cellframe-sdk)
if (SUPPORT_PYTHON_PLUGINS)
message("[+] Build with python plugins support")
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/")
SET( CPACK_SYSTEM_NAME "debian-9.5-amd64")
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()
SET( CPACK_DEBIAN_PACKAGE_MAINTAINER "Dmitriy Gerasimov <naeper@ldemlabs.net>" )
SET( CPACK_DEBIAN_PACKAGE_DESCRIPTION_SUMMARY "Kelvin Blockchain Node software" )
SET( CPACK_DEBIAN_PACKAGE_DESCRIPTION "DAP server" )
SET( CPACK_DEBIAN_PACKAGE_SECTION "extra")
SET( CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64" )
SET( CPACK_DEBIAN_PACKAGE_DEPENDS "debconf (>=1.5), dpkg (>=1.17), bash (>=4)")
SET( CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
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;")
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()
add_definitions ("-DDAP_SERVER")
add_definitions ("-DNODE_NETNAME=\"kelvin\"")
if(ANDROID )
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 )
target_link_libraries(${NODE_CLI_TARGET} ${NODE_CLI_LIBRARIES} pthread )
target_link_libraries(${NODE_TOOL_TARGET} ${NODE_TOOL_LIBRARIES} pthread )
endif()
endif()
target_include_directories(${PROJECT_NAME} INTERFACE .)
add_subdirectory(libdap)
add_subdirectory(libdap-server-core)
add_subdirectory(libdap-server)
add_subdirectory(libdap-chain)
add_subdirectory(libdap-stream)
add_subdirectory(libdap-stream-ch-vpn)
add_subdirectory(libdap-stream-ch-chain)
if(NOT ANDROID)
target_include_directories(${NODE_CLI_TARGET} INTERFACE .)
target_include_directories(${NODE_TOOL_TARGET} INTERFACE .)
endif()
if(DARWIN)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/ 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(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} )
#include_directories("${INCLUDE_DIRECTORIES} ${dap_core_INCLUDE_DIRS}")
#include_directories("${INCLUDE_DIRECTORIES} ${dap_http_INCLUDE_DIRS}")
#include_directories("${INCLUDE_DIRECTORIES} ${dap_crypto_INCLUDE_DIRS}")
#include_directories("${INCLUDE_DIRECTORIES} ${dap_enc_server_INCLUDE_DIRS}")
#include_directories("${INCLUDE_DIRECTORIES} ${dap_http_server_INCLUDE_DIRS}")
else()
#include_directories("${INCLUDE_DIRECTORIES} ${dap-chain_INCLUDE_DIRS}")
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*")
if(LINUX)
#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()
include_directories("${INCLUDE_DIRECTORIES} ${dap_core_server_INCLUDE_DIRS}")
#include_directories("${INCLUDE_DIRECTORIES} ${dap_udp_server_INCLUDE_DIRS}")
#include_directories("${INCLUDE_DIRECTORIES} ${dap_session_INCLUDE_DIRS}")
#include_directories("${INCLUDE_DIRECTORIES} ${dap_stream_INCLUDE_DIRS}")
#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} )
endif()
#add_definitions ("${dap_core_DEFINITIONS}")
#add_definitions ("${dap_crypto_DEFINITIONS}")
#add_definitions ("${dap_enc_server_DEFINITIONS}")
#add_definitions ("${dap_http_server_DEFINITIONS}")
#add_definitions ("${dap_http_DEFINITIONS}")
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()
#add_definitions ("${dap-chain_DEFINITIONS}")
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()
#add_definitions ("${dap_core_server_DEFINITIONS}")
#add_definitions ("${dap_udp_server_DEFINITIONS}")
#add_definitions ("${dap_session_DEFINITIONS}")
#add_definitions ("${dap_stream_DEFINITIONS}")
file(GLOB SERVER_SRCS *.c)
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(SOURCES sources/main.c )
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)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
add_executable(${PROJECT_NAME} "sources/main.c" "sources/sig_unix_handler.c"${HEADERS} ${SOURCES} ${SERVER_SRCS} )
endif()
endif()
target_link_libraries(${PROJECT_NAME} dap_core_server dap_http_server dap_udp_server dap_session dap_crypto dap_core dap_enc_server dap_stream dap_stream_ch_vpn dap_stream_ch_chain m pthread magic)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../dist/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*")
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin FILES_MATCHING PATTERN "*" PATTERN "*" PERMISSIONS OWNER_EXECUTE;OWNER_READ;OWNER_WRITE;WORLD_READ;GROUP_READ )
endif()
INCLUDE(CPack)
# kelvin-node
Kelvin Blockchain node
# cellframe-node
[Cellframe Node usage Wiki](https://wiki.cellframe.net/en/soft)
## This guide will work on Debian/Ubuntu
### Build from sources:
#### Linux Prerequsites
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):
* libsqlite3-dev
* libmagic-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 libz-dev libmagic-dev libsqlite3-dev traceroute debconf-utils xsltproc libpq-dev
```
#### MacOS Prerequsites
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 zlib
```
Generaly thats all what you need
#### Get all cellframe-node sources
This command fetch sources from gitlab and build them.
```
git clone https://gitlab.demlabs.net/cellframe/cellframe-node.git --recursive
```
#### Build cellframe using cmake framework
Get into directory with cellframe-node and execute the following commands
```
mkdir build
cd build
cmake ../
make -j$(nproc)
```
*-j$(nproc)* nrpoc parameter depends on your machine capacity - number of processor cores.
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 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:
```
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.2-0-Debian-21.10-amd64-impish-dbg.deb```
Please use ```dpkg``` command to install it:
```
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
```
sudo apt --fix-broken install
```
##### Install from DemLabs official public repository
* Create file /etc/apt/sources.list.d/demlabs.list with command ```sudo nano /etc/apt/sources.list.d/demlabs.list``` with one line below
* For Debian 11:
```
deb https://debian.pub.demlabs.net/public bullseye main
```
* For Debian 10:
```
deb https://debian.pub.demlabs.net/public buster main
```
* For Debian 9:
```
deb https://debian.pub.demlabs.net/public stretch main
```
* For Ubuntu 18 (Bionic):
```
deb https://debian.pub.demlabs.net/public bionic main
```
* Then download public signature and install it:
```
wget https://debian.pub.demlabs.net/public/public-key.gpg
sudo apt-key add public-key.gpg
```
* Then update your apt cache and install the package (apt-transport-https should be installed):
```
sudo apt-get update
sudo apt-get install cellframe-node
```
During installation it asks some questions
#### Debian package questions
All this could be changed after in configs
* Auto online
If true, the node goes online after he starts and then try to keep this state automatically
* Debug mode
If true - produce more log output in files. Suggested to set ```true``` until the testing period
* Debug stream headers
Dump stream headers in logs, set it ```true``` only if you want to get more debug information about stream packages passing through. Suggested ```false``` for almost everybody
* Accept connections
Enable/disable listening network address. Set ```false``` if you don't want to accept network connections to your node
* Server address
Network address used for listentning. Set ```0.0.0.0``` if you want to listen all network interfaces on your computer
* 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.
* Subzero: Enable network
Set ```true``` if you want to connect your node with ```Subzero``` (testnet)
* Mileena: Node type (role)
Select node type (or node role) from suggested list with short descriptions. By default suggested to select ```full``` (testnet)
* Minkowski: Enable network
Set ```true``` if you want to connect your node with ```Minkowski``` (KelVPN testnet)
* Bacbone: Enable network
Set ```true``` if you want to connect your node with ```Backbone``` (Mainnet)
### 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:
```
# VPN stream channel processing module
[srv_vpn]
# Turn to true if you want to share VPN service from you node
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
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.
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
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
Install DNS server, it could be any other than Bind9 but for example we will use exactly thats one - did we test this with any other? at a least a couple of others?
```sudo apt-get install bind9```
#### Switch on IPv4 forwarding
Open ```/etc/sysctl.conf``` with command ```sudo nano /etc/sysctl.conf``` and find line
```
# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1
```
Uncomment ```net.ipv4.ip_forward=1``` as the comment above suggests. Then after you've changed them and saved changes, implement them with:
```
sudo sysctl -p
```
Then after reboot they will be implemented automatically - do we need to specify a reboot command?
#### Configuring firewall with NAT
Easiest way is to install ```arno-iptables-firewall``` with the next command:
```
sudo apt-get install arno-iptables-firewall
```
It would ask next questions:
* `Do you want to manage the firewall setup with debconf` answer `Yes`
* `External network interfaces` answer with you network interface thats used for internet access. Usually its `eth0` or `wifi0` but could be different, examine you network configuration first.
* `Open external TCP-ports` answer `8079` or what the port do you configured for cellframe node when it was installed
* `Open external UDP-ports:` answer same as in previous
* `Internal network interfaces` answer `tun0` if you haven't configured any other VPN servers. If they are - find what the tunnel number is biggest and list all of them here with your tunnel name (`tun<max number plus 1>` )
* `Internal subnets ` here should be network_adddres/network_mask from VPN service configuration, ```10.11.12.0/255.255.255.0``` in our example
* `Should be restarted` answer `No` becase we need some more configs
Now lets increase config ask level and reconfigure the package with the next command:
```
sudo dpkg-reconfigure -plow arno-iptables-firewall
```
For answers where you'll see right answers just press enter to skip them. Then the next questions should appears:
* `Is DHCP used on external interfaces? ` usually answer `Yes`, answer `No` only if you have static network configuration for external connections
* `Should the machine be pingable from the outside world?` answer `Yes` because we use pings for network speed measurements
* `Do you want to enable NAT? ` answer `Yes`
* `Internal networks with access to external networks:` here you list internal networks again, ```10.11.12.0/255.255.255.0``` in our example
* `Should the firewall be (re)started now?` now answer `Yes` and have everything ready for routing
### How to run
If the node is installed in your system you need only to check it if its runned on your system
```
sudo service cellframe-node status
```
And if its not runned - start it. Start after reboot should be automaticaly executed.
```
sudo service cellframe-node start
```
To stop it use the next command:
```
sudo service cellframe-node stop
```
### How to publish service in network
#### Obtain node address
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 minkowski get status
```
It should print smth like this
```
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 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`
#### Create order for VPN service
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 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 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 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.
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 SEC for Seconds
* ```-price_token``` Token ticker
* ```-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```
# SubZero testnet
## Create wallet and token request
1. Install node according instructions above.
2. Create wallet
```
cellframe-node-cli wallet new -w subzero_wallet
Wallet 'subzero_wallet' (type=sig_dil) successfully created
```
3. Get wallet address:
```
cellframe-node-cli wallet info -w subzero_wallet -net subzero
addr: mJUUJk6Yk2gBSTjcDHXxAerggncSK7DP8ZViVG2zrtbuW6uiCtTvXXn9kdcoBadGeBiujC7VsfemGv5BLbq2zcxoCR8GVRKfCmLtaedd
network: subzero
balance: 0
```
4. Send wallet address and request for tCELL amount of money to telegram channel: t.me/cellframe_dev_en
5. Waiting for answer from admin and execute command for network chains and gdb syncronization:
```cellframe-node-cli net sync all -net subzero```
6. See wallet balance:
```
cellframe-node-cli wallet info -w subzero_wallet -net subzero
wallet: subzero_wallet
addr: mJUUJk6Yk2gBSTjcDHXxAerggncSK7DP8ZViVG2zrtbuW6uiCtTvXXn9kdcoBadGeBiujC7VsfemGv5BLbq2zcxoCR8GVRKfCmLtaedd
network: subzero
balance:
5500000.000000000 (5500000000000000) tCELL
```
## Balance replenishment
If you want increase amount of tCell on your wallet, you can wrote about it to SubZero admin.
## Tokens transfer
1. You can transfer tokens from your wallet to other wallet. For doing this you need to know address of 2nd wallet. Execute command
```
cellframe-node-cli tx_create -net subzero -chain support -from_wallet subzero_wallet -to_addr rTDbDdeStfpodpLUevvYaxJBh2k739fjwusqtmAU72VoUCm88ERPw555jHXtrkoEGJfYEZ7Mmwssc3ajijG9eEqEZxV2FmZvYcvnAVZz -value 32100000
transfer=Ok
tx_hash=0x4E6D540F86CD46CBFA551F219A04BA2248FF474BB795EB5B2C524299458AD709
```
- to_addr - address of 2nd wallet (you can see it using command ```cellframe-node-cli wallet info -w <wallet_name> -net subzero ```)
- value - amount of tokens
2. Execute command for database syncing
```cellframe-node-cli net sync all -net subzero```
3. Waiting for a while root node have processed you request
4. Don't create more then one request on balance changing, until you get confirmation about processing current request. That requests will not be processed (it can be fixed in future)
and see your updated balance
```cellframe-node-cli wallet info -w subzero_wallet -net subzero```
# Node notes
1. Token declaration operations, executing on node client (token_decl command) will be approved manually.
2. Token emission operations (token_emit command) will be processing automatically only for token owners.
3. Transactions (tx_create command) will be automatically processing as usual.
#### Remove cellframe-node
In order to remove cellframe-node, use the following command
```
sudo apt-get remove cellframe-node
```
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;
};