summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-05-18 10:55:38 -0400
committerirungentoo <irungentoo@gmail.com>2014-05-18 10:55:38 -0400
commite87929e869d3d63eb4800d1c74daf099e2f0a264 (patch)
treec74578eca2df52803cdde8a3bd4fca9cb697c8ef /toxcore/net_crypto.c
parent9d4947ffa5bb176628528887f46bcd0b405a9edd (diff)
TCP branch now ready for start of real testing.
Friends can now exchange TCP relay addresses so that they can connect together. Currently all bootstrap nodes are treated as TCP relays.
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.