Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap-chain-net
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
cellframe
libdap-chain-net
Commits
3cfb35df
Commit
3cfb35df
authored
6 years ago
by
Aleksandr Lysikov
Browse files
Options
Downloads
Patches
Plain Diff
update to merge with to master
parent
e9014161
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dap_chain_node_remote.c
+28
-75
28 additions, 75 deletions
dap_chain_node_remote.c
dap_chain_node_remote.h
+12
-15
12 additions, 15 deletions
dap_chain_node_remote.h
with
40 additions
and
90 deletions
dap_chain_node_remote.c
+
28
−
75
View file @
3cfb35df
...
...
@@ -22,116 +22,69 @@
#include
<stdint.h>
#include
<stdlib.h>
#include
<string.h>
#include
<glib.h>
#include
<pthread.h>
#include
"uthash.h"
#include
"dap_chain_node_remote.h"
typedef
struct
list_linked_item
{
dap_chain_node_addr_t
address
;
chain_node_client_t
*
client
;
UT_hash_handle
hh
;
}
list_linked_item_t
;
// List of connections
static
l
ist
_linked_item_t
*
conn_list
=
NULL
;
static
GL
ist
*
conn
ect
_list
=
NULL
;
// for separate access to connect_list
static
pthread_mutex_t
connect_list_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
/**
* Add new established connection to the list
*
* return 0 OK, -1 error, -2 already present
* Add new established connection in the list
*/
int
chain_node_client_list_add
(
dap_
chain_node_addr_t
*
address
,
chain_node_client_t
*
client
)
bool
chain_node_client_list_add
(
dap_chain_node_client_t
*
client
)
{
int
ret
=
0
;
if
(
!
address
||
!
client
)
return
-
1
;
list_linked_item_t
*
item_tmp
=
NULL
;
if
(
!
client
)
return
false
;
pthread_mutex_lock
(
&
connect_list_mutex
);
HASH_FIND
(
hh
,
conn_list
,
address
,
sizeof
(
dap_chain_node_addr_t
),
item_tmp
);
// address already in the hash?
if
(
item_tmp
==
NULL
)
{
item_tmp
=
DAP_NEW
(
list_linked_item_t
);
item_tmp
->
address
.
uint64
=
address
->
uint64
;
item_tmp
->
client
=
client
;
HASH_ADD
(
hh
,
conn_list
,
address
,
sizeof
(
dap_chain_node_addr_t
),
item_tmp
);
// address: name of key field
ret
=
0
;
}
// connection already present
else
ret
=
-
2
;
//connect_list = g_list_append(connect_list, client);
connect_list
=
g_list_append
(
connect_list
,
client
);
pthread_mutex_unlock
(
&
connect_list_mutex
);
return
ret
;
return
true
;
}
/**
* Delete established connection from the list
*
* return 0 OK, -1 error, -2 address not found
*/
int
chain_node_client_list_del
(
dap_chain_node_
addr_t
*
address
)
bool
chain_node_client_list_del
(
dap_chain_node_
client_t
*
client
)
{
int
ret
=
-
1
;
if
(
!
address
)
return
-
1
;
list_linked_item_t
*
item_tmp
;
pthread_mutex_lock
(
&
connect_list_mutex
);
HASH_FIND
(
hh
,
conn_list
,
address
,
sizeof
(
dap_chain_node_addr_t
),
item_tmp
);
if
(
item_tmp
!=
NULL
)
{
HASH_DEL
(
conn_list
,
item_tmp
);
ret
=
0
;
}
else
// address not found in the hash
ret
=
-
2
;
GList
*
list
=
g_list_find
(
connect_list
,
client
);
// found
if
(
list
)
connect_list
=
g_list_remove
(
connect_list
,
client
);
pthread_mutex_unlock
(
&
connect_list_mutex
);
if
(
!
ret
)
{
// close connection
chain_node_client_close
(
item_tmp
->
client
);
// del struct for hash
DAP_DELETE
(
item_tmp
);
}
return
ret
;
if
(
list
)
return
true
;
return
false
;
}
/**
* Delete all established connection from the list
* Get one established connection
*
* n - the position of the established connection, counting from 0
*
* return client, or NULL if the position is off the end of the list
*/
void
chain_node_client_list_
del_all
(
void
)
dap_chain_node_client_t
*
chain_node_client_list_
get_item
(
int
n
)
{
int
ret
=
-
1
;
list_linked_item_t
*
iter_current
,
*
item_tmp
;
pthread_mutex_lock
(
&
connect_list_mutex
);
HASH_ITER
(
hh
,
conn_list
,
iter_current
,
item_tmp
)
{
// close connection
chain_node_client_close
(
iter_current
->
client
);
// del struct for hash
HASH_DEL
(
conn_list
,
iter_current
);
}
dap_chain_node_client_t
*
client
=
g_list_nth_data
(
connect_list
,
(
guint
)
n
);
pthread_mutex_unlock
(
&
connect_list_mutex
);
return
client
;
}
/**
* Get present established connection by address
*
* return client, or NULL if the position is off the end of the list
* Get the number of established connections
*/
cons
t
chain_node_client_
t
*
chain_node_client_find
(
dap_chain_node_addr_t
*
address
)
in
t
chain_node_client_
list_count
(
void
)
{
int
ret
=
0
;
if
(
!
address
)
return
NULL
;
chain_node_client_t
*
client_ret
=
NULL
;
list_linked_item_t
*
item_tmp
;
pthread_mutex_lock
(
&
connect_list_mutex
);
HASH_FIND
(
hh
,
conn_list
,
address
,
sizeof
(
dap_chain_node_addr_t
),
item_tmp
);
// address already in the hash?
if
(
item_tmp
!=
NULL
)
{
client_ret
=
item_tmp
->
client
;
}
int
len
=
g_list_length
(
connect_list
);
pthread_mutex_unlock
(
&
connect_list_mutex
);
return
client_ret
;
return
len
;
}
This diff is collapsed.
Click to expand it.
dap_chain_node_remote.h
+
12
−
15
View file @
3cfb35df
...
...
@@ -23,31 +23,28 @@
#include
<stdbool.h>
#include
"dap_chain_node.h"
#include
"dap_chain_node_cli_connect.h"
#include
"dap_chain_node_client.h"
/**
* Add new established connection to the list
*
* return 0 OK, -1 error, -2 already present
* Add new established connection in the list
*/
int
chain_node_client_list_add
(
dap_
chain_node_addr_t
*
address
,
chain_node_client_t
*
client
);
bool
chain_node_client_list_add
(
dap_chain_node_client_t
*
client
);
/**
* Delete established connection from the list
*
* return 0 OK, -1 error, -2 address not found
*/
int
chain_node_client_list_del
(
dap_chain_node_
addr_t
*
address
);
bool
chain_node_client_list_del
(
dap_chain_node_
client_t
*
client
);
/**
* Delete all established connection from the list
* Get one established connection
*
* n - the position of the established connection, counting from 0
*
* return client, or NULL if the position is off the end of the list
*/
void
chain_node_client_list_
del_all
(
void
);
dap_chain_node_client_t
*
chain_node_client_list_
get_item
(
int
n
);
/**
* Get present established connection by address
*
* return client, or NULL if the position is off the end of the list
* Get the number of established connections
*/
cons
t
chain_node_client_
t
*
chain_node_client_find
(
dap_chain_node_addr_t
*
address
);
in
t
chain_node_client_
list_count
(
void
);
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