diff options
Diffstat (limited to 'other')
-rw-r--r-- | other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c index 896d6a69..8eb1530b 100644 --- a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c +++ b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c | |||
@@ -77,7 +77,7 @@ and connect to them. | |||
77 | returns 1 if the connection to the DHT is up | 77 | returns 1 if the connection to the DHT is up |
78 | returns -1 if all attempts failed | 78 | returns -1 if all attempts failed |
79 | */ | 79 | */ |
80 | int connect_to_servers(struct server_info_s *info) | 80 | int connect_to_servers(DHT * dht, struct server_info_s *info) |
81 | { | 81 | { |
82 | int i; | 82 | int i; |
83 | int c; | 83 | int c; |
@@ -86,7 +86,7 @@ int connect_to_servers(struct server_info_s *info) | |||
86 | if (info[i].valid) { | 86 | if (info[i].valid) { |
87 | /* Actual bootstrapping code goes here */ | 87 | /* Actual bootstrapping code goes here */ |
88 | //puts("Calling DHT_bootstrap"); | 88 | //puts("Calling DHT_bootstrap"); |
89 | DHT_bootstrap(info[i].conn, info[i].bs_pk); | 89 | DHT_bootstrap(dht, info[i].conn, info[i].bs_pk); |
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
@@ -94,28 +94,28 @@ int connect_to_servers(struct server_info_s *info) | |||
94 | for (c = 0; c != 100; ++c) { | 94 | for (c = 0; c != 100; ++c) { |
95 | usleep(10000); | 95 | usleep(10000); |
96 | 96 | ||
97 | if (DHT_isconnected()) { | 97 | if (DHT_isconnected(dht)) { |
98 | //puts("Connected"); | 98 | //puts("Connected"); |
99 | return 1; | 99 | return 1; |
100 | break; | 100 | break; |
101 | } | 101 | } |
102 | 102 | ||
103 | if (DHT_isconnected() == 0 && c == 99) { | 103 | if (DHT_isconnected(dht) == 0 && c == 99) { |
104 | //puts("Not connected"); | 104 | //puts("Not connected"); |
105 | return -1; | 105 | return -1; |
106 | break; | 106 | break; |
107 | } | 107 | } |
108 | 108 | ||
109 | doDHT(); | 109 | do_DHT(dht); |
110 | 110 | ||
111 | networking_poll(); | 111 | networking_poll(dht->c->lossless_udp->net); |
112 | } | 112 | } |
113 | 113 | ||
114 | /* This probably never happens */ | 114 | /* This probably never happens */ |
115 | return 0; | 115 | return 0; |
116 | } | 116 | } |
117 | 117 | ||
118 | void manage_keys(char *keys_file) | 118 | void manage_keys(DHT * dht, char *keys_file) |
119 | { | 119 | { |
120 | const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; | 120 | const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; |
121 | uint8_t keys[KEYS_SIZE]; | 121 | uint8_t keys[KEYS_SIZE]; |
@@ -134,13 +134,13 @@ void manage_keys(char *keys_file) | |||
134 | printf("Keys loaded successfully\n"); | 134 | printf("Keys loaded successfully\n"); |
135 | } | 135 | } |
136 | 136 | ||
137 | load_keys(keys); | 137 | load_keys(dht->c, keys); |
138 | 138 | ||
139 | } else { | 139 | } else { |
140 | /* otherwise save new keys */ | 140 | /* otherwise save new keys */ |
141 | /* Silly work-around to ignore any errors coming from new_keys() */ | 141 | /* Silly work-around to ignore any errors coming from new_keys() */ |
142 | new_keys(); | 142 | new_keys(dht->c); |
143 | save_keys(keys); | 143 | save_keys(dht->c, keys); |
144 | keysf = fopen(keys_file, "w"); | 144 | keysf = fopen(keys_file, "w"); |
145 | 145 | ||
146 | if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keysf) != KEYS_SIZE) { | 146 | if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keysf) != KEYS_SIZE) { |
@@ -293,10 +293,14 @@ int main(int argc, char *argv[]) | |||
293 | printf("Please specify a configuration file.\n"); | 293 | printf("Please specify a configuration file.\n"); |
294 | exit(EXIT_FAILURE); | 294 | exit(EXIT_FAILURE); |
295 | } | 295 | } |
296 | |||
297 | /* Read the config file */ | ||
298 | server_conf = configure_server(argv[1]); | 296 | server_conf = configure_server(argv[1]); |
299 | 297 | ||
298 | /* initialize networking | ||
299 | bind to ip 0.0.0.0:PORT */ | ||
300 | IP ip; | ||
301 | ip.i = 0; | ||
302 | DHT * dht = new_DHT(new_net_crypto(new_networking(ip, server_conf.port))); | ||
303 | /* Read the config file */ | ||
300 | printf("PID file: %s\n", server_conf.pid_file); | 304 | printf("PID file: %s\n", server_conf.pid_file); |
301 | printf("Key file: %s\n", server_conf.keys_file); | 305 | printf("Key file: %s\n", server_conf.keys_file); |
302 | 306 | ||
@@ -313,38 +317,32 @@ int main(int argc, char *argv[]) | |||
313 | /* Manage the keys */ | 317 | /* Manage the keys */ |
314 | /* for now, just ignore any errors after this call. */ | 318 | /* for now, just ignore any errors after this call. */ |
315 | int tmperr = errno; | 319 | int tmperr = errno; |
316 | manage_keys(server_conf.keys_file); | 320 | manage_keys(dht, server_conf.keys_file); |
317 | errno = tmperr; | 321 | errno = tmperr; |
318 | 322 | ||
323 | init_cryptopackets(dht); | ||
319 | /* Public key */ | 324 | /* Public key */ |
320 | int i; | 325 | int i; |
321 | printf("\nPublic Key: "); | 326 | printf("\nPublic Key: "); |
322 | 327 | ||
323 | for (i = 0; i < 32; ++i) { | 328 | for (i = 0; i < 32; ++i) { |
324 | uint8_t ln, hn; | 329 | uint8_t ln, hn; |
325 | ln = 0x0F & self_public_key[i]; | 330 | ln = 0x0F & dht->c->self_public_key[i]; |
326 | hn = 0xF0 & self_public_key[i]; | 331 | hn = 0xF0 & dht->c->self_public_key[i]; |
327 | hn = hn >> 4; | 332 | hn = hn >> 4; |
328 | printf("%X%X", hn, ln); | 333 | printf("%X%X", hn, ln); |
329 | } | 334 | } |
330 | 335 | ||
331 | printf("\n"); | 336 | printf("\n"); |
332 | 337 | ||
333 | /* initialize networking | ||
334 | bind to ip 0.0.0.0:PORT */ | ||
335 | IP ip; | ||
336 | ip.i = 0; | ||
337 | init_networking(ip, server_conf.port); | ||
338 | |||
339 | /* Bootstrap the DHT | 338 | /* Bootstrap the DHT |
340 | This one throws odd errors, too. Ignore. I assume they come | 339 | This one throws odd errors, too. Ignore. I assume they come |
341 | from somewhere in the core. */ | 340 | from somewhere in the core. */ |
342 | DHT_init(); | ||
343 | tmperr = errno; | 341 | tmperr = errno; |
344 | connect_to_servers(server_conf.info); | 342 | connect_to_servers(dht, server_conf.info); |
345 | errno = tmperr; | 343 | errno = tmperr; |
346 | 344 | ||
347 | if (!DHT_isconnected()) { | 345 | if (!DHT_isconnected(dht)) { |
348 | puts("Could not establish DHT connection. Check server settings.\n"); | 346 | puts("Could not establish DHT connection. Check server settings.\n"); |
349 | exit(EXIT_FAILURE); | 347 | exit(EXIT_FAILURE); |
350 | } else { | 348 | } else { |
@@ -404,13 +402,10 @@ int main(int argc, char *argv[]) | |||
404 | close(STDIN_FILENO); | 402 | close(STDIN_FILENO); |
405 | close(STDERR_FILENO); | 403 | close(STDERR_FILENO); |
406 | 404 | ||
407 | /* Main loop */ | ||
408 | friendreq_init(); | ||
409 | |||
410 | while (1) { | 405 | while (1) { |
411 | doDHT(); | 406 | do_DHT(dht); |
412 | 407 | ||
413 | networking_poll(); | 408 | networking_poll(dht->c->lossless_udp->net); |
414 | usleep(10000); | 409 | usleep(10000); |
415 | } | 410 | } |
416 | 411 | ||