GNUnet  0.10.x
Data Structures | Macros | Functions
plugin_ats_proportional.c File Reference

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"
Include dependency graph for plugin_ats_proportional.c:

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 (to be expanded...) 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_Addressget_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_Addressget_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...
 

Detailed Description

ATS proportional solver.

Author
Matthias Wachs
Christian Grothoff

Definition in file plugin_ats_proportional.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from(kind, "ats-proportional", __VA_ARGS__)

◆ PROP_STABILITY_FACTOR

#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.

Referenced by libgnunet_plugin_ats_proportional_init().

◆ PROPORTIONALITY_FACTOR

#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.

Referenced by libgnunet_plugin_ats_proportional_init().

Function Documentation

◆ is_bandwidth_available_in_network()

static int is_bandwidth_available_in_network ( struct Network net,
int  extra 
)
static

Test if bandwidth is available in this network to add an additional address.

Parameters
netthe network type to check
extrafor how many extra addresses do we check?
Returns
GNUNET_YES or GNUNET_NO

Definition at line 205 of file plugin_ats_proportional.c.

References Network::active_addresses, GNUNET_assert, GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, GNUNET_NO, GNUNET_YES, Network::total_quota_in, and Network::total_quota_out.

Referenced by find_best_address_it(), and update_active_address().

207 {
208  unsigned int na;
209  uint32_t min_bw = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
210 
211  GNUNET_assert(((int)net->active_addresses) + extra >= 0);
212  na = net->active_addresses + extra;
213  if (0 == na)
214  return GNUNET_YES;
215  if (((net->total_quota_in / na) > min_bw) &&
216  ((net->total_quota_out / na) > min_bw))
217  return GNUNET_YES;
218  return GNUNET_NO;
219 }
unsigned long long total_quota_out
Total outbound quota.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT
Bandwidth (in/out) to assume initially (before either peer has communicated any particular preference...
#define GNUNET_NO
Definition: gnunet_common.h:78
unsigned long long total_quota_in
Total inbound quota.
#define GNUNET_YES
Definition: gnunet_common.h:77
unsigned int active_addresses
Number of active addresses for this network.
Here is the caller graph for this function:

◆ all_require_connectivity()

static int all_require_connectivity ( struct GAS_PROPORTIONAL_Handle s,
struct Network net,
unsigned int  con 
)
static

Test if all peers in this network require connectivity at level at least con.

Parameters
sthe solver handle
netthe network type to check
conconnection return value threshold to check
Returns
GNUNET_YES or GNUNET_NO

Definition at line 232 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().

235 {
236  struct AddressWrapper *aw;
237 
238  for (aw = net->head; NULL != aw; aw = aw->next)
239  if (con >
240  s->env->get_connectivity(s->env->cls,
241  &aw->addr->peer))
242  return GNUNET_NO;
243  return GNUNET_YES;
244 }
struct AddressWrapper * next
Next in DLL.
struct GNUNET_PeerIdentity peer
Peer ID this address is for.
Address information stored for the proportional solver in the solver_information member of struct GNU...
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
struct AddressWrapper * head
Linked list of addresses in this network: head.
void * cls
Closure to pass to all callbacks in this struct.
struct ATS_Address * addr
The address.
#define GNUNET_YES
Definition: gnunet_common.h:77
GAS_get_connectivity get_connectivity
ATS addresses function to obtain preference values.
Here is the caller graph for this function:

◆ distribute_bandwidth()

static void distribute_bandwidth ( struct GAS_PROPORTIONAL_Handle s,
struct Network net 
)
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.

Parameters
sthe solver handle
netthe network type to update

Definition at line 257 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().

259 {
260  const uint32_t min_bw = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
261  struct AddressWrapper *aw;
262  unsigned long long remaining_quota_in;
263  unsigned long long quota_out_used;
264  unsigned long long remaining_quota_out;
265  unsigned long long quota_in_used;
266  unsigned int count_addresses;
267  double sum_relative_peer_prefences;
268  double peer_weight;
269  double total_weight;
270  const double *peer_relative_prefs;
271 
273  "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n",
274  net->desc,
275  net->active_addresses,
276  net->total_quota_in,
277  net->total_quota_in);
278 
279  if (0 == net->active_addresses)
280  return; /* no addresses to update */
281 
282  /* sanity checks */
283  if ((net->active_addresses * min_bw) > net->total_quota_in)
284  {
285  GNUNET_break(0);
286  return;
287  }
288  if ((net->active_addresses * min_bw) > net->total_quota_out)
289  {
290  GNUNET_break(0);
291  return;
292  }
293 
294  /* Calculate sum of relative preference for active addresses in this
295  network */
296  sum_relative_peer_prefences = 0.0;
297  count_addresses = 0;
298  for (aw = net->head; NULL != aw; aw = aw->next)
299  {
300  if (GNUNET_YES != aw->addr->active)
301  continue;
302  peer_relative_prefs = s->env->get_preferences(s->env->cls,
303  &aw->addr->peer);
304  sum_relative_peer_prefences
305  += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
306  count_addresses++;
307  }
308  if (count_addresses != net->active_addresses)
309  {
310  GNUNET_break(0);
312  "%s: Counted %u active addresses, expected %u active addresses\n",
313  net->desc,
314  count_addresses,
315  net->active_addresses);
316  /* try to fix... */
318  }
320  "Total relative preference %.3f for %u addresses in network %s\n",
321  sum_relative_peer_prefences,
322  net->active_addresses,
323  net->desc);
324 
325  /* check how much we have to distribute */
326  remaining_quota_in = net->total_quota_in - (net->active_addresses * min_bw);
327  remaining_quota_out = net->total_quota_out - (net->active_addresses * min_bw);
329  "Proportionally distributable bandwidth (in/out): %llu/%llu\n",
330  remaining_quota_in,
331  remaining_quota_out);
332 
333  /* distribute remaining quota; we do not do it exactly proportional,
334  but balance "even" distribution ("net->active_addresses") with
335  the preference sum using the "prop_factor". */
336  total_weight = net->active_addresses +
337  s->prop_factor * sum_relative_peer_prefences;
338  quota_out_used = 0;
339  quota_in_used = 0;
340  for (aw = net->head; NULL != aw; aw = aw->next)
341  {
342  if (GNUNET_YES != aw->addr->active)
343  {
344  /* set to 0, just to be sure */
345  aw->calculated_quota_in = 0;
346  aw->calculated_quota_out = 0;
347  continue;
348  }
349  peer_relative_prefs = s->env->get_preferences(s->env->cls,
350  &aw->addr->peer);
351  peer_weight = 1.0
352  + s->prop_factor * peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
353 
354  aw->calculated_quota_in = min_bw
355  + (peer_weight / total_weight) * remaining_quota_in;
356  aw->calculated_quota_out = min_bw
357  + (peer_weight / total_weight) * remaining_quota_out;
358 
360  "New quotas for peer `%s' with weight (cur/total) %.3f/%.3f (in/out) are: %u/%u\n",
361  GNUNET_i2s(&aw->addr->peer),
362  peer_weight,
363  total_weight,
364  (unsigned int)aw->calculated_quota_in,
365  (unsigned int)aw->calculated_quota_out);
366  quota_in_used += aw->calculated_quota_in;
367  quota_out_used += aw->calculated_quota_out;
368  }
370  "Total bandwidth assigned is (in/out): %llu /%llu\n",
371  quota_in_used,
372  quota_out_used);
373  /* +1 due to possible rounding errors */
374  GNUNET_break(quota_out_used <= net->total_quota_out + 1);
375  GNUNET_break(quota_in_used <= net->total_quota_in + 1);
376 }
static int count_addresses(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Address iterator that counts the remaining addresses.
struct AddressWrapper * next
Next in DLL.
unsigned long long total_quota_out
Total outbound quota.
uint32_t calculated_quota_out
Outbound quota.
int active
Is this the active address for this peer?
GAS_get_preferences get_preferences
ATS addresses function to obtain preference values.
struct GNUNET_PeerIdentity peer
Peer ID this address is for.
Address information stored for the proportional solver in the solver_information member of struct GNU...
const char * desc
Network description.
#define GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT
Bandwidth (in/out) to assume initially (before either peer has communicated any particular preference...
double prop_factor
Proportionality factor.
#define LOG(kind,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
struct AddressWrapper * head
Linked list of addresses in this network: head.
uint32_t calculated_quota_in
Inbound quota.
unsigned long long total_quota_in
Total inbound quota.
Change the peer&#39;s bandwidth value (value per byte of bandwidth in the goal function) to the given amo...
void * cls
Closure to pass to all callbacks in this struct.
struct ATS_Address * addr
The address.
#define GNUNET_YES
Definition: gnunet_common.h:77
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
unsigned int active_addresses
Number of active addresses for this network.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ propagate_bandwidth()

static void propagate_bandwidth ( struct GAS_PROPORTIONAL_Handle s,
struct Network net 
)
static

Notify ATS service of bandwidth changes to addresses.

Parameters
ssolver handle
netthe network to propagate changes in

Definition at line 386 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().

388 {
389  struct AddressWrapper *cur;
390 
391  for (cur = net->head; NULL != cur; cur = cur->next)
392  {
393  if ((cur->addr->assigned_bw_in == cur->calculated_quota_in) &&
394  (cur->addr->assigned_bw_out == cur->calculated_quota_out))
395  continue;
398  if (GNUNET_YES == cur->addr->active)
400  cur->addr);
401  }
402 }
struct AddressWrapper * next
Next in DLL.
uint32_t calculated_quota_out
Outbound quota.
int active
Is this the active address for this peer?
Address information stored for the proportional solver in the solver_information member of struct GNU...
uint32_t assigned_bw_in
Inbound bandwidth assigned by solver.
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
struct AddressWrapper * head
Linked list of addresses in this network: head.
uint32_t calculated_quota_in
Inbound quota.
uint32_t assigned_bw_out
Outbound bandwidth assigned by solver.
void * cls
Closure to pass to all callbacks in this struct.
struct ATS_Address * addr
The address.
#define GNUNET_YES
Definition: gnunet_common.h:77
GAS_bandwidth_changed_cb bandwidth_changed_cb
ATS addresses callback to be notified about bandwidth assignment changes.
Here is the caller graph for this function:

◆ distribute_bandwidth_in_network()

static void distribute_bandwidth_in_network ( struct GAS_PROPORTIONAL_Handle s,
struct Network n 
)
static

Distribute bandwidth.

The addresses have already been selected, this is merely distributed the bandwidth among the addresses.

Parameters
sthe solver handle
nthe network, can be NULL for all networks

Definition at line 413 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().

415 {
416  unsigned int i;
417 
418  if (0 != s->bulk_lock)
419  {
420  s->bulk_requests++;
421  return;
422  }
423  if (NULL != n)
424  {
426  "Redistributing bandwidth in network %s with %u active and %u total addresses\n",
428  n->active_addresses,
429  n->total_addresses);
430  s->env->info_cb(s->env->cls,
435  n);
436  s->env->info_cb(s->env->cls,
440  s->env->info_cb(s->env->cls,
445  n);
446 
447  s->env->info_cb(s->env->cls,
451  }
452  else
453  {
455  "Redistributing bandwidth in all %u networks\n",
456  s->env->network_count);
457  s->env->info_cb(s->env->cls,
461  for (i = 0; i < s->env->network_count; i++)
463  &s->network_entries[i]);
464  s->env->info_cb(s->env->cls,
468  s->env->info_cb(s->env->cls,
472  for (i = 0; i < s->env->network_count; i++)
474  &s->network_entries[i]);
475  s->env->info_cb(s->env->cls,
479  }
480 }
unsigned int total_addresses
Number of total addresses for this network.
After the problem was finished, start notifications about changes to addresses.
The proportional solver had to recalculate for a single network.
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
Definition: nt.c:43
The proportional solver had to recalculate for all networks.
#define LOG(kind,...)
A solution iteration has been started.
static void propagate_bandwidth(struct GAS_PROPORTIONAL_Handle *s, struct Network *net)
Notify ATS service of bandwidth changes to addresses.
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
unsigned int bulk_requests
Number of changes made while solver was locked.
enum GNUNET_NetworkType type
ATS network type.
static void distribute_bandwidth(struct GAS_PROPORTIONAL_Handle *s, struct Network *net)
Update bandwidth assigned to peers in this network.
struct Network * network_entries
Networks array.
A solution iteration has been finished.
GAS_solver_information_callback info_cb
Callback for solver to call with status information, can be NULL.
void * cls
Closure to pass to all callbacks in this struct.
unsigned int bulk_lock
Bulk lock counter.
After the problem was finished, notifications about changes to addresses are done.
unsigned int active_addresses
Number of active addresses for this network.
unsigned int network_count
Number of networks available, size of the out_quota and in_quota arrays.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_best_address_it()

static int find_best_address_it ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
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.

Parameters
clsthe `struct FindBestAddressCtx *' where we store the result
keythe peer we are trying to find the best address for
valueanother struct ATS_Address* to consider using
Returns
GNUNET_OK (continue to iterate)

Definition at line 511 of file plugin_ats_proportional.c.

References AddressWrapper::activated, ATS_Address::active, all_require_connectivity(), FindBestAddressCtx::best, GNUNET_ATS_PluginEnvironment::cls, ctx, GAS_PROPORTIONAL_Handle::env, GNUNET_ATS_PluginEnvironment::get_connectivity, GNUNET_NO, GNUNET_OK, GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_UNIT_SECONDS, GNUNET_YES, is_bandwidth_available_in_network(), AddressWrapper::network, GAS_NormalizationInfo::norm, ATS_Address::norm_delay, ATS_Address::norm_distance, GNUNET_TIME_Relative::rel_value_us, FindBestAddressCtx::s, ATS_Address::solver_information, GAS_PROPORTIONAL_Handle::stability_factor, and value.

Referenced by get_best_address().

514 {
515  struct FindBestAddressCtx *ctx = cls;
516  struct ATS_Address *current = value;
517  struct AddressWrapper *asi = current->solver_information;
518  struct GNUNET_TIME_Relative active_time;
519  double best_delay;
520  double best_distance;
521  double cur_delay;
522  double cur_distance;
523  unsigned int con;
524  int bw_available;
525  int need;
526 
527  /* we need +1 slot if 'current' is not yet active */
528  need = (GNUNET_YES == current->active) ? 0 : 1;
529  /* we save -1 slot if 'best' is active and belongs
530  to the same network (as we would replace it) */
531  if ((NULL != ctx->best) &&
532  (GNUNET_YES == ctx->best->active) &&
533  (((struct AddressWrapper *)ctx->best->solver_information)->network ==
534  asi->network))
535  need--;
536  /* we can gain -1 slot if this peers connectivity
537  requirement is higher than that of another peer
538  in that network scope */
539  con = ctx->s->env->get_connectivity(ctx->s->env->cls,
540  key);
541  if (GNUNET_YES !=
543  asi->network,
544  con))
545  need--;
546  /* test if minimum bandwidth for 'current' would be available */
547  bw_available
549  need);
550  if (!bw_available)
551  {
552  /* Bandwidth for this address is unavailable, so we cannot use
553  it. */
554  return GNUNET_OK;
555  }
556  if (GNUNET_YES == current->active)
557  {
558  active_time = GNUNET_TIME_absolute_get_duration(asi->activated);
559  if (active_time.rel_value_us <=
560  ((double)GNUNET_TIME_UNIT_SECONDS.rel_value_us) * ctx->s->stability_factor)
561  {
562  /* Keep active address for stability reasons */
563  ctx->best = current;
564  return GNUNET_NO;
565  }
566  }
567  if (NULL == ctx->best)
568  {
569  /* We so far have nothing else, so go with it! */
570  ctx->best = current;
571  return GNUNET_OK;
572  }
573 
574  /* Now compare ATS information */
575  cur_distance = current->norm_distance.norm;
576  best_distance = ctx->best->norm_distance.norm;
577  cur_delay = current->norm_delay.norm;
578  best_delay = ctx->best->norm_delay.norm;
579 
580  /* user shorter distance */
581  if (cur_distance < best_distance)
582  {
583  if (GNUNET_NO == ctx->best->active)
584  {
585  /* Activity doesn't influence the equation, use current */
586  ctx->best = current;
587  }
588  else if ((best_distance / cur_distance) > ctx->s->stability_factor)
589  {
590  /* Distance change is significant, switch active address! */
591  ctx->best = current;
592  }
593  }
594 
595  /* User connection with less delay */
596  if (cur_delay < best_delay)
597  {
598  if (GNUNET_NO == ctx->best->active)
599  {
600  /* Activity doesn't influence the equation, use current */
601  ctx->best = current;
602  }
603  else if ((best_delay / cur_delay) > ctx->s->stability_factor)
604  {
605  /* Latency change is significant, switch active address! */
606  ctx->best = current;
607  }
608  }
609  return GNUNET_OK;
610 }
struct ATS_Address * best
The currently best address.
struct GNUNET_TIME_Absolute activated
When was this address activated.
int active
Is this the active address for this peer?
Address information stored for the proportional solver in the solver_information member of struct GNU...
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GAS_PROPORTIONAL_Handle * s
The solver handle.
struct Network * network
Network scope this address is in.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static char * value
Value of the record to add/remove.
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
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.
Address with additional information.
void * solver_information
Solver-specific information for this address.
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...
Definition: time.c:373
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.
Context for finding the best address* Linked list of addresses in this network: head.
struct GAS_NormalizationInfo norm_delay
Normalized delay information for this address.
void * cls
Closure to pass to all callbacks in this struct.
#define GNUNET_YES
Definition: gnunet_common.h:77
double norm
Normalized values from queue to a range of values [1.0...2.0].
double stability_factor
Stability factor.
struct GAS_NormalizationInfo norm_distance
Normalized distance information for this address.
GAS_get_connectivity get_connectivity
ATS addresses function to obtain preference values.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
sthe proportional handle
addressesthe address hashmap
idthe peer id
Returns
the address or NULL

Definition at line 623 of file plugin_ats_proportional.c.

References FindBestAddressCtx::best, find_best_address_it(), GNUNET_CONTAINER_multipeermap_get_multiple(), and FindBestAddressCtx::s.

Referenced by update_active_address().

626 {
627  struct FindBestAddressCtx fba_ctx;
628 
629  fba_ctx.best = NULL;
630  fba_ctx.s = s;
632  id,
634  &fba_ctx);
635  return fba_ctx.best;
636 }
struct ATS_Address * best
The currently best address.
struct GAS_PROPORTIONAL_Handle * s
The solver handle.
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.
Context for finding the best address* Linked list of addresses in this network: head.
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ address_decrement_active()

static void address_decrement_active ( struct GAS_PROPORTIONAL_Handle s,
struct Network net 
)
static

Decrease number of active addresses in network.

Parameters
sthe solver handle
netthe network type

Definition at line 646 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(), Network::stat_active, and GNUNET_ATS_PluginEnvironment::stats.

Referenced by update_active_address().

648 {
650  net->active_addresses--;
652  net->stat_active,
653  -1,
654  GNUNET_NO);
656  s->active_addresses--;
658  "# ATS addresses total",
659  -1,
660  GNUNET_NO);
661 }
struct GNUNET_STATISTICS_Handle * stats
Statistics handle to be used by the solver.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
char * stat_active
String for statistics active addresses.
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
unsigned int active_addresses
Number of active addresses for solver.
unsigned int active_addresses
Number of active addresses for this network.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_active_address_it()

static int get_active_address_it ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Address map iterator to find current active address for peer.

Asserts that only one address is active per peer.

Parameters
clslast active address
keypeer's key
valueaddress to check
Returns
GNUNET_NO on double active address else GNUNET_YES;

Definition at line 674 of file plugin_ats_proportional.c.

References ATS_Address::active, GNUNET_assert, GNUNET_OK, GNUNET_YES, and value.

Referenced by get_active_address().

677 {
678  struct ATS_Address **dest = cls;
679  struct ATS_Address *aa = value;
680 
681  if (GNUNET_YES != aa->active)
682  return GNUNET_OK;
683  GNUNET_assert(NULL == (*dest));
684  (*dest) = aa;
685  return GNUNET_OK;
686 }
int active
Is this the active address for this peer?
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static char * value
Value of the record to add/remove.
Address with additional information.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the caller graph for this function:

◆ get_active_address()

static struct ATS_Address* get_active_address ( struct GAS_PROPORTIONAL_Handle s,
const struct GNUNET_PeerIdentity peer 
)
static

Find current active address for peer.

Parameters
sthe solver handle
peerthe peer
Returns
active address or NULL

Definition at line 697 of file plugin_ats_proportional.c.

References GNUNET_ATS_PluginEnvironment::addresses, GAS_PROPORTIONAL_Handle::env, get_active_address_it(), and GNUNET_CONTAINER_multipeermap_get_multiple().

Referenced by GAS_proportional_address_add(), GAS_proportional_start_get_address(), and GAS_proportional_stop_get_address().

699 {
700  struct ATS_Address *dest;
701 
702  dest = NULL;
704  peer,
706  &dest);
707  return dest;
708 }
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
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.
Address with additional information.
struct GNUNET_CONTAINER_MultiPeerMap * addresses
Hashmap containing all addresses available.
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_active_address()

static void update_active_address ( struct GAS_PROPORTIONAL_Handle s,
struct ATS_Address current_address,
const struct GNUNET_PeerIdentity peer 
)
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.

Parameters
ssolver handle
current_addressthe address currently active for the peer, NULL for none
peerthe peer to check

Definition at line 722 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, 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().

725 {
726  struct ATS_Address *best_address;
727  struct AddressWrapper *asi_cur;
728  struct AddressWrapper *asi_best;
729  struct AddressWrapper *aw;
730  struct AddressWrapper *aw_min;
731  unsigned int a_con;
732  unsigned int con_min;
733 
734  best_address = get_best_address(s,
735  s->env->addresses,
736  peer);
737  if (NULL != best_address)
738  asi_best = best_address->solver_information;
739  else
740  asi_best = NULL;
741  if (current_address == best_address)
742  return; /* no changes */
743  if (NULL != current_address)
744  {
745  /* We switch to a new address (or to none);
746  mark old address as inactive. */
747  asi_cur = current_address->solver_information;
748  GNUNET_assert(GNUNET_YES == current_address->active);
750  "Disabling previous active address for peer `%s'\n",
751  GNUNET_i2s(peer));
753  current_address->active = GNUNET_NO;
754  current_address->assigned_bw_in = 0;
755  current_address->assigned_bw_out = 0;
757  asi_cur->network);
758  if ((NULL == best_address) ||
759  (asi_best->network != asi_cur->network))
761  asi_cur->network);
762  if (NULL == best_address)
763  {
764  /* We previously had an active address, but now we cannot
765  * suggest one. Therefore we have to disconnect the peer.
766  * The above call to "distribute_bandwidth_in_network()
767  * does not see 'current_address' so we need to trigger
768  * the update here. */
770  "Disconnecting peer `%s'.\n",
771  GNUNET_i2s(peer));
773  current_address);
774  return;
775  }
776  }
777  if (NULL == best_address)
778  {
779  /* We do not have a new address, so we are done. */
781  "Cannot suggest address for peer `%s'\n",
782  GNUNET_i2s(peer));
783  return;
784  }
785  /* We do have a new address, activate it */
787  "Selecting new address %p for peer `%s'\n",
788  best_address,
789  GNUNET_i2s(peer));
790  /* Mark address as active */
791  best_address->active = GNUNET_YES;
792  asi_best->activated = GNUNET_TIME_absolute_get();
793  asi_best->network->active_addresses++;
794  s->active_addresses++;
796  "# ATS active addresses total",
797  1,
798  GNUNET_NO);
800  asi_best->network->stat_active,
801  1,
802  GNUNET_NO);
804  "Address %p for peer `%s' is now active\n",
805  best_address,
806  GNUNET_i2s(peer));
807 
808  if (GNUNET_NO ==
810  0))
811  {
812  /* we went over the maximum number of addresses for
813  this scope; remove the address with the smallest
814  connectivity requirement */
815  con_min = UINT32_MAX;
816  aw_min = NULL;
817  for (aw = asi_best->network->head; NULL != aw; aw = aw->next)
818  {
819  if ((con_min >
820  (a_con = s->env->get_connectivity(s->env->cls,
821  &aw->addr->peer))) &&
822  (GNUNET_YES == aw->addr->active))
823  {
824  aw_min = aw;
825  con_min = a_con;
826  if (0 == con_min)
827  break;
828  }
829  }
831  aw_min->addr,
832  &aw_min->addr->peer);
833  }
835  asi_best->network);
836 }
struct GNUNET_TIME_Absolute activated
When was this address activated.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
struct AddressWrapper * next
Next in DLL.
struct GNUNET_STATISTICS_Handle * stats
Statistics handle to be used by the solver.
int active
Is this the active address for this peer?
struct GNUNET_PeerIdentity peer
Peer ID this address is for.
Address information stored for the proportional solver in the solver_information member of struct GNU...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void address_decrement_active(struct GAS_PROPORTIONAL_Handle *s, struct Network *net)
Decrease number of active addresses in network.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define LOG(kind,...)
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 Network * network
Network scope this address is in.
char * stat_active
String for statistics active addresses.
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.
uint32_t assigned_bw_in
Inbound bandwidth assigned by solver.
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
static void distribute_bandwidth_in_network(struct GAS_PROPORTIONAL_Handle *s, struct Network *n)
Distribute bandwidth.
struct AddressWrapper * head
Linked list of addresses in this network: head.
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...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
Address with additional information.
void * solver_information
Solver-specific information for this address.
unsigned int active_addresses
Number of active addresses for solver.
uint32_t assigned_bw_out
Outbound bandwidth assigned by solver.
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.
void * cls
Closure to pass to all callbacks in this struct.
struct ATS_Address * addr
The address.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_CONTAINER_MultiPeerMap * addresses
Hashmap containing all addresses available.
GAS_bandwidth_changed_cb bandwidth_changed_cb
ATS addresses callback to be notified about bandwidth assignment changes.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
unsigned int active_addresses
Number of active addresses for this network.
GAS_get_connectivity get_connectivity
ATS addresses function to obtain preference values.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_proportional_change_preference()

static void GAS_proportional_change_preference ( void *  solver,
const struct GNUNET_PeerIdentity peer,
enum GNUNET_ATS_PreferenceKind  kind,
double  pref_rel 
)
static

The preferences for a peer in the problem changed.

Parameters
solverthe solver handle
peerthe peer to change the preference for
kindthe kind to change the preference
pref_relthe normalized preference value for this kind over all clients

Definition at line 848 of file plugin_ats_proportional.c.

References distribute_bandwidth_in_network(), and GNUNET_ATS_PREFERENCE_BANDWIDTH.

Referenced by libgnunet_plugin_ats_proportional_init().

852 {
853  struct GAS_PROPORTIONAL_Handle *s = solver;
854 
856  return; /* we do not care */
858  NULL);
859 }
A handle for the proportional solver.
static void distribute_bandwidth_in_network(struct GAS_PROPORTIONAL_Handle *s, struct Network *n)
Distribute bandwidth.
Change the peer&#39;s bandwidth value (value per byte of bandwidth in the goal function) to the given amo...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_proportional_feedback()

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 
)
static

Get application feedback for a peer.

Parameters
solverthe solver handle
applicationthe application
peerthe peer to change the preference for
scopethe time interval for this feedback: [now - scope .. now]
kindthe kind to change the preference
scorethe score

Definition at line 873 of file plugin_ats_proportional.c.

Referenced by libgnunet_plugin_ats_proportional_init().

879 {
880  /* Proportional does not care about feedback */
881 }
Here is the caller graph for this function:

◆ GAS_proportional_start_get_address()

static void GAS_proportional_start_get_address ( void *  solver,
const struct GNUNET_PeerIdentity peer 
)
static

Get the preferred address for a specific peer.

Parameters
solverthe solver handle
peerthe identity of the peer

Definition at line 891 of file plugin_ats_proportional.c.

References get_active_address(), and update_active_address().

Referenced by libgnunet_plugin_ats_proportional_init().

893 {
894  struct GAS_PROPORTIONAL_Handle *s = solver;
895 
898  peer),
899  peer);
900 }
A handle for the proportional solver.
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.
static struct ATS_Address * get_active_address(struct GAS_PROPORTIONAL_Handle *s, const struct GNUNET_PeerIdentity *peer)
Find current active address for peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_proportional_stop_get_address()

static void GAS_proportional_stop_get_address ( void *  solver,
const struct GNUNET_PeerIdentity peer 
)
static

Stop notifying about address and bandwidth changes for this peer.

Parameters
solverthe solver handle
peerthe peer

Definition at line 910 of file plugin_ats_proportional.c.

References distribute_bandwidth_in_network(), get_active_address(), AddressWrapper::network, and ATS_Address::solver_information.

Referenced by libgnunet_plugin_ats_proportional_init().

912 {
913  struct GAS_PROPORTIONAL_Handle *s = solver;
914  struct ATS_Address *cur;
915  struct AddressWrapper *asi;
916 
917  cur = get_active_address(s,
918  peer);
919  if (NULL == cur)
920  return;
921  asi = cur->solver_information;
923  asi->network);
924 }
A handle for the proportional solver.
Address information stored for the proportional solver in the solver_information member of struct GNU...
struct Network * network
Network scope this address is in.
static void distribute_bandwidth_in_network(struct GAS_PROPORTIONAL_Handle *s, struct Network *n)
Distribute bandwidth.
Address with additional information.
void * solver_information
Solver-specific information for this address.
static struct ATS_Address * get_active_address(struct GAS_PROPORTIONAL_Handle *s, const struct GNUNET_PeerIdentity *peer)
Find current active address for peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_proportional_bulk_start()

static void GAS_proportional_bulk_start ( void *  solver)
static

Start a bulk operation.

Parameters
solverthe solver

Definition at line 933 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().

934 {
935  struct GAS_PROPORTIONAL_Handle *s = solver;
936 
938  "Locking solver for bulk operation ...\n");
939  GNUNET_assert(NULL != solver);
940  s->bulk_lock++;
941 }
A handle for the proportional solver.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define LOG(kind,...)
unsigned int bulk_lock
Bulk lock counter.
Here is the caller graph for this function:

◆ GAS_proportional_bulk_stop()

static void GAS_proportional_bulk_stop ( void *  solver)
static

Bulk operation done.

Parameters
solverour struct GAS_PROPORTIONAL_Handle *

Definition at line 950 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().

951 {
952  struct GAS_PROPORTIONAL_Handle *s = solver;
953 
955  "Unlocking solver from bulk operation ...\n");
956  if (s->bulk_lock < 1)
957  {
958  GNUNET_break(0);
959  return;
960  }
961  s->bulk_lock--;
962  if ((0 == s->bulk_lock) &&
963  (0 < s->bulk_requests))
964  {
966  "No lock pending, recalculating\n");
968  NULL);
969  s->bulk_requests = 0;
970  }
971 }
A handle for the proportional solver.
#define LOG(kind,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static void distribute_bandwidth_in_network(struct GAS_PROPORTIONAL_Handle *s, struct Network *n)
Distribute bandwidth.
unsigned int bulk_requests
Number of changes made while solver was locked.
unsigned int bulk_lock
Bulk lock counter.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_proportional_address_property_changed()

static void GAS_proportional_address_property_changed ( void *  solver,
struct ATS_Address address 
)
static

Transport properties for this address have changed.

Parameters
solversolver handle
addressthe address

Definition at line 981 of file plugin_ats_proportional.c.

References distribute_bandwidth_in_network(), AddressWrapper::network, and ATS_Address::solver_information.

Referenced by libgnunet_plugin_ats_proportional_init().

983 {
984  struct GAS_PROPORTIONAL_Handle *s = solver;
985  struct AddressWrapper *asi = address->solver_information;
986 
988  asi->network);
989 }
A handle for the proportional solver.
Address information stored for the proportional solver in the solver_information member of struct GNU...
struct Network * network
Network scope this address is in.
static void distribute_bandwidth_in_network(struct GAS_PROPORTIONAL_Handle *s, struct Network *n)
Distribute bandwidth.
void * solver_information
Solver-specific information for this address.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_proportional_address_add()

static void GAS_proportional_address_add ( void *  solver,
struct ATS_Address address,
uint32_t  network 
)
static

Add a new single address to a network.

Parameters
solverthe solver Handle
addressthe address to add
networknetwork type of this address

Definition at line 1000 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, ATS_Address::peer, ATS_Address::solver_information, Network::stat_total, GNUNET_ATS_PluginEnvironment::stats, Network::tail, Network::total_addresses, and update_active_address().

Referenced by libgnunet_plugin_ats_proportional_init().

1003 {
1004  struct GAS_PROPORTIONAL_Handle *s = solver;
1005  struct Network *net;
1006  struct AddressWrapper *aw;
1007 
1008  GNUNET_assert(network < s->env->network_count);
1009  net = &s->network_entries[network];
1010  net->total_addresses++;
1011 
1012  aw = GNUNET_new(struct AddressWrapper);
1013  aw->addr = address;
1014  aw->network = net;
1015  address->solver_information = aw;
1017  net->tail,
1018  aw);
1020  "# ATS addresses total",
1021  1,
1022  GNUNET_NO);
1024  net->stat_total,
1025  1,
1026  GNUNET_NO);
1029  &address->peer),
1030  &address->peer);
1032  "Added new address for `%s', now total %u and active %u addresses in network `%s'\n",
1033  GNUNET_i2s(&address->peer),
1034  net->total_addresses,
1035  net->active_addresses,
1036  net->desc);
1037 }
unsigned int total_addresses
Number of total addresses for this network.
A handle for the proportional solver.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_STATISTICS_Handle * stats
Statistics handle to be used by the solver.
struct GNUNET_PeerIdentity peer
Peer ID this address is for.
Address information stored for the proportional solver in the solver_information member of struct GNU...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * desc
Network description.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define LOG(kind,...)
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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 Network * network
Network scope this address is in.
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.
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
Representation of a network (to be expanded...)
struct AddressWrapper * head
Linked list of addresses in this network: head.
char * stat_total
String for statistics total addresses.
void * solver_information
Solver-specific information for this address.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct Network * network_entries
Networks array.
static struct ATS_Address * get_active_address(struct GAS_PROPORTIONAL_Handle *s, const struct GNUNET_PeerIdentity *peer)
Find current active address for peer.
struct ATS_Address * addr
The address.
struct AddressWrapper * tail
Linked list of addresses in this network: tail.
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
unsigned int active_addresses
Number of active addresses for this network.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_proportional_address_delete()

static void GAS_proportional_address_delete ( void *  solver,
struct ATS_Address address 
)
static

Remove an address from the solver.

To do so, we:

  • Removed it from specific network
  • Decrease the number of total addresses
  • If active:
    • decrease number of active addreses
    • update quotas
Parameters
solverthe solver handle
addressthe address to remove

Definition at line 1052 of file plugin_ats_proportional.c.

References ATS_Address::active, Network::active_addresses, 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, ATS_Address::peer, ATS_Address::solver_information, Network::stat_total, GNUNET_ATS_PluginEnvironment::stats, Network::tail, Network::total_addresses, and update_active_address().

Referenced by libgnunet_plugin_ats_proportional_init().

1054 {
1055  struct GAS_PROPORTIONAL_Handle *s = solver;
1056  struct AddressWrapper *aw = address->solver_information;
1057  struct Network *net = aw->network;
1058 
1060  "Deleting %s address for peer `%s' from network `%s' (total: %u/active: %u)\n",
1061  (GNUNET_NO == address->active) ? "inactive" : "active",
1062  GNUNET_i2s(&address->peer),
1063  net->desc,
1064  net->total_addresses,
1065  net->active_addresses);
1066 
1068  net->tail,
1069  aw);
1070  GNUNET_assert(net->total_addresses > 0);
1071  net->total_addresses--;
1073  net->stat_total,
1074  -1,
1075  GNUNET_NO);
1076  if (GNUNET_YES == address->active)
1077  {
1078  /* Address was active, remove from network and update quotas */
1080  address,
1081  &address->peer);
1083  }
1084  GNUNET_free(aw);
1085  address->solver_information = NULL;
1087  "After deleting address now total %u and active %u addresses in network `%s'\n",
1088  net->total_addresses,
1089  net->active_addresses,
1090  net->desc);
1091 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
unsigned int total_addresses
Number of total addresses for this network.
A handle for the proportional solver.
struct GNUNET_STATISTICS_Handle * stats
Statistics handle to be used by the solver.
int active
Is this the active address for this peer?
struct GNUNET_PeerIdentity peer
Peer ID this address is for.
Address information stored for the proportional solver in the solver_information member of struct GNU...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * desc
Network description.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define LOG(kind,...)
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 Network * network
Network scope this address is in.
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.
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
static void distribute_bandwidth_in_network(struct GAS_PROPORTIONAL_Handle *s, struct Network *n)
Distribute bandwidth.
Representation of a network (to be expanded...)
struct AddressWrapper * head
Linked list of addresses in this network: head.
char * stat_total
String for statistics total addresses.
void * solver_information
Solver-specific information for this address.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct AddressWrapper * tail
Linked list of addresses in this network: tail.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
unsigned int active_addresses
Number of active addresses for this network.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_ats_proportional_init()

void* libgnunet_plugin_ats_proportional_init ( void *  cls)

Function invoked when the plugin is loaded.

Parameters
[in,out]clsthe struct GNUNET_ATS_PluginEnvironment * to use; modified to return the API functions (ugh).
Returns
the struct GAS_PROPORTIONAL_Handle to pass as a closure

Definition at line 1102 of file plugin_ats_proportional.c.

References _, GNUNET_ATS_PluginEnvironment::cfg, 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, GNUNET_ATS_PluginEnvironment::in_quota, LOG, GNUNET_ATS_PluginEnvironment::network_count, GAS_PROPORTIONAL_Handle::network_entries, GNUNET_ATS_PluginEnvironment::out_quota, 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.

1103 {
1104  static struct GNUNET_ATS_SolverFunctions sf;
1106  struct GAS_PROPORTIONAL_Handle *s;
1107  struct Network * cur;
1108  float f_tmp;
1109  unsigned int c;
1110 
1111  s = GNUNET_new(struct GAS_PROPORTIONAL_Handle);
1112  s->env = env;
1113  sf.cls = s;
1124  if (GNUNET_SYSERR !=
1126  "ats",
1127  "PROP_STABILITY_FACTOR",
1128  &f_tmp))
1129  {
1130  if ((f_tmp < 1.0) || (f_tmp > 2.0))
1131  {
1133  _("Invalid %s configuration %f \n"),
1134  "PROP_STABILITY_FACTOR",
1135  f_tmp);
1136  }
1137  else
1138  {
1139  s->stability_factor = f_tmp;
1141  "Using %s of %.3f\n",
1142  "PROP_STABILITY_FACTOR",
1143  f_tmp);
1144  }
1145  }
1147  if (GNUNET_SYSERR !=
1149  "ats",
1150  "PROP_PROPORTIONALITY_FACTOR",
1151  &f_tmp))
1152  {
1153  if (f_tmp < 1.0)
1154  {
1156  _("Invalid %s configuration %f\n"),
1157  "PROP_PROPORTIONALITY_FACTOR",
1158  f_tmp);
1159  }
1160  else
1161  {
1162  s->prop_factor = f_tmp;
1164  "Using %s of %.3f\n",
1165  "PROP_PROPORTIONALITY_FACTOR",
1166  f_tmp);
1167  }
1168  }
1169 
1171  sizeof(struct Network));
1172  for (c = 0; c < env->network_count; c++)
1173  {
1174  cur = &s->network_entries[c];
1175  cur->type = c;
1176  cur->total_quota_in = env->in_quota[c];
1177  cur->total_quota_out = env->out_quota[c];
1178  cur->desc = GNUNET_NT_to_string(c);
1180  "# ATS addresses %s total",
1181  cur->desc);
1183  "# ATS active addresses %s total",
1184  cur->desc);
1186  "Added network %u `%s' (%llu/%llu)\n",
1187  c,
1188  cur->desc,
1189  cur->total_quota_in,
1190  cur->total_quota_out);
1191  }
1192  return &sf;
1193 }
GAS_solver_stop_get_preferred_address s_get_stop
Tell solver stop notifying ATS about changes for this peers.
A handle for the proportional solver.
GAS_solver_address_add s_add
Add a new address for a peer to the solver.
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
Definition: nt.c:43
unsigned long long total_quota_out
Total outbound quota.
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.
#define PROPORTIONALITY_FACTOR
Default value to assume for the proportionality factor, if none is given in the configuration.
const char * desc
Network description.
static void GAS_proportional_start_get_address(void *solver, const struct GNUNET_PeerIdentity *peer)
Get the preferred address for a specific peer.
GAS_solver_address_feedback_preference s_feedback
Give feedback about the current assignment.
int 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.
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.
GAS_solver_address_property_changed s_address_update_property
Update the properties of an address in the solver.
double prop_factor
Proportionality factor.
#define PROP_STABILITY_FACTOR
How much do we value stability over adaptation by default.
#define LOG(kind,...)
#define GNUNET_new(type)
Allocate a struct or union of the given type.
char * stat_active
String for statistics active addresses.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
GAS_solver_address_delete s_del
Delete an address in the solver.
Representation of a network (to be expanded...)
GAS_solver_address_change_preference s_pref
Change relative preference for quality in solver.
static void GAS_proportional_address_delete(void *solver, struct ATS_Address *address)
Remove an address from the solver.
static void GAS_proportional_address_property_changed(void *solver, struct ATS_Address *address)
Transport properties for this address have changed.
char * stat_total
String for statistics total addresses.
enum GNUNET_NetworkType type
ATS network type.
unsigned long long total_quota_in
Total inbound quota.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void * cls
Closure to pass to all solver functions in this struct.
struct Network * network_entries
Networks array.
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...
unsigned long long in_quota[6]
Array of configured inbound quotas Order according to networks in network array.
GAS_solver_bulk_start s_bulk_start
Start a bulk operation.
static void GAS_proportional_bulk_start(void *solver)
Start a bulk operation.
static void GAS_proportional_bulk_stop(void *solver)
Bulk operation done.
static void GAS_proportional_address_add(void *solver, struct ATS_Address *address, uint32_t network)
Add a new single address to a network.
static void GAS_proportional_stop_get_address(void *solver, const struct GNUNET_PeerIdentity *peer)
Stop notifying about address and bandwidth changes for this peer.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle to be used by the solver.
unsigned long long out_quota[6]
Array of configured outbound quotas Order according to networks in network array. ...
void * cls
Closure to pass to all callbacks in this struct.
static struct GNUNET_ATS_SolverFunctions * sf
Solver handle.
The ATS plugin will pass a pointer to a struct of this type as to the initialization function of the ...
GAS_solver_bulk_stop s_bulk_stop
Bulk operation done.
unsigned int network_count
Number of networks available, size of the out_quota and in_quota arrays.
double stability_factor
Stability factor.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:

◆ libgnunet_plugin_ats_proportional_done()

void* libgnunet_plugin_ats_proportional_done ( void *  cls)

Function used to unload the plugin.

Parameters
clsreturn value from libgnunet_plugin_ats_proportional_init()

Definition at line 1202 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, GNUNET_free_non_null, 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.

1203 {
1204  struct GNUNET_ATS_SolverFunctions *sf = cls;
1205  struct GAS_PROPORTIONAL_Handle *s = sf->cls;
1206  struct AddressWrapper *cur;
1207  struct AddressWrapper *next;
1208  unsigned int c;
1209 
1210  for (c = 0; c < s->env->network_count; c++)
1211  {
1214  next = s->network_entries[c].head;
1215  while (NULL != (cur = next))
1216  {
1217  next = cur->next;
1219  s->network_entries[c].tail,
1220  cur);
1222  GNUNET_free(cur);
1223  }
1226  }
1227  GNUNET_break(0 == s->active_addresses);
1229  GNUNET_free(s);
1230  return NULL;
1231 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
unsigned int total_addresses
Number of total addresses for this network.
A handle for the proportional solver.
struct AddressWrapper * next
Next in DLL.
Address information stored for the proportional solver in the solver_information member of struct GNU...
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
char * stat_active
String for statistics active addresses.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_ATS_PluginEnvironment * env
Our execution environment.
struct AddressWrapper * head
Linked list of addresses in this network: head.
char * stat_total
String for statistics total addresses.
void * solver_information
Solver-specific information for this address.
void * cls
Closure to pass to all solver functions in this struct.
unsigned int active_addresses
Number of active addresses for solver.
struct Network * network_entries
Networks array.
struct ATS_Address * addr
The address.
struct AddressWrapper * tail
Linked list of addresses in this network: tail.
static struct GNUNET_ATS_SolverFunctions * sf
Solver handle.
unsigned int active_addresses
Number of active addresses for this network.
unsigned int network_count
Number of networks available, size of the out_quota and in_quota arrays.
#define GNUNET_free(ptr)
Wrapper around free.