diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-07-01 13:32:21 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-07-01 13:32:21 +0000 |
commit | fa85c492f751f5136a50d5ee4a24eb997f4eee70 (patch) | |
tree | b2f9fe6242333e40cffdb1edf356308f0092af3f /src/transport/plugin_transport_http.c | |
parent | 34679adf5a4d083ddd39da805e7509429fed7f45 (diff) | |
download | gnunet-fa85c492f751f5136a50d5ee4a24eb997f4eee70.tar.gz gnunet-fa85c492f751f5136a50d5ee4a24eb997f4eee70.zip |
changes to address mgmt
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r-- | src/transport/plugin_transport_http.c | 154 |
1 files changed, 88 insertions, 66 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 8d9aa3646..52865addc 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -90,23 +90,12 @@ | |||
90 | */ | 90 | */ |
91 | #define HTTP_CONNECT_TIMEOUT 30 | 91 | #define HTTP_CONNECT_TIMEOUT 30 |
92 | 92 | ||
93 | |||
94 | /** | 93 | /** |
95 | * Network format for IPv4 addresses. | 94 | * Network format for IPv4 addresses. |
96 | */ | 95 | */ |
97 | struct IPv4HttpAddress | 96 | struct IPv4HttpAddress |
98 | { | 97 | { |
99 | /** | 98 | /** |
100 | * Linked list next | ||
101 | */ | ||
102 | struct IPv4HttpAddress * next; | ||
103 | |||
104 | /** | ||
105 | * Linked list previous | ||
106 | */ | ||
107 | struct IPv4HttpAddress * prev; | ||
108 | |||
109 | /** | ||
110 | * IPv4 address, in network byte order. | 99 | * IPv4 address, in network byte order. |
111 | */ | 100 | */ |
112 | uint32_t ipv4_addr GNUNET_PACKED; | 101 | uint32_t ipv4_addr GNUNET_PACKED; |
@@ -115,25 +104,31 @@ struct IPv4HttpAddress | |||
115 | * Port number, in network byte order. | 104 | * Port number, in network byte order. |
116 | */ | 105 | */ |
117 | uint16_t u_port GNUNET_PACKED; | 106 | uint16_t u_port GNUNET_PACKED; |
118 | |||
119 | }; | 107 | }; |
120 | 108 | ||
121 | |||
122 | /** | 109 | /** |
123 | * Network format for IPv6 addresses. | 110 | * Wrapper for IPv4 addresses. |
124 | */ | 111 | */ |
125 | struct IPv6HttpAddress | 112 | struct IPv4HttpAddressWrapper |
126 | { | 113 | { |
127 | /** | 114 | /** |
128 | * Linked list next | 115 | * Linked list next |
129 | */ | 116 | */ |
130 | struct IPv6HttpAddress * next; | 117 | struct IPv4HttpAddressWrapper * next; |
131 | 118 | ||
132 | /** | 119 | /** |
133 | * Linked list previous | 120 | * Linked list previous |
134 | */ | 121 | */ |
135 | struct IPv6HttpAddress * prev; | 122 | struct IPv4HttpAddressWrapper * prev; |
123 | |||
124 | struct IPv4HttpAddress * addr; | ||
125 | }; | ||
136 | 126 | ||
127 | /** | ||
128 | * Network format for IPv6 addresses. | ||
129 | */ | ||
130 | struct IPv6HttpAddress | ||
131 | { | ||
137 | /** | 132 | /** |
138 | * IPv6 address. | 133 | * IPv6 address. |
139 | */ | 134 | */ |
@@ -146,6 +141,23 @@ struct IPv6HttpAddress | |||
146 | 141 | ||
147 | }; | 142 | }; |
148 | 143 | ||
144 | /** | ||
145 | * Wrapper for IPv4 addresses. | ||
146 | */ | ||
147 | struct IPv6HttpAddressWrapper | ||
148 | { | ||
149 | /** | ||
150 | * Linked list next | ||
151 | */ | ||
152 | struct IPv6HttpAddressWrapper * next; | ||
153 | |||
154 | /** | ||
155 | * Linked list previous | ||
156 | */ | ||
157 | struct IPv6HttpAddressWrapper * prev; | ||
158 | |||
159 | struct IPv6HttpAddress * addr; | ||
160 | }; | ||
149 | 161 | ||
150 | /** | 162 | /** |
151 | * Message to send using http | 163 | * Message to send using http |
@@ -421,22 +433,22 @@ struct Plugin | |||
421 | /** | 433 | /** |
422 | * ipv4 DLL head | 434 | * ipv4 DLL head |
423 | */ | 435 | */ |
424 | struct IPv4HttpAddress * ipv4_addr_head; | 436 | struct IPv4HttpAddressWrapper * ipv4_addr_head; |
425 | 437 | ||
426 | /** | 438 | /** |
427 | * ipv4 DLL tail | 439 | * ipv4 DLL tail |
428 | */ | 440 | */ |
429 | struct IPv4HttpAddress * ipv4_addr_tail; | 441 | struct IPv4HttpAddressWrapper * ipv4_addr_tail; |
430 | 442 | ||
431 | /** | 443 | /** |
432 | * ipv6 DLL head | 444 | * ipv6 DLL head |
433 | */ | 445 | */ |
434 | struct IPv6HttpAddress * ipv6_addr_head; | 446 | struct IPv6HttpAddressWrapper * ipv6_addr_head; |
435 | 447 | ||
436 | /** | 448 | /** |
437 | * ipv6 DLL tail | 449 | * ipv6 DLL tail |
438 | */ | 450 | */ |
439 | struct IPv6HttpAddress * ipv6_addr_tail; | 451 | struct IPv6HttpAddressWrapper * ipv6_addr_tail; |
440 | 452 | ||
441 | /** | 453 | /** |
442 | * Our ASCII encoded, hashed peer identity | 454 | * Our ASCII encoded, hashed peer identity |
@@ -2774,8 +2786,8 @@ http_plugin_address_suggested (void *cls, | |||
2774 | struct Plugin *plugin = cls; | 2786 | struct Plugin *plugin = cls; |
2775 | struct IPv4HttpAddress *v4; | 2787 | struct IPv4HttpAddress *v4; |
2776 | struct IPv6HttpAddress *v6; | 2788 | struct IPv6HttpAddress *v6; |
2777 | struct IPv4HttpAddress *tv4 = plugin->ipv4_addr_head; | 2789 | struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head; |
2778 | struct IPv6HttpAddress *tv6 = plugin->ipv6_addr_head; | 2790 | struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head; |
2779 | 2791 | ||
2780 | GNUNET_assert(cls !=NULL); | 2792 | GNUNET_assert(cls !=NULL); |
2781 | if ((addrlen != sizeof (struct IPv4HttpAddress)) && | 2793 | if ((addrlen != sizeof (struct IPv4HttpAddress)) && |
@@ -2791,13 +2803,13 @@ http_plugin_address_suggested (void *cls, | |||
2791 | else | 2803 | else |
2792 | return GNUNET_SYSERR; | 2804 | return GNUNET_SYSERR; |
2793 | } | 2805 | } |
2794 | while (tv4!=NULL) | 2806 | while (w_tv4!=NULL) |
2795 | { | 2807 | { |
2796 | if (0==memcmp (&tv4->ipv4_addr, &v4->ipv4_addr, sizeof(uint32_t))) | 2808 | if (0==memcmp (&w_tv4->addr->ipv4_addr, &v4->ipv4_addr, sizeof(uint32_t))) |
2797 | break; | 2809 | break; |
2798 | tv4 = tv4->next; | 2810 | w_tv4 = w_tv4->next; |
2799 | } | 2811 | } |
2800 | if (tv4 != NULL) | 2812 | if (w_tv4 != NULL) |
2801 | return GNUNET_OK; | 2813 | return GNUNET_OK; |
2802 | else | 2814 | else |
2803 | return GNUNET_SYSERR; | 2815 | return GNUNET_SYSERR; |
@@ -2812,13 +2824,13 @@ http_plugin_address_suggested (void *cls, | |||
2812 | else | 2824 | else |
2813 | return GNUNET_SYSERR; | 2825 | return GNUNET_SYSERR; |
2814 | } | 2826 | } |
2815 | while (tv6!=NULL) | 2827 | while (w_tv6!=NULL) |
2816 | { | 2828 | { |
2817 | if (0 == memcmp (&tv6->ipv6_addr, &v6->ipv6_addr, sizeof(struct in6_addr))) | 2829 | if (0 == memcmp (&w_tv6->addr->ipv6_addr, &v6->ipv6_addr, sizeof(struct in6_addr))) |
2818 | break; | 2830 | break; |
2819 | tv6 = tv6->next; | 2831 | w_tv6 = w_tv6->next; |
2820 | } | 2832 | } |
2821 | if (tv6 !=NULL) | 2833 | if (w_tv6 !=NULL) |
2822 | return GNUNET_OK; | 2834 | return GNUNET_OK; |
2823 | else | 2835 | else |
2824 | return GNUNET_SYSERR; | 2836 | return GNUNET_SYSERR; |
@@ -2910,64 +2922,73 @@ tcp_nat_cb_add_addr (void *cls, | |||
2910 | { | 2922 | { |
2911 | struct Plugin *plugin = cls; | 2923 | struct Plugin *plugin = cls; |
2912 | struct IPv4HttpAddress * t4 = NULL; | 2924 | struct IPv4HttpAddress * t4 = NULL; |
2925 | struct IPv4HttpAddressWrapper * w_t4 = NULL; | ||
2913 | struct IPv6HttpAddress * t6 = NULL; | 2926 | struct IPv6HttpAddress * t6 = NULL; |
2927 | struct IPv6HttpAddressWrapper * w_t6 = NULL; | ||
2914 | int af; | 2928 | int af; |
2915 | 2929 | ||
2916 | af = addr->sa_family; | 2930 | af = addr->sa_family; |
2917 | switch (af) | 2931 | switch (af) |
2918 | { | 2932 | { |
2919 | case AF_INET: | 2933 | case AF_INET: |
2920 | t4 = plugin->ipv4_addr_head; | 2934 | w_t4 = plugin->ipv4_addr_head; |
2921 | while (t4 != NULL) | 2935 | while (w_t4 != NULL) |
2922 | { | 2936 | { |
2923 | int res = memcmp(&t4->ipv4_addr, | 2937 | int res = memcmp(&w_t4->addr->ipv4_addr, |
2924 | &((struct sockaddr_in *) addr)->sin_addr, | 2938 | &((struct sockaddr_in *) addr)->sin_addr, |
2925 | sizeof (struct in_addr)); | 2939 | sizeof (struct in_addr)); |
2926 | if (0 == res) | 2940 | if (0 == res) |
2927 | break; | 2941 | break; |
2928 | t4 = t4->next; | 2942 | w_t4 = w_t4->next; |
2929 | } | 2943 | } |
2930 | if (t4 == NULL) | 2944 | if (w_t4 == NULL) |
2931 | { | 2945 | { |
2946 | w_t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddressWrapper)); | ||
2932 | t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress)); | 2947 | t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress)); |
2933 | memcpy (&t4->ipv4_addr, | 2948 | memcpy (&t4->ipv4_addr, |
2934 | &((struct sockaddr_in *) addr)->sin_addr, | 2949 | &((struct sockaddr_in *) addr)->sin_addr, |
2935 | sizeof (struct in_addr)); | 2950 | sizeof (struct in_addr)); |
2936 | t4->u_port = htons (plugin->port_inbound); | 2951 | t4->u_port = htons (plugin->port_inbound); |
2937 | 2952 | ||
2953 | w_t4->addr = t4; | ||
2954 | |||
2938 | GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head, | 2955 | GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head, |
2939 | plugin->ipv4_addr_tail,t4); | 2956 | plugin->ipv4_addr_tail,w_t4); |
2940 | } | 2957 | } |
2941 | plugin->env->notify_address(plugin->env->cls, | 2958 | plugin->env->notify_address(plugin->env->cls, |
2942 | add_remove, | 2959 | add_remove, |
2943 | t4, sizeof (struct IPv4HttpAddress)); | 2960 | w_t4->addr, sizeof (struct IPv4HttpAddress)); |
2944 | 2961 | ||
2945 | break; | 2962 | break; |
2946 | case AF_INET6: | 2963 | case AF_INET6: |
2947 | t6 = plugin->ipv6_addr_head; | 2964 | w_t6 = plugin->ipv6_addr_head; |
2948 | while (t6 != NULL) | 2965 | while (w_t6) |
2949 | { | 2966 | { |
2950 | int res = memcmp(&t6->ipv6_addr, | 2967 | int res = memcmp(&w_t6->addr->ipv6_addr, |
2951 | &((struct sockaddr_in6 *) addr)->sin6_addr, | 2968 | &((struct sockaddr_in6 *) addr)->sin6_addr, |
2952 | sizeof (struct in6_addr)); | 2969 | sizeof (struct in6_addr)); |
2953 | if (0 == res) | 2970 | if (0 == res) |
2954 | break; | 2971 | break; |
2955 | t6 = t6->next; | 2972 | w_t6 = w_t6->next; |
2956 | } | 2973 | } |
2957 | if (t6 == NULL) | 2974 | if (w_t6 == NULL) |
2958 | { | 2975 | { |
2976 | w_t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddressWrapper)); | ||
2959 | t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress)); | 2977 | t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress)); |
2960 | 2978 | ||
2961 | memcpy (&t6->ipv6_addr, | 2979 | memcpy (&t6->ipv6_addr, |
2962 | &((struct sockaddr_in6 *) addr)->sin6_addr, | 2980 | &((struct sockaddr_in6 *) addr)->sin6_addr, |
2963 | sizeof (struct in6_addr)); | 2981 | sizeof (struct in6_addr)); |
2964 | t6->u6_port = htons (plugin->port_inbound); | 2982 | t6->u6_port = htons (plugin->port_inbound); |
2983 | |||
2984 | w_t6->addr = t6; | ||
2985 | |||
2965 | GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head, | 2986 | GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head, |
2966 | plugin->ipv6_addr_tail,t6); | 2987 | plugin->ipv6_addr_tail,w_t6); |
2967 | } | 2988 | } |
2968 | plugin->env->notify_address(plugin->env->cls, | 2989 | plugin->env->notify_address(plugin->env->cls, |
2969 | add_remove, | 2990 | add_remove, |
2970 | t6, sizeof (struct IPv6HttpAddress)); | 2991 | w_t6->addr, sizeof (struct IPv6HttpAddress)); |
2971 | break; | 2992 | break; |
2972 | default: | 2993 | default: |
2973 | return; | 2994 | return; |
@@ -2982,54 +3003,54 @@ tcp_nat_cb_remove_addr (void *cls, | |||
2982 | socklen_t addrlen) | 3003 | socklen_t addrlen) |
2983 | { | 3004 | { |
2984 | struct Plugin *plugin = cls; | 3005 | struct Plugin *plugin = cls; |
2985 | struct IPv4HttpAddress * t4; | 3006 | struct IPv4HttpAddressWrapper * w_t4 = NULL; |
2986 | struct IPv6HttpAddress * t6; | 3007 | struct IPv6HttpAddressWrapper * w_t6 = NULL; |
2987 | int af; | 3008 | int af; |
2988 | 3009 | ||
2989 | af = addr->sa_family; | 3010 | af = addr->sa_family; |
2990 | switch (af) | 3011 | switch (af) |
2991 | { | 3012 | { |
2992 | case AF_INET: | 3013 | case AF_INET: |
2993 | t4 = plugin->ipv4_addr_head; | 3014 | w_t4 = plugin->ipv4_addr_head; |
2994 | while (t4 != NULL) | 3015 | while (w_t4 != NULL) |
2995 | { | 3016 | { |
2996 | int res = memcmp(&t4->ipv4_addr, | 3017 | int res = memcmp(&w_t4->addr->ipv4_addr, |
2997 | &((struct sockaddr_in *) addr)->sin_addr, | 3018 | &((struct sockaddr_in *) addr)->sin_addr, |
2998 | sizeof (struct in_addr)); | 3019 | sizeof (struct in_addr)); |
2999 | if (0 == res) | 3020 | if (0 == res) |
3000 | break; | 3021 | break; |
3001 | t4 = t4->next; | 3022 | w_t4 = w_t4->next; |
3002 | } | 3023 | } |
3003 | if (t4 == NULL) | 3024 | if (w_t4 == NULL) |
3004 | return; | 3025 | return; |
3005 | plugin->env->notify_address(plugin->env->cls, | 3026 | plugin->env->notify_address(plugin->env->cls, |
3006 | add_remove, | 3027 | add_remove, |
3007 | t4, sizeof (struct IPv4HttpAddress)); | 3028 | w_t4->addr, sizeof (struct IPv4HttpAddress)); |
3008 | 3029 | ||
3009 | GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head, | 3030 | /* GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head, |
3010 | plugin->ipv4_addr_tail,t4); | 3031 | plugin->ipv4_addr_tail,t4); |
3011 | GNUNET_free (t4); | 3032 | GNUNET_free (t4);*/ |
3012 | break; | 3033 | break; |
3013 | case AF_INET6: | 3034 | case AF_INET6: |
3014 | t6 = plugin->ipv6_addr_head; | 3035 | w_t6 = plugin->ipv6_addr_head; |
3015 | while (t6 != NULL) | 3036 | while (w_t6 != NULL) |
3016 | { | 3037 | { |
3017 | int res = memcmp(&t6->ipv6_addr, | 3038 | int res = memcmp(&w_t6->addr->ipv6_addr, |
3018 | &((struct sockaddr_in6 *) addr)->sin6_addr, | 3039 | &((struct sockaddr_in6 *) addr)->sin6_addr, |
3019 | sizeof (struct in6_addr)); | 3040 | sizeof (struct in6_addr)); |
3020 | if (0 == res) | 3041 | if (0 == res) |
3021 | break; | 3042 | break; |
3022 | t6 = t6->next; | 3043 | w_t6 = w_t6->next; |
3023 | } | 3044 | } |
3024 | if (t6 == NULL) | 3045 | if (w_t6 == NULL) |
3025 | return; | 3046 | return; |
3026 | plugin->env->notify_address(plugin->env->cls, | 3047 | plugin->env->notify_address(plugin->env->cls, |
3027 | add_remove, | 3048 | add_remove, |
3028 | t6, sizeof (struct IPv6HttpAddress)); | 3049 | w_t6->addr, sizeof (struct IPv6HttpAddress)); |
3029 | 3050 | ||
3030 | GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head, | 3051 | /* GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head, |
3031 | plugin->ipv6_addr_tail,t6); | 3052 | plugin->ipv6_addr_tail,t6); |
3032 | GNUNET_free (t6); | 3053 | GNUNET_free (t6);*/ |
3033 | break; | 3054 | break; |
3034 | default: | 3055 | default: |
3035 | return; | 3056 | return; |
@@ -3097,14 +3118,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
3097 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 3118 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
3098 | struct Plugin *plugin = api->cls; | 3119 | struct Plugin *plugin = api->cls; |
3099 | CURLMcode mret; | 3120 | CURLMcode mret; |
3100 | struct IPv4HttpAddress * ipv4addr; | 3121 | struct IPv4HttpAddressWrapper * ipv4addr; |
3101 | struct IPv6HttpAddress * ipv6addr; | 3122 | struct IPv6HttpAddressWrapper * ipv6addr; |
3102 | GNUNET_assert(cls !=NULL); | 3123 | GNUNET_assert(cls !=NULL); |
3103 | 3124 | ||
3104 | if (plugin->nat != NULL) | 3125 | if (plugin->nat != NULL) |
3105 | GNUNET_NAT_unregister (plugin->nat); | 3126 | GNUNET_NAT_unregister (plugin->nat); |
3106 | 3127 | ||
3107 | |||
3108 | if (plugin->http_server_daemon_v4 != NULL) | 3128 | if (plugin->http_server_daemon_v4 != NULL) |
3109 | { | 3129 | { |
3110 | MHD_stop_daemon (plugin->http_server_daemon_v4); | 3130 | MHD_stop_daemon (plugin->http_server_daemon_v4); |
@@ -3130,6 +3150,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
3130 | { | 3150 | { |
3131 | ipv4addr = plugin->ipv4_addr_head; | 3151 | ipv4addr = plugin->ipv4_addr_head; |
3132 | GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head,plugin->ipv4_addr_tail,ipv4addr); | 3152 | GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head,plugin->ipv4_addr_tail,ipv4addr); |
3153 | GNUNET_free(ipv4addr->addr); | ||
3133 | GNUNET_free(ipv4addr); | 3154 | GNUNET_free(ipv4addr); |
3134 | } | 3155 | } |
3135 | 3156 | ||
@@ -3137,6 +3158,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
3137 | { | 3158 | { |
3138 | ipv6addr = plugin->ipv6_addr_head; | 3159 | ipv6addr = plugin->ipv6_addr_head; |
3139 | GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,ipv6addr); | 3160 | GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,ipv6addr); |
3161 | GNUNET_free(ipv4addr->addr); | ||
3140 | GNUNET_free(ipv6addr); | 3162 | GNUNET_free(ipv6addr); |
3141 | } | 3163 | } |
3142 | 3164 | ||