aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht_neighbours.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c52
1 files changed, 20 insertions, 32 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 3cb788a06..ae3f34dce 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -70,11 +70,6 @@
70#define FIND_PEER_REPLICATION_LEVEL 4 70#define FIND_PEER_REPLICATION_LEVEL 4
71 71
72/** 72/**
73 * Maximum allowed replication level for all requests.
74 */
75#define MAXIMUM_REPLICATION_LEVEL 16
76
77/**
78 * Maximum allowed number of pending messages per peer. 73 * Maximum allowed number of pending messages per peer.
79 */ 74 */
80#define MAXIMUM_PENDING_PER_PEER 64 75#define MAXIMUM_PENDING_PER_PEER 64
@@ -855,8 +850,8 @@ get_forward_count (uint32_t hop_count,
855 850
856 if (0 == target_replication) 851 if (0 == target_replication)
857 target_replication = 1; /* 0 is verboten */ 852 target_replication = 1; /* 0 is verboten */
858 if (target_replication > MAXIMUM_REPLICATION_LEVEL) 853 if (target_replication > GNUNET_DHT_MAXIMUM_REPLICATION_LEVEL)
859 target_replication = MAXIMUM_REPLICATION_LEVEL; 854 target_replication = GNUNET_DHT_MAXIMUM_REPLICATION_LEVEL;
860 if (hop_count > GDS_NSE_get () * 4.0) 855 if (hop_count > GDS_NSE_get () * 4.0)
861 { 856 {
862 /* forcefully terminate */ 857 /* forcefully terminate */
@@ -872,7 +867,8 @@ get_forward_count (uint32_t hop_count,
872 } 867 }
873 /* bound by system-wide maximum */ 868 /* bound by system-wide maximum */
874 target_replication = 869 target_replication =
875 GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, target_replication); 870 GNUNET_MIN (GNUNET_DHT_MAXIMUM_REPLICATION_LEVEL,
871 target_replication);
876 target_value = 872 target_value =
877 1 + (target_replication - 1.0) / (GDS_NSE_get () 873 1 + (target_replication - 1.0) / (GDS_NSE_get ()
878 + ((float) (target_replication - 1.0) 874 + ((float) (target_replication - 1.0)
@@ -888,7 +884,7 @@ get_forward_count (uint32_t hop_count,
888 if (random_value < (target_value * UINT32_MAX)) 884 if (random_value < (target_value * UINT32_MAX))
889 forward_count++; 885 forward_count++;
890 return GNUNET_MIN (forward_count, 886 return GNUNET_MIN (forward_count,
891 MAXIMUM_REPLICATION_LEVEL); 887 GNUNET_DHT_MAXIMUM_REPLICATION_LEVEL);
892} 888}
893 889
894 890
@@ -906,36 +902,29 @@ enum GNUNET_GenericReturnValue
906GDS_am_closest_peer (const struct GNUNET_HashCode *key, 902GDS_am_closest_peer (const struct GNUNET_HashCode *key,
907 const struct GNUNET_CONTAINER_BloomFilter *bloom) 903 const struct GNUNET_CONTAINER_BloomFilter *bloom)
908{ 904{
909 struct GNUNET_HashCode xor;
910 int other_bits;
911 int bucket_num; 905 int bucket_num;
912 struct PeerInfo *pos;
913 906
914 if (0 == GNUNET_memcmp (&my_identity_hash, 907 if (0 == GNUNET_memcmp (&my_identity_hash,
915 key)) 908 key))
916 return GNUNET_YES; 909 return GNUNET_YES;
917 bucket_num = find_bucket (key); 910 bucket_num = find_bucket (key);
918 GNUNET_assert (bucket_num >= 0); 911 GNUNET_assert (bucket_num >= 0);
919 pos = k_buckets[bucket_num].head; 912 for (struct PeerInfo *pos = k_buckets[bucket_num].head;
920 while (NULL != pos) 913 NULL != pos;
914 pos = pos->next)
921 { 915 {
922 if ((NULL != bloom) && 916 if ( (NULL != bloom) &&
923 (GNUNET_YES == 917 (GNUNET_YES ==
924 GNUNET_CONTAINER_bloomfilter_test (bloom, 918 GNUNET_CONTAINER_bloomfilter_test (bloom,
925 &pos->phash))) 919 &pos->phash)) )
926 { 920 continue; /* Ignore filtered peers */
927 pos = pos->next; 921 /* All peers in this bucket must be closer than us, as
928 continue; /* Skip already checked entries */ 922 they mismatch with our PID on the pivotal bit. So
929 } 923 because an unfiltered peer exists, we are not the
930 GNUNET_CRYPTO_hash_xor (&pos->phash, 924 closest. */
931 key, 925 return GNUNET_NO;
932 &xor);
933 other_bits = GNUNET_CRYPTO_hash_count_leading_zeros (&xor);
934 if (other_bits > bucket_num)
935 return GNUNET_NO;
936 pos = pos->next;
937 } 926 }
938 /* No peers closer, we are the closest! */ 927 /* No closer (unfiltered) peers found; we must be the closest! */
939 return GNUNET_YES; 928 return GNUNET_YES;
940} 929}
941 930
@@ -1258,8 +1247,7 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1258 return GNUNET_NO; 1247 return GNUNET_NO;
1259 } 1248 }
1260 GNUNET_STATISTICS_update (GDS_stats, 1249 GNUNET_STATISTICS_update (GDS_stats,
1261 gettext_noop ( 1250 "# PUT messages queued for transmission",
1262 "# PUT messages queued for transmission"),
1263 target_count, 1251 target_count,
1264 GNUNET_NO); 1252 GNUNET_NO);
1265 skip_count = 0; 1253 skip_count = 0;