/*
This file is part of GNUnet
- Copyright (C) 2002-2014 GNUnet e.V.
+ Copyright (C) 2002-2014, 2017 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
#include "gnunet_util_lib.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_plugin.h"
-#include "gnunet_nat_lib.h"
+#include "gnunet_nat_service.h"
#include "plugin_transport_http_common.h"
#include <microhttpd.h>
#include <regex.h>
*/
int connected;
+ /**
+ * Currently suspended
+ */
+ bool suspended;
+
};
/**
* Message stream tokenizer for incoming data
*/
- struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk;
+ struct GNUNET_MessageStreamTokenizer *msg_tk;
/**
* Client recv handle
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Session %p: Waking up PUT handle\n",
s);
+ GNUNET_assert (s->server_recv->suspended);
MHD_resume_connection (s->server_recv->mhd_conn);
+ s->server_recv->suspended = false;
}
GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
s->recv_wakeup_task = NULL;
if (NULL != s->server_recv)
+ {
+ GNUNET_assert (s->server_recv->suspended);
+ s->server_recv->suspended = false;
MHD_resume_connection (s->server_recv->mhd_conn);
+ }
}
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multipeermap_remove (plugin->sessions,
MHD_set_connection_option (s->server_send->mhd_conn,
MHD_CONNECTION_OPTION_TIMEOUT,
1 /* 0 = no timeout, so this is MIN */);
+ if (s->server_send->suspended)
+ {
+ s->server_send->suspended = false;
+ MHD_resume_connection (s->server_send->mhd_conn);
+ }
server_reschedule (plugin,
s->server_send->mhd_daemon,
GNUNET_YES);
}
if (NULL != s->msg_tk)
{
- GNUNET_SERVER_mst_destroy (s->msg_tk);
+ GNUNET_MST_destroy (s->msg_tk);
s->msg_tk = NULL;
}
GNUNET_HELLO_address_free (s->address);
GNUNET_free (stat_txt);
if (NULL != session->server_send)
+ {
+ if (session->server_send->suspended)
+ {
+ MHD_resume_connection (session->server_send->mhd_conn);
+ session->server_send->suspended = false;
+ }
server_reschedule (session->plugin,
session->server_send->mhd_daemon,
GNUNET_YES);
+ }
return bytes_sent;
}
s);
return MHD_CONTENT_READER_END_OF_STREAM;
}
+ else
+ {
+ MHD_suspend_connection (s->server_send->mhd_conn);
+ s->server_send->suspended = true;
+ return 0;
+ }
return bytes_read;
}
* Callback called by MessageStreamTokenizer when a message has arrived
*
* @param cls current session as closure
- * @param client client
* @param message the message to be forwarded to transport service
- * @return #GNUNET_OK
+ * @return #GNUNET_OK (all OK)
*/
static int
server_receive_mst_cb (void *cls,
- void *client,
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_ATS_Session *s = cls;
*upload_data_size);
if (s->msg_tk == NULL)
{
- s->msg_tk = GNUNET_SERVER_mst_create (&server_receive_mst_cb, s);
+ s->msg_tk = GNUNET_MST_create (&server_receive_mst_cb,
+ s);
}
- GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, *upload_data_size,
- GNUNET_NO, GNUNET_NO);
+ GNUNET_MST_from_buffer (s->msg_tk,
+ upload_data,
+ *upload_data_size,
+ GNUNET_NO, GNUNET_NO);
server_mhd_connection_timeout (plugin, s,
- GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us / 1000LL
- / 1000LL);
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us / 1000LL
+ / 1000LL);
(*upload_data_size) = 0;
}
else
GNUNET_YES));
GNUNET_assert(s->server_recv->mhd_conn == mhd_connection);
MHD_suspend_connection (s->server_recv->mhd_conn);
+ s->server_recv->suspended = true;
if (NULL == s->recv_wakeup_task)
s->recv_wakeup_task
= GNUNET_SCHEDULER_add_delayed (delay,
sc->session->server_recv = NULL;
if (NULL != sc->session->msg_tk)
{
- GNUNET_SERVER_mst_destroy (sc->session->msg_tk);
+ GNUNET_MST_destroy (sc->session->msg_tk);
sc->session->msg_tk = NULL;
}
}
}
+/**
+ * Callback from MHD when a connection starts/stops
+ *
+ * @param cls closure with the `struct HTTP_Server_Plugin *`
+ * @param connection connection handle
+ * @param socket_context socket-specific pointer
+ * @param toe reason for connection notification
+ * @see #MHD_OPTION_NOTIFY_CONNECTION
+ */
+static void
+server_connection_cb (void *cls,
+ struct MHD_Connection *connection,
+ void **socket_context,
+ enum MHD_ConnectionNotificationCode toe)
+{
+ struct HTTP_Server_Plugin *plugin = cls;
+ const union MHD_ConnectionInfo *info;
+
+ if (MHD_CONNECTION_NOTIFY_STARTED == toe)
+ return;
+
+ /* Reschedule to remove closed socket from our select set */
+ info = MHD_get_connection_info (connection,
+ MHD_CONNECTION_INFO_DAEMON);
+ GNUNET_assert (NULL != info);
+ server_reschedule (plugin,
+ info->daemon,
+ GNUNET_YES);
+}
+
+
/**
* Check if incoming connection is accepted.
*
timeout,
MHD_OPTION_CONNECTION_MEMORY_LIMIT,
(size_t) (2 *
- GNUNET_SERVER_MAX_MESSAGE_SIZE),
+ GNUNET_MAX_MESSAGE_SIZE),
MHD_OPTION_NOTIFY_COMPLETED,
&server_disconnect_cb, plugin,
+ MHD_OPTION_NOTIFY_CONNECTION,
+ &server_connection_cb, plugin,
MHD_OPTION_EXTERNAL_LOGGER,
&server_log, NULL,
MHD_OPTION_END);
* @param cls closure, the 'struct LocalAddrList'
* @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
* the previous (now invalid) one
+ * @param ac address class the address belongs to
* @param addr either the previous or the new public IP address
* @param addrlen actual lenght of the address
*/
static void
server_nat_port_map_callback (void *cls,
int add_remove,
+ enum GNUNET_NAT_AddressClass ac,
const struct sockaddr *addr,
socklen_t addrlen)
{
if ((NULL != plugin->server_addr_v4) &&
(0 != memcmp (&plugin->server_addr_v4->sin_addr,
- &s4->sin_addr, sizeof (struct in_addr))))
+ &s4->sin_addr,
+ sizeof (struct in_addr))))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Skipping address `%s' (not bindto address)\n",
return;
}
- plugin->nat =
- GNUNET_NAT_register (plugin->env->cfg,
- GNUNET_YES,
- plugin->port,
+ plugin->nat
+ = GNUNET_NAT_register (plugin->env->cfg,
+ "transport-http_server",
+ IPPROTO_TCP,
(unsigned int) res,
- (const struct sockaddr **) addrs, addrlens,
- &server_nat_port_map_callback, NULL,
- plugin, NULL);
+ (const struct sockaddr **) addrs,
+ addrlens,
+ &server_nat_port_map_callback,
+ NULL,
+ plugin);
while (res > 0)
{
res--;