diff options
Diffstat (limited to 'other/bootstrap_daemon/src/tox-bootstrapd.c')
-rw-r--r-- | other/bootstrap_daemon/src/tox-bootstrapd.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index d75018d8..807e1100 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c | |||
@@ -230,8 +230,6 @@ int main(int argc, char *argv[]) | |||
230 | IP ip; | 230 | IP ip; |
231 | ip_init(&ip, enable_ipv6); | 231 | ip_init(&ip, enable_ipv6); |
232 | 232 | ||
233 | unix_time_update(); | ||
234 | |||
235 | Logger *logger = logger_new(); | 233 | Logger *logger = logger_new(); |
236 | 234 | ||
237 | Networking_Core *net = new_networking(logger, ip, port); | 235 | Networking_Core *net = new_networking(logger, ip, port); |
@@ -255,19 +253,31 @@ int main(int argc, char *argv[]) | |||
255 | } | 253 | } |
256 | } | 254 | } |
257 | 255 | ||
258 | DHT *dht = new_dht(logger, net, true); | 256 | Mono_Time *const mono_time = mono_time_new(); |
257 | |||
258 | if (mono_time == nullptr) { | ||
259 | log_write(LOG_LEVEL_ERROR, "Couldn't initialize monotonic timer. Exiting.\n"); | ||
260 | logger_kill(logger); | ||
261 | return 1; | ||
262 | } | ||
263 | |||
264 | mono_time_update(mono_time); | ||
265 | |||
266 | DHT *const dht = new_dht(logger, mono_time, net, true); | ||
259 | 267 | ||
260 | if (dht == nullptr) { | 268 | if (dht == nullptr) { |
261 | log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n"); | 269 | log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n"); |
270 | mono_time_free(mono_time); | ||
262 | logger_kill(logger); | 271 | logger_kill(logger); |
263 | return 1; | 272 | return 1; |
264 | } | 273 | } |
265 | 274 | ||
266 | Onion *onion = new_onion(dht); | 275 | Onion *onion = new_onion(mono_time, dht); |
267 | Onion_Announce *onion_a = new_onion_announce(dht); | 276 | Onion_Announce *onion_a = new_onion_announce(mono_time, dht); |
268 | 277 | ||
269 | if (!(onion && onion_a)) { | 278 | if (!(onion && onion_a)) { |
270 | log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n"); | 279 | log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n"); |
280 | mono_time_free(mono_time); | ||
271 | logger_kill(logger); | 281 | logger_kill(logger); |
272 | return 1; | 282 | return 1; |
273 | } | 283 | } |
@@ -277,6 +287,7 @@ int main(int argc, char *argv[]) | |||
277 | log_write(LOG_LEVEL_INFO, "Set MOTD successfully.\n"); | 287 | log_write(LOG_LEVEL_INFO, "Set MOTD successfully.\n"); |
278 | } else { | 288 | } else { |
279 | log_write(LOG_LEVEL_ERROR, "Couldn't set MOTD: %s. Exiting.\n", motd); | 289 | log_write(LOG_LEVEL_ERROR, "Couldn't set MOTD: %s. Exiting.\n", motd); |
290 | mono_time_free(mono_time); | ||
280 | logger_kill(logger); | 291 | logger_kill(logger); |
281 | return 1; | 292 | return 1; |
282 | } | 293 | } |
@@ -288,6 +299,7 @@ int main(int argc, char *argv[]) | |||
288 | log_write(LOG_LEVEL_INFO, "Keys are managed successfully.\n"); | 299 | log_write(LOG_LEVEL_INFO, "Keys are managed successfully.\n"); |
289 | } else { | 300 | } else { |
290 | log_write(LOG_LEVEL_ERROR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); | 301 | log_write(LOG_LEVEL_ERROR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); |
302 | mono_time_free(mono_time); | ||
291 | logger_kill(logger); | 303 | logger_kill(logger); |
292 | return 1; | 304 | return 1; |
293 | } | 305 | } |
@@ -299,6 +311,7 @@ int main(int argc, char *argv[]) | |||
299 | if (enable_tcp_relay) { | 311 | if (enable_tcp_relay) { |
300 | if (tcp_relay_port_count == 0) { | 312 | if (tcp_relay_port_count == 0) { |
301 | log_write(LOG_LEVEL_ERROR, "No TCP relay ports read. Exiting.\n"); | 313 | log_write(LOG_LEVEL_ERROR, "No TCP relay ports read. Exiting.\n"); |
314 | mono_time_free(mono_time); | ||
302 | logger_kill(logger); | 315 | logger_kill(logger); |
303 | return 1; | 316 | return 1; |
304 | } | 317 | } |
@@ -312,6 +325,7 @@ int main(int argc, char *argv[]) | |||
312 | log_write(LOG_LEVEL_INFO, "Initialized Tox TCP server successfully.\n"); | 325 | log_write(LOG_LEVEL_INFO, "Initialized Tox TCP server successfully.\n"); |
313 | } else { | 326 | } else { |
314 | log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox TCP server. Exiting.\n"); | 327 | log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox TCP server. Exiting.\n"); |
328 | mono_time_free(mono_time); | ||
315 | logger_kill(logger); | 329 | logger_kill(logger); |
316 | return 1; | 330 | return 1; |
317 | } | 331 | } |
@@ -321,6 +335,7 @@ int main(int argc, char *argv[]) | |||
321 | log_write(LOG_LEVEL_INFO, "List of bootstrap nodes read successfully.\n"); | 335 | log_write(LOG_LEVEL_INFO, "List of bootstrap nodes read successfully.\n"); |
322 | } else { | 336 | } else { |
323 | log_write(LOG_LEVEL_ERROR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path); | 337 | log_write(LOG_LEVEL_ERROR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path); |
338 | mono_time_free(mono_time); | ||
324 | logger_kill(logger); | 339 | logger_kill(logger); |
325 | return 1; | 340 | return 1; |
326 | } | 341 | } |
@@ -338,17 +353,17 @@ int main(int argc, char *argv[]) | |||
338 | } | 353 | } |
339 | 354 | ||
340 | while (1) { | 355 | while (1) { |
341 | unix_time_update(); | 356 | mono_time_update(mono_time); |
342 | 357 | ||
343 | do_dht(dht); | 358 | do_dht(dht); |
344 | 359 | ||
345 | if (enable_lan_discovery && is_timeout(last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) { | 360 | if (enable_lan_discovery && mono_time_is_timeout(mono_time, last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) { |
346 | lan_discovery_send(net_htons_port, dht); | 361 | lan_discovery_send(net_htons_port, dht); |
347 | last_LANdiscovery = unix_time(); | 362 | last_LANdiscovery = mono_time_get(mono_time); |
348 | } | 363 | } |
349 | 364 | ||
350 | if (enable_tcp_relay) { | 365 | if (enable_tcp_relay) { |
351 | do_TCP_server(tcp_server); | 366 | do_TCP_server(tcp_server, mono_time); |
352 | } | 367 | } |
353 | 368 | ||
354 | networking_poll(dht_get_net(dht), nullptr); | 369 | networking_poll(dht_get_net(dht), nullptr); |