summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r--toxcore/net_crypto.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index b47460bc..7cbac43b 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -1823,6 +1823,41 @@ int add_tcp_relay(Net_Crypto *c, IP_Port ip_port, uint8_t *public_key)
1823 return -1; 1823 return -1;
1824} 1824}
1825 1825
1826/* Copy a maximum of num TCP relays we are connected to to tcp_relays.
1827 * NOTE that the family of the copied ip ports will be set to TCP_INET or TCP_INET6.
1828 *
1829 * return number of relays copied to tcp_relays on success.
1830 * return 0 on failure.
1831 */
1832unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, uint16_t num)
1833{
1834 if (num == 0)
1835 return 0;
1836
1837 uint32_t i;
1838 uint16_t copied = 0;
1839
1840 for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) {
1841 if (c->tcp_connections[i] != NULL) {
1842 memcpy(tcp_relays[copied].client_id, c->tcp_connections[i]->public_key, crypto_box_PUBLICKEYBYTES);
1843 tcp_relays[copied].ip_port = c->tcp_connections[i]->ip_port;
1844
1845 if (tcp_relays[copied].ip_port.ip.family == AF_INET) {
1846 tcp_relays[copied].ip_port.ip.family = TCP_INET;
1847 } else if (tcp_relays[copied].ip_port.ip.family == AF_INET6) {
1848 tcp_relays[copied].ip_port.ip.family = TCP_INET6;
1849 }
1850
1851 ++copied;
1852
1853 if (copied == num)
1854 return copied;
1855 }
1856 }
1857
1858 return copied;
1859}
1860
1826/* Add a connected tcp connection to the tcp_connections array. 1861/* Add a connected tcp connection to the tcp_connections array.
1827 * 1862 *
1828 * return 0 if it was added. 1863 * return 0 if it was added.