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
16
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
3987a0c1
Commit
3987a0c1
authored
6 years ago
by
Aleksandr Lysikov
Browse files
Options
Downloads
Patches
Plain Diff
update list of the established connections
parent
9203a535
No related branches found
No related tags found
1 merge request
!24
Support 3689
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dap_chain_node_cli_cmd.c
+57
-10
57 additions, 10 deletions
dap_chain_node_cli_cmd.c
dap_chain_node_remote.c
+77
-29
77 additions, 29 deletions
dap_chain_node_remote.c
dap_chain_node_remote.h
+14
-11
14 additions, 11 deletions
dap_chain_node_remote.h
with
148 additions
and
50 deletions
dap_chain_node_cli_cmd.c
+
57
−
10
View file @
3987a0c1
...
...
@@ -33,6 +33,7 @@
#include
"iputils/iputils.h"
//#include "dap_common.h"
#include
"dap_hash.h"
#include
"dap_chain_common.h"
#include
"dap_chain_wallet.h"
#include
"dap_chain_node.h"
#include
"dap_chain_global_db.h"
...
...
@@ -45,6 +46,7 @@
#include
"dap_chain_datum_tx_out.h"
#include
"dap_chain_datum_tx_pkey.h"
#include
"dap_chain_datum_tx_sig.h"
#include
"dap_chain_datum_tx_cache.h"
// Max and min macros
#define max(a,b) ((a) > (b) ? (a) : (b))
...
...
@@ -766,11 +768,11 @@ int com_node(int argc, const char ** argv, char **str_reply)
switch
(
ret
)
{
case
-
1
:
chain_node_client_close
(
client
);
dap_
chain_node_client_close
(
client
);
set_reply_text
(
str_reply
,
"connection established, but not saved"
);
return
-
1
;
case
-
2
:
chain_node_client_close
(
client
);
dap_
chain_node_client_close
(
client
);
set_reply_text
(
str_reply
,
"connection already present"
);
return
-
1
;
}
...
...
@@ -987,7 +989,7 @@ dap_chain_datum_tx_t* create_tx(const char *net_name)
dap_chain_tx_in_t
tx_out
;
tx_in
.
header
.
type
=
TX_ITEM_TYPE_IN
;
tx_in
.
header
.
sig_size
=
0
;
//
tx_in.header.sig_size = 0;
//tx_in
dap_chain_datum_tx_t
*
tx
=
DAP_NEW_Z
(
dap_chain_datum_tx_t
);
...
...
@@ -1027,13 +1029,57 @@ int com_tx_create(int argc, const char ** argv, char **str_reply)
const
char
*
a_wallet_name
=
"w1"
;
dap_chain_net_id_t
a_net_id
=
{
0x1
};
dap_chain_sign_type_t
a_sig_type
=
{
SIG_TYPE_TESLA
};
//dap_chain_sign_type_t a_sig_type = { SIG_TYPE_PICNIC };
//dap_chain_sign_type_t a_sig_type = { SIG_TYPE_BLISS };
//
dap_chain_wallet_t *wallet = dap_chain_wallet_create(a_wallet_name, a_wallets_path, a_net_id, a_sig_type);
//size_t num = dap_chain_wallet_get_certs_number(wallet
);
dap_chain_wallet_t
*
wallet
=
dap_chain_wallet_open
(
a_wallet_name
,
a_wallets_path
);
dap_chain_wallet_t
*
wallet
=
dap_chain_wallet_create
(
a_wallet_name
,
a_wallets_path
,
a_net_id
,
a_sig_type
);
dap_chain_wallet_t
*
wallet2
=
dap_chain_wallet_open
(
a_wallet_name
,
a_wallets_path
);
//
wallet = dap_chain_wallet_open(a_wallet_name, a_wallets_path);
//dap_chain_wallet_save(wallet2);
dap_chain_datum_tx_t
*
tx
=
create_tx
(
"0x123"
);
static
bool
l_first_start
=
true
;
if
(
l_first_start
)
{
const
char
*
l_token_name
=
"KLVN"
;
dap_enc_key_t
*
l_key
=
dap_chain_wallet_get_key
(
wallet
,
0
);
const
dap_chain_addr_t
*
l_addr
=
dap_chain_wallet_get_addr
(
wallet
);
dap_chain_node_datum_tx_cache_init
(
l_key
,
l_token_name
,
(
dap_chain_addr_t
*
)
l_addr
,
1000
);
l_first_start
=
false
;
}
const
dap_chain_addr_t
*
addr
=
dap_chain_wallet_get_addr
(
wallet
);
char
*
addr_str
=
dap_chain_addr_to_str
((
dap_chain_addr_t
*
)
addr
);
const
dap_chain_addr_t
*
addr2
=
dap_chain_str_to_addr
(
addr_str
);
char
*
addr_str2
=
dap_chain_addr_to_str
(
addr2
);
free
(
addr_str
);
// debug - check signing
{
int
a_data_size
=
50
;
char
*
a_data
=
"DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify"
;
dap_enc_key_t
*
a_key0
=
dap_enc_key_new_generate
(
DAP_ENC_KEY_TYPE_SIG_BLISS
,
NULL
,
0
,
NULL
,
0
,
0
);
dap_enc_key_t
*
a_key1
=
dap_chain_wallet_get_key
(
wallet
,
0
);
dap_enc_key_t
*
a_key2
=
dap_chain_wallet_get_key
(
wallet2
,
0
);
dap_chain_sign_t
*
a_chain_sign0
=
dap_chain_sign_create
(
a_key0
,
a_data
,
a_data_size
,
0
);
dap_chain_sign_t
*
a_chain_sign1
=
dap_chain_sign_create
(
a_key1
,
a_data
,
a_data_size
,
0
);
dap_chain_sign_t
*
a_chain_sign2
=
dap_chain_sign_create
(
a_key2
,
a_data
,
a_data_size
,
0
);
size_t
a_chain_sign_size
=
dap_chain_sign_get_size
(
a_chain_sign1
);
int
verify0
=
dap_chain_sign_verify
(
a_chain_sign0
,
a_data
,
a_data_size
);
int
verify1
=
dap_chain_sign_verify
(
a_chain_sign1
,
a_data
,
a_data_size
);
int
verify2
=
dap_chain_sign_verify
(
a_chain_sign2
,
a_data
,
a_data_size
);
printf
(
"a_chain_sign=%d verify=%d %d %d
\n
"
,
a_chain_sign_size
,
verify0
,
verify1
,
verify2
);
free
(
a_chain_sign2
);
free
(
a_chain_sign1
);
free
(
a_chain_sign0
);
//dap_enc_key_delete(a_key2);
dap_enc_key_delete
(
a_key0
);
//dap_enc_key_delete(a_key1);
}
if
(
wallet
)
{
if
(
dap_chain_wallet_get_certs_number
(
wallet
)
>
0
)
{
dap_chain_pkey_t
*
pk0
=
dap_chain_wallet_get_pkey
(
wallet
,
0
);
...
...
@@ -1041,15 +1087,16 @@ int com_tx_create(int argc, const char ** argv, char **str_reply)
//dap_enc_key_t *a_key1 = dap_chain_wallet_get_key(wallet, 0);
//dap_enc_key_t *a_key2 = dap_chain_wallet_get_key(wallet2, 0);
int
res
=
dap_chain_datum_tx_add_sign
(
&
tx
,
a_key
);
//
int res1 = dap_chain_datum_tx_add_sign(&tx, a_key);
//
int res2 = dap_chain_datum_tx_add_sign(&tx, a_key
2
);
int
res1
=
dap_chain_datum_tx_add_sign
(
&
tx
,
a_key
);
int
res2
=
dap_chain_datum_tx_add_sign
(
&
tx
,
a_key
);
int
res3
=
dap_chain_datum_tx_verify_sign
(
tx
);
res3
=
0
;
}
dap_chain_wallet_close
(
wallet
);
DAP_DELETE
(
tx
);
}
set_reply_text
(
str_reply
,
"com_tx_create ok"
);
return
-
1
;
return
0
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
dap_chain_node_remote.c
+
77
−
29
View file @
3987a0c1
...
...
@@ -22,69 +22,117 @@
#include
<stdint.h>
#include
<stdlib.h>
#include
<string.h>
#include
<glib.h>
#include
<pthread.h>
#include
"uthash.h"
#include
"dap_common.h"
#include
"dap_chain_node_remote.h"
typedef
struct
list_linked_item
{
dap_chain_node_addr_t
address
;
dap_chain_node_client_t
*
client
;
UT_hash_handle
hh
;
}
list_linked_item_t
;
// List of connections
static
GL
ist
*
conn
ect
_list
=
NULL
;
static
l
ist
_linked_item_t
*
conn_list
=
NULL
;
// for separate access to connect_list
static
pthread_mutex_t
connect_list_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
/**
* Add new established connection in the list
* Add new established connection to the list
*
* return 0 OK, -1 error, -2 already present
*/
bool
chain_node_client_list_add
(
dap_chain_node_client_t
*
client
)
int
chain_node_client_list_add
(
dap_chain_node_addr_t
*
a_address
,
dap_chain_node_client_t
*
a_
client
)
{
if
(
!
client
)
return
false
;
int
l_ret
=
0
;
if
(
!
a_address
||
!
a_client
)
return
-
1
;
list_linked_item_t
*
item_tmp
=
NULL
;
pthread_mutex_lock
(
&
connect_list_mutex
);
connect_list
=
g_list_append
(
connect_list
,
client
);
HASH_FIND
(
hh
,
conn_list
,
a_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
=
a_address
->
uint64
;
item_tmp
->
client
=
a_client
;
HASH_ADD
(
hh
,
conn_list
,
address
,
sizeof
(
dap_chain_node_addr_t
),
item_tmp
);
// address: name of key field
l_ret
=
0
;
}
// connection already present
else
l_ret
=
-
2
;
//connect_list = g_list_append(connect_list, client);
pthread_mutex_unlock
(
&
connect_list_mutex
);
return
true
;
return
l_ret
;
}
/**
* Delete established connection from the list
*
* return 0 OK, -1 error, -2 address not found
*/
bool
chain_node_client_list_del
(
dap_chain_node_
client_t
*
client
)
int
chain_node_client_list_del
(
dap_chain_node_
addr_t
*
address
)
{
int
ret
=
-
1
;
if
(
!
address
)
return
-
1
;
list_linked_item_t
*
item_tmp
;
pthread_mutex_lock
(
&
connect_list_mutex
);
GList
*
list
=
g_list_find
(
connect_list
,
client
);
// found
if
(
list
)
connect_list
=
g_list_remove
(
connect_list
,
client
);
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
;
pthread_mutex_unlock
(
&
connect_list_mutex
);
if
(
list
)
return
true
;
return
false
;
if
(
!
ret
)
{
// close connection
dap_chain_node_client_close
(
item_tmp
->
client
);
// del struct for hash
DAP_DELETE
(
item_tmp
);
}
return
ret
;
}
/**
* 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
* Delete all established connection from the list
*/
dap_chain_node_client_t
*
chain_node_client_list_
get_item
(
int
n
)
void
chain_node_client_list_
del_all
(
void
)
{
int
ret
=
-
1
;
list_linked_item_t
*
iter_current
,
*
item_tmp
;
pthread_mutex_lock
(
&
connect_list_mutex
);
dap_chain_node_client_t
*
client
=
g_list_nth_data
(
connect_list
,
(
guint
)
n
);
HASH_ITER
(
hh
,
conn_list
,
iter_current
,
item_tmp
)
{
// close connection
dap_chain_node_client_close
(
iter_current
->
client
);
// del struct for hash
HASH_DEL
(
conn_list
,
iter_current
);
}
pthread_mutex_unlock
(
&
connect_list_mutex
);
return
client
;
}
/**
* Get the number of established connections
* Get present established connection by address
*
* return client, or NULL if the connection not found in the list
*/
int
chain_node_client_
list_count
(
void
)
const
dap_
chain_node_client_
t
*
chain_node_client_find
(
dap_chain_node_addr_t
*
address
)
{
int
ret
=
0
;
if
(
!
address
)
return
NULL
;
dap_chain_node_client_t
*
client_ret
=
NULL
;
list_linked_item_t
*
item_tmp
;
pthread_mutex_lock
(
&
connect_list_mutex
);
int
len
=
g_list_length
(
connect_list
);
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
;
}
pthread_mutex_unlock
(
&
connect_list_mutex
);
return
len
;
return
client_ret
;
}
This diff is collapsed.
Click to expand it.
dap_chain_node_remote.h
+
14
−
11
View file @
3987a0c1
...
...
@@ -23,28 +23,31 @@
#include
<stdbool.h>
#include
"dap_chain_node.h"
#include
"dap_chain_node_client.h"
/**
* Add new established connection in the list
* Add new established connection to the list
*
* return 0 OK, -1 error, -2 already present
*/
bool
chain_node_client_list_add
(
dap_chain_node_client_t
*
client
);
int
chain_node_client_list_add
(
dap_chain_node_addr_t
*
address
,
dap_chain_node_client_t
*
client
);
/**
* Delete established connection from the list
*
* return 0 OK, -1 error, -2 address not found
*/
bool
chain_node_client_list_del
(
dap_chain_node_
client_t
*
client
);
int
chain_node_client_list_del
(
dap_chain_node_
addr_t
*
address
);
/**
* 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
* Delete all established connection from the list
*/
dap_chain_node_client_t
*
chain_node_client_list_
get_item
(
int
n
);
void
chain_node_client_list_
del_all
(
void
);
/**
* Get the number of established connections
* Get present established connection by address
*
* return client, or NULL if the connection not found in the list
*/
int
chain_node_client_
list_count
(
void
);
const
dap_
chain_node_client_
t
*
chain_node_client_find
(
dap_chain_node_addr_t
*
address
);
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