Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small changes #60

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@

# tuntox related, not needed in repo
tuntox
tuntox_nostatic
debian/debhelper-build-stamp
debian/files
debian/tuntox.substvars
45 changes: 19 additions & 26 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,6 @@ int main(int argc, char *argv[])
case 'i':
/* Tox ID */
server_whitelist_mode = 1;
log_printf(L_DEBUG, "Server whitelist mode enabled");
allowed_toxid_obj = (allowed_toxid *)calloc(sizeof(allowed_toxid), 1);
if(!allowed_toxid_obj)
{
Expand Down Expand Up @@ -1435,6 +1434,12 @@ int main(int argc, char *argv[])
min_log_level = L_INFO;
}

if(client_mode && !remote_tox_id)
{
log_printf(L_ERROR, "Tox id is required in client mode. Use -i 58435984ABCDEF475...\n");
exit(1);
}

if(!client_mode && server_whitelist_mode)
{
log_printf(L_INFO, "Server in ToxID whitelisting mode - only clients listed with -i can connect");
Expand Down Expand Up @@ -1524,34 +1529,15 @@ int main(int argc, char *argv[])

do_bootstrap(tox);

if(client_mode)
if((!client_mode) || load_saved_toxid_in_client_mode)
{
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
char_t readable_dht_key[2 * TOX_PUBLIC_KEY_SIZE + 1];

tox_self_get_address(tox, tox_id);
id_to_string(tox_printable_id, tox_id);
tox_printable_id[TOX_ADDRESS_SIZE * 2] = '\0';
log_printf(L_DEBUG, "Generated Tox ID: %s\n", tox_printable_id);

tox_self_get_dht_id(tox, dht_key);
to_hex(readable_dht_key, dht_key, TOX_PUBLIC_KEY_SIZE);
log_printf(L_DEBUG, "DHT key: %s\n", readable_dht_key);

if(!remote_tox_id)
{
log_printf(L_ERROR, "Tox id is required in client mode. Use -i 58435984ABCDEF475...\n");
exit(1);
}
do_client_loop(remote_tox_id);
write_save(tox);
}
else

{
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
char_t readable_dht_key[2 * TOX_PUBLIC_KEY_SIZE + 1];

write_save(tox);

if(!use_shared_secret)
{
log_printf(L_WARNING, "Shared secret authentication is not used - skilled attackers may connect to your tuntox server");
Expand All @@ -1567,9 +1553,16 @@ int main(int argc, char *argv[])
to_hex(readable_dht_key, dht_key, TOX_PUBLIC_KEY_SIZE);
log_printf(L_DEBUG, "DHT key: %s\n", readable_dht_key);

tox_callback_friend_request(tox, accept_friend_request);
do_server_loop();
clear_rules();
if (client_mode)
{
do_client_loop(remote_tox_id);
}
else
{
tox_callback_friend_request(tox, accept_friend_request);
do_server_loop();
clear_rules();
}
}

return 0;
Expand Down