gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10936 - gnunet/src/hostlist


From: gnunet
Subject: [GNUnet-SVN] r10936 - gnunet/src/hostlist
Date: Fri, 16 Apr 2010 17:32:05 +0200

Author: wachs
Date: 2010-04-16 17:32:05 +0200 (Fri, 16 Apr 2010)
New Revision: 10936

Modified:
   gnunet/src/hostlist/hostlist-client.c
Log:
hostlist client is now alternating between preconfigured servers and learned 
hostlists when downloading

Modified: gnunet/src/hostlist/hostlist-client.c
===================================================================
--- gnunet/src/hostlist/hostlist-client.c       2010-04-16 15:15:04 UTC (rev 
10935)
+++ gnunet/src/hostlist/hostlist-client.c       2010-04-16 15:32:05 UTC (rev 
10936)
@@ -179,16 +179,27 @@
  */
 static struct GNUNET_TIME_Absolute end_time;
 
-/* Head of the linked list used to store hostlists */
+/**
+ * Head of the linked list used to store hostlists
+ */
 static struct Hostlist * linked_list_head;
 
-/* Tail of the linked list used to store hostlists */
+/**
+ *  Tail of the linked list used to store hostlists
+ */
 static struct Hostlist * linked_list_tail;
 
-/* Size of the linke list  used to store hostlists */
+/*
+ *  Size of the linke list  used to store hostlists
+ */
 static unsigned int linked_list_size;
 
 /**
+ * Value saying if preconfigured  is used
+ */
+static unsigned int use_preconfigured_list;
+
+/**
  * Process downloaded bits by calling callback on each HELLO.
  *
  * @param ptr buffer with downloaded data
@@ -296,7 +307,7 @@
  * @return NULL if there is no URL available
  */
 static char *
-get_url ()
+get_bootstrap_url ()
 {
   char *servers;
   char *ret;
@@ -305,13 +316,13 @@
 
   if (GNUNET_OK != 
       GNUNET_CONFIGURATION_get_value_string (cfg,
-                                            "HOSTLIST",
-                                            "SERVERS",
-                                            &servers))
+                                             "HOSTLIST",
+                                             "SERVERS",
+                                             &servers))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                 _("No `%s' specified in `%s' configuration, will not 
bootstrap.\n"),
-                 "SERVERS", "HOSTLIST");
+                  _("No `%s' specified in `%s' configuration, will not 
bootstrap.\n"),
+                  "SERVERS", "HOSTLIST");
       return NULL;
     }
 
@@ -330,8 +341,8 @@
   if (urls == 0)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                 _("No `%s' specified in `%s' configuration, will not 
bootstrap.\n"),
-                 "SERVERS", "HOSTLIST");
+                  _("No `%s' specified in `%s' configuration, will not 
bootstrap.\n"),
+                  "SERVERS", "HOSTLIST");
       GNUNET_free (servers);
       return NULL;
     }
@@ -357,7 +368,39 @@
   return ret;
 }
 
+/**
+ * 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 *
+get_list_url ()
+{
+  uint32_t index;
+  unsigned int counter;
+  struct Hostlist * pos;
 
+  if ( GNUNET_YES == use_preconfigured_list)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Using preconfigured bootstrap server\n");
+    use_preconfigured_list = GNUNET_NO;
+    return get_bootstrap_url();
+  }
+  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 ++;
+    }
+  use_preconfigured_list = GNUNET_YES;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Using learned hostlist `%s'\n", pos->hostlist_uri);
+  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);
 
 
@@ -591,7 +634,7 @@
       clean_up ();
       return;
     }
-  current_url = get_url ();
+  current_url = get_list_url ();
   GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
              _("Bootstrapping using hostlist at `%s'.\n"), 
              current_url);
@@ -747,9 +790,9 @@
 }
 
 /**
- * Task that checks if we should try to download a hostlist.
- * If so, we initiate the download, otherwise we schedule
- * this task again for a later time.
+ * Task that writes hostlist entries to a file on a regular base
+ * cls closure
+ * tc TaskContext
  */
 static void
 hostlist_saving_task (void *cls,
@@ -1175,6 +1218,7 @@
     *msgh = NULL;
   linked_list_head = NULL;
   linked_list_tail = NULL;
+  use_preconfigured_list = GNUNET_YES;
   load_hostlist_file ();
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,





reply via email to

[Prev in Thread] Current Thread [Next in Thread]