Skip to content
Snippets Groups Projects
Commit 59e4d907 authored by Dmitriy A. Gerasimov's avatar Dmitriy A. Gerasimov
Browse files

[*] New node with quick reactor

parent d7186a06
No related branches found
No related tags found
No related merge requests found
Pipeline #5028 passed with stage
in 6 seconds
......@@ -8,10 +8,10 @@ set(CMAKE_C_STANDARD 11)
SET( CPACK_PACKAGE_NAME "${PROJECT_NAME}")
SET( CPACK_PACKAGE_VERSION_MAJOR 4)
SET( CPACK_PACKAGE_VERSION_MINOR 0)
SET( CPACK_PACKAGE_VERSION_PATCH 15)
SET( CPACK_PACKAGE_VERSION_PATCH 36)
# init CellFrame SDK
add_definitions("-DDAP_VERSION=\"${CPACK_PACKAGE_VERSION_MAJOR}\"")
add_definitions("-DDAP_VERSION=\"${CPACK_PACKAGE_VERSION_MAJOR}-${CPACK_PACKAGE_VERSION_MINOR}-${CPACK_PACKAGE_VERSION_PATCH}\"")
set(SUBMODULES_NO_BUILD ON)
set(SUPPORT_PYTHON_PLUGINS ON)
......
Subproject commit 7aadfc1bd1b82b2ff6b5e11bce1ad9d9086d39c3
Subproject commit 65f1dec34f0bbac21a4b2c24305ac0c6c468dfe4
......@@ -20,7 +20,7 @@ listen_port_tcp={SERVER_PORT}
# Builtin DNS server
[dns_server]
enabled=false
bootstrap_balancer=true
bootstrap_balancer=false
[srv]
order_signed_only=false
......@@ -58,6 +58,7 @@ tx_cond_create=false
# Turn to true if you want to share VPN service from you node
enabled=false
geoip_enabled=false
debug_more=false
# List of loca security access groups. Built in: expats,admins,services,nobody,everybody
network_address=10.11.12.0
network_mask=255.255.255.0
......
Subproject commit c5fce4f8d55f9b956fcc1e9b05ccf2459f604c86
Subproject commit d2d1011c82454a886c3e66b0580ae65c89540076
/*
* Authors:
* Dmitriy A. Gearasimov <kahovski@gmail.com>
* Dmitriy A. Gerasimov <kahovski@gmail.com>
* DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc
* Copyright (c) 2017-2019
......@@ -58,6 +58,9 @@
#include "dap_server.h"
#include "dap_http.h"
#include "dap_http_folder.h"
#include "dap_dns_server.h"
#include "dap_modules_dynamic_cdb.h"
#include "dap_events.h"
#include "dap_enc.h"
......@@ -70,9 +73,13 @@
#include "dap_chain_cs_dag.h"
#include "dap_chain_cs_dag_poa.h"
#include "dap_chain_cs_dag_pos.h"
#include "dap_chain_cs_none.h"
#include "dap_chain_net.h"
#include "dap_chain_net_srv.h"
#include "dap_chain_net_srv_app.h"
#include "dap_chain_net_srv_app_db.h"
#include "dap_chain_net_srv_datum.h"
#include "dap_chain_net_srv_geoip.h"
#ifdef DAP_OS_LINUX
......@@ -81,15 +88,10 @@
#include "dap_chain_net_srv_vpn_cdb_server_list.h"
#include "dap_chain_net_vpn_client.h"
#endif
#include "dap_chain_net_news.h"
#include "dap_chain_net_bugreport.h"
#include "dap_chain_net_srv_app.h"
#include "dap_chain_net_srv_datum.h"
#include "dap_dns_server.h"
#include "dap_chain_node.h"
#include "dap_chain_global_db.h"
#include "dap_chain_mempool.h"
#include "dap_chain_node.h"
#include "dap_chain_node_cli.h"
#include "dap_stream_session.h"
......@@ -99,19 +101,23 @@
#include "dap_stream_ch_chain_net.h"
#include "dap_stream_ch_chain_net_srv.h"
#include "dap_chain_net_srv_xchange.h"
#include "dap_chain_net_srv_stake.h"
#include "dap_common.h"
#include "dap_client_remote.h"
#include "dap_events_socket.h"
#include "dap_client.h"
#include "dap_http_client.h"
//#include "dap_http_client_simple.h"
#include "dap_http_simple.h"
#include "dap_client_http.h"
#include "dap_process_manager.h"
#include "dap_traffic_track.h"
#include "dap_defines.h"
#include "dap_file_utils.h"
#ifdef DAP_SUPPORT_PYTHON_PLUGINS
#include "dap_chain_plugins.h"
#endif
#define ENC_HTTP_URL "/enc_init"
#define STREAM_CTL_URL "/stream_ctl"
......@@ -128,7 +134,7 @@ void parse_args( int argc, const char **argv );
void exit_if_server_already_running( void );
static const char *s_pid_file_path = NULL;
static void s_auth_callback(enc_http_delegate_t *a_delegate, void * a_arg);
bool dap_chain_net_srv_pay_verificator(dap_chain_tx_out_cond_t *a_cond, dap_chain_datum_tx_t *a_tx) { return true; }
#ifdef __ANDROID__
......@@ -139,7 +145,7 @@ int main( int argc, const char **argv )
{
dap_server_t *l_server = NULL; // DAP Server instance
bool l_debug_mode = true;
bool bServerEnabled = true;
bool bServerEnabled = false;
int rc = 0;
dap_set_appname("dapcash-node");
......@@ -148,21 +154,20 @@ int main( int argc, const char **argv )
#endif
#ifdef _WIN32
g_sys_dir_path =dap_strdup_printf("%s/%s", regGetUsrPath(), dap_get_appname());
g_sys_dir_path = dap_strdup_printf("%s/%s", regGetUsrPath(), dap_get_appname());
#elif DAP_OS_MAC
g_sys_dir_path =dap_strdup_printf( "/Applications/%s.app/Contents/Resources", dap_get_appname());
g_sys_dir_path = dap_strdup_printf("/Applications/%s.app/Contents/Resources", dap_get_appname());
#elif DAP_OS_ANDROID
g_sys_dir_path = dap_strdup_printf("/storage/emulated/0/opt/%s",dap_get_appname());
g_sys_dir_path = dap_strdup_printf("/storage/emulated/0/opt/%s",dap_get_appname());
#elif DAP_OS_UNIX
g_sys_dir_path =dap_strdup_printf("/opt/%s", dap_get_appname());
g_sys_dir_path = dap_strdup_printf("/opt/%s", dap_get_appname());
#endif
{
char l_log_path[MAX_PATH] = {'\0'};
int l_pos = dap_sprintf(l_log_path, "%s/var/log", g_sys_dir_path);
dap_mkdir_with_parents(l_log_path);
dap_sprintf(l_log_path + l_pos, "/%s.log", dap_get_appname());
if (dap_common_init(dap_get_appname(), l_log_path) != 0) {
printf("Fatal Error: Can't init common functions module");
return -2;
......@@ -181,10 +186,11 @@ int main( int argc, const char **argv )
}
s_pid_file_path = dap_config_get_item_str_default( g_config, "resources", "pid_path","/tmp") ;
log_it(L_DEBUG, "Parsing command line args");
parse_args( argc, argv );
#ifdef _WIN32
CreateMutexW( NULL, FALSE, (WCHAR *) L"DAP_DAPCASH_NODE_74E9201D33F7F7F684D2FEF1982799A79B6BF94B568446A8D1DE947B00E3C75060F3FD5BF277592D02F77D7E50935E56" );
CreateMutexW( NULL, FALSE, (WCHAR *) L"DAPCASH_NODE_74E9201D33F7F7F684D2FEF1982799A79B6BF94B568446A8D1DE947B00E3C75060F3FD5BF277592D02F77D7E50935E56" );
#endif
l_debug_mode = dap_config_get_item_bool_default( g_config,"general","debug_mode", false );
......@@ -215,31 +221,25 @@ int main( int argc, const char **argv )
l_thread_cnt = si.dwNumberOfProcessors;
#endif
}
#ifdef __WIN32
WSADATA wsaData;
int ret = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (ret != 0) {
log_it(L_CRITICAL, "Couldn't init Winsock DLL, error: %d", ret);
return -2;
if ( dap_enc_init() != 0 ){
log_it( L_CRITICAL, "Can't init encryption module" );
return -56;
}
#endif
// New event loop init
dap_events_init( 0, 0 );
dap_events_t *l_events = dap_events_new( );
dap_events_start( l_events );
bServerEnabled = dap_config_get_item_bool_default( g_config, "server", "enabled", false );
log_it ( L_DEBUG,"config server->enabled = \"%u\" ", bServerEnabled );
if ( bServerEnabled && dap_server_init(l_thread_cnt) != 0 ) {
if ( bServerEnabled && dap_server_init() != 0 ) {
log_it( L_CRITICAL, "Can't init socket server module" );
return -4;
}
// New event loop init
dap_events_init( 0, 0 );
dap_events_t *l_events = dap_events_new( );
dap_events_start( l_events );
dap_client_init();
if ( dap_http_init() != 0 ) {
log_it( L_CRITICAL, "Can't init http server module" );
......@@ -250,18 +250,37 @@ int main( int argc, const char **argv )
log_it( L_CRITICAL, "Can't init http server module" );
return -55;
}
if ( dap_http_simple_module_init() != 0 ) {
log_it(L_CRITICAL,"Can't init http simple module");
return -9;
}
if ( enc_http_init() != 0 ) {
log_it( L_CRITICAL, "Can't init encryption http session storage module" );
return -81;
}
if ( dap_stream_init(dap_config_get_item_bool_default(g_config,"general","debug_dump_stream_headers",false)) != 0 ) {
log_it( L_CRITICAL, "Can't init stream server module" );
return -82;
}
if ( dap_stream_ctl_init(DAP_ENC_KEY_TYPE_OAES, 32) != 0 ){
log_it( L_CRITICAL, "Can't init stream control module" );
return -83;
}
dap_client_init();
if ( dap_enc_init() != 0 ){
log_it( L_CRITICAL, "Can't init encryption module" );
return -56;
}
if ( dap_chain_global_db_init(g_config) ) {
log_it( L_CRITICAL, "Can't init global db module" );
return -58;
}
//dap_http_client_simple_init( );
//dap_http_client_simple_init( );
if ( dap_datum_mempool_init() ) {
log_it( L_CRITICAL, "Can't init mempool module" );
......@@ -293,9 +312,14 @@ int main( int argc, const char **argv )
return -64;
}
if(dap_chain_gdb_init() != 0) {
log_it(L_CRITICAL, "Can't init dap chain gdb module");
return -71;
}
dap_chain_ledger_verificator_add(DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE, dap_chain_net_srv_xchange_verificator);
dap_chain_ledger_verificator_add(DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_PAY, dap_chain_net_srv_pay_verificator);
dap_chain_ledger_verificator_add(DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_STAKE, dap_chain_net_srv_stake_verificator);
if( dap_chain_net_init() !=0){
log_it(L_CRITICAL,"Can't init dap chain network module");
......@@ -339,26 +363,6 @@ int main( int argc, const char **argv )
}
}
if ( enc_http_init() != 0 ) {
log_it( L_CRITICAL, "Can't init encryption http session storage module" );
return -81;
}
if ( dap_stream_init(dap_config_get_item_bool_default(g_config,"general","debug_dump_stream_headers",false)) != 0 ) {
log_it( L_CRITICAL, "Can't init stream server module" );
return -82;
}
if ( dap_stream_ctl_init(DAP_ENC_KEY_TYPE_OAES, 32) != 0 ){
log_it( L_CRITICAL, "Can't init stream control module" );
return -83;
}
if ( dap_http_simple_module_init() != 0 ) {
log_it(L_CRITICAL,"Can't init http simple module");
return -9;
}
if ( dap_chain_node_cli_init(g_config) ) {
log_it( L_CRITICAL, "Can't init server for console" );
return -11;
......@@ -379,20 +383,17 @@ int main( int argc, const char **argv )
}
#endif
if (dap_chain_node_mempool_init()) {
log_it( L_CRITICAL, "Can't init mempool" );
return -13;
}
log_it(L_INFO, "Automatic mempool processing %s",
dap_chain_node_mempool_autoproc_init() ? "enabled" : "disabled");
save_process_pid_in_file(s_pid_file_path);
if ( bServerEnabled ) {
int32_t l_port = dap_config_get_item_int32(g_config, "server", "listen_port_tcp");
if( l_port > 0 ) {
l_server = dap_server_listen((dap_config_get_item_str_default(g_config, "server", "listen_address", "0.0.0.0")),
l_server = dap_server_new(l_events, (dap_config_get_item_str(g_config, "server", "listen_address")),
(uint16_t) l_port,
DAP_SERVER_TCP );
} else
......@@ -414,24 +415,13 @@ int main( int argc, const char **argv )
log_it(L_NOTICE, "Central DataBase (CDB) is initialized");
}
}
// Handshake URL
enc_http_add_proc( DAP_HTTP(l_server), ENC_HTTP_URL );
// Streaming URLs
dap_stream_add_proc_http( DAP_HTTP(l_server), STREAM_URL );
dap_stream_ctl_add_proc( DAP_HTTP(l_server), STREAM_CTL_URL );
/*
// BugReport URLs
bool l_bugreport_url_enabled = dap_config_get_item_bool_default(g_config, "server", "bugreport_url_enabled", false);
if(l_bugreport_url_enabled) {
dap_chain_net_bugreport_add_proc(DAP_HTTP(l_server));
}
// News URLs
bool l_news_url_enabled = dap_config_get_item_bool_default(g_config, "server", "news_url_enabled", false);
if(l_news_url_enabled) {
dap_chain_net_news_add_proc(DAP_HTTP(l_server));
}*/
const char *str_start_mempool = dap_config_get_item_str( g_config, "mempool", "accept" );
if ( str_start_mempool && !strcmp(str_start_mempool, "true")) {
......@@ -451,6 +441,7 @@ int main( int argc, const char **argv )
} else
log_it( L_INFO, "No enabled server, working in client mode only" );
// DNS server start
bool bootstrap_balancer_enabled = dap_config_get_item_bool_default(g_config, "dns_server", "bootstrap_balancer", false);
log_it(L_DEBUG, "config dns_server->bootstrap_balancer = \"%u\" ", bootstrap_balancer_enabled);
......@@ -468,31 +459,42 @@ int main( int argc, const char **argv )
if (!dap_chain_net_srv_xchange_init()) {
log_it(L_ERROR, "Can't provide exchange capability");
}
if (bServerEnabled) {
// Endless loop for server's requests processing
rc = dap_server_loop(l_server);
// After loop exit actions
log_it( rc ? L_CRITICAL : L_NOTICE, "Server loop stopped with return code %d", rc );
} else {
dap_events_wait(l_events);
if (!dap_chain_net_srv_stake_init()) {
log_it(L_ERROR, "Can't start delegated stake service");
}
/// if (dap_config_get_item_bool_default(g_config,"vpn","enabled",false))
/// dap_stream_ch_vpn_deinit();
//dap_chain_net_load_all();
//Init python plugins
#ifdef DAP_SUPPORT_PYTHON_PLUGINS
log_it(L_NOTICE, "Loading python plugins");
dap_chain_plugins_init(g_config);
#endif
rc = dap_events_wait(l_events);
log_it( rc ? L_CRITICAL : L_NOTICE, "Server loop stopped with return code %d", rc );
// Deinit modules
//failure:
#ifdef __WIN32
WSACleanup();
#endif
#ifdef DAP_SUPPORT_PYTHON_PLUGINS
dap_chain_plugins_deinit();
#endif
dap_dns_server_stop();
dap_stream_deinit();
dap_stream_deinit();
dap_stream_ctl_deinit();
dap_http_folder_deinit();
dap_http_deinit();
if (bServerEnabled) dap_server_deinit();
if (bServerEnabled) dap_server_deinit();
dap_enc_ks_deinit();
dap_chain_node_mempool_deinit();
dap_chain_node_mempool_autoproc_deinit();
dap_chain_net_srv_xchange_deinit();
dap_chain_net_srv_stake_deinit();
dap_config_close( g_config );
dap_common_deinit();
......@@ -557,7 +559,7 @@ void exit_if_server_already_running( void ) {
bool mf = false;
#ifdef _WIN32
CreateMutexW( NULL, FALSE, (WCHAR *) L"DAP_DAPCASH_NODE_74E9201D33F7F7F684D2FEF1982799A79B6BF94B568446A8D1DE947B00E3C75060F3FD5BF277592D02F77D7E50935E56" );
CreateMutexW( NULL, FALSE, (WCHAR *) L"DAPCASH_NODE_74E9201D33F7F7F684D2FEF1982799A79B6BF94B568446A8D1DE947B00E3C75060F3FD5BF277592D02F77D7E50935E56" );
if ( GetLastError( ) == 183 ) {
mf = true;
......
......@@ -27,55 +27,254 @@
#include <stdlib.h>
#include <string.h>
//#include "dap_client.h"
#include "dap_common.h"
#include "dap_file_utils.h"
#include "dap_strfuncs.h"
#include "dap_config.h"
#include "dap_chain_node_cli.h"
#include "dap_app_cli.h"
#include "dap_app_cli_net.h"
#include "dap_app_cli_shell.h"
#ifdef __ANDROID__
#include "dapcash_node.h"
#include "cellframe_node.h"
#endif
#ifdef _WIN32
#include "registry.h"
#endif
#include "dap_defines.h"
static dap_app_cli_connect_param_t *cparam;
/**
* split string to argc and argv
*/
static char** split_word(char *line, int *argc)
{
if(!line)
{
if(argc)
*argc = 0;
return NULL ;
}
char **argv = calloc(sizeof(char*), strlen(line));
int n = 0;
char *s, *start = line;
size_t len = strlen(line);
for(s = line; s <= line + len; s++) {
if(whitespace(*s)) {
*s = '\0';
argv[n] = start;
s++;
// miss spaces
for(; whitespace(*s); s++)
;
start = s;
n++;
}
}
// last param
if(len) {
argv[n] = start;
n++;
}
if(argc)
*argc = n;
return argv;
}
/*
* Execute a command line.
*/
int execute_line(char *line)
{
register int i;
char *word;
/* Isolate the command word. */
i = 0;
while(line[i] && whitespace(line[i]))
i++;
word = line + i;
/* while(line[i] && !whitespace(line[i]))
i++;
if(line[i])
line[i++] = '\0';
command = find_command(word);
if(!command)
{
fprintf(stderr, "%s: No such command\n", word);
return (-1);
}*/
/* Get argument to command, if any.
while(whitespace(line[i]))
i++;
word = line + i;*/
int argc = 0;
char **argv = split_word(word, &argc);
// Call the function
if(argc > 0) {
dap_app_cli_cmd_state_t cmd;
memset(&cmd, 0, sizeof(dap_app_cli_cmd_state_t));
cmd.cmd_name = (char *) argv[0];
cmd.cmd_param_count = argc - 1;
if(cmd.cmd_param_count > 0)
cmd.cmd_param = (char**) (argv + 1);
// Send command
int res = dap_app_cli_post_command(cparam, &cmd);
return res;
}
fprintf(stderr, "No command\n");
return -1; //((*(command->func))(argc, (const char **) argv, NULL));
}
/**
* Clear and delete memory of structure cmd_state
*/
void free_cmd_state(dap_app_cli_cmd_state_t *cmd) {
if(!cmd->cmd_param)
return;
for(int i = 0; i < cmd->cmd_param_count; i++)
{
DAP_DELETE(cmd->cmd_param[i]);
}
DAP_DELETE(cmd->cmd_res);
DAP_DELETE(cmd);
}
/**
* Read and execute commands until EOF is reached. This assumes that
* the input source has already been initialized.
*/
int shell_reader_loop()
{
char *line, *s;
rl_initialize(); /* Bind our completer. */
int done = 0;
// Loop reading and executing lines until the user quits.
for(; done == 0;) {
// Read a line of input
line = rl_readline("> ");
if(!line)
break;
/* Remove leading and trailing whitespace from the line.
Then, if there is anything left, add it to the history list
and execute it. */
s = rl_stripwhite(line);
if(*s)
{
add_history(s);
execute_line(s);
}
DAP_DELETE(line);
}
return 0;
}
#ifdef __ANDROID__
int dapcash_node__cli_Main(int argc, const char *argv[])
int cellframe_node__cli_Main(int argc, const char *argv[])
#else
int main(int argc, const char *argv[])
#endif
{
dap_set_appname("dapcash-node");
dap_set_appname("cellframe-node");
#ifdef _WIN32
g_sys_dir_path =dap_strdup_printf("%s/%s", regGetUsrPath(), dap_get_appname());
g_sys_dir_path = dap_strdup_printf("%s/%s", regGetUsrPath(), dap_get_appname());
#elif DAP_OS_MAC
g_sys_dir_path =dap_strdup_printf( "/Applications/%s.app/Contents/Resources", dap_get_appname());
g_sys_dir_path = dap_strdup_printf("/Applications/%s.app/Contents/Resources", dap_get_appname());
#elif DAP_OS_ANDROID
g_sys_dir_path = dap_strdup_printf("/storage/emulated/0/opt/%s",dap_get_appname());
#elif DAP_OS_UNIX
g_sys_dir_path =dap_strdup_printf("/opt/%s", dap_get_appname());
g_sys_dir_path = dap_strdup_printf("/opt/%s", dap_get_appname());
#endif
if ( dap_common_init( dap_get_appname(), NULL ) != 0 ) {
printf( "Fatal Error: Can't init common functions module" );
if (dap_common_init(dap_get_appname(), NULL) != 0) {
printf("Fatal Error: Can't init common functions module");
return -2;
}
{
char l_config_dir[MAX_PATH] = {'\0'};
dap_sprintf(l_config_dir, "%s/etc", g_sys_dir_path);
dap_config_init(l_config_dir);
}
dap_log_level_set( L_CRITICAL );
dap_log_level_set(L_CRITICAL);
if((g_config = dap_config_open(dap_get_appname())) == NULL) {
printf("Can't init general configurations %s.cfg\n", dap_get_appname());
exit(-1);
}
const char * l_socket_path = dap_config_get_item_str_default(g_config, "conserver", "listen_unix_socket_path", "");
return dap_app_cli_main( "dapcash-node", l_socket_path, argc, argv);
// connect to node
#ifndef _WIN32
const char* listen_socket = dap_config_get_item_str( g_config, "conserver", "listen_unix_socket_path"); // unix socket mode
#else
const char* listen_socket = NULL;
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData);
#endif
cparam = dap_app_cli_connect(listen_socket);
if(!cparam)
{
printf("Can't connect to %s\n",dap_get_appname());
exit(-1);
}
/*{
printf("start node_cli_post_command()\n");
cmd_state *cmd = DAP_NEW_Z(cmd_state);
cmd->cmd_name = "cmd1";
cmd->cmd_param_count = 2;
cmd->cmd_param = DAP_NEW_Z_SIZE(char*, cmd->cmd_param_count * sizeof(char*));
cmd->cmd_param[0] = strdup("t2-t1");
cmd->cmd_param[1] = strdup("-opt");
int a = node_cli_post_command(cparam, cmd);
printf("node_cli_post_command()=%d\n", a);
free_cmd_state(cmd);
}*/
if(argc > 1){
// Call the function
//int res = ((*(command->func))(argc - 2, argv + 2));
dap_app_cli_cmd_state_t cmd;
memset(&cmd, 0, sizeof(dap_app_cli_cmd_state_t));
cmd.cmd_name = strdup(argv[1]);
cmd.cmd_param_count = argc - 2;
if(cmd.cmd_param_count > 0)
cmd.cmd_param = (char**) (argv + 2);
// Send command
int res = dap_app_cli_post_command(cparam, &cmd);
dap_app_cli_disconnect(cparam);
#ifdef _WIN32
WSACleanup();
#endif
return res;
}else{
// command not found, start interactive shell
shell_reader_loop();
dap_app_cli_disconnect(cparam);
}
#ifdef _WIN32
WSACleanup();
#endif
return 0;
}
......@@ -63,7 +63,9 @@
#include "dap_chain_net.h"
#include "dap_chain_net_srv.h"
#include "dap_chain_net_srv_app.h"
#include "dap_chain_net_srv_app_db.h"
#include "dap_chain_net_srv_datum.h"
#ifndef _WIN32
#include "dap_chain_net_srv_vpn.h"
......@@ -96,6 +98,9 @@
#include "cellframe_node.h"
#endif
#undef log_it
#define log_it(_log_level, string, ...) printf(string, ##__VA_ARGS__)
static int s_init( int argc, const char * argv[] );
static void s_help( );
......@@ -159,7 +164,6 @@ int main(int argc, const char **argv)
l_wallet = dap_chain_wallet_create(l_wallet_name, dap_config_get_item_str(g_config, "resources", "wallets_path"), l_sig_type);
}
else if ( strcmp( argv[2],"sign_file") == 0 ) {
// wallet sign_file <wallet name> <cert index> <data file path> <data offset> <data length> <dsign file path>
if ( argc < 8 ) {
log_it(L_ERROR,"Wrong 'wallet sign_file' command params");
......@@ -167,7 +171,6 @@ int main(int argc, const char **argv)
exit(-3000);
}
dap_chain_wallet_t *l_wallet = dap_chain_wallet_open(argv[3], dap_config_get_item_str(g_config, "resources", "wallets_path"));
if ( !l_wallet ) {
log_it(L_ERROR,"Can't open wallet \"%s\"",argv[3]);
s_help();
......@@ -182,7 +185,7 @@ int main(int argc, const char **argv)
if ( l_data_file ) {}
}
else {
log_it( L_ERROR, "Cert index %d can't be found in wallet with %u certs inside"
log_it( L_ERROR, "Cert index %d can't be found in wallet with %lu certs inside"
,l_cert_index,l_wallet_certs_number );
s_help();
exit( -3002 );
......@@ -283,13 +286,11 @@ int main(int argc, const char **argv)
exit(-7021);
}
}
}
else if ( strcmp( argv[2],"create" ) == 0 ) {
} else if ( strcmp( argv[2],"create" ) == 0 ) {
if ( argc < 5 ) {
s_help();
exit(-500);
}
size_t l_key_length = 0;
const char *l_cert_name = argv[3];
size_t l_cert_path_length = strlen(argv[3])+8+strlen(s_system_ca_dir);
char *l_cert_path = DAP_NEW_Z_SIZE(char,l_cert_path_length);
......@@ -316,7 +317,6 @@ int main(int argc, const char **argv)
}
if ( l_key_type != DAP_ENC_KEY_TYPE_NULL ) {
int l_key_length = argc >=6 ? atoi(argv[5]) : 0;
dap_cert_t * l_cert = dap_cert_generate(l_cert_name,l_cert_path,l_key_type ); // key length ignored!
if (l_cert == NULL){
log_it(L_ERROR, "Can't create %s",l_cert_path);
......@@ -328,7 +328,28 @@ int main(int argc, const char **argv)
exit(-500);
}
DAP_DELETE(l_cert_path);
} else if (strcmp(argv[2], "add_metadata") == 0) {
if (argc >= 5) {
const char *l_cert_name = argv[3];
dap_cert_t *l_cert = dap_cert_add_file(l_cert_name, s_system_ca_dir);
if ( l_cert ) {
char **l_params = dap_strsplit(argv[4], ":", 4);
dap_cert_metadata_type_t l_type = (dap_cert_metadata_type_t)atoi(l_params[1]);
if (l_type == DAP_CERT_META_STRING || l_type == DAP_CERT_META_SIGN || l_type == DAP_CERT_META_CUSTOM) {
dap_cert_add_meta(l_cert, l_params[0], l_type, (void *)l_params[3], strtoul(l_params[2], NULL, 10));
} else {
dap_cert_add_meta_scalar(l_cert, l_params[0], l_type,
strtoull(l_params[3], NULL, 10), strtoul(l_params[2], NULL, 10));
}
dap_strfreev(l_params);
dap_cert_save_to_folder(l_cert, s_system_ca_dir);
dap_cert_delete_by_name(l_cert_name);
ret = 0;
}
else {
exit(-800);
}
}
} else {
log_it(L_ERROR,"Wrong params");
s_help();
......@@ -355,27 +376,28 @@ int main(int argc, const char **argv)
*/
static int s_init( int argc, const char **argv )
{
dap_set_appname("dapcash-node");
dap_set_appname("cellframe-node");
#ifdef _WIN32
g_sys_dir_path =dap_strdup_printf("%s/%s", regGetUsrPath(), dap_get_appname());
g_sys_dir_path = dap_strdup_printf("%s/%s", regGetUsrPath(), dap_get_appname());
#elif DAP_OS_MAC
g_sys_dir_path =dap_strdup_printf( "/Applications/%s.app/Contents/Resources", dap_get_appname());
g_sys_dir_path = dap_strdup_printf("/Applications/%s.app/Contents/Resources", dap_get_appname());
#elif DAP_OS_ANDROID
g_sys_dir_path = dap_strdup_printf("/storage/emulated/0/opt/%s",dap_get_appname());
#elif DAP_OS_UNIX
g_sys_dir_path =dap_strdup_printf("/opt/%s", dap_get_appname());
g_sys_dir_path = dap_strdup_printf("/opt/%s", dap_get_appname());
#endif
if (dap_common_init(dap_get_appname(), NULL) != 0) {
printf("Fatal Error: Can't init common functions module");
return -2;
}
{
char l_config_dir[MAX_PATH] = {'\0'};
dap_sprintf(l_config_dir, "%s/etc", g_sys_dir_path);
dap_config_init(l_config_dir);
}
dap_log_level_set( L_CRITICAL );
dap_log_level_set(L_CRITICAL);
if((g_config = dap_config_open(dap_get_appname())) == NULL) {
printf("Can't init general configurations %s.cfg\n", dap_get_appname());
......@@ -472,4 +494,7 @@ static void s_help()
printf(" * Export only public key from <cert name> and stores it \n");
printf("\t%s cert create_cert_pkey <cert name> <new cert name>\n\n",dap_get_appname());
printf(" * Add metadata item to <cert name>\n");
printf("\t%s cert add_metadata <cert name> <key:type:length:value>\n\n",dap_get_appname());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment