fix
[oweals/gnunet.git] / src / hostlist / hostlist-client.c
index a5d345b605df447db8a2efe07254b3cb81ba73e6..d2fa654339cfc43653f5d91c75309128d6eb7a00 100644 (file)
@@ -108,11 +108,6 @@ struct Hostlist
  */
 static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
-/**
- * Our scheduler.
- */
-static struct GNUNET_SCHEDULER_Handle *sched;
-
 /**
  * Statistics handle.
  */
@@ -340,7 +335,7 @@ callback_download (void *ptr,
                                    1, 
                                    GNUNET_NO);
          stat_hellos_obtained++;
-         GNUNET_TRANSPORT_offer_hello (transport, msg);
+         GNUNET_TRANSPORT_offer_hello (transport, msg, NULL, NULL);
        }
       else
        {
@@ -769,8 +764,7 @@ download_prepare ()
               "Scheduling task for hostlist download using cURL\n");
 #endif
   ti_download
-    = GNUNET_SCHEDULER_add_select (sched,
-                                   GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+    = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
                                    GNUNET_SCHEDULER_NO_TASK,
                                    rtime,
                                    grs,
@@ -1036,8 +1030,7 @@ task_download_dispatcher (void *cls,
    {
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Download in progess, have to wait...\n");
-     ti_download_dispatcher_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                                              WAITING_INTERVALL,
+     ti_download_dispatcher_task = GNUNET_SCHEDULER_add_delayed (WAITING_INTERVALL,
                                                               &task_download_dispatcher,
                                                               NULL);
    }
@@ -1061,8 +1054,7 @@ task_check (void *cls,
 
   if (stat_connection_count < MIN_CONNECTIONS)
   {
-    ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now ( sched,
-                                                          &task_download_dispatcher,
+    ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now (&task_download_dispatcher,
                                                           NULL);
   }
 
@@ -1093,8 +1085,7 @@ task_check (void *cls,
               stat_connection_count,
               MIN_CONNECTIONS,
               (unsigned long long) delay.rel_value);
-  ti_check_download = GNUNET_SCHEDULER_add_delayed (sched,
-                                               delay,
+  ti_check_download = GNUNET_SCHEDULER_add_delayed (delay,
                                                &task_check,
                                                NULL);
 }
@@ -1136,8 +1127,7 @@ task_hostlist_saving (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               _("Hostlists will be saved to file again in %llums\n"),
               (unsigned long long) SAVING_INTERVALL.rel_value);
-  ti_saving_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                               SAVING_INTERVALL,
+  ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL,
                                                &task_hostlist_saving,
                                                NULL);
 }
@@ -1147,27 +1137,20 @@ task_hostlist_saving (void *cls,
  *
  * @param cls closure
  * @param peer peer identity this notification is about
- * @param latency reported latency of the connection with 'other'
- * @param distance reported distance (DV) to 'other' 
+ * @param atsi performance data
  */
 static void
 handler_connect (void *cls,
                 const struct
                 GNUNET_PeerIdentity * peer,
-                struct GNUNET_TIME_Relative latency,
-                uint32_t distance)
+                const struct GNUNET_TRANSPORT_ATS_Information *atsi)
 {
-  unsigned int max = 0 ;
-  max --;
-
-  if (stat_connection_count < max)
-  {
+  GNUNET_assert (stat_connection_count < UINT_MAX);
   stat_connection_count++;
   GNUNET_STATISTICS_update (stats, 
                            gettext_noop ("# active connections"), 
                            1, 
                            GNUNET_NO);
-  }
 }
 
 
@@ -1185,9 +1168,9 @@ handler_disconnect (void *cls,
   GNUNET_assert (stat_connection_count > 0);
   stat_connection_count--;
   GNUNET_STATISTICS_update (stats,
-                            gettext_noop ("# active connections"),
-                            -1,
-                            GNUNET_NO);
+                           gettext_noop ("# active connections"),
+                           -1,
+                           GNUNET_NO);
 }
 
 /**
@@ -1196,17 +1179,15 @@ handler_disconnect (void *cls,
  * @param cls closure (always NULL)
  * @param peer the peer sending the message
  * @param message the actual message
- * @param latency latency
- * @param distance distance
+ * @param atsi performance data
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handler_advertisement (void *cls,
-    const struct GNUNET_PeerIdentity * peer,
-    const struct GNUNET_MessageHeader * message,
-    struct GNUNET_TIME_Relative latency,
-    uint32_t distance)
+                      const struct GNUNET_PeerIdentity * peer,
+                      const struct GNUNET_MessageHeader * message,
+                      const struct GNUNET_TRANSPORT_ATS_Information *atsi)
 {
   size_t size;
   size_t uri_size;
@@ -1264,8 +1245,7 @@ handler_advertisement (void *cls,
 
   stat_testing_hostlist = GNUNET_YES;
   stat_testing_allowed = GNUNET_NO;
-  ti_testing_intervall_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                                         TESTING_INTERVAL,
+  ti_testing_intervall_task = GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL,
                                                          &task_testing_intervall_reset,
                                                          NULL);
 
@@ -1273,8 +1253,7 @@ handler_advertisement (void *cls,
             "Testing new hostlist advertisements is locked for the next %u ms\n",
             TESTING_INTERVAL.rel_value);
 
-  ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now (sched,
-                                                     &task_download_dispatcher,
+  ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now (&task_download_dispatcher,
                                                      NULL);
 
   return GNUNET_OK;
@@ -1299,8 +1278,7 @@ primary_task (void *cls, int success)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Statistics request done, scheduling hostlist download\n");
 #endif
-  ti_check_download = GNUNET_SCHEDULER_add_now (sched,
-                                           &task_check,
+  ti_check_download = GNUNET_SCHEDULER_add_now (&task_check,
                                            NULL);
 }
 
@@ -1439,6 +1417,8 @@ static void save_hostlist_file ( int shutdown )
                   "HOSTLISTFILE", "HOSTLIST");
       return;
     }
+  if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
+    return;
   wh = GNUNET_BIO_write_open (filename);
   if ( NULL == wh)
     {
@@ -1452,7 +1432,6 @@ static void save_hostlist_file ( int shutdown )
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               _("Writing %u hostlist URIs to `%s'\n" ),
               linked_list_size, filename);
-
   /* add code to write hostlists to file using bio */
   ok = GNUNET_YES;
   counter = 0;
@@ -1507,7 +1486,6 @@ static void save_hostlist_file ( int shutdown )
  */
 int
 GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
-                             struct GNUNET_SCHEDULER_Handle *s,
                              struct GNUNET_STATISTICS_Handle *st,
                              GNUNET_CORE_ConnectEventHandler *ch,
                              GNUNET_CORE_DisconnectEventHandler *dh,
@@ -1522,14 +1500,13 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
       GNUNET_break (0);
       return GNUNET_SYSERR;
     }
-  transport = GNUNET_TRANSPORT_connect (s, c, NULL, NULL, NULL, NULL, NULL);
+  transport = GNUNET_TRANSPORT_connect (c, NULL, NULL, NULL, NULL, NULL);
   if (NULL == transport)
     {
       curl_global_cleanup ();
       return GNUNET_SYSERR;
     }
   cfg = c;
-  sched = s;
   stats = st;
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
@@ -1555,8 +1532,7 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               _("Hostlists will be saved to file again in  %llums\n"),
               (unsigned long long) SAVING_INTERVALL.rel_value);
-    ti_saving_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                               SAVING_INTERVALL,
+    ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL,
                                                &task_hostlist_saving,
                                                NULL);
   }
@@ -1611,29 +1587,24 @@ GNUNET_HOSTLIST_client_stop ()
 
   if (ti_saving_task != GNUNET_SCHEDULER_NO_TASK)
     {
-      GNUNET_SCHEDULER_cancel (sched,
-          ti_saving_task);
+      GNUNET_SCHEDULER_cancel (ti_saving_task);
     }
 
   if (ti_download_dispatcher_task != GNUNET_SCHEDULER_NO_TASK)
     {
-      GNUNET_SCHEDULER_cancel (sched,
-          ti_download_dispatcher_task);
+      GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task);
     }
   if (ti_testing_intervall_task != GNUNET_SCHEDULER_NO_TASK)
     {
-      GNUNET_SCHEDULER_cancel (sched,
-          ti_testing_intervall_task);
+      GNUNET_SCHEDULER_cancel (ti_testing_intervall_task);
     }
   if (ti_download != GNUNET_SCHEDULER_NO_TASK)
     {
-      GNUNET_SCHEDULER_cancel (sched,
-                               ti_download);
+      GNUNET_SCHEDULER_cancel (ti_download);
     }
   if (ti_check_download != GNUNET_SCHEDULER_NO_TASK)
     {
-      GNUNET_SCHEDULER_cancel (sched,
-                              ti_check_download);
+      GNUNET_SCHEDULER_cancel (ti_check_download);
       curl_global_cleanup ();
     }
   if (transport != NULL)
@@ -1645,7 +1616,6 @@ GNUNET_HOSTLIST_client_stop ()
   GNUNET_free_non_null (proxy);
   proxy = NULL;
   cfg = NULL;
-  sched = NULL;
 }
 
 /* end of hostlist-client.c */