aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_http_server.c')
-rw-r--r--src/transport/plugin_transport_http_server.c112
1 files changed, 52 insertions, 60 deletions
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
286GNUNET_NETWORK_STRUCT_BEGIN
287
288/**
289 * HTTP addresses including a full URI
290 */
291struct 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};
303GNUNET_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 */
446static struct Session *
447http_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
1477server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1480server_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;