Skip to content

Commit

Permalink
Make tox_callback_friend_name stateless.
Browse files Browse the repository at this point in the history
See TokTok#27 and TokTok#40 for details.
  • Loading branch information
iphydf committed Aug 17, 2016
1 parent db22522 commit ff6c471
Show file tree
Hide file tree
Showing 32 changed files with 161 additions and 153 deletions.
82 changes: 42 additions & 40 deletions auto_tests/TCP_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ static int status_callback(void *object, uint32_t number, uint8_t connection_id,
return 0;
}
static int data_callback_good;
static int data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length)
static int data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length,
void *userdata)
{
if (object != (void *)3)
return 1;
Expand All @@ -355,7 +356,8 @@ static int data_callback(void *object, uint32_t number, uint8_t connection_id, c

static int oob_data_callback_good;
static uint8_t oob_pubkey[crypto_box_PUBLICKEYBYTES];
static int oob_data_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length)
static int oob_data_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length,
void *userdata)
{
if (object != (void *)4)
return 1;
Expand Down Expand Up @@ -394,21 +396,21 @@ START_TEST(test_client)
ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback;
TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0);
c_sleep(50);
do_TCP_connection(conn);
do_TCP_connection(conn, NULL);
ck_assert_msg(conn->status == TCP_CLIENT_UNCONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_UNCONFIRMED,
conn->status);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_TCP_connection(conn);
do_TCP_connection(conn, NULL);
ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
conn->status);
c_sleep(500);
do_TCP_connection(conn);
do_TCP_connection(conn, NULL);
ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
conn->status);
c_sleep(500);
do_TCP_connection(conn);
do_TCP_connection(conn, NULL);
ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
conn->status);
do_TCP_server(tcp_s);
Expand All @@ -427,13 +429,13 @@ START_TEST(test_client)
oob_data_handler(conn, oob_data_callback, (void *)4);
oob_data_callback_good = response_callback_good = status_callback_good = data_callback_good = 0;
c_sleep(50);
do_TCP_connection(conn);
do_TCP_connection(conn2);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn2, NULL);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_TCP_connection(conn);
do_TCP_connection(conn2);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn2, NULL);
c_sleep(50);
uint8_t data[5] = {1, 2, 3, 4, 5};
memcpy(oob_pubkey, f2_public_key, crypto_box_PUBLICKEYBYTES);
Expand All @@ -443,8 +445,8 @@ START_TEST(test_client)
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_TCP_connection(conn);
do_TCP_connection(conn2);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn2, NULL);
ck_assert_msg(oob_data_callback_good == 1, "oob callback not called");
ck_assert_msg(response_callback_good == 1, "response callback not called");
ck_assert_msg(public_key_cmp(response_callback_public_key, f2_public_key) == 0, "wrong public key");
Expand All @@ -457,16 +459,16 @@ START_TEST(test_client)
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_TCP_connection(conn);
do_TCP_connection(conn2);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn2, NULL);
ck_assert_msg(data_callback_good == 1, "data callback not called");
status_callback_good = 0;
send_disconnect_request(conn2, 0);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_TCP_connection(conn);
do_TCP_connection(conn2);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn2, NULL);
ck_assert_msg(status_callback_good == 1, "status callback not called");
ck_assert_msg(status_callback_status == 1, "wrong status");
kill_TCP_server(tcp_s);
Expand All @@ -492,15 +494,15 @@ START_TEST(test_client_invalid)
ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback;
TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0);
c_sleep(50);
do_TCP_connection(conn);
do_TCP_connection(conn, NULL);
ck_assert_msg(conn->status == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONNECTING,
conn->status);
c_sleep(5000);
do_TCP_connection(conn);
do_TCP_connection(conn, NULL);
ck_assert_msg(conn->status == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONNECTING,
conn->status);
c_sleep(6000);
do_TCP_connection(conn);
do_TCP_connection(conn, NULL);
ck_assert_msg(conn->status == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_DISCONNECTED,
conn->status);

Expand All @@ -511,7 +513,7 @@ END_TEST
#include "../toxcore/TCP_connection.h"

_Bool tcp_data_callback_called;
static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t length)
static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t length, void *userdata)
{
if (object != (void *)120397)
return -1;
Expand Down Expand Up @@ -572,18 +574,18 @@ START_TEST(test_tcp_connection)
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1);
do_tcp_connections(tc_2);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1);
do_tcp_connections(tc_2);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1);
do_tcp_connections(tc_2);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);

int ret = send_packet_tcp_connection(tc_1, 0, "Gentoo", 6);
ck_assert_msg(ret == 0, "could not send packet.");
Expand All @@ -593,8 +595,8 @@ START_TEST(test_tcp_connection)
do_TCP_server(tcp_s);
c_sleep(50);

do_tcp_connections(tc_1);
do_tcp_connections(tc_2);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);

ck_assert_msg(tcp_data_callback_called, "could not recv packet.");
ck_assert_msg(tcp_connection_to_online_tcp_relays(tc_1, 0) == 1, "Wrong number of connected relays");
Expand All @@ -603,8 +605,8 @@ START_TEST(test_tcp_connection)
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1);
do_tcp_connections(tc_2);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);

ck_assert_msg(send_packet_tcp_connection(tc_1, 0, "Gentoo", 6) == -1, "could send packet.");
ck_assert_msg(kill_tcp_connection_to(tc_2, 0) == 0, "could not kill connection to\n");
Expand Down Expand Up @@ -669,18 +671,18 @@ START_TEST(test_tcp_connection2)
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1);
do_tcp_connections(tc_2);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1);
do_tcp_connections(tc_2);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1);
do_tcp_connections(tc_2);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);

int ret = send_packet_tcp_connection(tc_1, 0, "Gentoo", 6);
ck_assert_msg(ret == 0, "could not send packet.");
Expand All @@ -691,17 +693,17 @@ START_TEST(test_tcp_connection2)
do_TCP_server(tcp_s);
c_sleep(50);

do_tcp_connections(tc_1);
do_tcp_connections(tc_2);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);

ck_assert_msg(tcp_oobdata_callback_called, "could not recv packet.");

c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);

do_tcp_connections(tc_1);
do_tcp_connections(tc_2);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);

ck_assert_msg(tcp_data_callback_called, "could not recv packet.");
ck_assert_msg(kill_tcp_connection_to(tc_1, 0) == 0, "could not kill connection to\n");
Expand Down
2 changes: 1 addition & 1 deletion auto_tests/dht_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ START_TEST(test_DHT_test)
}

for (i = 0; i < NUM_DHT; ++i) {
networking_poll(dhts[i]->net);
networking_poll(dhts[i]->net, NULL);
do_DHT(dhts[i]);
}

Expand Down
12 changes: 6 additions & 6 deletions auto_tests/onion_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

void do_onion(Onion *onion)
{
networking_poll(onion->net);
networking_poll(onion->net, NULL);
do_DHT(onion->dht);
}

static int handled_test_1;
static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
{
Onion *onion = object;

Expand All @@ -46,7 +46,7 @@ static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, ui
}

static int handled_test_2;
static int handle_test_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
static int handle_test_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
{
if (length != sizeof("install Gentoo"))
return 1;
Expand All @@ -72,7 +72,7 @@ uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH];
static int handled_test_3;
uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES];
uint8_t test_3_ping_id[crypto_hash_sha256_BYTES];
static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
{
Onion *onion = object;

Expand Down Expand Up @@ -101,7 +101,7 @@ static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, ui

uint8_t nonce[crypto_box_NONCEBYTES];
static int handled_test_4;
static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
{
Onion *onion = object;

Expand Down Expand Up @@ -286,7 +286,7 @@ Onions *new_onions(uint16_t port)

void do_onions(Onions *on)
{
networking_poll(on->onion->net);
networking_poll(on->onion->net, NULL);
do_DHT(on->onion->dht);
do_onion_client(on->onion_c);
}
Expand Down
2 changes: 1 addition & 1 deletion auto_tests/tox_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ START_TEST(test_few_clients)
}

printf("tox clients connected took %llu seconds\n", time(NULL) - con_time);
tox_callback_friend_name(tox3, print_nickchange, &to_compare);
tox_callback_friend_name(tox3, print_nickchange);
TOX_ERR_SET_INFO err_n;
bool succ = tox_self_set_name(tox2, (uint8_t *)"Gentoo", sizeof("Gentoo"), &err_n);
ck_assert_msg(succ && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_name failed because %u\n", err_n);
Expand Down
2 changes: 1 addition & 1 deletion other/DHT_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ int main(int argc, char *argv[])
#ifdef TCP_RELAY_ENABLED
do_TCP_server(tcp_s);
#endif
networking_poll(dht->net);
networking_poll(dht->net, NULL);

c_sleep(1);
}
Expand Down
2 changes: 1 addition & 1 deletion other/apidsl/tox.in.h
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ namespace friend {
/**
* This event is triggered when a friend changes their name.
*/
event name {
event name const {
/**
* @param friend_number The friend number of the friend whose name changed.
* @param name A byte array containing the same data as
Expand Down
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/src/tox-bootstrapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ int main(int argc, char *argv[])
do_TCP_server(tcp_server);
}

networking_poll(dht->net);
networking_poll(dht->net, NULL);

if (waiting_for_dht_connection && DHT_isconnected(dht)) {
write_log(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n");
Expand Down
2 changes: 1 addition & 1 deletion other/bootstrap_node_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static uint16_t bootstrap_motd_length;
/* To request this packet just send a packet of length INFO_REQUEST_PACKET_LENGTH
* with the first byte being BOOTSTRAP_INFO_PACKET_ID
*/
static int handle_info_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
static int handle_info_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
{
if (length != INFO_REQUEST_PACKET_LENGTH)
return 1;
Expand Down
2 changes: 1 addition & 1 deletion testing/DHT_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ int main(int argc, char *argv[])
}
}
*/
networking_poll(dht->net);
networking_poll(dht->net, NULL);

print_clientlist(dht);
print_friendlist(dht);
Expand Down
2 changes: 1 addition & 1 deletion testing/nTox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ int main(int argc, char *argv[])

tox_callback_friend_request(m, print_request, NULL);
tox_callback_friend_message(m, print_message, NULL);
tox_callback_friend_name(m, print_nickchange, NULL);
tox_callback_friend_name(m, print_nickchange);
tox_callback_friend_status_message(m, print_statuschange, NULL);
tox_callback_group_invite(m, print_invite, NULL);
tox_callback_group_message(m, print_groupmessage, NULL);
Expand Down
6 changes: 3 additions & 3 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
return sendpacket(dht->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + len);
}

static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
{
if (length != (1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof(
uint64_t) + crypto_box_MACBYTES))
Expand Down Expand Up @@ -1285,7 +1285,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
return 0;
}

static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
{
DHT *dht = object;
Node_format plain_nodes[MAX_SENT_NODES];
Expand Down Expand Up @@ -2343,7 +2343,7 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c
dht->cryptopackethandlers[byte].object = object;
}

static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
{
DHT *dht = object;

Expand Down
2 changes: 1 addition & 1 deletion toxcore/LAN_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ int LAN_ip(IP ip)
return -1;
}

static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
{
DHT *dht = object;

Expand Down
Loading

0 comments on commit ff6c471

Please sign in to comment.