#include "gnunet_transport_service.h"
#include "gnunet_resolver_service.h"
#include "plugin_transport.h"
+#include "gnunet_os_lib.h"
#include "microhttpd.h"
#include <curl/curl.h>
*/
struct Plugin;
+/**
+ * Network format for IPv4 addresses.
+ */
+struct IPv4HttpAddress
+{
+ /**
+ * IPv4 address, in network byte order.
+ */
+ uint32_t ipv4_addr;
+
+ /**
+ * Port number, in network byte order.
+ */
+ uint16_t u_port;
+
+};
+
+
+/**
+ * Network format for IPv6 addresses.
+ */
+struct IPv6HttpAddress
+{
+ /**
+ * IPv6 address.
+ */
+ struct in6_addr ipv6_addr;
+
+ /**
+ * Port number, in network byte order.
+ */
+ uint16_t u6_port;
+
+};
+
+
+
/**
* Message to send using http
*/
/**
* amount of data to sent
*/
- size_t size;
-
size_t len;
};
*/
struct GNUNET_SERVICE_Context *service;
+ unsigned int port_inbound;
+
/**
* List of open sessions.
*/
asc, void *asc_cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: http_plugin_address_pretty_printer\n");
+
+
asc (asc_cls, NULL);
}
return NULL;
}
+/**
+ * Add the IP of our network interface to the list of
+ * our external IP addresses.
+ *
+ * @param cls the 'struct Plugin*'
+ * @param name name of the interface
+ * @param isDefault do we think this may be our default interface
+ * @param addr address of the interface
+ * @param addrlen number of bytes in addr
+ * @return GNUNET_OK to continue iterating
+ */
+static int
+process_interfaces (void *cls,
+ const char *name,
+ int isDefault,
+ const struct sockaddr *addr, socklen_t addrlen)
+{
+ struct IPv4HttpAddress t4;
+ struct IPv6HttpAddress t6;
+ int af;
+ void *arg;
+ uint16_t args;
+
+ af = addr->sa_family;
+ if (af == AF_INET)
+ {
+ t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
+ t4.u_port = htons (plugin->port_inbound);
+ arg = &t4;
+ args = sizeof (t4);
+ }
+ else if (af == AF_INET6)
+ {
+ if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
+ {
+ /* skip link local addresses */
+ return GNUNET_OK;
+ }
+ memcpy (&t6.ipv6_addr,
+ &((struct sockaddr_in6 *) addr)->sin6_addr,
+ sizeof (struct in6_addr));
+ t6.u6_port = htons (plugin->port_inbound);
+ arg = &t6;
+ args = sizeof (t6);
+ }
+ else
+ {
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
+ plugin->env->notify_address(plugin->env->cls,"http",arg, args, GNUNET_TIME_UNIT_FOREVER_REL);
+
+ return GNUNET_OK;
+}
+
/**
* Exit point from the plugin.
*/
libgnunet_plugin_transport_http_done (api);
return NULL;
}
-
+ plugin->port_inbound = port;
gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
timeout = ( gn_timeout.value / 1000);
if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0))
if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port);
+
/* Initializing cURL */
multi_handle = curl_multi_init();
if ( NULL == multi_handle )
libgnunet_plugin_transport_http_done (api);
return NULL;
}
+
+ GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
+
return api;
}
const struct GNUNET_PeerIdentity * p;
+
+/**
+ * Did the test pass or fail?
+ */
+static int fail_notify_address;
+/**
+ * Did the test pass or fail?
+ */
+static int fail_notify_address_count;
+
/**
* Did the test pass or fail?
*/
return GNUNET_TIME_UNIT_ZERO;
}
+
+/**
+ * Network format for IPv4 addresses.
+ */
+struct IPv4HttpAddress
+{
+ /**
+ * IPv4 address, in network byte order.
+ */
+ uint32_t ipv4_addr;
+
+ /**
+ * Port number, in network byte order.
+ */
+ uint16_t u_port;
+
+};
+
+
+/**
+ * Network format for IPv6 addresses.
+ */
+struct IPv6HttpAddress
+{
+ /**
+ * IPv6 address.
+ */
+ struct in6_addr ipv6_addr;
+
+ /**
+ * Port number, in network byte order.
+ */
+ uint16_t u6_port;
+
+};
+
+/**
+ * Plugin notifies transport (aka testcase) about its addresses
+ */
void
notify_address (void *cls,
const char *name,
uint16_t addrlen,
struct GNUNET_TIME_Relative expires)
{
+ char * address = NULL;
+ unsigned int port;
+
+ if (addrlen == (sizeof (struct IPv4HttpAddress)))
+ {
+ address = GNUNET_malloc (INET_ADDRSTRLEN);
+ inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN);
+ port = ntohs(((struct IPv4HttpAddress *) addr)->u_port);
+ }
+
+ if (addrlen == (sizeof (struct IPv6HttpAddress)))
+ {
+ address = GNUNET_malloc (INET6_ADDRSTRLEN);
+ inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN);
+ port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Transport plugin notification for address: `%s':%u\n"),address,port);
+ fail_notify_address_count++;
+
+ fail_notify_address = GNUNET_NO;
}
/**
if (my_private_key == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Transport service could not access hostkey. Exiting.\n"));
+ _("Transport service could not access hostkey. Exiting.\n"));
GNUNET_SCHEDULER_shutdown (s);
fail = 1;
return;
ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, TEST_TIMEOUT, &task_timeout, NULL);
/* testing plugin functionality */
-
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin returned %u addresses to connect to\n"), fail_notify_address_count);
/* testing finished, shutting down */
+
+ if (fail_notify_address == GNUNET_NO)
+ fail = 0;
+
+
+
shutdown_clean();
- fail = 0;
+
return;
}