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

Merge pull request #2 from IvanDeniskin/master

Http handshake test
parents b40ad6c3 200d8608
No related branches found
No related tags found
No related merge requests found
...@@ -5,39 +5,42 @@ set(CMAKE_VERBOSE_MAKEFILE ON) ...@@ -5,39 +5,42 @@ set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_COLOR_MAKEFILE ON) set(CMAKE_COLOR_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 11) set (CMAKE_CXX_STANDARD 11)
add_definitions ("-DDAP_SERVER")
add_subdirectory(libdap-server)
add_subdirectory(libdap) add_subdirectory(libdap)
#add_subdirectory(libdap-chain) #add_subdirectory(libdap-chain)
add_subdirectory(libdap-server)
add_subdirectory(libdap-stream) add_subdirectory(libdap-stream)
add_definitions ("-DDAP_SERVER")
include_directories("${INCLUDE_DIRECTORIES} ${dap_core_INCLUDE_DIRS}") include_directories("${INCLUDE_DIRECTORIES} ${dap_core_INCLUDE_DIRS}")
include_directories("${INCLUDE_DIRECTORIES} ${dap_http_INCLUDE_DIRS}") include_directories("${INCLUDE_DIRECTORIES} ${dap_http_INCLUDE_DIRS}")
include_directories("${INCLUDE_DIRECTORIES} ${dap_crypto_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_enc_server_INCLUDE_DIRS}")
include_directories("${INCLUDE_DIRECTORIES} ${dap_http_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_client_INCLUDE_DIRS}")
#include_directories("${INCLUDE_DIRECTORIES} ${dap-chain_INCLUDE_DIRS}") #include_directories("${INCLUDE_DIRECTORIES} ${dap-chain_INCLUDE_DIRS}")
include_directories("${INCLUDE_DIRECTORIES} ${dap_core_server_INCLUDE_DIRS}") include_directories("${INCLUDE_DIRECTORIES} ${dap_core_server_INCLUDE_DIRS}")
include_directories("${INCLUDE_DIRECTORIES} ${dap_stream_INCLUDE_DIRS}") include_directories("${INCLUDE_DIRECTORIES} ${dap_udp_server_INCLUDE_DIRS}")
include_directories("${INCLUDE_DIRECTORIES} ${dap_session_INCLUDE_DIRS}") include_directories("${INCLUDE_DIRECTORIES} ${dap_session_INCLUDE_DIRS}")
add_definitions ("${dap_enc_server_DEFINITIONS}") include_directories("${INCLUDE_DIRECTORIES} ${dap_stream_INCLUDE_DIRS}")
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_core_DEFINITIONS}")
add_definitions ("${dap_crypto_DEFINITIONS}") add_definitions ("${dap_crypto_DEFINITIONS}")
add_definitions ("${dap_client_DEFINITIONS}") add_definitions ("${dap_client_DEFINITIONS}")
add_definitions ("${dap_enc_server_DEFINITIONS}")
add_definitions ("${dap_http_server_DEFINITIONS}")
add_definitions ("${dap_http_DEFINITIONS}")
#add_definitions ("${dap-chain_DEFINITIONS}") #add_definitions ("${dap-chain_DEFINITIONS}")
add_definitions ("${dap_core_server_DEFINITIONS}") add_definitions ("${dap_core_server_DEFINITIONS}")
add_definitions ("${dap_stream_DEFINITIONS}") add_definitions ("${dap_udp_server_DEFINITIONS}")
add_definitions ("${dap_session_DEFINITIONS}") add_definitions ("${dap_session_DEFINITIONS}")
set(SOURCES sources/kelvin-node.c sources/node_manager.c) add_definitions ("${dap_stream_DEFINITIONS}")
set(SOURCES sources/kelvin-node.c sources/node_manager.c )
set(HEADERS sources/node_manager.h) set(HEADERS sources/node_manager.h)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
add_executable(${PROJECT_NAME} "sources/kelvin-node.c" ${HEADERS} ${SOURCES}) add_executable(${PROJECT_NAME} "sources/kelvin-node.c" ${HEADERS} ${SOURCES} ${CRYPTO_SRCS})
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) target_link_libraries(${PROJECT_NAME} dap_http_server dap_core_server dap_udp_server dap_session dap_crypto dap_client dap_core dap_http dap_enc_server dap_stream m pthread)
\ No newline at end of file
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License 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/>. along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define DAP_SERVER
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
...@@ -26,18 +26,32 @@ ...@@ -26,18 +26,32 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "uthash.h" #include "uthash.h"
#include "dap_udp_server.h"
#include "dap_udp_client.h"
#include "dap_http.h" #include "dap_http.h"
#include "stream.h" #include "stream.h"
#include "node_manager.h" #include "node_manager.h"
/*struct ev_loop *repeat_loop;
ev_timer timeout_watcher;
static void repeat_cb (EV_P_ ev_timer *w, int revents){
puts("repeat");
}*/
int main(int argc, char **argv) { int main(int argc, char **argv) {
/* repeat_loop = EV_DEFAULT;
ev_timer_init (&timeout_watcher, repeat_cb, 3, 3);
ev_timer_start (repeat_loop, &timeout_watcher);
ev_run (repeat_loop, 0);*/
printf("Kelvin Node version 0.1 \n"); printf("Kelvin Node version 0.1 \n");
if (argc > 1) if (argc > 1)
{ {
...@@ -45,8 +59,9 @@ int main(int argc, char **argv) { ...@@ -45,8 +59,9 @@ int main(int argc, char **argv) {
node_manager_init(); node_manager_init();
node_manager_t* manager = new_node_manager(l_config_name); // node_manager_t* manager = new_node_manager(l_config_name);
node_manager_start(manager); // node_manager_start(manager);
node_manager_start_stream();
node_manager_deinit(); node_manager_deinit();
free(l_config_name); free(l_config_name);
......
...@@ -19,33 +19,60 @@ ...@@ -19,33 +19,60 @@
*/ */
#include "node_manager.h" #include "node_manager.h"
#include "dap_http.h"
#include "stream.h"
#include "stream_ch_pkt.h"
#define LOG_TAG "main" #define LOG_TAG "main"
void client_new(dap_udp_client_t *client,void * arg){
void channel_new(struct stream_ch* ch,void* arg){
puts("Channel new");
}
void channel_delete(struct stream_ch* ch,void* arg){
puts("Channel delete");
}
void channel_packet_in(struct stream_ch* ch,void* arg){
stream_ch_pkt_t * ch_pkt = arg;
char* data = (char*)malloc(ch_pkt->hdr.size);
memcpy(data,ch_pkt->data,ch_pkt->hdr.size);
printf("Income data: %s from %s \n",data,itoa(ch->stream->conn_udp->host_key));
stream_ch_set_ready_to_write(ch,false);
stream_ch_pkt_write_f(ch, 1, "ping");
stream_ch_set_ready_to_write(ch,true);
}
void channel_packet_out(struct stream_ch* ch,void* arg){
stream_ch_set_ready_to_write(ch,false);
}
void client_new(dap_client_remote_t *client,void * arg){
printf("Client connected"); printf("Client connected");
} }
void client_read(dap_udp_client_t *client,void * arg){ void client_read(dap_client_remote_t *client,void * arg){
printf("Client read \n"); printf("Client read \n");
unsigned char* data = (char*)malloc(client->buf_in_size); unsigned char* data = (char*)malloc(client->buf_in_size);
data[client->buf_in_size] = 0; data[client->buf_in_size] = 0;
if(client->_ready_to_read) if(client->_ready_to_read)
{ {
dap_udp_client_read(client,data,client->buf_in_size); dap_client_read(client,data,client->buf_in_size);
} }
puts(data); puts(data);
char outbox[] = "ping"; char outbox[] = "ping";
dap_udp_client_write(client,outbox,strlen(outbox)); dap_client_write(client,outbox,strlen(outbox));
dap_udp_client_ready_to_write(client,true); dap_udp_client_ready_to_write(client,true);
free(data); free(data);
} }
void client_write(dap_udp_client_t *client,void * arg){ void client_write(dap_client_remote_t *client,void * arg){
printf("Client write"); printf("Client write");
} }
void client_disconnect(struct dap_client_remote *client,void * arg){ void client_disconnect(dap_client_remote_t *client,void * arg){
printf("Client disconnect"); printf("Client disconnect");
} }
...@@ -70,14 +97,18 @@ int node_manager_init(){ ...@@ -70,14 +97,18 @@ int node_manager_init(){
log_it(L_CRITICAL,"Can't init encryption key module"); log_it(L_CRITICAL,"Can't init encryption key module");
return -57; return -57;
} }
if(dap_udp_server_init()!=0){ if(dap_server_init()!=0){
log_it(L_CRITICAL,"Can't init udp server module"); log_it(L_CRITICAL,"Can't init udp server module");
return -4; return -4;
} }
if(dap_udp_client_init()!=0){ if(dap_client_init()!=0){
log_it(L_CRITICAL,"Can't init udp client module"); log_it(L_CRITICAL,"Can't init udp client module");
return -4; return -4;
} }
stream_init();
stream_session_init();
dap_http_init();
dap_http_simple_module_init();
return 0; return 0;
} }
...@@ -85,8 +116,9 @@ int node_manager_init(){ ...@@ -85,8 +116,9 @@ int node_manager_init(){
* @brief dap_server_deinit Deinit modules * @brief dap_server_deinit Deinit modules
*/ */
void node_manager_deinit(){ void node_manager_deinit(){
dap_udp_server_deinit(); stream_session_deinit();
dap_udp_client_deinit(); dap_server_deinit();
dap_client_deinit();
dap_enc_key_deinit(); dap_enc_key_deinit();
dap_enc_deinit(); dap_enc_deinit();
common_deinit(); common_deinit();
...@@ -119,7 +151,7 @@ void node_manager_start(node_manager_t* manager){ ...@@ -119,7 +151,7 @@ void node_manager_start(node_manager_t* manager){
log_it(L_CRITICAL,"Unable to read port value"); log_it(L_CRITICAL,"Unable to read port value");
return; return;
} }
dap_udp_server_t* sh = manager->sh; dap_server_t* sh = manager->sh;
sh = dap_udp_server_listen(port); sh = dap_udp_server_listen(port);
sh->client_read_callback = *client_read; sh->client_read_callback = *client_read;
sh->client_write_callback = *client_write; sh->client_write_callback = *client_write;
...@@ -127,4 +159,13 @@ void node_manager_start(node_manager_t* manager){ ...@@ -127,4 +159,13 @@ void node_manager_start(node_manager_t* manager){
sh->client_delete_callback = *client_disconnect; sh->client_delete_callback = *client_disconnect;
dap_udp_server_loop(sh); dap_udp_server_loop(sh);
dap_udp_server_delete(sh); dap_udp_server_delete(sh);
}
\ No newline at end of file
}
void node_manager_start_stream(){
dap_server_t* server = dap_server_listen("localhost",56001,DAP_SERVER_TCP);
dap_http_new(server,"HTTP-serv");
enc_http_add_proc(DAP_HTTP(server),"/handshake");
dap_server_loop(server);
}
...@@ -25,16 +25,17 @@ ...@@ -25,16 +25,17 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "dap_udp_server.h" #include "dap_server.h"
#include "dap_udp_client.h"
#include "dap_common.h" #include "dap_common.h"
#include "dap_config.h" #include "dap_config.h"
#include "dap_udp_server.h"
#include "dap_udp_client.h"
#include "dap_enc.h" #include "dap_enc.h"
#include "dap_enc_key.h" #include "dap_enc_key.h"
typedef struct node_manager{ typedef struct node_manager{
dap_udp_server_t* sh; dap_server_t* sh;
dap_config_t *l_config; dap_config_t *l_config;
} node_manager_t; } node_manager_t;
......
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