#include "gnunet_disk_lib.h"
#include "gnunet_protocols.h"
-#define DEBUG_SERVER GNUNET_YES
+#define DEBUG_SERVER GNUNET_NO
/**
* List of arrays of message handlers.
*/
struct GNUNET_TIME_Relative idle_timeout;
- /**
- * maximum write buffer size for accepted sockets
- */
- size_t maxbuf;
-
/**
* Task scheduled to do the listening.
*/
sock =
GNUNET_CONNECTION_create_from_accept (tc->sched, server->access,
server->access_cls,
- server->listen_sockets[i],
- server->maxbuf);
+ server->listen_sockets[i]);
if (sock != NULL)
{
#if DEBUG_SERVER
}
+/**
+ * Create a new server.
+ *
+ * @param sched scheduler to use
+ * @param access function for access control
+ * @param access_cls closure for access
+ * @param lsocks NULL-terminated array of listen sockets
+ * @param idle_timeout after how long should we timeout idle connections?
+ * @param require_found if YES, connections sending messages of unknown type
+ * will be closed
+ * @return handle for the new server, NULL on error
+ * (typically, "port" already in use)
+ */
+struct GNUNET_SERVER_Handle *
+GNUNET_SERVER_create_with_sockets (struct GNUNET_SCHEDULER_Handle *sched,
+ GNUNET_CONNECTION_AccessCheck access, void *access_cls,
+ struct GNUNET_NETWORK_Handle **lsocks,
+ struct GNUNET_TIME_Relative
+ idle_timeout,
+ int require_found)
+{
+ struct GNUNET_SERVER_Handle *ret;
+ struct GNUNET_NETWORK_FDSet *r;
+ int i;
+
+ ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle));
+ ret->sched = sched;
+ ret->idle_timeout = idle_timeout;
+ ret->listen_sockets = lsocks;
+ ret->access = access;
+ ret->access_cls = access_cls;
+ ret->require_found = require_found;
+ if (lsocks != NULL)
+ {
+ r = GNUNET_NETWORK_fdset_create ();
+ i = 0;
+ while (NULL != ret->listen_sockets[i])
+ GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]);
+ ret->listen_task = GNUNET_SCHEDULER_add_select (sched,
+ GNUNET_SCHEDULER_PRIORITY_HIGH,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ r, NULL,
+ &process_listen_socket,
+ ret);
+ GNUNET_NETWORK_fdset_destroy (r);
+ }
+ return ret;
+}
+
+
/**
* Create a new server.
*
* @param access_cls closure for access
* @param serverAddr address to listen on (including port), NULL terminated array
* @param socklen length of serverAddr
- * @param maxbuf maximum write buffer size for accepted sockets
* @param idle_timeout after how long should we timeout idle connections?
* @param require_found if YES, connections sending messages of unknown type
* will be closed
void *access_cls,
struct sockaddr *const *serverAddr,
const socklen_t * socklen,
- size_t maxbuf,
struct GNUNET_TIME_Relative
idle_timeout, int require_found)
{
- struct GNUNET_SERVER_Handle *ret;
struct GNUNET_NETWORK_Handle **lsocks;
- struct GNUNET_NETWORK_FDSet *r;
unsigned int i;
unsigned int j;
{
lsocks = NULL;
}
- ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle));
- ret->sched = sched;
- ret->maxbuf = maxbuf;
- ret->idle_timeout = idle_timeout;
- ret->listen_sockets = lsocks;
- ret->access = access;
- ret->access_cls = access_cls;
- ret->require_found = require_found;
- if (lsocks != NULL)
- {
- r = GNUNET_NETWORK_fdset_create ();
- i = 0;
- while (NULL != ret->listen_sockets[i])
- GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]);
- ret->listen_task = GNUNET_SCHEDULER_add_select (sched,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL,
- r, NULL,
- &process_listen_socket,
- ret);
- GNUNET_NETWORK_fdset_destroy (r);
- }
- return ret;
+ return GNUNET_SERVER_create_with_sockets (sched,
+ access, access_cls,
+ lsocks,
+ idle_timeout,
+ require_found);
}
{
if ((mh->expected_size != 0) && (mh->expected_size != size))
{
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Expected %u bytes for message of type %u, got %u\n",
+ mh->expected_size,
+ mh->type,
+ size);
+#endif
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
"Server re-enters receive loop.\n");
#endif
GNUNET_CONNECTION_receive (client->connection,
- GNUNET_SERVER_MAX_MESSAGE_SIZE,
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
client->server->idle_timeout,
&process_incoming, client);
break;
#if DEBUG_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server processes additional messages instantly.\n");
#endif
- ret = GNUNET_SERVER_mst_receive (client->mst, NULL, 0, GNUNET_NO, GNUNET_YES);
+ ret = GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO, GNUNET_YES);
}
#if DEBUG_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
#endif
GNUNET_SERVER_client_keep (client);
client->last_activity = GNUNET_TIME_absolute_get ();
- ret = GNUNET_SERVER_mst_receive (client->mst, buf, available, GNUNET_NO, GNUNET_YES);
+ ret = GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO, GNUNET_YES);
process_mst (client, ret);
}
#endif
client->receive_pending = GNUNET_YES;
GNUNET_CONNECTION_receive (client->connection,
- GNUNET_SERVER_MAX_MESSAGE_SIZE,
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
client->server->idle_timeout, &process_incoming, client);
return;
}
client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client));
client->connection = connection;
- client->mst = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE,
- client,
- &client_message_tokenizer_callback,
+ client->mst = GNUNET_SERVER_mst_create (&client_message_tokenizer_callback,
server);
client->reference_count = 1;
client->server = server;
server->clients = client;
client->receive_pending = GNUNET_YES;
GNUNET_CONNECTION_receive (client->connection,
- GNUNET_SERVER_MAX_MESSAGE_SIZE,
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
server->idle_timeout, &process_incoming, client);
return client;
}