diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-06-30 15:21:18 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-06-30 15:21:18 +0000 |
commit | 5c5b1bd3586da2f5b076b6371e2c906e7f689c80 (patch) | |
tree | de5491fff341351674e08ff11aa44f9ff86c5444 /src/transport/plugin_transport_http.c | |
parent | 9b0efad5a1cd2ff9886a460866b715a3216fea1c (diff) | |
download | gnunet-5c5b1bd3586da2f5b076b6371e2c906e7f689c80.tar.gz gnunet-5c5b1bd3586da2f5b076b6371e2c906e7f689c80.zip |
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r-- | src/transport/plugin_transport_http.c | 205 |
1 files changed, 170 insertions, 35 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 07c4bd5e8..de91935e8 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -746,6 +746,8 @@ remove_session (struct HTTP_PeerContext * pc, | |||
746 | return GNUNET_OK; | 746 | return GNUNET_OK; |
747 | } | 747 | } |
748 | 748 | ||
749 | |||
750 | #if 0 | ||
749 | static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen) | 751 | static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen) |
750 | { | 752 | { |
751 | uint32_t res = 0; | 753 | uint32_t res = 0; |
@@ -785,6 +787,7 @@ static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen) | |||
785 | return local; | 787 | return local; |
786 | } | 788 | } |
787 | 789 | ||
790 | |||
788 | /** | 791 | /** |
789 | * Add the IP of our network interface to the list of | 792 | * Add the IP of our network interface to the list of |
790 | * our external IP addresses. | 793 | * our external IP addresses. |
@@ -899,7 +902,7 @@ process_interfaces (void *cls, | |||
899 | } | 902 | } |
900 | return GNUNET_OK; | 903 | return GNUNET_OK; |
901 | } | 904 | } |
902 | 905 | #endif | |
903 | 906 | ||
904 | /** | 907 | /** |
905 | * External logging function for MHD | 908 | * External logging function for MHD |
@@ -2899,6 +2902,159 @@ try_connection_reversal (void *cls, | |||
2899 | 2902 | ||
2900 | } | 2903 | } |
2901 | 2904 | ||
2905 | static void | ||
2906 | tcp_nat_cb_add_addr (void *cls, | ||
2907 | int add_remove, | ||
2908 | const struct sockaddr *addr, | ||
2909 | socklen_t addrlen) | ||
2910 | { | ||
2911 | struct Plugin *plugin = cls; | ||
2912 | struct IPv4HttpAddress * t4 = NULL; | ||
2913 | struct IPv6HttpAddress * t6 = NULL; | ||
2914 | int af; | ||
2915 | |||
2916 | af = addr->sa_family; | ||
2917 | switch (af) | ||
2918 | { | ||
2919 | case AF_INET: | ||
2920 | return; | ||
2921 | t4 = plugin->ipv4_addr_head; | ||
2922 | while (t4 != NULL) | ||
2923 | { | ||
2924 | int res = memcmp(&t4->ipv4_addr, | ||
2925 | &((struct sockaddr_in *) addr)->sin_addr, | ||
2926 | sizeof (struct in_addr)); | ||
2927 | if (0 == res) | ||
2928 | break; | ||
2929 | t4 = t4->next; | ||
2930 | } | ||
2931 | if (t4 == NULL) | ||
2932 | { | ||
2933 | t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress)); | ||
2934 | memcpy (&t4->ipv4_addr, | ||
2935 | &((struct sockaddr_in *) addr)->sin_addr, | ||
2936 | sizeof (struct in_addr)); | ||
2937 | t4->u_port = htons (plugin->port_inbound); | ||
2938 | |||
2939 | GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head, | ||
2940 | plugin->ipv4_addr_tail,t4); | ||
2941 | } | ||
2942 | plugin->env->notify_address(plugin->env->cls, | ||
2943 | add_remove, | ||
2944 | t4, sizeof (struct IPv4HttpAddress)); | ||
2945 | |||
2946 | break; | ||
2947 | case AF_INET6: | ||
2948 | t6 = plugin->ipv6_addr_head; | ||
2949 | while (t6 != NULL) | ||
2950 | { | ||
2951 | int res = memcmp(&t6->ipv6_addr, | ||
2952 | &((struct sockaddr_in6 *) addr)->sin6_addr, | ||
2953 | sizeof (struct in6_addr)); | ||
2954 | if (0 == res) | ||
2955 | { | ||
2956 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
2957 | "tcp", | ||
2958 | "FOUND\n"); | ||
2959 | break; | ||
2960 | } | ||
2961 | t6 = t6->next; | ||
2962 | } | ||
2963 | if (t6 == NULL) | ||
2964 | { | ||
2965 | t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress)); | ||
2966 | |||
2967 | memcpy (&t6->ipv6_addr, | ||
2968 | &((struct sockaddr_in6 *) addr)->sin6_addr, | ||
2969 | sizeof (struct in6_addr)); | ||
2970 | t6->u6_port = htons (plugin->port_inbound); | ||
2971 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
2972 | "tcp", | ||
2973 | "Added `%s' to our address set\n", http_plugin_address_to_string(NULL, t6, sizeof (struct IPv6HttpAddress))); | ||
2974 | GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head, | ||
2975 | plugin->ipv6_addr_tail,t6); | ||
2976 | } | ||
2977 | plugin->env->notify_address(plugin->env->cls, | ||
2978 | add_remove, | ||
2979 | t6, sizeof (struct IPv6HttpAddress)); | ||
2980 | break; | ||
2981 | default: | ||
2982 | return; | ||
2983 | } | ||
2984 | |||
2985 | } | ||
2986 | |||
2987 | static void | ||
2988 | tcp_nat_cb_remove_addr (void *cls, | ||
2989 | int add_remove, | ||
2990 | const struct sockaddr *addr, | ||
2991 | socklen_t addrlen) | ||
2992 | { | ||
2993 | struct Plugin *plugin = cls; | ||
2994 | struct IPv4HttpAddress * t4; | ||
2995 | struct IPv6HttpAddress * t6; | ||
2996 | int af; | ||
2997 | |||
2998 | af = addr->sa_family; | ||
2999 | switch (af) | ||
3000 | { | ||
3001 | case AF_INET: | ||
3002 | return; | ||
3003 | t4 = plugin->ipv4_addr_head; | ||
3004 | while (t4 != NULL) | ||
3005 | { | ||
3006 | int res = memcmp(&t4->ipv4_addr, | ||
3007 | &((struct sockaddr_in *) addr)->sin_addr, | ||
3008 | sizeof (struct in_addr)); | ||
3009 | if (0 == res) | ||
3010 | break; | ||
3011 | t4 = t4->next; | ||
3012 | } | ||
3013 | if (t4 == NULL) | ||
3014 | return; | ||
3015 | plugin->env->notify_address(plugin->env->cls, | ||
3016 | add_remove, | ||
3017 | t4, sizeof (struct IPv4HttpAddress)); | ||
3018 | |||
3019 | GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head, | ||
3020 | plugin->ipv4_addr_tail,t4); | ||
3021 | GNUNET_free (t4); | ||
3022 | break; | ||
3023 | case AF_INET6: | ||
3024 | t6 = plugin->ipv6_addr_head; | ||
3025 | while (t6 != NULL) | ||
3026 | { | ||
3027 | int res = memcmp(&t6->ipv6_addr, | ||
3028 | &((struct sockaddr_in6 *) addr)->sin6_addr, | ||
3029 | sizeof (struct in6_addr)); | ||
3030 | if (0 == res) | ||
3031 | { | ||
3032 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
3033 | "tcp", | ||
3034 | "FOUND\n"); | ||
3035 | break; | ||
3036 | } | ||
3037 | t6 = t6->next; | ||
3038 | } | ||
3039 | if (t6 == NULL) | ||
3040 | return; | ||
3041 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
3042 | "tcp", | ||
3043 | "Removing `%s' from our address set\n", http_plugin_address_to_string(NULL, t6, sizeof (struct IPv6HttpAddress))); | ||
3044 | plugin->env->notify_address(plugin->env->cls, | ||
3045 | add_remove, | ||
3046 | t6, sizeof (struct IPv6HttpAddress)); | ||
3047 | |||
3048 | GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head, | ||
3049 | plugin->ipv6_addr_tail,t6); | ||
3050 | GNUNET_free (t6); | ||
3051 | break; | ||
3052 | default: | ||
3053 | return; | ||
3054 | } | ||
3055 | |||
3056 | } | ||
3057 | |||
2902 | /** | 3058 | /** |
2903 | * Our external IP address/port mapping has changed. | 3059 | * Our external IP address/port mapping has changed. |
2904 | * | 3060 | * |
@@ -2914,14 +3070,6 @@ tcp_nat_port_map_callback (void *cls, | |||
2914 | const struct sockaddr *addr, | 3070 | const struct sockaddr *addr, |
2915 | socklen_t addrlen) | 3071 | socklen_t addrlen) |
2916 | { | 3072 | { |
2917 | |||
2918 | struct Plugin *plugin = cls; | ||
2919 | struct IPv4HttpAddress t4; | ||
2920 | struct IPv6HttpAddress t6; | ||
2921 | void *arg; | ||
2922 | size_t args; | ||
2923 | int af; | ||
2924 | |||
2925 | GNUNET_assert(cls !=NULL ); | 3073 | GNUNET_assert(cls !=NULL ); |
2926 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 3074 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
2927 | "tcp", | 3075 | "tcp", |
@@ -2930,35 +3078,18 @@ tcp_nat_port_map_callback (void *cls, | |||
2930 | GNUNET_a2s (addr, addrlen)); | 3078 | GNUNET_a2s (addr, addrlen)); |
2931 | 3079 | ||
2932 | /* convert 'addr' to our internal format */ | 3080 | /* convert 'addr' to our internal format */ |
2933 | return; | 3081 | switch (add_remove) |
2934 | |||
2935 | af = addr->sa_family; | ||
2936 | switch (af) | ||
2937 | { | 3082 | { |
2938 | case AF_INET: | 3083 | case GNUNET_YES: |
2939 | t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; | 3084 | tcp_nat_cb_add_addr (cls, add_remove, addr, addrlen); |
2940 | memcpy (&t4.ipv4_addr, | ||
2941 | &((struct sockaddr_in *) addr)->sin_addr.s_addr, | ||
2942 | sizeof (struct in_addr)); | ||
2943 | t4.u_port = htons (plugin->port_inbound); | ||
2944 | plugin->env->notify_address(plugin->env->cls, | ||
2945 | add_remove, | ||
2946 | &t4, sizeof (struct IPv6HttpAddress)); | ||
2947 | break; | 3085 | break; |
2948 | case AF_INET6: | 3086 | case GNUNET_NO: |
2949 | memcpy (&t6.ipv6_addr, | 3087 | tcp_nat_cb_remove_addr (cls, add_remove, addr, addrlen); |
2950 | &((struct sockaddr_in6 *) addr)->sin6_addr, | ||
2951 | sizeof (struct in6_addr)); | ||
2952 | t6.u6_port = htons (plugin->port_inbound); | ||
2953 | plugin->env->notify_address(plugin->env->cls, | ||
2954 | add_remove, | ||
2955 | &t6, sizeof (struct IPv6HttpAddress)); | ||
2956 | break; | 3088 | break; |
2957 | default: | ||
2958 | return; | ||
2959 | } | 3089 | } |
2960 | } | 3090 | } |
2961 | 3091 | ||
3092 | #if 0 | ||
2962 | /** | 3093 | /** |
2963 | * Notify transport service about address | 3094 | * Notify transport service about address |
2964 | * | 3095 | * |
@@ -2973,6 +3104,7 @@ address_notification (void *cls, | |||
2973 | 3104 | ||
2974 | GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); | 3105 | GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); |
2975 | } | 3106 | } |
3107 | #endif | ||
2976 | 3108 | ||
2977 | /** | 3109 | /** |
2978 | * Exit point from the plugin. | 3110 | * Exit point from the plugin. |
@@ -2987,6 +3119,10 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
2987 | struct IPv6HttpAddress * ipv6addr; | 3119 | struct IPv6HttpAddress * ipv6addr; |
2988 | GNUNET_assert(cls !=NULL); | 3120 | GNUNET_assert(cls !=NULL); |
2989 | 3121 | ||
3122 | if (plugin->nat != NULL) | ||
3123 | GNUNET_NAT_unregister (plugin->nat); | ||
3124 | |||
3125 | |||
2990 | if (plugin->http_server_daemon_v4 != NULL) | 3126 | if (plugin->http_server_daemon_v4 != NULL) |
2991 | { | 3127 | { |
2992 | MHD_stop_daemon (plugin->http_server_daemon_v4); | 3128 | MHD_stop_daemon (plugin->http_server_daemon_v4); |
@@ -3046,8 +3182,6 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
3046 | plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; | 3182 | plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; |
3047 | } | 3183 | } |
3048 | 3184 | ||
3049 | if (plugin->nat != NULL) | ||
3050 | GNUNET_NAT_unregister (plugin->nat); | ||
3051 | 3185 | ||
3052 | GNUNET_free_non_null (plugin->bind4_address); | 3186 | GNUNET_free_non_null (plugin->bind4_address); |
3053 | GNUNET_free_non_null (plugin->bind6_address); | 3187 | GNUNET_free_non_null (plugin->bind6_address); |
@@ -3408,6 +3542,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
3408 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) plugin->max_connect_per_transport, | 3542 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) plugin->max_connect_per_transport, |
3409 | #if BUILD_HTTPS | 3543 | #if BUILD_HTTPS |
3410 | MHD_OPTION_HTTPS_PRIORITIES, plugin->crypto_init, | 3544 | MHD_OPTION_HTTPS_PRIORITIES, plugin->crypto_init, |
3545 | |||
3411 | MHD_OPTION_HTTPS_MEM_KEY, plugin->key, | 3546 | MHD_OPTION_HTTPS_MEM_KEY, plugin->key, |
3412 | MHD_OPTION_HTTPS_MEM_CERT, plugin->cert, | 3547 | MHD_OPTION_HTTPS_MEM_CERT, plugin->cert, |
3413 | #endif | 3548 | #endif |
@@ -3547,7 +3682,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
3547 | plugin->peers = GNUNET_CONTAINER_multihashmap_create (10); | 3682 | plugin->peers = GNUNET_CONTAINER_multihashmap_create (10); |
3548 | 3683 | ||
3549 | GNUNET_free(component_name); | 3684 | GNUNET_free(component_name); |
3550 | GNUNET_SCHEDULER_add_now(address_notification, plugin); | 3685 | //GNUNET_SCHEDULER_add_now(address_notification, plugin); |
3551 | return api; | 3686 | return api; |
3552 | } | 3687 | } |
3553 | 3688 | ||