summaryrefslogtreecommitdiff
path: root/toxcore/TCP_client.h
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-04-06 20:51:03 -0400
committerirungentoo <irungentoo@gmail.com>2014-04-06 20:51:03 -0400
commitbd0d24fc9cad83d77cdf4bfd335ee5e25954c8ce (patch)
tree9776a8dea2573c866610a66d195f319652c84b27 /toxcore/TCP_client.h
parentef744ebbc29a3dc1ebc6c626b83c90ead15bb391 (diff)
Added TCP_client.
Some work done on the TCP part.
Diffstat (limited to 'toxcore/TCP_client.h')
-rw-r--r--toxcore/TCP_client.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/toxcore/TCP_client.h b/toxcore/TCP_client.h
new file mode 100644
index 00000000..eb2aa39c
--- /dev/null
+++ b/toxcore/TCP_client.h
@@ -0,0 +1,78 @@
1/*
2* TCP_client.h -- Implementation of the TCP relay client part of Tox.
3*
4* Copyright (C) 2014 Tox project All Rights Reserved.
5*
6* This file is part of Tox.
7*
8* Tox is free software: you can redistribute it and/or modify
9* it under the terms of the GNU General Public License as published by
10* the Free Software Foundation, either version 3 of the License, or
11* (at your option) any later version.
12*
13* Tox is distributed in the hope that it will be useful,
14* but WITHOUT ANY WARRANTY; without even the implied warranty of
15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16* GNU General Public License for more details.
17*
18* You should have received a copy of the GNU General Public License
19* along with Tox. If not, see <http://www.gnu.org/licenses/>.
20*
21*/
22
23
24#ifndef TCP_CLIENT_H
25#define TCP_CLIENT_H
26
27#include "net_crypto.h"
28#include "TCP_server.h"
29
30#define TCP_CONNECTION_TIMEOUT 10
31
32enum {
33 TCP_CLIENT_NO_STATUS,
34 TCP_CLIENT_CONNECTING,
35 TCP_CLIENT_UNCONFIRMED,
36 TCP_CLIENT_CONFIRMED,
37 TCP_CLIENT_DISCONNECTED,
38};
39typedef struct {
40 uint8_t status;
41 sock_t sock;
42 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* public key of the server */
43 uint8_t recv_nonce[crypto_box_NONCEBYTES]; /* Nonce of received packets. */
44 uint8_t sent_nonce[crypto_box_NONCEBYTES]; /* Nonce of sent packets. */
45 uint8_t shared_key[crypto_box_BEFORENMBYTES];
46 uint16_t next_packet_length;
47
48 uint8_t temp_secret_key[crypto_box_SECRETKEYBYTES];
49
50 uint8_t last_packet[2 + MAX_PACKET_SIZE];
51 uint16_t last_packet_length;
52 uint16_t last_packet_sent;
53
54 uint64_t kill_at;
55
56 uint64_t last_pinged;
57 uint64_t ping_id;
58} TCP_Client_Connection;
59
60/* Create new TCP connection to ip_port/public_key
61 */
62TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, uint8_t *public_key, uint8_t *self_public_key,
63 uint8_t *self_secret_key);
64
65/* Run the TCP connection
66 */
67void do_TCP_connection(TCP_Client_Connection *TCP_connection);
68
69/* Kill the TCP connection
70 */
71void kill_TCP_connection(TCP_Client_Connection *TCP_connection);
72
73int get_TCP_connection_status(TCP_Client_Connection *TCP_connection);
74
75int read_TCP_connection(TCP_Client_Connection *TCP_connection, uint8_t *data);
76
77
78#endif