diff options
author | Bart Polot <bart@net.in.tum.de> | 2012-08-01 13:04:29 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2012-08-01 13:04:29 +0000 |
commit | 08f25a23f9750237979ca591c0ba8ca7002b2ea7 (patch) | |
tree | c0efdc35b4af694ac48782ee6e1f2ed7fe6e4296 | |
parent | aeec4593b1ce3a32ad7df1ae0b778ad2cd699d3c (diff) | |
download | gnunet-08f25a23f9750237979ca591c0ba8ca7002b2ea7.tar.gz gnunet-08f25a23f9750237979ca591c0ba8ca7002b2ea7.zip |
- wip
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 69 | ||||
-rw-r--r-- | src/mesh/mesh.h | 5 | ||||
-rw-r--r-- | src/mesh/mesh_api.c | 10 |
3 files changed, 57 insertions, 27 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index b6c5daa1b..27697a27a 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -78,6 +78,7 @@ | |||
78 | 78 | ||
79 | /** FWD declaration */ | 79 | /** FWD declaration */ |
80 | struct MeshPeerInfo; | 80 | struct MeshPeerInfo; |
81 | struct MeshClient; | ||
81 | 82 | ||
82 | 83 | ||
83 | /** | 84 | /** |
@@ -259,7 +260,28 @@ struct MESH_TunnelID | |||
259 | }; | 260 | }; |
260 | 261 | ||
261 | 262 | ||
262 | struct MeshClient; /* FWD declaration */ | 263 | /** |
264 | * Info collected during iteration of child nodes in order to get the ACK value | ||
265 | * for a tunnel. | ||
266 | */ | ||
267 | struct MeshTunnelChildIteratorContext | ||
268 | { | ||
269 | /** | ||
270 | * Tunnel whose info is being collected. | ||
271 | */ | ||
272 | struct MeshTunnel *t; | ||
273 | |||
274 | /** | ||
275 | * Maximum child ACK so far. | ||
276 | */ | ||
277 | uint32_t max_child_ack; | ||
278 | |||
279 | /** | ||
280 | * Number of children nodes | ||
281 | */ | ||
282 | unsigned int nchildren; | ||
283 | }; | ||
284 | |||
263 | 285 | ||
264 | /** | 286 | /** |
265 | * Struct containing all information regarding a tunnel | 287 | * Struct containing all information regarding a tunnel |
@@ -308,11 +330,6 @@ struct MeshTunnel | |||
308 | uint32_t last_ack; | 330 | uint32_t last_ack; |
309 | 331 | ||
310 | /** | 332 | /** |
311 | * Maximum child ACK. | ||
312 | */ | ||
313 | uint32_t max_child_ack; | ||
314 | |||
315 | /** | ||
316 | * How many messages are in the queue. | 333 | * How many messages are in the queue. |
317 | */ | 334 | */ |
318 | unsigned int queue_n; | 335 | unsigned int queue_n; |
@@ -1622,6 +1639,17 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1622 | /****************** GENERAL HELPER FUNCTIONS ************************/ | 1639 | /****************** GENERAL HELPER FUNCTIONS ************************/ |
1623 | /******************************************************************************/ | 1640 | /******************************************************************************/ |
1624 | 1641 | ||
1642 | static uint32_t | ||
1643 | max_ack (uint32_t a, uint32_t b) | ||
1644 | { | ||
1645 | } | ||
1646 | |||
1647 | static uint32_t | ||
1648 | min_ack (uint32_t a, uint32_t b) | ||
1649 | { | ||
1650 | return (max_ack (a, b) == a) ? b : a; | ||
1651 | } | ||
1652 | |||
1625 | 1653 | ||
1626 | /** | 1654 | /** |
1627 | * Decrements the reference counter and frees all resources if needed | 1655 | * Decrements the reference counter and frees all resources if needed |
@@ -1827,7 +1855,6 @@ client_delete_tunnel (struct MeshClient *c, struct MeshTunnel *t) | |||
1827 | &hash, | 1855 | &hash, |
1828 | t)); | 1856 | t)); |
1829 | } | 1857 | } |
1830 | |||
1831 | } | 1858 | } |
1832 | 1859 | ||
1833 | 1860 | ||
@@ -3253,7 +3280,8 @@ tunnel_get_child_ack (void *cls, | |||
3253 | { | 3280 | { |
3254 | struct GNUNET_PeerIdentity peer_id; | 3281 | struct GNUNET_PeerIdentity peer_id; |
3255 | struct MeshTunnelChildInfo *cinfo; | 3282 | struct MeshTunnelChildInfo *cinfo; |
3256 | struct MeshTunnel *t = cls; | 3283 | struct MeshTunnelChildIteratorContext *ctx = cls; |
3284 | struct MeshTunnel *t = ctx->t; | ||
3257 | uint32_t ack; | 3285 | uint32_t ack; |
3258 | 3286 | ||
3259 | GNUNET_PEER_resolve (id, &peer_id); | 3287 | GNUNET_PEER_resolve (id, &peer_id); |
@@ -3277,16 +3305,16 @@ tunnel_get_child_ack (void *cls, | |||
3277 | ack = cinfo->max_pid; | 3305 | ack = cinfo->max_pid; |
3278 | } | 3306 | } |
3279 | 3307 | ||
3280 | if (0 == t->max_child_ack) | 3308 | if (0 == ctx->max_child_ack) |
3281 | t->max_child_ack = ack; | 3309 | ctx->max_child_ack = ack; |
3282 | 3310 | ||
3283 | if (GNUNET_YES == t->speed_min) | 3311 | if (GNUNET_YES == t->speed_min) |
3284 | { | 3312 | { |
3285 | t->max_child_ack = t->max_child_ack > ack ? ack : t->max_child_ack; | 3313 | ctx->max_child_ack = ctx->max_child_ack > ack ? ack : ctx->max_child_ack; |
3286 | } | 3314 | } |
3287 | else | 3315 | else |
3288 | { | 3316 | { |
3289 | t->max_child_ack = t->max_child_ack > ack ? t->max_child_ack : ack; | 3317 | ctx->max_child_ack = ctx->max_child_ack > ack ? ctx->max_child_ack : ack; |
3290 | } | 3318 | } |
3291 | 3319 | ||
3292 | } | 3320 | } |
@@ -3299,14 +3327,21 @@ tunnel_get_child_ack (void *cls, | |||
3299 | * | 3327 | * |
3300 | * @param t Tunnel. | 3328 | * @param t Tunnel. |
3301 | * | 3329 | * |
3302 | * @return Maximum PID allowed, 0 if node has no children. | 3330 | * @return Maximum PID allowed (uint32 MAX), -1 if node has no children. |
3303 | */ | 3331 | */ |
3304 | static uint32_t | 3332 | static int64_t |
3305 | tunnel_get_children_ack (struct MeshTunnel *t) | 3333 | tunnel_get_children_ack (struct MeshTunnel *t) |
3306 | { | 3334 | { |
3307 | t->max_child_ack = 0; | 3335 | struct MeshTunnelChildIteratorContext ctx; |
3308 | tree_iterate_children (t->tree, tunnel_get_child_ack, t); | 3336 | ctx.t = t; |
3309 | return t->max_child_ack; | 3337 | ctx.max_child_ack = 0; |
3338 | ctx.nchildren = 0; | ||
3339 | tree_iterate_children (t->tree, tunnel_get_child_ack, &ctx); | ||
3340 | |||
3341 | if (0 == ctx.nchildren) | ||
3342 | return -1LL; | ||
3343 | |||
3344 | return (int64_t) ctx.max_child_ack; | ||
3310 | } | 3345 | } |
3311 | 3346 | ||
3312 | 3347 | ||
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index 15599c4ba..e1448aa49 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h | |||
@@ -78,6 +78,11 @@ | |||
78 | #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000 | 78 | #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000 |
79 | #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000 | 79 | #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000 |
80 | 80 | ||
81 | #define HIGH_PID 0xFFFF0000 | ||
82 | #define LOW_PID 0x0000FFFF | ||
83 | |||
84 | #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID) | ||
85 | |||
81 | /******************************************************************************/ | 86 | /******************************************************************************/ |
82 | /************************** MESSAGES ******************************/ | 87 | /************************** MESSAGES ******************************/ |
83 | /******************************************************************************/ | 88 | /******************************************************************************/ |
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index f1c9a78e5..ac1c3114e 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c | |||
@@ -21,7 +21,6 @@ | |||
21 | * @author Bartlomiej Polot | 21 | * @author Bartlomiej Polot |
22 | * | 22 | * |
23 | * STRUCTURE: | 23 | * STRUCTURE: |
24 | * - CONSTANTS | ||
25 | * - DATA STRUCTURES | 24 | * - DATA STRUCTURES |
26 | * - DECLARATIONS | 25 | * - DECLARATIONS |
27 | * - AUXILIARY FUNCTIONS | 26 | * - AUXILIARY FUNCTIONS |
@@ -44,15 +43,6 @@ | |||
44 | 43 | ||
45 | 44 | ||
46 | /******************************************************************************/ | 45 | /******************************************************************************/ |
47 | /************************ CONSTANTS ****************************/ | ||
48 | /******************************************************************************/ | ||
49 | |||
50 | #define HIGH_PID 0xFFFF0000 | ||
51 | #define LOW_PID 0x0000FFFF | ||
52 | |||
53 | #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID) | ||
54 | |||
55 | /******************************************************************************/ | ||
56 | /************************ DATA STRUCTURES ****************************/ | 46 | /************************ DATA STRUCTURES ****************************/ |
57 | /******************************************************************************/ | 47 | /******************************************************************************/ |
58 | 48 | ||