Skip to content

Commit 132b8bd

Browse files
committed
refactor: Use struct wrapper for Family.
1 parent fc0b2ae commit 132b8bd

18 files changed

+92
-85
lines changed

auto_tests/auto_test_support.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,38 @@ static const struct BootstrapNodes {
3636
const uint8_t key[32];
3737
} bootstrap_nodes[] = {
3838
{
39-
"tox.abilinski.com", 33445,
40-
0x10, 0xC0, 0x0E, 0xB2, 0x50, 0xC3, 0x23, 0x3E,
41-
0x34, 0x3E, 0x2A, 0xEB, 0xA0, 0x71, 0x15, 0xA5,
42-
0xC2, 0x89, 0x20, 0xE9, 0xC8, 0xD2, 0x94, 0x92,
43-
0xF6, 0xD0, 0x0B, 0x29, 0x04, 0x9E, 0xDC, 0x7E,
39+
"tox.abilinski.com", 33445, {
40+
0x10, 0xC0, 0x0E, 0xB2, 0x50, 0xC3, 0x23, 0x3E,
41+
0x34, 0x3E, 0x2A, 0xEB, 0xA0, 0x71, 0x15, 0xA5,
42+
0xC2, 0x89, 0x20, 0xE9, 0xC8, 0xD2, 0x94, 0x92,
43+
0xF6, 0xD0, 0x0B, 0x29, 0x04, 0x9E, 0xDC, 0x7E,
44+
},
4445
},
4546
{
46-
"tox.initramfs.io", 33445,
47-
0x02, 0x80, 0x7C, 0xF4, 0xF8, 0xBB, 0x8F, 0xB3,
48-
0x90, 0xCC, 0x37, 0x94, 0xBD, 0xF1, 0xE8, 0x44,
49-
0x9E, 0x9A, 0x83, 0x92, 0xC5, 0xD3, 0xF2, 0x20,
50-
0x00, 0x19, 0xDA, 0x9F, 0x1E, 0x81, 0x2E, 0x46,
47+
"tox.initramfs.io", 33445, {
48+
0x02, 0x80, 0x7C, 0xF4, 0xF8, 0xBB, 0x8F, 0xB3,
49+
0x90, 0xCC, 0x37, 0x94, 0xBD, 0xF1, 0xE8, 0x44,
50+
0x9E, 0x9A, 0x83, 0x92, 0xC5, 0xD3, 0xF2, 0x20,
51+
0x00, 0x19, 0xDA, 0x9F, 0x1E, 0x81, 0x2E, 0x46,
52+
},
5153
},
5254
{
53-
"tox.plastiras.org", 33445,
54-
0x8E, 0x8B, 0x63, 0x29, 0x9B, 0x3D, 0x52, 0x0F,
55-
0xB3, 0x77, 0xFE, 0x51, 0x00, 0xE6, 0x5E, 0x33,
56-
0x22, 0xF7, 0xAE, 0x5B, 0x20, 0xA0, 0xAC, 0xED,
57-
0x29, 0x81, 0x76, 0x9F, 0xC5, 0xB4, 0x37, 0x25,
55+
"tox.plastiras.org", 33445, {
56+
0x8E, 0x8B, 0x63, 0x29, 0x9B, 0x3D, 0x52, 0x0F,
57+
0xB3, 0x77, 0xFE, 0x51, 0x00, 0xE6, 0x5E, 0x33,
58+
0x22, 0xF7, 0xAE, 0x5B, 0x20, 0xA0, 0xAC, 0xED,
59+
0x29, 0x81, 0x76, 0x9F, 0xC5, 0xB4, 0x37, 0x25,
60+
},
5861
},
5962
{
60-
"tox.novg.net", 33445,
61-
0xD5, 0x27, 0xE5, 0x84, 0x7F, 0x83, 0x30, 0xD6,
62-
0x28, 0xDA, 0xB1, 0x81, 0x4F, 0x0A, 0x42, 0x2F,
63-
0x6D, 0xC9, 0xD0, 0xA3, 0x00, 0xE6, 0xC3, 0x57,
64-
0x63, 0x4E, 0xE2, 0xDA, 0x88, 0xC3, 0x54, 0x63,
63+
"tox.novg.net", 33445, {
64+
0xD5, 0x27, 0xE5, 0x84, 0x7F, 0x83, 0x30, 0xD6,
65+
0x28, 0xDA, 0xB1, 0x81, 0x4F, 0x0A, 0x42, 0x2F,
66+
0x6D, 0xC9, 0xD0, 0xA3, 0x00, 0xE6, 0xC3, 0x57,
67+
0x63, 0x4E, 0xE2, 0xDA, 0x88, 0xC3, 0x54, 0x63,
68+
},
6569
},
66-
{ nullptr, 0, 0 },
70+
{ nullptr, 0, {0} },
6771
};
6872

6973
void bootstrap_tox_live_network(Tox *tox, bool enable_tcp)

auto_tests/forwarding_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static Forwarding_Subtox *new_forwarding_subtox(const Memory *mem, bool no_udp,
126126

127127
subtox->dht = new_dht(subtox->log, mem, rng, ns, subtox->mono_time, subtox->net, true, true);
128128

129-
const TCP_Proxy_Info inf = {{{0}}};
129+
const TCP_Proxy_Info inf = {{{{0}}}};
130130
subtox->c = new_net_crypto(subtox->log, mem, rng, ns, subtox->mono_time, subtox->dht, &inf);
131131

132132
subtox->forwarding = new_forwarding(subtox->log, rng, subtox->mono_time, subtox->dht);

auto_tests/network_test.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void test_addr_resolv_localhost(void)
3636
net_kill_strerror(strerror);
3737

3838
Ip_Ntoa ip_str;
39-
ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family NET_FAMILY_IPV4, got %u.", ip.family);
39+
ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family NET_FAMILY_IPV4, got %u.", ip.family.value);
4040
const uint32_t loopback = get_ip4_loopback().uint32;
4141
ck_assert_msg(ip.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.",
4242
net_ip_ntoa(&ip, &ip_str));
@@ -59,7 +59,7 @@ static void test_addr_resolv_localhost(void)
5959
net_kill_strerror(strerror);
6060

6161
ck_assert_msg(net_family_is_ipv6(ip.family), "Expected family NET_FAMILY_IPV6 (%d), got %u.", NET_FAMILY_IPV6,
62-
ip.family);
62+
ip.family.value);
6363
IP6 ip6_loopback = get_ip6_loopback();
6464
ck_assert_msg(!memcmp(&ip.ip.v6, &ip6_loopback, sizeof(IP6)), "Expected ::1, got %s.",
6565
net_ip_ntoa(&ip, &ip_str));
@@ -83,17 +83,17 @@ static void test_addr_resolv_localhost(void)
8383

8484
#if USE_IPV6
8585
ck_assert_msg(net_family_is_ipv6(ip.family), "Expected family NET_FAMILY_IPV6 (%d), got %u.", NET_FAMILY_IPV6,
86-
ip.family);
86+
ip.family.value);
8787
ck_assert_msg(!memcmp(&ip.ip.v6, &ip6_loopback, sizeof(IP6)), "Expected ::1, got %s.",
8888
net_ip_ntoa(&ip, &ip_str));
8989

9090
ck_assert_msg(net_family_is_ipv4(extra.family), "Expected family NET_FAMILY_IPV4 (%d), got %u.", NET_FAMILY_IPV4,
91-
extra.family);
91+
extra.family.value);
9292
ck_assert_msg(extra.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.",
9393
net_ip_ntoa(&ip, &ip_str));
9494
#elif 0
9595
// TODO(iphydf): Fix this to work on IPv6-supporting systems.
96-
ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family NET_FAMILY_IPV4 (%d), got %u.", NET_FAMILY_IPV4, ip.family);
96+
ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family NET_FAMILY_IPV4 (%d), got %u.", NET_FAMILY_IPV4, ip.family.value);
9797
ck_assert_msg(ip.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.",
9898
net_ip_ntoa(&ip, &ip_str));
9999
#endif

auto_tests/onion_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ static Onions *new_onions(const Memory *mem, const Random *rng, uint16_t port, u
471471
return nullptr;
472472
}
473473

474-
TCP_Proxy_Info inf = {{{0}}};
474+
TCP_Proxy_Info inf = {{{{0}}}};
475475
on->onion_c = new_onion_client(on->log, mem, rng, on->mono_time, new_net_crypto(on->log, mem, rng, ns, on->mono_time, dht, &inf));
476476

477477
if (!on->onion_c) {

toxcore/DHT.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ static bool client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_t
606606
LOGGER_DEBUG(log, "coipil[%u]: switching public_key (ipv%d)", index, ip_version);
607607

608608
/* kill the other address, if it was set */
609-
const IPPTsPng empty_ipptspng = {{{0}}};
609+
const IPPTsPng empty_ipptspng = {{{{0}}}};
610610
*assoc = empty_ipptspng;
611611
return true;
612612
}
@@ -964,7 +964,7 @@ static void update_client_with_reset(const Mono_Time *mono_time, Client_data *cl
964964
ipptp_write->ret_ip_self = false;
965965

966966
/* zero out other address */
967-
const IPPTsPng empty_ipptp = {{{0}}};
967+
const IPPTsPng empty_ipptp = {{{{0}}}};
968968
*ipptp_clear = empty_ipptp;
969969
}
970970

toxcore/DHT_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ TEST(AddToList, OverridesKeysWithCloserKeys)
116116

117117
std::array<Node_format, 4> nodes{};
118118

119-
IP_Port ip_port = {NET_FAMILY_UNSPEC};
119+
IP_Port ip_port = {{{NET_FAMILY_UNSPEC}}};
120120
EXPECT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[0].data(), &ip_port, self_pk.data()));
121121
EXPECT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[1].data(), &ip_port, self_pk.data()));
122122
EXPECT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[2].data(), &ip_port, self_pk.data()));
@@ -355,7 +355,7 @@ TEST(AnnounceNodes, SetAndTest)
355355
PublicKey pk2(to_array(pk_data));
356356
ASSERT_NE(pk2, pk1);
357357

358-
IP_Port ip_port = {NET_FAMILY_UNSPEC};
358+
IP_Port ip_port = {{{NET_FAMILY_UNSPEC}}};
359359
ip_port.ip.family = net_family_ipv4();
360360

361361
set_announce_node(dht.get(), pk1.data());

toxcore/TCP_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ TCP_Client_Connection *new_tcp_connection(
594594
return nullptr;
595595
}
596596

597-
const TCP_Proxy_Info default_proxyinfo = {{{0}}};
597+
const TCP_Proxy_Info default_proxyinfo = {{{{0}}}};
598598

599599
if (proxy_info == nullptr) {
600600
proxy_info = &default_proxyinfo;

toxcore/TCP_connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ void set_forwarding_packet_tcp_connection_callback(TCP_Connections *tcp_c,
578578
*/
579579
IP_Port tcp_connections_number_to_ip_port(unsigned int tcp_connections_number)
580580
{
581-
IP_Port ip_port = {{0}};
581+
IP_Port ip_port = {{{0}}};
582582
ip_port.ip.family = net_family_tcp_server();
583583
ip_port.ip.ip.v6.uint32[0] = tcp_connections_number;
584584
return ip_port;

toxcore/TCP_server.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static int handle_tcp_handshake(const Logger *logger, TCP_Secure_Connection *con
355355
return -1;
356356
}
357357

358-
const IP_Port ipp = {{0}};
358+
const IP_Port ipp = {{{0}}};
359359

360360
if (TCP_SERVER_HANDSHAKE_SIZE != net_send(con->con.ns, logger, con->con.sock, response, TCP_SERVER_HANDSHAKE_SIZE, &ipp)) {
361361
crypto_memzero(shared_key, sizeof(shared_key));
@@ -584,7 +584,7 @@ static int rm_connection_index(TCP_Server *tcp_server, TCP_Secure_Connection *co
584584
*/
585585
static IP_Port con_id_to_ip_port(uint32_t con_id, uint64_t identifier)
586586
{
587-
IP_Port ip_port = {{0}};
587+
IP_Port ip_port = {{{0}}};
588588
ip_port.ip.family = net_family_tcp_client();
589589
ip_port.ip.ip.v6.uint32[0] = con_id;
590590
ip_port.ip.ip.v6.uint64[1] = identifier;
@@ -919,7 +919,7 @@ static Socket new_listening_tcp_socket(const Logger *logger, const Network *ns,
919919
const Socket sock = net_socket(ns, family, TOX_SOCK_STREAM, TOX_PROTO_TCP);
920920

921921
if (!sock_valid(sock)) {
922-
LOGGER_ERROR(logger, "TCP socket creation failed (family = %d)", family);
922+
LOGGER_ERROR(logger, "TCP socket creation failed (family = %d)", family.value);
923923
return net_invalid_socket();
924924
}
925925

@@ -938,7 +938,7 @@ static Socket new_listening_tcp_socket(const Logger *logger, const Network *ns,
938938
if (!ok) {
939939
char *const error = net_new_strerror(net_error());
940940
LOGGER_WARNING(logger, "could not bind to TCP port %d (family = %d): %s",
941-
port, family, error != nullptr ? error : "(null)");
941+
port, family.value, error != nullptr ? error : "(null)");
942942
net_kill_strerror(error);
943943
kill_sock(ns, sock);
944944
return net_invalid_socket();

toxcore/group_announce_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ TEST_F(AnnouncesPack, AnnouncesValidationCheck)
215215
EXPECT_EQ(gca_is_valid_announce(nullptr), false);
216216
#endif
217217

218-
GC_Announce announce = {0};
218+
GC_Announce announce = {{{{0}}}};
219219
EXPECT_EQ(gca_is_valid_announce(&announce), false);
220220
EXPECT_EQ(gca_is_valid_announce(&announces_[0]), true);
221221
EXPECT_EQ(gca_is_valid_announce(&announces_[1]), true);

0 commit comments

Comments
 (0)