Compare commits
27 Commits
cd28b26761
...
tmp_tox_lo
Author | SHA1 | Date | |
---|---|---|---|
30f96b780b | |||
85a06de59a | |||
6b5f40b4a0 | |||
7495a50723 | |||
1cdde5170b | |||
4248d1d9ab | |||
05d1648209 | |||
4f02c2b55b | |||
fd9d14d00c | |||
4e4f62dd20 | |||
cdc4284cb5 | |||
bedbacddde | |||
32a8dba185 | |||
d6e5051b15 | |||
780a67a40d | |||
0c7fff3029 | |||
e7db39d20a | |||
869edb8d84 | |||
dce42b866a | |||
da19b0ac31 | |||
bc090bdaa8 | |||
2a5937652e | |||
b9d4f594ce | |||
c79068c561 | |||
e7095a1849 | |||
3f78e17888 | |||
897253e1d6 |
2
external/solanaceae_contact
vendored
2
external/solanaceae_contact
vendored
Submodule external/solanaceae_contact updated: 738d2abe7b...2d73c7272c
2
external/solanaceae_message3
vendored
2
external/solanaceae_message3
vendored
Submodule external/solanaceae_message3 updated: c577a1fa3d...1a036c2321
2
external/solanaceae_plugin
vendored
2
external/solanaceae_plugin
vendored
Submodule external/solanaceae_plugin updated: 3bcb504a71...eeab3109e7
2
external/solanaceae_tox
vendored
2
external/solanaceae_tox
vendored
Submodule external/solanaceae_tox updated: 0e6556cd86...89e74b35f8
2
external/solanaceae_toxcore
vendored
2
external/solanaceae_toxcore
vendored
Submodule external/solanaceae_toxcore updated: dfa5a501ec...d05875f489
2
external/solanaceae_util
vendored
2
external/solanaceae_util
vendored
Submodule external/solanaceae_util updated: 92eee153f2...2b20c2d2a4
10
external/toxcore/CMakeLists.txt
vendored
10
external/toxcore/CMakeLists.txt
vendored
@@ -155,13 +155,19 @@ configure_file(
|
||||
${TOX_DIR}tox/tox_events.h
|
||||
@ONLY
|
||||
)
|
||||
configure_file(
|
||||
${TOX_DIR}toxcore/tox_private.h
|
||||
${TOX_DIR}tox/tox_private.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
target_include_directories(toxcore PRIVATE "${TOX_DIR}toxcore")
|
||||
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_INFO)
|
||||
#target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_INFO)
|
||||
|
||||
find_package(unofficial-sodium CONFIG QUIET)
|
||||
find_package(sodium QUIET)
|
||||
|
@@ -4,11 +4,9 @@ set -eux
|
||||
|
||||
git submodule update --init --recursive
|
||||
/src/workspace/tools/inject-repo c-toxcore
|
||||
# TODO(iphydf): Re-enable fuzz-test when https://github.com/tweag/rules_nixpkgs/issues/442 is fixed.
|
||||
cd /src/workspace && bazel test -k \
|
||||
--config=remote \
|
||||
--build_tag_filters=-haskell \
|
||||
--test_tag_filters=-haskell \
|
||||
--remote_download_minimal \
|
||||
--build_tag_filters=-haskell,-fuzz-test \
|
||||
--test_tag_filters=-haskell,-fuzz-test \
|
||||
-- \
|
||||
//c-toxcore/... \
|
||||
"$@"
|
||||
|
29
external/toxcore/c-toxcore/.circleci/config.yml
vendored
29
external/toxcore/c-toxcore/.circleci/config.yml
vendored
@@ -7,11 +7,11 @@ workflows:
|
||||
jobs:
|
||||
# Dynamic analysis in the Bazel build
|
||||
- bazel-asan
|
||||
- bazel-msan
|
||||
- bazel-tsan
|
||||
# Dynamic analysis with CMake
|
||||
- asan
|
||||
- tsan
|
||||
- msan
|
||||
- ubsan
|
||||
# Static analysis
|
||||
- clang-analyze
|
||||
@@ -29,6 +29,7 @@ jobs:
|
||||
steps:
|
||||
- checkout
|
||||
- run: .circleci/bazel-test
|
||||
//c-toxcore/...
|
||||
|
||||
bazel-tsan:
|
||||
working_directory: /tmp/cirrus-ci-build
|
||||
@@ -38,11 +39,22 @@ jobs:
|
||||
steps:
|
||||
- checkout
|
||||
- run: .circleci/bazel-test
|
||||
//c-toxcore/...
|
||||
-//c-toxcore/auto_tests:conference_av_test
|
||||
-//c-toxcore/auto_tests:conference_test
|
||||
-//c-toxcore/auto_tests:onion_test
|
||||
-//c-toxcore/auto_tests:tox_many_test
|
||||
|
||||
bazel-msan:
|
||||
working_directory: /tmp/cirrus-ci-build
|
||||
docker:
|
||||
- image: toxchat/toktok-stack:latest-msan
|
||||
|
||||
steps:
|
||||
- checkout
|
||||
- run: .circleci/bazel-test
|
||||
//c-toxcore/auto_tests:lossless_packet_test
|
||||
|
||||
asan:
|
||||
working_directory: ~/work
|
||||
docker:
|
||||
@@ -91,21 +103,6 @@ jobs:
|
||||
- run: git submodule update --init --recursive
|
||||
- run: CC=clang .circleci/cmake-ubsan
|
||||
|
||||
msan:
|
||||
working_directory: ~/work
|
||||
docker:
|
||||
- image: toxchat/toktok-stack:latest-msan
|
||||
|
||||
steps:
|
||||
- checkout
|
||||
- run: git submodule update --init --recursive
|
||||
- run: rm -rf /src/workspace/c-toxcore/* && mv * /src/workspace/c-toxcore/
|
||||
- run:
|
||||
cd /src/workspace && bazel test
|
||||
//c-toxcore/auto_tests:lossless_packet_test
|
||||
//c-toxcore/toxav/...
|
||||
//c-toxcore/toxcore/...
|
||||
|
||||
infer:
|
||||
working_directory: ~/work
|
||||
docker:
|
||||
|
8
external/toxcore/c-toxcore/.cirrus.yml
vendored
8
external/toxcore/c-toxcore/.cirrus.yml
vendored
@@ -9,10 +9,9 @@ bazel-opt_task:
|
||||
- /src/workspace/tools/inject-repo c-toxcore
|
||||
test_all_script:
|
||||
- cd /src/workspace && bazel test -k
|
||||
--remote_http_cache=http://$CIRRUS_HTTP_CACHE_HOST
|
||||
--config=ci
|
||||
--build_tag_filters=-haskell
|
||||
--test_tag_filters=-haskell
|
||||
--remote_download_minimal
|
||||
--
|
||||
//c-toxcore/...
|
||||
-//c-toxcore/auto_tests:tcp_relay_test # TODO(robinlinden): Why does this pass locally but not in Cirrus?
|
||||
@@ -27,10 +26,9 @@ bazel-dbg_task:
|
||||
- /src/workspace/tools/inject-repo c-toxcore
|
||||
test_all_script:
|
||||
- cd /src/workspace && bazel test -k
|
||||
--remote_http_cache=http://$CIRRUS_HTTP_CACHE_HOST
|
||||
--config=ci
|
||||
--build_tag_filters=-haskell
|
||||
--test_tag_filters=-haskell
|
||||
--remote_download_minimal
|
||||
--
|
||||
//c-toxcore/...
|
||||
-//c-toxcore/auto_tests:tcp_relay_test # TODO(robinlinden): Why does this pass locally but not in Cirrus?
|
||||
@@ -45,7 +43,7 @@ cimple_task:
|
||||
- /src/workspace/tools/inject-repo c-toxcore
|
||||
test_all_script:
|
||||
- cd /src/workspace && bazel test -k
|
||||
--remote_http_cache=http://$CIRRUS_HTTP_CACHE_HOST
|
||||
--config=ci
|
||||
--build_tag_filters=haskell
|
||||
--test_tag_filters=haskell
|
||||
--
|
||||
|
@@ -29,12 +29,26 @@ flaky_tests = {
|
||||
"tox_many_tcp_test": True,
|
||||
}
|
||||
|
||||
extra_args = {
|
||||
"proxy_test": ["$(location //c-toxcore/other/proxy)"],
|
||||
}
|
||||
|
||||
extra_data = {
|
||||
"proxy_test": ["//c-toxcore/other/proxy"],
|
||||
}
|
||||
|
||||
[cc_test(
|
||||
name = src[:-2],
|
||||
size = "small",
|
||||
srcs = [src],
|
||||
args = ["$(location %s)" % src] + ["$(location //c-toxcore/other/proxy)"],
|
||||
data = glob(["data/*"]) + ["//c-toxcore/other/proxy"],
|
||||
args = ["$(location %s)" % src] + extra_args.get(
|
||||
src[:-2],
|
||||
[],
|
||||
),
|
||||
data = glob(["data/*"]) + extra_data.get(
|
||||
src[:-2],
|
||||
[],
|
||||
),
|
||||
flaky = flaky_tests.get(
|
||||
src[:-2],
|
||||
False,
|
||||
|
@@ -122,6 +122,12 @@ static void test_dht_getnodes(AutoTox *autotoxes)
|
||||
|
||||
tox_self_get_dht_id(autotoxes[i].tox, public_key_list[i]);
|
||||
tox_callback_dht_get_nodes_response(autotoxes[i].tox, getnodes_response_cb);
|
||||
|
||||
printf("Peer %zu dht closenode count total/annouce-capable: %d/%d\n",
|
||||
i,
|
||||
tox_dht_get_num_closelist(autotoxes[i].tox),
|
||||
tox_dht_get_num_closelist_announce_capable(autotoxes[i].tox)
|
||||
);
|
||||
}
|
||||
|
||||
while (!all_nodes_crawled(autotoxes, NUM_TOXES, public_key_list)) {
|
||||
|
1
external/toxcore/c-toxcore/other/BUILD.bazel
vendored
1
external/toxcore/c-toxcore/other/BUILD.bazel
vendored
@@ -16,6 +16,7 @@ cc_binary(
|
||||
testonly = 1,
|
||||
srcs = ["DHT_bootstrap.c"],
|
||||
deps = [
|
||||
":bootstrap_node_packets",
|
||||
"//c-toxcore/testing:misc_tools",
|
||||
"//c-toxcore/toxcore:DHT",
|
||||
"//c-toxcore/toxcore:LAN_discovery",
|
||||
|
11
external/toxcore/c-toxcore/other/DHT_bootstrap.c
vendored
11
external/toxcore/c-toxcore/other/DHT_bootstrap.c
vendored
@@ -31,11 +31,16 @@
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
|
||||
#define DHT_NODE_EXTRA_PACKETS
|
||||
|
||||
#ifdef DHT_NODE_EXTRA_PACKETS
|
||||
#include "./bootstrap_node_packets.h"
|
||||
|
||||
#define DHT_VERSION_NUMBER 1
|
||||
#define DHT_MOTD "This is a test motd"
|
||||
#ifndef DAEMON_VERSION_NUMBER
|
||||
#define DAEMON_VERSION_NUMBER (1000000000UL + TOX_VERSION_MAJOR*1000000UL + TOX_VERSION_MINOR*1000UL + TOX_VERSION_PATCH*1UL)
|
||||
#endif
|
||||
|
||||
static const char *motd_str = ""; //Change this to anything within 256 bytes(but 96 bytes maximum prefered)
|
||||
#endif
|
||||
|
||||
#define PORT 33445
|
||||
@@ -152,7 +157,7 @@ int main(int argc, char *argv[])
|
||||
Onion_Announce *onion_a = new_onion_announce(logger, mem, rng, mono_time, dht);
|
||||
|
||||
#ifdef DHT_NODE_EXTRA_PACKETS
|
||||
bootstrap_set_callbacks(dht_get_net(dht), DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD));
|
||||
bootstrap_set_callbacks(dht_get_net(dht), (uint32_t)DAEMON_VERSION_NUMBER, (const uint8_t *) motd_str, strlen(motd_str)+1);
|
||||
#endif
|
||||
|
||||
if (!(onion && forwarding && onion_a)) {
|
||||
|
@@ -1 +1 @@
|
||||
4f5b47978dc26aed78719526f862a44693f821db12f5ff6d70b338d67fb6f784 /usr/local/bin/tox-bootstrapd
|
||||
b2996d73cab7c7453dc10ccf7ad733622558de3b1ad0db824a379cf96f500379 /usr/local/bin/tox-bootstrapd
|
||||
|
@@ -306,7 +306,7 @@ void generate_event_impl(const std::string& event_name, std::vector<EventType> e
|
||||
f << " Tox_Event_" << event_name << " *event, Bin_Unpack *bu)\n{\n";
|
||||
f << " assert(event != nullptr);\n";
|
||||
if (event_types.size() > 1) {
|
||||
f << " if (!bin_unpack_array_fixed(bu, " << event_types.size() << ")) {\n return false;\n }\n\n";
|
||||
f << " if (!bin_unpack_array_fixed(bu, " << event_types.size() << ", nullptr)) {\n return false;\n }\n\n";
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
|
@@ -28,7 +28,7 @@ cc_library(
|
||||
|
||||
cc_fuzz_test(
|
||||
name = "bootstrap_fuzz_test",
|
||||
#size = "small",
|
||||
size = "small",
|
||||
srcs = ["bootstrap_harness.cc"],
|
||||
copts = ["-UNDEBUG"],
|
||||
corpus = ["//tools/toktok-fuzzer/corpus:bootstrap_fuzzer"],
|
||||
@@ -43,7 +43,7 @@ cc_fuzz_test(
|
||||
|
||||
cc_fuzz_test(
|
||||
name = "e2e_fuzz_test",
|
||||
#size = "small",
|
||||
size = "small",
|
||||
srcs = ["e2e_fuzz_test.cc"],
|
||||
copts = ["-UNDEBUG"],
|
||||
corpus = ["//tools/toktok-fuzzer/corpus:e2e_fuzz_test"],
|
||||
@@ -59,7 +59,7 @@ cc_fuzz_test(
|
||||
|
||||
cc_fuzz_test(
|
||||
name = "toxsave_fuzz_test",
|
||||
#size = "small",
|
||||
size = "small",
|
||||
srcs = ["toxsave_harness.cc"],
|
||||
copts = ["-UNDEBUG"],
|
||||
corpus = ["//tools/toktok-fuzzer/corpus:toxsave_fuzzer"],
|
||||
@@ -92,7 +92,7 @@ fuzzing_binary(
|
||||
|
||||
cc_fuzz_test(
|
||||
name = "protodump_reduce",
|
||||
#size = "small",
|
||||
size = "small",
|
||||
srcs = ["protodump_reduce.cc"],
|
||||
copts = ["-UNDEBUG"],
|
||||
deps = [
|
||||
|
@@ -22,6 +22,8 @@
|
||||
|
||||
const bool DEBUG = false;
|
||||
|
||||
static constexpr tox_mono_time_cb *get_self_clock =  { return self->clock; };
|
||||
|
||||
// TODO(iphydf): Put this somewhere shared.
|
||||
struct Network_Addr {
|
||||
struct sockaddr_storage addr;
|
||||
@@ -182,7 +184,7 @@ Fuzz_System::Fuzz_System(Fuzz_Data &input)
|
||||
}
|
||||
, data(input)
|
||||
{
|
||||
sys->mono_time_callback =  { return self->clock; };
|
||||
sys->mono_time_callback = get_self_clock;
|
||||
sys->mono_time_user_data = this;
|
||||
sys->mem = mem.get();
|
||||
sys->ns = ns.get();
|
||||
@@ -269,7 +271,7 @@ Null_System::Null_System()
|
||||
std::make_unique<Random>(Random{&null_random_funcs, this}),
|
||||
}
|
||||
{
|
||||
sys->mono_time_callback =  { return self->clock; };
|
||||
sys->mono_time_callback = get_self_clock;
|
||||
sys->mono_time_user_data = this;
|
||||
sys->mem = mem.get();
|
||||
sys->ns = ns.get();
|
||||
@@ -400,7 +402,7 @@ Record_System::Record_System(Global &global, uint64_t seed, const char *name)
|
||||
, seed_(seed)
|
||||
, name_(name)
|
||||
{
|
||||
sys->mono_time_callback =  { return self->clock; };
|
||||
sys->mono_time_callback = get_self_clock;
|
||||
sys->mono_time_user_data = this;
|
||||
sys->mem = mem.get();
|
||||
sys->ns = ns.get();
|
||||
|
32
external/toxcore/c-toxcore/toxcore/DHT.c
vendored
32
external/toxcore/c-toxcore/toxcore/DHT.c
vendored
@@ -533,8 +533,8 @@ int pack_nodes(const Logger *logger, uint8_t *data, uint16_t length, const Node_
|
||||
|
||||
#ifndef NDEBUG
|
||||
const uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE;
|
||||
#endif
|
||||
assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6);
|
||||
#endif
|
||||
}
|
||||
|
||||
return packed_length;
|
||||
@@ -565,8 +565,8 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
|
||||
|
||||
#ifndef NDEBUG
|
||||
const uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE;
|
||||
#endif
|
||||
assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (processed_data_len != nullptr) {
|
||||
@@ -2965,6 +2965,34 @@ bool dht_non_lan_connected(const DHT *dht)
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t dht_get_num_closelist(const DHT *dht) {
|
||||
uint16_t num_valid_close_clients = 0;
|
||||
for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
|
||||
const Client_data *const client = dht_get_close_client(dht, i);
|
||||
|
||||
// check if client is valid
|
||||
if (!(assoc_timeout(dht->cur_time, &client->assoc4) && assoc_timeout(dht->cur_time, &client->assoc6))) {
|
||||
++num_valid_close_clients;
|
||||
}
|
||||
}
|
||||
|
||||
return num_valid_close_clients;
|
||||
}
|
||||
|
||||
uint16_t dht_get_num_closelist_announce_capable(const DHT *dht) {
|
||||
uint16_t num_valid_close_clients_with_cap = 0;
|
||||
for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
|
||||
const Client_data *const client = dht_get_close_client(dht, i);
|
||||
|
||||
// check if client is valid
|
||||
if (!(assoc_timeout(dht->cur_time, &client->assoc4) && assoc_timeout(dht->cur_time, &client->assoc6)) && client->announce_node) {
|
||||
++num_valid_close_clients_with_cap;
|
||||
}
|
||||
}
|
||||
|
||||
return num_valid_close_clients_with_cap;
|
||||
}
|
||||
|
||||
unsigned int ipport_self_copy(const DHT *dht, IP_Port *dest)
|
||||
{
|
||||
ipport_reset(dest);
|
||||
|
18
external/toxcore/c-toxcore/toxcore/DHT.h
vendored
18
external/toxcore/c-toxcore/toxcore/DHT.h
vendored
@@ -515,6 +515,24 @@ bool dht_isconnected(const DHT *dht);
|
||||
non_null()
|
||||
bool dht_non_lan_connected(const DHT *dht);
|
||||
|
||||
/**
|
||||
* This function returns the ratio of close dht nodes that are known to support announce/store.
|
||||
* This function returns the number of DHT nodes in the closelist.
|
||||
*
|
||||
* @return number
|
||||
*/
|
||||
non_null()
|
||||
uint16_t dht_get_num_closelist(const DHT *dht);
|
||||
|
||||
/**
|
||||
* This function returns the number of DHT nodes in the closelist,
|
||||
* that are capable to store annouce data (introduced in version 0.2.18).
|
||||
*
|
||||
* @return number
|
||||
*/
|
||||
non_null()
|
||||
uint16_t dht_get_num_closelist_announce_capable(const DHT *dht);
|
||||
|
||||
/** @brief Attempt to add client with ip_port and public_key to the friends client list
|
||||
* and close_clientlist.
|
||||
*
|
||||
|
@@ -2988,6 +2988,7 @@ static State_Load_Status load_nospam_keys(Messenger *m, const uint8_t *data, uin
|
||||
load_secret_key(m->net_crypto, data + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE);
|
||||
|
||||
if (!pk_equal(data + sizeof(uint32_t), nc_get_self_public_key(m->net_crypto))) {
|
||||
LOGGER_ERROR(m->log, "public key stored in savedata does not match its secret key");
|
||||
return STATE_LOAD_STATUS_ERROR;
|
||||
}
|
||||
|
||||
@@ -3219,9 +3220,13 @@ static State_Load_Status groups_load(Messenger *m, const uint8_t *data, uint32_t
|
||||
|
||||
if (group_number < 0) {
|
||||
LOGGER_WARNING(m->log, "Failed to load group %u", i);
|
||||
// Can't recover trivially. We may need to skip over some data here.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER_DEBUG(m->log, "Successfully loaded %u groups", gc_count_groups(m->group_handler));
|
||||
|
||||
bin_unpack_free(bu);
|
||||
|
||||
return STATE_LOAD_STATUS_CONTINUE;
|
||||
|
22
external/toxcore/c-toxcore/toxcore/bin_unpack.c
vendored
22
external/toxcore/c-toxcore/toxcore/bin_unpack.c
vendored
@@ -73,10 +73,14 @@ bool bin_unpack_array(Bin_Unpack *bu, uint32_t *size)
|
||||
return cmp_read_array(&bu->ctx, size) && *size <= bu->bytes_size;
|
||||
}
|
||||
|
||||
bool bin_unpack_array_fixed(Bin_Unpack *bu, uint32_t required_size)
|
||||
bool bin_unpack_array_fixed(Bin_Unpack *bu, uint32_t required_size, uint32_t *actual_size)
|
||||
{
|
||||
uint32_t size;
|
||||
return cmp_read_array(&bu->ctx, &size) && size == required_size;
|
||||
uint32_t size = 0;
|
||||
const bool success = cmp_read_array(&bu->ctx, &size) && size == required_size;
|
||||
if (actual_size != nullptr) {
|
||||
*actual_size = size;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool bin_unpack_bool(Bin_Unpack *bu, bool *val)
|
||||
@@ -128,6 +132,18 @@ bool bin_unpack_bin(Bin_Unpack *bu, uint8_t **data_ptr, uint32_t *data_length_pt
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bin_unpack_bin_max(Bin_Unpack *bu, uint8_t *data, uint16_t *data_length_ptr, uint16_t max_data_length)
|
||||
{
|
||||
uint32_t bin_size;
|
||||
if (!bin_unpack_bin_size(bu, &bin_size) || bin_size > max_data_length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*data_length_ptr = bin_size;
|
||||
|
||||
return bin_unpack_bin_b(bu, data, bin_size);
|
||||
}
|
||||
|
||||
bool bin_unpack_bin_fixed(Bin_Unpack *bu, uint8_t *data, uint32_t data_length)
|
||||
{
|
||||
uint32_t bin_size;
|
||||
|
16
external/toxcore/c-toxcore/toxcore/bin_unpack.h
vendored
16
external/toxcore/c-toxcore/toxcore/bin_unpack.h
vendored
@@ -45,10 +45,14 @@ void bin_unpack_free(Bin_Unpack *bu);
|
||||
non_null() bool bin_unpack_array(Bin_Unpack *bu, uint32_t *size);
|
||||
|
||||
/** @brief Start unpacking a fixed size MessagePack array.
|
||||
*
|
||||
* Fails if the array size is not the required size. If `actual_size` is passed a non-null
|
||||
* pointer, the array size is written there.
|
||||
*
|
||||
* @retval false if the packed array size is not exactly the required size.
|
||||
*/
|
||||
non_null() bool bin_unpack_array_fixed(Bin_Unpack *bu, uint32_t required_size);
|
||||
non_null(1) nullable(3)
|
||||
bool bin_unpack_array_fixed(Bin_Unpack *bu, uint32_t required_size, uint32_t *actual_size);
|
||||
|
||||
/** @brief Unpack a MessagePack bool. */
|
||||
non_null() bool bin_unpack_bool(Bin_Unpack *bu, bool *val);
|
||||
@@ -71,10 +75,16 @@ non_null() bool bin_unpack_nil(Bin_Unpack *bu);
|
||||
* large allocation unless the input array was already that large.
|
||||
*/
|
||||
non_null() bool bin_unpack_bin(Bin_Unpack *bu, uint8_t **data_ptr, uint32_t *data_length_ptr);
|
||||
/** @brief Unpack a variable size MessagePack bin into a fixed size byte array.
|
||||
*
|
||||
* Stores unpacked data into `data` with its length stored in `data_length_ptr`. This function does
|
||||
* not allocate memory and requires that `max_data_length` is less than or equal to `sizeof(arr)`
|
||||
* when `arr` is passed as `data` pointer.
|
||||
*/
|
||||
non_null() bool bin_unpack_bin_max(Bin_Unpack *bu, uint8_t *data, uint16_t *data_length_ptr, uint16_t max_data_length);
|
||||
/** @brief Unpack a MessagePack bin of a fixed length into a pre-allocated byte array.
|
||||
*
|
||||
* Unlike the function above, this function does not allocate any memory, but requires the size to
|
||||
* be known up front.
|
||||
* Similar to the function above, but doesn't output the data length.
|
||||
*/
|
||||
non_null() bool bin_unpack_bin_fixed(Bin_Unpack *bu, uint8_t *data, uint32_t data_length);
|
||||
|
||||
|
@@ -120,7 +120,7 @@ static bool tox_event_conference_invite_unpack(
|
||||
Tox_Event_Conference_Invite *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 3)) {
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -135,7 +135,7 @@ static bool tox_event_conference_message_unpack(
|
||||
Tox_Event_Conference_Message *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 4)) {
|
||||
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -120,7 +120,7 @@ static bool tox_event_conference_peer_name_unpack(
|
||||
Tox_Event_Conference_Peer_Name *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 3)) {
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -119,7 +119,7 @@ static bool tox_event_conference_title_unpack(
|
||||
Tox_Event_Conference_Title *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 3)) {
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -112,7 +112,7 @@ static bool tox_event_file_chunk_request_unpack(
|
||||
Tox_Event_File_Chunk_Request *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 4)) {
|
||||
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -149,7 +149,7 @@ static bool tox_event_file_recv_unpack(
|
||||
Tox_Event_File_Recv *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 5)) {
|
||||
if (!bin_unpack_array_fixed(bu, 5, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -134,7 +134,7 @@ static bool tox_event_file_recv_chunk_unpack(
|
||||
Tox_Event_File_Recv_Chunk *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 4)) {
|
||||
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -99,7 +99,7 @@ static bool tox_event_file_recv_control_unpack(
|
||||
Tox_Event_File_Recv_Control *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 3)) {
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -86,7 +86,7 @@ static bool tox_event_friend_connection_status_unpack(
|
||||
Tox_Event_Friend_Connection_Status *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -105,7 +105,7 @@ static bool tox_event_friend_lossless_packet_unpack(
|
||||
Tox_Event_Friend_Lossless_Packet *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -104,7 +104,7 @@ static bool tox_event_friend_lossy_packet_unpack(
|
||||
Tox_Event_Friend_Lossy_Packet *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -119,7 +119,7 @@ static bool tox_event_friend_message_unpack(
|
||||
Tox_Event_Friend_Message *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 3)) {
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -104,7 +104,7 @@ static bool tox_event_friend_name_unpack(
|
||||
Tox_Event_Friend_Name *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -83,7 +83,7 @@ static bool tox_event_friend_read_receipt_unpack(
|
||||
Tox_Event_Friend_Read_Receipt *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -105,7 +105,7 @@ static bool tox_event_friend_request_unpack(
|
||||
Tox_Event_Friend_Request *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -84,7 +84,7 @@ static bool tox_event_friend_status_unpack(
|
||||
Tox_Event_Friend_Status *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -106,7 +106,7 @@ static bool tox_event_friend_status_message_unpack(
|
||||
Tox_Event_Friend_Status_Message *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -82,7 +82,7 @@ static bool tox_event_friend_typing_unpack(
|
||||
Tox_Event_Friend_Typing *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -120,7 +120,7 @@ static bool tox_event_group_custom_packet_unpack(
|
||||
Tox_Event_Group_Custom_Packet *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 3)) {
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -120,7 +120,7 @@ static bool tox_event_group_custom_private_packet_unpack(
|
||||
Tox_Event_Group_Custom_Private_Packet *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 3)) {
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -142,7 +142,7 @@ static bool tox_event_group_invite_unpack(
|
||||
Tox_Event_Group_Invite *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 3)) {
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -84,7 +84,7 @@ static bool tox_event_group_join_fail_unpack(
|
||||
Tox_Event_Group_Join_Fail *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -150,7 +150,7 @@ static bool tox_event_group_message_unpack(
|
||||
Tox_Event_Group_Message *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 5)) {
|
||||
if (!bin_unpack_array_fixed(bu, 5, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -114,7 +114,7 @@ static bool tox_event_group_moderation_unpack(
|
||||
Tox_Event_Group_Moderation *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 4)) {
|
||||
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -105,7 +105,7 @@ static bool tox_event_group_password_unpack(
|
||||
Tox_Event_Group_Password *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -172,7 +172,7 @@ static bool tox_event_group_peer_exit_unpack(
|
||||
Tox_Event_Group_Peer_Exit *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 5)) {
|
||||
if (!bin_unpack_array_fixed(bu, 5, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -84,7 +84,7 @@ static bool tox_event_group_peer_join_unpack(
|
||||
Tox_Event_Group_Peer_Join *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -84,7 +84,7 @@ static bool tox_event_group_peer_limit_unpack(
|
||||
Tox_Event_Group_Peer_Limit *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -120,7 +120,7 @@ static bool tox_event_group_peer_name_unpack(
|
||||
Tox_Event_Group_Peer_Name *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 3)) {
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -99,7 +99,7 @@ static bool tox_event_group_peer_status_unpack(
|
||||
Tox_Event_Group_Peer_Status *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 3)) {
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -84,7 +84,7 @@ static bool tox_event_group_privacy_state_unpack(
|
||||
Tox_Event_Group_Privacy_State *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -135,7 +135,7 @@ static bool tox_event_group_private_message_unpack(
|
||||
Tox_Event_Group_Private_Message *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 4)) {
|
||||
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -120,7 +120,7 @@ static bool tox_event_group_topic_unpack(
|
||||
Tox_Event_Group_Topic *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 3)) {
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -84,7 +84,7 @@ static bool tox_event_group_topic_lock_unpack(
|
||||
Tox_Event_Group_Topic_Lock *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -84,7 +84,7 @@ static bool tox_event_group_voice_state_unpack(
|
||||
Tox_Event_Group_Voice_State *event, Bin_Unpack *bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
4
external/toxcore/c-toxcore/toxcore/group.c
vendored
4
external/toxcore/c-toxcore/toxcore/group.c
vendored
@@ -802,6 +802,7 @@ static int addpeer(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_p
|
||||
|
||||
if (peer_index != -1) {
|
||||
if (!pk_equal(g->group[peer_index].real_pk, real_pk)) {
|
||||
LOGGER_ERROR(g_c->m->log, "peer public key is incorrect for peer %d", peer_number);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -3679,6 +3680,7 @@ static State_Load_Status load_conferences_helper(Group_Chats *g_c, const uint8_t
|
||||
|
||||
if (groupnumber == -1) {
|
||||
// If this fails there's a serious problem, don't bother with cleanup
|
||||
LOGGER_ERROR(g_c->m->log, "conference creation failed");
|
||||
return STATE_LOAD_STATUS_ERROR;
|
||||
}
|
||||
|
||||
@@ -3696,6 +3698,7 @@ static State_Load_Status load_conferences_helper(Group_Chats *g_c, const uint8_t
|
||||
assert(ret);
|
||||
}
|
||||
|
||||
LOGGER_ERROR(g_c->m->log, "conference loading failed");
|
||||
return STATE_LOAD_STATUS_ERROR;
|
||||
}
|
||||
|
||||
@@ -3705,6 +3708,7 @@ static State_Load_Status load_conferences_helper(Group_Chats *g_c, const uint8_t
|
||||
nullptr, true, false);
|
||||
|
||||
if (peer_index == -1) {
|
||||
LOGGER_ERROR(g_c->m->log, "adding peer %d failed", g->peer_number);
|
||||
return STATE_LOAD_STATUS_ERROR;
|
||||
}
|
||||
|
||||
|
34
external/toxcore/c-toxcore/toxcore/group_chats.c
vendored
34
external/toxcore/c-toxcore/toxcore/group_chats.c
vendored
@@ -108,10 +108,19 @@ static_assert(GCC_BUFFER_SIZE <= UINT16_MAX,
|
||||
static_assert(MAX_GC_PACKET_CHUNK_SIZE < MAX_GC_PACKET_SIZE,
|
||||
"MAX_GC_PACKET_CHUNK_SIZE must be < MAX_GC_PACKET_SIZE");
|
||||
|
||||
static_assert(MAX_GC_PACKET_INCOMING_CHUNK_SIZE < MAX_GC_PACKET_SIZE,
|
||||
"MAX_GC_PACKET_INCOMING_CHUNK_SIZE must be < MAX_GC_PACKET_SIZE");
|
||||
|
||||
static_assert(MAX_GC_PACKET_INCOMING_CHUNK_SIZE >= MAX_GC_PACKET_CHUNK_SIZE,
|
||||
"MAX_GC_PACKET_INCOMING_CHUNK_SIZE must be >= MAX_GC_PACKET_CHUNK_SIZE");
|
||||
|
||||
// size of a lossless handshake packet - lossless packets can't/shouldn't be split up
|
||||
static_assert(MAX_GC_PACKET_CHUNK_SIZE >= 171,
|
||||
"MAX_GC_PACKET_CHUNK_SIZE must be >= 171");
|
||||
|
||||
static_assert(MAX_GC_PACKET_INCOMING_CHUNK_SIZE >= 171,
|
||||
"MAX_GC_PACKET_INCOMING_CHUNK_SIZE must be >= 171");
|
||||
|
||||
// group_moderation constants assume this is the max packet size.
|
||||
static_assert(MAX_GC_PACKET_SIZE >= 50000,
|
||||
"MAX_GC_PACKET_SIZE doesn't match constants in group_moderation.h");
|
||||
@@ -119,6 +128,9 @@ static_assert(MAX_GC_PACKET_SIZE >= 50000,
|
||||
static_assert(MAX_GC_PACKET_SIZE <= UINT16_MAX - MAX_GC_PACKET_CHUNK_SIZE,
|
||||
"MAX_GC_PACKET_SIZE must be <= UINT16_MAX - MAX_GC_PACKET_CHUNK_SIZE");
|
||||
|
||||
static_assert(MAX_GC_PACKET_SIZE <= UINT16_MAX - MAX_GC_PACKET_INCOMING_CHUNK_SIZE,
|
||||
"MAX_GC_PACKET_SIZE must be <= UINT16_MAX - MAX_GC_PACKET_INCOMING_CHUNK_SIZE");
|
||||
|
||||
/** Types of broadcast messages. */
|
||||
typedef enum Group_Message_Type {
|
||||
GC_MESSAGE_TYPE_NORMAL = 0x00,
|
||||
@@ -6255,13 +6267,13 @@ static int handle_gc_tcp_packet(void *object, int id, const uint8_t *packet, uin
|
||||
|
||||
if (length <= MIN_TCP_PACKET_SIZE) {
|
||||
LOGGER_WARNING(m->log, "Got tcp packet with invalid length: %u (expected %u to %u)", length,
|
||||
MIN_TCP_PACKET_SIZE, MAX_GC_PACKET_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
|
||||
MIN_TCP_PACKET_SIZE, MAX_GC_PACKET_INCOMING_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (length > MAX_GC_PACKET_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE) {
|
||||
if (length > MAX_GC_PACKET_INCOMING_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE) {
|
||||
LOGGER_WARNING(m->log, "Got tcp packet with invalid length: %u (expected %u to %u)", length,
|
||||
MIN_TCP_PACKET_SIZE, MAX_GC_PACKET_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
|
||||
MIN_TCP_PACKET_SIZE, MAX_GC_PACKET_INCOMING_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -6336,13 +6348,13 @@ static int handle_gc_tcp_oob_packet(void *object, const uint8_t *public_key, uns
|
||||
|
||||
if (length <= GC_MIN_HS_PACKET_PAYLOAD_SIZE) {
|
||||
LOGGER_WARNING(m->log, "Got tcp oob packet with invalid length: %u (expected %u to %u)", length,
|
||||
GC_MIN_HS_PACKET_PAYLOAD_SIZE, MAX_GC_PACKET_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE);
|
||||
GC_MIN_HS_PACKET_PAYLOAD_SIZE, MAX_GC_PACKET_INCOMING_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (length > MAX_GC_PACKET_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE) {
|
||||
if (length > MAX_GC_PACKET_INCOMING_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE) {
|
||||
LOGGER_WARNING(m->log, "Got tcp oob packet with invalid length: %u (expected %u to %u)", length,
|
||||
GC_MIN_HS_PACKET_PAYLOAD_SIZE, MAX_GC_PACKET_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE);
|
||||
GC_MIN_HS_PACKET_PAYLOAD_SIZE, MAX_GC_PACKET_INCOMING_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -6392,13 +6404,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_PACKET_INCOMING_CHUNK_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_PACKET_INCOMING_CHUNK_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_PACKET_INCOMING_CHUNK_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -6961,12 +6973,12 @@ static bool ping_peer(const GC_Chat *chat, const GC_Connection *gconn)
|
||||
|
||||
if (!send_lossy_group_packet(chat, gconn, data, packed_len, GP_PING)) {
|
||||
free(data);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
free(data);
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -28,6 +28,8 @@
|
||||
* For an explanation on why this value was chosen, see the following link: https://archive.ph/vsCOG
|
||||
*/
|
||||
#define MAX_GC_PACKET_CHUNK_SIZE 500
|
||||
/* Max size of an incoming packet chunk that is allowed */
|
||||
#define MAX_GC_PACKET_INCOMING_CHUNK_SIZE 1372
|
||||
|
||||
#define MAX_GC_MESSAGE_SIZE GROUP_MAX_MESSAGE_LENGTH
|
||||
#define MAX_GC_MESSAGE_RAW_SIZE (MAX_GC_MESSAGE_SIZE + GC_MESSAGE_PSEUDO_ID_SIZE)
|
||||
|
@@ -366,7 +366,7 @@ static uint16_t reassemble_packet(const Logger *log, GC_Connection *gconn, uint8
|
||||
// search backwards in recv array until we find an empty slot or a non-fragment packet type
|
||||
while (!array_entry_is_empty(entry) && entry->packet_type == GP_FRAGMENT) {
|
||||
assert(entry->data != nullptr);
|
||||
assert(entry->data_length <= MAX_GC_PACKET_CHUNK_SIZE);
|
||||
assert(entry->data_length <= MAX_GC_PACKET_INCOMING_CHUNK_SIZE);
|
||||
|
||||
const uint16_t diff = packet_length + entry->data_length;
|
||||
|
||||
|
40
external/toxcore/c-toxcore/toxcore/group_pack.c
vendored
40
external/toxcore/c-toxcore/toxcore/group_pack.c
vendored
@@ -22,7 +22,7 @@
|
||||
non_null()
|
||||
static bool load_unpack_state_values(GC_Chat *chat, Bin_Unpack *bu)
|
||||
{
|
||||
if (!bin_unpack_array_fixed(bu, 8)) {
|
||||
if (!bin_unpack_array_fixed(bu, 8, nullptr)) {
|
||||
LOGGER_ERROR(chat->log, "Group state values array malformed");
|
||||
return false;
|
||||
}
|
||||
@@ -58,15 +58,23 @@ static bool load_unpack_state_values(GC_Chat *chat, Bin_Unpack *bu)
|
||||
non_null()
|
||||
static bool load_unpack_state_bin(GC_Chat *chat, Bin_Unpack *bu)
|
||||
{
|
||||
if (!bin_unpack_array_fixed(bu, 5)) {
|
||||
if (!bin_unpack_array_fixed(bu, 5, nullptr)) {
|
||||
LOGGER_ERROR(chat->log, "Group state binary array malformed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(bin_unpack_bin_fixed(bu, chat->shared_state_sig, SIGNATURE_SIZE)
|
||||
&& bin_unpack_bin_fixed(bu, chat->shared_state.founder_public_key, EXT_PUBLIC_KEY_SIZE)
|
||||
&& bin_unpack_bin_fixed(bu, chat->shared_state.group_name, chat->shared_state.group_name_len)
|
||||
&& bin_unpack_bin_fixed(bu, chat->shared_state.password, chat->shared_state.password_length)
|
||||
if (!bin_unpack_bin_fixed(bu, chat->shared_state_sig, SIGNATURE_SIZE)) {
|
||||
LOGGER_ERROR(chat->log, "Failed to unpack shared state signature");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bin_unpack_bin_fixed(bu, chat->shared_state.founder_public_key, EXT_PUBLIC_KEY_SIZE)) {
|
||||
LOGGER_ERROR(chat->log, "Failed to unpack founder public key");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(bin_unpack_bin_max(bu, chat->shared_state.group_name, &chat->shared_state.group_name_len, sizeof(chat->shared_state.group_name))
|
||||
&& bin_unpack_bin_max(bu, chat->shared_state.password, &chat->shared_state.password_length, sizeof(chat->shared_state.password))
|
||||
&& bin_unpack_bin_fixed(bu, chat->shared_state.mod_list_hash, MOD_MODERATION_HASH_SIZE))) {
|
||||
LOGGER_ERROR(chat->log, "Failed to unpack state binary data");
|
||||
return false;
|
||||
@@ -78,7 +86,7 @@ static bool load_unpack_state_bin(GC_Chat *chat, Bin_Unpack *bu)
|
||||
non_null()
|
||||
static bool load_unpack_topic_info(GC_Chat *chat, Bin_Unpack *bu)
|
||||
{
|
||||
if (!bin_unpack_array_fixed(bu, 6)) {
|
||||
if (!bin_unpack_array_fixed(bu, 6, nullptr)) {
|
||||
LOGGER_ERROR(chat->log, "Group topic array malformed");
|
||||
return false;
|
||||
}
|
||||
@@ -86,7 +94,7 @@ static bool load_unpack_topic_info(GC_Chat *chat, Bin_Unpack *bu)
|
||||
if (!(bin_unpack_u32(bu, &chat->topic_info.version)
|
||||
&& bin_unpack_u16(bu, &chat->topic_info.length)
|
||||
&& bin_unpack_u16(bu, &chat->topic_info.checksum)
|
||||
&& bin_unpack_bin_fixed(bu, chat->topic_info.topic, chat->topic_info.length)
|
||||
&& bin_unpack_bin_max(bu, chat->topic_info.topic, &chat->topic_info.length, sizeof(chat->topic_info.topic))
|
||||
&& bin_unpack_bin_fixed(bu, chat->topic_info.public_sig_key, SIG_PUBLIC_KEY_SIZE)
|
||||
&& bin_unpack_bin_fixed(bu, chat->topic_sig, SIGNATURE_SIZE))) {
|
||||
LOGGER_ERROR(chat->log, "Failed to unpack topic info");
|
||||
@@ -99,8 +107,9 @@ static bool load_unpack_topic_info(GC_Chat *chat, Bin_Unpack *bu)
|
||||
non_null()
|
||||
static bool load_unpack_mod_list(GC_Chat *chat, Bin_Unpack *bu)
|
||||
{
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
LOGGER_ERROR(chat->log, "Group mod list array malformed");
|
||||
uint32_t actual_size = 0;
|
||||
if (!bin_unpack_array_fixed(bu, 2, &actual_size)) {
|
||||
LOGGER_ERROR(chat->log, "Group mod list array malformed: %d != 2", actual_size);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -148,7 +157,7 @@ static bool load_unpack_mod_list(GC_Chat *chat, Bin_Unpack *bu)
|
||||
non_null()
|
||||
static bool load_unpack_keys(GC_Chat *chat, Bin_Unpack *bu)
|
||||
{
|
||||
if (!bin_unpack_array_fixed(bu, 4)) {
|
||||
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
|
||||
LOGGER_ERROR(chat->log, "Group keys array malformed");
|
||||
return false;
|
||||
}
|
||||
@@ -167,7 +176,7 @@ static bool load_unpack_keys(GC_Chat *chat, Bin_Unpack *bu)
|
||||
non_null()
|
||||
static bool load_unpack_self_info(GC_Chat *chat, Bin_Unpack *bu)
|
||||
{
|
||||
if (!bin_unpack_array_fixed(bu, 4)) {
|
||||
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
|
||||
LOGGER_ERROR(chat->log, "Group self info array malformed");
|
||||
return false;
|
||||
}
|
||||
@@ -214,7 +223,7 @@ static bool load_unpack_self_info(GC_Chat *chat, Bin_Unpack *bu)
|
||||
non_null()
|
||||
static bool load_unpack_saved_peers(GC_Chat *chat, Bin_Unpack *bu)
|
||||
{
|
||||
if (!bin_unpack_array_fixed(bu, 2)) {
|
||||
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
|
||||
LOGGER_ERROR(chat->log, "Group saved peers array malformed");
|
||||
return false;
|
||||
}
|
||||
@@ -256,8 +265,9 @@ static bool load_unpack_saved_peers(GC_Chat *chat, Bin_Unpack *bu)
|
||||
|
||||
bool gc_load_unpack_group(GC_Chat *chat, Bin_Unpack *bu)
|
||||
{
|
||||
if (!bin_unpack_array_fixed(bu, 7)) {
|
||||
LOGGER_ERROR(chat->log, "Group info array malformed");
|
||||
uint32_t actual_size;
|
||||
if (!bin_unpack_array_fixed(bu, 7, &actual_size)) {
|
||||
LOGGER_ERROR(chat->log, "Group info array malformed: %d != 7", actual_size);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
2
external/toxcore/c-toxcore/toxcore/network.c
vendored
2
external/toxcore/c-toxcore/toxcore/network.c
vendored
@@ -1086,7 +1086,7 @@ void networking_poll(const Networking_Core *net, void *userdata)
|
||||
}
|
||||
|
||||
IP_Port ip_port;
|
||||
uint8_t data[MAX_UDP_PACKET_SIZE];
|
||||
uint8_t data[MAX_UDP_PACKET_SIZE] = {0};
|
||||
uint32_t length;
|
||||
|
||||
while (receivepacket(net->ns, net->mem, net->log, net->sock, &ip_port, data, &length) != -1) {
|
||||
|
2
external/toxcore/c-toxcore/toxcore/state.c
vendored
2
external/toxcore/c-toxcore/toxcore/state.c
vendored
@@ -52,7 +52,7 @@ int state_load(const Logger *log, state_load_cb *state_load_callback, void *oute
|
||||
}
|
||||
|
||||
case STATE_LOAD_STATUS_ERROR: {
|
||||
LOGGER_ERROR(log, "Error occcured in state file (type: %u).", type);
|
||||
LOGGER_ERROR(log, "Error occcured in state file (type: 0x%02x).", type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
25
external/toxcore/c-toxcore/toxcore/tox.c
vendored
25
external/toxcore/c-toxcore/toxcore/tox.c
vendored
@@ -858,12 +858,26 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
|
||||
|
||||
if (load_savedata_tox
|
||||
&& tox_load(tox, tox_options_get_savedata_data(opts), tox_options_get_savedata_length(opts)) == -1) {
|
||||
kill_groupchats(tox->m->conferences_object);
|
||||
kill_messenger(tox->m);
|
||||
|
||||
mono_time_free(tox->sys.mem, tox->mono_time);
|
||||
tox_options_free(default_options);
|
||||
tox_unlock(tox);
|
||||
|
||||
if (tox->mutex != nullptr) {
|
||||
pthread_mutex_destroy(tox->mutex);
|
||||
}
|
||||
|
||||
mem_delete(sys->mem, tox->mutex);
|
||||
mem_delete(sys->mem, tox);
|
||||
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT);
|
||||
} else if (load_savedata_sk) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (load_savedata_sk) {
|
||||
load_secret_key(tox->m->net_crypto, tox_options_get_savedata_data(opts));
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK);
|
||||
} else {
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK);
|
||||
}
|
||||
|
||||
m_callback_namechange(tox->m, tox_friend_name_handler);
|
||||
@@ -913,6 +927,9 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
|
||||
tox_options_free(default_options);
|
||||
|
||||
tox_unlock(tox);
|
||||
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK);
|
||||
|
||||
return tox;
|
||||
}
|
||||
|
||||
|
3
external/toxcore/c-toxcore/toxcore/tox.h
vendored
3
external/toxcore/c-toxcore/toxcore/tox.h
vendored
@@ -890,9 +890,6 @@ typedef enum Tox_Err_New {
|
||||
* This function will bring the instance into a valid state. Running the event
|
||||
* loop with a new instance will operate correctly.
|
||||
*
|
||||
* If loading failed or succeeded only partially, the new or partially loaded
|
||||
* instance is returned and an error code is set.
|
||||
*
|
||||
* @param options An options object as described above. If this parameter is
|
||||
* NULL, the default options are used.
|
||||
*
|
||||
|
17
external/toxcore/c-toxcore/toxcore/tox_private.c
vendored
17
external/toxcore/c-toxcore/toxcore/tox_private.c
vendored
@@ -149,3 +149,20 @@ bool tox_dht_get_nodes(const Tox *tox, const uint8_t *public_key, const char *ip
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t tox_dht_get_num_closelist(const Tox *tox) {
|
||||
tox_lock(tox);
|
||||
const uint16_t num_total = dht_get_num_closelist(tox->m->dht);
|
||||
tox_unlock(tox);
|
||||
|
||||
return num_total;
|
||||
}
|
||||
|
||||
uint16_t tox_dht_get_num_closelist_announce_capable(const Tox *tox){
|
||||
tox_lock(tox);
|
||||
const uint16_t num_cap = dht_get_num_closelist_announce_capable(tox->m->dht);
|
||||
tox_unlock(tox);
|
||||
|
||||
return num_cap;
|
||||
}
|
||||
|
||||
|
16
external/toxcore/c-toxcore/toxcore/tox_private.h
vendored
16
external/toxcore/c-toxcore/toxcore/tox_private.h
vendored
@@ -140,6 +140,22 @@ typedef enum Tox_Err_Dht_Get_Nodes {
|
||||
bool tox_dht_get_nodes(const Tox *tox, const uint8_t *public_key, const char *ip, uint16_t port,
|
||||
const uint8_t *target_public_key, Tox_Err_Dht_Get_Nodes *error);
|
||||
|
||||
/**
|
||||
* This function returns the ratio of close dht nodes that are known to support announce/store.
|
||||
* This function returns the number of DHT nodes in the closelist.
|
||||
*
|
||||
* @return number
|
||||
*/
|
||||
uint16_t tox_dht_get_num_closelist(const Tox *tox);
|
||||
|
||||
/**
|
||||
* This function returns the number of DHT nodes in the closelist,
|
||||
* that are capable to store annouce data (introduced in version 0.2.18).
|
||||
*
|
||||
* @return number
|
||||
*/
|
||||
uint16_t tox_dht_get_num_closelist_announce_capable(const Tox *tox);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -37,6 +37,9 @@ add_executable(tomato
|
||||
./message_image_loader.hpp
|
||||
./message_image_loader.cpp
|
||||
|
||||
./tox_avatar_manager.hpp
|
||||
./tox_avatar_manager.cpp
|
||||
|
||||
./media_meta_info_loader.hpp
|
||||
./media_meta_info_loader.cpp
|
||||
|
||||
@@ -49,6 +52,15 @@ add_executable(tomato
|
||||
./send_image_popup.hpp
|
||||
./send_image_popup.cpp
|
||||
|
||||
./settings_window.hpp
|
||||
./settings_window.cpp
|
||||
|
||||
./tox_ui_utils.hpp
|
||||
./tox_ui_utils.cpp
|
||||
|
||||
./tox_dht_cap_histo.hpp
|
||||
./tox_dht_cap_histo.cpp
|
||||
|
||||
./chat_gui4.hpp
|
||||
./chat_gui4.cpp
|
||||
)
|
||||
|
@@ -6,6 +6,9 @@
|
||||
#include <solanaceae/tox_messages/components.hpp>
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
|
||||
// HACK: remove them
|
||||
#include <solanaceae/tox_contacts/components.hpp>
|
||||
#include <solanaceae/toxcore/utils.hpp>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/misc/cpp/imgui_stdlib.h>
|
||||
@@ -21,6 +24,7 @@
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
@@ -61,6 +65,9 @@ void ChatGui4::render(void) {
|
||||
_contact_tc.update();
|
||||
_msg_tc.update();
|
||||
|
||||
_fss.render();
|
||||
_sip.render();
|
||||
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(viewport->WorkPos);
|
||||
ImGui::SetNextWindowSize(viewport->WorkSize);
|
||||
@@ -150,11 +157,21 @@ void ChatGui4::render(void) {
|
||||
|
||||
if (ImGui::BeginChild("message_log", {0, -100}, false, ImGuiWindowFlags_MenuBar)) {
|
||||
if (ImGui::BeginMenuBar()) {
|
||||
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";
|
||||
if (ImGui::BeginMenu("debug")) {
|
||||
ImGui::Checkbox("show extra info", &_show_chat_extra_info);
|
||||
ImGui::Checkbox("show avatar transfers", &_show_chat_avatar_tf);
|
||||
|
||||
ImGui::SeparatorText("tox");
|
||||
|
||||
if (_cr.all_of<Contact::Components::ToxGroupPersistent>(*_selected_contact)) {
|
||||
if (ImGui::MenuItem("copy ngc chatid")) {
|
||||
const auto& chat_id = _cr.get<Contact::Components::ToxGroupPersistent>(*_selected_contact).chat_id.data;
|
||||
const auto chat_id_str = bin2hex(std::vector<uint8_t>{chat_id.begin(), chat_id.end()});
|
||||
ImGui::SetClipboardText(chat_id_str.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
@@ -167,6 +184,8 @@ void ChatGui4::render(void) {
|
||||
if (const auto* unread_storage = mm.storage<Message::Components::TagUnread>(); unread_storage != nullptr && !unread_storage->empty()) {
|
||||
//assert(unread_storage->size() == 0);
|
||||
//assert(unread_storage.cbegin() == unread_storage.cend());
|
||||
|
||||
#if 0
|
||||
std::cout << "UNREAD ";
|
||||
Message3 prev_ent = entt::null;
|
||||
for (const Message3 e : mm.view<Message::Components::TagUnread>()) {
|
||||
@@ -177,6 +196,7 @@ void ChatGui4::render(void) {
|
||||
prev_ent = e;
|
||||
}
|
||||
std::cout << "\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,44 +386,24 @@ void ChatGui4::render(void) {
|
||||
if (ImGui::Button("paste\nfile", {-FLT_MIN, 0})) {
|
||||
const auto* mime_type = clipboardHasImage();
|
||||
if (mime_type != nullptr) { // making sure
|
||||
size_t data_size = 0;
|
||||
void* data = SDL_GetClipboardData(mime_type, &data_size);
|
||||
|
||||
std::cout << "CG: pasted image of size " << data_size << " mime " << mime_type << "\n";
|
||||
|
||||
_sip.sendMemory(
|
||||
static_cast<const uint8_t*>(data), data_size,
|
||||
[this](const auto& img_data, const auto file_ext) {
|
||||
// create file name
|
||||
// TODO: move this into sip
|
||||
std::ostringstream tmp_file_name {"tomato_Image_", std::ios_base::ate};
|
||||
{
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const auto ctime = std::chrono::system_clock::to_time_t(now);
|
||||
tmp_file_name
|
||||
<< std::put_time(std::localtime(&ctime), "%F_%H-%M-%S")
|
||||
<< "."
|
||||
<< std::setfill('0') << std::setw(3)
|
||||
<< std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch() - std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch())).count()
|
||||
<< file_ext
|
||||
;
|
||||
}
|
||||
|
||||
std::cout << "tmp image path " << tmp_file_name.str() << "\n";
|
||||
|
||||
const std::filesystem::path tmp_send_file_path = "tmp_send_files";
|
||||
std::filesystem::create_directories(tmp_send_file_path);
|
||||
const auto tmp_file_path = tmp_send_file_path / tmp_file_name.str();
|
||||
|
||||
std::ofstream(tmp_file_path, std::ios_base::out | std::ios_base::binary)
|
||||
.write(reinterpret_cast<const char*>(img_data.data()), img_data.size());
|
||||
|
||||
_rmm.sendFilePath(*_selected_contact, tmp_file_name.str(), tmp_file_path.u8string());
|
||||
},
|
||||
[](){}
|
||||
);
|
||||
SDL_free(data); // free data
|
||||
pasteFile(mime_type);
|
||||
}
|
||||
//} else if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
|
||||
} else if (ImGui::BeginPopupContextItem(nullptr, ImGuiMouseButton_Right)) {
|
||||
const static std::vector<const char*> image_mime_types {
|
||||
"image/png",
|
||||
"image/webp",
|
||||
"image/gif",
|
||||
"image/jpeg",
|
||||
"image/bmp",
|
||||
};
|
||||
|
||||
for (const char* mime_type : image_mime_types) {
|
||||
if (ImGui::MenuItem(mime_type)) {
|
||||
pasteFile(mime_type);
|
||||
}
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
//ImGui::EndDisabled();
|
||||
}
|
||||
@@ -428,13 +428,16 @@ void ChatGui4::render(void) {
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
_fss.render();
|
||||
_sip.render();
|
||||
|
||||
_contact_tc.workLoadQueue();
|
||||
_msg_tc.workLoadQueue();
|
||||
}
|
||||
|
||||
void ChatGui4::sendFilePath(const char* file_path) {
|
||||
if (_selected_contact && std::filesystem::is_regular_file(file_path)) {
|
||||
_rmm.sendFilePath(*_selected_contact, std::filesystem::path(file_path).filename().u8string(), file_path);
|
||||
}
|
||||
}
|
||||
|
||||
// has MessageText
|
||||
void ChatGui4::renderMessageBodyText(Message3Registry& reg, const Message3 e) {
|
||||
const auto& msgtext = reg.get<Message::Components::MessageText>(e).text;
|
||||
@@ -479,6 +482,18 @@ void ChatGui4::renderMessageBodyText(Message3Registry& reg, const Message3 e) {
|
||||
}
|
||||
|
||||
void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
|
||||
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;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (msg_reg.all_of<Components::TransferState>(e)) {
|
||||
switch (msg_reg.get<Components::TransferState>(e).state) {
|
||||
@@ -553,9 +568,16 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
|
||||
ImGui::TextUnformatted("down");
|
||||
if (reg.all_of<Message::Components::Transfer::BytesReceived>(e)) {
|
||||
ImGui::SameLine();
|
||||
|
||||
float fraction = float(reg.get<Message::Components::Transfer::BytesReceived>(e).total) / reg.get<Message::Components::Transfer::FileInfo>(e).total_size;
|
||||
|
||||
char overlay_buf[32];
|
||||
std::snprintf(overlay_buf, sizeof(overlay_buf), "%.1f%%", fraction * 100 + 0.01f);
|
||||
|
||||
ImGui::ProgressBar(
|
||||
float(reg.get<Message::Components::Transfer::BytesReceived>(e).total) / reg.get<Message::Components::Transfer::FileInfo>(e).total_size,
|
||||
{-FLT_MIN, TEXT_BASE_HEIGHT}
|
||||
fraction,
|
||||
{-FLT_MIN, TEXT_BASE_HEIGHT},
|
||||
overlay_buf
|
||||
);
|
||||
// TODO: numbers
|
||||
}
|
||||
@@ -567,9 +589,16 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
|
||||
ImGui::TextUnformatted(" up");
|
||||
if (reg.all_of<Message::Components::Transfer::BytesSent>(e)) {
|
||||
ImGui::SameLine();
|
||||
|
||||
float fraction = float(reg.get<Message::Components::Transfer::BytesSent>(e).total) / reg.get<Message::Components::Transfer::FileInfo>(e).total_size;
|
||||
|
||||
char overlay_buf[32];
|
||||
std::snprintf(overlay_buf, sizeof(overlay_buf), "%.1f%%", fraction * 100 + 0.01f);
|
||||
|
||||
ImGui::ProgressBar(
|
||||
float(reg.get<Message::Components::Transfer::BytesSent>(e).total) / reg.get<Message::Components::Transfer::FileInfo>(e).total_size,
|
||||
{-FLT_MIN, TEXT_BASE_HEIGHT}
|
||||
fraction,
|
||||
{-FLT_MIN, TEXT_BASE_HEIGHT},
|
||||
overlay_buf
|
||||
);
|
||||
// TODO: numbers
|
||||
}
|
||||
@@ -812,3 +841,45 @@ bool ChatGui4::renderSubContactListContact(const Contact3 c, const bool selected
|
||||
return ImGui::Selectable(label.c_str(), selected);
|
||||
}
|
||||
|
||||
void ChatGui4::pasteFile(const char* mime_type) {
|
||||
size_t data_size = 0;
|
||||
void* data = SDL_GetClipboardData(mime_type, &data_size);
|
||||
|
||||
// if image
|
||||
|
||||
std::cout << "CG: pasted image of size " << data_size << " mime " << mime_type << "\n";
|
||||
|
||||
_sip.sendMemory(
|
||||
static_cast<const uint8_t*>(data), data_size,
|
||||
[this](const auto& img_data, const auto file_ext) {
|
||||
// create file name
|
||||
// TODO: move this into sip
|
||||
std::ostringstream tmp_file_name {"tomato_Image_", std::ios_base::ate};
|
||||
{
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const auto ctime = std::chrono::system_clock::to_time_t(now);
|
||||
tmp_file_name
|
||||
<< std::put_time(std::localtime(&ctime), "%F_%H-%M-%S")
|
||||
<< "."
|
||||
<< std::setfill('0') << std::setw(3)
|
||||
<< std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch() - std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch())).count()
|
||||
<< file_ext
|
||||
;
|
||||
}
|
||||
|
||||
std::cout << "tmp image path " << tmp_file_name.str() << "\n";
|
||||
|
||||
const std::filesystem::path tmp_send_file_path = "tmp_send_files";
|
||||
std::filesystem::create_directories(tmp_send_file_path);
|
||||
const auto tmp_file_path = tmp_send_file_path / tmp_file_name.str();
|
||||
|
||||
std::ofstream(tmp_file_path, std::ios_base::out | std::ios_base::binary)
|
||||
.write(reinterpret_cast<const char*>(img_data.data()), img_data.size());
|
||||
|
||||
_rmm.sendFilePath(*_selected_contact, tmp_file_name.str(), tmp_file_path.u8string());
|
||||
},
|
||||
[](){}
|
||||
);
|
||||
SDL_free(data); // free data
|
||||
}
|
||||
|
||||
|
@@ -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};
|
||||
@@ -50,6 +51,8 @@ class ChatGui4 {
|
||||
public:
|
||||
bool any_unread {false};
|
||||
|
||||
void sendFilePath(const char* file_path);
|
||||
|
||||
private:
|
||||
void renderMessageBodyText(Message3Registry& reg, const Message3 e);
|
||||
void renderMessageBodyFile(Message3Registry& reg, const Message3 e);
|
||||
@@ -59,6 +62,8 @@ class ChatGui4 {
|
||||
bool renderContactListContactBig(const Contact3 c, const bool selected);
|
||||
bool renderContactListContactSmall(const Contact3 c, const bool selected) const;
|
||||
bool renderSubContactListContact(const Contact3 c, const bool selected) const;
|
||||
|
||||
void pasteFile(const char* mime_type);
|
||||
};
|
||||
|
||||
|
||||
|
@@ -11,13 +11,18 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::stri
|
||||
rmm(cr),
|
||||
mts(rmm),
|
||||
tc(save_path, save_password),
|
||||
tpi(tc.getTox()),
|
||||
ad(tc),
|
||||
tcm(cr, tc, tc),
|
||||
tmm(rmm, cr, tcm, tc, tc),
|
||||
ttm(rmm, cr, tcm, tc, tc),
|
||||
mmil(rmm),
|
||||
tam(rmm, cr, conf),
|
||||
sdlrtu(renderer_),
|
||||
cg(conf, rmm, cr, sdlrtu)
|
||||
cg(conf, rmm, cr, sdlrtu),
|
||||
sw(conf),
|
||||
tuiu(tc, conf),
|
||||
tdch(tpi)
|
||||
{
|
||||
tel.subscribeAll(tc);
|
||||
|
||||
@@ -41,6 +46,7 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::stri
|
||||
g_provideInstance<RegistryMessageModel>("RegistryMessageModel", "host", &rmm);
|
||||
|
||||
g_provideInstance<ToxI>("ToxI", "host", &tc);
|
||||
g_provideInstance<ToxPrivateI>("ToxPrivateI", "host", &tpi);
|
||||
g_provideInstance<ToxEventProviderI>("ToxEventProviderI", "host", &tc);
|
||||
g_provideInstance<ToxContactModel2>("ToxContactModel2", "host", &tcm);
|
||||
|
||||
@@ -66,6 +72,12 @@ MainScreen::~MainScreen(void) {
|
||||
}
|
||||
|
||||
bool MainScreen::handleEvent(SDL_Event& e) {
|
||||
if (e.type == SDL_EVENT_DROP_FILE) {
|
||||
std::cout << "DROP FILE: " << e.drop.file << "\n";
|
||||
cg.sendFilePath(e.drop.file);
|
||||
return true; // TODO: forward return succ from sendFilePath()
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -78,11 +90,34 @@ Screen* MainScreen::poll(bool& quit) {
|
||||
|
||||
tcm.iterate(time_delta);
|
||||
|
||||
tam.iterate();
|
||||
|
||||
// HACK: render the tomato main window first, with proper flags set.
|
||||
// flags need to be set the first time begin() is called.
|
||||
// and plugins are run before the main cg is run.
|
||||
{
|
||||
// TODO: maybe render cg earlier? or move the main window out of cg?
|
||||
constexpr auto bg_window_flags =
|
||||
ImGuiWindowFlags_NoDecoration |
|
||||
ImGuiWindowFlags_NoMove |
|
||||
ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoSavedSettings |
|
||||
ImGuiWindowFlags_MenuBar |
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus;
|
||||
|
||||
ImGui::Begin("tomato", nullptr, bg_window_flags);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
pm.tick(time_delta);
|
||||
tdch.tick(time_delta);
|
||||
|
||||
mts.iterate();
|
||||
|
||||
cg.render();
|
||||
sw.render();
|
||||
tuiu.render();
|
||||
tdch.render();
|
||||
|
||||
if constexpr (false) {
|
||||
ImGui::ShowDemoWindow();
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include <solanaceae/message3/message_time_sort.hpp>
|
||||
#include <solanaceae/plugin/plugin_manager.hpp>
|
||||
#include <solanaceae/toxcore/tox_event_logger.hpp>
|
||||
#include "./tox_private_impl.hpp"
|
||||
|
||||
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
||||
#include <solanaceae/tox_messages/tox_message_manager.hpp>
|
||||
@@ -17,9 +18,13 @@
|
||||
#include "./auto_dirty.hpp"
|
||||
|
||||
#include "./media_meta_info_loader.hpp"
|
||||
#include "./tox_avatar_manager.hpp"
|
||||
|
||||
#include "./sdlrenderer_texture_uploader.hpp"
|
||||
#include "./chat_gui4.hpp"
|
||||
#include "./settings_window.hpp"
|
||||
#include "./tox_ui_utils.hpp"
|
||||
#include "./tox_dht_cap_histo.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
@@ -44,17 +49,22 @@ struct MainScreen final : public Screen {
|
||||
|
||||
ToxEventLogger tel{std::cout};
|
||||
ToxClient tc;
|
||||
ToxPrivateImpl tpi;
|
||||
AutoDirty ad;
|
||||
ToxContactModel2 tcm;
|
||||
ToxMessageManager tmm;
|
||||
ToxTransferManager ttm;
|
||||
|
||||
MediaMetaInfoLoader mmil;
|
||||
ToxAvatarManager tam;
|
||||
|
||||
SDLRendererTextureUploader sdlrtu;
|
||||
//OpenGLTextureUploader ogltu;
|
||||
|
||||
ChatGui4 cg;
|
||||
SettingsWindow sw;
|
||||
ToxUIUtils tuiu;
|
||||
ToxDHTCapHisto tdch;
|
||||
|
||||
MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins);
|
||||
~MainScreen(void);
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "./image_loader_sdl_bmp.hpp"
|
||||
#include "./image_loader_stb.hpp"
|
||||
#include "./image_loader_webp.hpp"
|
||||
#include "./media_meta_info_loader.hpp"
|
||||
|
||||
#include <solanaceae/message3/components.hpp>
|
||||
|
||||
@@ -22,6 +23,10 @@ std::optional<TextureEntry> MessageImageLoader::load(TextureUploaderI& tu, Messa
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (m.all_of<Message::Components::TagNotImage>()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (m.all_of<Message::Components::Transfer::FileInfoLocal>()) {
|
||||
const auto& file_list = m.get<Message::Components::Transfer::FileInfoLocal>().file_list;
|
||||
assert(!file_list.empty());
|
||||
|
@@ -6,8 +6,8 @@
|
||||
|
||||
const char* clipboardHasImage(void) {
|
||||
const static std::vector<const char*> image_mime_types {
|
||||
"image/webp",
|
||||
"image/png",
|
||||
"image/webp",
|
||||
"image/gif",
|
||||
"image/jpeg",
|
||||
"image/bmp",
|
||||
|
221
src/settings_window.cpp
Normal file
221
src/settings_window.cpp
Normal file
@@ -0,0 +1,221 @@
|
||||
#include "./settings_window.hpp"
|
||||
|
||||
#include <solanaceae/util/simple_config_model.hpp>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/misc/cpp/imgui_stdlib.h>
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
template<typename FNCat, typename ...MapTypes>
|
||||
void iterateMultMaps(FNCat&& fn_cat, MapTypes& ...map_types) {
|
||||
// the iterators
|
||||
std::tuple its{map_types.begin()...};
|
||||
|
||||
// assuming ever maps returned .begin() has a unique type
|
||||
// TODO: use index instead
|
||||
while ( ((std::get<decltype(map_types.begin())>(its) != map_types.end()) || ...) ) {
|
||||
// figure out current module and participants
|
||||
|
||||
std::string_view current_module;
|
||||
// find current_module
|
||||
((
|
||||
current_module = (
|
||||
std::get<decltype(map_types.begin())>(its) != map_types.end() && (current_module.empty() || current_module >= std::get<decltype(map_types.begin())>(its)->first)
|
||||
) ? std::get<decltype(map_types.begin())>(its)->first : current_module
|
||||
), ...);
|
||||
|
||||
assert(!current_module.empty());
|
||||
|
||||
fn_cat(
|
||||
current_module,
|
||||
((
|
||||
std::get<decltype(map_types.begin())>(its) != map_types.end() &&
|
||||
current_module == std::get<decltype(map_types.begin())>(its)->first
|
||||
) ? std::get<decltype(map_types.begin())>(its)->second : decltype(map_types.begin()->second){})...
|
||||
);
|
||||
|
||||
// increment participanting iterators
|
||||
((
|
||||
(
|
||||
std::get<decltype(map_types.begin())>(its) != map_types.end() &&
|
||||
current_module == std::get<decltype(map_types.begin())>(its)->first
|
||||
) ? void(++std::get<decltype(map_types.begin())>(its)) : void(0)
|
||||
), ...);
|
||||
}
|
||||
}
|
||||
|
||||
//template<typename T>
|
||||
//static void renderConfigCat(SimpleConfigModel& conf, std::string_view cmodule, std::string_view ccat, const std::pair<std::optional<T>, std::map<std::string, T>>& cat_dat) {
|
||||
//if (cat_dat.first.has_value()) {
|
||||
//T tmp = cat_dat.first.value();
|
||||
////if (ImGui::Checkbox(ccat.data(), &tmp)) {
|
||||
////conf.set(cmodule, ccat, tmp);
|
||||
////}
|
||||
//} else if (!cat_dat.second.empty()) {
|
||||
//ImGui::Text("uhhh");
|
||||
//}
|
||||
//}
|
||||
static void renderConfigCat(SimpleConfigModel& conf, std::string_view cmodule, std::string_view ccat, const std::pair<std::optional<bool>, std::map<std::string, bool>>& cat_dat) {
|
||||
if (cat_dat.first.has_value()) {
|
||||
bool tmp = cat_dat.first.value();
|
||||
if (ImGui::Checkbox(ccat.data(), &tmp)) {
|
||||
conf.set(cmodule, ccat, tmp);
|
||||
}
|
||||
} else if (!cat_dat.second.empty()) {
|
||||
ImGui::Text("uhhh");
|
||||
}
|
||||
}
|
||||
static void renderConfigCat(SimpleConfigModel& conf, std::string_view cmodule, std::string_view ccat, const std::pair<std::optional<int64_t>, std::map<std::string, int64_t>>& cat_dat) {
|
||||
if (cat_dat.first.has_value()) {
|
||||
int64_t tmp = cat_dat.first.value();
|
||||
if (ImGui::InputScalar(ccat.data(), ImGuiDataType_S64, &tmp)) {
|
||||
conf.set(cmodule, ccat, tmp);
|
||||
}
|
||||
} else if (!cat_dat.second.empty()) {
|
||||
ImGui::Text("uhhh");
|
||||
}
|
||||
}
|
||||
static void renderConfigCat(SimpleConfigModel& conf, std::string_view cmodule, std::string_view ccat, const std::pair<std::optional<double>, std::map<std::string, double>>& cat_dat) {
|
||||
if (cat_dat.first.has_value()) {
|
||||
double tmp = cat_dat.first.value();
|
||||
if (ImGui::InputDouble(ccat.data(), &tmp)) {
|
||||
conf.set(cmodule, ccat, tmp);
|
||||
}
|
||||
} else if (!cat_dat.second.empty()) {
|
||||
ImGui::Text("uhhh");
|
||||
}
|
||||
}
|
||||
static void renderConfigCat(SimpleConfigModel& conf, std::string_view cmodule, std::string_view ccat, const std::pair<std::optional<std::string>, std::map<std::string, std::string>>& cat_dat) {
|
||||
if (cat_dat.first.has_value()) {
|
||||
std::string tmp = cat_dat.first.value();
|
||||
if (ImGui::InputText(ccat.data(), &tmp)) {
|
||||
conf.set(cmodule, ccat, CM_ISV{tmp});
|
||||
}
|
||||
} else if (!cat_dat.second.empty()) {
|
||||
ImGui::Text("uhhh");
|
||||
}
|
||||
}
|
||||
|
||||
SettingsWindow::SettingsWindow(SimpleConfigModel& conf) : _conf(conf) {
|
||||
}
|
||||
|
||||
void SettingsWindow::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("Settings")) {
|
||||
if (ImGui::MenuItem("settings window")) {
|
||||
_show_window = true;
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if (_show_window) {
|
||||
if (ImGui::Begin("Settings", &_show_window)) {
|
||||
ImGui::TextDisabled("most settings are only fetched once at program startup");
|
||||
|
||||
// ufff
|
||||
// we need to iterate 4 maps, ideally in lexicographic order
|
||||
// (pain)
|
||||
// std::maps should be ordered more or less correctly
|
||||
// (less pain)
|
||||
// its recursive
|
||||
// (pain)
|
||||
// but the code is reusable
|
||||
// (less pain)
|
||||
|
||||
iterateMultMaps(
|
||||
[this](std::string_view cmodule, const auto& ...mod_map_types) {
|
||||
if (ImGui::CollapsingHeader(cmodule.data())) {
|
||||
iterateMultMaps(
|
||||
[this, cmodule](std::string_view ccat, const auto& ...cat_map_types) {
|
||||
(renderConfigCat(_conf, cmodule, ccat, cat_map_types), ...);
|
||||
},
|
||||
mod_map_types...
|
||||
);
|
||||
}
|
||||
},
|
||||
_conf._map_bool,
|
||||
_conf._map_int,
|
||||
_conf._map_double,
|
||||
_conf._map_string
|
||||
);
|
||||
|
||||
#if 0
|
||||
auto it_b = _conf._map_bool.begin();
|
||||
auto it_i = _conf._map_int.begin();
|
||||
auto it_d = _conf._map_double.begin();
|
||||
auto it_s = _conf._map_string.begin();
|
||||
|
||||
while (
|
||||
it_b != _conf._map_bool.end() ||
|
||||
it_i != _conf._map_int.end() ||
|
||||
it_d != _conf._map_double.end() ||
|
||||
it_s != _conf._map_string.end()
|
||||
) {
|
||||
// figure out current module
|
||||
std::string_view current_module;
|
||||
bool bool_is_curr = false;
|
||||
bool int_is_curr = false;
|
||||
bool double_is_curr = false;
|
||||
bool string_is_curr = false;
|
||||
|
||||
if (it_b != _conf._map_bool.end() && (current_module.empty() || current_module >= it_b->first)) {
|
||||
//std::cerr << "SET bool\n";
|
||||
bool_is_curr = true;
|
||||
current_module = it_b->first;
|
||||
}
|
||||
if (it_i != _conf._map_int.end() && (current_module.empty() || current_module >= it_i->first)) {
|
||||
//std::cerr << "SET int\n";
|
||||
int_is_curr = true;
|
||||
current_module = it_i->first;
|
||||
}
|
||||
if (it_d != _conf._map_double.end() && (current_module.empty() || current_module >= it_d->first)) {
|
||||
//std::cerr << "SET double\n";
|
||||
double_is_curr = true;
|
||||
current_module = it_d->first;
|
||||
}
|
||||
if (it_s != _conf._map_string.end() && (current_module.empty() || current_module >= it_s->first)) {
|
||||
//std::cerr << "SET string\n";
|
||||
string_is_curr = true;
|
||||
current_module = it_s->first;
|
||||
}
|
||||
|
||||
assert(!current_module.empty());
|
||||
|
||||
//ImGui::Text("module '%s'", current_module.data());
|
||||
if (ImGui::CollapsingHeader(current_module.data())) {
|
||||
// ... do the whole 4way iterate again but on categoy
|
||||
}
|
||||
|
||||
// after the module, increment iterators pointing to current_module
|
||||
if (bool_is_curr) {
|
||||
it_b++;
|
||||
}
|
||||
if (int_is_curr) {
|
||||
it_i++;
|
||||
}
|
||||
if (double_is_curr) {
|
||||
it_d++;
|
||||
}
|
||||
if (string_is_curr) {
|
||||
it_s++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
15
src/settings_window.hpp
Normal file
15
src/settings_window.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
struct SimpleConfigModel;
|
||||
|
||||
class SettingsWindow {
|
||||
bool _show_window {false};
|
||||
// TODO: add iteration api to interface
|
||||
SimpleConfigModel& _conf;
|
||||
|
||||
public:
|
||||
SettingsWindow(SimpleConfigModel& conf);
|
||||
|
||||
void render(void);
|
||||
};
|
||||
|
@@ -151,8 +151,10 @@ struct TextureCache {
|
||||
|
||||
void invalidate(const std::vector<KeyType>& to_purge) {
|
||||
for (const auto& key : to_purge) {
|
||||
for (const auto& tex_id : _cache.at(key).textures) {
|
||||
_tu.destroy(tex_id);
|
||||
if (_cache.count(key)) {
|
||||
for (const auto& tex_id : _cache.at(key).textures) {
|
||||
_tu.destroy(tex_id);
|
||||
}
|
||||
}
|
||||
_cache.erase(key);
|
||||
}
|
||||
|
@@ -175,7 +175,7 @@ std::optional<TextureEntry> ToxAvatarLoader::load(TextureUploaderI& tu, Contact3
|
||||
return new_entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // continues if loading img fails
|
||||
|
||||
if (!_cr.any_of<
|
||||
Contact::Components::ToxFriendPersistent,
|
||||
|
215
src/tox_avatar_manager.cpp
Normal file
215
src/tox_avatar_manager.cpp
Normal file
@@ -0,0 +1,215 @@
|
||||
#include "./tox_avatar_manager.hpp"
|
||||
|
||||
#include <solanaceae/util/config_model.hpp>
|
||||
|
||||
#include <solanaceae/message3/components.hpp>
|
||||
// for comp transfer tox filekind (TODO: generalize -> content system?)
|
||||
#include <solanaceae/tox_messages/components.hpp>
|
||||
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
#include <solanaceae/tox_contacts/components.hpp>
|
||||
|
||||
#include <solanaceae/toxcore/utils.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <string_view>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// see https://github.com/Tox/Tox-Client-Standard/blob/master/user_identification/avatar.md
|
||||
// see (old) https://github.com/Tox-Archive/Tox-STS/blob/master/STS.md#avatars
|
||||
|
||||
// https://youtu.be/_uuCLRqc9QA
|
||||
|
||||
namespace Components {
|
||||
struct TagAvatarImageHandled {};
|
||||
};
|
||||
|
||||
ToxAvatarManager::ToxAvatarManager(
|
||||
RegistryMessageModel& rmm,
|
||||
Contact3Registry& cr,
|
||||
ConfigModelI& conf
|
||||
) : _rmm(rmm), _cr(cr), _conf(conf) {
|
||||
_rmm.subscribe(this, RegistryMessageModel_Event::message_construct);
|
||||
_rmm.subscribe(this, RegistryMessageModel_Event::message_updated);
|
||||
|
||||
if (!_conf.has_string("ToxAvatarManager", "save_path")) {
|
||||
// or on linux: $HOME/.config/tox/avatars/
|
||||
_conf.set("ToxAvatarManager", "save_path", std::string_view{"tmp_avatar_dir"});
|
||||
}
|
||||
|
||||
//_conf.set("TransferAutoAccept", "autoaccept_limit", int64_t(50l*1024l*1024l)); // sane default
|
||||
|
||||
const std::string_view avatar_save_path {_conf.get_string("ToxAvatarManager", "save_path").value()};
|
||||
// make sure it exists
|
||||
std::filesystem::create_directories(avatar_save_path);
|
||||
|
||||
{ // scan tox contacts for cached avatars
|
||||
// old sts says pubkey.png
|
||||
|
||||
_cr.view<Contact::Components::ToxFriendPersistent>().each([this](auto c, const Contact::Components::ToxFriendPersistent& tox_pers) {
|
||||
addAvatarFileToContact(c, tox_pers.key);
|
||||
});
|
||||
|
||||
_cr.view<Contact::Components::ToxGroupPersistent>().each([this](auto c, const Contact::Components::ToxGroupPersistent& tox_pers) {
|
||||
addAvatarFileToContact(c, tox_pers.chat_id);
|
||||
});
|
||||
|
||||
// TODO: also for group peers?
|
||||
// TODO: conf?
|
||||
}
|
||||
}
|
||||
|
||||
void ToxAvatarManager::iterate(void) {
|
||||
// cancel queue
|
||||
|
||||
// accept queue
|
||||
for (auto& [m, path] : _accept_queue) {
|
||||
if (m.all_of<Message::Components::Transfer::ActionAccept>()) {
|
||||
continue; // already accepted
|
||||
}
|
||||
|
||||
m.emplace<Message::Components::Transfer::ActionAccept>(path, true);
|
||||
std::cout << "TAM: auto accepted transfer\n";
|
||||
|
||||
_rmm.throwEventUpdate(m);
|
||||
}
|
||||
_accept_queue.clear();
|
||||
|
||||
// - add message/content/transfer listener for onComplete
|
||||
}
|
||||
|
||||
std::string ToxAvatarManager::getAvatarPath(const ToxKey& key) const {
|
||||
const std::string_view avatar_save_path {_conf.get_string("ToxAvatarManager", "save_path").value()};
|
||||
const auto pub_key_string = bin2hex({key.data.cbegin(), key.data.cend()});
|
||||
const auto file_path = std::filesystem::path(avatar_save_path) / (pub_key_string + ".png");
|
||||
return file_path.u8string();
|
||||
}
|
||||
|
||||
void ToxAvatarManager::addAvatarFileToContact(const Contact3 c, const ToxKey& key) {
|
||||
//const std::string_view avatar_save_path {_conf.get_string("ToxAvatarManager", "save_path").value()};
|
||||
//const auto pub_key_string = bin2hex({key.data.cbegin(), key.data.cend()});
|
||||
//const auto file_path = std::filesystem::path(avatar_save_path) / (pub_key_string + ".png");
|
||||
const auto file_path = getAvatarPath(key);
|
||||
if (std::filesystem::is_regular_file(file_path)) {
|
||||
// avatar file png file exists
|
||||
_cr.emplace_or_replace<Contact::Components::AvatarFile>(c, file_path);
|
||||
_cr.emplace_or_replace<Contact::Components::TagAvatarInvalidate>(c);
|
||||
}
|
||||
}
|
||||
|
||||
void ToxAvatarManager::clearAvatarFromContact(const Contact3 c) {
|
||||
if (_cr.all_of<Contact::Components::AvatarFile>(c)) {
|
||||
std::filesystem::remove(_cr.get<Contact::Components::AvatarFile>(c).file_path);
|
||||
_cr.remove<Contact::Components::AvatarFile>(c);
|
||||
_cr.emplace_or_replace<Contact::Components::TagAvatarInvalidate>(c);
|
||||
}
|
||||
}
|
||||
|
||||
void ToxAvatarManager::checkMsg(Message3Handle h) {
|
||||
if (h.any_of<
|
||||
Message::Components::Transfer::ActionAccept,
|
||||
Components::TagAvatarImageHandled
|
||||
>()) {
|
||||
return; // already accepted or handled
|
||||
}
|
||||
|
||||
if (!h.any_of<
|
||||
Message::Components::Transfer::TagPaused,
|
||||
Message::Components::Transfer::TagHaveAll
|
||||
>()) {
|
||||
// we only handle unaccepted or finished
|
||||
return;
|
||||
}
|
||||
|
||||
if (!h.all_of<
|
||||
Message::Components::Transfer::TagReceiving,
|
||||
Message::Components::Transfer::FileInfo,
|
||||
Message::Components::Transfer::FileKind,
|
||||
Message::Components::ContactFrom // should always be there, just making sure
|
||||
>()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TCS-2.2.11 (big list, should have been sub points ...)
|
||||
|
||||
if (h.get<Message::Components::Transfer::FileKind>().kind != 1) {
|
||||
// not an avatar
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// TCS-2.2.10
|
||||
if (file_info.file_list.empty() || file_info.file_list.front().file_name.empty() || file_info.total_size == 0) {
|
||||
// reset
|
||||
clearAvatarFromContact(contact);
|
||||
// TODO: cancel
|
||||
return;
|
||||
}
|
||||
|
||||
if (!h.all_of<
|
||||
Message::Components::Transfer::FileID
|
||||
>()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string file_path;
|
||||
if (_cr.all_of<Contact::Components::ToxFriendPersistent>(contact)) {
|
||||
file_path = getAvatarPath(_cr.get<Contact::Components::ToxFriendPersistent>(contact).key);
|
||||
} else if (_cr.all_of<Contact::Components::ToxGroupPersistent>(contact)) {
|
||||
file_path = getAvatarPath(_cr.get<Contact::Components::ToxGroupPersistent>(contact).chat_id);
|
||||
} else {
|
||||
std::cerr << "TAM error: cant get toxkey for contact\n";
|
||||
// TODO: mark handled?
|
||||
return;
|
||||
}
|
||||
|
||||
if (h.all_of<Message::Components::Transfer::TagHaveAll>()) {
|
||||
std::cout << "TAM: full avatar received\n";
|
||||
|
||||
if (_cr.all_of<Contact::Components::ToxFriendPersistent>(contact)) {
|
||||
addAvatarFileToContact(contact, _cr.get<Contact::Components::ToxFriendPersistent>(contact).key);
|
||||
} else if (_cr.all_of<Contact::Components::ToxGroupPersistent>(contact)) {
|
||||
addAvatarFileToContact(contact, _cr.get<Contact::Components::ToxGroupPersistent>(contact).chat_id);
|
||||
} else {
|
||||
std::cerr << "TAM error: cant get toxkey for contact\n";
|
||||
}
|
||||
|
||||
h.emplace_or_replace<Components::TagAvatarImageHandled>();
|
||||
} else {
|
||||
// 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});
|
||||
}
|
||||
}
|
||||
|
||||
bool ToxAvatarManager::onEvent(const Message::Events::MessageConstruct& e) {
|
||||
checkMsg(e.e);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ToxAvatarManager::onEvent(const Message::Events::MessageUpdated& e) {
|
||||
checkMsg(e.e);
|
||||
return false;
|
||||
}
|
||||
|
45
src/tox_avatar_manager.hpp
Normal file
45
src/tox_avatar_manager.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
#include <solanaceae/contact/contact_model3.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
// RIP fishy c=<
|
||||
|
||||
struct ConfigModelI;
|
||||
struct ToxKey;
|
||||
|
||||
class ToxAvatarManager : public RegistryMessageModelEventI {
|
||||
RegistryMessageModel& _rmm;
|
||||
Contact3Registry& _cr;
|
||||
ConfigModelI& _conf;
|
||||
|
||||
struct AcceptEntry {
|
||||
Message3Handle m;
|
||||
std::string file_path;
|
||||
};
|
||||
std::vector<AcceptEntry> _accept_queue;
|
||||
|
||||
public:
|
||||
ToxAvatarManager(
|
||||
RegistryMessageModel& rmm,
|
||||
Contact3Registry& cr,
|
||||
ConfigModelI& conf
|
||||
);
|
||||
|
||||
void iterate(void);
|
||||
|
||||
protected:
|
||||
std::string getAvatarPath(const ToxKey& key) const;
|
||||
void addAvatarFileToContact(const Contact3 c, const ToxKey& key);
|
||||
void clearAvatarFromContact(const Contact3 c);
|
||||
void checkMsg(Message3Handle h);
|
||||
|
||||
protected: // mm
|
||||
bool onEvent(const Message::Events::MessageConstruct& e) override;
|
||||
bool onEvent(const Message::Events::MessageUpdated& e) override;
|
||||
};
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "./tox_client.hpp"
|
||||
#include "toxcore/tox.h"
|
||||
|
||||
// meh, change this
|
||||
#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) :
|
||||
_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 = tox_new(options, &err_new);
|
||||
tox_options_free(options);
|
||||
@@ -91,9 +99,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 ++) {
|
||||
|
69
src/tox_dht_cap_histo.cpp
Normal file
69
src/tox_dht_cap_histo.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "./tox_dht_cap_histo.hpp"
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
void ToxDHTCapHisto::tick(float time_delta) {
|
||||
if (!_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
_time_since_last_add += time_delta;
|
||||
if (_time_since_last_add >= _value_add_interval) {
|
||||
_time_since_last_add = 0.f; // very loose
|
||||
|
||||
const auto total = _tpi.toxDHTGetNumCloselist();
|
||||
const auto with_cap = _tpi.toxDHTGetNumCloselistAnnounceCapable();
|
||||
|
||||
if (total == 0 || with_cap == 0) {
|
||||
_ratios.push_back(0.f);
|
||||
} else {
|
||||
_ratios.push_back(float(with_cap) / float(total));
|
||||
}
|
||||
|
||||
// TODO: limit
|
||||
while (_ratios.size() > 5*60) {
|
||||
_ratios.erase(_ratios.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ToxDHTCapHisto::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")) {
|
||||
ImGui::SeparatorText("DHT diagnostics");
|
||||
|
||||
ImGui::Checkbox("enabled", &_enabled);
|
||||
|
||||
if (ImGui::MenuItem("show DHT announce capability histogram")) {
|
||||
_show_window = true;
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
if (_show_window) {
|
||||
if (ImGui::Begin("Tox DHT announce capability histogram", &_show_window)) {
|
||||
if (_enabled) {
|
||||
ImGui::PlotHistogram("##histogram", _ratios.data(), _ratios.size(), 0, nullptr, 0.f, 1.f, {-1, -1});
|
||||
} else {
|
||||
ImGui::TextUnformatted("logging disabled!");
|
||||
if (ImGui::Button("enable")) {
|
||||
_enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
22
src/tox_dht_cap_histo.hpp
Normal file
22
src/tox_dht_cap_histo.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <solanaceae/toxcore/tox_private_interface.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class ToxDHTCapHisto {
|
||||
ToxPrivateI& _tpi;
|
||||
|
||||
bool _enabled {true};
|
||||
bool _show_window {false};
|
||||
|
||||
std::vector<float> _ratios;
|
||||
const float _value_add_interval {1.f}; // every second
|
||||
float _time_since_last_add {0.f};
|
||||
|
||||
public:
|
||||
ToxDHTCapHisto(ToxPrivateI& tpi) : _tpi(tpi) {}
|
||||
|
||||
void tick(float time_delta);
|
||||
void render(void);
|
||||
};
|
19
src/tox_private_impl.hpp
Normal file
19
src/tox_private_impl.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <tox/tox_private.h>
|
||||
#include <solanaceae/toxcore/tox_private_interface.hpp>
|
||||
|
||||
struct ToxPrivateImpl : public ToxPrivateI {
|
||||
Tox* _tox = nullptr;
|
||||
|
||||
ToxPrivateImpl(Tox* tox) : _tox(tox) {}
|
||||
virtual ~ToxPrivateImpl(void) {}
|
||||
|
||||
uint16_t toxDHTGetNumCloselist(void) override {
|
||||
return tox_dht_get_num_closelist(_tox);
|
||||
}
|
||||
|
||||
uint16_t toxDHTGetNumCloselistAnnounceCapable(void) override {
|
||||
return tox_dht_get_num_closelist_announce_capable(_tox);
|
||||
}
|
||||
};
|
109
src/tox_ui_utils.cpp
Normal file
109
src/tox_ui_utils.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "./tox_ui_utils.hpp"
|
||||
|
||||
#include <tox/tox.h>
|
||||
|
||||
#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")) {
|
||||
ImGui::SeparatorText("Friends/Groups");
|
||||
|
||||
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
21
src/tox_ui_utils.hpp
Normal 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);
|
||||
};
|
||||
|
Reference in New Issue
Block a user