diff options
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 36 |
1 files changed, 36 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 | } |