diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-02-27 01:07:46 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-05-20 19:35:28 +0000 |
commit | 21675ce0d2581597b0e0a727ab4cf6cfb796a037 (patch) | |
tree | e1ac4ca63c5cc2b2dc78fcd5b20a8202eab98d9d /toxcore/onion_client.c | |
parent | 4f6ab0708c85f3e3da7726f6caecc381c6d21370 (diff) |
Finish @Diadlo's network Family abstraction.
The Family stuff in toxcore is a big mess. I'm sure I saw a bunch of bugs
on the way, but I'm not verifying that code now, so the bugs stay.
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r-- | toxcore/onion_client.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 3ee3e0ca..fa6c08c9 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -163,7 +163,7 @@ Net_Crypto *onion_get_net_crypto(const Onion_Client *onion_c) | |||
163 | */ | 163 | */ |
164 | int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key) | 164 | int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key) |
165 | { | 165 | { |
166 | if (ip_port.ip.family != TOX_AF_INET && ip_port.ip.family != TOX_AF_INET6) { | 166 | if (!net_family_is_ipv4(ip_port.ip.family) && !net_family_is_ipv6(ip_port.ip.family)) { |
167 | return -1; | 167 | return -1; |
168 | } | 168 | } |
169 | 169 | ||
@@ -196,7 +196,7 @@ int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t | |||
196 | */ | 196 | */ |
197 | static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key) | 197 | static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key) |
198 | { | 198 | { |
199 | if (ip_port.ip.family != TOX_AF_INET && ip_port.ip.family != TOX_AF_INET6) { | 199 | if (!net_family_is_ipv4(ip_port.ip.family) && !net_family_is_ipv6(ip_port.ip.family)) { |
200 | return -1; | 200 | return -1; |
201 | } | 201 | } |
202 | 202 | ||
@@ -282,7 +282,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format | |||
282 | } | 282 | } |
283 | 283 | ||
284 | if (num_nodes >= 2) { | 284 | if (num_nodes >= 2) { |
285 | nodes[0].ip_port.ip.family = TCP_FAMILY; | 285 | nodes[0].ip_port.ip.family = net_family_tcp_family; |
286 | nodes[0].ip_port.ip.ip.v4.uint32 = random_tcp; | 286 | nodes[0].ip_port.ip.ip.v4.uint32 = random_tcp; |
287 | 287 | ||
288 | for (i = 1; i < max_num; ++i) { | 288 | for (i = 1; i < max_num; ++i) { |
@@ -296,7 +296,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format | |||
296 | return 0; | 296 | return 0; |
297 | } | 297 | } |
298 | 298 | ||
299 | nodes[0].ip_port.ip.family = TCP_FAMILY; | 299 | nodes[0].ip_port.ip.family = net_family_tcp_family; |
300 | nodes[0].ip_port.ip.ip.v4.uint32 = random_tcp; | 300 | nodes[0].ip_port.ip.ip.v4.uint32 = random_tcp; |
301 | 301 | ||
302 | for (i = 1; i < max_num; ++i) { | 302 | for (i = 1; i < max_num; ++i) { |
@@ -465,7 +465,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t | |||
465 | static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Path *path, IP_Port dest, | 465 | static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Path *path, IP_Port dest, |
466 | const uint8_t *data, uint16_t length) | 466 | const uint8_t *data, uint16_t length) |
467 | { | 467 | { |
468 | if (path->ip_port1.ip.family == TOX_AF_INET || path->ip_port1.ip.family == TOX_AF_INET6) { | 468 | if (net_family_is_ipv4(path->ip_port1.ip.family) || net_family_is_ipv6(path->ip_port1.ip.family)) { |
469 | uint8_t packet[ONION_MAX_PACKET_SIZE]; | 469 | uint8_t packet[ONION_MAX_PACKET_SIZE]; |
470 | int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length); | 470 | int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length); |
471 | 471 | ||
@@ -480,7 +480,7 @@ static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Pa | |||
480 | return 0; | 480 | return 0; |
481 | } | 481 | } |
482 | 482 | ||
483 | if (path->ip_port1.ip.family == TCP_FAMILY) { | 483 | if (net_family_is_tcp_family(path->ip_port1.ip.family)) { |
484 | uint8_t packet[ONION_MAX_PACKET_SIZE]; | 484 | uint8_t packet[ONION_MAX_PACKET_SIZE]; |
485 | int len = create_onion_packet_tcp(packet, sizeof(packet), path, dest, data, length); | 485 | int len = create_onion_packet_tcp(packet, sizeof(packet), path, dest, data, length); |
486 | 486 | ||
@@ -987,11 +987,11 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con | |||
987 | int i; | 987 | int i; |
988 | 988 | ||
989 | for (i = 0; i < num_nodes; ++i) { | 989 | for (i = 0; i < num_nodes; ++i) { |
990 | uint8_t family = nodes[i].ip_port.ip.family; | 990 | const Family family = nodes[i].ip_port.ip.family; |
991 | 991 | ||
992 | if (family == TOX_AF_INET || family == TOX_AF_INET6) { | 992 | if (net_family_is_ipv4(family) || net_family_is_ipv6(family)) { |
993 | DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].public_key, onion_c->friends_list[friend_num].dht_public_key); | 993 | DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].public_key, onion_c->friends_list[friend_num].dht_public_key); |
994 | } else if (family == TCP_INET || family == TCP_INET6) { | 994 | } else if (net_family_is_tcp_ipv4(family) || net_family_is_tcp_ipv6(family)) { |
995 | if (onion_c->friends_list[friend_num].tcp_relay_node_callback) { | 995 | if (onion_c->friends_list[friend_num].tcp_relay_node_callback) { |
996 | void *obj = onion_c->friends_list[friend_num].tcp_relay_node_callback_object; | 996 | void *obj = onion_c->friends_list[friend_num].tcp_relay_node_callback_object; |
997 | uint32_t number = onion_c->friends_list[friend_num].tcp_relay_node_callback_number; | 997 | uint32_t number = onion_c->friends_list[friend_num].tcp_relay_node_callback_number; |
@@ -1010,8 +1010,8 @@ static int handle_tcp_onion(void *object, const uint8_t *data, uint16_t length, | |||
1010 | return 1; | 1010 | return 1; |
1011 | } | 1011 | } |
1012 | 1012 | ||
1013 | IP_Port ip_port = {{0}}; | 1013 | IP_Port ip_port = {{{0}}}; |
1014 | ip_port.ip.family = TCP_FAMILY; | 1014 | ip_port.ip.family = net_family_tcp_family; |
1015 | 1015 | ||
1016 | if (data[0] == NET_PACKET_ANNOUNCE_RESPONSE) { | 1016 | if (data[0] == NET_PACKET_ANNOUNCE_RESPONSE) { |
1017 | return handle_announce_response(object, ip_port, data, length, userdata); | 1017 | return handle_announce_response(object, ip_port, data, length, userdata); |