Compare commits

..

3 Commits

Author SHA1 Message Date
30f96b780b disable lan 2023-12-16 20:44:23 +01:00
85a06de59a lower log level 2023-12-16 20:36:41 +01:00
6b5f40b4a0 add temp log callback 2023-12-16 19:13:49 +01:00
5 changed files with 21 additions and 27 deletions

View File

@ -164,9 +164,10 @@ configure_file(
target_include_directories(toxcore PRIVATE "${TOX_DIR}toxcore") target_include_directories(toxcore PRIVATE "${TOX_DIR}toxcore")
target_include_directories(toxcore PUBLIC "${TOX_DIR}") target_include_directories(toxcore PUBLIC "${TOX_DIR}")
target_compile_definitions(toxcore PUBLIC USE_IPV6=1) #target_compile_definitions(toxcore PUBLIC USE_IPV6=1)
target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE)
#target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_DEBUG) #target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_DEBUG)
target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_INFO) #target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_INFO)
find_package(unofficial-sodium CONFIG QUIET) find_package(unofficial-sodium CONFIG QUIET)
find_package(sodium QUIET) find_package(sodium QUIET)

View File

@ -182,11 +182,7 @@ static void kill_group_friend_connection(const GC_Session *c, const GC_Chat *cha
uint16_t gc_get_wrapped_packet_size(uint16_t length, Net_Packet_Type packet_type) uint16_t gc_get_wrapped_packet_size(uint16_t length, Net_Packet_Type packet_type)
{ {
if (packet_type == NET_PACKET_GC_LOSSY) { assert(length <= MAX_GC_PACKET_CHUNK_SIZE);
assert(length <= MAX_GC_CUSTOM_LOSSY_PACKET_SIZE);
} else {
assert(length <= MAX_GC_PACKET_CHUNK_SIZE);
}
const uint16_t min_header_size = packet_type == NET_PACKET_GC_LOSSY const uint16_t min_header_size = packet_type == NET_PACKET_GC_LOSSY
? GC_MIN_LOSSY_PAYLOAD_SIZE ? GC_MIN_LOSSY_PAYLOAD_SIZE
@ -231,13 +227,9 @@ GC_Connection *get_gc_connection(const GC_Chat *chat, int peer_number)
} }
/** Returns the amount of empty padding a packet of designated length should have. */ /** Returns the amount of empty padding a packet of designated length should have. */
static uint16_t group_packet_padding_length(uint16_t length, uint8_t net_packet_type) static uint16_t group_packet_padding_length(uint16_t length)
{ {
if (net_packet_type == NET_PACKET_GC_LOSSY) { return (MAX_GC_PACKET_CHUNK_SIZE - length) % GC_MAX_PACKET_PADDING;
return (MAX_GC_CUSTOM_LOSSY_PACKET_SIZE - length) % GC_MAX_PACKET_PADDING;
} else {
return (MAX_GC_PACKET_CHUNK_SIZE - length) % GC_MAX_PACKET_PADDING;
}
} }
void gc_get_self_nick(const GC_Chat *chat, uint8_t *nick) void gc_get_self_nick(const GC_Chat *chat, uint8_t *nick)
@ -1493,7 +1485,7 @@ int group_packet_wrap(
uint16_t packet_size, const uint8_t *data, uint16_t length, uint64_t message_id, uint16_t packet_size, const uint8_t *data, uint16_t length, uint64_t message_id,
uint8_t gp_packet_type, uint8_t net_packet_type) uint8_t gp_packet_type, uint8_t net_packet_type)
{ {
const uint16_t padding_len = group_packet_padding_length(length, net_packet_type); const uint16_t padding_len = group_packet_padding_length(length);
const uint16_t min_packet_size = net_packet_type == NET_PACKET_GC_LOSSLESS const uint16_t min_packet_size = net_packet_type == NET_PACKET_GC_LOSSLESS
? length + padding_len + CRYPTO_MAC_SIZE + 1 + ENC_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + GC_MESSAGE_ID_BYTES + 1 ? length + padding_len + CRYPTO_MAC_SIZE + 1 + ENC_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + GC_MESSAGE_ID_BYTES + 1
: length + padding_len + CRYPTO_MAC_SIZE + 1 + ENC_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + 1; : length + padding_len + CRYPTO_MAC_SIZE + 1 + ENC_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + 1;
@ -1503,16 +1495,9 @@ int group_packet_wrap(
return -1; return -1;
} }
if (net_packet_type == NET_PACKET_GC_LOSSY) { if (length > MAX_GC_PACKET_CHUNK_SIZE) {
if (length > MAX_GC_CUSTOM_LOSSY_PACKET_SIZE) { LOGGER_ERROR(log, "Packet payload size (%u) exceeds maximum (%u)", length, MAX_GC_PACKET_CHUNK_SIZE);
LOGGER_ERROR(log, "Packet payload size (%u) exceeds maximum (%u)", length, MAX_GC_CUSTOM_LOSSY_PACKET_SIZE); return -1;
return -1;
}
} else {
if (length > MAX_GC_PACKET_CHUNK_SIZE) {
LOGGER_ERROR(log, "Packet payload size (%u) exceeds maximum (%u)", length, MAX_GC_PACKET_CHUNK_SIZE);
return -1;
}
} }
uint8_t *plain = (uint8_t *)malloc(packet_size); uint8_t *plain = (uint8_t *)malloc(packet_size);
@ -1578,7 +1563,7 @@ non_null()
static bool send_lossy_group_packet(const GC_Chat *chat, const GC_Connection *gconn, const uint8_t *data, static bool send_lossy_group_packet(const GC_Chat *chat, const GC_Connection *gconn, const uint8_t *data,
uint16_t length, uint8_t packet_type) uint16_t length, uint8_t packet_type)
{ {
assert(length <= MAX_GC_CUSTOM_LOSSY_PACKET_SIZE); assert(length <= MAX_GC_PACKET_CHUNK_SIZE);
if (!gconn->handshaked || gconn->pending_delete) { if (!gconn->handshaked || gconn->pending_delete) {
return false; return false;

View File

@ -34,7 +34,7 @@
#define MAX_GC_MESSAGE_SIZE GROUP_MAX_MESSAGE_LENGTH #define MAX_GC_MESSAGE_SIZE GROUP_MAX_MESSAGE_LENGTH
#define MAX_GC_MESSAGE_RAW_SIZE (MAX_GC_MESSAGE_SIZE + GC_MESSAGE_PSEUDO_ID_SIZE) #define MAX_GC_MESSAGE_RAW_SIZE (MAX_GC_MESSAGE_SIZE + GC_MESSAGE_PSEUDO_ID_SIZE)
#define MAX_GC_CUSTOM_LOSSLESS_PACKET_SIZE 1373 #define MAX_GC_CUSTOM_LOSSLESS_PACKET_SIZE 1373
#define MAX_GC_CUSTOM_LOSSY_PACKET_SIZE 1000 #define MAX_GC_CUSTOM_LOSSY_PACKET_SIZE MAX_GC_PACKET_CHUNK_SIZE
#define MAX_GC_PASSWORD_SIZE 32 #define MAX_GC_PASSWORD_SIZE 32
#define MAX_GC_SAVED_INVITES 10 #define MAX_GC_SAVED_INVITES 10
#define MAX_GC_PEERS_DEFAULT 100 #define MAX_GC_PEERS_DEFAULT 100

View File

@ -3307,7 +3307,7 @@ uint32_t tox_group_max_message_length(void);
/** /**
* Maximum length of a group custom lossy packet. * Maximum length of a group custom lossy packet.
*/ */
#define TOX_GROUP_MAX_CUSTOM_LOSSY_PACKET_LENGTH 1000 #define TOX_GROUP_MAX_CUSTOM_LOSSY_PACKET_LENGTH 500
uint32_t tox_group_max_custom_lossy_packet_length(void); uint32_t tox_group_max_custom_lossy_packet_length(void);

View File

@ -1,4 +1,5 @@
#include "./tox_client.hpp" #include "./tox_client.hpp"
#include "toxcore/tox.h"
// meh, change this // meh, change this
#include <exception> #include <exception>
@ -18,6 +19,10 @@ static void eee(std::string& mod) {
} }
} }
static void tmp_tox_log_cb(Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func, const char *message, void *user_data) {
std::cerr << "l:" << level << " " << file << ":" << line << "@" << func << "(): '" << message << "'\n";
}
ToxClient::ToxClient(std::string_view save_path, std::string_view save_password) : ToxClient::ToxClient(std::string_view save_path, std::string_view save_password) :
_tox_profile_path(save_path), _tox_profile_password(save_password) _tox_profile_path(save_path), _tox_profile_password(save_password)
{ {
@ -67,6 +72,9 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password)
} }
} }
tox_options_set_local_discovery_enabled(options, false);
tox_options_set_log_callback(options, tmp_tox_log_cb);
TOX_ERR_NEW err_new; TOX_ERR_NEW err_new;
_tox = tox_new(options, &err_new); _tox = tox_new(options, &err_new);
tox_options_free(options); tox_options_free(options);