mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
cleanup: Remove port from Broadcast_Info
.
This is added later when we actually send the broadcasts.
This commit is contained in:
parent
64254d6459
commit
6c2014d719
|
@ -152,7 +152,7 @@ void set_mono_time_callback(AutoTox *autotox)
|
|||
Mono_Time *mono_time = ((Messenger *)autotox->tox)->mono_time;
|
||||
|
||||
autotox->clock = current_time_monotonic(mono_time);
|
||||
mono_time_set_current_time_callback(mono_time, nullptr, &autotox->clock); // set to default first
|
||||
mono_time_set_current_time_callback(mono_time, nullptr, nullptr); // set to default first
|
||||
mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &autotox->clock);
|
||||
}
|
||||
|
||||
|
@ -379,8 +379,11 @@ Tox *tox_new_log_lan(struct Tox_Options *options, Tox_Err_New *err, void *log_us
|
|||
assert(log_options != nullptr);
|
||||
|
||||
tox_options_set_local_discovery_enabled(log_options, lan_discovery);
|
||||
tox_options_set_start_port(log_options, 33445);
|
||||
tox_options_set_end_port(log_options, 33445 + 2000);
|
||||
// Use a higher start port for non-LAN-discovery tests so it's more likely for the LAN discovery
|
||||
// test to get the default port 33445.
|
||||
const uint16_t start_port = lan_discovery ? 33445 : 33545;
|
||||
tox_options_set_start_port(log_options, start_port);
|
||||
tox_options_set_end_port(log_options, start_port + 2000);
|
||||
tox_options_set_log_callback(log_options, &print_debug_log);
|
||||
tox_options_set_log_user_data(log_options, log_user_data);
|
||||
Tox *tox = tox_new(log_options, err);
|
||||
|
|
|
@ -5,11 +5,32 @@
|
|||
#include "../toxcore/ccompat.h"
|
||||
#include "auto_test_support.h"
|
||||
|
||||
static uint64_t get_state_clock_callback(Mono_Time *mono_time, void *user_data)
|
||||
{
|
||||
const uint64_t *clock = (const uint64_t *)user_data;
|
||||
return *clock;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
Tox *tox1 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true);
|
||||
Tox *tox2 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true);
|
||||
ck_assert(tox1 != nullptr);
|
||||
ck_assert(tox2 != nullptr);
|
||||
|
||||
// TODO(iphydf): Don't rely on toxcore internals.
|
||||
uint64_t clock = current_time_monotonic(((Messenger *)tox1)->mono_time);
|
||||
Mono_Time *mono_time;
|
||||
|
||||
// TODO(iphydf): Don't rely on toxcore internals.
|
||||
mono_time = ((Messenger *)tox1)->mono_time;
|
||||
mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &clock);
|
||||
|
||||
// TODO(iphydf): Don't rely on toxcore internals.
|
||||
mono_time = ((Messenger *)tox2)->mono_time;
|
||||
mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &clock);
|
||||
|
||||
printf("Waiting for LAN discovery. This loop will attempt to run until successful.");
|
||||
|
||||
|
@ -19,7 +40,8 @@ int main(void)
|
|||
|
||||
tox_iterate(tox1, nullptr);
|
||||
tox_iterate(tox2, nullptr);
|
||||
c_sleep(1000);
|
||||
c_sleep(5);
|
||||
clock += 100;
|
||||
} while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE ||
|
||||
tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE);
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
eb9e7efd034de17ba6af095bbfd595308ff994148f394e715087078859d860f6 /usr/local/bin/tox-bootstrapd
|
||||
ce191b497af89aafb2837d053043469c725ea7af0b1aa2bbedc39f8de2686d56 /usr/local/bin/tox-bootstrapd
|
||||
|
|
|
@ -71,7 +71,7 @@ def run_mallocfail(tmpdir: str, timeout: float, exe: str,
|
|||
print(f"\x1b[0;34mProgram '{exe}' timed out\x1b[0m")
|
||||
else:
|
||||
print(
|
||||
f"\x1b[1;34mProgram '{exe}' failed to handle OOM situation cleanly\x1b[0m"
|
||||
f"\x1b[1;32mProgram '{exe}' failed to handle OOM situation cleanly\x1b[0m"
|
||||
)
|
||||
raise Exception("Aborting test")
|
||||
|
||||
|
|
|
@ -46,12 +46,12 @@
|
|||
|
||||
struct Broadcast_Info {
|
||||
uint32_t count;
|
||||
IP_Port ip_ports[MAX_INTERFACES];
|
||||
IP ips[MAX_INTERFACES];
|
||||
};
|
||||
|
||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||
|
||||
static Broadcast_Info *fetch_broadcast_info(uint16_t port)
|
||||
static Broadcast_Info *fetch_broadcast_info(void)
|
||||
{
|
||||
Broadcast_Info *broadcast = (Broadcast_Info *)calloc(1, sizeof(Broadcast_Info));
|
||||
|
||||
|
@ -89,13 +89,12 @@ static Broadcast_Info *fetch_broadcast_info(uint16_t port)
|
|||
if (addr_parse_ip(pAdapter->IpAddressList.IpMask.String, &subnet_mask)
|
||||
&& addr_parse_ip(pAdapter->GatewayList.IpAddress.String, &gateway)) {
|
||||
if (net_family_is_ipv4(gateway.family) && net_family_is_ipv4(subnet_mask.family)) {
|
||||
IP_Port *ip_port = &broadcast->ip_ports[broadcast->count];
|
||||
ip_port->ip.family = net_family_ipv4;
|
||||
IP *ip = &broadcast->ips[broadcast->count];
|
||||
ip->family = net_family_ipv4;
|
||||
const uint32_t gateway_ip = net_ntohl(gateway.ip.v4.uint32);
|
||||
const uint32_t subnet_ip = net_ntohl(subnet_mask.ip.v4.uint32);
|
||||
const uint32_t broadcast_ip = gateway_ip + ~subnet_ip - 1;
|
||||
ip_port->ip.ip.v4.uint32 = net_htonl(broadcast_ip);
|
||||
ip_port->port = port;
|
||||
ip->ip.v4.uint32 = net_htonl(broadcast_ip);
|
||||
++broadcast->count;
|
||||
|
||||
if (broadcast->count >= MAX_INTERFACES) {
|
||||
|
@ -117,7 +116,7 @@ static Broadcast_Info *fetch_broadcast_info(uint16_t port)
|
|||
|
||||
#elif !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && (defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__))
|
||||
|
||||
static Broadcast_Info *fetch_broadcast_info(uint16_t port)
|
||||
static Broadcast_Info *fetch_broadcast_info(void)
|
||||
{
|
||||
Broadcast_Info *broadcast = (Broadcast_Info *)calloc(1, sizeof(Broadcast_Info));
|
||||
|
||||
|
@ -174,15 +173,14 @@ static Broadcast_Info *fetch_broadcast_info(uint16_t port)
|
|||
break;
|
||||
}
|
||||
|
||||
IP_Port *ip_port = &broadcast->ip_ports[broadcast->count];
|
||||
ip_port->ip.family = net_family_ipv4;
|
||||
ip_port->ip.ip.v4.uint32 = sock4->sin_addr.s_addr;
|
||||
IP *ip = &broadcast->ips[broadcast->count];
|
||||
ip->family = net_family_ipv4;
|
||||
ip->ip.v4.uint32 = sock4->sin_addr.s_addr;
|
||||
|
||||
if (ip_port->ip.ip.v4.uint32 == 0) {
|
||||
if (ip->ip.v4.uint32 == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ip_port->port = port;
|
||||
++broadcast->count;
|
||||
}
|
||||
|
||||
|
@ -193,7 +191,7 @@ static Broadcast_Info *fetch_broadcast_info(uint16_t port)
|
|||
|
||||
#else // TODO(irungentoo): Other platforms?
|
||||
|
||||
static Broadcast_Info *fetch_broadcast_info(uint16_t port)
|
||||
static Broadcast_Info *fetch_broadcast_info(void)
|
||||
{
|
||||
return (Broadcast_Info *)calloc(1, sizeof(Broadcast_Info));
|
||||
}
|
||||
|
@ -214,7 +212,10 @@ static bool send_broadcasts(const Networking_Core *net, const Broadcast_Info *br
|
|||
}
|
||||
|
||||
for (uint32_t i = 0; i < broadcast->count; ++i) {
|
||||
sendpacket(net, &broadcast->ip_ports[i], data, length);
|
||||
IP_Port ip_port;
|
||||
ip_port.ip = broadcast->ips[i];
|
||||
ip_port.port = port;
|
||||
sendpacket(net, &ip_port, data, length);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -393,7 +394,7 @@ bool lan_discovery_send(Networking_Core *net, const Broadcast_Info *broadcast, c
|
|||
|
||||
Broadcast_Info *lan_discovery_init(DHT *dht)
|
||||
{
|
||||
Broadcast_Info *broadcast = fetch_broadcast_info(net_htons(TOX_PORT_DEFAULT));
|
||||
Broadcast_Info *broadcast = fetch_broadcast_info();
|
||||
networking_registerhandler(dht_get_net(dht), NET_PACKET_LAN_DISCOVERY, &handle_LANdiscovery, dht);
|
||||
return broadcast;
|
||||
}
|
||||
|
|
|
@ -19,16 +19,23 @@ static void set_random_name_and_status_message(Tox *tox, uint8_t *name, uint8_t
|
|||
|
||||
TEST(Tox, OneTest)
|
||||
{
|
||||
struct Tox_Options *options = tox_options_new(nullptr);
|
||||
ASSERT_NE(options, nullptr);
|
||||
|
||||
// Higher start/end point here to avoid conflict with the LAN discovery test.
|
||||
tox_options_set_start_port(options, 33545);
|
||||
tox_options_set_end_port(options, 33545 + 2000);
|
||||
|
||||
std::array<uint8_t, TOX_MAX_NAME_LENGTH> name;
|
||||
std::array<uint8_t, TOX_MAX_STATUS_MESSAGE_LENGTH> status_message;
|
||||
|
||||
std::array<uint8_t, TOX_MAX_NAME_LENGTH> name2;
|
||||
std::array<uint8_t, TOX_MAX_STATUS_MESSAGE_LENGTH> status_message2;
|
||||
|
||||
Tox *tox1 = tox_new(nullptr, nullptr);
|
||||
Tox *tox1 = tox_new(options, nullptr);
|
||||
ASSERT_NE(tox1, nullptr);
|
||||
set_random_name_and_status_message(tox1, name.data(), status_message.data());
|
||||
Tox *tox2 = tox_new(nullptr, nullptr);
|
||||
Tox *tox2 = tox_new(options, nullptr);
|
||||
ASSERT_NE(tox2, nullptr);
|
||||
set_random_name_and_status_message(tox2, name2.data(), status_message2.data());
|
||||
|
||||
|
@ -79,8 +86,6 @@ TEST(Tox, OneTest)
|
|||
tox_kill(tox2);
|
||||
Tox_Err_New err_n;
|
||||
|
||||
struct Tox_Options *options = tox_options_new(nullptr);
|
||||
ASSERT_NE(options, nullptr);
|
||||
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
|
||||
tox_options_set_savedata_data(options, data.data(), data.size());
|
||||
tox2 = tox_new(options, &err_n);
|
||||
|
|
Loading…
Reference in New Issue
Block a user