ATS proportional solver. More...
#include "platform.h"
#include "gnunet_statistics_service.h"
#include "gnunet_ats_service.h"
#include "gnunet_ats_plugin.h"
#include "gnunet-service-ats_addresses.h"
Go to the source code of this file.
Data Structures | |
struct | AddressWrapper |
Address information stored for the proportional solver in the solver_information member of struct GNUNET_ATS_Address . More... | |
struct | Network |
Representation of a network. More... | |
struct | GAS_PROPORTIONAL_Handle |
A handle for the proportional solver. More... | |
struct | FindBestAddressCtx |
Context for finding the best address* Linked list of addresses in this network: head. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "ats-proportional", __VA_ARGS__) |
#define | PROP_STABILITY_FACTOR 1.25 |
How much do we value stability over adaptation by default. More... | |
#define | PROPORTIONALITY_FACTOR 2.0 |
Default value to assume for the proportionality factor, if none is given in the configuration. More... | |
Functions | |
static int | is_bandwidth_available_in_network (struct Network *net, int extra) |
Test if bandwidth is available in this network to add an additional address. More... | |
static int | all_require_connectivity (struct GAS_PROPORTIONAL_Handle *s, struct Network *net, unsigned int con) |
Test if all peers in this network require connectivity at level at least con. More... | |
static void | distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, struct Network *net) |
Update bandwidth assigned to peers in this network. More... | |
static void | propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s, struct Network *net) |
Notify ATS service of bandwidth changes to addresses. More... | |
static void | distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, struct Network *n) |
Distribute bandwidth. More... | |
static int | find_best_address_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
Find a "good" address to use for a peer by iterating over the addresses for this peer. More... | |
struct ATS_Address * | get_best_address (struct GAS_PROPORTIONAL_Handle *s, struct GNUNET_CONTAINER_MultiPeerMap *addresses, const struct GNUNET_PeerIdentity *id) |
Find the currently best address for a peer from the set of addresses available or return NULL of no address is available. More... | |
static void | address_decrement_active (struct GAS_PROPORTIONAL_Handle *s, struct Network *net) |
Decrease number of active addresses in network. More... | |
static int | get_active_address_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
Address map iterator to find current active address for peer. More... | |
static struct ATS_Address * | get_active_address (struct GAS_PROPORTIONAL_Handle *s, const struct GNUNET_PeerIdentity *peer) |
Find current active address for peer. More... | |
static void | update_active_address (struct GAS_PROPORTIONAL_Handle *s, struct ATS_Address *current_address, const struct GNUNET_PeerIdentity *peer) |
Update active address for a peer. More... | |
static void | GAS_proportional_change_preference (void *solver, const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, double pref_rel) |
The preferences for a peer in the problem changed. More... | |
static void | GAS_proportional_feedback (void *solver, struct GNUNET_SERVICE_Client *application, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TIME_Relative scope, enum GNUNET_ATS_PreferenceKind kind, double score) |
Get application feedback for a peer. More... | |
static void | GAS_proportional_start_get_address (void *solver, const struct GNUNET_PeerIdentity *peer) |
Get the preferred address for a specific peer. More... | |
static void | GAS_proportional_stop_get_address (void *solver, const struct GNUNET_PeerIdentity *peer) |
Stop notifying about address and bandwidth changes for this peer. More... | |
static void | GAS_proportional_bulk_start (void *solver) |
Start a bulk operation. More... | |
static void | GAS_proportional_bulk_stop (void *solver) |
Bulk operation done. More... | |
static void | GAS_proportional_address_property_changed (void *solver, struct ATS_Address *address) |
Transport properties for this address have changed. More... | |
static void | GAS_proportional_address_add (void *solver, struct ATS_Address *address, uint32_t network) |
Add a new single address to a network. More... | |
static void | GAS_proportional_address_delete (void *solver, struct ATS_Address *address) |
Remove an address from the solver. More... | |
void * | libgnunet_plugin_ats_proportional_init (void *cls) |
Function invoked when the plugin is loaded. More... | |
void * | libgnunet_plugin_ats_proportional_done (void *cls) |
Function used to unload the plugin. More... | |
ATS proportional solver.
Definition in file plugin_ats_proportional.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "ats-proportional", __VA_ARGS__) |
Definition at line 32 of file plugin_ats_proportional.c.
#define PROP_STABILITY_FACTOR 1.25 |
How much do we value stability over adaptation by default.
A low value (close to 1.0) means we adapt as soon as possible, a larger value means that we have to have the respective factor of an advantage (or delay) before we adapt and sacrifice stability.
Definition at line 40 of file plugin_ats_proportional.c.
#define PROPORTIONALITY_FACTOR 2.0 |
Default value to assume for the proportionality factor, if none is given in the configuration.
This factor determines how strong the bandwidth allocation will orient itself on the application preferences. A lower factor means a more balanced bandwidth distribution while a larger number means a distribution more in line with application (bandwidth) preferences.
Definition at line 51 of file plugin_ats_proportional.c.
|
static |
Test if bandwidth is available in this network to add an additional address.
net | the network type to check |
extra | for how many extra addresses do we check? |
Definition at line 208 of file plugin_ats_proportional.c.
References Network::active_addresses, GNUNET_assert, GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_YES, LOG, Network::total_quota_in, and Network::total_quota_out.
Referenced by find_best_address_it(), and update_active_address().
|
static |
Test if all peers in this network require connectivity at level at least con.
s | the solver handle |
net | the network type to check |
con | connection return value threshold to check |
Definition at line 237 of file plugin_ats_proportional.c.
References AddressWrapper::addr, GNUNET_ATS_PluginEnvironment::cls, GAS_PROPORTIONAL_Handle::env, GNUNET_ATS_PluginEnvironment::get_connectivity, GNUNET_NO, GNUNET_YES, Network::head, AddressWrapper::next, and ATS_Address::peer.
Referenced by find_best_address_it().
|
static |
Update bandwidth assigned to peers in this network.
The basic idea is to assign every peer in the network the minimum bandwidth, and then distribute the remaining bandwidth proportional to application preferences.
s | the solver handle |
net | the network type to update |
Definition at line 262 of file plugin_ats_proportional.c.
References ATS_Address::active, Network::active_addresses, AddressWrapper::addr, AddressWrapper::calculated_quota_in, AddressWrapper::calculated_quota_out, GNUNET_ATS_PluginEnvironment::cls, count_addresses(), Network::desc, GAS_PROPORTIONAL_Handle::env, GNUNET_ATS_PluginEnvironment::get_preferences, GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_break, GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s(), GNUNET_YES, Network::head, LOG, AddressWrapper::next, ATS_Address::peer, GAS_PROPORTIONAL_Handle::prop_factor, Network::total_quota_in, and Network::total_quota_out.
Referenced by distribute_bandwidth_in_network().
|
static |
Notify ATS service of bandwidth changes to addresses.
s | solver handle |
net | the network to propagate changes in |
Definition at line 394 of file plugin_ats_proportional.c.
References ATS_Address::active, AddressWrapper::addr, ATS_Address::assigned_bw_in, ATS_Address::assigned_bw_out, GNUNET_ATS_PluginEnvironment::bandwidth_changed_cb, AddressWrapper::calculated_quota_in, AddressWrapper::calculated_quota_out, GNUNET_ATS_PluginEnvironment::cls, GAS_PROPORTIONAL_Handle::env, GNUNET_YES, Network::head, and AddressWrapper::next.
Referenced by distribute_bandwidth_in_network().
|
static |
Distribute bandwidth.
The addresses have already been selected, this is merely distributed the bandwidth among the addresses.
s | the solver handle |
n | the network, can be NULL for all networks |
Definition at line 421 of file plugin_ats_proportional.c.
References Network::active_addresses, GAS_PROPORTIONAL_Handle::bulk_lock, GAS_PROPORTIONAL_Handle::bulk_requests, GNUNET_ATS_PluginEnvironment::cls, distribute_bandwidth(), GAS_PROPORTIONAL_Handle::env, GAS_INFO_PROP_ALL, GAS_INFO_PROP_SINGLE, GAS_OP_SOLVE_START, GAS_OP_SOLVE_STOP, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, GAS_STAT_SUCCESS, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NT_to_string(), GNUNET_ATS_PluginEnvironment::info_cb, LOG, GNUNET_ATS_PluginEnvironment::network_count, GAS_PROPORTIONAL_Handle::network_entries, propagate_bandwidth(), Network::total_addresses, and Network::type.
Referenced by GAS_proportional_address_delete(), GAS_proportional_address_property_changed(), GAS_proportional_bulk_stop(), GAS_proportional_change_preference(), GAS_proportional_stop_get_address(), and update_active_address().
|
static |
Find a "good" address to use for a peer by iterating over the addresses for this peer.
If we already have an existing address, we stick to it. Otherwise, we pick by lowest distance and then by lowest latency.
cls | the ‘struct FindBestAddressCtx *’ where we store the result |
key | the peer we are trying to find the best address for |
value | another struct ATS_Address* to consider using |
Definition at line 520 of file plugin_ats_proportional.c.
References AddressWrapper::activated, ATS_Address::active, all_require_connectivity(), ctx, GNUNET_NO, GNUNET_OK, GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_UNIT_SECONDS, GNUNET_YES, is_bandwidth_available_in_network(), key, AddressWrapper::network, GAS_NormalizationInfo::norm, ATS_Address::norm_delay, ATS_Address::norm_distance, GNUNET_TIME_Relative::rel_value_us, ATS_Address::solver_information, and value.
Referenced by get_best_address().
struct ATS_Address* get_best_address | ( | struct GAS_PROPORTIONAL_Handle * | s, |
struct GNUNET_CONTAINER_MultiPeerMap * | addresses, | ||
const struct GNUNET_PeerIdentity * | id | ||
) |
Find the currently best address for a peer from the set of addresses available or return NULL of no address is available.
s | the proportional handle |
addresses | the address hashmap |
id | the peer id |
Definition at line 633 of file plugin_ats_proportional.c.
References addresses, FindBestAddressCtx::best, find_best_address_it(), GNUNET_CONTAINER_multipeermap_get_multiple(), and FindBestAddressCtx::s.
Referenced by update_active_address().
|
static |
Decrease number of active addresses in network.
s | the solver handle |
net | the network type |
Definition at line 656 of file plugin_ats_proportional.c.
References Network::active_addresses, GAS_PROPORTIONAL_Handle::active_addresses, GAS_PROPORTIONAL_Handle::env, GNUNET_assert, GNUNET_NO, GNUNET_STATISTICS_update(), FindBestAddressCtx::s, Network::stat_active, and GNUNET_ATS_PluginEnvironment::stats.
Referenced by update_active_address().
|
static |
Address map iterator to find current active address for peer.
Asserts that only one address is active per peer.
cls | last active address |
key | peer's key |
value | address to check |
Definition at line 684 of file plugin_ats_proportional.c.
References ATS_Address::active, warningfilter::dest, GNUNET_assert, GNUNET_OK, GNUNET_YES, and value.
Referenced by get_active_address().
|
static |
Find current active address for peer.
s | the solver handle |
peer | the peer |
Definition at line 707 of file plugin_ats_proportional.c.
References GNUNET_ATS_PluginEnvironment::addresses, warningfilter::dest, GAS_PROPORTIONAL_Handle::env, get_active_address_it(), GNUNET_CONTAINER_multipeermap_get_multiple(), and peer.
Referenced by GAS_proportional_address_add(), GAS_proportional_start_get_address(), and GAS_proportional_stop_get_address().
|
static |
Update active address for a peer.
Check if active address exists and what the best address is, if addresses are different switch. Then reallocate bandwidth within the affected network scopes.
s | solver handle |
current_address | the address currently active for the peer, NULL for none |
peer | the peer to check |
Definition at line 732 of file plugin_ats_proportional.c.
References AddressWrapper::activated, ATS_Address::active, Network::active_addresses, GAS_PROPORTIONAL_Handle::active_addresses, AddressWrapper::addr, address_decrement_active(), GNUNET_ATS_PluginEnvironment::addresses, ATS_Address::assigned_bw_in, ATS_Address::assigned_bw_out, GNUNET_ATS_PluginEnvironment::bandwidth_changed_cb, GNUNET_ATS_PluginEnvironment::cls, distribute_bandwidth_in_network(), GAS_PROPORTIONAL_Handle::env, get_best_address(), GNUNET_ATS_PluginEnvironment::get_connectivity, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_YES, Network::head, is_bandwidth_available_in_network(), LOG, AddressWrapper::network, AddressWrapper::next, ATS_Address::peer, peer, ATS_Address::solver_information, Network::stat_active, and GNUNET_ATS_PluginEnvironment::stats.
Referenced by GAS_proportional_address_add(), GAS_proportional_address_delete(), and GAS_proportional_start_get_address().
|
static |
The preferences for a peer in the problem changed.
solver | the solver handle |
peer | the peer to change the preference for |
kind | the kind to change the preference |
pref_rel | the normalized preference value for this kind over all clients |
Definition at line 857 of file plugin_ats_proportional.c.
References distribute_bandwidth_in_network(), and GNUNET_ATS_PREFERENCE_BANDWIDTH.
Referenced by libgnunet_plugin_ats_proportional_init().
|
static |
Get application feedback for a peer.
solver | the solver handle |
application | the application |
peer | the peer to change the preference for |
scope | the time interval for this feedback: [now - scope .. now] |
kind | the kind to change the preference |
score | the score |
Definition at line 882 of file plugin_ats_proportional.c.
Referenced by libgnunet_plugin_ats_proportional_init().
|
static |
Get the preferred address for a specific peer.
solver | the solver handle |
peer | the identity of the peer |
Definition at line 900 of file plugin_ats_proportional.c.
References get_active_address(), peer, and update_active_address().
Referenced by libgnunet_plugin_ats_proportional_init().
|
static |
Stop notifying about address and bandwidth changes for this peer.
solver | the solver handle |
peer | the peer |
Definition at line 919 of file plugin_ats_proportional.c.
References distribute_bandwidth_in_network(), get_active_address(), AddressWrapper::network, peer, and ATS_Address::solver_information.
Referenced by libgnunet_plugin_ats_proportional_init().
|
static |
Start a bulk operation.
solver | the solver |
Definition at line 942 of file plugin_ats_proportional.c.
References GAS_PROPORTIONAL_Handle::bulk_lock, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, and LOG.
Referenced by libgnunet_plugin_ats_proportional_init().
|
static |
Bulk operation done.
solver | our struct GAS_PROPORTIONAL_Handle * |
Definition at line 959 of file plugin_ats_proportional.c.
References GAS_PROPORTIONAL_Handle::bulk_lock, GAS_PROPORTIONAL_Handle::bulk_requests, distribute_bandwidth_in_network(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, and LOG.
Referenced by libgnunet_plugin_ats_proportional_init().
|
static |
Transport properties for this address have changed.
solver | solver handle |
address | the address |
Definition at line 990 of file plugin_ats_proportional.c.
References address, distribute_bandwidth_in_network(), and AddressWrapper::network.
Referenced by libgnunet_plugin_ats_proportional_init().
|
static |
Add a new single address to a network.
solver | the solver Handle |
address | the address to add |
network | network type of this address |
Definition at line 1009 of file plugin_ats_proportional.c.
References Network::active_addresses, AddressWrapper::addr, address, Network::desc, env, GAS_PROPORTIONAL_Handle::env, get_active_address(), GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_update(), Network::head, LOG, AddressWrapper::network, GAS_PROPORTIONAL_Handle::network_entries, Network::stat_total, GNUNET_ATS_PluginEnvironment::stats, Network::tail, Network::total_addresses, and update_active_address().
Referenced by libgnunet_plugin_ats_proportional_init().
|
static |
Remove an address from the solver.
To do so, we:
solver | the solver handle |
address | the address to remove |
Definition at line 1061 of file plugin_ats_proportional.c.
References Network::active_addresses, address, Network::desc, distribute_bandwidth_in_network(), GAS_PROPORTIONAL_Handle::env, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, Network::head, LOG, AddressWrapper::network, Network::stat_total, GNUNET_ATS_PluginEnvironment::stats, Network::tail, Network::total_addresses, and update_active_address().
Referenced by libgnunet_plugin_ats_proportional_init().
void* libgnunet_plugin_ats_proportional_init | ( | void * | cls | ) |
Function invoked when the plugin is loaded.
[in,out] | cls | the struct GNUNET_ATS_PluginEnvironment * to use; modified to return the API functions (ugh). |
struct GAS_PROPORTIONAL_Handle
to pass as a closure Definition at line 1111 of file plugin_ats_proportional.c.
References _, GNUNET_ATS_SolverFunctions::cls, GNUNET_ATS_PluginEnvironment::cls, Network::desc, env, GAS_PROPORTIONAL_Handle::env, GAS_proportional_address_add(), GAS_proportional_address_delete(), GAS_proportional_address_property_changed(), GAS_proportional_bulk_start(), GAS_proportional_bulk_stop(), GAS_proportional_change_preference(), GAS_proportional_feedback(), GAS_proportional_start_get_address(), GAS_proportional_stop_get_address(), GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_float(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_malloc, GNUNET_new, GNUNET_NT_to_string(), GNUNET_SYSERR, LOG, GAS_PROPORTIONAL_Handle::network_entries, GAS_PROPORTIONAL_Handle::prop_factor, PROP_STABILITY_FACTOR, PROPORTIONALITY_FACTOR, GNUNET_ATS_SolverFunctions::s_add, GNUNET_ATS_SolverFunctions::s_address_update_property, GNUNET_ATS_SolverFunctions::s_bulk_start, GNUNET_ATS_SolverFunctions::s_bulk_stop, GNUNET_ATS_SolverFunctions::s_del, GNUNET_ATS_SolverFunctions::s_feedback, GNUNET_ATS_SolverFunctions::s_get, GNUNET_ATS_SolverFunctions::s_get_stop, GNUNET_ATS_SolverFunctions::s_pref, sf, GAS_PROPORTIONAL_Handle::stability_factor, Network::stat_active, Network::stat_total, Network::total_quota_in, Network::total_quota_out, and Network::type.
void* libgnunet_plugin_ats_proportional_done | ( | void * | cls | ) |
Function used to unload the plugin.
cls | return value from libgnunet_plugin_ats_proportional_init() |
Definition at line 1211 of file plugin_ats_proportional.c.
References Network::active_addresses, GAS_PROPORTIONAL_Handle::active_addresses, AddressWrapper::addr, GNUNET_ATS_SolverFunctions::cls, GAS_PROPORTIONAL_Handle::env, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, Network::head, GNUNET_ATS_PluginEnvironment::network_count, GAS_PROPORTIONAL_Handle::network_entries, AddressWrapper::next, sf, ATS_Address::solver_information, Network::stat_active, Network::stat_total, Network::tail, and Network::total_addresses.