summaryrefslogtreecommitdiff
path: root/toxcore/TCP_connection.h
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-04-15 19:47:57 -0400
committerirungentoo <irungentoo@gmail.com>2015-04-15 19:47:57 -0400
commit34265616bd2e4570bd5e7e1a3636ef22f1bb5ab1 (patch)
tree3afff77ab4077839852fb4d2b7081a209c4068d2 /toxcore/TCP_connection.h
parent2ff39d3d546e39803f8416f521b23f8cf0a8dd87 (diff)
Some work done on TCP_Connection.
The main thing left to do is the reconnect if we get disconnected part.
Diffstat (limited to 'toxcore/TCP_connection.h')
-rw-r--r--toxcore/TCP_connection.h35
1 files changed, 30 insertions, 5 deletions
diff --git a/toxcore/TCP_connection.h b/toxcore/TCP_connection.h
index fc7925a3..2c86304f 100644
--- a/toxcore/TCP_connection.h
+++ b/toxcore/TCP_connection.h
@@ -68,8 +68,8 @@ typedef struct {
68 int (*tcp_data_callback)(void *object, int id, const uint8_t *data, uint16_t length); 68 int (*tcp_data_callback)(void *object, int id, const uint8_t *data, uint16_t length);
69 void *tcp_data_callback_object; 69 void *tcp_data_callback_object;
70 70
71 int (*tcp_oob_callback)(void *object, const uint8_t *public_key, const uint8_t *relay_pk, const uint8_t *data, 71 int (*tcp_oob_callback)(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
72 uint16_t length); 72 const uint8_t *data, uint16_t length);
73 void *tcp_oob_callback_object; 73 void *tcp_oob_callback_object;
74 74
75 int (*tcp_onion_callback)(void *object, const uint8_t *data, uint16_t length); 75 int (*tcp_onion_callback)(void *object, const uint8_t *data, uint16_t length);
@@ -83,7 +83,7 @@ typedef struct {
83 * return -1 on failure. 83 * return -1 on failure.
84 * return 0 on success. 84 * return 0 on success.
85 */ 85 */
86int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, uint8_t *packet, uint16_t length); 86int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, const uint8_t *packet, uint16_t length);
87 87
88/* Return a random TCP connection number for use in send_tcp_onion_request. 88/* Return a random TCP connection number for use in send_tcp_onion_request.
89 * 89 *
@@ -103,12 +103,20 @@ int get_random_tcp_conn_number(TCP_Connections *tcp_c);
103int tcp_send_onion_request(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *data, 103int tcp_send_onion_request(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *data,
104 uint16_t length); 104 uint16_t length);
105 105
106/* Send an oob packet via the TCP relay corresponding to tcp_connections_number.
107 *
108 * return 0 on success.
109 * return -1 on failure.
110 */
111int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *public_key,
112 const uint8_t *packet, uint16_t length);
113
106/* Set the callback for TCP data packets. 114/* Set the callback for TCP data packets.
107 */ 115 */
108void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_data_callback)(void *object, int id, 116void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_data_callback)(void *object, int id,
109 const uint8_t *data, uint16_t length), void *object); 117 const uint8_t *data, uint16_t length), void *object);
110 118
111/* Set the callback for TCP oob data packets. 119/* Set the callback for TCP onion packets.
112 */ 120 */
113void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_onion_callback)(void *object, 121void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_onion_callback)(void *object,
114 const uint8_t *data, uint16_t length), void *object); 122 const uint8_t *data, uint16_t length), void *object);
@@ -116,7 +124,7 @@ void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_
116/* Set the callback for TCP oob data packets. 124/* Set the callback for TCP oob data packets.
117 */ 125 */
118void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_oob_callback)(void *object, 126void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_oob_callback)(void *object,
119 const uint8_t *public_key, const uint8_t *relay_pk, const uint8_t *data, uint16_t length), void *object); 127 const uint8_t *public_key, unsigned int tcp_connections_number, const uint8_t *data, uint16_t length), void *object);
120 128
121/* Create a new TCP connection to public_key. 129/* Create a new TCP connection to public_key.
122 * 130 *
@@ -134,6 +142,16 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
134 142
135/* Add a TCP relay tied to a connection. 143/* Add a TCP relay tied to a connection.
136 * 144 *
145 * NOTE: This can only be used during the tcp_oob_callback.
146 *
147 * return 0 on success.
148 * return -1 on failure.
149 */
150int add_tcp_number_relay_connection(TCP_Connections *tcp_c, int connections_number,
151 unsigned int tcp_connections_number);
152
153/* Add a TCP relay tied to a connection.
154 *
137 * return 0 on success. 155 * return 0 on success.
138 * return -1 on failure. 156 * return -1 on failure.
139 */ 157 */
@@ -146,6 +164,13 @@ int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, IP_
146 */ 164 */
147int add_tcp_relay_global(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t *relay_pk); 165int add_tcp_relay_global(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t *relay_pk);
148 166
167/* Copy a maximum of max_num TCP relays we are connected to to tcp_relays.
168 * NOTE that the family of the copied ip ports will be set to TCP_INET or TCP_INET6.
169 *
170 * return number of relays copied to tcp_relays on success.
171 * return 0 on failure.
172 */
173unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num);
149 174
150TCP_Connections *new_tcp_connections(DHT *dht); 175TCP_Connections *new_tcp_connections(DHT *dht);
151void do_tcp_connections(TCP_Connections *tcp_c); 176void do_tcp_connections(TCP_Connections *tcp_c);