gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r16449 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r16449 - gnunet/src/transport
Date: Thu, 11 Aug 2011 15:05:42 +0200

Author: grothoff
Date: 2011-08-11 15:05:42 +0200 (Thu, 11 Aug 2011)
New Revision: 16449

Modified:
   gnunet/src/transport/gnunet-service-transport_ats-new.c
   gnunet/src/transport/gnunet-service-transport_ats-new.h
Log:
dummy ATS implementation

Modified: gnunet/src/transport/gnunet-service-transport_ats-new.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_ats-new.c     2011-08-11 
12:46:39 UTC (rev 16448)
+++ gnunet/src/transport/gnunet-service-transport_ats-new.c     2011-08-11 
13:05:42 UTC (rev 16449)
@@ -106,18 +106,108 @@
    * Task scheduled to update our bandwidth assignment.
    */
   GNUNET_SCHEDULER_TaskIdentifier ba_task;
+
+  /**
+   * Total bandwidth per configuration.
+   */
+  unsigned long long total_bps;
 };
 
 
+
+/**
+ * Count number of connected records.
+ *
+ * @param cls pointer to counter
+ * @param key identity of the peer associated with the records
+ * @param value a 'struct AllocationRecord' 
+ * @return GNUNET_YES (continue iteration)
+ */
+static int
+count_connections (void *cls,
+                  const GNUNET_HashCode *key,
+                  void *value)
+{
+  unsigned int *ac = cls;
+  struct AllocationRecord *ar = value;
+  
+  if (GNUNET_YES == ar->connected)
+    (*ac)++;
+  return GNUNET_YES;
+}
+
+struct SetBandwidthContext
+{
+  struct GST_AtsHandle *atc;
+  struct GNUNET_BANDWIDTH_Value32NBO bw;
+};
+
+/**
+ * Set bandwidth based on record.
+ *
+ * @param cls 'struct SetBandwidthContext'
+ * @param key identity of the peer associated with the records
+ * @param value a 'struct AllocationRecord' 
+ * @return GNUNET_YES (continue iteration)
+ */
+static int
+set_bw_connections (void *cls,
+                   const GNUNET_HashCode *key,
+                   void *value)
+{
+  struct SetBandwidthContext *sbc = cls;
+  struct AllocationRecord *ar = value;
+  
+  if (GNUNET_YES == ar->connected)
+    {
+      ar->bandwidth = sbc->bw;
+      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);
+    }
+  else if (ntohl(ar->bandwidth.value__) > 0)
+    {
+      ar->bandwidth = 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);
+    }
+  return GNUNET_YES;
+}
+
+
+/**
+ * Task run to update bandwidth assignments.
+ *
+ * @param cls the 'struct GST_AtsHandle'
+ * @param tc scheduler context
+ */ 
 static void
 update_bandwidth_task (void *cls,
                       const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GST_AtsHandle *atc = cls;
+  unsigned int ac;
+  struct SetBandwidthContext bwc;
 
   atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
-  /* FIXME: update calculations! */
-
+  /* FIXME: update calculations NICELY; what follows is a naive version */
+  GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
+                                        &count_connections,
+                                        &ac);
+  bwc.atc = atc;
+  bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac);
+  GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
+                                        &set_bw_connections,
+                                        &bwc);
 }
 
 
@@ -158,6 +248,10 @@
   atc->alloc_cb = alloc_cb;
   atc->alloc_cb_cls = alloc_cb_cls;
   atc->peers = GNUNET_CONTAINER_multihashmap_create (256);
+  GNUNET_CONFIGURATION_get_value_number (cfg,
+                                        "core",
+                                        "TOTAL_QUOTA_OUT",
+                                        &atc->total_bps);
   return atc;
 }
 

Modified: gnunet/src/transport/gnunet-service-transport_ats-new.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_ats-new.h     2011-08-11 
12:46:39 UTC (rev 16448)
+++ gnunet/src/transport/gnunet-service-transport_ats-new.h     2011-08-11 
13:05:42 UTC (rev 16449)
@@ -19,9 +19,14 @@
 */
 /**
  * @file transport/gnunet-service-transport_ats-new.h
- * @brief automatic transport selection API
+ * @brief automatic transport selection and outbound bandwidth determination
  * @author Christian Grothoff
  * @author Matthias Wachs
+ *
+ * TODO:
+ * - turn into service
+ * - extend API to express communication preferences to ATS 
+ *   (to be called DIRECTLY from apps, not from transport/core!)
  */
 #ifndef GNUNET_SERVICE_TRANSPORT_ATS_H
 #define GNUNET_SERVICE_TRANSPORT_ATS_H
@@ -51,7 +56,7 @@
  * @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 bandwidth for the connection
+ * @param bandwidth assigned outbound bandwidth for the connection
  */
 typedef void (*GNUNET_TRANSPORT_ATS_AllocationNotification)(void *cls,
                                                            const struct 
GNUNET_PeerIdentity *peer,




reply via email to

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