gdr / tuntox (public) (License: GPLv3) (since 2017-01-24) (hash sha1)
Tunnel TCP connections over the Tox protocol
List of commits:
Subject Hash Author Date (UTC)
Remove FDs of closed tunnels from fdset 816245f429145052b8908d500c64d372fc8c2972 GDR! 2016-06-07 18:42:45
Mention toxvpn c2a78f48bd44613162a6e3c1d02cb53266611936 GDR! 2016-05-05 17:55:59
ProxyCommand explained c17be222aa46a4cf1a9d19c0ae767697ad585fd3 GDR! 2016-05-05 17:50:05
Visible ToxID 4f38371fd72ba889e39805b76a1a2402194b5398 GDR! 2016-05-05 17:46:06
Tuntox does fork! 0d1230def56597b25bcd731346794058c66d3e7c GDR! 2016-05-05 17:45:25
Tox.chat 2 90990f49bda18d06c89fca0495b39726bd55a076 GDR! 2016-05-05 17:43:58
Tox.chat 5b921bc92cf04773f8e5b08120e5850156fbb580 GDR! 2016-05-05 17:43:11
Possible fix for Issue #16 cc633e9ad431850d298638dbcdcbf1e8a4dfdeb1 GDR! 2016-05-05 17:39:42
Fix build on non-mac platforms 981501cf1e19d07a11e28cff99b9cd7c7b1d0b1d GDR! 2015-09-17 08:30:57
* fix: Possibility to compile on Mac OS platform 199787953243d91449ac5f4a5ac16edc2497e438 Dawid 'nCore' Opis 2015-09-16 18:14:03
remove tox.im because it's evil b57ae8b86109e6fe6f626d03ddeca79539d07822 GrayHatter 2015-08-08 00:45:31
Update README.md 9226aa00b30e7af7a0122b0772cc3e20ae5b49d0 GDR! 2015-07-14 12:57:55
CID 122512 (#1 of 1): Resource leak (RESOURCE_LEAK)11. leaked_storage: 5d9e9c5d9078d8d1987375e972282220d50b9328 GDR! 2015-07-08 10:04:52
off_by_one: Testing whether handle sockfd is strictly greater than zero a6d788c45764afb4d172dd3c75dfe593b85b5dab GDR! 2015-07-08 10:02:12
Remaining coverity bugs 5d387074214a9b9f7437bed4dcc02aab1f9abd7f GDR! 2015-07-07 17:39:47
CID 122498 (#1 of 1): Unchecked return value from library 8ae485719161a1b1d33c5d777b2b2d4035c9ff06 GDR! 2015-07-07 17:35:36
CID 122499 (#1 of 1): Unchecked return value from library 7262fd7141bdae8ae15c3f625988a7f26463cdb5 GDR! 2015-07-07 17:30:50
CID 122500 (#1 of 1): Missing return statement (MISSING_RETURN)6. f1826d2061908883fb654059f0675f79396edad0 GDR! 2015-07-07 17:25:53
CID 122503 (#1 of 1): Missing return statement (MISSING_RETURN)1. 25c3d4cc3bd800d5866a54fc0c6bc4f792971a11 GDR! 2015-07-07 17:22:40
CID 122505 (#1 of 1): Missing return statement (MISSING_RETURN)5. 92b037219a65e3b6fb7d44dd03932b4a46aa276c GDR! 2015-07-07 17:19:35
Commit 816245f429145052b8908d500c64d372fc8c2972 - Remove FDs of closed tunnels from fdset
For #19 and #17
Author: GDR!
Author date (UTC): 2016-06-07 18:42
Committer name: GDR!
Committer date (UTC): 2016-06-07 18:42
Parent(s): c2a78f48bd44613162a6e3c1d02cb53266611936
Signer:
Signing key:
Signing status: N
Tree: 6bd800e5a6cc7f5cf47efa0d1f8fa22cd687d74c
File Lines added Lines deleted
client.c 75 47
log.h 1 0
main.c 58 41
File client.c changed (mode: 100644) (index bfcab14..9dc1b03)
... ... int handle_server_tcp_frame(protocol_frame *rcvd_frame)
210 210 frame->connid = tun->connid; frame->connid = tun->connid;
211 211 frame->data_length = 0; frame->data_length = 0;
212 212 send_frame(frame, data); send_frame(frame, data);
213 if(tun->sockfd)
214 {
215 FD_CLR(tun->sockfd, &client_master_fdset);
216 }
213 217 tunnel_delete(tun); tunnel_delete(tun);
214 218
215 219 return -1; return -1;
 
... ... int handle_server_tcp_fin_frame(protocol_frame *rcvd_frame)
244 248 return -1; return -1;
245 249 } }
246 250
251 if(tun->sockfd)
252 {
253 FD_CLR(tun->sockfd, &client_master_fdset);
254 }
247 255 tunnel_delete(tun); tunnel_delete(tun);
248 256
249 257 return 0; return 0;
 
... ... int do_client_loop(char *tox_id_str)
442 450 case CLIENT_STATE_FORWARDING: case CLIENT_STATE_FORWARDING:
443 451 { {
444 452 int accept_fd = 0; int accept_fd = 0;
453 int select_rv = 0;
445 454 tunnel *tmp = NULL; tunnel *tmp = NULL;
446 455 tunnel *tun = NULL; tunnel *tun = NULL;
447 456
 
... ... int do_client_loop(char *tox_id_str)
469 478 } }
470 479
471 480 /* Handle reading from sockets */ /* Handle reading from sockets */
472 select(select_nfds, &fds, NULL, NULL, &tv);
473 HASH_ITER(hh, by_id, tun, tmp)
481 select_rv = select(select_nfds, &fds, NULL, NULL, &tv);
482 if(select_rv == -1 || select_rv == 0)
474 483 { {
475 if(FD_ISSET(tun->sockfd, &fds))
484 if(select_rv == -1)
476 485 { {
477 int nbytes;
478 if(client_local_port_mode)
479 {
480 nbytes = recv(tun->sockfd,
481 tox_packet_buf + PROTOCOL_BUFFER_OFFSET,
482 READ_BUFFER_SIZE, 0);
483 }
484 else
485 {
486 nbytes = read(tun->sockfd,
487 tox_packet_buf + PROTOCOL_BUFFER_OFFSET,
488 READ_BUFFER_SIZE
489 );
490 }
491
492 /* Check if connection closed */
493 if(nbytes == 0)
494 {
495 char data[PROTOCOL_BUFFER_OFFSET];
496 protocol_frame frame_st, *frame;
497
498 log_printf(L_INFO, "Connection closed\n");
499
500 frame = &frame_st;
501 memset(frame, 0, sizeof(protocol_frame));
502 frame->friendnumber = tun->friendnumber;
503 frame->packet_type = PACKET_TYPE_TCP_FIN;
504 frame->connid = tun->connid;
505 frame->data_length = 0;
506 send_frame(frame, data);
507 tunnel_delete(tun);
508 }
509 else
486 log_printf(L_DEBUG, "Reading from local socket failed: code=%d (%s)\n",
487 errno, strerror(errno));
488 }
489 else
490 {
491 log_printf(L_DEBUG2, "Nothing to read...");
492 }
493 }
494 else
495 {
496 HASH_ITER(hh, by_id, tun, tmp)
497 {
498 if(FD_ISSET(tun->sockfd, &fds))
510 499 { {
511 protocol_frame frame_st, *frame;
512
513 frame = &frame_st;
514 memset(frame, 0, sizeof(protocol_frame));
515 frame->friendnumber = tun->friendnumber;
516 frame->packet_type = PACKET_TYPE_TCP;
517 frame->connid = tun->connid;
518 frame->data_length = nbytes;
519 send_frame(frame, tox_packet_buf);
520
521 // printf("Wrote %d bytes from sock %d to tunnel %d\n", nbytes, tun->sockfd, tun->connid);
500 int nbytes;
501 if(client_local_port_mode)
502 {
503 nbytes = recv(tun->sockfd,
504 tox_packet_buf + PROTOCOL_BUFFER_OFFSET,
505 READ_BUFFER_SIZE, 0);
506 }
507 else
508 {
509 nbytes = read(tun->sockfd,
510 tox_packet_buf + PROTOCOL_BUFFER_OFFSET,
511 READ_BUFFER_SIZE
512 );
513 }
514
515 /* Check if connection closed */
516 if(nbytes == 0)
517 {
518 char data[PROTOCOL_BUFFER_OFFSET];
519 protocol_frame frame_st, *frame;
520
521 log_printf(L_INFO, "Connection closed\n");
522
523 frame = &frame_st;
524 memset(frame, 0, sizeof(protocol_frame));
525 frame->friendnumber = tun->friendnumber;
526 frame->packet_type = PACKET_TYPE_TCP_FIN;
527 frame->connid = tun->connid;
528 frame->data_length = 0;
529 send_frame(frame, data);
530 if(tun->sockfd)
531 {
532 FD_CLR(tun->sockfd, &client_master_fdset);
533 }
534 tunnel_delete(tun);
535 }
536 else
537 {
538 protocol_frame frame_st, *frame;
539
540 frame = &frame_st;
541 memset(frame, 0, sizeof(protocol_frame));
542 frame->friendnumber = tun->friendnumber;
543 frame->packet_type = PACKET_TYPE_TCP;
544 frame->connid = tun->connid;
545 frame->data_length = nbytes;
546 send_frame(frame, tox_packet_buf);
547
548 // printf("Wrote %d bytes from sock %d to tunnel %d\n", nbytes, tun->sockfd, tun->connid);
549 }
522 550 } }
523 551 } }
524 552 } }
File log.h changed (mode: 100644) (index ed48364..11d07d5)
3 3 #define L_NOTICE 5 #define L_NOTICE 5
4 4 #define L_INFO 6 #define L_INFO 6
5 5 #define L_DEBUG 7 #define L_DEBUG 7
6 #define L_DEBUG2 8
6 7
7 8 #define L_UNSET 0x29a #define L_UNSET 0x29a
8 9
File main.c changed (mode: 100644) (index 0535e67..b87172c)
... ... void tunnel_delete(tunnel *t)
115 115 if(t->sockfd) if(t->sockfd)
116 116 { {
117 117 close(t->sockfd); close(t->sockfd);
118 FD_CLR(t->sockfd, &master_server_fds);
118 119 } }
119 120 HASH_DEL( by_id, t ); HASH_DEL( by_id, t );
120 121 free(t); free(t);
 
... ... void handle_connection_status_change(Tox *tox, TOX_CONNECTION p_connection_statu
744 745 log_printf(L_INFO, "Connection status changed: %s", status); log_printf(L_INFO, "Connection status changed: %s", status);
745 746 } }
746 747
747 void cleanup(int status, void *tmp)
748 void cleanup()
748 749 { {
749 750 log_printf(L_DEBUG, "kthxbye\n"); log_printf(L_DEBUG, "kthxbye\n");
750 751 fflush(stdout); fflush(stdout);
 
... ... int do_server_loop()
778 779 { {
779 780 TOX_CONNECTION tmp_isconnected = 0; TOX_CONNECTION tmp_isconnected = 0;
780 781 uint32_t tox_do_interval_ms; uint32_t tox_do_interval_ms;
782 int select_rv = 0;
781 783
782 784 /* Let tox do its stuff */ /* Let tox do its stuff */
783 785 tox_iterate(tox); tox_iterate(tox);
 
... ... int do_server_loop()
807 809 fds = master_server_fds; fds = master_server_fds;
808 810
809 811 /* Poll for data from our client connection */ /* Poll for data from our client connection */
810 select(select_nfds, &fds, NULL, NULL, &tv);
811 HASH_ITER(hh, by_id, tun, tmp)
812 select_rv = select(select_nfds, &fds, NULL, NULL, &tv);
813 if(select_rv == -1 || select_rv == 0)
812 814 { {
813 if(FD_ISSET(tun->sockfd, &fds))
815 if(select_rv == -1)
814 816 { {
815 int nbytes = recv(tun->sockfd,
816 tox_packet_buf+PROTOCOL_BUFFER_OFFSET,
817 READ_BUFFER_SIZE, 0);
818
819 /* Check if connection closed */
820 if(nbytes <= 0)
817 log_printf(L_DEBUG, "Reading from local socket failed: code=%d (%s)\n",
818 errno, strerror(errno));
819 }
820 else
821 {
822 log_printf(L_DEBUG2, "Nothing to read...");
823 }
824 }
825 else
826 {
827 HASH_ITER(hh, by_id, tun, tmp)
828 {
829 if(FD_ISSET(tun->sockfd, &fds))
821 830 { {
822 char data[PROTOCOL_BUFFER_OFFSET];
823 protocol_frame frame_st, *frame;
831 int nbytes = recv(tun->sockfd,
832 tox_packet_buf+PROTOCOL_BUFFER_OFFSET,
833 READ_BUFFER_SIZE, 0);
824 834
825 if(nbytes == 0)
835 /* Check if connection closed */
836 if(nbytes <= 0)
826 837 { {
827 log_printf(L_WARNING, "conn closed!\n");
838 char data[PROTOCOL_BUFFER_OFFSET];
839 protocol_frame frame_st, *frame;
840
841 if(nbytes == 0)
842 {
843 log_printf(L_WARNING, "conn closed!\n");
844 }
845 else
846 {
847 log_printf(L_WARNING, "conn closed, code=%d (%s)\n",
848 errno, strerror(errno));
849 }
850
851 frame = &frame_st;
852 memset(frame, 0, sizeof(protocol_frame));
853 frame->friendnumber = tun->friendnumber;
854 frame->packet_type = PACKET_TYPE_TCP_FIN;
855 frame->connid = tun->connid;
856 frame->data_length = 0;
857 send_frame(frame, data);
858
859 tunnel_delete(tun);
860
861 continue;
828 862 } }
829 863 else else
830 864 { {
831 log_printf(L_WARNING, "conn closed, code=%d (%s)\n",
832 errno, strerror(errno));
865 protocol_frame frame_st, *frame;
866
867 frame = &frame_st;
868 memset(frame, 0, sizeof(protocol_frame));
869 frame->friendnumber = tun->friendnumber;
870 frame->packet_type = PACKET_TYPE_TCP;
871 frame->connid = tun->connid;
872 frame->data_length = nbytes;
873 send_frame(frame, tox_packet_buf);
833 874 } }
834
835 frame = &frame_st;
836 memset(frame, 0, sizeof(protocol_frame));
837 frame->friendnumber = tun->friendnumber;
838 frame->packet_type = PACKET_TYPE_TCP_FIN;
839 frame->connid = tun->connid;
840 frame->data_length = 0;
841 send_frame(frame, data);
842
843 tunnel_delete(tun);
844
845 continue;
846 }
847 else
848 {
849 protocol_frame frame_st, *frame;
850
851 frame = &frame_st;
852 memset(frame, 0, sizeof(protocol_frame));
853 frame->friendnumber = tun->friendnumber;
854 frame->packet_type = PACKET_TYPE_TCP;
855 frame->connid = tun->connid;
856 frame->data_length = nbytes;
857 send_frame(frame, tox_packet_buf);
858 875 } }
859 876 } }
860 877 } }
 
... ... int do_server_loop()
865 882
866 883 if(ms_end - ms_start < tox_do_interval_ms) if(ms_end - ms_start < tox_do_interval_ms)
867 884 { {
868 log_printf(L_DEBUG, "Sleeping for %d ms extra to prevent high CPU usage\n", (tox_do_interval_ms - (ms_end - ms_start)));
885 /*log_printf(L_DEBUG, "Sleeping for %d ms extra to prevent high CPU usage\n", (tox_do_interval_ms - (ms_end - ms_start)));*/
869 886 usleep((tox_do_interval_ms - (ms_end - ms_start)) * 1000); usleep((tox_do_interval_ms - (ms_end - ms_start)) * 1000);
870 887 } }
871 888 } }
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/gdr/tuntox

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/gdr/tuntox

Clone this repository using git:
git clone git://git.rocketgit.com/user/gdr/tuntox

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main