Compare commits

...

2 Commits

7 changed files with 49 additions and 25 deletions

View File

@ -170,7 +170,11 @@ 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)
{
if (packet_type == NET_PACKET_GC_LOSSY) {
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
? GC_MIN_LOSSY_PAYLOAD_SIZE
@ -215,10 +219,14 @@ 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. */
static uint16_t group_packet_padding_length(uint16_t length)
static uint16_t group_packet_padding_length(uint16_t length, uint8_t net_packet_type)
{
if (net_packet_type == NET_PACKET_GC_LOSSY) {
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)
{
@ -1473,7 +1481,7 @@ int group_packet_wrap(
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)
{
const uint16_t padding_len = group_packet_padding_length(length);
const uint16_t padding_len = group_packet_padding_length(length, net_packet_type);
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 + 1;
@ -1483,10 +1491,17 @@ int group_packet_wrap(
return -1;
}
if (net_packet_type == NET_PACKET_GC_LOSSY) {
if (length > MAX_GC_CUSTOM_LOSSY_PACKET_SIZE) {
LOGGER_ERROR(log, "Packet payload size (%u) exceeds maximum (%u)", length, MAX_GC_CUSTOM_LOSSY_PACKET_SIZE);
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);
@ -1551,7 +1566,7 @@ non_null()
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)
{
assert(length <= MAX_GC_PACKET_CHUNK_SIZE);
assert(length <= MAX_GC_CUSTOM_LOSSY_PACKET_SIZE);
if (!gconn->handshaked || gconn->pending_delete) {
return false;
@ -6392,13 +6407,13 @@ static int handle_gc_udp_packet(void *object, const IP_Port *ipp, const uint8_t
if (length <= MIN_UDP_PACKET_SIZE) {
LOGGER_WARNING(m->log, "Got UDP packet with invalid length: %u (expected %u to %u)", length,
MIN_UDP_PACKET_SIZE, MAX_GC_PACKET_CHUNK_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
MIN_UDP_PACKET_SIZE, MAX_GC_CUSTOM_LOSSY_PACKET_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
return -1;
}
if (length > MAX_GC_PACKET_CHUNK_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE) {
if (length > MAX_GC_CUSTOM_LOSSY_PACKET_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE) {
LOGGER_WARNING(m->log, "Got UDP packet with invalid length: %u (expected %u to %u)", length,
MIN_UDP_PACKET_SIZE, MAX_GC_PACKET_CHUNK_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
MIN_UDP_PACKET_SIZE, MAX_GC_CUSTOM_LOSSY_PACKET_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
return -1;
}

View File

@ -32,7 +32,7 @@
#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_CUSTOM_LOSSLESS_PACKET_SIZE 1373
#define MAX_GC_CUSTOM_LOSSY_PACKET_SIZE MAX_GC_PACKET_CHUNK_SIZE
#define MAX_GC_CUSTOM_LOSSY_PACKET_SIZE 1000
#define MAX_GC_PASSWORD_SIZE 32
#define MAX_GC_SAVED_INVITES 10
#define MAX_GC_PEERS_DEFAULT 100

View File

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

View File

@ -154,11 +154,11 @@ void ChatGui4::render(void) {
if (ImGui::BeginChild("message_log", {0, -100}, false, ImGuiWindowFlags_MenuBar)) {
if (ImGui::BeginMenuBar()) {
if (ImGui::BeginMenu("debug")) {
ImGui::Checkbox("show extra info", &_show_chat_extra_info);
if (ImGui::SmallButton("test")) {
_cr.emplace_or_replace<Contact::Components::AvatarFile>(*_selected_contact, "tomato_v1_256.png");
_cr.emplace_or_replace<Contact::Components::TagAvatarInvalidate>(*_selected_contact);
std::cout << "DEBUG: added AvatarFile comp to contact\n";
ImGui::Checkbox("show avatar transfers", &_show_chat_avatar_tf);
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
@ -466,7 +466,13 @@ void ChatGui4::renderMessageBodyText(Message3Registry& reg, const Message3 e) {
}
void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
if (reg.all_of<Message::Components::Transfer::FileKind>(e) && reg.get<Message::Components::Transfer::FileKind>(e).kind == 1) {
if (
!_show_chat_avatar_tf
&& (
reg.all_of<Message::Components::Transfer::FileKind>(e)
&& reg.get<Message::Components::Transfer::FileKind>(e).kind == 1
)
) {
// TODO: this looks ugly
ImGui::TextDisabled("set avatar");
return;

View File

@ -31,7 +31,8 @@ class ChatGui4 {
// TODO: per contact
std::string _text_input_buffer;
bool _show_chat_extra_info {true};
bool _show_chat_extra_info {false};
bool _show_chat_avatar_tf {false};
float TEXT_BASE_WIDTH {1};
float TEXT_BASE_HEIGHT {1};

View File

@ -109,7 +109,7 @@ void SettingsWindow::render(void) {
if (ImGui::BeginMenuBar()) {
ImGui::Separator();
if (ImGui::BeginMenu("Settings")) {
if (ImGui::MenuItem("show settings window")) {
if (ImGui::MenuItem("settings window")) {
_show_window = true;
}
ImGui::EndMenu();

View File

@ -140,14 +140,14 @@ void ToxAvatarManager::checkMsg(Message3Handle h) {
const auto& file_info = h.get<Message::Components::Transfer::FileInfo>();
const auto contact = h.get<Message::Components::ContactFrom>().c;
// TCS-2.2.4
if (file_info.total_size > 65536ul) {
// TODO: mark handled?
return; // too large
}
const auto contact = h.get<Message::Components::ContactFrom>().c;
// TCS-2.2.10
if (file_info.file_list.empty() || file_info.file_list.front().file_name.empty() || file_info.total_size == 0) {
// reset
@ -186,16 +186,18 @@ void ToxAvatarManager::checkMsg(Message3Handle h) {
h.emplace_or_replace<Components::TagAvatarImageHandled>();
} else {
const auto& supposed_file_hash = h.get<Message::Components::Transfer::FileID>().id;
// check file id for existing hash
if (std::filesystem::is_regular_file(file_path)) {
//const auto& supposed_file_hash = h.get<Message::Components::Transfer::FileID>().id;
// load file
// hash file
//_t.toxHash();
std::filesystem::remove(file_path); // hack, hard replace existing file
}
std::cout << "TAM: accepted avatar ft\n";
// if not already on disk
_accept_queue.push_back(AcceptEntry{h, file_path});
}