File client.c changed (mode: 100644) (index 9dc1b03..0634702) |
... |
... |
int do_client_loop(char *tox_id_str) |
266 |
266 |
struct timeval tv; |
struct timeval tv; |
267 |
267 |
fd_set fds; |
fd_set fds; |
268 |
268 |
static time_t invitation_sent_time = 0; |
static time_t invitation_sent_time = 0; |
|
269 |
|
uint32_t invitations_sent = 0; |
269 |
270 |
TOX_ERR_FRIEND_QUERY friend_query_error; |
TOX_ERR_FRIEND_QUERY friend_query_error; |
270 |
271 |
TOX_ERR_FRIEND_CUSTOM_PACKET custom_packet_error; |
TOX_ERR_FRIEND_CUSTOM_PACKET custom_packet_error; |
271 |
272 |
|
|
|
... |
... |
int do_client_loop(char *tox_id_str) |
318 |
319 |
log_printf(L_DEBUG, "Sent shared secret of length %u\n", length); |
log_printf(L_DEBUG, "Sent shared secret of length %u\n", length); |
319 |
320 |
} |
} |
320 |
321 |
|
|
321 |
|
log_printf(L_INFO, "Connected. Sending friend request.\n"); |
|
|
322 |
|
if(invitations_sent == 0) |
|
323 |
|
{ |
|
324 |
|
log_printf(L_INFO, "Connected. Sending friend request.\n"); |
|
325 |
|
} |
|
326 |
|
else |
|
327 |
|
{ |
|
328 |
|
log_printf(L_INFO, "Sending another friend request.\n"); |
|
329 |
|
} |
322 |
330 |
|
|
323 |
331 |
friendnumber = tox_friend_add( |
friendnumber = tox_friend_add( |
324 |
332 |
tox, |
tox, |
|
... |
... |
int do_client_loop(char *tox_id_str) |
337 |
345 |
} |
} |
338 |
346 |
|
|
339 |
347 |
invitation_sent_time = time(NULL); |
invitation_sent_time = time(NULL); |
|
348 |
|
invitations_sent++; |
340 |
349 |
state = CLIENT_STATE_SENTREQUEST; |
state = CLIENT_STATE_SENTREQUEST; |
341 |
350 |
log_printf(L_INFO, "Waiting for friend to accept us...\n"); |
log_printf(L_INFO, "Waiting for friend to accept us...\n"); |
342 |
351 |
} |
} |
|
... |
... |
int do_client_loop(char *tox_id_str) |
359 |
368 |
} |
} |
360 |
369 |
else |
else |
361 |
370 |
{ |
{ |
362 |
|
if(0 && (time(NULL) - invitation_sent_time > 60)) |
|
|
371 |
|
if(1 && (time(NULL) - invitation_sent_time > 45)) |
363 |
372 |
{ |
{ |
|
373 |
|
TOX_ERR_FRIEND_DELETE error = 0; |
|
374 |
|
|
364 |
375 |
log_printf(L_INFO, "Sending another friend request..."); |
log_printf(L_INFO, "Sending another friend request..."); |
|
376 |
|
tox_friend_delete( |
|
377 |
|
tox, |
|
378 |
|
friendnumber, |
|
379 |
|
&error); |
|
380 |
|
if(error != TOX_ERR_FRIEND_DELETE_OK) |
|
381 |
|
{ |
|
382 |
|
log_printf(L_ERROR, "Error %u deleting friend before reconnection\n", error); |
|
383 |
|
exit(-1); |
|
384 |
|
} |
|
385 |
|
|
365 |
386 |
state = CLIENT_STATE_CONNECTED; |
state = CLIENT_STATE_CONNECTED; |
366 |
387 |
} |
} |
367 |
388 |
} |
} |
File main.c changed (mode: 100644) (index b87172c..94f0396) |
... |
... |
char *daemon_username = NULL; |
47 |
47 |
int use_shared_secret = 0; |
int use_shared_secret = 0; |
48 |
48 |
char shared_secret[TOX_MAX_FRIEND_REQUEST_LENGTH]; |
char shared_secret[TOX_MAX_FRIEND_REQUEST_LENGTH]; |
49 |
49 |
|
|
|
50 |
|
/* Only let in a whitelisted client */ |
|
51 |
|
int server_whitelist_mode = 1; |
|
52 |
|
allowed_toxid *allowed_toxids = NULL; |
|
53 |
|
|
|
54 |
|
int load_saved_toxid_in_client_mode = 0; |
|
55 |
|
|
50 |
56 |
fd_set master_server_fds; |
fd_set master_server_fds; |
51 |
57 |
|
|
52 |
58 |
/* We keep two hash tables: one indexed by sockfd and another by "connection id" */ |
/* We keep two hash tables: one indexed by sockfd and another by "connection id" */ |
|
... |
... |
uint16_t get_random_tunnel_id() |
76 |
82 |
} |
} |
77 |
83 |
} |
} |
78 |
84 |
|
|
|
85 |
|
/* Comparison function for allowed_toxid objects */ |
|
86 |
|
int allowed_toxid_cmp(allowed_toxid *a, allowed_toxid *b) |
|
87 |
|
{ |
|
88 |
|
return memcmp(a->toxid, b->toxid, TOX_PUBLIC_KEY_SIZE); |
|
89 |
|
} |
|
90 |
|
|
79 |
91 |
void update_select_nfds(int fd) |
void update_select_nfds(int fd) |
80 |
92 |
{ |
{ |
81 |
93 |
/* TODO maybe replace with a scan every time to make select() more efficient in the long run? */ |
/* TODO maybe replace with a scan every time to make select() more efficient in the long run? */ |
|
... |
... |
void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *m |
723 |
735 |
} |
} |
724 |
736 |
} |
} |
725 |
737 |
|
|
|
738 |
|
memset(tox_printable_id, '\0', sizeof(tox_printable_id)); |
|
739 |
|
id_to_string(tox_printable_id, public_key); |
|
740 |
|
|
|
741 |
|
if(server_whitelist_mode) |
|
742 |
|
{ |
|
743 |
|
allowed_toxid etmp, *found = NULL; |
|
744 |
|
memcpy(etmp.toxid, public_key, TOX_PUBLIC_KEY_SIZE); |
|
745 |
|
LL_SEARCH(allowed_toxids, found, &etmp, allowed_toxid_cmp); |
|
746 |
|
if(!found) |
|
747 |
|
{ |
|
748 |
|
log_printf(L_WARNING, "Rejected friend request from non-whitelisted friend %s", tox_printable_id); |
|
749 |
|
return; |
|
750 |
|
} |
|
751 |
|
log_printf(L_DEBUG, "Friend %s passed whitelist check", tox_printable_id); |
|
752 |
|
} |
726 |
753 |
|
|
727 |
754 |
friendnumber = tox_friend_add_norequest(tox, public_key, &friend_add_error); |
friendnumber = tox_friend_add_norequest(tox, public_key, &friend_add_error); |
728 |
755 |
if(friend_add_error != TOX_ERR_FRIEND_ADD_OK) |
if(friend_add_error != TOX_ERR_FRIEND_ADD_OK) |
|
... |
... |
void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *m |
731 |
758 |
return; |
return; |
732 |
759 |
} |
} |
733 |
760 |
|
|
734 |
|
memset(tox_printable_id, '\0', sizeof(tox_printable_id)); |
|
735 |
|
id_to_string(tox_printable_id, public_key); |
|
736 |
761 |
log_printf(L_INFO, "Accepted friend request from %s as %d\n", tox_printable_id, friendnumber); |
log_printf(L_INFO, "Accepted friend request from %s as %d\n", tox_printable_id, friendnumber); |
737 |
762 |
} |
} |
738 |
763 |
|
|
|
... |
... |
int do_server_loop() |
788 |
813 |
tox_do_interval_ms = tox_iteration_interval(tox); |
tox_do_interval_ms = tox_iteration_interval(tox); |
789 |
814 |
tv.tv_usec = (tox_do_interval_ms % 1000) * 1000; |
tv.tv_usec = (tox_do_interval_ms % 1000) * 1000; |
790 |
815 |
tv.tv_sec = tox_do_interval_ms / 1000; |
tv.tv_sec = tox_do_interval_ms / 1000; |
791 |
|
log_printf(L_DEBUG, "Iteration interval: %dms\n", tox_do_interval_ms); |
|
|
816 |
|
log_printf(L_DEBUG2, "Iteration interval: %dms\n", tox_do_interval_ms); |
792 |
817 |
gettimeofday(&tv_start, NULL); |
gettimeofday(&tv_start, NULL); |
793 |
818 |
|
|
794 |
819 |
/* Check change in connection state */ |
/* Check change in connection state */ |
|
... |
... |
int main(int argc, char *argv[]) |
1051 |
1076 |
int oc; |
int oc; |
1052 |
1077 |
size_t save_size = 0; |
size_t save_size = 0; |
1053 |
1078 |
uint8_t *save_data = NULL; |
uint8_t *save_data = NULL; |
|
1079 |
|
allowed_toxid *allowed_toxid_obj = NULL; |
1054 |
1080 |
|
|
1055 |
1081 |
log_init(); |
log_init(); |
1056 |
1082 |
|
|
|
... |
... |
int main(int argc, char *argv[]) |
1099 |
1125 |
break; |
break; |
1100 |
1126 |
case 'i': |
case 'i': |
1101 |
1127 |
/* Tox ID */ |
/* Tox ID */ |
|
1128 |
|
allowed_toxid_obj = (allowed_toxid *)calloc(sizeof(allowed_toxid), 1); |
|
1129 |
|
if(!allowed_toxid_obj) |
|
1130 |
|
{ |
|
1131 |
|
log_printf(L_ERROR, "Could not allocate memory for allowed_toxid"); |
|
1132 |
|
exit(1); |
|
1133 |
|
} |
1102 |
1134 |
remote_tox_id = optarg; |
remote_tox_id = optarg; |
|
1135 |
|
if(!string_to_id(allowed_toxid_obj->toxid, optarg)) |
|
1136 |
|
{ |
|
1137 |
|
log_printf(L_ERROR, "Invalid Tox ID"); |
|
1138 |
|
exit(1); |
|
1139 |
|
} |
|
1140 |
|
LL_APPEND(allowed_toxids, allowed_toxid_obj); |
1103 |
1141 |
break; |
break; |
1104 |
1142 |
case 'C': |
case 'C': |
1105 |
1143 |
/* Config directory */ |
/* Config directory */ |
|
... |
... |
int main(int argc, char *argv[]) |
1111 |
1149 |
config_path[optarg_len] = '/'; |
config_path[optarg_len] = '/'; |
1112 |
1150 |
config_path[optarg_len + 1] = '\0'; |
config_path[optarg_len + 1] = '\0'; |
1113 |
1151 |
} |
} |
|
1152 |
|
load_saved_toxid_in_client_mode = 1; |
1114 |
1153 |
break; |
break; |
1115 |
1154 |
case 's': |
case 's': |
1116 |
1155 |
/* Shared secret */ |
/* Shared secret */ |
|
... |
... |
int main(int argc, char *argv[]) |
1148 |
1187 |
|
|
1149 |
1188 |
if(!client_mode && min_log_level == L_UNSET) |
if(!client_mode && min_log_level == L_UNSET) |
1150 |
1189 |
{ |
{ |
1151 |
|
min_log_level = L_INFO; |
|
|
1190 |
|
min_log_level = L_INFO; |
|
1191 |
|
} |
|
1192 |
|
|
|
1193 |
|
if(!client_mode && remote_tox_id) |
|
1194 |
|
{ |
|
1195 |
|
server_whitelist_mode = 1; |
|
1196 |
|
log_printf(L_INFO, "Server in ToxID whitelisting mode - only clients listed with -i can connect"); |
1152 |
1197 |
} |
} |
1153 |
1198 |
|
|
1154 |
1199 |
if(daemonize) |
if(daemonize) |
|
... |
... |
int main(int argc, char *argv[]) |
1162 |
1207 |
|
|
1163 |
1208 |
/* Bootstrap tox */ |
/* Bootstrap tox */ |
1164 |
1209 |
tox_options_default(&tox_options); |
tox_options_default(&tox_options); |
1165 |
|
if(!client_mode) |
|
|
1210 |
|
if((!client_mode) || load_saved_toxid_in_client_mode) |
1166 |
1211 |
{ |
{ |
1167 |
1212 |
uint8_t *save_data = NULL; |
uint8_t *save_data = NULL; |
1168 |
1213 |
save_size = load_save(&save_data); |
save_size = load_save(&save_data); |