gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r28046 - in gnunet/src: include mesh


From: gnunet
Subject: [GNUnet-SVN] r28046 - in gnunet/src: include mesh
Date: Mon, 15 Jul 2013 14:22:42 +0200

Author: bartpolot
Date: 2013-07-15 14:22:42 +0200 (Mon, 15 Jul 2013)
New Revision: 28046

Modified:
   gnunet/src/include/gnunet_mesh_service.h
   gnunet/src/mesh/mesh.h
   gnunet/src/mesh/mesh_api.c
Log:
Change get_info API

Modified: gnunet/src/include/gnunet_mesh_service.h
===================================================================
--- gnunet/src/include/gnunet_mesh_service.h    2013-07-15 12:22:19 UTC (rev 
28045)
+++ gnunet/src/include/gnunet_mesh_service.h    2013-07-15 12:22:42 UTC (rev 
28046)
@@ -45,7 +45,7 @@
 /**
  * Version number of GNUnet-mesh API.
  */
-#define GNUNET_MESH_VERSION 0x00000001
+#define GNUNET_MESH_VERSION 0x00000002
 
 
 /**
@@ -60,6 +60,39 @@
 
 
 /**
+ * Options for querying a tunnel.
+ * Second line indicates filed in the MeshTunnelInfo union carrying the answer.
+ */
+enum MeshTunnelOption
+{
+  /**
+   * Disable buffering on intermediate nodes (for minimum latency).
+   * Yes/No.
+   */
+  GNUNET_MESH_OPTION_NOBUFFER   = 0x1,
+
+  /**
+   * Enable tunnel reliability, lost messages will be retransmitted.
+   * Yes/No.
+   */
+  GNUNET_MESH_OPTION_RELIABLE   = 0x2,
+
+  /**
+   * Enable out of order delivery of messages.
+   * Yes/No.
+   */
+  GNUNET_MESH_OPTION_OOORDER    = 0x4,
+
+  /**
+   * Who is the peer at the other end of the tunnel.
+   * struct GNUNET_PeerIdentity *peer
+   */
+  GNUNET_MESH_OPTION_PEER       = 0x8
+
+};
+
+
+/**
  * Functions with this signature are called whenever a message is
  * received.
  * 
@@ -225,17 +258,17 @@
 /**
  * Struct to retrieve info about a tunnel.
  */
-struct MeshTunnelInfo {
+union MeshTunnelInfo {
 
   /**
-   * Property, as listed in src/mesh/mesh.h (GNUNET_MESH_OPTION_*)
+   * GNUNET_YES / GNUNET_NO, for binary flags.
    */
-  unsigned int prop;
+  int yes_no;
 
   /**
-   * Value, of type dependant on @c prop.
+   * Peer on the other side of the tunnel
    */
-  void *value;
+  struct GNUNET_PeerIdentity *peer;
 };
 
 
@@ -243,11 +276,14 @@
  * Get information about a tunnel.
  *
  * @param tunnel Tunnel handle.
- * 
- * @return Allocated, {0, NULL} terminated set of tunnel properties.
+ * @param option Query, as listed in src/mesh/mesh.h (GNUNET_MESH_OPTION_*)
+ * @param ... dependant on option, currently not used
+ *
+ * @return Union with an answer to the query.
  */
-struct MeshTunnelInfo *
-GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel);
+const union MeshTunnelInfo *
+GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel,
+                             enum MeshTunnelOption option, ...);
 
 
 /**

Modified: gnunet/src/mesh/mesh.h
===================================================================
--- gnunet/src/mesh/mesh.h      2013-07-15 12:22:19 UTC (rev 28045)
+++ gnunet/src/mesh/mesh.h      2013-07-15 12:22:42 UTC (rev 28046)
@@ -88,28 +88,6 @@
 #define HIGH_PID                                0xFFFF0000
 #define LOW_PID                                 0x0000FFFF
 
-/**
- * Value in tunnel info: *int (GNUNET_YES/GNUNET_NO)
- */
-typedef enum
-{
-  /**
-   * Disable buffering on intermediate nodes (for minimum latency).
-   */
-  GNUNET_MESH_OPTION_NOBUFFER   = 0x1,
-
-  /**
-   * Enable tunnel reliability, lost messages will be retransmitted.
-   */
-  GNUNET_MESH_OPTION_RELIABLE   = 0x2,
-
-  /**
-   * Enable out of order delivery of messages.
-   */
-  GNUNET_MESH_OPTION_OOORDER    = 0x4
-
-} MeshTunnelOption;
-
 #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
 
 
/******************************************************************************/

Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c  2013-07-15 12:22:19 UTC (rev 28045)
+++ gnunet/src/mesh/mesh_api.c  2013-07-15 12:22:42 UTC (rev 28046)
@@ -296,14 +296,19 @@
     /**
      * Is the tunnel allowed to buffer?
      */
-  int buffering;
+  int nobuffer;
 
     /**
-     * Is the tunnel allowed to buffer?
+     * Is the tunnel realiable?
      */
   int reliable;
 
     /**
+     * If reliable, is the tunnel out of order?
+     */
+  int ooorder;
+
+    /**
      * Are we allowed to send to the service?
      */
   int allow_send;
@@ -449,7 +454,7 @@
     t->tid = tid;
   }
   t->allow_send = GNUNET_NO;
-  t->buffering = GNUNET_YES;
+  t->nobuffer = GNUNET_NO;
   return t;
 }
 
@@ -730,7 +735,7 @@
     GNUNET_PEER_resolve (t->peer, &tmsg.peer);
 
     options = 0;
-    if (GNUNET_NO == t->buffering)
+    if (GNUNET_YES == t->nobuffer)
       options |= GNUNET_MESH_OPTION_NOBUFFER;
 
     if (GNUNET_YES == t->reliable)
@@ -812,13 +817,18 @@
     t->tid = tid;
     t->port = ntohl (msg->port);
     if (0 != (msg->opt & GNUNET_MESH_OPTION_NOBUFFER))
-      t->buffering = GNUNET_NO;
+      t->nobuffer = GNUNET_YES;
     else
-      t->buffering = GNUNET_YES;
+      t->nobuffer = GNUNET_NO;
     if (0 != (msg->opt & GNUNET_MESH_OPTION_RELIABLE))
       t->reliable = GNUNET_YES;
     else
       t->reliable = GNUNET_NO;
+    if (GNUNET_YES == t->reliable &&
+        0 != (msg->opt & GNUNET_MESH_OPTION_OOORDER))
+      t->ooorder = GNUNET_YES;
+    else
+      t->ooorder = GNUNET_NO;
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  created tunnel %p\n", t);
     t->ctx = h->new_tunnel (h->cls, t, &msg->peer, t->port);
     LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n");
@@ -1481,21 +1491,35 @@
  * Get information about a tunnel.
  *
  * @param tunnel Tunnel handle.
- * 
- * @return Allocated, {0, NULL} terminated set of tunnel properties.
+ * @param option Query (GNUNET_MESH_OPTION_*).
+ * @param ... dependant on option, currently not used
+ *
+ * @return Union with an answer to the query.
  */
-struct MeshTunnelInfo *
-GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel)
+const union MeshTunnelInfo *
+GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel,
+                             enum MeshTunnelOption option, ...)
 {
-  struct MeshTunnelInfo *ret;
+  const union MeshTunnelInfo *ret;
 
-  ret = GNUNET_malloc (sizeof (struct MeshTunnelInfo) * 3);
-  ret[0].prop = GNUNET_MESH_OPTION_NOBUFFER;
-  ret[0].value = &tunnel->buffering; // FIXME use "nobuffer"
-  ret[1].prop = GNUNET_MESH_OPTION_RELIABLE;
-  ret[1].value = &tunnel->reliable;
-  ret[2].prop = 0;
-  ret[2].value = NULL;
+  switch (option)
+  {
+    case GNUNET_MESH_OPTION_NOBUFFER:
+      ret = (const union MeshTunnelInfo *) &tunnel->nobuffer;
+      break;
+    case GNUNET_MESH_OPTION_RELIABLE:
+      ret = (const union MeshTunnelInfo *) &tunnel->reliable;
+      break;
+    case GNUNET_MESH_OPTION_OOORDER:
+      ret = (const union MeshTunnelInfo *) &tunnel->ooorder;
+      break;
+    case GNUNET_MESH_OPTION_PEER:
+      ret = (const union MeshTunnelInfo *) &tunnel->peer;
+      break;
+    default:
+      GNUNET_break (0);
+      return NULL;
+  }
 
   return ret;
 }




reply via email to

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