psyc: in-order message delivery
[oweals/gnunet.git] / src / ats / gnunet-service-ats_addresses.h
index b5ae248e48acb526cf7ee2296091f2bc20269d26..aa0b919ea477f8d47f2f4d03161866ea82861415 100644 (file)
 
  */
 
+/**
+ * Available ressource assignment modes
+ */
+enum ATS_Mode
+{
+  /*
+   * proportional mode:
+   *
+   * Assign each peer an equal amount of bandwidth (bw)
+   *
+   * bw_per_peer = bw_total / #active addresses
+   */
+  MODE_PROPORTIONAL,
+
+  /*
+   * MLP mode:
+   *
+   * Solve ressource assignment as an optimization problem
+   * Uses an mixed integer programming solver
+   */
+  MODE_MLP,
+
+  /*
+   * Reinforcement Learning mode:
+   *
+   * Solve resource assignment using a learning agent
+   */
+  MODE_RIL
+};
+
+
 /*
  * How long will address suggestions blocked after a suggestion
  */
@@ -281,6 +312,8 @@ struct ATS_Address
    */
   uint32_t session_id;
 
+  uint32_t local_address_info;
+
   /**
    * Address
    */
@@ -331,6 +364,16 @@ struct ATS_Address
    */
   struct GNUNET_TIME_Absolute blocked_until;
 
+  /**
+   * Time when address had last activity (update, in uses)
+   */
+  struct GNUNET_TIME_Absolute t_last_activity;
+
+  /**
+   * Time when address was added
+   */
+  struct GNUNET_TIME_Absolute t_added;
+
   /**
    * Is this the active address for this peer?
    */
@@ -348,234 +391,11 @@ struct ATS_Address
   struct GAS_NormalizationInfo atsin[GNUNET_ATS_QualityPropertiesCount];
 };
 
-/**
- * Callback to call from solver when bandwidth for address has changed
- *
- * @param address the with changed bandwidth assigned
- */
-typedef void
-(*GAS_bandwidth_changed_cb) (void *cls, struct ATS_Address *address);
-
-/**
- * Callback to call from solver to obtain application preference values for a
- * peer
- *
- * @param cls the cls
- * @param id the peer id
- * @return carry of double values containing the preferences with
- *     GNUNET_ATS_PreferenceCount elements
- */
-typedef const double *
-(*GAS_get_preferences) (void *cls, const struct GNUNET_PeerIdentity *id);
-
-/**
- * Callback to call from solver to obtain transport properties for an
- * address
- *
- * @param cls the cls
- * @param address the address
- * @return carry of double values containing the preferences with
- *     GNUNET_ATS_PreferenceCount elements
- */
-typedef const double *
-(*GAS_get_properties) (void *cls, const struct ATS_Address *address);
-
-/*
- * Solver API
- * ----------
- */
-
-/**
- * Init the problem solving component
- *
- * Quotas:
- * network[i] contains the network type as type GNUNET_ATS_NetworkType[i]
- * out_quota[i] contains outbound quota for network type i
- * in_quota[i] contains inbound quota for network type i
- *
- * Example
- * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN}
- * network[2]   == GNUNET_ATS_NET_LAN
- * out_quota[2] == 65353
- * in_quota[2]  == 65353
- *
- * @param cfg configuration handle
- * @param stats the GNUNET_STATISTICS handle
- * @param addresses hashmap containing all addresses
- * @param network array of GNUNET_ATS_NetworkType with length dest_length
- * @param out_quota array of outbound quotas
- * @param in_quota array of outbound quota
- * @param bw_changed_cb callback to call when assigned changes
- * @return handle for the solver on success, NULL on fail
- */
-typedef void *
-(*GAS_solver_init) (const struct GNUNET_CONFIGURATION_Handle *cfg,
-    const struct GNUNET_STATISTICS_Handle *stats,
-    const struct GNUNET_CONTAINER_MultiHashMap *addresses, int *network,
-    unsigned long long *out_quota, unsigned long long *in_quota,
-    int dest_length, GAS_bandwidth_changed_cb bw_changed_cb,
-    void *bw_changed_cb_cls, GAS_get_preferences get_preference,
-    void *get_preference_cls, GAS_get_properties get_properties,
-    void *get_properties_cls);
-
-/**
- * Change the preference for a peer
- *
- * @param handle the solver handle
- * @param client the client sending this request
- * @param peer the peer id
- * @param kind the preference kind to change
- * @param score the new preference score
- * @param pref_rel the normalized preference value for this kind over all clients
- */
-typedef void
-(*GAS_solver_address_change_preference) (void *solver,
-    const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind,
-    double pref_rel);
-
-/**
- * Give feedback about the current assignment
- *
- * @param handle the solver handle
- * @param application the application sending this request
- * @param peer the peer id
- * @param scope the time interval for this feedback: [now - scope .. now]
- * @param kind the preference kind for this feedback
- * @param score the feedback score
- */
-typedef void
-(*GAS_solver_address_feedback_preference) (void *solver, void *application,
-    const struct GNUNET_PeerIdentity *peer,
-    const struct GNUNET_TIME_Relative scope,
-    enum GNUNET_ATS_PreferenceKind kind, double score);
-
-/**
- * Notify the solver about a bulk operation changing possibly a lot of values
- * Solver will not resolve until all bulk operations are marked as done
- *
- * @param solver the solver
- */
-typedef void
-(*GAS_solver_bulk_start) (void *solver);
-
-/**
- * Mark a bulk operation as done
- * Solver will resolve if values have changed
- *
- * @param solver the solver
- */
-typedef void
-(*GAS_solver_bulk_stop) (void *solver);
-
-/**
- * Add a single address within a network to the solver
- *
- * @param solver the solver Handle
- * @param addresses the address hashmap containing all addresses
- * @param address the address to add
- * @param network network type of this address
- */
-typedef void
-(*GAS_solver_address_add) (void *solver, struct ATS_Address *address,
-    uint32_t network);
-
-/**
- * Delete an address or just the session from the solver
- *
- * @param solver the solver Handle
- * @param addresses the address hashmap containing all addresses
- * @param address the address to delete
- * @param session_only remove address or just session
- */
-typedef void
-(*GAS_solver_address_delete) (void *solver, struct ATS_Address *address,
-    int session_only);
-
-/**
- * Transport properties for this address have changed
- *
- * @param solver solver handle
- * @param address the address
- * @param type the ATSI type in HBO
- * @param abs_value the absolute value of the property
- * @param rel_value the normalized value
- */
-typedef void
-(*GAS_solver_address_property_changed) (void *solver,
-    struct ATS_Address *address, uint32_t type, uint32_t abs_value,
-    double rel_value);
-
-/**
- * Transport session for this address has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param cur_session the current session
- * @param new_session the new session
- */
-typedef void
-(*GAS_solver_address_session_changed) (void *solver,
-    struct ATS_Address *address, uint32_t cur_session, uint32_t new_session);
-
-/**
- * Transport session for this address has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param in_use usage state
- */
-typedef void
-(*GAS_solver_address_inuse_changed) (void *solver, struct ATS_Address *address,
-    int in_use);
-
-/**
- * Network scope for this address has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param current_network the current network
- * @param new_network the new network
- */
-typedef void
-(*GAS_solver_address_network_changed) (void *solver,
-    struct ATS_Address *address, uint32_t current_network, uint32_t new_network);
-
-/**
- * Get the prefered address for a peer from solver
- *
- * @param solver the solver to use
- * @param addresses the address hashmap containing all addresses
- * @param peer the peer
- */
-typedef const struct ATS_Address *
-(*GAS_solver_get_preferred_address) (void *solver,
-    const struct GNUNET_PeerIdentity *peer);
-
-/**
- * Stop getting the prefered address for a peer from solver
- *
- * @param solver the solver to use
- * @param addresses the address hashmap containing all addresses
- * @param peer the peer
- */
-typedef void
-(*GAS_solver_stop_get_preferred_address) (void *solver,
-    const struct GNUNET_PeerIdentity *peer);
 
 /**
- * Shutdown solver
- *
- * @param solver the solver to shutdown
+ * Handle for ATS address component
  */
-
-typedef void
-(*GAS_solver_done) (void *solver);
+struct GAS_Addresses_Handle;
 
 /**
  * Initialize address subsystem. The addresses subsystem manages the addresses
@@ -607,15 +427,21 @@ GAS_addresses_done (struct GAS_Addresses_Handle *handle);
  * @param plugin_name transport plugin name
  * @param plugin_addr plugin address
  * @param plugin_addr_len length of the plugin address
+ * @param local_address_info the local address for the address
  * @param session_id session id, can be 0
  * @param atsi performance information for this address
  * @param atsi_count number of performance information contained
  */
 void
 GAS_addresses_add (struct GAS_Addresses_Handle *handle,
-    const struct GNUNET_PeerIdentity *peer, const char *plugin_name,
-    const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id,
-    const struct GNUNET_ATS_Information *atsi, uint32_t atsi_count);
+    const struct GNUNET_PeerIdentity *peer,
+    const char *plugin_name,
+    const void *plugin_addr,
+    size_t plugin_addr_len,
+    uint32_t local_address_info,
+    uint32_t session_id,
+    const struct GNUNET_ATS_Information *atsi,
+    uint32_t atsi_count);
 
 /**
  * Notification about active use of an address.
@@ -632,6 +458,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
  * @param plugin_name transport plugin name
  * @param plugin_addr plugin address
  * @param plugin_addr_len length of the plugin address
+ * @param local_address_info the local address for the address
  * @param session_id session id, can be 0
  * @param in_use GNUNET_YES if GNUNET_NO
  * @return GNUNET_SYSERR on failure (address unknown ...)
@@ -639,7 +466,9 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
 int
 GAS_addresses_in_use (struct GAS_Addresses_Handle *handle,
     const struct GNUNET_PeerIdentity *peer, const char *plugin_name,
-    const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id,
+    const void *plugin_addr, size_t plugin_addr_len,
+    uint32_t local_address_info,
+    uint32_t session_id,
     int in_use);
 
 /**
@@ -653,6 +482,7 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle,
  * @param plugin_name transport plugin name
  * @param plugin_addr plugin address
  * @param plugin_addr_len length of the plugin address
+ * @param local_address_info the local address for the address
  * @param session_id session id, can be 0
  * @param atsi performance information for this address
  * @param atsi_count number of performance information contained
@@ -660,7 +490,8 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle,
 void
 GAS_addresses_update (struct GAS_Addresses_Handle *handle,
     const struct GNUNET_PeerIdentity *peer, const char *plugin_name,
-    const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id,
+    const void *plugin_addr, size_t plugin_addr_len,
+    uint32_t local_address_info, uint32_t session_id,
     const struct GNUNET_ATS_Information *atsi, uint32_t atsi_count);
 
 /**
@@ -672,11 +503,13 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle,
  * @param plugin_addr plugin address
  * @param plugin_addr_len length of the plugin address
  * @param session_id session id, can be 0
+ * @param local_address_info the local address for the address
  */
 void
 GAS_addresses_destroy (struct GAS_Addresses_Handle *handle,
     const struct GNUNET_PeerIdentity *peer, const char *plugin_name,
-    const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id);
+    const void *plugin_addr, size_t plugin_addr_len,
+    uint32_t local_address_info, uint32_t session_id);
 
 /**
  * Remove all addresses
@@ -719,6 +552,18 @@ void
 GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle,
     const struct GNUNET_PeerIdentity *peer);
 
+
+/**
+ * A performance client disconnected
+ *
+ * @param handle address handle
+ * @param client the client
+ */
+
+void
+GAS_addresses_preference_client_disconnect (struct GAS_Addresses_Handle *handle,
+    void *client);
+
 /**
  * Change the preference for a peer
  *
@@ -729,18 +574,26 @@ GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle,
  * @param score_abs the new preference score
  */
 void
-GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle,
+GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle,
     void *client, const struct GNUNET_PeerIdentity *peer,
     enum GNUNET_ATS_PreferenceKind kind, float score_abs);
 
 /**
- * Change the preference for a peer
+ * Application feedback on how good preference requirements are fulfilled
+ * for a specific preference in the given time scope [now - scope .. now]
+ *
+ * An application notifies ATS if (and only if) it has feedback information
+ * for a specific property. This value is valid until the feedback score is
+ * updated by the application.
+ *
+ * If the application has no feedback for this preference kind the application
+ * will not explicitly call.
  *
  * @param handle the address handle
- * @param application the client sending this request
+ * @param application the application sending this request
  * @param peer the peer id
  * @param scope the time interval this valid for: [now - scope .. now]
- * @param kind the preference kind to change
+ * @param kind the preference kind this feedback is intended for
  * @param score_abs the new preference score
  */
 void