32 #define LOG(kind, ...) GNUNET_log_from (kind, "ats-proportional", __VA_ARGS__)
40 #define PROP_STABILITY_FACTOR 1.25
51 #define PROPORTIONALITY_FACTOR 2.0
222 "No bandwidth available in network\n");
243 for (aw = net->
head; NULL != aw; aw = aw->
next)
267 unsigned long long remaining_quota_in;
268 unsigned long long quota_out_used;
269 unsigned long long remaining_quota_out;
270 unsigned long long quota_in_used;
272 double sum_relative_peer_prefences;
275 const double *peer_relative_prefs;
278 "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n",
301 sum_relative_peer_prefences = 0.0;
303 for (aw = net->
head; NULL != aw; aw = aw->
next)
309 sum_relative_peer_prefences
317 "%s: Counted %u active addresses, expected %u active addresses\n",
325 "Total relative preference %.3f for %u addresses in network %s\n",
326 sum_relative_peer_prefences,
334 "Proportionally distributable bandwidth (in/out): %llu/%llu\n",
336 remaining_quota_out);
345 for (aw = net->
head; NULL != aw; aw = aw->
next)
361 + (peer_weight / total_weight)
362 * remaining_quota_in;
364 + (peer_weight / total_weight)
365 * remaining_quota_out;
368 "New quotas for peer `%s' with weight (cur/total) %.3f/%.3f (in/out) are: %u/%u\n",
378 "Total bandwidth assigned is (in/out): %llu /%llu\n",
382 GNUNET_break (quota_out_used <= net->total_quota_out + 1);
383 GNUNET_break (quota_in_used <= net->total_quota_in + 1);
399 for (cur = net->
head; NULL != cur; cur = cur->
next)
434 "Redistributing bandwidth in network %s with %u active and %u total addresses\n",
463 "Redistributing bandwidth in all %u networks\n",
529 double best_distance;
540 if ((NULL !=
ctx->best) &&
548 con =
ctx->s->env->get_connectivity (
ctx->s->env->cls,
570 *
ctx->s->stability_factor)
577 if (NULL ==
ctx->best)
586 best_distance =
ctx->best->norm_distance.norm;
588 best_delay =
ctx->best->norm_delay.norm;
591 if (cur_distance < best_distance)
598 else if ((best_distance / cur_distance) >
ctx->s->stability_factor)
606 if (cur_delay < best_delay)
613 else if ((best_delay / cur_delay) >
ctx->s->stability_factor)
668 "# ATS addresses total",
742 unsigned int con_min;
747 if (NULL != best_address)
751 if (current_address == best_address)
753 if (NULL != current_address)
760 "Disabling previous active address for peer `%s'\n",
768 if ((NULL == best_address) ||
772 if (NULL == best_address)
779 "Disconnecting peer `%s'.\n",
786 if (NULL == best_address)
790 "Cannot suggest address for peer `%s'\n",
796 "Selecting new address %p for peer `%s'\n",
805 "# ATS active addresses total",
813 "Address %p for peer `%s' is now active\n",
824 con_min = UINT32_MAX;
947 "Locking solver for bulk operation ...\n");
964 "Unlocking solver from bulk operation ...\n");
975 "No lock pending, recalculating\n");
1024 address->solver_information = aw;
1029 "# ATS addresses total",
1041 "Added new address for `%s', now total %u and active %u addresses in network `%s'\n",
1069 "Deleting %s address for peer `%s' from network `%s' (total: %u/active: %u)\n",
1094 address->solver_information = NULL;
1096 "After deleting address now total %u and active %u addresses in network `%s'\n",
1136 "PROP_STABILITY_FACTOR",
1139 if ((f_tmp < 1.0) || (f_tmp > 2.0))
1142 _ (
"Invalid %s configuration %f \n"),
1143 "PROP_STABILITY_FACTOR",
1150 "Using %s of %.3f\n",
1151 "PROP_STABILITY_FACTOR",
1159 "PROP_PROPORTIONALITY_FACTOR",
1165 _ (
"Invalid %s configuration %f\n"),
1166 "PROP_PROPORTIONALITY_FACTOR",
1173 "Using %s of %.3f\n",
1174 "PROP_PROPORTIONALITY_FACTOR",
1181 for (c = 0; c <
env->network_count; c++)
1189 "# ATS addresses %s total",
1192 "# ATS active addresses %s total",
1195 "Added network %u `%s' (%llu/%llu)\n",
1224 while (NULL != (cur =
next))
struct GNUNET_MQ_Envelope * env
static struct GNUNET_CONTAINER_MultiPeerMap * addresses
Hashmap to store addresses.
static char * address
GNS address for this phone.
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
ats service address management
static struct GNUNET_ATS_SolverFunctions * sf
Solver handle.
static int count_addresses(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Address iterator that counts the remaining addresses.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
Automatic transport selection and outbound bandwidth determination.
API to create, modify and access statistics.
@ GAS_STAT_SUCCESS
Success.
@ GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
After the problem was finished, start notifications about changes to addresses.
@ GAS_OP_SOLVE_START
A solution iteration has been started.
@ GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
After the problem was finished, notifications about changes to addresses are done.
@ GAS_OP_SOLVE_STOP
A solution iteration has been finished.
@ GAS_INFO_PROP_ALL
The proportional solver had to recalculate for all networks.
@ GAS_INFO_PROP_SINGLE
The proportional solver had to recalculate for a single network.
GNUNET_ATS_PreferenceKind
Enum defining all known preference categories.
@ GNUNET_ATS_PREFERENCE_BANDWIDTH
Change the peer's bandwidth value (value per byte of bandwidth in the goal function) to the given amo...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_float(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float *number)
Get a configuration value that should be a floating point number.
#define GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT
Bandwidth (in/out) to assume initially (before either peer has communicated any particular preference...
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static void GAS_proportional_address_delete(void *solver, struct ATS_Address *address)
Remove an address from the solver.
static struct ATS_Address * get_active_address(struct GAS_PROPORTIONAL_Handle *s, const struct GNUNET_PeerIdentity *peer)
Find current active address for peer.
static void GAS_proportional_address_property_changed(void *solver, struct ATS_Address *address)
Transport properties for this address have changed.
static void distribute_bandwidth(struct GAS_PROPORTIONAL_Handle *s, struct Network *net)
Update bandwidth assigned to peers in this network.
static void propagate_bandwidth(struct GAS_PROPORTIONAL_Handle *s, struct Network *net)
Notify ATS service of bandwidth changes to addresses.
void * libgnunet_plugin_ats_proportional_done(void *cls)
Function used to unload the plugin.
static void GAS_proportional_stop_get_address(void *solver, const struct GNUNET_PeerIdentity *peer)
Stop notifying about address and bandwidth changes for this peer.
#define PROPORTIONALITY_FACTOR
Default value to assume for the proportionality factor, if none is given in the configuration.
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.
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.
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.
static void distribute_bandwidth_in_network(struct GAS_PROPORTIONAL_Handle *s, struct Network *n)
Distribute bandwidth.
static void GAS_proportional_address_add(void *solver, struct ATS_Address *address, uint32_t network)
Add a new single address to a network.
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.
#define PROP_STABILITY_FACTOR
How much do we value stability over adaptation by default.
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 a...
static void GAS_proportional_start_get_address(void *solver, const struct GNUNET_PeerIdentity *peer)
Get the preferred address for a specific peer.
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.
void * libgnunet_plugin_ats_proportional_init(void *cls)
Function invoked when the plugin is loaded.
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.
static void GAS_proportional_bulk_start(void *solver)
Start a bulk operation.
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.
static void GAS_proportional_bulk_stop(void *solver)
Bulk operation done.
static void address_decrement_active(struct GAS_PROPORTIONAL_Handle *s, struct Network *net)
Decrease number of active addresses in network.
static enum GNUNET_NetworkType scope
Which network scope do we belong to?
Address with additional information.
struct GAS_NormalizationInfo norm_delay
Normalized delay information for this address.
uint32_t assigned_bw_in
Inbound bandwidth assigned by solver.
struct GNUNET_PeerIdentity peer
Peer ID this address is for.
int active
Is this the active address for this peer?
void * solver_information
Solver-specific information for this address.
uint32_t assigned_bw_out
Outbound bandwidth assigned by solver.
struct GAS_NormalizationInfo norm_distance
Normalized distance information for this address.
Address information stored for the proportional solver in the solver_information member of struct GNU...
struct ATS_Address * addr
The address.
struct AddressWrapper * prev
Previous in DLL.
uint32_t calculated_quota_in
Inbound quota.
struct Network * network
Network scope this address is in.
struct AddressWrapper * next
Next in DLL.
struct GNUNET_TIME_Absolute activated
When was this address activated.
uint32_t calculated_quota_out
Outbound quota.
Context for finding the best address* Linked list of addresses in this network: head.
struct ATS_Address * best
The currently best address.
struct GAS_PROPORTIONAL_Handle * s
The solver handle.
double norm
Normalized values from queue to a range of values [1.0...2.0].
A handle for the proportional solver.
double prop_factor
Proportionality factor.
double stability_factor
Stability factor.
struct Network * network_entries
Networks array.
unsigned int bulk_requests
Number of changes made while solver was locked.
unsigned int active_addresses
Number of active addresses for solver.
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
unsigned int bulk_lock
Bulk lock counter.
The ATS plugin will pass a pointer to a struct of this type as to the initialization function of the ...
void * cls
Closure to pass to all callbacks in this struct.
GAS_solver_information_callback info_cb
Callback for solver to call with status information, can be NULL.
GAS_get_preferences get_preferences
ATS addresses function to obtain preference values.
struct GNUNET_CONTAINER_MultiPeerMap * addresses
Hashmap containing all addresses available.
GAS_get_connectivity get_connectivity
ATS addresses function to obtain preference values.
unsigned int network_count
Number of networks available, size of the out_quota and in_quota arrays.
GAS_bandwidth_changed_cb bandwidth_changed_cb
ATS addresses callback to be notified about bandwidth assignment changes.
struct GNUNET_STATISTICS_Handle * stats
Statistics handle to be used by the solver.
GAS_solver_address_feedback_preference s_feedback
Give feedback about the current assignment.
GAS_solver_address_property_changed s_address_update_property
Update the properties of an address in the solver.
GAS_solver_address_add s_add
Add a new address for a peer to the solver.
void * cls
Closure to pass to all solver functions in this struct.
GAS_solver_bulk_start s_bulk_start
Start a bulk operation.
GAS_solver_get_preferred_address s_get
Tell solver to notify ATS if the address to use changes for a specific peer using the bandwidth chang...
GAS_solver_bulk_stop s_bulk_stop
Bulk operation done.
GAS_solver_address_change_preference s_pref
Change relative preference for quality in solver.
GAS_solver_stop_get_preferred_address s_get_stop
Tell solver stop notifying ATS about changes for this peers.
GAS_solver_address_delete s_del
Delete an address in the solver.
Internal representation of the hash map.
The identity of the host (wraps the signing key of the peer).
Handle to a client that is connected to a service.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Representation of a network.
unsigned int active_addresses
Number of active addresses for this network.
struct AddressWrapper * tail
Linked list of addresses in this network: tail.
unsigned long long total_quota_in
Total inbound quota.
char * stat_active
String for statistics active addresses.
struct AddressWrapper * head
Linked list of addresses in this network: head.
const char * desc
Network description.
enum GNUNET_NetworkType type
ATS network type.
char * stat_total
String for statistics total addresses.
unsigned long long total_quota_out
Total outbound quota.
unsigned int total_addresses
Number of total addresses for this network.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.