forked from Green-Sky/tomato
Squashed 'external/toxcore/c-toxcore/' changes from 640e6cace..e58eb27a8
e58eb27a8 fix(toxav): remove extra copy of video frame on encode Tested and works, but there might be alignment issues and other stuff. 206ea3530 refactor: Explicitly pass dependencies to constructors. 7cefa93cf fix(toxencryptsave): Wipe salt and passkey after usage. 7c3be2342 refactor: Add file/line to tox-bootstrapd logging. f84e8cdce refactor: Move loglogdata out of network.c. 390f7db06 refactor: Move random and memory OS-specifics to `os_*` files. REVERT: 640e6cace fix(toxav): remove extra copy of video frame on encode Tested and works, but there might be alignment issues and other stuff. git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: e58eb27a84f9fa0cd996868e079f39e90a5c04b6
This commit is contained in:
@@ -86,6 +86,7 @@
|
||||
#include "ccompat.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "net_log.h"
|
||||
#include "net_profile.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -714,170 +715,6 @@ static int net_getsockopt(const Network *_Nonnull ns, Socket sock, int level, in
|
||||
return ns->funcs->getsockopt(ns->obj, sock, level, optname, optval, optlen);
|
||||
}
|
||||
|
||||
static uint32_t data_0(uint16_t buflen, const uint8_t *_Nonnull buffer)
|
||||
{
|
||||
uint32_t data = 0;
|
||||
|
||||
if (buflen > 4) {
|
||||
net_unpack_u32(buffer + 1, &data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
static uint32_t data_1(uint16_t buflen, const uint8_t *_Nonnull buffer)
|
||||
{
|
||||
uint32_t data = 0;
|
||||
|
||||
if (buflen > 8) {
|
||||
net_unpack_u32(buffer + 5, &data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static const char *net_packet_type_name(Net_Packet_Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case NET_PACKET_PING_REQUEST:
|
||||
return "PING_REQUEST";
|
||||
|
||||
case NET_PACKET_PING_RESPONSE:
|
||||
return "PING_RESPONSE";
|
||||
|
||||
case NET_PACKET_NODES_REQUEST:
|
||||
return "NODES_REQUEST";
|
||||
|
||||
case NET_PACKET_NODES_RESPONSE:
|
||||
return "NODES_RESPONSE";
|
||||
|
||||
case NET_PACKET_COOKIE_REQUEST:
|
||||
return "COOKIE_REQUEST";
|
||||
|
||||
case NET_PACKET_COOKIE_RESPONSE:
|
||||
return "COOKIE_RESPONSE";
|
||||
|
||||
case NET_PACKET_CRYPTO_HS:
|
||||
return "CRYPTO_HS";
|
||||
|
||||
case NET_PACKET_CRYPTO_DATA:
|
||||
return "CRYPTO_DATA";
|
||||
|
||||
case NET_PACKET_CRYPTO:
|
||||
return "CRYPTO";
|
||||
|
||||
case NET_PACKET_GC_HANDSHAKE:
|
||||
return "GC_HANDSHAKE";
|
||||
|
||||
case NET_PACKET_GC_LOSSLESS:
|
||||
return "GC_LOSSLESS";
|
||||
|
||||
case NET_PACKET_GC_LOSSY:
|
||||
return "GC_LOSSY";
|
||||
|
||||
case NET_PACKET_LAN_DISCOVERY:
|
||||
return "LAN_DISCOVERY";
|
||||
|
||||
case NET_PACKET_ONION_SEND_INITIAL:
|
||||
return "ONION_SEND_INITIAL";
|
||||
|
||||
case NET_PACKET_ONION_SEND_1:
|
||||
return "ONION_SEND_1";
|
||||
|
||||
case NET_PACKET_ONION_SEND_2:
|
||||
return "ONION_SEND_2";
|
||||
|
||||
case NET_PACKET_ANNOUNCE_REQUEST_OLD:
|
||||
return "ANNOUNCE_REQUEST_OLD";
|
||||
|
||||
case NET_PACKET_ANNOUNCE_RESPONSE_OLD:
|
||||
return "ANNOUNCE_RESPONSE_OLD";
|
||||
|
||||
case NET_PACKET_ONION_DATA_REQUEST:
|
||||
return "ONION_DATA_REQUEST";
|
||||
|
||||
case NET_PACKET_ONION_DATA_RESPONSE:
|
||||
return "ONION_DATA_RESPONSE";
|
||||
|
||||
case NET_PACKET_ANNOUNCE_REQUEST:
|
||||
return "ANNOUNCE_REQUEST";
|
||||
|
||||
case NET_PACKET_ANNOUNCE_RESPONSE:
|
||||
return "ANNOUNCE_RESPONSE";
|
||||
|
||||
case NET_PACKET_ONION_RECV_3:
|
||||
return "ONION_RECV_3";
|
||||
|
||||
case NET_PACKET_ONION_RECV_2:
|
||||
return "ONION_RECV_2";
|
||||
|
||||
case NET_PACKET_ONION_RECV_1:
|
||||
return "ONION_RECV_1";
|
||||
|
||||
case NET_PACKET_FORWARD_REQUEST:
|
||||
return "FORWARD_REQUEST";
|
||||
|
||||
case NET_PACKET_FORWARDING:
|
||||
return "FORWARDING";
|
||||
|
||||
case NET_PACKET_FORWARD_REPLY:
|
||||
return "FORWARD_REPLY";
|
||||
|
||||
case NET_PACKET_DATA_SEARCH_REQUEST:
|
||||
return "DATA_SEARCH_REQUEST";
|
||||
|
||||
case NET_PACKET_DATA_SEARCH_RESPONSE:
|
||||
return "DATA_SEARCH_RESPONSE";
|
||||
|
||||
case NET_PACKET_DATA_RETRIEVE_REQUEST:
|
||||
return "DATA_RETRIEVE_REQUEST";
|
||||
|
||||
case NET_PACKET_DATA_RETRIEVE_RESPONSE:
|
||||
return "DATA_RETRIEVE_RESPONSE";
|
||||
|
||||
case NET_PACKET_STORE_ANNOUNCE_REQUEST:
|
||||
return "STORE_ANNOUNCE_REQUEST";
|
||||
|
||||
case NET_PACKET_STORE_ANNOUNCE_RESPONSE:
|
||||
return "STORE_ANNOUNCE_RESPONSE";
|
||||
|
||||
case BOOTSTRAP_INFO_PACKET_ID:
|
||||
return "BOOTSTRAP_INFO";
|
||||
|
||||
case NET_PACKET_MAX:
|
||||
return "MAX";
|
||||
}
|
||||
|
||||
return "<unknown>";
|
||||
}
|
||||
|
||||
static void loglogdata(const Logger *_Nonnull log, const char *_Nonnull message, const uint8_t *_Nonnull buffer, uint16_t buflen, const IP_Port *_Nonnull ip_port, long res)
|
||||
{
|
||||
if (res < 0) { /* Windows doesn't necessarily know `%zu` */
|
||||
Ip_Ntoa ip_str;
|
||||
const int error = net_error();
|
||||
Net_Strerror error_str;
|
||||
LOGGER_TRACE(log, "[%02x = %-21s] %s %3u%c %s:%u (%u: %s) | %08x%08x...%02x",
|
||||
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
|
||||
min_u16(buflen, 999), 'E',
|
||||
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), (unsigned int)error,
|
||||
net_strerror(error, &error_str), data_0(buflen, buffer), data_1(buflen, buffer), buffer[buflen - 1]);
|
||||
} else if ((res > 0) && ((size_t)res <= buflen)) {
|
||||
Ip_Ntoa ip_str;
|
||||
LOGGER_TRACE(log, "[%02x = %-21s] %s %3u%c %s:%u (%u: %s) | %08x%08x...%02x",
|
||||
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
|
||||
min_u16(res, 999), (size_t)res < buflen ? '<' : '=',
|
||||
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), (unsigned int)0, "OK",
|
||||
data_0(buflen, buffer), data_1(buflen, buffer), buffer[buflen - 1]);
|
||||
} else { /* empty or overwrite */
|
||||
Ip_Ntoa ip_str;
|
||||
LOGGER_TRACE(log, "[%02x = %-21s] %s %lu%c%u %s:%u (%u: %s) | %08x%08x...%02x",
|
||||
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
|
||||
(unsigned long)res, res == 0 ? '!' : '>', buflen,
|
||||
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), (unsigned int)0, "OK",
|
||||
data_0(buflen, buffer), data_1(buflen, buffer), buffer[buflen - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
int net_send(const Network *ns, const Logger *log,
|
||||
Socket sock, const uint8_t *buf, size_t len, const IP_Port *ip_port, Net_Profile *net_profile)
|
||||
{
|
||||
@@ -887,7 +724,7 @@ int net_send(const Network *ns, const Logger *log,
|
||||
netprof_record_packet(net_profile, buf[0], res, PACKET_DIRECTION_SEND);
|
||||
}
|
||||
|
||||
loglogdata(log, "T=>", buf, len, ip_port, res);
|
||||
net_log_data(log, "T=>", buf, len, ip_port, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -900,7 +737,7 @@ int net_recv(const Network *ns, const Logger *log,
|
||||
Socket sock, uint8_t *buf, size_t len, const IP_Port *ip_port)
|
||||
{
|
||||
const int res = ns->funcs->recv(ns->obj, sock, buf, len);
|
||||
loglogdata(log, "=>T", buf, len, ip_port, res);
|
||||
net_log_data(log, "=>T", buf, len, ip_port, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1068,7 +905,7 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe
|
||||
}
|
||||
|
||||
const long res = net_sendto(net->ns, net->sock, packet.data, packet.length, &addr, &ipp_copy);
|
||||
loglogdata(net->log, "O=>", packet.data, packet.length, ip_port, res);
|
||||
net_log_data(net->log, "O=>", packet.data, packet.length, ip_port, res);
|
||||
|
||||
assert(res <= INT_MAX);
|
||||
|
||||
@@ -1151,7 +988,7 @@ static int receivepacket(const Network *_Nonnull ns, const Logger *_Nonnull log,
|
||||
return -1;
|
||||
}
|
||||
|
||||
loglogdata(log, "=>O", data, MAX_UDP_PACKET_SIZE, ip_port, *length);
|
||||
net_log_data(log, "=>O", data, MAX_UDP_PACKET_SIZE, ip_port, *length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user