diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d70aec97a94165937137d16102c003b938a8bc17..a5944d65a40039fdfcba854db52f9d6807f54f60 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,4 +10,4 @@ kelvin-node-schedule: stage: build tags: - kelvin-node - script: ~/production/integration/gitlab-CI/build_all_handler.sh kelvin-node && ~/production/integration/gitlab-CI/travis_test.sh + script: ~/production/integration/gitlab-CI/build_all_handler.sh cellframe-node && ~/production/integration/gitlab-CI/travis_test.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ebfcf91310e9c7e7cc9d52f1b82efe24f1d4478..c2989c0a16373464b5f5338be99deab53b028075 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ project(cellframe-node C) cmake_minimum_required(VERSION 2.8) +set(DAP_RELEASE 1) if(WIN32) message(STATUS "Building for Windows") endif() @@ -73,7 +74,7 @@ if(WIN32) add_definitions ("-DCURL_STATICLIB") if(DAP_RELEASE) - set(_CCOPT "-mconsole -static -Wall -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all") + set(_CCOPT "-static -Wall -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all") else() set(_CCOPT "-mconsole -static -Wall -pg") set(_LOPT "-mconsole -static -pg") @@ -205,7 +206,7 @@ if(WIN32) Secur32 userenv ) - + set_property(TARGET ${PROJECT_NAME}-cli APPEND_STRING PROPERTY LINK_FLAGS "-mconsole") target_link_libraries(${PROJECT_NAME}-tool dap_core dap_crypto dap_server_core dap_enc_server dap_udp_server dap_session dap_enc_server dap_stream dap_stream_ch_vpn dap_stream_ch_chain dap_stream_ch_chain_net dap_stream_ch_chain_net_srv dap_chain dap_chain_crypto dap_client @@ -250,7 +251,7 @@ if(WIN32) Secur32 userenv ) - + set_property(TARGET ${PROJECT_NAME}-tool APPEND_STRING PROPERTY LINK_FLAGS "-mconsole") target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_server_core dap_enc_server dap_udp_server dap_session dap_enc_server dap_stream dap_stream_ch_vpn dap_stream_ch_chain dap_stream_ch_chain_net @@ -295,6 +296,7 @@ if(WIN32) Secur32 userenv ) + set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS "-mwindows") #dap_chain_net_srv_vpn dap_server_http_db_auth diff --git a/README.md b/README.md index 9b279c4888a018dbdbfa79cff29599f695912058..12de40b160f80be0577a6dd687463bb7f07abdc2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# kelvin-node -Kelvin Blockchain node +# cellframe-node +Cellframe Blockchain node [](https://travis-ci.com/osetrovich/kelvin-node-ci) -[Kelvin node manual](https://github.com/cellframe/kelvin-node/wiki/Kelvin-Node) +[Cellframe node manual](https://github.com/cellframe/kelvin-node/wiki/Kelvin-Node) ## Build diff --git a/libdap b/libdap index 6c79910e7f5a3b1c1bc19c5646076fe773e637f4..9a657b5c7671694bc15a21330c4288a62d5d13fe 160000 --- a/libdap +++ b/libdap @@ -1 +1 @@ -Subproject commit 6c79910e7f5a3b1c1bc19c5646076fe773e637f4 +Subproject commit 9a657b5c7671694bc15a21330c4288a62d5d13fe diff --git a/libdap-chain-global-db b/libdap-chain-global-db index 23bf6fd9ae12cdaa17fd4817227f565e88221806..badda74eb2f1cd74ab5728e23d4b4523fc0f5554 160000 --- a/libdap-chain-global-db +++ b/libdap-chain-global-db @@ -1 +1 @@ -Subproject commit 23bf6fd9ae12cdaa17fd4817227f565e88221806 +Subproject commit badda74eb2f1cd74ab5728e23d4b4523fc0f5554 diff --git a/libdap-crypto b/libdap-crypto index d2c567906d783f94e28ae2ca87acc875175da6a8..4d764dfacaaa6aa1d8e5ba3c8242d8466e4faf10 160000 --- a/libdap-crypto +++ b/libdap-crypto @@ -1 +1 @@ -Subproject commit d2c567906d783f94e28ae2ca87acc875175da6a8 +Subproject commit 4d764dfacaaa6aa1d8e5ba3c8242d8466e4faf10 diff --git a/sources/main.c b/sources/main.c index 7d82f879d53b50ec0a63b2aa0937501f2f640a5c..7644498dc60eaf6d9a13f1a6f9be76fa41e3a232 100644 --- a/sources/main.c +++ b/sources/main.c @@ -44,7 +44,7 @@ //#include "wrappers.h" #include <wepoll.h> #include <pthread.h> -#include "Userenv.h" +#include "userenv.h" #endif @@ -53,10 +53,9 @@ #ifndef _WIN32 #include "sig_unix_handler.h" #else - #include "sig_win32_handler.h" - - void S_SetExceptionFilter( void ); - + #include "sig_win32_handler.h" + #include "registry.h" + void S_SetExceptionFilter( void ); #endif #include "dap_config.h" @@ -105,6 +104,7 @@ #include "dap_traffic_track.h" #include "dap_defines.h" +#include "dap_file_utils.h" #define ENC_HTTP_URL "/enc_init" #define STREAM_CTL_URL "/stream_ctl" @@ -114,11 +114,14 @@ #define MEMPOOL_URL "/mempool" #define MAIN_URL "/" +#ifndef MAX_PATH +#define MAX_PATH 120 +#endif + void parse_args( int argc, const char **argv ); void exit_if_server_already_running( void ); -char *win_prefix = NULL, *l_pid_file_path = NULL; -uint32_t win_prefix_size = 0; +static char *s_pid_file_path = NULL; int main( int argc, const char **argv ) { @@ -131,76 +134,40 @@ int main( int argc, const char **argv ) S_SetExceptionFilter( ); #endif - char *l_log_file_path, - *l_sys_dir_path; - - char *l_path_buff = (char *)DAP_MALLOC( 2048 * 4 ); - if ( !l_path_buff ) - goto failure; - - win_prefix = l_path_buff; - l_log_file_path = l_path_buff + 2048; - l_sys_dir_path = l_path_buff + 2048 * 2; - l_pid_file_path = l_path_buff + 2048 * 3; - uint32_t path_len = 0; + { + char l_log_file_path[MAX_PATH], l_sys_dir_path[MAX_PATH], l_pid_file_path[MAX_PATH]; +#ifdef _WIN32 + dap_sprintf(l_sys_dir_path, "%s/%s", regGetUsrPath(), DAP_APP_NAME); + path_len = strlen(l_sys_dir_path); + memcpy(l_log_file_path, l_sys_dir_path, path_len); + memcpy(l_pid_file_path, l_log_file_path, path_len); +#endif + memcpy( l_log_file_path + path_len, SYSTEM_LOGS_DIR, sizeof(SYSTEM_LOGS_DIR) ); + dap_mkdir_with_parents( l_log_file_path ); - #ifdef _WIN32 - { - HKEY hKey; - win_prefix_size = 2048; - - LSTATUS lRes = RegOpenKeyExA( HKEY_CURRENT_USER, - "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", - 0, KEY_READ, &hKey ); - - lRes = RegQueryValueExA( hKey, "Personal", 0, NULL, (LPBYTE)&win_prefix[0], (DWORD*)&win_prefix_size ); - RegCloseKey( hKey ); - - if ( lRes != ERROR_SUCCESS ) { - memcpy( &win_prefix[0], "c:", 3 ); - win_prefix_size = 3; - } - - path_len = dap_sprintf( l_log_file_path, "%s/%s", win_prefix, DAP_APP_NAME ); - - memcpy( l_pid_file_path, l_log_file_path, path_len + 1 ); - memcpy( l_sys_dir_path, l_log_file_path, path_len + 1 ); - - path_len = dap_sprintf( l_pid_file_path, "%s/%s", win_prefix, DAP_APP_NAME ); - memcpy( l_sys_dir_path, l_pid_file_path, path_len + 1 ); - - } - #endif - - dap_sprintf( l_pid_file_path + win_prefix_size - 1, "/%s%s", DAP_APP_NAME, SYSTEM_PID_FILE_PATH ); - - memcpy( l_log_file_path + path_len, SYSTEM_LOGS_DIR, sizeof(SYSTEM_LOGS_DIR) ); - dap_mkdir_with_parents( l_log_file_path ); - - //#if !DAP_RELEASE - // dap_sprintf( l_log_file_path, "%s_logs.txt", DAP_APP_NAME ); - //#else - dap_sprintf( l_log_file_path + path_len + sizeof(SYSTEM_LOGS_DIR) - 1, "/%s_logs.txt", DAP_APP_NAME ); - //#endif - - if ( dap_common_init( DAP_APP_NAME, l_log_file_path ) != 0 ) { - printf( "Fatal Error: Can't init common functions module" ); - return -2; - } + dap_sprintf( l_log_file_path + path_len + sizeof(SYSTEM_LOGS_DIR) - 1, "/%s_logs.txt", DAP_APP_NAME ); - memcpy( l_sys_dir_path + path_len, SYSTEM_CONFIGS_DIR, sizeof(SYSTEM_CONFIGS_DIR) ); + if ( dap_common_init( DAP_APP_NAME, l_log_file_path ) != 0 ) { + printf( "Fatal Error: Can't init common functions module" ); + return -2; + } - dap_config_init( l_sys_dir_path ); + memcpy( l_sys_dir_path + path_len, SYSTEM_CONFIGS_DIR, sizeof(SYSTEM_CONFIGS_DIR) ); - if ( (g_config = dap_config_open(DAP_APP_NAME)) == NULL ) { - log_it( L_CRITICAL,"Can't init general configurations" ); - printf("log_it\n"); - return -1; - } + dap_config_init( l_sys_dir_path ); + if ( (g_config = dap_config_open(DAP_APP_NAME)) == NULL ) { + log_it( L_CRITICAL,"Can't init general configurations" ); + return -1; + } + dap_sprintf(l_pid_file_path + path_len, "/%s", dap_config_get_item_str_default( g_config, + "resources", + "pid_path", + l_pid_file_path)); + s_pid_file_path = dap_strdup(l_pid_file_path); + } parse_args( argc, argv ); - #ifdef _WIN32 CreateMutexW( NULL, FALSE, (WCHAR *) L"DAP_KELVIN_NODE_74E9201D33F7F7F684D2FEF1982799A79B6BF94B568446A8D1DE947B00E3C75060F3FD5BF277592D02F77D7E50935E56" ); #endif @@ -374,12 +341,7 @@ int main( int argc, const char **argv ) } #endif - - - save_process_pid_in_file(dap_config_get_item_str_default( g_config, - "resources", - "pid_path", - l_pid_file_path)); + save_process_pid_in_file(s_pid_file_path); bServerEnabled = dap_config_get_item_bool_default( g_config, "server", "enabled", false ); @@ -479,7 +441,7 @@ int main( int argc, const char **argv ) // Deinit modules -failure:; +failure: dap_stream_deinit(); dap_stream_ctl_deinit(); @@ -491,8 +453,7 @@ failure:; dap_config_close( g_config ); dap_common_deinit(); - if ( l_path_buff ) - DAP_FREE( l_path_buff ); + if (s_pid_file_path) { free(s_pid_file_path); } return rc * 10; } @@ -513,7 +474,7 @@ void parse_args( int argc, const char **argv ) { case 0: // --stop { - pid_t pid = get_pid_from_file( dap_config_get_item_str_default( g_config, "resources", "pid_path", l_pid_file_path) ); + pid_t pid = get_pid_from_file(s_pid_file_path); if ( pid == 0 ) { log_it( L_ERROR, "Can't read pid from file" ); @@ -549,7 +510,7 @@ void parse_args( int argc, const char **argv ) { void exit_if_server_already_running( void ) { - pid_t pid = get_pid_from_file( dap_config_get_item_str_default( g_config, "resources", "pid_path", l_pid_file_path) ); + pid_t pid = get_pid_from_file(s_pid_file_path); bool mf = false; diff --git a/sources/main_node_cli.c b/sources/main_node_cli.c index 2c27fe7aac6ebee66a05f7ef82012f1e3e9078da..3530a7f40031564a38298bbdf22b4d12a26db19d 100644 --- a/sources/main_node_cli.c +++ b/sources/main_node_cli.c @@ -34,6 +34,10 @@ #include "main_node_cli_net.h" #include "main_node_cli_shell.h" +#ifdef _WIN32 +#include "registry.h" +#endif + #include "dap_defines.h" static connect_param *cparam; @@ -182,26 +186,10 @@ int main(int argc, const char * argv[]) uint32_t path_len = 0; uint32_t win_prefix_size; - #ifdef _WIN32 - { - HKEY hKey; - win_prefix_size = 2048; - - LSTATUS lRes = RegOpenKeyExA( HKEY_CURRENT_USER, - "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", - 0, KEY_READ, &hKey ); - - lRes = RegQueryValueExA( hKey, "Personal", 0, NULL, (LPBYTE)&win_prefix[0], (DWORD*)&win_prefix_size ); - RegCloseKey( hKey ); - - if ( lRes != ERROR_SUCCESS ) { - memcpy( &win_prefix[0], "c:", 3 ); - win_prefix_size = 3; - } - - path_len = dap_sprintf( l_sys_dir_path, "%s/%s", win_prefix, DAP_APP_NAME ); - } - #endif +#ifdef _WIN32 + dap_sprintf(l_sys_dir_path, "%s/%s", regGetUsrPath(), DAP_APP_NAME); + path_len = strlen(l_sys_dir_path); +#endif // set_default_locale(); // command_execution_string = shell_script_filename = (char *) NULL; diff --git a/sources/main_node_cli_net.c b/sources/main_node_cli_net.c index 88d930458504fbc1cd9ed59517397be2611c2dba..91fa95317fe96b3114184fd9fa18bd9ffaca7c77 100644 --- a/sources/main_node_cli_net.c +++ b/sources/main_node_cli_net.c @@ -126,7 +126,7 @@ connect_param* node_cli_connect(void) #ifndef _WIN32 int ret = curl_easy_setopt(curl_handle, CURLOPT_UNIX_SOCKET_PATH, dap_config_get_item_str( g_config, "conserver", "listen_unix_socket_path") ); // unix socket mode #else - int ret = curl_easy_setopt(curl_handle, CURLOPT_PORT, dap_config_get_item_uint16 ( g_config, "conserver", "listen_tcp_port")); // unix socket mode + int ret = curl_easy_setopt(curl_handle, CURLOPT_PORT, dap_config_get_item_uint16 ( g_config, "conserver", "listen_port_tcp")); // unix socket mode #endif curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 60L); // complete within 60 seconds