forked from Green-Sky/tomato
Squashed 'external/toxcore/c-toxcore/' changes from 11ab1d2a723..d9b8fa6098d
d9b8fa6098d fix: Fake broadcast address for 127.x.x.x aa649165a57 chore: Add code for future netprof TCP testing 9e5693de5ac chore: add to_string functions for netprof enums 52d915e6a90 cleanup: Heap allocate network profile objects 80fabd4a729 feat: Implement Tox network profiler 05abe083cb6 cleanup: Some random cleanups, mostly related to mem. 5cca24513b8 cleanup: Check that onion IP/Port packing worked. e092ecd1244 cleanup: Use tox memory allocator in some more places. 3cfe41c7587 fix: Avoid `memcpy`-ing structs into onion ping id data. e32ac001938 fix: Add more information on why the frame was not sent. ab887003687 fix: Allow TCP connections to fail `connect` calls. 7603170e663 refactor: Use tox memory in group connection allocations. 5bd8a85eb89 cleanup: Align internal logger with external on type of source line. e9bf524d9e1 cleanup: Add missing `#include` to sort_test.cc. d10c966b998 feat: Add `to_string` functions for toxencryptsave errors. 7bfd0dc8003 docs: Update the docs for group join functions 380dde9f2ae test: Add more logging to TCP connection constructor. 0f12f384c8c cleanup: Reduce stack frame sizes to below 4096 bytes. bc43cec0626 chore: Happy new year! fbe78f1702e cleanup: Add a `TOX_HIDE_DEPRECATED` check to hide deprecated symbols. 44d9da07e77 refactor: Use tox memory for group moderation/pack allocations. 7f26d520168 refactor: Use tox memory in group chats allocations. 2f62f3d0e77 refactor: Use tox Memory for group allocations. 8a968162041 chore: Add dispatch/events headers to bazel export. 2bbfb35abf6 docs: Output the error code string instead of int. in toxav logging d55d0e4eaef cleanup: Remove redundant code for checking if group exists 2a6dc643338 chore: Upgrade dependencies for websockify. fc0650601c1 fix: Allow peers to reconnect to group chats using a password git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: d9b8fa6098de6c074038b6664d2572627540b148
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "net_profile.h"
|
||||
#include "network.h"
|
||||
#include "util.h"
|
||||
|
||||
@ -109,11 +110,23 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value)
|
||||
non_null()
|
||||
static bool connect_sock_to(const Network *ns, const Logger *logger, const Memory *mem, Socket sock, const IP_Port *ip_port, const TCP_Proxy_Info *proxy_info)
|
||||
{
|
||||
Net_Err_Connect err;
|
||||
if (proxy_info->proxy_type != TCP_PROXY_NONE) {
|
||||
return net_connect(ns, mem, logger, sock, &proxy_info->ip_port);
|
||||
net_connect(ns, mem, logger, sock, &proxy_info->ip_port, &err);
|
||||
} else {
|
||||
return net_connect(ns, mem, logger, sock, ip_port);
|
||||
net_connect(ns, mem, logger, sock, ip_port, &err);
|
||||
}
|
||||
switch (err) {
|
||||
case NET_ERR_CONNECT_OK:
|
||||
case NET_ERR_CONNECT_FAILED: {
|
||||
/* nonblocking socket, connect will never return success */
|
||||
return true;
|
||||
}
|
||||
case NET_ERR_CONNECT_INVALID_FAMILY:
|
||||
return false;
|
||||
}
|
||||
LOGGER_ERROR(logger, "unexpected error code %s from net_connect", net_err_connect_to_string(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -582,7 +595,7 @@ void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwa
|
||||
TCP_Client_Connection *new_tcp_connection(
|
||||
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
|
||||
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
|
||||
const TCP_Proxy_Info *proxy_info)
|
||||
const TCP_Proxy_Info *proxy_info, Net_Profile *net_profile)
|
||||
{
|
||||
assert(logger != nullptr);
|
||||
assert(mem != nullptr);
|
||||
@ -591,6 +604,7 @@ TCP_Client_Connection *new_tcp_connection(
|
||||
assert(ns != nullptr);
|
||||
|
||||
if (!net_family_is_ipv4(ip_port->ip.family) && !net_family_is_ipv6(ip_port->ip.family)) {
|
||||
LOGGER_ERROR(logger, "Invalid IP family: %d", ip_port->ip.family.value);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -609,15 +623,26 @@ TCP_Client_Connection *new_tcp_connection(
|
||||
const Socket sock = net_socket(ns, family, TOX_SOCK_STREAM, TOX_PROTO_TCP);
|
||||
|
||||
if (!sock_valid(sock)) {
|
||||
LOGGER_ERROR(logger, "Failed to create TCP socket with family %d", family.value);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!set_socket_nosigpipe(ns, sock)) {
|
||||
LOGGER_ERROR(logger, "Failed to set TCP socket to ignore SIGPIPE");
|
||||
kill_sock(ns, sock);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!(set_socket_nonblock(ns, sock) && connect_sock_to(ns, logger, mem, sock, ip_port, proxy_info))) {
|
||||
if (!set_socket_nonblock(ns, sock)) {
|
||||
LOGGER_ERROR(logger, "Failed to set TCP socket to non-blocking");
|
||||
kill_sock(ns, sock);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!connect_sock_to(ns, logger, mem, sock, ip_port, proxy_info)) {
|
||||
Ip_Ntoa ip_ntoa;
|
||||
LOGGER_WARNING(logger, "Failed to connect TCP socket to %s:%u",
|
||||
net_ip_ntoa(&ip_port->ip, &ip_ntoa), net_ntohs(ip_port->port));
|
||||
kill_sock(ns, sock);
|
||||
return nullptr;
|
||||
}
|
||||
@ -625,6 +650,7 @@ TCP_Client_Connection *new_tcp_connection(
|
||||
TCP_Client_Connection *temp = (TCP_Client_Connection *)mem_alloc(mem, sizeof(TCP_Client_Connection));
|
||||
|
||||
if (temp == nullptr) {
|
||||
LOGGER_ERROR(logger, "Failed to allocate memory for TCP_Client_Connection");
|
||||
kill_sock(ns, sock);
|
||||
return nullptr;
|
||||
}
|
||||
@ -634,6 +660,7 @@ TCP_Client_Connection *new_tcp_connection(
|
||||
temp->con.rng = rng;
|
||||
temp->con.sock = sock;
|
||||
temp->con.ip_port = *ip_port;
|
||||
temp->con.net_profile = net_profile;
|
||||
memcpy(temp->public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(temp->self_public_key, self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
encrypt_precompute(temp->public_key, self_secret_key, temp->con.shared_key);
|
||||
@ -657,6 +684,7 @@ TCP_Client_Connection *new_tcp_connection(
|
||||
temp->status = TCP_CLIENT_CONNECTING;
|
||||
|
||||
if (generate_handshake(temp) == -1) {
|
||||
LOGGER_ERROR(logger, "Failed to generate handshake");
|
||||
kill_sock(ns, sock);
|
||||
mem_delete(mem, temp);
|
||||
return nullptr;
|
||||
@ -819,6 +847,8 @@ static int handle_tcp_client_packet(const Logger *logger, TCP_Client_Connection
|
||||
return -1;
|
||||
}
|
||||
|
||||
netprof_record_packet(conn->con.net_profile, data[0], length, PACKET_DIRECTION_RECV);
|
||||
|
||||
switch (data[0]) {
|
||||
case TCP_PACKET_ROUTING_RESPONSE:
|
||||
return handle_tcp_client_routing_response(conn, data, length);
|
||||
|
Reference in New Issue
Block a user