diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..98d4f68d647afa6ae43250cc96b29021c2c1d6f5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[submodule "libdap"] + path = libdap + url = https://github.com/demlabsinc/libdap.git +[submodule "libdap-server"] + path = libdap-server + url = https://github.com/demlabsinc/libdap-server.git +[submodule "libdap-chain"] + path = libdap-chain + url = https://github.com/demlabsinc/libdap-chain.git +[submodule "libdap-stream"] + path = libdap-stream + url = https://github.com/demlabsinc/libdap-stream.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7b7dc51aff466bb08c52e1294d3a58599caa481e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,43 @@ +project(kelvin-node C) +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_VERBOSE_MAKEFILE ON) +set(CMAKE_COLOR_MAKEFILE ON) +set (CMAKE_CXX_STANDARD 11) + +add_subdirectory(libdap) +#add_subdirectory(libdap-chain) +add_subdirectory(libdap-server) +add_subdirectory(libdap-stream) + +add_definitions ("-DDAP_SERVER") + +include_directories("${INCLUDE_DIRECTORIES} ${dap_core_INCLUDE_DIRS}") +include_directories("${INCLUDE_DIRECTORIES} ${dap_http_INCLUDE_DIRS}") +include_directories("${INCLUDE_DIRECTORIES} ${dap_crypto_INCLUDE_DIRS}") +include_directories("${INCLUDE_DIRECTORIES} ${dap_udp_server_INCLUDE_DIRS}") +include_directories("${INCLUDE_DIRECTORIES} ${dap_enc_server_INCLUDE_DIRS}") +include_directories("${INCLUDE_DIRECTORIES} ${dap_http_server_INCLUDE_DIRS}") +include_directories("${INCLUDE_DIRECTORIES} ${dap_client_INCLUDE_DIRS}") +#include_directories("${INCLUDE_DIRECTORIES} ${dap-chain_INCLUDE_DIRS}") +include_directories("${INCLUDE_DIRECTORIES} ${dap_core_server_INCLUDE_DIRS}") +include_directories("${INCLUDE_DIRECTORIES} ${dap_stream_INCLUDE_DIRS}") +include_directories("${INCLUDE_DIRECTORIES} ${dap_session_INCLUDE_DIRS}") +add_definitions ("${dap_enc_server_DEFINITIONS}") +add_definitions ("${dap_http_server_DEFINITIONS}") +add_definitions ("${dap_udp_server_DEFINITIONS}") +add_definitions ("${dap_http_DEFINITIONS}") +add_definitions ("${dap_core_DEFINITIONS}") +add_definitions ("${dap_crypto_DEFINITIONS}") +add_definitions ("${dap_client_DEFINITIONS}") +#add_definitions ("${dap-chain_DEFINITIONS}") +add_definitions ("${dap_core_server_DEFINITIONS}") +add_definitions ("${dap_stream_DEFINITIONS}") +add_definitions ("${dap_session_DEFINITIONS}") +set(SOURCES sources/kelvin-node.c sources/node_manager.c) +set(HEADERS sources/node_manager.h) + + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ") +add_executable(${PROJECT_NAME} "sources/kelvin-node.c" ${HEADERS} ${SOURCES}) +target_link_libraries(${PROJECT_NAME} dap_http_server dap_enc_server dap_core_server dap_udp_server dap_client dap_crypto dap_core dap_http dap_session dap_stream m pthread) diff --git a/config/node.cfg b/config/node.cfg new file mode 100644 index 0000000000000000000000000000000000000000..b43630a498acf715e747526a875bcbd4a6ffcabd --- /dev/null +++ b/config/node.cfg @@ -0,0 +1,3 @@ +[general] +port = 56001 + diff --git a/libdap b/libdap new file mode 160000 index 0000000000000000000000000000000000000000..8fd1d21201bf36461bd40249236d27edbd4dff73 --- /dev/null +++ b/libdap @@ -0,0 +1 @@ +Subproject commit 8fd1d21201bf36461bd40249236d27edbd4dff73 diff --git a/libdap-chain b/libdap-chain new file mode 160000 index 0000000000000000000000000000000000000000..62b75944b3114c1abb1fa5ebc3b58b78bfe33338 --- /dev/null +++ b/libdap-chain @@ -0,0 +1 @@ +Subproject commit 62b75944b3114c1abb1fa5ebc3b58b78bfe33338 diff --git a/libdap-server b/libdap-server new file mode 160000 index 0000000000000000000000000000000000000000..b7c3f362f85be6695d8fe431dcf6b74ec1944793 --- /dev/null +++ b/libdap-server @@ -0,0 +1 @@ +Subproject commit b7c3f362f85be6695d8fe431dcf6b74ec1944793 diff --git a/libdap-stream b/libdap-stream new file mode 160000 index 0000000000000000000000000000000000000000..7194c7a9ed7f234ad30aeba4f508ee9f027cd915 --- /dev/null +++ b/libdap-stream @@ -0,0 +1 @@ +Subproject commit 7194c7a9ed7f234ad30aeba4f508ee9f027cd915 diff --git a/sources/kelvin-node.c b/sources/kelvin-node.c new file mode 100644 index 0000000000000000000000000000000000000000..447d052365dae57104470538a1c7700954a6a45e --- /dev/null +++ b/sources/kelvin-node.c @@ -0,0 +1,58 @@ +/* + Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc + 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 Lesser 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + + +#include <errno.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include "uthash.h" +#include "dap_udp_server.h" +#include "dap_udp_client.h" +#include "dap_http.h" +#include "stream.h" +#include "node_manager.h" + + + + + + +int main(int argc, char **argv) { + printf("Kelvin Node version 0.1 \n"); + if (argc > 1) + { + char *l_config_name = strdup(argv[1]); + + node_manager_init(); + + node_manager_t* manager = new_node_manager(l_config_name); + node_manager_start(manager); + + node_manager_deinit(); + free(l_config_name); + } + else + puts("Please, specify config file path."); + + return 0; +} \ No newline at end of file diff --git a/sources/node_manager.c b/sources/node_manager.c new file mode 100644 index 0000000000000000000000000000000000000000..dcc98cf5b663eb104cafd419058fda400aa604bf --- /dev/null +++ b/sources/node_manager.c @@ -0,0 +1,130 @@ +/* + Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc + 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 Lesser 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "node_manager.h" +#define LOG_TAG "main" + + +void client_new(dap_udp_client_t *client,void * arg){ + printf("Client connected"); +} + +void client_read(dap_udp_client_t *client,void * arg){ + printf("Client read \n"); + unsigned char* data = (char*)malloc(client->buf_in_size); + data[client->buf_in_size] = 0; + if(client->_ready_to_read) + { + dap_udp_client_read(client,data,client->buf_in_size); + } + puts(data); + char outbox[] = "ping"; + dap_udp_client_write(client,outbox,strlen(outbox)); + dap_udp_client_ready_to_write(client,true); + free(data); +} + +void client_write(dap_udp_client_t *client,void * arg){ + printf("Client write"); +} + +void client_disconnect(struct dap_client_remote *client,void * arg){ + printf("Client disconnect"); +} + +/** + * @brief node_manager_init Init all modules + * @return Zero if ok or error code + */ +int node_manager_init(){ + if(dap_common_init("build/log.txt")!=0){ + log_it(L_CRITICAL,"Can't init common functions module"); + return -2; + } + if(dap_config_init("build/config")!=0){ + log_it(L_CRITICAL,"Can't init configurations module"); + return -1; + } + if(dap_enc_init()!=0){ + log_it(L_CRITICAL,"Can't init encryption module"); + return -56; + } + if(dap_enc_key_init()!=0){ + log_it(L_CRITICAL,"Can't init encryption key module"); + return -57; + } + if(dap_udp_server_init()!=0){ + log_it(L_CRITICAL,"Can't init udp server module"); + return -4; + } + if(dap_udp_client_init()!=0){ + log_it(L_CRITICAL,"Can't init udp client module"); + return -4; + } + return 0; +} + +/** + * @brief dap_server_deinit Deinit modules + */ +void node_manager_deinit(){ + dap_udp_server_deinit(); + dap_udp_client_deinit(); + dap_enc_key_deinit(); + dap_enc_deinit(); + common_deinit(); + dap_config_deinit(); +} + +/** + * @brief new_node_manager Create node manager structure + * @return Manager instance + */ +node_manager_t* new_node_manager(char* config_file){ + node_manager_t* manager = (node_manager_t*)malloc(sizeof(node_manager_t)); + manager->l_config = dap_config_open(config_file); + return manager; +} + +/** + * @brief node_manager_start Start node work + * @param manager Manager instance + */ +void node_manager_start(node_manager_t* manager){ + int port = 0; + if (manager->l_config) + port = atoi(dap_config_get_item_str(manager->l_config, "general", "port")); + else{ + log_it(L_CRITICAL,"Unable to find config file"); + return; + } + if(port == 0){ + log_it(L_CRITICAL,"Unable to read port value"); + return; + } + dap_udp_server_t* sh = manager->sh; + sh = dap_udp_server_listen(port); + sh->client_read_callback = *client_read; + sh->client_write_callback = *client_write; + sh->client_new_callback = *client_new; + sh->client_delete_callback = *client_disconnect; + dap_udp_server_loop(sh); + dap_udp_server_delete(sh); +} \ No newline at end of file diff --git a/sources/node_manager.h b/sources/node_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..a4624f3aa1f2ee2beb9855dc712bab0a5c5c76b2 --- /dev/null +++ b/sources/node_manager.h @@ -0,0 +1,52 @@ +/* + Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc + 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 Lesser 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once +#ifndef _NODE_MANAGER_H_ +#define _NODE_MANAGER_H_ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include "dap_udp_server.h" +#include "dap_udp_client.h" +#include "dap_common.h" +#include "dap_config.h" +#include "dap_enc.h" +#include "dap_enc_key.h" + + +typedef struct node_manager{ + dap_udp_server_t* sh; + dap_config_t *l_config; + +} node_manager_t; + + +extern int node_manager_init(); + +node_manager_t* new_node_manager(char* config_file); // Create new manager structure + +extern void node_manager_deinit(); + +extern void node_manager_start(node_manager_t* manager); // Start manager work + + +#endif \ No newline at end of file