gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r17453 - in gnunet/src: dht fs


From: gnunet
Subject: [GNUnet-SVN] r17453 - in gnunet/src: dht fs
Date: Thu, 13 Oct 2011 19:00:28 +0200

Author: grothoff
Date: 2011-10-13 19:00:28 +0200 (Thu, 13 Oct 2011)
New Revision: 17453

Modified:
   gnunet/src/dht/gnunet-service-dht_neighbours.c
   gnunet/src/fs/gnunet-service-fs_cp.c
Log:
adapting code to new ATS APIs

Modified: gnunet/src/dht/gnunet-service-dht_neighbours.c
===================================================================
--- gnunet/src/dht/gnunet-service-dht_neighbours.c      2011-10-13 16:32:30 UTC 
(rev 17452)
+++ gnunet/src/dht/gnunet-service-dht_neighbours.c      2011-10-13 17:00:28 UTC 
(rev 17453)
@@ -320,11 +320,6 @@
   struct GNUNET_CORE_TransmitHandle *th;
 
   /**
-   * Preference update context
-   */
-  struct GNUNET_ATS_InformationRequestContext *info_ctx;
-
-  /**
    * Task for scheduling preference updates
    */
   GNUNET_SCHEDULER_TaskIdentifier preference_task;
@@ -415,7 +410,7 @@
 /**
  * Handle to ATS.
  */
-static struct GNUNET_ATS_SchedulingHandle *atsAPI;
+static struct GNUNET_ATS_PerformanceHandle *atsAPI;
 
 
 
@@ -450,42 +445,6 @@
  */ 
 static void
 update_core_preference (void *cls,
-                        const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-
-/**
- * Function called with statistics about the given peer.
- *
- * @param cls closure
- * @param peer identifies the peer
- * @param amount set to the amount that was actually reserved or unreserved;
- *               either the full requested amount or zero (no partial 
reservations)
- * @param res_delay if the reservation could not be satisfied (amount was 0), 
how
- *        long should the client wait until re-trying?
- */
-static void
-update_core_preference_finish (void *cls,
-                               const struct GNUNET_PeerIdentity *peer,
-                               int32_t amount,
-                               struct GNUNET_TIME_Relative res_delay)
-{
-  struct PeerInfo *peer_info = cls;
-
-  peer_info->info_ctx = NULL;
-  peer_info->preference_task
-    = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
-                                   &update_core_preference, peer_info);
-}
-
-
-/**
- * Let GNUnet core know that we like the given peer.
- *
- * @param cls the 'struct PeerInfo' of the peer
- * @param tc scheduler context.
- */ 
-static void
-update_core_preference (void *cls,
                         const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct PeerInfo *peer = cls;
@@ -519,11 +478,15 @@
   GNUNET_STATISTICS_update (GDS_stats,
                            gettext_noop ("# Preference updates given to 
core"), 1,
                            GNUNET_NO);
-  peer->info_ctx =
-    GNUNET_ATS_peer_change_preference (atsAPI, &peer->id,
-                                      0,
-                                      preference,
-                                      &update_core_preference_finish, peer);
+  GNUNET_ATS_change_preference (atsAPI, &peer->id,
+                               GNUNET_ATS_PREFERENCE_BANDWIDTH,
+                               (double) preference,
+                               GNUNET_ATS_PREFERENCE_END);
+  peer->preference_task
+    = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
+                                   &update_core_preference, peer);
+
+
 }
 
 
@@ -729,11 +692,6 @@
                  GNUNET_CONTAINER_multihashmap_remove (all_known_peers,
                                                        &peer->hashPubKey,
                                                        to_remove));
-  if (NULL != to_remove->info_ctx)
-  {
-    GNUNET_ATS_peer_change_preference_cancel (to_remove->info_ctx);
-    to_remove->info_ctx = NULL;
-  }
   if (GNUNET_SCHEDULER_NO_TASK != to_remove->preference_task)
   {
     GNUNET_SCHEDULER_cancel (to_remove->preference_task);
@@ -2050,7 +2008,7 @@
       GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size",
                                              &temp_config_num))
     bucket_size = (unsigned int) temp_config_num;  
-  atsAPI = GNUNET_ATS_init (GDS_cfg, NULL, NULL);
+  atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL);
   coreAPI = GNUNET_CORE_connect (GDS_cfg,
                                  1,
                                  NULL,
@@ -2077,7 +2035,7 @@
     return;
   GNUNET_CORE_disconnect (coreAPI);
   coreAPI = NULL;    
-  GNUNET_ATS_shutdown (atsAPI);
+  GNUNET_ATS_performance_done (atsAPI);
   atsAPI = NULL;    
   GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers));
   GNUNET_CONTAINER_multihashmap_destroy (all_known_peers);

Modified: gnunet/src/fs/gnunet-service-fs_cp.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_cp.c        2011-10-13 16:32:30 UTC (rev 
17452)
+++ gnunet/src/fs/gnunet-service-fs_cp.c        2011-10-13 17:00:28 UTC (rev 
17453)
@@ -241,14 +241,14 @@
   struct GSF_PeerTransmitHandle *migration_pth;
 
   /**
-   * Context of our GNUNET_ATS_peer_change_preference call (or NULL).
+   * Context of our GNUNET_ATS_reserve_bandwidth call (or NULL).
    */
-  struct GNUNET_ATS_InformationRequestContext *irc;
+  struct GNUNET_ATS_ReservationContext *rc;
 
   /**
    * Task scheduled if we need to retry bandwidth reservation later.
    */
-  GNUNET_SCHEDULER_TaskIdentifier irc_delay_task;
+  GNUNET_SCHEDULER_TaskIdentifier rc_delay_task;
 
   /**
    * Active requests from this neighbour, map of query to 'struct PeerRequest'.
@@ -305,7 +305,7 @@
 /**
  * Handle to ATS service.
  */
-static struct GNUNET_ATS_SchedulingHandle *ats;
+static struct GNUNET_ATS_PerformanceHandle *ats;
 
 /**
  * Get the filename under which we would store the GNUNET_HELLO_Message
@@ -419,13 +419,23 @@
 {
   struct GSF_ConnectedPeer *cp;
   struct GNUNET_PeerIdentity target;
-  uint64_t ip;
 
   if ((NULL != pth->cth) || (0 != pth->cth_in_progress))
     return;                     /* already done */
   cp = pth->cp;
   GNUNET_assert (0 != cp->ppd.pid);
   GNUNET_PEER_resolve (cp->ppd.pid, &target);
+
+  if (0 != cp->inc_preference)
+  {
+    GNUNET_ATS_change_preference (ats,
+                                 &target,
+                                 GNUNET_ATS_PREFERENCE_BANDWIDTH,
+                                 (double) cp->inc_preference,
+                                 GNUNET_ATS_PREFERENCE_END);
+    cp->inc_preference = 0;
+  }
+
   if ((GNUNET_YES == pth->is_query) && (GNUNET_YES != pth->was_reserved))
   {
     /* query, need reservation */
@@ -434,12 +444,10 @@
     cp->did_reserve = GNUNET_NO;
     /* reservation already done! */
     pth->was_reserved = GNUNET_YES;
-    ip = cp->inc_preference;
-    cp->inc_preference = 0;
-    cp->irc =
-        GNUNET_ATS_peer_change_preference (ats, &target,
-                                          DBLOCK_SIZE, ip,
-                                          &ats_reserve_callback, cp);
+    cp->rc =
+        GNUNET_ATS_reserve_bandwidth (ats, &target,
+                                     DBLOCK_SIZE, 
+                                     &ats_reserve_callback, cp);
   }
   GNUNET_assert (pth->cth == NULL);
   pth->cth_in_progress++;
@@ -515,17 +523,14 @@
 retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GSF_ConnectedPeer *cp = cls;
-  uint64_t ip;
   struct GNUNET_PeerIdentity target;
 
   GNUNET_PEER_resolve (cp->ppd.pid, &target);
-  cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
-  ip = cp->inc_preference;
-  cp->inc_preference = 0;
-  cp->irc =
-      GNUNET_ATS_peer_change_preference (ats, &target,
-                                        DBLOCK_SIZE, ip,
-                                        &ats_reserve_callback, cp);
+  cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK;
+  cp->rc =
+      GNUNET_ATS_reserve_bandwidth (ats, &target,
+                                   DBLOCK_SIZE, 
+                                   &ats_reserve_callback, cp);
 }
 
 
@@ -541,15 +546,15 @@
  */
 static void
 ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
-                       int32_t amount, struct GNUNET_TIME_Relative res_delay)
+                     int32_t amount, struct GNUNET_TIME_Relative res_delay)
 {
   struct GSF_ConnectedPeer *cp = cls;
   struct GSF_PeerTransmitHandle *pth;
 
-  cp->irc = NULL;
+  cp->rc = NULL;
   if (0 == amount)
   {
-    cp->irc_delay_task =
+    cp->rc_delay_task =
         GNUNET_SCHEDULER_add_delayed (res_delay, &retry_reservation, cp);
     return;
   }
@@ -588,10 +593,10 @@
   cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer));
   cp->ppd.pid = GNUNET_PEER_intern (peer);
   cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
-  cp->irc =
-      GNUNET_ATS_peer_change_preference (ats, peer,
-                                        DBLOCK_SIZE, 0,
-                                        &ats_reserve_callback, cp);
+  cp->rc =
+      GNUNET_ATS_reserve_bandwidth (ats, peer,
+                                   DBLOCK_SIZE, 
+                                   &ats_reserve_callback, cp);
   fn = get_trust_filename (peer);
   if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) &&
       (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust))))
@@ -1528,15 +1533,15 @@
     GSF_peer_transmit_cancel_ (cp->migration_pth);
     cp->migration_pth = NULL;
   }
-  if (NULL != cp->irc)
+  if (NULL != cp->rc)
   {
-    GNUNET_ATS_peer_change_preference_cancel (cp->irc);
-    cp->irc = NULL;
+    GNUNET_ATS_reserve_bandwidth_cancel (cp->rc);
+    cp->rc = NULL;
   }
-  if (GNUNET_SCHEDULER_NO_TASK != cp->irc_delay_task)
+  if (GNUNET_SCHEDULER_NO_TASK != cp->rc_delay_task)
   {
-    GNUNET_SCHEDULER_cancel (cp->irc_delay_task);
-    cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
+    GNUNET_SCHEDULER_cancel (cp->rc_delay_task);
+    cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK;
   }
   GNUNET_CONTAINER_multihashmap_iterate (cp->request_map,
                                          &cancel_pending_request, cp);
@@ -1804,7 +1809,7 @@
 GSF_connected_peer_init_ ()
 {
   cp_map = GNUNET_CONTAINER_multihashmap_create (128);
-  ats = GNUNET_ATS_init (GSF_cfg, NULL, NULL);
+  ats = GNUNET_ATS_performance_init (GSF_cfg, NULL, NULL);
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, "fs",
                                                           "TRUST",
@@ -1843,7 +1848,7 @@
   cp_map = NULL;
   GNUNET_free (trustDirectory);
   trustDirectory = NULL;
-  GNUNET_ATS_shutdown (ats);
+  GNUNET_ATS_performance_done (ats);
   ats = NULL;
 }
 




reply via email to

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