From 72321f7659412b5eab817ac1398c8053510ee981 Mon Sep 17 00:00:00 2001 From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net> Date: Thu, 12 Mar 2020 18:57:17 +0700 Subject: [PATCH] [*] Big fat update --- CMakeLists.txt | 35 ++++--- cellframe-sdk | 2 +- cellframe-sdk-python/libdap-crypto-python | 2 +- dists/examples/1.Authority/MyAuth.py | 36 +++++++ dists/examples/1.Authority/MyAuthCA.py | 49 ++++++++++ dists/examples/1.Authority/MyAuthCli.py | 9 ++ dists/examples/1.Authority/MyAuthCmd.py | 17 ++++ dists/examples/1.Authority/MyAuthConf.py | 95 +++++++++++++++++++ dists/examples/1.Authority/MyChainsCli.py | 7 -- .../{MyChains.py => var/lib/ca/.keep-it} | 0 .../lib/wallet/.keep-it} | 0 dists/examples/1.Authority/var/log/.keep-it | 0 dists/examples/3.Stock/MyStockInitCA.py | 12 +-- setup.py | 2 +- src/python-cellframe.c | 50 ++++++++-- 15 files changed, 279 insertions(+), 37 deletions(-) create mode 100755 dists/examples/1.Authority/MyAuth.py create mode 100755 dists/examples/1.Authority/MyAuthCA.py create mode 100755 dists/examples/1.Authority/MyAuthCli.py create mode 100644 dists/examples/1.Authority/MyAuthCmd.py create mode 100644 dists/examples/1.Authority/MyAuthConf.py delete mode 100644 dists/examples/1.Authority/MyChainsCli.py rename dists/examples/1.Authority/{MyChains.py => var/lib/ca/.keep-it} (100%) rename dists/examples/1.Authority/{MyChainsConf.py => var/lib/wallet/.keep-it} (100%) create mode 100644 dists/examples/1.Authority/var/log/.keep-it diff --git a/CMakeLists.txt b/CMakeLists.txt index c1e2be15..c881ea87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,23 +10,30 @@ SET( CPACK_GENERATOR "DEB") SET( CPACK_PACKAGE_NAME "${PROJECT_NAME}") SET( CPACK_PACKAGE_VERSION_MAJOR 0) SET( CPACK_PACKAGE_VERSION_MINOR 9) -SET( CPACK_PACKAGE_VERSION_PATCH 9) +SET( CPACK_PACKAGE_VERSION_PATCH 10) add_definitions("-DDAP_VERSION_MAJOR=\"${CPACK_PACKAGE_VERSION_MAJOR}\"") add_definitions("-DDAP_VERSION_MINOR=\"${CPACK_PACKAGE_VERSION_MINOR}\"") add_definitions("-DDAP_VERSION_PATCH=\"${CPACK_PACKAGE_VERSION_PATCH}\"") add_definitions("-DDAP_VERSION=\"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-${CPACK_PACKAGE_VERSION_PATCH}\"") +if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (DAP_DEBUG)) + message("Debug build") + SET(DAP_DEBUG ON) +else() + message("Release build") + SET(DAP_RELEASE ON) +endif() + if(UNIX) add_definitions ("-DDAP_OS_LINUX -DDAP_OS_UNIX") # add_definitions ("-DDAP_LOG_MT") - if(DAP_RELEASE) - set(_CCOPT " -Wall -O3 -fPIC -fno-ident -ffast-math -ftree-vectorize -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all -std=gnu11 -") + if(DAP_DEBUG) + set(_CCOPT "-Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -pg -g3 -ggdb -fno-eliminate-unused-debug-symbols") + set(_LOPT "-pg") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg") else() - set(_CCOPT "-Wall -pg -g3 -ggdb -fno-eliminate-unused-debug-symbols") - set(_LOPT "-pg") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg") + set(_CCOPT "-DDAP_DEBUG -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fPIC -fno-ident -ffast-math -ftree-vectorize -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all -std=gnu11") endif() if (ANDROID) @@ -63,15 +70,17 @@ if(WIN32) add_definitions("-DHAVE_STRNDUP") add_compile_definitions(WINVER=0x0600 _WIN32_WINNT=0x0600) - if(DAP_RELEASE) - set(_CCOPT "-static -std=gnu11 -Wall -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,-- -gc-sections -Wl,--strip-all") + if(DAP_DEBUG) + set(_CCOPT "-mconsole -static -Wall -std=gnu11 -Wextra -Wno-unused-function -Wno-implicit-fallthrough -Wno-un + used-variable -Wno-unused-parameter -Wno-unused-but-set-variable -g3 -ggdb -fno-eliminate-unused-debug-symbols -pg") + set(_LOPT "-mconsole -static -pg") else() - set(_CCOPT "-mconsole -static -Wall -pg") - set(_LOPT "-mconsole -static -pg") + set(_CCOPT "-static -std=gnu11 -Wall -Wextra -Wno-unused-function -Wno-implicit-fallthrough -Wno-un + used-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,-- + gc-sections -Wl,--strip-all") endif() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT} ") set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${_LOPT}") include_directories(libdap/src/win32/) diff --git a/cellframe-sdk b/cellframe-sdk index 8f37970b..7673a49a 160000 --- a/cellframe-sdk +++ b/cellframe-sdk @@ -1 +1 @@ -Subproject commit 8f37970bc2e5f1ff41d8e8d866ec009c614f83d2 +Subproject commit 7673a49aa07982dbdb148412eca5f4603e23658c diff --git a/cellframe-sdk-python/libdap-crypto-python b/cellframe-sdk-python/libdap-crypto-python index 6e835a3a..bc4970d5 160000 --- a/cellframe-sdk-python/libdap-crypto-python +++ b/cellframe-sdk-python/libdap-crypto-python @@ -1 +1 @@ -Subproject commit 6e835a3a748734b7e4fe0219d594f3bc9901b627 +Subproject commit bc4970d5d7d498bdf521d82e63585badc54fdca5 diff --git a/dists/examples/1.Authority/MyAuth.py b/dists/examples/1.Authority/MyAuth.py new file mode 100755 index 00000000..0c985df4 --- /dev/null +++ b/dists/examples/1.Authority/MyAuth.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 +# CellFrame SDK.Python v0.9 Example Application #1 +from CellFrame.libCellFrame import * +import os +import json +import sys +import MyAuthConf +import MyAuthCmd +app_name = "MyAuth" + +jsonCfg=MyAuthConf.getJsonString(app_name) +try: + init( jsonCfg ) +except json.decoder.JSONDecodeError as jex: + sys.stderr.write("load_json_config JSONdecode :%s" % jex) + exit(-1) + +setLogLevel(DEBUG) + +server_host_name = configGetItem("server", "listen_address") +server_port = int(configGetItem("server", "listen_port_tcp")) +sr = ServerCore.listen(server_host_name, server_port, 0) +Http.new(sr, app_name) +EncHttp.addProc(sr, "/enc_http") +Stream.addProcHttp(sr, "/stream") +StreamCtl.addProcHttp(sr, "/stream_ctl") + +ev = Events() +ev.start() + +MyAuthCmd.init() + +print(app_name+" v0.1 runned on port "+str(server_port)) + +rc = ServerCore.loop(sr) +deinit() diff --git a/dists/examples/1.Authority/MyAuthCA.py b/dists/examples/1.Authority/MyAuthCA.py new file mode 100755 index 00000000..7e2fcb43 --- /dev/null +++ b/dists/examples/1.Authority/MyAuthCA.py @@ -0,0 +1,49 @@ +#!/usr/bin/python3 +from CellFrame.libCellFrame import * +from string import Template +import os +import sys +import MyAuthConf + +tmp_dir = os.getcwd() + "/tmp" +var_dir = os.getcwd() + "/var" +app_name = "MyAuth" + +jsonCfg=MyAuthConf.getJsonString(app_name,"CRITICAL") +try: + init( jsonCfg ) +except json.decoder.JSONDecodeError as jex: + sys.stderr.write("load_json_config JSONdecode :%s" % jex) + exit(-1) + +counter=0 + +action = "help" +cmd_name = "" +action_arg = {} +for arg in sys.argv: + counter+=1 + if counter == 1: + cmd_name = arg + if counter == 2: + if arg == "init_root_ca": + print( "Init CA for root nodes selected" ) + action = "init_root_ca" + elif counter == 3: + if arg == "create_ca": + print( "Create custom CA action selected" ) + action="create_ca" + elif counter >= 4: + action_arg[counter-3]=arg + +if action == "help": + print("CA managment script usage: ") + print("") + print("To get this help") + print("\t"+cmd_name+" [help]") + print("") + print("Generate <Root nodes number> certificates (5 by default) for selected <Algorythm> (\"sig_dil\" by default)") + print("\t"+cmd_name+" init_root_ca [<Root nodes number>] [<Algorythm>]") + print("") +elif action =="init_root_ca": + Crypto. diff --git a/dists/examples/1.Authority/MyAuthCli.py b/dists/examples/1.Authority/MyAuthCli.py new file mode 100755 index 00000000..d2b5b6e6 --- /dev/null +++ b/dists/examples/1.Authority/MyAuthCli.py @@ -0,0 +1,9 @@ +#!/usr/bin/python3 +import sys +import os +from CellFrame.libCellFrame import AppCli + +app_name="MyAuth" +tmp_dir = os.getcwd() + "/tmp" +var_dir = os.getcwd() + "/var" +sys.exit( AppCli.main(app_name,tmp_dir+"/node_cli", sys.argv )) diff --git a/dists/examples/1.Authority/MyAuthCmd.py b/dists/examples/1.Authority/MyAuthCmd.py new file mode 100644 index 00000000..96a0c661 --- /dev/null +++ b/dists/examples/1.Authority/MyAuthCmd.py @@ -0,0 +1,17 @@ +from CellFrame.libCellFrame import * + +def cmdUser(*argv): + reply="user managment command:\n" + for arg in argv: + reply+=" arg"+str(arg)+"=\""+arg+"\"\n" + setReplyText(reply) + +def init(): + AppCliServer.cmdItemCreate("user",cmdUser,"User managment command",""" +Print user list + user list + +Create user + user create -u <user name> -p <password> + """) + logItNotice("Initalized custom command set") diff --git a/dists/examples/1.Authority/MyAuthConf.py b/dists/examples/1.Authority/MyAuthConf.py new file mode 100644 index 00000000..d48340b1 --- /dev/null +++ b/dists/examples/1.Authority/MyAuthConf.py @@ -0,0 +1,95 @@ +import os +from string import Template + +def getJsonString(app_name, log_level="DEBUG"): + tmp_dir = os.getcwd() + "/tmp" + var_dir = os.getcwd() + "/var" + + ret_tpl = Template(""" + { + "modules": [ + "Crypto", "ServerCore", "Http", + "HttpFolder","GlobalDB","Client","HttpClientSimple","Mempool", + "Chain", "Wallet", "ChainCSDag", "ChainCSDagPoa", "ChainCSDagPos", "GDB", "Net", "AppCliServer", + "ChainNetSrv", "EncHttp","Stream", "StreamCtl", "HttpSimple", "StreamChChain", "StreamChChainNet", + "StreamChChainNetSrv" ], + "Core": { + "config_dir": "${tmp_dir}", + "log_level": "${log_level}", + "application_name": "${app_name}", + "file_name_log": "${var_dir}/log/${app_name}.log" + }, + "Stream" : { + "DebugDumpStreamHeaders": false + }, + "ServerCore" : { + "thread_cnt": 0, + "conn": 0 + }, + "Configuration" : { + "server": { + "enabled": true, + "listen_address": "0.0.0.0", + "listen_port_tcp": 8079 + }, + "conserver": { + "enabled": true, + "listen_unix_socket_path": "${tmp_dir}/node_cli" + }, + "resources": { + "threads_cnt": 0, + "pid_path": "${var_dir}/run/${app_name}.pid", + "log_file": "${var_dir}/log/${app_name}.log", + "wallets_path": "${var_dir}/lib/wallet", + "ca_folders": [ "${var_dir}/lib/ca" ], + "dap_global_db_path": "${var_dir}/lib/global_db", + "dap_global_db_driver": "cdb" + }, + "networks":{ + "${net_name}": { + "general":{ + "id": "0xFF00000000000003", + "name": "${net_name}", + "node-role": "root", + "gdb_groups_prefix": "${net_name}" + }, + "name_cfg_files": ["main"], + "conf_files":{ + "main": { + "general": { + "id": "0xF00000000000000F", + "name": "main", + "consensus": "dag-poa", + "datum_types": ["ca", "transaction","token","token_update","emission","shard"] + }, + "dag":{ + "is_single_line": false, + "is_celled": true, + "is_add_directly": true, + "datum_and_hash_count": 3 + }, + "dag-poa":{ + "auth_certs_prefix": "${net_name}.root", + "auth_certs_number": 5, + "auth_certs_number_verify":1, + "auth_certs_dir": "${var_dir}/lib/ca" + }, + "files":{ + "storage_dir":"{$var_dir}/lib/network/${net_name}/main" + } + } + } + } + } + } + }""" + ) + tpl_vars={ + "var_dir":var_dir, + "tmp_dir":tmp_dir, + "app_name":app_name, + "net_name": str.lower(app_name)+"-dev", + "log_level":log_level + + } + return ret_tpl.substitute(tpl_vars) diff --git a/dists/examples/1.Authority/MyChainsCli.py b/dists/examples/1.Authority/MyChainsCli.py deleted file mode 100644 index ca82cffe..00000000 --- a/dists/examples/1.Authority/MyChainsCli.py +++ /dev/null @@ -1,7 +0,0 @@ -import sys -import CellFrame.AppCli - -app_name=’MyChains’ -tmp_dir = os.getcwd() + "/tmp" -var_dir = os.getcwd() + "/var" -sys.exit( AppCli.main(app_name,tmp_dir+’/node_cli’, sys.argv )) diff --git a/dists/examples/1.Authority/MyChains.py b/dists/examples/1.Authority/var/lib/ca/.keep-it similarity index 100% rename from dists/examples/1.Authority/MyChains.py rename to dists/examples/1.Authority/var/lib/ca/.keep-it diff --git a/dists/examples/1.Authority/MyChainsConf.py b/dists/examples/1.Authority/var/lib/wallet/.keep-it similarity index 100% rename from dists/examples/1.Authority/MyChainsConf.py rename to dists/examples/1.Authority/var/lib/wallet/.keep-it diff --git a/dists/examples/1.Authority/var/log/.keep-it b/dists/examples/1.Authority/var/log/.keep-it new file mode 100644 index 00000000..e69de29b diff --git a/dists/examples/3.Stock/MyStockInitCA.py b/dists/examples/3.Stock/MyStockInitCA.py index a31aba23..af59ff02 100755 --- a/dists/examples/3.Stock/MyStockInitCA.py +++ b/dists/examples/3.Stock/MyStockInitCA.py @@ -10,17 +10,17 @@ app_name = "MyStock" init_json_string = Template("""{ "modules": ["Core","Crypto"], "Core": { - "config_dir": "${tmpdir}", - "log_level": "L_CRITICAL", - "application_name": "${appname}" + "config_dir": "${tmp_dir}", + "log_level": "L_DEBUG", + "application_name": "${app_name}" } } """) tpl_vars={ - "vardir":var_dir, - "tmpdir":tmp_dir, - "appname":app_name + "var_dir":var_dir, + "tmp_dir":tmp_dir, + "app_name":app_name } print("begin") diff --git a/setup.py b/setup.py index 2c758e21..71ae850f 100755 --- a/setup.py +++ b/setup.py @@ -69,7 +69,7 @@ class CMakeBuild(build_ext): setup( name="CellFrame", - version="0.9-post9", + version="0.9-post10", description="CellFrame SDK", author='Demlabs (2007-2020)', license="GNU GPLv3", diff --git a/src/python-cellframe.c b/src/python-cellframe.c index 9d3c390f..875636a2 100644 --- a/src/python-cellframe.c +++ b/src/python-cellframe.c @@ -34,6 +34,7 @@ PyObject *python_cellframe_init(PyObject *self, PyObject *args){ s_init_ks = true; if (!PyArg_ParseTuple(args, "s", &JSON_str)){ + PyErr_SetString(CellFrame_error, "ERROR in function call signature: can't get one String argument"); return NULL; } @@ -42,16 +43,24 @@ PyObject *python_cellframe_init(PyObject *self, PyObject *args){ PyErr_SetString(CellFrame_error, "ERROR importing module"); return NULL; } + PyObject* JSONLoadsFunction = PyObject_GetAttrString(JSON_Module, "loads"); - if (JSONLoadsFunction == NULL) + if (JSONLoadsFunction == NULL) { + PyErr_SetString(CellFrame_error, "Can't find \"loads\" section"); return NULL; + } + PyObject* argsInLoadsJSON = PyTuple_Pack(1,PyUnicode_FromString(JSON_str)); PyObject* result = PyObject_CallObject(JSONLoadsFunction, argsInLoadsJSON); - if (result == NULL) + if (result == NULL){ + PyErr_SetString(CellFrame_error, "ERROR in JSONLoadsFunction"); return NULL; + } PyObject* getModules = PyDict_GetItemString(result, "modules"); - if (getModules == NULL) + if (getModules == NULL){ + PyErr_SetString(CellFrame_error, "Can't find \"modules\" section"); return NULL; + } // DAP or Core PyObject* getDap = PyDict_GetItemString(result, "DAP"); @@ -59,8 +68,10 @@ PyObject *python_cellframe_init(PyObject *self, PyObject *args){ if (getDap == NULL) getDap = PyDict_GetItemString(result, "Core"); - if( getDap == NULL ) + if( getDap == NULL ){ + PyErr_SetString(CellFrame_error, "Can't find \"Core\" or \"DAP\" section"); return NULL; + } /*Parse DAP*/ PyObject* config_dir_PyObject = PyDict_GetItemString(getDap, "config_dir"); @@ -68,8 +79,10 @@ PyObject *python_cellframe_init(PyObject *self, PyObject *args){ PyObject* file_name_log_PyObject = PyDict_GetItemString(getDap, "file_name_log"); PyObject* logLevel_PyObject = PyDict_GetItemString(getDap, "log_level"); if (config_dir_PyObject == NULL || application_name_PyObject == NULL || - logLevel_PyObject == NULL || file_name_log_PyObject == NULL) + logLevel_PyObject == NULL || file_name_log_PyObject == NULL){ + PyErr_SetString(CellFrame_error, "config_dir or application_name or file_name_log or log_level"); return NULL; + } app_name = PyUnicode_AsUTF8(application_name_PyObject); file_name_log = PyUnicode_AsUTF8(file_name_log_PyObject); config_dir = PyUnicode_AsUTF8(config_dir_PyObject); @@ -80,6 +93,25 @@ PyObject *python_cellframe_init(PyObject *self, PyObject *args){ return NULL; } dap_set_appname(app_name); + if ( dap_strcmp( log_level, "L_DEBUG" )==0 || dap_strcmp( log_level, "DEBUG" )==0 ){ + dap_log_level_set(L_DEBUG); + }else if ( dap_strcmp( log_level, "L_INFO" )==0 || dap_strcmp( log_level, "INFO" )==0 ){ + dap_log_level_set(L_INFO); + }else if ( dap_strcmp( log_level, "L_NOTICE" )==0 || dap_strcmp( log_level, "NOTICE" )==0 ){ + dap_log_level_set(L_NOTICE); + }else if ( dap_strcmp( log_level, "L_MSG" )==0 || dap_strcmp( log_level, "MSG" )==0 ){ + dap_log_level_set(L_MSG); + }else if ( dap_strcmp( log_level, "L_DAP" )==0 || dap_strcmp( log_level, "DAP" )==0 ){ + dap_log_level_set(L_DAP); + }else if ( dap_strcmp( log_level, "L_WARNING" )==0 || dap_strcmp( log_level, "WARNING" )==0 ){ + dap_log_level_set(L_WARNING); + }else if ( dap_strcmp( log_level, "L_ATT" )==0 || dap_strcmp( log_level, "ATTENTION" )==0 ){ + dap_log_level_set(L_ATT); + }else if ( dap_strcmp( log_level, "ERROR" )==0 || dap_strcmp( log_level, "ERROR" )==0 ){ + dap_log_level_set(L_ERROR); + }else if ( dap_strcmp( log_level, "L_CRITICAL" )==0 || dap_strcmp( log_level, "CRITICAL" )==0 ){ + dap_log_level_set(L_CRITICAL); + } //generation config files PyObject *configure = PyDict_GetItemString(result, "Configuration"); int res_gen_config_file = gen_config_files(config_dir, app_name, configure); @@ -115,6 +147,7 @@ PyObject *python_cellframe_init(PyObject *self, PyObject *args){ PyErr_SetString(CellFrame_error, "An error occurred while initializing the libdap-crypto-python module."); return NULL; } + dap_cert_init(); }else if (strcmp(c_value, "ServerCore") == 0){ PyObject* getServerCoreData = PyDict_GetItemString(result, "ServerCore"); if (getServerCoreData == NULL){ @@ -281,9 +314,9 @@ PyObject *python_cellframe_init(PyObject *self, PyObject *args){ PyErr_SetString(CellFrame_error, "Failed to initialize AppCliServer " ); return NULL; } - }else - return NULL; - + }else{ + log_it(L_WARNING,"Unknown module \"%s\"", c_value); + } // if (strcmp(c_value, "ENC") == 0){ // if (dap_enc_init()) @@ -362,6 +395,7 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){ PyModule_AddObject(module, "CRITICAL", PyLong_FromLong(L_CRITICAL)); PyModule_AddObject(module, "Crypto", (PyObject*)&dapCrypto_dapCryptoType); + PyModule_AddObject(module, "CryptoCert", (PyObject*)&dapCrypto_dapCryptoCertType); PyModule_AddObject(module, "ServerCore", (PyObject*)&ServerCore_ServerCoreType); PyModule_AddObject(module, "Events", (PyObject*)&dapEvents_dapEventsType); -- GitLab