Skip to content
Snippets Groups Projects
Unverified Commit 6d776ae7 authored by Dmitriy A. Gerasimov's avatar Dmitriy A. Gerasimov Committed by GitHub
Browse files

Merge pull request #1 from IvanDeniskin/master

Added submodules, node manager, modules initialization, udp server example and config file.
parents 8052823d 1b045af6
No related branches found
No related tags found
No related merge requests found
[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
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)
[general]
port = 56001
Subproject commit 8fd1d21201bf36461bd40249236d27edbd4dff73
Subproject commit 62b75944b3114c1abb1fa5ebc3b58b78bfe33338
Subproject commit b7c3f362f85be6695d8fe431dcf6b74ec1944793
Subproject commit 7194c7a9ed7f234ad30aeba4f508ee9f027cd915
/*
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
/*
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
/*
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
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