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-2023 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
@ -86,6 +86,7 @@
|
||||
#include "ccompat.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "net_profile.h"
|
||||
#include "util.h"
|
||||
|
||||
// Disable MSG_NOSIGNAL on systems not supporting it, e.g. Windows, FreeBSD
|
||||
@ -907,9 +908,14 @@ static void loglogdata(const Logger *log, const char *message, const uint8_t *bu
|
||||
}
|
||||
|
||||
int net_send(const Network *ns, const Logger *log,
|
||||
Socket sock, const uint8_t *buf, size_t len, const IP_Port *ip_port)
|
||||
Socket sock, const uint8_t *buf, size_t len, const IP_Port *ip_port, Net_Profile *net_profile)
|
||||
{
|
||||
const int res = ns->funcs->send(ns->obj, sock, buf, len);
|
||||
|
||||
if (res > 0) {
|
||||
netprof_record_packet(net_profile, buf[0], res, PACKET_DIRECTION_SEND);
|
||||
}
|
||||
|
||||
loglogdata(log, "T=>", buf, len, ip_port, res);
|
||||
return res;
|
||||
}
|
||||
@ -1013,6 +1019,8 @@ struct Networking_Core {
|
||||
uint16_t port;
|
||||
/* Our UDP socket. */
|
||||
Socket sock;
|
||||
|
||||
Net_Profile *udp_net_profile;
|
||||
};
|
||||
|
||||
Family net_family(const Networking_Core *net)
|
||||
@ -1098,6 +1106,11 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe
|
||||
loglogdata(net->log, "O=>", packet.data, packet.length, ip_port, res);
|
||||
|
||||
assert(res <= INT_MAX);
|
||||
|
||||
if (res == packet.length && packet.data != nullptr) {
|
||||
netprof_record_packet(net->udp_net_profile, packet.data[0], packet.length, PACKET_DIRECTION_SEND);
|
||||
}
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -1202,6 +1215,8 @@ void networking_poll(const Networking_Core *net, void *userdata)
|
||||
continue;
|
||||
}
|
||||
|
||||
netprof_record_packet(net->udp_net_profile, data[0], length, PACKET_DIRECTION_RECV);
|
||||
|
||||
const Packet_Handler *const handler = &net->packethandlers[data[0]];
|
||||
|
||||
if (handler->function == nullptr) {
|
||||
@ -1262,6 +1277,14 @@ Networking_Core *new_networking_ex(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Net_Profile *np = netprof_new(log, mem);
|
||||
|
||||
if (np == nullptr) {
|
||||
free(temp);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
temp->udp_net_profile = np;
|
||||
temp->ns = ns;
|
||||
temp->log = log;
|
||||
temp->mem = mem;
|
||||
@ -1278,6 +1301,7 @@ Networking_Core *new_networking_ex(
|
||||
char *strerror = net_new_strerror(neterror);
|
||||
LOGGER_ERROR(log, "failed to get a socket?! %d, %s", neterror, strerror);
|
||||
net_kill_strerror(strerror);
|
||||
netprof_kill(mem, temp->udp_net_profile);
|
||||
mem_delete(mem, temp);
|
||||
|
||||
if (error != nullptr) {
|
||||
@ -1485,6 +1509,7 @@ void kill_networking(Networking_Core *net)
|
||||
kill_sock(net->ns, net->sock);
|
||||
}
|
||||
|
||||
netprof_kill(net->mem, net->udp_net_profile);
|
||||
mem_delete(net->mem, net);
|
||||
}
|
||||
|
||||
@ -2015,7 +2040,21 @@ bool addr_resolve_or_parse_ip(const Network *ns, const Memory *mem, const char *
|
||||
return addr_parse_ip(address, to);
|
||||
}
|
||||
|
||||
bool net_connect(const Network *ns, const Memory *mem, const Logger *log, Socket sock, const IP_Port *ip_port)
|
||||
const char *net_err_connect_to_string(Net_Err_Connect err)
|
||||
{
|
||||
switch (err) {
|
||||
case NET_ERR_CONNECT_OK:
|
||||
return "NET_ERR_CONNECT_OK";
|
||||
case NET_ERR_CONNECT_INVALID_FAMILY:
|
||||
return "NET_ERR_CONNECT_INVALID_FAMILY";
|
||||
case NET_ERR_CONNECT_FAILED:
|
||||
return "NET_ERR_CONNECT_FAILED";
|
||||
}
|
||||
|
||||
return "<invalid Net_Err_Connect>";
|
||||
}
|
||||
|
||||
bool net_connect(const Network *ns, const Memory *mem, const Logger *log, Socket sock, const IP_Port *ip_port, Net_Err_Connect *err)
|
||||
{
|
||||
Network_Addr addr = {{0}};
|
||||
|
||||
@ -2037,11 +2076,13 @@ bool net_connect(const Network *ns, const Memory *mem, const Logger *log, Socket
|
||||
Ip_Ntoa ip_str;
|
||||
LOGGER_ERROR(log, "cannot connect to %s:%d which is neither IPv4 nor IPv6",
|
||||
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port));
|
||||
*err = NET_ERR_CONNECT_INVALID_FAMILY;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
if ((true)) {
|
||||
*err = NET_ERR_CONNECT_OK;
|
||||
return true;
|
||||
}
|
||||
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
|
||||
@ -2060,10 +2101,12 @@ bool net_connect(const Network *ns, const Memory *mem, const Logger *log, Socket
|
||||
LOGGER_WARNING(log, "failed to connect to %s:%d: %d (%s)",
|
||||
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), error, net_strerror);
|
||||
net_kill_strerror(net_strerror);
|
||||
*err = NET_ERR_CONNECT_FAILED;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
*err = NET_ERR_CONNECT_OK;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2393,3 +2436,12 @@ void net_kill_strerror(char *strerror)
|
||||
free(strerror);
|
||||
#endif /* OS_WIN32 */
|
||||
}
|
||||
|
||||
const Net_Profile *net_get_net_profile(const Networking_Core *net)
|
||||
{
|
||||
if (net == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return net->udp_net_profile;
|
||||
}
|
||||
|
Reference in New Issue
Block a user