gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18479 - in gnunet/src: include transport util


From: gnunet
Subject: [GNUnet-SVN] r18479 - in gnunet/src: include transport util
Date: Tue, 6 Dec 2011 21:07:08 +0100

Author: grothoff
Date: 2011-12-06 21:07:08 +0100 (Tue, 06 Dec 2011)
New Revision: 18479

Modified:
   gnunet/src/include/gnunet_common.h
   gnunet/src/include/gnunet_network_lib.h
   gnunet/src/include/gnunet_server_lib.h
   gnunet/src/transport/Makefile.am
   gnunet/src/transport/gnunet-transport-wlan-helper.c
   gnunet/src/util/pseudonym.c
Log:
eliminating last dependency on util code from wlan helper by inlining

Modified: gnunet/src/include/gnunet_common.h
===================================================================
--- gnunet/src/include/gnunet_common.h  2011-12-06 19:56:51 UTC (rev 18478)
+++ gnunet/src/include/gnunet_common.h  2011-12-06 20:07:08 UTC (rev 18479)
@@ -52,12 +52,6 @@
 #define GNUNET_UTIL_VERSION 0x00090000
 
 /**
- * Name used for "services" that are actually command-line
- * programs invoked by the end user.
- */
-#define GNUNET_CLIENT_SERVICE_NAME "client"
-
-/**
  * Named constants for return values.  The following
  * invariants hold: "GNUNET_NO == 0" (to allow "if (GNUNET_NO)")
  * "GNUNET_OK != GNUNET_SYSERR", "GNUNET_OK != GNUNET_NO", "GNUNET_NO != 
GNUNET_SYSERR"

Modified: gnunet/src/include/gnunet_network_lib.h
===================================================================
--- gnunet/src/include/gnunet_network_lib.h     2011-12-06 19:56:51 UTC (rev 
18478)
+++ gnunet/src/include/gnunet_network_lib.h     2011-12-06 20:07:08 UTC (rev 
18479)
@@ -89,7 +89,6 @@
                               socklen_t * address_len);
 
 
-#ifdef MINGW
 /**
  * Box a native socket (and check that it is a socket).
  *
@@ -98,7 +97,6 @@
  */
 struct GNUNET_NETWORK_Handle *
 GNUNET_NETWORK_socket_box_native (SOCKTYPE fd);
-#endif
 
 
 /**

Modified: gnunet/src/include/gnunet_server_lib.h
===================================================================
--- gnunet/src/include/gnunet_server_lib.h      2011-12-06 19:56:51 UTC (rev 
18478)
+++ gnunet/src/include/gnunet_server_lib.h      2011-12-06 20:07:08 UTC (rev 
18479)
@@ -46,7 +46,7 @@
 #define GNUNET_SERVER_MAX_MESSAGE_SIZE 65536
 
 /**
- * Largest supported message.
+ * Smallest supported message.
  */
 #define GNUNET_SERVER_MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader)
 

Modified: gnunet/src/transport/Makefile.am
===================================================================
--- gnunet/src/transport/Makefile.am    2011-12-06 19:56:51 UTC (rev 18478)
+++ gnunet/src/transport/Makefile.am    2011-12-06 20:07:08 UTC (rev 18479)
@@ -109,8 +109,6 @@
 
 gnunet_transport_wlan_helper_SOURCES = \
  gnunet-transport-wlan-helper.c
-gnunet_transport_wlan_helper_LDADD = \
-  $(top_builddir)/src/util/libgnunetutil.la 
 
 gnunet_transport_wlan_helper_dummy_SOURCES = \
  gnunet-transport-wlan-helper-dummy.c

Modified: gnunet/src/transport/gnunet-transport-wlan-helper.c
===================================================================
--- gnunet/src/transport/gnunet-transport-wlan-helper.c 2011-12-06 19:56:51 UTC 
(rev 18478)
+++ gnunet/src/transport/gnunet-transport-wlan-helper.c 2011-12-06 20:07:08 UTC 
(rev 18479)
@@ -100,7 +100,6 @@
 #include <stdint.h>
 
 #include "gnunet_protocols.h"
-#include "gnunet_server_lib.h"
 #include "plugin_transport_wlan.h"
 
 #define ARPHRD_IEEE80211        801
@@ -446,7 +445,306 @@
 };
 
 
+
+/* specialized version of server_mst.c begins here */
+
+#define ALIGN_FACTOR 8
+
 /**
+ * Smallest supported message.
+ */
+#define GNUNET_SERVER_MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader)
+
+
+/**
+ * Functions with this signature are called whenever a
+ * complete message is received by the tokenizer.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param message the actual message
+ */
+typedef void (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, void 
*client,
+                                                        const struct
+                                                        GNUNET_MessageHeader *
+                                                        message);
+
+/**
+ * Handle to a message stream tokenizer.
+ */
+struct GNUNET_SERVER_MessageStreamTokenizer
+{
+
+  /**
+   * Function to call on completed messages.
+   */
+  GNUNET_SERVER_MessageTokenizerCallback cb;
+
+  /**
+   * Closure for cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Size of the buffer (starting at 'hdr').
+   */
+  size_t curr_buf;
+
+  /**
+   * How many bytes in buffer have we already processed?
+   */
+  size_t off;
+
+  /**
+   * How many bytes in buffer are valid right now?
+   */
+  size_t pos;
+
+  /**
+   * Beginning of the buffer.  Typed like this to force alignment.
+   */
+  struct GNUNET_MessageHeader *hdr;
+
+};
+
+
+
+/**
+ * Create a message stream tokenizer.
+ *
+ * @param cb function to call on completed messages
+ * @param cb_cls closure for cb
+ * @return handle to tokenizer
+ */
+struct GNUNET_SERVER_MessageStreamTokenizer *
+GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
+                          void *cb_cls)
+{
+  struct GNUNET_SERVER_MessageStreamTokenizer *ret;
+
+  ret = malloc (sizeof (struct GNUNET_SERVER_MessageStreamTokenizer));
+  if (NULL == ret)
+    exit (1);
+  ret->hdr = malloc (GNUNET_SERVER_MIN_BUFFER_SIZE);
+  if (NULL == ret->hdr)
+    exit (2);
+  ret->curr_buf = GNUNET_SERVER_MIN_BUFFER_SIZE;
+  ret->cb = cb;
+  ret->cb_cls = cb_cls;
+  return ret;
+}
+
+
+#define GNUNET_MIN(a,b) (((a) < (b)) ? (a) : (b))
+
+/**
+ * Named constants for return values.  The following
+ * invariants hold: "GNUNET_NO == 0" (to allow "if (GNUNET_NO)")
+ * "GNUNET_OK != GNUNET_SYSERR", "GNUNET_OK != GNUNET_NO", "GNUNET_NO != 
GNUNET_SYSERR"
+ * and finally "GNUNET_YES != GNUNET_NO".
+ */
+#define GNUNET_OK      1
+#define GNUNET_SYSERR -1
+#define GNUNET_YES     1
+#define GNUNET_NO      0
+
+
+/**
+ * Add incoming data to the receive buffer and call the
+ * callback for all complete messages.
+ *
+ * @param mst tokenizer to use
+ * @param client_identity ID of client for which this is a buffer
+ * @param buf input data to add
+ * @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)
+ * @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,
+                           void *client_identity, const char *buf, size_t size,
+                           int purge, int one_shot)
+{
+  const struct GNUNET_MessageHeader *hdr;
+  size_t delta;
+  uint16_t want;
+  char *ibuf;
+  int need_align;
+  unsigned long offset;
+  int ret;
+
+  ret = GNUNET_OK;
+  ibuf = (char *) mst->hdr;
+  while (mst->pos > 0)
+  {
+do_align:
+    if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) ||
+        (0 != (mst->off % ALIGN_FACTOR)))
+    {
+      /* need to align or need more space */
+      mst->pos -= mst->off;
+      memmove (ibuf, &ibuf[mst->off], mst->pos);
+      mst->off = 0;
+    }
+    if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
+    {
+      delta =
+          GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) -
+                      (mst->pos - mst->off), size);
+      memcpy (&ibuf[mst->pos], buf, delta);
+      mst->pos += delta;
+      buf += delta;
+      size -= delta;
+    }
+    if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
+    {
+      if (purge)
+      {
+        mst->off = 0;
+        mst->pos = 0;
+      }
+      return GNUNET_OK;
+    }
+    hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
+    want = ntohs (hdr->size);
+    if (want < sizeof (struct GNUNET_MessageHeader))
+    {
+      // GNUNET_break_op (0);
+      return GNUNET_SYSERR;
+    }
+    if (mst->curr_buf - mst->off < want)
+    {
+      /* need more space */
+      mst->pos -= mst->off;
+      memmove (ibuf, &ibuf[mst->off], mst->pos);
+      mst->off = 0;
+    }
+    if (want > mst->curr_buf)
+    {
+      mst->hdr = realloc (mst->hdr, want);
+      if (NULL == mst->hdr)
+       exit (3);
+      ibuf = (char *) mst->hdr;
+      mst->curr_buf = want;
+    }
+    hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
+    if (mst->pos - mst->off < want)
+    {
+      delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
+      memcpy (&ibuf[mst->pos], buf, delta);
+      mst->pos += delta;
+      buf += delta;
+      size -= delta;
+    }
+    if (mst->pos - mst->off < want)
+    {
+      if (purge)
+      {
+        mst->off = 0;
+        mst->pos = 0;
+      }
+      return GNUNET_OK;
+    }
+    if (one_shot == GNUNET_SYSERR)
+    {
+      /* cannot call callback again, but return value saying that
+       * we have another full message in the buffer */
+      ret = GNUNET_NO;
+      goto copy;
+    }
+    if (one_shot == GNUNET_YES)
+      one_shot = GNUNET_SYSERR;
+    mst->cb (mst->cb_cls, client_identity, hdr);
+    mst->off += want;
+    if (mst->off == mst->pos)
+    {
+      /* reset to beginning of buffer, it's free right now! */
+      mst->off = 0;
+      mst->pos = 0;
+    }
+  }
+  while (size > 0)
+  {
+    if (size < sizeof (struct GNUNET_MessageHeader))
+      break;
+    offset = (unsigned long) buf;
+    need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
+    if (GNUNET_NO == need_align)
+    {
+      /* can try to do zero-copy and process directly from original buffer */
+      hdr = (const struct GNUNET_MessageHeader *) buf;
+      want = ntohs (hdr->size);
+      if (want < sizeof (struct GNUNET_MessageHeader))
+      {
+        // GNUNET_break_op (0);
+        mst->off = 0;
+        return GNUNET_SYSERR;
+      }
+      if (size < want)
+        break;                  /* or not, buffer incomplete, so copy to 
private buffer... */
+      if (one_shot == GNUNET_SYSERR)
+      {
+        /* cannot call callback again, but return value saying that
+         * we have another full message in the buffer */
+        ret = GNUNET_NO;
+        goto copy;
+      }
+      if (one_shot == GNUNET_YES)
+        one_shot = GNUNET_SYSERR;
+      mst->cb (mst->cb_cls, client_identity, hdr);
+      buf += want;
+      size -= want;
+    }
+    else
+    {
+      /* need to copy to private buffer to align;
+       * yes, we go a bit more spagetti than usual here */
+      goto do_align;
+    }
+  }
+copy:
+  if ((size > 0) && (!purge))
+  {
+    if (size + mst->pos > mst->curr_buf)
+    {
+      mst->hdr = realloc (mst->hdr, size + mst->pos);
+      if (NULL == mst->hdr)
+       exit (4);
+      ibuf = (char *) mst->hdr;
+      mst->curr_buf = size + mst->pos;
+    }
+    // GNUNET_assert (mst->pos + size <= mst->curr_buf);
+    memcpy (&ibuf[mst->pos], buf, size);
+    mst->pos += size;
+  }
+  if (purge)
+    mst->off = 0;
+  return ret;
+}
+
+
+/**
+ * Destroys a tokenizer.
+ *
+ * @param mst tokenizer to destroy
+ */
+void
+GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst)
+{
+  free (mst->hdr);
+  free (mst);
+}
+
+/* end of server_mst.c copy */
+
+
+
+
+/**
  * Radiotap header iteration
  *
  * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
@@ -1352,7 +1650,7 @@
 
   dev.write_pout.size = 0;
   dev.write_pout.pos = 0;
-  stdin_mst = GNUNET_SERVER_mst_create (&stdin_send_hw, &dev);
+  stdin_mst = GNUNET_SERVER_mst_create (&stdin_send_hw, &dev);  
 
   /* send mac to STDOUT first */
   write_std.pos = 0;

Modified: gnunet/src/util/pseudonym.c
===================================================================
--- gnunet/src/util/pseudonym.c 2011-12-06 19:56:51 UTC (rev 18478)
+++ gnunet/src/util/pseudonym.c 2011-12-06 20:07:08 UTC (rev 18479)
@@ -47,6 +47,13 @@
 
 
 /**
+ * Configuration section we use.
+ */
+#define GNUNET_CLIENT_SERVICE_NAME "client"
+
+
+
+/**
  * Registered callbacks for discovery of pseudonyms.
  */
 struct DiscoveryCallback




reply via email to

[Prev in Thread] Current Thread [Next in Thread]