Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: Add explicit callback setters for MSI callbacks. #2134

Merged
merged 3 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions auto_tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ flaky_tests = {
"//c-toxcore/toxcore:tox",
"//c-toxcore/toxcore:tox_dispatch",
"//c-toxcore/toxcore:tox_events",
"//c-toxcore/toxcore:util",
"//c-toxcore/toxencryptsave",
"@libsodium",
"@libvpx",
Expand Down
2 changes: 1 addition & 1 deletion auto_tests/dht_getnodes_api_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static bool node_crawled(Dht_Node **nodes, size_t num_nodes, const uint8_t *publ
return false;
}

static bool all_nodes_crawled(AutoTox *autotoxes, uint32_t num_toxes, uint8_t **public_key_list)
static bool all_nodes_crawled(const AutoTox *autotoxes, uint32_t num_toxes, uint8_t **public_key_list)
{
for (uint32_t i = 0; i < num_toxes; ++i) {
const State *state = (const State *)autotoxes[i].state;
Expand Down
17 changes: 4 additions & 13 deletions auto_tests/friend_request_spam_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,16 @@ static void test_friend_request(AutoTox *autotoxes)
}

for (uint32_t t = 0; t < 100; ++t) {
bool connected = true;
for (uint32_t i = 0; i < FR_TOX_COUNT; ++i) {
uint32_t size = tox_self_get_friend_list_size(autotoxes[i].tox);
for (uint32_t fn = 0; fn < size; ++fn) {
if (tox_friend_get_connection_status(autotoxes[i].tox, fn, nullptr) == TOX_CONNECTION_NONE) {
connected = false;
}
}
}

if (connected) {
if (all_friends_connected(autotoxes, FR_TOX_COUNT)) {
break;
}

iterate_all_wait(autotoxes, FR_TOX_COUNT, ITERATION_INTERVAL);
}

uint32_t size = tox_self_get_friend_list_size(autotoxes[0].tox);
printf("Tox clients connected took %lu seconds; tox1 has %u friends.\n", (unsigned long)(time(nullptr) - con_time), size);
const size_t size = tox_self_get_friend_list_size(autotoxes[0].tox);
printf("Tox clients connected took %lu seconds; tox1 has %u friends.\n",
(unsigned long)(time(nullptr) - con_time), (unsigned int)size);
}

int main(void)
Expand Down
8 changes: 4 additions & 4 deletions auto_tests/onion_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ static void test_basic(void)
Mono_Time *mono_time2 = mono_time_new();

IP ip = get_loopback();
Onion *onion1 = new_onion(log1, mono_time1, new_dht(log1, mono_time1, new_networking(log1, &ip, 36567), true));
Onion *onion2 = new_onion(log2, mono_time2, new_dht(log2, mono_time2, new_networking(log2, &ip, 36568), true));
Onion *onion1 = new_onion(log1, mono_time1, new_dht(log1, mono_time1, new_networking(log1, &ip, 36567), true, false));
Onion *onion2 = new_onion(log2, mono_time2, new_dht(log2, mono_time2, new_networking(log2, &ip, 36568), true, false));
ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing.");
networking_registerhandler(onion2->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_test_1, onion2);

Expand Down Expand Up @@ -291,7 +291,7 @@ static void test_basic(void)

Mono_Time *mono_time3 = mono_time_new();

Onion *onion3 = new_onion(log3, mono_time3, new_dht(log3, mono_time3, new_networking(log3, &ip, 36569), true));
Onion *onion3 = new_onion(log3, mono_time3, new_dht(log3, mono_time3, new_networking(log3, &ip, 36569), true, false));
ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");

random_nonce(nonce);
Expand Down Expand Up @@ -392,7 +392,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
return nullptr;
}

DHT *dht = new_dht(on->log, on->mono_time, net, true);
DHT *dht = new_dht(on->log, on->mono_time, net, true, false);

if (!dht) {
kill_networking(net);
Expand Down
4 changes: 3 additions & 1 deletion other/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ cc_binary(
deps = [
"//c-toxcore/testing:misc_tools",
"//c-toxcore/toxcore:DHT",
"//c-toxcore/toxcore:LAN_discovery",
"//c-toxcore/toxcore:TCP_server",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:friend_requests",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:network",
"//c-toxcore/toxcore:tox",
"//c-toxcore/toxcore:util",
],
)
5 changes: 3 additions & 2 deletions other/DHT_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "../toxcore/DHT.h"
#include "../toxcore/LAN_discovery.h"
#include "../toxcore/ccompat.h"
#include "../toxcore/friend_requests.h"
#include "../toxcore/logger.h"
#include "../toxcore/mono_time.h"
Expand Down Expand Up @@ -142,7 +143,7 @@ int main(int argc, char *argv[])
}

Mono_Time *mono_time = mono_time_new();
DHT *dht = new_dht(logger, mono_time, new_networking_ex(logger, &ip, PORT, PORT, nullptr), true);
DHT *dht = new_dht(logger, mono_time, new_networking_ex(logger, &ip, PORT, PORT, nullptr), true, true);
Onion *onion = new_onion(logger, mono_time, dht);
const Onion_Announce *onion_a = new_onion_announce(logger, mono_time, dht);

Expand Down Expand Up @@ -217,7 +218,7 @@ int main(int argc, char *argv[])
int is_waiting_for_dht_connection = 1;

uint64_t last_LANdiscovery = 0;
Broadcast_Info *broadcast = lan_discovery_init(dht);
const Broadcast_Info *broadcast = lan_discovery_init();

while (1) {
mono_time_update(mono_time);
Expand Down
3 changes: 2 additions & 1 deletion other/bootstrap_daemon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ cc_binary(
deps = [
"//c-toxcore/other:bootstrap_node_packets",
"//c-toxcore/toxcore:DHT",
"//c-toxcore/toxcore:LAN_discovery",
"//c-toxcore/toxcore:TCP_server",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:network",
"//c-toxcore/toxcore:onion_announce",
"//c-toxcore/toxcore:tox",
"//c-toxcore/toxcore:util",
"@libconfig",
],
)
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8174a792e8e5092b6bb322b612534db544c25f9a448f55723a12d328101000c9 /usr/local/bin/tox-bootstrapd
799360df399d3c82adb10f60765a25b1686e7c091b3a817ae4b2f1aa9db1a622 /usr/local/bin/tox-bootstrapd
9 changes: 3 additions & 6 deletions other/bootstrap_daemon/src/tox-bootstrapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ int main(int argc, char *argv[])

mono_time_update(mono_time);

DHT *const dht = new_dht(logger, mono_time, net, true);
DHT *const dht = new_dht(logger, mono_time, net, true, enable_lan_discovery);

if (dht == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n");
Expand Down Expand Up @@ -478,7 +478,7 @@ int main(int argc, char *argv[])
Broadcast_Info *broadcast = nullptr;

if (enable_lan_discovery) {
broadcast = lan_discovery_init(dht);
broadcast = lan_discovery_init();
log_write(LOG_LEVEL_INFO, "Initialized LAN discovery successfully.\n");
}

Expand Down Expand Up @@ -537,10 +537,7 @@ int main(int argc, char *argv[])
log_write(LOG_LEVEL_INFO, "Received (%d) signal. Exiting.\n", caught_signal);
}

if (enable_lan_discovery) {
lan_discovery_kill(dht, broadcast);
}

lan_discovery_kill(broadcast);
kill_TCP_server(tcp_server);
kill_onion_announce(onion_a);
kill_onion(onion);
Expand Down
1 change: 1 addition & 0 deletions testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ cc_binary(
deps = [
":misc_tools",
"//c-toxcore/toxcore:Messenger",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:mono_time",
],
)
Expand Down
1 change: 1 addition & 0 deletions testing/Messenger_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#endif

#include "../toxcore/Messenger.h"
#include "../toxcore/ccompat.h"
#include "../toxcore/mono_time.h"
#include "misc_tools.h"

Expand Down
16 changes: 11 additions & 5 deletions toxav/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ cc_library(
":ring_buffer",
"//c-toxcore/toxcore",
"//c-toxcore/toxcore:Messenger",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:network",
"//c-toxcore/toxcore:util",
],
)

Expand All @@ -64,9 +65,10 @@ cc_library(
deps = [
":bwcontroller",
"//c-toxcore/toxcore:Messenger",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:network",
"//c-toxcore/toxcore:util",
],
)

Expand All @@ -89,9 +91,9 @@ cc_library(
deps = [
":public_api",
":rtp",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:network",
"@opus",
],
)
Expand All @@ -111,9 +113,11 @@ cc_library(
":public_api",
":ring_buffer",
":rtp",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:network",
"//c-toxcore/toxcore:util",
"@libvpx",
],
)
Expand All @@ -124,9 +128,10 @@ cc_library(
hdrs = ["groupav.h"],
deps = [
"//c-toxcore/toxcore",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:network",
"//c-toxcore/toxcore:util",
"@opus",
],
)
Expand All @@ -146,9 +151,10 @@ cc_library(
":rtp",
":video",
"//c-toxcore/toxcore:Messenger",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:network",
"//c-toxcore/toxcore:util",
],
)

Expand Down
1 change: 1 addition & 0 deletions toxav/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "rtp.h"

#include "../toxcore/ccompat.h"
#include "../toxcore/logger.h"
#include "../toxcore/mono_time.h"

Expand Down
1 change: 1 addition & 0 deletions toxav/bwcontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "ring_buffer.h"

#include "../toxcore/ccompat.h"
#include "../toxcore/logger.h"
#include "../toxcore/mono_time.h"
#include "../toxcore/util.h"
Expand Down
1 change: 1 addition & 0 deletions toxav/groupav.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdlib.h>
#include <string.h>

#include "../toxcore/ccompat.h"
#include "../toxcore/logger.h"
#include "../toxcore/mono_time.h"
#include "../toxcore/util.h"
Expand Down
64 changes: 24 additions & 40 deletions toxav/msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>

#include "../toxcore/ccompat.h"
#include "../toxcore/logger.h"
#include "../toxcore/util.h"

Expand Down Expand Up @@ -79,48 +80,31 @@ static msi_action_cb *get_callback(MSISession *session, MSICallbackID id);
* Public functions
*/

void msi_register_callback(MSISession *session, msi_action_cb *callback, MSICallbackID id)
void msi_callback_invite(MSISession *session, msi_action_cb *callback)
{
if (session == nullptr) {
return;
}

pthread_mutex_lock(session->mutex);

switch (id) {
case MSI_ON_INVITE: {
session->invite_callback = callback;
break;
}

case MSI_ON_START: {
session->start_callback = callback;
break;
}

case MSI_ON_END: {
session->end_callback = callback;
break;
}

case MSI_ON_ERROR: {
session->error_callback = callback;
break;
}

case MSI_ON_PEERTIMEOUT: {
session->peertimeout_callback = callback;
break;
}

case MSI_ON_CAPABILITIES: {
session->capabilities_callback = callback;
break;
}
}

pthread_mutex_unlock(session->mutex);
session->invite_callback = callback;
}
void msi_callback_start(MSISession *session, msi_action_cb *callback)
{
session->start_callback = callback;
}
void msi_callback_end(MSISession *session, msi_action_cb *callback)
{
session->end_callback = callback;
}
void msi_callback_error(MSISession *session, msi_action_cb *callback)
{
session->error_callback = callback;
}
void msi_callback_peertimeout(MSISession *session, msi_action_cb *callback)
{
session->peertimeout_callback = callback;
}
void msi_callback_capabilities(MSISession *session, msi_action_cb *callback)
{
session->capabilities_callback = callback;
}

MSISession *msi_new(Messenger *m)
{
if (m == nullptr) {
Expand Down
9 changes: 7 additions & 2 deletions toxav/msi.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,14 @@ MSISession *msi_new(Messenger *m);
*/
int msi_kill(MSISession *session, const Logger *log);
/**
* Callback setter.
* Callback setters.
*/
void msi_register_callback(MSISession *session, msi_action_cb *callback, MSICallbackID id);
void msi_callback_invite(MSISession *session, msi_action_cb *callback);
void msi_callback_start(MSISession *session, msi_action_cb *callback);
void msi_callback_end(MSISession *session, msi_action_cb *callback);
void msi_callback_error(MSISession *session, msi_action_cb *callback);
void msi_callback_peertimeout(MSISession *session, msi_action_cb *callback);
void msi_callback_capabilities(MSISession *session, msi_action_cb *callback);
/**
* Send invite request to friend_number.
*/
Expand Down
1 change: 1 addition & 0 deletions toxav/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "bwcontroller.h"

#include "../toxcore/Messenger.h"
#include "../toxcore/ccompat.h"
#include "../toxcore/logger.h"
#include "../toxcore/mono_time.h"
#include "../toxcore/util.h"
Expand Down
Loading