summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoren[m] <Break@Ocean>2013-10-24 22:47:23 +0200
committerCoren[m] <Break@Ocean>2013-10-24 22:47:23 +0200
commit065495cd7c269389af7f834e568d12105589dd97 (patch)
treec38eb6cfd8117b9a721b5d41144502736ed18bac
parent0a4c3d7e2e080dafd66d25f7a5806b89f7be1bcf (diff)
parentf3be5609049d278ee3f46754ea4b0eb929876dba (diff)
Merge remote-tracking branch 'upstream/master' into cleanup_unix_time_id_eq_cpy_is_timeout
Conflicts: toxcore/net_crypto.c
-rw-r--r--.gitignore27
-rw-r--r--README.md4
-rw-r--r--auto_tests/messenger_test.c18
-rw-r--r--testing/Messenger_test.c16
-rw-r--r--toxcore/Lossless_UDP.c14
-rw-r--r--toxcore/Lossless_UDP.h10
-rw-r--r--toxcore/Messenger.c36
-rw-r--r--toxcore/Messenger.h18
-rw-r--r--toxcore/net_crypto.c64
-rw-r--r--toxcore/net_crypto.h10
-rw-r--r--toxcore/ping.c18
-rw-r--r--toxcore/ping.h17
-rw-r--r--toxcore/tox.c18
-rw-r--r--toxcore/util.c17
-rw-r--r--toxcore/util.h17
15 files changed, 183 insertions, 121 deletions
diff --git a/.gitignore b/.gitignore
index aa7d8f50..e903e3ca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,31 +3,28 @@
3.DS_Store? 3.DS_Store?
4._* 4._*
5.Spotlight-V100 5.Spotlight-V100
6.Trashes 6.Trash*
7Icon?
7ethumbs.db 8ethumbs.db
8Thumbs.db 9Thumbs.db
10*.tmp
9 11
10//nacl build 12# Make
11nacl/build/
12build/
13!build/Makefile.am
14sodium
15
16CMakeCache.txt 13CMakeCache.txt
17CMakeFiles 14CMakeFiles
18Makefile 15Makefile
19cmake_install.cmake 16cmake_install.cmake
20install_manifest.txt 17install_manifest.txt
18tags
19Makefile.in
21 20
21# Testing
22testing/data 22testing/data
23*~ 23*~
24 24
25# Vim 25# Vim
26*.swp 26*.swp
27 27
28# Ctags
29tags
30
31# Object files 28# Object files
32*.o 29*.o
33*.lo 30*.lo
@@ -37,14 +34,13 @@ tags
37*.exe 34*.exe
38*.out 35*.out
39*.app 36*.app
40*.swp
41*.la 37*.la
42 38
39# Misc (?)
43m4/* 40m4/*
44!m4/pkg.m4
45configure 41configure
46configure_aux 42configure_aux
47Makefile.in 43!m4/pkg.m4
48aclocal.m4 44aclocal.m4
49config.h* 45config.h*
50config.log 46config.log
@@ -53,13 +49,12 @@ stamp-h1
53autom4te.cache 49autom4te.cache
54libtoxcore.pc 50libtoxcore.pc
55libtool 51libtool
56
57.deps 52.deps
58.libs 53.libs
59.dirstamp 54.dirstamp
60 55
61#netbeans 56# Netbeans
62nbproject 57nbproject
63 58
64#astyle 59# astyle
65*.orig 60*.orig
diff --git a/README.md b/README.md
index 39fc259e..e794b7fb 100644
--- a/README.md
+++ b/README.md
@@ -12,9 +12,7 @@ With the rise of governmental monitoring programs, Tox aims to be an easy to use
12**Website translations**: [here](https://github.com/Tox/tox.im)<br/> 12**Website translations**: [here](https://github.com/Tox/tox.im)<br/>
13**Qt GUI**: [see nurupo's repository](https://github.com/nurupo/ProjectTox-Qt-GUI) 13**Qt GUI**: [see nurupo's repository](https://github.com/nurupo/ProjectTox-Qt-GUI)
14 14
15**How to build Tox on Linux**: [YouTube video](http://www.youtube.com/watch?v=M4WXE4VKmyg)<br /> 15**How to build Tox** [INSTALL.md](INSTALL.md)
16**How to use Tox on Windows**: [YouTube video](http://www.youtube.com/watch?v=qg_j_sDb6WQ)<br />
17**For Mac OSX read** [INSTALL.md](INSTALL.md)
18 16
19### Objectives: 17### Objectives:
20 18
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c
index 605fa4f3..52c49650 100644
--- a/auto_tests/messenger_test.c
+++ b/auto_tests/messenger_test.c
@@ -276,18 +276,18 @@ START_TEST(test_messenger_state_saveloadsave)
276 * c) a second save() is of equal size 276 * c) a second save() is of equal size
277 * d) the second save() is of equal content */ 277 * d) the second save() is of equal content */
278 size_t i, extra = 64; 278 size_t i, extra = 64;
279 size_t size = Messenger_size(m); 279 size_t size = messenger_size(m);
280 uint8_t buffer[size + 2 * extra]; 280 uint8_t buffer[size + 2 * extra];
281 memset(buffer, 0xCD, extra); 281 memset(buffer, 0xCD, extra);
282 memset(buffer + extra + size, 0xCD, extra); 282 memset(buffer + extra + size, 0xCD, extra);
283 Messenger_save(m, buffer + extra); 283 messenger_save(m, buffer + extra);
284 284
285 for (i = 0; i < extra; i++) { 285 for (i = 0; i < extra; i++) {
286 ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from Messenger_save() @%u", i); 286 ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from messenger_save() @%u", i);
287 ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from Messenger_save() @%u", i); 287 ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from messenger_save() @%u", i);
288 } 288 }
289 289
290 int res = Messenger_load(m, buffer + extra, size); 290 int res = messenger_load(m, buffer + extra, size);
291 291
292 if (res == -1) 292 if (res == -1)
293 ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1"); 293 ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1");
@@ -300,11 +300,11 @@ START_TEST(test_messenger_state_saveloadsave)
300 ck_assert_msg(res == 0, msg); 300 ck_assert_msg(res == 0, msg);
301 } 301 }
302 302
303 size_t size2 = Messenger_size(m); 303 size_t size2 = messenger_size(m);
304 ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2); 304 ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2);
305 305
306 uint8_t buffer2[size2]; 306 uint8_t buffer2[size2];
307 Messenger_save(m, buffer2); 307 messenger_save(m, buffer2);
308 308
309 ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "Messenger state changed by store/load/store cycle"); 309 ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "Messenger state changed by store/load/store cycle");
310} 310}
@@ -350,7 +350,7 @@ int main(int argc, char *argv[])
350 bad_id = hex_string_to_bin(bad_id_str); 350 bad_id = hex_string_to_bin(bad_id_str);
351 351
352 /* IPv6 status from global define */ 352 /* IPv6 status from global define */
353 m = initMessenger(TOX_ENABLE_IPV6_DEFAULT); 353 m = new_messenger(TOX_ENABLE_IPV6_DEFAULT);
354 354
355 /* setup a default friend and friendnum */ 355 /* setup a default friend and friendnum */
356 if (m_addfriend_norequest(m, (uint8_t *)friend_id) < 0) 356 if (m_addfriend_norequest(m, (uint8_t *)friend_id) < 0)
@@ -372,7 +372,7 @@ int main(int argc, char *argv[])
372 free(good_id_b); 372 free(good_id_b);
373 free(bad_id); 373 free(bad_id);
374 374
375 cleanupMessenger(m); 375 kill_messenger(m);
376 376
377 return number_failed; 377 return number_failed;
378} 378}
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index 619d94b1..82dbd43c 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -110,7 +110,7 @@ int main(int argc, char *argv[])
110 exit(0); 110 exit(0);
111 } 111 }
112 112
113 m = initMessenger(ipv6enabled); 113 m = new_messenger(ipv6enabled);
114 114
115 if ( !m ) { 115 if ( !m ) {
116 fputs("Failed to allocate messenger datastructure\n", stderr); 116 fputs("Failed to allocate messenger datastructure\n", stderr);
@@ -139,7 +139,7 @@ int main(int argc, char *argv[])
139 int read; 139 int read;
140 uint8_t buffer[128000]; 140 uint8_t buffer[128000];
141 read = fread(buffer, 1, 128000, file); 141 read = fread(buffer, 1, 128000, file);
142 printf("Messenger loaded: %i\n", Messenger_load(m, buffer, read)); 142 printf("Messenger loaded: %i\n", messenger_load(m, buffer, read));
143 fclose(file); 143 fclose(file);
144 144
145 } 145 }
@@ -178,7 +178,7 @@ int main(int argc, char *argv[])
178 printf("%s\n", name); 178 printf("%s\n", name);
179 179
180 m_sendmessage(m, num, (uint8_t *)"Test", 5); 180 m_sendmessage(m, num, (uint8_t *)"Test", 5);
181 doMessenger(m); 181 do_messenger(m);
182 c_sleep(30); 182 c_sleep(30);
183 FILE *file = fopen("Save.bak", "wb"); 183 FILE *file = fopen("Save.bak", "wb");
184 184
@@ -186,11 +186,11 @@ int main(int argc, char *argv[])
186 return 1; 186 return 1;
187 } 187 }
188 188
189 uint8_t *buffer = malloc(Messenger_size(m)); 189 uint8_t *buffer = malloc(messenger_size(m));
190 Messenger_save(m, buffer); 190 messenger_save(m, buffer);
191 size_t write_result = fwrite(buffer, 1, Messenger_size(m), file); 191 size_t write_result = fwrite(buffer, 1, messenger_size(m), file);
192 192
193 if (write_result < Messenger_size(m)) { 193 if (write_result < messenger_size(m)) {
194 return 1; 194 return 1;
195 } 195 }
196 196
@@ -198,5 +198,5 @@ int main(int argc, char *argv[])
198 fclose(file); 198 fclose(file);
199 } 199 }
200 200
201 cleanupMessenger(m); 201 kill_messenger(m);
202} 202}
diff --git a/toxcore/Lossless_UDP.c b/toxcore/Lossless_UDP.c
index 6d82b768..e291340d 100644
--- a/toxcore/Lossless_UDP.c
+++ b/toxcore/Lossless_UDP.c
@@ -198,8 +198,8 @@ int new_connection(Lossless_UDP *ludp, IP_Port ip_port)
198 memset(connection, 0, sizeof(Connection)); 198 memset(connection, 0, sizeof(Connection));
199 199
200 uint32_t handshake_id1 = handshake_id(ludp, ip_port); 200 uint32_t handshake_id1 = handshake_id(ludp, ip_port);
201 /* add randomness to timeout to prevent connections getting stuck in a loop. */ 201 /* Add randomness to timeout to prevent connections getting stuck in a loop. */
202 uint8_t timeout = CONNEXION_TIMEOUT + rand() % CONNEXION_TIMEOUT; 202 uint8_t timeout = CONNECTION_TIMEOUT + rand() % CONNECTION_TIMEOUT;
203 203
204 *connection = (Connection) { 204 *connection = (Connection) {
205 .ip_port = ip_port, 205 .ip_port = ip_port,
@@ -260,7 +260,7 @@ static int new_inconnection(Lossless_UDP *ludp, IP_Port ip_port)
260 Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection); 260 Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection);
261 memset(connection, 0, sizeof(Connection)); 261 memset(connection, 0, sizeof(Connection));
262 /* Add randomness to timeout to prevent connections getting stuck in a loop. */ 262 /* Add randomness to timeout to prevent connections getting stuck in a loop. */
263 uint8_t timeout = CONNEXION_TIMEOUT + rand() % CONNEXION_TIMEOUT; 263 uint8_t timeout = CONNECTION_TIMEOUT + rand() % CONNECTION_TIMEOUT;
264 264
265 *connection = (Connection) { 265 *connection = (Connection) {
266 .ip_port = ip_port, 266 .ip_port = ip_port,
@@ -403,7 +403,7 @@ int connection_confirmed(Lossless_UDP *ludp, int connection_id)
403} 403}
404 404
405/* Confirm an incoming connection. 405/* Confirm an incoming connection.
406 * Also disables the auto kill timeout on incomming connections. 406 * Also disable the auto kill timeout on incomming connections.
407 * 407 *
408 * return 0 on success 408 * return 0 on success
409 * return -1 on failure. 409 * return -1 on failure.
@@ -777,7 +777,7 @@ static int handle_handshake(void *object, IP_Port source, uint8_t *packet, uint3
777 /* if handshake_id2 is what we sent previously as handshake_id1 */ 777 /* if handshake_id2 is what we sent previously as handshake_id1 */
778 if (handshake_id2 == connection->handshake_id1) { 778 if (handshake_id2 == connection->handshake_id1) {
779 connection->status = LUDP_NOT_CONFIRMED; 779 connection->status = LUDP_NOT_CONFIRMED;
780 /* NOTE: is this necessary? 780 /* NOTE: Is this necessary?
781 connection->handshake_id2 = handshake_id1; */ 781 connection->handshake_id2 = handshake_id1; */
782 connection->orecv_packetnum = handshake_id2; 782 connection->orecv_packetnum = handshake_id2;
783 connection->osent_packetnum = handshake_id1; 783 connection->osent_packetnum = handshake_id1;
@@ -847,7 +847,7 @@ static int handle_SYNC2(Lossless_UDP *ludp, int connection_id, uint8_t counter,
847/* 847/*
848 * Automatically adjusts send rates of data packets for optimal transmission. 848 * Automatically adjusts send rates of data packets for optimal transmission.
849 * 849 *
850 * TODO: Impove this. 850 * TODO: Improve this.
851 */ 851 */
852static void adjust_datasendspeed(Connection *connection, uint32_t req_packets) 852static void adjust_datasendspeed(Connection *connection, uint32_t req_packets)
853{ 853{
@@ -1144,7 +1144,7 @@ static void adjust_rates(Lossless_UDP *ludp)
1144 } 1144 }
1145} 1145}
1146 1146
1147/* Call this function a couple times per second It's the main loop. */ 1147/* Call this function a couple times per second. It is the main loop. */
1148void do_lossless_udp(Lossless_UDP *ludp) 1148void do_lossless_udp(Lossless_UDP *ludp)
1149{ 1149{
1150 do_new(ludp); 1150 do_new(ludp);
diff --git a/toxcore/Lossless_UDP.h b/toxcore/Lossless_UDP.h
index d2f1986f..d4d6ec4e 100644
--- a/toxcore/Lossless_UDP.h
+++ b/toxcore/Lossless_UDP.h
@@ -38,10 +38,10 @@
38/* Maximum number of data packets in the buffer. */ 38/* Maximum number of data packets in the buffer. */
39#define MAX_REQUESTED_PACKETS 256 39#define MAX_REQUESTED_PACKETS 256
40 40
41/* Timeout per connection is randomly set between CONNEXION_TIMEOUT and 2*CONNEXION_TIMEOUT. */ 41/* Timeout per connection is randomly set between CONNECTION_TIMEOUT and 2*CONNECTION_TIMEOUT. */
42#define CONNEXION_TIMEOUT 5 42#define CONNECTION_TIMEOUT 5
43 43
44/* Initial amount of sync/hanshake packets to send per second. */ 44/* Initial amount of sync/handshake packets to send per second. */
45#define SYNC_RATE 2 45#define SYNC_RATE 2
46 46
47/* Initial send rate of data. */ 47/* Initial send rate of data. */
@@ -124,7 +124,7 @@ typedef struct {
124 uint8_t send_counter; 124 uint8_t send_counter;
125 uint8_t timeout; /* connection timeout in seconds. */ 125 uint8_t timeout; /* connection timeout in seconds. */
126 126
127 /* is the connection confirmed or not 1 if yes, 0 if no */ 127 /* Is the connection confirmed or not? 1 if yes, 0 if no */
128 uint8_t confirmed; 128 uint8_t confirmed;
129} Connection; 129} Connection;
130 130
@@ -249,7 +249,7 @@ uint32_t recvqueue(Lossless_UDP *ludp, int connection_id);
249 */ 249 */
250int is_connected(Lossless_UDP *ludp, int connection_id); 250int is_connected(Lossless_UDP *ludp, int connection_id);
251 251
252/* Call this function a couple times per second It's the main loop. */ 252/* Call this function a couple times per second. It is the main loop. */
253void do_lossless_udp(Lossless_UDP *ludp); 253void do_lossless_udp(Lossless_UDP *ludp);
254 254
255/* This function sets up LosslessUDP packet handling. */ 255/* This function sets up LosslessUDP packet handling. */
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 7710a33c..7da77541 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -714,7 +714,7 @@ IP_Port get_friend_ipport(Messenger *m, int friendnumber)
714 714
715 int crypt_id = m->friendlist[friendnumber].crypt_connection_id; 715 int crypt_id = m->friendlist[friendnumber].crypt_connection_id;
716 716
717 if (is_cryptoconnected(m->net_crypto, crypt_id) != 3) 717 if (is_cryptoconnected(m->net_crypto, crypt_id) != CRYPTO_CONN_ESTABLISHED)
718 return zero; 718 return zero;
719 719
720 return connection_ip(m->net_crypto->lossless_udp, m->net_crypto->crypto_connections[crypt_id].number); 720 return connection_ip(m->net_crypto->lossless_udp, m->net_crypto->crypto_connections[crypt_id].number);
@@ -1357,7 +1357,7 @@ static void LANdiscovery(Messenger *m)
1357} 1357}
1358 1358
1359/* Run this at startup. */ 1359/* Run this at startup. */
1360Messenger *initMessenger(uint8_t ipv6enabled) 1360Messenger *new_messenger(uint8_t ipv6enabled)
1361{ 1361{
1362 Messenger *m = calloc(1, sizeof(Messenger)); 1362 Messenger *m = calloc(1, sizeof(Messenger));
1363 1363
@@ -1402,7 +1402,7 @@ Messenger *initMessenger(uint8_t ipv6enabled)
1402} 1402}
1403 1403
1404/* Run this before closing shop. */ 1404/* Run this before closing shop. */
1405void cleanupMessenger(Messenger *m) 1405void kill_messenger(Messenger *m)
1406{ 1406{
1407 /* FIXME TODO: ideally cleanupMessenger will mirror initMessenger. 1407 /* FIXME TODO: ideally cleanupMessenger will mirror initMessenger.
1408 * This requires the other modules to expose cleanup functions. 1408 * This requires the other modules to expose cleanup functions.
@@ -1415,7 +1415,7 @@ void cleanupMessenger(Messenger *m)
1415} 1415}
1416 1416
1417/* TODO: Make this function not suck. */ 1417/* TODO: Make this function not suck. */
1418void doFriends(Messenger *m) 1418void do_friends(Messenger *m)
1419{ 1419{
1420 /* TODO: Add incoming connections and some other stuff. */ 1420 /* TODO: Add incoming connections and some other stuff. */
1421 uint32_t i; 1421 uint32_t i;
@@ -1454,13 +1454,13 @@ void doFriends(Messenger *m)
1454 int friendok = DHT_getfriendip(m->dht, m->friendlist[i].client_id, &friendip); 1454 int friendok = DHT_getfriendip(m->dht, m->friendlist[i].client_id, &friendip);
1455 1455
1456 switch (is_cryptoconnected(m->net_crypto, m->friendlist[i].crypt_connection_id)) { 1456 switch (is_cryptoconnected(m->net_crypto, m->friendlist[i].crypt_connection_id)) {
1457 case 0: 1457 case CRYPTO_CONN_NO_CONNECTION:
1458 if (friendok == 1) 1458 if (friendok == 1)
1459 m->friendlist[i].crypt_connection_id = crypto_connect(m->net_crypto, m->friendlist[i].client_id, friendip); 1459 m->friendlist[i].crypt_connection_id = crypto_connect(m->net_crypto, m->friendlist[i].client_id, friendip);
1460 1460
1461 break; 1461 break;
1462 1462
1463 case 3: /* Connection is established. */ 1463 case CRYPTO_CONN_ESTABLISHED: /* Connection is established. */
1464 set_friend_status(m, i, FRIEND_ONLINE); 1464 set_friend_status(m, i, FRIEND_ONLINE);
1465 m->friendlist[i].name_sent = 0; 1465 m->friendlist[i].name_sent = 0;
1466 m->friendlist[i].userstatus_sent = 0; 1466 m->friendlist[i].userstatus_sent = 0;
@@ -1468,7 +1468,7 @@ void doFriends(Messenger *m)
1468 m->friendlist[i].ping_lastrecv = temp_time; 1468 m->friendlist[i].ping_lastrecv = temp_time;
1469 break; 1469 break;
1470 1470
1471 case 4: 1471 case CRYPTO_CONN_TIMED_OUT:
1472 crypto_kill(m->net_crypto, m->friendlist[i].crypt_connection_id); 1472 crypto_kill(m->net_crypto, m->friendlist[i].crypt_connection_id);
1473 m->friendlist[i].crypt_connection_id = -1; 1473 m->friendlist[i].crypt_connection_id = -1;
1474 break; 1474 break;
@@ -1706,7 +1706,7 @@ void doFriends(Messenger *m)
1706 } 1706 }
1707 } else { 1707 } else {
1708 if (is_cryptoconnected(m->net_crypto, 1708 if (is_cryptoconnected(m->net_crypto,
1709 m->friendlist[i].crypt_connection_id) == 4) { /* If the connection timed out, kill it. */ 1709 m->friendlist[i].crypt_connection_id) == CRYPTO_CONN_TIMED_OUT) { /* If the connection timed out, kill it. */
1710 crypto_kill(m->net_crypto, m->friendlist[i].crypt_connection_id); 1710 crypto_kill(m->net_crypto, m->friendlist[i].crypt_connection_id);
1711 m->friendlist[i].crypt_connection_id = -1; 1711 m->friendlist[i].crypt_connection_id = -1;
1712 set_friend_status(m, i, FRIEND_CONFIRMED); 1712 set_friend_status(m, i, FRIEND_CONFIRMED);
@@ -1725,7 +1725,7 @@ void doFriends(Messenger *m)
1725 } 1725 }
1726} 1726}
1727 1727
1728void doInbound(Messenger *m) 1728void do_inbound(Messenger *m)
1729{ 1729{
1730 uint8_t secret_nonce[crypto_box_NONCEBYTES]; 1730 uint8_t secret_nonce[crypto_box_NONCEBYTES];
1731 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; 1731 uint8_t public_key[crypto_box_PUBLICKEYBYTES];
@@ -1767,7 +1767,7 @@ static char *ID2String(uint8_t *client_id)
1767#endif 1767#endif
1768 1768
1769/* The main loop that needs to be run at least 20 times per second. */ 1769/* The main loop that needs to be run at least 20 times per second. */
1770void doMessenger(Messenger *m) 1770void do_messenger(Messenger *m)
1771{ 1771{
1772 unix_time_update(); 1772 unix_time_update();
1773 1773
@@ -1775,8 +1775,8 @@ void doMessenger(Messenger *m)
1775 1775
1776 do_DHT(m->dht); 1776 do_DHT(m->dht);
1777 do_net_crypto(m->net_crypto); 1777 do_net_crypto(m->net_crypto);
1778 doFriends(m); 1778 do_friends(m);
1779 doInbound(m); 1779 do_inbound(m);
1780 do_allgroupchats(m); 1780 do_allgroupchats(m);
1781 LANdiscovery(m); 1781 LANdiscovery(m);
1782 1782
@@ -1875,17 +1875,17 @@ void doMessenger(Messenger *m)
1875/* 1875/*
1876 * functions to avoid excessive polling 1876 * functions to avoid excessive polling
1877 */ 1877 */
1878int waitprepareMessenger(Messenger *m, uint8_t *data, uint16_t *lenptr) 1878int wait_prepare_messenger(Messenger *m, uint8_t *data, uint16_t *lenptr)
1879{ 1879{
1880 return networking_wait_prepare(m->net, sendqueue_total(m->net_crypto->lossless_udp), data, lenptr); 1880 return networking_wait_prepare(m->net, sendqueue_total(m->net_crypto->lossless_udp), data, lenptr);
1881} 1881}
1882 1882
1883int waitexecuteMessenger(Messenger *m, uint8_t *data, uint16_t len, uint16_t milliseconds) 1883int wait_execute_messenger(Messenger *m, uint8_t *data, uint16_t len, uint16_t milliseconds)
1884{ 1884{
1885 return networking_wait_execute(data, len, milliseconds); 1885 return networking_wait_execute(data, len, milliseconds);
1886}; 1886};
1887 1887
1888void waitcleanupMessenger(Messenger *m, uint8_t *data, uint16_t len) 1888void wait_cleanup_messenger(Messenger *m, uint8_t *data, uint16_t len)
1889{ 1889{
1890 networking_wait_cleanup(m->net, data, len); 1890 networking_wait_cleanup(m->net, data, len);
1891} 1891}
@@ -2039,7 +2039,7 @@ static int Messenger_load_old(Messenger *m, uint8_t *data, uint32_t length)
2039#define MESSENGER_STATE_TYPE_NAME 4 2039#define MESSENGER_STATE_TYPE_NAME 4
2040 2040
2041/* return size of the messenger data (for saving) */ 2041/* return size of the messenger data (for saving) */
2042uint32_t Messenger_size(Messenger *m) 2042uint32_t messenger_size(Messenger *m)
2043{ 2043{
2044 uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2; 2044 uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2;
2045 return size32 * 2 // global cookie 2045 return size32 * 2 // global cookie
@@ -2060,7 +2060,7 @@ static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t typ
2060} 2060}
2061 2061
2062/* Save the messenger in data of size Messenger_size(). */ 2062/* Save the messenger in data of size Messenger_size(). */
2063void Messenger_save(Messenger *m, uint8_t *data) 2063void messenger_save(Messenger *m, uint8_t *data)
2064{ 2064{
2065 uint32_t len; 2065 uint32_t len;
2066 uint16_t type; 2066 uint16_t type;
@@ -2163,7 +2163,7 @@ static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t le
2163} 2163}
2164 2164
2165/* Load the messenger from data of size length. */ 2165/* Load the messenger from data of size length. */
2166int Messenger_load(Messenger *m, uint8_t *data, uint32_t length) 2166int messenger_load(Messenger *m, uint8_t *data, uint32_t length)
2167{ 2167{
2168 uint32_t cookie_len = 2 * sizeof(uint32_t); 2168 uint32_t cookie_len = 2 * sizeof(uint32_t);
2169 2169
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index c6ead732..aa9d8632 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -580,33 +580,33 @@ int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length)
580 * return allocated instance of Messenger on success. 580 * return allocated instance of Messenger on success.
581 * return 0 if there are problems. 581 * return 0 if there are problems.
582 */ 582 */
583Messenger *initMessenger(uint8_t ipv6enabled); 583Messenger *new_messenger(uint8_t ipv6enabled);
584 584
585/* Run this before closing shop 585/* Run this before closing shop
586 * Free all datastructures. 586 * Free all datastructures.
587 */ 587 */
588void cleanupMessenger(Messenger *M); 588void kill_messenger(Messenger *M);
589 589
590/* The main loop that needs to be run at least 20 times per second. */ 590/* The main loop that needs to be run at least 20 times per second. */
591void doMessenger(Messenger *m); 591void do_messenger(Messenger *m);
592 592
593/* 593/*
594 * functions to avoid excessive polling 594 * functions to avoid excessive polling
595 */ 595 */
596int waitprepareMessenger(Messenger *m, uint8_t *data, uint16_t *lenptr); 596int wait_prepare_messenger(Messenger *m, uint8_t *data, uint16_t *lenptr);
597int waitexecuteMessenger(Messenger *m, uint8_t *data, uint16_t len, uint16_t milliseconds); 597int wait_execute_messenger(Messenger *m, uint8_t *data, uint16_t len, uint16_t milliseconds);
598void waitcleanupMessenger(Messenger *m, uint8_t *data, uint16_t len); 598void wait_cleanup_messenger(Messenger *m, uint8_t *data, uint16_t len);
599 599
600/* SAVING AND LOADING FUNCTIONS: */ 600/* SAVING AND LOADING FUNCTIONS: */
601 601
602/* return size of the messenger data (for saving). */ 602/* return size of the messenger data (for saving). */
603uint32_t Messenger_size(Messenger *m); 603uint32_t messenger_size(Messenger *m);
604 604
605/* Save the messenger in data (must be allocated memory of size Messenger_size()) */ 605/* Save the messenger in data (must be allocated memory of size Messenger_size()) */
606void Messenger_save(Messenger *m, uint8_t *data); 606void messenger_save(Messenger *m, uint8_t *data);
607 607
608/* Load the messenger from data of size length. */ 608/* Load the messenger from data of size length. */
609int Messenger_load(Messenger *m, uint8_t *data, uint32_t length); 609int messenger_load(Messenger *m, uint8_t *data, uint32_t length);
610 610
611/* Return the number of friends in the instance m. 611/* Return the number of friends in the instance m.
612 * You should use this to determine how much memory to allocate 612 * You should use this to determine how much memory to allocate
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 0a7ff665..7ae7c502 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -31,12 +31,6 @@
31#include "net_crypto.h" 31#include "net_crypto.h"
32#include "util.h" 32#include "util.h"
33 33
34#define CONN_NO_CONNECTION 0
35#define CONN_HANDSHAKE_SENT 1
36#define CONN_NOT_CONFIRMED 2
37#define CONN_ESTABLISHED 3
38#define CONN_TIMED_OUT 4
39
40static uint8_t crypt_connection_id_not_valid(Net_Crypto *c, int crypt_connection_id) 34static uint8_t crypt_connection_id_not_valid(Net_Crypto *c, int crypt_connection_id)
41{ 35{
42 return (uint32_t)crypt_connection_id >= c->crypto_connections_length; 36 return (uint32_t)crypt_connection_id >= c->crypto_connections_length;
@@ -153,7 +147,7 @@ void random_nonce(uint8_t *nonce)
153static uint8_t base_nonce[crypto_box_NONCEBYTES]; 147static uint8_t base_nonce[crypto_box_NONCEBYTES];
154static uint8_t nonce_set = 0; 148static uint8_t nonce_set = 0;
155 149
156/*Gives a nonce guaranteed to be different from previous ones.*/ 150/* Gives a nonce guaranteed to be different from previous ones.*/
157void new_nonce(uint8_t *nonce) 151void new_nonce(uint8_t *nonce)
158{ 152{
159 if (nonce_set == 0) { 153 if (nonce_set == 0) {
@@ -175,7 +169,7 @@ int read_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data)
175 if (crypt_connection_id_not_valid(c, crypt_connection_id)) 169 if (crypt_connection_id_not_valid(c, crypt_connection_id))
176 return 0; 170 return 0;
177 171
178 if (c->crypto_connections[crypt_connection_id].status != CONN_ESTABLISHED) 172 if (c->crypto_connections[crypt_connection_id].status != CRYPTO_CONN_ESTABLISHED)
179 return 0; 173 return 0;
180 174
181 uint8_t temp_data[MAX_DATA_SIZE]; 175 uint8_t temp_data[MAX_DATA_SIZE];
@@ -221,7 +215,7 @@ int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uin
221 if (length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES > MAX_DATA_SIZE - 1) 215 if (length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES > MAX_DATA_SIZE - 1)
222 return 0; 216 return 0;
223 217
224 if (c->crypto_connections[crypt_connection_id].status != CONN_ESTABLISHED) 218 if (c->crypto_connections[crypt_connection_id].status != CRYPTO_CONN_ESTABLISHED)
225 return 0; 219 return 0;
226 220
227 uint8_t temp_data[MAX_DATA_SIZE]; 221 uint8_t temp_data[MAX_DATA_SIZE];
@@ -241,7 +235,7 @@ int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uin
241 return 1; 235 return 1;
242} 236}
243 237
244/* Ceate a request to peer. 238/* Create a request to peer.
245 * send_public_key and send_secret_key are the pub/secret keys of the sender. 239 * send_public_key and send_secret_key are the pub/secret keys of the sender.
246 * recv_public_key is public key of reciever. 240 * recv_public_key is public key of reciever.
247 * packet must be an array of MAX_DATA_SIZE big. 241 * packet must be an array of MAX_DATA_SIZE big.
@@ -421,7 +415,7 @@ static int getcryptconnection_id(Net_Crypto *c, uint8_t *public_key)
421 uint32_t i; 415 uint32_t i;
422 416
423 for (i = 0; i < c->crypto_connections_length; ++i) 417 for (i = 0; i < c->crypto_connections_length; ++i)
424 if (c->crypto_connections[i].status != CONN_NO_CONNECTION) 418 if (c->crypto_connections[i].status != CRYPTO_CONN_NO_CONNECTION)
425 if (id_equal(public_key, c->crypto_connections[i].public_key)) 419 if (id_equal(public_key, c->crypto_connections[i].public_key))
426 return i; 420 return i;
427 421
@@ -474,14 +468,14 @@ int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port)
474 c->crypto_connections[c->crypto_connections_length].number = ~0; 468 c->crypto_connections[c->crypto_connections_length].number = ~0;
475 469
476 for (i = 0; i <= c->crypto_connections_length; ++i) { 470 for (i = 0; i <= c->crypto_connections_length; ++i) {
477 if (c->crypto_connections[i].status == CONN_NO_CONNECTION) { 471 if (c->crypto_connections[i].status == CRYPTO_CONN_NO_CONNECTION) {
478 int id_new = new_connection(c->lossless_udp, ip_port); 472 int id_new = new_connection(c->lossless_udp, ip_port);
479 473
480 if (id_new == -1) 474 if (id_new == -1)
481 return -1; 475 return -1;
482 476
483 c->crypto_connections[i].number = id_new; 477 c->crypto_connections[i].number = id_new;
484 c->crypto_connections[i].status = CONN_HANDSHAKE_SENT; 478 c->crypto_connections[i].status = CRYPTO_CONN_HANDSHAKE_SENT;
485 random_nonce(c->crypto_connections[i].recv_nonce); 479 random_nonce(c->crypto_connections[i].recv_nonce);
486 id_copy(c->crypto_connections[i].public_key, public_key); 480 id_copy(c->crypto_connections[i].public_key, public_key);
487 crypto_box_keypair(c->crypto_connections[i].sessionpublic_key, c->crypto_connections[i].sessionsecret_key); 481 crypto_box_keypair(c->crypto_connections[i].sessionpublic_key, c->crypto_connections[i].sessionsecret_key);
@@ -550,15 +544,15 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id)
550 if (crypt_connection_id_not_valid(c, crypt_connection_id)) 544 if (crypt_connection_id_not_valid(c, crypt_connection_id))
551 return 1; 545 return 1;
552 546
553 if (c->crypto_connections[crypt_connection_id].status != CONN_NO_CONNECTION) { 547 if (c->crypto_connections[crypt_connection_id].status != CRYPTO_CONN_NO_CONNECTION) {
554 c->crypto_connections[crypt_connection_id].status = CONN_NO_CONNECTION; 548 c->crypto_connections[crypt_connection_id].status = CRYPTO_CONN_NO_CONNECTION;
555 kill_connection(c->lossless_udp, c->crypto_connections[crypt_connection_id].number); 549 kill_connection(c->lossless_udp, c->crypto_connections[crypt_connection_id].number);
556 memset(&(c->crypto_connections[crypt_connection_id]), 0 , sizeof(Crypto_Connection)); 550 memset(&(c->crypto_connections[crypt_connection_id]), 0 , sizeof(Crypto_Connection));
557 c->crypto_connections[crypt_connection_id].number = ~0; 551 c->crypto_connections[crypt_connection_id].number = ~0;
558 uint32_t i; 552 uint32_t i;
559 553
560 for (i = c->crypto_connections_length; i != 0; --i) { 554 for (i = c->crypto_connections_length; i != 0; --i) {
561 if (c->crypto_connections[i - 1].status != CONN_NO_CONNECTION) 555 if (c->crypto_connections[i - 1].status != CRYPTO_CONN_NO_CONNECTION)
562 break; 556 break;
563 } 557 }
564 558
@@ -598,9 +592,9 @@ int accept_crypto_inbound(Net_Crypto *c, int connection_id, uint8_t *public_key,
598 c->crypto_connections[c->crypto_connections_length].number = ~0; 592 c->crypto_connections[c->crypto_connections_length].number = ~0;
599 593
600 for (i = 0; i <= c->crypto_connections_length; ++i) { 594 for (i = 0; i <= c->crypto_connections_length; ++i) {
601 if (c->crypto_connections[i].status == CONN_NO_CONNECTION) { 595 if (c->crypto_connections[i].status == CRYPTO_CONN_NO_CONNECTION) {
602 c->crypto_connections[i].number = connection_id; 596 c->crypto_connections[i].number = connection_id;
603 c->crypto_connections[i].status = CONN_NOT_CONFIRMED; 597 c->crypto_connections[i].status = CRYPTO_CONN_NOT_CONFIRMED;
604 c->crypto_connections[i].timeout = unix_time() + CRYPTO_HANDSHAKE_TIMEOUT; 598 c->crypto_connections[i].timeout = unix_time() + CRYPTO_HANDSHAKE_TIMEOUT;
605 random_nonce(c->crypto_connections[i].recv_nonce); 599 random_nonce(c->crypto_connections[i].recv_nonce);
606 memcpy(c->crypto_connections[i].sent_nonce, secret_nonce, crypto_box_NONCEBYTES); 600 memcpy(c->crypto_connections[i].sent_nonce, secret_nonce, crypto_box_NONCEBYTES);
@@ -621,9 +615,9 @@ int accept_crypto_inbound(Net_Crypto *c, int connection_id, uint8_t *public_key,
621 c->crypto_connections[i].sessionsecret_key, 615 c->crypto_connections[i].sessionsecret_key,
622 c->crypto_connections[i].shared_key); 616 c->crypto_connections[i].shared_key);
623 c->crypto_connections[i].status = 617 c->crypto_connections[i].status =
624 CONN_ESTABLISHED; /* Connection status needs to be 3 for write_cryptpacket() to work. */ 618 CRYPTO_CONN_ESTABLISHED; /* Connection status needs to be 3 for write_cryptpacket() to work. */
625 write_cryptpacket(c, i, ((uint8_t *)&zero), sizeof(zero)); 619 write_cryptpacket(c, i, ((uint8_t *)&zero), sizeof(zero));
626 c->crypto_connections[i].status = CONN_NOT_CONFIRMED; /* Set it to its proper value right after. */ 620 c->crypto_connections[i].status = CRYPTO_CONN_NOT_CONFIRMED; /* Set it to its proper value right after. */
627 return i; 621 return i;
628 } 622 }
629 623
@@ -645,7 +639,7 @@ int is_cryptoconnected(Net_Crypto *c, int crypt_connection_id)
645 if ((unsigned int)crypt_connection_id < c->crypto_connections_length) 639 if ((unsigned int)crypt_connection_id < c->crypto_connections_length)
646 return c->crypto_connections[crypt_connection_id].status; 640 return c->crypto_connections[crypt_connection_id].status;
647 641
648 return CONN_NO_CONNECTION; 642 return CRYPTO_CONN_NO_CONNECTION;
649} 643}
650 644
651void new_keys(Net_Crypto *c) 645void new_keys(Net_Crypto *c)
@@ -678,10 +672,10 @@ static void receive_crypto(Net_Crypto *c)
678 uint64_t temp_time = unix_time(); 672 uint64_t temp_time = unix_time();
679 673
680 for (i = 0; i < c->crypto_connections_length; ++i) { 674 for (i = 0; i < c->crypto_connections_length; ++i) {
681 if (c->crypto_connections[i].status == CONN_NO_CONNECTION) 675 if (c->crypto_connections[i].status == CRYPTO_CONN_NO_CONNECTION)
682 continue; 676 continue;
683 677
684 if (c->crypto_connections[i].status == CONN_HANDSHAKE_SENT) { 678 if (c->crypto_connections[i].status == CRYPTO_CONN_HANDSHAKE_SENT) {
685 uint8_t temp_data[MAX_DATA_SIZE]; 679 uint8_t temp_data[MAX_DATA_SIZE];
686 uint8_t secret_nonce[crypto_box_NONCEBYTES]; 680 uint8_t secret_nonce[crypto_box_NONCEBYTES];
687 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; 681 uint8_t public_key[crypto_box_PUBLICKEYBYTES];
@@ -701,25 +695,25 @@ static void receive_crypto(Net_Crypto *c)
701 c->crypto_connections[i].sessionsecret_key, 695 c->crypto_connections[i].sessionsecret_key,
702 c->crypto_connections[i].shared_key); 696 c->crypto_connections[i].shared_key);
703 c->crypto_connections[i].status = 697 c->crypto_connections[i].status =
704 CONN_ESTABLISHED; /* Connection status needs to be 3 for write_cryptpacket() to work. */ 698 CRYPTO_CONN_ESTABLISHED; /* Connection status needs to be 3 for write_cryptpacket() to work. */
705 write_cryptpacket(c, i, ((uint8_t *)&zero), sizeof(zero)); 699 write_cryptpacket(c, i, ((uint8_t *)&zero), sizeof(zero));
706 c->crypto_connections[i].status = CONN_NOT_CONFIRMED; /* Set it to its proper value right after. */ 700 c->crypto_connections[i].status = CRYPTO_CONN_NOT_CONFIRMED; /* Set it to its proper value right after. */
707 } else { 701 } else {
708 /* This should not happen, timeout the connection if it does. */ 702 /* This should not happen, timeout the connection if it does. */
709 c->crypto_connections[i].status = CONN_TIMED_OUT; 703 c->crypto_connections[i].status = CRYPTO_CONN_TIMED_OUT;
710 } 704 }
711 } else { 705 } else {
712 /* This should not happen, timeout the connection if it does. */ 706 /* This should not happen, timeout the connection if it does. */
713 c->crypto_connections[i].status = CONN_TIMED_OUT; 707 c->crypto_connections[i].status = CRYPTO_CONN_TIMED_OUT;
714 } 708 }
715 } else if (id_packet(c->lossless_udp, 709 } else if (id_packet(c->lossless_udp,
716 c->crypto_connections[i].number) != -1) { 710 c->crypto_connections[i].number) != -1) {
717 /* This should not happen, timeout the connection if it does. */ 711 /* This should not happen, timeout the connection if it does. */
718 c->crypto_connections[i].status = CONN_TIMED_OUT; 712 c->crypto_connections[i].status = CRYPTO_CONN_TIMED_OUT;
719 } 713 }
720 } 714 }
721 715
722 if (c->crypto_connections[i].status == CONN_NOT_CONFIRMED) { 716 if (c->crypto_connections[i].status == CRYPTO_CONN_NOT_CONFIRMED) {
723 if (id_packet(c->lossless_udp, c->crypto_connections[i].number) == 3) { 717 if (id_packet(c->lossless_udp, c->crypto_connections[i].number) == 3) {
724 uint8_t temp_data[MAX_DATA_SIZE]; 718 uint8_t temp_data[MAX_DATA_SIZE];
725 uint8_t data[MAX_DATA_SIZE]; 719 uint8_t data[MAX_DATA_SIZE];
@@ -734,22 +728,22 @@ static void receive_crypto(Net_Crypto *c)
734 encrypt_precompute(c->crypto_connections[i].peersessionpublic_key, 728 encrypt_precompute(c->crypto_connections[i].peersessionpublic_key,
735 c->crypto_connections[i].sessionsecret_key, 729 c->crypto_connections[i].sessionsecret_key,
736 c->crypto_connections[i].shared_key); 730 c->crypto_connections[i].shared_key);
737 c->crypto_connections[i].status = CONN_ESTABLISHED; 731 c->crypto_connections[i].status = CRYPTO_CONN_ESTABLISHED;
738 c->crypto_connections[i].timeout = ~0; 732 c->crypto_connections[i].timeout = ~0;
739 /* Connection is accepted. */ 733 /* Connection is accepted. */
740 confirm_connection(c->lossless_udp, c->crypto_connections[i].number); 734 confirm_connection(c->lossless_udp, c->crypto_connections[i].number);
741 } else { 735 } else {
742 /* This should not happen, timeout the connection if it does. */ 736 /* This should not happen, timeout the connection if it does. */
743 c->crypto_connections[i].status = CONN_TIMED_OUT; 737 c->crypto_connections[i].status = CRYPTO_CONN_TIMED_OUT;
744 } 738 }
745 } else if (id_packet(c->lossless_udp, c->crypto_connections[i].number) != -1) { 739 } else if (id_packet(c->lossless_udp, c->crypto_connections[i].number) != -1) {
746 /* This should not happen, timeout the connection if it does. */ 740 /* This should not happen, timeout the connection if it does. */
747 c->crypto_connections[i].status = CONN_TIMED_OUT; 741 c->crypto_connections[i].status = CRYPTO_CONN_TIMED_OUT;
748 } 742 }
749 } 743 }
750 744
751 if (temp_time > c->crypto_connections[i].timeout) { 745 if (temp_time > c->crypto_connections[i].timeout) {
752 c->crypto_connections[i].status = CONN_TIMED_OUT; 746 c->crypto_connections[i].status = CRYPTO_CONN_TIMED_OUT;
753 } 747 }
754 } 748 }
755} 749}
@@ -788,9 +782,9 @@ static void kill_timedout(Net_Crypto *c)
788 uint32_t i; 782 uint32_t i;
789 783
790 for (i = 0; i < c->crypto_connections_length; ++i) { 784 for (i = 0; i < c->crypto_connections_length; ++i) {
791 if (c->crypto_connections[i].status != CONN_NO_CONNECTION 785 if (c->crypto_connections[i].status != CRYPTO_CONN_NO_CONNECTION
792 && is_connected(c->lossless_udp, c->crypto_connections[i].number) == LUDP_TIMED_OUT) 786 && is_connected(c->lossless_udp, c->crypto_connections[i].number) == LUDP_TIMED_OUT)
793 c->crypto_connections[i].status = CONN_TIMED_OUT; 787 c->crypto_connections[i].status = CRYPTO_CONN_TIMED_OUT;
794 } 788 }
795} 789}
796 790
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index 0ddb711a..0de66e98 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -28,7 +28,13 @@
28 28
29#define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */ 29#define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */
30#define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */ 30#define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */
31#define CRYPTO_HANDSHAKE_TIMEOUT (CONNEXION_TIMEOUT * 2) 31#define CRYPTO_HANDSHAKE_TIMEOUT (CONNECTION_TIMEOUT * 2)
32
33#define CRYPTO_CONN_NO_CONNECTION 0
34#define CRYPTO_CONN_HANDSHAKE_SENT 1
35#define CRYPTO_CONN_NOT_CONFIRMED 2
36#define CRYPTO_CONN_ESTABLISHED 3
37#define CRYPTO_CONN_TIMED_OUT 4
32 38
33typedef struct { 39typedef struct {
34 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* The real public key of the peer. */ 40 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* The real public key of the peer. */
@@ -38,7 +44,7 @@ typedef struct {
38 uint8_t sessionsecret_key[crypto_box_SECRETKEYBYTES]; /* Our private key for this session. */ 44 uint8_t sessionsecret_key[crypto_box_SECRETKEYBYTES]; /* Our private key for this session. */
39 uint8_t peersessionpublic_key[crypto_box_PUBLICKEYBYTES]; /* The public key of the peer. */ 45 uint8_t peersessionpublic_key[crypto_box_PUBLICKEYBYTES]; /* The public key of the peer. */
40 uint8_t shared_key[crypto_box_BEFORENMBYTES]; /* The precomputed shared key from encrypt_precompute. */ 46 uint8_t shared_key[crypto_box_BEFORENMBYTES]; /* The precomputed shared key from encrypt_precompute. */
41 uint8_t status; /* 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet 47 uint8_t status; /* 0 if no connection, 1 we have sent a handshake, 2 if connection is not confirmed yet
42 * (we have received a handshake but no empty data packet), 3 if the connection is established. 48 * (we have received a handshake but no empty data packet), 3 if the connection is established.
43 * 4 if the connection is timed out. 49 * 4 if the connection is timed out.
44 */ 50 */
diff --git a/toxcore/ping.c b/toxcore/ping.c
index e4bc16d9..c7b829b4 100644
--- a/toxcore/ping.c
+++ b/toxcore/ping.c
@@ -3,6 +3,24 @@
3 * 3 *
4 * This file is donated to the Tox Project. 4 * This file is donated to the Tox Project.
5 * Copyright 2013 plutooo 5 * Copyright 2013 plutooo
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 *
6 */ 24 */
7 25
8#ifdef HAVE_CONFIG_H 26#ifdef HAVE_CONFIG_H
diff --git a/toxcore/ping.h b/toxcore/ping.h
index fabb1afd..32742401 100644
--- a/toxcore/ping.h
+++ b/toxcore/ping.h
@@ -3,6 +3,23 @@
3 * 3 *
4 * This file is donated to the Tox Project. 4 * This file is donated to the Tox Project.
5 * Copyright 2013 plutooo 5 * Copyright 2013 plutooo
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/>.
6 */ 23 */
7#ifndef __PING_H__ 24#ifndef __PING_H__
8#define __PING_H__ 25#define __PING_H__
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 5f882965..6a0c6a62 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -609,7 +609,7 @@ int tox_isconnected(Tox *tox)
609 */ 609 */
610Tox *tox_new(uint8_t ipv6enabled) 610Tox *tox_new(uint8_t ipv6enabled)
611{ 611{
612 return initMessenger(ipv6enabled); 612 return new_messenger(ipv6enabled);
613} 613}
614 614
615/* Run this before closing shop. 615/* Run this before closing shop.
@@ -618,14 +618,14 @@ Tox *tox_new(uint8_t ipv6enabled)
618void tox_kill(Tox *tox) 618void tox_kill(Tox *tox)
619{ 619{
620 Messenger *m = tox; 620 Messenger *m = tox;
621 cleanupMessenger(m); 621 kill_messenger(m);
622} 622}
623 623
624/* The main loop that needs to be run at least 20 times per second. */ 624/* The main loop that needs to be run at least 20 times per second. */
625void tox_do(Tox *tox) 625void tox_do(Tox *tox)
626{ 626{
627 Messenger *m = tox; 627 Messenger *m = tox;
628 doMessenger(m); 628 do_messenger(m);
629} 629}
630 630
631/* 631/*
@@ -634,19 +634,19 @@ void tox_do(Tox *tox)
634int tox_wait_prepare(Tox *tox, uint8_t *data, uint16_t *lenptr) 634int tox_wait_prepare(Tox *tox, uint8_t *data, uint16_t *lenptr)
635{ 635{
636 Messenger *m = tox; 636 Messenger *m = tox;
637 return waitprepareMessenger(m, data, lenptr); 637 return wait_prepare_messenger(m, data, lenptr);
638} 638}
639 639
640int tox_wait_execute(Tox *tox, uint8_t *data, uint16_t len, uint16_t milliseconds) 640int tox_wait_execute(Tox *tox, uint8_t *data, uint16_t len, uint16_t milliseconds)
641{ 641{
642 Messenger *m = tox; 642 Messenger *m = tox;
643 return waitexecuteMessenger(m, data, len, milliseconds); 643 return wait_execute_messenger(m, data, len, milliseconds);
644} 644}
645 645
646void tox_wait_cleanup(Tox *tox, uint8_t *data, uint16_t len) 646void tox_wait_cleanup(Tox *tox, uint8_t *data, uint16_t len)
647{ 647{
648 Messenger *m = tox; 648 Messenger *m = tox;
649 waitcleanupMessenger(m, data, len); 649 wait_cleanup_messenger(m, data, len);
650} 650}
651 651
652/* SAVING AND LOADING FUNCTIONS: */ 652/* SAVING AND LOADING FUNCTIONS: */
@@ -655,20 +655,20 @@ void tox_wait_cleanup(Tox *tox, uint8_t *data, uint16_t len)
655uint32_t tox_size(Tox *tox) 655uint32_t tox_size(Tox *tox)
656{ 656{
657 Messenger *m = tox; 657 Messenger *m = tox;
658 return Messenger_size(m); 658 return messenger_size(m);
659} 659}
660 660
661/* Save the messenger in data (must be allocated memory of size Messenger_size()). */ 661/* Save the messenger in data (must be allocated memory of size Messenger_size()). */
662void tox_save(Tox *tox, uint8_t *data) 662void tox_save(Tox *tox, uint8_t *data)
663{ 663{
664 Messenger *m = tox; 664 Messenger *m = tox;
665 Messenger_save(m, data); 665 messenger_save(m, data);
666} 666}
667 667
668/* Load the messenger from data of size length. */ 668/* Load the messenger from data of size length. */
669int tox_load(Tox *tox, uint8_t *data, uint32_t length) 669int tox_load(Tox *tox, uint8_t *data, uint32_t length)
670{ 670{
671 Messenger *m = tox; 671 Messenger *m = tox;
672 return Messenger_load(m, data, length); 672 return messenger_load(m, data, length);
673} 673}
674 674
diff --git a/toxcore/util.c b/toxcore/util.c
index 3fdac9dd..d3df64c1 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -3,6 +3,23 @@
3 * 3 *
4 * This file is donated to the Tox Project. 4 * This file is donated to the Tox Project.
5 * Copyright 2013 plutooo 5 * Copyright 2013 plutooo
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/>.
6 */ 23 */
7 24
8#ifdef HAVE_CONFIG_H 25#ifdef HAVE_CONFIG_H
diff --git a/toxcore/util.h b/toxcore/util.h
index 3ecefd9c..f69f294b 100644
--- a/toxcore/util.h
+++ b/toxcore/util.h
@@ -3,6 +3,23 @@
3 * 3 *
4 * This file is donated to the Tox Project. 4 * This file is donated to the Tox Project.
5 * Copyright 2013 plutooo 5 * Copyright 2013 plutooo
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/>.
6 */ 23 */
7 24
8#ifndef __UTIL_H__ 25#ifndef __UTIL_H__