ffi-tox 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/ProjectTox-Core/AUTHORS +0 -0
  3. data/ProjectTox-Core/ChangeLog +0 -0
  4. data/ProjectTox-Core/INSTALL +370 -0
  5. data/ProjectTox-Core/INSTALL.md +455 -56
  6. data/ProjectTox-Core/Makefile.am +35 -0
  7. data/ProjectTox-Core/NEWS +0 -0
  8. data/ProjectTox-Core/README +43 -0
  9. data/ProjectTox-Core/README.md +34 -44
  10. data/ProjectTox-Core/auto_tests/Makefile.inc +110 -0
  11. data/ProjectTox-Core/auto_tests/TCP_test.c +519 -0
  12. data/ProjectTox-Core/auto_tests/assoc_test.c +160 -0
  13. data/ProjectTox-Core/auto_tests/crypto_test.c +302 -0
  14. data/ProjectTox-Core/auto_tests/dht_test.c +362 -0
  15. data/ProjectTox-Core/auto_tests/encryptsave_test.c +104 -0
  16. data/ProjectTox-Core/auto_tests/friends_test.c +238 -0
  17. data/ProjectTox-Core/auto_tests/helpers.h +15 -0
  18. data/ProjectTox-Core/auto_tests/messenger_test.c +365 -0
  19. data/ProjectTox-Core/auto_tests/network_test.c +171 -0
  20. data/ProjectTox-Core/auto_tests/onion_test.c +363 -0
  21. data/ProjectTox-Core/auto_tests/skeleton_test.c +49 -0
  22. data/ProjectTox-Core/auto_tests/tox_test.c +454 -0
  23. data/ProjectTox-Core/auto_tests/toxav_basic_test.c +597 -0
  24. data/ProjectTox-Core/auto_tests/toxav_many_test.c +402 -0
  25. data/ProjectTox-Core/autogen.sh +6 -0
  26. data/ProjectTox-Core/build/Makefile.am +14 -0
  27. data/ProjectTox-Core/configure.ac +694 -0
  28. data/ProjectTox-Core/dist-build/android-arm.sh +3 -0
  29. data/ProjectTox-Core/dist-build/android-armv7.sh +3 -0
  30. data/ProjectTox-Core/dist-build/android-build.sh +59 -0
  31. data/ProjectTox-Core/dist-build/android-mips.sh +3 -0
  32. data/ProjectTox-Core/dist-build/android-x86.sh +3 -0
  33. data/ProjectTox-Core/docs/Group-Chats.md +71 -0
  34. data/ProjectTox-Core/docs/Hardening.txt +60 -0
  35. data/ProjectTox-Core/docs/Hardening_docs.txt +30 -0
  36. data/ProjectTox-Core/docs/Prevent_Tracking.txt +160 -0
  37. data/ProjectTox-Core/docs/TCP_Network.txt +154 -0
  38. data/ProjectTox-Core/docs/TODO +62 -0
  39. data/ProjectTox-Core/docs/Tox_middle_level_network_protocol.txt +120 -0
  40. data/ProjectTox-Core/docs/av_api.md +194 -0
  41. data/ProjectTox-Core/libtoxav.pc.in +11 -0
  42. data/ProjectTox-Core/libtoxcore.pc.in +11 -0
  43. data/ProjectTox-Core/m4/ax_have_epoll.m4 +104 -0
  44. data/ProjectTox-Core/m4/ax_pthread.m4 +317 -0
  45. data/ProjectTox-Core/m4/pkg.m4 +199 -0
  46. data/ProjectTox-Core/other/DHT_bootstrap.c +121 -58
  47. data/ProjectTox-Core/other/DHTnodes +3 -0
  48. data/ProjectTox-Core/other/Makefile.inc +20 -0
  49. data/ProjectTox-Core/other/bootstrap_node_packets.c +65 -0
  50. data/ProjectTox-Core/other/tox.png +0 -0
  51. data/ProjectTox-Core/testing/DHT_test.c +170 -98
  52. data/ProjectTox-Core/testing/Makefile.inc +112 -0
  53. data/ProjectTox-Core/testing/Messenger_test.c +133 -69
  54. data/ProjectTox-Core/testing/dns3_test.c +115 -0
  55. data/ProjectTox-Core/testing/misc_tools.c +59 -13
  56. data/ProjectTox-Core/testing/nTox.c +1127 -264
  57. data/ProjectTox-Core/testing/nTox.h +10 -19
  58. data/ProjectTox-Core/testing/tox_shell.c +159 -0
  59. data/ProjectTox-Core/testing/tox_sync.c +299 -0
  60. data/ProjectTox-Core/tools/README +11 -0
  61. data/ProjectTox-Core/tools/astylerc +11 -0
  62. data/ProjectTox-Core/tools/pre-commit +17 -0
  63. data/ProjectTox-Core/toxav/Makefile.inc +36 -0
  64. data/ProjectTox-Core/toxav/codec.c +357 -0
  65. data/ProjectTox-Core/toxav/codec.h +116 -0
  66. data/ProjectTox-Core/toxav/msi.c +1949 -0
  67. data/ProjectTox-Core/toxav/msi.h +267 -0
  68. data/ProjectTox-Core/toxav/rtp.c +600 -0
  69. data/ProjectTox-Core/toxav/rtp.h +196 -0
  70. data/ProjectTox-Core/toxav/toxav.c +1148 -0
  71. data/ProjectTox-Core/toxav/toxav.h +389 -0
  72. data/ProjectTox-Core/toxcore/DHT.c +2521 -0
  73. data/ProjectTox-Core/toxcore/DHT.h +412 -0
  74. data/ProjectTox-Core/toxcore/LAN_discovery.c +322 -0
  75. data/ProjectTox-Core/{core → toxcore}/LAN_discovery.h +17 -12
  76. data/ProjectTox-Core/toxcore/Makefile.inc +67 -0
  77. data/ProjectTox-Core/toxcore/Messenger.c +3006 -0
  78. data/ProjectTox-Core/toxcore/Messenger.h +818 -0
  79. data/ProjectTox-Core/toxcore/TCP_client.c +858 -0
  80. data/ProjectTox-Core/toxcore/TCP_client.h +156 -0
  81. data/ProjectTox-Core/toxcore/TCP_server.c +1332 -0
  82. data/ProjectTox-Core/toxcore/TCP_server.h +181 -0
  83. data/ProjectTox-Core/toxcore/assoc.c +1033 -0
  84. data/ProjectTox-Core/toxcore/assoc.h +104 -0
  85. data/ProjectTox-Core/toxcore/crypto_core.c +278 -0
  86. data/ProjectTox-Core/toxcore/crypto_core.h +151 -0
  87. data/ProjectTox-Core/toxcore/friend_requests.c +175 -0
  88. data/ProjectTox-Core/toxcore/friend_requests.h +83 -0
  89. data/ProjectTox-Core/toxcore/group_chats.c +837 -0
  90. data/ProjectTox-Core/toxcore/group_chats.h +199 -0
  91. data/ProjectTox-Core/toxcore/list.c +256 -0
  92. data/ProjectTox-Core/toxcore/list.h +85 -0
  93. data/ProjectTox-Core/toxcore/logger.c +153 -0
  94. data/ProjectTox-Core/toxcore/logger.h +84 -0
  95. data/ProjectTox-Core/toxcore/misc_tools.h +70 -0
  96. data/ProjectTox-Core/toxcore/net_crypto.c +2753 -0
  97. data/ProjectTox-Core/toxcore/net_crypto.h +410 -0
  98. data/ProjectTox-Core/toxcore/network.c +979 -0
  99. data/ProjectTox-Core/toxcore/network.h +367 -0
  100. data/ProjectTox-Core/toxcore/onion.c +540 -0
  101. data/ProjectTox-Core/toxcore/onion.h +150 -0
  102. data/ProjectTox-Core/toxcore/onion_announce.c +433 -0
  103. data/ProjectTox-Core/toxcore/onion_announce.h +139 -0
  104. data/ProjectTox-Core/toxcore/onion_client.c +1347 -0
  105. data/ProjectTox-Core/toxcore/onion_client.h +253 -0
  106. data/ProjectTox-Core/toxcore/ping.c +346 -0
  107. data/ProjectTox-Core/toxcore/ping.h +47 -0
  108. data/ProjectTox-Core/toxcore/ping_array.c +162 -0
  109. data/ProjectTox-Core/toxcore/ping_array.h +75 -0
  110. data/ProjectTox-Core/toxcore/tox.c +940 -0
  111. data/ProjectTox-Core/toxcore/tox.h +734 -0
  112. data/ProjectTox-Core/toxcore/util.c +193 -0
  113. data/ProjectTox-Core/toxcore/util.h +63 -0
  114. data/ProjectTox-Core/toxdns/Makefile.inc +29 -0
  115. data/ProjectTox-Core/toxdns/toxdns.c +238 -0
  116. data/ProjectTox-Core/toxdns/toxdns.h +88 -0
  117. data/ProjectTox-Core/toxencryptsave/Makefile.inc +45 -0
  118. data/ProjectTox-Core/toxencryptsave/toxencryptsave.c +179 -0
  119. data/ProjectTox-Core/toxencryptsave/toxencryptsave.h +74 -0
  120. data/interfaces/libtox.i +2 -6
  121. data/lib/ffi-tox/libtox.rb +406 -28
  122. metadata +124 -46
  123. data/ProjectTox-Core/CMakeLists.txt +0 -50
  124. data/ProjectTox-Core/cmake/FindLIBCONFIG.cmake +0 -15
  125. data/ProjectTox-Core/cmake/FindNaCl.cmake +0 -17
  126. data/ProjectTox-Core/cmake/FindSODIUM.cmake +0 -15
  127. data/ProjectTox-Core/core/CMakeLists.txt +0 -19
  128. data/ProjectTox-Core/core/DHT.c +0 -1104
  129. data/ProjectTox-Core/core/DHT.h +0 -111
  130. data/ProjectTox-Core/core/LAN_discovery.c +0 -79
  131. data/ProjectTox-Core/core/Lossless_UDP.c +0 -755
  132. data/ProjectTox-Core/core/Lossless_UDP.h +0 -106
  133. data/ProjectTox-Core/core/Messenger.c +0 -596
  134. data/ProjectTox-Core/core/Messenger.h +0 -165
  135. data/ProjectTox-Core/core/friend_requests.c +0 -131
  136. data/ProjectTox-Core/core/friend_requests.h +0 -51
  137. data/ProjectTox-Core/core/net_crypto.c +0 -575
  138. data/ProjectTox-Core/core/net_crypto.h +0 -134
  139. data/ProjectTox-Core/core/network.c +0 -205
  140. data/ProjectTox-Core/core/network.h +0 -134
  141. data/ProjectTox-Core/docs/commands.md +0 -25
  142. data/ProjectTox-Core/docs/start_guide.de.md +0 -40
  143. data/ProjectTox-Core/docs/start_guide.md +0 -38
  144. data/ProjectTox-Core/other/CMakeLists.txt +0 -9
  145. data/ProjectTox-Core/testing/CMakeLists.txt +0 -18
  146. data/ProjectTox-Core/testing/DHT_cryptosendfiletest.c +0 -228
  147. data/ProjectTox-Core/testing/DHT_sendfiletest.c +0 -176
  148. data/ProjectTox-Core/testing/Lossless_UDP_testclient.c +0 -214
  149. data/ProjectTox-Core/testing/Lossless_UDP_testserver.c +0 -201
  150. data/ProjectTox-Core/testing/misc_tools.h +0 -29
  151. data/ProjectTox-Core/testing/nTox_win32.c +0 -387
  152. data/ProjectTox-Core/testing/nTox_win32.h +0 -40
  153. data/ProjectTox-Core/testing/rect.py +0 -45
@@ -0,0 +1,112 @@
1
+ if BUILD_NTOX
2
+
3
+ bin_PROGRAMS += nTox
4
+
5
+ nTox_SOURCES = ../testing/nTox.h \
6
+ ../testing/nTox.c
7
+
8
+ nTox_CFLAGS = $(LIBSODIUM_CFLAGS) \
9
+ $(NACL_CFLAGS) \
10
+ $(NCURSES_CFLAGS)
11
+
12
+ nTox_LDADD = $(LIBSODIUM_LDFLAGS) \
13
+ $(NAC_LDFLAGS) \
14
+ libtoxcore.la \
15
+ $(LIBSODIUM_LIBS) \
16
+ $(NACL_OBJECTS) \
17
+ $(NACL_LIBS) \
18
+ $(NCURSES_LIBS) \
19
+ $(WINSOCK2_LIBS)
20
+ endif
21
+
22
+
23
+ if BUILD_TESTING
24
+
25
+ noinst_PROGRAMS += DHT_test \
26
+ Messenger_test \
27
+ dns3_test
28
+
29
+ DHT_test_SOURCES = ../testing/DHT_test.c
30
+
31
+ DHT_test_CFLAGS = $(LIBSODIUM_CFLAGS) \
32
+ $(NACL_CFLAGS)
33
+
34
+ DHT_test_LDADD = $(LIBSODIUM_LDFLAGS) \
35
+ $(NACL_LDFLAGS) \
36
+ libtoxcore.la \
37
+ $(LIBSODIUM_LIBS) \
38
+ $(NACL_OBJECTS) \
39
+ $(NACL_LIBS) \
40
+ $(WINSOCK2_LIBS)
41
+
42
+
43
+ Messenger_test_SOURCES = \
44
+ ../testing/Messenger_test.c
45
+
46
+ Messenger_test_CFLAGS = $(LIBSODIUM_CFLAGS) \
47
+ $(NACL_CFLAGS)
48
+
49
+ Messenger_test_LDADD = $(LIBSODIUM_LDFLAGS) \
50
+ $(NACL_LDFLAGS) \
51
+ libtoxcore.la \
52
+ $(LIBSODIUM_LIBS) \
53
+ $(NACL_OBJECTS) \
54
+ $(NACL_LIBS) \
55
+ $(WINSOCK2_LIBS)
56
+
57
+
58
+
59
+ dns3_test_SOURCES = \
60
+ ../testing/dns3_test.c
61
+
62
+ dns3_test_CFLAGS = \
63
+ $(LIBSODIUM_CFLAGS) \
64
+ $(NACL_CFLAGS)
65
+
66
+ dns3_test_LDADD = \
67
+ $(LIBSODIUM_LDFLAGS) \
68
+ $(NACL_LDFLAGS) \
69
+ libtoxdns.la \
70
+ libtoxcore.la \
71
+ $(LIBSODIUM_LIBS) \
72
+ $(NACL_OBJECTS) \
73
+ $(NACL_LIBS) \
74
+ $(WINSOCK2_LIBS)
75
+
76
+ if !WIN32
77
+
78
+ noinst_PROGRAMS += tox_sync
79
+
80
+ tox_sync_SOURCES = ../testing/tox_sync.c
81
+
82
+ tox_sync_CFLAGS = $(LIBSODIUM_CFLAGS) \
83
+ $(NACL_CFLAGS)
84
+
85
+ tox_sync_LDADD = $(LIBSODIUM_LDFLAGS) \
86
+ $(NACL_LDFLAGS) \
87
+ libtoxcore.la \
88
+ $(LIBSODIUM_LIBS) \
89
+ $(NACL_OBJECTS) \
90
+ $(NACL_LIBS)
91
+
92
+
93
+ noinst_PROGRAMS += tox_shell
94
+
95
+ tox_shell_SOURCES = ../testing/tox_shell.c
96
+
97
+ tox_shell_CFLAGS = $(LIBSODIUM_CFLAGS) \
98
+ $(NACL_CFLAGS)
99
+
100
+ tox_shell_LDADD = $(LIBSODIUM_LDFLAGS) \
101
+ $(NACL_LDFLAGS) \
102
+ libtoxcore.la \
103
+ $(LIBSODIUM_LIBS) \
104
+ $(NACL_OBJECTS) \
105
+ $(NACL_LIBS) \
106
+ -lutil
107
+
108
+ endif
109
+
110
+ EXTRA_DIST += $(top_srcdir)/testing/misc_tools.c
111
+
112
+ endif
@@ -1,21 +1,21 @@
1
1
  /* Messenger test
2
- *
2
+ *
3
3
  * This program adds a friend and accepts all friend requests with the proper message.
4
- *
4
+ *
5
5
  * It tries sending a message to the added friend.
6
- *
7
- * If it recieves a message from a friend it replies back.
8
- *
9
- *
6
+ *
7
+ * If it receives a message from a friend it replies back.
8
+ *
9
+ *
10
10
  * This is how I compile it: gcc -O2 -Wall -D VANILLA_NACL -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} Messenger_test.c
11
11
  *
12
- *
12
+ *
13
13
  * Command line arguments are the ip, port and public_key of a node (for bootstrapping).
14
- *
14
+ *
15
15
  * EX: ./test 127.0.0.1 33445 CDCFD319CE3460824B33BE58FD86B8941C9585181D8FBD7C79C5721D7C2E9F7C
16
- *
16
+ *
17
17
  * Or the argument can be the path to the save file.
18
- *
18
+ *
19
19
  * EX: ./test Save.bak
20
20
  *
21
21
  * Copyright (C) 2013 Tox project All Rights Reserved.
@@ -34,13 +34,17 @@
34
34
  *
35
35
  * You should have received a copy of the GNU General Public License
36
36
  * along with Tox. If not, see <http://www.gnu.org/licenses/>.
37
- *
37
+ *
38
38
  */
39
39
 
40
- #include "../core/Messenger.h"
41
- #include "misc_tools.h"
40
+ #ifdef HAVE_CONFIG_H
41
+ #include "config.h"
42
+ #endif
43
+
44
+ #include "../toxcore/Messenger.h"
45
+ #include "misc_tools.c"
42
46
 
43
- #ifdef WIN32
47
+ #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
44
48
 
45
49
  #define c_sleep(x) Sleep(1*x)
46
50
 
@@ -48,98 +52,158 @@
48
52
  #include <unistd.h>
49
53
  #include <arpa/inet.h>
50
54
  #define c_sleep(x) usleep(1000*x)
55
+ #define PORT 33445
51
56
 
52
57
  #endif
53
58
 
54
- void print_request(uint8_t * public_key, uint8_t * data, uint16_t length)
59
+ void print_message(Messenger *m, int friendnumber, const uint8_t *string, uint16_t length, void *userdata)
55
60
  {
56
- printf("Friend request recieved from: \n");
61
+ printf("Message with length %u received from %u: %s \n", length, friendnumber, string);
62
+ m_sendmessage(m, friendnumber, (uint8_t *)"Test1", 6);
63
+ }
64
+
65
+ /* FIXME needed as print_request has to match the interface expected by
66
+ * networking_requesthandler and so cannot take a Messenger * */
67
+ static Messenger *m;
68
+
69
+ void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
70
+ {
71
+ printf("Friend request received from: \n");
57
72
  printf("ClientID: ");
58
73
  uint32_t j;
59
- for(j = 0; j < 32; j++)
60
- {
61
- if(public_key[j] < 16)
74
+
75
+ for (j = 0; j < 32; j++) {
76
+ if (public_key[j] < 16)
62
77
  printf("0");
78
+
63
79
  printf("%hhX", public_key[j]);
64
80
  }
81
+
65
82
  printf("\nOf length: %u with data: %s \n", length, data);
66
-
67
- if(length != sizeof("Install Gentoo"))
68
- {
83
+
84
+ if (length != sizeof("Install Gentoo")) {
69
85
  return;
70
86
  }
71
- if(memcmp(data , "Install Gentoo", sizeof("Install Gentoo")) == 0 )
72
- //if the request contained the message of peace the person is obviously a friend so we add him.
87
+
88
+ if (memcmp(data , "Install Gentoo", sizeof("Install Gentoo")) == 0 )
89
+ //if the request contained the message of peace the person is obviously a friend so we add him.
73
90
  {
74
91
  printf("Friend request accepted.\n");
75
- m_addfriend_norequest(public_key);
92
+ m_addfriend_norequest(m, public_key);
76
93
  }
77
94
  }
78
95
 
79
- void print_message(int friendnumber, uint8_t * string, uint16_t length)
80
- {
81
- printf("Message with length %u recieved from %u: %s \n", length, friendnumber, string);
82
- m_sendmessage(friendnumber, (uint8_t*)"Test1", 6);
83
- }
84
-
85
96
  int main(int argc, char *argv[])
86
97
  {
87
- if (argc < 4 && argc != 2) {
88
- printf("usage %s ip port public_key (of the DHT bootstrap node)\n or\n %s Save.bak\n", argv[0], argv[0]);
98
+ /* let user override default by cmdline */
99
+ uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
100
+ int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
101
+
102
+ if (argvoffset < 0)
103
+ exit(1);
104
+
105
+ /* with optional --ipvx, now it can be 1-4 arguments... */
106
+ if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) {
107
+ printf("Usage: %s [--ipv4|--ipv6] ip port public_key (of the DHT bootstrap node)\n", argv[0]);
108
+ printf("or\n");
109
+ printf(" %s [--ipv4|--ipv6] Save.bak (to read Save.bak as state file)\n", argv[0]);
89
110
  exit(0);
90
111
  }
91
- initMessenger();
92
- if(argc > 3) {
93
- IP_Port bootstrap_ip_port;
94
- bootstrap_ip_port.port = htons(atoi(argv[2]));
95
- bootstrap_ip_port.ip.i = inet_addr(argv[1]);
96
- DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
112
+
113
+ Messenger_Options options = {0};
114
+ options.ipv6enabled = ipv6enabled;
115
+ m = new_messenger(&options);
116
+
117
+ if ( !m ) {
118
+ fputs("Failed to allocate messenger datastructure\n", stderr);
119
+ exit(0);
120
+ }
121
+
122
+ if (argc == argvoffset + 4) {
123
+ uint16_t port = htons(atoi(argv[argvoffset + 2]));
124
+ uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
125
+ int res = DHT_bootstrap_from_address(m->dht, argv[argvoffset + 1],
126
+ ipv6enabled, port, bootstrap_key);
127
+ free(bootstrap_key);
128
+
129
+ if (!res) {
130
+ printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
131
+ exit(1);
132
+ }
97
133
  } else {
98
- FILE *file = fopen(argv[1], "rb");
99
- if ( file==NULL ){return 1;}
134
+ FILE *file = fopen(argv[argvoffset + 1], "rb");
135
+
136
+ if ( file == NULL ) {
137
+ printf("Failed to open \"%s\" - does it exist?\n", argv[argvoffset + 1]);
138
+ return 1;
139
+ }
140
+
100
141
  int read;
101
142
  uint8_t buffer[128000];
102
143
  read = fread(buffer, 1, 128000, file);
103
- printf("Messenger loaded: %i\n", Messenger_load(buffer, read));
144
+ printf("Messenger loaded: %i\n", messenger_load(m, buffer, read));
104
145
  fclose(file);
105
-
146
+
106
147
  }
107
- m_callback_friendrequest(print_request);
108
- m_callback_friendmessage(print_message);
109
-
148
+
149
+ m_callback_friendrequest(m, print_request, NULL);
150
+ m_callback_friendmessage(m, print_message, NULL);
151
+
110
152
  printf("OUR ID: ");
111
153
  uint32_t i;
112
- for(i = 0; i < 32; i++) {
113
- if(self_public_key[i] < 16)
154
+ uint8_t address[FRIEND_ADDRESS_SIZE];
155
+ getaddress(m, address);
156
+
157
+ for (i = 0; i < FRIEND_ADDRESS_SIZE; i++) {
158
+ if (address[i] < 16)
114
159
  printf("0");
115
- printf("%hhX",self_public_key[i]);
116
- }
117
-
118
- setname((uint8_t *)"Anon", 5);
119
-
120
- char temp_id[128];
121
- printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n");
122
- if(scanf("%s", temp_id) != 1) {
123
- return 1;
160
+
161
+ printf("%hhX", address[i]);
124
162
  }
125
- int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
126
-
163
+
164
+ setname(m, (uint8_t *)"Anon", 5);
165
+
166
+ char temp_hex_id[128];
167
+ printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n");
168
+
169
+ if (!fgets(temp_hex_id, sizeof(temp_hex_id), stdin))
170
+ exit(0);
171
+
172
+ if ((strlen(temp_hex_id) > 0) && (temp_hex_id[strlen(temp_hex_id) - 1] == '\n'))
173
+ temp_hex_id[strlen(temp_hex_id) - 1] = '\0';
174
+
175
+
176
+ uint8_t *bin_id = hex_string_to_bin(temp_hex_id);
177
+ int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"));
178
+ free(bin_id);
179
+
127
180
  perror("Initialization");
128
181
 
129
- while(1) {
182
+ while (1) {
130
183
  uint8_t name[128];
131
- getname(num, name);
184
+ getname(m, num, name);
132
185
  printf("%s\n", name);
133
-
134
- m_sendmessage(num, (uint8_t*)"Test", 5);
135
- doMessenger();
186
+
187
+ m_sendmessage(m, num, (uint8_t *)"Test", 5);
188
+ do_messenger(m);
136
189
  c_sleep(30);
137
190
  FILE *file = fopen("Save.bak", "wb");
138
- if ( file==NULL ){return 1;}
139
- uint8_t * buffer = malloc(Messenger_size());
140
- Messenger_save(buffer);
141
- fwrite(buffer, 1, Messenger_size(), file);
191
+
192
+ if ( file == NULL ) {
193
+ return 1;
194
+ }
195
+
196
+ uint8_t *buffer = malloc(messenger_size(m));
197
+ messenger_save(m, buffer);
198
+ size_t write_result = fwrite(buffer, 1, messenger_size(m), file);
199
+
200
+ if (write_result < messenger_size(m)) {
201
+ return 1;
202
+ }
203
+
142
204
  free(buffer);
143
205
  fclose(file);
144
- }
206
+ }
207
+
208
+ kill_messenger(m);
145
209
  }
@@ -0,0 +1,115 @@
1
+
2
+
3
+ #include "../toxdns/toxdns.h"
4
+ #include "../toxcore/tox.h"
5
+ #include "../toxcore/network.h"
6
+ #include "misc_tools.c"
7
+
8
+ #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
9
+
10
+ #define c_sleep(x) Sleep(1*x)
11
+
12
+ #else
13
+ #define c_sleep(x) usleep(1000*x)
14
+
15
+ #endif
16
+
17
+ uint32_t create_packet(uint8_t *packet, uint8_t *string, uint8_t str_len, uint8_t id)
18
+ {
19
+ memset(packet, 0, str_len + 13 + 16);
20
+ packet[0] = id;
21
+ packet[1] = rand();
22
+ packet[5] = 1;
23
+ packet[11] = 1;
24
+ packet[12] = '.';
25
+ memcpy(packet + 13, string, str_len);
26
+ uint32_t i, c = 0;
27
+
28
+ for (i = str_len + 12; i != 11; --i) {
29
+ if (packet[i] == '.') {
30
+ packet[i] = c;
31
+ c = 0;
32
+ } else {
33
+ ++c;
34
+ }
35
+ }
36
+
37
+ packet[str_len + 13 + 2] = 16;
38
+ packet[str_len + 13 + 4] = 1;
39
+ packet[str_len + 13 + 7] = 0x29;
40
+ packet[str_len + 13 + 8] = 16;
41
+ packet[str_len + 13 + 12] = 0x80;
42
+ return str_len + 13 + 16;
43
+ }
44
+
45
+ int main(int argc, char *argv[])
46
+ {
47
+ if (argc < 4) {
48
+ printf("Usage: %s domain domain_public_key queried_username\nEX: %s utox.org D3154F65D28A5B41A05D4AC7E4B39C6B1C233CC857FB365C56E8392737462A12 username\n",
49
+ argv[0], argv[0]);
50
+ exit(0);
51
+ }
52
+
53
+ IP ip = {0};
54
+ ip.family = AF_INET;
55
+ sock_t sock = socket(ip.family, SOCK_DGRAM, IPPROTO_UDP);
56
+
57
+ if (!sock_valid(sock))
58
+ return -1;
59
+
60
+ if (!addr_resolve_or_parse_ip(argv[1], &ip, 0))
61
+ return -1;
62
+
63
+ struct sockaddr_in target;
64
+ size_t addrsize = sizeof(struct sockaddr_in);
65
+ target.sin_family = AF_INET;
66
+ target.sin_addr = ip.ip4.in_addr;
67
+ target.sin_port = htons(53);
68
+
69
+ uint8_t string[1024] = {0};
70
+ void *d = tox_dns3_new(hex_string_to_bin(argv[2]));
71
+ unsigned int i;
72
+ uint32_t request_id;
73
+ /*
74
+ for (i = 0; i < 255; ++i) {
75
+ tox_generate_dns3_string(d, string, sizeof(string), &request_id, string, i);
76
+ printf("%s\n", string);
77
+ }*/
78
+ int len = tox_generate_dns3_string(d, string + 1, sizeof(string) - 1, &request_id, (uint8_t *)argv[3], strlen(argv[3]));
79
+
80
+ if (len == -1)
81
+ return -1;
82
+
83
+ string[0] = '_';
84
+ memcpy(string + len + 1, "._tox.", sizeof("._tox."));
85
+ memcpy((char *)(string + len + 1 + sizeof("._tox.") - 1), argv[1], strlen(argv[1]));
86
+ uint8_t packet[512];
87
+ uint8_t id = rand();
88
+ uint32_t p_len = create_packet(packet, string, strlen((char *)string), id);
89
+
90
+ if (sendto(sock, (char *) packet, p_len, 0, (struct sockaddr *)&target, addrsize) != p_len)
91
+ return -1;
92
+
93
+ uint8_t buffer[512] = {};
94
+ int r_len = recv(sock, buffer, sizeof(buffer), 0);
95
+
96
+ if (r_len < (int)p_len)
97
+ return -1;
98
+
99
+ for (i = r_len - 1; i != 0 && buffer[i] != '='; --i);
100
+
101
+ uint8_t tox_id[TOX_FRIEND_ADDRESS_SIZE];
102
+
103
+ if (tox_decrypt_dns3_TXT(d, tox_id, buffer + i + 1, r_len - (i + 1), request_id) != 0)
104
+ return -1;
105
+
106
+ printf("The Tox id for username %s is:\n", argv[3]);
107
+
108
+ //unsigned int i;
109
+ for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; ++i) {
110
+ printf("%02hhX", tox_id[i]);
111
+ }
112
+
113
+ printf("\n");
114
+ return 0;
115
+ }