diff options
author | Julius Bünger <buenger@mytum.de> | 2015-01-07 17:27:15 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-01-07 17:27:15 +0000 |
commit | 3d8c1be931ffa54a86ea66cc5c981eb651ea50b4 (patch) | |
tree | 66a971908aa1aa7dc53d12710b150840214f61bf /src/rps | |
parent | 4d370bed62e5f6a47faba53fe3446a2d2a59d1ae (diff) | |
download | gnunet-3d8c1be931ffa54a86ea66cc5c981eb651ea50b4.tar.gz gnunet-3d8c1be931ffa54a86ea66cc5c981eb651ea50b4.zip |
got rid of touch_*()
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 91 |
1 files changed, 27 insertions, 64 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 1897f3e57..5d473a6e9 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -291,95 +291,51 @@ get_rand_peer(const struct GNUNET_PeerIdentity *peer_list, unsigned int list_siz | |||
291 | 291 | ||
292 | 292 | ||
293 | /** | 293 | /** |
294 | * Make sure the context of a given peer exists in the given peer_map. | 294 | * Get the context of a peer. If not existing, create. |
295 | */ | 295 | */ |
296 | void | 296 | struct peer_context * |
297 | touch_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) | 297 | get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) |
298 | { | 298 | { |
299 | struct peer_context *ctx; | 299 | struct peer_context *ctx; |
300 | 300 | ||
301 | if ( GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains( peer_map, peer ) ) | 301 | if ( GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) |
302 | { | 302 | { |
303 | ctx = GNUNET_CONTAINER_multipeermap_get(peer_map, peer); | 303 | ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer); |
304 | } | 304 | } |
305 | else | 305 | else |
306 | { | 306 | { |
307 | ctx = GNUNET_new(struct peer_context); | 307 | ctx = GNUNET_new (struct peer_context); |
308 | ctx->in_flags = 0; | 308 | ctx->in_flags = 0; |
309 | ctx->mq = NULL; | 309 | ctx->mq = NULL; |
310 | ctx->to_channel = NULL; | 310 | ctx->to_channel = NULL; |
311 | ctx->from_channel = NULL; | 311 | ctx->from_channel = NULL; |
312 | (void) GNUNET_CONTAINER_multipeermap_put( peer_map, peer, ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 312 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
313 | } | 313 | } |
314 | } | ||
315 | |||
316 | /** | ||
317 | * Get the context of a peer. If not existing, create. | ||
318 | */ | ||
319 | struct peer_context * | ||
320 | get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) | ||
321 | { | ||
322 | struct peer_context *ctx; | ||
323 | |||
324 | touch_peer_ctx(peer_map, peer); | ||
325 | ctx = GNUNET_CONTAINER_multipeermap_get(peer_map, peer); | ||
326 | return ctx; | 314 | return ctx; |
327 | } | 315 | } |
328 | 316 | ||
317 | |||
329 | /** | 318 | /** |
330 | * Get the channel of a peer. If not existing, create. | 319 | * Get the channel of a peer. If not existing, create. |
331 | */ | 320 | */ |
332 | void | 321 | struct GNUNET_CADET_Channel * |
333 | touch_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) | 322 | get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) |
334 | { | 323 | { |
335 | struct peer_context *ctx; | 324 | struct peer_context *ctx; |
336 | 325 | ||
337 | ctx = get_peer_ctx (peer_map, peer); | 326 | ctx = get_peer_ctx (peer_map, peer); |
338 | if (NULL == ctx->to_channel) | 327 | if (NULL == ctx->to_channel) |
339 | { | 328 | { |
340 | ctx->to_channel = GNUNET_CADET_channel_create(cadet_handle, NULL, peer, | 329 | ctx->to_channel = GNUNET_CADET_channel_create (cadet_handle, NULL, peer, |
341 | GNUNET_RPS_CADET_PORT, | 330 | GNUNET_RPS_CADET_PORT, |
342 | GNUNET_CADET_OPTION_RELIABLE); | 331 | GNUNET_CADET_OPTION_RELIABLE); |
343 | // do I have to explicitly put it in the peer_map? | 332 | // do I have to explicitly put it in the peer_map? |
344 | GNUNET_CONTAINER_multipeermap_put(peer_map, peer, ctx, | 333 | GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, |
345 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 334 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
346 | } | 335 | } |
347 | } | ||
348 | |||
349 | /** | ||
350 | * Get the channel of a peer. If not existing, create. | ||
351 | */ | ||
352 | struct GNUNET_CADET_Channel * | ||
353 | get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) | ||
354 | { | ||
355 | struct peer_context *ctx; | ||
356 | |||
357 | ctx = get_peer_ctx (peer_map, peer); | ||
358 | touch_channel(peer_map, peer); | ||
359 | return ctx->to_channel; | 336 | return ctx->to_channel; |
360 | } | 337 | } |
361 | 338 | ||
362 | /** | ||
363 | * Make sure the mq for a given peer exists. | ||
364 | * | ||
365 | * If we already have a message queue open to this client, | ||
366 | * simply return it, otherways create one. | ||
367 | */ | ||
368 | void | ||
369 | touch_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer_id) | ||
370 | { | ||
371 | struct peer_context *ctx; | ||
372 | |||
373 | ctx = get_peer_ctx(peer_map, peer_id); | ||
374 | if (NULL == ctx->mq) | ||
375 | { | ||
376 | touch_channel(peer_map, peer_id); | ||
377 | ctx->mq = GNUNET_CADET_mq_create(ctx->to_channel); | ||
378 | //do I have to explicitly put it in the peer_map? | ||
379 | GNUNET_CONTAINER_multipeermap_put(peer_map, peer_id, ctx, | ||
380 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | ||
381 | } | ||
382 | } | ||
383 | 339 | ||
384 | /** | 340 | /** |
385 | * Get the message queue of a specific peer. | 341 | * Get the message queue of a specific peer. |
@@ -392,12 +348,19 @@ get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_Peer | |||
392 | { | 348 | { |
393 | struct peer_context *ctx; | 349 | struct peer_context *ctx; |
394 | 350 | ||
395 | ctx = get_peer_ctx(peer_map, peer_id); | 351 | ctx = get_peer_ctx (peer_map, peer_id); |
396 | touch_mq(peer_map, peer_id); | 352 | if (NULL == ctx->mq) |
397 | 353 | { | |
354 | (void) get_channel (peer_map, peer_id); | ||
355 | ctx->mq = GNUNET_CADET_mq_create (ctx->to_channel); | ||
356 | //do I have to explicitly put it in the peer_map? | ||
357 | GNUNET_CONTAINER_multipeermap_put (peer_map, peer_id, ctx, | ||
358 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | ||
359 | } | ||
398 | return ctx->mq; | 360 | return ctx->mq; |
399 | } | 361 | } |
400 | 362 | ||
363 | |||
401 | /*********************************************************************** | 364 | /*********************************************************************** |
402 | * /Util functions | 365 | * /Util functions |
403 | ***********************************************************************/ | 366 | ***********************************************************************/ |
@@ -797,7 +760,7 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
797 | insertCB (void *cls, const struct GNUNET_PeerIdentity *id) | 760 | insertCB (void *cls, const struct GNUNET_PeerIdentity *id) |
798 | { | 761 | { |
799 | // We open a channel to be notified when this peer goes down. | 762 | // We open a channel to be notified when this peer goes down. |
800 | touch_channel (peer_map, id); | 763 | (void) get_channel (peer_map, id); |
801 | } | 764 | } |
802 | 765 | ||
803 | /** | 766 | /** |
@@ -856,7 +819,7 @@ init_peer_cb (void *cls, | |||
856 | "Got %" PRIX32 ". peer %s (at %p) from CADET (gossip_list_size: %u)\n", | 819 | "Got %" PRIX32 ". peer %s (at %p) from CADET (gossip_list_size: %u)\n", |
857 | ipc->i, GNUNET_i2s (peer), peer, gossip_list_size); | 820 | ipc->i, GNUNET_i2s (peer), peer, gossip_list_size); |
858 | RPS_sampler_update_list (peer); | 821 | RPS_sampler_update_list (peer); |
859 | touch_peer_ctx (peer_map, peer); // unneeded? -> insertCB | 822 | (void) get_peer_ctx (peer_map, peer); // unneeded? -> insertCB |
860 | 823 | ||
861 | if (ipc->i < gossip_list_size) | 824 | if (ipc->i < gossip_list_size) |
862 | { | 825 | { |