summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c5
-rw-r--r--toxcore/Messenger.c2
-rw-r--r--toxcore/onion_client.c63
-rw-r--r--toxcore/onion_client.h14
4 files changed, 60 insertions, 24 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index c8702c45..f93a6d7a 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -308,7 +308,8 @@ static void get_close_nodes_inner(DHT *dht, uint8_t *client_id, Node_format *nod
308 if (LAN_ip(ipptp->ip_port.ip) == 0 && !is_LAN) 308 if (LAN_ip(ipptp->ip_port.ip) == 0 && !is_LAN)
309 continue; 309 continue;
310 310
311 if (LAN_ip(ipptp->ip_port.ip) != 0 && want_good && hardening_correct(&ipptp->hardening) != HARDENING_ALL_OK && !id_equal(client_id, client->client_id)) 311 if (LAN_ip(ipptp->ip_port.ip) != 0 && want_good && hardening_correct(&ipptp->hardening) != HARDENING_ALL_OK
312 && !id_equal(client_id, client->client_id))
312 continue; 313 continue;
313 314
314 if (num_nodes < MAX_SENT_NODES) { 315 if (num_nodes < MAX_SENT_NODES) {
@@ -1838,7 +1839,7 @@ static void do_NAT(DHT *dht)
1838/*----------------------------------------------------------------------------------*/ 1839/*----------------------------------------------------------------------------------*/
1839/*-----------------------END OF NAT PUNCHING FUNCTIONS------------------------------*/ 1840/*-----------------------END OF NAT PUNCHING FUNCTIONS------------------------------*/
1840 1841
1841#define HARDREQ_DATA_SIZE 768 /* Attempt to prevent amplification/other attacks*/ 1842#define HARDREQ_DATA_SIZE 384 /* Attempt to prevent amplification/other attacks*/
1842 1843
1843#define CHECK_TYPE_ROUTE_REQ 0 1844#define CHECK_TYPE_ROUTE_REQ 0
1844#define CHECK_TYPE_ROUTE_RES 1 1845#define CHECK_TYPE_ROUTE_RES 1
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 3bc9f211..2f270fb6 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -683,6 +683,8 @@ static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_
683 const uint8_t was_online = m->friendlist[friendnumber].status == FRIEND_ONLINE; 683 const uint8_t was_online = m->friendlist[friendnumber].status == FRIEND_ONLINE;
684 const uint8_t is_online = status == FRIEND_ONLINE; 684 const uint8_t is_online = status == FRIEND_ONLINE;
685 685
686 onion_set_friend_online(m->onion_c, m->friendlist[friendnumber].onion_friendnum, is_online);
687
686 if (is_online != was_online) { 688 if (is_online != was_online) {
687 if (was_online) 689 if (was_online)
688 break_files(m, friendnumber); 690 break_files(m, friendnumber);
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 1efe519a..932ffad7 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -582,6 +582,24 @@ int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port)
582 return DHT_getfriendip(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id, ip_port); 582 return DHT_getfriendip(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id, ip_port);
583} 583}
584 584
585/* Set if friend is online or not.
586 * NOTE: This function is there and should be used so that we don't send useless packets to the friend if he is online.
587 *
588 * is_online 1 means friend is online.
589 * is_online 0 means friend is offline
590 *
591 * return -1 on failure.
592 * return 0 on success.
593 */
594int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_online)
595{
596 if ((uint32_t)friend_num >= onion_c->num_friends)
597 return -1;
598
599 onion_c->friends_list[friend_num].is_online = is_online;
600 return 0;
601}
602
585/* Takes 3 random nodes that we know and puts them in nodes 603/* Takes 3 random nodes that we know and puts them in nodes
586 * 604 *
587 * nodes must be longer than 3. 605 * nodes must be longer than 3.
@@ -598,7 +616,7 @@ int random_path(Onion_Client *onion_c, Node_format *nodes)
598 return 0; 616 return 0;
599} 617}
600 618
601#define ANNOUNCE_FRIEND 30 619#define ANNOUNCE_FRIEND 120
602 620
603static void do_friend(Onion_Client *onion_c, uint16_t friendnum) 621static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
604{ 622{
@@ -611,32 +629,35 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
611 uint32_t i, count = 0; 629 uint32_t i, count = 0;
612 Onion_Node *list_nodes = onion_c->friends_list[friendnum].clients_list; 630 Onion_Node *list_nodes = onion_c->friends_list[friendnum].clients_list;
613 631
614 for (i = 0; i < MAX_ONION_CLIENTS; ++i) { 632 if (!onion_c->friends_list[friendnum].is_online) {
615 if (is_timeout(list_nodes[i].timestamp, ONION_NODE_TIMEOUT)) 633 for (i = 0; i < MAX_ONION_CLIENTS; ++i) {
616 continue; 634 if (is_timeout(list_nodes[i].timestamp, ONION_NODE_TIMEOUT))
635 continue;
617 636
618 ++count; 637 ++count;
619 638
620 if (is_timeout(list_nodes[i].last_pinged, ANNOUNCE_FRIEND)) { 639 if (is_timeout(list_nodes[i].last_pinged, ANNOUNCE_FRIEND)) {
621 if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port, list_nodes[i].client_id, 0) == 0) { 640 if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port, list_nodes[i].client_id, 0) == 0) {
622 list_nodes[i].last_pinged = unix_time(); 641 list_nodes[i].last_pinged = unix_time();
642 }
623 } 643 }
624 } 644 }
625 }
626 645
627 if (count < MAX_ONION_CLIENTS / 2) { 646 if (count < MAX_ONION_CLIENTS / 2) {
628 Node_format nodes_list[MAX_SENT_NODES]; 647 Node_format nodes_list[MAX_SENT_NODES];
629 uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->friends_list[friendnum].real_client_id, nodes_list, 648 uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->friends_list[friendnum].real_client_id, nodes_list,
630 rand() % 2 ? AF_INET : AF_INET6, 1, 0); 649 rand() % 2 ? AF_INET : AF_INET6, 1, 0);
650
651 for (i = 0; i < num_nodes; ++i)
652 client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0);
653 }
631 654
632 for (i = 0; i < num_nodes; ++i)
633 client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0);
634 }
635 655
636 /* send packets to friend telling them our fake DHT id. */ 656 /* send packets to friend telling them our fake DHT id. */
637 if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_sent, ONION_FAKEID_INTERVAL)) 657 if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_sent, ONION_FAKEID_INTERVAL))
638 if (send_fakeid_announce(onion_c, friendnum) > 1) 658 if (send_fakeid_announce(onion_c, friendnum) > 1)
639 onion_c->friends_list[friendnum].last_fakeid_sent = unix_time(); 659 onion_c->friends_list[friendnum].last_fakeid_sent = unix_time();
660 }
640} 661}
641/* Function to call when onion data packet with contents beginning with byte is received. */ 662/* Function to call when onion data packet with contents beginning with byte is received. */
642void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_callback cb, void *object) 663void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_callback cb, void *object)
@@ -646,7 +667,7 @@ void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_ha
646} 667}
647 668
648#define ANNOUNCE_INTERVAL_NOT_ANNOUNCED 10 669#define ANNOUNCE_INTERVAL_NOT_ANNOUNCED 10
649#define ANNOUNCE_INTERVAL_ANNOUNCED 60 670#define ANNOUNCE_INTERVAL_ANNOUNCED 120
650 671
651static void do_announce(Onion_Client *onion_c) 672static void do_announce(Onion_Client *onion_c)
652{ 673{
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h
index 417e7f80..78587846 100644
--- a/toxcore/onion_client.h
+++ b/toxcore/onion_client.h
@@ -27,7 +27,7 @@
27#include "onion_announce.h" 27#include "onion_announce.h"
28 28
29#define MAX_ONION_CLIENTS 8 29#define MAX_ONION_CLIENTS 8
30#define ONION_NODE_TIMEOUT 200 30#define ONION_NODE_TIMEOUT 240
31 31
32/* The interval in seconds at which to tell our friends where we are */ 32/* The interval in seconds at which to tell our friends where we are */
33#define ONION_FAKEID_INTERVAL 60 33#define ONION_FAKEID_INTERVAL 60
@@ -43,6 +43,7 @@ typedef struct {
43 43
44typedef struct { 44typedef struct {
45 uint8_t status; /* 0 if friend is not valid, 1 if friend is valid.*/ 45 uint8_t status; /* 0 if friend is not valid, 1 if friend is valid.*/
46 uint8_t is_online; /* Set by the onion_set_friend_status function. */
46 47
47 uint8_t fake_client_id[crypto_box_PUBLICKEYBYTES]; 48 uint8_t fake_client_id[crypto_box_PUBLICKEYBYTES];
48 uint8_t real_client_id[crypto_box_PUBLICKEYBYTES]; 49 uint8_t real_client_id[crypto_box_PUBLICKEYBYTES];
@@ -94,6 +95,17 @@ int onion_addfriend(Onion_Client *onion_c, uint8_t *client_id);
94 */ 95 */
95int onion_delfriend(Onion_Client *onion_c, int friend_num); 96int onion_delfriend(Onion_Client *onion_c, int friend_num);
96 97
98/* Set if friend is online or not.
99 * NOTE: This function is there and should be used so that we don't send useless packets to the friend if he is online.
100 *
101 * is_online 1 means friend is online.
102 * is_online 0 means friend is offline
103 *
104 * return -1 on failure.
105 * return 0 on success.
106 */
107int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_online);
108
97/* Get the ip of friend friendnum and put it in ip_port 109/* Get the ip of friend friendnum and put it in ip_port
98 * 110 *
99 * return -1, -- if client_id does NOT refer to a friend 111 * return -1, -- if client_id does NOT refer to a friend