diff options
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index bb3a56f0..2f0bde29 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -206,11 +206,16 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length) | |||
206 | 206 | ||
207 | memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); | 207 | memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); |
208 | 208 | ||
209 | int onion_friendnum = onion_addfriend(m->onion_c, client_id); | ||
210 | |||
211 | if (onion_friendnum == -1) | ||
212 | return FAERR_UNKNOWN; | ||
213 | |||
209 | uint32_t i; | 214 | uint32_t i; |
210 | 215 | ||
211 | for (i = 0; i <= m->numfriends; ++i) { | 216 | for (i = 0; i <= m->numfriends; ++i) { |
212 | if (m->friendlist[i].status == NOFRIEND) { | 217 | if (m->friendlist[i].status == NOFRIEND) { |
213 | DHT_addfriend(m->dht, client_id); | 218 | m->friendlist[i].onion_friendnum = onion_friendnum; |
214 | m->friendlist[i].status = FRIEND_ADDED; | 219 | m->friendlist[i].status = FRIEND_ADDED; |
215 | m->friendlist[i].crypt_connection_id = -1; | 220 | m->friendlist[i].crypt_connection_id = -1; |
216 | m->friendlist[i].friendrequest_lastsent = 0; | 221 | m->friendlist[i].friendrequest_lastsent = 0; |
@@ -249,11 +254,16 @@ int m_addfriend_norequest(Messenger *m, uint8_t *client_id) | |||
249 | 254 | ||
250 | memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); | 255 | memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); |
251 | 256 | ||
257 | int onion_friendnum = onion_addfriend(m->onion_c, client_id); | ||
258 | |||
259 | if (onion_friendnum == -1) | ||
260 | return FAERR_UNKNOWN; | ||
261 | |||
252 | uint32_t i; | 262 | uint32_t i; |
253 | 263 | ||
254 | for (i = 0; i <= m->numfriends; ++i) { | 264 | for (i = 0; i <= m->numfriends; ++i) { |
255 | if (m->friendlist[i].status == NOFRIEND) { | 265 | if (m->friendlist[i].status == NOFRIEND) { |
256 | DHT_addfriend(m->dht, client_id); | 266 | m->friendlist[i].onion_friendnum = onion_friendnum; |
257 | m->friendlist[i].status = FRIEND_CONFIRMED; | 267 | m->friendlist[i].status = FRIEND_CONFIRMED; |
258 | m->friendlist[i].crypt_connection_id = -1; | 268 | m->friendlist[i].crypt_connection_id = -1; |
259 | m->friendlist[i].friendrequest_lastsent = 0; | 269 | m->friendlist[i].friendrequest_lastsent = 0; |
@@ -284,7 +294,7 @@ int m_delfriend(Messenger *m, int friendnumber) | |||
284 | if (friend_not_valid(m, friendnumber)) | 294 | if (friend_not_valid(m, friendnumber)) |
285 | return -1; | 295 | return -1; |
286 | 296 | ||
287 | DHT_delfriend(m->dht, m->friendlist[friendnumber].client_id); | 297 | onion_delfriend(m->onion_c, m->friendlist[friendnumber].onion_friendnum); |
288 | crypto_kill(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id); | 298 | crypto_kill(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id); |
289 | free(m->friendlist[friendnumber].statusmessage); | 299 | free(m->friendlist[friendnumber].statusmessage); |
290 | memset(&(m->friendlist[friendnumber]), 0, sizeof(Friend)); | 300 | memset(&(m->friendlist[friendnumber]), 0, sizeof(Friend)); |
@@ -1513,7 +1523,7 @@ static int friend_already_added(uint8_t *client_id, void *data) | |||
1513 | static void LANdiscovery(Messenger *m) | 1523 | static void LANdiscovery(Messenger *m) |
1514 | { | 1524 | { |
1515 | if (m->last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) { | 1525 | if (m->last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) { |
1516 | send_LANdiscovery(htons(TOX_PORT_DEFAULT), m->net_crypto); | 1526 | send_LANdiscovery(htons(TOX_PORT_DEFAULT), m->dht); |
1517 | m->last_LANdiscovery = unix_time(); | 1527 | m->last_LANdiscovery = unix_time(); |
1518 | } | 1528 | } |
1519 | } | 1529 | } |
@@ -1552,9 +1562,24 @@ Messenger *new_messenger(uint8_t ipv6enabled) | |||
1552 | return NULL; | 1562 | return NULL; |
1553 | } | 1563 | } |
1554 | 1564 | ||
1565 | m->onion = new_onion(m->dht); | ||
1566 | m->onion_a = new_onion_announce(m->dht); | ||
1567 | m->onion_c = new_onion_client(m->dht); | ||
1568 | |||
1569 | if (!(m->onion && m->onion_a && m->onion_c)) { | ||
1570 | kill_onion(m->onion); | ||
1571 | kill_onion_announce(m->onion_a); | ||
1572 | kill_onion_client(m->onion_c); | ||
1573 | kill_DHT(m->dht); | ||
1574 | kill_net_crypto(m->net_crypto); | ||
1575 | kill_networking(m->net); | ||
1576 | free(m); | ||
1577 | return NULL; | ||
1578 | } | ||
1579 | |||
1555 | m_set_statusmessage(m, (uint8_t *)"Online", sizeof("Online")); | 1580 | m_set_statusmessage(m, (uint8_t *)"Online", sizeof("Online")); |
1556 | 1581 | ||
1557 | friendreq_init(&(m->fr), m->net_crypto); | 1582 | friendreq_init(&(m->fr), m->onion_c); |
1558 | LANdiscovery_init(m->dht); | 1583 | LANdiscovery_init(m->dht); |
1559 | set_nospam(&(m->fr), random_int()); | 1584 | set_nospam(&(m->fr), random_int()); |
1560 | set_filter_function(&(m->fr), &friend_already_added, m); | 1585 | set_filter_function(&(m->fr), &friend_already_added, m); |
@@ -1610,7 +1635,7 @@ void do_friends(Messenger *m) | |||
1610 | 1635 | ||
1611 | for (i = 0; i < m->numfriends; ++i) { | 1636 | for (i = 0; i < m->numfriends; ++i) { |
1612 | if (m->friendlist[i].status == FRIEND_ADDED) { | 1637 | if (m->friendlist[i].status == FRIEND_ADDED) { |
1613 | int fr = send_friendrequest(m->dht, m->friendlist[i].client_id, m->friendlist[i].friendrequest_nospam, | 1638 | int fr = send_friendrequest(m->onion_c, m->friendlist[i].client_id, m->friendlist[i].friendrequest_nospam, |
1614 | m->friendlist[i].info, | 1639 | m->friendlist[i].info, |
1615 | m->friendlist[i].info_size); | 1640 | m->friendlist[i].info_size); |
1616 | 1641 | ||
@@ -1630,7 +1655,7 @@ void do_friends(Messenger *m) | |||
1630 | } | 1655 | } |
1631 | 1656 | ||
1632 | IP_Port friendip; | 1657 | IP_Port friendip; |
1633 | int friendok = DHT_getfriendip(m->dht, m->friendlist[i].client_id, &friendip); | 1658 | int friendok = onion_getfriendip(m->onion_c, m->friendlist[i].onion_friendnum, &friendip); |
1634 | 1659 | ||
1635 | switch (is_cryptoconnected(m->net_crypto, m->friendlist[i].crypt_connection_id)) { | 1660 | switch (is_cryptoconnected(m->net_crypto, m->friendlist[i].crypt_connection_id)) { |
1636 | case CRYPTO_CONN_NO_CONNECTION: | 1661 | case CRYPTO_CONN_NO_CONNECTION: |
@@ -1957,6 +1982,7 @@ void do_messenger(Messenger *m) | |||
1957 | 1982 | ||
1958 | do_DHT(m->dht); | 1983 | do_DHT(m->dht); |
1959 | do_net_crypto(m->net_crypto); | 1984 | do_net_crypto(m->net_crypto); |
1985 | do_onion_client(m->onion_c); | ||
1960 | do_friends(m); | 1986 | do_friends(m); |
1961 | do_inbound(m); | 1987 | do_inbound(m); |
1962 | do_allgroupchats(m); | 1988 | do_allgroupchats(m); |