diff options
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 273d39873..bd624c1d5 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -298,12 +298,11 @@ struct Session | |||
298 | * call or on our 'accept' call). | 298 | * call or on our 'accept' call). |
299 | * | 299 | * |
300 | * struct IPv4TcpAddress or struct IPv6TcpAddress | 300 | * struct IPv4TcpAddress or struct IPv6TcpAddress |
301 | * | ||
302 | */ | 301 | */ |
303 | void *addr; | 302 | void *addr; |
304 | 303 | ||
305 | /** | 304 | /** |
306 | * Length of connect_addr. | 305 | * Length of @e addr. |
307 | */ | 306 | */ |
308 | size_t addrlen; | 307 | size_t addrlen; |
309 | 308 | ||
@@ -1019,12 +1018,14 @@ process_pending_messages (struct Session *session) | |||
1019 | * establish a connection. | 1018 | * establish a connection. |
1020 | * | 1019 | * |
1021 | * @param session session to close down | 1020 | * @param session session to close down |
1021 | * @return #GNUNET_OK on success | ||
1022 | */ | 1022 | */ |
1023 | static void | 1023 | static int |
1024 | disconnect_session (struct Session *session) | 1024 | tcp_disconnect_session (void *cls, |
1025 | struct Session *session) | ||
1025 | { | 1026 | { |
1027 | struct Plugin *plugin = cls; | ||
1026 | struct PendingMessage *pm; | 1028 | struct PendingMessage *pm; |
1027 | struct Plugin * plugin = session->plugin; | ||
1028 | 1029 | ||
1029 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1030 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1030 | "Disconnecting session of peer `%s' address `%s'\n", | 1031 | "Disconnecting session of peer `%s' address `%s'\n", |
@@ -1101,6 +1102,7 @@ disconnect_session (struct Session *session) | |||
1101 | GNUNET_free_non_null (session->addr); | 1102 | GNUNET_free_non_null (session->addr); |
1102 | GNUNET_assert (NULL == session->transmit_handle); | 1103 | GNUNET_assert (NULL == session->transmit_handle); |
1103 | GNUNET_free (session); | 1104 | GNUNET_free (session); |
1105 | return GNUNET_OK; | ||
1104 | } | 1106 | } |
1105 | 1107 | ||
1106 | 1108 | ||
@@ -1172,7 +1174,7 @@ find_session (struct Plugin *plugin, struct Session *session) | |||
1172 | * been transmitted (or if the transport is ready | 1174 | * been transmitted (or if the transport is ready |
1173 | * for the next transmission call; or if the | 1175 | * for the next transmission call; or if the |
1174 | * peer disconnected...); can be NULL | 1176 | * peer disconnected...); can be NULL |
1175 | * @param cont_cls closure for cont | 1177 | * @param cont_cls closure for @a cont |
1176 | * @return number of bytes used (on the physical network, with overheads); | 1178 | * @return number of bytes used (on the physical network, with overheads); |
1177 | * -1 on hard errors (i.e. address invalid); 0 is a legal value | 1179 | * -1 on hard errors (i.e. address invalid); 0 is a legal value |
1178 | * and does NOT mean that the message was not transmitted (DV) | 1180 | * and does NOT mean that the message was not transmitted (DV) |
@@ -1315,15 +1317,19 @@ session_lookup_it (void *cls, | |||
1315 | * Task cleaning up a NAT connection attempt after timeout | 1317 | * Task cleaning up a NAT connection attempt after timeout |
1316 | */ | 1318 | */ |
1317 | static void | 1319 | static void |
1318 | nat_connect_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1320 | nat_connect_timeout (void *cls, |
1321 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1319 | { | 1322 | { |
1320 | struct Session *session = cls; | 1323 | struct Session *session = cls; |
1321 | 1324 | ||
1322 | session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; | 1325 | session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; |
1323 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1326 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1324 | "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", | 1327 | "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", |
1325 | GNUNET_i2s (&session->target), tcp_address_to_string(NULL, session->addr, session->addrlen)); | 1328 | GNUNET_i2s (&session->target), |
1326 | disconnect_session (session); | 1329 | tcp_address_to_string (NULL, |
1330 | session->addr, session->addrlen)); | ||
1331 | tcp_disconnect_session (session->plugin, | ||
1332 | session); | ||
1327 | } | 1333 | } |
1328 | 1334 | ||
1329 | 1335 | ||
@@ -1491,7 +1497,7 @@ tcp_plugin_get_session (void *cls, | |||
1491 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1497 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1492 | "Running NAT client for `%4s' at `%s' failed\n", | 1498 | "Running NAT client for `%4s' at `%s' failed\n", |
1493 | GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); | 1499 | GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); |
1494 | disconnect_session (session); | 1500 | tcp_disconnect_session (plugin, session); |
1495 | return NULL; | 1501 | return NULL; |
1496 | } | 1502 | } |
1497 | } | 1503 | } |
@@ -1544,13 +1550,15 @@ session_disconnect_it (void *cls, | |||
1544 | const struct GNUNET_PeerIdentity *key, | 1550 | const struct GNUNET_PeerIdentity *key, |
1545 | void *value) | 1551 | void *value) |
1546 | { | 1552 | { |
1553 | struct Plugin *plugin = cls; | ||
1547 | struct Session *session = value; | 1554 | struct Session *session = value; |
1548 | 1555 | ||
1549 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 1556 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
1550 | gettext_noop | 1557 | gettext_noop |
1551 | ("# transport-service disconnect requests for TCP"), | 1558 | ("# transport-service disconnect requests for TCP"), |
1552 | 1, GNUNET_NO); | 1559 | 1, GNUNET_NO); |
1553 | disconnect_session (session); | 1560 | tcp_disconnect_session (plugin, |
1561 | session); | ||
1554 | return GNUNET_YES; | 1562 | return GNUNET_YES; |
1555 | } | 1563 | } |
1556 | 1564 | ||
@@ -1980,7 +1988,7 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, | |||
1980 | { | 1988 | { |
1981 | GNUNET_break (0); | 1989 | GNUNET_break (0); |
1982 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1990 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1983 | disconnect_session (session); | 1991 | tcp_disconnect_session (plugin, session); |
1984 | return; | 1992 | return; |
1985 | } | 1993 | } |
1986 | GNUNET_assert (GNUNET_CONTAINER_multipeermap_remove | 1994 | GNUNET_assert (GNUNET_CONTAINER_multipeermap_remove |
@@ -2021,7 +2029,7 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, | |||
2021 | "Bad address for incoming connection!\n"); | 2029 | "Bad address for incoming connection!\n"); |
2022 | GNUNET_free (vaddr); | 2030 | GNUNET_free (vaddr); |
2023 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2031 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2024 | disconnect_session (session); | 2032 | tcp_disconnect_session (plugin, session); |
2025 | return; | 2033 | return; |
2026 | } | 2034 | } |
2027 | GNUNET_free (vaddr); | 2035 | GNUNET_free (vaddr); |
@@ -2334,18 +2342,18 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) | |||
2334 | "*"); | 2342 | "*"); |
2335 | 2343 | ||
2336 | if (plugin->cur_connections == plugin->max_connections) | 2344 | if (plugin->cur_connections == plugin->max_connections) |
2337 | GNUNET_SERVER_resume (plugin->server); /* Resume server */ | 2345 | GNUNET_SERVER_resume (plugin->server); /* Resume server */ |
2338 | 2346 | ||
2339 | if (plugin->cur_connections < 1) | 2347 | if (plugin->cur_connections < 1) |
2340 | GNUNET_break (0); | 2348 | GNUNET_break (0); |
2341 | else | 2349 | else |
2342 | plugin->cur_connections--; | 2350 | plugin->cur_connections--; |
2343 | 2351 | ||
2344 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 2352 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
2345 | gettext_noop | 2353 | gettext_noop |
2346 | ("# network-level TCP disconnect events"), 1, | 2354 | ("# network-level TCP disconnect events"), 1, |
2347 | GNUNET_NO); | 2355 | GNUNET_NO); |
2348 | disconnect_session (session); | 2356 | tcp_disconnect_session (plugin, session); |
2349 | } | 2357 | } |
2350 | 2358 | ||
2351 | 2359 | ||
@@ -2451,7 +2459,7 @@ session_timeout (void *cls, | |||
2451 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 2459 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
2452 | GNUNET_YES)); | 2460 | GNUNET_YES)); |
2453 | /* call session destroy function */ | 2461 | /* call session destroy function */ |
2454 | disconnect_session (s); | 2462 | tcp_disconnect_session(s->plugin, s); |
2455 | } | 2463 | } |
2456 | 2464 | ||
2457 | 2465 | ||
@@ -2461,11 +2469,10 @@ session_timeout (void *cls, | |||
2461 | static void | 2469 | static void |
2462 | start_session_timeout (struct Session *s) | 2470 | start_session_timeout (struct Session *s) |
2463 | { | 2471 | { |
2464 | GNUNET_assert (NULL != s); | ||
2465 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); | 2472 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); |
2466 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 2473 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
2467 | &session_timeout, | 2474 | &session_timeout, |
2468 | s); | 2475 | s); |
2469 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2470 | "Timeout for session %p set to %s\n", | 2477 | "Timeout for session %p set to %s\n", |
2471 | s, | 2478 | s, |
@@ -2567,7 +2574,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2567 | { | 2574 | { |
2568 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 2575 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
2569 | initialze the plugin or the API */ | 2576 | initialze the plugin or the API */ |
2570 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 2577 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
2571 | api->cls = NULL; | 2578 | api->cls = NULL; |
2572 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; | 2579 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; |
2573 | api->address_to_string = &tcp_address_to_string; | 2580 | api->address_to_string = &tcp_address_to_string; |
@@ -2592,8 +2599,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2592 | (aport > 65535))) | 2599 | (aport > 65535))) |
2593 | { | 2600 | { |
2594 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2601 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2595 | _ | 2602 | _("Require valid port number for service `%s' in configuration!\n"), |
2596 | ("Require valid port number for service `%s' in configuration!\n"), | ||
2597 | "transport-tcp"); | 2603 | "transport-tcp"); |
2598 | return NULL; | 2604 | return NULL; |
2599 | } | 2605 | } |
@@ -2617,7 +2623,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2617 | /* Initialize my flags */ | 2623 | /* Initialize my flags */ |
2618 | myoptions = 0; | 2624 | myoptions = 0; |
2619 | 2625 | ||
2620 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | 2626 | plugin = GNUNET_new (struct Plugin); |
2621 | plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); | 2627 | plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); |
2622 | plugin->max_connections = max_connections; | 2628 | plugin->max_connections = max_connections; |
2623 | plugin->cur_connections = 0; | 2629 | plugin->cur_connections = 0; |
@@ -2659,14 +2665,15 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2659 | api->send = &tcp_plugin_send; | 2665 | api->send = &tcp_plugin_send; |
2660 | api->get_session = &tcp_plugin_get_session; | 2666 | api->get_session = &tcp_plugin_get_session; |
2661 | 2667 | ||
2662 | api->disconnect = &tcp_plugin_disconnect; | 2668 | api->disconnect_session = &tcp_disconnect_session; |
2669 | api->disconnect_peer = &tcp_plugin_disconnect; | ||
2663 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; | 2670 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; |
2664 | api->check_address = &tcp_plugin_check_address; | 2671 | api->check_address = &tcp_plugin_check_address; |
2665 | api->address_to_string = &tcp_address_to_string; | 2672 | api->address_to_string = &tcp_address_to_string; |
2666 | api->string_to_address = &tcp_string_to_address; | 2673 | api->string_to_address = &tcp_string_to_address; |
2667 | api->get_network = &tcp_get_network; | 2674 | api->get_network = &tcp_get_network; |
2668 | plugin->service = service; | 2675 | plugin->service = service; |
2669 | if (service != NULL) | 2676 | if (NULL != service) |
2670 | { | 2677 | { |
2671 | plugin->server = GNUNET_SERVICE_get_server (service); | 2678 | plugin->server = GNUNET_SERVICE_get_server (service); |
2672 | } | 2679 | } |
@@ -2703,13 +2710,11 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2703 | _("TCP transport listening on port %llu\n"), bport); | 2710 | _("TCP transport listening on port %llu\n"), bport); |
2704 | else | 2711 | else |
2705 | LOG (GNUNET_ERROR_TYPE_INFO, | 2712 | LOG (GNUNET_ERROR_TYPE_INFO, |
2706 | _ | 2713 | _("TCP transport not listening on any port (client only)\n")); |
2707 | ("TCP transport not listening on any port (client only)\n")); | ||
2708 | if (aport != bport) | 2714 | if (aport != bport) |
2709 | LOG (GNUNET_ERROR_TYPE_INFO, | 2715 | LOG (GNUNET_ERROR_TYPE_INFO, |
2710 | _ | 2716 | _("TCP transport advertises itself as being on port %llu\n"), |
2711 | ("TCP transport advertises itself as being on port %llu\n"), | 2717 | aport); |
2712 | aport); | ||
2713 | /* Initially set connections to 0 */ | 2718 | /* Initially set connections to 0 */ |
2714 | GNUNET_assert (NULL != plugin->env->stats); | 2719 | GNUNET_assert (NULL != plugin->env->stats); |
2715 | GNUNET_STATISTICS_set (plugin->env->stats, | 2720 | GNUNET_STATISTICS_set (plugin->env->stats, |