Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cellframe-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
18
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cellframe
cellframe-sdk
Commits
01081038
Commit
01081038
authored
3 years ago
by
dmitriy.gerasimov
Browse files
Options
Downloads
Patches
Plain Diff
[+] Added check for existance of dap_chain_node_client_t inside timer
parent
e332fd30
No related branches found
No related tags found
1 merge request
!326
Release 2.9
Pipeline
#7657
passed with stage
in 4 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/net/dap_chain_node_client.c
+51
-4
51 additions, 4 deletions
modules/net/dap_chain_node_client.c
modules/net/include/dap_chain_node_client.h
+1
-0
1 addition, 0 deletions
modules/net/include/dap_chain_node_client.h
with
52 additions
and
4 deletions
modules/net/dap_chain_node_client.c
+
51
−
4
View file @
01081038
...
@@ -29,7 +29,6 @@
...
@@ -29,7 +29,6 @@
#include
<errno.h>
#include
<errno.h>
#include
<assert.h>
#include
<assert.h>
#include
<string.h>
#include
<string.h>
#include
<json-c/json.h>
#ifdef WIN32
#ifdef WIN32
#include
<winsock2.h>
#include
<winsock2.h>
...
@@ -44,12 +43,16 @@
...
@@ -44,12 +43,16 @@
#include
<arpa/inet.h>
#include
<arpa/inet.h>
#endif
#endif
#include
<json-c/json.h>
#include
"uthash.h"
#include
"dap_common.h"
#include
"dap_common.h"
#include
"dap_client.h"
#include
"dap_client.h"
#include
"dap_config.h"
#include
"dap_config.h"
#include
"dap_events.h"
#include
"dap_events.h"
#include
"dap_timerfd.h"
#include
"dap_timerfd.h"
#include
"dap_hash.h"
#include
"dap_hash.h"
#include
"dap_uuid.h"
//#include "dap_http_client_simple.h"
//#include "dap_http_client_simple.h"
#include
"dap_client_pvt.h"
#include
"dap_client_pvt.h"
#include
"dap_chain_global_db_remote.h"
#include
"dap_chain_global_db_remote.h"
...
@@ -73,6 +76,14 @@
...
@@ -73,6 +76,14 @@
#define LOG_TAG "dap_chain_node_client"
#define LOG_TAG "dap_chain_node_client"
typedef
struct
dap_chain_node_client_handle
{
uint128_t
uuid
;
dap_chain_node_client_t
*
client
;
UT_hash_handle
hh
;
}
dap_chain_node_client_handle_t
;
static
dap_chain_node_client_handle_t
*
s_clients
=
NULL
;
//static int listen_port_tcp = 8079;
//static int listen_port_tcp = 8079;
...
@@ -106,6 +117,11 @@ int dap_chain_node_client_init(void)
...
@@ -106,6 +117,11 @@ int dap_chain_node_client_init(void)
*/
*/
void
dap_chain_node_client_deinit
()
void
dap_chain_node_client_deinit
()
{
{
dap_chain_node_client_handle_t
*
l_client
=
NULL
,
*
l_tmp
=
NULL
;
HASH_ITER
(
hh
,
s_clients
,
l_client
,
l_tmp
){
HASH_DEL
(
s_clients
,
l_client
);
DAP_DELETE
(
l_client
);
}
//dap_http_client_simple_deinit();
//dap_http_client_simple_deinit();
dap_client_deinit
();
dap_client_deinit
();
}
}
...
@@ -148,7 +164,13 @@ static void s_stage_status_error_callback(dap_client_t *a_client, void *a_arg)
...
@@ -148,7 +164,13 @@ static void s_stage_status_error_callback(dap_client_t *a_client, void *a_arg)
#endif
#endif
pthread_mutex_unlock
(
&
l_node_client
->
wait_mutex
);
pthread_mutex_unlock
(
&
l_node_client
->
wait_mutex
);
l_node_client
->
own_esh
.
esocket
=
0
;
l_node_client
->
own_esh
.
esocket
=
0
;
dap_timerfd_start_on_worker
(
dap_events_worker_get_auto
(),
s_timer_update_states
*
1000
,
s_timer_update_states_callback
,
l_node_client
);
dap_chain_node_client_handle_t
*
l_client_handle
=
DAP_NEW_Z
(
dap_chain_node_client_handle_t
);
l_client_handle
->
uuid
=
l_node_client
->
uuid
;
l_client_handle
->
client
=
l_node_client
;
dap_timerfd_start_on_worker
(
dap_events_worker_get_auto
(),
s_timer_update_states
*
1000
,
s_timer_update_states_callback
,
l_client_handle
);
return
;
return
;
}
}
...
@@ -186,7 +208,16 @@ static void s_stage_status_error_callback(dap_client_t *a_client, void *a_arg)
...
@@ -186,7 +208,16 @@ static void s_stage_status_error_callback(dap_client_t *a_client, void *a_arg)
*/
*/
static
bool
s_timer_update_states_callback
(
void
*
a_arg
)
static
bool
s_timer_update_states_callback
(
void
*
a_arg
)
{
{
dap_chain_node_client_t
*
l_me
=
(
dap_chain_node_client_t
*
)
a_arg
;
dap_chain_node_client_handle_t
*
l_client_handle
=
(
dap_chain_node_client_handle_t
*
)
a_arg
,
*
l_client_found
=
NULL
;
assert
(
l_client_handle
);
HASH_FIND
(
hh
,
s_clients
,
&
l_client_handle
->
uuid
,
sizeof
(
l_client_handle
->
uuid
),
l_client_found
);
if
(
!
l_client_found
){
log_it
(
L_DEBUG
,
"Chain node client %p was deleted before timer fired, nothing to do"
,
l_client_handle
->
client
);
DAP_DELETE
(
l_client_handle
);
return
false
;
}
dap_chain_node_client_t
*
l_me
=
l_client_handle
->
client
;
dap_worker_t
*
l_worker
=
dap_events_get_current_worker
(
dap_events_get_default
());
dap_worker_t
*
l_worker
=
dap_events_get_current_worker
(
dap_events_get_default
());
assert
(
l_worker
);
assert
(
l_worker
);
assert
(
l_me
);
assert
(
l_me
);
...
@@ -220,6 +251,7 @@ static bool s_timer_update_states_callback(void * a_arg )
...
@@ -220,6 +251,7 @@ static bool s_timer_update_states_callback(void * a_arg )
l_chain_id
.
uint64
,
l_net
->
pub
.
cell_id
.
uint64
,
l_chain_id
.
uint64
,
l_net
->
pub
.
cell_id
.
uint64
,
&
l_sync_gdb
,
sizeof
(
l_sync_gdb
));
&
l_sync_gdb
,
sizeof
(
l_sync_gdb
));
}
}
DAP_DELETE
(
l_client_handle
);
return
true
;
return
true
;
}
}
}
}
...
@@ -231,6 +263,7 @@ static bool s_timer_update_states_callback(void * a_arg )
...
@@ -231,6 +263,7 @@ static bool s_timer_update_states_callback(void * a_arg )
log_it
(
L_INFO
,
"Reconnecting node client with peer "
NODE_ADDR_FP_STR
,
NODE_ADDR_FP_ARGS_S
(
l_me
->
remote_node_addr
));
log_it
(
L_INFO
,
"Reconnecting node client with peer "
NODE_ADDR_FP_STR
,
NODE_ADDR_FP_ARGS_S
(
l_me
->
remote_node_addr
));
dap_chain_node_client_connect_internal
(
l_me
,
"CN"
);
// isn't always CN here?
dap_chain_node_client_connect_internal
(
l_me
,
"CN"
);
// isn't always CN here?
}
}
DAP_DELETE
(
l_client_handle
);
return
false
;
return
false
;
}
}
...
@@ -267,7 +300,11 @@ static void s_stage_connected_callback(dap_client_t *a_client, void *a_arg)
...
@@ -267,7 +300,11 @@ static void s_stage_connected_callback(dap_client_t *a_client, void *a_arg)
if
(
l_stream
)
{
if
(
l_stream
)
{
l_node_client
->
own_esh
.
esocket
=
l_stream
->
esocket
;
l_node_client
->
own_esh
.
esocket
=
l_stream
->
esocket
;
l_node_client
->
own_esh
.
uuid
=
l_stream
->
esocket
->
uuid
;
l_node_client
->
own_esh
.
uuid
=
l_stream
->
esocket
->
uuid
;
dap_timerfd_start_on_worker
(
l_stream
->
esocket
->
worker
,
s_timer_update_states
*
1000
,
s_timer_update_states_callback
,
l_node_client
);
dap_chain_node_client_handle_t
*
l_client_handle
=
DAP_NEW_Z
(
dap_chain_node_client_handle_t
);
l_client_handle
->
uuid
=
l_node_client
->
uuid
;
l_client_handle
->
client
=
l_node_client
;
dap_timerfd_start_on_worker
(
l_stream
->
esocket
->
worker
,
s_timer_update_states
*
1000
,
s_timer_update_states_callback
,
l_client_handle
);
}
}
#ifndef _WIN32
#ifndef _WIN32
pthread_cond_broadcast
(
&
l_node_client
->
wait_cond
);
pthread_cond_broadcast
(
&
l_node_client
->
wait_cond
);
...
@@ -586,6 +623,7 @@ dap_chain_node_client_t* dap_chain_node_client_create_n_connect(dap_chain_net_t
...
@@ -586,6 +623,7 @@ dap_chain_node_client_t* dap_chain_node_client_create_n_connect(dap_chain_net_t
memcpy
(
&
l_node_client
->
callbacks
,
a_callbacks
,
sizeof
(
*
a_callbacks
));
memcpy
(
&
l_node_client
->
callbacks
,
a_callbacks
,
sizeof
(
*
a_callbacks
));
l_node_client
->
info
=
a_node_info
;
l_node_client
->
info
=
a_node_info
;
l_node_client
->
net
=
a_net
;
l_node_client
->
net
=
a_net
;
l_node_client
->
uuid
=
dap_uuid_generate_uint128
();
#ifndef _WIN32
#ifndef _WIN32
pthread_condattr_t
attr
;
pthread_condattr_t
attr
;
...
@@ -679,6 +717,15 @@ void dap_chain_node_client_close(dap_chain_node_client_t *a_client)
...
@@ -679,6 +717,15 @@ void dap_chain_node_client_close(dap_chain_node_client_t *a_client)
#endif
#endif
pthread_mutex_destroy
(
&
a_client
->
wait_mutex
);
pthread_mutex_destroy
(
&
a_client
->
wait_mutex
);
a_client
->
client
=
NULL
;
a_client
->
client
=
NULL
;
dap_chain_node_client_handle_t
*
l_client_found
=
NULL
;
HASH_FIND
(
hh
,
s_clients
,
&
a_client
->
uuid
,
sizeof
(
a_client
->
uuid
),
l_client_found
);
if
(
l_client_found
){
HASH_DEL
(
s_clients
,
l_client_found
);
DAP_DELETE
(
l_client_found
);
}
else
{
log_it
(
L_WARNING
,
"Chain node client was removed from hash table before for some reasons"
);
}
DAP_DELETE
(
a_client
);
DAP_DELETE
(
a_client
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
modules/net/include/dap_chain_node_client.h
+
1
−
0
View file @
01081038
...
@@ -66,6 +66,7 @@ typedef struct dap_chain_node_client_callbacks{
...
@@ -66,6 +66,7 @@ typedef struct dap_chain_node_client_callbacks{
// state for a client connection
// state for a client connection
typedef
struct
dap_chain_node_client
{
typedef
struct
dap_chain_node_client
{
dap_chain_node_client_state_t
state
;
dap_chain_node_client_state_t
state
;
uint128_t
uuid
;
bool
sync_gdb
;
bool
sync_gdb
;
bool
sync_chains
;
bool
sync_chains
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment