refine API to make it usable for server itself
authorChristian Grothoff <christian@grothoff.org>
Tue, 22 Jun 2010 07:22:50 +0000 (07:22 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 22 Jun 2010 07:22:50 +0000 (07:22 +0000)
TODO
src/include/gnunet_server_lib.h
src/util/server_mst.c

diff --git a/TODO b/TODO
index 07fbc23cc3320eac481b7ef7bc02fb1ad442d375..da54c87aa4a765753ace87d2d65ebcbf13d023bf 100644 (file)
--- a/TODO
+++ b/TODO
@@ -5,11 +5,6 @@
 * TRANSPORT:
   - HTTP backend [MW]
 * DV: [Nate]
-  - write DV API (need to move declarations from dv_api.c to gnunet_dv_service.h!)
-  - implement DV service 
-  - implement DV library (looks done)
-  - implement DV transport plugin
-  - implement testcases 
   - implement performance tests (needs tbench)
 * UTIL:
   - only connect() sockets that are ready (select()) [Nils]
index 7af133b89fbeea15dad1c5d4086a15a7cac089c6..070d254adf71270046078bd66bd8a96a4b0a944d 100644 (file)
@@ -657,14 +657,36 @@ GNUNET_SERVER_mst_create (size_t maxbuf,
  * @param size number of bytes in buf
  * @param purge should any excess bytes in the buffer be discarded 
  *       (i.e. for packet-based services like UDP)
- * @return GNUNET_NO if the data stream is corrupt 
- *         GNUNET_SYSERR if the data stream is corrupt beyond repair
+ * @param one_shot only call callback once, keep rest of message in buffer
+ * @return GNUNET_OK if we are done processing (need more data)
+ *         GNUNET_NO if one_shot was set and we have another message ready
+ *         GNUNET_SYSERR if the data stream is corrupt
  */
 int
 GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
                           const char *buf,
                           size_t size,
-                          int purge);
+                          int purge,
+                          int one_shot);
+
+
+/**
+ * Read incoming data into the receive buffer and call the
+ * callback for all complete messages.
+ *
+ * @param mst tokenizer to use
+ * @param sock socket to read from (must be ready according to select)
+ * @param purge should any excess bytes in the buffer be discarded 
+ *       (i.e. for packet-based services like UDP)
+ * @return GNUNET_NO if the data stream is corrupt 
+ *         GNUNET_SYSERR if the data stream is corrupt beyond repair
+ */
+int
+GNUNET_SERVER_mst_read (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
+                       const char *buf,
+                       size_t size,
+                       int purge);
+
 
 /**
  * Destroys a tokenizer.
index 53cae7035577c79d95db697b143de5c3ea61f44f..8df4e4b7d3af2faff255e8c4ec15716675bb899c 100644 (file)
@@ -92,14 +92,17 @@ GNUNET_SERVER_mst_create (size_t maxbuf,
  * @param size number of bytes in buf
  * @param purge should any excess bytes in the buffer be discarded 
  *       (i.e. for packet-based services like UDP)
- * @return GNUNET_NO if the data stream is corrupt 
- *         GNUNET_SYSERR if the data stream is corrupt beyond repair
+ * @param one_shot only call callback once, keep rest of message in buffer
+ * @return GNUNET_OK if we are done processing (need more data)
+ *         GNUNET_NO if one_shot was set and we have another message ready
+ *         GNUNET_SYSERR if the data stream is corrupt
  */
 int
 GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
                           const char *buf,
                           size_t size,
-                          int purge)
+                          int purge,
+                          int one_shot)
 {
   const struct GNUNET_MessageHeader *hdr;
   size_t delta;
@@ -107,7 +110,9 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
   char *ibuf;
   int need_align;
   unsigned long offset;
+  int ret;
 
+  ret = GNUNET_OK;
   ibuf = (char*) &mst->hdr;
   if (mst->off > 0)
     {
@@ -133,8 +138,6 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
       if (want < sizeof (struct GNUNET_MessageHeader))
        {
          GNUNET_break_op (0);
-         if (purge)
-           return GNUNET_NO;
          return GNUNET_SYSERR;
        }
       if (want < mst->off)
@@ -154,6 +157,13 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
            mst->off = 0;    
          return GNUNET_OK;
        }
+      if (one_shot == GNUNET_SYSERR)
+       {
+         ret = GNUNET_NO;
+         goto copy;
+       }
+      if (one_shot == GNUNET_YES)
+       one_shot = GNUNET_SYSERR;
       mst->cb (mst->cb_cls, mst->client_identity, &mst->hdr);
       mst->off = 0;
     }
@@ -174,6 +184,13 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
          want = ntohs (hdr->size);
          if (size < want)
            break; /* or not, buffer incomplete... */
+         if (one_shot == GNUNET_SYSERR)
+           {
+             ret = GNUNET_NO;
+             goto copy;
+           }
+         if (one_shot == GNUNET_YES)
+           one_shot = GNUNET_SYSERR;
          mst->cb (mst->cb_cls, mst->client_identity, hdr);
          buf += want;
          size -= want;
@@ -184,15 +201,16 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
          goto do_align;
        }
     }
+ copy:
   if ( (size > 0) && (! purge) )
     {
-      memcpy (&mst->hdr, buf, size);
-      mst->off = size;
+      memcpy (&ibuf[mst->off], buf, size);
+      mst->off += size;
       size = 0;
     }
   if (purge)
     mst->off = 0;    
-  return GNUNET_OK;
+  return ret;
 }