diff --git a/CMakeLists.txt b/CMakeLists.txt index 6250dae17b530dec09627d88d0355b56957f15dd..fd8b26188261b4b12c44aac8f83cda9f832b3b62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 2.8) + if (SUPPORT_PYTHON_PLUGINS) project(API_CellFrame C) else() @@ -9,15 +10,16 @@ set(CMAKE_COLOR_MAKEFILE ON) set(CMAKE_C_STANDARD 11) -set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4) +set(Python_ADDITIONAL_VERSIONS 3.9 3.8 3.7 3.6 3.5 3.4) find_package (PythonLibs REQUIRED) include_directories(${PYTHON_INCLUDE_DIR} include/) -file(GLOB PYTHON_CELLFRAME_SRCS src/*.c) +file(GLOB PYTHON_CELLFRAME_SRCS CellFrame/*.c) file(GLOB PYTHON_CELLFRAME_HEADERS include/*.h) set(SUBMODULES_NO_BUILD ON) if (NOT (SUPPORT_PYTHON_PLUGINS)) + include(cellframe-sdk/cmake/OS_Detection.cmake) add_subdirectory(cellframe-sdk) endif() @@ -40,7 +42,9 @@ target_compile_options(dap_stream_ch_chain_net PRIVATE "-fpic" ) target_compile_options(dap_stream_ch_chain PRIVATE "-fpic" ) target_compile_options(dap_udp_server PRIVATE "-fpic" ) target_compile_options(dap_chain_net_srv PRIVATE "-fpic" ) -target_compile_options(dap_chain_net_srv_vpn PRIVATE "-fpic" ) +if(NOT WIN32) + target_compile_options(dap_chain_net_srv_vpn PRIVATE "-fpic" ) +endif() target_compile_options(dap_chain_gdb PRIVATE "-fpic" ) target_compile_options(dap_enc_server PRIVATE "-fpic") target_compile_options(dap_http_server PRIVATE "-fpic") @@ -64,7 +68,7 @@ else() SET( CPACK_PACKAGE_NAME "${PROJECT_NAME}") SET( CPACK_PACKAGE_VERSION_MAJOR 0) SET( CPACK_PACKAGE_VERSION_MINOR 9) - SET( CPACK_PACKAGE_VERSION_PATCH 12) + SET( CPACK_PACKAGE_VERSION_PATCH 14) add_definitions("-DDAP_VERSION_MAJOR=\"${CPACK_PACKAGE_VERSION_MAJOR}\"") add_definitions("-DDAP_VERSION_MINOR=\"${CPACK_PACKAGE_VERSION_MINOR}\"") @@ -101,8 +105,8 @@ else() #python_extension_module(${PROJECT_NAME} LINKED_MODULES_VAR dap_crypto_python_module) #python_extension_module(${PROJECT_NAME} LINKED_MODULES_VAR DapServerCore) install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${PROJECT_NAME}) - install(FILES src/__init__.py DESTINATION ${PROJECT_NAME}) - install(FILES src/PublicNetworks/* DESTINATION ${PROJECT_NAME}) + install(FILES CellFrame/__init__.py DESTINATION ${PROJECT_NAME}) + install(FILES CellFrame/PublicNetworks/* DESTINATION ${PROJECT_NAME}) # install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libdap-python/libdap_python_module.so DESTINATION CellFrame/lib) # install(TARGETS dap_python_module LIBRARY DESTINATION CellFrame) # install(TARGETS dap_crypto_python_module LIBRARY DESTINATION CellFrame) @@ -132,7 +136,9 @@ target_compile_options(dap_stream_ch_chain_net PRIVATE "-fpic" ) target_compile_options(dap_stream_ch_chain PRIVATE "-fpic" ) target_compile_options(dap_udp_server PRIVATE "-fpic" ) target_compile_options(dap_chain_net_srv PRIVATE "-fpic" ) +if (NOT WIN32) target_compile_options(dap_chain_net_srv_vpn PRIVATE "-fpic" ) +endif() target_compile_options(dap_chain_gdb PRIVATE "-fpic" ) target_compile_options(dap_enc_server PRIVATE "-fpic") target_compile_options(dap_http_server PRIVATE "-fpic") @@ -143,6 +149,9 @@ target_compile_options(dap_chain_cs_dag_poa PRIVATE "-fpic") target_compile_options(dap_chain_cs_dag_pos PRIVATE "-fpic") +if (WIN32) + set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".pyd") +endif() target_link_libraries(${PROJECT_NAME} cellframe-sdk dap_python_module diff --git a/CellFrame b/CellFrame deleted file mode 120000 index 945c9b46d684f08ec84cb316e1dc0061e361f794..0000000000000000000000000000000000000000 --- a/CellFrame +++ /dev/null @@ -1 +0,0 @@ -. \ No newline at end of file diff --git a/src/PublicNetworks/KelvinTestNet.py b/CellFrame/PublicNetworks/KelvinTestNet.py similarity index 98% rename from src/PublicNetworks/KelvinTestNet.py rename to CellFrame/PublicNetworks/KelvinTestNet.py index 5a134ba1ce4d8fbd4c4ded480fd7f4da75f2329d..f3f37380f318054a90e8a41f6881a3058eb180d3 100644 --- a/src/PublicNetworks/KelvinTestNet.py +++ b/CellFrame/PublicNetworks/KelvinTestNet.py @@ -67,7 +67,7 @@ def getJsonString(var_dir, dist_dir, node_role="full", poa_sign_cert=None,pos_si "dag-pos":{ "tokens_hold": ["KELT","KEL"], "tokens_hold_value": [1000000000,1000000000], - "confirmations_minumum": 3, + "confirmations_minumum": 1, } "files":{ "storage_dir":"{$var_dir}/lib/network/kelvin-testnet/pasma" diff --git a/CellFrame/__init__.py b/CellFrame/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e5a782db17e69d7e7c80a046df94c49f69b5fbe5 --- /dev/null +++ b/CellFrame/__init__.py @@ -0,0 +1 @@ +from .libCellFrame import * diff --git a/src/generator_config_file.c b/CellFrame/generator_config_file.c similarity index 100% rename from src/generator_config_file.c rename to CellFrame/generator_config_file.c diff --git a/src/python-cellframe.c b/CellFrame/python-cellframe.c similarity index 98% rename from src/python-cellframe.c rename to CellFrame/python-cellframe.c index e0ac0d024b534a96beef8a5f1e6e897ec37adef1..aee6558ade9b998bff056f3979c291626bc50e41 100644 --- a/src/python-cellframe.c +++ b/CellFrame/python-cellframe.c @@ -13,7 +13,7 @@ static bool s_init_http_enc = false; static bool s_init_server_core = false; static bool s_init_mempool = false; -static bool s_init_http_client_simple = false; +//static bool s_init_http_client_simple = false; static bool s_init_wallet = false; static bool s_init_cs_dag = false; static bool s_init_cs_dag_poa = false; @@ -263,12 +263,13 @@ PyObject *python_cellframe_init(PyObject *self, PyObject *args){ return NULL; } s_init_mempool = true; + /* } else if (strcmp(c_value, "HttpClientSimple") == 0){ -// if (dap_http_client_simple_init() != 0){ -// PyErr_SetString(CellFrame_error, "Failed to initialize HttpClientSimple module. "); -// return NULL; -// } -// s_init_http_client_simple = true; + if (dap_http_client_simple_init() != 0){ + PyErr_SetString(CellFrame_error, "Failed to initialize HttpClientSimple module. "); + return NULL; + } + s_init_http_client_simple = true;*/ } else if (strcmp(c_value, "Wallet") == 0){ if (dap_chain_wallet_init() != 0){ PyErr_SetString(CellFrame_error, "Failed to initialize Wallet module. "); diff --git a/src/wrapping_dap_enc_http.c b/CellFrame/wrapping_dap_enc_http.c similarity index 100% rename from src/wrapping_dap_enc_http.c rename to CellFrame/wrapping_dap_enc_http.c diff --git a/src/wrapping_dap_http_folder.c b/CellFrame/wrapping_dap_http_folder.c similarity index 100% rename from src/wrapping_dap_http_folder.c rename to CellFrame/wrapping_dap_http_folder.c diff --git a/src/wrapping_dap_mempool.c b/CellFrame/wrapping_dap_mempool.c similarity index 100% rename from src/wrapping_dap_mempool.c rename to CellFrame/wrapping_dap_mempool.c diff --git a/src/wrapping_dap_stream.c b/CellFrame/wrapping_dap_stream.c similarity index 100% rename from src/wrapping_dap_stream.c rename to CellFrame/wrapping_dap_stream.c diff --git a/src/wrapping_dap_stream_ctl.c b/CellFrame/wrapping_dap_stream_ctl.c similarity index 100% rename from src/wrapping_dap_stream_ctl.c rename to CellFrame/wrapping_dap_stream_ctl.c diff --git a/src/wrapping_http.c b/CellFrame/wrapping_http.c similarity index 100% rename from src/wrapping_http.c rename to CellFrame/wrapping_http.c diff --git a/README.md b/README.md index fb20862e54bd86b4fc13ed86fcad4209e59f0d58..d9db84fd2a87c496dadb14d3990f98d8f6d0a703 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,15 @@ # python-cellframe +## Prerequisites +To install, you must have Python3.7 including pip and a scikit-build. +sudo apt-get install pip3 +If there is a problem on Debian buster +"unknown system group 'Debian-exim' in statoverride file; the system group got removed" +Use the following command to fix it +dpkg-statoverride --remove /etc/exim4/passwd.client +Now repeat sudo apt-get install pip3 + ## Build and Run tests: -To install, you must have Python3.7 and a scikit-build. ``` git clone https://gitlab.demlabs.net/cellframe/python-cellframe.git cd python-cellframe @@ -28,9 +36,20 @@ sudo apt-get install libverto-dev sudo apt-get install lldb-7 sudo apt-get install libmemcached-dev sudo apt-get install libldb-dev -sudo apt-get install libtalloc-dev sudo apt-get install libtevent-dev sudo apt-get install libpython3-dev -sudo apt-get install traceroute -``` \ No newline at end of file +``` + + +## Windows Build +First of all you need to install msys2. It provides 3 shells. +To install dependencies, run from MSYS shell: +``` +pacman -S base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-file mingw-w64-x86_64-json-c mingw-w64-x86_64-python-pip +``` + +To start a build, run from MinGW 64bit shell (don't forget to change dir to python-cellframe repo): +``` +python setup.py install +``` diff --git a/dists/examples/0.Beginning/MyChains.py b/dists/examples/0.Beginning/MyChains.py index 116994098d86eed6a17d1165a39164ce1c5cf92e..4941f3f6dd31e629c0d8503e3a6b7ec2b5e100bc 100755 --- a/dists/examples/0.Beginning/MyChains.py +++ b/dists/examples/0.Beginning/MyChains.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 # CellFrame SDK.Python v0.9-4 Example Application #0 -from CellFrame.libCellFrame import * +from CellFrame import * import os app_name = "MyChains" @@ -33,7 +33,7 @@ json_string = """{ "server": { "enabled": true, "listen_address": "0.0.0.0", - "listen_port_tcp": 8079 + "listen_port_tcp": 8099 }, "conserver": { "enabled": true, diff --git a/dists/examples/0.Beginning/MyChainsCli.py b/dists/examples/0.Beginning/MyChainsCli.py index 40298a1ba49eb7663280ac6db8f86139e72eaa94..6ff17585aba61c27ee7b14718f340e404502c335 100755 --- a/dists/examples/0.Beginning/MyChainsCli.py +++ b/dists/examples/0.Beginning/MyChainsCli.py @@ -2,7 +2,7 @@ import sys import os -from CellFrame.libCellFrame import * +from CellFrame import * app_name="MyChains" tmp_dir = os.getcwd() + "/tmp" diff --git a/dists/examples/1.Authority/MyAuthCA.py b/dists/examples/1.Authority/MyAuthCA.py index a002cb445d2c6c65dd1b261e0446d9c3ca0067ab..97104a7a619c55746f7babfd0fb2967a34008430 100755 --- a/dists/examples/1.Authority/MyAuthCA.py +++ b/dists/examples/1.Authority/MyAuthCA.py @@ -1,33 +1,55 @@ #!/usr/bin/python3 -from CellFrame.libCellFrame import * +from CellFrame.libCellFrame import init, Cert,CryptoKeyType from string import Template import os import sys import MyAuthConf +import random +import string + +# ---- Vars ---- # App name appName = "MyAuth" # Generate config -jsonCfg=MyAuthConf.getJsonString(appName,"CRITICAL") +jsonCfg = MyAuthConf.getJsonString(appName, "CRITICAL") # Init SDK try: - init( jsonCfg ) + init(jsonCfg) except json.decoder.JSONDecodeError as jex: sys.stderr.write("load_json_config JSONdecode :%s" % jex) exit(-1) -# Prepare to parse input arguments -counter=0 + +def randomString(stringLength=10): + """Generate a random string of fixed length """ + letters = string.ascii_lowercase + return ''.join(random.choice(letters) for i in range(stringLength)) + +# Action Help +def help(): + print("CA managment script usage: ") + print("") + print("To get this help") + print("\t"+cmdName+" [help]") + print("") + print("Generate <Root nodes number> certificates (5 by default)" + + "for selected <Algorythm> (\"sig_dil\" by default)") + print("\t"+cmdName+" init_root_ca [<Root nodes number>] [<Algorythm>] [<Restore string>]") + print("") + + +counter = 0 action = "help" cmdName = "" action_arg = {} # Parse input arguments for arg in sys.argv: - counter+=1 + counter += 1 # Extract command name if counter == 1: cmdName = arg @@ -36,18 +58,8 @@ for arg in sys.argv: if counter == 2: action = arg elif counter > 2: - action_arg[counter-2]=arg + action_arg[counter-2] = arg # Process actions -# Action Help -def help(): - print("CA managment script usage: ") - print("") - print("To get this help") - print("\t"+cmdName+" [help]") - print("") - print("Generate <Root nodes number> certificates (5 by default) for selected <Algorythm> (\"sig_dil\" by default)") - print("\t"+cmdName+" init_root_ca [<Root nodes number>] [<Algorythm>]") - print("") if action == "help": help() # Action init root CAs @@ -55,26 +67,28 @@ elif action == "init_root_ca": # Default params rootCaNumber = 5 rootCaAlgoName = "sig_dil" + restoreString = randomString(12) # Set default algo Dilithium - rootCaAlgo = CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_DILITHIUM + rootCaAlgo = CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_DILITHIUM() # Read action args if len(action_arg) > 0: rootCaNumber = action_arg[1] if len(action_arg) > 1: rootCaAlgoName = action_arg[2] - + if len(action_arg) > 2: + restoreString = action_arg[3] # Parse algo name if rootCaAlgoName == "sig_bliss": - rootCaAlgo = CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_BLISS + rootCaAlgo = CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_BLISS() elif rootCaAlgoName == "sig_tesla": - rootCaAlgo = CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_TESLA + rootCaAlgo = CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_TESLA() elif rootCaAlgoName == "sig_picnic": - rootCaAlgo = CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_PICNIC + rootCaAlgo = CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_PICNIC() elif rootCaAlgoName == "sig_dil": - rootCaAlgo = CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_DILITHIUM + rootCaAlgo = CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_DILITHIUM() else: # Process error case print("(!) Wrong algo name \""+rootCaAlgoName+"\", possible names: sig_bliss, sig_tesla, sig_picnic, sig_dil") @@ -82,7 +96,11 @@ elif action == "init_root_ca": exit(-1) # Create certs - print("Init root "+str(rootCaNumber)+" certificates with algo "+rootCaAlgoName) + print("Init root "+str(rootCaNumber)+" certificates with algo " + + rootCaAlgoName) + print("Record somewhere the restore string(without braces): \"" + + restoreString+"\"") for cur in range(int(rootCaNumber)): - certName = MyAuthConf.getNetworkName(appName,"_") +"_root_"+str(cur) - cert=Cert.generate( certName, rootCaAlgo,"fasdfsdf" ) + cname = MyAuthConf.getNetworkName(appName, "_") + "_root_" + str(cur) + cert = Cert.generate(cname, rootCaAlgo, restoreString) + cert.save() diff --git a/dists/examples/1.Authority/MyAuthCli.py b/dists/examples/1.Authority/MyAuthCli.py index 1133efa5fe63117f95f96ce33629e73f47875f19..d2b5b6e6c611e5a3c6c34d3435bb84aa9628bf1d 100755 --- a/dists/examples/1.Authority/MyAuthCli.py +++ b/dists/examples/1.Authority/MyAuthCli.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 import sys import os -from CellFrame.libCelLFrame import AppCli +from CellFrame.libCellFrame import AppCli app_name="MyAuth" tmp_dir = os.getcwd() + "/tmp" diff --git a/dists/examples/1.Authority/MyAuthCmd.py b/dists/examples/1.Authority/MyAuthCmd.py index 96a0c661a41be79fbb67ce913ce9a784f89bff78..22496bd7cf193f263a60b04fb7d56a3d94e4cfcc 100644 --- a/dists/examples/1.Authority/MyAuthCmd.py +++ b/dists/examples/1.Authority/MyAuthCmd.py @@ -1,10 +1,10 @@ from CellFrame.libCellFrame import * -def cmdUser(*argv): +def cmdUser(argv, strReply): reply="user managment command:\n" for arg in argv: reply+=" arg"+str(arg)+"=\""+arg+"\"\n" - setReplyText(reply) + AppCliServer.setReplyText(reply, strReply) def init(): AppCliServer.cmdItemCreate("user",cmdUser,"User managment command",""" diff --git a/dists/examples/1.Authority/MyAuthConf.py b/dists/examples/1.Authority/MyAuthConf.py index 096f8333ca9ec6c84f8c5f2d7c5e71536c9d1212..17b321c5893b918857e29be59ff78f4d4dd71708 100644 --- a/dists/examples/1.Authority/MyAuthConf.py +++ b/dists/examples/1.Authority/MyAuthConf.py @@ -33,7 +33,7 @@ def getJsonString(app_name, log_level="DEBUG"): "server": { "enabled": true, "listen_address": "0.0.0.0", - "listen_port_tcp": 8079 + "listen_port_tcp": 8099 }, "conserver": { "enabled": true, diff --git a/setup.py b/setup.py index 11256e7633649c7cd0ced832ebee6a592b5b7a47..17d1deb153bf63d72e56e5d3cf9d00239a01fe5a 100755 --- a/setup.py +++ b/setup.py @@ -48,9 +48,10 @@ class CMakeBuild(build_ext): cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format( cfg.upper(), extdir)] - if sys.maxsize > 2**32: - cmake_args += ['-A', 'x64'] - build_args += ['--', '/m'] + cmake_args += ['-G', 'MinGW Makefiles'] + #if sys.maxsize > 2**32: + # cmake_args += ['-A', 'x64'] + #build_args += ['--', '/m'] else: cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] build_args += ['--', '-j4'] @@ -69,7 +70,7 @@ class CMakeBuild(build_ext): setup( name="CellFrame", - version="0.9-post12", + version="0.9-post14", description="CellFrame SDK", author='Demlabs (2007-2020)', license="GNU GPLv3", diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index a6c59c1ee14056d6af117801b941599d1657b064..0000000000000000000000000000000000000000 --- a/src/__init__.py +++ /dev/null @@ -1 +0,0 @@ -#from .libCellFrame import *