diff options
-rw-r--r-- | src/transport/plugin_transport_http_common.c | 70 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_common.h | 54 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_server.c | 112 | ||||
-rw-r--r-- | src/transport/test_transport_api_http_reverse_proxy.conf | 2 |
4 files changed, 170 insertions, 68 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index b1bf7b0de..a7a39baec 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c | |||
@@ -50,8 +50,11 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
50 | GNUNET_TRANSPORT_AddressStringCallback | 50 | GNUNET_TRANSPORT_AddressStringCallback |
51 | asc, void *asc_cls) | 51 | asc, void *asc_cls) |
52 | { | 52 | { |
53 | GNUNET_break (0); | 53 | const char *saddr = (const char *) addr; |
54 | asc (asc_cls, NULL); | 54 | GNUNET_assert (NULL != saddr); |
55 | GNUNET_assert (0 < addrlen); | ||
56 | GNUNET_assert (saddr[addrlen-1] == '\0'); | ||
57 | asc (asc_cls, saddr); | ||
55 | } | 58 | } |
56 | 59 | ||
57 | 60 | ||
@@ -69,8 +72,11 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
69 | const char * | 72 | const char * |
70 | http_common_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | 73 | http_common_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) |
71 | { | 74 | { |
72 | GNUNET_break (0); | 75 | const char *saddr = (const char *) addr; |
73 | return NULL; | 76 | GNUNET_assert (NULL != saddr); |
77 | GNUNET_assert (0 < addrlen); | ||
78 | GNUNET_assert (saddr[addrlen-1] == '\0'); | ||
79 | return saddr; | ||
74 | } | 80 | } |
75 | 81 | ||
76 | /** | 82 | /** |
@@ -92,8 +98,60 @@ http_common_plugin_string_to_address (void *cls, | |||
92 | void **buf, | 98 | void **buf, |
93 | size_t *added) | 99 | size_t *added) |
94 | { | 100 | { |
95 | GNUNET_break (0); | 101 | GNUNET_assert (NULL != addr); |
96 | return GNUNET_SYSERR; | 102 | GNUNET_assert (0 < addrlen); |
103 | GNUNET_assert (addr[addrlen-1] == '\0'); | ||
104 | |||
105 | (*buf) = strdup (addr); | ||
106 | (*added) = strlen (addr) + 1; | ||
107 | return GNUNET_OK; | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * Create a HTTP address from a socketaddr | ||
112 | * | ||
113 | * @param protocol protocol | ||
114 | * @param addr sockaddr * address | ||
115 | * @param addrlen length of the address | ||
116 | * @return the string | ||
117 | */ | ||
118 | char * | ||
119 | http_common_address_from_socket (const char *protocol, const struct sockaddr *addr, socklen_t addrlen) | ||
120 | { | ||
121 | char *res; | ||
122 | GNUNET_asprintf(&res, "%s://%s", protocol, GNUNET_a2s (addr, addrlen)); | ||
123 | return res; | ||
124 | } | ||
125 | |||
126 | /** | ||
127 | * Get the length of an address | ||
128 | * | ||
129 | * @param addr address | ||
130 | * @return the size | ||
131 | */ | ||
132 | size_t | ||
133 | http_common_address_get_size (const void *addr) | ||
134 | { | ||
135 | return strlen (addr) + 1; | ||
97 | } | 136 | } |
98 | 137 | ||
138 | /** | ||
139 | * Compare addr1 to addr2 | ||
140 | * | ||
141 | * @param addr1 address1 | ||
142 | * @param addrlen1 address 1 length | ||
143 | * @param addr2 address2 | ||
144 | * @param addrlen2 address 2 length | ||
145 | * @return GNUNET_YES if equal, GNUNET_NO else | ||
146 | */ | ||
147 | size_t | ||
148 | http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2) | ||
149 | { | ||
150 | if (0 == strcmp (addr1, addr2)) | ||
151 | return GNUNET_YES; | ||
152 | return GNUNET_NO; | ||
153 | } | ||
154 | |||
155 | |||
156 | |||
99 | /* end of plugin_transport_http_common.c */ | 157 | /* end of plugin_transport_http_common.c */ |
diff --git a/src/transport/plugin_transport_http_common.h b/src/transport/plugin_transport_http_common.h index b29801d24..ff2fcc41f 100644 --- a/src/transport/plugin_transport_http_common.h +++ b/src/transport/plugin_transport_http_common.h | |||
@@ -27,6 +27,21 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_common.h" | 28 | #include "gnunet_common.h" |
29 | 29 | ||
30 | #if 0 | ||
31 | GNUNET_NETWORK_STRUCT_BEGIN | ||
32 | /** | ||
33 | * HTTP addresses including a full URI | ||
34 | */ | ||
35 | struct HttpAddress | ||
36 | { | ||
37 | /** | ||
38 | * Address following | ||
39 | */ | ||
40 | char *address GNUNET_PACKED; | ||
41 | }; | ||
42 | GNUNET_NETWORK_STRUCT_END | ||
43 | #endif | ||
44 | |||
30 | /** | 45 | /** |
31 | * Convert the transports address to a nice, human-readable | 46 | * Convert the transports address to a nice, human-readable |
32 | * format. | 47 | * format. |
@@ -61,7 +76,9 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
61 | * @return string representing the same address | 76 | * @return string representing the same address |
62 | */ | 77 | */ |
63 | const char * | 78 | const char * |
64 | http_common_plugin_address_to_string (void *cls, const void *addr, size_t addrlen); | 79 | http_common_plugin_address_to_string (void *cls, |
80 | const void *addr, | ||
81 | size_t addrlen); | ||
65 | 82 | ||
66 | /** | 83 | /** |
67 | * Function called to convert a string address to | 84 | * Function called to convert a string address to |
@@ -82,4 +99,39 @@ http_common_plugin_string_to_address (void *cls, | |||
82 | void **buf, | 99 | void **buf, |
83 | size_t *added); | 100 | size_t *added); |
84 | 101 | ||
102 | |||
103 | /** | ||
104 | * Create a HTTP address from a socketaddr | ||
105 | * | ||
106 | * @param protocol protocol | ||
107 | * @param addr sockaddr * address | ||
108 | * @param addrlen length of the address | ||
109 | * @return the string | ||
110 | */ | ||
111 | char * | ||
112 | http_common_address_from_socket (const char *protocol, | ||
113 | const struct sockaddr *addr, | ||
114 | socklen_t addrlen); | ||
115 | |||
116 | /** | ||
117 | * Get the length of an address | ||
118 | * | ||
119 | * @param addr address | ||
120 | * @return the size | ||
121 | */ | ||
122 | size_t | ||
123 | http_common_address_get_size (void *addr); | ||
124 | |||
125 | |||
126 | /** | ||
127 | * Compare addr1 to addr2 | ||
128 | * | ||
129 | * @param addr1 address1 | ||
130 | * @param addrlen1 address 1 length | ||
131 | * @param addr2 address2 | ||
132 | * @param addrlen2 address 2 length | ||
133 | * @return GNUNET_YES if equal, GNUNET_NO else | ||
134 | */ | ||
135 | size_t | ||
136 | http_common_cmp_addresses (void *addr1, size_t addrlen1, void *addr2, size_t addrlen2); | ||
85 | /* end of plugin_transport_http_common.c */ | 137 | /* end of plugin_transport_http_common.c */ |
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index e8bd43c2f..ff1037d53 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -163,7 +163,7 @@ struct HTTP_Server_Plugin | |||
163 | * External hostname the plugin can be connected to, can be different to | 163 | * External hostname the plugin can be connected to, can be different to |
164 | * the host's FQDN, used e.g. for reverse proxying | 164 | * the host's FQDN, used e.g. for reverse proxying |
165 | */ | 165 | */ |
166 | struct HttpAddress *ext_addr; | 166 | char *ext_addr; |
167 | 167 | ||
168 | /** | 168 | /** |
169 | * External address length | 169 | * External address length |
@@ -283,25 +283,6 @@ struct HTTP_Server_Plugin | |||
283 | 283 | ||
284 | }; | 284 | }; |
285 | 285 | ||
286 | GNUNET_NETWORK_STRUCT_BEGIN | ||
287 | |||
288 | /** | ||
289 | * HTTP addresses including a full URI | ||
290 | */ | ||
291 | struct HttpAddress | ||
292 | { | ||
293 | /** | ||
294 | * Length of the address following in NBO | ||
295 | */ | ||
296 | uint32_t addr_len GNUNET_PACKED; | ||
297 | |||
298 | /** | ||
299 | * Address following | ||
300 | */ | ||
301 | void *addr GNUNET_PACKED; | ||
302 | }; | ||
303 | GNUNET_NETWORK_STRUCT_END | ||
304 | |||
305 | /** | 286 | /** |
306 | * Wrapper to manage addresses | 287 | * Wrapper to manage addresses |
307 | */ | 288 | */ |
@@ -317,7 +298,7 @@ struct HttpAddressWrapper | |||
317 | */ | 298 | */ |
318 | struct HttpAddressWrapper *prev; | 299 | struct HttpAddressWrapper *prev; |
319 | 300 | ||
320 | struct HttpAddress *addr; | 301 | void *addr; |
321 | }; | 302 | }; |
322 | 303 | ||
323 | /** | 304 | /** |
@@ -452,6 +433,23 @@ http_server_plugin_address_suggested (void *cls, const void *addr, size_t addrle | |||
452 | return GNUNET_OK; | 433 | return GNUNET_OK; |
453 | } | 434 | } |
454 | 435 | ||
436 | /** | ||
437 | * Creates a new outbound session the transport | ||
438 | * service will use to send data to the peer | ||
439 | * | ||
440 | * Since HTTP/S server cannot create sessions, always return NULL | ||
441 | * | ||
442 | * @param cls the plugin | ||
443 | * @param address the address | ||
444 | * @return always NULL | ||
445 | */ | ||
446 | static struct Session * | ||
447 | http_server_plugin_get_session (void *cls, | ||
448 | const struct GNUNET_HELLO_Address *address) | ||
449 | { | ||
450 | return NULL; | ||
451 | } | ||
452 | |||
455 | 453 | ||
456 | /** | 454 | /** |
457 | * Deleting the session | 455 | * Deleting the session |
@@ -498,12 +496,20 @@ server_find_address (struct HTTP_Server_Plugin *plugin, const struct sockaddr *a | |||
498 | { | 496 | { |
499 | struct HttpAddressWrapper *w = NULL; | 497 | struct HttpAddressWrapper *w = NULL; |
500 | char *saddr; | 498 | char *saddr; |
499 | size_t salen; | ||
500 | |||
501 | saddr = http_common_address_from_socket (plugin->protocol, addr, addrlen); | ||
502 | if (NULL == saddr) | ||
503 | return NULL; | ||
504 | salen = http_common_address_get_size (saddr); | ||
501 | 505 | ||
502 | GNUNET_asprintf(&saddr, "%s://%s", plugin->protocol, GNUNET_a2s (addr, addrlen)); | ||
503 | w = plugin->addr_head; | 506 | w = plugin->addr_head; |
504 | while (NULL != w) | 507 | while (NULL != w) |
505 | { | 508 | { |
506 | if (0 == strcmp (saddr, w->addr->addr)) | 509 | if (GNUNET_YES == http_common_cmp_addresses(saddr, |
510 | salen, | ||
511 | w->addr, | ||
512 | http_common_address_get_size (w->addr))) | ||
507 | break; | 513 | break; |
508 | w = w->next; | 514 | w = w->next; |
509 | } | 515 | } |
@@ -1118,24 +1124,23 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
1118 | { | 1124 | { |
1119 | struct HTTP_Server_Plugin *plugin = cls; | 1125 | struct HTTP_Server_Plugin *plugin = cls; |
1120 | struct HttpAddressWrapper *w = NULL; | 1126 | struct HttpAddressWrapper *w = NULL; |
1121 | char *saddr; | 1127 | size_t alen; |
1122 | size_t haddrlen; | ||
1123 | 1128 | ||
1124 | GNUNET_asprintf(&saddr, "%s://%s", plugin->protocol, GNUNET_a2s (addr, addrlen)); | ||
1125 | |||
1126 | haddrlen = sizeof (struct HttpAddress) + strlen(saddr) + 1; | ||
1127 | w = GNUNET_malloc (sizeof (struct HttpAddressWrapper)); | 1129 | w = GNUNET_malloc (sizeof (struct HttpAddressWrapper)); |
1128 | w->addr = GNUNET_malloc (haddrlen); | 1130 | w->addr = http_common_address_from_socket (plugin->protocol, addr, addrlen); |
1129 | w->addr->addr = &w->addr[1]; | 1131 | if (NULL == w->addr) |
1130 | w->addr->addr_len = htonl (strlen(saddr) + 1); | 1132 | { |
1131 | memcpy (w->addr->addr, saddr, strlen(saddr) + 1); | 1133 | GNUNET_free (w); |
1132 | GNUNET_free (saddr); | 1134 | return; |
1135 | } | ||
1136 | alen = http_common_address_get_size (w->addr); | ||
1133 | 1137 | ||
1134 | GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w); | 1138 | GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w); |
1135 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1139 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1136 | "Notifying transport to add address `%s'\n", w->addr->addr); | 1140 | "Notifying transport to add address `%s'\n", |
1141 | http_common_plugin_address_to_string(NULL, w->addr, alen)); | ||
1137 | 1142 | ||
1138 | plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, haddrlen); | 1143 | plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, alen); |
1139 | } | 1144 | } |
1140 | 1145 | ||
1141 | 1146 | ||
@@ -1145,20 +1150,18 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
1145 | { | 1150 | { |
1146 | struct HTTP_Server_Plugin *plugin = cls; | 1151 | struct HTTP_Server_Plugin *plugin = cls; |
1147 | struct HttpAddressWrapper *w = NULL; | 1152 | struct HttpAddressWrapper *w = NULL; |
1148 | size_t haddrlen; | 1153 | size_t alen; |
1149 | 1154 | ||
1150 | w = server_find_address (plugin, addr, addrlen); | 1155 | w = server_find_address (plugin, addr, addrlen); |
1151 | if (NULL == w) | 1156 | if (NULL == w) |
1152 | return; | 1157 | return; |
1153 | 1158 | ||
1154 | haddrlen = sizeof (struct HttpAddress) + ntohl (w->addr->addr_len); | 1159 | alen = http_common_address_get_size (w->addr); |
1155 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1160 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1156 | "Notifying transport to remove address `%s'\n", http_server_plugin_address_to_string (NULL, w->addr, haddrlen)); | 1161 | "Notifying transport to remove address `%s'\n", |
1157 | 1162 | http_common_plugin_address_to_string (NULL, w->addr, alen)); | |
1158 | |||
1159 | GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); | 1163 | GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); |
1160 | plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, | 1164 | plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, alen); |
1161 | sizeof (struct HttpAddress) + ntohl (w->addr->addr_len)); | ||
1162 | GNUNET_free (w->addr); | 1165 | GNUNET_free (w->addr); |
1163 | GNUNET_free (w); | 1166 | GNUNET_free (w); |
1164 | } | 1167 | } |
@@ -1477,30 +1480,17 @@ static void | |||
1477 | server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1480 | server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1478 | { | 1481 | { |
1479 | struct HTTP_Server_Plugin *plugin = cls; | 1482 | struct HTTP_Server_Plugin *plugin = cls; |
1480 | struct HttpAddress *eaddr; | ||
1481 | char *addr; | ||
1482 | size_t eaddr_len; | ||
1483 | size_t uri_len; | ||
1484 | 1483 | ||
1485 | plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK; | 1484 | plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK; |
1486 | 1485 | ||
1487 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1486 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1488 | return; | 1487 | return; |
1489 | 1488 | ||
1490 | GNUNET_asprintf(&addr, "%s://%s", plugin->protocol, plugin->external_hostname); | 1489 | GNUNET_asprintf(&plugin->ext_addr, "%s://%s", plugin->protocol, plugin->external_hostname); |
1491 | uri_len = strlen (addr) + 1; | 1490 | plugin->ext_addr_len = strlen (plugin->ext_addr) + 1; |
1492 | eaddr_len = sizeof (struct HttpAddress) + uri_len; | ||
1493 | eaddr = GNUNET_malloc (eaddr_len); | ||
1494 | eaddr->addr_len = htonl (uri_len); | ||
1495 | eaddr->addr = (void *) &eaddr[1]; | ||
1496 | memcpy (&eaddr->addr, addr, uri_len); | ||
1497 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1491 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1498 | "Notifying transport about external hostname address `%s'\n", addr); | 1492 | "Notifying transport about external hostname address `%s'\n", plugin->ext_addr); |
1499 | 1493 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr, plugin->ext_addr_len ); | |
1500 | GNUNET_free (addr); | ||
1501 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, eaddr, eaddr_len); | ||
1502 | plugin->ext_addr = eaddr; | ||
1503 | plugin->ext_addr_len = eaddr_len; | ||
1504 | } | 1494 | } |
1505 | 1495 | ||
1506 | 1496 | ||
@@ -1670,7 +1660,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
1670 | { | 1660 | { |
1671 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1661 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1672 | "Notifying transport to remove address `%s'\n", | 1662 | "Notifying transport to remove address `%s'\n", |
1673 | http_server_plugin_address_to_string (NULL, | 1663 | http_common_plugin_address_to_string (NULL, |
1674 | plugin->ext_addr, | 1664 | plugin->ext_addr, |
1675 | plugin->ext_addr_len)); | 1665 | plugin->ext_addr_len)); |
1676 | plugin->env->notify_address (plugin->env->cls, | 1666 | plugin->env->notify_address (plugin->env->cls, |
@@ -1713,6 +1703,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
1713 | api->send = &http_server_plugin_send; | 1703 | api->send = &http_server_plugin_send; |
1714 | api->disconnect = &http_server_plugin_disconnect; | 1704 | api->disconnect = &http_server_plugin_disconnect; |
1715 | api->check_address = &http_server_plugin_address_suggested; | 1705 | api->check_address = &http_server_plugin_address_suggested; |
1706 | api->get_session = &http_server_plugin_get_session; | ||
1707 | |||
1716 | api->address_to_string = &http_common_plugin_address_to_string; | 1708 | api->address_to_string = &http_common_plugin_address_to_string; |
1717 | api->string_to_address = &http_common_plugin_string_to_address; | 1709 | api->string_to_address = &http_common_plugin_string_to_address; |
1718 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; | 1710 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; |
diff --git a/src/transport/test_transport_api_http_reverse_proxy.conf b/src/transport/test_transport_api_http_reverse_proxy.conf index 699a0745f..f8a7ac331 100644 --- a/src/transport/test_transport_api_http_reverse_proxy.conf +++ b/src/transport/test_transport_api_http_reverse_proxy.conf | |||
@@ -37,7 +37,7 @@ UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock | |||
37 | [transport] | 37 | [transport] |
38 | #DEBUG = YES | 38 | #DEBUG = YES |
39 | PORT = 12081 | 39 | PORT = 12081 |
40 | PLUGINS = https_client | 40 | PLUGINS = http_server |
41 | # http_client | 41 | # http_client |
42 | #BINARY = .libs/gnunet-service-transport | 42 | #BINARY = .libs/gnunet-service-transport |
43 | UNIXPATH = /tmp/gnunet-p1-service-transport.sock | 43 | UNIXPATH = /tmp/gnunet-p1-service-transport.sock |