From 0ea8118293ceb1188befe07ed43982c3328b645f Mon Sep 17 00:00:00 2001 From: Dmitriy Gerasimov <dm@cifercom.com> Date: Tue, 14 Aug 2018 09:15:42 +0700 Subject: [PATCH] [+] dap_chain_srv, dap_chain_node and some others objects skelet [*] Build errors fixed [-] libconfig usage in libdap-server. TODO: replace static declaration with dap_config object calls --- CMakeLists.txt | 4 +++ dap_chain.c | 2 +- dap_chain_block.h | 32 +++++++++++------------ dap_chain_mine.h | 23 ----------------- dap_chain_node.c | 23 +++++++++++++++++ dap_chain_node.h | 40 +++++++++++++++++++++++++++++ dap_chain_srv.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ dap_chain_srv.h | 21 +++++++++++++++ dap_chain_srv_pkt.c | 3 +++ dap_chain_srv_pkt.h | 35 +++++++++++++++++++++++++ 10 files changed, 205 insertions(+), 40 deletions(-) create mode 100644 dap_chain_node.c create mode 100644 dap_chain_node.h create mode 100644 dap_chain_srv_pkt.c create mode 100644 dap_chain_srv_pkt.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e26e9fc..b65645f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,9 @@ set(DAP_CHAIN_SRCS dap_chain.c dap_chain_ops.c dap_chain_coin.c + dap_chain_node.c dap_chain_srv.c + dap_chain_srv_pkt.c dap_hash.c dap_hash_fusion.c dap_hash_keccak.c @@ -32,7 +34,9 @@ set(DAP_CHAIN_HEADERS dap_chain_internal.h dap_chain_common.h dap_chain_coin.h + dap_chain_node.h dap_chain_srv.h + dap_chain_srv_pkt.h dap_chain_section.h dap_chain_section_roots.h dap_chain_section_tx.h diff --git a/dap_chain.c b/dap_chain.c index cfea228..d3fa2cf 100644 --- a/dap_chain.c +++ b/dap_chain.c @@ -138,7 +138,7 @@ void dap_chain_save(dap_chain_t * a_chain) */ void dap_chain_file_write(dap_chain_block_cache_t *l_block_cache){ - if (dap_chain_hash_kind_check(l_block_cache, l_block_cache->block->header.difficulty)==HASH_GOLD){ + if (dap_chain_hash_kind_check(&l_block_cache->block_hash, l_block_cache->block->header.difficulty)==HASH_GOLD){ fwrite(l_block_cache->block->header.size, 64, 1, my_file_to_wite_gold); fwrite(l_block_cache->block, l_block_cache->block->header.size, 1, my_file_to_wite_gold); blocks_mined_gold += 1; diff --git a/dap_chain_block.h b/dap_chain_block.h index 4e3426d..d7adb30 100644 --- a/dap_chain_block.h +++ b/dap_chain_block.h @@ -44,22 +44,22 @@ typedef struct dap_chain_block{ int32_t version; /// @param version @brief block version (be carefull, signed value, as Bitcoin has) uint32_t size; /// @param size of the whole block uint64_t timestamp; /// @param timestamp @brief Block create time timestamp - uint64_t difficulty; /// difficulty level - uint64_t nonce; /// Nonce value to allow header variation for mining - union{ - struct{ // Zero-level block without sharding - dap_chain_hash_t prev_block; /// @param prev_block Hash of the previous block - dap_chain_hash_t padding0; // - uint32_t padding1; // - uint64_t padding2; // Always zero (should be well compresed) - }; - struct{ - dap_chain_hash_t prev_block_0lvl; /// @param prev_block Hash of the previous block - dap_chain_hash_t prev_block_shard; /// @param prev_block Hash of the previous block - uint32_t shard_id; // Shard id - uint64_t nonce2; // Second NonCE for block mining inside the shard - } - } + uint64_t difficulty; /// difficulty level + uint64_t nonce; /// Nonce value to allow header variation for mining + union{ + struct{ // Zero-level block without sharding + dap_chain_hash_t prev_block; /// @param prev_block Hash of the previous block + dap_chain_hash_t padding0; // + uint32_t padding1; // + uint64_t padding2; // Always zero (should be well compresed) + }; + struct{ + dap_chain_hash_t prev_block_0lvl; /// @param prev_block Hash of the previous block + dap_chain_hash_t prev_block_shard; /// @param prev_block Hash of the previous block + uint32_t shard_id; // Shard id + uint64_t nonce2; // Second NonCE for block mining inside the shard + }; + }; dap_chain_hash_t root_sections;/// @param root_main Main tree's root for all sections's hashes } DAP_ALIGN_PACKED header; uint8_t sections[]; // Sections diff --git a/dap_chain_mine.h b/dap_chain_mine.h index 71d1d59..98494cb 100644 --- a/dap_chain_mine.h +++ b/dap_chain_mine.h @@ -1,26 +1,3 @@ -/* - * 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/>. -*/ #pragma once diff --git a/dap_chain_node.c b/dap_chain_node.c new file mode 100644 index 0000000..216b750 --- /dev/null +++ b/dap_chain_node.c @@ -0,0 +1,23 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <naeper@demlabs.net> + * DeM Labs Inc. https://demlabs.net + + 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 "dap_chain_node.h" + diff --git a/dap_chain_node.h b/dap_chain_node.h new file mode 100644 index 0000000..37f73f8 --- /dev/null +++ b/dap_chain_node.h @@ -0,0 +1,40 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <naeper@demlabs.net> + * DeM Labs Inc. https://demlabs.net + + 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 <stdint.h> +#include <stddef.h> +#include <sys/socket.h> +#include <netinet/in.h> + +typedef union dap_chain_node_addr{ + uint64_t addr_raw; + uint8_t addr_oct[sizeof(uint64_t)]; // Access to selected octects +} dap_chain_node_addr_t; + +typedef struct dap_chain_node{ + dap_chain_node_addr_t addr; + dap_chain_node_addr_t *uplinks; + dap_chain_node_addr_t *downlinks; + struct in_addr *ipv4_addrs; + struct in6_addr *ipv6_addrs; +} dap_chain_node_t; diff --git a/dap_chain_srv.c b/dap_chain_srv.c index ca69d99..79e9ea1 100644 --- a/dap_chain_srv.c +++ b/dap_chain_srv.c @@ -22,5 +22,67 @@ along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ +#include "utlist.h" + #include "dap_chain_srv.h" +#define LOG_TAG "chain_srv" + +size_t m_uid_count; +dap_chain_srv_uid_t * m_uid; + +/** + * @brief dap_chain_srv_init + * @return + */ +int dap_chain_srv_init() +{ + m_uid = NULL; + m_uid_count = NULL; + return 0; +} + +/** + * @brief dap_chain_srv_deinit + */ +void dap_chain_srv_deinit() +{ + +} + +/** + * @brief dap_chain_srv_add + * @param a_srv + */ +void dap_chain_srv_add(dap_chain_srv_t * a_srv) +{ + +} + +/** + * @brief dap_chain_srv_get + * @param a_uid + * @return + */ +dap_chain_srv_t * dap_chain_srv_get( dap_chain_srv_uid_t a_uid) +{ + +} + +/** + * @brief dap_chain_srv_count + * @return + */ +const size_t dap_chain_srv_count() +{ + +} + +/** + * @brief dap_chain_srv_list + * @return + */ +const dap_chain_srv_uid_t * dap_chain_srv_list() +{ + +} diff --git a/dap_chain_srv.h b/dap_chain_srv.h index 8bf7f08..780be5f 100644 --- a/dap_chain_srv.h +++ b/dap_chain_srv.h @@ -22,3 +22,24 @@ along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ #pragma once + +#include "dap_chain_node.h" +#include "dap_chain_srv_pkt.h" + +typedef struct dap_chain_srv +{ + dap_chain_node_t * node; + dap_chain_srv_uid_t uid; // Unique ID for service. + + void * _internal; + void * _inhertor; +} dap_chain_srv_t; + +int dap_chain_srv_init(); +void dap_chain_srv_deinit(); + +void dap_chain_srv_add(dap_chain_srv_t * a_srv); +dap_chain_srv_t * dap_chain_srv_get( dap_chain_srv_uid_t a_uid); +const size_t dap_chain_srv_count(); +const dap_chain_srv_uid_t * dap_chain_srv_list(); + diff --git a/dap_chain_srv_pkt.c b/dap_chain_srv_pkt.c new file mode 100644 index 0000000..e7e590f --- /dev/null +++ b/dap_chain_srv_pkt.c @@ -0,0 +1,3 @@ +#include "dap_chain_srv_pkt.h" + +#define LOG_TAG "srv_pkt" diff --git a/dap_chain_srv_pkt.h b/dap_chain_srv_pkt.h new file mode 100644 index 0000000..0e731fb --- /dev/null +++ b/dap_chain_srv_pkt.h @@ -0,0 +1,35 @@ +/* + * 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/>. +*/ + +#pragma once + +#include <stdint.h> + +typedef uint64_t dap_chain_srv_uid_t; +typedef struct dap_chain_srv_pkt{ + struct { + dap_chain_srv_uid_t uid; + } __attribute__((packed)) header ; + uint8_t data[]; +} __attribute__((packed)) dap_chain_srv_pkt_t; -- GitLab