gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r10975 - gnunet/src/hostlist
Date: Mon, 19 Apr 2010 14:35:59 +0200

Author: wachs
Date: 2010-04-19 14:35:59 +0200 (Mon, 19 Apr 2010)
New Revision: 10975

Modified:
   gnunet/src/hostlist/hostlist-client.c
   gnunet/src/hostlist/hostlist-client.h
Log:
added code to update hostlist statistics

Modified: gnunet/src/hostlist/hostlist-client.c
===================================================================
--- gnunet/src/hostlist/hostlist-client.c       2010-04-19 11:00:23 UTC (rev 
10974)
+++ gnunet/src/hostlist/hostlist-client.c       2010-04-19 12:35:59 UTC (rev 
10975)
@@ -92,7 +92,7 @@
   uint32_t hello_count;
 
   /**
-   * Number of times the hostlist was obtained
+   * Number of times the hostlist was successfully obtained
    */
   uint32_t times_used;
 
@@ -189,6 +189,12 @@
  */
 static struct Hostlist * linked_list_tail;
 
+/**
+ *  Current hostlist used for downloading
+ */
+static struct Hostlist * current_hostlist;
+
+
 /*
  *  Size of the linke list  used to store hostlists
  */
@@ -200,6 +206,21 @@
 static unsigned int use_preconfigured_list;
 
 /**
+ * Set if we are allowed to learn new hostlists and use them
+ */
+static int learning;
+
+/**
+ * Value saying how many valid HELLO messages were obtained during download
+ */
+static unsigned int hellos_obtained;
+
+/**
+ * Value saying how many valid HELLO messages were obtained during download
+ */
+static unsigned int download_successful;
+
+/**
  * Process downloaded bits by calling callback on each HELLO.
  *
  * @param ptr buffer with downloaded data
@@ -276,7 +297,8 @@
          GNUNET_STATISTICS_update (stats, 
                                    gettext_noop ("# valid HELLOs downloaded 
from hostlist servers"), 
                                    1, 
-                                   GNUNET_NO);  
+                                   GNUNET_NO);
+         hellos_obtained++;
          GNUNET_TRANSPORT_offer_hello (transport, msg);
        }
       else
@@ -379,12 +401,19 @@
   unsigned int counter;
   struct Hostlist * pos;
 
+  if ( GNUNET_NO == learning)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Using preconfigured bootstrap server\n");
+    current_hostlist = NULL;
+    return get_bootstrap_url();
+  }
   if ( (GNUNET_YES == use_preconfigured_list) ||
        (linked_list_size == 0) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Using preconfigured bootstrap server\n");
-    use_preconfigured_list = GNUNET_NO;
+    current_hostlist = NULL;
     return get_bootstrap_url();
   }
   index = GNUNET_CRYPTO_random_u32 ( GNUNET_CRYPTO_QUALITY_WEAK, 
linked_list_size);
@@ -395,9 +424,9 @@
       pos = pos->next;
       counter ++;
     }
-  use_preconfigured_list = GNUNET_YES;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Using learned hostlist `%s'\n", pos->hostlist_uri);
+  current_hostlist = pos;
   return strdup(pos->hostlist_uri);
 }
 
@@ -419,6 +448,78 @@
 static void save_hostlist_file ( int shutdown );
 
 /**
+ * add val2 to val1 with overflow check
+ * return = val1 + val2
+ * @val1 value 1
+ * @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;
+}
+
+/**
+ * substract val2 from val1 with underflow check
+ * return = val1 - val2
+ * @val1 value 1
+ * @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 updating hostlist statistics
+ */
+static void update_hostlist ( )
+{
+  if ( (use_preconfigured_list == GNUNET_NO) && ( 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->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->times_used++;
+       current_hostlist->quality = checked_add( current_hostlist->quality, 
HOSTLIST_SUCCESSFUL_DOWNLOAD);
+     }
+     else
+       current_hostlist->quality = checked_sub ( current_hostlist->quality, 
HOSTLIST_FAILED_DOWNLOAD );
+  }
+  current_hostlist = NULL;
+  /* Alternating the usage of preconfigured and learned hostlists */
+
+  if ( GNUNET_YES == learning)
+    {
+    if (use_preconfigured_list == GNUNET_YES)
+      use_preconfigured_list = GNUNET_NO;
+    else
+      use_preconfigured_list = GNUNET_YES;
+    }
+  else
+    use_preconfigured_list = GNUNET_YES;
+}
+
+/**
  * Clean up the state from the task that downloaded the
  * hostlist and schedule the next task.
  */
@@ -452,6 +553,7 @@
     }  
   GNUNET_free_non_null (current_url);
   current_url = NULL;
+
   schedule_hostlist_task ();
 }
 
@@ -486,6 +588,7 @@
                  "Shutdown requested while trying to download hostlist from 
`%s'\n",
                  current_url);
 #endif
+      update_hostlist();
       clean_up ();
       return;
     }
@@ -494,6 +597,7 @@
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                  _("Timeout trying to download hostlist from `%s'\n"),
                  current_url);
+      update_hostlist();
       clean_up ();
       return;
     }
@@ -526,9 +630,13 @@
                               __LINE__,
                               curl_easy_strerror (msg->data.result));          
  
                  else
+                   {
                    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                                _("Download of hostlist `%s' completed.\n"),
                                current_url);
+                   download_successful = GNUNET_YES;
+                   update_hostlist();
+                   }
                  clean_up ();
                  return;
                default:
@@ -641,6 +749,8 @@
   GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
              _("Bootstrapping using hostlist at `%s'.\n"), 
              current_url);
+  hellos_obtained = 0;
+  download_successful = GNUNET_NO;
   GNUNET_STATISTICS_update (stats, 
                            gettext_noop ("# hostlist downloads initiated"), 
                            1, 
@@ -1225,16 +1335,25 @@
   linked_list_head = NULL;
   linked_list_tail = NULL;
   use_preconfigured_list = GNUNET_YES;
-  load_hostlist_file ();
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+  learning = learn;
+  if ( GNUNET_YES == learning )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              _("Learning is enabled on this peer\n"));
+    load_hostlist_file ();
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               _("Hostlists will be saved to file again in  %llums\n"),
               (unsigned long long) SAVING_INTERVALL.value);
-  saving_task = GNUNET_SCHEDULER_add_delayed (sched,
+    saving_task = GNUNET_SCHEDULER_add_delayed (sched,
                                                SAVING_INTERVALL,
                                                &hostlist_saving_task,
                                                NULL);
-
+  }
+  else
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              _("Learning is not enabled on this peer\n"));
+  }
   GNUNET_STATISTICS_get (stats,
                         "hostlist",
                         gettext_noop("# seconds between hostlist downloads"),

Modified: gnunet/src/hostlist/hostlist-client.h
===================================================================
--- gnunet/src/hostlist/hostlist-client.h       2010-04-19 11:00:23 UTC (rev 
10974)
+++ gnunet/src/hostlist/hostlist-client.h       2010-04-19 12:35:59 UTC (rev 
10975)
@@ -42,8 +42,10 @@
 #define HOSTLIST_INITIAL 10000
 #define HOSTLIST_FAILED_DOWNLOAD 100
 #define HOSTLIST_SUCCESSFUL_DOWNLOAD 100
+#define HOSTLIST_SUCCESSFUL_HELLO 1
 
 
+
 /**
  * Start downloading hostlists from hostlist servers as necessary.
  *





reply via email to

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