From 268f58d7e1bade3fcb4035df6359ecfd5b27a579 Mon Sep 17 00:00:00 2001 From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net> Date: Wed, 20 Nov 2019 12:20:09 +0700 Subject: [PATCH] [+] Auth callback and other stuff from node's main.c --- CMakeLists.txt | 6 +- dap_chain_net_srv_vpn_cdb.c | 117 ++++++++++++++++++++++++++++++++++++ dap_chain_net_srv_vpn_cdb.h | 28 +++++++++ 3 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 dap_chain_net_srv_vpn_cdb.c create mode 100644 dap_chain_net_srv_vpn_cdb.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9312637..1ce515b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project (dap_chain_net_srv_vpn) set(DAP_CHAIN_NET_SRV_VPN_SRCS dap_chain_net_srv_vpn.c + dap_chain_net_srv_vpn_cdb.c dap_chain_net_srv_vpn_cdb_server_list.c dap_chain_net_vpn_client.c dap_chain_net_vpn_client_tun.c @@ -10,7 +11,8 @@ set(DAP_CHAIN_NET_SRV_VPN_SRCS set(DAP_CHAIN_NET_SRV_VPN_HEADERS dap_chain_net_srv_vpn.h - dap_chain_net_srv_vpn_cdb_server_list.h + dap_chain_net_srv_vpn_cdb.h + dap_chain_net_srv_vpn_cdb_server_list.h dap_chain_net_vpn_client.h dap_chain_net_vpn_client_tun.h @@ -30,7 +32,7 @@ endif() add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_NET_SRV_VPN_SRCS} ${DAP_CHAIN_NET_SRV_VPN_HEADERS}) -target_link_libraries(dap_chain_net_srv_vpn dap_core dap_crypto dap_chain dap_chain_crypto dap_chain_net dap_chain_net_srv) +target_link_libraries(dap_chain_net_srv_vpn dap_core dap_crypto dap_chain dap_chain_crypto dap_chain_net dap_chain_net_srv dap_server_http_db dap_server_http_db_auth) target_include_directories(dap_chain_net_srv_vpn INTERFACE .) set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE) diff --git a/dap_chain_net_srv_vpn_cdb.c b/dap_chain_net_srv_vpn_cdb.c new file mode 100644 index 0000000..7df46a5 --- /dev/null +++ b/dap_chain_net_srv_vpn_cdb.c @@ -0,0 +1,117 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2019 + * All rights reserved. + + This file is part of CellFrame SDK the open source project + + CellFrame SDK is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + CellFrame SDK is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "dap_common.h" +#include "dap_config.h" +#include "dap_chain.h" +#include "dap_enc_http.h" +#include "dap_http.h" + +#include "db_core.h" +#include "db_auth.h" +#include "db_http.h" +#include "db_http_file.h" + +#include "dap_chain_net_srv_vpn_cdb.h" +#include "dap_chain_net_srv_vpn_cdb_server_list.h" + + +#define LOG_TAG "dap_chain_net_srv_vpn_cdb" + +#define DB_URL "/db" +#define DB_FILE_URL "/db_file" +#define SLIST_URL "/nodelist" + +static void s_auth_callback(enc_http_delegate_t* a_delegate, void * a_arg); + +/** + * @brief dap_chain_net_srv_vpn_cdb_init + * @return + */ +int dap_chain_net_srv_vpn_cdb_init(dap_http_t * a_http) +{ + int rc; + if (dap_config_get_item_bool_default( g_config, + "cdb", + "servers_list_enabled", + false)) { + + if (dap_chain_net_srv_vpn_cdb_server_list_init() != 0) { + log_it(L_CRITICAL,"Can't init vpn servers list"); + return -10; + } + } + + + if((rc=db_core_init(dap_config_get_item_str_default(g_config, + "cdb", + "db_path", + "mongodb://localhost/db")))!=0 ){ + log_it(L_CRITICAL,"Can't init CDB module, return code %d",rc); + return -3; + } + if( dap_config_get_item_bool_default( g_config,"cdb_auth","enabled",false) ){ + db_auth_init( dap_config_get_item_str_default(g_config,"cdb_auth","collection_name","cdb") ); + } + db_http_add_proc( a_http , DB_URL ); + db_http_file_proc_add( a_http , DB_FILE_URL ); + + // Load all chain networks + if (dap_config_get_item_bool_default( g_config, + "cdb", + "servers_list_enabled", + false)) { + dap_chain_net_srv_vpn_cdb_server_list_add_proc ( a_http, SLIST_URL); + } + + // Produce transaction for authorized users + if (dap_config_get_item_bool_default( g_config, + "cdb", + "tx_cond_create", + false)) { + db_auth_set_callbacks( s_auth_callback ); + } + return 0; +} + +/** + * @brief dap_chain_net_srv_vpn_cdb_deinit + */ +void dap_chain_net_srv_vpn_cdb_deinit() +{ + +} + + + +/** + * @brief s_auth_callback + * @param a_delegate + * @param a_arg + */ +static void s_auth_callback(enc_http_delegate_t* a_delegate, void * a_arg) +{ + log_it( L_DEBUG, "Authorized, now need to create conditioned transaction if not present"); +} diff --git a/dap_chain_net_srv_vpn_cdb.h b/dap_chain_net_srv_vpn_cdb.h new file mode 100644 index 0000000..c333d6c --- /dev/null +++ b/dap_chain_net_srv_vpn_cdb.h @@ -0,0 +1,28 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2019 + * All rights reserved. + + This file is part of CellFrame SDK the open source project + + CellFrame SDK is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + CellFrame SDK is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once +#include "dap_http.h" +int dap_chain_net_srv_vpn_cdb_init(dap_http_t * a_http); +void dap_chain_net_srv_vpn_cdb_deinit(); -- GitLab