[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r23362 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r23362 - gnunet/src/transport |
Date: |
Wed, 22 Aug 2012 16:49:12 +0200 |
Author: wachs
Date: 2012-08-22 16:49:12 +0200 (Wed, 22 Aug 2012)
New Revision: 23362
Modified:
gnunet/src/transport/plugin_transport_http_common.c
gnunet/src/transport/plugin_transport_http_common.h
gnunet/src/transport/plugin_transport_http_server.c
gnunet/src/transport/test_transport_api_http_reverse_proxy.conf
Log:
changes
Modified: gnunet/src/transport/plugin_transport_http_common.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_common.c 2012-08-22 14:47:12 UTC
(rev 23361)
+++ gnunet/src/transport/plugin_transport_http_common.c 2012-08-22 14:49:12 UTC
(rev 23362)
@@ -50,8 +50,11 @@
GNUNET_TRANSPORT_AddressStringCallback
asc, void *asc_cls)
{
- GNUNET_break (0);
- asc (asc_cls, NULL);
+ const char *saddr = (const char *) addr;
+ GNUNET_assert (NULL != saddr);
+ GNUNET_assert (0 < addrlen);
+ GNUNET_assert (saddr[addrlen-1] == '\0');
+ asc (asc_cls, saddr);
}
@@ -69,8 +72,11 @@
const char *
http_common_plugin_address_to_string (void *cls, const void *addr, size_t
addrlen)
{
- GNUNET_break (0);
- return NULL;
+ const char *saddr = (const char *) addr;
+ GNUNET_assert (NULL != saddr);
+ GNUNET_assert (0 < addrlen);
+ GNUNET_assert (saddr[addrlen-1] == '\0');
+ return saddr;
}
/**
@@ -92,8 +98,60 @@
void **buf,
size_t *added)
{
- GNUNET_break (0);
- return GNUNET_SYSERR;
+ GNUNET_assert (NULL != addr);
+ GNUNET_assert (0 < addrlen);
+ GNUNET_assert (addr[addrlen-1] == '\0');
+
+ (*buf) = strdup (addr);
+ (*added) = strlen (addr) + 1;
+ return GNUNET_OK;
}
+/**
+ * Create a HTTP address from a socketaddr
+ *
+ * @param protocol protocol
+ * @param addr sockaddr * address
+ * @param addrlen length of the address
+ * @return the string
+ */
+char *
+http_common_address_from_socket (const char *protocol, const struct sockaddr
*addr, socklen_t addrlen)
+{
+ char *res;
+ GNUNET_asprintf(&res, "%s://%s", protocol, GNUNET_a2s (addr, addrlen));
+ return res;
+}
+
+/**
+ * Get the length of an address
+ *
+ * @param addr address
+ * @return the size
+ */
+size_t
+http_common_address_get_size (const void *addr)
+{
+ return strlen (addr) + 1;
+}
+
+/**
+ * Compare addr1 to addr2
+ *
+ * @param addr1 address1
+ * @param addrlen1 address 1 length
+ * @param addr2 address2
+ * @param addrlen2 address 2 length
+ * @return GNUNET_YES if equal, GNUNET_NO else
+ */
+size_t
+http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void
*addr2, size_t addrlen2)
+{
+ if (0 == strcmp (addr1, addr2))
+ return GNUNET_YES;
+ return GNUNET_NO;
+}
+
+
+
/* end of plugin_transport_http_common.c */
Modified: gnunet/src/transport/plugin_transport_http_common.h
===================================================================
--- gnunet/src/transport/plugin_transport_http_common.h 2012-08-22 14:47:12 UTC
(rev 23361)
+++ gnunet/src/transport/plugin_transport_http_common.h 2012-08-22 14:49:12 UTC
(rev 23362)
@@ -27,7 +27,22 @@
#include "platform.h"
#include "gnunet_common.h"
+#if 0
+GNUNET_NETWORK_STRUCT_BEGIN
/**
+ * HTTP addresses including a full URI
+ */
+struct HttpAddress
+{
+ /**
+ * Address following
+ */
+ char *address GNUNET_PACKED;
+};
+GNUNET_NETWORK_STRUCT_END
+#endif
+
+/**
* Convert the transports address to a nice, human-readable
* format.
*
@@ -61,7 +76,9 @@
* @return string representing the same address
*/
const char *
-http_common_plugin_address_to_string (void *cls, const void *addr, size_t
addrlen);
+http_common_plugin_address_to_string (void *cls,
+ const void *addr,
+ size_t addrlen);
/**
* Function called to convert a string address to
@@ -82,4 +99,39 @@
void **buf,
size_t *added);
+
+/**
+ * Create a HTTP address from a socketaddr
+ *
+ * @param protocol protocol
+ * @param addr sockaddr * address
+ * @param addrlen length of the address
+ * @return the string
+ */
+char *
+http_common_address_from_socket (const char *protocol,
+ const struct sockaddr *addr,
+ socklen_t addrlen);
+
+/**
+ * Get the length of an address
+ *
+ * @param addr address
+ * @return the size
+ */
+size_t
+http_common_address_get_size (void *addr);
+
+
+/**
+ * Compare addr1 to addr2
+ *
+ * @param addr1 address1
+ * @param addrlen1 address 1 length
+ * @param addr2 address2
+ * @param addrlen2 address 2 length
+ * @return GNUNET_YES if equal, GNUNET_NO else
+ */
+size_t
+http_common_cmp_addresses (void *addr1, size_t addrlen1, void *addr2, size_t
addrlen2);
/* end of plugin_transport_http_common.c */
Modified: gnunet/src/transport/plugin_transport_http_server.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_server.c 2012-08-22 14:47:12 UTC
(rev 23361)
+++ gnunet/src/transport/plugin_transport_http_server.c 2012-08-22 14:49:12 UTC
(rev 23362)
@@ -163,7 +163,7 @@
* External hostname the plugin can be connected to, can be different to
* the host's FQDN, used e.g. for reverse proxying
*/
- struct HttpAddress *ext_addr;
+ char *ext_addr;
/**
* External address length
@@ -283,26 +283,7 @@
};
-GNUNET_NETWORK_STRUCT_BEGIN
-
/**
- * HTTP addresses including a full URI
- */
-struct HttpAddress
-{
- /**
- * Length of the address following in NBO
- */
- uint32_t addr_len GNUNET_PACKED;
-
- /**
- * Address following
- */
- void *addr GNUNET_PACKED;
-};
-GNUNET_NETWORK_STRUCT_END
-
-/**
* Wrapper to manage addresses
*/
struct HttpAddressWrapper
@@ -317,7 +298,7 @@
*/
struct HttpAddressWrapper *prev;
- struct HttpAddress *addr;
+ void *addr;
};
/**
@@ -452,7 +433,24 @@
return GNUNET_OK;
}
+/**
+ * Creates a new outbound session the transport
+ * service will use to send data to the peer
+ *
+ * Since HTTP/S server cannot create sessions, always return NULL
+ *
+ * @param cls the plugin
+ * @param address the address
+ * @return always NULL
+ */
+static struct Session *
+http_server_plugin_get_session (void *cls,
+ const struct GNUNET_HELLO_Address *address)
+{
+ return NULL;
+}
+
/**
* Deleting the session
* Must not be used afterwards
@@ -498,12 +496,20 @@
{
struct HttpAddressWrapper *w = NULL;
char *saddr;
+ size_t salen;
- GNUNET_asprintf(&saddr, "%s://%s", plugin->protocol, GNUNET_a2s (addr,
addrlen));
+ saddr = http_common_address_from_socket (plugin->protocol, addr, addrlen);
+ if (NULL == saddr)
+ return NULL;
+ salen = http_common_address_get_size (saddr);
+
w = plugin->addr_head;
while (NULL != w)
{
- if (0 == strcmp (saddr, w->addr->addr))
+ if (GNUNET_YES == http_common_cmp_addresses(saddr,
+ salen,
+ w->addr,
+ http_common_address_get_size
(w->addr)))
break;
w = w->next;
}
@@ -1118,24 +1124,23 @@
{
struct HTTP_Server_Plugin *plugin = cls;
struct HttpAddressWrapper *w = NULL;
- char *saddr;
- size_t haddrlen;
+ size_t alen;
- GNUNET_asprintf(&saddr, "%s://%s", plugin->protocol, GNUNET_a2s (addr,
addrlen));
-
- haddrlen = sizeof (struct HttpAddress) + strlen(saddr) + 1;
w = GNUNET_malloc (sizeof (struct HttpAddressWrapper));
- w->addr = GNUNET_malloc (haddrlen);
- w->addr->addr = &w->addr[1];
- w->addr->addr_len = htonl (strlen(saddr) + 1);
- memcpy (w->addr->addr, saddr, strlen(saddr) + 1);
- GNUNET_free (saddr);
+ w->addr = http_common_address_from_socket (plugin->protocol, addr, addrlen);
+ if (NULL == w->addr)
+ {
+ GNUNET_free (w);
+ return;
+ }
+ alen = http_common_address_get_size (w->addr);
GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w);
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Notifying transport to add address `%s'\n", w->addr->addr);
+ "Notifying transport to add address `%s'\n",
+ http_common_plugin_address_to_string(NULL, w->addr, alen));
- plugin->env->notify_address (plugin->env->cls, add_remove, w->addr,
haddrlen);
+ plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, alen);
}
@@ -1145,20 +1150,18 @@
{
struct HTTP_Server_Plugin *plugin = cls;
struct HttpAddressWrapper *w = NULL;
- size_t haddrlen;
+ size_t alen;
w = server_find_address (plugin, addr, addrlen);
if (NULL == w)
return;
- haddrlen = sizeof (struct HttpAddress) + ntohl (w->addr->addr_len);
+ alen = http_common_address_get_size (w->addr);
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Notifying transport to remove address `%s'\n",
http_server_plugin_address_to_string (NULL, w->addr, haddrlen));
-
-
+ "Notifying transport to remove address `%s'\n",
+ http_common_plugin_address_to_string (NULL, w->addr, alen));
GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w);
- plugin->env->notify_address (plugin->env->cls, add_remove, w->addr,
- sizeof (struct HttpAddress) + ntohl (w->addr->addr_len));
+ plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, alen);
GNUNET_free (w->addr);
GNUNET_free (w);
}
@@ -1477,30 +1480,17 @@
server_notify_external_hostname (void *cls, const struct
GNUNET_SCHEDULER_TaskContext *tc)
{
struct HTTP_Server_Plugin *plugin = cls;
- struct HttpAddress *eaddr;
- char *addr;
- size_t eaddr_len;
- size_t uri_len;
plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- GNUNET_asprintf(&addr, "%s://%s", plugin->protocol,
plugin->external_hostname);
- uri_len = strlen (addr) + 1;
- eaddr_len = sizeof (struct HttpAddress) + uri_len;
- eaddr = GNUNET_malloc (eaddr_len);
- eaddr->addr_len = htonl (uri_len);
- eaddr->addr = (void *) &eaddr[1];
- memcpy (&eaddr->addr, addr, uri_len);
+ GNUNET_asprintf(&plugin->ext_addr, "%s://%s", plugin->protocol,
plugin->external_hostname);
+ plugin->ext_addr_len = strlen (plugin->ext_addr) + 1;
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Notifying transport about external hostname address
`%s'\n", addr);
-
- GNUNET_free (addr);
- plugin->env->notify_address (plugin->env->cls, GNUNET_YES, eaddr, eaddr_len);
- plugin->ext_addr = eaddr;
- plugin->ext_addr_len = eaddr_len;
+ "Notifying transport about external hostname address
`%s'\n", plugin->ext_addr);
+ plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr,
plugin->ext_addr_len );
}
@@ -1670,7 +1660,7 @@
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
"Notifying transport to remove address `%s'\n",
- http_server_plugin_address_to_string (NULL,
+ http_common_plugin_address_to_string (NULL,
plugin->ext_addr,
plugin->ext_addr_len));
plugin->env->notify_address (plugin->env->cls,
@@ -1713,6 +1703,8 @@
api->send = &http_server_plugin_send;
api->disconnect = &http_server_plugin_disconnect;
api->check_address = &http_server_plugin_address_suggested;
+ api->get_session = &http_server_plugin_get_session;
+
api->address_to_string = &http_common_plugin_address_to_string;
api->string_to_address = &http_common_plugin_string_to_address;
api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
Modified: gnunet/src/transport/test_transport_api_http_reverse_proxy.conf
===================================================================
--- gnunet/src/transport/test_transport_api_http_reverse_proxy.conf
2012-08-22 14:47:12 UTC (rev 23361)
+++ gnunet/src/transport/test_transport_api_http_reverse_proxy.conf
2012-08-22 14:49:12 UTC (rev 23362)
@@ -37,7 +37,7 @@
[transport]
#DEBUG = YES
PORT = 12081
-PLUGINS = https_client
+PLUGINS = http_server
# http_client
#BINARY = .libs/gnunet-service-transport
UNIXPATH = /tmp/gnunet-p1-service-transport.sock
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r23362 - gnunet/src/transport,
gnunet <=