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)
Server state loading/saving 7cb0f811c9a573342ec390080ac67e640d0f2e30 GDR! 2014-11-26 12:55:12
Multi-connection support client-side. 16add85eb81629b07dd7bdb04fbe30be1410cc83 GDR! 2014-11-25 22:09:45
TCP works, yay c311fb3bdd2c26c347c2dd734f97003ac0538037 GDR! 2014-11-16 02:54:56
creating tunnels half-made 9b523f2b826dea54613f2eac78f754c9772841b6 GDR! 2014-11-15 19:14:53
builds well 3b42ed1ca1be6d1c8f14606befee8b8deae64ac8 GDR! 2014-11-10 18:05:14
makefile f877c04fdb45aebff081df4ed1b7fea9bd293fa5 GDR! 2014-11-09 16:24:12
Commit 7cb0f811c9a573342ec390080ac67e640d0f2e30 - Server state loading/saving
Author: GDR!
Author date (UTC): 2014-11-26 12:55
Committer name: GDR!
Committer date (UTC): 2014-11-26 12:55
Parent(s): 16add85eb81629b07dd7bdb04fbe30be1410cc83
Signer:
Signing key:
Signing status: N
Tree: 16bf9d1ee4f806b61f56d8e3bb57276ffd8bd42e
File Lines added Lines deleted
main.c 109 8
util.c 40 0
util.h 1 0
File main.c changed (mode: 100644) (index c3444ee..4b7a3c5)
... ... int client_pipe_mode = 0;
22 22 /* Remote Tox ID in client mode */ /* Remote Tox ID in client mode */
23 23 char *remote_tox_id = NULL; char *remote_tox_id = NULL;
24 24
25 /* Directory with config and tox save */
26 char config_path[500] = "/etc/tuntox/";
27
25 28 /* Ports and hostname for port forwarding */ /* Ports and hostname for port forwarding */
26 29 int remote_port = 0; int remote_port = 0;
27 30 char *remote_host = NULL; char *remote_host = NULL;
 
... ... int get_client_socket(char *hostname, int port)
203 206
204 207 if (p == NULL) { if (p == NULL) {
205 208 fprintf(stderr, "failed to connect to %s:%d\n", hostname, port); fprintf(stderr, "failed to connect to %s:%d\n", hostname, port);
206 exit(1);
209 return -1;
207 210 } }
208 211
209 212 inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
 
... ... int send_frame(protocol_frame *frame, uint8_t *data)
270 273
271 274 if(i > 0 && rv >= 0) if(i > 0 && rv >= 0)
272 275 { {
273 fprintf(stderr, "Packet succeeded at try %d", i+1);
276 fprintf(stderr, "Packet succeeded at try %d\n", i+1);
274 277 } }
275 278
276 279 return rv; return rv;
 
... ... int send_tunnel_request_packet(char *remote_host, int remote_port, int friend_nu
559 562
560 563 /* End proto */ /* End proto */
561 564
565 /* Save tox identity to a file */
566 static void write_save(Tox *tox)
567 {
568 void *data;
569 uint32_t size;
570 uint8_t path_tmp[512], path_real[512], *p;
571 FILE *file;
572
573 size = tox_size(tox);
574 data = malloc(size);
575 tox_save(tox, data);
576
577 strncpy(path_real, config_path, sizeof(config_path));
578
579 p = path_real + strlen(path_real);
580 memcpy(p, "tox_save", sizeof("tox_save"));
581
582 unsigned int path_len = (p - path_real) + sizeof("tox_save");
583 memcpy(path_tmp, path_real, path_len);
584 memcpy(path_tmp + (path_len - 1), ".tmp", sizeof(".tmp"));
585
586 file = fopen((char*)path_tmp, "wb");
587 if(file) {
588 fwrite(data, size, 1, file);
589 fflush(file);
590 fclose(file);
591 if (rename((char*)path_tmp, (char*)path_real) != 0) {
592 fprintf(stderr, "Failed to rename file. %s to %s deleting and trying again\n", path_tmp, path_real);
593 remove((const char *)path_real);
594 if (rename((char*)path_tmp, (char*)path_real) != 0) {
595 fprintf(stderr, "Saving Failed\n");
596 } else {
597 fprintf(stderr, "Saved data\n");
598 }
599 } else {
600 fprintf(stderr, "Saved data\n");
601 }
602 }
603 else
604 {
605 fprintf(stderr, "Could not open save file\n");
606 }
607
608 free(data);
609 }
610
611 /* Load tox identity from a file */
612 static int load_save(Tox *tox)
613 {
614 void *data;
615 uint32_t size;
616 uint8_t path_tmp[512], path_real[512], *p;
617 FILE *file;
618
619 strncpy(path_real, config_path, sizeof(config_path));
620
621 p = path_real + strlen(path_real);
622 memcpy(p, "tox_save", sizeof("tox_save"));
623
624 unsigned int path_len = (p - path_real) + sizeof("tox_save");
625
626 data = file_raw((char *)path_real, &size);
627
628 if(data)
629 {
630 tox_load(tox, data, size);
631 free(data);
632 return 1;
633 }
634 else
635 {
636 fprintf(stderr, "Could not open save file\n");
637 return 0;
638 }
639 }
640
562 641 void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
563 642 { {
564 643 unsigned char tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1]; unsigned char tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1];
 
... ... int main(int argc, char *argv[])
699 778 unsigned char tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1]; unsigned char tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1];
700 779 int oc; int oc;
701 780
702 while ((oc = getopt(argc, argv, "L:pi:")) != -1)
781 while ((oc = getopt(argc, argv, "L:pi:C:")) != -1)
703 782 { {
704 783 switch(oc) switch(oc)
705 784 { {
 
... ... int main(int argc, char *argv[])
727 806 ping_mode = 1; ping_mode = 1;
728 807 break; break;
729 808 case 'i': case 'i':
809 /* Tox ID */
730 810 remote_tox_id = optarg; remote_tox_id = optarg;
731 811 break; break;
812 case 'C':
813 /* Config directory */
814 strncpy(config_path, optarg, sizeof(config_path) - 1);
815 if(optarg[strlen(optarg) - 1] != '/')
816 {
817 int optarg_len = strlen(optarg);
818
819 config_path[optarg_len] = '/';
820 config_path[optarg_len + 1] = '\0';
821 }
822 break;
732 823 case '?': case '?':
733 824 default: default:
734 825 help(); help();
 
... ... int main(int argc, char *argv[])
747 838
748 839 set_tox_username(tox); set_tox_username(tox);
749 840
750 tox_get_address(tox, tox_id);
751 id_to_string(tox_printable_id, tox_id);
752 tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0';
753 printf("Generated Tox ID: %s\n", tox_printable_id);
754
755 841 do_bootstrap(tox); do_bootstrap(tox);
756 842
757 843 /* TODO use proper argparse */ /* TODO use proper argparse */
758 844 if(client_mode) if(client_mode)
759 845 { {
846 tox_get_address(tox, tox_id);
847 id_to_string(tox_printable_id, tox_id);
848 tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0';
849 printf("Generated Tox ID: %s\n", tox_printable_id);
850
760 851 if(!remote_tox_id) if(!remote_tox_id)
761 852 { {
762 853 fprintf(stderr, "Tox id is required in client mode. Use -i 58435984ABCDEF475...\n"); fprintf(stderr, "Tox id is required in client mode. Use -i 58435984ABCDEF475...\n");
 
... ... int main(int argc, char *argv[])
768 859 { {
769 860 /* Connect to the forwarded service */ /* Connect to the forwarded service */
770 861 // client_socket = get_client_socket(); // client_socket = get_client_socket();
862 if(!load_save(tox))
863 {
864 /* Write generated ID if one is not already present */
865 write_save(tox);
866 }
867
868 tox_get_address(tox, tox_id);
869 id_to_string(tox_printable_id, tox_id);
870 tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0';
871 printf("Using Tox ID: %s\n", tox_printable_id);
771 872
772 873 tox_callback_friend_request(tox, accept_friend_request, NULL); tox_callback_friend_request(tox, accept_friend_request, NULL);
773 874 do_server_loop(); do_server_loop();
File util.c changed (mode: 100644) (index 8366d60..653a009)
1 1 #include "util.h" #include "util.h"
2 2 #include <string.h> #include <string.h>
3 3 #include <tox/tox.h> #include <tox/tox.h>
4 #include <stdio.h>
4 5
5 6 void writechecksum(uint8_t *address) void writechecksum(uint8_t *address)
6 7 { {
 
... ... int parse_local_port_forward(char *string, int *local_port, char **hostname, int
100 101
101 102 return 0; return 0;
102 103 } }
104
105 void* file_raw(char *path, uint32_t *size)
106 {
107 FILE *file;
108 char *data;
109 int len;
110
111 file = fopen(path, "rb");
112 if(!file) {
113 fprintf(stderr, "File not found (%s)\n", path);
114 return NULL;
115 }
116
117 fseek(file, 0, SEEK_END);
118 len = ftell(file);
119 data = malloc(len);
120 if(!data) {
121 fclose(file);
122 return NULL;
123 }
124
125 fseek(file, 0, SEEK_SET);
126
127 if(fread(data, len, 1, file) != 1) {
128 fprintf(stderr, "Read error (%s)\n", path);
129 fclose(file);
130 free(data);
131 return NULL;
132 }
133
134 fclose(file);
135
136 fprintf(stderr, "Read %u bytes (%s)\n", len, path);
137
138 if(size) {
139 *size = len;
140 }
141 return data;
142 }
File util.h changed (mode: 100644) (index 723e27d..30d24a5)
... ... void writechecksum(uint8_t *address);
10 10 void to_hex(char_t *a, const char_t *p, int size); void to_hex(char_t *a, const char_t *p, int size);
11 11 void id_to_string(char_t *dest, const char_t *src); void id_to_string(char_t *dest, const char_t *src);
12 12 int string_to_id(char_t *w, char_t *a); int string_to_id(char_t *w, char_t *a);
13 void* file_raw(char *path, uint32_t *size);
13 14
14 15 #endif #endif
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