[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r8666 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r8666 - gnunet/src/util |
Date: |
Sat, 11 Jul 2009 05:40:21 -0600 |
Author: grothoff
Date: 2009-07-11 05:40:21 -0600 (Sat, 11 Jul 2009)
New Revision: 8666
Modified:
gnunet/src/util/network.c
gnunet/src/util/server.c
gnunet/src/util/test_client.c
gnunet/src/util/test_server.c
gnunet/src/util/test_server_with_client.c
Log:
some documentation and bugfix in testcase
Modified: gnunet/src/util/network.c
===================================================================
--- gnunet/src/util/network.c 2009-07-10 21:20:25 UTC (rev 8665)
+++ gnunet/src/util/network.c 2009-07-11 11:40:21 UTC (rev 8666)
@@ -40,7 +40,7 @@
#include "gnunet_network_lib.h"
#include "gnunet_scheduler_lib.h"
-#define DEBUG_NETWORK GNUNET_NO
+#define DEBUG_NETWORK GNUNET_YES
/**
* List of address families to give as hints to
Modified: gnunet/src/util/server.c
===================================================================
--- gnunet/src/util/server.c 2009-07-10 21:20:25 UTC (rev 8665)
+++ gnunet/src/util/server.c 2009-07-11 11:40:21 UTC (rev 8666)
@@ -34,6 +34,8 @@
#include "gnunet_server_lib.h"
#include "gnunet_time_lib.h"
+#define DEBUG_SERVER GNUNET_YES
+
/**
* List of arrays of message handlers.
*/
@@ -274,6 +276,10 @@
struct HandlerList *hpos;
struct NotifyList *npos;
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Server shutting down.\n");
+#endif
GNUNET_assert (server->listen_socket == -1);
GNUNET_break (0 == CLOSE (server->shutpipe[0]));
GNUNET_break (0 == CLOSE (server->shutpipe[1]));
@@ -330,6 +336,10 @@
server->maxbuf);
if (sock != NULL)
{
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Server accepted incoming connection.\n");
+#endif
client = GNUNET_SERVER_connect_socket (server, sock);
/* decrement reference count, we don't keep "client" alive */
GNUNET_SERVER_client_drop (client);
@@ -405,6 +415,11 @@
GNUNET_break (0 == CLOSE (fd));
return -1;
}
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Server starts to listen on port %u.\n",
+ port);
+#endif
return fd;
}
@@ -551,6 +566,12 @@
type = ntohs (message->type);
size = ntohs (message->size);
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Server schedules transmission of %u-byte message of type %u to
client.\n",
+ size,
+ type);
+#endif
pos = server->handlers;
found = GNUNET_NO;
while (pos != NULL)
@@ -633,6 +654,13 @@
}
+/**
+ * Go over the contents of the client buffer; as long as full messages
+ * are available, pass them on for processing. Update the buffer
+ * accordingly. Handles fatal errors by shutting down the connection.
+ *
+ * @param client identifies which client receive buffer to process
+ */
static void
process_client_buffer (struct GNUNET_SERVER_Client *client)
{
@@ -642,13 +670,33 @@
client->in_process_client_buffer = GNUNET_YES;
server = client->server;
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Private buffer contains %u bytes; client is %s and we are %s\n",
+ client->receive_pos,
+ client->suspended ? "suspended" : "up",
+ client->shutdown_now ? "in shutdown" : "running");
+#endif
while ((client->receive_pos >= sizeof (struct GNUNET_MessageHeader)) &&
(0 == client->suspended) && (GNUNET_YES != client->shutdown_now))
{
hdr = (const struct GNUNET_MessageHeader *) &client->incoming_buffer;
msize = ntohs (hdr->size);
if (msize > client->receive_pos)
- break;
+ {
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Total message size is %u, we only have %u bytes; need
more data\n",
+ msize,
+ client->receive_pos);
+#endif
+ break;
+ }
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Passing %u bytes to callback for processing\n",
+ msize);
+#endif
if ((msize < sizeof (struct GNUNET_MessageHeader)) ||
(GNUNET_OK != GNUNET_SERVER_inject (server, client, hdr)))
{
@@ -671,12 +719,21 @@
/**
* We are receiving an incoming message. Process it.
+ *
+ * @param cls our closure (handle for the client)
+ * @param buf buffer with data received from network
+ * @param available number of bytes available in buf
+ * @param addr address of the sender
+ * @param addrlen length of addr
+ * @param errCode code indicating errors receiving, 0 for success
*/
static void
process_incoming (void *cls,
const void *buf,
size_t available,
- const struct sockaddr *addr, socklen_t addrlen, int errCode)
+ const struct sockaddr *addr,
+ socklen_t addrlen,
+ int errCode)
{
struct GNUNET_SERVER_Client *client = cls;
struct GNUNET_SERVER_Handle *server = client->server;
@@ -695,6 +752,12 @@
shutdown_incoming_processing (client);
return;
}
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Server receives %u bytes from `%s'.\n",
+ available,
+ GNUNET_a2s(addr, addrlen));
+#endif
GNUNET_SERVER_client_keep (client);
client->last_activity = GNUNET_TIME_absolute_get ();
/* process data (if available) */
@@ -703,6 +766,11 @@
maxcpy = available;
if (maxcpy > sizeof (client->incoming_buffer) - client->receive_pos)
maxcpy = sizeof (client->incoming_buffer) - client->receive_pos;
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Can copy %u bytes to private buffer\n",
+ maxcpy);
+#endif
memcpy (&client->incoming_buffer[client->receive_pos], cbuf, maxcpy);
client->receive_pos += maxcpy;
cbuf += maxcpy;
@@ -711,6 +779,13 @@
{
if (available > 0)
{
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client has suspended processing; copying %u bytes to
side buffer to be used later.\n",
+ available);
+#endif
+ GNUNET_assert (client->side_buf_size == 0);
+ GNUNET_assert (client->side_buf == NULL);
client->side_buf_size = available;
client->side_buf = GNUNET_malloc (available);
memcpy (client->side_buf, cbuf, available);
@@ -718,6 +793,10 @@
}
break; /* do not run next client iteration! */
}
+#if DEBUG_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Now processing messages in private buffer\n");
+#endif
process_client_buffer (client);
}
GNUNET_assert (available == 0);
@@ -736,6 +815,9 @@
}
+/**
+ * FIXME: document.
+ */
static void
restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
@@ -768,6 +850,17 @@
&process_incoming, client);
}
+
+/**
+ * Create a request for receiving data from a socket.
+ *
+ * @param cls identifies the socket to receive from
+ * @param max how much data to read at most
+ * @param timeout when should this operation time out
+ * @param receiver function to call for processing
+ * @param receiver_cls closure for receiver
+ * @return task identifier that can be used to cancel the operation
+ */
static GNUNET_SCHEDULER_TaskIdentifier
sock_receive (void *cls,
size_t max,
@@ -777,6 +870,13 @@
return GNUNET_NETWORK_receive (cls, max, timeout, receiver, receiver_cls);
}
+
+/**
+ * Wrapper to cancel receiving from a socket.
+ *
+ * @param cls handle to the GNUNET_NETWORK_SocketHandle to cancel
+ * @param tc task ID that was returned by GNUNET_NETWORK_receive
+ */
static void
sock_receive_cancel (void *cls, GNUNET_SCHEDULER_TaskIdentifier ti)
{
@@ -784,6 +884,9 @@
}
+/**
+ * FIXME: document.
+ */
static void *
sock_notify_transmit_ready (void *cls,
size_t size,
@@ -796,6 +899,9 @@
}
+/**
+ * FIXME: document.
+ */
static void
sock_notify_transmit_ready_cancel (void *cls, void *h)
{
Modified: gnunet/src/util/test_client.c
===================================================================
--- gnunet/src/util/test_client.c 2009-07-10 21:20:25 UTC (rev 8665)
+++ gnunet/src/util/test_client.c 2009-07-11 11:40:21 UTC (rev 8666)
@@ -61,6 +61,8 @@
GNUNET_SERVER_receive_done (ctx->client, GNUNET_OK);
GNUNET_free (cpy);
GNUNET_free (ctx);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Message bounced back to client\n");
return sizeof (struct GNUNET_MessageHeader);
}
@@ -76,6 +78,8 @@
struct CopyContext *cc;
struct GNUNET_MessageHeader *cpy;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Receiving message from client, bouncing back\n");
GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
ntohs (message->size));
cc = GNUNET_malloc (sizeof (struct CopyContext));
@@ -104,9 +108,11 @@
struct GNUNET_MessageHeader msg;
GNUNET_assert (got != NULL); /* timeout */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Receiving bounce, checking content\n");
msg.type = htons (MY_TYPE);
- msg.size = htons (sizeof (msg));
- GNUNET_assert (0 == memcmp (got, &msg, sizeof (msg)));
+ msg.size = htons (sizeof (struct GNUNET_MessageHeader));
+ GNUNET_assert (0 == memcmp (got, &msg, sizeof (struct
GNUNET_MessageHeader)));
GNUNET_CLIENT_disconnect (client);
client = NULL;
GNUNET_SERVER_destroy (server);
@@ -121,7 +127,9 @@
struct GNUNET_MessageHeader *msg = buf;
GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
msg->type = htons (MY_TYPE);
- msg->size = htons (sizeof (msg));
+ msg->size = htons (sizeof (struct GNUNET_MessageHeader));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating message for transmission\n");
return sizeof (struct GNUNET_MessageHeader);
}
@@ -185,7 +193,13 @@
{
int ret = 0;
- GNUNET_log_setup ("test_client", "WARNING", NULL);
+ GNUNET_log_setup ("test_client",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
ret += check ();
return ret;
Modified: gnunet/src/util/test_server.c
===================================================================
--- gnunet/src/util/test_server.c 2009-07-10 21:20:25 UTC (rev 8665)
+++ gnunet/src/util/test_server.c 2009-07-11 11:40:21 UTC (rev 8666)
@@ -83,8 +83,8 @@
case 1:
*ok = 2; /* report success */
msg.type = htons (MY_TYPE2);
- msg.size = htons (sizeof (msg));
- receiver (receiver_cls, &msg, sizeof (msg), NULL, 0, 0);
+ msg.size = htons (sizeof (struct GNUNET_MessageHeader));
+ receiver (receiver_cls, &msg, sizeof (struct GNUNET_MessageHeader),
NULL, 0, 0);
break;
case 3:
/* called after first receive instantly
@@ -130,7 +130,7 @@
GNUNET_assert (size == sizeof (struct GNUNET_MessageHeader));
notify (notify_cls, size, buf);
msg.type = htons (MY_TYPE);
- msg.size = htons (sizeof (msg));
+ msg.size = htons (sizeof (struct GNUNET_MessageHeader));
GNUNET_assert (0 == memcmp (&msg, buf, size));
*ok = 5; /* report success */
return &non_null_addr;
@@ -250,9 +250,9 @@
handlers[1].callback_cls = cls;
GNUNET_SERVER_add_handlers (server, handlers);
msg.type = htons (MY_TYPE);
- msg.size = htons (sizeof (msg));
+ msg.size = htons (sizeof (struct GNUNET_MessageHeader));
GNUNET_SERVER_inject (server, NULL, &msg);
- memset (&msg, 0, sizeof (msg));
+ memset (&msg, 0, sizeof (struct GNUNET_MessageHeader));
}
Modified: gnunet/src/util/test_server_with_client.c
===================================================================
--- gnunet/src/util/test_server_with_client.c 2009-07-10 21:20:25 UTC (rev
8665)
+++ gnunet/src/util/test_server_with_client.c 2009-07-11 11:40:21 UTC (rev
8666)
@@ -30,7 +30,7 @@
#include "gnunet_server_lib.h"
#include "gnunet_time_lib.h"
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
#define PORT 22335
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r8666 - gnunet/src/util,
gnunet <=