diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-03 08:02:44 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-03 08:02:44 +0000 |
commit | c3ff8f261c25be9fc76ea40ab2f4e3b1313d3c08 (patch) | |
tree | 1ccf8dc7fad1c1c9a032c6097d3c95c3a56d3d90 /src/transport/plugin_transport_tcp.c | |
parent | fc0229e6dcdcb8e5f560051da73721609af64e2c (diff) | |
download | gnunet-c3ff8f261c25be9fc76ea40ab2f4e3b1313d3c08.tar.gz gnunet-c3ff8f261c25be9fc76ea40ab2f4e3b1313d3c08.zip |
-indentation and doxygen fixes
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 271 |
1 files changed, 169 insertions, 102 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index eda6bd23e..36da5027a 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -421,7 +421,10 @@ struct Plugin | |||
421 | * @return string representing the same address | 421 | * @return string representing the same address |
422 | */ | 422 | */ |
423 | static const char * | 423 | static const char * |
424 | tcp_address_to_string (void *cls, const void *addr, size_t addrlen); | 424 | tcp_address_to_string (void *cls, |
425 | const void *addr, | ||
426 | size_t addrlen); | ||
427 | |||
425 | 428 | ||
426 | /** | 429 | /** |
427 | * Function to check if an inbound connection is acceptable. | 430 | * Function to check if an inbound connection is acceptable. |
@@ -437,8 +440,9 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen); | |||
437 | */ | 440 | */ |
438 | static int | 441 | static int |
439 | plugin_tcp_access_check (void *cls, | 442 | plugin_tcp_access_check (void *cls, |
440 | const struct GNUNET_CONNECTION_Credentials *ucred, | 443 | const struct GNUNET_CONNECTION_Credentials *ucred, |
441 | const struct sockaddr *addr, socklen_t addrlen) | 444 | const struct sockaddr *addr, |
445 | socklen_t addrlen) | ||
442 | { | 446 | { |
443 | struct Plugin *plugin = cls; | 447 | struct Plugin *plugin = cls; |
444 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 448 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
@@ -450,18 +454,21 @@ plugin_tcp_access_check (void *cls, | |||
450 | return GNUNET_YES; | 454 | return GNUNET_YES; |
451 | } | 455 | } |
452 | 456 | ||
457 | |||
453 | /** | 458 | /** |
454 | * Our external IP address/port mapping has changed. | 459 | * Our external IP address/port mapping has changed. |
455 | * | 460 | * |
456 | * @param cls closure, the 'struct Plugin' | 461 | * @param cls closure, the `struct Plugin` |
457 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean | 462 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean |
458 | * the previous (now invalid) one | 463 | * the previous (now invalid) one |
459 | * @param addr either the previous or the new public IP address | 464 | * @param addr either the previous or the new public IP address |
460 | * @param addrlen actual lenght of the address | 465 | * @param addrlen actual length of @a addr |
461 | */ | 466 | */ |
462 | static void | 467 | static void |
463 | tcp_nat_port_map_callback (void *cls, int add_remove, | 468 | tcp_nat_port_map_callback (void *cls, |
464 | const struct sockaddr *addr, socklen_t addrlen) | 469 | int add_remove, |
470 | const struct sockaddr *addr, | ||
471 | socklen_t addrlen) | ||
465 | { | 472 | { |
466 | struct Plugin *plugin = cls; | 473 | struct Plugin *plugin = cls; |
467 | struct GNUNET_HELLO_Address *address; | 474 | struct GNUNET_HELLO_Address *address; |
@@ -508,6 +515,7 @@ tcp_nat_port_map_callback (void *cls, int add_remove, | |||
508 | GNUNET_HELLO_address_free(address); | 515 | GNUNET_HELLO_address_free(address); |
509 | } | 516 | } |
510 | 517 | ||
518 | |||
511 | /** | 519 | /** |
512 | * Function called for a quick conversion of the binary address to | 520 | * Function called for a quick conversion of the binary address to |
513 | * a numeric address. Note that the caller must not free the | 521 | * a numeric address. Note that the caller must not free the |
@@ -516,11 +524,13 @@ tcp_nat_port_map_callback (void *cls, int add_remove, | |||
516 | * | 524 | * |
517 | * @param cls closure (`struct Plugin*`) | 525 | * @param cls closure (`struct Plugin*`) |
518 | * @param addr binary address | 526 | * @param addr binary address |
519 | * @param addrlen length of the address | 527 | * @param addrlen length of @a addr |
520 | * @return string representing the same address | 528 | * @return string representing the same address |
521 | */ | 529 | */ |
522 | static const char * | 530 | static const char * |
523 | tcp_address_to_string (void *cls, const void *addr, size_t addrlen) | 531 | tcp_address_to_string (void *cls, |
532 | const void *addr, | ||
533 | size_t addrlen) | ||
524 | { | 534 | { |
525 | static char rbuf[INET6_ADDRSTRLEN + 12]; | 535 | static char rbuf[INET6_ADDRSTRLEN + 12]; |
526 | char buf[INET6_ADDRSTRLEN]; | 536 | char buf[INET6_ADDRSTRLEN]; |
@@ -562,11 +572,15 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
562 | return NULL ; | 572 | return NULL ; |
563 | } | 573 | } |
564 | GNUNET_snprintf (rbuf, sizeof(rbuf), | 574 | GNUNET_snprintf (rbuf, sizeof(rbuf), |
565 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", PLUGIN_NAME, options, | 575 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", |
566 | buf, port); | 576 | PLUGIN_NAME, |
577 | options, | ||
578 | buf, | ||
579 | port); | ||
567 | return rbuf; | 580 | return rbuf; |
568 | } | 581 | } |
569 | 582 | ||
583 | |||
570 | /** | 584 | /** |
571 | * Function called to convert a string address to | 585 | * Function called to convert a string address to |
572 | * a binary address. | 586 | * a binary address. |
@@ -580,8 +594,11 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
580 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 594 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
581 | */ | 595 | */ |
582 | static int | 596 | static int |
583 | tcp_string_to_address (void *cls, const char *addr, uint16_t addrlen, | 597 | tcp_string_to_address (void *cls, |
584 | void **buf, size_t *added) | 598 | const char *addr, |
599 | uint16_t addrlen, | ||
600 | void **buf, | ||
601 | size_t *added) | ||
585 | { | 602 | { |
586 | struct sockaddr_storage socket_address; | 603 | struct sockaddr_storage socket_address; |
587 | char *address; | 604 | char *address; |
@@ -670,6 +687,7 @@ tcp_string_to_address (void *cls, const char *addr, uint16_t addrlen, | |||
670 | } | 687 | } |
671 | } | 688 | } |
672 | 689 | ||
690 | |||
673 | /** | 691 | /** |
674 | * Closure for #session_lookup_by_client_it(). | 692 | * Closure for #session_lookup_by_client_it(). |
675 | */ | 693 | */ |
@@ -686,9 +704,11 @@ struct SessionClientCtx | |||
686 | struct Session *ret; | 704 | struct Session *ret; |
687 | }; | 705 | }; |
688 | 706 | ||
707 | |||
689 | static int | 708 | static int |
690 | session_lookup_by_client_it (void *cls, const struct GNUNET_PeerIdentity *key, | 709 | session_lookup_by_client_it (void *cls, |
691 | void *value) | 710 | const struct GNUNET_PeerIdentity *key, |
711 | void *value) | ||
692 | { | 712 | { |
693 | struct SessionClientCtx *sc_ctx = cls; | 713 | struct SessionClientCtx *sc_ctx = cls; |
694 | struct Session *s = value; | 714 | struct Session *s = value; |
@@ -701,6 +721,7 @@ session_lookup_by_client_it (void *cls, const struct GNUNET_PeerIdentity *key, | |||
701 | return GNUNET_YES; | 721 | return GNUNET_YES; |
702 | } | 722 | } |
703 | 723 | ||
724 | |||
704 | /** | 725 | /** |
705 | * Find the session handle for the given client. | 726 | * Find the session handle for the given client. |
706 | * Currently uses both the hashmap and the client | 727 | * Currently uses both the hashmap and the client |
@@ -713,7 +734,7 @@ session_lookup_by_client_it (void *cls, const struct GNUNET_PeerIdentity *key, | |||
713 | */ | 734 | */ |
714 | static struct Session * | 735 | static struct Session * |
715 | lookup_session_by_client (struct Plugin *plugin, | 736 | lookup_session_by_client (struct Plugin *plugin, |
716 | struct GNUNET_SERVER_Client *client) | 737 | struct GNUNET_SERVER_Client *client) |
717 | { | 738 | { |
718 | struct Session *ret; | 739 | struct Session *ret; |
719 | struct SessionClientCtx sc_ctx; | 740 | struct SessionClientCtx sc_ctx; |
@@ -728,6 +749,7 @@ lookup_session_by_client (struct Plugin *plugin, | |||
728 | return sc_ctx.ret; | 749 | return sc_ctx.ret; |
729 | } | 750 | } |
730 | 751 | ||
752 | |||
731 | /** | 753 | /** |
732 | * Functions with this signature are called whenever we need | 754 | * Functions with this signature are called whenever we need |
733 | * to close a session due to a disconnect or failure to | 755 | * to close a session due to a disconnect or failure to |
@@ -738,7 +760,8 @@ lookup_session_by_client (struct Plugin *plugin, | |||
738 | * @return #GNUNET_OK on success | 760 | * @return #GNUNET_OK on success |
739 | */ | 761 | */ |
740 | static int | 762 | static int |
741 | tcp_disconnect_session (void *cls, struct Session *session) | 763 | tcp_disconnect_session (void *cls, |
764 | struct Session *session) | ||
742 | { | 765 | { |
743 | struct Plugin *plugin = cls; | 766 | struct Plugin *plugin = cls; |
744 | struct PendingMessage *pm; | 767 | struct PendingMessage *pm; |
@@ -746,7 +769,9 @@ tcp_disconnect_session (void *cls, struct Session *session) | |||
746 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 769 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
747 | "Disconnecting session of peer `%s' address `%s'\n", | 770 | "Disconnecting session of peer `%s' address `%s'\n", |
748 | GNUNET_i2s (&session->target), | 771 | GNUNET_i2s (&session->target), |
749 | tcp_address_to_string (NULL, session->address->address, session->address->address_length)); | 772 | tcp_address_to_string (NULL, |
773 | session->address->address, | ||
774 | session->address->address_length)); | ||
750 | 775 | ||
751 | if (GNUNET_SCHEDULER_NO_TASK != session->timeout_task) | 776 | if (GNUNET_SCHEDULER_NO_TASK != session->timeout_task) |
752 | { | 777 | { |
@@ -763,11 +788,14 @@ tcp_disconnect_session (void *cls, struct Session *session) | |||
763 | } | 788 | } |
764 | else | 789 | else |
765 | { | 790 | { |
766 | GNUNET_assert( | 791 | GNUNET_assert(GNUNET_YES == |
767 | GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, &session->target, session)); | 792 | GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, |
793 | &session->target, | ||
794 | session)); | ||
768 | } | 795 | } |
769 | if (NULL != session->client) | 796 | if (NULL != session->client) |
770 | GNUNET_SERVER_client_set_user_context(session->client, (void *) NULL); | 797 | GNUNET_SERVER_client_set_user_context (session->client, |
798 | (void *) NULL); | ||
771 | 799 | ||
772 | /* clean up state */ | 800 | /* clean up state */ |
773 | if (NULL != session->transmit_handle) | 801 | if (NULL != session->transmit_handle) |
@@ -821,9 +849,10 @@ tcp_disconnect_session (void *cls, struct Session *session) | |||
821 | return GNUNET_OK; | 849 | return GNUNET_OK; |
822 | } | 850 | } |
823 | 851 | ||
852 | |||
824 | /** | 853 | /** |
825 | * Function that is called to get the keepalive factor. | 854 | * Function that is called to get the keepalive factor. |
826 | * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to | 855 | * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to |
827 | * calculate the interval between keepalive packets. | 856 | * calculate the interval between keepalive packets. |
828 | * | 857 | * |
829 | * @param cls closure with the `struct Plugin` | 858 | * @param cls closure with the `struct Plugin` |
@@ -835,6 +864,7 @@ tcp_query_keepalive_factor (void *cls) | |||
835 | return 3; | 864 | return 3; |
836 | } | 865 | } |
837 | 866 | ||
867 | |||
838 | /** | 868 | /** |
839 | * Session was idle, so disconnect it | 869 | * Session was idle, so disconnect it |
840 | * | 870 | * |
@@ -842,18 +872,21 @@ tcp_query_keepalive_factor (void *cls) | |||
842 | * @param tc scheduler context | 872 | * @param tc scheduler context |
843 | */ | 873 | */ |
844 | static void | 874 | static void |
845 | session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 875 | session_timeout (void *cls, |
876 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
846 | { | 877 | { |
847 | struct Session *s = cls; | 878 | struct Session *s = cls; |
848 | 879 | ||
849 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 880 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
850 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 881 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
851 | "Session %p was idle for %s, disconnecting\n", s, | 882 | "Session %p was idle for %s, disconnecting\n", s, |
852 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_YES)); | 883 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
884 | GNUNET_YES)); | ||
853 | /* call session destroy function */ | 885 | /* call session destroy function */ |
854 | tcp_disconnect_session (s->plugin, s); | 886 | tcp_disconnect_session (s->plugin, s); |
855 | } | 887 | } |
856 | 888 | ||
889 | |||
857 | /** | 890 | /** |
858 | * Increment session timeout due to activity | 891 | * Increment session timeout due to activity |
859 | * | 892 | * |
@@ -897,7 +930,8 @@ create_session (struct Plugin *plugin, | |||
897 | else | 930 | else |
898 | GNUNET_assert(NULL == client); | 931 | GNUNET_assert(NULL == client); |
899 | 932 | ||
900 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new session for peer `%4s'\n", | 933 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
934 | "Creating new session for peer `%4s'\n", | ||
901 | GNUNET_i2s (&address->peer)); | 935 | GNUNET_i2s (&address->peer)); |
902 | session = GNUNET_new (struct Session); | 936 | session = GNUNET_new (struct Session); |
903 | session->last_activity = GNUNET_TIME_absolute_get (); | 937 | session->last_activity = GNUNET_TIME_absolute_get (); |
@@ -934,6 +968,7 @@ create_session (struct Plugin *plugin, | |||
934 | return session; | 968 | return session; |
935 | } | 969 | } |
936 | 970 | ||
971 | |||
937 | /** | 972 | /** |
938 | * If we have pending messages, ask the server to | 973 | * If we have pending messages, ask the server to |
939 | * transmit them (schedule the respective tasks, etc.) | 974 | * transmit them (schedule the respective tasks, etc.) |
@@ -943,6 +978,7 @@ create_session (struct Plugin *plugin, | |||
943 | static void | 978 | static void |
944 | process_pending_messages (struct Session *session); | 979 | process_pending_messages (struct Session *session); |
945 | 980 | ||
981 | |||
946 | /** | 982 | /** |
947 | * Function called to notify a client about the socket | 983 | * Function called to notify a client about the socket |
948 | * being ready to queue more data. "buf" will be | 984 | * being ready to queue more data. "buf" will be |
@@ -950,9 +986,9 @@ process_pending_messages (struct Session *session); | |||
950 | * writing in the meantime. | 986 | * writing in the meantime. |
951 | * | 987 | * |
952 | * @param cls closure | 988 | * @param cls closure |
953 | * @param size number of bytes available in buf | 989 | * @param size number of bytes available in @a buf |
954 | * @param buf where the callee should write the message | 990 | * @param buf where the callee should write the message |
955 | * @return number of bytes written to buf | 991 | * @return number of bytes written to @a buf |
956 | */ | 992 | */ |
957 | static size_t | 993 | static size_t |
958 | do_transmit (void *cls, size_t size, void *buf) | 994 | do_transmit (void *cls, size_t size, void *buf) |
@@ -1061,6 +1097,7 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1061 | return ret; | 1097 | return ret; |
1062 | } | 1098 | } |
1063 | 1099 | ||
1100 | |||
1064 | /** | 1101 | /** |
1065 | * If we have pending messages, ask the server to | 1102 | * If we have pending messages, ask the server to |
1066 | * transmit them (schedule the respective tasks, etc.) | 1103 | * transmit them (schedule the respective tasks, etc.) |
@@ -1100,6 +1137,7 @@ struct FindSessionContext | |||
1100 | int res; | 1137 | int res; |
1101 | }; | 1138 | }; |
1102 | 1139 | ||
1140 | |||
1103 | /** | 1141 | /** |
1104 | * Function called to check if a session is in our maps. | 1142 | * Function called to check if a session is in our maps. |
1105 | * | 1143 | * |
@@ -1153,6 +1191,7 @@ find_session (struct Plugin *plugin, struct Session *session) | |||
1153 | } | 1191 | } |
1154 | #endif | 1192 | #endif |
1155 | 1193 | ||
1194 | |||
1156 | /** | 1195 | /** |
1157 | * Function that can be used by the transport service to transmit | 1196 | * Function that can be used by the transport service to transmit |
1158 | * a message using the plugin. Note that in the case of a | 1197 | * a message using the plugin. Note that in the case of a |
@@ -1271,6 +1310,7 @@ struct SessionItCtx | |||
1271 | 1310 | ||
1272 | }; | 1311 | }; |
1273 | 1312 | ||
1313 | |||
1274 | /** | 1314 | /** |
1275 | * Look for a session by address. | 1315 | * Look for a session by address. |
1276 | * | 1316 | * |
@@ -1280,8 +1320,9 @@ struct SessionItCtx | |||
1280 | * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session | 1320 | * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session |
1281 | */ | 1321 | */ |
1282 | static int | 1322 | static int |
1283 | session_lookup_it (void *cls, const struct GNUNET_PeerIdentity *key, | 1323 | session_lookup_it (void *cls, |
1284 | void *value) | 1324 | const struct GNUNET_PeerIdentity *key, |
1325 | void *value) | ||
1285 | { | 1326 | { |
1286 | struct SessionItCtx * si_ctx = cls; | 1327 | struct SessionItCtx * si_ctx = cls; |
1287 | struct Session * session = value; | 1328 | struct Session * session = value; |
@@ -2257,10 +2298,10 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) | |||
2257 | struct Plugin *plugin = cls; | 2298 | struct Plugin *plugin = cls; |
2258 | struct Session *session; | 2299 | struct Session *session; |
2259 | 2300 | ||
2260 | if (client == NULL ) | 2301 | if (NULL == client) |
2261 | return; | 2302 | return; |
2262 | session = lookup_session_by_client (plugin, client); | 2303 | session = lookup_session_by_client (plugin, client); |
2263 | if (session == NULL ) | 2304 | if (NULL == session) |
2264 | return; /* unknown, nothing to do */ | 2305 | return; /* unknown, nothing to do */ |
2265 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2306 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2266 | "Destroying session of `%4s' with %s due to network-level disconnect.\n", | 2307 | "Destroying session of `%4s' with %s due to network-level disconnect.\n", |
@@ -2287,10 +2328,12 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) | |||
2287 | * @param cls closure, a struct TCPProbeContext | 2328 | * @param cls closure, a struct TCPProbeContext |
2288 | * @param size max size to copy | 2329 | * @param size max size to copy |
2289 | * @param buf buffer to copy message to | 2330 | * @param buf buffer to copy message to |
2290 | * @return number of bytes copied into buf | 2331 | * @return number of bytes copied into @a buf |
2291 | */ | 2332 | */ |
2292 | static size_t | 2333 | static size_t |
2293 | notify_send_probe (void *cls, size_t size, void *buf) | 2334 | notify_send_probe (void *cls, |
2335 | size_t size, | ||
2336 | void *buf) | ||
2294 | { | 2337 | { |
2295 | struct TCPProbeContext *tcp_probe_ctx = cls; | 2338 | struct TCPProbeContext *tcp_probe_ctx = cls; |
2296 | struct Plugin *plugin = tcp_probe_ctx->plugin; | 2339 | struct Plugin *plugin = tcp_probe_ctx->plugin; |
@@ -2314,6 +2357,7 @@ notify_send_probe (void *cls, size_t size, void *buf) | |||
2314 | return ret; | 2357 | return ret; |
2315 | } | 2358 | } |
2316 | 2359 | ||
2360 | |||
2317 | /** | 2361 | /** |
2318 | * Function called by the NAT subsystem suggesting another peer wants | 2362 | * Function called by the NAT subsystem suggesting another peer wants |
2319 | * to connect to us via connection reversal. Try to connect back to the | 2363 | * to connect to us via connection reversal. Try to connect back to the |
@@ -2324,8 +2368,9 @@ notify_send_probe (void *cls, size_t size, void *buf) | |||
2324 | * @param addrlen number of bytes in @a addr | 2368 | * @param addrlen number of bytes in @a addr |
2325 | */ | 2369 | */ |
2326 | static void | 2370 | static void |
2327 | try_connection_reversal (void *cls, const struct sockaddr *addr, | 2371 | try_connection_reversal (void *cls, |
2328 | socklen_t addrlen) | 2372 | const struct sockaddr *addr, |
2373 | socklen_t addrlen) | ||
2329 | { | 2374 | { |
2330 | struct Plugin *plugin = cls; | 2375 | struct Plugin *plugin = cls; |
2331 | struct GNUNET_CONNECTION_Handle *sock; | 2376 | struct GNUNET_CONNECTION_Handle *sock; |
@@ -2359,6 +2404,7 @@ try_connection_reversal (void *cls, const struct sockaddr *addr, | |||
2359 | 2404 | ||
2360 | } | 2405 | } |
2361 | 2406 | ||
2407 | |||
2362 | /** | 2408 | /** |
2363 | * Function obtain the network type for a session | 2409 | * Function obtain the network type for a session |
2364 | * | 2410 | * |
@@ -2367,9 +2413,11 @@ try_connection_reversal (void *cls, const struct sockaddr *addr, | |||
2367 | * @return the network type in HBO or #GNUNET_SYSERR | 2413 | * @return the network type in HBO or #GNUNET_SYSERR |
2368 | */ | 2414 | */ |
2369 | static enum GNUNET_ATS_Network_Type | 2415 | static enum GNUNET_ATS_Network_Type |
2370 | tcp_get_network (void *cls, struct Session *session) | 2416 | tcp_get_network (void *cls, |
2417 | struct Session *session) | ||
2371 | { | 2418 | { |
2372 | struct Plugin * plugin = cls; | 2419 | struct Plugin * plugin = cls; |
2420 | |||
2373 | GNUNET_assert (NULL != plugin); | 2421 | GNUNET_assert (NULL != plugin); |
2374 | GNUNET_assert (NULL != session); | 2422 | GNUNET_assert (NULL != session); |
2375 | if (GNUNET_SYSERR == find_session (plugin,session)) | 2423 | if (GNUNET_SYSERR == find_session (plugin,session)) |
@@ -2377,6 +2425,7 @@ tcp_get_network (void *cls, struct Session *session) | |||
2377 | return session->ats_address_network_type; | 2425 | return session->ats_address_network_type; |
2378 | } | 2426 | } |
2379 | 2427 | ||
2428 | |||
2380 | /** | 2429 | /** |
2381 | * Entry point for the plugin. | 2430 | * Entry point for the plugin. |
2382 | * | 2431 | * |
@@ -2386,12 +2435,15 @@ tcp_get_network (void *cls, struct Session *session) | |||
2386 | void * | 2435 | void * |
2387 | libgnunet_plugin_transport_tcp_init (void *cls) | 2436 | libgnunet_plugin_transport_tcp_init (void *cls) |
2388 | { | 2437 | { |
2389 | static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { { | 2438 | static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { |
2390 | &handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, | 2439 | { &handle_tcp_welcome, NULL, |
2391 | sizeof(struct WelcomeMessage) }, { &handle_tcp_nat_probe, NULL, | 2440 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, sizeof(struct WelcomeMessage) }, |
2392 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, | 2441 | { &handle_tcp_nat_probe, NULL, |
2393 | sizeof(struct TCP_NAT_ProbeMessage) }, { &handle_tcp_data, NULL, | 2442 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, sizeof(struct TCP_NAT_ProbeMessage) }, |
2394 | GNUNET_MESSAGE_TYPE_ALL, 0 }, { NULL, NULL, 0, 0 } }; | 2443 | { &handle_tcp_data, NULL, |
2444 | GNUNET_MESSAGE_TYPE_ALL, 0 }, | ||
2445 | { NULL, NULL, 0, 0 } | ||
2446 | }; | ||
2395 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; | 2447 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; |
2396 | struct GNUNET_TRANSPORT_PluginFunctions *api; | 2448 | struct GNUNET_TRANSPORT_PluginFunctions *api; |
2397 | struct Plugin *plugin; | 2449 | struct Plugin *plugin; |
@@ -2418,10 +2470,12 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2418 | return api; | 2470 | return api; |
2419 | } | 2471 | } |
2420 | 2472 | ||
2421 | GNUNET_assert(NULL != env->cfg); | 2473 | GNUNET_assert (NULL != env->cfg); |
2422 | if (GNUNET_OK | 2474 | if (GNUNET_OK != |
2423 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", | 2475 | GNUNET_CONFIGURATION_get_value_number (env->cfg, |
2424 | "MAX_CONNECTIONS", &max_connections)) | 2476 | "transport-tcp", |
2477 | "MAX_CONNECTIONS", | ||
2478 | &max_connections)) | ||
2425 | max_connections = 128; | 2479 | max_connections = 128; |
2426 | 2480 | ||
2427 | aport = 0; | 2481 | aport = 0; |
@@ -2466,34 +2520,38 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2466 | plugin->adv_port = aport; | 2520 | plugin->adv_port = aport; |
2467 | plugin->env = env; | 2521 | plugin->env = env; |
2468 | plugin->lsock = NULL; | 2522 | plugin->lsock = NULL; |
2469 | if ((service != NULL )&& | 2523 | if ( (service != NULL) && |
2470 | (GNUNET_SYSERR != | 2524 | (GNUNET_SYSERR != |
2471 | (ret_s = | 2525 | (ret_s = |
2472 | GNUNET_SERVICE_get_server_addresses ("transport-tcp", env->cfg, &addrs, | 2526 | GNUNET_SERVICE_get_server_addresses ("transport-tcp", |
2473 | &addrlens)))){ | 2527 | env->cfg, |
2474 | for (ret = ret_s-1; ret >= 0; ret--) | 2528 | &addrs, |
2475 | LOG (GNUNET_ERROR_TYPE_INFO, | 2529 | &addrlens)))) |
2476 | "Binding to address `%s'\n", | 2530 | { |
2477 | GNUNET_a2s (addrs[ret], addrlens[ret])); | 2531 | for (ret = ret_s-1; ret >= 0; ret--) |
2478 | plugin->nat = | 2532 | LOG (GNUNET_ERROR_TYPE_INFO, |
2479 | GNUNET_NAT_register (env->cfg, GNUNET_YES, aport, (unsigned int) ret_s, | 2533 | "Binding to address `%s'\n", |
2480 | (const struct sockaddr **) addrs, addrlens, | 2534 | GNUNET_a2s (addrs[ret], addrlens[ret])); |
2481 | &tcp_nat_port_map_callback, | 2535 | plugin->nat |
2482 | &try_connection_reversal, plugin); | 2536 | = GNUNET_NAT_register (env->cfg, |
2483 | for (ret = ret_s -1; ret >= 0; ret--) | 2537 | GNUNET_YES, |
2484 | { | 2538 | aport, |
2485 | GNUNET_assert (addrs[ret] != NULL); | 2539 | (unsigned int) ret_s, |
2486 | GNUNET_free (addrs[ret]); | 2540 | (const struct sockaddr **) addrs, addrlens, |
2487 | } | 2541 | &tcp_nat_port_map_callback, |
2488 | GNUNET_free_non_null (addrs); | 2542 | &try_connection_reversal, |
2489 | GNUNET_free_non_null (addrlens); | 2543 | plugin); |
2490 | } | 2544 | for (ret = ret_s -1; ret >= 0; ret--) |
2491 | else | 2545 | GNUNET_free (addrs[ret]); |
2492 | { | 2546 | GNUNET_free_non_null (addrs); |
2493 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, | 2547 | GNUNET_free_non_null (addrlens); |
2494 | GNUNET_YES, 0, 0, NULL, NULL, NULL, | 2548 | } |
2495 | &try_connection_reversal, plugin); | 2549 | else |
2496 | } | 2550 | { |
2551 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, | ||
2552 | GNUNET_YES, 0, 0, NULL, NULL, NULL, | ||
2553 | &try_connection_reversal, plugin); | ||
2554 | } | ||
2497 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 2555 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
2498 | api->cls = plugin; | 2556 | api->cls = plugin; |
2499 | api->send = &tcp_plugin_send; | 2557 | api->send = &tcp_plugin_send; |
@@ -2516,41 +2574,46 @@ else | |||
2516 | } | 2574 | } |
2517 | else | 2575 | else |
2518 | { | 2576 | { |
2519 | if (GNUNET_OK | 2577 | if (GNUNET_OK != |
2520 | != GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp", | 2578 | GNUNET_CONFIGURATION_get_value_time (env->cfg, |
2521 | "TIMEOUT", &idle_timeout)) | 2579 | "transport-tcp", |
2580 | "TIMEOUT", | ||
2581 | &idle_timeout)) | ||
2522 | { | 2582 | { |
2523 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "transport-tcp", | 2583 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
2524 | "TIMEOUT"); | 2584 | "transport-tcp", |
2525 | if (plugin->nat != NULL ) | 2585 | "TIMEOUT"); |
2586 | if (NULL != plugin->nat) | ||
2526 | GNUNET_NAT_unregister (plugin->nat); | 2587 | GNUNET_NAT_unregister (plugin->nat); |
2527 | GNUNET_free(plugin); | 2588 | GNUNET_free(plugin); |
2528 | GNUNET_free(api); | 2589 | GNUNET_free(api); |
2529 | return NULL ; | 2590 | return NULL; |
2530 | } | 2591 | } |
2531 | plugin->server = GNUNET_SERVER_create_with_sockets ( | 2592 | plugin->server = GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, |
2532 | &plugin_tcp_access_check, plugin, NULL, idle_timeout, GNUNET_YES); | 2593 | plugin, NULL, |
2594 | idle_timeout, GNUNET_YES); | ||
2533 | } | 2595 | } |
2534 | plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); | 2596 | plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); |
2535 | memcpy (plugin->handlers, my_handlers, sizeof(my_handlers)); | 2597 | memcpy (plugin->handlers, my_handlers, sizeof(my_handlers)); |
2536 | for (i = 0; | 2598 | for (i = 0;i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);i++) |
2537 | i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler); | ||
2538 | i++) | ||
2539 | plugin->handlers[i].callback_cls = plugin; | 2599 | plugin->handlers[i].callback_cls = plugin; |
2540 | 2600 | ||
2541 | GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); | 2601 | GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); |
2542 | GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); | 2602 | GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); |
2543 | plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16, | 2603 | plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16, |
2544 | GNUNET_YES); | 2604 | GNUNET_YES); |
2545 | if (bport != 0) | 2605 | if (0 != bport) |
2546 | LOG(GNUNET_ERROR_TYPE_INFO, _("TCP transport listening on port %llu\n"), | 2606 | LOG (GNUNET_ERROR_TYPE_INFO, |
2547 | bport); | 2607 | _("TCP transport listening on port %llu\n"), |
2608 | bport); | ||
2548 | else | 2609 | else |
2549 | LOG(GNUNET_ERROR_TYPE_INFO, | 2610 | LOG (GNUNET_ERROR_TYPE_INFO, |
2550 | _("TCP transport not listening on any port (client only)\n")); | 2611 | _("TCP transport not listening on any port (client only)\n")); |
2551 | if (aport != bport) | 2612 | if ( (aport != bport) && |
2552 | LOG(GNUNET_ERROR_TYPE_INFO, | 2613 | (0 != bport) ) |
2553 | _("TCP transport advertises itself as being on port %llu\n"), aport); | 2614 | LOG (GNUNET_ERROR_TYPE_INFO, |
2615 | _("TCP transport advertises itself as being on port %llu\n"), | ||
2616 | aport); | ||
2554 | /* Initially set connections to 0 */ | 2617 | /* Initially set connections to 0 */ |
2555 | GNUNET_assert(NULL != plugin->env->stats); | 2618 | GNUNET_assert(NULL != plugin->env->stats); |
2556 | GNUNET_STATISTICS_set (plugin->env->stats, | 2619 | GNUNET_STATISTICS_set (plugin->env->stats, |
@@ -2558,6 +2621,7 @@ else | |||
2558 | return api; | 2621 | return api; |
2559 | } | 2622 | } |
2560 | 2623 | ||
2624 | |||
2561 | /** | 2625 | /** |
2562 | * Exit point from the plugin. | 2626 | * Exit point from the plugin. |
2563 | * | 2627 | * |
@@ -2578,14 +2642,17 @@ libgnunet_plugin_transport_tcp_done (void *cls) | |||
2578 | GNUNET_free(api); | 2642 | GNUNET_free(api); |
2579 | return NULL ; | 2643 | return NULL ; |
2580 | } | 2644 | } |
2581 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); | 2645 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2646 | "Shutting down TCP plugin\n"); | ||
2582 | 2647 | ||
2583 | /* Removing leftover sessions */ | 2648 | /* Removing leftover sessions */ |
2584 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, | 2649 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, |
2585 | &session_disconnect_it, plugin); | 2650 | &session_disconnect_it, |
2651 | plugin); | ||
2586 | /* Removing leftover NAT sessions */ | 2652 | /* Removing leftover NAT sessions */ |
2587 | GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, | 2653 | GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, |
2588 | &session_disconnect_it, plugin); | 2654 | &session_disconnect_it, |
2655 | plugin); | ||
2589 | 2656 | ||
2590 | next = ppc_dll_head; | 2657 | next = ppc_dll_head; |
2591 | for (cur = next; NULL != cur; cur = next) | 2658 | for (cur = next; NULL != cur; cur = next) |
@@ -2599,12 +2666,12 @@ libgnunet_plugin_transport_tcp_done (void *cls) | |||
2599 | GNUNET_break(0); | 2666 | GNUNET_break(0); |
2600 | } | 2667 | } |
2601 | 2668 | ||
2602 | if (plugin->service != NULL ) | 2669 | if (NULL != plugin->service) |
2603 | GNUNET_SERVICE_stop (plugin->service); | 2670 | GNUNET_SERVICE_stop (plugin->service); |
2604 | else | 2671 | else |
2605 | GNUNET_SERVER_destroy (plugin->server); | 2672 | GNUNET_SERVER_destroy (plugin->server); |
2606 | GNUNET_free(plugin->handlers); | 2673 | GNUNET_free(plugin->handlers); |
2607 | if (plugin->nat != NULL ) | 2674 | if (NULL != plugin->nat) |
2608 | GNUNET_NAT_unregister (plugin->nat); | 2675 | GNUNET_NAT_unregister (plugin->nat); |
2609 | while (NULL != (tcp_probe = plugin->probe_head)) | 2676 | while (NULL != (tcp_probe = plugin->probe_head)) |
2610 | { | 2677 | { |
@@ -2617,7 +2684,7 @@ libgnunet_plugin_transport_tcp_done (void *cls) | |||
2617 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); | 2684 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); |
2618 | GNUNET_free(plugin); | 2685 | GNUNET_free(plugin); |
2619 | GNUNET_free(api); | 2686 | GNUNET_free(api); |
2620 | return NULL ; | 2687 | return NULL; |
2621 | } | 2688 | } |
2622 | 2689 | ||
2623 | /* end of plugin_transport_tcp.c */ | 2690 | /* end of plugin_transport_tcp.c */ |