Squashed 'external/toxcore/c-toxcore/' changes from c9cdae001..9ed2fa80d
9ed2fa80d fix(toxav): remove extra copy of video frame on encode de30cf3ad docs: Add new file kinds, that should be useful to all clients. d5b5e879d fix(DHT): Correct node skipping logic timed out nodes. 30e71fe97 refactor: Generate event dispatch functions and add tox_events_dispatch. 8fdbb0b50 style: Format parameter lists in event handlers. d00dee12b refactor: Add warning logs when losing chat invites. b144e8db1 feat: Add a way to look up a file number by ID. 849281ea0 feat: Add a way to fetch groups by chat ID. a2c177396 refactor: Harden event system and improve type safety. 8f5caa656 refactor: Add MessagePack string support to bin_pack. 34e8d5ad5 chore: Add GitHub CodeQL workflow and local Docker runner. f7b068010 refactor: Add nullability annotations to event headers. 788abe651 refactor(toxav): Use system allocator for mutexes. 2e4b423eb refactor: Use specific typedefs for public API arrays. 2baf34775 docs(toxav): update idle iteration interval see 679444751876fa3882a717772918ebdc8f083354 2f87ac67b feat: Add Event Loop abstraction (Ev). f8dfc38d8 test: Fix data race in ToxScenario virtual_clock. 38313921e test(TCP): Add regression test for TCP priority queue integrity. f94a50d9a refactor(toxav): Replace mutable_mutex with dynamically allocated mutex. ad054511e refactor: Internalize DHT structs and add debug helpers. 8b467cc96 fix: Prevent potential integer overflow in group chat handshake. 4962bdbb8 test: Improve TCP simulation and add tests 5f0227093 refactor: Allow nullable data in group chat handlers. e97b18ea9 chore: Improve Windows Docker support. b14943bbd refactor: Move Logger out of Messenger into Tox. dd3136250 cleanup: Apply nullability qualifiers to C++ codebase. 1849f70fc refactor: Extract low-level networking code to net and os_network. 8fec75421 refactor: Delete tox_random, align on rng and os_random. a03ae8051 refactor: Delete tox_memory, align on mem and os_memory. 4c88fed2c refactor: Use `std::` prefixes more consistently in C++ code. 72452f2ae test: Add some more tests for onion and shared key cache. d5a51b09a cleanup: Use tox_attributes.h in tox_private.h and install it. b6f5b9fc5 test: Add some benchmarks for various high level things. 8a8d02785 test(support): Introduce threaded Tox runner and simulation barrier d68d1d095 perf(toxav): optimize audio and video intermediate buffers by keeping them around REVERT: c9cdae001 fix(toxav): remove extra copy of video frame on encode git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: 9ed2fa80d582c714d6bdde6a7648220a92cddff8
This commit is contained in:
@@ -17,126 +17,14 @@
|
||||
#include "bin_pack.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "net.h"
|
||||
#include "net_profile.h"
|
||||
#include "os_network.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef bitwise int Socket_Value;
|
||||
typedef struct Socket {
|
||||
Socket_Value value;
|
||||
} Socket;
|
||||
|
||||
#define SIZE_IP4 4
|
||||
#define SIZE_IP6 16
|
||||
#define SIZE_IP (1 + SIZE_IP6)
|
||||
#define SIZE_PORT 2
|
||||
#define SIZE_IPPORT (SIZE_IP + SIZE_PORT)
|
||||
|
||||
typedef struct Family {
|
||||
uint8_t value;
|
||||
} Family;
|
||||
|
||||
typedef union IP4 {
|
||||
uint32_t uint32;
|
||||
uint16_t uint16[2];
|
||||
uint8_t uint8[4];
|
||||
} IP4;
|
||||
|
||||
typedef union IP6 {
|
||||
uint8_t uint8[16];
|
||||
uint16_t uint16[8];
|
||||
uint32_t uint32[4];
|
||||
uint64_t uint64[2];
|
||||
} IP6;
|
||||
|
||||
typedef union IP_Union {
|
||||
IP4 v4;
|
||||
IP6 v6;
|
||||
} IP_Union;
|
||||
|
||||
typedef struct IP {
|
||||
Family family;
|
||||
IP_Union ip;
|
||||
} IP;
|
||||
|
||||
typedef struct IP_Port {
|
||||
IP ip;
|
||||
uint16_t port;
|
||||
} IP_Port;
|
||||
|
||||
int net_socket_to_native(Socket sock);
|
||||
Socket net_socket_from_native(int sock);
|
||||
|
||||
typedef int net_close_cb(void *_Nullable obj, Socket sock);
|
||||
typedef Socket net_accept_cb(void *_Nullable obj, Socket sock);
|
||||
typedef int net_bind_cb(void *_Nullable obj, Socket sock, const IP_Port *_Nonnull addr);
|
||||
typedef int net_listen_cb(void *_Nullable obj, Socket sock, int backlog);
|
||||
typedef int net_connect_cb(void *_Nullable obj, Socket sock, const IP_Port *_Nonnull addr);
|
||||
typedef int net_recvbuf_cb(void *_Nullable obj, Socket sock);
|
||||
typedef int net_recv_cb(void *_Nullable obj, Socket sock, uint8_t *_Nonnull buf, size_t len);
|
||||
typedef int net_recvfrom_cb(void *_Nullable obj, Socket sock, uint8_t *_Nonnull buf, size_t len, IP_Port *_Nonnull addr);
|
||||
typedef int net_send_cb(void *_Nullable obj, Socket sock, const uint8_t *_Nonnull buf, size_t len);
|
||||
typedef int net_sendto_cb(void *_Nullable obj, Socket sock, const uint8_t *_Nonnull buf, size_t len, const IP_Port *_Nonnull addr);
|
||||
typedef Socket net_socket_cb(void *_Nullable obj, int domain, int type, int proto);
|
||||
typedef int net_socket_nonblock_cb(void *_Nullable obj, Socket sock, bool nonblock);
|
||||
typedef int net_getsockopt_cb(void *_Nullable obj, Socket sock, int level, int optname, void *_Nonnull optval, size_t *_Nonnull optlen);
|
||||
typedef int net_setsockopt_cb(void *_Nullable obj, Socket sock, int level, int optname, const void *_Nonnull optval, size_t optlen);
|
||||
typedef int net_getaddrinfo_cb(void *_Nullable obj, const Memory *_Nonnull mem, const char *_Nonnull address, int family, int protocol, IP_Port *_Nullable *_Nonnull addrs);
|
||||
typedef int net_freeaddrinfo_cb(void *_Nullable obj, const Memory *_Nonnull mem, IP_Port *_Nullable addrs);
|
||||
|
||||
/** @brief Functions wrapping POSIX network functions.
|
||||
*
|
||||
* Refer to POSIX man pages for documentation of what these functions are
|
||||
* expected to do when providing alternative Network implementations.
|
||||
*/
|
||||
typedef struct Network_Funcs {
|
||||
net_close_cb *_Nullable close;
|
||||
net_accept_cb *_Nullable accept;
|
||||
net_bind_cb *_Nullable bind;
|
||||
net_listen_cb *_Nullable listen;
|
||||
net_connect_cb *_Nullable connect;
|
||||
net_recvbuf_cb *_Nullable recvbuf;
|
||||
net_recv_cb *_Nullable recv;
|
||||
net_recvfrom_cb *_Nullable recvfrom;
|
||||
net_send_cb *_Nullable send;
|
||||
net_sendto_cb *_Nullable sendto;
|
||||
net_socket_cb *_Nullable socket;
|
||||
net_socket_nonblock_cb *_Nullable socket_nonblock;
|
||||
net_getsockopt_cb *_Nullable getsockopt;
|
||||
net_setsockopt_cb *_Nullable setsockopt;
|
||||
net_getaddrinfo_cb *_Nullable getaddrinfo;
|
||||
net_freeaddrinfo_cb *_Nullable freeaddrinfo;
|
||||
} Network_Funcs;
|
||||
|
||||
typedef struct Network {
|
||||
const Network_Funcs *_Nullable funcs;
|
||||
void *_Nullable obj;
|
||||
} Network;
|
||||
|
||||
const Network *_Nullable os_network(void);
|
||||
|
||||
bool net_family_is_unspec(Family family);
|
||||
bool net_family_is_ipv4(Family family);
|
||||
bool net_family_is_ipv6(Family family);
|
||||
bool net_family_is_tcp_server(Family family);
|
||||
bool net_family_is_tcp_client(Family family);
|
||||
bool net_family_is_tcp_ipv4(Family family);
|
||||
bool net_family_is_tcp_ipv6(Family family);
|
||||
bool net_family_is_tox_tcp_ipv4(Family family);
|
||||
bool net_family_is_tox_tcp_ipv6(Family family);
|
||||
|
||||
Family net_family_unspec(void);
|
||||
Family net_family_ipv4(void);
|
||||
Family net_family_ipv6(void);
|
||||
Family net_family_tcp_server(void);
|
||||
Family net_family_tcp_client(void);
|
||||
Family net_family_tcp_ipv4(void);
|
||||
Family net_family_tcp_ipv6(void);
|
||||
Family net_family_tox_tcp_ipv4(void);
|
||||
Family net_family_tox_tcp_ipv6(void);
|
||||
|
||||
#define MAX_UDP_PACKET_SIZE 2048
|
||||
|
||||
typedef enum Net_Packet_Type {
|
||||
@@ -192,25 +80,6 @@ typedef enum Net_Packet_Type {
|
||||
#define TOX_PORTRANGE_TO 33545
|
||||
#define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM
|
||||
|
||||
/** Redefinitions of variables for safe transfer over wire. */
|
||||
#define TOX_AF_UNSPEC 0
|
||||
#define TOX_AF_INET 2
|
||||
#define TOX_AF_INET6 10
|
||||
#define TOX_TCP_INET 130
|
||||
#define TOX_TCP_INET6 138
|
||||
|
||||
#define TOX_SOCK_STREAM 1
|
||||
#define TOX_SOCK_DGRAM 2
|
||||
|
||||
#define TOX_PROTO_TCP 1
|
||||
#define TOX_PROTO_UDP 2
|
||||
|
||||
/** TCP related */
|
||||
#define TCP_CLIENT_FAMILY (TOX_AF_INET6 + 1)
|
||||
#define TCP_INET (TOX_AF_INET6 + 2)
|
||||
#define TCP_INET6 (TOX_AF_INET6 + 3)
|
||||
#define TCP_SERVER_FAMILY (TOX_AF_INET6 + 4)
|
||||
|
||||
IP4 get_ip4_loopback(void);
|
||||
IP4 get_ip4_broadcast(void);
|
||||
|
||||
@@ -226,8 +95,6 @@ Socket net_socket(const Network *_Nonnull ns, Family domain, int type, int proto
|
||||
*/
|
||||
bool sock_valid(Socket sock);
|
||||
|
||||
Socket net_invalid_socket(void);
|
||||
|
||||
/**
|
||||
* Calls send(sockfd, buf, len, MSG_NOSIGNAL).
|
||||
*
|
||||
@@ -267,22 +134,6 @@ Socket net_accept(const Network *_Nonnull ns, Socket sock);
|
||||
*/
|
||||
uint16_t net_socket_data_recv_buffer(const Network *_Nonnull ns, Socket sock);
|
||||
|
||||
/** Convert values between host and network byte order. */
|
||||
uint32_t net_htonl(uint32_t hostlong);
|
||||
uint16_t net_htons(uint16_t hostshort);
|
||||
uint32_t net_ntohl(uint32_t hostlong);
|
||||
uint16_t net_ntohs(uint16_t hostshort);
|
||||
|
||||
size_t net_pack_bool(uint8_t *_Nonnull bytes, bool v);
|
||||
size_t net_pack_u16(uint8_t *_Nonnull bytes, uint16_t v);
|
||||
size_t net_pack_u32(uint8_t *_Nonnull bytes, uint32_t v);
|
||||
size_t net_pack_u64(uint8_t *_Nonnull bytes, uint64_t v);
|
||||
|
||||
size_t net_unpack_bool(const uint8_t *_Nonnull bytes, bool *_Nonnull v);
|
||||
size_t net_unpack_u16(const uint8_t *_Nonnull bytes, uint16_t *_Nonnull v);
|
||||
size_t net_unpack_u32(const uint8_t *_Nonnull bytes, uint32_t *_Nonnull v);
|
||||
size_t net_unpack_u64(const uint8_t *_Nonnull bytes, uint64_t *_Nonnull v);
|
||||
|
||||
/** Does the IP6 struct a contain an IPv4 address in an IPv6 one? */
|
||||
bool ipv6_ipv4_in_v6(const IP6 *_Nonnull a);
|
||||
|
||||
@@ -531,40 +382,6 @@ int unpack_ip_port(IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull data, uint
|
||||
*/
|
||||
bool bind_to_port(const Network *_Nonnull ns, Socket sock, Family family, uint16_t port);
|
||||
|
||||
/** @brief Get the last networking error code.
|
||||
*
|
||||
* Similar to Unix's errno, but cross-platform, as not all platforms use errno
|
||||
* to indicate networking errors.
|
||||
*
|
||||
* Note that different platforms may return different codes for the same error,
|
||||
* so you likely shouldn't be checking the value returned by this function
|
||||
* unless you know what you are doing, you likely just want to use it in
|
||||
* combination with `net_strerror()` to print the error.
|
||||
*
|
||||
* return platform-dependent network error code, if any.
|
||||
*/
|
||||
int net_error(void);
|
||||
|
||||
#define NET_STRERROR_SIZE 256
|
||||
|
||||
/** @brief Contains a null terminated formatted error message.
|
||||
*
|
||||
* This struct should not contain more than at most the 2 fields.
|
||||
*/
|
||||
typedef struct Net_Strerror {
|
||||
char data[NET_STRERROR_SIZE];
|
||||
uint16_t size;
|
||||
} Net_Strerror;
|
||||
|
||||
/** @brief Get a text explanation for the error code from `net_error()`.
|
||||
*
|
||||
* @param error The error code to get a string for.
|
||||
* @param buf The struct to store the error message in (usually on stack).
|
||||
*
|
||||
* @return pointer to a NULL-terminated string describing the error code.
|
||||
*/
|
||||
char *_Nonnull net_strerror(int error, Net_Strerror *_Nonnull buf);
|
||||
|
||||
/** @brief Initialize networking.
|
||||
* Bind to ip and port.
|
||||
* ip must be in network order EX: 127.0.0.1 = (7F000001).
|
||||
|
||||
Reference in New Issue
Block a user