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.
- checksums.yaml +4 -4
- data/ProjectTox-Core/AUTHORS +0 -0
- data/ProjectTox-Core/ChangeLog +0 -0
- data/ProjectTox-Core/INSTALL +370 -0
- data/ProjectTox-Core/INSTALL.md +455 -56
- data/ProjectTox-Core/Makefile.am +35 -0
- data/ProjectTox-Core/NEWS +0 -0
- data/ProjectTox-Core/README +43 -0
- data/ProjectTox-Core/README.md +34 -44
- data/ProjectTox-Core/auto_tests/Makefile.inc +110 -0
- data/ProjectTox-Core/auto_tests/TCP_test.c +519 -0
- data/ProjectTox-Core/auto_tests/assoc_test.c +160 -0
- data/ProjectTox-Core/auto_tests/crypto_test.c +302 -0
- data/ProjectTox-Core/auto_tests/dht_test.c +362 -0
- data/ProjectTox-Core/auto_tests/encryptsave_test.c +104 -0
- data/ProjectTox-Core/auto_tests/friends_test.c +238 -0
- data/ProjectTox-Core/auto_tests/helpers.h +15 -0
- data/ProjectTox-Core/auto_tests/messenger_test.c +365 -0
- data/ProjectTox-Core/auto_tests/network_test.c +171 -0
- data/ProjectTox-Core/auto_tests/onion_test.c +363 -0
- data/ProjectTox-Core/auto_tests/skeleton_test.c +49 -0
- data/ProjectTox-Core/auto_tests/tox_test.c +454 -0
- data/ProjectTox-Core/auto_tests/toxav_basic_test.c +597 -0
- data/ProjectTox-Core/auto_tests/toxav_many_test.c +402 -0
- data/ProjectTox-Core/autogen.sh +6 -0
- data/ProjectTox-Core/build/Makefile.am +14 -0
- data/ProjectTox-Core/configure.ac +694 -0
- data/ProjectTox-Core/dist-build/android-arm.sh +3 -0
- data/ProjectTox-Core/dist-build/android-armv7.sh +3 -0
- data/ProjectTox-Core/dist-build/android-build.sh +59 -0
- data/ProjectTox-Core/dist-build/android-mips.sh +3 -0
- data/ProjectTox-Core/dist-build/android-x86.sh +3 -0
- data/ProjectTox-Core/docs/Group-Chats.md +71 -0
- data/ProjectTox-Core/docs/Hardening.txt +60 -0
- data/ProjectTox-Core/docs/Hardening_docs.txt +30 -0
- data/ProjectTox-Core/docs/Prevent_Tracking.txt +160 -0
- data/ProjectTox-Core/docs/TCP_Network.txt +154 -0
- data/ProjectTox-Core/docs/TODO +62 -0
- data/ProjectTox-Core/docs/Tox_middle_level_network_protocol.txt +120 -0
- data/ProjectTox-Core/docs/av_api.md +194 -0
- data/ProjectTox-Core/libtoxav.pc.in +11 -0
- data/ProjectTox-Core/libtoxcore.pc.in +11 -0
- data/ProjectTox-Core/m4/ax_have_epoll.m4 +104 -0
- data/ProjectTox-Core/m4/ax_pthread.m4 +317 -0
- data/ProjectTox-Core/m4/pkg.m4 +199 -0
- data/ProjectTox-Core/other/DHT_bootstrap.c +121 -58
- data/ProjectTox-Core/other/DHTnodes +3 -0
- data/ProjectTox-Core/other/Makefile.inc +20 -0
- data/ProjectTox-Core/other/bootstrap_node_packets.c +65 -0
- data/ProjectTox-Core/other/tox.png +0 -0
- data/ProjectTox-Core/testing/DHT_test.c +170 -98
- data/ProjectTox-Core/testing/Makefile.inc +112 -0
- data/ProjectTox-Core/testing/Messenger_test.c +133 -69
- data/ProjectTox-Core/testing/dns3_test.c +115 -0
- data/ProjectTox-Core/testing/misc_tools.c +59 -13
- data/ProjectTox-Core/testing/nTox.c +1127 -264
- data/ProjectTox-Core/testing/nTox.h +10 -19
- data/ProjectTox-Core/testing/tox_shell.c +159 -0
- data/ProjectTox-Core/testing/tox_sync.c +299 -0
- data/ProjectTox-Core/tools/README +11 -0
- data/ProjectTox-Core/tools/astylerc +11 -0
- data/ProjectTox-Core/tools/pre-commit +17 -0
- data/ProjectTox-Core/toxav/Makefile.inc +36 -0
- data/ProjectTox-Core/toxav/codec.c +357 -0
- data/ProjectTox-Core/toxav/codec.h +116 -0
- data/ProjectTox-Core/toxav/msi.c +1949 -0
- data/ProjectTox-Core/toxav/msi.h +267 -0
- data/ProjectTox-Core/toxav/rtp.c +600 -0
- data/ProjectTox-Core/toxav/rtp.h +196 -0
- data/ProjectTox-Core/toxav/toxav.c +1148 -0
- data/ProjectTox-Core/toxav/toxav.h +389 -0
- data/ProjectTox-Core/toxcore/DHT.c +2521 -0
- data/ProjectTox-Core/toxcore/DHT.h +412 -0
- data/ProjectTox-Core/toxcore/LAN_discovery.c +322 -0
- data/ProjectTox-Core/{core → toxcore}/LAN_discovery.h +17 -12
- data/ProjectTox-Core/toxcore/Makefile.inc +67 -0
- data/ProjectTox-Core/toxcore/Messenger.c +3006 -0
- data/ProjectTox-Core/toxcore/Messenger.h +818 -0
- data/ProjectTox-Core/toxcore/TCP_client.c +858 -0
- data/ProjectTox-Core/toxcore/TCP_client.h +156 -0
- data/ProjectTox-Core/toxcore/TCP_server.c +1332 -0
- data/ProjectTox-Core/toxcore/TCP_server.h +181 -0
- data/ProjectTox-Core/toxcore/assoc.c +1033 -0
- data/ProjectTox-Core/toxcore/assoc.h +104 -0
- data/ProjectTox-Core/toxcore/crypto_core.c +278 -0
- data/ProjectTox-Core/toxcore/crypto_core.h +151 -0
- data/ProjectTox-Core/toxcore/friend_requests.c +175 -0
- data/ProjectTox-Core/toxcore/friend_requests.h +83 -0
- data/ProjectTox-Core/toxcore/group_chats.c +837 -0
- data/ProjectTox-Core/toxcore/group_chats.h +199 -0
- data/ProjectTox-Core/toxcore/list.c +256 -0
- data/ProjectTox-Core/toxcore/list.h +85 -0
- data/ProjectTox-Core/toxcore/logger.c +153 -0
- data/ProjectTox-Core/toxcore/logger.h +84 -0
- data/ProjectTox-Core/toxcore/misc_tools.h +70 -0
- data/ProjectTox-Core/toxcore/net_crypto.c +2753 -0
- data/ProjectTox-Core/toxcore/net_crypto.h +410 -0
- data/ProjectTox-Core/toxcore/network.c +979 -0
- data/ProjectTox-Core/toxcore/network.h +367 -0
- data/ProjectTox-Core/toxcore/onion.c +540 -0
- data/ProjectTox-Core/toxcore/onion.h +150 -0
- data/ProjectTox-Core/toxcore/onion_announce.c +433 -0
- data/ProjectTox-Core/toxcore/onion_announce.h +139 -0
- data/ProjectTox-Core/toxcore/onion_client.c +1347 -0
- data/ProjectTox-Core/toxcore/onion_client.h +253 -0
- data/ProjectTox-Core/toxcore/ping.c +346 -0
- data/ProjectTox-Core/toxcore/ping.h +47 -0
- data/ProjectTox-Core/toxcore/ping_array.c +162 -0
- data/ProjectTox-Core/toxcore/ping_array.h +75 -0
- data/ProjectTox-Core/toxcore/tox.c +940 -0
- data/ProjectTox-Core/toxcore/tox.h +734 -0
- data/ProjectTox-Core/toxcore/util.c +193 -0
- data/ProjectTox-Core/toxcore/util.h +63 -0
- data/ProjectTox-Core/toxdns/Makefile.inc +29 -0
- data/ProjectTox-Core/toxdns/toxdns.c +238 -0
- data/ProjectTox-Core/toxdns/toxdns.h +88 -0
- data/ProjectTox-Core/toxencryptsave/Makefile.inc +45 -0
- data/ProjectTox-Core/toxencryptsave/toxencryptsave.c +179 -0
- data/ProjectTox-Core/toxencryptsave/toxencryptsave.h +74 -0
- data/interfaces/libtox.i +2 -6
- data/lib/ffi-tox/libtox.rb +406 -28
- metadata +124 -46
- data/ProjectTox-Core/CMakeLists.txt +0 -50
- data/ProjectTox-Core/cmake/FindLIBCONFIG.cmake +0 -15
- data/ProjectTox-Core/cmake/FindNaCl.cmake +0 -17
- data/ProjectTox-Core/cmake/FindSODIUM.cmake +0 -15
- data/ProjectTox-Core/core/CMakeLists.txt +0 -19
- data/ProjectTox-Core/core/DHT.c +0 -1104
- data/ProjectTox-Core/core/DHT.h +0 -111
- data/ProjectTox-Core/core/LAN_discovery.c +0 -79
- data/ProjectTox-Core/core/Lossless_UDP.c +0 -755
- data/ProjectTox-Core/core/Lossless_UDP.h +0 -106
- data/ProjectTox-Core/core/Messenger.c +0 -596
- data/ProjectTox-Core/core/Messenger.h +0 -165
- data/ProjectTox-Core/core/friend_requests.c +0 -131
- data/ProjectTox-Core/core/friend_requests.h +0 -51
- data/ProjectTox-Core/core/net_crypto.c +0 -575
- data/ProjectTox-Core/core/net_crypto.h +0 -134
- data/ProjectTox-Core/core/network.c +0 -205
- data/ProjectTox-Core/core/network.h +0 -134
- data/ProjectTox-Core/docs/commands.md +0 -25
- data/ProjectTox-Core/docs/start_guide.de.md +0 -40
- data/ProjectTox-Core/docs/start_guide.md +0 -38
- data/ProjectTox-Core/other/CMakeLists.txt +0 -9
- data/ProjectTox-Core/testing/CMakeLists.txt +0 -18
- data/ProjectTox-Core/testing/DHT_cryptosendfiletest.c +0 -228
- data/ProjectTox-Core/testing/DHT_sendfiletest.c +0 -176
- data/ProjectTox-Core/testing/Lossless_UDP_testclient.c +0 -214
- data/ProjectTox-Core/testing/Lossless_UDP_testserver.c +0 -201
- data/ProjectTox-Core/testing/misc_tools.h +0 -29
- data/ProjectTox-Core/testing/nTox_win32.c +0 -387
- data/ProjectTox-Core/testing/nTox_win32.h +0 -40
- data/ProjectTox-Core/testing/rect.py +0 -45
@@ -1,12 +1,7 @@
|
|
1
|
+
|
1
2
|
/* DHT boostrap
|
2
3
|
*
|
3
|
-
* A simple DHT boostrap
|
4
|
-
*
|
5
|
-
* Build commands (use one or the other):
|
6
|
-
* gcc -O2 -Wall -D VANILLA_NACL -o bootstrap_server ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../core/friend_requests.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} DHT_bootstrap.c
|
7
|
-
*
|
8
|
-
* gcc -O2 -Wall -o bootstrap_server ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../core/friend_requests.c -lsodium DHT_bootstrap.c
|
9
|
-
*
|
4
|
+
* A simple DHT boostrap node for tox.
|
10
5
|
*
|
11
6
|
* Copyright (C) 2013 Tox project All Rights Reserved.
|
12
7
|
*
|
@@ -24,15 +19,35 @@
|
|
24
19
|
*
|
25
20
|
* You should have received a copy of the GNU General Public License
|
26
21
|
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
27
|
-
*
|
22
|
+
*
|
28
23
|
*/
|
29
24
|
|
30
|
-
#
|
31
|
-
#include "
|
32
|
-
#
|
25
|
+
#ifdef HAVE_CONFIG_H
|
26
|
+
#include "config.h"
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#include "../toxcore/DHT.h"
|
30
|
+
#include "../toxcore/LAN_discovery.h"
|
31
|
+
#include "../toxcore/friend_requests.h"
|
32
|
+
#include "../toxcore/util.h"
|
33
|
+
|
34
|
+
#define TCP_RELAY_ENABLED
|
35
|
+
|
36
|
+
#ifdef TCP_RELAY_ENABLED
|
37
|
+
#include "../toxcore/TCP_server.h"
|
38
|
+
#endif
|
39
|
+
|
40
|
+
#include "../testing/misc_tools.c"
|
41
|
+
|
42
|
+
#ifdef DHT_NODE_EXTRA_PACKETS
|
43
|
+
#include "./bootstrap_node_packets.c"
|
44
|
+
|
45
|
+
#define DHT_VERSION_NUMBER 1
|
46
|
+
#define DHT_MOTD "This is a test motd"
|
47
|
+
#endif
|
33
48
|
|
34
|
-
|
35
|
-
#
|
49
|
+
/* Sleep function (x = milliseconds) */
|
50
|
+
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
|
36
51
|
#define c_sleep(x) Sleep(1*x)
|
37
52
|
#else
|
38
53
|
#include <unistd.h>
|
@@ -43,32 +58,37 @@
|
|
43
58
|
#define PORT 33445
|
44
59
|
|
45
60
|
|
46
|
-
|
47
|
-
void manage_keys()
|
61
|
+
void manage_keys(DHT *dht)
|
48
62
|
{
|
49
63
|
const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
|
50
64
|
uint8_t keys[KEYS_SIZE];
|
51
65
|
|
52
66
|
FILE *keys_file = fopen("key", "r");
|
67
|
+
|
53
68
|
if (keys_file != NULL) {
|
54
|
-
|
69
|
+
/* If file was opened successfully -- load keys,
|
70
|
+
otherwise save new keys */
|
55
71
|
size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
|
72
|
+
|
56
73
|
if (read_size != KEYS_SIZE) {
|
57
74
|
printf("Error while reading the key file\nExiting.\n");
|
58
75
|
exit(1);
|
59
76
|
}
|
60
|
-
|
61
|
-
|
77
|
+
|
78
|
+
memcpy(dht->self_public_key, keys, crypto_box_PUBLICKEYBYTES);
|
79
|
+
memcpy(dht->self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES);
|
80
|
+
printf("Keys loaded successfully.\n");
|
62
81
|
} else {
|
63
|
-
|
64
|
-
|
65
|
-
save_keys(keys);
|
82
|
+
memcpy(keys, dht->self_public_key, crypto_box_PUBLICKEYBYTES);
|
83
|
+
memcpy(keys + crypto_box_PUBLICKEYBYTES, dht->self_secret_key, crypto_box_SECRETKEYBYTES);
|
66
84
|
keys_file = fopen("key", "w");
|
85
|
+
|
67
86
|
if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
|
68
87
|
printf("Error while writing the key file.\nExiting.\n");
|
69
88
|
exit(1);
|
70
89
|
}
|
71
|
-
|
90
|
+
|
91
|
+
printf("Keys saved successfully.\n");
|
72
92
|
}
|
73
93
|
|
74
94
|
fclose(keys_file);
|
@@ -76,64 +96,107 @@ void manage_keys()
|
|
76
96
|
|
77
97
|
int main(int argc, char *argv[])
|
78
98
|
{
|
79
|
-
|
99
|
+
if (argc == 2 && !strncasecmp(argv[1], "-h", 3)) {
|
100
|
+
printf("Usage (connected) : %s [--ipv4|--ipv6] IP PORT KEY\n", argv[0]);
|
101
|
+
printf("Usage (unconnected): %s [--ipv4|--ipv6]\n", argv[0]);
|
102
|
+
exit(0);
|
103
|
+
}
|
104
|
+
|
105
|
+
/* let user override default by cmdline */
|
106
|
+
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
107
|
+
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
108
|
+
|
109
|
+
if (argvoffset < 0)
|
110
|
+
exit(1);
|
111
|
+
|
112
|
+
/* Initialize networking -
|
113
|
+
Bind to ip 0.0.0.0 / [::] : PORT */
|
114
|
+
IP ip;
|
115
|
+
ip_init(&ip, ipv6enabled);
|
116
|
+
|
117
|
+
DHT *dht = new_DHT(new_networking(ip, PORT));
|
118
|
+
Onion *onion = new_onion(dht);
|
119
|
+
Onion_Announce *onion_a = new_onion_announce(dht);
|
120
|
+
|
121
|
+
#ifdef DHT_NODE_EXTRA_PACKETS
|
122
|
+
bootstrap_set_callbacks(dht->net, DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD));
|
123
|
+
#endif
|
124
|
+
|
125
|
+
if (!(onion && onion_a)) {
|
126
|
+
printf("Something failed to initialize.\n");
|
127
|
+
exit(1);
|
128
|
+
}
|
129
|
+
|
130
|
+
perror("Initialization");
|
131
|
+
|
132
|
+
manage_keys(dht);
|
80
133
|
printf("Public key: ");
|
81
134
|
uint32_t i;
|
82
135
|
|
136
|
+
#ifdef TCP_RELAY_ENABLED
|
137
|
+
#define NUM_PORTS 3
|
138
|
+
uint16_t ports[NUM_PORTS] = {443, 3389, PORT};
|
139
|
+
TCP_Server *tcp_s = new_TCP_server(ipv6enabled, NUM_PORTS, ports, dht->self_public_key, dht->self_secret_key, onion);
|
140
|
+
|
141
|
+
if (tcp_s == NULL) {
|
142
|
+
printf("TCP server failed to initialize.\n");
|
143
|
+
exit(1);
|
144
|
+
}
|
145
|
+
|
146
|
+
#endif
|
147
|
+
|
83
148
|
FILE *file;
|
84
149
|
file = fopen("PUBLIC_ID.txt", "w");
|
85
150
|
|
86
|
-
for(i = 0; i < 32; i++)
|
87
|
-
|
88
|
-
|
89
|
-
printf("0");
|
90
|
-
printf("%hhX",self_public_key[i]);
|
91
|
-
fprintf(file, "%hhX",self_public_key[i]);
|
151
|
+
for (i = 0; i < 32; i++) {
|
152
|
+
printf("%02hhX", dht->self_public_key[i]);
|
153
|
+
fprintf(file, "%02hhX", dht->self_public_key[i]);
|
92
154
|
}
|
93
155
|
|
94
156
|
fclose(file);
|
95
157
|
|
96
158
|
printf("\n");
|
97
|
-
printf("Port: %u\n",
|
98
|
-
//initialize networking
|
99
|
-
//bind to ip 0.0.0.0:PORT
|
100
|
-
IP ip;
|
101
|
-
ip.i = 0;
|
102
|
-
init_networking(ip, PORT);
|
159
|
+
printf("Port: %u\n", ntohs(dht->net->port));
|
103
160
|
|
104
|
-
|
105
|
-
|
106
|
-
if (argc > 3) {
|
161
|
+
if (argc > argvoffset + 3) {
|
107
162
|
printf("Trying to bootstrap into the network...\n");
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
DHT_bootstrap(bootstrap_info, bootstrap_key);
|
163
|
+
uint16_t port = htons(atoi(argv[argvoffset + 2]));
|
164
|
+
uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
|
165
|
+
int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1],
|
166
|
+
ipv6enabled, port, bootstrap_key);
|
113
167
|
free(bootstrap_key);
|
114
|
-
}
|
115
168
|
|
116
|
-
|
117
|
-
|
118
|
-
|
169
|
+
if (!res) {
|
170
|
+
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
171
|
+
exit(1);
|
172
|
+
}
|
173
|
+
}
|
119
174
|
|
120
175
|
int is_waiting_for_dht_connection = 1;
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
176
|
+
|
177
|
+
uint64_t last_LANdiscovery = 0;
|
178
|
+
LANdiscovery_init(dht);
|
179
|
+
|
180
|
+
while (1) {
|
181
|
+
if (is_waiting_for_dht_connection && DHT_isconnected(dht)) {
|
182
|
+
printf("Connected to other bootstrap node successfully.\n");
|
126
183
|
is_waiting_for_dht_connection = 0;
|
127
184
|
}
|
128
|
-
doDHT();
|
129
185
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
186
|
+
do_DHT(dht);
|
187
|
+
|
188
|
+
if (is_timeout(last_LANdiscovery, is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL)) {
|
189
|
+
send_LANdiscovery(htons(PORT), dht);
|
190
|
+
last_LANdiscovery = unix_time();
|
134
191
|
}
|
192
|
+
|
193
|
+
#ifdef TCP_RELAY_ENABLED
|
194
|
+
do_TCP_server(tcp_s);
|
195
|
+
#endif
|
196
|
+
networking_poll(dht->net);
|
197
|
+
|
135
198
|
c_sleep(1);
|
136
199
|
}
|
137
|
-
|
200
|
+
|
138
201
|
return 0;
|
139
202
|
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
bin_PROGRAMS += DHT_bootstrap
|
2
|
+
|
3
|
+
DHT_bootstrap_SOURCES = ../other/DHT_bootstrap.c \
|
4
|
+
../toxcore/DHT.h \
|
5
|
+
../toxcore/friend_requests.h
|
6
|
+
|
7
|
+
DHT_bootstrap_CFLAGS = -I$(top_srcdir)/other \
|
8
|
+
$(LIBSODIUM_CFLAGS) \
|
9
|
+
$(NACL_CFLAGS)
|
10
|
+
|
11
|
+
DHT_bootstrap_LDADD = $(LIBSODIUM_LDFLAGS) \
|
12
|
+
$(NACL_LDFLAGS) \
|
13
|
+
libtoxcore.la \
|
14
|
+
$(LIBSODIUM_LIBS) \
|
15
|
+
$(NACL_OBJECTS) \
|
16
|
+
$(NACL_LIBS) \
|
17
|
+
$(WINSOCK2_LIBS)
|
18
|
+
|
19
|
+
EXTRA_DIST += $(top_srcdir)/other/DHTnodes \
|
20
|
+
$(top_srcdir)/other/tox.png
|
@@ -0,0 +1,65 @@
|
|
1
|
+
/* bootstrap_node_packets.c
|
2
|
+
*
|
3
|
+
* Special bootstrap node only packets.
|
4
|
+
*
|
5
|
+
* Include it in your bootstrap node and use: bootstrap_set_callbacks() to enable.
|
6
|
+
*
|
7
|
+
* Copyright (C) 2013 Tox project All Rights Reserved.
|
8
|
+
*
|
9
|
+
* This file is part of Tox.
|
10
|
+
*
|
11
|
+
* Tox is free software: you can redistribute it and/or modify
|
12
|
+
* it under the terms of the GNU General Public License as published by
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
14
|
+
* (at your option) any later version.
|
15
|
+
*
|
16
|
+
* Tox is distributed in the hope that it will be useful,
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
* GNU General Public License for more details.
|
20
|
+
*
|
21
|
+
* You should have received a copy of the GNU General Public License
|
22
|
+
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
*
|
24
|
+
*/
|
25
|
+
|
26
|
+
#define MAX_MOTD_LENGTH 256 /* I recommend you use a maximum of 96 bytes. The hard maximum is this though. */
|
27
|
+
|
28
|
+
#define INFO_REQUEST_PACKET_LENGTH 78
|
29
|
+
|
30
|
+
static uint32_t bootstrap_version;
|
31
|
+
static uint8_t bootstrap_motd[MAX_MOTD_LENGTH];
|
32
|
+
static uint16_t bootstrap_motd_length;
|
33
|
+
|
34
|
+
/* To request this packet just send a packet of length INFO_REQUEST_PACKET_LENGTH
|
35
|
+
* with the first byte being BOOTSTRAP_INFO_PACKET_ID
|
36
|
+
*/
|
37
|
+
static int handle_info_request(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
|
38
|
+
{
|
39
|
+
if (length != INFO_REQUEST_PACKET_LENGTH)
|
40
|
+
return 1;
|
41
|
+
|
42
|
+
uint8_t data[1 + sizeof(bootstrap_version) + MAX_MOTD_LENGTH];
|
43
|
+
data[0] = BOOTSTRAP_INFO_PACKET_ID;
|
44
|
+
memcpy(data + 1, &bootstrap_version, sizeof(bootstrap_version));
|
45
|
+
uint16_t len = 1 + sizeof(bootstrap_version) + bootstrap_motd_length;
|
46
|
+
memcpy(data + 1 + sizeof(bootstrap_version), bootstrap_motd, bootstrap_motd_length);
|
47
|
+
|
48
|
+
if (sendpacket(object, source, data, len) == len)
|
49
|
+
return 0;
|
50
|
+
|
51
|
+
return 1;
|
52
|
+
}
|
53
|
+
|
54
|
+
int bootstrap_set_callbacks(Networking_Core *net, uint32_t version, uint8_t *motd, uint16_t motd_length)
|
55
|
+
{
|
56
|
+
if (motd_length > MAX_MOTD_LENGTH)
|
57
|
+
return -1;
|
58
|
+
|
59
|
+
bootstrap_version = htonl(version);
|
60
|
+
memcpy(bootstrap_motd, motd, motd_length);
|
61
|
+
bootstrap_motd_length = motd_length;
|
62
|
+
|
63
|
+
networking_registerhandler(net, BOOTSTRAP_INFO_PACKET_ID, &handle_info_request, net);
|
64
|
+
return 0;
|
65
|
+
}
|
Binary file
|
@@ -1,11 +1,11 @@
|
|
1
1
|
/* DHT test
|
2
2
|
* A file with a main that runs our DHT for testing.
|
3
|
-
*
|
3
|
+
*
|
4
4
|
* Compile with: gcc -O2 -Wall -D VANILLA_NACL -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} DHT_test.c
|
5
|
-
*
|
5
|
+
*
|
6
6
|
* Command line arguments are the ip, port and public key of a node.
|
7
7
|
* EX: ./test 127.0.0.1 33445 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
8
|
-
*
|
8
|
+
*
|
9
9
|
* The test will then ask you for the id (in hex format) of the friend you wish to add
|
10
10
|
*
|
11
11
|
* Copyright (C) 2013 Tox project All Rights Reserved.
|
@@ -24,18 +24,22 @@
|
|
24
24
|
*
|
25
25
|
* You should have received a copy of the GNU General Public License
|
26
26
|
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
27
|
-
*
|
27
|
+
*
|
28
28
|
*/
|
29
|
-
|
29
|
+
|
30
|
+
#ifdef HAVE_CONFIG_H
|
31
|
+
#include "config.h"
|
32
|
+
#endif
|
33
|
+
|
30
34
|
//#include "../core/network.h"
|
31
|
-
#include "../
|
32
|
-
#include "../
|
33
|
-
#include "misc_tools.
|
35
|
+
#include "../toxcore/DHT.h"
|
36
|
+
#include "../toxcore/friend_requests.h"
|
37
|
+
#include "misc_tools.c"
|
34
38
|
|
35
39
|
#include <string.h>
|
36
40
|
|
37
41
|
//Sleep function (x = milliseconds)
|
38
|
-
#
|
42
|
+
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
|
39
43
|
|
40
44
|
#define c_sleep(x) Sleep(1*x)
|
41
45
|
|
@@ -48,135 +52,203 @@
|
|
48
52
|
|
49
53
|
#define PORT 33445
|
50
54
|
|
51
|
-
|
55
|
+
uint8_t zeroes_cid[CLIENT_ID_SIZE];
|
56
|
+
|
57
|
+
void print_client_id(uint8_t *client_id)
|
52
58
|
{
|
53
|
-
uint32_t
|
54
|
-
|
59
|
+
uint32_t j;
|
60
|
+
|
61
|
+
for (j = 0; j < CLIENT_ID_SIZE; j++) {
|
62
|
+
printf("%02hhX", client_id[j]);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
void print_hardening(Hardening *h)
|
67
|
+
{
|
68
|
+
printf("Hardening:\n");
|
69
|
+
printf("routes_requests_ok: %hhu\n", h->routes_requests_ok);
|
70
|
+
printf("routes_requests_timestamp: %llu\n", (long long unsigned int)h->routes_requests_timestamp);
|
71
|
+
printf("routes_requests_pingedid: ");
|
72
|
+
print_client_id(h->routes_requests_pingedid);
|
73
|
+
printf("\nsend_nodes_ok: %hhu\n", h->send_nodes_ok);
|
74
|
+
printf("send_nodes_timestamp: %llu\n", (long long unsigned int)h->send_nodes_timestamp);
|
75
|
+
printf("send_nodes_pingedid: ");
|
76
|
+
print_client_id(h->send_nodes_pingedid);
|
77
|
+
printf("\ntesting_requests: %hhu\n", h->testing_requests);
|
78
|
+
printf("testing_timestamp: %llu\n", (long long unsigned int)h->testing_timestamp);
|
79
|
+
printf("testing_pingedid: ");
|
80
|
+
print_client_id(h->testing_pingedid);
|
81
|
+
printf("\n\n");
|
82
|
+
}
|
83
|
+
|
84
|
+
void print_assoc(IPPTsPng *assoc, uint8_t ours)
|
85
|
+
{
|
86
|
+
IP_Port *ipp = &assoc->ip_port;
|
87
|
+
printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip), ntohs(ipp->port));
|
88
|
+
printf("\nTimestamp: %llu", (long long unsigned int) assoc->timestamp);
|
89
|
+
printf("\nLast pinged: %llu\n", (long long unsigned int) assoc->last_pinged);
|
90
|
+
|
91
|
+
ipp = &assoc->ret_ip_port;
|
92
|
+
|
93
|
+
if (ours)
|
94
|
+
printf("OUR IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port));
|
95
|
+
else
|
96
|
+
printf("RET IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port));
|
97
|
+
|
98
|
+
printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp);
|
99
|
+
print_hardening(&assoc->hardening);
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
void print_clientlist(DHT *dht)
|
104
|
+
{
|
105
|
+
uint32_t i;
|
55
106
|
printf("___________________CLOSE________________________________\n");
|
56
|
-
|
107
|
+
|
108
|
+
for (i = 0; i < LCLIENT_LIST; i++) {
|
109
|
+
Client_data *client = &dht->close_clientlist[i];
|
110
|
+
|
111
|
+
if (memcmp(client->client_id, zeroes_cid, CLIENT_ID_SIZE) == 0)
|
112
|
+
continue;
|
113
|
+
|
57
114
|
printf("ClientID: ");
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
printf("\nTimestamp: %u", close_clientlist[i].timestamp);
|
64
|
-
printf("\nLast pinged: %u\n", close_clientlist[i].last_pinged);
|
65
|
-
p_ip = close_clientlist[i].ret_ip_port;
|
66
|
-
printf("OUR IP: %u.%u.%u.%u Port: %u\n",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port));
|
67
|
-
printf("Timestamp: %u\n", close_clientlist[i].ret_timestamp);
|
68
|
-
}
|
115
|
+
print_client_id(client->client_id);
|
116
|
+
|
117
|
+
print_assoc(&client->assoc4, 1);
|
118
|
+
print_assoc(&client->assoc6, 1);
|
119
|
+
}
|
69
120
|
}
|
70
121
|
|
71
|
-
void print_friendlist()
|
122
|
+
void print_friendlist(DHT *dht)
|
72
123
|
{
|
73
|
-
uint32_t i,
|
124
|
+
uint32_t i, k;
|
74
125
|
IP_Port p_ip;
|
75
126
|
printf("_________________FRIENDS__________________________________\n");
|
76
|
-
|
127
|
+
|
128
|
+
for (k = 0; k < dht->num_friends; k++) {
|
77
129
|
printf("FRIEND %u\n", k);
|
78
130
|
printf("ID: ");
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
printf("\nIP: %
|
131
|
+
|
132
|
+
print_client_id(dht->friends_list[k].client_id);
|
133
|
+
|
134
|
+
int friendok = DHT_getfriendip(dht, dht->friends_list[k].client_id, &p_ip);
|
135
|
+
printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip), ntohs(p_ip.port), friendok);
|
84
136
|
|
85
137
|
printf("\nCLIENTS IN LIST:\n\n");
|
86
|
-
|
87
|
-
for(i = 0; i <
|
138
|
+
|
139
|
+
for (i = 0; i < MAX_FRIEND_CLIENTS; i++) {
|
140
|
+
Client_data *client = &dht->friends_list[k].client_list[i];
|
141
|
+
|
142
|
+
if (memcmp(client->client_id, zeroes_cid, CLIENT_ID_SIZE) == 0)
|
143
|
+
continue;
|
144
|
+
|
88
145
|
printf("ClientID: ");
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|
94
|
-
p_ip = friends_list[k].client_list[i].ip_port;
|
95
|
-
printf("\nIP: %u.%u.%u.%u:%u",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port));
|
96
|
-
printf("\nTimestamp: %u", friends_list[k].client_list[i].timestamp);
|
97
|
-
printf("\nLast pinged: %u\n", friends_list[k].client_list[i].last_pinged);
|
98
|
-
p_ip = friends_list[k].client_list[i].ret_ip_port;
|
99
|
-
printf("ret IP: %u.%u.%u.%u:%u\n",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port));
|
100
|
-
printf("Timestamp: %u\n", friends_list[k].client_list[i].ret_timestamp);
|
146
|
+
print_client_id(client->client_id);
|
147
|
+
|
148
|
+
print_assoc(&client->assoc4, 0);
|
149
|
+
print_assoc(&client->assoc6, 0);
|
101
150
|
}
|
102
151
|
}
|
103
152
|
}
|
104
153
|
|
105
|
-
void printpacket(uint8_t *
|
154
|
+
void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port)
|
106
155
|
{
|
107
156
|
uint32_t i;
|
108
157
|
printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length);
|
109
158
|
printf("--------------------BEGIN-----------------------------\n");
|
110
|
-
|
111
|
-
|
159
|
+
|
160
|
+
for (i = 0; i < length; i++) {
|
161
|
+
if (data[i] < 16)
|
112
162
|
printf("0");
|
113
|
-
|
163
|
+
|
164
|
+
printf("%hhX", data[i]);
|
114
165
|
}
|
166
|
+
|
115
167
|
printf("\n--------------------END-----------------------------\n\n\n");
|
116
168
|
}
|
117
169
|
|
118
170
|
int main(int argc, char *argv[])
|
119
171
|
{
|
120
|
-
//memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32);
|
121
|
-
|
122
172
|
if (argc < 4) {
|
123
|
-
printf("
|
173
|
+
printf("Usage: %s [--ipv4|--ipv6] ip port public_key\n", argv[0]);
|
124
174
|
exit(0);
|
125
175
|
}
|
126
|
-
|
176
|
+
|
177
|
+
/* let user override default by cmdline */
|
178
|
+
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
179
|
+
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
180
|
+
|
181
|
+
if (argvoffset < 0)
|
182
|
+
exit(1);
|
183
|
+
|
184
|
+
//memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32);
|
185
|
+
/* initialize networking */
|
186
|
+
/* bind to ip 0.0.0.0:PORT */
|
187
|
+
IP ip;
|
188
|
+
ip_init(&ip, ipv6enabled);
|
189
|
+
|
190
|
+
DHT *dht = new_DHT(new_networking(ip, PORT));
|
127
191
|
printf("OUR ID: ");
|
128
192
|
uint32_t i;
|
129
|
-
|
130
|
-
|
193
|
+
|
194
|
+
for (i = 0; i < 32; i++) {
|
195
|
+
if (dht->self_public_key[i] < 16)
|
131
196
|
printf("0");
|
132
|
-
|
197
|
+
|
198
|
+
printf("%hhX", dht->self_public_key[i]);
|
133
199
|
}
|
134
|
-
|
200
|
+
|
135
201
|
char temp_id[128];
|
136
202
|
printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n");
|
137
|
-
|
203
|
+
|
204
|
+
if (!fgets(temp_id, sizeof(temp_id), stdin))
|
138
205
|
exit(0);
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
init_networking(ip, PORT);
|
147
|
-
|
206
|
+
|
207
|
+
if ((strlen(temp_id) > 0) && (temp_id[strlen(temp_id) - 1] == '\n'))
|
208
|
+
temp_id[strlen(temp_id) - 1] = '\0';
|
209
|
+
|
210
|
+
uint8_t *bin_id = hex_string_to_bin(temp_id);
|
211
|
+
DHT_addfriend(dht, bin_id);
|
212
|
+
free(bin_id);
|
148
213
|
|
149
214
|
perror("Initialization");
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
215
|
+
|
216
|
+
uint16_t port = htons(atoi(argv[argvoffset + 2]));
|
217
|
+
unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
|
218
|
+
int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string);
|
219
|
+
free(binary_string);
|
220
|
+
|
221
|
+
if (!res) {
|
222
|
+
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
223
|
+
return 1;
|
224
|
+
}
|
225
|
+
|
226
|
+
/*
|
227
|
+
IP_Port ip_port;
|
228
|
+
uint8_t data[MAX_UDP_PACKET_SIZE];
|
229
|
+
uint32_t length;
|
230
|
+
*/
|
231
|
+
|
232
|
+
while (1) {
|
233
|
+
|
234
|
+
do_DHT(dht);
|
235
|
+
|
236
|
+
/* slvrTODO:
|
237
|
+
while(receivepacket(&ip_port, data, &length) != -1) {
|
238
|
+
if(DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) {
|
239
|
+
//unhandled packet
|
240
|
+
printpacket(data, length, ip_port);
|
241
|
+
} else {
|
242
|
+
printf("Received handled packet with length: %u\n", length);
|
243
|
+
}
|
244
|
+
}
|
245
|
+
*/
|
246
|
+
networking_poll(dht->net);
|
247
|
+
|
248
|
+
print_clientlist(dht);
|
249
|
+
print_friendlist(dht);
|
177
250
|
c_sleep(300);
|
178
251
|
}
|
179
|
-
|
180
|
-
|
181
|
-
return 0;
|
252
|
+
|
253
|
+
return 0;
|
182
254
|
}
|