+#if MHD_VERSION >= 0x00090E00
+ server_mhd_connection_timeout (plugin, s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000);
+#endif
+ (*upload_data_size) = 0;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Session %p / Connection %p: no inbound bandwidth available! Next read was delayed by %llu ms\n",
+ s, sc, now.abs_value - s->next_receive.abs_value);
+ }
+ return MHD_YES;
+ }
+ else
+ {
+ GNUNET_break (0);
+ return MHD_NO;
+ }
+ }
+ return res;
+}
+
+
+/**
+ * Callback from MHD when a connection disconnects
+ *
+ * @param cls closure
+ * @param connection the disconnected MHD connection
+ * @param httpSessionCache the pointer to distinguish
+ */
+static void
+server_disconnect_cb (void *cls, struct MHD_Connection *connection,
+ void **httpSessionCache)
+{
+ struct ServerConnection *sc = *httpSessionCache;
+ struct Session *s = NULL;
+ struct Session *t = NULL;
+ struct HTTP_Server_Plugin *plugin = NULL;
+
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, p->name,
+ "Disconnect for connection %p \n", sc);
+
+ if (sc == NULL)
+ return;
+
+ if (NULL == (s = server_lookup_session (p, sc)))
+ return;
+
+ GNUNET_assert (NULL != p);
+ for (t = p->head; t != NULL; t = t->next)
+ {
+ if (t == s)
+ break;
+ }
+ if (NULL == t)
+ return;
+
+ plugin = s->plugin;
+ if (sc->direction == _SEND)
+ {
+
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Peer `%s' connection %p, GET on address `%s' disconnected\n",
+ GNUNET_i2s (&s->target), s->server_send,
+ http_common_plugin_address_to_string (NULL, s->addr, s->addrlen));
+ s->server_send = NULL;
+ if (NULL != (s->server_recv))
+ {
+ s->server_recv->disconnect = GNUNET_YES;
+ GNUNET_assert (NULL != s->server_recv->mhd_conn);
+#if MHD_VERSION >= 0x00090E00
+ MHD_set_connection_option (s->server_recv->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
+ 1);
+#endif
+ server_reschedule (plugin, s->server_recv->mhd_daemon, GNUNET_NO);
+ }
+ }
+ if (sc->direction == _RECEIVE)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Peer `%s' connection %p PUT on address `%s' disconnected\n",
+ GNUNET_i2s (&s->target), s->server_recv,
+ http_common_plugin_address_to_string (NULL, s->addr, s->addrlen));
+ s->server_recv = NULL;
+ /* Do not terminate session when PUT disconnects
+ if (NULL != (s->server_send))
+ {
+ s->server_send->disconnect = GNUNET_YES;
+ GNUNET_assert (NULL != s->server_send->mhd_conn);
+#if MHD_VERSION >= 0x00090E00
+ MHD_set_connection_option (s->server_send->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
+ 1);
+#endif
+ server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO);
+ }*/
+ if (s->msg_tk != NULL)
+ {
+ GNUNET_SERVER_mst_destroy (s->msg_tk);
+ s->msg_tk = NULL;
+ }
+ }
+
+ GNUNET_free (sc);
+ plugin->cur_connections--;
+
+ if ((s->server_send == NULL) && (s->server_recv == NULL))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Peer `%s' on address `%s' disconnected\n",
+ GNUNET_i2s (&s->target),
+ http_common_plugin_address_to_string (NULL, s->addr, s->addrlen));
+
+ if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended))
+ {
+ /* Notify transport immediately that this session is invalid */
+ s->session_ended = GNUNET_YES;
+ plugin->env->session_end (plugin->env->cls, &s->target, s);
+ }
+ server_delete_session (s);
+ }
+
+}
+
+
+/**
+ * Check if incoming connection is accepted.
+
+ * @param cls plugin as closure
+ * @param addr address of incoming connection
+ * @param addr_len address length of incoming connection
+ * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected
+ *
+ */
+static int
+server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len)
+{
+ struct HTTP_Server_Plugin *plugin = cls;
+
+ if (plugin->cur_connections <= plugin->max_connections)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ _("Accepting connection (%u of %u) from `%s'\n"),
+ plugin->cur_connections, plugin->max_connections,
+ GNUNET_a2s (addr, addr_len));
+ return MHD_YES;
+ }
+ else
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
+ _("Server reached maximum number connections (%u), rejecting new connection\n"),
+ plugin->max_connections);
+ return MHD_NO;
+ }
+}
+
+static void
+server_log (void *arg, const char *fmt, va_list ap)
+{
+ char text[1024];
+
+ vsnprintf (text, sizeof (text), fmt, ap);
+ va_end (ap);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: %s\n", text);
+}
+
+
+/**
+ * Call MHD IPv4 to process pending requests and then go back
+ * and schedule the next run.
+ * @param cls plugin as closure
+ * @param tc task context
+ */
+static void
+server_v4_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct HTTP_Server_Plugin *plugin = cls;
+
+ GNUNET_assert (cls != NULL);
+
+ plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
+#if 0
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Running IPv4 server\n");
+#endif
+ plugin->server_v4_immediately = GNUNET_NO;
+ GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4));
+ server_reschedule (plugin, plugin->server_v4, GNUNET_NO);
+}
+
+
+/**
+ * Call MHD IPv6 to process pending requests and then go back
+ * and schedule the next run.
+ * @param cls plugin as closure
+ * @param tc task context
+ */
+static void
+server_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct HTTP_Server_Plugin *plugin = cls;
+
+ GNUNET_assert (cls != NULL);
+ plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
+#if 0
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Running IPv6 server\n");
+#endif
+ plugin->server_v6_immediately = GNUNET_NO;
+ GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6));
+ server_reschedule (plugin, plugin->server_v6, GNUNET_NO);
+}
+
+
+#define UNSIGNED_MHD_LONG_LONG unsigned MHD_LONG_LONG
+
+/**
+ * Function that queries MHD's select sets and
+ * starts the task waiting for them.
+ *
+ * @param plugin plugin
+ * @param daemon_handle the MHD daemon handle
+ * @return gnunet task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier
+server_schedule (struct HTTP_Server_Plugin *plugin,
+ struct MHD_Daemon *daemon_handle,
+ int now)
+{
+ GNUNET_SCHEDULER_TaskIdentifier ret;
+ fd_set rs;
+ fd_set ws;
+ fd_set es;
+ struct GNUNET_NETWORK_FDSet *wrs;
+ struct GNUNET_NETWORK_FDSet *wws;
+ struct GNUNET_NETWORK_FDSet *wes;
+ int max;
+ UNSIGNED_MHD_LONG_LONG timeout;
+ static unsigned long long last_timeout = 0;
+ int haveto;
+
+ struct GNUNET_TIME_Relative tv;
+
+ if (GNUNET_YES == plugin->in_shutdown)
+ return GNUNET_SCHEDULER_NO_TASK;
+
+ ret = GNUNET_SCHEDULER_NO_TASK;
+ FD_ZERO (&rs);
+ FD_ZERO (&ws);
+ FD_ZERO (&es);
+ wrs = GNUNET_NETWORK_fdset_create ();
+ wes = GNUNET_NETWORK_fdset_create ();
+ wws = GNUNET_NETWORK_fdset_create ();
+ max = -1;
+ GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
+ haveto = MHD_get_timeout (daemon_handle, &timeout);
+ if (haveto == MHD_YES)
+ {
+ if (timeout != last_timeout)
+ {
+
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "SELECT Timeout changed from %llu to %llu\n",
+ last_timeout, timeout);
+ last_timeout = timeout;
+ }
+ if (timeout <= GNUNET_TIME_UNIT_SECONDS.rel_value)
+ tv.rel_value = (uint64_t) timeout;
+ else
+ tv = GNUNET_TIME_UNIT_SECONDS;
+ }
+ else
+ tv = GNUNET_TIME_UNIT_SECONDS;
+ /* Force immediate run, since we have outbound data to send */
+ if (now == GNUNET_YES)
+ tv = GNUNET_TIME_UNIT_MILLISECONDS;
+ GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
+ GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
+ GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
+
+ if (daemon_handle == plugin->server_v4)
+ {
+ if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
+ plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+#if 0
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Scheduling IPv4 server task in %llu ms\n", tv);
+#endif
+ ret =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ tv, wrs, wws,
+ &server_v4_run, plugin);
+ }
+ if (daemon_handle == plugin->server_v6)
+ {
+ if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
+ plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+#if 0
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Scheduling IPv6 server task in %llu ms\n", tv);
+#endif
+ ret =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ tv, wrs, wws,
+ &server_v6_run, plugin);
+ }
+ GNUNET_NETWORK_fdset_destroy (wrs);
+ GNUNET_NETWORK_fdset_destroy (wws);
+ GNUNET_NETWORK_fdset_destroy (wes);
+ return ret;
+}
+
+
+#if BUILD_HTTPS
+/**
+ * Load ssl certificate from file
+ *
+ * @param file filename
+ * @return content of the file
+ */
+static char *
+server_load_file (const char *file)
+{
+ struct GNUNET_DISK_FileHandle *gn_file;
+ uint64_t fsize;
+ char *text = NULL;
+
+ if (GNUNET_OK != GNUNET_DISK_file_size (file,
+ &fsize, GNUNET_NO, GNUNET_YES))
+ return NULL;
+ text = GNUNET_malloc (fsize + 1);
+ gn_file =
+ GNUNET_DISK_file_open (file, GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_USER_READ);
+ if (gn_file == NULL)
+ {
+ GNUNET_free (text);
+ return NULL;
+ }
+ if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fsize))
+ {
+ GNUNET_free (text);
+ GNUNET_DISK_file_close (gn_file);
+ return NULL;
+ }
+ text[fsize] = '\0';
+ GNUNET_DISK_file_close (gn_file);
+ return text;
+}
+#endif
+
+
+#if BUILD_HTTPS
+/**
+ * Load ssl certificate
+ *
+ * @param plugin the plugin
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+static int
+server_load_certificate (struct HTTP_Server_Plugin *plugin)
+{
+ int res = GNUNET_OK;
+
+ char *sh;
+ char *key_file;
+ char *cert_file;
+
+ /* Get crypto init string from config
+ * If not present just use default values */
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+ "PATHS",
+ "SERVICEHOME",
+ &sh))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Failed to get servicehome!\n");
+ return GNUNET_SYSERR;
+ }
+
+
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+ plugin->name,
+ "CRYPTO_INIT",
+ &plugin->crypto_init))
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Using crypto init string `%s'\n",
+ plugin->crypto_init);
+ else
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Using default crypto init string \n");
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name,
+ "KEY_FILE", &key_file))
+ {
+ GNUNET_break (0);
+ GNUNET_asprintf (&key_file, "%s/%s", sh, "https_key.key");
+ }
+
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name,
+ "CERT_FILE", &cert_file))
+ {
+ GNUNET_break (0);
+ GNUNET_asprintf (&cert_file, "%s/%s", sh, "https_cert.crt");
+ }
+ GNUNET_free (sh);
+ /* read key & certificates from file */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to loading TLS certificate from key-file `%s' cert-file`%s'\n",
+ key_file, cert_file);
+
+ plugin->key = server_load_file (key_file);
+ plugin->cert = server_load_file (cert_file);
+
+ if ((plugin->key == NULL) || (plugin->cert == NULL))
+ {
+ struct GNUNET_OS_Process *cert_creation;
+
+ GNUNET_free_non_null (plugin->key);
+ plugin->key = NULL;
+ GNUNET_free_non_null (plugin->cert);
+ plugin->cert = NULL;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No usable TLS certificate found, creating certificate\n");
+ errno = 0;
+ cert_creation =
+ GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL,
+ "gnunet-transport-certificate-creation",
+ "gnunet-transport-certificate-creation",
+ key_file, cert_file, NULL);
+ if (cert_creation == NULL)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ _
+ ("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
+ GNUNET_free (key_file);
+ GNUNET_free (cert_file);
+
+ GNUNET_free_non_null (plugin->key);
+ plugin->key = NULL;
+ GNUNET_free_non_null (plugin->cert);
+ plugin->cert = NULL;
+ GNUNET_free_non_null (plugin->crypto_init);
+ plugin->crypto_init = NULL;
+
+ return GNUNET_SYSERR;
+ }
+ GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (cert_creation));
+ GNUNET_OS_process_destroy (cert_creation);
+
+ plugin->key = server_load_file (key_file);
+ plugin->cert = server_load_file (cert_file);
+ }
+
+ if ((plugin->key == NULL) || (plugin->cert == NULL))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ _
+ ("No usable TLS certificate found and creating one failed!\n"),
+ "transport-https");
+ GNUNET_free (key_file);
+ GNUNET_free (cert_file);
+
+ GNUNET_free_non_null (plugin->key);
+ plugin->key = NULL;
+ GNUNET_free_non_null (plugin->cert);
+ plugin->cert = NULL;
+ GNUNET_free_non_null (plugin->crypto_init);
+ plugin->crypto_init = NULL;
+
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (key_file);
+ GNUNET_free (cert_file);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TLS certificate loaded\n");
+ return res;
+}
+#endif
+
+
+/**
+ * Start the HTTP server
+ *
+ * @param plugin the plugin handle
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+static int
+server_start (struct HTTP_Server_Plugin *plugin)
+{
+ unsigned int timeout;
+ GNUNET_assert (NULL != plugin);
+
+#if BUILD_HTTPS
+ if (GNUNET_SYSERR == server_load_certificate (plugin))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Could not load or create server certificate! Loading plugin failed!\n");
+ return GNUNET_SYSERR;
+ }
+#endif
+
+
+#if MHD_VERSION >= 0x00090E00
+ timeout = HTTP_SERVER_NOT_VALIDATED_TIMEOUT.rel_value / 1000;
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "MHD can set timeout per connection! Default time out %u sec.\n",
+ timeout);
+#else
+ timeout = SERVER_SESSION_TIMEOUT.rel_value / 1000;
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
+ "MHD cannot set timeout per connection! Default time out %u sec.\n",
+ timeout);
+#endif
+ plugin->server_v4 = NULL;
+ if (plugin->use_ipv4 == GNUNET_YES)
+ {
+ plugin->server_v4 = MHD_start_daemon (
+#if VERBOSE_SERVER
+ MHD_USE_DEBUG |
+#endif
+#if BUILD_HTTPS
+ MHD_USE_SSL |
+#endif
+ MHD_NO_FLAG, plugin->port,
+ &server_accept_cb, plugin,
+ &server_access_cb, plugin,
+ MHD_OPTION_SOCK_ADDR,
+ (struct sockaddr_in *)
+ plugin->server_addr_v4,
+ MHD_OPTION_CONNECTION_LIMIT,
+ (unsigned int)
+ plugin->max_connections,
+#if BUILD_HTTPS
+ MHD_OPTION_HTTPS_PRIORITIES,
+ plugin->crypto_init,
+ MHD_OPTION_HTTPS_MEM_KEY,
+ plugin->key,
+ MHD_OPTION_HTTPS_MEM_CERT,
+ plugin->cert,
+#endif
+ MHD_OPTION_CONNECTION_TIMEOUT,
+ timeout,
+ MHD_OPTION_CONNECTION_MEMORY_LIMIT,
+ (size_t) (2 *
+ GNUNET_SERVER_MAX_MESSAGE_SIZE),
+ MHD_OPTION_NOTIFY_COMPLETED,
+ &server_disconnect_cb, plugin,
+ MHD_OPTION_EXTERNAL_LOGGER,
+ server_log, NULL, MHD_OPTION_END);
+ }
+ plugin->server_v6 = NULL;
+ if (plugin->use_ipv6 == GNUNET_YES)
+ {
+ plugin->server_v6 = MHD_start_daemon (
+#if VERBOSE_SERVER
+ MHD_USE_DEBUG |
+#endif
+#if BUILD_HTTPS
+ MHD_USE_SSL |
+#endif
+ MHD_USE_IPv6, plugin->port,
+ &server_accept_cb, plugin,
+ &server_access_cb, plugin,
+ MHD_OPTION_SOCK_ADDR,
+ (struct sockaddr_in6 *)
+ plugin->server_addr_v6,
+ MHD_OPTION_CONNECTION_LIMIT,
+ (unsigned int)
+ plugin->max_connections,
+#if BUILD_HTTPS
+ MHD_OPTION_HTTPS_PRIORITIES,
+ plugin->crypto_init,
+ MHD_OPTION_HTTPS_MEM_KEY,
+ plugin->key,
+ MHD_OPTION_HTTPS_MEM_CERT,
+ plugin->cert,
+#endif
+ MHD_OPTION_CONNECTION_TIMEOUT,
+ timeout,
+ MHD_OPTION_CONNECTION_MEMORY_LIMIT,
+ (size_t) (2 *
+ GNUNET_SERVER_MAX_MESSAGE_SIZE),
+ MHD_OPTION_NOTIFY_COMPLETED,
+ &server_disconnect_cb, plugin,
+ MHD_OPTION_EXTERNAL_LOGGER,
+ server_log, NULL, MHD_OPTION_END);
+
+ }
+
+ if ((plugin->use_ipv4 == GNUNET_YES) && (plugin->server_v4 == NULL))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Failed to start %s IPv4 server component on port %u\n",
+ plugin->name, plugin->port);
+ return GNUNET_SYSERR;
+ }
+ server_reschedule (plugin, plugin->server_v4, GNUNET_NO);
+
+ if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->server_v6 == NULL))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Failed to start %s IPv6 server component on port %u\n",
+ plugin->name, plugin->port);
+ return GNUNET_SYSERR;
+ }
+ server_reschedule (plugin, plugin->server_v6, GNUNET_NO);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "%s server component started on port %u\n", plugin->name,
+ plugin->port);
+ return GNUNET_OK;
+}
+
+
+void
+server_stop (struct HTTP_Server_Plugin *plugin)
+{
+ if (plugin->server_v4 != NULL)
+ {
+ MHD_stop_daemon (plugin->server_v4);
+ plugin->server_v4 = NULL;
+ }
+ if ( plugin->server_v6 != NULL)
+ {
+ MHD_stop_daemon (plugin->server_v6);
+ plugin->server_v6 = NULL;
+ }
+
+
+ if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
+ plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
+ if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
+ plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ p = NULL;
+
+#if BUILD_HTTPS
+ GNUNET_free_non_null (plugin->crypto_init);
+ GNUNET_free_non_null (plugin->cert);
+ GNUNET_free_non_null (plugin->key);
+#endif
+
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "%s server component stopped\n", plugin->name);
+}
+
+
+/**
+ * Add an address to the server's set of addresses and notify transport
+ *
+ * @param cls the plugin handle
+ * @param add_remove GNUNET_YES on add, GNUNET_NO on remove
+ * @param addr the address
+ * @param addrlen address length
+ */
+static void
+server_add_address (void *cls, int add_remove, const struct sockaddr *addr,
+ socklen_t addrlen)
+{
+ struct HTTP_Server_Plugin *plugin = cls;
+ struct HttpAddressWrapper *w = NULL;
+
+ w = GNUNET_malloc (sizeof (struct HttpAddressWrapper));
+ w->addr = http_common_address_from_socket (plugin->protocol, addr, addrlen);
+ if (NULL == w->addr)
+ {
+ GNUNET_free (w);
+ return;
+ }
+ w->addrlen = 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",
+ http_common_plugin_address_to_string(NULL, w->addr, w->addrlen));
+#if BUILD_HTTPS
+ plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, w->addrlen, "https_client");
+#else
+ plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, w->addrlen, "http_client");
+#endif
+}