/*
- This file is part of GNUnet.
- (C) 2011 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
+ This file is part of GNUnet.
+ Copyright (C) 2011-2014 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
/**
* @file ats/gnunet-service-ats_addresses.h
#include "gnunet_util_lib.h"
#include "gnunet_ats_service.h"
#include "gnunet-service-ats.h"
-#include "gnunet_statistics_service.h"
-#include "ats.h"
/**
* NOTE: Do not change this documentation. This documentation is based on
* it as a value_number. If no configuration value is found it will assign
* GNUNET_ATS_DefaultBandwidth. The most important step is to load the
* configured solver using configuration "[ats]:MODE". Current solvers are
- * MODE_SIMPLISTIC, MODE_MLP. Interaction is done using a solver API
+ * MODE_PROPORTIONAL, MODE_MLP. Interaction is done using a solver API
*
* 1.4 Solver API
*
* prevent the client from being thrashed. If the client requires immediately
* it can reset this block using GAS_addresses_handle_backoff_reset.
*
- * 1.7.7 Marking address in use
- *
- * The client can notify addresses that it successfully uses an address and
- * wants this address to be kept by calling GSA_address_in_use. Adresses will
- * mark the address as used an notify the solver about the use.
- *
- * 1.7.8 Address lifecycle
+ * 1.7.7 Address lifecycle
*
* * (add address)
- * * (updated address) || (address in use)
+ * * (updated address)
* * (delete address)
*
* 1.8 Bandwidth assignment
* The bandwidth assigned to a peer can be influenced by setting a preference
* for a peer. The prefernce will be given to to the solver with s_pref which
* has to take care of the preference value
-
*/
*/
#define ATS_BLOCKING_DELTA GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100)
-struct GAS_Addresses_Handle;
-
/**
* Information provided by ATS normalization
*/
struct GAS_NormalizationInfo
-{
- /**
- * Next index to use in averaging queue
- */
- unsigned int avg_queue_index;
-
- /**
- * Averaging queue
- */
- uint32_t atsi_abs[GAS_normalization_queue_length];
-
- /**
- * Averaged ATSI values from queue
- */
- uint32_t avg;
-
- /**
- * Normalized values from queue to a range of values [1.0...2.0]
- */
- double norm;
-};
-
-/**
- * Address with additional information
- */
-struct ATS_Address
{
/**
- * Next element in DLL
+ * Next index to use in averaging queue
*/
- struct ATS_Address *next;
+ unsigned int avg_queue_index;
/**
- * Previous element in DLL
+ * Averaging queue
*/
- struct ATS_Address *prev;
+ uint64_t atsi_abs[GAS_normalization_queue_length];
/**
- * Peer ID
+ * Averaged ATSI values from queue
*/
- struct GNUNET_PeerIdentity peer;
+ uint64_t avg;
/**
- * Session ID, 0 if no session is given
+ * Normalized values from queue to a range of values [1.0...2.0]
*/
- uint32_t session_id;
+ double norm;
+};
+
+/**
+ * Address with additional information
+ */
+struct ATS_Address
+{
/**
- * Address
+ * Peer ID this address is for.
*/
- const void *addr;
+ struct GNUNET_PeerIdentity peer;
/**
- * Address length
+ * Address (in plugin-specific binary format).
*/
- size_t addr_len;
+ const void *addr;
/**
* Plugin name
char *plugin;
/**
- * Solver specific information for this address
+ * Solver-specific information for this address
*/
void *solver_information;
/**
* ATS performance information for this address
*/
- struct GNUNET_ATS_Information *atsi;
+ struct GNUNET_ATS_Properties properties;
/**
- * ATS performance information for this address
+ * Time when address had last activity (update, in uses)
*/
- uint32_t atsi_count;
-
-#if 0
- /* CHECK USAGE */
- struct GNUNET_TIME_Relative atsp_latency;
-
- /* CHECK USAGE */
- struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_in;
-
- /* CHECK USAGE */
- struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_out;
+ struct GNUNET_TIME_Absolute t_last_activity;
+ /**
+ * Time when address was added
+ */
+ struct GNUNET_TIME_Absolute t_added;
- /* CHECK USAGE */
- uint32_t atsp_distance;
+ /**
+ * Address length, number of bytes in @e addr.
+ */
+ size_t addr_len;
- /* CHECK USAGE */
- uint32_t atsp_cost_wan;
+ /**
+ * Session ID, can never be 0.
+ */
+ uint32_t session_id;
- /* CHECK USAGE */
- uint32_t atsp_cost_lan;
+ /**
+ * Field to store local flags.
+ */
+ enum GNUNET_HELLO_AddressInfo local_address_info;
- /* CHECK USAGE */
- uint32_t atsp_cost_wlan;
+ /**
+ * ATS performance information for this address, size of the @e atsi array.
+ */
+ uint32_t atsi_count;
- /* CHECK USAGE */
- uint32_t atsp_network_type;
-#endif
/**
- * Inbound bandwidth assigned by solver in NBO
+ * Inbound bandwidth assigned by solver
*/
- struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_in;
+ uint32_t assigned_bw_in;
/**
- * Outbound bandwidth assigned by solver in NBO
+ * Outbound bandwidth assigned by solver
*/
- struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_out;
+ uint32_t assigned_bw_out;
/**
- * Blocking interval
+ * Inbound bandwidth assigned by solver in NBO
*/
- struct GNUNET_TIME_Relative block_interval;
+ uint32_t last_notified_bw_in;
/**
- * Time when address can be suggested again
+ * Outbound bandwidth assigned by solver in NBO
*/
- struct GNUNET_TIME_Absolute blocked_until;
+ uint32_t last_notified_bw_out;
/**
* Is this the active address for this peer?
int active;
/**
- * Is this the address for this peer in use?
+ * Normalized delay information for this address.
*/
- int used;
+ struct GAS_NormalizationInfo norm_delay;
/**
- * Normalized ATS performance information for this address
- * Each entry can be accessed using the GNUNET_ATS_QualityProperties avg_queue_index
+ * Normalized distance information for this 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);
-
-typedef const double *
- (*GAS_get_preferences) (void *cls, const struct GNUNET_PeerIdentity *id);
-
-
-/*
- * Solver API
- * ----------
- */
-
-/**
- * Init the simplistic 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 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,
- 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);
-
-
-/**
- * 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,
- struct GNUNET_CONTAINER_MultiHashMap *addresses,
- const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- double pref_rel);
-
-typedef void
-(*GAS_solver_bulk_start) (void *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 GNUNET_CONTAINER_MultiHashMap *addresses,
- 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 GNUNET_CONTAINER_MultiHashMap *addresses,
- struct ATS_Address *address,
- int session_only);
-
-/**
- * Notify the solver about an update for an address
- *
- * @param solver the solver to use
- * @param addresses the address hashmap containing all addresses
- * @param address the address
- * @param session the previous session
- * @param in_use previous address used state: yes or no
- * @param atsi ats previous performance information
- * @param atsi_count previous number of ats performance information
- *
- */
-typedef void
-(*GAS_solver_address_update) (void *solver,
- struct GNUNET_CONTAINER_MultiHashMap *addresses,
- struct ATS_Address *address,
- uint32_t prev_session,
- int in_use,
- const struct GNUNET_ATS_Information *prev_atsi,
- uint32_t prev_atsi_count);
+ struct GAS_NormalizationInfo norm_distance;
+ /**
+ * Normalized utilization inbound for this address.
+ */
+ struct GAS_NormalizationInfo norm_utilization_in;
-/**
- * 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,
- struct GNUNET_CONTAINER_MultiHashMap *addresses,
- const struct GNUNET_PeerIdentity *peer);
+ /**
+ * Normalized utilization outbound for this address.
+ */
+ struct GAS_NormalizationInfo norm_utilization_out;
+};
-/**
- * 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,
- struct GNUNET_CONTAINER_MultiHashMap *addresses,
- const struct GNUNET_PeerIdentity *peer);
/**
- * Shutdown solver
- *
- * @param solver the solver to shutdown
+ * A multipeermap mapping peer identities to `struct ATS_Address`.
*/
-
-typedef void
- (*GAS_solver_done) (void *solver);
+extern struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses;
/**
* Initialize address subsystem. The addresses subsystem manages the addresses
- * known and current performance information. It has a solver component
- * responsible for the resource allocation. It tells the solver about changes
- * and receives updates when the solver changes the ressource allocation.
+ * known and current performance information.
*
- * @param cfg configuration to use
- * @param stats the statistics handle to use
- * @return an address handle
+ * @param server handle to our server
*/
-struct GAS_Addresses_Handle *
-GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const struct GNUNET_STATISTICS_Handle *stats);
+void
+GAS_addresses_init (struct GNUNET_SERVER_Handle *server);
/**
* Shutdown address subsystem.
- *
- * @param handle the address handle to shutdown
*/
void
-GAS_addresses_done (struct GAS_Addresses_Handle *handle);
+GAS_addresses_done (void);
/**
* Add a new address for a peer.
*
- * @param handle the address handle to use
* @param peer peer
* @param plugin_name transport plugin name
* @param plugin_addr plugin address
- * @param plugin_addr_len length of the plugin address
- * @param session_id session id, can be 0
- * @param atsi performance information for this address
- * @param atsi_count number of performance information contained
+ * @param plugin_addr_len length of the @a plugin_addr
+ * @param local_address_info the local address for the address
+ * @param session_id session id, can never be 0.
+ * @param prop performance information for this address
*/
void
-GAS_addresses_add (struct GAS_Addresses_Handle *handle,
- const struct GNUNET_PeerIdentity *peer,
+GAS_addresses_add (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);
+ const struct GNUNET_ATS_Properties *prop);
/**
- * Notification about active use of an address.
- * in_use == GNUNET_YES:
- * This address is used to maintain an active connection with a peer.
- * in_use == GNUNET_NO:
- * This address is no longer used to maintain an active connection with a peer.
+ * Update an address with new performance information for a peer.
*
- * Note: can only be called with in_use == GNUNET_NO if called with GNUNET_YES
- * before
- *
- * @param handle the address handle to use
* @param peer peer
- * @param plugin_name transport plugin name
- * @param plugin_addr plugin address
- * @param plugin_addr_len length of the plugin address
- * @param session_id session id, can be 0
- * @param in_use GNUNET_YES if GNUNET_NO
- * @return GNUNET_SYSERR on failure (address unknown ...)
- */
-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,
- int in_use);
-
-
-/**
- * Update an address with a session or performance information for a peer.
- *
- * If an address was added without a session it will be updated with the
- * session
- *
- * @param handle the address handle to use
- * @param peer peer
- * @param plugin_name transport plugin name
- * @param plugin_addr plugin address
- * @param plugin_addr_len length of the plugin address
- * @param session_id session id, can be 0
- * @param atsi performance information for this address
- * @param atsi_count number of performance information contained
+ * @param session_id session id, can never be 0
+ * @param prop performance information for this address
*/
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,
+GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
uint32_t session_id,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count);
+ const struct GNUNET_ATS_Properties *prop);
/**
- * Remove an address or just a session for a peer.
+ * Remove an address for a peer.
*
- * @param handle the address handle to use
* @param peer peer
- * @param plugin_name transport plugin name
- * @param plugin_addr plugin address
- * @param plugin_addr_len length of the plugin address
- * @param session_id session id, can be 0
+ * @param session_id session id, can never be 0
*/
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,
+GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
uint32_t session_id);
/**
- * Remove all addresses
- *
- * @param handle the address handle to use
- */
-void
-GAS_addresses_destroy_all (struct GAS_Addresses_Handle *handle);
-
-
-/**
- * Request address suggestions for a peer
- *
- * @param handle the address handle
- * @param peer the peer id
- */
-void
-GAS_addresses_request_address (struct GAS_Addresses_Handle *handle,
- const struct GNUNET_PeerIdentity *peer);
-
-/**
- * Cancel address suggestions for a peer
- *
- * @param handle the address handle
- * @param peer the peer id
- */
-void
-GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle,
- const struct GNUNET_PeerIdentity *peer);
-
-
-/**
- * Reset suggestion backoff for a peer
- *
- * Suggesting addresses is blocked for ATS_BLOCKING_DELTA. Blocking can be
- * reset using this function
- *
- * @param handle the address handle
- * @param peer the peer id
- */
-void
-GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle,
- const struct GNUNET_PeerIdentity *peer);
-
-
-/**
- * Change the preference for a peer
- *
- * @param handle the address handle
- * @param client the client sending this request
- * @param peer the peer id
- * @param kind the preference kind to change
- * @param score_abs the new preference score
+ * Remove all addresses.
*/
void
-GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle,
- void *client,
- const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- float score_abs);
+GAS_addresses_destroy_all (void);
/**
- * Iterator for GAS_addresses_iterate_peers
+ * Iterator for #GAS_addresses_get_peer_info()
*
- * @param p_it_cls closure
- * @param id the peer id
- */
-typedef void (*GNUNET_ATS_Peer_Iterator) (void *p_it_cls,
- const struct GNUNET_PeerIdentity *id);
-
-
-/**
- * Return all peers currently known to ATS
- *
- * @param handle the address handle to use
- * @param p_it the iterator to call for every peer
- * @param p_it_cls the closure for the iterator
- */
-void
-GAS_addresses_iterate_peers (struct GAS_Addresses_Handle *handle,
- GNUNET_ATS_Peer_Iterator p_it,
- void *p_it_cls);
-
-
-/**
- * Iterator for GAS_addresses_get_peer_info
- *
- * @param p_it_cls closure closure
+ * @param cls closure
* @param id the peer id
* @param plugin_name plugin name
* @param plugin_addr address
- * @param plugin_addr_len address length
+ * @param plugin_addr_len length of @a plugin_addr
* @param address_active is address actively used
* @param atsi ats performance information
- * @param atsi_count number of ats performance elements
+ * @param local_address_info flags for the address
* @param bandwidth_out current outbound bandwidth assigned to address
* @param bandwidth_in current inbound bandwidth assigned to address
*/
-typedef void (*GNUNET_ATS_PeerInfo_Iterator) (void *p_it_cls,
- const struct GNUNET_PeerIdentity *id,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const int address_active,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
+typedef void
+(*GNUNET_ATS_PeerInfo_Iterator) (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const char *plugin_name,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const int address_active,
+ const struct GNUNET_ATS_Properties *prop,
+ enum GNUNET_HELLO_AddressInfo local_address_info,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
/**
* Return information all peers currently known to ATS
*
- * @param handle the address handle to use
* @param peer the respective peer
* @param pi_it the iterator to call for every peer
- * @param pi_it_cls the closure for the iterator
+ * @param pi_it_cls the closure for @a pi_it
*/
void
-GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle,
- const struct GNUNET_PeerIdentity *peer,
+GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer,
GNUNET_ATS_PeerInfo_Iterator pi_it,
void *pi_it_cls);
+
+/**
+ * Handle 'address list request' messages from clients.
+ *
+ * @param cls unused, NULL
+ * @param client client that sent the request
+ * @param message the request message
+ */
+void
+GAS_handle_request_address_list (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message);
+
+
#endif
/* end of gnunet-service-ats_addresses.h */