aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-07-18 12:26:34 +0000
committerChristian Grothoff <christian@grothoff.org>2012-07-18 12:26:34 +0000
commite59aabf0eb8ce56d3414254ab9c7b6cc90dd05c3 (patch)
tree86c124c147254f165b64453aa7d8f4f30f42ed42 /src/dht
parent09addded5bf92db20b1f7c5a56b103f31147953b (diff)
downloadgnunet-e59aabf0eb8ce56d3414254ab9c7b6cc90dd05c3.tar.gz
gnunet-e59aabf0eb8ce56d3414254ab9c7b6cc90dd05c3.zip
-trying to fix high CPU load caused by DHT
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-dht_routing.c58
1 files changed, 55 insertions, 3 deletions
diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c
index c1dca4e21..796991b5b 100644
--- a/src/dht/gnunet-service-dht_routing.c
+++ b/src/dht/gnunet-service-dht_routing.c
@@ -322,6 +322,48 @@ expire_oldest_entry ()
322} 322}
323 323
324 324
325/**
326 * Try to combine multiple recent requests for the same value
327 * (if they come from the same peer).
328 *
329 * @param cls the new 'struct RecentRequest' (to discard upon successful combination)
330 * @param key the query
331 * @param value the existing 'struct RecentRequest' (to update upon successful combination)
332 * @return GNUNET_OK (continue to iterate),
333 * GNUNET_SYSERR if the request was successfully combined
334 */
335static int
336try_combine_recent (void *cls, const struct GNUNET_HashCode * key, void *value)
337{
338 struct RecentRequest *in = cls;
339 struct RecentRequest *rr = value;
340
341 if ( (0 != memcmp (&in->peer,
342 &rr->peer,
343 sizeof (struct GNUNET_PeerIdentity))) ||
344 (in->type != rr->type) ||
345 (in->xquery_size != rr->xquery_size) ||
346 (0 != memcmp (in->xquery,
347 rr->xquery,
348 in->xquery_size)) )
349 return GNUNET_OK;
350 if (in->reply_bf_mutator != rr->reply_bf_mutator)
351 {
352 rr->reply_bf_mutator = in->reply_bf_mutator;
353 GNUNET_CONTAINER_bloomfilter_free (rr->reply_bf);
354 rr->reply_bf = in->reply_bf;
355 }
356 else
357 {
358 GNUNET_CONTAINER_bloomfilter_or2 (rr->reply_bf,
359 in->reply_bf,
360 GNUNET_CONTAINER_bloomfilter_get_size (in->reply_bf));
361 GNUNET_CONTAINER_bloomfilter_free (in->reply_bf);
362 }
363 GNUNET_free (in);
364 return GNUNET_SYSERR;
365}
366
325 367
326/** 368/**
327 * Add a new entry to our routing table. 369 * Add a new entry to our routing table.
@@ -354,15 +396,25 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
354 recent_req = GNUNET_malloc (sizeof (struct RecentRequest) + xquery_size); 396 recent_req = GNUNET_malloc (sizeof (struct RecentRequest) + xquery_size);
355 recent_req->peer = *sender; 397 recent_req->peer = *sender;
356 recent_req->key = *key; 398 recent_req->key = *key;
357 recent_req->heap_node =
358 GNUNET_CONTAINER_heap_insert (recent_heap, recent_req,
359 GNUNET_TIME_absolute_get ().abs_value);
360 recent_req->reply_bf = GNUNET_CONTAINER_bloomfilter_copy (reply_bf); 399 recent_req->reply_bf = GNUNET_CONTAINER_bloomfilter_copy (reply_bf);
361 recent_req->type = type; 400 recent_req->type = type;
362 recent_req->options = options; 401 recent_req->options = options;
363 recent_req->xquery = &recent_req[1]; 402 recent_req->xquery = &recent_req[1];
364 recent_req->xquery_size = xquery_size; 403 recent_req->xquery_size = xquery_size;
365 recent_req->reply_bf_mutator = reply_bf_mutator; 404 recent_req->reply_bf_mutator = reply_bf_mutator;
405 if (GNUNET_SYSERR ==
406 GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, key,
407 &try_combine_recent, recent_req))
408 {
409 GNUNET_STATISTICS_update (GDS_stats,
410 gettext_noop
411 ("# DHT requests combined"),
412 1, GNUNET_NO);
413 return;
414 }
415 recent_req->heap_node =
416 GNUNET_CONTAINER_heap_insert (recent_heap, recent_req,
417 GNUNET_TIME_absolute_get ().abs_value);
366 GNUNET_CONTAINER_multihashmap_put (recent_map, key, recent_req, 418 GNUNET_CONTAINER_multihashmap_put (recent_map, key, recent_req,
367 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 419 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
368 420