From 124f3e77a5e022f5f7ab49df49023d0080bcbbb4 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 25 Oct 2015 23:22:33 +0000 Subject: [PATCH] -reduce calls in get_latest() --- src/fs/gnunet-service-fs.c | 11 +++++++---- src/fs/gnunet-service-fs_cp.c | 8 ++++---- src/fs/gnunet-service-fs_pe.c | 15 ++++++++++----- src/fs/gnunet-service-fs_pr.c | 34 +++++++++++++++++++++++----------- 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index a4300a4ce..b4f336a6c 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -355,7 +355,8 @@ consider_forwarding (void *cls, { if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) return; /* we're done... */ - GSF_iterate_connected_peers_ (&consider_request_for_forwarding, pr); + GSF_iterate_connected_peers_ (&consider_request_for_forwarding, + pr); } @@ -376,12 +377,14 @@ handle_p2p_get (void *cls, { struct GSF_PendingRequest *pr; - pr = GSF_handle_p2p_query_ (other, message); + pr = GSF_handle_p2p_query_ (other, + message); if (NULL == pr) - return GNUNET_SYSERR; + return GNUNET_OK; /* exists, identical to existing request, or malformed */ GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES; GSF_local_lookup_ (pr, - &consider_forwarding, NULL); + &consider_forwarding, + NULL); return GNUNET_OK; } diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index 8fb2d2a3a..7066b0698 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c @@ -1160,11 +1160,12 @@ bound_priority (uint32_t prio_in, struct GSF_ConnectedPeer *cp) * * @param ttl_in requested ttl * @param prio given priority - * @return ttl_in if ttl_in is below the limit, - * otherwise the ttl-limit for the given priority + * @return @a ttl_in if @a ttl_in is below the limit, + * otherwise the ttl-limit for the given @a prio */ static int32_t -bound_ttl (int32_t ttl_in, uint32_t prio) +bound_ttl (int32_t ttl_in, + uint32_t prio) { unsigned long long allowed; @@ -1257,7 +1258,6 @@ test_exist_cb (void *cls, } - /** * Handle P2P "QUERY" message. Creates the pending request entry * and sets up all of the data structures to that we will diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c index beb435c0c..ede109c2d 100644 --- a/src/fs/gnunet-service-fs_pe.c +++ b/src/fs/gnunet-service-fs_pe.c @@ -355,18 +355,23 @@ get_latest (const struct GSF_RequestPlan *rp) { struct GSF_PendingRequest *ret; struct GSF_PendingRequestPlanBijection *bi; + const struct GSF_PendingRequestData *rprd; + const struct GSF_PendingRequestData *prd; bi = rp->pe_head; if (NULL == bi) return NULL; /* should never happen */ ret = bi->pr; - bi = bi->next_PE; - while (NULL != bi) + rprd = GSF_pending_request_get_data_ (ret); + for (bi = bi->next_PE; NULL != bi; bi = bi->next_PE) { - if (GSF_pending_request_get_data_ (bi->pr)->ttl.abs_value_us > - GSF_pending_request_get_data_ (ret)->ttl.abs_value_us) + prd = GSF_pending_request_get_data_ (bi->pr); + if (prd->ttl.abs_value_us > + rprd->ttl.abs_value_us) + { ret = bi->pr; - bi = bi->next_PE; + rprd = prd; + } } return ret; } diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index 298532520..b507992b4 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c @@ -290,13 +290,16 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, const struct GNUNET_HashCode *query, const struct GNUNET_PeerIdentity *target, const char *bf_data, size_t bf_size, - uint32_t mingle, uint32_t anonymity_level, - uint32_t priority, int32_t ttl, + uint32_t mingle, + uint32_t anonymity_level, + uint32_t priority, + int32_t ttl, GNUNET_PEER_Id sender_pid, GNUNET_PEER_Id origin_pid, const struct GNUNET_HashCode *replies_seen, unsigned int replies_seen_count, - GSF_PendingRequestReplyHandler rh, void *rh_cls) + GSF_PendingRequestReplyHandler rh, + void *rh_cls) { struct GSF_PendingRequest *pr; struct GSF_PendingRequest *dpr; @@ -351,14 +354,16 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, pr->replies_seen_size = replies_seen_count; pr->replies_seen = GNUNET_malloc (sizeof (struct GNUNET_HashCode) * pr->replies_seen_size); - memcpy (pr->replies_seen, replies_seen, + memcpy (pr->replies_seen, + replies_seen, replies_seen_count * sizeof (struct GNUNET_HashCode)); pr->replies_seen_count = replies_seen_count; } if (NULL != bf_data) { pr->bf = - GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size, + GNUNET_CONTAINER_bloomfilter_init (bf_data, + bf_size, GNUNET_CONSTANTS_BLOOMFILTER_K); pr->mingle = mingle; } @@ -368,26 +373,33 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, refresh_bloomfilter (pr); } GNUNET_CONTAINER_multihashmap_put (pr_map, - &pr->public_data.query, pr, + &pr->public_data.query, + pr, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); if (0 == (options & GSF_PRO_REQUEST_NEVER_EXPIRES)) { pr->hnode = - GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap, pr, + GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap, + pr, pr->public_data.ttl.abs_value_us); /* make sure we don't track too many requests */ while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) > max_pending_requests) { dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap); - GNUNET_assert (dpr != NULL); + GNUNET_assert (NULL != dpr); if (pr == dpr) break; /* let the request live briefly... */ if (NULL != dpr->rh) - dpr->rh (dpr->rh_cls, GNUNET_BLOCK_EVALUATION_REQUEST_VALID, dpr, - UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_ABS, + dpr->rh (dpr->rh_cls, + GNUNET_BLOCK_EVALUATION_REQUEST_VALID, + dpr, + UINT32_MAX, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_BLOCK_TYPE_ANY, NULL, 0); - GSF_pending_request_cancel_ (dpr, GNUNET_YES); + GSF_pending_request_cancel_ (dpr, + GNUNET_YES); } } GNUNET_STATISTICS_update (GSF_stats, -- 2.25.1