summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c13
-rw-r--r--toxcore/Messenger.h2
-rw-r--r--toxcore/TCP_connection.c4
-rw-r--r--toxcore/TCP_connection.h6
4 files changed, 19 insertions, 6 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index bd44115d..3233a466 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -755,11 +755,23 @@ static int send_user_istyping(const Messenger *m, int32_t friendnumber, uint8_t
755 755
756static int send_relays(const Messenger *m, int32_t friendnumber) 756static int send_relays(const Messenger *m, int32_t friendnumber)
757{ 757{
758 if (friend_not_valid(m, friendnumber))
759 return 0;
760
758 Node_format nodes[MAX_SHARED_RELAYS]; 761 Node_format nodes[MAX_SHARED_RELAYS];
759 uint8_t data[1024]; 762 uint8_t data[1024];
760 int n, length; 763 int n, length;
761 764
762 n = copy_connected_tcp_relays(m->net_crypto, nodes, MAX_SHARED_RELAYS); 765 n = copy_connected_tcp_relays(m->net_crypto, nodes, MAX_SHARED_RELAYS);
766
767 unsigned int i;
768
769 for (i = 0; i < n; ++i) {
770 /* Associated the relays being sent with this connection.
771 On receiving the peer will do the same which will establish the connection. */
772 friend_add_tcp_relay(m->fr_c, m->friendlist[friendnumber].friendcon_id, nodes[i].ip_port, nodes[i].public_key);
773 }
774
763 length = pack_nodes(data, sizeof(data), nodes, n); 775 length = pack_nodes(data, sizeof(data), nodes, n);
764 776
765 int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_SHARE_RELAYS, data, length, 0); 777 int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_SHARE_RELAYS, data, length, 0);
@@ -1914,6 +1926,7 @@ static int handle_status(void *object, int i, uint8_t status)
1914 m->friendlist[i].userstatus_sent = 0; 1926 m->friendlist[i].userstatus_sent = 0;
1915 m->friendlist[i].statusmessage_sent = 0; 1927 m->friendlist[i].statusmessage_sent = 0;
1916 m->friendlist[i].user_istyping_sent = 0; 1928 m->friendlist[i].user_istyping_sent = 0;
1929 m->friendlist[i].share_relays_lastsent = 0;
1917 } else { /* Went offline. */ 1930 } else { /* Went offline. */
1918 if (m->friendlist[i].status == FRIEND_ONLINE) { 1931 if (m->friendlist[i].status == FRIEND_ONLINE) {
1919 set_friend_status(m, i, FRIEND_CONFIRMED); 1932 set_friend_status(m, i, FRIEND_CONFIRMED);
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 63fb2820..e17bbb42 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -63,7 +63,7 @@ enum {
63#define PACKET_ID_LOSSY_GROUPCHAT 199 63#define PACKET_ID_LOSSY_GROUPCHAT 199
64 64
65/* Max number of tcp relays sent to friends */ 65/* Max number of tcp relays sent to friends */
66#define MAX_SHARED_RELAYS 16 66#define MAX_SHARED_RELAYS (RECOMMENDED_FRIEND_TCP_CONNECTIONS)
67 67
68/* All packets starting with a byte in this range can be used for anything. */ 68/* All packets starting with a byte in this range can be used for anything. */
69#define PACKET_ID_LOSSLESS_RANGE_START 160 69#define PACKET_ID_LOSSLESS_RANGE_START 160
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index 49a213a7..ab18daac 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -901,10 +901,10 @@ int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, IP_
901 */ 901 */
902unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num) 902unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num)
903{ 903{
904 unsigned int i, copied = 0; 904 unsigned int i, copied = 0, r = rand();
905 905
906 for (i = 0; (i < tcp_c->tcp_connections_length) && (copied < max_num); ++i) { 906 for (i = 0; (i < tcp_c->tcp_connections_length) && (copied < max_num); ++i) {
907 TCP_con *tcp_con = get_tcp_connection(tcp_c, i); 907 TCP_con *tcp_con = get_tcp_connection(tcp_c, (i + r) % tcp_c->tcp_connections_length);
908 908
909 if (!tcp_con) { 909 if (!tcp_con) {
910 continue; 910 continue;
diff --git a/toxcore/TCP_connection.h b/toxcore/TCP_connection.h
index 98f52f8d..07d7820c 100644
--- a/toxcore/TCP_connection.h
+++ b/toxcore/TCP_connection.h
@@ -34,14 +34,14 @@
34#define TCP_CONNECTIONS_STATUS_REGISTERED 1 34#define TCP_CONNECTIONS_STATUS_REGISTERED 1
35#define TCP_CONNECTIONS_STATUS_ONLINE 2 35#define TCP_CONNECTIONS_STATUS_ONLINE 2
36 36
37#define MAX_FRIEND_TCP_CONNECTIONS 4 37#define MAX_FRIEND_TCP_CONNECTIONS 6
38 38
39/* Time until connection to friend gets killed (if it doesn't get locked withing that time) */ 39/* Time until connection to friend gets killed (if it doesn't get locked withing that time) */
40#define TCP_CONNECTION_ANNOUNCE_TIMEOUT (TCP_CONNECTION_TIMEOUT) 40#define TCP_CONNECTION_ANNOUNCE_TIMEOUT (TCP_CONNECTION_TIMEOUT)
41 41
42/* The amount of recommended connections for each friend 42/* The amount of recommended connections for each friend
43 NOTE: Must be equal or smaller than MAX_FRIEND_TCP_CONNECTIONS */ 43 NOTE: Must be at most (MAX_FRIEND_TCP_CONNECTIONS / 2) */
44#define RECOMMENDED_FRIEND_TCP_CONNECTIONS 3 44#define RECOMMENDED_FRIEND_TCP_CONNECTIONS (MAX_FRIEND_TCP_CONNECTIONS / 2)
45 45
46typedef struct { 46typedef struct {
47 uint8_t status; 47 uint8_t status;