Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
howjmay committed Jun 27, 2020
1 parent 5b3fe83 commit 0ad894a
Show file tree
Hide file tree
Showing 19 changed files with 488 additions and 307 deletions.
1 change: 1 addition & 0 deletions accelerator/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cc_binary(
deps = [
":ta_config",
"//connectivity/http",
"//accelerator/core:background",
"@org_iota_common//utils/handles:signal",
] + select({
":mqtt_enable": [
Expand Down
1 change: 1 addition & 0 deletions accelerator/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ status_t ta_core_default_init(ta_core_t* const core) {
cache->state = false;
cache->buffer_list_name = BUFFER_LIST_NAME;
cache->done_list_name = DONE_LIST_NAME;
cache->buffer_mam_list_name = BUFFER_MAM_LIST_NAME;
cache->capacity = CACHE_MAX_CAPACITY;

ta_log_info("Initializing IOTA full node configuration\n");
Expand Down
18 changes: 10 additions & 8 deletions accelerator/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern "C" {
#define MAM_FILE_PREFIX "/tmp/mam_bin_XXXXXX"
#define BUFFER_LIST_NAME "txn_buff_list"
#define DONE_LIST_NAME "done_txn_buff_list"
#define BUFFER_MAM_LIST_NAME "mam_buff_list"
#define CACHE_MAX_CAPACITY 170 * 1024 * 1024 // default to 170MB
#define HEALTH_TRACK_PERIOD 1800 // Check every half hour in default
#define RESULT_SET_LIMIT 100 // The maximun returned transaction object number when querying transaction object by tag
Expand Down Expand Up @@ -98,14 +99,15 @@ typedef struct iota_config_s {

/** struct type of accelerator cache */
typedef struct ta_cache_s {
char* host; /**< Binding address of redis server */
uint64_t timeout; /**< Timeout for keys in cache server */
char* buffer_list_name; /**< Name of the list to buffer transactions */
char* done_list_name; /**< Name of the list to store successfully broadcast transactions from buffer */
uint16_t port; /**< Binding port of redis server */
bool state; /**< Set it true to turn on cache server */
long int capacity; /**< The maximum capacity of cache server */
pthread_rwlock_t* rwlock; /**< Read/Write lock to avoid data racing in buffering */
char* host; /**< Binding address of redis server */
uint64_t timeout; /**< Timeout for keys in cache server */
char* buffer_list_name; /**< Name of the list to buffer transactions */
char* done_list_name; /**< Name of the list to store successfully broadcast transactions from buffer */
char* buffer_mam_list_name; /**< Name of the list to buffer MAM requests UUID */
uint16_t port; /**< Binding port of redis server */
bool state; /**< Set it true to turn on cache server */
long int capacity; /**< The maximum capacity of cache server */
pthread_rwlock_t* rwlock; /**< Read/Write lock to avoid data racing in buffering */
} ta_cache_t;

/** struct type of accelerator core */
Expand Down
15 changes: 15 additions & 0 deletions accelerator/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,18 @@ cc_library(
"@org_iota_common//utils:time",
],
)

cc_library(
name = "background",
srcs = ["background.c"],
hdrs = ["background.h"],
linkopts = [
"-lpthread",
],
visibility = ["//visibility:public"],
deps = [
":core",
"//common:ta_errors",
"//common:ta_logger",
],
)
27 changes: 22 additions & 5 deletions accelerator/core/apis.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,31 +220,48 @@ status_t api_recv_mam_message(const iota_config_t* const iconf, const iota_clien
}

status_t api_send_mam_message(const ta_config_t* const info, const iota_config_t* const iconf,
const iota_client_service_t* const service, char const* const obj, char** json_result) {
const ta_cache_t* const cache, const iota_client_service_t* const service,
char const* const obj, char** json_result) {
status_t ret = SC_OK;
ta_send_mam_req_t* req = send_mam_req_new();
ta_send_mam_res_t* res = send_mam_res_new();

if (send_mam_message_req_deserialize(obj, req)) {
ret = SC_MAM_FAILED_INIT;
ta_log_error("%s\n", ta_error_to_string(ret));
goto done;
}

ret = ta_send_mam_message(info, iconf, service, req, res);
// Generate UUID
char uuid[UUID_STR_LEN];
uuid_t binuuid;
uuid_generate_random(binuuid);
uuid_unparse(binuuid, uuid);
if (!uuid[0]) {
ta_log_error("%s\n", "Failed to generate UUID");
goto done;
}

// Buffer send_mam_req_t object for publishing it later
ret = cache_set(uuid, UUID_STR_LEN - 1, obj, strlen(obj), cache->timeout);
if (ret != SC_OK) {
ta_log_error("%s\n", ta_error_to_string(ret));
goto done;
}

// Buffer the UUID to the list
ret = cache_list_push(cache->buffer_mam_list_name, strlen(cache->buffer_mam_list_name), uuid, UUID_STR_LEN - 1);
if (ret != SC_OK) {
ta_log_error("%s\n", ta_error_to_string(ret));
goto done;
}

ret = send_mam_message_res_serialize(res, json_result);
ret = send_mam_message_res_serialize(NULL, uuid, json_result);
if (ret != SC_OK) {
ta_log_error("%s\n", ta_error_to_string(ret));
}

done:
send_mam_req_free(&req);
send_mam_res_free(&res);
return ret;
}

Expand Down
3 changes: 2 additions & 1 deletion accelerator/core/apis.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ status_t api_recv_mam_message(const iota_config_t* const iconf, const iota_clien
* - non-zero on error
*/
status_t api_send_mam_message(const ta_config_t* const info, const iota_config_t* const iconf,
const iota_client_service_t* const service, char const* const obj, char** json_result);
const ta_cache_t* const cache, const iota_client_service_t* const service,
char const* const obj, char** json_result);

/**
* @brief Send transfer to tangle.
Expand Down
Loading

0 comments on commit 0ad894a

Please sign in to comment.