+/**
+ * Method deciding if a preconfigured or advertisied hostlist is used on a 50:50 ratio
+ * @return uri to use, NULL if there is no URL available
+ */
+static char *
+download_get_url ()
+{
+ uint32_t index;
+ unsigned int counter;
+ struct Hostlist * pos;
+
+ if ( GNUNET_NO == stat_learning)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using preconfigured bootstrap server\n");
+ current_hostlist = NULL;
+ return get_bootstrap_server();
+ }
+
+ if ( ( GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing new advertised hostlist if it is obtainable\n");
+ current_hostlist = hostlist_to_test;
+ return strdup(hostlist_to_test->hostlist_uri);
+ }
+
+ if ( (GNUNET_YES == stat_use_bootstrap) ||
+ (linked_list_size == 0) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using preconfigured bootstrap server\n");
+ current_hostlist = NULL;
+ return get_bootstrap_server();
+ }
+ index = GNUNET_CRYPTO_random_u32 ( GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size);
+ counter = 0;
+ pos = linked_list_head;
+ while ( counter < index )
+ {
+ pos = pos->next;
+ counter ++;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using learned hostlist `%s'\n", pos->hostlist_uri);
+ current_hostlist = pos;
+ return strdup(pos->hostlist_uri);
+}
+
+
+#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)
+
+/**
+ * Method to save hostlist to a file during hostlist client shutdown
+ * @param shutdown set if called because of shutdown, entries in linked list will be destroyed
+ */
+static void save_hostlist_file ( int shutdown );
+
+/**
+ * add val2 to val1 with overflow check
+ * @param val1 value 1
+ * @param val2 value 2
+ * @return result
+ */
+static uint64_t checked_add (uint64_t val1, uint64_t val2)
+{
+ static uint64_t temp;
+ static uint64_t maxv;
+
+ maxv = 0;
+ maxv--;
+
+ temp = val1+val2;
+ if ( temp < val1)
+ return maxv;
+ else
+ return temp;
+}
+
+/**
+ * Subtract val2 from val1 with underflow check
+ * @param val1 value 1
+ * @param val2 value 2
+ * @return result
+ */
+static uint64_t checked_sub (uint64_t val1, uint64_t val2)
+{
+ if ( val1 <= val2)
+ return 0;
+ else
+ return (val1-val2);
+}
+
+/**
+ * Method to check if a URI is in hostlist linked list
+ * @param uri uri to check
+ * @return GNUNET_YES if existing in linked list, GNUNET_NO if not
+ */
+static int
+linked_list_contains (const char * uri)
+{
+ struct Hostlist * pos;
+
+ pos = linked_list_head;
+ while (pos != NULL)
+ {
+ if (0 == strcmp(pos->hostlist_uri, uri) )
+ return GNUNET_YES;
+ pos = pos->next;
+ }
+ return GNUNET_NO;
+}
+
+
+/**
+ * Method returning the hostlist element with the lowest quality in the datastore
+ * @return hostlist with lowest quality
+ */
+static struct Hostlist *
+linked_list_get_lowest_quality ( )
+{
+ struct Hostlist * pos;
+ struct Hostlist * lowest;