From e67faec7efa18a8ce2bdb97798828e9d1a524683 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Mon, 15 Jul 2013 12:22:42 +0000 Subject: [PATCH] Change get_info API --- src/include/gnunet_mesh_service.h | 56 +++++++++++++++++++++++----- src/mesh/mesh.h | 22 ----------- src/mesh/mesh_api.c | 62 +++++++++++++++++++++---------- 3 files changed, 89 insertions(+), 51 deletions(-) diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h index 378d40ba0..1f6f69a59 100644 --- a/src/include/gnunet_mesh_service.h +++ b/src/include/gnunet_mesh_service.h @@ -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, ...); /** diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index 73bc04d27..38b5e966c 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h @@ -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) /******************************************************************************/ diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 7547616ed..db3af28cc 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -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; } -- 2.25.1