Skip to content
Snippets Groups Projects
Commit bf56a545 authored by Dmitriy A. Gerasimov's avatar Dmitriy A. Gerasimov
Browse files

[*] Renames

[-] pvt object usage
parent 63b5a2b1
No related branches found
No related tags found
1 merge request!24Support 3689
...@@ -7,7 +7,7 @@ set(DAP_CHAIN_NET_SRCS ...@@ -7,7 +7,7 @@ set(DAP_CHAIN_NET_SRCS
dap_chain_node_ctl.c dap_chain_node_ctl.c
dap_chain_node_cli.c dap_chain_node_cli.c
dap_chain_node_cli_cmd.c dap_chain_node_cli_cmd.c
dap_chain_node_cli_connect.c dap_chain_node_client.c
dap_chain_node_remote.c dap_chain_node_remote.c
) )
...@@ -17,7 +17,7 @@ set(DAP_CHAIN_NET_HEADERS ...@@ -17,7 +17,7 @@ set(DAP_CHAIN_NET_HEADERS
dap_chain_node_ctl.h dap_chain_node_ctl.h
dap_chain_node_cli.h dap_chain_node_cli.h
dap_chain_node_cli_cmd.h dap_chain_node_cli_cmd.h
dap_chain_node_cli_connect.h dap_chain_node_client.h
dap_chain_node_remote.h dap_chain_node_remote.h
) )
......
...@@ -41,8 +41,8 @@ typedef struct dap_chain_net{ ...@@ -41,8 +41,8 @@ typedef struct dap_chain_net{
uint8_t pvt[]; uint8_t pvt[];
} dap_chain_net_t; } dap_chain_net_t;
int dap_chain_net_init(); int dap_chain_net_init(void);
void dap_chain_net_deinit(); void dap_chain_net_deinit(void);
dap_chain_net_t * dap_chain_net_new (const char * a_id, const char * a_name, dap_chain_net_t * dap_chain_net_new (const char * a_id, const char * a_name,
const char* a_node_role , const char* a_node_name ); const char* a_node_role , const char* a_node_name );
......
...@@ -49,7 +49,7 @@ typedef int SOCKET; ...@@ -49,7 +49,7 @@ typedef int SOCKET;
#include "iputils/iputils.h" #include "iputils/iputils.h"
#include "dap_common.h" #include "dap_common.h"
#include "dap_chain_node_cli_cmd.h" #include "dap_chain_node_cli_cmd.h"
#include "dap_chain_node_cli_connect.h" #include "dap_chain_node_client.h"
#include "dap_chain_node_cli.h" #include "dap_chain_node_cli.h"
//#include "dap_chain_node_cli.h" //#include "dap_chain_node_cli.h"
...@@ -379,7 +379,7 @@ int dap_chain_node_cli_init(dap_config_t * g_config) ...@@ -379,7 +379,7 @@ int dap_chain_node_cli_init(dap_config_t * g_config)
//strcpy(server.sun_path, SOCKET_FILE); //strcpy(server.sun_path, SOCKET_FILE);
// init client for handshake // init client for handshake
chain_node_client_init(); dap_chain_node_client_init();
SOCKET sockfd; SOCKET sockfd;
...@@ -432,5 +432,5 @@ void dap_chain_node_cli_delete(void) ...@@ -432,5 +432,5 @@ void dap_chain_node_cli_delete(void)
closesocket(server_sockfd); closesocket(server_sockfd);
// deinit client for handshake // deinit client for handshake
chain_node_client_deinit(); dap_chain_node_client_deinit();
} }
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
//#include "dap_common.h" //#include "dap_common.h"
#include "dap_chain_node.h" #include "dap_chain_node.h"
#include "dap_chain_global_db.h" #include "dap_chain_global_db.h"
#include "dap_chain_node_cli_connect.h" #include "dap_chain_node_client.h"
#include "dap_chain_node_remote.h" #include "dap_chain_node_remote.h"
#include "dap_chain_node_cli_cmd.h" #include "dap_chain_node_cli_cmd.h"
...@@ -735,7 +735,7 @@ int com_node(int argc, const char ** argv, char **str_reply) ...@@ -735,7 +735,7 @@ int com_node(int argc, const char ** argv, char **str_reply)
} }
int timeout_ms = 100000; //100 sec. int timeout_ms = 100000; //100 sec.
// start handshake // start handshake
chain_node_client_t *client = chain_node_client_connect(node_info); dap_chain_node_client_t *client = dap_chain_node_client_connect(node_info);
if(!client) { if(!client) {
set_reply_text(str_reply, "can't connect"); set_reply_text(str_reply, "can't connect");
DAP_DELETE(node_info); DAP_DELETE(node_info);
...@@ -746,7 +746,7 @@ int com_node(int argc, const char ** argv, char **str_reply) ...@@ -746,7 +746,7 @@ int com_node(int argc, const char ** argv, char **str_reply)
if(res != 1) { if(res != 1) {
set_reply_text(str_reply, "no response from node"); set_reply_text(str_reply, "no response from node");
// clean client struct // clean client struct
chain_node_client_close(client); dap_chain_node_client_close(client);
DAP_DELETE(node_info); DAP_DELETE(node_info);
return -1; return -1;
} }
......
...@@ -29,13 +29,12 @@ ...@@ -29,13 +29,12 @@
#include "dap_common.h" #include "dap_common.h"
#include "dap_client.h" #include "dap_client.h"
#include "dap_client_pvt.h"
#include "dap_config.h" #include "dap_config.h"
#include "dap_events.h" #include "dap_events.h"
#include "dap_http_client_simple.h" #include "dap_http_client_simple.h"
#include "dap_chain_node_cli_connect.h" #include "dap_chain_node_client.h"
#define LOG_TAG "chain_node_cli_connect" #define LOG_TAG "dap_chain_node_client"
#define DAP_APP_NAME NODE_NETNAME"-node" #define DAP_APP_NAME NODE_NETNAME"-node"
#define SYSTEM_PREFIX "/opt/"DAP_APP_NAME #define SYSTEM_PREFIX "/opt/"DAP_APP_NAME
...@@ -43,7 +42,7 @@ ...@@ -43,7 +42,7 @@
static int listen_port_tcp = 8079; static int listen_port_tcp = 8079;
int chain_node_client_init(void) int dap_chain_node_client_init(void)
{ {
int res = dap_client_init(); int res = dap_client_init();
res = dap_http_client_simple_init(); res = dap_http_client_simple_init();
...@@ -62,7 +61,7 @@ int chain_node_client_init(void) ...@@ -62,7 +61,7 @@ int chain_node_client_init(void)
return res; return res;
} }
void chain_node_client_deinit() void dap_chain_node_client_deinit()
{ {
dap_http_client_simple_deinit(); dap_http_client_simple_deinit();
dap_client_deinit(); dap_client_deinit();
...@@ -82,7 +81,7 @@ static void stage_status_error_callback(dap_client_t *a_client, void *a_arg) ...@@ -82,7 +81,7 @@ static void stage_status_error_callback(dap_client_t *a_client, void *a_arg)
// callback for the end of handshake in dap_client_go_stage() / chain_node_client_connect() // callback for the end of handshake in dap_client_go_stage() / chain_node_client_connect()
static void a_stage_end_callback(dap_client_t *a_client, void *a_arg) static void a_stage_end_callback(dap_client_t *a_client, void *a_arg)
{ {
chain_node_client_t *client = a_client->_inheritor; dap_chain_node_client_t *client = a_client->_inheritor;
assert(client); assert(client);
if(client) { if(client) {
pthread_mutex_lock(&client->wait_mutex); pthread_mutex_lock(&client->wait_mutex);
...@@ -97,21 +96,20 @@ static void a_stage_end_callback(dap_client_t *a_client, void *a_arg) ...@@ -97,21 +96,20 @@ static void a_stage_end_callback(dap_client_t *a_client, void *a_arg)
* *
* return a connection handle, or NULL, if an error * return a connection handle, or NULL, if an error
*/ */
chain_node_client_t* chain_node_client_connect(dap_chain_node_info_t *node_info) dap_chain_node_client_t* dap_chain_node_client_connect(dap_chain_node_info_t *node_info)
{ {
if(!node_info) if(!node_info)
return NULL; return NULL;
chain_node_client_t *client = DAP_NEW_Z(chain_node_client_t); dap_chain_node_client_t *l_node_client = DAP_NEW_Z(dap_chain_node_client_t);
client->state = NODE_CLIENT_STATE_INIT; l_node_client->state = NODE_CLIENT_STATE_INIT;
pthread_condattr_t attr; pthread_condattr_t attr;
pthread_condattr_init(&attr); pthread_condattr_init(&attr);
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC); pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
pthread_cond_init(&client->wait_cond, &attr); pthread_cond_init(&l_node_client->wait_cond, &attr);
pthread_mutex_init(&client->wait_mutex, NULL); pthread_mutex_init(&l_node_client->wait_mutex, NULL);
client->a_events = dap_events_new(); l_node_client->events = dap_events_new();
client->a_client = dap_client_new(client->a_events, stage_status_callback, stage_status_error_callback); l_node_client->client = dap_client_new(l_node_client->events, stage_status_callback, stage_status_error_callback);
client->a_client->_inheritor = client; l_node_client->client->_inheritor = l_node_client;
dap_client_pvt_t *l_client_internal = DAP_CLIENT_PVT(client->a_client);
int hostlen = 128; int hostlen = 128;
char host[hostlen]; char host[hostlen];
...@@ -127,34 +125,31 @@ chain_node_client_t* chain_node_client_connect(dap_chain_node_info_t *node_info) ...@@ -127,34 +125,31 @@ chain_node_client_t* chain_node_client_connect(dap_chain_node_info_t *node_info)
} }
// address not defined // address not defined
if(!strcmp(host, "::")) { if(!strcmp(host, "::")) {
chain_node_client_close(client); dap_chain_node_client_close(l_node_client);
return NULL; return NULL;
} }
l_client_internal->uplink_addr = strdup(host); dap_client_set_uplink( l_node_client->client, strdup(host), listen_port_tcp );
l_client_internal->uplink_port = listen_port_tcp; // reads from settings, default 8079 dap_client_stage_t a_stage_target = STAGE_STREAM_STREAMING;
l_client_internal->uplink_protocol_version = DAP_PROTOCOL_VERSION;
dap_client_stage_t a_stage_target = STAGE_ENC_INIT;
client->state = NODE_CLIENT_STATE_CONNECT; l_node_client->state = NODE_CLIENT_STATE_CONNECT;
// Handshake // Handshake
dap_client_go_stage(client->a_client, a_stage_target, a_stage_end_callback); dap_client_go_stage(l_node_client->client, a_stage_target, a_stage_end_callback);
return client; return l_node_client;
} }
/** /**
* Close connection to server, delete chain_node_client_t *client * Close connection to server, delete chain_node_client_t *client
*/ */
void chain_node_client_close(chain_node_client_t *client) void dap_chain_node_client_close(dap_chain_node_client_t *a_client)
{ {
if(client) { if(a_client) {
// clean client // clean client
dap_client_pvt_t *l_client_internal = DAP_CLIENT_PVT(client->a_client); dap_client_delete(a_client->client);
DAP_DELETE(l_client_internal->uplink_addr); dap_events_delete(a_client->events);
dap_client_delete(client->a_client); pthread_cond_destroy(&a_client->wait_cond);
dap_events_delete(client->a_events); pthread_mutex_destroy(&a_client->wait_mutex);
pthread_cond_destroy(&client->wait_cond); DAP_DELETE(a_client);
pthread_mutex_destroy(&client->wait_mutex);
DAP_DELETE(client);
} }
} }
...@@ -165,7 +160,7 @@ void chain_node_client_close(chain_node_client_t *client) ...@@ -165,7 +160,7 @@ void chain_node_client_close(chain_node_client_t *client)
* waited_state state which we will wait, sample NODE_CLIENT_STATE_CONNECT or NODE_CLIENT_STATE_SENDED * waited_state state which we will wait, sample NODE_CLIENT_STATE_CONNECT or NODE_CLIENT_STATE_SENDED
* return -1 false, 0 timeout, 1 end of connection or sending data * return -1 false, 0 timeout, 1 end of connection or sending data
*/ */
int chain_node_client_wait(chain_node_client_t *client, int waited_state, int timeout_ms) int chain_node_client_wait(dap_chain_node_client_t *client, int waited_state, int timeout_ms)
{ {
int ret = -1; int ret = -1;
if(!client) if(!client)
......
...@@ -38,31 +38,39 @@ enum { ...@@ -38,31 +38,39 @@ enum {
NODE_CLIENT_STATE_END NODE_CLIENT_STATE_END
}; };
typedef struct dap_chain_node_client dap_chain_node_client_t;
typedef void (*dap_chain_node_client_callback_t) (dap_chain_node_client_t *, void*);
// state for a client connection // state for a client connection
typedef struct chain_node_client { typedef struct dap_chain_node_client {
int state; int state;
dap_client_t *a_client; dap_client_t *client;
dap_events_t *a_events; dap_events_t *events;
dap_chain_node_client_callback_t callback_stream_connected;
pthread_cond_t wait_cond; pthread_cond_t wait_cond;
pthread_mutex_t wait_mutex; pthread_mutex_t wait_mutex;
} chain_node_client_t; } dap_chain_node_client_t;
int chain_node_client_init(void); int dap_chain_node_client_init(void);
void chain_node_client_deinit(); void dap_chain_node_client_deinit();
/** /**
* Create connection to server * Create handshake to server
* *
* return a connection handle, or NULL, if an error * return a connection handle, or NULL, if an error
*/ */
chain_node_client_t* chain_node_client_connect(dap_chain_node_info_t *node_info); dap_chain_node_client_t* dap_chain_node_client_connect(dap_chain_node_info_t *node_info);
/** /**
* Close connection to server, delete chain_node_client_t *client * Close connection to server, delete chain_node_client_t *client
*/ */
void chain_node_client_close(chain_node_client_t *client); void dap_chain_node_client_close(dap_chain_node_client_t *client);
/** /**
* wait for the complete of request * wait for the complete of request
...@@ -71,5 +79,5 @@ void chain_node_client_close(chain_node_client_t *client); ...@@ -71,5 +79,5 @@ void chain_node_client_close(chain_node_client_t *client);
* waited_state state which we will wait, sample NODE_CLIENT_STATE_CONNECT or NODE_CLIENT_STATE_SENDED * waited_state state which we will wait, sample NODE_CLIENT_STATE_CONNECT or NODE_CLIENT_STATE_SENDED
* return -1 false, 0 timeout, 1 end of connection or sending data * return -1 false, 0 timeout, 1 end of connection or sending data
*/ */
int chain_node_client_wait(chain_node_client_t *client, int waited_state, int timeout_ms); int chain_node_client_wait(dap_chain_node_client_t *client, int waited_state, int timeout_ms);
...@@ -37,7 +37,7 @@ static pthread_mutex_t connect_list_mutex = PTHREAD_MUTEX_INITIALIZER; ...@@ -37,7 +37,7 @@ static pthread_mutex_t connect_list_mutex = PTHREAD_MUTEX_INITIALIZER;
/** /**
* Add new established connection in the list * Add new established connection in the list
*/ */
bool chain_node_client_list_add(chain_node_client_t *client) bool chain_node_client_list_add(dap_chain_node_client_t *client)
{ {
if(!client) if(!client)
return false; return false;
...@@ -50,7 +50,7 @@ bool chain_node_client_list_add(chain_node_client_t *client) ...@@ -50,7 +50,7 @@ bool chain_node_client_list_add(chain_node_client_t *client)
/** /**
* Delete established connection from the list * Delete established connection from the list
*/ */
bool chain_node_client_list_del(chain_node_client_t *client) bool chain_node_client_list_del(dap_chain_node_client_t *client)
{ {
pthread_mutex_lock(&connect_list_mutex); pthread_mutex_lock(&connect_list_mutex);
GList *list = g_list_find(connect_list, client); GList *list = g_list_find(connect_list, client);
...@@ -70,10 +70,10 @@ bool chain_node_client_list_del(chain_node_client_t *client) ...@@ -70,10 +70,10 @@ bool chain_node_client_list_del(chain_node_client_t *client)
* *
* return client, or NULL if the position is off the end of the list * return client, or NULL if the position is off the end of the list
*/ */
chain_node_client_t* chain_node_client_list_get_item(int n) dap_chain_node_client_t* chain_node_client_list_get_item(int n)
{ {
pthread_mutex_lock(&connect_list_mutex); pthread_mutex_lock(&connect_list_mutex);
chain_node_client_t *client = g_list_nth_data(connect_list, (guint) n); dap_chain_node_client_t *client = g_list_nth_data(connect_list, (guint) n);
pthread_mutex_unlock(&connect_list_mutex); pthread_mutex_unlock(&connect_list_mutex);
return client; return client;
} }
......
...@@ -23,17 +23,17 @@ ...@@ -23,17 +23,17 @@
#include <stdbool.h> #include <stdbool.h>
#include "dap_chain_node_cli_connect.h" #include "dap_chain_node_client.h"
/** /**
* Add new established connection in the list * Add new established connection in the list
*/ */
bool chain_node_client_list_add(chain_node_client_t *client); bool chain_node_client_list_add(dap_chain_node_client_t *client);
/** /**
* Delete established connection from the list * Delete established connection from the list
*/ */
bool chain_node_client_list_del(chain_node_client_t *client); bool chain_node_client_list_del(dap_chain_node_client_t *client);
/** /**
* Get one established connection * Get one established connection
...@@ -42,7 +42,7 @@ bool chain_node_client_list_del(chain_node_client_t *client); ...@@ -42,7 +42,7 @@ bool chain_node_client_list_del(chain_node_client_t *client);
* *
* return client, or NULL if the position is off the end of the list * return client, or NULL if the position is off the end of the list
*/ */
chain_node_client_t* chain_node_client_list_get_item(int n); dap_chain_node_client_t* chain_node_client_list_get_item(int n);
/** /**
* Get the number of established connections * Get the number of established connections
......
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