diff options
Diffstat (limited to 'other')
-rw-r--r-- | other/bootstrap_daemon/src/config.c | 24 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/log.c | 11 | ||||
-rw-r--r-- | other/bootstrap_node_packets.c | 4 |
3 files changed, 22 insertions, 17 deletions
diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index 27d1364a..3e102af9 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c | |||
@@ -62,7 +62,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por | |||
62 | } | 62 | } |
63 | 63 | ||
64 | // similar procedure to the one of reading config file below | 64 | // similar procedure to the one of reading config file below |
65 | *tcp_relay_ports = malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t)); | 65 | *tcp_relay_ports = (uint16_t *)malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t)); |
66 | 66 | ||
67 | for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { | 67 | for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { |
68 | 68 | ||
@@ -80,7 +80,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por | |||
80 | 80 | ||
81 | // the loop above skips invalid ports, so we adjust the allocated memory size | 81 | // the loop above skips invalid ports, so we adjust the allocated memory size |
82 | if ((*tcp_relay_port_count) > 0) { | 82 | if ((*tcp_relay_port_count) > 0) { |
83 | *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); | 83 | *tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); |
84 | } else { | 84 | } else { |
85 | free(*tcp_relay_ports); | 85 | free(*tcp_relay_ports); |
86 | *tcp_relay_ports = NULL; | 86 | *tcp_relay_ports = NULL; |
@@ -102,7 +102,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por | |||
102 | return; | 102 | return; |
103 | } | 103 | } |
104 | 104 | ||
105 | *tcp_relay_ports = malloc(config_port_count * sizeof(uint16_t)); | 105 | *tcp_relay_ports = (uint16_t *)malloc(config_port_count * sizeof(uint16_t)); |
106 | 106 | ||
107 | int i; | 107 | int i; |
108 | 108 | ||
@@ -134,7 +134,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por | |||
134 | 134 | ||
135 | // the loop above skips invalid ports, so we adjust the allocated memory size | 135 | // the loop above skips invalid ports, so we adjust the allocated memory size |
136 | if ((*tcp_relay_port_count) > 0) { | 136 | if ((*tcp_relay_port_count) > 0) { |
137 | *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); | 137 | *tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); |
138 | } else { | 138 | } else { |
139 | free(*tcp_relay_ports); | 139 | free(*tcp_relay_ports); |
140 | *tcp_relay_ports = NULL; | 140 | *tcp_relay_ports = NULL; |
@@ -182,7 +182,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
182 | tmp_pid_file = DEFAULT_PID_FILE_PATH; | 182 | tmp_pid_file = DEFAULT_PID_FILE_PATH; |
183 | } | 183 | } |
184 | 184 | ||
185 | *pid_file_path = malloc(strlen(tmp_pid_file) + 1); | 185 | *pid_file_path = (char *)malloc(strlen(tmp_pid_file) + 1); |
186 | strcpy(*pid_file_path, tmp_pid_file); | 186 | strcpy(*pid_file_path, tmp_pid_file); |
187 | 187 | ||
188 | // Get keys file location | 188 | // Get keys file location |
@@ -194,7 +194,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
194 | tmp_keys_file = DEFAULT_KEYS_FILE_PATH; | 194 | tmp_keys_file = DEFAULT_KEYS_FILE_PATH; |
195 | } | 195 | } |
196 | 196 | ||
197 | *keys_file_path = malloc(strlen(tmp_keys_file) + 1); | 197 | *keys_file_path = (char *)malloc(strlen(tmp_keys_file) + 1); |
198 | strcpy(*keys_file_path, tmp_keys_file); | 198 | strcpy(*keys_file_path, tmp_keys_file); |
199 | 199 | ||
200 | // Get IPv6 option | 200 | // Get IPv6 option |
@@ -254,7 +254,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
254 | 254 | ||
255 | size_t tmp_motd_length = strlen(tmp_motd) + 1; | 255 | size_t tmp_motd_length = strlen(tmp_motd) + 1; |
256 | size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length; | 256 | size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length; |
257 | *motd = malloc(motd_length); | 257 | *motd = (char *)malloc(motd_length); |
258 | strncpy(*motd, tmp_motd, motd_length); | 258 | strncpy(*motd, tmp_motd, motd_length); |
259 | (*motd)[motd_length - 1] = '\0'; | 259 | (*motd)[motd_length - 1] = '\0'; |
260 | } | 260 | } |
@@ -310,7 +310,7 @@ static uint8_t *hex_string_to_bin(const char *hex_string) | |||
310 | } | 310 | } |
311 | 311 | ||
312 | size_t len = strlen(hex_string) / 2; | 312 | size_t len = strlen(hex_string) / 2; |
313 | uint8_t *ret = malloc(len); | 313 | uint8_t *ret = (uint8_t *)malloc(len); |
314 | 314 | ||
315 | const char *pos = hex_string; | 315 | const char *pos = hex_string; |
316 | size_t i; | 316 | size_t i; |
@@ -364,6 +364,8 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
364 | int i = 0; | 364 | int i = 0; |
365 | 365 | ||
366 | while (config_setting_length(node_list)) { | 366 | while (config_setting_length(node_list)) { |
367 | int address_resolved; | ||
368 | uint8_t *bs_public_key_bin; | ||
367 | 369 | ||
368 | node = config_setting_get_elem(node_list, 0); | 370 | node = config_setting_get_elem(node_list, 0); |
369 | 371 | ||
@@ -403,9 +405,9 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
403 | goto next; | 405 | goto next; |
404 | } | 406 | } |
405 | 407 | ||
406 | uint8_t *bs_public_key_bin = hex_string_to_bin(bs_public_key); | 408 | bs_public_key_bin = hex_string_to_bin(bs_public_key); |
407 | const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), | 409 | address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), |
408 | bs_public_key_bin); | 410 | bs_public_key_bin); |
409 | free(bs_public_key_bin); | 411 | free(bs_public_key_bin); |
410 | 412 | ||
411 | if (!address_resolved) { | 413 | if (!address_resolved) { |
diff --git a/other/bootstrap_daemon/src/log.c b/other/bootstrap_daemon/src/log.c index 2eae3286..7632d739 100644 --- a/other/bootstrap_daemon/src/log.c +++ b/other/bootstrap_daemon/src/log.c | |||
@@ -31,11 +31,12 @@ | |||
31 | #include <stdarg.h> | 31 | #include <stdarg.h> |
32 | #include <stdio.h> | 32 | #include <stdio.h> |
33 | 33 | ||
34 | static LOG_BACKEND current_backend = -1; | 34 | #define INVALID_BACKEND (LOG_BACKEND)-1u |
35 | static LOG_BACKEND current_backend = INVALID_BACKEND; | ||
35 | 36 | ||
36 | bool open_log(LOG_BACKEND backend) | 37 | bool open_log(LOG_BACKEND backend) |
37 | { | 38 | { |
38 | if (current_backend != -1) { | 39 | if (current_backend != INVALID_BACKEND) { |
39 | return false; | 40 | return false; |
40 | } | 41 | } |
41 | 42 | ||
@@ -50,7 +51,7 @@ bool open_log(LOG_BACKEND backend) | |||
50 | 51 | ||
51 | bool close_log(void) | 52 | bool close_log(void) |
52 | { | 53 | { |
53 | if (current_backend == -1) { | 54 | if (current_backend == INVALID_BACKEND) { |
54 | return false; | 55 | return false; |
55 | } | 56 | } |
56 | 57 | ||
@@ -58,7 +59,7 @@ bool close_log(void) | |||
58 | closelog(); | 59 | closelog(); |
59 | } | 60 | } |
60 | 61 | ||
61 | current_backend = -1; | 62 | current_backend = INVALID_BACKEND; |
62 | 63 | ||
63 | return true; | 64 | return true; |
64 | } | 65 | } |
@@ -121,5 +122,5 @@ bool write_log(LOG_LEVEL level, const char *format, ...) | |||
121 | 122 | ||
122 | va_end(args); | 123 | va_end(args); |
123 | 124 | ||
124 | return current_backend != -1; | 125 | return current_backend != INVALID_BACKEND; |
125 | } | 126 | } |
diff --git a/other/bootstrap_node_packets.c b/other/bootstrap_node_packets.c index 8ee26786..8abbb7f2 100644 --- a/other/bootstrap_node_packets.c +++ b/other/bootstrap_node_packets.c | |||
@@ -40,13 +40,15 @@ static int handle_info_request(void *object, IP_Port source, const uint8_t *pack | |||
40 | return 1; | 40 | return 1; |
41 | } | 41 | } |
42 | 42 | ||
43 | Networking_Core *nc = (Networking_Core *)object; | ||
44 | |||
43 | uint8_t data[1 + sizeof(bootstrap_version) + MAX_MOTD_LENGTH]; | 45 | uint8_t data[1 + sizeof(bootstrap_version) + MAX_MOTD_LENGTH]; |
44 | data[0] = BOOTSTRAP_INFO_PACKET_ID; | 46 | data[0] = BOOTSTRAP_INFO_PACKET_ID; |
45 | memcpy(data + 1, &bootstrap_version, sizeof(bootstrap_version)); | 47 | memcpy(data + 1, &bootstrap_version, sizeof(bootstrap_version)); |
46 | uint16_t len = 1 + sizeof(bootstrap_version) + bootstrap_motd_length; | 48 | uint16_t len = 1 + sizeof(bootstrap_version) + bootstrap_motd_length; |
47 | memcpy(data + 1 + sizeof(bootstrap_version), bootstrap_motd, bootstrap_motd_length); | 49 | memcpy(data + 1 + sizeof(bootstrap_version), bootstrap_motd, bootstrap_motd_length); |
48 | 50 | ||
49 | if (sendpacket(object, source, data, len) == len) { | 51 | if (sendpacket(nc, source, data, len) == len) { |
50 | return 0; | 52 | return 0; |
51 | } | 53 | } |
52 | 54 | ||