diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-08-01 23:02:13 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-08-16 21:01:43 +0000 |
commit | d6d305feeb76735ee4b4e14c6bca737a5482bc19 (patch) | |
tree | 99005c635a452245006b3b5de44f1dd80da9f77f /other | |
parent | 54066f338f185f2fbd6694d9a4877f42cbfa21c8 (diff) |
Use per-instance `Mono_Time` for Messenger and onion.
Diffstat (limited to 'other')
-rw-r--r-- | other/DHT_bootstrap.c | 17 | ||||
-rwxr-xr-x | other/astyle/format-source | 4 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/tox-bootstrapd.c | 33 |
3 files changed, 35 insertions, 19 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index fc1bba47..6af042ac 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c | |||
@@ -115,12 +115,11 @@ int main(int argc, char *argv[]) | |||
115 | IP ip; | 115 | IP ip; |
116 | ip_init(&ip, ipv6enabled); | 116 | ip_init(&ip, ipv6enabled); |
117 | 117 | ||
118 | unix_time_update(); | ||
119 | |||
120 | Logger *logger = logger_new(); | 118 | Logger *logger = logger_new(); |
121 | DHT *dht = new_dht(logger, new_networking(logger, ip, PORT), true); | 119 | Mono_Time *mono_time = mono_time_new(); |
122 | Onion *onion = new_onion(dht); | 120 | DHT *dht = new_dht(logger, mono_time, new_networking(logger, ip, PORT), true); |
123 | Onion_Announce *onion_a = new_onion_announce(dht); | 121 | Onion *onion = new_onion(mono_time, dht); |
122 | Onion_Announce *onion_a = new_onion_announce(mono_time, dht); | ||
124 | 123 | ||
125 | #ifdef DHT_NODE_EXTRA_PACKETS | 124 | #ifdef DHT_NODE_EXTRA_PACKETS |
126 | bootstrap_set_callbacks(dht_get_net(dht), DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD)); | 125 | bootstrap_set_callbacks(dht_get_net(dht), DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD)); |
@@ -188,7 +187,7 @@ int main(int argc, char *argv[]) | |||
188 | lan_discovery_init(dht); | 187 | lan_discovery_init(dht); |
189 | 188 | ||
190 | while (1) { | 189 | while (1) { |
191 | unix_time_update(); | 190 | mono_time_update(mono_time); |
192 | 191 | ||
193 | if (is_waiting_for_dht_connection && dht_isconnected(dht)) { | 192 | if (is_waiting_for_dht_connection && dht_isconnected(dht)) { |
194 | printf("Connected to other bootstrap node successfully.\n"); | 193 | printf("Connected to other bootstrap node successfully.\n"); |
@@ -197,13 +196,13 @@ int main(int argc, char *argv[]) | |||
197 | 196 | ||
198 | do_dht(dht); | 197 | do_dht(dht); |
199 | 198 | ||
200 | if (is_timeout(last_LANdiscovery, is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL)) { | 199 | if (mono_time_is_timeout(mono_time, last_LANdiscovery, is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL)) { |
201 | lan_discovery_send(net_htons(PORT), dht); | 200 | lan_discovery_send(net_htons(PORT), dht); |
202 | last_LANdiscovery = unix_time(); | 201 | last_LANdiscovery = mono_time_get(mono_time); |
203 | } | 202 | } |
204 | 203 | ||
205 | #ifdef TCP_RELAY_ENABLED | 204 | #ifdef TCP_RELAY_ENABLED |
206 | do_TCP_server(tcp_s); | 205 | do_TCP_server(tcp_s, mono_time); |
207 | #endif | 206 | #endif |
208 | networking_poll(dht_get_net(dht), nullptr); | 207 | networking_poll(dht_get_net(dht), nullptr); |
209 | 208 | ||
diff --git a/other/astyle/format-source b/other/astyle/format-source index 5b560622..5e139d89 100755 --- a/other/astyle/format-source +++ b/other/astyle/format-source | |||
@@ -36,11 +36,13 @@ apidsl_curl() { | |||
36 | 36 | ||
37 | # Check if apidsl generated sources are up to date. | 37 | # Check if apidsl generated sources are up to date. |
38 | $APIDSL toxcore/crypto_core.api.h > toxcore/crypto_core.h & | 38 | $APIDSL toxcore/crypto_core.api.h > toxcore/crypto_core.h & |
39 | $APIDSL toxcore/ping.api.h > toxcore/ping.h & | ||
40 | $APIDSL toxcore/ping_array.api.h > toxcore/ping_array.h & | ||
39 | $APIDSL toxcore/tox.api.h > toxcore/tox.h & | 41 | $APIDSL toxcore/tox.api.h > toxcore/tox.h & |
40 | $APIDSL toxav/toxav.api.h > toxav/toxav.h & | 42 | $APIDSL toxav/toxav.api.h > toxav/toxav.h & |
41 | $APIDSL toxencryptsave/toxencryptsave.api.h > toxencryptsave/toxencryptsave.h & | 43 | $APIDSL toxencryptsave/toxencryptsave.api.h > toxencryptsave/toxencryptsave.h & |
42 | 44 | ||
43 | wait; wait; wait; wait | 45 | wait; wait; wait; wait; wait; wait |
44 | 46 | ||
45 | if grep '<unresolved>' */*.h; then | 47 | if grep '<unresolved>' */*.h; then |
46 | echo "error: some apidsl references were unresolved" | 48 | echo "error: some apidsl references were unresolved" |
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); |