diff options
author | Andrew Cady <d@jerkface.net> | 2020-08-19 01:50:57 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2020-08-19 01:56:07 -0400 |
commit | 15400c29ae57ed6d70fcd3999f8fb6f74bcbd2f1 (patch) | |
tree | 42fdccb2915e5e24c5ca70eb29b78f0a0e635965 | |
parent | ee6e9376ab416283340d62c1f901bd1c04e2319e (diff) |
Avoid code repetition
The client and server blocks were nearly identical. Now they share code.
Both client and server now call memset() on tox_printable_id.
The distinct client message "Generated Tox ID: %s\n" was not preserved;
both client and server will say "Using Tox ID: %s\n" which is more
accurate (Tox ID might be persistent with -C).
-rw-r--r-- | main.c | 41 |
1 files changed, 16 insertions, 25 deletions
@@ -1434,6 +1434,12 @@ int main(int argc, char *argv[]) | |||
1434 | min_log_level = L_INFO; | 1434 | min_log_level = L_INFO; |
1435 | } | 1435 | } |
1436 | 1436 | ||
1437 | if(client_mode && !remote_tox_id) | ||
1438 | { | ||
1439 | log_printf(L_ERROR, "Tox id is required in client mode. Use -i 58435984ABCDEF475...\n"); | ||
1440 | exit(1); | ||
1441 | } | ||
1442 | |||
1437 | if(!client_mode && server_whitelist_mode) | 1443 | if(!client_mode && server_whitelist_mode) |
1438 | { | 1444 | { |
1439 | log_printf(L_INFO, "Server in ToxID whitelisting mode - only clients listed with -i can connect"); | 1445 | log_printf(L_INFO, "Server in ToxID whitelisting mode - only clients listed with -i can connect"); |
@@ -1528,28 +1534,6 @@ int main(int argc, char *argv[]) | |||
1528 | write_save(tox); | 1534 | write_save(tox); |
1529 | } | 1535 | } |
1530 | 1536 | ||
1531 | if(client_mode) | ||
1532 | { | ||
1533 | uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; | ||
1534 | char_t readable_dht_key[2 * TOX_PUBLIC_KEY_SIZE + 1]; | ||
1535 | |||
1536 | tox_self_get_address(tox, tox_id); | ||
1537 | id_to_string(tox_printable_id, tox_id); | ||
1538 | tox_printable_id[TOX_ADDRESS_SIZE * 2] = '\0'; | ||
1539 | log_printf(L_DEBUG, "Generated Tox ID: %s\n", tox_printable_id); | ||
1540 | |||
1541 | tox_self_get_dht_id(tox, dht_key); | ||
1542 | to_hex(readable_dht_key, dht_key, TOX_PUBLIC_KEY_SIZE); | ||
1543 | log_printf(L_DEBUG, "DHT key: %s\n", readable_dht_key); | ||
1544 | |||
1545 | if(!remote_tox_id) | ||
1546 | { | ||
1547 | log_printf(L_ERROR, "Tox id is required in client mode. Use -i 58435984ABCDEF475...\n"); | ||
1548 | exit(1); | ||
1549 | } | ||
1550 | do_client_loop(remote_tox_id); | ||
1551 | } | ||
1552 | else | ||
1553 | { | 1537 | { |
1554 | uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; | 1538 | uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; |
1555 | char_t readable_dht_key[2 * TOX_PUBLIC_KEY_SIZE + 1]; | 1539 | char_t readable_dht_key[2 * TOX_PUBLIC_KEY_SIZE + 1]; |
@@ -1569,9 +1553,16 @@ int main(int argc, char *argv[]) | |||
1569 | to_hex(readable_dht_key, dht_key, TOX_PUBLIC_KEY_SIZE); | 1553 | to_hex(readable_dht_key, dht_key, TOX_PUBLIC_KEY_SIZE); |
1570 | log_printf(L_DEBUG, "DHT key: %s\n", readable_dht_key); | 1554 | log_printf(L_DEBUG, "DHT key: %s\n", readable_dht_key); |
1571 | 1555 | ||
1572 | tox_callback_friend_request(tox, accept_friend_request); | 1556 | if (client_mode) |
1573 | do_server_loop(); | 1557 | { |
1574 | clear_rules(); | 1558 | do_client_loop(remote_tox_id); |
1559 | } | ||
1560 | else | ||
1561 | { | ||
1562 | tox_callback_friend_request(tox, accept_friend_request); | ||
1563 | do_server_loop(); | ||
1564 | clear_rules(); | ||
1565 | } | ||
1575 | } | 1566 | } |
1576 | 1567 | ||
1577 | return 0; | 1568 | return 0; |