gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r26465 - in gnunet/src: . dv include


From: gnunet
Subject: [GNUnet-SVN] r26465 - in gnunet/src: . dv include
Date: Fri, 15 Mar 2013 20:46:04 +0100

Author: grothoff
Date: 2013-03-15 20:46:04 +0100 (Fri, 15 Mar 2013)
New Revision: 26465

Modified:
   gnunet/src/Makefile.am
   gnunet/src/dv/plugin_transport_dv.c
   gnunet/src/include/gnunet_protocols.h
Log:
-box DV messages when needed

Modified: gnunet/src/Makefile.am
===================================================================
--- gnunet/src/Makefile.am      2013-03-15 16:09:15 UTC (rev 26464)
+++ gnunet/src/Makefile.am      2013-03-15 19:46:04 UTC (rev 26465)
@@ -3,7 +3,7 @@
 #endif
 
 if HAVE_EXPERIMENTAL
- EXP_DIR = chat dv consensus sysmon
+ EXP_DIR = chat consensus dv sysmon
 endif
 
 if LINUX

Modified: gnunet/src/dv/plugin_transport_dv.c
===================================================================
--- gnunet/src/dv/plugin_transport_dv.c 2013-03-15 16:09:15 UTC (rev 26464)
+++ gnunet/src/dv/plugin_transport_dv.c 2013-03-15 19:46:04 UTC (rev 26465)
@@ -156,6 +156,11 @@
    */
   struct GNUNET_DV_ServiceHandle *dvh;
 
+  /**
+   * Tokenizer for boxed messages.
+   */
+  struct GNUNET_SERVER_MessageStreamTokenizer *mst; 
+
 };
 
 
@@ -172,6 +177,35 @@
 
 
 /**
+ * Function called by MST on each message from the box.
+ *
+ * @param cls closure with the 'struct Plugin'
+ * @param client identification of the client (with the 'struct Session')
+ * @param message the actual message
+ * @return GNUNET_OK on success
+ */
+static int
+unbox_cb (void *cls,
+         void *client,
+         const struct GNUNET_MessageHeader *message)
+{
+  struct Plugin *plugin = cls;
+  struct Session *session = client;
+  struct GNUNET_ATS_Information ats;
+  
+  ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
+  ats.value = htonl (session->distance);
+  session->active = GNUNET_YES;
+  plugin->env->receive (plugin->env->cls, 
+                       &session->sender,
+                        message,
+                        &ats, 1,
+                       session, "", 0);
+  return GNUNET_OK;
+}
+
+
+/**
  * Handler for messages received from the DV service.
  *
  * @param cls closure with the plugin
@@ -196,6 +230,17 @@
     GNUNET_break (0);
     return;
   }
+  if (GNUNET_MESSAGE_TYPE_DV_BOX == ntohs (msg->type))
+  {
+    /* need to unbox using MST */
+    GNUNET_SERVER_mst_receive (plugin->mst, 
+                              session,
+                              (const char *) &msg[1],
+                              ntohs (msg->size) - sizeof (struct 
GNUNET_MessageHeader),
+                              GNUNET_YES,
+                              GNUNET_NO);
+    return;
+  }
   ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
   ats.value = htonl (distance);
   session->active = GNUNET_YES;
@@ -382,9 +427,19 @@
 {
   struct PendingRequest *pr;
   const struct GNUNET_MessageHeader *msg;
+  struct GNUNET_MessageHeader *box;
 
+  box = NULL;
   msg = (const struct GNUNET_MessageHeader *) msgbuf;
-  GNUNET_assert (ntohs (msg->size) == msgbuf_size); // API will change...
+  if (ntohs (msg->size) != msgbuf_size)
+  {
+    /* need to box */
+    box = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader) + msgbuf_size);
+    box->type = htons (GNUNET_MESSAGE_TYPE_DV_BOX);
+    box->size = htons (sizeof (struct GNUNET_MessageHeader) + msgbuf_size);
+    memcpy (&box[1], msgbuf, msgbuf_size);
+    msg = box;
+  }
   pr = GNUNET_malloc (sizeof (struct PendingRequest));
   pr->transmit_cont = cont;
   pr->transmit_cont_cls = cont_cls;
@@ -397,6 +452,7 @@
                           msg,
                           &send_finished,
                           pr);
+  GNUNET_free_non_null (box);
   return 0; /* DV */
 }
 
@@ -580,6 +636,8 @@
   plugin = GNUNET_malloc (sizeof (struct Plugin));
   plugin->env = env;
   plugin->sessions = GNUNET_CONTAINER_multihashmap_create (1024 * 8, 
GNUNET_YES);
+  plugin->mst = GNUNET_SERVER_mst_create (&unbox_cb,
+                                         plugin);
   plugin->dvh = GNUNET_DV_service_connect (env->cfg,
                                           plugin,
                                           &handle_dv_connect,
@@ -589,6 +647,7 @@
   if (NULL == plugin->dvh)
   {
     GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
+    GNUNET_SERVER_mst_destroy (plugin->mst);    
     GNUNET_free (plugin);
     return NULL;
   }
@@ -639,6 +698,7 @@
                                         &free_session_iterator,
                                         NULL);
   GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
+  GNUNET_SERVER_mst_destroy (plugin->mst);    
   GNUNET_free (plugin);
   GNUNET_free (api);
   return NULL;

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2013-03-15 16:09:15 UTC (rev 
26464)
+++ gnunet/src/include/gnunet_protocols.h       2013-03-15 19:46:04 UTC (rev 
26465)
@@ -212,7 +212,12 @@
  */
 #define GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED 52
 
+/**
+ * DV message box for boxing multiple messages.
+ */
+#define GNUNET_MESSAGE_TYPE_DV_BOX 53
 
+
 
/*******************************************************************************
  * Transport-UDP message types
  
******************************************************************************/




reply via email to

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