diff options
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r-- | src/transport/plugin_transport_http.c | 105 |
1 files changed, 102 insertions, 3 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 726a9dbe2..5e439e75e 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "gnunet_transport_service.h" | 34 | #include "gnunet_transport_service.h" |
35 | #include "gnunet_resolver_service.h" | 35 | #include "gnunet_resolver_service.h" |
36 | #include "plugin_transport.h" | 36 | #include "plugin_transport.h" |
37 | #include "gnunet_os_lib.h" | ||
37 | #include "microhttpd.h" | 38 | #include "microhttpd.h" |
38 | #include <curl/curl.h> | 39 | #include <curl/curl.h> |
39 | 40 | ||
@@ -70,6 +71,43 @@ | |||
70 | struct Plugin; | 71 | struct Plugin; |
71 | 72 | ||
72 | /** | 73 | /** |
74 | * Network format for IPv4 addresses. | ||
75 | */ | ||
76 | struct IPv4HttpAddress | ||
77 | { | ||
78 | /** | ||
79 | * IPv4 address, in network byte order. | ||
80 | */ | ||
81 | uint32_t ipv4_addr; | ||
82 | |||
83 | /** | ||
84 | * Port number, in network byte order. | ||
85 | */ | ||
86 | uint16_t u_port; | ||
87 | |||
88 | }; | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Network format for IPv6 addresses. | ||
93 | */ | ||
94 | struct IPv6HttpAddress | ||
95 | { | ||
96 | /** | ||
97 | * IPv6 address. | ||
98 | */ | ||
99 | struct in6_addr ipv6_addr; | ||
100 | |||
101 | /** | ||
102 | * Port number, in network byte order. | ||
103 | */ | ||
104 | uint16_t u6_port; | ||
105 | |||
106 | }; | ||
107 | |||
108 | |||
109 | |||
110 | /** | ||
73 | * Message to send using http | 111 | * Message to send using http |
74 | */ | 112 | */ |
75 | struct HTTP_Message | 113 | struct HTTP_Message |
@@ -92,8 +130,6 @@ struct HTTP_Message | |||
92 | /** | 130 | /** |
93 | * amount of data to sent | 131 | * amount of data to sent |
94 | */ | 132 | */ |
95 | size_t size; | ||
96 | |||
97 | size_t len; | 133 | size_t len; |
98 | }; | 134 | }; |
99 | 135 | ||
@@ -204,6 +240,8 @@ struct Plugin | |||
204 | */ | 240 | */ |
205 | struct GNUNET_SERVICE_Context *service; | 241 | struct GNUNET_SERVICE_Context *service; |
206 | 242 | ||
243 | unsigned int port_inbound; | ||
244 | |||
207 | /** | 245 | /** |
208 | * List of open sessions. | 246 | * List of open sessions. |
209 | */ | 247 | */ |
@@ -1106,6 +1144,8 @@ http_plugin_address_pretty_printer (void *cls, | |||
1106 | asc, void *asc_cls) | 1144 | asc, void *asc_cls) |
1107 | { | 1145 | { |
1108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: http_plugin_address_pretty_printer\n"); | 1146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: http_plugin_address_pretty_printer\n"); |
1147 | |||
1148 | |||
1109 | asc (asc_cls, NULL); | 1149 | asc (asc_cls, NULL); |
1110 | } | 1150 | } |
1111 | 1151 | ||
@@ -1158,6 +1198,61 @@ http_plugin_address_to_string (void *cls, | |||
1158 | } | 1198 | } |
1159 | 1199 | ||
1160 | /** | 1200 | /** |
1201 | * Add the IP of our network interface to the list of | ||
1202 | * our external IP addresses. | ||
1203 | * | ||
1204 | * @param cls the 'struct Plugin*' | ||
1205 | * @param name name of the interface | ||
1206 | * @param isDefault do we think this may be our default interface | ||
1207 | * @param addr address of the interface | ||
1208 | * @param addrlen number of bytes in addr | ||
1209 | * @return GNUNET_OK to continue iterating | ||
1210 | */ | ||
1211 | static int | ||
1212 | process_interfaces (void *cls, | ||
1213 | const char *name, | ||
1214 | int isDefault, | ||
1215 | const struct sockaddr *addr, socklen_t addrlen) | ||
1216 | { | ||
1217 | struct IPv4HttpAddress t4; | ||
1218 | struct IPv6HttpAddress t6; | ||
1219 | int af; | ||
1220 | void *arg; | ||
1221 | uint16_t args; | ||
1222 | |||
1223 | af = addr->sa_family; | ||
1224 | if (af == AF_INET) | ||
1225 | { | ||
1226 | t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; | ||
1227 | t4.u_port = htons (plugin->port_inbound); | ||
1228 | arg = &t4; | ||
1229 | args = sizeof (t4); | ||
1230 | } | ||
1231 | else if (af == AF_INET6) | ||
1232 | { | ||
1233 | if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) | ||
1234 | { | ||
1235 | /* skip link local addresses */ | ||
1236 | return GNUNET_OK; | ||
1237 | } | ||
1238 | memcpy (&t6.ipv6_addr, | ||
1239 | &((struct sockaddr_in6 *) addr)->sin6_addr, | ||
1240 | sizeof (struct in6_addr)); | ||
1241 | t6.u6_port = htons (plugin->port_inbound); | ||
1242 | arg = &t6; | ||
1243 | args = sizeof (t6); | ||
1244 | } | ||
1245 | else | ||
1246 | { | ||
1247 | GNUNET_break (0); | ||
1248 | return GNUNET_OK; | ||
1249 | } | ||
1250 | plugin->env->notify_address(plugin->env->cls,"http",arg, args, GNUNET_TIME_UNIT_FOREVER_REL); | ||
1251 | |||
1252 | return GNUNET_OK; | ||
1253 | } | ||
1254 | |||
1255 | /** | ||
1161 | * Exit point from the plugin. | 1256 | * Exit point from the plugin. |
1162 | */ | 1257 | */ |
1163 | void * | 1258 | void * |
@@ -1302,7 +1397,7 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1302 | libgnunet_plugin_transport_http_done (api); | 1397 | libgnunet_plugin_transport_http_done (api); |
1303 | return NULL; | 1398 | return NULL; |
1304 | } | 1399 | } |
1305 | 1400 | plugin->port_inbound = port; | |
1306 | gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; | 1401 | gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; |
1307 | timeout = ( gn_timeout.value / 1000); | 1402 | timeout = ( gn_timeout.value / 1000); |
1308 | if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0)) | 1403 | if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0)) |
@@ -1340,6 +1435,7 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1340 | if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK) | 1435 | if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK) |
1341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port); | 1436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port); |
1342 | 1437 | ||
1438 | |||
1343 | /* Initializing cURL */ | 1439 | /* Initializing cURL */ |
1344 | multi_handle = curl_multi_init(); | 1440 | multi_handle = curl_multi_init(); |
1345 | if ( NULL == multi_handle ) | 1441 | if ( NULL == multi_handle ) |
@@ -1351,6 +1447,9 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1351 | libgnunet_plugin_transport_http_done (api); | 1447 | libgnunet_plugin_transport_http_done (api); |
1352 | return NULL; | 1448 | return NULL; |
1353 | } | 1449 | } |
1450 | |||
1451 | GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); | ||
1452 | |||
1354 | return api; | 1453 | return api; |
1355 | } | 1454 | } |
1356 | 1455 | ||