fix for 0002392
[oweals/gnunet.git] / src / ats / gnunet-service-ats_addresses_mlp.h
index 52631eb3cd9207a6c947e139ae4575b00cc396b6..d37eea75298ea99c8c4dd286eec9160b84dd6dbd 100644 (file)
 
 #define DEBUG_MLP GNUNET_EXTRA_LOGGING
 
+#define BIG_M_VALUE (UINT32_MAX) /10
+#define BIG_M_STRING "unlimited"
+
+#define MLP_AVERAGING_QUEUE_LENGTH 3
+
 #define MLP_MAX_EXEC_DURATION   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
 #define MLP_MAX_ITERATIONS      INT_MAX
 
@@ -61,6 +66,21 @@ struct ATS_Peer
   struct ATS_Address *tail;
 };
 
+struct ATS_PreferedAddress
+{
+  uint32_t bandwidth_out;
+  uint32_t bandwidth_in;
+  struct ATS_Address *address;
+};
+
+struct GAS_MLP_SolutionContext
+{
+  int lp_result;
+  int mlp_result;
+  struct GNUNET_TIME_Relative lp_duration;
+  struct GNUNET_TIME_Relative mlp_duration;
+};
+
 /**
  * MLP Handle
  */
@@ -119,6 +139,8 @@ struct GAS_MLP_Handle
    */
   int auto_solve;
 
+  int semaphore;
+
   /* state information */
 
   /**
@@ -223,6 +245,13 @@ struct GAS_MLP_Handle
   /* number of quality metrics */
   int m_q;
 
+  /* ATS network quotas */
+  int c_quota[GNUNET_ATS_NetworkTypeCount];
+  int r_quota[GNUNET_ATS_NetworkTypeCount];
+  int quota_index [GNUNET_ATS_NetworkTypeCount];
+  unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
+  unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
+
   /* ATS ressource costs
    *
    * array with GNUNET_ATS_QualityPropertiesCount elements
@@ -251,6 +280,10 @@ struct GAS_MLP_Handle
  */
 struct MLP_information
 {
+  double b;
+
+  int n;
+
   /* bandwidth column index */
   signed int c_b;
 
@@ -268,11 +301,14 @@ struct MLP_information
   /* Quality information row indices */
   unsigned int r_q[GNUNET_ATS_QualityPropertiesCount];
 
-  /* Quality information column indices */
-  unsigned int c_q[GNUNET_ATS_QualityPropertiesCount];
-
   /* Quality information */
-  double q[GNUNET_ATS_QualityPropertiesCount];
+  double q[GNUNET_ATS_QualityPropertiesCount][MLP_AVERAGING_QUEUE_LENGTH];
+
+  /* Quality information averaged */
+  double q_averaged[GNUNET_ATS_QualityPropertiesCount];
+
+  /* Averaging index */
+  int q_avg_i[GNUNET_ATS_QualityPropertiesCount];
 };
 
 
@@ -295,10 +331,11 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * Solves the MLP problem on demand
  *
  * @param mlp the MLP Handle
+ * @param ctx solution context
  * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
  */
 int
-GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp);
+GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *ctx);
 
 
 /**
@@ -348,6 +385,19 @@ GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp,
                                    float score);
 
 
+/**
+ * Get the preferred address for a specific peer
+ *
+ * @param mlp the MLP Handle
+ * @param addresses address hashmap
+ * @param peer the peer
+ * @return suggested address
+ */
+struct ATS_PreferedAddress *
+GAS_mlp_get_preferred_address (struct GAS_MLP_Handle *mlp,
+                               struct GNUNET_CONTAINER_MultiHashMap * addresses,
+                               const struct GNUNET_PeerIdentity *peer);
+
 /**
  * Shutdown the MLP problem solving component
  */