diff options
-rw-r--r-- | client.c | 41 | ||||
-rw-r--r-- | gitversion.h | 2 |
2 files changed, 39 insertions, 4 deletions
@@ -244,14 +244,33 @@ int handle_server_tcp_fin_frame(protocol_frame *rcvd_frame) | |||
244 | log_printf(L_WARNING, "Friend #%d tried to close tunnel while server is #%d\n", rcvd_frame->friendnumber, tun->friendnumber); | 244 | log_printf(L_WARNING, "Friend #%d tried to close tunnel while server is #%d\n", rcvd_frame->friendnumber, tun->friendnumber); |
245 | return -1; | 245 | return -1; |
246 | } | 246 | } |
247 | 247 | ||
248 | client_close_tunnel(tun); | ||
249 | |||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | /* Delete tunnel and clear client-side fdset */ | ||
254 | int client_close_tunnel(tunnel *tun) | ||
255 | { | ||
248 | if(tun->sockfd) | 256 | if(tun->sockfd) |
249 | { | 257 | { |
250 | FD_CLR(tun->sockfd, &client_master_fdset); | 258 | FD_CLR(tun->sockfd, &client_master_fdset); |
251 | } | 259 | } |
260 | |||
252 | tunnel_delete(tun); | 261 | tunnel_delete(tun); |
262 | } | ||
253 | 263 | ||
254 | return 0; | 264 | /* Close and delete all tunnels (when server went offline) */ |
265 | int client_close_all_connections() | ||
266 | { | ||
267 | tunnel *tmp = NULL; | ||
268 | tunnel *tun = NULL; | ||
269 | |||
270 | HASH_ITER(hh, by_id, tun, tmp) | ||
271 | { | ||
272 | client_close_tunnel(tun); | ||
273 | } | ||
255 | } | 274 | } |
256 | 275 | ||
257 | /* Main loop for the client */ | 276 | /* Main loop for the client */ |
@@ -308,6 +327,7 @@ int do_client_loop(uint8_t *tox_id_str) | |||
308 | { | 327 | { |
309 | uint8_t* data = (uint8_t *)"Hi, fellow tuntox instance!"; | 328 | uint8_t* data = (uint8_t *)"Hi, fellow tuntox instance!"; |
310 | uint16_t length = sizeof(data); | 329 | uint16_t length = sizeof(data); |
330 | /* https://github.com/TokTok/c-toxcore/blob/acb6b2d8543c8f2ea0c2e60dc046767cf5cc0de8/toxcore/tox.h#L1168 */ | ||
311 | TOX_ERR_FRIEND_ADD add_error; | 331 | TOX_ERR_FRIEND_ADD add_error; |
312 | 332 | ||
313 | if(use_shared_secret) | 333 | if(use_shared_secret) |
@@ -592,7 +612,22 @@ int do_client_loop(uint8_t *tox_id_str) | |||
592 | if(friend_connection_status != last_friend_connection_status) | 612 | if(friend_connection_status != last_friend_connection_status) |
593 | { | 613 | { |
594 | const char* status = readable_connection_status(friend_connection_status); | 614 | const char* status = readable_connection_status(friend_connection_status); |
595 | log_printf(L_INFO, "Friend connection status changed to: %s\n", status); | 615 | log_printf(L_INFO, "Friend connection status changed to: %s (%d)\n", status, friend_connection_status); |
616 | |||
617 | if(friend_connection_status == TOX_CONNECTION_NONE) | ||
618 | { | ||
619 | /* https://github.com/TokTok/c-toxcore/blob/acb6b2d8543c8f2ea0c2e60dc046767cf5cc0de8/toxcore/tox.h#L1267 */ | ||
620 | TOX_ERR_FRIEND_DELETE tox_delete_error; | ||
621 | |||
622 | log_printf(L_WARNING, "Lost connection to server, closing all tunnels and re-adding friend\n"); | ||
623 | client_close_all_connections(); | ||
624 | tox_friend_delete(tox, friendnumber, &tox_delete_error); | ||
625 | if(tox_delete_error) | ||
626 | { | ||
627 | log_printf(L_ERROR, "Error when deleting server from friend list: %d\n", tox_delete_error); | ||
628 | } | ||
629 | state = CLIENT_STATE_INITIAL; | ||
630 | } | ||
596 | } | 631 | } |
597 | 632 | ||
598 | last_friend_connection_status_received = time(NULL); | 633 | last_friend_connection_status_received = time(NULL); |
diff --git a/gitversion.h b/gitversion.h index 091c4df..627af8a 100644 --- a/gitversion.h +++ b/gitversion.h | |||
@@ -1 +1 @@ | |||
#define GITVERSION "f94b4083396676ed14681cff8d4e06f4194d31e5" | #define GITVERSION "3adc626eb1646ee3456ca282e1855142f9f935e0" | ||