/work/toxcore/TCP_server.h
Line | Count | Source |
1 | | /* SPDX-License-Identifier: GPL-3.0-or-later |
2 | | * Copyright © 2016-2026 The TokTok team. |
3 | | * Copyright © 2014 Tox project. |
4 | | */ |
5 | | |
6 | | /** |
7 | | * Implementation of the TCP relay server part of Tox. |
8 | | */ |
9 | | #ifndef C_TOXCORE_TOXCORE_TCP_SERVER_H |
10 | | #define C_TOXCORE_TOXCORE_TCP_SERVER_H |
11 | | |
12 | | #include <stdbool.h> |
13 | | #include <stdint.h> |
14 | | |
15 | | #include "attributes.h" |
16 | | #include "crypto_core.h" |
17 | | #include "forwarding.h" |
18 | | #include "logger.h" |
19 | | #include "mem.h" |
20 | | #include "mono_time.h" |
21 | | #include "net.h" |
22 | | #include "net_profile.h" |
23 | | #include "network.h" |
24 | | #include "onion.h" |
25 | | #include "rng.h" |
26 | | |
27 | | #ifdef __cplusplus |
28 | | extern "C" { |
29 | | #endif |
30 | | |
31 | 2.48k | #define MAX_INCOMING_CONNECTIONS 256 |
32 | | |
33 | 34 | #define TCP_MAX_BACKLOG MAX_INCOMING_CONNECTIONS |
34 | | |
35 | | #define ARRAY_ENTRY_SIZE 6 |
36 | | |
37 | | typedef enum TCP_Status { |
38 | | TCP_STATUS_NO_STATUS, |
39 | | TCP_STATUS_CONNECTED, |
40 | | TCP_STATUS_UNCONFIRMED, |
41 | | TCP_STATUS_CONFIRMED, |
42 | | } TCP_Status; |
43 | | |
44 | | typedef struct TCP_Server TCP_Server; |
45 | | |
46 | | const uint8_t *_Nonnull tcp_server_public_key(const TCP_Server *_Nonnull tcp_server); |
47 | | size_t tcp_server_listen_count(const TCP_Server *_Nonnull tcp_server); |
48 | | |
49 | | /** Create new TCP server instance. */ |
50 | | TCP_Server *_Nullable new_tcp_server(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns, |
51 | | bool ipv6_enabled, uint16_t num_sockets, const uint16_t *_Nonnull ports, |
52 | | const uint8_t *_Nonnull secret_key, Onion *_Nullable onion, Forwarding *_Nullable forwarding); |
53 | | /** Run the TCP_server */ |
54 | | void do_tcp_server(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time); |
55 | | |
56 | | /** Kill the TCP server */ |
57 | | void kill_tcp_server(TCP_Server *_Nullable tcp_server); |
58 | | /** @brief Returns a pointer to the net profile associated with `tcp_server`. |
59 | | * |
60 | | * Returns null if `tcp_server` is null. |
61 | | */ |
62 | | const Net_Profile *_Nullable tcp_server_get_net_profile(const TCP_Server *_Nullable tcp_server); |
63 | | |
64 | | #ifdef __cplusplus |
65 | | } /* extern "C" */ |
66 | | #endif |
67 | | |
68 | | #endif /* C_TOXCORE_TOXCORE_TCP_SERVER_H */ |