aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-04-28 08:55:59 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-04-28 08:55:59 +0000
commit43bb2e8d1def0d823a876e30f50bca941e351da0 (patch)
tree5075e8b13b56a6f5eb9f6ab5b37da93bed25dada /src/hostlist
parent31062c5c8b972ad07b1c7d59c5a4ea27c177d95e (diff)
downloadgnunet-43bb2e8d1def0d823a876e30f50bca941e351da0.tar.gz
gnunet-43bb2e8d1def0d823a876e30f50bca941e351da0.zip
- Implemented download limit on client side
- Disabled verbose
Diffstat (limited to 'src/hostlist')
-rw-r--r--src/hostlist/hostlist-client.c16
-rw-r--r--src/hostlist/hostlist-client.h2
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_learning.c115
-rw-r--r--src/hostlist/test_learning_adv_peer.conf2
4 files changed, 27 insertions, 108 deletions
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c
index 82f4b78ac..d5cd4ac79 100644
--- a/src/hostlist/hostlist-client.c
+++ b/src/hostlist/hostlist-client.c
@@ -36,7 +36,7 @@
36#include "gnunet_common.h" 36#include "gnunet_common.h"
37#include "gnunet_bio_lib.h" 37#include "gnunet_bio_lib.h"
38 38
39#define DEBUG_HOSTLIST_CLIENT GNUNET_YES 39#define DEBUG_HOSTLIST_CLIENT GNUNET_NO
40 40
41 41
42/** 42/**
@@ -151,7 +151,7 @@ static CURLM *multi;
151/** 151/**
152 * 152 *
153 */ 153 */
154static uint32_t bytes_downloaded; 154static uint32_t stat_bytes_downloaded;
155/** 155/**
156 * Amount of time we wait between hostlist downloads. 156 * Amount of time we wait between hostlist downloads.
157 */ 157 */
@@ -280,16 +280,12 @@ callback_download (void *ptr,
280 uint16_t msize; 280 uint16_t msize;
281 281
282 total = size * nmemb; 282 total = size * nmemb;
283 bytes_downloaded = total; 283 stat_bytes_downloaded += total;
284 if ( (total == 0) || (stat_bogus_url) ) 284 if ( (total == 0) || (stat_bogus_url) )
285 { 285 {
286 return total; /* ok, no data or bogus data */ 286 return total; /* ok, no data or bogus data */
287 } 287 }
288 288
289 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
290 _("Total: %u, nmeb: %u, size %u \n"),
291 total, nmemb, size);
292
293 GNUNET_STATISTICS_update (stats, 289 GNUNET_STATISTICS_update (stats,
294 gettext_noop ("# bytes downloaded from hostlist servers"), 290 gettext_noop ("# bytes downloaded from hostlist servers"),
295 (int64_t) total, 291 (int64_t) total,
@@ -711,7 +707,7 @@ clean_up ()
711 } 707 }
712 GNUNET_free_non_null (current_url); 708 GNUNET_free_non_null (current_url);
713 current_url = NULL; 709 current_url = NULL;
714 bytes_downloaded = 0; 710 stat_bytes_downloaded = 0;
715 stat_download_in_progress = GNUNET_NO; 711 stat_download_in_progress = GNUNET_NO;
716} 712}
717 713
@@ -808,7 +804,6 @@ task_download (void *cls,
808 struct CURLMsg *msg; 804 struct CURLMsg *msg;
809 CURLMcode mret; 805 CURLMcode mret;
810 806
811 bytes_downloaded = 0;
812 ti_download = GNUNET_SCHEDULER_NO_TASK; 807 ti_download = GNUNET_SCHEDULER_NO_TASK;
813 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 808 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
814 { 809 {
@@ -838,7 +833,7 @@ task_download (void *cls,
838 do 833 do
839 { 834 {
840 running = 0; 835 running = 0;
841 if (bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) 836 if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS)
842 { 837 {
843 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 838 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
844 _("Download limit of %u bytes exceeded, stopping download\n"),MAX_BYTES_PER_HOSTLISTS); 839 _("Download limit of %u bytes exceeded, stopping download\n"),MAX_BYTES_PER_HOSTLISTS);
@@ -937,6 +932,7 @@ download_hostlist ()
937 stat_download_in_progress = GNUNET_YES; 932 stat_download_in_progress = GNUNET_YES;
938 stat_download_successful = GNUNET_NO; 933 stat_download_successful = GNUNET_NO;
939 stat_hellos_obtained = 0; 934 stat_hellos_obtained = 0;
935 stat_bytes_downloaded = 0;
940 936
941 GNUNET_STATISTICS_update (stats, 937 GNUNET_STATISTICS_update (stats,
942 gettext_noop ("# hostlist downloads initiated"), 938 gettext_noop ("# hostlist downloads initiated"),
diff --git a/src/hostlist/hostlist-client.h b/src/hostlist/hostlist-client.h
index ad4b59223..def2c633e 100644
--- a/src/hostlist/hostlist-client.h
+++ b/src/hostlist/hostlist-client.h
@@ -33,7 +33,7 @@
33#include "gnunet_time_lib.h" 33#include "gnunet_time_lib.h"
34 34
35#define MAX_NUMBER_HOSTLISTS 30 35#define MAX_NUMBER_HOSTLISTS 30
36#define MAX_BYTES_PER_HOSTLISTS 50000 36#define MAX_BYTES_PER_HOSTLISTS 100000
37#define SAVING_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) 37#define SAVING_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
38#define TESTING_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) 38#define TESTING_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
39#define WAITING_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 39#define WAITING_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
index cd22226f1..ab7465dc1 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
@@ -30,7 +30,7 @@
30#include "gnunet_resolver_service.h" 30#include "gnunet_resolver_service.h"
31#include "gnunet_statistics_service.h" 31#include "gnunet_statistics_service.h"
32 32
33#define VERBOSE GNUNET_YES 33#define VERBOSE GNUNET_NO
34 34
35#define START_ARM GNUNET_YES 35#define START_ARM GNUNET_YES
36#define MAX_URL_LEN 1000 36#define MAX_URL_LEN 1000
@@ -43,14 +43,10 @@
43 43
44static int timeout; 44static int timeout;
45static int adv_sent; 45static int adv_sent;
46static int adv_arrived;
46 47
47static int adv_arrived_p1; 48static int learned_hostlist_saved;
48static int learned_hostlist_saved_p1; 49static int learned_hostlist_downloaded;
49static int learned_hostlist_downloaded_p1;
50
51static int adv_arrived_p2;
52static int learned_hostlist_saved_p2;
53static int learned_hostlist_downloaded_p2;
54 50
55static char * current_adv_uri; 51static char * current_adv_uri;
56 52
@@ -76,9 +72,6 @@ static struct PeerContext adv_peer;
76 72
77static struct PeerContext learn_peer; 73static struct PeerContext learn_peer;
78 74
79static struct PeerContext learn_peer2;
80
81
82static void 75static void
83waitpid_task (void *cls, 76waitpid_task (void *cls,
84 const struct GNUNET_SCHEDULER_TaskContext *tc) 77 const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -144,12 +137,6 @@ static void shutdown_testcase()
144 GNUNET_TRANSPORT_disconnect (learn_peer.th); 137 GNUNET_TRANSPORT_disconnect (learn_peer.th);
145 learn_peer.th = NULL; 138 learn_peer.th = NULL;
146 } 139 }
147 /*
148 if (learn_peer2.th != NULL)
149 {
150 GNUNET_TRANSPORT_disconnect (learn_peer2.th);
151 learn_peer2.th = NULL;
152 }*/
153 if (adv_peer.core != NULL) 140 if (adv_peer.core != NULL)
154 { 141 {
155 GNUNET_CORE_disconnect (adv_peer.core); 142 GNUNET_CORE_disconnect (adv_peer.core);
@@ -160,20 +147,11 @@ static void shutdown_testcase()
160 GNUNET_CORE_disconnect (learn_peer.core); 147 GNUNET_CORE_disconnect (learn_peer.core);
161 learn_peer.core = NULL; 148 learn_peer.core = NULL;
162 } 149 }
163 /*
164 if (learn_peer2.core != NULL)
165 {
166 GNUNET_CORE_disconnect (learn_peer2.core);
167 learn_peer2.core = NULL;
168 }*/
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "Asking ARM to stop core services\n"); 151 "Asking ARM to stop core services\n");
171 learn_peer.arm = GNUNET_ARM_connect (learn_peer.cfg, sched, NULL); 152 learn_peer.arm = GNUNET_ARM_connect (learn_peer.cfg, sched, NULL);
172 GNUNET_ARM_stop_service (learn_peer.arm, "core", GNUNET_TIME_UNIT_SECONDS, 153 GNUNET_ARM_stop_service (learn_peer.arm, "core", GNUNET_TIME_UNIT_SECONDS,
173 &stop_cb, &learn_peer); 154 &stop_cb, &learn_peer);
174 /* learn_peer2.arm = GNUNET_ARM_connect (learn_peer2.cfg, sched, NULL);
175 GNUNET_ARM_stop_service (learn_peer2.arm, "core", GNUNET_TIME_UNIT_SECONDS,
176 &stop_cb, &learn_peer2);*/
177 adv_peer.arm = GNUNET_ARM_connect (adv_peer.cfg, sched, NULL); 155 adv_peer.arm = GNUNET_ARM_connect (adv_peer.cfg, sched, NULL);
178 GNUNET_ARM_stop_service (adv_peer.arm, "core", GNUNET_TIME_UNIT_SECONDS, 156 GNUNET_ARM_stop_service (adv_peer.arm, "core", GNUNET_TIME_UNIT_SECONDS,
179 &stop_cb, &adv_peer); 157 &stop_cb, &adv_peer);
@@ -203,20 +181,13 @@ process_downloads (void *cls,
203{ 181{
204 182
205 183
206 if ( ((struct PeerContext *) cls == &learn_peer) && (value == 2) && (learned_hostlist_downloaded_p1 == GNUNET_NO) ) 184 if ( ((struct PeerContext *) cls == &learn_peer) && (value == 2) && (learned_hostlist_downloaded == GNUNET_NO) )
207 { 185 {
208 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 186 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
209 _("Peer1 has successfully downloaded advertised URI \n")); 187 _("Peer has successfully downloaded advertised URI \n"));
210 learned_hostlist_downloaded_p1 = GNUNET_YES; 188 learned_hostlist_downloaded = GNUNET_YES;
211 } 189 }
212 /* 190 if (GNUNET_NO != learned_hostlist_downloaded)
213 if ( ((struct PeerContext *) cls == &learn_peer2) && (value == 2) && (learned_hostlist_downloaded_p2 == GNUNET_NO) )
214 {
215 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
216 _("Peer2 has successfully downloaded advertised URI \n"));
217 learned_hostlist_downloaded_p2 = GNUNET_YES;
218 }*/
219 if ( (GNUNET_NO != learned_hostlist_downloaded_p1) /*&& (GNUNET_NO != learned_hostlist_downloaded_p2)*/ )
220 shutdown_testcase(); 191 shutdown_testcase();
221 return GNUNET_OK; 192 return GNUNET_OK;
222} 193}
@@ -228,19 +199,12 @@ process_uris_recv (void *cls,
228 uint64_t value, 199 uint64_t value,
229 int is_persistent) 200 int is_persistent)
230{ 201{
231 if ( ((struct PeerContext *) cls == &learn_peer) && (value == 1) && (learned_hostlist_saved_p1 == GNUNET_NO)) 202 if ( ((struct PeerContext *) cls == &learn_peer) && (value == 1) && (learned_hostlist_saved == GNUNET_NO))
232 { 203 {
233 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 204 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
234 _("Peer1 has successfully saved advertised URI \n")); 205 _("Peer has successfully saved advertised URI \n"));
235 learned_hostlist_saved_p1 = GNUNET_YES; 206 learned_hostlist_saved = GNUNET_YES;
236 } 207 }
237 /*
238 if ( ((struct PeerContext *) cls == &learn_peer2) && (value == 1) && (learned_hostlist_saved_p2 == GNUNET_NO))
239 {
240 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
241 _("Peer2 has successfully saved advertised URI \n"));
242 learned_hostlist_saved_p2 = GNUNET_YES;
243 }*/
244 return GNUNET_OK; 208 return GNUNET_OK;
245} 209}
246 210
@@ -278,13 +242,6 @@ check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
278 NULL, 242 NULL,
279 &process_downloads, 243 &process_downloads,
280 &learn_peer); 244 &learn_peer);
281 /*GNUNET_STATISTICS_get (learn_peer2.stats,
282 "hostlist",
283 stat,
284 GNUNET_TIME_UNIT_MINUTES,
285 NULL,
286 &process_downloads,
287 &learn_peer2);*/
288 GNUNET_free (stat); 245 GNUNET_free (stat);
289 246
290 GNUNET_STATISTICS_get (learn_peer.stats, 247 GNUNET_STATISTICS_get (learn_peer.stats,
@@ -294,13 +251,6 @@ check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
294 NULL, 251 NULL,
295 &process_uris_recv, 252 &process_uris_recv,
296 &learn_peer); 253 &learn_peer);
297 /*GNUNET_STATISTICS_get (learn_peer2.stats,
298 "hostlist",
299 gettext_noop("# advertised hostlist URIs"),
300 GNUNET_TIME_UNIT_MINUTES,
301 NULL,
302 &process_uris_recv,
303 &learn_peer2);*/
304 GNUNET_STATISTICS_get (adv_peer.stats, 254 GNUNET_STATISTICS_get (adv_peer.stats,
305 "hostlist", 255 "hostlist",
306 gettext_noop("# hostlist advertisements send"), 256 gettext_noop("# hostlist advertisements send"),
@@ -363,8 +313,7 @@ static int ad_arrive_handler (void *cls,
363 { 313 {
364 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 314 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
365 "Recieved hostlist advertisement with URI `%s' as expected\n", current_adv_uri); 315 "Recieved hostlist advertisement with URI `%s' as expected\n", current_adv_uri);
366 adv_arrived_p1 = GNUNET_YES; 316 adv_arrived = GNUNET_YES;
367 adv_arrived_p2 = GNUNET_YES;
368 } 317 }
369 else 318 else
370 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 319 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -456,13 +405,9 @@ run (void *cls,
456 timeout = GNUNET_NO; 405 timeout = GNUNET_NO;
457 adv_sent =GNUNET_NO; 406 adv_sent =GNUNET_NO;
458 407
459 adv_arrived_p1 = GNUNET_NO; 408 adv_arrived = 0;
460 learned_hostlist_downloaded_p1 = GNUNET_NO; 409 learned_hostlist_saved = GNUNET_NO;
461 learned_hostlist_saved_p1 = GNUNET_NO; 410 learned_hostlist_downloaded = GNUNET_NO;
462
463 /*adv_arrived_p2 = GNUNET_NO;
464 learned_hostlist_downloaded_p2 = GNUNET_NO;
465 learned_hostlist_saved_p2 = GNUNET_NO;*/
466 411
467 sched = s; 412 sched = s;
468 timeout_task = GNUNET_SCHEDULER_add_delayed (sched, 413 timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
@@ -476,8 +421,6 @@ run (void *cls,
476 421
477 setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf"); 422 setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf");
478 setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf"); 423 setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf");
479 // setup_learn_peer (&learn_peer2, "test_learning_learn_peer2.conf");
480
481} 424}
482 425
483 426
@@ -508,44 +451,24 @@ check ()
508 "Testcase could not set up two communicating peers, timeout\n"); 451 "Testcase could not set up two communicating peers, timeout\n");
509 failed = GNUNET_YES; 452 failed = GNUNET_YES;
510 } 453 }
511 if (adv_arrived_p1 == GNUNET_NO) 454 if (adv_arrived != GNUNET_YES)
512 { 455 {
513 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 456 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
514 "Peer1: Learning peer did not recieve advertisement from server\n"); 457 "Learning peer did not receive advertisement from server\n");
515 failed = GNUNET_YES; 458 failed = GNUNET_YES;
516 } 459 }
517 if ( learned_hostlist_saved_p1 == GNUNET_NO ) 460 if ( learned_hostlist_saved == GNUNET_NO )
518 { 461 {
519 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 462 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
520 "Peer1: Advertised hostlist was not saved in datastore\n"); 463 "Peer1: Advertised hostlist was not saved in datastore\n");
521 failed = GNUNET_YES; 464 failed = GNUNET_YES;
522 } 465 }
523 if (learned_hostlist_downloaded_p1 == GNUNET_NO) 466 if (learned_hostlist_downloaded == GNUNET_NO)
524 { 467 {
525 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 468 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
526 "Peer1: Advertised hostlist could not be downloaded from server\n"); 469 "Peer1: Advertised hostlist could not be downloaded from server\n");
527 failed = GNUNET_YES; 470 failed = GNUNET_YES;
528 } 471 }
529 /*
530 if (adv_arrived_p2 == GNUNET_NO)
531 {
532 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
533 "Peer2: Learning peer did not recieve advertisement from server\n");
534 failed = GNUNET_YES;
535 }
536 if ( learned_hostlist_saved_p2 == GNUNET_NO )
537 {
538 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
539 "Peer2: Advertised hostlist was not saved in datastore\n");
540 failed = GNUNET_YES;
541 }
542 if (learned_hostlist_downloaded_p2 == GNUNET_NO)
543 {
544 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
545 "Peer2: Advertised hostlist could not be downloaded from server\n");
546 failed = GNUNET_YES;
547 }*/
548
549 if (adv_sent == GNUNET_NO) 472 if (adv_sent == GNUNET_NO)
550 { 473 {
551 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 474 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/hostlist/test_learning_adv_peer.conf b/src/hostlist/test_learning_adv_peer.conf
index 3423af138..8a26c585a 100644
--- a/src/hostlist/test_learning_adv_peer.conf
+++ b/src/hostlist/test_learning_adv_peer.conf
@@ -36,7 +36,7 @@ WEAKRANDOM = YES
36[hostlist] 36[hostlist]
37HTTPPORT = 12981 37HTTPPORT = 12981
38SERVERS = http://localhost:12981/ 38SERVERS = http://localhost:12981/
39OPTIONS = -p -a -b -e 39OPTIONS = -p -a
40#OPTIONS = -b -p -a 40#OPTIONS = -b -p -a
41#DEBUG = YES 41#DEBUG = YES
42HOSTLISTFILE = hostlists_adv_peer.file 42HOSTLISTFILE = hostlists_adv_peer.file