diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-13 13:06:08 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-13 13:06:08 +0000 |
commit | c3d94522a912a821b11e3c00d0480e06d407447c (patch) | |
tree | 811b78808f1823984b44dfabed2c60cec12b2d81 /src/transport/plugin_transport_tcp.c | |
parent | 5e900316b0b70bb65f573d0ad110f3d93551b11b (diff) | |
download | gnunet-c3d94522a912a821b11e3c00d0480e06d407447c.tar.gz gnunet-c3d94522a912a821b11e3c00d0480e06d407447c.zip |
use enum GNUNET_ATS_Network_Type instead of uint32_t where appropriate
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index ce918d191..9e78e47d9 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -330,7 +330,7 @@ struct Session | |||
330 | /** | 330 | /** |
331 | * ATS network type in NBO | 331 | * ATS network type in NBO |
332 | */ | 332 | */ |
333 | uint32_t ats_address_network_type; | 333 | enum GNUNET_ATS_Network_Type ats_address_network_type; |
334 | }; | 334 | }; |
335 | 335 | ||
336 | 336 | ||
@@ -806,7 +806,8 @@ lookup_session_by_client (struct Plugin *plugin, | |||
806 | * @return new session object | 806 | * @return new session object |
807 | */ | 807 | */ |
808 | static struct Session * | 808 | static struct Session * |
809 | create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | 809 | create_session (struct Plugin *plugin, |
810 | const struct GNUNET_PeerIdentity *target, | ||
810 | struct GNUNET_SERVER_Client *client, int is_nat) | 811 | struct GNUNET_SERVER_Client *client, int is_nat) |
811 | { | 812 | { |
812 | struct Session *session; | 813 | struct Session *session; |
@@ -821,14 +822,14 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | |||
821 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 822 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
822 | "Creating new session for peer `%4s'\n", | 823 | "Creating new session for peer `%4s'\n", |
823 | GNUNET_i2s (target)); | 824 | GNUNET_i2s (target)); |
824 | session = GNUNET_malloc (sizeof (struct Session)); | 825 | session = GNUNET_new (struct Session); |
825 | session->last_activity = GNUNET_TIME_absolute_get (); | 826 | session->last_activity = GNUNET_TIME_absolute_get (); |
826 | session->plugin = plugin; | 827 | session->plugin = plugin; |
827 | session->is_nat = is_nat; | 828 | session->is_nat = is_nat; |
828 | session->client = client; | 829 | session->client = client; |
829 | session->target = *target; | 830 | session->target = *target; |
830 | session->expecting_welcome = GNUNET_YES; | 831 | session->expecting_welcome = GNUNET_YES; |
831 | session->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED); | 832 | session->ats_address_network_type = GNUNET_ATS_NET_UNSPECIFIED; |
832 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + | 833 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + |
833 | sizeof (struct WelcomeMessage)); | 834 | sizeof (struct WelcomeMessage)); |
834 | pm->msg = (const char *) &pm[1]; | 835 | pm->msg = (const char *) &pm[1]; |
@@ -1443,7 +1444,7 @@ tcp_plugin_get_session (void *cls, | |||
1443 | return NULL; | 1444 | return NULL; |
1444 | } | 1445 | } |
1445 | 1446 | ||
1446 | ats = plugin->env->get_address_type (plugin->env->cls, sb ,sbs); | 1447 | ats = plugin->env->get_address_type (plugin->env->cls, sb, sbs); |
1447 | 1448 | ||
1448 | if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress))) | 1449 | if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress))) |
1449 | { | 1450 | { |
@@ -1473,10 +1474,15 @@ tcp_plugin_get_session (void *cls, | |||
1473 | { | 1474 | { |
1474 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1475 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1475 | "Found valid IPv4 NAT address (creating session)!\n") ; | 1476 | "Found valid IPv4 NAT address (creating session)!\n") ; |
1476 | session = create_session (plugin, &address->peer, NULL, GNUNET_YES); | 1477 | session = create_session (plugin, |
1478 | &address->peer, | ||
1479 | NULL, | ||
1480 | GNUNET_YES); | ||
1477 | session->addrlen = 0; | 1481 | session->addrlen = 0; |
1478 | session->addr = NULL; | 1482 | session->addr = NULL; |
1479 | session->ats_address_network_type = ats.value; | 1483 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value) |
1484 | ; | ||
1485 | GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); | ||
1480 | session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, | 1486 | session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, |
1481 | &nat_connect_timeout, | 1487 | &nat_connect_timeout, |
1482 | session); | 1488 | session); |
@@ -1528,8 +1534,8 @@ tcp_plugin_get_session (void *cls, | |||
1528 | session->addr = GNUNET_malloc (addrlen); | 1534 | session->addr = GNUNET_malloc (addrlen); |
1529 | memcpy (session->addr, address->address, addrlen); | 1535 | memcpy (session->addr, address->address, addrlen); |
1530 | session->addrlen = addrlen; | 1536 | session->addrlen = addrlen; |
1531 | session->ats_address_network_type = ats.value; | 1537 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value); |
1532 | 1538 | GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); | |
1533 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, | 1539 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, |
1534 | &session->target, | 1540 | &session->target, |
1535 | session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 1541 | session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
@@ -2118,7 +2124,7 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, | |||
2118 | if (alen == sizeof (struct sockaddr_in)) | 2124 | if (alen == sizeof (struct sockaddr_in)) |
2119 | { | 2125 | { |
2120 | s4 = vaddr; | 2126 | s4 = vaddr; |
2121 | t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress)); | 2127 | t4 = GNUNET_new (struct IPv4TcpAddress); |
2122 | t4->options = htonl (0); | 2128 | t4->options = htonl (0); |
2123 | t4->t4_port = s4->sin_port; | 2129 | t4->t4_port = s4->sin_port; |
2124 | t4->ipv4_addr = s4->sin_addr.s_addr; | 2130 | t4->ipv4_addr = s4->sin_addr.s_addr; |
@@ -2128,7 +2134,7 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, | |||
2128 | else if (alen == sizeof (struct sockaddr_in6)) | 2134 | else if (alen == sizeof (struct sockaddr_in6)) |
2129 | { | 2135 | { |
2130 | s6 = vaddr; | 2136 | s6 = vaddr; |
2131 | t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress)); | 2137 | t6 = GNUNET_new (struct IPv6TcpAddress); |
2132 | t6->options = htonl (0); | 2138 | t6->options = htonl (0); |
2133 | t6->t6_port = s6->sin6_port; | 2139 | t6->t6_port = s6->sin6_port; |
2134 | memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); | 2140 | memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); |
@@ -2137,11 +2143,11 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, | |||
2137 | } | 2143 | } |
2138 | 2144 | ||
2139 | ats = plugin->env->get_address_type (plugin->env->cls, vaddr ,alen); | 2145 | ats = plugin->env->get_address_type (plugin->env->cls, vaddr ,alen); |
2140 | session->ats_address_network_type = ats.value; | 2146 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value); |
2141 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2147 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2142 | "Creating new session %p for peer `%s'\n", | 2148 | "Creating new session %p for peer `%s'\n", |
2143 | session, | 2149 | session, |
2144 | GNUNET_a2s (vaddr, alen)); | 2150 | GNUNET_a2s (vaddr, alen)); |
2145 | GNUNET_free (vaddr); | 2151 | GNUNET_free (vaddr); |
2146 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, | 2152 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, |
2147 | &session->target, | 2153 | &session->target, |
@@ -2277,8 +2283,8 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
2277 | struct GNUNET_ATS_Information distance; | 2283 | struct GNUNET_ATS_Information distance; |
2278 | 2284 | ||
2279 | distance.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 2285 | distance.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
2280 | distance.value = session->ats_address_network_type; | 2286 | distance.value = htonl ((uint32_t) session->ats_address_network_type); |
2281 | GNUNET_break (ntohl(session->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); | 2287 | GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); |
2282 | 2288 | ||
2283 | GNUNET_assert (GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, | 2289 | GNUNET_assert (GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, |
2284 | &session->target, | 2290 | &session->target, |
@@ -2535,7 +2541,7 @@ tcp_get_network (void *cls, | |||
2535 | struct Session *session) | 2541 | struct Session *session) |
2536 | { | 2542 | { |
2537 | GNUNET_assert (NULL != session); | 2543 | GNUNET_assert (NULL != session); |
2538 | return ntohl (session->ats_address_network_type); | 2544 | return session->ats_address_network_type; |
2539 | } | 2545 | } |
2540 | 2546 | ||
2541 | 2547 | ||