WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
endif
+if HAVE_MHD
+ GN_LIBMHD = -lmicrohttpd
+ HTTP_PLUGIN_LA = libgnunet_plugin_transport_http.la
+ HTTP_PLGUIN_CHECK = test_plugin_transport_http
+endif
+
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
endif
libgnunet_plugin_transport_tcp.la \
libgnunet_plugin_transport_udp.la \
libgnunet_plugin_transport_udp_nat.la \
+ $(HTTP_PLUGIN_LA) \
libgnunet_plugin_transport_template.la
-# libgnunet_plugin_transport_http.la
# TODO: add http, nat, etc.
libgnunet_plugin_transport_tcp_la_SOURCES = \
libgnunet_plugin_transport_udp_nat_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
+if HAVE_MHD
libgnunet_plugin_transport_http_la_SOURCES = \
plugin_transport_http.c
libgnunet_plugin_transport_http_la_LIBADD = \
$(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
$(top_builddir)/src/util/libgnunetutil.la
libgnunet_plugin_transport_http_la_LDFLAGS = \
+ $(GN_LIBMHD) \
$(GN_PLUGIN_LDFLAGS)
-
+endif
check_PROGRAMS = \
test_transport_api_tcp \
test_transport_api_udp \
- test_transport_api_udp_nat \
- test_plugin_transport_http
+ $(HTTP_PLGUIN_CHECK) \
+ test_transport_api_udp_nat
# test_transport_api_http \
# TODO: add tests for http, nat, etc.
#include "gnunet_statistics_service.h"
#include "gnunet_transport_service.h"
#include "plugin_transport.h"
+#include "microhttpd.h"
-#define DEBUG_HTTP GNUNET_YES
+#define VERBOSE GNUNET_YES
+#define DEBUG GNUNET_YES
/**
* After how long do we expire an address that we
*/
#define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6)
+#define HTTP_TIMEOUT 600
/**
* Encapsulation of all of the state of the plugin.
};
+/**
+ * Daemon for listening for new connections.
+ */
+static struct MHD_Daemon *http_daemon;
+
/**
* Function that can be used by the transport service to transmit
* a message using the plugin.
return GNUNET_OK;
}
+/**
+ * Check if we are allowed to connect to the given IP.
+ */
+static int
+acceptPolicyCallback (void *cls,
+ const struct sockaddr *addr, socklen_t addr_len)
+{
+ return MHD_YES;
+}
+
+/**
+ * Process GET or PUT request received via MHD. For
+ * GET, queue response that will send back our pending
+ * messages. For PUT, process incoming data and send
+ * to GNUnet core. In either case, check if a session
+ * already exists and create a new one if not.
+ */
+static int
+accessHandlerCallback (void *cls,
+ struct MHD_Connection *session,
+ const char *url,
+ const char *method,
+ const char *version,
+ const char *upload_data,
+ size_t * upload_data_size, void **httpSessionCache)
+{
+ return MHD_YES;
+}
+
+/**
+ * MHD is done handling a request. Cleanup
+ * the respective transport state.
+ */
+static void
+requestCompletedCallback (void *unused,
+ struct MHD_Connection *session,
+ void **httpSessionCache)
+{
+
+}
/**
* Entry point for the plugin.
struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
struct GNUNET_TRANSPORT_PluginFunctions *api;
struct Plugin *plugin;
+ long long unsigned int port;
+ int use_ipv6;
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
api->disconnect = &http_plugin_disconnect;
api->address_pretty_printer = &http_plugin_address_pretty_printer;
api->check_address = &http_plugin_address_suggested;
- return api;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n");
+ /* Reading port number from config file */
+ if ((GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ "transport-http",
+ "PORT",
+ &port)) ||
+ (port > 65535) )
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "http",
+ _
+ ("Require valid port number for service `%s' in configuration!\n"),
+ "transport-http");
+ return NULL;
+ }
+ use_ipv6 = GNUNET_YES;
+ use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-http","USE_IPV6");
+ if ((http_daemon == NULL) && (port != 0))
+ {
+ if ( use_ipv6 == GNUNET_YES)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon could not started, http plugin not working\n");
+ http_daemon = MHD_start_daemon (MHD_USE_IPv6,
+ port,
+ &acceptPolicyCallback,
+ NULL, &accessHandlerCallback, NULL,
+ MHD_OPTION_CONNECTION_TIMEOUT,
+ (unsigned int) HTTP_TIMEOUT,
+ MHD_OPTION_CONNECTION_MEMORY_LIMIT,
+ (unsigned int) GNUNET_SERVER_MAX_MESSAGE_SIZE,
+ MHD_OPTION_CONNECTION_LIMIT,
+ (unsigned int) 128,
+ MHD_OPTION_PER_IP_CONNECTION_LIMIT,
+ (unsigned int) 8,
+ MHD_OPTION_NOTIFY_COMPLETED,
+ &requestCompletedCallback, NULL,
+ MHD_OPTION_END);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u with IPv6 disabled\n",port);
+ http_daemon = MHD_start_daemon (MHD_NO_FLAG,
+ port,
+ &acceptPolicyCallback,
+ NULL, &accessHandlerCallback, NULL,
+ MHD_OPTION_CONNECTION_TIMEOUT,
+ (unsigned int) HTTP_TIMEOUT,
+ MHD_OPTION_CONNECTION_MEMORY_LIMIT,
+ (unsigned int) GNUNET_SERVER_MAX_MESSAGE_SIZE,
+ MHD_OPTION_CONNECTION_LIMIT,
+ (unsigned int) 128,
+ MHD_OPTION_PER_IP_CONNECTION_LIMIT,
+ (unsigned int) 8,
+ MHD_OPTION_NOTIFY_COMPLETED,
+ &requestCompletedCallback, NULL,
+ MHD_OPTION_END);
+ }
+ }
+ if ( NULL != http_daemon )
+ return api;
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"Starting MHD on port %u with IPv6 disabled\n",port);
+ return NULL;
+ }
}
struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
+ if (http_daemon != NULL)
+ {
+ MHD_stop_daemon (http_daemon);
+ http_daemon = NULL;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Shutting down http plugin...\n");
+
GNUNET_free (plugin);
GNUNET_free (api);
return NULL;
#include "plugin_transport.h"
#include "transport.h"
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
+#define DEBUG GNUNET_YES
/**
* How long until we give up on transmitting the message?
unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (NULL ==
- GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_udp",
+ GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http",
api));
if (my_private_key != NULL)
GNUNET_CRYPTO_rsa_key_free (my_private_key);
test_validation ()
{
struct sockaddr_in soaddr;
-
memset (&soaddr, 0, sizeof (soaddr));
#if HAVE_SOCKADDR_IN_SIN_LEN
soaddr.sin_len = sizeof (soaddr);
GNUNET_SCHEDULER_shutdown (s);
return;
}
+ /*
max_connect_per_transport = (uint32_t) tneigh;
my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
}
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
GNUNET_CRYPTO_hash (&my_public_key,
- sizeof (my_public_key), &my_identity.hashPubKey);
+ sizeof (my_public_key), &my_identity.hashPubKey);*/
/* load plugins... */
setup_plugin_environment ();
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading http transport plugin\n"));
+
GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
api = GNUNET_PLUGIN_load (libname, &env);
+ if (api != NULL )
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Loading transport plugin for http `%s' successful\n",libname);
+
GNUNET_free (libname);
if (api == NULL)
{