gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r11065 - gnunet/src/hostlist
Date: Mon, 26 Apr 2010 13:51:03 +0200

Author: wachs
Date: 2010-04-26 13:51:03 +0200 (Mon, 26 Apr 2010)
New Revision: 11065

Modified:
   gnunet/src/hostlist/hostlist-client.c
Log:


Modified: gnunet/src/hostlist/hostlist-client.c
===================================================================
--- gnunet/src/hostlist/hostlist-client.c       2010-04-26 11:38:13 UTC (rev 
11064)
+++ gnunet/src/hostlist/hostlist-client.c       2010-04-26 11:51:03 UTC (rev 
11065)
@@ -149,47 +149,36 @@
 static CURLM *multi;
 
 /**
- * ID of the current task scheduled.
+ * Amount of time we wait between hostlist downloads.
  */
+static struct GNUNET_TIME_Relative hostlist_delay;
+
+/**
+ * ID of the task, checking if hostlist download should take plate
+ */
 static GNUNET_SCHEDULER_TaskIdentifier ti_check_download;
 
 /**
- * ID of the current task scheduled.
+ * ID of the task downloading the hostlist
  */
 static GNUNET_SCHEDULER_TaskIdentifier ti_download;
 
 /**
- * ID of the current hostlist saving task scheduled.
+ * ID of the task saving the hostlsit in a regular intervall
  */
 static GNUNET_SCHEDULER_TaskIdentifier ti_saving_task;
 
 /**
- * ID of the current hostlist saving task scheduled.
+ * ID of the task called to initiate a download
  */
 static GNUNET_SCHEDULER_TaskIdentifier ti_download_dispatcher_task;
 
-
 /**
- * ID of the task checking the intervall between to hostlist tests
+ * ID of the task controlling the locking between two hostlist tests
  */
 static GNUNET_SCHEDULER_TaskIdentifier ti_testing_intervall_task;
 
 /**
- * Amount of time we wait between hostlist downloads.
- */
-static struct GNUNET_TIME_Relative hostlist_delay;
-
-/**
- * Set to GNUNET_YES if the current URL had some problems.
- */ 
-static int bogus_url;
-
-/**
- * Number of active connections (according to core service).
- */
-static unsigned int connection_count;
-
-/**
  * At what time MUST the current hostlist request be done?
  */
 static struct GNUNET_TIME_Absolute end_time;
@@ -219,32 +208,51 @@
  */
 static struct Hostlist * hostlist_to_test;
 
-static int testing_hostlist;
+/**
+ * Set to GNUNET_YES if the current URL had some problems.
+ */
+static int stat_bogus_url;
 
-static int testing_allowed;
+/**
+ * Value controlling if a hostlist is tested at the moment
+ */
+static int stat_testing_hostlist;
 
-static int download_in_progress;
+/**
+ * Value controlling if a hostlist testing is allowed at the moment
+ */
+static int stat_testing_allowed;
 
 /**
- * Value saying if preconfigured  is used
+ * Value controlling if a hostlist download is running at the moment
  */
-static unsigned int use_preconfigured_list;
+static int stat_download_in_progress;
 
 /**
+ * Value saying if a preconfigured bootstrap server is used
+ */
+static unsigned int stat_use_bootstrap;
+/**
  * Set if we are allowed to learn new hostlists and use them
  */
-static int learning;
+static int stat_learning;
 
 /**
+ * Value saying if hostlist download was successful
+ */
+static unsigned int stat_download_successful;
+
+/**
  * Value saying how many valid HELLO messages were obtained during download
  */
-static unsigned int hellos_obtained;
+static unsigned int stat_hellos_obtained;
 
 /**
- * Value saying if hostlist download was successful
+ * Number of active connections (according to core service).
  */
-static unsigned int download_successful;
+static unsigned int stat_connection_count;
 
+
 /**
  * Process downloaded bits by calling callback on each HELLO.
  *
@@ -255,7 +263,7 @@
  * @return number of bytes that were processed (always size*nmemb)
  */
 static size_t
-download_hostlist_processor (void *ptr, 
+callback_download (void *ptr, 
                             size_t size, 
                             size_t nmemb, 
                             void *ctx)
@@ -268,7 +276,7 @@
   uint16_t msize;
 
   total = size * nmemb;
-  if ( (total == 0) || (bogus_url) )
+  if ( (total == 0) || (stat_bogus_url) )
     {
       return total;  /* ok, no data or bogus data */
     }
@@ -304,7 +312,7 @@
                      _("Invalid `%s' message received from hostlist at 
`%s'\n"),
                      "HELLO",
                      current_url); 
-         bogus_url = 1;
+         stat_bogus_url = 1;
          return total;
        }
       if (download_pos < msize)
@@ -323,7 +331,7 @@
                                    gettext_noop ("# valid HELLOs downloaded 
from hostlist servers"), 
                                    1, 
                                    GNUNET_NO);
-         hellos_obtained++;
+         stat_hellos_obtained++;
          GNUNET_TRANSPORT_offer_hello (transport, msg);
        }
       else
@@ -336,7 +344,7 @@
                      _("Invalid `%s' message received from hostlist at 
`%s'\n"),
                      "HELLO",
                      current_url);
-         bogus_url = GNUNET_YES;
+         stat_bogus_url = GNUNET_YES;
          return total;
        }
       memmove (download_buffer,
@@ -354,7 +362,7 @@
  * @return NULL if there is no URL available
  */
 static char *
-get_bootstrap_url ()
+get_bootstrap_server ()
 {
   char *servers;
   char *ret;
@@ -420,21 +428,21 @@
  * @return uri to use, NULL if there is no URL available
  */
 static char *
-get_list_url ()
+download_get_url ()
 {
   uint32_t index;
   unsigned int counter;
   struct Hostlist * pos;
 
-  if ( GNUNET_NO == learning)
+  if ( GNUNET_NO == stat_learning)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Using preconfigured bootstrap server\n");
     current_hostlist = NULL;
-    return get_bootstrap_url();
+    return get_bootstrap_server();
   }
 
-  if ( ( GNUNET_YES == testing_hostlist) && (NULL != hostlist_to_test) )
+  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");
@@ -442,13 +450,13 @@
     return strdup(hostlist_to_test->hostlist_uri);
   }
 
-  if ( (GNUNET_YES == use_preconfigured_list) ||
+  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_url();
+    return get_bootstrap_server();
   }
   index = GNUNET_CRYPTO_random_u32 ( GNUNET_CRYPTO_QUALITY_WEAK, 
linked_list_size);
   counter = 0;
@@ -468,7 +476,7 @@
 #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 load persistent hostlist file during hostlist client shutdown
+ * 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 );
@@ -509,7 +517,7 @@
 }
 
 /**
- * Method to check if URI is in hostlist linked list
+ * 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
  */
@@ -530,7 +538,7 @@
 
 
 /**
- * Method returning the uri with the lowest quality in the datastore
+ * Method returning the hostlist element with the lowest quality in the 
datastore
  * @return hostlist with lowest quality
  */
 static struct Hostlist *
@@ -588,7 +596,7 @@
 
   GNUNET_free (lowest_quality);
 
-  testing_hostlist = GNUNET_NO;
+  stat_testing_hostlist = GNUNET_NO;
   return;
 }
 
@@ -599,15 +607,15 @@
 static void update_hostlist ( )
 {
   char *stat;
-  if ( ((use_preconfigured_list == GNUNET_NO) && ( NULL != current_hostlist )) 
||
-       ((testing_hostlist == GNUNET_YES) && ( NULL != current_hostlist )) )
+  if ( ((stat_use_bootstrap == GNUNET_NO) && ( NULL != current_hostlist )) ||
+       ((stat_testing_hostlist == GNUNET_YES) && ( NULL != current_hostlist )) 
)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 "Updating hostlist statics for URI 
`%s'\n",current_hostlist->hostlist_uri );
-     current_hostlist->hello_count = hellos_obtained;
+     current_hostlist->hello_count = stat_hellos_obtained;
      current_hostlist->time_last_usage = GNUNET_TIME_absolute_get();
-     current_hostlist->quality = checked_add ( current_hostlist->quality, 
(hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO));
-     if ( GNUNET_YES == download_successful )
+     current_hostlist->quality = checked_add ( current_hostlist->quality, 
(stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO));
+     if ( GNUNET_YES == stat_download_successful )
      {
        current_hostlist->times_used++;
        current_hostlist->quality = checked_add ( current_hostlist->quality, 
HOSTLIST_SUCCESSFUL_DOWNLOAD);
@@ -627,18 +635,18 @@
   current_hostlist = NULL;
   /* Alternating the usage of preconfigured and learned hostlists */
 
-  if (testing_hostlist == GNUNET_YES)
+  if (stat_testing_hostlist == GNUNET_YES)
     return;
 
-  if ( GNUNET_YES == learning)
+  if ( GNUNET_YES == stat_learning)
     {
-    if (use_preconfigured_list == GNUNET_YES)
-      use_preconfigured_list = GNUNET_NO;
+    if (stat_use_bootstrap == GNUNET_YES)
+      stat_use_bootstrap = GNUNET_NO;
     else
-      use_preconfigured_list = GNUNET_YES;
+      stat_use_bootstrap = GNUNET_YES;
     }
   else
-    use_preconfigured_list = GNUNET_YES;
+    stat_use_bootstrap = GNUNET_YES;
 }
 
 /**
@@ -650,15 +658,15 @@
 {
   CURLMcode mret;
 
-  if ( ( testing_hostlist == GNUNET_YES ) && ( GNUNET_NO == 
download_successful) && (NULL != hostlist_to_test))
+  if ( ( stat_testing_hostlist == GNUNET_YES ) && ( GNUNET_NO == 
stat_download_successful) && (NULL != hostlist_to_test))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 _("Advertised hostlist with URI `%s' could not be downloaded. 
Advertised URI gets dismissed.\n"),hostlist_to_test->hostlist_uri);
   }
 
-  if ( testing_hostlist == GNUNET_YES )
+  if ( stat_testing_hostlist == GNUNET_YES )
     {
-    testing_hostlist = GNUNET_NO;
+    stat_testing_hostlist = GNUNET_NO;
     }
   if ( NULL != hostlist_to_test)
   {
@@ -693,7 +701,7 @@
   GNUNET_free_non_null (current_url);
   current_url = NULL;
 
-  download_in_progress = GNUNET_NO;
+  stat_download_in_progress = GNUNET_NO;
 }
 
 /**
@@ -704,7 +712,7 @@
  * @param tc task context, unused
  */
 static void
-multi_ready (void *cls,
+task_download (void *cls,
              const struct GNUNET_SCHEDULER_TaskContext *tc);
 
 /**
@@ -712,7 +720,7 @@
  * receiving task with the scheduler.
  */
 static void
-run_multi ()
+download_prepare ()
 {
   CURLMcode mret;
   fd_set rs;
@@ -766,7 +774,7 @@
                                    rtime,
                                    grs,
                                    gws,
-                                   &multi_ready,
+                                   &task_download,
                                    multi);
   GNUNET_NETWORK_fdset_destroy (gws);
   GNUNET_NETWORK_fdset_destroy (grs);
@@ -781,7 +789,7 @@
  * @param tc task context, unused
  */
 static void
-multi_ready (void *cls,
+task_download (void *cls,
             const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   unsigned int counter;
@@ -847,15 +855,15 @@
                    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                                _("Download of hostlist `%s' completed.\n"),
                                current_url);
-                   download_successful = GNUNET_YES;
+                   stat_download_successful = GNUNET_YES;
                    update_hostlist();
-                   if (GNUNET_YES == testing_hostlist)
+                   if (GNUNET_YES == stat_testing_hostlist)
                     {
                       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                                         _("Adding successfully tested hostlist 
`%s' datastore.\n"),current_url);
                      insert_hostlist();
                      hostlist_to_test = NULL;
-                     testing_hostlist = GNUNET_NO;
+                     stat_testing_hostlist = GNUNET_NO;
                     }
                    }
                  clean_up ();
@@ -877,7 +885,7 @@
                  curl_multi_strerror (mret));
       clean_up ();
     }
-  run_multi ();
+  download_prepare ();
 }
 
 
@@ -892,7 +900,7 @@
   CURLMcode mret;
 
 
-  current_url = get_list_url ();
+  current_url = download_get_url ();
   if (current_url == NULL)
     return;
   curl = curl_easy_init ();
@@ -907,9 +915,9 @@
              _("Bootstrapping using hostlist at `%s'.\n"), 
              current_url);
 
-  download_in_progress = GNUNET_YES;
-  download_successful = GNUNET_NO;
-  hellos_obtained = 0;
+  stat_download_in_progress = GNUNET_YES;
+  stat_download_successful = GNUNET_NO;
+  stat_hellos_obtained = 0;
 
   GNUNET_STATISTICS_update (stats, 
                            gettext_noop ("# hostlist downloads initiated"), 
@@ -918,10 +926,10 @@
   if (proxy != NULL)
     CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy);    
   download_pos = 0;
-  bogus_url = 0;
+  stat_bogus_url = 0;
   CURL_EASY_SETOPT (curl,
                    CURLOPT_WRITEFUNCTION, 
-                   &download_hostlist_processor);
+                   &callback_download);
   if (ret != CURLE_OK)
     {
       clean_up ();
@@ -996,12 +1004,12 @@
       return;
     }
   end_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
-  run_multi ();
+  download_prepare ();
 }  
 
 
 static void
-download_dispatcher (void *cls,
+task_download_dispatcher (void *cls,
             const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   ti_download_dispatcher_task = GNUNET_SCHEDULER_NO_TASK;
@@ -1009,7 +1017,7 @@
       return;
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Download is initiated...\n");
-   if ( GNUNET_NO == download_in_progress )
+   if ( GNUNET_NO == stat_download_in_progress )
    {
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Download can start immediately...\n");
@@ -1021,7 +1029,7 @@
                "Download in progess, have to wait...\n");
      ti_download_dispatcher_task = GNUNET_SCHEDULER_add_delayed (sched,
                                                               
WAITING_INTERVALL,
-                                                              
&download_dispatcher,
+                                                              
&task_download_dispatcher,
                                                               NULL);
    }
 }
@@ -1032,17 +1040,17 @@
  * this task again for a later time.
  */
 static void
-check_task (void *cls,
+task_check (void *cls,
            const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   ti_check_download = GNUNET_SCHEDULER_NO_TASK;
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
     return;
 
-  if (connection_count < MIN_CONNECTIONS)
+  if (stat_connection_count < MIN_CONNECTIONS)
   {
     ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now ( sched,
-                                                          &download_dispatcher,
+                                                          
&task_download_dispatcher,
                                                           NULL);
   }
 
@@ -1059,9 +1067,9 @@
     hostlist_delay = GNUNET_TIME_UNIT_SECONDS;
   else
     hostlist_delay = GNUNET_TIME_relative_multiply (hostlist_delay, 2);
-  if (hostlist_delay.value > GNUNET_TIME_UNIT_HOURS.value * (1 + 
connection_count))
+  if (hostlist_delay.value > GNUNET_TIME_UNIT_HOURS.value * (1 + 
stat_connection_count))
     hostlist_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS,
-                                                    (1 + connection_count));
+                                                    (1 + 
stat_connection_count));
   GNUNET_STATISTICS_set (stats,
                          gettext_noop("# seconds between hostlist downloads"),
                          hostlist_delay.value,
@@ -1073,12 +1081,12 @@
     }  
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               _("Have %u/%u connections.  Will consider downloading hostlist 
in %llums\n"),
-              connection_count,
+              stat_connection_count,
               MIN_CONNECTIONS,
               (unsigned long long) delay.value);
   ti_check_download = GNUNET_SCHEDULER_add_delayed (sched,
                                                delay,
-                                               &check_task,
+                                               &task_check,
                                                NULL);
 }
 
@@ -1094,7 +1102,7 @@
   ti_testing_intervall_task = GNUNET_SCHEDULER_NO_TASK;
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
     return;
-   testing_allowed = GNUNET_OK;
+   stat_testing_allowed = GNUNET_OK;
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Testing new hostlist advertisements is allowed again\n");
 }
@@ -1140,7 +1148,7 @@
                 struct GNUNET_TIME_Relative latency,
                 uint32_t distance)
 {
-  connection_count++;
+  stat_connection_count++;
   GNUNET_STATISTICS_update (stats, 
                            gettext_noop ("# active connections"), 
                            1, 
@@ -1159,7 +1167,7 @@
                    const struct
                    GNUNET_PeerIdentity * peer)
 {
-  connection_count--;
+  stat_connection_count--;
   GNUNET_STATISTICS_update (stats, 
                            gettext_noop ("# active connections"), 
                            -1, 
@@ -1217,13 +1225,13 @@
       return GNUNET_OK;
     }
 
-  if ( GNUNET_NO == testing_allowed )
+  if ( GNUNET_NO == stat_testing_allowed )
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Currently not accepting new advertisements: interval between 
to advertisements is not reached\n");
       return GNUNET_SYSERR;
     }
-  if ( GNUNET_YES == testing_hostlist )
+  if ( GNUNET_YES == stat_testing_hostlist )
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Currently not accepting new advertisements: we are already 
testing a hostlist\n");
@@ -1238,8 +1246,8 @@
   hostlist->quality = HOSTLIST_INITIAL;
   hostlist_to_test = hostlist;
 
-  testing_hostlist = GNUNET_YES;
-  testing_allowed = GNUNET_NO;
+  stat_testing_hostlist = GNUNET_YES;
+  stat_testing_allowed = GNUNET_NO;
   ti_testing_intervall_task = GNUNET_SCHEDULER_add_delayed (sched,
                                                          TESTING_INTERVALL,
                                                          
&task_testing_intervall_reset,
@@ -1250,7 +1258,7 @@
             TESTING_INTERVALL);
 
   ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now (sched,
-                                                     &download_dispatcher,
+                                                     &task_download_dispatcher,
                                                      NULL);
 
   return GNUNET_OK;
@@ -1276,7 +1284,7 @@
              "Statistics request done, scheduling hostlist download\n");
 #endif
   ti_check_download = GNUNET_SCHEDULER_add_now (sched,
-                                           &check_task,
+                                           &task_check,
                                            NULL);
 }
 
@@ -1512,16 +1520,16 @@
                                             "HTTP-PROXY", 
                                             &proxy))
     proxy = NULL;
-  learning = learn;
+  stat_learning = learn;
   *ch = &handler_connect;
   *dh = &handler_disconnect;
   linked_list_head = NULL;
   linked_list_tail = NULL;
-  use_preconfigured_list = GNUNET_YES;
-  testing_hostlist = GNUNET_NO;
-  testing_allowed = GNUNET_YES;
+  stat_use_bootstrap = GNUNET_YES;
+  stat_testing_hostlist = GNUNET_NO;
+  stat_testing_allowed = GNUNET_YES;
 
-  if ( GNUNET_YES == learning )
+  if ( GNUNET_YES == stat_learning )
   {
     *msgh = &handler_advertisement;
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -1579,7 +1587,7 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Hostlist client shutdown\n");
 #endif
-  if ( GNUNET_YES == learning )
+  if ( GNUNET_YES == stat_learning )
     save_hostlist_file ( GNUNET_YES );
 
   if (ti_saving_task != GNUNET_SCHEDULER_NO_TASK)





reply via email to

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