From 3d8c1be931ffa54a86ea66cc5c981eb651ea50b4 Mon Sep 17 00:00:00 2001 From: Julius Bünger Date: Wed, 7 Jan 2015 17:27:15 +0000 Subject: got rid of touch_*() --- src/rps/gnunet-service-rps.c | 91 +++++++++++++------------------------------- 1 file changed, 27 insertions(+), 64 deletions(-) (limited to 'src/rps') 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 /** - * Make sure the context of a given peer exists in the given peer_map. + * Get the context of a peer. If not existing, create. */ - void -touch_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) + struct peer_context * +get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) { struct peer_context *ctx; - if ( GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains( peer_map, peer ) ) + if ( GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) { - ctx = GNUNET_CONTAINER_multipeermap_get(peer_map, peer); + ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer); } else { - ctx = GNUNET_new(struct peer_context); + ctx = GNUNET_new (struct peer_context); ctx->in_flags = 0; ctx->mq = NULL; ctx->to_channel = NULL; ctx->from_channel = NULL; - (void) GNUNET_CONTAINER_multipeermap_put( peer_map, peer, ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); } -} - -/** - * Get the context of a peer. If not existing, create. - */ - struct peer_context * -get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) -{ - struct peer_context *ctx; - - touch_peer_ctx(peer_map, peer); - ctx = GNUNET_CONTAINER_multipeermap_get(peer_map, peer); return ctx; } + /** * Get the channel of a peer. If not existing, create. */ - void -touch_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) + struct GNUNET_CADET_Channel * +get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) { struct peer_context *ctx; ctx = get_peer_ctx (peer_map, peer); if (NULL == ctx->to_channel) { - ctx->to_channel = GNUNET_CADET_channel_create(cadet_handle, NULL, peer, - GNUNET_RPS_CADET_PORT, - GNUNET_CADET_OPTION_RELIABLE); + ctx->to_channel = GNUNET_CADET_channel_create (cadet_handle, NULL, peer, + GNUNET_RPS_CADET_PORT, + GNUNET_CADET_OPTION_RELIABLE); // do I have to explicitly put it in the peer_map? - GNUNET_CONTAINER_multipeermap_put(peer_map, peer, ctx, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); + GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); } -} - -/** - * Get the channel of a peer. If not existing, create. - */ - struct GNUNET_CADET_Channel * -get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) -{ - struct peer_context *ctx; - - ctx = get_peer_ctx (peer_map, peer); - touch_channel(peer_map, peer); return ctx->to_channel; } -/** - * Make sure the mq for a given peer exists. - * - * If we already have a message queue open to this client, - * simply return it, otherways create one. - */ - void -touch_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer_id) -{ - struct peer_context *ctx; - - ctx = get_peer_ctx(peer_map, peer_id); - if (NULL == ctx->mq) - { - touch_channel(peer_map, peer_id); - ctx->mq = GNUNET_CADET_mq_create(ctx->to_channel); - //do I have to explicitly put it in the peer_map? - GNUNET_CONTAINER_multipeermap_put(peer_map, peer_id, ctx, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); - } -} /** * Get the message queue of a specific peer. @@ -392,12 +348,19 @@ get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_Peer { struct peer_context *ctx; - ctx = get_peer_ctx(peer_map, peer_id); - touch_mq(peer_map, peer_id); - + ctx = get_peer_ctx (peer_map, peer_id); + if (NULL == ctx->mq) + { + (void) get_channel (peer_map, peer_id); + ctx->mq = GNUNET_CADET_mq_create (ctx->to_channel); + //do I have to explicitly put it in the peer_map? + GNUNET_CONTAINER_multipeermap_put (peer_map, peer_id, ctx, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); + } return ctx->mq; } + /*********************************************************************** * /Util functions ***********************************************************************/ @@ -797,7 +760,7 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) insertCB (void *cls, const struct GNUNET_PeerIdentity *id) { // We open a channel to be notified when this peer goes down. - touch_channel (peer_map, id); + (void) get_channel (peer_map, id); } /** @@ -856,7 +819,7 @@ init_peer_cb (void *cls, "Got %" PRIX32 ". peer %s (at %p) from CADET (gossip_list_size: %u)\n", ipc->i, GNUNET_i2s (peer), peer, gossip_list_size); RPS_sampler_update_list (peer); - touch_peer_ctx (peer_map, peer); // unneeded? -> insertCB + (void) get_peer_ctx (peer_map, peer); // unneeded? -> insertCB if (ipc->i < gossip_list_size) { -- cgit v1.2.3