Compare commits

...

2 Commits

10 changed files with 172 additions and 17 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)
{
assert(length <= MAX_GC_PACKET_CHUNK_SIZE);
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,9 +219,13 @@ 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)
{
return (MAX_GC_PACKET_CHUNK_SIZE - length) % GC_MAX_PACKET_PADDING;
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,9 +1491,16 @@ int group_packet_wrap(
return -1;
}
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;
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

@ -55,6 +55,9 @@ add_executable(tomato
./settings_window.hpp
./settings_window.cpp
./tox_ui_utils.hpp
./tox_ui_utils.cpp
./chat_gui4.hpp
./chat_gui4.cpp
)

View File

@ -2,7 +2,6 @@
#include "./file_selector.hpp"
#include <cstdio>
#include <solanaceae/message3/components.hpp>
#include <solanaceae/tox_messages/components.hpp>
#include <solanaceae/contact/components.hpp>
@ -22,6 +21,7 @@
#include <vector>
#include <chrono>
#include <ctime>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <sstream>

View File

@ -19,7 +19,8 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::stri
tam(rmm, cr, conf),
sdlrtu(renderer_),
cg(conf, rmm, cr, sdlrtu),
sw(conf)
sw(conf),
tuiu(tc, conf)
{
tel.subscribeAll(tc);
@ -111,6 +112,7 @@ Screen* MainScreen::poll(bool& quit) {
cg.render();
sw.render();
tuiu.render();
if constexpr (false) {
ImGui::ShowDemoWindow();

View File

@ -22,6 +22,7 @@
#include "./sdlrenderer_texture_uploader.hpp"
#include "./chat_gui4.hpp"
#include "./settings_window.hpp"
#include "./tox_ui_utils.hpp"
#include <string>
#include <iostream>
@ -59,6 +60,7 @@ struct MainScreen final : public Screen {
ChatGui4 cg;
SettingsWindow sw;
ToxUIUtils tuiu;
MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins);
~MainScreen(void);

View File

@ -91,9 +91,16 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password)
{
// TODO: more/diff nodes
// you can change or add your own bs and tcprelays here, ideally closer to you
{"tox.plastiras.org", 443, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14
{"tox2.plastiras.org", 33445, "B6626D386BE7E3ACA107B46F48A5C4D522D29281750D44A0CBA6A2721E79C951", {}}, // DE tha14
//{"tox.plastiras.org", 33445, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14
{"104.244.74.69", 443, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14
{"104.244.74.69", 33445, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14
//{"tox2.plastiras.org", 33445, "B6626D386BE7E3ACA107B46F48A5C4D522D29281750D44A0CBA6A2721E79C951", {}}, // DE tha14
//{"tox4.plastiras.org", 33445, "836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409", {}}, // MD tha14
{"37.221.66.161", 443, "836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409", {}}, // MD tha14
{"37.221.66.161", 33445, "836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409", {}}, // MD tha14
};
for (size_t i = 0; i < sizeof(nodes)/sizeof(DHT_node); i ++) {

105
src/tox_ui_utils.cpp Normal file
View File

@ -0,0 +1,105 @@
#include "./tox_ui_utils.hpp"
#include <solanaceae/toxcore/tox_interface.hpp>
#include <solanaceae/toxcore/utils.hpp>
#include <solanaceae/util/config_model.hpp>
#include <imgui/imgui.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
ToxUIUtils::ToxUIUtils(
ToxI& t,
ConfigModelI& conf
) : _t(t), _conf(conf) {
}
void ToxUIUtils::render(void) {
{ // main window menubar injection
// assumes the window "tomato" was rendered already by cg
if (ImGui::Begin("tomato")) {
if (ImGui::BeginMenuBar()) {
ImGui::Separator();
if (ImGui::BeginMenu("Tox")) {
if (ImGui::MenuItem("add Friend by ID")) {
_show_add_friend_window = true;
}
if (ImGui::MenuItem("join Group by ID (ngc)")) {
_show_add_group_window = true;
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
}
ImGui::End();
}
if (_show_add_friend_window) {
if (ImGui::Begin("Tox add Friend", &_show_add_friend_window)) {
static char tox_id[TOX_ADDRESS_SIZE*2+1] = {};
ImGui::InputText("Tox ID", tox_id, TOX_ADDRESS_SIZE*2+1);
static std::string message = "Add me, I'm tomat";
ImGui::InputText("message", &message);
static Tox_Err_Friend_Add err = Tox_Err_Friend_Add::TOX_ERR_FRIEND_ADD_OK;
if (ImGui::Button("add")) {
// TODO: add string_view variant to utils
auto [_, err_r] = _t.toxFriendAdd(hex2bin(std::string{tox_id}), message);
err = err_r;
}
if (err != Tox_Err_Friend_Add::TOX_ERR_FRIEND_ADD_OK) {
ImGui::SameLine();
ImGui::Text("error adding friend (code: %d)", err);
}
}
ImGui::End();
}
if (_show_add_group_window) {
if (ImGui::Begin("Tox join Group", &_show_add_group_window)) {
ImGui::TextDisabled("NGC refers to the New DHT enabled Group Chats.");
ImGui::TextDisabled("Connecting via ID might take a very long time.");
static char chat_id[TOX_GROUP_CHAT_ID_SIZE*2+1] = {};
ImGui::InputText("chat ID", chat_id, TOX_GROUP_CHAT_ID_SIZE*2+1);
static std::string self_name = _conf.get_string("tox", "name").value_or("default_tomato");
ImGui::InputText("name to join with", &self_name);
static std::string password;
ImGui::InputText("password to join with", &password);
static Tox_Err_Group_Join err = Tox_Err_Group_Join::TOX_ERR_GROUP_JOIN_OK;
if (ImGui::Button("join")) {
auto [_, err_r] = _t.toxGroupJoin(
hex2bin(std::string{chat_id}), // TODO: add string_view variant to utils
self_name,
password
);
err = err_r;
{ // reset everything
for (size_t i = 0; i < sizeof(chat_id); i++) {
chat_id[i] = '\0';
}
self_name = _conf.get_string("tox", "name").value_or("default_tomato");
for (size_t i = 0; i < password.size(); i++) {
password.at(i) = '\0';
}
password.clear();
}
}
if (err != Tox_Err_Group_Join::TOX_ERR_GROUP_JOIN_OK) {
ImGui::SameLine();
ImGui::Text("error joining group (code: %d)", err);
}
}
ImGui::End();
}
}

21
src/tox_ui_utils.hpp Normal file
View File

@ -0,0 +1,21 @@
#pragma once
struct ToxI;
struct ConfigModelI;
class ToxUIUtils {
bool _show_add_friend_window {false};
bool _show_add_group_window {false};
ToxI& _t;
ConfigModelI& _conf;
public:
ToxUIUtils(
ToxI& t,
ConfigModelI& conf
);
void render(void);
};