summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-09-27 09:58:15 +0000
committerChristian Grothoff <christian@grothoff.org>2011-09-27 09:58:15 +0000
commitedab319f07cc940f64111b6e89da245a2afcf71a (patch)
tree20124181cbcc8e0e36d98b448369b7e62a1b0192
parent4f3f80d05ac7101b8049c352d70abe97bc81ab23 (diff)
downloadgnunet-edab319f07cc940f64111b6e89da245a2afcf71a.tar.gz
gnunet-edab319f07cc940f64111b6e89da245a2afcf71a.zip
making some files compile
-rw-r--r--src/dht/gnunet-service-dht.h5
-rw-r--r--src/dht/gnunet-service-dht_datacache.c67
-rw-r--r--src/dht/gnunet-service-dht_datacache.h3
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c354
-rw-r--r--src/dht/gnunet-service-dht_neighbours.h8
-rw-r--r--src/dht/gnunet-service-dht_nse.c11
-rw-r--r--src/dht/gnunet-service-dht_nse.h12
-rw-r--r--src/dht/gnunet-service-dht_routing.c32
8 files changed, 303 insertions, 189 deletions
diff --git a/src/dht/gnunet-service-dht.h b/src/dht/gnunet-service-dht.h
index 04f3e9fb3..cacc00971 100644
--- a/src/dht/gnunet-service-dht.h
+++ b/src/dht/gnunet-service-dht.h
@@ -46,11 +46,6 @@ extern struct GNUNET_BLOCK_Context *GDS_block_context;
46extern struct GNUNET_STATISTICS_Handle *GDS_stats; 46extern struct GNUNET_STATISTICS_Handle *GDS_stats;
47 47
48/** 48/**
49 * The identity of our peer.
50 */
51extern struct GNUNET_PeerIdentity GDS_my_identity;
52
53/**
54 * Our HELLO 49 * Our HELLO
55 */ 50 */
56extern struct GNUNET_MessageHeader *GDS_my_hello; 51extern struct GNUNET_MessageHeader *GDS_my_hello;
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c
index 2c1a3fe20..fc1983419 100644
--- a/src/dht/gnunet-service-dht_datacache.c
+++ b/src/dht/gnunet-service-dht_datacache.c
@@ -24,7 +24,12 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * @author Nathan Evans 25 * @author Nathan Evans
26 */ 26 */
27#include "platform.h"
28#include "gnunet_datacache_lib.h"
29#include "gnunet-service-dht_clients.h"
27#include "gnunet-service-dht_datacache.h" 30#include "gnunet-service-dht_datacache.h"
31#include "gnunet-service-dht_routing.h"
32#include "gnunet-service-dht.h"
28 33
29 34
30/** 35/**
@@ -80,7 +85,6 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
80 char buf[plen]; 85 char buf[plen];
81 struct DHTPutEntry *pe; 86 struct DHTPutEntry *pe;
82 struct GNUNET_PeerIdentity *pp; 87 struct GNUNET_PeerIdentity *pp;
83 char *path_offset;
84 88
85 if (datacache == NULL) 89 if (datacache == NULL)
86 { 90 {
@@ -162,32 +166,32 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
162 struct GetRequestContext *ctx = cls; 166 struct GetRequestContext *ctx = cls;
163 const struct DHTPutEntry *pe; 167 const struct DHTPutEntry *pe;
164 const struct GNUNET_PeerIdentity *pp; 168 const struct GNUNET_PeerIdentity *pp;
165 const char *data; 169 const char *rdata;
166 size_t data_size; 170 size_t rdata_size;
167 uint16_t put_path_length; 171 uint16_t put_path_length;
168 enum GNUNET_BLOCK_EvaluationResult eval; 172 enum GNUNET_BLOCK_EvaluationResult eval;
169 173
170 pe = (const struct DHTPutEntry *) data; 174 pe = (const struct DHTPutEntry *) data;
171 put_path_length = ntohs (pe->path_length); 175 put_path_length = ntohs (pe->path_length);
172 data_size = ntohs (pe->data_size); 176 rdata_size = ntohs (pe->data_size);
173 177
174 if (size != 178 if (size !=
175 sizeof (struct DHTPutEntry) + data_size + 179 sizeof (struct DHTPutEntry) + rdata_size +
176 (put_path_length * sizeof (struct GNUNET_PeerIdentity))) 180 (put_path_length * sizeof (struct GNUNET_PeerIdentity)))
177 { 181 {
178 GNUNET_break (0); 182 GNUNET_break (0);
179 return GNUNET_OK; 183 return GNUNET_OK;
180 } 184 }
181 pp = (const struct GNUNET_PeerIdentity *) &pe[1]; 185 pp = (const struct GNUNET_PeerIdentity *) &pe[1];
182 data = (const char*) &pp[put_path_length]; 186 rdata = (const char*) &pp[put_path_length];
183 eval = 187 eval =
184 GNUNET_BLOCK_evaluate (block_context, type, key, 188 GNUNET_BLOCK_evaluate (GDS_block_context, type, key,
185 ctx->reply_bf, 189 ctx->reply_bf,
186 ctx->reply_bf_mutator, 190 ctx->reply_bf_mutator,
187 ctx->xquery, 191 ctx->xquery,
188 ctx->xquery_size, 192 ctx->xquery_size,
189 data, 193 rdata,
190 data_size); 194 rdata_size);
191 switch (eval) 195 switch (eval)
192 { 196 {
193 case GNUNET_BLOCK_EVALUATION_OK_LAST: 197 case GNUNET_BLOCK_EVALUATION_OK_LAST:
@@ -197,11 +201,11 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
197 key, 201 key,
198 0, NULL, 202 0, NULL,
199 put_path_length, pp, 203 put_path_length, pp,
200 type, data_size, data); 204 type, rdata_size, rdata);
201 /* forward to other peers */ 205 /* forward to other peers */
202 GDS_NEIGHBOURS_handle_reply (type, exp, 206 GDS_ROUTING_process (type, exp,
203 key, put_path_length, pp, 207 key, put_path_length, pp,
204 0, NULL, data, data_size); 208 0, NULL, rdata, rdata_size);
205 break; 209 break;
206 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 210 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
207 break; 211 break;
@@ -224,39 +228,6 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
224 228
225 229
226/** 230/**
227 * Context containing information about a GET request.
228 */
229struct GetRequestContext
230{
231 /**
232 * extended query (see gnunet_block_lib.h).
233 */
234 const void *xquery;
235
236 /**
237 * Bloomfilter to filter out duplicate replies (updated)
238 */
239 struct GNUNET_CONTAINER_BloomFilter **reply_bf;
240
241 /**
242 * The key this request was about
243 */
244 GNUNET_HashCode key;
245
246 /**
247 * Number of bytes in xquery.
248 */
249 size_t xquery_size;
250
251 /**
252 * Mutator value for the reply_bf, see gnunet_block_lib.h
253 */
254 uint32_t reply_bf_mutator;
255
256};
257
258
259/**
260 * Handle a GET request we've received from another peer. 231 * Handle a GET request we've received from another peer.
261 * 232 *
262 * @param key the query 233 * @param key the query
@@ -283,7 +254,7 @@ GDS_DATACACHE_handle_get (const GNUNET_HashCode *key,
283 ctx.xquery_size = xquery_size; 254 ctx.xquery_size = xquery_size;
284 ctx.reply_bf = reply_bf; 255 ctx.reply_bf = reply_bf;
285 ctx.reply_bf_mutator = reply_bf_mutator; 256 ctx.reply_bf_mutator = reply_bf_mutator;
286 (void) GNUNET_DATACACHE_get (datacache, &msg_ctx->key, type, 257 (void) GNUNET_DATACACHE_get (datacache, key, type,
287 &datacache_get_iterator, &ctx); 258 &datacache_get_iterator, &ctx);
288} 259}
289 260
@@ -294,7 +265,7 @@ GDS_DATACACHE_handle_get (const GNUNET_HashCode *key,
294void 265void
295GDS_DATACACHE_init () 266GDS_DATACACHE_init ()
296{ 267{
297 datacache = GNUNET_DATACACHE_create (cfg, "dhtcache"); 268 datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache");
298} 269}
299 270
300 271
diff --git a/src/dht/gnunet-service-dht_datacache.h b/src/dht/gnunet-service-dht_datacache.h
index ecb3a24a1..dce15bd7d 100644
--- a/src/dht/gnunet-service-dht_datacache.h
+++ b/src/dht/gnunet-service-dht_datacache.h
@@ -27,6 +27,9 @@
27#ifndef GNUNET_SERVICE_DHT_DATACACHE_H 27#ifndef GNUNET_SERVICE_DHT_DATACACHE_H
28#define GNUNET_SERVICE_DHT_DATACACHE_H 28#define GNUNET_SERVICE_DHT_DATACACHE_H
29 29
30#include "gnunet_util_lib.h"
31#include "gnunet_block_lib.h"
32
30/** 33/**
31 * Handle a datum we've received from another peer. Cache if 34 * Handle a datum we've received from another peer. Cache if
32 * possible. 35 * possible.
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 8a566ec0e..2ce50a11d 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -37,7 +37,10 @@
37#include "gnunet_dht_service.h" 37#include "gnunet_dht_service.h"
38#include "gnunet_statistics_service.h" 38#include "gnunet_statistics_service.h"
39#include "dht.h" 39#include "dht.h"
40#include "gnunet-service-dht.h"
41#include "gnunet-service-dht_clients.h"
40#include "gnunet-service-dht_datacache.h" 42#include "gnunet-service-dht_datacache.h"
43#include "gnunet-service-dht_nse.h"
41#include "gnunet-service-dht_routing.h" 44#include "gnunet-service-dht_routing.h"
42#include <fenv.h> 45#include <fenv.h>
43 46
@@ -56,6 +59,21 @@
56 */ 59 */
57#define DHT_BLOOM_SIZE 128 60#define DHT_BLOOM_SIZE 128
58 61
62/**
63 * How often to update our preference levels for peers in our routing tables.
64 */
65#define DHT_DEFAULT_PREFERENCE_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2)
66
67/**
68 * How long at least to wait before sending another find peer request.
69 */
70#define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2)
71
72/**
73 * How long at most to wait before sending another find peer request.
74 */
75#define DHT_MAXIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 8)
76
59 77
60/** 78/**
61 * P2P PUT message 79 * P2P PUT message
@@ -374,6 +392,16 @@ static unsigned int bucket_size = DEFAULT_BUCKET_SIZE;
374 */ 392 */
375static GNUNET_SCHEDULER_TaskIdentifier find_peer_task; 393static GNUNET_SCHEDULER_TaskIdentifier find_peer_task;
376 394
395/**
396 * Identity of this peer.
397 */
398static struct GNUNET_PeerIdentity my_identity;
399
400/**
401 * Handle to GNUnet core.
402 */
403static struct GNUNET_CORE_Handle *coreAPI;
404
377 405
378/** 406/**
379 * Find the optimal bucket for this key. 407 * Find the optimal bucket for this key.
@@ -399,6 +427,90 @@ find_bucket (const GNUNET_HashCode * hc)
399 427
400 428
401/** 429/**
430 * Let GNUnet core know that we like the given peer.
431 *
432 * @param cls the 'struct PeerInfo' of the peer
433 * @param tc scheduler context.
434 */
435static void
436update_core_preference (void *cls,
437 const struct GNUNET_SCHEDULER_TaskContext *tc);
438
439
440/**
441 * Function called with statistics about the given peer.
442 *
443 * @param cls closure
444 * @param peer identifies the peer
445 * @param bpm_out set to the current bandwidth limit (sending) for this peer
446 * @param amount set to the amount that was actually reserved or unreserved;
447 * either the full requested amount or zero (no partial reservations)
448 * @param res_delay if the reservation could not be satisfied (amount was 0), how
449 * long should the client wait until re-trying?
450 * @param preference current traffic preference for the given peer
451 */
452static void
453update_core_preference_finish (void *cls,
454 const struct GNUNET_PeerIdentity *peer,
455 struct GNUNET_BANDWIDTH_Value32NBO bpm_out,
456 int32_t amount,
457 struct GNUNET_TIME_Relative res_delay,
458 uint64_t preference)
459{
460 struct PeerInfo *peer_info = cls;
461
462 peer_info->info_ctx = NULL;
463 peer_info->preference_task
464 = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
465 &update_core_preference, peer_info);
466}
467
468
469/**
470 * Let GNUnet core know that we like the given peer.
471 *
472 * @param cls the 'struct PeerInfo' of the peer
473 * @param tc scheduler context.
474 */
475static void
476update_core_preference (void *cls,
477 const struct GNUNET_SCHEDULER_TaskContext *tc)
478{
479 struct PeerInfo *peer = cls;
480 uint64_t preference;
481 unsigned int matching;
482 int bucket;
483
484 peer->preference_task = GNUNET_SCHEDULER_NO_TASK;
485 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
486 return;
487 matching =
488 GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey,
489 &peer->id.hashPubKey);
490 if (matching >= 64)
491 matching = 63;
492 bucket = find_bucket(&peer->id.hashPubKey);
493 if (bucket == GNUNET_SYSERR)
494 preference = 0;
495 else
496 preference = (1LL << matching) / k_buckets[bucket].peers_size;
497 if (preference == 0)
498 {
499 peer->preference_task
500 = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
501 &update_core_preference, peer);
502 return;
503 }
504 peer->info_ctx =
505 GNUNET_CORE_peer_change_preference (coreAPI, &peer->id,
506 GNUNET_TIME_UNIT_FOREVER_REL,
507 GNUNET_BANDWIDTH_VALUE_MAX, 0,
508 preference,
509 &update_core_preference_finish, peer);
510}
511
512
513/**
402 * Method called whenever a peer connects. 514 * Method called whenever a peer connects.
403 * 515 *
404 * @param cls closure 516 * @param cls closure
@@ -444,7 +556,6 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
444 GNUNET_CONTAINER_multihashmap_put (all_known_peers, 556 GNUNET_CONTAINER_multihashmap_put (all_known_peers,
445 &peer->hashPubKey, ret, 557 &peer->hashPubKey, ret,
446 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 558 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
447 increment_stats (STAT_PEERS_KNOWN);
448} 559}
449 560
450 561
@@ -460,7 +571,6 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
460 struct PeerInfo *to_remove; 571 struct PeerInfo *to_remove;
461 int current_bucket; 572 int current_bucket;
462 struct P2PPendingMessage *pos; 573 struct P2PPendingMessage *pos;
463 struct P2PPendingMessage *next;
464 574
465 /* Check for disconnect from self message */ 575 /* Check for disconnect from self message */
466 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) 576 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
@@ -481,21 +591,16 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
481 GNUNET_CORE_peer_change_preference_cancel (to_remove->info_ctx); 591 GNUNET_CORE_peer_change_preference_cancel (to_remove->info_ctx);
482 to_remove->info_ctx = NULL; 592 to_remove->info_ctx = NULL;
483 } 593 }
484 current_bucket = find_current_bucket (&to_remove->id.hashPubKey); 594 current_bucket = find_bucket (&to_remove->id.hashPubKey);
485 GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head, 595 GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head,
486 k_buckets[current_bucket].tail, 596 k_buckets[current_bucket].tail,
487 to_remove); 597 to_remove);
488 GNUNET_assert (k_buckets[current_bucket].peers_size > 0); 598 GNUNET_assert (k_buckets[current_bucket].peers_size > 0);
489 k_buckets[current_bucket].peers_size--; 599 k_buckets[current_bucket].peers_size--;
490 while ( (lowest_bucket > 0) && 600 while ( (closest_bucket > 0) &&
491 (k_buckets[lowest_bucket].peers_size == 0) ) 601 (k_buckets[closest_bucket].peers_size == 0) )
492 lowest_bucket--; 602 closest_bucket--;
493 603
494 if (to_remove->send_task != GNUNET_SCHEDULER_NO_TASK)
495 {
496 GNUNET_SCHEDULER_cancel (peer->send_task);
497 peer->send_task = GNUNET_SCHEDULER_NO_TASK;
498 }
499 if (to_remove->th != NULL) 604 if (to_remove->th != NULL)
500 { 605 {
501 GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th); 606 GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th);
@@ -554,7 +659,8 @@ core_transmit_notify (void *cls, size_t size, void *buf)
554 peer->th 659 peer->th
555 = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, 660 = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
556 pending->importance, 661 pending->importance,
557 pending->timeout, &peer->id, msize, 662 GNUNET_TIME_absolute_get_remaining (pending->timeout),
663 &peer->id, msize,
558 &core_transmit_notify, peer); 664 &core_transmit_notify, peer);
559 665
560 return off; 666 return off;
@@ -578,7 +684,8 @@ process_peer_queue (struct PeerInfo *peer)
578 peer->th 684 peer->th
579 = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, 685 = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
580 pending->importance, 686 pending->importance,
581 pending->timeout, &peer->id, 687 GNUNET_TIME_absolute_get_remaining (pending->timeout),
688 &peer->id,
582 ntohs (pending->msg->size), 689 ntohs (pending->msg->size),
583 &core_transmit_notify, peer); 690 &core_transmit_notify, peer);
584} 691}
@@ -600,12 +707,12 @@ get_forward_count (uint32_t hop_count,
600 uint32_t forward_count; 707 uint32_t forward_count;
601 float target_value; 708 float target_value;
602 709
603 if (hop_count > log_of_network_size_estimate * 4.0) 710 if (hop_count > GDS_NSE_get () * 4.0)
604 { 711 {
605 /* forcefully terminate */ 712 /* forcefully terminate */
606 return 0; 713 return 0;
607 } 714 }
608 if (hop_count > log_of_network_size_estimate * 2.0) 715 if (hop_count > GDS_NSE_get () * 2.0)
609 { 716 {
610 /* Once we have reached our ideal number of hops, only forward to 1 peer */ 717 /* Once we have reached our ideal number of hops, only forward to 1 peer */
611 return 1; 718 return 1;
@@ -614,7 +721,7 @@ get_forward_count (uint32_t hop_count,
614 target_replication = GNUNET_MIN (16 /* FIXME: use named constant */, 721 target_replication = GNUNET_MIN (16 /* FIXME: use named constant */,
615 target_replication); 722 target_replication);
616 target_value = 723 target_value =
617 1 + (target_replication - 1.0) / (log_of_network_size_estimate + 724 1 + (target_replication - 1.0) / (GDS_NSE_get () +
618 ((float) (target_replication - 1.0) * 725 ((float) (target_replication - 1.0) *
619 hop_count)); 726 hop_count));
620 /* Set forward count to floor of target_value */ 727 /* Set forward count to floor of target_value */
@@ -630,6 +737,81 @@ get_forward_count (uint32_t hop_count,
630 737
631 738
632/** 739/**
740 * Compute the distance between have and target as a 32-bit value.
741 * Differences in the lower bits must count stronger than differences
742 * in the higher bits.
743 *
744 * @return 0 if have==target, otherwise a number
745 * that is larger as the distance between
746 * the two hash codes increases
747 */
748static unsigned int
749distance (const GNUNET_HashCode * target, const GNUNET_HashCode * have)
750{
751 unsigned int bucket;
752 unsigned int msb;
753 unsigned int lsb;
754 unsigned int i;
755
756 /* We have to represent the distance between two 2^9 (=512)-bit
757 * numbers as a 2^5 (=32)-bit number with "0" being used for the
758 * two numbers being identical; furthermore, we need to
759 * guarantee that a difference in the number of matching
760 * bits is always represented in the result.
761 *
762 * We use 2^32/2^9 numerical values to distinguish between
763 * hash codes that have the same LSB bit distance and
764 * use the highest 2^9 bits of the result to signify the
765 * number of (mis)matching LSB bits; if we have 0 matching
766 * and hence 512 mismatching LSB bits we return -1 (since
767 * 512 itself cannot be represented with 9 bits) */
768
769 /* first, calculate the most significant 9 bits of our
770 * result, aka the number of LSBs */
771 bucket = GNUNET_CRYPTO_hash_matching_bits (target, have);
772 /* bucket is now a value between 0 and 512 */
773 if (bucket == 512)
774 return 0; /* perfect match */
775 if (bucket == 0)
776 return (unsigned int) -1; /* LSB differs; use max (if we did the bit-shifting
777 * below, we'd end up with max+1 (overflow)) */
778
779 /* calculate the most significant bits of the final result */
780 msb = (512 - bucket) << (32 - 9);
781 /* calculate the 32-9 least significant bits of the final result by
782 * looking at the differences in the 32-9 bits following the
783 * mismatching bit at 'bucket' */
784 lsb = 0;
785 for (i = bucket + 1;
786 (i < sizeof (GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); i++)
787 {
788 if (GNUNET_CRYPTO_hash_get_bit (target, i) !=
789 GNUNET_CRYPTO_hash_get_bit (have, i))
790 lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10,
791 * last bit set will be 31 -- if
792 * i does not reach 512 first... */
793 }
794 return msb | lsb;
795}
796
797
798/**
799 * Return a number that is larger the closer the
800 * "have" GNUNET_hash code is to the "target".
801 *
802 * @return inverse distance metric, non-zero.
803 * Must fudge the value if NO bits match.
804 */
805static unsigned int
806inverse_distance (const GNUNET_HashCode * target, const GNUNET_HashCode * have)
807{
808 if (GNUNET_CRYPTO_hash_matching_bits (target, have) == 0)
809 return 1; /* Never return 0! */
810 return ((unsigned int) -1) - distance (target, have);
811}
812
813
814/**
633 * Check whether my identity is closer than any known peers. If a 815 * Check whether my identity is closer than any known peers. If a
634 * non-null bloomfilter is given, check if this is the closest peer 816 * non-null bloomfilter is given, check if this is the closest peer
635 * that hasn't already been routed to. 817 * that hasn't already been routed to.
@@ -640,7 +822,8 @@ get_forward_count (uint32_t hop_count,
640 * @return GNUNET_YES if node location is closest, 822 * @return GNUNET_YES if node location is closest,
641 * GNUNET_NO otherwise. 823 * GNUNET_NO otherwise.
642 */ 824 */
643static int 825/* static */
826int
644am_closest_peer (const GNUNET_HashCode *key, 827am_closest_peer (const GNUNET_HashCode *key,
645 const struct GNUNET_CONTAINER_BloomFilter *bloom) 828 const struct GNUNET_CONTAINER_BloomFilter *bloom)
646{ 829{
@@ -653,7 +836,7 @@ am_closest_peer (const GNUNET_HashCode *key,
653 836
654 if (0 == memcmp (&my_identity.hashPubKey, key, sizeof (GNUNET_HashCode))) 837 if (0 == memcmp (&my_identity.hashPubKey, key, sizeof (GNUNET_HashCode)))
655 return GNUNET_YES; 838 return GNUNET_YES;
656 bucket_num = find_current_bucket (key); 839 bucket_num = find_bucket (key);
657 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, key); 840 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, key);
658 my_distance = distance (&my_identity.hashPubKey, key); 841 my_distance = distance (&my_identity.hashPubKey, key);
659 pos = k_buckets[bucket_num].head; 842 pos = k_buckets[bucket_num].head;
@@ -709,12 +892,12 @@ select_peer (const GNUNET_HashCode *key,
709 unsigned int largest_distance; 892 unsigned int largest_distance;
710 struct PeerInfo *chosen; 893 struct PeerInfo *chosen;
711 894
712 if (hops >= log_of_network_size_estimate) 895 if (hops >= GDS_NSE_get ())
713 { 896 {
714 /* greedy selection (closest peer that is not in bloomfilter) */ 897 /* greedy selection (closest peer that is not in bloomfilter) */
715 largest_distance = 0; 898 largest_distance = 0;
716 chosen = NULL; 899 chosen = NULL;
717 for (bc = lowest_bucket; bc < MAX_BUCKETS; bc++) 900 for (bc = closest_bucket; bc < MAX_BUCKETS; bc++)
718 { 901 {
719 pos = k_buckets[bc].head; 902 pos = k_buckets[bc].head;
720 count = 0; 903 count = 0;
@@ -741,7 +924,7 @@ select_peer (const GNUNET_HashCode *key,
741 /* select "random" peer */ 924 /* select "random" peer */
742 /* count number of peers that are available and not filtered */ 925 /* count number of peers that are available and not filtered */
743 count = 0; 926 count = 0;
744 for (bc = lowest_bucket; bc < MAX_BUCKETS; bc++) 927 for (bc = closest_bucket; bc < MAX_BUCKETS; bc++)
745 { 928 {
746 pos = k_buckets[bc].head; 929 pos = k_buckets[bc].head;
747 while ((pos != NULL) && (count < bucket_size)) 930 while ((pos != NULL) && (count < bucket_size))
@@ -763,7 +946,7 @@ select_peer (const GNUNET_HashCode *key,
763 /* Now actually choose a peer */ 946 /* Now actually choose a peer */
764 selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, count); 947 selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, count);
765 count = 0; 948 count = 0;
766 for (bc = lowest_bucket; bc < MAX_BUCKETS; bc++) 949 for (bc = closest_bucket; bc < MAX_BUCKETS; bc++)
767 { 950 {
768 pos = k_buckets[bc].head; 951 pos = k_buckets[bc].head;
769 while ((pos != NULL) && (count < bucket_size)) 952 while ((pos != NULL) && (count < bucket_size))
@@ -859,7 +1042,7 @@ void
859GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, 1042GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
860 enum GNUNET_DHT_RouteOption options, 1043 enum GNUNET_DHT_RouteOption options,
861 uint32_t desired_replication_level, 1044 uint32_t desired_replication_level,
862 GNUNET_TIME_Absolute expiration_time, 1045 struct GNUNET_TIME_Absolute expiration_time,
863 uint32_t hop_count, 1046 uint32_t hop_count,
864 struct GNUNET_CONTAINER_BloomFilter *bf, 1047 struct GNUNET_CONTAINER_BloomFilter *bf,
865 const GNUNET_HashCode *key, 1048 const GNUNET_HashCode *key,
@@ -914,7 +1097,7 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
914 ppm->bloomfilter, 1097 ppm->bloomfilter,
915 DHT_BLOOM_SIZE)); 1098 DHT_BLOOM_SIZE));
916 ppm->key = *key; 1099 ppm->key = *key;
917 pp = (const struct GNUNET_PeerIdentity*) &ppm[1]; 1100 pp = (struct GNUNET_PeerIdentity*) &ppm[1];
918 memcpy (pp, put_path, sizeof (struct GNUNET_PeerIdentity) * put_path_length); 1101 memcpy (pp, put_path, sizeof (struct GNUNET_PeerIdentity) * put_path_length);
919 memcpy (&pp[put_path_length], data, data_size); 1102 memcpy (&pp[put_path_length], data, data_size);
920 GNUNET_CONTAINER_DLL_insert (target->head, 1103 GNUNET_CONTAINER_DLL_insert (target->head,
@@ -954,7 +1137,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
954 size_t xquery_size, 1137 size_t xquery_size,
955 const struct GNUNET_CONTAINER_BloomFilter *reply_bf, 1138 const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
956 uint32_t reply_bf_mutator, 1139 uint32_t reply_bf_mutator,
957 const struct GNUNET_CONTAINER_BloomFilter *peer_bf) 1140 struct GNUNET_CONTAINER_BloomFilter *peer_bf)
958{ 1141{
959 unsigned int target_count; 1142 unsigned int target_count;
960 unsigned int i; 1143 unsigned int i;
@@ -1000,7 +1183,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1000 pgm->bloomfilter, 1183 pgm->bloomfilter,
1001 DHT_BLOOM_SIZE)); 1184 DHT_BLOOM_SIZE));
1002 pgm->key = *key; 1185 pgm->key = *key;
1003 xq = (const struct GNUNET_PeerIdentity*) &ppm[1]; 1186 xq = (char *) &pgm[1];
1004 memcpy (xq, xquery, xquery_size); 1187 memcpy (xq, xquery, xquery_size);
1005 GNUNET_assert (GNUNET_OK == 1188 GNUNET_assert (GNUNET_OK ==
1006 GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf, 1189 GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf,
@@ -1033,9 +1216,9 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1033 * @param data_size number of bytes in data 1216 * @param data_size number of bytes in data
1034 */ 1217 */
1035void 1218void
1036GDS_NEIGHBOURS_handle_reply (const GNUNET_PeerIdentity *target, 1219GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
1037 enum GNUNET_BLOCK_Type type, 1220 enum GNUNET_BLOCK_Type type,
1038 GNUNET_TIME_Absolute expiration_time, 1221 struct GNUNET_TIME_Absolute expiration_time,
1039 const GNUNET_HashCode *key, 1222 const GNUNET_HashCode *key,
1040 unsigned int put_path_length, 1223 unsigned int put_path_length,
1041 struct GNUNET_PeerIdentity *put_path, 1224 struct GNUNET_PeerIdentity *put_path,
@@ -1079,17 +1262,17 @@ GDS_NEIGHBOURS_handle_reply (const GNUNET_PeerIdentity *target,
1079 prm->get_path_length = htonl (get_path_length); 1262 prm->get_path_length = htonl (get_path_length);
1080 prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); 1263 prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1081 prm->key = *key; 1264 prm->key = *key;
1082 paths = (struct GNUNET_PeerIdentity) &prm[1]; 1265 paths = (struct GNUNET_PeerIdentity*) &prm[1];
1083 memcpy (paths, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); 1266 memcpy (paths, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity));
1084 memcpy (&paths[put_path_length], 1267 memcpy (&paths[put_path_length],
1085 get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); 1268 get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity));
1086 memcpy (&paths[put_path_length + get_path_length], 1269 memcpy (&paths[put_path_length + get_path_length],
1087 data, data_size); 1270 data, data_size);
1088 GNUNET_CONTAINER_DLL_insert (target->head, 1271 GNUNET_CONTAINER_DLL_insert (pi->head,
1089 target->tail, 1272 pi->tail,
1090 pending); 1273 pending);
1091 target->pending_count++; 1274 pi->pending_count++;
1092 process_peer_queue (target); 1275 process_peer_queue (pi);
1093} 1276}
1094 1277
1095 1278
@@ -1143,8 +1326,6 @@ static void
1143send_find_peer_message (void *cls, 1326send_find_peer_message (void *cls,
1144 const struct GNUNET_SCHEDULER_TaskContext *tc) 1327 const struct GNUNET_SCHEDULER_TaskContext *tc)
1145{ 1328{
1146 struct GNUNET_DHT_FindPeerMessage *find_peer_msg;
1147 struct DHT_MessageContext msg_ctx;
1148 struct GNUNET_TIME_Relative next_send_time; 1329 struct GNUNET_TIME_Relative next_send_time;
1149 struct BloomConstructorContext bcc; 1330 struct BloomConstructorContext bcc;
1150 1331
@@ -1199,8 +1380,11 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
1199 const struct GNUNET_PeerIdentity *identity, 1380 const struct GNUNET_PeerIdentity *identity,
1200 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 1381 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
1201{ 1382{
1383 struct GNUNET_TIME_Relative next_send_time;
1384
1202 GNUNET_assert (server != NULL); 1385 GNUNET_assert (server != NULL);
1203 my_identity = *identity; 1386 my_identity = *identity;
1387 /* FIXME: do upon 1st connect instead! */
1204 next_send_time.rel_value = 1388 next_send_time.rel_value =
1205 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + 1389 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
1206 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, 1390 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
@@ -1258,13 +1442,13 @@ handle_dht_p2p_put (void *cls,
1258 payload = &put_path[putlen]; 1442 payload = &put_path[putlen];
1259 payload_size = msize - (sizeof (struct PeerPutMessage) + 1443 payload_size = msize - (sizeof (struct PeerPutMessage) +
1260 putlen * sizeof (struct GNUNET_PeerIdentity)); 1444 putlen * sizeof (struct GNUNET_PeerIdentity));
1261 switch (GNUNET_BLOCK_get_key (block_context, 1445 switch (GNUNET_BLOCK_get_key (GDS_block_context,
1262 ntohl (put->type), 1446 ntohl (put->type),
1263 payload, payload_size, 1447 payload, payload_size,
1264 &test_key)) 1448 &test_key))
1265 { 1449 {
1266 case GNUNET_YES: 1450 case GNUNET_YES:
1267 if (0 != memcmp (&test_key, key, sizeof (GNUNET_HashCode))) 1451 if (0 != memcmp (&test_key, &put->key, sizeof (GNUNET_HashCode)))
1268 { 1452 {
1269 GNUNET_break_op (0); 1453 GNUNET_break_op (0);
1270 return GNUNET_YES; 1454 return GNUNET_YES;
@@ -1285,7 +1469,7 @@ handle_dht_p2p_put (void *cls,
1285 1469
1286 /* extend 'put path' by sender */ 1470 /* extend 'put path' by sender */
1287 memcpy (pp, put_path, putlen * sizeof (struct GNUNET_PeerIdentity)); 1471 memcpy (pp, put_path, putlen * sizeof (struct GNUNET_PeerIdentity));
1288 pp[putlen] = *sender; 1472 pp[putlen] = *peer;
1289 1473
1290 /* give to local clients */ 1474 /* give to local clients */
1291 GDS_CLIENT_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time), 1475 GDS_CLIENT_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time),
@@ -1308,8 +1492,9 @@ handle_dht_p2p_put (void *cls,
1308 ntohl (put->options), 1492 ntohl (put->options),
1309 ntohl (put->desired_replication_level), 1493 ntohl (put->desired_replication_level),
1310 GNUNET_TIME_absolute_ntoh (put->expiration_time), 1494 GNUNET_TIME_absolute_ntoh (put->expiration_time),
1311 ntohl (put->hop_count), 1495 ntohl (put->hop_count) + 1 /* who adds +1? */,
1312 bf, 1496 bf,
1497 &put->key,
1313 putlen + 1, pp, 1498 putlen + 1, pp,
1314 payload, 1499 payload,
1315 payload_size); 1500 payload_size);
@@ -1370,7 +1555,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1370 reply_bf = GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], 1555 reply_bf = GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size],
1371 reply_bf_size, 1556 reply_bf_size,
1372 GNUNET_DHT_GET_BLOOMFILTER_K); 1557 GNUNET_DHT_GET_BLOOMFILTER_K);
1373 eval = GNUNET_BLOCK_evaluate (block_context, 1558 eval = GNUNET_BLOCK_evaluate (GDS_block_context,
1374 type, 1559 type,
1375 &get->key, 1560 &get->key,
1376 &reply_bf, 1561 &reply_bf,
@@ -1395,7 +1580,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1395 type, 1580 type,
1396 &get->key, 1581 &get->key,
1397 xquery, xquery_size, 1582 xquery, xquery_size,
1398 reply_bf, get->reply_bf_mutator); 1583 reply_bf, get->bf_mutator);
1399 /* FIXME: check options (find peer, local-processing-only-if-nearest, etc.!) */ 1584 /* FIXME: check options (find peer, local-processing-only-if-nearest, etc.!) */
1400 1585
1401 /* local lookup (this may update the reply_bf) */ 1586 /* local lookup (this may update the reply_bf) */
@@ -1403,7 +1588,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1403 type, 1588 type,
1404 xquery, xquery_size, 1589 xquery, xquery_size,
1405 &reply_bf, 1590 &reply_bf,
1406 get->reply_bf_mutator); 1591 get->bf_mutator);
1407 /* FIXME: should track if the local lookup resulted in a 1592 /* FIXME: should track if the local lookup resulted in a
1408 definitive result and then NOT do P2P forwarding */ 1593 definitive result and then NOT do P2P forwarding */
1409 1594
@@ -1415,7 +1600,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1415 &get->key, 1600 &get->key,
1416 xquery, xquery_size, 1601 xquery, xquery_size,
1417 reply_bf, 1602 reply_bf,
1418 get->reply_bf_mutator, 1603 get->bf_mutator,
1419 peer_bf); 1604 peer_bf);
1420 /* clean up */ 1605 /* clean up */
1421 if (NULL != reply_bf) 1606 if (NULL != reply_bf)
@@ -1482,7 +1667,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1482 xget_path[get_path_length] = *peer; 1667 xget_path[get_path_length] = *peer;
1483 1668
1484 /* forward to local clients */ 1669 /* forward to local clients */
1485 GDS_CLIENT_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration), 1670 GDS_CLIENT_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time),
1486 &prm->key, 1671 &prm->key,
1487 get_path_length + 1, 1672 get_path_length + 1,
1488 xget_path, 1673 xget_path,
@@ -1494,7 +1679,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1494 1679
1495 /* forward to other peers */ 1680 /* forward to other peers */
1496 GDS_ROUTING_process (type, 1681 GDS_ROUTING_process (type,
1497 GNUNET_TIME_absolute_ntoh (prm->expiration), 1682 GNUNET_TIME_absolute_ntoh (prm->expiration_time),
1498 &prm->key, 1683 &prm->key,
1499 put_path_length, 1684 put_path_length,
1500 put_path, 1685 put_path,
@@ -1516,16 +1701,15 @@ int
1516GDS_NEIGHBOURS_init () 1701GDS_NEIGHBOURS_init ()
1517{ 1702{
1518 static struct GNUNET_CORE_MessageHandler core_handlers[] = { 1703 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
1519 {&handle_dht_get, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, 0}, 1704 {&handle_dht_p2p_get, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, 0},
1520 {&handle_dht_put, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, 0}, 1705 {&handle_dht_p2p_put, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, 0},
1521 {&handle_dht_result, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, 0}, 1706 {&handle_dht_p2p_result, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, 0},
1522 {NULL, 0, 0} 1707 {NULL, 0, 0}
1523 }; 1708 };
1524 unsigned long long temp_config_num; 1709 unsigned long long temp_config_num;
1525 struct GNUNET_TIME_Relative next_send_time;
1526 1710
1527 if (GNUNET_OK == 1711 if (GNUNET_OK ==
1528 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", "bucket_size", 1712 GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size",
1529 &temp_config_num)) 1713 &temp_config_num))
1530 bucket_size = (unsigned int) temp_config_num; 1714 bucket_size = (unsigned int) temp_config_num;
1531 coreAPI = GNUNET_CORE_connect (GDS_cfg, 1715 coreAPI = GNUNET_CORE_connect (GDS_cfg,
@@ -1542,6 +1726,8 @@ GDS_NEIGHBOURS_init ()
1542 return GNUNET_SYSERR; 1726 return GNUNET_SYSERR;
1543 all_known_peers = GNUNET_CONTAINER_multihashmap_create (256); 1727 all_known_peers = GNUNET_CONTAINER_multihashmap_create (256);
1544#if 0 1728#if 0
1729 struct GNUNET_TIME_Relative next_send_time;
1730
1545 // FIXME! 1731 // FIXME!
1546 next_send_time.rel_value = 1732 next_send_time.rel_value =
1547 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + 1733 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
@@ -1567,7 +1753,7 @@ GDS_NEIGHBOURS_done ()
1567 return; 1753 return;
1568 GNUNET_CORE_disconnect (coreAPI); 1754 GNUNET_CORE_disconnect (coreAPI);
1569 coreAPI = NULL; 1755 coreAPI = NULL;
1570 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_get_size (all_known_peers)); 1756 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers));
1571 GNUNET_CONTAINER_multihashmap_destroy (all_known_peers); 1757 GNUNET_CONTAINER_multihashmap_destroy (all_known_peers);
1572 all_known_peers = NULL; 1758 all_known_peers = NULL;
1573 if (GNUNET_SCHEDULER_NO_TASK != find_peer_task) 1759 if (GNUNET_SCHEDULER_NO_TASK != find_peer_task)
@@ -1583,72 +1769,6 @@ GDS_NEIGHBOURS_done ()
1583 1769
1584#if 0 1770#if 0
1585 1771
1586/* Forward declaration */
1587static void
1588update_core_preference (void *cls,
1589 const struct GNUNET_SCHEDULER_TaskContext *tc);
1590
1591
1592/**
1593 * Function called with statistics about the given peer.
1594 *
1595 * @param cls closure
1596 * @param peer identifies the peer
1597 * @param bpm_out set to the current bandwidth limit (sending) for this peer
1598 * @param amount set to the amount that was actually reserved or unreserved;
1599 * either the full requested amount or zero (no partial reservations)
1600 * @param res_delay if the reservation could not be satisfied (amount was 0), how
1601 * long should the client wait until re-trying?
1602 * @param preference current traffic preference for the given peer
1603 */
1604static void
1605update_core_preference_finish (void *cls,
1606 const struct GNUNET_PeerIdentity *peer,
1607 struct GNUNET_BANDWIDTH_Value32NBO bpm_out,
1608 int32_t amount,
1609 struct GNUNET_TIME_Relative res_delay,
1610 uint64_t preference)
1611{
1612 struct PeerInfo *peer_info = cls;
1613
1614 peer_info->info_ctx = NULL;
1615 GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
1616 &update_core_preference, peer_info);
1617}
1618
1619
1620static void
1621update_core_preference (void *cls,
1622 const struct GNUNET_SCHEDULER_TaskContext *tc)
1623{
1624 struct PeerInfo *peer = cls;
1625 uint64_t preference;
1626 unsigned int matching;
1627
1628 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1629 {
1630 return;
1631 }
1632 matching =
1633 GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey,
1634 &peer->id.hashPubKey);
1635 if (matching >= 64)
1636 {
1637#if DEBUG_DHT
1638 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1639 "Peer identifier matches by %u bits, only shifting as much as we can!\n",
1640 matching);
1641#endif
1642 matching = 63;
1643 }
1644 preference = 1LL << matching;
1645 peer->info_ctx =
1646 GNUNET_CORE_peer_change_preference (core_api, &peer->id,
1647 GNUNET_TIME_UNIT_FOREVER_REL,
1648 GNUNET_BANDWIDTH_VALUE_MAX, 0,
1649 preference,
1650 &update_core_preference_finish, peer);
1651}
1652 1772
1653 1773
1654#endif 1774#endif
diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h
index e679b4162..d23ea10ab 100644
--- a/src/dht/gnunet-service-dht_neighbours.h
+++ b/src/dht/gnunet-service-dht_neighbours.h
@@ -79,7 +79,7 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
79 * @param xquery_size number of bytes in xquery 79 * @param xquery_size number of bytes in xquery
80 * @param reply_bf bloomfilter to filter duplicates 80 * @param reply_bf bloomfilter to filter duplicates
81 * @param reply_bf_mutator mutator for reply_bf 81 * @param reply_bf_mutator mutator for reply_bf
82 * @param peer_bf filter for peers not to select (again) 82 * @param peer_bf filter for peers not to select (again, updated)
83 */ 83 */
84void 84void
85GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, 85GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
@@ -91,7 +91,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
91 size_t xquery_size, 91 size_t xquery_size,
92 const struct GNUNET_CONTAINER_BloomFilter *reply_bf, 92 const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
93 uint32_t reply_bf_mutator, 93 uint32_t reply_bf_mutator,
94 const struct GNUNET_CONTAINER_BloomFilter *peer_bf); 94 struct GNUNET_CONTAINER_BloomFilter *peer_bf);
95 95
96 96
97/** 97/**
@@ -116,9 +116,9 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
116 struct GNUNET_TIME_Absolute expiration_time, 116 struct GNUNET_TIME_Absolute expiration_time,
117 const GNUNET_HashCode *key, 117 const GNUNET_HashCode *key,
118 unsigned int put_path_length, 118 unsigned int put_path_length,
119 struct GNUNET_PeerIdentity *put_path, 119 const struct GNUNET_PeerIdentity *put_path,
120 unsigned int get_path_length, 120 unsigned int get_path_length,
121 struct GNUNET_PeerIdentity *get_path, 121 const struct GNUNET_PeerIdentity *get_path,
122 const void *data, 122 const void *data,
123 size_t data_size); 123 size_t data_size);
124 124
diff --git a/src/dht/gnunet-service-dht_nse.c b/src/dht/gnunet-service-dht_nse.c
index a6e20fb57..b8cda34bd 100644
--- a/src/dht/gnunet-service-dht_nse.c
+++ b/src/dht/gnunet-service-dht_nse.c
@@ -59,6 +59,11 @@ update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
59} 59}
60 60
61 61
62/**
63 * Return the log of the current network size estimate.
64 *
65 * @return log of NSE
66 */
62double 67double
63GDS_NSE_get () 68GDS_NSE_get ()
64{ 69{
@@ -66,6 +71,9 @@ GDS_NSE_get ()
66} 71}
67 72
68 73
74/**
75 * Initialize NSE subsystem.
76 */
69void 77void
70GDS_NSE_init () 78GDS_NSE_init ()
71{ 79{
@@ -73,6 +81,9 @@ GDS_NSE_init ()
73} 81}
74 82
75 83
84/**
85 * Shutdown NSE subsystem.
86 */
76void 87void
77GDS_NSE_done () 88GDS_NSE_done ()
78{ 89{
diff --git a/src/dht/gnunet-service-dht_nse.h b/src/dht/gnunet-service-dht_nse.h
index e2f73a9dd..bddd4bdf7 100644
--- a/src/dht/gnunet-service-dht_nse.h
+++ b/src/dht/gnunet-service-dht_nse.h
@@ -27,13 +27,25 @@
27#define GNUNET_SERVICE_DHT_NSE_H 27#define GNUNET_SERVICE_DHT_NSE_H
28 28
29 29
30/**
31 * Return the log of the current network size estimate.
32 *
33 * @return log of NSE
34 */
30double 35double
31GDS_NSE_get (void); 36GDS_NSE_get (void);
32 37
33 38
39/**
40 * Initialize NSE subsystem.
41 */
34void 42void
35GDS_NSE_init (void); 43GDS_NSE_init (void);
36 44
45
46/**
47 * Shutdown NSE subsystem.
48 */
37void 49void
38GDS_NSE_done (void); 50GDS_NSE_done (void);
39 51
diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c
index 1d43cfd3d..4024c61fb 100644
--- a/src/dht/gnunet-service-dht_routing.c
+++ b/src/dht/gnunet-service-dht_routing.c
@@ -23,8 +23,10 @@
23 * @brief GNUnet DHT tracking of requests for routing replies 23 * @brief GNUnet DHT tracking of requests for routing replies
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26 26#include "platform.h"
27#include "gnunet-service-dht_neighbours.h"
27#include "gnunet-service-dht_routing.h" 28#include "gnunet-service-dht_routing.h"
29#include "gnunet-service-dht.h"
28 30
29 31
30/** 32/**
@@ -118,7 +120,7 @@ struct ProcessContext
118 /** 120 /**
119 * Expiration time of the result. 121 * Expiration time of the result.
120 */ 122 */
121 GNUNET_TIME_Absolute expiration_time; 123 struct GNUNET_TIME_Absolute expiration_time;
122 124
123 /** 125 /**
124 * Number of entries in 'put_path'. 126 * Number of entries in 'put_path'.
@@ -164,7 +166,7 @@ process (void *cls,
164 if ( (rr->type != GNUNET_BLOCK_TYPE_ANY) && 166 if ( (rr->type != GNUNET_BLOCK_TYPE_ANY) &&
165 (rr->type != pc->type) ) 167 (rr->type != pc->type) )
166 return GNUNET_OK; /* type missmatch */ 168 return GNUNET_OK; /* type missmatch */
167 eval = GNUNET_BLOCK_evaluate (block_context, 169 eval = GNUNET_BLOCK_evaluate (GDS_block_context,
168 pc->type, 170 pc->type,
169 key, 171 key,
170 &rr->reply_bf, 172 &rr->reply_bf,
@@ -177,7 +179,7 @@ process (void *cls,
177 { 179 {
178 case GNUNET_BLOCK_EVALUATION_OK_MORE: 180 case GNUNET_BLOCK_EVALUATION_OK_MORE:
179 case GNUNET_BLOCK_EVALUATION_OK_LAST: 181 case GNUNET_BLOCK_EVALUATION_OK_LAST:
180 GDS_NEIGHBOURS_handle_reply (&rr->target, 182 GDS_NEIGHBOURS_handle_reply (&rr->peer,
181 pc->type, 183 pc->type,
182 pc->expiration_time, 184 pc->expiration_time,
183 key, 185 key,
@@ -194,7 +196,7 @@ process (void *cls,
194 GNUNET_break_op (0); 196 GNUNET_break_op (0);
195 return GNUNET_SYSERR; 197 return GNUNET_SYSERR;
196 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 198 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
197 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 199 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
198 GNUNET_break (0); 200 GNUNET_break (0);
199 return GNUNET_OK; 201 return GNUNET_OK;
200 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 202 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
@@ -226,7 +228,7 @@ process (void *cls,
226 */ 228 */
227void 229void
228GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, 230GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
229 GNUNET_TIME_Absolute expiration_time, 231 struct GNUNET_TIME_Absolute expiration_time,
230 const GNUNET_HashCode *key, 232 const GNUNET_HashCode *key,
231 unsigned int put_path_length, 233 unsigned int put_path_length,
232 const struct GNUNET_PeerIdentity *put_path, 234 const struct GNUNET_PeerIdentity *put_path,
@@ -245,10 +247,10 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
245 pc.get_path = get_path; 247 pc.get_path = get_path;
246 pc.data = data; 248 pc.data = data;
247 pc.data_size = data_size; 249 pc.data_size = data_size;
248 GNUNET_CONTAINER_multihashmap_iterate (recent_map, 250 GNUNET_CONTAINER_multihashmap_get_multiple (recent_map,
249 key, 251 key,
250 &process, 252 &process,
251 &pc); 253 &pc);
252} 254}
253 255
254 256
@@ -264,7 +266,7 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
264 * @param reply_bf_mutator mutator for reply_bf 266 * @param reply_bf_mutator mutator for reply_bf
265*/ 267*/
266void 268void
267GDS_ROUTING_add (const GNUNET_PeerIdentity *sender, 269GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
268 enum GNUNET_BLOCK_Type type, 270 enum GNUNET_BLOCK_Type type,
269 const GNUNET_HashCode *key, 271 const GNUNET_HashCode *key,
270 const void *xquery, 272 const void *xquery,
@@ -279,7 +281,7 @@ GDS_ROUTING_add (const GNUNET_PeerIdentity *sender,
279 recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); 281 recent_req = GNUNET_CONTAINER_heap_peek (recent_heap);
280 GNUNET_assert (recent_req != NULL); 282 GNUNET_assert (recent_req != NULL);
281 GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); 283 GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node);
282 GNUNET_CONTAINER_bloomfilter_free (recent_req->bloom); 284 GNUNET_CONTAINER_bloomfilter_free (recent_req->reply_bf);
283 GNUNET_free (recent_req); 285 GNUNET_free (recent_req);
284 } 286 }
285 287
@@ -313,7 +315,7 @@ GDS_ROUTING_init ()
313 recent_heap = 315 recent_heap =
314 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 316 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
315 recent_map = 317 recent_map =
316 GNUNET_CONTAINER_multihashmap_create (MAX_BUCKETS / 8); 318 GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3);
317} 319}
318 320
319 321
@@ -330,10 +332,10 @@ GDS_ROUTING_done ()
330 recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); 332 recent_req = GNUNET_CONTAINER_heap_peek (recent_heap);
331 GNUNET_assert (recent_req != NULL); 333 GNUNET_assert (recent_req != NULL);
332 GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); 334 GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node);
333 GNUNET_CONTAINER_bloomfilter_free (recent_req->bloom); 335 GNUNET_CONTAINER_bloomfilter_free (recent_req->reply_bf);
334 GNUNET_free (recent_req); 336 GNUNET_free (recent_req);
335 } 337 }
336 GNUNET_assert (0 == GNUNET_CONTAINER_heap_size (recent_heap)); 338 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (recent_heap));
337 GNUNET_CONTAINER_heap_destroy (recent_heap); 339 GNUNET_CONTAINER_heap_destroy (recent_heap);
338 recent_heap = NULL; 340 recent_heap = NULL;
339 GNUNET_CONTAINER_multihashmap_destroy (recent_map); 341 GNUNET_CONTAINER_multihashmap_destroy (recent_map);