Skip to content

Commit 15400c2

Browse files
author
Andrew Cady
committed
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).
1 parent ee6e937 commit 15400c2

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

main.c

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,12 @@ int main(int argc, char *argv[])
14341434
min_log_level = L_INFO;
14351435
}
14361436

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+
14371443
if(!client_mode && server_whitelist_mode)
14381444
{
14391445
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[])
15281534
write_save(tox);
15291535
}
15301536

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
15531537
{
15541538
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
15551539
char_t readable_dht_key[2 * TOX_PUBLIC_KEY_SIZE + 1];
@@ -1569,9 +1553,16 @@ int main(int argc, char *argv[])
15691553
to_hex(readable_dht_key, dht_key, TOX_PUBLIC_KEY_SIZE);
15701554
log_printf(L_DEBUG, "DHT key: %s\n", readable_dht_key);
15711555

1572-
tox_callback_friend_request(tox, accept_friend_request);
1573-
do_server_loop();
1574-
clear_rules();
1556+
if (client_mode)
1557+
{
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+
}
15751566
}
15761567

15771568
return 0;

0 commit comments

Comments
 (0)