ATS API: do inbound and outbound bw
authorChristian Grothoff <christian@grothoff.org>
Mon, 10 Oct 2011 10:39:43 +0000 (10:39 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 10 Oct 2011 10:39:43 +0000 (10:39 +0000)
src/ats/ats_api.c
src/include/gnunet_ats_service.h
src/transport/gnunet-service-transport.c
src/transport/gnunet-service-transport_neighbours.c

index f7f3c95527029d952c2a91c8259858b84b94dee8..ce598c4e330512256397f9ec0c3134b4892b2bfa 100644 (file)
@@ -77,9 +77,14 @@ struct AllocationRecord
   uint32_t ats_count;
 
   /**
-   * Bandwidth assigned to this address right now, 0 for none.
+   * Inbound bandwidth assigned to this address right now, 0 for none.
    */
-  struct GNUNET_BANDWIDTH_Value32NBO bandwidth;
+  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
+
+  /**
+   * Outbound bandwidth assigned to this address right now, 0 for none.
+   */
+  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
 
   /**
    * Set to GNUNET_YES if this is the connected address of a connected peer.
@@ -156,9 +161,14 @@ struct GNUNET_ATS_Handle
   GNUNET_SCHEDULER_TaskIdentifier ba_task;
 
   /**
-   * Total bandwidth per configuration.
+   * Total inbound bandwidth per configuration.
+   */
+  unsigned long long total_bps_in;
+
+  /**
+   * Total outbound bandwidth per configuration.
    */
-  unsigned long long total_bps;
+  unsigned long long total_bps_out;
 };
 
 
@@ -193,9 +203,14 @@ struct SetBandwidthContext
   struct GNUNET_ATS_Handle *atc;
 
   /**
-   * Bandwidth to assign.
+   * Inbound bandwidth to assign.
    */
-  struct GNUNET_BANDWIDTH_Value32NBO bw;
+  struct GNUNET_BANDWIDTH_Value32NBO bw_in;
+
+  /**
+   * Outbound bandwidth to assign.
+   */
+  struct GNUNET_BANDWIDTH_Value32NBO bw_out;
 };
 
 
@@ -215,19 +230,21 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
 
   if (GNUNET_YES == ar->connected)
   {
-    ar->bandwidth = sbc->bw;
+    ar->bandwidth_in = sbc->bw_in;
+    ar->bandwidth_out = sbc->bw_out;
     sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
                         (const struct GNUNET_PeerIdentity *) key,
                         ar->plugin_name, ar->session, ar->plugin_addr,
-                        ar->plugin_addr_len, ar->bandwidth);
+                        ar->plugin_addr_len, ar->bandwidth_out, ar->bandwidth_in);
   }
-  else if (ntohl (ar->bandwidth.value__) > 0)
+  else if (ntohl (ar->bandwidth_out.value__) > 0)
   {
-    ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
+    ar->bandwidth_in = GNUNET_BANDWIDTH_value_init (0);
+    ar->bandwidth_out = GNUNET_BANDWIDTH_value_init (0);
     sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
                         (const struct GNUNET_PeerIdentity *) key,
                         ar->plugin_name, ar->session, ar->plugin_addr,
-                        ar->plugin_addr_len, ar->bandwidth);
+                        ar->plugin_addr_len, ar->bandwidth_out, ar->bandwidth_in);
   }
   return GNUNET_YES;
 }
@@ -253,7 +270,8 @@ update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   if (ac == 0)
     ac++;
   GNUNET_assert (ac > 0);
-  bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac);
+  bwc.bw_in = GNUNET_BANDWIDTH_value_init (atc->total_bps_in / ac);
+  bwc.bw_out = GNUNET_BANDWIDTH_value_init (atc->total_bps_out / ac);
   GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc);
 }
 
@@ -296,7 +314,9 @@ suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
   /* trivial strategy: pick first available address... */
   asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr,
            ar->plugin_addr_len, ar->session,
-           GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats,
+           GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_out / 32), 
+           GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_in / 32), 
+          ar->ats,
            ar->ats_count);
   asc->cb = NULL;
   return GNUNET_NO;
@@ -392,7 +412,9 @@ GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
   atc->peers = GNUNET_CONTAINER_multihashmap_create (256);
   atc->notify_map = GNUNET_CONTAINER_multihashmap_create (256);
   GNUNET_CONFIGURATION_get_value_number (cfg, "core", "TOTAL_QUOTA_OUT",
-                                         &atc->total_bps);
+                                         &atc->total_bps_out);
+  GNUNET_CONFIGURATION_get_value_number (cfg, "core", "TOTAL_QUOTA_IN",
+                                         &atc->total_bps_in);
   return atc;
 }
 
@@ -767,8 +789,9 @@ notify_valid (void *cls, const GNUNET_HashCode * key, void *value)
 
   asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr,
            ar->plugin_addr_len, ar->session,
-           GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats,
-           ar->ats_count);
+           GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_out / 32), 
+           GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_in / 32), 
+          ar->ats, ar->ats_count);
   GNUNET_ATS_suggest_address_cancel (asc);
   asc = NULL;
   return GNUNET_OK;
index 9317ace43869c30a85fc60c9b2026b689fcb5130..5e302da5cf23a1441a2faaef24029a5b4602462c 100644 (file)
@@ -56,7 +56,8 @@ struct GNUNET_ATS_Handle;
  * @param session session to use (if available)
  * @param plugin_addr address to use (if available)
  * @param plugin_addr_len number of bytes in addr
- * @param bandwidth assigned outbound bandwidth for the connection
+ * @param bandwidth_out assigned outbound bandwidth for the connection
+ * @param bandwidth_in assigned inbound bandwidth for the connection
  */
 typedef void (*GNUNET_TRANSPORT_ATS_AllocationNotification) (void *cls,
                                                              const struct
@@ -72,7 +73,10 @@ typedef void (*GNUNET_TRANSPORT_ATS_AllocationNotification) (void *cls,
                                                              plugin_addr_len,
                                                              struct
                                                              GNUNET_BANDWIDTH_Value32NBO
-                                                             bandwidth);
+                                                             bandwidth_out,
+                                                             struct
+                                                             GNUNET_BANDWIDTH_Value32NBO
+                                                             bandwidth_in);
 
 
 /**
@@ -106,7 +110,8 @@ GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc);
  * @param plugin_name name of the plugin, NULL if we have no suggestion
  * @param plugin_addr suggested address, NULL if we have no suggestion
  * @param plugin_addr_len number of bytes in plugin_addr
- * @param bandwidth assigned outbound bandwidth for the connection
+ * @param bandwidth_out assigned outbound bandwidth for the connection
+ * @param bandwidth_in assigned inbound bandwidth for the connection
  * @param ats performance data for the address (as far as known)
  * @param ats_count number of performance records in 'ats'
  */
@@ -120,7 +125,10 @@ typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
                                                       struct Session * session,
                                                       struct
                                                       GNUNET_BANDWIDTH_Value32NBO
-                                                      bandwidth,
+                                                      bandwidth_out,
+                                                      struct
+                                                      GNUNET_BANDWIDTH_Value32NBO
+                                                      bandwidth_in,
                                                       const struct
                                                       GNUNET_TRANSPORT_ATS_Information
                                                       * ats,
index 3693bcf2e22da6c9a9f055f43c0c75985adb3cc1..fb5a5c5e6d1c007025e0d2427d86872f55379f78 100644 (file)
@@ -322,17 +322,20 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param session session to use (if available)
  * @param plugin_addr address to use (if available)
  * @param plugin_addr_len number of bytes in addr
- * @param bandwidth assigned outbound bandwidth for the connection
+ * @param bandwidth_out assigned outbound bandwidth for the connection
+ * @param bandwidth_in assigned inbound bandwidth for the connection
  */
 static void
 ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer,
                             const char *plugin_name, struct Session *session,
                             const void *plugin_addr, size_t plugin_addr_len,
-                            struct GNUNET_BANDWIDTH_Value32NBO bandwidth)
+                            struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                            struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 {
   GST_neighbours_switch_to_address (peer, plugin_name, plugin_addr,
                                     plugin_addr_len, session, NULL, 0);
-  GST_neighbours_set_incoming_quota (peer, bandwidth);
+  GST_neighbours_set_incoming_quota (peer, bandwidth_in);
+  // FIXME: use 'bandwidth_out'!
 }
 
 
index c4d880d0a9c75e97c74ed5a8ca61c3a2b96f06d8..e4d0057ae3e2a29e56a01e1703bba2bd7383777f 100644 (file)
@@ -702,7 +702,8 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
  * @param plugin_address binary address
  * @param plugin_address_len length of address
  * @param session session to use
- * @param bandwidth available bandwidth
+ * @param bandwidth_out available outbound bandwidth
+ * @param bandwidth_in available inbound bandwidth
  * @param ats performance data for the address (as far as known)
  * @param ats_count number of performance records in 'ats'
  */
@@ -710,7 +711,8 @@ static void
 try_connect_using_address (void *cls, const struct GNUNET_PeerIdentity *target,
                            const char *plugin_name, const void *plugin_address,
                            size_t plugin_address_len, struct Session *session,
-                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth,
+                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
                            const struct GNUNET_TRANSPORT_ATS_Information *ats,
                            uint32_t ats_count)
 {