diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-16 15:32:05 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-16 15:32:05 +0000 |
commit | 6848d6776a7cdf30670a8da032a31b24438d8709 (patch) | |
tree | 5dcfdcfd7819073b956373c764b10a8aa3040b05 /src/hostlist/hostlist-client.c | |
parent | 0bbb1957c9ad0e6dedf550fe640b8fc923180161 (diff) | |
download | gnunet-6848d6776a7cdf30670a8da032a31b24438d8709.tar.gz gnunet-6848d6776a7cdf30670a8da032a31b24438d8709.zip |
hostlist client is now alternating between preconfigured servers and learned hostlists when downloading
Diffstat (limited to 'src/hostlist/hostlist-client.c')
-rw-r--r-- | src/hostlist/hostlist-client.c | 74 |
1 files changed, 59 insertions, 15 deletions
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index a9bddb061..ecdd578af 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c | |||
@@ -179,16 +179,27 @@ static unsigned int connection_count; | |||
179 | */ | 179 | */ |
180 | static struct GNUNET_TIME_Absolute end_time; | 180 | static struct GNUNET_TIME_Absolute end_time; |
181 | 181 | ||
182 | /* Head of the linked list used to store hostlists */ | 182 | /** |
183 | * Head of the linked list used to store hostlists | ||
184 | */ | ||
183 | static struct Hostlist * linked_list_head; | 185 | static struct Hostlist * linked_list_head; |
184 | 186 | ||
185 | /* Tail of the linked list used to store hostlists */ | 187 | /** |
188 | * Tail of the linked list used to store hostlists | ||
189 | */ | ||
186 | static struct Hostlist * linked_list_tail; | 190 | static struct Hostlist * linked_list_tail; |
187 | 191 | ||
188 | /* Size of the linke list used to store hostlists */ | 192 | /* |
193 | * Size of the linke list used to store hostlists | ||
194 | */ | ||
189 | static unsigned int linked_list_size; | 195 | static unsigned int linked_list_size; |
190 | 196 | ||
191 | /** | 197 | /** |
198 | * Value saying if preconfigured is used | ||
199 | */ | ||
200 | static unsigned int use_preconfigured_list; | ||
201 | |||
202 | /** | ||
192 | * Process downloaded bits by calling callback on each HELLO. | 203 | * Process downloaded bits by calling callback on each HELLO. |
193 | * | 204 | * |
194 | * @param ptr buffer with downloaded data | 205 | * @param ptr buffer with downloaded data |
@@ -296,7 +307,7 @@ download_hostlist_processor (void *ptr, | |||
296 | * @return NULL if there is no URL available | 307 | * @return NULL if there is no URL available |
297 | */ | 308 | */ |
298 | static char * | 309 | static char * |
299 | get_url () | 310 | get_bootstrap_url () |
300 | { | 311 | { |
301 | char *servers; | 312 | char *servers; |
302 | char *ret; | 313 | char *ret; |
@@ -305,13 +316,13 @@ get_url () | |||
305 | 316 | ||
306 | if (GNUNET_OK != | 317 | if (GNUNET_OK != |
307 | GNUNET_CONFIGURATION_get_value_string (cfg, | 318 | GNUNET_CONFIGURATION_get_value_string (cfg, |
308 | "HOSTLIST", | 319 | "HOSTLIST", |
309 | "SERVERS", | 320 | "SERVERS", |
310 | &servers)) | 321 | &servers)) |
311 | { | 322 | { |
312 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 323 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
313 | _("No `%s' specified in `%s' configuration, will not bootstrap.\n"), | 324 | _("No `%s' specified in `%s' configuration, will not bootstrap.\n"), |
314 | "SERVERS", "HOSTLIST"); | 325 | "SERVERS", "HOSTLIST"); |
315 | return NULL; | 326 | return NULL; |
316 | } | 327 | } |
317 | 328 | ||
@@ -330,8 +341,8 @@ get_url () | |||
330 | if (urls == 0) | 341 | if (urls == 0) |
331 | { | 342 | { |
332 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 343 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
333 | _("No `%s' specified in `%s' configuration, will not bootstrap.\n"), | 344 | _("No `%s' specified in `%s' configuration, will not bootstrap.\n"), |
334 | "SERVERS", "HOSTLIST"); | 345 | "SERVERS", "HOSTLIST"); |
335 | GNUNET_free (servers); | 346 | GNUNET_free (servers); |
336 | return NULL; | 347 | return NULL; |
337 | } | 348 | } |
@@ -357,6 +368,38 @@ get_url () | |||
357 | return ret; | 368 | return ret; |
358 | } | 369 | } |
359 | 370 | ||
371 | /** | ||
372 | * Method deciding if a preconfigured or advertisied hostlist is used on a 50:50 ratio | ||
373 | * @return uri to use, NULL if there is no URL available | ||
374 | */ | ||
375 | static char * | ||
376 | get_list_url () | ||
377 | { | ||
378 | uint32_t index; | ||
379 | unsigned int counter; | ||
380 | struct Hostlist * pos; | ||
381 | |||
382 | if ( GNUNET_YES == use_preconfigured_list) | ||
383 | { | ||
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
385 | "Using preconfigured bootstrap server\n"); | ||
386 | use_preconfigured_list = GNUNET_NO; | ||
387 | return get_bootstrap_url(); | ||
388 | } | ||
389 | index = GNUNET_CRYPTO_random_u32 ( GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size); | ||
390 | counter = 0; | ||
391 | pos = linked_list_head; | ||
392 | while ( counter < index ) | ||
393 | { | ||
394 | pos = pos->next; | ||
395 | counter ++; | ||
396 | } | ||
397 | use_preconfigured_list = GNUNET_YES; | ||
398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
399 | "Using learned hostlist `%s'\n", pos->hostlist_uri); | ||
400 | return strdup(pos->hostlist_uri); | ||
401 | } | ||
402 | |||
360 | 403 | ||
361 | #define CURL_EASY_SETOPT(c, a, b) do { ret = curl_easy_setopt(c, a, b); if (ret != CURLE_OK) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, _("%s failed at %s:%d: `%s'\n"), "curl_easy_setopt", __FILE__, __LINE__, curl_easy_strerror(ret)); } while (0); | 404 | #define CURL_EASY_SETOPT(c, a, b) do { ret = curl_easy_setopt(c, a, b); if (ret != CURLE_OK) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, _("%s failed at %s:%d: `%s'\n"), "curl_easy_setopt", __FILE__, __LINE__, curl_easy_strerror(ret)); } while (0); |
362 | 405 | ||
@@ -591,7 +634,7 @@ download_hostlist () | |||
591 | clean_up (); | 634 | clean_up (); |
592 | return; | 635 | return; |
593 | } | 636 | } |
594 | current_url = get_url (); | 637 | current_url = get_list_url (); |
595 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 638 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
596 | _("Bootstrapping using hostlist at `%s'.\n"), | 639 | _("Bootstrapping using hostlist at `%s'.\n"), |
597 | current_url); | 640 | current_url); |
@@ -747,9 +790,9 @@ schedule_hostlist_task () | |||
747 | } | 790 | } |
748 | 791 | ||
749 | /** | 792 | /** |
750 | * Task that checks if we should try to download a hostlist. | 793 | * Task that writes hostlist entries to a file on a regular base |
751 | * If so, we initiate the download, otherwise we schedule | 794 | * cls closure |
752 | * this task again for a later time. | 795 | * tc TaskContext |
753 | */ | 796 | */ |
754 | static void | 797 | static void |
755 | hostlist_saving_task (void *cls, | 798 | hostlist_saving_task (void *cls, |
@@ -1175,6 +1218,7 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1175 | *msgh = NULL; | 1218 | *msgh = NULL; |
1176 | linked_list_head = NULL; | 1219 | linked_list_head = NULL; |
1177 | linked_list_tail = NULL; | 1220 | linked_list_tail = NULL; |
1221 | use_preconfigured_list = GNUNET_YES; | ||
1178 | load_hostlist_file (); | 1222 | load_hostlist_file (); |
1179 | 1223 | ||
1180 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1224 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |