aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2011-01-14 18:09:15 +0000
committerNathan S. Evans <evans@in.tum.de>2011-01-14 18:09:15 +0000
commit41b30ee2fbe3f601ccd69e75393fc7df0e9540e4 (patch)
tree4f5175c26b7fd0bfcd4cc39941161c7e418439ed /src
parente265bc76b9cca9b6e0a4fbc69e6a0cb1ff30649f (diff)
downloadgnunet-41b30ee2fbe3f601ccd69e75393fc7df0e9540e4.tar.gz
gnunet-41b30ee2fbe3f601ccd69e75393fc7df0e9540e4.zip
change how peers are filtered (peer id gets freed somehow?)
Diffstat (limited to 'src')
-rw-r--r--src/dht/gnunet-dht-driver.c66
1 files changed, 50 insertions, 16 deletions
diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c
index 07dbd6f2e..71f1b0e80 100644
--- a/src/dht/gnunet-dht-driver.c
+++ b/src/dht/gnunet-dht-driver.c
@@ -880,12 +880,11 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
880 */ 880 */
881static void 881static void
882log_topology_cb (void *cls, 882log_topology_cb (void *cls,
883 const struct GNUNET_PeerIdentity *first, 883 const struct GNUNET_PeerIdentity *first,
884 const struct GNUNET_PeerIdentity *second, 884 const struct GNUNET_PeerIdentity *second,
885 const char *emsg) 885 const char *emsg)
886{ 886{
887 struct TopologyIteratorContext *topo_ctx = cls; 887 struct TopologyIteratorContext *topo_ctx = cls;
888 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "log_topology_cb\n");
889 if ((first != NULL) && (second != NULL)) 888 if ((first != NULL) && (second != NULL))
890 { 889 {
891 /* GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "According to CORE, peer %s is connected to %s\n", GNUNET_i2s(first), GNUNET_h2s(&second->hashPubKey));*/ 890 /* GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "According to CORE, peer %s is connected to %s\n", GNUNET_i2s(first), GNUNET_h2s(&second->hashPubKey));*/
@@ -2116,6 +2115,20 @@ schedule_find_peer_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContex
2116} 2115}
2117 2116
2118/** 2117/**
2118 * Convert unique ID to hash code.
2119 *
2120 * @param uid unique ID to convert
2121 * @param hash set to uid (extended with zeros)
2122 */
2123static void
2124hash_from_uid (uint32_t uid, GNUNET_HashCode *hash)
2125{
2126 memset (hash, 0, sizeof (GNUNET_HashCode));
2127 *((uint32_t *) hash) = uid;
2128}
2129
2130
2131/**
2119 * Set up all of the put and get operations we want to do 2132 * Set up all of the put and get operations we want to do
2120 * in the current round. Allocate data structure for each, 2133 * in the current round. Allocate data structure for each,
2121 * add to list, then schedule the actual PUT operations. 2134 * add to list, then schedule the actual PUT operations.
@@ -2126,6 +2139,8 @@ setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2126 int i; 2139 int i;
2127 struct TestPutContext *test_put; 2140 struct TestPutContext *test_put;
2128 struct TestGetContext *test_get; 2141 struct TestGetContext *test_get;
2142 uint32_t temp_peer;
2143 GNUNET_HashCode uid_hash;
2129#if REMEMBER 2144#if REMEMBER
2130 int remember[num_puts][num_peers]; 2145 int remember[num_puts][num_peers];
2131 memset(&remember, 0, sizeof(int) * num_puts * num_peers); 2146 memset(&remember, 0, sizeof(int) * num_puts * num_peers);
@@ -2143,12 +2158,18 @@ setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2143 memcpy(&known_keys[i], &sybil_target, sizeof(GNUNET_HashCode) / 2); 2158 memcpy(&known_keys[i], &sybil_target, sizeof(GNUNET_HashCode) / 2);
2144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Distance between sybil location and key is %d\n", GNUNET_CRYPTO_hash_matching_bits(&known_keys[i], &sybil_target)); 2159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Distance between sybil location and key is %d\n", GNUNET_CRYPTO_hash_matching_bits(&known_keys[i], &sybil_target));
2145 } 2160 }
2146 test_put->daemon = GNUNET_TESTING_daemon_get(pg, GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers)); 2161 temp_peer = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2162 test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_peer);
2147 /* Don't start PUTs at malicious peers! */ 2163 /* Don't start PUTs at malicious peers! */
2148 if (malicious_bloom != NULL) 2164 if (malicious_bloom != NULL)
2149 { 2165 {
2150 while (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test(malicious_bloom, &test_put->daemon->id.hashPubKey)) 2166 hash_from_uid(temp_peer, &uid_hash);
2151 test_put->daemon = GNUNET_TESTING_daemon_get(pg, GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers)); 2167 while (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test(malicious_bloom, &uid_hash))
2168 {
2169 temp_peer = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2170 hash_from_uid(temp_peer, &uid_hash);
2171 test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_peer);
2172 }
2152 } 2173 }
2153 2174
2154 test_put->next = all_puts; 2175 test_put->next = all_puts;
@@ -2164,12 +2185,18 @@ setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2164 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers); 2185 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2165 remember[test_get->uid][temp_daemon] = 1; 2186 remember[test_get->uid][temp_daemon] = 1;
2166#endif 2187#endif
2167 test_get->daemon = GNUNET_TESTING_daemon_get(pg, GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers)); 2188 temp_peer = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2189 test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_peer);
2168 /* Don't start GETs at malicious peers! */ 2190 /* Don't start GETs at malicious peers! */
2169 if (malicious_bloom != NULL) 2191 if (malicious_bloom != NULL)
2170 { 2192 {
2171 while (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test(malicious_bloom, &test_get->daemon->id.hashPubKey)) 2193 hash_from_uid(temp_peer, &uid_hash);
2172 test_get->daemon = GNUNET_TESTING_daemon_get(pg, GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers)); 2194 while (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test(malicious_bloom, &uid_hash))
2195 {
2196 temp_peer = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2197 hash_from_uid(temp_peer, &uid_hash);
2198 test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_peer);
2199 }
2173 } 2200 }
2174 test_get->next = all_gets; 2201 test_get->next = all_gets;
2175 all_gets = test_get; 2202 all_gets = test_get;
@@ -2325,6 +2352,7 @@ set_malicious (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2325 &malicious_disconnect_task, ctx); 2352 &malicious_disconnect_task, ctx);
2326} 2353}
2327 2354
2355
2328#if HAVE_MALICIOUS 2356#if HAVE_MALICIOUS
2329/** 2357/**
2330 * Choose the next peer from the peer group to set as malicious. 2358 * Choose the next peer from the peer group to set as malicious.
@@ -2344,6 +2372,7 @@ choose_next_malicious (struct GNUNET_TESTING_PeerGroup *pg, struct GNUNET_CONTAI
2344 int bits_match; 2372 int bits_match;
2345 int curr_distance; 2373 int curr_distance;
2346 struct GNUNET_TESTING_Daemon *temp_daemon; 2374 struct GNUNET_TESTING_Daemon *temp_daemon;
2375 GNUNET_HashCode uid_hash;
2347 2376
2348 curr_distance = 0; 2377 curr_distance = 0;
2349 GNUNET_assert (bloom != NULL); 2378 GNUNET_assert (bloom != NULL);
@@ -2353,8 +2382,9 @@ choose_next_malicious (struct GNUNET_TESTING_PeerGroup *pg, struct GNUNET_CONTAI
2353 for (i = 0; i < num_peers; i++) 2382 for (i = 0; i < num_peers; i++)
2354 { 2383 {
2355 temp_daemon = GNUNET_TESTING_daemon_get(pg, i); 2384 temp_daemon = GNUNET_TESTING_daemon_get(pg, i);
2385 hash_from_uid(i, &uid_hash);
2356 /* Check if this peer matches the bloomfilter */ 2386 /* Check if this peer matches the bloomfilter */
2357 if ((GNUNET_NO == GNUNET_TESTING_daemon_running(temp_daemon)) || (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &temp_daemon->id.hashPubKey))) 2387 if ((GNUNET_NO == GNUNET_TESTING_daemon_running(temp_daemon)) || (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &uid_hash)))
2358 continue; 2388 continue;
2359 2389
2360 bits_match = GNUNET_CRYPTO_hash_matching_bits (&temp_daemon->id.hashPubKey, &sybil_target); 2390 bits_match = GNUNET_CRYPTO_hash_matching_bits (&temp_daemon->id.hashPubKey, &sybil_target);
@@ -2369,7 +2399,8 @@ choose_next_malicious (struct GNUNET_TESTING_PeerGroup *pg, struct GNUNET_CONTAI
2369 else 2399 else
2370 { 2400 {
2371 nearest = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers); 2401 nearest = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2372 while (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &temp_daemon->id.hashPubKey)) 2402 hash_from_uid(nearest, &uid_hash);
2403 while (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &uid_hash))
2373 { 2404 {
2374 nearest = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers); 2405 nearest = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2375 } 2406 }
@@ -2389,13 +2420,15 @@ setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc
2389 struct MaliciousContext *ctx; 2420 struct MaliciousContext *ctx;
2390 int i; 2421 int i;
2391 uint32_t temp_daemon; 2422 uint32_t temp_daemon;
2423 GNUNET_HashCode uid_hash;
2392 2424
2393 for (i = 0; i < malicious_getters; i++) 2425 for (i = 0; i < malicious_getters; i++)
2394 { 2426 {
2395 ctx = GNUNET_malloc(sizeof(struct MaliciousContext)); 2427 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
2396 temp_daemon = choose_next_malicious(pg, malicious_bloom); 2428 temp_daemon = choose_next_malicious(pg, malicious_bloom);
2397 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon); 2429 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
2398 GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &ctx->daemon->id.hashPubKey); 2430 hash_from_uid(temp_daemon, &uid_hash);
2431 GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &uid_hash);
2399 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET; 2432 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET;
2400 GNUNET_SCHEDULER_add_now (&set_malicious, ctx); 2433 GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
2401 2434
@@ -2406,7 +2439,8 @@ setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc
2406 ctx = GNUNET_malloc(sizeof(struct MaliciousContext)); 2439 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
2407 temp_daemon = choose_next_malicious(pg, malicious_bloom); 2440 temp_daemon = choose_next_malicious(pg, malicious_bloom);
2408 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon); 2441 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
2409 GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &ctx->daemon->id.hashPubKey); 2442 hash_from_uid(temp_daemon, &uid_hash);
2443 GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &uid_hash);
2410 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT; 2444 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT;
2411 GNUNET_SCHEDULER_add_now (&set_malicious, ctx); 2445 GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
2412 2446
@@ -2417,7 +2451,8 @@ setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc
2417 ctx = GNUNET_malloc(sizeof(struct MaliciousContext)); 2451 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
2418 temp_daemon = choose_next_malicious(pg, malicious_bloom); 2452 temp_daemon = choose_next_malicious(pg, malicious_bloom);
2419 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon); 2453 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
2420 GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &ctx->daemon->id.hashPubKey); 2454 hash_from_uid(temp_daemon, &uid_hash);
2455 GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &uid_hash);
2421 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP; 2456 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP;
2422 GNUNET_SCHEDULER_add_now (&set_malicious, ctx); 2457 GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
2423 } 2458 }
@@ -3246,7 +3281,6 @@ main (int argc, char *argv[])
3246 argv, "gnunet-dht-driver", "nohelp", 3281 argv, "gnunet-dht-driver", "nohelp",
3247 options, &run, &ok); 3282 options, &run, &ok);
3248 3283
3249
3250 if (malicious_bloom != NULL) 3284 if (malicious_bloom != NULL)
3251 GNUNET_CONTAINER_bloomfilter_free (malicious_bloom); 3285 GNUNET_CONTAINER_bloomfilter_free (malicious_bloom);
3252 3286