mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Implemented the 3 low level network information functions.
Added tox_get_udp_port() to tests.
This commit is contained in:
parent
916b6aa734
commit
88a8a079b6
|
@ -207,6 +207,12 @@ START_TEST(test_one)
|
|||
Tox *tox1 = tox_new(0, 0, 0, 0);
|
||||
Tox *tox2 = tox_new(0, 0, 0, 0);
|
||||
|
||||
{
|
||||
TOX_ERR_GET_PORT error;
|
||||
ck_assert_msg(tox_get_udp_port(tox1, &error) == 33445, "First Tox instance did not bind to udp port 33445.\n");
|
||||
ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error");
|
||||
}
|
||||
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(tox1, address);
|
||||
TOX_ERR_FRIEND_ADD error;
|
||||
|
@ -272,6 +278,13 @@ START_TEST(test_few_clients)
|
|||
Tox *tox2 = tox_new(0, 0, 0, 0);
|
||||
Tox *tox3 = tox_new(0, 0, 0, 0);
|
||||
ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances");
|
||||
|
||||
{
|
||||
TOX_ERR_GET_PORT error;
|
||||
ck_assert_msg(tox_get_udp_port(tox1, &error) == 33445, "First Tox instance did not bind to udp port 33445.\n");
|
||||
ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error");
|
||||
}
|
||||
|
||||
uint32_t to_compare = 974536;
|
||||
tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
|
@ -495,6 +508,12 @@ START_TEST(test_many_clients)
|
|||
tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp);
|
||||
}
|
||||
|
||||
{
|
||||
TOX_ERR_GET_PORT error;
|
||||
ck_assert_msg(tox_get_udp_port(toxes[0], &error) == 33445, "First Tox instance did not bind to udp port 33445.\n");
|
||||
ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error");
|
||||
}
|
||||
|
||||
struct {
|
||||
uint16_t tox1;
|
||||
uint16_t tox2;
|
||||
|
@ -617,6 +636,12 @@ START_TEST(test_many_group)
|
|||
tox_callback_group_invite(toxes[i], &print_group_invite_callback, &to_comp);
|
||||
}
|
||||
|
||||
{
|
||||
TOX_ERR_GET_PORT error;
|
||||
ck_assert_msg(tox_get_udp_port(toxes[0], &error) == 33445, "First Tox instance did not bind to udp port 33445.\n");
|
||||
ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error");
|
||||
}
|
||||
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(toxes[NUM_GROUP_TOX - 1], address);
|
||||
|
||||
|
|
|
@ -1076,5 +1076,33 @@ void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb
|
|||
custom_lossless_packet_registerhandler(m, function, user_data);
|
||||
}
|
||||
|
||||
void tox_get_dht_id(const Tox *tox, uint8_t *dht_id)
|
||||
{
|
||||
if (dht_id) {
|
||||
const Messenger *m = tox;
|
||||
memcpy(dht_id , m->dht->self_public_key, crypto_box_PUBLICKEYBYTES);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t tox_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error)
|
||||
{
|
||||
const Messenger *m = tox;
|
||||
uint16_t port = htons(m->net->port);
|
||||
|
||||
if (port) {
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK);
|
||||
} else {
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_NOT_BOUND);
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
uint16_t tox_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error)
|
||||
{
|
||||
/* TCP server not yet implemented in clients. */
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_NOT_BOUND);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "tox_old.c"
|
||||
|
|
Loading…
Reference in New Issue
Block a user