diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ee838e6dc6c8f8ba455636c56ad1b40bf24d45d..5d3b84fa128b049c421d455b928234b02e899194 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,12 +11,10 @@ set(DAP_CHAIN_NET_SRV_HEADERS dap_chain_net_srv_common.h ) - add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_NET_SRV_SRCS} ${DAP_CHAIN_NET_SRV_HEADERS}) -target_link_libraries(dap_chain_net_srv dap_core dap_crypto dap_chain dap_chain_crypto dap_chain_net) -#target_link_libraries(dap_chain_net_srv dap_core dap_crypto dap_chain dap_chain_crypto dap_chain_net dap_server_http_db_auth) +target_link_libraries(dap_chain_net_srv dap_core dap_crypto dap_chain dap_chain_crypto dap_chain_net ) target_include_directories(dap_chain_net_srv INTERFACE .) set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE) diff --git a/dap_chain_net_srv.c b/dap_chain_net_srv.c new file mode 100755 index 0000000000000000000000000000000000000000..f1fec03525986c2ee729e08ce06eda3ff3b250c2 --- /dev/null +++ b/dap_chain_net_srv.c @@ -0,0 +1,89 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) 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. + + DAP 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 DAP based project. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "utlist.h" + +#include "dap_chain_net_srv.h" + +#define LOG_TAG "chain_net_srv" + +size_t m_uid_count; +dap_chain_net_srv_uid_t * m_uid; + +/** + * @brief dap_chain_net_srv_init + * @return + */ +int dap_chain_net_srv_init() +{ + m_uid = NULL; + m_uid_count = 0; + + return 0; +} + +/** + * @brief dap_chain_net_srv_deinit + */ +void dap_chain_net_srv_deinit() +{ + +} + +/** + * @brief dap_chain_net_srv_add + * @param a_srv + */ +void dap_chain_net_srv_add(dap_chain_net_srv_t * a_srv) +{ + +} + +/** + * @brief dap_chain_net_srv_get + * @param a_uid + * @return + */ +dap_chain_net_srv_t * dap_chain_net_srv_get(dap_chain_net_srv_uid_t a_uid) +{ + +} + +/** + * @brief dap_chain_net_srv_count + * @return + */ +const size_t dap_chain_net_srv_count() +{ + +} + +/** + * @brief dap_chain_net_srv_list + * @return + */ +const dap_chain_net_srv_uid_t * dap_chain_net_srv_list() +{ + +} diff --git a/dap_chain_net_srv.h b/dap_chain_net_srv.h new file mode 100755 index 0000000000000000000000000000000000000000..bd9c5ea57793f146197556ce5f16e2c569147836 --- /dev/null +++ b/dap_chain_net_srv.h @@ -0,0 +1,78 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * Kelvin Project https://github.com/kelvinblockchain + * Copyright (c) 2017-2018 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) 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. + + DAP 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 DAP based project. If not, see <http://www.gnu.org/licenses/>. + */ +#pragma once + +#include "dap_chain_node_ctl.h" +#include "dap_chain_net_srv_common.h" + +//Classes of services +enum { + SERV_CLASS_ONCE = 1, // one-time service + SERV_CLASS_PERMANENT = 2 +}; + +//Types of services +enum { + SERV_ID_VPN = 1, +}; + +typedef struct dap_chain_net_srv +{ + dap_chain_node_ctl_t * node; + dap_chain_net_srv_uid_t uid; // Unique ID for service. + + void * _internal; + void * _inhertor; +} dap_chain_net_srv_t; + +typedef struct dap_chain_net_srv_abstract +{ + uint64_t proposal_id; // id trade proposal. Must be unique to the node. + + uint8_t class; //Class of service + uint8_t type_id; //Type of service + union { + struct { + int bandwith; + int abuse_resistant; + int limit_bytes; + } vpn; + struct { + int value; + } other_srv; + } proposal_params; + + uint64_t price; // service price, for SERV_CLASS_ONCE ONCE for the whole service, for SERV_CLASS_PERMANENT for one unit. + uint8_t price_units; // Unit of service (seconds, megabytes, etc.) Only for SERV_CLASS_PERMANENT + char decription[128]; +} DAP_ALIGN_PACKED dap_chain_net_srv_abstract_t; + +int dap_chain_net_srv_init(); +void dap_chain_net_srv_deinit(); + +void dap_chain_net_srv_add(dap_chain_net_srv_t * a_srv); +dap_chain_net_srv_t * dap_chain_net_srv_get(dap_chain_net_srv_uid_t a_uid); +const size_t dap_chain_net_srv_count(); +const dap_chain_net_srv_uid_t * dap_chain_net_srv_list(); + diff --git a/dap_chain_net_srv_common.c b/dap_chain_net_srv_common.c index cd1709eef82484bf4919439e5851c57512d953e1..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100755 --- a/dap_chain_net_srv_common.c +++ b/dap_chain_net_srv_common.c @@ -1,62 +0,0 @@ -#include <stdint.h> -#include "rand/dap_rand.h" -#include "dap_chain_net_srv_common.h" -#include "dap_chain_datum_tx_items.h" -#include "dap_chain_utxo.h" - -/** - * Generate unique id for service - */ -bool dap_chain_net_srv_gen_uid(dap_chain_net_srv_uid_t *a_srv) -{ - if(!a_srv) - return false; - randombytes(a_srv, sizeof(dap_chain_net_srv_uid_t)); - return true; -} - -/** - * - */ -uint64_t dap_chain_net_srv_client_auth(char *a_addr_base58, uint8_t *a_sign, size_t a_sign_size, - const dap_chain_net_srv_abstract_t **a_cond_out) -{ - dap_chain_addr_t *l_addr = (a_addr_base58) ? dap_chain_str_to_addr(a_addr_base58) : NULL; - dap_chain_tx_out_cond_t *l_tx_out_cond = NULL; - - // Search all value in transactions with l_addr in 'out_cond' item - uint64_t l_value = 0;//!!!dap_chain_node_datum_tx_cache_get_out_cond_value(l_addr, &l_tx_out_cond); - DAP_DELETE(l_addr); - // not found transaction with l_addr in 'out_cond' item - if(!l_value) - return 0; - - size_t l_pkey_size = 0; - size_t l_cond_size = 0; - uint8_t *l_cond = dap_chain_datum_tx_out_cond_item_get_pkey(l_tx_out_cond, &l_cond_size); - uint8_t *l_pkey = dap_chain_datum_tx_out_cond_item_get_cond(l_tx_out_cond, &l_pkey_size); - - // create l_chain_sign for check a_sign - dap_chain_sign_t *l_chain_sign = DAP_NEW_Z_SIZE(dap_chain_sign_t, - sizeof(dap_chain_sign_t) + a_sign_size + l_pkey_size); - l_chain_sign->header.type = l_addr->sig_type; - l_chain_sign->header.sign_size = l_pkey_size; - l_chain_sign->header.sign_pkey_size = l_pkey_size; - // write serialized public key to dap_chain_sign_t - memcpy(l_chain_sign->pkey_n_sign, l_pkey, l_pkey_size); - // write serialized signature to dap_chain_sign_t - memcpy(l_chain_sign->pkey_n_sign + l_pkey_size, a_sign, a_sign_size); - - // check signature - if(dap_chain_sign_verify(l_chain_sign, a_sign, a_sign_size) != 1) { - // invalid signature - return 0; - } - - if(l_cond_size != sizeof(dap_chain_net_srv_abstract_t)) { - return 0; - } - if(a_cond_out) - *a_cond_out = (const dap_chain_net_srv_abstract_t*) l_cond; - return l_value; -} diff --git a/dap_chain_net_srv_common.h b/dap_chain_net_srv_common.h index ee6835544d2aff9491dac791246f37e8d1670cc5..51403634cc1cf2032011cbe4efe3d4857841ca8f 100755 --- a/dap_chain_net_srv_common.h +++ b/dap_chain_net_srv_common.h @@ -1,6 +1,5 @@ #pragma once #include <stdint.h> -#include <stdbool.h> #include "dap_common.h" #include "dap_math_ops.h" @@ -14,46 +13,3 @@ typedef union{ dap_uint128_t raw_ui128[1]; #endif } dap_chain_net_srv_uid_t; - - -//Classes of services -enum { - SERV_CLASS_ONCE = 1, // one-time service - SERV_CLASS_PERMANENT = 2 -}; - -//Types of services -enum { - SERV_ID_VPN = 1, -}; - -typedef struct dap_chain_net_srv_abstract -{ - uint64_t proposal_id; // id trade proposal. Must be unique to the node. - - uint8_t class; //Class of service - uint8_t type_id; //Type of service - union { - struct { - int bandwith; - int abuse_resistant; - int limit_bytes; - } vpn; - /*struct { - int value; - } another_srv;*/ - } proposal_params; - - //size_t pub_key_data_size; - //void * pub_key_data; - - uint64_t price; // service price, for SERV_CLASS_ONCE ONCE for the whole service, for SERV_CLASS_PERMANENT for one unit. - uint8_t price_units; // Unit of service (seconds, megabytes, etc.) Only for SERV_CLASS_PERMANENT - char decription[128]; -} DAP_ALIGN_PACKED dap_chain_net_srv_abstract_t; - -// generate new dap_chain_net_srv_uid_t -bool dap_chain_net_srv_gen_uid(dap_chain_net_srv_uid_t *a_srv); - -uint64_t dap_chain_net_srv_client_auth(char *a_addr_base58, uint8_t *a_sign, size_t a_sign_size, - const dap_chain_net_srv_abstract_t **a_cond_out);