diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-15 01:23:08 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-01-16 20:06:07 +0000 |
commit | 643eea60bb9dcf4ecb33d64666b1bc77cbfd7438 (patch) | |
tree | 2f98b0c7869fddac03f834be508a182da06f07b4 /other | |
parent | 22db2b9fe581a35300b66126604d12e83c2eafb1 (diff) |
Make DHT a module-private type.
Diffstat (limited to 'other')
-rw-r--r-- | other/DHT_bootstrap.c | 21 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/tox-bootstrapd.c | 16 |
2 files changed, 19 insertions, 18 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 5eae46b9..33ca45c2 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c | |||
@@ -70,12 +70,12 @@ static void manage_keys(DHT *dht) | |||
70 | exit(1); | 70 | exit(1); |
71 | } | 71 | } |
72 | 72 | ||
73 | memcpy(dht->self_public_key, keys, CRYPTO_PUBLIC_KEY_SIZE); | 73 | dht_set_self_public_key(dht, keys); |
74 | memcpy(dht->self_secret_key, keys + CRYPTO_PUBLIC_KEY_SIZE, CRYPTO_SECRET_KEY_SIZE); | 74 | dht_set_self_public_key(dht, keys + CRYPTO_PUBLIC_KEY_SIZE); |
75 | printf("Keys loaded successfully.\n"); | 75 | printf("Keys loaded successfully.\n"); |
76 | } else { | 76 | } else { |
77 | memcpy(keys, dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 77 | memcpy(keys, dht_get_self_public_key(dht), CRYPTO_PUBLIC_KEY_SIZE); |
78 | memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht->self_secret_key, CRYPTO_SECRET_KEY_SIZE); | 78 | memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht_get_self_secret_key(dht), CRYPTO_SECRET_KEY_SIZE); |
79 | keys_file = fopen("key", "w"); | 79 | keys_file = fopen("key", "w"); |
80 | 80 | ||
81 | if (keys_file == NULL) { | 81 | if (keys_file == NULL) { |
@@ -120,7 +120,7 @@ int main(int argc, char *argv[]) | |||
120 | Onion_Announce *onion_a = new_onion_announce(dht); | 120 | Onion_Announce *onion_a = new_onion_announce(dht); |
121 | 121 | ||
122 | #ifdef DHT_NODE_EXTRA_PACKETS | 122 | #ifdef DHT_NODE_EXTRA_PACKETS |
123 | bootstrap_set_callbacks(dht->net, DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD)); | 123 | bootstrap_set_callbacks(dht_get_net(dht), DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD)); |
124 | #endif | 124 | #endif |
125 | 125 | ||
126 | if (!(onion && onion_a)) { | 126 | if (!(onion && onion_a)) { |
@@ -137,7 +137,7 @@ int main(int argc, char *argv[]) | |||
137 | #ifdef TCP_RELAY_ENABLED | 137 | #ifdef TCP_RELAY_ENABLED |
138 | #define NUM_PORTS 3 | 138 | #define NUM_PORTS 3 |
139 | uint16_t ports[NUM_PORTS] = {443, 3389, PORT}; | 139 | uint16_t ports[NUM_PORTS] = {443, 3389, PORT}; |
140 | TCP_Server *tcp_s = new_TCP_server(ipv6enabled, NUM_PORTS, ports, dht->self_secret_key, onion); | 140 | TCP_Server *tcp_s = new_TCP_server(ipv6enabled, NUM_PORTS, ports, dht_get_self_secret_key(dht), onion); |
141 | 141 | ||
142 | if (tcp_s == NULL) { | 142 | if (tcp_s == NULL) { |
143 | printf("TCP server failed to initialize.\n"); | 143 | printf("TCP server failed to initialize.\n"); |
@@ -155,14 +155,15 @@ int main(int argc, char *argv[]) | |||
155 | } | 155 | } |
156 | 156 | ||
157 | for (i = 0; i < 32; i++) { | 157 | for (i = 0; i < 32; i++) { |
158 | printf("%02hhX", dht->self_public_key[i]); | 158 | const uint8_t *const self_public_key = dht_get_self_public_key(dht); |
159 | fprintf(file, "%02hhX", dht->self_public_key[i]); | 159 | printf("%02hhX", self_public_key[i]); |
160 | fprintf(file, "%02hhX", self_public_key[i]); | ||
160 | } | 161 | } |
161 | 162 | ||
162 | fclose(file); | 163 | fclose(file); |
163 | 164 | ||
164 | printf("\n"); | 165 | printf("\n"); |
165 | printf("Port: %u\n", net_ntohs(net_port(dht->net))); | 166 | printf("Port: %u\n", net_ntohs(net_port(dht_get_net(dht)))); |
166 | 167 | ||
167 | if (argc > argvoffset + 3) { | 168 | if (argc > argvoffset + 3) { |
168 | printf("Trying to bootstrap into the network...\n"); | 169 | printf("Trying to bootstrap into the network...\n"); |
@@ -199,7 +200,7 @@ int main(int argc, char *argv[]) | |||
199 | #ifdef TCP_RELAY_ENABLED | 200 | #ifdef TCP_RELAY_ENABLED |
200 | do_TCP_server(tcp_s); | 201 | do_TCP_server(tcp_s); |
201 | #endif | 202 | #endif |
202 | networking_poll(dht->net, NULL); | 203 | networking_poll(dht_get_net(dht), NULL); |
203 | 204 | ||
204 | c_sleep(1); | 205 | c_sleep(1); |
205 | } | 206 | } |
diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index c6780fa3..e0472cba 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c | |||
@@ -73,12 +73,12 @@ static int manage_keys(DHT *dht, char *keys_file_path) | |||
73 | return 0; | 73 | return 0; |
74 | } | 74 | } |
75 | 75 | ||
76 | memcpy(dht->self_public_key, keys, CRYPTO_PUBLIC_KEY_SIZE); | 76 | dht_set_self_public_key(dht, keys); |
77 | memcpy(dht->self_secret_key, keys + CRYPTO_PUBLIC_KEY_SIZE, CRYPTO_SECRET_KEY_SIZE); | 77 | dht_set_self_secret_key(dht, keys + CRYPTO_PUBLIC_KEY_SIZE); |
78 | } else { | 78 | } else { |
79 | // Otherwise save new keys | 79 | // Otherwise save new keys |
80 | memcpy(keys, dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 80 | memcpy(keys, dht_get_self_public_key(dht), CRYPTO_PUBLIC_KEY_SIZE); |
81 | memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht->self_secret_key, CRYPTO_SECRET_KEY_SIZE); | 81 | memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht_get_self_secret_key(dht), CRYPTO_SECRET_KEY_SIZE); |
82 | 82 | ||
83 | keys_file = fopen(keys_file_path, "w"); | 83 | keys_file = fopen(keys_file_path, "w"); |
84 | 84 | ||
@@ -261,7 +261,7 @@ int main(int argc, char *argv[]) | |||
261 | } | 261 | } |
262 | 262 | ||
263 | if (enable_motd) { | 263 | if (enable_motd) { |
264 | if (bootstrap_set_callbacks(dht->net, DAEMON_VERSION_NUMBER, (uint8_t *)motd, strlen(motd) + 1) == 0) { | 264 | if (bootstrap_set_callbacks(dht_get_net(dht), DAEMON_VERSION_NUMBER, (uint8_t *)motd, strlen(motd) + 1) == 0) { |
265 | log_write(LOG_LEVEL_INFO, "Set MOTD successfully.\n"); | 265 | log_write(LOG_LEVEL_INFO, "Set MOTD successfully.\n"); |
266 | } else { | 266 | } else { |
267 | log_write(LOG_LEVEL_ERROR, "Couldn't set MOTD: %s. Exiting.\n", motd); | 267 | log_write(LOG_LEVEL_ERROR, "Couldn't set MOTD: %s. Exiting.\n", motd); |
@@ -288,7 +288,7 @@ int main(int argc, char *argv[]) | |||
288 | return 1; | 288 | return 1; |
289 | } | 289 | } |
290 | 290 | ||
291 | tcp_server = new_TCP_server(enable_ipv6, tcp_relay_port_count, tcp_relay_ports, dht->self_secret_key, onion); | 291 | tcp_server = new_TCP_server(enable_ipv6, tcp_relay_port_count, tcp_relay_ports, dht_get_self_secret_key(dht), onion); |
292 | 292 | ||
293 | // tcp_relay_port_count != 0 at this point | 293 | // tcp_relay_port_count != 0 at this point |
294 | free(tcp_relay_ports); | 294 | free(tcp_relay_ports); |
@@ -308,7 +308,7 @@ int main(int argc, char *argv[]) | |||
308 | return 1; | 308 | return 1; |
309 | } | 309 | } |
310 | 310 | ||
311 | print_public_key(dht->self_public_key); | 311 | print_public_key(dht_get_self_public_key(dht)); |
312 | 312 | ||
313 | uint64_t last_LANdiscovery = 0; | 313 | uint64_t last_LANdiscovery = 0; |
314 | const uint16_t net_htons_port = net_htons(port); | 314 | const uint16_t net_htons_port = net_htons(port); |
@@ -332,7 +332,7 @@ int main(int argc, char *argv[]) | |||
332 | do_TCP_server(tcp_server); | 332 | do_TCP_server(tcp_server); |
333 | } | 333 | } |
334 | 334 | ||
335 | networking_poll(dht->net, NULL); | 335 | networking_poll(dht_get_net(dht), NULL); |
336 | 336 | ||
337 | if (waiting_for_dht_connection && DHT_isconnected(dht)) { | 337 | if (waiting_for_dht_connection && DHT_isconnected(dht)) { |
338 | log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n"); | 338 | log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n"); |