aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-10-25 23:22:33 +0000
committerChristian Grothoff <christian@grothoff.org>2015-10-25 23:22:33 +0000
commit124f3e77a5e022f5f7ab49df49023d0080bcbbb4 (patch)
tree2c88e59709c52594d2c98c6df52671419c957162 /src/fs
parent8306257cfea6b5ca5d7cd0119b8d1369f422a07f (diff)
downloadgnunet-124f3e77a5e022f5f7ab49df49023d0080bcbbb4.tar.gz
gnunet-124f3e77a5e022f5f7ab49df49023d0080bcbbb4.zip
-reduce calls in get_latest()
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/gnunet-service-fs.c11
-rw-r--r--src/fs/gnunet-service-fs_cp.c8
-rw-r--r--src/fs/gnunet-service-fs_pe.c15
-rw-r--r--src/fs/gnunet-service-fs_pr.c34
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,
355{ 355{
356 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) 356 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
357 return; /* we're done... */ 357 return; /* we're done... */
358 GSF_iterate_connected_peers_ (&consider_request_for_forwarding, pr); 358 GSF_iterate_connected_peers_ (&consider_request_for_forwarding,
359 pr);
359} 360}
360 361
361 362
@@ -376,12 +377,14 @@ handle_p2p_get (void *cls,
376{ 377{
377 struct GSF_PendingRequest *pr; 378 struct GSF_PendingRequest *pr;
378 379
379 pr = GSF_handle_p2p_query_ (other, message); 380 pr = GSF_handle_p2p_query_ (other,
381 message);
380 if (NULL == pr) 382 if (NULL == pr)
381 return GNUNET_SYSERR; 383 return GNUNET_OK; /* exists, identical to existing request, or malformed */
382 GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES; 384 GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
383 GSF_local_lookup_ (pr, 385 GSF_local_lookup_ (pr,
384 &consider_forwarding, NULL); 386 &consider_forwarding,
387 NULL);
385 return GNUNET_OK; 388 return GNUNET_OK;
386} 389}
387 390
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)
1160 * 1160 *
1161 * @param ttl_in requested ttl 1161 * @param ttl_in requested ttl
1162 * @param prio given priority 1162 * @param prio given priority
1163 * @return ttl_in if ttl_in is below the limit, 1163 * @return @a ttl_in if @a ttl_in is below the limit,
1164 * otherwise the ttl-limit for the given priority 1164 * otherwise the ttl-limit for the given @a prio
1165 */ 1165 */
1166static int32_t 1166static int32_t
1167bound_ttl (int32_t ttl_in, uint32_t prio) 1167bound_ttl (int32_t ttl_in,
1168 uint32_t prio)
1168{ 1169{
1169 unsigned long long allowed; 1170 unsigned long long allowed;
1170 1171
@@ -1257,7 +1258,6 @@ test_exist_cb (void *cls,
1257} 1258}
1258 1259
1259 1260
1260
1261/** 1261/**
1262 * Handle P2P "QUERY" message. Creates the pending request entry 1262 * Handle P2P "QUERY" message. Creates the pending request entry
1263 * and sets up all of the data structures to that we will 1263 * 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)
355{ 355{
356 struct GSF_PendingRequest *ret; 356 struct GSF_PendingRequest *ret;
357 struct GSF_PendingRequestPlanBijection *bi; 357 struct GSF_PendingRequestPlanBijection *bi;
358 const struct GSF_PendingRequestData *rprd;
359 const struct GSF_PendingRequestData *prd;
358 360
359 bi = rp->pe_head; 361 bi = rp->pe_head;
360 if (NULL == bi) 362 if (NULL == bi)
361 return NULL; /* should never happen */ 363 return NULL; /* should never happen */
362 ret = bi->pr; 364 ret = bi->pr;
363 bi = bi->next_PE; 365 rprd = GSF_pending_request_get_data_ (ret);
364 while (NULL != bi) 366 for (bi = bi->next_PE; NULL != bi; bi = bi->next_PE)
365 { 367 {
366 if (GSF_pending_request_get_data_ (bi->pr)->ttl.abs_value_us > 368 prd = GSF_pending_request_get_data_ (bi->pr);
367 GSF_pending_request_get_data_ (ret)->ttl.abs_value_us) 369 if (prd->ttl.abs_value_us >
370 rprd->ttl.abs_value_us)
371 {
368 ret = bi->pr; 372 ret = bi->pr;
369 bi = bi->next_PE; 373 rprd = prd;
374 }
370 } 375 }
371 return ret; 376 return ret;
372} 377}
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,
290 const struct GNUNET_HashCode *query, 290 const struct GNUNET_HashCode *query,
291 const struct GNUNET_PeerIdentity *target, 291 const struct GNUNET_PeerIdentity *target,
292 const char *bf_data, size_t bf_size, 292 const char *bf_data, size_t bf_size,
293 uint32_t mingle, uint32_t anonymity_level, 293 uint32_t mingle,
294 uint32_t priority, int32_t ttl, 294 uint32_t anonymity_level,
295 uint32_t priority,
296 int32_t ttl,
295 GNUNET_PEER_Id sender_pid, 297 GNUNET_PEER_Id sender_pid,
296 GNUNET_PEER_Id origin_pid, 298 GNUNET_PEER_Id origin_pid,
297 const struct GNUNET_HashCode *replies_seen, 299 const struct GNUNET_HashCode *replies_seen,
298 unsigned int replies_seen_count, 300 unsigned int replies_seen_count,
299 GSF_PendingRequestReplyHandler rh, void *rh_cls) 301 GSF_PendingRequestReplyHandler rh,
302 void *rh_cls)
300{ 303{
301 struct GSF_PendingRequest *pr; 304 struct GSF_PendingRequest *pr;
302 struct GSF_PendingRequest *dpr; 305 struct GSF_PendingRequest *dpr;
@@ -351,14 +354,16 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
351 pr->replies_seen_size = replies_seen_count; 354 pr->replies_seen_size = replies_seen_count;
352 pr->replies_seen = 355 pr->replies_seen =
353 GNUNET_malloc (sizeof (struct GNUNET_HashCode) * pr->replies_seen_size); 356 GNUNET_malloc (sizeof (struct GNUNET_HashCode) * pr->replies_seen_size);
354 memcpy (pr->replies_seen, replies_seen, 357 memcpy (pr->replies_seen,
358 replies_seen,
355 replies_seen_count * sizeof (struct GNUNET_HashCode)); 359 replies_seen_count * sizeof (struct GNUNET_HashCode));
356 pr->replies_seen_count = replies_seen_count; 360 pr->replies_seen_count = replies_seen_count;
357 } 361 }
358 if (NULL != bf_data) 362 if (NULL != bf_data)
359 { 363 {
360 pr->bf = 364 pr->bf =
361 GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size, 365 GNUNET_CONTAINER_bloomfilter_init (bf_data,
366 bf_size,
362 GNUNET_CONSTANTS_BLOOMFILTER_K); 367 GNUNET_CONSTANTS_BLOOMFILTER_K);
363 pr->mingle = mingle; 368 pr->mingle = mingle;
364 } 369 }
@@ -368,26 +373,33 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
368 refresh_bloomfilter (pr); 373 refresh_bloomfilter (pr);
369 } 374 }
370 GNUNET_CONTAINER_multihashmap_put (pr_map, 375 GNUNET_CONTAINER_multihashmap_put (pr_map,
371 &pr->public_data.query, pr, 376 &pr->public_data.query,
377 pr,
372 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 378 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
373 if (0 == (options & GSF_PRO_REQUEST_NEVER_EXPIRES)) 379 if (0 == (options & GSF_PRO_REQUEST_NEVER_EXPIRES))
374 { 380 {
375 pr->hnode = 381 pr->hnode =
376 GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap, pr, 382 GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap,
383 pr,
377 pr->public_data.ttl.abs_value_us); 384 pr->public_data.ttl.abs_value_us);
378 /* make sure we don't track too many requests */ 385 /* make sure we don't track too many requests */
379 while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) > 386 while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) >
380 max_pending_requests) 387 max_pending_requests)
381 { 388 {
382 dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap); 389 dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap);
383 GNUNET_assert (dpr != NULL); 390 GNUNET_assert (NULL != dpr);
384 if (pr == dpr) 391 if (pr == dpr)
385 break; /* let the request live briefly... */ 392 break; /* let the request live briefly... */
386 if (NULL != dpr->rh) 393 if (NULL != dpr->rh)
387 dpr->rh (dpr->rh_cls, GNUNET_BLOCK_EVALUATION_REQUEST_VALID, dpr, 394 dpr->rh (dpr->rh_cls,
388 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_ABS, 395 GNUNET_BLOCK_EVALUATION_REQUEST_VALID,
396 dpr,
397 UINT32_MAX,
398 GNUNET_TIME_UNIT_FOREVER_ABS,
399 GNUNET_TIME_UNIT_FOREVER_ABS,
389 GNUNET_BLOCK_TYPE_ANY, NULL, 0); 400 GNUNET_BLOCK_TYPE_ANY, NULL, 0);
390 GSF_pending_request_cancel_ (dpr, GNUNET_YES); 401 GSF_pending_request_cancel_ (dpr,
402 GNUNET_YES);
391 } 403 }
392 } 404 }
393 GNUNET_STATISTICS_update (GSF_stats, 405 GNUNET_STATISTICS_update (GSF_stats,