diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 36 | ||||
-rw-r--r-- | toxcore/Messenger.h | 6 |
2 files changed, 42 insertions, 0 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 96005237..a32911fa 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -714,6 +714,25 @@ static int send_ping(Messenger *m, int32_t friendnumber) | |||
714 | return ret; | 714 | return ret; |
715 | } | 715 | } |
716 | 716 | ||
717 | static int send_relays(Messenger *m, int32_t friendnumber) | ||
718 | { | ||
719 | Node_format nodes[MAX_TCP_CONNECTIONS]; | ||
720 | uint8_t data[1024]; | ||
721 | int n, length; | ||
722 | |||
723 | n = copy_connected_tcp_relays(m->net_crypto, nodes, MAX_TCP_CONNECTIONS); | ||
724 | length = pack_nodes(data, sizeof(data), nodes, n); | ||
725 | |||
726 | int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_SHARE_RELAYS, data, length); | ||
727 | |||
728 | if (ret == 1) | ||
729 | m->friendlist[friendnumber].share_relays_lastsent = unix_time(); | ||
730 | |||
731 | return ret; | ||
732 | } | ||
733 | |||
734 | |||
735 | |||
717 | static int set_friend_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *status, uint16_t length) | 736 | static int set_friend_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *status, uint16_t length) |
718 | { | 737 | { |
719 | if (friend_not_valid(m, friendnumber)) | 738 | if (friend_not_valid(m, friendnumber)) |
@@ -2160,6 +2179,19 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len) | |||
2160 | (*m->msi_packet)(m, i, data, data_length, m->msi_packet_userdata); | 2179 | (*m->msi_packet)(m, i, data, data_length, m->msi_packet_userdata); |
2161 | } | 2180 | } |
2162 | 2181 | ||
2182 | case PACKET_ID_SHARE_RELAYS: { | ||
2183 | Node_format nodes[MAX_TCP_CONNECTIONS]; | ||
2184 | int n; | ||
2185 | |||
2186 | if ((n = unpack_nodes(nodes, MAX_TCP_CONNECTIONS, NULL, data, data_length, 1) == -1)) | ||
2187 | break; | ||
2188 | |||
2189 | int i; | ||
2190 | for(i = 0; i < n; i++) { | ||
2191 | add_tcp_relay(m->net_crypto, nodes[i].ip_port, nodes[i].client_id); | ||
2192 | } | ||
2193 | } | ||
2194 | |||
2163 | default: { | 2195 | default: { |
2164 | break; | 2196 | break; |
2165 | } | 2197 | } |
@@ -2274,6 +2306,10 @@ void do_friends(Messenger *m) | |||
2274 | m->friendlist[i].crypt_connection_id = -1; | 2306 | m->friendlist[i].crypt_connection_id = -1; |
2275 | set_friend_status(m, i, FRIEND_CONFIRMED); | 2307 | set_friend_status(m, i, FRIEND_CONFIRMED); |
2276 | } | 2308 | } |
2309 | |||
2310 | if (m->friendlist[i].share_relays_lastsent + FRIEND_SHARE_RELAYS_INTERVAL < temp_time) { | ||
2311 | send_relays(m, i); | ||
2312 | } | ||
2277 | } | 2313 | } |
2278 | } | 2314 | } |
2279 | } | 2315 | } |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index b72a0831..c505f1f1 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -41,6 +41,7 @@ | |||
41 | 41 | ||
42 | /* NOTE: Packet ids below 16 must never be used. */ | 42 | /* NOTE: Packet ids below 16 must never be used. */ |
43 | #define PACKET_ID_ALIVE 16 | 43 | #define PACKET_ID_ALIVE 16 |
44 | #define PACKET_ID_SHARE_RELAYS 17 | ||
44 | #define PACKET_ID_NICKNAME 48 | 45 | #define PACKET_ID_NICKNAME 48 |
45 | #define PACKET_ID_STATUSMESSAGE 49 | 46 | #define PACKET_ID_STATUSMESSAGE 49 |
46 | #define PACKET_ID_USERSTATUS 50 | 47 | #define PACKET_ID_USERSTATUS 50 |
@@ -88,9 +89,13 @@ enum { | |||
88 | /* Interval between the sending of ping packets. */ | 89 | /* Interval between the sending of ping packets. */ |
89 | #define FRIEND_PING_INTERVAL 5 | 90 | #define FRIEND_PING_INTERVAL 5 |
90 | 91 | ||
92 | /* Interval between the sending of tcp relay information */ | ||
93 | #define FRIEND_SHARE_RELAYS_INTERVAL (5 * 60) | ||
94 | |||
91 | /* If no packets are received from friend in this time interval, kill the connection. */ | 95 | /* If no packets are received from friend in this time interval, kill the connection. */ |
92 | #define FRIEND_CONNECTION_TIMEOUT (FRIEND_PING_INTERVAL * 2) | 96 | #define FRIEND_CONNECTION_TIMEOUT (FRIEND_PING_INTERVAL * 2) |
93 | 97 | ||
98 | |||
94 | /* USERSTATUS - | 99 | /* USERSTATUS - |
95 | * Represents userstatuses someone can have. | 100 | * Represents userstatuses someone can have. |
96 | */ | 101 | */ |
@@ -153,6 +158,7 @@ typedef struct { | |||
153 | uint32_t friendrequest_nospam; // The nospam number used in the friend request. | 158 | uint32_t friendrequest_nospam; // The nospam number used in the friend request. |
154 | uint64_t ping_lastrecv; | 159 | uint64_t ping_lastrecv; |
155 | uint64_t ping_lastsent; | 160 | uint64_t ping_lastsent; |
161 | uint64_t share_relays_lastsent; | ||
156 | struct File_Transfers file_sending[MAX_CONCURRENT_FILE_PIPES]; | 162 | struct File_Transfers file_sending[MAX_CONCURRENT_FILE_PIPES]; |
157 | struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES]; | 163 | struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES]; |
158 | int invited_groups[MAX_INVITED_GROUPS]; | 164 | int invited_groups[MAX_INVITED_GROUPS]; |