blob: 89ccb50f1e2b02242caf56bddc8d6f8ea804253d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/*
* TCP_server.h -- Implementation of the TCP relay server part of Tox.
*
* Copyright (C) 2013 Tox project All Rights Reserved.
*
* This file is part of Tox.
*
* Tox is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tox is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "net_crypto.h"
#define MAX_INCOMMING_CONNECTIONS 32
#define TCP_MAX_BACKLOG MAX_INCOMMING_CONNECTIONS
#define MAX_PACKET_SIZE 8192
#define TCP_HANDSHAKE_PLAIN_SIZE (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES)
#define TCP_SERVER_HANDSHAKE_SIZE (crypto_box_NONCEBYTES + TCP_HANDSHAKE_PLAIN_SIZE + crypto_box_MACBYTES)
#define TCP_CLIENT_HANDSHAKE_SIZE (crypto_box_PUBLICKEYBYTES + TCP_SERVER_HANDSHAKE_SIZE)
enum {
TCP_STATUS_NO_STATUS,
TCP_STATUS_CONNECTED,
TCP_STATUS_UNCONFIRMED,
TCP_STATUS_CONFIRMED,
};
typedef struct {
uint8_t status;
sock_t sock;
uint8_t public_key[crypto_box_PUBLICKEYBYTES];
uint8_t recv_nonce[crypto_box_NONCEBYTES]; /* Nonce of received packets. */
uint8_t sent_nonce[crypto_box_NONCEBYTES]; /* Nonce of sent packets. */
uint8_t shared_key[crypto_box_BEFORENMBYTES];
uint16_t next_packet_length;
} TCP_Secure_Connection;
typedef struct {
sock_t *socks_listening;
unsigned int num_listening_socks;
uint8_t public_key[crypto_box_PUBLICKEYBYTES];
uint8_t secret_key[crypto_box_SECRETKEYBYTES];
TCP_Secure_Connection incomming_connection_queue[MAX_INCOMMING_CONNECTIONS];
uint16_t incomming_connection_queue_index;
TCP_Secure_Connection unconfirmed_connection_queue[MAX_INCOMMING_CONNECTIONS];
uint16_t unconfirmed_connection_queue_index;
} TCP_Server;
/* Create new TCP server instance.
*/
TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, uint16_t *ports, uint8_t *public_key,
uint8_t *secret_key);
/* Run the TCP_server
*/
void do_TCP_server(TCP_Server *TCP_server);
/* Kill the TCP server
*/
void kill_TCP_server(TCP_Server *TCP_server);
|