From a862354f26aed581165064b86f74b26b9c0945aa Mon Sep 17 00:00:00 2001 From: HYChang Date: Mon, 24 Feb 2020 10:42:02 +0800 Subject: [PATCH] feat: Migrate ta-endpoint into legato Add legato build target into gitignore. Add new file util/utils.h util/utils.c for utitlity functions. Add build libta_endpoint.so library target for legato app ta_app into Makefile. Add ta_app build target and cleanup target into Makefile. Remove redefined macro inside `conn_http.h`. Add new directory endpointComponent and files for legato app ta_app. Move utility functions inside `main.c` into utils.h utils.c. Add doxgen comment for utils.h. Fix compile warning inside utils directory files. Closes #20 --- .gitignore | 6 +- Makefile | 24 +++++--- connectivity/Makefile | 2 +- connectivity/conn_http.h | 3 - endpointComponent/Component.cdef | 41 +++++++++++++ endpointComponent/endpoint.c | 96 +++++++++++++++++++++++++++++ endpointComponent/resolv.conf | 2 + main.c | 100 ++++--------------------------- ta-endpoint.adef | 12 ++++ utils/Makefile | 8 +-- utils/crypto_utils.c | 8 +-- utils/crypto_utils.h | 4 +- utils/uart_utils.c | 8 ++- utils/utils.c | 75 +++++++++++++++++++++++ utils/utils.h | 66 ++++++++++++++++++++ 15 files changed, 343 insertions(+), 112 deletions(-) create mode 100644 endpointComponent/Component.cdef create mode 100644 endpointComponent/endpoint.c create mode 100644 endpointComponent/resolv.conf create mode 100644 ta-endpoint.adef create mode 100644 utils/utils.c create mode 100644 utils/utils.h diff --git a/.gitignore b/.gitignore index 933f959..5af0012 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,8 @@ build/ addr_log.log tests/build/ *.c.d -*/*.c.d \ No newline at end of file +*/*.c.d + +# Legato build targets +_build_ta-endpoint/ +ta_endpoint.wp77xx.update diff --git a/Makefile b/Makefile index ea736c9..2b7cb78 100644 --- a/Makefile +++ b/Makefile @@ -29,17 +29,18 @@ INCLUDES = -I$(THIRD_PARTY_PATH)/http-parser -I$(MBEDTLS_PATH)/include -I$(ROOT_ LIBS = $(MBEDTLS_PATH)/library/libmbedx509.a $(MBEDTLS_PATH)/library/libmbedtls.a $(MBEDTLS_PATH)/library/libmbedcrypto.a export INCLUDES -UTILS_OBJS = $(UTILS_PATH)/crypto_utils.o $(UTILS_PATH)/serializer.o $(UTILS_PATH)/tryte_byte_conv.o $(UTILS_PATH)/uart_utils.o +UTILS_OBJS = $(UTILS_PATH)/crypto_utils.o $(UTILS_PATH)/serializer.o $(UTILS_PATH)/tryte_byte_conv.o $(UTILS_PATH)/uart_utils.o $(UTILS_PATH)/utils.o # We need to modify this rule here to be compatible to the situation # that we have several different ways of connectivity in the future CONNECTIVITY_OBJS = conn_http.o -OBJS = main.o $(HTTP_PARSER_PATH)/http_parser.o $(UTILS_OBJS) $(CONNECTIVITY_OBJS) +OBJS = main.o http_parser.o $(UTILS_OBJS) $(CONNECTIVITY_OBJS) +TALIB = libta_endpoint.so .SUFFIXES:.c .o .PHONY: all clean test pre-build -all: pre-build ta_client mbedtls_make +all: pre-build ta_client mbedtls_make $(TALIB) ta_app ta_client: mbedtls_make $(OBJS) @echo Linking: $@ .... @@ -51,10 +52,14 @@ mbedtls_make: if [ $$? != 0 ]; then exit 1; fi; \ done +$(TALIB): $(UTILS_OBJS) $(CONNECTIVITY_OBJS) http_parser.o + $(CC) -shared -o $@ $< + conn_http.o: connectivity/conn_http.c @echo Compiling $@ ... - $(CC) -v -c $(CFLAGS) $(INCLUDES) -o $@ $< - + $(CC) -c $(CFLAGS) $(INCLUDES) -o $@ $< +http_parser.o: $(THIRD_PARTY_PATH)/http-parser/http_parser.c $(THIRD_PARTY_PATH)/http-parser/http_parser.h + $(CC) -c $(CFLAGS) $(INCLUDES) -o $@ $< main.o: main.c $(UTILS_OBJS) @echo Compiling: $< .... $(CC) -c $(CFLAGS) $(INCLUDES) -o $@ $< @@ -62,8 +67,10 @@ $(UTILS_OBJS): $(MAKE) -C $(UTILS_PATH) test: $(TEST_PATH) $(UTILS_OBJS) $(MAKE) -C $(TEST_PATH) +ta_app: $(TALIB) + mkapp -v -t wp77xx ta-endpoint.adef -clean: clean_client clean_third_party clean_test +clean: clean_client clean_third_party clean_test clean_build_app clean_test: $(MAKE) -C $(TEST_PATH) clean @@ -71,7 +78,10 @@ clean_test: clean_client: $(MAKE) -C $(UTILS_PATH) clean $(MAKE) -C $(CONNECTIVITY_PATH) clean - rm -f ta_client *.o *.c.d + rm -f ta_client *.o *.c.d $(TALIB) + +clean_build_app: + rm -rf _build_* *.update clean_third_party: clean_mbedtls clean_http_parser diff --git a/connectivity/Makefile b/connectivity/Makefile index 604c323..6ed28c6 100644 --- a/connectivity/Makefile +++ b/connectivity/Makefile @@ -5,7 +5,7 @@ all: conn_http.o .NOTPARALLEL: connectivity/conn_http.o: conn_http.c @echo Compiling $@ ... - $(CC) -v -c $(CFLAGS) $(INCLUDES) -MMD -MF conn_http.c.d -o $@ $< + $(CC) -fPIC -c $(CFLAGS) $(INCLUDES) -MMD -MF conn_http.c.d -o $@ $< clean: rm -f *.o *.c.d diff --git a/connectivity/conn_http.h b/connectivity/conn_http.h index 0f36a66..4119b34 100644 --- a/connectivity/conn_http.h +++ b/connectivity/conn_http.h @@ -12,7 +12,6 @@ #ifdef __cplusplus extern "C" { #endif - #include #include "defined_error.h" #include "http_parser.h" @@ -23,8 +22,6 @@ extern "C" { #include "mbedtls/net.h" #include "mbedtls/ssl.h" -#define HTTP_OK 200 - char *http_res_body; typedef struct { diff --git a/endpointComponent/Component.cdef b/endpointComponent/Component.cdef new file mode 100644 index 0000000..2cb9130 --- /dev/null +++ b/endpointComponent/Component.cdef @@ -0,0 +1,41 @@ +sources: +{ + endpoint.c +} + +cflags: +{ + -g -O0 + -DDEBUG=1 + -I$CURDIR/../utils + -I$CURDIR/../connectivity + -I$CURDIR/../third_party/http-parser + -I$CURDIR/../third_party/mbedtls/include +} + +ldflags: +{ + -L$CURDIR/../ +} + +bundles: +{ + file: + { + [r] resolv.conf /etc/ + $CURDIR/../libta_endpoint.so /lib/ + } +} + +requires: +{ + device: + { + [rw] /dev/ttyHS0 /dev/ttyHS0 + } + + lib: + { + libta_endpoint.so + } +} diff --git a/endpointComponent/endpoint.c b/endpointComponent/endpoint.c new file mode 100644 index 0000000..87c7026 --- /dev/null +++ b/endpointComponent/endpoint.c @@ -0,0 +1,96 @@ +#include "interfaces.h" +#include "legato.h" + +#include +#include +#include +#include +#include "connectivity/conn_http.h" +#include "utils/crypto_utils.h" +#include "utils/serializer.h" +#include "utils/tryte_byte_conv.h" +#include "utils/uart_utils.h" +#include "utils/utils.h" + +#define MSG "%s:%s" + +COMPONENT_INIT { + uint8_t ciphertext[1024] = {0}, iv[16] = {0}, raw_msg[1000] = {0}; + uint32_t raw_msg_len = 1 + ADDR_LEN + 20, ciphertext_len = 0, msg_len; + char tryte_msg[1024] = {0}, msg[1024] = {0}, addr[ADDR_LEN + 1] = ADDRESS, next_addr[ADDR_LEN + 1] = {0}; + srand(time(NULL)); + + // init uart for modem + int fd = uart_init(); + if (fd < 0) { + LE_ERROR("Error in initializing UART\n"); + } + + // create log file + if (log_address(next_addr) != 0) { + LE_ERROR("log address failed\n"); + } + + char *response = NULL; + time_t timer; + char time_str[26]; + struct tm *tm_info; + + fd_set rset; + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = 500; + // TODO:change to none blocking I/O descriptor + while (true) { + FD_ZERO(&rset); + FD_SET(fd, &rset); + select(fd + 1, &rset, NULL, NULL, &tv); + + if (FD_ISSET(fd, &rset)) { + time(&timer); + tm_info = localtime(&timer); + strftime(time_str, 26, "%Y-%m-%d %H:%M:%S", tm_info); + printf("%s\n", time_str); + gen_trytes(ADDR_LEN, next_addr); + + response = uart_read(fd); + // real transmitted data + snprintf((char *)raw_msg, raw_msg_len, MSG, next_addr, response); + LE_DEBUG("Raw_msg:%s\n", raw_msg); + uint8_t private_key[AES_BLOCK_SIZE * 2] = {0}; + uint8_t id[IMSI_LEN + 1] = {0}; + + if (get_aes_key(private_key) != 0) { + LE_ERROR("%s\n", "get aes key error"); + } + // fetch Device_ID (IMSI, len <= 15) + if (get_device_id((char *)id) != 0) { + LE_ERROR("%s\n", "get device id error"); + } + + ciphertext_len = ta_encrypt(raw_msg, strlen((char *)raw_msg), ciphertext, 1024, iv, private_key, id); + if (ciphertext_len == 0) { + LE_ERROR("%s\n", "ta_encrypt msg error"); + } + serialize_msg(iv, ciphertext_len, ciphertext, msg, &msg_len); + bytes_to_trytes((const unsigned char *)msg, msg_len, tryte_msg); + + // Init http session. verify: check the server CA cert. + char msg_body[1024]; + gen_tryte_msg(tryte_msg, addr, msg_body); + if (send_https_msg(HOST, PORT, API, msg_body, 1024) != HTTP_OK) { + LE_ERROR("Response from ta server failed\n"); + } + + strncpy(addr, next_addr, ADDR_LEN); + free(response); + response = NULL; + printf( + "========================Finishing Sending " + "Transaction========================\n\n"); + } + if (tcflush(fd, TCIOFLUSH) != 0) { + perror("tcflush error"); + } + } +} diff --git a/endpointComponent/resolv.conf b/endpointComponent/resolv.conf new file mode 100644 index 0000000..276c26b --- /dev/null +++ b/endpointComponent/resolv.conf @@ -0,0 +1,2 @@ +nameserver 8.8.8.8 +nameserver 8.8.4.4 diff --git a/main.c b/main.c index 1a14200..dfefc8e 100644 --- a/main.c +++ b/main.c @@ -1,94 +1,21 @@ #include #include #include -#include -#include "connectivity/conn_http.h" -#include "http_parser.h" -#include "utils/crypto_utils.h" -#include "utils/serializer.h" -#include "utils/tryte_byte_conv.h" -#include "utils/uart_utils.h" - -#define HOST "tangle-accel.puyuma.org" -#define PORT "443" -#define API "transaction/" -#define SSL_SEED "nonce" -#define REQ_BODY \ - "{\"value\": 0, \"tag\": \"POWEREDBYTANGLEACCELERATOR9\", \"message\": " \ - "\"%s\", \"address\":\"%s\"}\r\n\r\n" -#define ADDRESS \ - "POWEREDBYTANGLEACCELERATOR999999999999999999999999999999999999999999999999" \ - "999999A" -#define ADDR_LEN 81 +#include +#include +#include "conn_http.h" +#include "crypto_utils.h" +#include "serializer.h" +#include "tryte_byte_conv.h" +#include "uart_utils.h" +#include "utils.h" #ifndef DEBUG #define MSG "%s:%s" #else #define MSG "%s:THISISMSG9THISISMSG9THISISMSG" -#define ADDR_LOG_PATH "addr_log.log" #endif -static char addr_log_template[] = "\n%s\n"; - -// Test mode only, should not use on deployment -void gen_trytes(uint16_t len, char *out) { - const char tryte_alphabet[] = "9ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - uint8_t rand_index; - for (int i = 0; i < len; i++) { - rand_index = rand() % 27; - out[i] = tryte_alphabet[rand_index]; - } -} - -int send_https_msg(char const *const host, char const *const port, char const *const api, char const *const tryte_msg, - char const *const addr) { - char req_body[1024] = {}, res[4096] = {0}; - char *req = NULL; - int ret = 0; - sprintf(req_body, REQ_BODY, tryte_msg, addr); - set_post_request(api, host, atoi(port), req_body, &req); - -#ifdef DEBUG - printf("req packet = \n%s", req); -#endif - - http_parser_settings settings; - settings.on_body = parser_body_callback; - http_parser *parser = malloc(sizeof(http_parser)); - - connect_info_t info = {.https = true}; - http_open(&info, SSL_SEED, host, port); - http_send_request(&info, req); - http_read_response(&info, res, sizeof(res) / sizeof(char)); - http_close(&info); - http_parser_init(parser, HTTP_RESPONSE); - http_parser_execute(parser, &settings, res, strlen(res)); - printf("HTTP Response: %s\n", http_res_body); - free(http_res_body); - http_res_body = NULL; - - ret = parser->status_code; - free(parser); - free(req); - return ret; -} - -int log_address(char *next_addr) { - FILE *fp; - char addr_log[ADDR_LEN + 3]; - // Append the next address to the address log file - fp = fopen(ADDR_LOG_PATH, "a"); - if (!fp) { - perror("open addr_log.log failed:"); - fclose(fp); - return -1; - } - snprintf(addr_log, 83, addr_log_template, next_addr); - fputs(addr_log, fp); - fclose(fp); - return 0; -} - int main(int argc, char *argv[]) { uint8_t ciphertext[1024] = {0}, iv[16] = {0}, raw_msg[1000] = {0}; uint32_t raw_msg_len = 1 + ADDR_LEN + 20, ciphertext_len = 0, msg_len; @@ -119,7 +46,6 @@ int main(int argc, char *argv[]) { tv.tv_sec = 0; tv.tv_usec = 500; while (true) { - // TODO add select FD_ZERO(&rset); FD_SET(fd, &rset); select(fd + 1, &rset, NULL, NULL, &tv); @@ -130,7 +56,6 @@ int main(int argc, char *argv[]) { tm_info = localtime(&timer); strftime(time_str, 26, "%Y-%m-%d %H:%M:%S", tm_info); printf("%s\n", time_str); - // TODO: not good gen_trytes(ADDR_LEN, next_addr); #ifndef DEBUG @@ -155,7 +80,7 @@ int main(int argc, char *argv[]) { return -1; } // fetch Device_ID (IMSI, len <= 15) - if (get_device_id(id) != 0) { + if (get_device_id((char *)id) != 0) { fprintf(stderr, "%s\n", "get device id error"); return -1; } @@ -182,8 +107,10 @@ int main(int argc, char *argv[]) { bytes_to_trytes((const unsigned char *)msg, msg_len, tryte_msg); // Init http session. verify: check the server CA cert. - if (send_https_msg(HOST, PORT, API, tryte_msg, addr) != HTTP_OK) { - fprintf(stderr, "Response from ta server failed"); + char msg_body[1024]; + gen_tryte_msg(tryte_msg, addr, msg_body); + if (send_https_msg(HOST, PORT, API, msg_body, 1024) != HTTP_OK) { + fprintf(stderr, "Response from ta server failed\n"); } strncpy(addr, next_addr, ADDR_LEN); @@ -199,6 +126,5 @@ int main(int argc, char *argv[]) { } } #endif - return 0; } diff --git a/ta-endpoint.adef b/ta-endpoint.adef new file mode 100644 index 0000000..936a21f --- /dev/null +++ b/ta-endpoint.adef @@ -0,0 +1,12 @@ +executables: +{ + taEndpoint = (endpointComponent) +} + +processes: +{ + run: + { + (taEndpoint) + } +} diff --git a/utils/Makefile b/utils/Makefile index b486a56..fa82534 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -1,6 +1,6 @@ -OBJS = crypto_utils.o serializer.o tryte_byte_conv.o uart_utils.o +OBJS = crypto_utils.o serializer.o tryte_byte_conv.o uart_utils.o utils.o -ifeq ($(KEY_DEBUG), n) +ifeq ($(DEBUG), n) UTILS_CFLAGS = $(CFLAGS) else UTILS_CFLAGS = $(CFLAGS) -DKEY_DEBUG @@ -9,7 +9,7 @@ endif all: $(OBJS) %.o: %.c - $(CC) -c $(UTILS_CFLAGS) $(INCLUDES) -o $@ $^ + $(CC) -fPIC -c $(UTILS_CFLAGS) $(INCLUDES) -o $@ $^ clean: - rm -f *.o \ No newline at end of file + rm -f *.o diff --git a/utils/crypto_utils.c b/utils/crypto_utils.c index bc8b8a4..770b621 100644 --- a/utils/crypto_utils.c +++ b/utils/crypto_utils.c @@ -10,7 +10,7 @@ // The device ID we are used here is IMSI. We could use other physical ID in the // future. -int get_device_id(const char *device_id) { +int get_device_id(char *device_id) { // TODO: replace cm command char result_buf[MAXLINE], *imsi; char cmd[] = "cm sim info"; @@ -39,7 +39,7 @@ int get_device_id(const char *device_id) { } // Get AES key with hashchain in legato originated app form. -int get_aes_key(const uint8_t *key) { +int get_aes_key(uint8_t *key) { // TODO: replace cm command char hash_chain_res[MAXLINE]; char cmd[] = "cm sim info"; @@ -178,11 +178,11 @@ int encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *cipherte // fetch timestamp uint64_t timestamp = time(NULL); // concatenate (Device_ID, timestamp) - snprintf(nonce, IMSI_LEN + MAX_TIMESTAMP_LEN + 1, "%s-%ld", device_id, timestamp); + snprintf(nonce, IMSI_LEN + MAX_TIMESTAMP_LEN + 1, "%s-%llu", device_id, timestamp); // hash base data #ifndef DEBUG mbedtls_md_starts(&sha_ctx); - mbedtls_md_update(&sha_ctx, nonce, IMSI_LEN + MAX_TIMESTAMP_LEN); + mbedtls_md_update(&sha_ctx, (unsigned char *)nonce, IMSI_LEN + MAX_TIMESTAMP_LEN); mbedtls_md_finish(&sha_ctx, digest); mbedtls_md_starts(&sha_ctx); diff --git a/utils/crypto_utils.h b/utils/crypto_utils.h index 39d8231..49a6e10 100644 --- a/utils/crypto_utils.h +++ b/utils/crypto_utils.h @@ -19,8 +19,8 @@ extern "C" { #define MAXLINE 1024 #define IMSI_LEN 15 -int get_device_id(const char *device_id); -int get_aes_key(const uint8_t *key); +int get_device_id(char *device_id); +int get_aes_key(uint8_t *key); int encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *ciphertext, int ciphertext_len, uint8_t iv[16], uint8_t key[AES_BLOCK_SIZE * 2], uint8_t device_id[IMSI_LEN + 1]); int decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *plaintext, int plaintext_len, uint8_t iv[16], diff --git a/utils/uart_utils.c b/utils/uart_utils.c index e494fa1..612512c 100644 --- a/utils/uart_utils.c +++ b/utils/uart_utils.c @@ -70,7 +70,7 @@ void uart_write(const int fd, char *cmd) { ssize_t cmd_len = strlen(cmd); ssize_t wlen = write(fd, cmd, cmd_len); if (wlen != cmd_len) { - printf("Error from write: %ld, %d\n", wlen, errno); + printf("Error from write: %zd, %d\n", wlen, errno); } tcdrain(fd); /* delay for output */ } @@ -81,11 +81,13 @@ char *uart_read(const int fd) { ssize_t rdlen = read(fd, buf, sizeof(buf) - 1); if (rdlen > 0) { - // printf("buf = %s\n", buf); +#ifdef DEBUG + printf("buf = %s\n", buf); +#endif response = (char *)malloc(sizeof(char) * rdlen); strncpy(response, (char *)buf, READ_BUFFER_SIZE); } else if (rdlen < 0) { - printf("Error from read: %ld: %s\n", rdlen, strerror(errno)); + printf("Error from read: %zd: %s\n", rdlen, strerror(errno)); } return response; diff --git a/utils/utils.c b/utils/utils.c new file mode 100644 index 0000000..ab734a0 --- /dev/null +++ b/utils/utils.c @@ -0,0 +1,75 @@ +#include "utils.h" + +#include +#include +#include +#include +#include +#include "conn_http.h" +#include "http_parser.h" + +static char addr_log_template[] = "\n%s\n"; + +void gen_trytes(uint16_t len, char *out) { + const char tryte_alphabet[] = "9ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + uint8_t rand_index; + for (int i = 0; i < len; i++) { + rand_index = rand() % 27; + out[i] = tryte_alphabet[rand_index]; + } +} + +void gen_tryte_msg(const char *tryte_msg, const char *addr, char req_body[1024]) { + memset(req_body, '0', sizeof(char) * 1024); + snprintf(req_body, 1024, REQ_BODY, tryte_msg, addr); + +#ifdef DEBUG + printf("req packet = \n%s", req_body); +#endif +} + +int send_https_msg(char const *const host, char const *const port, char const *const api, const char *msg, + const int msg_len) { + char res[4096] = {0}; + char *req = NULL; + int ret = 0; + + set_post_request(api, host, atoi(port), msg, &req); + http_parser_settings settings; + settings.on_body = parser_body_callback; + http_parser *parser = malloc(sizeof(http_parser)); + + connect_info_t info = {.https = true}; + http_open(&info, SSL_SEED, host, port); + http_send_request(&info, req); + http_read_response(&info, res, sizeof(res) / sizeof(char)); + http_close(&info); + http_parser_init(parser, HTTP_RESPONSE); + http_parser_execute(parser, &settings, res, strlen(res)); +#ifdef DEBUG + printf("HTTP Response: %s\n", http_res_body); +#endif + free(http_res_body); + http_res_body = NULL; + + ret = parser->status_code; + free(parser); + free(req); + return ret; +} + +int log_address(char *next_addr) { + FILE *fp; + char addr_log[ADDR_LEN + 3]; + // Append the next address to the address log file + fp = fopen(ADDR_LOG_PATH, "a"); + if (!fp) { + perror("open addr_log.log failed:"); + fclose(fp); + return -1; + } + snprintf(addr_log, 83, addr_log_template, next_addr); + fputs(addr_log, fp); + fclose(fp); + return 0; +} diff --git a/utils/utils.h b/utils/utils.h new file mode 100644 index 0000000..adeb2f0 --- /dev/null +++ b/utils/utils.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ +#ifndef UTILS_H_JKZACOAY +#define UTILS_H_JKZACOAY + +#include +#define HOST "tangle-accel.puyuma.org" +#define PORT "443" +#define API "transaction/" +#define SSL_SEED "nonce" +#define REQ_BODY \ + "{\"value\": 0, \"tag\": \"POWEREDBYTANGLEACCELERATOR9\", \"message\": " \ + "\"%s\", \"address\":\"%s\"}\r\n\r\n" +#define ADDRESS \ + "POWEREDBYTANGLEACCELERATOR999999999999999999999999999999999999999999999999" \ + "999999A" +#define ADDR_LEN 81 +#define ADDR_LOG_PATH "addr_log.log" + +/** + * @brief generate trytes from random + * + * @param len length of output + * @param out output array + */ +void gen_trytes(uint16_t len, char *out); + +/** + * @brief log address into addr_log.log + * + * @param next_addr address to log + * + * @return log success 0 else -1 + * @see gen_trytes() + */ +int log_address(char *next_addr); + +/** + * @brief create message to send to tangle accerlator + * + * @param tryte_msg byte message which has convert to tryte + * @param addr IOTA next address + * @param req_body[1024] message array + */ +void gen_tryte_msg(const char *tryte_msg, const char *addr, char req_body[1024]); + +/** + * @brief send message vi http protocal + * + * @param host http host + * @param port http port + * @param api http api + * @param msg message to send + * @param msg_len length of message array + * + * @return http status + * @see http_retcode_t + */ +int send_https_msg(char const *const host, char const *const port, char const *const api, const char *msg, + const int msg_len); +#endif /* end of include guard: UTILS_H_JKZACOAY */