Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap-chain-mempool
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-mempool
Commits
15d5b398
Unverified
Commit
15d5b398
authored
5 years ago
by
Dmitriy A. Gerasimov
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #7 from cellframe/1.1-11-Win
1.1-11-Win
parents
6a4ea175
0037a6f3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+12
-0
12 additions, 0 deletions
CMakeLists.txt
client_mempool.c
+54
-2
54 additions, 2 deletions
client_mempool.c
dap_chain_mempool.c
+24
-7
24 additions, 7 deletions
dap_chain_mempool.c
with
90 additions
and
9 deletions
CMakeLists.txt
+
12
−
0
View file @
15d5b398
...
@@ -6,6 +6,18 @@ file(GLOB DAP_CHAIN_MEMPOOL_HDR *.h)
...
@@ -6,6 +6,18 @@ file(GLOB DAP_CHAIN_MEMPOOL_HDR *.h)
add_definitions
(
"-DNODE_NETNAME=
\"
kelvin
\"
"
)
add_definitions
(
"-DNODE_NETNAME=
\"
kelvin
\"
"
)
if
(
WIN32
)
include_directories
(
../libdap/src/win32/
)
include_directories
(
../3rdparty/libmemcached/
)
include_directories
(
../3rdparty/libmemcached/win32/
)
include_directories
(
../3rdparty/wepoll/include/
)
include_directories
(
../3rdparty/uthash/src/
)
include_directories
(
../3rdparty/libjson-c/
)
include_directories
(
../3rdparty/libmagic/src/
)
include_directories
(
../3rdparty/curl/include/
)
include_directories
(
../3rdparty/libsqlite3/
)
endif
()
add_library
(
${
PROJECT_NAME
}
STATIC
${
DAP_CHAIN_MEMPOOL_SRC
}
${
DAP_CHAIN_MEMPOOL_HDR
}
)
add_library
(
${
PROJECT_NAME
}
STATIC
${
DAP_CHAIN_MEMPOOL_SRC
}
${
DAP_CHAIN_MEMPOOL_HDR
}
)
target_link_libraries
(
dap_chain_mempool dap_http_server dap_client dap_chain_net dap_chain_global_db dap_core
)
target_link_libraries
(
dap_chain_mempool dap_http_server dap_client dap_chain_net dap_chain_global_db dap_core
)
...
...
This diff is collapsed.
Click to expand it.
client_mempool.c
+
54
−
2
View file @
15d5b398
...
@@ -28,6 +28,20 @@
...
@@ -28,6 +28,20 @@
#include
<time.h>
#include
<time.h>
#include
<assert.h>
#include
<assert.h>
#include
<errno.h>
#include
<errno.h>
#ifdef _WIN32
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#include
<winsock2.h>
#include
<windows.h>
#include
<mswsock.h>
#include
<ws2tcpip.h>
#include
<io.h>
#include
<time.h>
#include
<wepoll.h>
#include
<pthread.h>
#endif
#include
"dap_common.h"
#include
"dap_common.h"
#include
"dap_config.h"
#include
"dap_config.h"
#include
"dap_events.h"
#include
"dap_events.h"
...
@@ -40,6 +54,8 @@
...
@@ -40,6 +54,8 @@
#define SYSTEM_PREFIX "/opt/"DAP_APP_NAME
#define SYSTEM_PREFIX "/opt/"DAP_APP_NAME
#define SYSTEM_CONFIGS_DIR SYSTEM_PREFIX"/etc"
#define SYSTEM_CONFIGS_DIR SYSTEM_PREFIX"/etc"
#define LOG_TAG "dap_client_mempool"
static
int
listen_port_tcp
=
8079
;
static
int
listen_port_tcp
=
8079
;
// send request to server
// send request to server
...
@@ -74,7 +90,13 @@ static void a_response_proc(dap_client_t *a_client, void *str, size_t str_len)
...
@@ -74,7 +90,13 @@ static void a_response_proc(dap_client_t *a_client, void *str, size_t str_len)
}
}
pthread_mutex_lock
(
&
mempool
->
wait_mutex
);
pthread_mutex_lock
(
&
mempool
->
wait_mutex
);
mempool
->
state
=
CLIENT_MEMPOOL_SENDED
;
mempool
->
state
=
CLIENT_MEMPOOL_SENDED
;
#ifndef _WIN32
pthread_cond_signal
(
&
mempool
->
wait_cond
);
pthread_cond_signal
(
&
mempool
->
wait_cond
);
#else
SetEvent
(
mempool
->
wait_cond
);
#endif
pthread_mutex_unlock
(
&
mempool
->
wait_mutex
);
pthread_mutex_unlock
(
&
mempool
->
wait_mutex
);
}
}
}
}
...
@@ -88,7 +110,11 @@ static void a_response_error(dap_client_t *a_client, int val)
...
@@ -88,7 +110,11 @@ static void a_response_error(dap_client_t *a_client, int val)
if
(
mempool
)
{
if
(
mempool
)
{
pthread_mutex_lock
(
&
mempool
->
wait_mutex
);
pthread_mutex_lock
(
&
mempool
->
wait_mutex
);
mempool
->
state
=
CLIENT_MEMPOOL_ERROR
;
mempool
->
state
=
CLIENT_MEMPOOL_ERROR
;
#ifndef _WIN32
pthread_cond_signal
(
&
mempool
->
wait_cond
);
pthread_cond_signal
(
&
mempool
->
wait_cond
);
#else
SetEvent
(
mempool
->
wait_cond
);
#endif
pthread_mutex_unlock
(
&
mempool
->
wait_mutex
);
pthread_mutex_unlock
(
&
mempool
->
wait_mutex
);
}
}
}
}
...
@@ -101,7 +127,11 @@ static void a_stage_end_callback(dap_client_t *a_client, void *a_arg)
...
@@ -101,7 +127,11 @@ static void a_stage_end_callback(dap_client_t *a_client, void *a_arg)
if
(
mempool
)
{
if
(
mempool
)
{
pthread_mutex_lock
(
&
mempool
->
wait_mutex
);
pthread_mutex_lock
(
&
mempool
->
wait_mutex
);
mempool
->
state
=
CLIENT_MEMPOOL_CONNECTED
;
mempool
->
state
=
CLIENT_MEMPOOL_CONNECTED
;
#ifndef _WIN32
pthread_cond_signal
(
&
mempool
->
wait_cond
);
pthread_cond_signal
(
&
mempool
->
wait_cond
);
#else
SetEvent
(
mempool
->
wait_cond
);
#endif
pthread_mutex_unlock
(
&
mempool
->
wait_mutex
);
pthread_mutex_unlock
(
&
mempool
->
wait_mutex
);
}
}
}
}
...
@@ -129,16 +159,24 @@ void client_mempool_deinit()
...
@@ -129,16 +159,24 @@ void client_mempool_deinit()
dap_client_deinit
();
dap_client_deinit
();
}
}
client_mempool_t
*
client_mempool_connect
(
const
char
*
addr
)
client_mempool_t
*
client_mempool_connect
(
const
char
*
addr
)
{
{
if
(
!
addr
||
strlen
(
addr
)
<
1
)
if
(
!
addr
||
strlen
(
addr
)
<
1
)
return
NULL
;
return
NULL
;
client_mempool_t
*
mempool
=
DAP_NEW_Z
(
client_mempool_t
);
client_mempool_t
*
mempool
=
DAP_NEW_Z
(
client_mempool_t
);
mempool
->
state
=
CLIENT_MEMPOOL_INIT
;
mempool
->
state
=
CLIENT_MEMPOOL_INIT
;
log_it
(
L_NOTICE
,
"======= client_mempool_connect( )"
);
#ifndef _WIN32
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
(
&
mempool
->
wait_cond
,
&
attr
);
pthread_cond_init
(
&
mempool
->
wait_cond
,
&
attr
);
#else
mempool
->
wait_cond
=
CreateEventA
(
NULL
,
FALSE
,
FALSE
,
NULL
);
#endif
pthread_mutex_init
(
&
mempool
->
wait_mutex
,
NULL
);
pthread_mutex_init
(
&
mempool
->
wait_mutex
,
NULL
);
mempool
->
a_events
=
dap_events_new
();
mempool
->
a_events
=
dap_events_new
();
mempool
->
a_client
=
dap_client_new
(
mempool
->
a_events
,
stage_status_callback
,
stage_status_error_callback
);
mempool
->
a_client
=
dap_client_new
(
mempool
->
a_events
,
stage_status_callback
,
stage_status_error_callback
);
...
@@ -166,8 +204,11 @@ client_mempool_t* client_mempool_connect(const char *addr)
...
@@ -166,8 +204,11 @@ client_mempool_t* client_mempool_connect(const char *addr)
int
client_mempool_wait
(
client_mempool_t
*
mempool
,
int
waited_state
,
int
timeout_ms
)
int
client_mempool_wait
(
client_mempool_t
*
mempool
,
int
waited_state
,
int
timeout_ms
)
{
{
int
ret
=
-
1
;
int
ret
=
-
1
;
if
(
!
mempool
)
if
(
!
mempool
)
return
-
1
;
return
-
1
;
log_it
(
L_NOTICE
,
"======= client_mempool_wait( ) tm %u ms"
,
timeout_ms
);
pthread_mutex_lock
(
&
mempool
->
wait_mutex
);
pthread_mutex_lock
(
&
mempool
->
wait_mutex
);
// have waited
// have waited
if
(
mempool
->
state
==
waited_state
)
{
if
(
mempool
->
state
==
waited_state
)
{
...
@@ -175,6 +216,7 @@ int client_mempool_wait(client_mempool_t *mempool, int waited_state, int timeout
...
@@ -175,6 +216,7 @@ int client_mempool_wait(client_mempool_t *mempool, int waited_state, int timeout
return
1
;
return
1
;
}
}
// prepare for signal waiting
// prepare for signal waiting
#ifndef _WIN32
struct
timespec
to
;
struct
timespec
to
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
to
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
to
);
int64_t
nsec_new
=
to
.
tv_nsec
+
timeout_ms
*
1000000ll
;
int64_t
nsec_new
=
to
.
tv_nsec
+
timeout_ms
*
1000000ll
;
...
@@ -191,6 +233,16 @@ int client_mempool_wait(client_mempool_t *mempool, int waited_state, int timeout
...
@@ -191,6 +233,16 @@ int client_mempool_wait(client_mempool_t *mempool, int waited_state, int timeout
ret
=
1
;
ret
=
1
;
else
if
(
wait
==
ETIMEDOUT
)
// 110 260
else
if
(
wait
==
ETIMEDOUT
)
// 110 260
ret
=
0
;
ret
=
0
;
#else
int
wait
=
WaitForSingleObject
(
mempool
->
wait_cond
,
(
uint32_t
)
timeout_ms
);
pthread_mutex_lock
(
&
mempool
->
wait_mutex
);
if
(
wait
==
WAIT_OBJECT_0
)
return
1
;
else
if
(
wait
==
WAIT_TIMEOUT
||
wait
==
WAIT_FAILED
)
{
ret
=
0
;
}
#endif
pthread_mutex_unlock
(
&
mempool
->
wait_mutex
);
pthread_mutex_unlock
(
&
mempool
->
wait_mutex
);
return
ret
;
return
ret
;
}
}
...
...
This diff is collapsed.
Click to expand it.
dap_chain_mempool.c
+
24
−
7
View file @
15d5b398
...
@@ -29,8 +29,19 @@
...
@@ -29,8 +29,19 @@
#include
<assert.h>
#include
<assert.h>
#include
<memory.h>
#include
<memory.h>
//#include <dap_http_simple.h>
#ifdef _WIN32
//#include <http_status_code.h>
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#include
<winsock2.h>
#include
<windows.h>
#include
<mswsock.h>
#include
<ws2tcpip.h>
#include
<io.h>
#include
<time.h>
#include
<wepoll.h>
#include
<pthread.h>
#endif
#include
"dap_common.h"
#include
"dap_common.h"
#include
"dap_hash.h"
#include
"dap_hash.h"
#include
"dap_http_client.h"
#include
"dap_http_client.h"
...
@@ -309,7 +320,9 @@ int dap_chain_mempool_tx_create_massive( dap_chain_t * a_chain, dap_enc_key_t *a
...
@@ -309,7 +320,9 @@ int dap_chain_mempool_tx_create_massive( dap_chain_t * a_chain, dap_enc_key_t *a
while
(
l_list_tmp
)
{
while
(
l_list_tmp
)
{
list_used_item_t
*
item
=
l_list_tmp
->
data
;
list_used_item_t
*
item
=
l_list_tmp
->
data
;
char
l_in_hash_str
[
70
];
char
l_in_hash_str
[
70
];
dap_chain_hash_fast_to_str
(
&
item
->
tx_hash_fast
,
l_in_hash_str
,
sizeof
(
l_in_hash_str
)
);
dap_chain_hash_fast_to_str
(
&
item
->
tx_hash_fast
,
l_in_hash_str
,
sizeof
(
l_in_hash_str
)
);
if
(
dap_chain_datum_tx_add_in_item
(
&
l_tx_new
,
&
item
->
tx_hash_fast
,
(
uint32_t
)
item
->
num_idx_out
)
==
1
)
{
if
(
dap_chain_datum_tx_add_in_item
(
&
l_tx_new
,
&
item
->
tx_hash_fast
,
(
uint32_t
)
item
->
num_idx_out
)
==
1
)
{
l_value_to_items
+=
item
->
value
;
l_value_to_items
+=
item
->
value
;
log_it
(
L_DEBUG
,
"Added input %s with %llu datoshi"
,
l_in_hash_str
,
item
->
value
);
log_it
(
L_DEBUG
,
"Added input %s with %llu datoshi"
,
l_in_hash_str
,
item
->
value
);
...
@@ -768,11 +781,15 @@ static char* calc_datum_hash(const char *datum_str, size_t datum_size)
...
@@ -768,11 +781,15 @@ static char* calc_datum_hash(const char *datum_str, size_t datum_size)
dap_hash
(
datum_str
,
datum_size
,
a_hash
.
raw
,
sizeof
(
a_hash
.
raw
),
DAP_HASH_TYPE_SLOW_0
);
dap_hash
(
datum_str
,
datum_size
,
a_hash
.
raw
,
sizeof
(
a_hash
.
raw
),
DAP_HASH_TYPE_SLOW_0
);
size_t
a_str_max
=
(
sizeof
(
a_hash
.
raw
)
+
1
)
*
2
+
2
;
/* heading 0x */
size_t
a_str_max
=
(
sizeof
(
a_hash
.
raw
)
+
1
)
*
2
+
2
;
/* heading 0x */
char
*
a_str
=
DAP_NEW_Z_SIZE
(
char
,
a_str_max
);
char
*
a_str
=
DAP_NEW_Z_SIZE
(
char
,
a_str_max
);
size_t
hash_len
=
dap_chain_hash_fast_to_str
(
&
a_hash
,
a_str
,
a_str_max
);
if
(
!
hash_len
)
{
// size_t hash_len = dap_chain_hash_fast_to_str(&a_hash, a_str, a_str_max);
DAP_DELETE
(
a_str
);
dap_chain_hash_fast_to_str
(
&
a_hash
,
a_str
,
a_str_max
);
return
NULL
;
}
// if(!hash_len) {
// DAP_DELETE(a_str);
// return NULL;
// }
return
a_str
;
return
a_str
;
}
}
...
...
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