summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
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 /toxcore/Messenger.c
parent0a4c3d7e2e080dafd66d25f7a5806b89f7be1bcf (diff)
parentf3be5609049d278ee3f46754ea4b0eb929876dba (diff)
Merge remote-tracking branch 'upstream/master' into cleanup_unix_time_id_eq_cpy_is_timeout
Conflicts: toxcore/net_crypto.c
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c36
1 files changed, 18 insertions, 18 deletions
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