/*
This file is part of GNUnet
- Copyright (C) 2002-2014 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2002-2014 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* The session this server request belongs to
* Can be NULL, when session was disconnected and freed
*/
- struct Session *session;
+ struct GNUNET_ATS_Session *session;
/**
* The MHD connection
/**
* Session handle for connections.
*/
-struct Session
+struct GNUNET_ATS_Session
{
/**
/**
* MHD IPv4 task
*/
- struct GNUNET_SCHEDULER_Task * server_v4_task;
+ struct GNUNET_SCHEDULER_Task *server_v4_task;
/**
* MHD IPv6 task
*/
- struct GNUNET_SCHEDULER_Task * server_v6_task;
+ struct GNUNET_SCHEDULER_Task *server_v6_task;
/**
* Task calling transport service about external address
*/
- struct GNUNET_SCHEDULER_Task * notify_ext_task;
+ struct GNUNET_SCHEDULER_Task *notify_ext_task;
/**
* Notify transport only about external address
*/
static void
notify_session_monitor (struct HTTP_Server_Plugin *plugin,
- struct Session *session,
+ struct GNUNET_ATS_Session *session,
enum GNUNET_TRANSPORT_SessionState state)
{
struct GNUNET_TRANSPORT_SessionInfo info;
* Wake up an MHD connection which was suspended
*
* @param cls the session
- * @param tc task context
*/
static void
-server_wake_up (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+server_wake_up (void *cls)
{
- struct Session *s = cls;
+ struct GNUNET_ATS_Session *s = cls;
s->recv_wakeup_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Session %p: Waking up PUT handle\n",
s);
* @param s the session to delete
*/
static void
-server_delete_session (struct Session *s)
+server_delete_session (struct GNUNET_ATS_Session *s)
{
struct HTTP_Server_Plugin *plugin = s->plugin;
struct HTTP_Message *msg;
*/
static int
http_server_plugin_disconnect_session (void *cls,
- struct Session *s)
+ struct GNUNET_ATS_Session *s)
{
server_delete_session (s);
return GNUNET_OK;
* Session was idle, so disconnect it
*
* @param cls the session
- * @param tc task context
*/
static void
-server_session_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+server_session_timeout (void *cls)
{
- struct Session *s = cls;
+ struct GNUNET_ATS_Session *s = cls;
struct GNUNET_TIME_Relative left;
s->timeout_task = NULL;
* @param s the session
*/
static void
-server_reschedule_session_timeout (struct Session *s)
+server_reschedule_session_timeout (struct GNUNET_ATS_Session *s)
{
GNUNET_assert (NULL != s->timeout_task);
s->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
*/
static ssize_t
http_server_plugin_send (void *cls,
- struct Session *session,
+ struct GNUNET_ATS_Session *session,
const char *msgbuf,
size_t msgbuf_size,
unsigned int priority,
*
* @param cls the `struct HTTP_Server_Plugin *`
* @param peer for which this is a session
- * @param value the `struct Session` to clean up
+ * @param value the `struct GNUNET_ATS_Session` to clean up
* @return #GNUNET_OK (continue to iterate)
*/
static int
const struct GNUNET_PeerIdentity *peer,
void *value)
{
- struct Session *s = value;
+ struct GNUNET_ATS_Session *s = value;
struct ServerRequest *sc_send;
struct ServerRequest *sc_recv;
*
* @param cls the `struct HTTP_Server_Plugin *`
* @param peer for which this is a session
- * @param value the `struct Session` to clean up
+ * @param value the `struct GNUNET_ATS_Session` to clean up
* @return #GNUNET_OK (continue to iterate)
*/
static int
const struct GNUNET_PeerIdentity *peer,
void *value)
{
- struct Session *s = value;
+ struct GNUNET_ATS_Session *s = value;
server_delete_session (s);
return GNUNET_OK;
* @param address the address
* @return always NULL
*/
-static struct Session *
+static struct GNUNET_ATS_Session *
http_server_plugin_get_session (void *cls,
const struct GNUNET_HELLO_Address *address)
{
* 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)
+server_v4_run (void *cls)
{
struct HTTP_Server_Plugin *plugin = cls;
plugin->server_v4_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
plugin->server_v4_immediately = GNUNET_NO;
GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4));
server_reschedule (plugin, plugin->server_v4, GNUNET_NO);
* 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)
+server_v6_run (void *cls)
{
struct HTTP_Server_Plugin *plugin = cls;
plugin->server_v6_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
plugin->server_v6_immediately = GNUNET_NO;
GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6));
server_reschedule (plugin, plugin->server_v6, GNUNET_NO);
static void
http_server_plugin_update_session_timeout (void *cls,
const struct GNUNET_PeerIdentity *peer,
- struct Session *session)
+ struct GNUNET_ATS_Session *session)
{
server_reschedule_session_timeout (session);
}
*/
static void
server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin,
- struct Session *s,
+ struct GNUNET_ATS_Session *s,
unsigned int to)
{
/* Setting timeouts for other connections */
/**
* Closure for #session_tag_it().
*/
-struct SessionTagContext
+struct GNUNET_ATS_SessionTagContext
{
/**
* Set to session matching the tag.
*/
- struct Session *res;
+ struct GNUNET_ATS_Session *res;
/**
* Tag we are looking for.
/**
* Find a session with a matching tag.
*
- * @param cls the `struct SessionTagContext *`
+ * @param cls the `struct GNUNET_ATS_SessionTagContext *`
* @param key peer identity (unused)
- * @param value the `struct Session *`
+ * @param value the `struct GNUNET_ATS_Session *`
* @return #GNUNET_NO if we found the session, #GNUNET_OK if not
*/
static int
const struct GNUNET_PeerIdentity *key,
void *value)
{
- struct SessionTagContext *stc = cls;
- struct Session *s = value;
+ struct GNUNET_ATS_SessionTagContext *stc = cls;
+ struct GNUNET_ATS_Session *s = value;
if (s->tag == stc->tag)
{
const char *url,
const char *method)
{
- struct Session *s = NULL;
+ struct GNUNET_ATS_Session *s = NULL;
struct ServerRequest *sc = NULL;
const union MHD_ConnectionInfo *conn_info;
struct HttpAddress *addr;
struct GNUNET_PeerIdentity target;
size_t addr_len;
- struct SessionTagContext stc;
+ struct GNUNET_ATS_SessionTagContext stc;
uint32_t options;
int direction = GNUNET_SYSERR;
unsigned int to;
method,
url);
stc.tag = 0;
+ options = 0; /* make gcc happy */
if (GNUNET_SYSERR ==
server_parse_url (plugin, url, &target, &stc.tag, &options))
{
/* external host name */
return NULL;
}
- s = GNUNET_new (struct Session);
+ s = GNUNET_new (struct GNUNET_ATS_Session);
s->target = target;
s->plugin = plugin;
s->scope = scope;
size_t max)
{
struct ServerRequest *sc = cls;
- struct Session *s = sc->session;
+ struct GNUNET_ATS_Session *s = sc->session;
ssize_t bytes_read = 0;
struct HTTP_Message *msg;
char *stat_txt;
void *client,
const struct GNUNET_MessageHeader *message)
{
- struct Session *s = cls;
+ struct GNUNET_ATS_Session *s = cls;
struct HTTP_Server_Plugin *plugin = s->plugin;
struct GNUNET_TIME_Relative delay;
char *stat_txt;
{
struct HTTP_Server_Plugin *plugin = cls;
struct ServerRequest *sc = *httpSessionCache;
- struct Session *s;
+ struct GNUNET_ATS_Session *s;
struct MHD_Response *response;
int res = MHD_YES;
else
{
/* existing session already has matching connection, refuse */
- response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),
- HTTP_ERROR_RESPONSE,
- MHD_NO,
- MHD_NO);
+ response = MHD_create_response_from_buffer (strlen (HTTP_ERROR_RESPONSE),
+ HTTP_ERROR_RESPONSE,
+ MHD_RESPMEM_PERSISTENT);
MHD_add_response_header (response,
MHD_HTTP_HEADER_CONTENT_TYPE,
"text/html");
{
/* Session was already disconnected;
sent HTTP/1.1: 200 OK as response */
- response = MHD_create_response_from_data (strlen ("Thank you!"),
- "Thank you!", MHD_NO, MHD_NO);
+ response = MHD_create_response_from_buffer (strlen ("Thank you!"),
+ "Thank you!",
+ MHD_RESPMEM_PERSISTENT);
add_cors_headers(response);
MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
MHD_destroy_response (response);
s->address->address_length));
sc->connected = GNUNET_NO;
/* Sent HTTP/1.1: 200 OK as PUT Response\ */
- response = MHD_create_response_from_data (strlen ("Thank you!"),
- "Thank you!", MHD_NO, MHD_NO);
+ response = MHD_create_response_from_buffer (strlen ("Thank you!"),
+ "Thank you!",
+ MHD_RESPMEM_PERSISTENT);
add_cors_headers(response);
MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
MHD_destroy_response (response);
GNUNET_assert(s->server_recv->mhd_conn == mhd_connection);
MHD_suspend_connection (s->server_recv->mhd_conn);
if (NULL == s->recv_wakeup_task)
- s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delay,
- &server_wake_up, s);
+ s->recv_wakeup_task
+ = GNUNET_SCHEDULER_add_delayed (delay,
+ &server_wake_up,
+ s);
}
return MHD_YES;
}
plugin->port,
(unsigned int) res,
(const struct sockaddr **) addrs, addrlens,
- &server_nat_port_map_callback, NULL, plugin);
+ &server_nat_port_map_callback, NULL, plugin, NULL);
while (res > 0)
{
res--;
* Notify server about our external hostname
*
* @param cls plugin
- * @param tc task context (unused)
*/
static void
-server_notify_external_hostname (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+server_notify_external_hostname (void *cls)
{
struct HTTP_Server_Plugin *plugin = cls;
struct HttpAddress *ext_addr;
char *url;
plugin->notify_ext_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
- GNUNET_asprintf(&url,
- "%s://%s",
- plugin->protocol,
- plugin->external_hostname);
-
+ GNUNET_asprintf (&url,
+ "%s://%s",
+ plugin->protocol,
+ plugin->external_hostname);
urlen = strlen (url) + 1;
ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen);
ext_addr->options = htonl (plugin->options);
"Enabling SSL verification for external hostname address `%s'\n",
plugin->external_hostname);
plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
- "https_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE );
- plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr);
+ "https_client",
+ ext_addr,
+ ext_addr_len,
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
+ plugin->env->notify_address (plugin->env->cls,
+ GNUNET_YES,
+ plugin->ext_addr);
GNUNET_free (ext_addr);
#else
plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
- "http_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE );
- plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr);
+ "http_client",
+ ext_addr,
+ ext_addr_len,
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
+ plugin->env->notify_address (plugin->env->cls,
+ GNUNET_YES,
+ plugin->ext_addr);
GNUNET_free (ext_addr);
#endif
}
/**
* Function obtain the network type for a session
*
- * @param cls closure ('struct HTTP_Server_Plugin*')
+ * @param cls closure (`struct HTTP_Server_Plugin *`)
* @param session the session
* @return the network type in HBO or #GNUNET_SYSERR
*/
static enum GNUNET_ATS_Network_Type
http_server_plugin_get_network (void *cls,
- struct Session *session)
+ struct GNUNET_ATS_Session *session)
{
return session->scope;
}
+/**
+ * Function obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_ATS_Network_Type
+http_server_plugin_get_network_for_address (void *cls,
+ const struct GNUNET_HELLO_Address *address)
+{
+ struct HTTP_Server_Plugin *plugin = cls;
+
+ return http_common_get_network_for_address (plugin->env,
+ address);
+}
+
+
/**
* Function that will be called whenever the transport service wants to
* notify the plugin that the inbound quota changed and that the plugin
static void
http_server_plugin_update_inbound_delay (void *cls,
const struct GNUNET_PeerIdentity *peer,
- struct Session *session,
+ struct GNUNET_ATS_Session *session,
struct GNUNET_TIME_Relative delay)
{
session->next_receive = GNUNET_TIME_relative_to_absolute (delay);
*
* @param cls the `struct Plugin` with the monitor callback (`sic`)
* @param peer peer we send information about
- * @param value our `struct Session` to send information about
+ * @param value our `struct GNUNET_ATS_Session` to send information about
* @return #GNUNET_OK (continue to iterate)
*/
static int
void *value)
{
struct HTTP_Server_Plugin *plugin = cls;
- struct Session *session = value;
+ struct GNUNET_ATS_Session *session = value;
notify_session_monitor (plugin,
session,
api->string_to_address = &http_common_plugin_string_to_address;
api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
api->get_network = &http_server_plugin_get_network;
+ api->get_network_for_address = &http_server_plugin_get_network_for_address;
api->update_session_timeout = &http_server_plugin_update_session_timeout;
api->update_inbound_delay = &http_server_plugin_update_inbound_delay;
api->setup_monitor = &http_server_plugin_setup_monitor;