summaryrefslogtreecommitdiff
path: root/toxcore/TCP_server.h
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-03-19 20:19:51 -0400
committerirungentoo <irungentoo@gmail.com>2014-03-19 20:19:51 -0400
commitd0136733665e79484fc42e72d792a3c1f9383824 (patch)
tree5a35aa16354921152bc5e85c1202ce40f1d65fe7 /toxcore/TCP_server.h
parent91838f8c2d3f3bb30f23d20aeba4691ce797fb45 (diff)
A bit more code written for TCP servers.
Diffstat (limited to 'toxcore/TCP_server.h')
-rw-r--r--toxcore/TCP_server.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/toxcore/TCP_server.h b/toxcore/TCP_server.h
index 89ccb50f..504ffd77 100644
--- a/toxcore/TCP_server.h
+++ b/toxcore/TCP_server.h
@@ -32,6 +32,18 @@
32#define TCP_SERVER_HANDSHAKE_SIZE (crypto_box_NONCEBYTES + TCP_HANDSHAKE_PLAIN_SIZE + crypto_box_MACBYTES) 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) 33#define TCP_CLIENT_HANDSHAKE_SIZE (crypto_box_PUBLICKEYBYTES + TCP_SERVER_HANDSHAKE_SIZE)
34 34
35#define NUM_RESERVED_PORTS 16
36#define NUM_CLIENT_CONNECTIONS (256 - NUM_RESERVED_PORTS)
37
38#define TCP_PACKET_ROUTING_REQUEST 0
39#define TCP_PACKET_ROUTING_RESPONSE 1
40#define TCP_PACKET_CONNECTION_NOTIFICATION 2
41#define TCP_PACKET_DISCONNECT_NOTIFICATION 3
42#define TCP_PACKET_ONION_REQUEST 8
43#define TCP_PACKET_ONION_RESPONSE 9
44
45#define ARRAY_ENTRY_SIZE 6
46
35enum { 47enum {
36 TCP_STATUS_NO_STATUS, 48 TCP_STATUS_NO_STATUS,
37 TCP_STATUS_CONNECTED, 49 TCP_STATUS_CONNECTED,
@@ -39,7 +51,7 @@ enum {
39 TCP_STATUS_CONFIRMED, 51 TCP_STATUS_CONFIRMED,
40}; 52};
41 53
42typedef struct { 54typedef struct TCP_Secure_Connection {
43 uint8_t status; 55 uint8_t status;
44 sock_t sock; 56 sock_t sock;
45 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; 57 uint8_t public_key[crypto_box_PUBLICKEYBYTES];
@@ -47,8 +59,13 @@ typedef struct {
47 uint8_t sent_nonce[crypto_box_NONCEBYTES]; /* Nonce of sent packets. */ 59 uint8_t sent_nonce[crypto_box_NONCEBYTES]; /* Nonce of sent packets. */
48 uint8_t shared_key[crypto_box_BEFORENMBYTES]; 60 uint8_t shared_key[crypto_box_BEFORENMBYTES];
49 uint16_t next_packet_length; 61 uint16_t next_packet_length;
62 struct {
63 struct TCP_Secure_Connection *connection;
64 uint8_t other_id;
65 } connections[NUM_CLIENT_CONNECTIONS];
50} TCP_Secure_Connection; 66} TCP_Secure_Connection;
51 67
68
52typedef struct { 69typedef struct {
53 sock_t *socks_listening; 70 sock_t *socks_listening;
54 unsigned int num_listening_socks; 71 unsigned int num_listening_socks;
@@ -59,6 +76,10 @@ typedef struct {
59 uint16_t incomming_connection_queue_index; 76 uint16_t incomming_connection_queue_index;
60 TCP_Secure_Connection unconfirmed_connection_queue[MAX_INCOMMING_CONNECTIONS]; 77 TCP_Secure_Connection unconfirmed_connection_queue[MAX_INCOMMING_CONNECTIONS];
61 uint16_t unconfirmed_connection_queue_index; 78 uint16_t unconfirmed_connection_queue_index;
79
80 TCP_Secure_Connection *accepted_connection_array;
81 uint32_t size_accepted_connections;
82 uint32_t num_accepted_connections;
62} TCP_Server; 83} TCP_Server;
63 84
64/* Create new TCP server instance. 85/* Create new TCP server instance.