diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-07-15 12:22:42 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-07-15 12:22:42 +0000 |
commit | e67faec7efa18a8ce2bdb97798828e9d1a524683 (patch) | |
tree | bcc4b71a428a88e1a6c18f78ea9af4ce1eb848cd /src | |
parent | ba1afcb5c2c1f9fe26cb2250aa981ea1bcfeaad1 (diff) | |
download | gnunet-e67faec7efa18a8ce2bdb97798828e9d1a524683.tar.gz gnunet-e67faec7efa18a8ce2bdb97798828e9d1a524683.zip |
Change get_info API
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_mesh_service.h | 56 | ||||
-rw-r--r-- | src/mesh/mesh.h | 22 | ||||
-rw-r--r-- | 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" | |||
45 | /** | 45 | /** |
46 | * Version number of GNUnet-mesh API. | 46 | * Version number of GNUnet-mesh API. |
47 | */ | 47 | */ |
48 | #define GNUNET_MESH_VERSION 0x00000001 | 48 | #define GNUNET_MESH_VERSION 0x00000002 |
49 | 49 | ||
50 | 50 | ||
51 | /** | 51 | /** |
@@ -60,6 +60,39 @@ struct GNUNET_MESH_Tunnel; | |||
60 | 60 | ||
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Options for querying a tunnel. | ||
64 | * Second line indicates filed in the MeshTunnelInfo union carrying the answer. | ||
65 | */ | ||
66 | enum MeshTunnelOption | ||
67 | { | ||
68 | /** | ||
69 | * Disable buffering on intermediate nodes (for minimum latency). | ||
70 | * Yes/No. | ||
71 | */ | ||
72 | GNUNET_MESH_OPTION_NOBUFFER = 0x1, | ||
73 | |||
74 | /** | ||
75 | * Enable tunnel reliability, lost messages will be retransmitted. | ||
76 | * Yes/No. | ||
77 | */ | ||
78 | GNUNET_MESH_OPTION_RELIABLE = 0x2, | ||
79 | |||
80 | /** | ||
81 | * Enable out of order delivery of messages. | ||
82 | * Yes/No. | ||
83 | */ | ||
84 | GNUNET_MESH_OPTION_OOORDER = 0x4, | ||
85 | |||
86 | /** | ||
87 | * Who is the peer at the other end of the tunnel. | ||
88 | * struct GNUNET_PeerIdentity *peer | ||
89 | */ | ||
90 | GNUNET_MESH_OPTION_PEER = 0x8 | ||
91 | |||
92 | }; | ||
93 | |||
94 | |||
95 | /** | ||
63 | * Functions with this signature are called whenever a message is | 96 | * Functions with this signature are called whenever a message is |
64 | * received. | 97 | * received. |
65 | * | 98 | * |
@@ -225,17 +258,17 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel); | |||
225 | /** | 258 | /** |
226 | * Struct to retrieve info about a tunnel. | 259 | * Struct to retrieve info about a tunnel. |
227 | */ | 260 | */ |
228 | struct MeshTunnelInfo { | 261 | union MeshTunnelInfo { |
229 | 262 | ||
230 | /** | 263 | /** |
231 | * Property, as listed in src/mesh/mesh.h (GNUNET_MESH_OPTION_*) | 264 | * GNUNET_YES / GNUNET_NO, for binary flags. |
232 | */ | 265 | */ |
233 | unsigned int prop; | 266 | int yes_no; |
234 | 267 | ||
235 | /** | 268 | /** |
236 | * Value, of type dependant on @c prop. | 269 | * Peer on the other side of the tunnel |
237 | */ | 270 | */ |
238 | void *value; | 271 | struct GNUNET_PeerIdentity *peer; |
239 | }; | 272 | }; |
240 | 273 | ||
241 | 274 | ||
@@ -243,11 +276,14 @@ struct MeshTunnelInfo { | |||
243 | * Get information about a tunnel. | 276 | * Get information about a tunnel. |
244 | * | 277 | * |
245 | * @param tunnel Tunnel handle. | 278 | * @param tunnel Tunnel handle. |
246 | * | 279 | * @param option Query, as listed in src/mesh/mesh.h (GNUNET_MESH_OPTION_*) |
247 | * @return Allocated, {0, NULL} terminated set of tunnel properties. | 280 | * @param ... dependant on option, currently not used |
281 | * | ||
282 | * @return Union with an answer to the query. | ||
248 | */ | 283 | */ |
249 | struct MeshTunnelInfo * | 284 | const union MeshTunnelInfo * |
250 | GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel); | 285 | GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel, |
286 | enum MeshTunnelOption option, ...); | ||
251 | 287 | ||
252 | 288 | ||
253 | /** | 289 | /** |
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" | |||
88 | #define HIGH_PID 0xFFFF0000 | 88 | #define HIGH_PID 0xFFFF0000 |
89 | #define LOW_PID 0x0000FFFF | 89 | #define LOW_PID 0x0000FFFF |
90 | 90 | ||
91 | /** | ||
92 | * Value in tunnel info: *int (GNUNET_YES/GNUNET_NO) | ||
93 | */ | ||
94 | typedef enum | ||
95 | { | ||
96 | /** | ||
97 | * Disable buffering on intermediate nodes (for minimum latency). | ||
98 | */ | ||
99 | GNUNET_MESH_OPTION_NOBUFFER = 0x1, | ||
100 | |||
101 | /** | ||
102 | * Enable tunnel reliability, lost messages will be retransmitted. | ||
103 | */ | ||
104 | GNUNET_MESH_OPTION_RELIABLE = 0x2, | ||
105 | |||
106 | /** | ||
107 | * Enable out of order delivery of messages. | ||
108 | */ | ||
109 | GNUNET_MESH_OPTION_OOORDER = 0x4 | ||
110 | |||
111 | } MeshTunnelOption; | ||
112 | |||
113 | #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID) | 91 | #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID) |
114 | 92 | ||
115 | /******************************************************************************/ | 93 | /******************************************************************************/ |
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,14 +296,19 @@ struct GNUNET_MESH_Tunnel | |||
296 | /** | 296 | /** |
297 | * Is the tunnel allowed to buffer? | 297 | * Is the tunnel allowed to buffer? |
298 | */ | 298 | */ |
299 | int buffering; | 299 | int nobuffer; |
300 | 300 | ||
301 | /** | 301 | /** |
302 | * Is the tunnel allowed to buffer? | 302 | * Is the tunnel realiable? |
303 | */ | 303 | */ |
304 | int reliable; | 304 | int reliable; |
305 | 305 | ||
306 | /** | 306 | /** |
307 | * If reliable, is the tunnel out of order? | ||
308 | */ | ||
309 | int ooorder; | ||
310 | |||
311 | /** | ||
307 | * Are we allowed to send to the service? | 312 | * Are we allowed to send to the service? |
308 | */ | 313 | */ |
309 | int allow_send; | 314 | int allow_send; |
@@ -449,7 +454,7 @@ create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) | |||
449 | t->tid = tid; | 454 | t->tid = tid; |
450 | } | 455 | } |
451 | t->allow_send = GNUNET_NO; | 456 | t->allow_send = GNUNET_NO; |
452 | t->buffering = GNUNET_YES; | 457 | t->nobuffer = GNUNET_NO; |
453 | return t; | 458 | return t; |
454 | } | 459 | } |
455 | 460 | ||
@@ -730,7 +735,7 @@ do_reconnect (struct GNUNET_MESH_Handle *h) | |||
730 | GNUNET_PEER_resolve (t->peer, &tmsg.peer); | 735 | GNUNET_PEER_resolve (t->peer, &tmsg.peer); |
731 | 736 | ||
732 | options = 0; | 737 | options = 0; |
733 | if (GNUNET_NO == t->buffering) | 738 | if (GNUNET_YES == t->nobuffer) |
734 | options |= GNUNET_MESH_OPTION_NOBUFFER; | 739 | options |= GNUNET_MESH_OPTION_NOBUFFER; |
735 | 740 | ||
736 | if (GNUNET_YES == t->reliable) | 741 | if (GNUNET_YES == t->reliable) |
@@ -812,13 +817,18 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h, | |||
812 | t->tid = tid; | 817 | t->tid = tid; |
813 | t->port = ntohl (msg->port); | 818 | t->port = ntohl (msg->port); |
814 | if (0 != (msg->opt & GNUNET_MESH_OPTION_NOBUFFER)) | 819 | if (0 != (msg->opt & GNUNET_MESH_OPTION_NOBUFFER)) |
815 | t->buffering = GNUNET_NO; | 820 | t->nobuffer = GNUNET_YES; |
816 | else | 821 | else |
817 | t->buffering = GNUNET_YES; | 822 | t->nobuffer = GNUNET_NO; |
818 | if (0 != (msg->opt & GNUNET_MESH_OPTION_RELIABLE)) | 823 | if (0 != (msg->opt & GNUNET_MESH_OPTION_RELIABLE)) |
819 | t->reliable = GNUNET_YES; | 824 | t->reliable = GNUNET_YES; |
820 | else | 825 | else |
821 | t->reliable = GNUNET_NO; | 826 | t->reliable = GNUNET_NO; |
827 | if (GNUNET_YES == t->reliable && | ||
828 | 0 != (msg->opt & GNUNET_MESH_OPTION_OOORDER)) | ||
829 | t->ooorder = GNUNET_YES; | ||
830 | else | ||
831 | t->ooorder = GNUNET_NO; | ||
822 | LOG (GNUNET_ERROR_TYPE_DEBUG, " created tunnel %p\n", t); | 832 | LOG (GNUNET_ERROR_TYPE_DEBUG, " created tunnel %p\n", t); |
823 | t->ctx = h->new_tunnel (h->cls, t, &msg->peer, t->port); | 833 | t->ctx = h->new_tunnel (h->cls, t, &msg->peer, t->port); |
824 | LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n"); | 834 | LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n"); |
@@ -1481,21 +1491,35 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel) | |||
1481 | * Get information about a tunnel. | 1491 | * Get information about a tunnel. |
1482 | * | 1492 | * |
1483 | * @param tunnel Tunnel handle. | 1493 | * @param tunnel Tunnel handle. |
1484 | * | 1494 | * @param option Query (GNUNET_MESH_OPTION_*). |
1485 | * @return Allocated, {0, NULL} terminated set of tunnel properties. | 1495 | * @param ... dependant on option, currently not used |
1496 | * | ||
1497 | * @return Union with an answer to the query. | ||
1486 | */ | 1498 | */ |
1487 | struct MeshTunnelInfo * | 1499 | const union MeshTunnelInfo * |
1488 | GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel) | 1500 | GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel, |
1501 | enum MeshTunnelOption option, ...) | ||
1489 | { | 1502 | { |
1490 | struct MeshTunnelInfo *ret; | 1503 | const union MeshTunnelInfo *ret; |
1491 | 1504 | ||
1492 | ret = GNUNET_malloc (sizeof (struct MeshTunnelInfo) * 3); | 1505 | switch (option) |
1493 | ret[0].prop = GNUNET_MESH_OPTION_NOBUFFER; | 1506 | { |
1494 | ret[0].value = &tunnel->buffering; // FIXME use "nobuffer" | 1507 | case GNUNET_MESH_OPTION_NOBUFFER: |
1495 | ret[1].prop = GNUNET_MESH_OPTION_RELIABLE; | 1508 | ret = (const union MeshTunnelInfo *) &tunnel->nobuffer; |
1496 | ret[1].value = &tunnel->reliable; | 1509 | break; |
1497 | ret[2].prop = 0; | 1510 | case GNUNET_MESH_OPTION_RELIABLE: |
1498 | ret[2].value = NULL; | 1511 | ret = (const union MeshTunnelInfo *) &tunnel->reliable; |
1512 | break; | ||
1513 | case GNUNET_MESH_OPTION_OOORDER: | ||
1514 | ret = (const union MeshTunnelInfo *) &tunnel->ooorder; | ||
1515 | break; | ||
1516 | case GNUNET_MESH_OPTION_PEER: | ||
1517 | ret = (const union MeshTunnelInfo *) &tunnel->peer; | ||
1518 | break; | ||
1519 | default: | ||
1520 | GNUNET_break (0); | ||
1521 | return NULL; | ||
1522 | } | ||
1499 | 1523 | ||
1500 | return ret; | 1524 | return ret; |
1501 | } | 1525 | } |