/**
* Version number of GNUnet-mesh API.
*/
-#define GNUNET_MESH_VERSION 0x00000001
+#define GNUNET_MESH_VERSION 0x00000002
/**
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.
/**
* 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;
};
* 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, ...);
/**
#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)
/******************************************************************************/
/**
* 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?
*/
t->tid = tid;
}
t->allow_send = GNUNET_NO;
- t->buffering = GNUNET_YES;
+ t->nobuffer = GNUNET_NO;
return t;
}
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)
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");
* 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;
}