diff options
Diffstat (limited to 'toxcore/TCP_server.h')
-rw-r--r-- | toxcore/TCP_server.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/toxcore/TCP_server.h b/toxcore/TCP_server.h new file mode 100644 index 00000000..89ccb50f --- /dev/null +++ b/toxcore/TCP_server.h | |||
@@ -0,0 +1,75 @@ | |||
1 | /* | ||
2 | * TCP_server.h -- Implementation of the TCP relay server part of Tox. | ||
3 | * | ||
4 | * Copyright (C) 2013 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 | #include "net_crypto.h" | ||
24 | |||
25 | #define MAX_INCOMMING_CONNECTIONS 32 | ||
26 | |||
27 | #define TCP_MAX_BACKLOG MAX_INCOMMING_CONNECTIONS | ||
28 | |||
29 | #define MAX_PACKET_SIZE 8192 | ||
30 | |||
31 | #define TCP_HANDSHAKE_PLAIN_SIZE (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES) | ||
32 | #define TCP_SERVER_HANDSHAKE_SIZE (crypto_box_NONCEBYTES + TCP_HANDSHAKE_PLAIN_SIZE + crypto_box_MACBYTES) | ||
33 | #define TCP_CLIENT_HANDSHAKE_SIZE (crypto_box_PUBLICKEYBYTES + TCP_SERVER_HANDSHAKE_SIZE) | ||
34 | |||
35 | enum { | ||
36 | TCP_STATUS_NO_STATUS, | ||
37 | TCP_STATUS_CONNECTED, | ||
38 | TCP_STATUS_UNCONFIRMED, | ||
39 | TCP_STATUS_CONFIRMED, | ||
40 | }; | ||
41 | |||
42 | typedef struct { | ||
43 | uint8_t status; | ||
44 | sock_t sock; | ||
45 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | ||
46 | uint8_t recv_nonce[crypto_box_NONCEBYTES]; /* Nonce of received packets. */ | ||
47 | uint8_t sent_nonce[crypto_box_NONCEBYTES]; /* Nonce of sent packets. */ | ||
48 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | ||
49 | uint16_t next_packet_length; | ||
50 | } TCP_Secure_Connection; | ||
51 | |||
52 | typedef struct { | ||
53 | sock_t *socks_listening; | ||
54 | unsigned int num_listening_socks; | ||
55 | |||
56 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | ||
57 | uint8_t secret_key[crypto_box_SECRETKEYBYTES]; | ||
58 | TCP_Secure_Connection incomming_connection_queue[MAX_INCOMMING_CONNECTIONS]; | ||
59 | uint16_t incomming_connection_queue_index; | ||
60 | TCP_Secure_Connection unconfirmed_connection_queue[MAX_INCOMMING_CONNECTIONS]; | ||
61 | uint16_t unconfirmed_connection_queue_index; | ||
62 | } TCP_Server; | ||
63 | |||
64 | /* Create new TCP server instance. | ||
65 | */ | ||
66 | TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, uint16_t *ports, uint8_t *public_key, | ||
67 | uint8_t *secret_key); | ||
68 | |||
69 | /* Run the TCP_server | ||
70 | */ | ||
71 | void do_TCP_server(TCP_Server *TCP_server); | ||
72 | |||
73 | /* Kill the TCP server | ||
74 | */ | ||
75 | void kill_TCP_server(TCP_Server *TCP_server); | ||