aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-dht-driver.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-12-28 14:52:59 +0000
committerNathan S. Evans <evans@in.tum.de>2010-12-28 14:52:59 +0000
commit98e6b155d4ea5e63dcf6acb0480d2806f6df6d45 (patch)
treefa3bfc5b9bb8bbd9db977e4791d3867a5155fca6 /src/dht/gnunet-dht-driver.c
parent31876c24162802355c9c0d94a801c69570ab55a5 (diff)
downloadgnunet-98e6b155d4ea5e63dcf6acb0480d2806f6df6d45.tar.gz
gnunet-98e6b155d4ea5e63dcf6acb0480d2806f6df6d45.zip
asynchronous malicious peer setup, fix for timing issues
Diffstat (limited to 'src/dht/gnunet-dht-driver.c')
-rw-r--r--src/dht/gnunet-dht-driver.c46
1 files changed, 9 insertions, 37 deletions
diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c
index 603151de4..f5848486d 100644
--- a/src/dht/gnunet-dht-driver.c
+++ b/src/dht/gnunet-dht-driver.c
@@ -1139,8 +1139,7 @@ decrement_find_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1139 GNUNET_assert(test_find_peer->find_peer_context->outstanding > 0); 1139 GNUNET_assert(test_find_peer->find_peer_context->outstanding > 0);
1140 test_find_peer->find_peer_context->outstanding--; 1140 test_find_peer->find_peer_context->outstanding--;
1141 test_find_peer->find_peer_context->total--; 1141 test_find_peer->find_peer_context->total--;
1142 if ((0 == test_find_peer->find_peer_context->total) && 1142 if (0 == test_find_peer->find_peer_context->total)
1143 (GNUNET_TIME_absolute_get_remaining(test_find_peer->find_peer_context->endtime).rel_value > 60))
1144 { 1143 {
1145 GNUNET_SCHEDULER_add_now(&count_new_peers, test_find_peer->find_peer_context); 1144 GNUNET_SCHEDULER_add_now(&count_new_peers, test_find_peer->find_peer_context);
1146 } 1145 }
@@ -2181,6 +2180,11 @@ continue_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * t
2181 if (dhtlog_handle != NULL) 2180 if (dhtlog_handle != NULL)
2182 dhtlog_handle->insert_round(DHT_ROUND_NORMAL, rounds_finished); 2181 dhtlog_handle->insert_round(DHT_ROUND_NORMAL, rounds_finished);
2183 2182
2183 if (GNUNET_YES != malicious_after_settle)
2184 {
2185 GNUNET_SCHEDULER_add_now(&setup_malicious_peers, NULL);
2186 }
2187
2184 if (GNUNET_YES == do_find_peer) 2188 if (GNUNET_YES == do_find_peer)
2185 { 2189 {
2186 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling find peer requests during \"settle\" time.\n"); 2190 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling find peer requests during \"settle\" time.\n");
@@ -2211,13 +2215,7 @@ malicious_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext
2211 2215
2212 if (malicious_completed == malicious_getters + malicious_putters + malicious_droppers) 2216 if (malicious_completed == malicious_getters + malicious_putters + malicious_droppers)
2213 { 2217 {
2214 GNUNET_SCHEDULER_cancel(die_task); 2218 fprintf(stderr, "Finished setting all malicious peers up!\n");
2215 fprintf(stderr, "Finished setting all malicious peers up, calling continuation!\n");
2216 if (dhtlog_handle != NULL)
2217 GNUNET_SCHEDULER_add_now (&continue_puts_and_gets, NULL);
2218 else
2219 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time),
2220 &continue_puts_and_gets, NULL);
2221 } 2219 }
2222 2220
2223} 2221}
@@ -2323,25 +2321,6 @@ setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc
2323 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP; 2321 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP;
2324 GNUNET_SCHEDULER_add_now (&set_malicious, ctx); 2322 GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
2325 } 2323 }
2326
2327 /**
2328 * If we have any malicious peers to set up,
2329 * the malicious callback should call continue_gets_and_puts
2330 */
2331 if (malicious_getters + malicious_putters + malicious_droppers > 0)
2332 {
2333 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Giving malicious set tasks some time before starting testing!\n");
2334 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, (malicious_getters + malicious_putters + malicious_droppers) * 2),
2335 &end_badly, "from set malicious");
2336 }
2337 else /* Otherwise, continue testing */
2338 {
2339 if (cls != NULL)
2340 {
2341 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Scheduling continue_puts_and_gets now!\n");
2342 GNUNET_SCHEDULER_add_now (&continue_puts_and_gets, NULL);
2343 }
2344 }
2345} 2324}
2346 2325
2347/** 2326/**
@@ -2409,18 +2388,10 @@ topology_callback (void *cls,
2409 if ((dhtlog_handle != NULL) && (settle_time > 0)) 2388 if ((dhtlog_handle != NULL) && (settle_time > 0))
2410 { 2389 {
2411 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext)); 2390 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
2412 if (GNUNET_YES == malicious_after_settle) /* Don't set malicious peers until after settle_time */ 2391 topo_ctx->cont = &continue_puts_and_gets;
2413 topo_ctx->cont = &continue_puts_and_gets;
2414 else /* Set malicious peers now */
2415 topo_ctx->cont = &setup_malicious_peers;
2416 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create(num_peers); 2392 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create(num_peers);
2417 topo_ctx->cls = &continue_puts_and_gets;
2418 GNUNET_SCHEDULER_add_now(&capture_current_topology, topo_ctx); 2393 GNUNET_SCHEDULER_add_now(&capture_current_topology, topo_ctx);
2419 } 2394 }
2420 else
2421 {
2422 GNUNET_SCHEDULER_add_now(&setup_malicious_peers, &continue_puts_and_gets);
2423 }
2424 } 2395 }
2425 else if (total_connections + failed_connections == expected_connections) 2396 else if (total_connections + failed_connections == expected_connections)
2426 { 2397 {
@@ -3161,6 +3132,7 @@ main (int argc, char *argv[])
3161 argv, "gnunet-dht-driver", "nohelp", 3132 argv, "gnunet-dht-driver", "nohelp",
3162 options, &run, &ok); 3133 options, &run, &ok);
3163 3134
3135
3164 if (ret != GNUNET_OK) 3136 if (ret != GNUNET_OK)
3165 { 3137 {
3166 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`gnunet-dht-driver': Failed with error code %d\n", ret); 3138 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`gnunet-dht-driver': Failed with error code %d\n", ret);