Change get_info API
authorBart Polot <bart@net.in.tum.de>
Mon, 15 Jul 2013 12:22:42 +0000 (12:22 +0000)
committerBart Polot <bart@net.in.tum.de>
Mon, 15 Jul 2013 12:22:42 +0000 (12:22 +0000)
src/include/gnunet_mesh_service.h
src/mesh/mesh.h
src/mesh/mesh_api.c

index 378d40ba0734b2e7399f9d3a4b7f00412ff5f5a5..1f6f69a594e604b1a060cdb933a45cdfe8f9bc58 100644 (file)
@@ -45,7 +45,7 @@ extern "C"
 /**
  * Version number of GNUnet-mesh API.
  */
-#define GNUNET_MESH_VERSION 0x00000001
+#define GNUNET_MESH_VERSION 0x00000002
 
 
 /**
@@ -59,6 +59,39 @@ struct GNUNET_MESH_Handle;
 struct GNUNET_MESH_Tunnel;
 
 
+/**
+ * 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 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel);
 /**
  * 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 @@ struct MeshTunnelInfo {
  * 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, ...);
 
 
 /**
index 73bc04d27c1e07b7232b478971bcee0916f7b9a3..38b5e966c0262cb08fdebd441178455fe99656c8 100644 (file)
@@ -88,28 +88,6 @@ extern "C"
 #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)
 
 /******************************************************************************/
index 7547616ed3a05cb5e628e7e7c69da02779b1980c..db3af28cc74aeed024484c786a2bca34e9c859d9 100644 (file)
@@ -296,13 +296,18 @@ struct GNUNET_MESH_Tunnel
     /**
      * 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?
      */
@@ -449,7 +454,7 @@ create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
     t->tid = tid;
   }
   t->allow_send = GNUNET_NO;
-  t->buffering = GNUNET_YES;
+  t->nobuffer = GNUNET_NO;
   return t;
 }
 
@@ -730,7 +735,7 @@ do_reconnect (struct GNUNET_MESH_Handle *h)
     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 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h,
     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 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel)
  * 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;
-
-  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;
+  const union MeshTunnelInfo *ret;
+
+  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;
 }