2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file ats/plugin_ats_proportional.c
23 * @brief ATS proportional solver
24 * @author Matthias Wachs
25 * @author Christian Grothoff
27 #include "plugin_ats_proportional.h"
29 #define LOG(kind,...) GNUNET_log_from (kind, "ats-proportional",__VA_ARGS__)
34 * NOTE: Do not change this documentation. This documentation is based
35 * on gnunet.org:/vcs/fsnsg/ats-paper.git/tech-doku/ats-tech-guide.tex
36 * use build_txt.sh to generate plaintext output
38 * ATS addresses : proportional solver
40 * The proportional solver ("proportional") distributes the available
41 * bandwidth fair over all the addresses influenced by the
42 * preference values. For each available network type an in- and
43 * outbound quota is configured and the bandwidth available in
44 * these networks is distributed over the addresses. The solver
45 * first assigns every addresses the minimum amount of bandwidth
46 * GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT and then distributes the
47 * remaining bandwidth available according to the preference
48 * values. For each peer only a single address gets bandwidth
49 * assigned and only one address marked as active. The most
50 * important functionality for the solver is implemented in: *
51 * find_address_it is an hashmap iterator returning the prefered
52 * address for an peer * update_quota_per_network distributes
53 * available bandwidth for a network over active addresses
55 * Changes to addresses automatically have an impact on the the
56 * bandwidth assigned to other addresses in the same network since
57 * the solver distributes the remaining bandwidth over the
58 * addresses in the network. When changes to the addresses occur,
59 * the solver first performs the changes, like adding or deleting
60 * addresses, and then updates bandwidth assignment for the
61 * affected network. Bandwidth assignment is only recalculated on
62 * demand when an address is requested by a client for a peer or
63 * when the addresses available have changed or an address changed
64 * the network it is located in. When the bandwidth assignment has
65 * changed the callback is called with the new bandwidth
66 * assignments. The bandwidth distribution for a network is
67 * recalculated due to: * address suggestion requests * address
68 * deletions * address switching networks during address update *
71 * 3.1 Data structures used
73 * For each ATS network (e.g. WAN, LAN, loopback) a struct Network
74 * is used to specify network related information as total adresses
75 * and active addresses in this network and the configured in- and
76 * outbound quota. Each network also contains a list of addresses
77 * added to the solver located in this network. The proportional
78 * solver uses the addresses' solver_information field to store the
79 * proportional network it belongs to for each address.
83 * When the proportional solver is initialized the solver creates a
84 * new solver handle and initializes the network structures with
85 * the quotas passed from addresses and returns the handle solver.
87 * 3.3 Adding an address
89 * When a new address is added to the solver using s_add, a lookup
90 * for the network for this address is done and the address is
91 * enqueued in in the linked list of the network.
93 * 3.4 Updating an address
95 * The main purpose of address updates is to update the ATS
96 * information for addresse selection. Important for the proportional
97 * solver is when an address switches network it is located
98 * in. This is common because addresses added by transport's
99 * validation mechanism are commonly located in
100 * GNUNET_ATS_NET_UNSPECIFIED. Addresses in validation are located
101 * in this network type and only if a connection is successful on
102 * return of payload data transport switches to the real network
103 * the address is located in. When an address changes networks it
104 * is first of all removed from the old network using the solver
105 * API function GAS_proportional_address_delete and the network in
106 * the address struct is updated. A lookup for the respective new
107 * proportional network is done and stored in the addresse's
108 * solver_information field. Next the address is re-added to the
109 * solver using the solver API function
110 * GAS_proportional_address_add. If the address was marked as in
111 * active, the solver checks if bandwidth is available in the
112 * network and if yes sets the address to active and updates the
113 * bandwidth distribution in this network. If no bandwidth is
114 * available it sets the bandwidth for this address to 0 and tries
115 * to suggest an alternative address. If an alternative address was
116 * found, addresses' callback is called for this address.
118 * 3.5 Deleting an address
120 * When an address is removed from the solver, it removes the
121 * respective address from the network and if the address was
122 * marked as active, it updates the bandwidth distribution for this
125 * 3.6 Requesting addresses
127 * When an address is requested for a peer the solver performs a
128 * lookup for the peer entry in addresses address hashmap and
129 * selects the best address. The selection of the most suitable
130 * address is done in the find_address_it hashmap iterator
131 * described in detail in section 3.7. If no address is returned,
132 * no address can be suggested at the moment. If the address
133 * returned is marked as active, the solver can return this
134 * address. If the address is not marked as active, the solver
135 * checks if another address belongign to this peer is marked as
136 * active and marks the address as inactive, updates the bandwidth
137 * for this address to 0, call the bandwidth changed callback for
138 * this address due to the change and updates quota assignment for
139 * the addresse's network. the now in-active address is belonging
140 * to. The solver marks the new address as active and updates the
141 * bandwidth assignment for this network.
143 * 3.7 Choosing addresses
145 * Choosing the best possible address for suggestion is done by
146 * iterating over all addresses of a peer stored in addresses'
147 * hashmap and using the hashmap iterator find_address_it to select
148 * the best available address. Several checks are done when an
149 * address is selected. First if this address is currently blocked
150 * by addresses from being suggested. An address is blocked for the
151 * duration of ATS_BLOCKING_DELTA when it is suggested to
152 * transport. Next it is checked if at least
153 * GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT bytes bandwidth is available
154 * in the addresse's network, because suggesting an address without
155 * bandwidth does not make sense. This also ensures that all active
156 * addresses in this network get at least the minimum amount of
157 * bandwidth assigned. In the next step the solver ensures that for
158 * tcp connections inbound connections are prefered over outbound
159 * connections. In the next stet the solver ensures that
160 * connections are prefered in the following order: * connections
161 * are already established and have bandwidth assigned *
162 * connections with a shorter distance * connectes have a shorter
165 * 3.8 Changing preferences
169 * During shutdown all network entries and aging processes are
170 * destroyed and freed.
175 * This solver assigns in and outbound bandwidth equally for all
176 * addresses in specific network type (WAN, LAN) based on configured
177 * in and outbound quota for this network.
179 * The solver is notified by addresses about changes to the addresses
180 * and recalculates the bandwith assigned if required. The solver
181 * notifies addresses by calling the GAS_bandwidth_changed_cb
189 * For each peer only a single is selected and marked as "active" in the address
194 * You have the networks WAN and LAN and quotas
195 * WAN_TOTAL_IN, WAN_TOTAL_OUT
196 * LAN_TOTAL_IN, LAN_TOTAL_OUT
198 * If you have x addresses in the network segment LAN, the quotas are
199 * QUOTA_PER_ADDRESS = LAN_TOTAL_OUT / x
201 * Quotas are automatically recalculated and reported back when addresses are
206 #define PROPORTIONALITY_FACTOR 2.0
209 * A handle for the proportional solver
211 struct GAS_PROPORTIONAL_Handle
213 struct GNUNET_ATS_PluginEnvironment *env;
218 struct GNUNET_STATISTICS_Handle *stats;
221 * Hashmap containing all valid addresses
223 const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
226 * Pending address requests
228 struct GNUNET_CONTAINER_MultiPeerMap *requests;
231 * Bandwidth changed callback
233 GAS_bandwidth_changed_cb bw_changed;
236 * Bandwidth changed callback cls
238 void *bw_changed_cls;
241 * ATS function to get preferences
243 GAS_get_preferences get_preferences;
246 * Closure for ATS function to get preferences
248 void *get_preferences_cls;
251 * ATS function to get properties
253 GAS_get_properties get_properties;
256 * Closure for ATS function to get properties
258 void *get_properties_cls;
266 * Number of changes while solver was locked
271 * Total number of addresses for solver
273 unsigned int total_addresses;
276 * Number of active addresses for solver
278 unsigned int active_addresses;
283 struct Network *network_entries;
288 unsigned int network_count;
291 * Proportionality factor
297 * Representation of a network
307 * Network description
312 * Total inbound quota
315 unsigned long long total_quota_in;
318 * Total outbound quota
321 unsigned long long total_quota_out;
324 * Number of active addresses for this network
326 unsigned int active_addresses;
329 * Number of total addresses for this network
331 unsigned int total_addresses;
334 * String for statistics total addresses
339 * String for statistics active addresses
343 struct AddressWrapper *head;
344 struct AddressWrapper *tail;
348 * Address information stored in the solver
350 struct AddressSolverInformation
352 struct Network *network;
358 unsigned long long calculated_quota_in_NBO;
364 unsigned long long calculated_quota_out_NBO;
370 * Wrapper for addresses to store them in network's linked list
372 struct AddressWrapper
377 struct AddressWrapper *next;
382 struct AddressWrapper *prev;
387 struct ATS_Address *addr;
391 * Important solver functions
392 * ---------------------------
396 libgnunet_plugin_ats_proportional_init (void *cls)
398 struct GNUNET_ATS_PluginEnvironment *env = cls;
399 struct GAS_PROPORTIONAL_Handle *s;
400 struct Network * cur;
401 char * net_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
402 unsigned long long prop_factor;
405 GNUNET_assert (NULL != env);
406 GNUNET_assert(NULL != env->cfg);
407 GNUNET_assert(NULL != env->bandwidth_changed_cb);
408 GNUNET_assert(NULL != env->get_preferences);
409 GNUNET_assert(NULL != env->get_property);
411 s = GNUNET_new (struct GAS_PROPORTIONAL_Handle);
413 env->sf.s_add = &GAS_proportional_address_add;
414 env->sf.s_address_update_property = &GAS_proportional_address_property_changed;
415 env->sf.s_address_update_session = &GAS_proportional_address_session_changed;
416 env->sf.s_address_update_inuse = &GAS_proportional_address_inuse_changed;
417 env->sf.s_address_update_network = &GAS_proportional_address_change_network;
418 env->sf.s_get = &GAS_proportional_get_preferred_address;
419 env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address;
420 env->sf.s_pref = &GAS_proportional_address_change_preference;
421 env->sf.s_feedback = &GAS_proportional_address_preference_feedback;
422 env->sf.s_del = &GAS_proportional_address_delete;
423 env->sf.s_bulk_start = &GAS_proportional_bulk_start;
424 env->sf.s_bulk_stop = &GAS_proportional_bulk_stop;
426 s->stats = (struct GNUNET_STATISTICS_Handle *) env->stats;
427 s->bw_changed = env->bandwidth_changed_cb;
428 s->bw_changed_cls = env->bw_changed_cb_cls;
429 s->get_preferences = env->get_preferences;
430 s->get_preferences_cls = env->get_preference_cls;
431 s->get_properties = env->get_property;
432 s->get_properties_cls = env->get_property_cls;
433 s->network_count = env->network_count;
434 s->network_entries = GNUNET_malloc (env->network_count * sizeof (struct Network));
437 s->active_addresses = 0;
438 s->total_addresses = 0;
439 s->bulk_lock = GNUNET_NO;
440 s->addresses = env->addresses;
441 s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
443 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number(s->env->cfg, "ats",
444 "PROP_PROPORTIONALITY_FACTOR", &prop_factor))
447 s->prop_factor = (double) prop_factor;
451 s->prop_factor = PROPORTIONALITY_FACTOR;
455 s->prop_factor = PROPORTIONALITY_FACTOR;
456 LOG (GNUNET_ERROR_TYPE_ERROR, "Using proportionality factor %.0f\n",
460 for (c = 0; c < env->network_count; c++)
462 cur = &s->network_entries[c];
463 cur->total_addresses = 0;
464 cur->active_addresses = 0;
465 cur->type = env->networks[c];
466 cur->total_quota_in = env->in_quota[c];
467 cur->total_quota_out = env->out_quota[c];
468 cur->desc = net_str[c];
469 GNUNET_asprintf (&cur->stat_total,
470 "# ATS addresses %s total", cur->desc);
471 GNUNET_asprintf (&cur->stat_active,
472 "# ATS active addresses %s total", cur->desc);
473 LOG (GNUNET_ERROR_TYPE_INFO, "Added network %u `%s' (%llu/%llu)\n",
474 c, cur->desc, cur->total_quota_in, cur->total_quota_out);
480 libgnunet_plugin_ats_proportional_done (void *cls)
482 struct GAS_PROPORTIONAL_Handle *s = cls;
483 struct AddressWrapper *cur;
484 struct AddressWrapper *next;
486 GNUNET_assert(s != NULL);
487 for (c = 0; c < s->network_count; c++)
489 if (s->network_entries[c].total_addresses > 0)
491 LOG(GNUNET_ERROR_TYPE_DEBUG,
492 "Had %u addresses for network `%s' not deleted during shutdown\n",
493 s->network_entries[c].total_addresses, s->network_entries[c].desc);
497 if (s->network_entries[c].active_addresses > 0)
499 LOG(GNUNET_ERROR_TYPE_DEBUG,
500 "Had %u active addresses for network `%s' not deleted during shutdown\n",
501 s->network_entries[c].active_addresses, s->network_entries[c].desc);
505 next = s->network_entries[c].head;
506 while (NULL != (cur = next))
509 GNUNET_CONTAINER_DLL_remove(s->network_entries[c].head,
510 s->network_entries[c].tail, cur);
511 GNUNET_free_non_null (cur->addr->solver_information);
514 GNUNET_free(s->network_entries[c].stat_total);
515 GNUNET_free(s->network_entries[c].stat_active);
517 if (s->total_addresses > 0)
519 LOG(GNUNET_ERROR_TYPE_DEBUG,
520 "Had %u addresses not deleted during shutdown\n", s->total_addresses);
523 if (s->active_addresses > 0)
525 LOG(GNUNET_ERROR_TYPE_DEBUG,
526 "Had %u active addresses not deleted during shutdown\n",
527 s->active_addresses);
530 GNUNET_free (s->network_entries);
531 GNUNET_CONTAINER_multipeermap_destroy (s->requests);
538 * Test if bandwidth is available in this network to add an additional address
540 * @param net the network type to update
541 * @return GNUNET_YES or GNUNET_NO
544 is_bandwidth_available_in_network (struct Network *net)
546 GNUNET_assert(NULL != net);
547 unsigned int na = net->active_addresses + 1;
548 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
549 if (((net->total_quota_in / na) > min_bw)
550 && ((net->total_quota_out / na) > min_bw))
552 LOG(GNUNET_ERROR_TYPE_DEBUG,
553 "Enough bandwidth available for %u active addresses in network `%s'\n",
558 LOG(GNUNET_ERROR_TYPE_DEBUG,
559 "Not enough bandwidth available for %u active addresses in network `%s'\n",
565 * Update bandwidth assigned to peers in this network
567 * @param s the solver handle
568 * @param net the network type to update
569 * @param address_except address excluded from notification, since we suggest
573 distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
574 struct Network *net, struct ATS_Address *address_except)
576 struct AddressSolverInformation *asi;
577 struct AddressWrapper *cur_address;
579 unsigned long long remaining_quota_in = 0;
580 unsigned long long quota_out_used = 0;
581 unsigned long long remaining_quota_out = 0;
582 unsigned long long quota_in_used = 0;
584 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
585 double relative_peer_prefence;
586 double sum_relative_peer_prefences; /* Important: has to be double not float due to precision */
587 double cur_pref; /* Important: has to be double not float due to precision */
590 const double *peer_relative_prefs = NULL; /* Important: has to be double not float due to precision */
592 unsigned long long assigned_quota_in = 0;
593 unsigned long long assigned_quota_out = 0;
596 LOG(GNUNET_ERROR_TYPE_INFO,
597 "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n",
598 net->desc, net->active_addresses, net->total_quota_in,
599 net->total_quota_in);
601 if (net->active_addresses == 0)
603 return; /* no addresses to update */
607 * Assign every peer in network minimum Bandwidth
608 * Distribute bandwidth left according to preference
611 if ((net->active_addresses * min_bw) > net->total_quota_in)
616 if ((net->active_addresses * min_bw) > net->total_quota_out)
622 remaining_quota_in = net->total_quota_in - (net->active_addresses * min_bw);
623 remaining_quota_out = net->total_quota_out - (net->active_addresses * min_bw);
624 LOG(GNUNET_ERROR_TYPE_DEBUG, "Remaining bandwidth : (in/out): %llu/%llu \n",
625 remaining_quota_in, remaining_quota_out);
626 sum_relative_peer_prefences = 0.0;
628 /* Calculate sum of relative preference for active addresses in this network */
630 for (cur_address = net->head; NULL != cur_address; cur_address = cur_address->next)
632 if (GNUNET_YES != cur_address->addr->active)
635 GNUNET_assert( NULL != (peer_relative_prefs = s->get_preferences (s->get_preferences_cls,
636 &cur_address->addr->peer)));
637 relative_peer_prefence = 0.0;
638 relative_peer_prefence += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
639 sum_relative_peer_prefences += relative_peer_prefence;
643 GNUNET_assert (count_addresses == net->active_addresses);
645 LOG (GNUNET_ERROR_TYPE_INFO,
646 "Total relative preference %.3f for %u addresses in network %s\n",
647 sum_relative_peer_prefences, net->active_addresses, net->desc);
649 for (cur_address = net->head; NULL != cur_address; cur_address = cur_address->next)
651 if (GNUNET_YES == cur_address->addr->active)
653 GNUNET_assert( NULL != (peer_relative_prefs =
654 s->get_preferences (s->get_preferences_cls, &cur_address->addr->peer)));
656 cur_pref = peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
657 total_weight = net->active_addresses +
658 s->prop_factor * sum_relative_peer_prefences;
659 peer_weight = (1.0 + (s->prop_factor * cur_pref));
661 assigned_quota_in = min_bw
662 + ((peer_weight / total_weight) * remaining_quota_in);
663 assigned_quota_out = min_bw
664 + ((peer_weight / total_weight) * remaining_quota_out);
666 LOG (GNUNET_ERROR_TYPE_INFO,
667 "New quota for peer `%s' with weight (cur/total) %.3f/%.3f (in/out): %llu / %llu\n",
668 GNUNET_i2s (&cur_address->addr->peer), peer_weight, total_weight,
669 assigned_quota_in, assigned_quota_out);
673 assigned_quota_in = 0;
674 assigned_quota_out = 0;
677 quota_in_used += assigned_quota_in;
678 quota_out_used += assigned_quota_out;
679 /* Prevent overflow due to rounding errors */
680 if (assigned_quota_in > UINT32_MAX)
681 assigned_quota_in = UINT32_MAX;
682 if (assigned_quota_out > UINT32_MAX)
683 assigned_quota_out = UINT32_MAX;
685 /* Compare to current bandwidth assigned */
686 asi = cur_address->addr->solver_information;
687 asi->calculated_quota_in_NBO = htonl (assigned_quota_in);
688 asi->calculated_quota_out_NBO = htonl (assigned_quota_out);
690 LOG(GNUNET_ERROR_TYPE_DEBUG,
691 "Total bandwidth assigned is (in/out): %llu /%llu\n", quota_in_used,
693 if (quota_out_used > net->total_quota_out + 1) /* +1 is required due to rounding errors */
695 LOG(GNUNET_ERROR_TYPE_ERROR,
696 "Total outbound bandwidth assigned is larger than allowed (used/allowed) for %u active addresses: %llu / %llu\n",
697 net->active_addresses, quota_out_used, net->total_quota_out);
699 if (quota_in_used > net->total_quota_in + 1) /* +1 is required due to rounding errors */
701 LOG(GNUNET_ERROR_TYPE_ERROR,
702 "Total inbound bandwidth assigned is larger than allowed (used/allowed) for %u active addresses: %llu / %llu\n",
703 net->active_addresses, quota_in_used, net->total_quota_in);
707 struct FindBestAddressCtx
709 struct GAS_PROPORTIONAL_Handle *s;
710 struct ATS_Address *best;
714 find_property_index (uint32_t type)
716 int existing_types[] = GNUNET_ATS_QualityProperties;
718 for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
719 if (existing_types[c] == type)
721 return GNUNET_SYSERR;
725 * Find a "good" address to use for a peer by iterating over the addresses for this peer.
726 * If we already have an existing address, we stick to it.
727 * Otherwise, we pick by lowest distance and then by lowest latency.
729 * @param cls the 'struct ATS_Address**' where we store the result
731 * @param value another 'struct ATS_Address*' to consider using
732 * @return GNUNET_OK (continue to iterate)
735 find_best_address_it (void *cls,
736 const struct GNUNET_PeerIdentity *key,
739 struct FindBestAddressCtx *ctx = (struct FindBestAddressCtx *) cls;
740 struct ATS_Address *current = (struct ATS_Address *) value;
741 struct ATS_Address *current_best = (struct ATS_Address *) value;
742 struct GNUNET_TIME_Absolute now;
743 struct AddressSolverInformation *asi;
744 const double *norm_prop_cur;
745 const double *norm_prop_best;
749 asi = current->solver_information;
750 now = GNUNET_TIME_absolute_get ();
752 if (current->blocked_until.abs_value_us
753 == GNUNET_TIME_absolute_max (now, current->blocked_until).abs_value_us)
755 /* This address is blocked for suggestion */
756 LOG(GNUNET_ERROR_TYPE_DEBUG, "Address %p blocked for suggestion for %s \n",
758 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (now, current->blocked_until), GNUNET_YES));
767 if (GNUNET_NO == is_bandwidth_available_in_network (asi->network))
768 return GNUNET_OK; /* There's no bandwidth available in this network */
770 if (NULL != ctx->best)
772 /* Compare current addresses with denominated 'best' address */
774 current_best = ctx->best;
775 if ((0 != ctx->best->addr_len) && (0 == current->addr_len))
777 /* saved address was an outbound address, but we have an inbound address */
778 current_best = current;
781 if (ctx->best->t_last_activity.abs_value_us < current->t_last_activity.abs_value_us)
783 /* Current address is newer */
784 current_best = current;
786 if (ctx->best->t_added.abs_value_us < current->t_added.abs_value_us)
788 /* Current address is newer */
789 current_best = current;
793 if (NULL == ctx->best)
795 /* We do not have a 'best' address so take this address */
796 current_best = current;
800 if ( (ntohl (ctx->best->assigned_bw_in.value__) == 0) &&
801 (ntohl (current->assigned_bw_in.value__) > 0) )
803 /* stick to existing connection */
804 current_best = current;
807 /* Now compare ATS information */
808 norm_prop_cur = ctx->s->get_properties (ctx->s->get_properties_cls,
809 (const struct ATS_Address *) current);
810 norm_prop_best = ctx->s->get_properties (ctx->s->get_properties_cls,
811 (const struct ATS_Address *) ctx->best);
813 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
814 if (GNUNET_SYSERR != index)
816 /* user shorter distance */
817 if (norm_prop_cur[index] < norm_prop_best[index])
818 current_best = current;
820 current_best = ctx->best;
823 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
824 if (GNUNET_SYSERR != index)
826 /* User connection with less delay */
827 if (norm_prop_cur[index] < norm_prop_best[index])
828 current_best = current;
830 current_best = ctx->best;
833 ctx->best = current_best;
839 * ---------------------------
842 propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
843 struct Network *net, struct ATS_Address *address_except)
845 struct AddressWrapper *cur;
846 struct AddressSolverInformation *asi;
847 for (cur = net->head; NULL != cur; cur = cur->next)
849 asi = cur->addr->solver_information;
850 if ( (cur->addr->assigned_bw_in.value__ != asi->calculated_quota_in_NBO) ||
851 (cur->addr->assigned_bw_out.value__ != asi->calculated_quota_out_NBO) )
853 cur->addr->assigned_bw_in.value__ = asi->calculated_quota_in_NBO;
854 cur->addr->assigned_bw_out.value__ = asi->calculated_quota_out_NBO;
856 /* Reset for next iteration */
857 asi->calculated_quota_in_NBO = htonl (0);
858 asi->calculated_quota_out_NBO = htonl (0);
860 LOG (GNUNET_ERROR_TYPE_DEBUG,
861 "Bandwidth for %s address %p for peer `%s' changed to %u/%u\n",
862 (GNUNET_NO == cur->addr->active) ? "inactive" : "active",
864 GNUNET_i2s (&cur->addr->peer),
865 ntohl (cur->addr->assigned_bw_in.value__),
866 ntohl (cur->addr->assigned_bw_out.value__ ));
868 /* Notify on change */
869 if ((GNUNET_YES == cur->addr->active) && (cur->addr != address_except))
870 s->bw_changed (s->bw_changed_cls, cur->addr);
876 * Distribibute bandwidth
878 * @param s the solver handle
879 * @param n the network, can be NULL for all network
880 * @param address_except do not notify for this address
883 distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
884 struct Network *n, struct ATS_Address *address_except)
886 if (GNUNET_YES == s->bulk_lock)
894 LOG (GNUNET_ERROR_TYPE_INFO,
895 "Redistributing bandwidth in network %s with %u active and %u total addresses\n",
896 GNUNET_ATS_print_network_type(n->type),
897 n->active_addresses, n->total_addresses);
899 if (NULL != s->env->info_cb)
900 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START,
901 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
902 distribute_bandwidth(s, n, address_except);
903 if (NULL != s->env->info_cb)
904 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP,
905 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
906 if (NULL != s->env->info_cb)
907 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
908 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
909 propagate_bandwidth(s, n, address_except);
910 if (NULL != s->env->info_cb)
911 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
912 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
917 if (NULL != s->env->info_cb)
918 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START,
919 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
920 for (i = 0; i < s->network_count; i++)
921 distribute_bandwidth(s, &s->network_entries[i], NULL);
922 if (NULL != s->env->info_cb)
923 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP,
924 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
925 if (NULL != s->env->info_cb)
926 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
927 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
928 for (i = 0; i < s->network_count; i++)
930 propagate_bandwidth(s, &s->network_entries[i], address_except);
932 if (NULL != s->env->info_cb)
933 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
934 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
939 * Lookup network struct by type
941 * @param s the solver handle
942 * @param type the network type
943 * @return the network struct
945 static struct Network *
946 get_network (struct GAS_PROPORTIONAL_Handle *s, uint32_t type)
949 for (c = 0; c < s->network_count; c++)
951 if (s->network_entries[c].type == type)
952 return &s->network_entries[c];
958 * Hashmap Iterator to find current active address for peer
960 * @param cls last active address
961 * @param key peer's key
962 * @param value address to check
963 * @return #GNUNET_NO on double active address else #GNUNET_YES;
966 get_active_address_it (void *cls,
967 const struct GNUNET_PeerIdentity *key,
970 struct ATS_Address **dest = cls;
971 struct ATS_Address *aa = (struct ATS_Address *) value;
973 if (GNUNET_YES == aa->active)
978 /* should never happen */
979 LOG(GNUNET_ERROR_TYPE_ERROR, "Multiple active addresses for peer `%s'\n",
980 GNUNET_i2s (&aa->peer));
990 * Find current active address for peer
992 * @param solver the solver handle
993 * @param addresses the address set
994 * @param peer the peer
995 * @return active address or NULL
997 static struct ATS_Address *
998 get_active_address (void *solver,
999 const struct GNUNET_CONTAINER_MultiPeerMap * addresses,
1000 const struct GNUNET_PeerIdentity *peer)
1002 struct ATS_Address * dest = NULL;
1004 GNUNET_CONTAINER_multipeermap_get_multiple (addresses, peer,
1005 &get_active_address_it, &dest);
1011 addresse_increment (struct GAS_PROPORTIONAL_Handle *s, struct Network *net,
1012 int total, int active)
1014 if (GNUNET_YES == total)
1016 s->total_addresses++;
1017 net->total_addresses++;
1018 GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", 1, GNUNET_NO);
1019 GNUNET_STATISTICS_update (s->stats, net->stat_total, 1, GNUNET_NO);
1021 if (GNUNET_YES == active)
1023 net->active_addresses++;
1024 s->active_addresses++;
1025 GNUNET_STATISTICS_update (s->stats, "# ATS active addresses total", 1,
1027 GNUNET_STATISTICS_update (s->stats, net->stat_active, 1, GNUNET_NO);
1034 addresse_decrement (struct GAS_PROPORTIONAL_Handle *s, struct Network *net,
1035 int total, int active)
1037 int res = GNUNET_OK;
1038 if (GNUNET_YES == total)
1040 if (s->total_addresses < 1)
1043 res = GNUNET_SYSERR;
1047 s->total_addresses--;
1048 GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", -1,
1051 if (net->total_addresses < 1)
1054 res = GNUNET_SYSERR;
1058 net->total_addresses--;
1059 GNUNET_STATISTICS_update (s->stats, net->stat_total, -1, GNUNET_NO);
1063 if (GNUNET_YES == active)
1065 if (net->active_addresses < 1)
1068 res = GNUNET_SYSERR;
1072 net->active_addresses--;
1073 GNUNET_STATISTICS_update (s->stats, net->stat_active, -1, GNUNET_NO);
1075 if (s->active_addresses < 1)
1078 res = GNUNET_SYSERR;
1082 s->active_addresses--;
1083 GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", -1,
1091 * Solver API functions
1092 * ---------------------------
1096 * Changes the preferences for a peer in the problem
1098 * @param solver the solver handle
1099 * @param peer the peer to change the preference for
1100 * @param kind the kind to change the preference
1101 * @param pref_rel the normalized preference value for this kind over all clients
1104 GAS_proportional_address_change_preference (void *solver,
1105 const struct GNUNET_PeerIdentity *peer,
1106 enum GNUNET_ATS_PreferenceKind kind,
1109 struct GAS_PROPORTIONAL_Handle *s = solver;
1110 GNUNET_assert(NULL != solver);
1111 GNUNET_assert(NULL != peer);
1113 distribute_bandwidth_in_network (s, NULL, NULL);
1118 * Get application feedback for a peer
1120 * @param solver the solver handle
1121 * @param application the application
1122 * @param peer the peer to change the preference for
1123 * @param scope the time interval for this feedback: [now - scope .. now]
1124 * @param kind the kind to change the preference
1125 * @param score the score
1128 GAS_proportional_address_preference_feedback (void *solver, void *application,
1129 const struct GNUNET_PeerIdentity *peer,
1130 const struct GNUNET_TIME_Relative scope,
1131 enum GNUNET_ATS_PreferenceKind kind, double score)
1133 struct GAS_PROPORTIONAL_Handle *s = solver;
1134 GNUNET_assert(NULL != solver);
1135 GNUNET_assert(NULL != peer);
1137 GNUNET_assert(NULL != s);
1142 * Get the preferred address for a specific peer
1144 * @param solver the solver handle
1145 * @param peer the identity of the peer
1147 const struct ATS_Address *
1148 GAS_proportional_get_preferred_address (void *solver,
1149 const struct GNUNET_PeerIdentity *peer)
1151 struct GAS_PROPORTIONAL_Handle *s = solver;
1152 struct Network *net_prev;
1153 struct Network *net_cur;
1154 struct ATS_Address *prev;
1155 struct FindBestAddressCtx fba_ctx;
1156 struct AddressSolverInformation *asi;
1157 struct AddressSolverInformation *asi_prev;
1159 GNUNET_assert(s != NULL);
1160 GNUNET_assert(peer != NULL);
1162 /* Add to list of pending requests */
1163 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, peer))
1166 GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (s->requests, peer, NULL,
1167 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1170 /* Get address with: stick to current address, lower distance, lower latency */
1172 fba_ctx.best = NULL;
1174 GNUNET_CONTAINER_multipeermap_get_multiple (s->addresses, peer,
1175 &find_best_address_it, &fba_ctx);
1176 if (NULL == fba_ctx.best)
1178 LOG(GNUNET_ERROR_TYPE_INFO, "Cannot suggest address for peer `%s'\n",
1183 LOG(GNUNET_ERROR_TYPE_INFO, "Suggesting %s address %p for peer `%s'\n",
1184 (GNUNET_NO == fba_ctx.best->active) ? "inactive" : "active", fba_ctx.best,
1186 asi = fba_ctx.best->solver_information;
1187 net_cur = asi->network ;
1188 if (NULL == fba_ctx.best)
1190 LOG(GNUNET_ERROR_TYPE_ERROR,
1191 "Trying to suggesting unknown address peer `%s'\n", GNUNET_i2s (peer));
1195 if (GNUNET_YES == fba_ctx.best->active)
1197 /* This address was selected previously, so no need to update quotas */
1198 return fba_ctx.best;
1201 /* This address was not active, so we have to:
1203 * - mark previous active address as not active
1204 * - update quota for previous address network
1205 * - update quota for this address network
1207 prev = get_active_address (s, s->addresses, peer);
1210 asi_prev = prev->solver_information;
1211 net_prev = (struct Network *) asi_prev->network;
1212 prev->active = GNUNET_NO; /* No active any longer */
1213 prev->assigned_bw_in = BANDWIDTH_ZERO; /* no bandwidth assigned */
1214 prev->assigned_bw_out = BANDWIDTH_ZERO; /* no bandwidth assigned */
1216 if (GNUNET_SYSERR == addresse_decrement (s, net_prev, GNUNET_NO, GNUNET_YES))
1218 distribute_bandwidth_in_network (s, net_prev, NULL);
1221 if (GNUNET_NO == (is_bandwidth_available_in_network (net_cur)))
1223 GNUNET_break(0); /* This should never happen*/
1227 fba_ctx.best->active = GNUNET_YES;
1228 addresse_increment (s, net_cur, GNUNET_NO, GNUNET_YES);
1229 distribute_bandwidth_in_network (s, net_cur, fba_ctx.best);
1230 return fba_ctx.best;
1234 * Stop notifying about address and bandwidth changes for this peer
1236 * @param solver the solver handle
1237 * @param peer the peer
1240 GAS_proportional_stop_get_preferred_address (void *solver,
1241 const struct GNUNET_PeerIdentity *peer)
1243 struct GAS_PROPORTIONAL_Handle *s = solver;
1244 struct ATS_Address *cur;
1245 struct AddressSolverInformation *asi;
1246 struct Network *cur_net;
1249 == GNUNET_CONTAINER_multipeermap_contains (s->requests,
1251 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (s->requests, peer,
1254 cur = get_active_address (s, s->addresses, peer);
1257 LOG(GNUNET_ERROR_TYPE_INFO,
1258 "Disabling %s address %p for peer `%s'\n",
1259 (GNUNET_NO == cur->active) ? "inactive" : "active", cur,
1260 GNUNET_i2s (&cur->peer));
1262 /* Disabling current address */
1263 asi = cur->solver_information;
1264 cur_net = asi->network ;
1265 cur->active = GNUNET_NO; /* No active any longer */
1266 cur->assigned_bw_in = BANDWIDTH_ZERO; /* no bandwidth assigned */
1267 cur->assigned_bw_out = BANDWIDTH_ZERO; /* no bandwidth assigned */
1269 if (GNUNET_SYSERR == addresse_decrement (s, cur_net, GNUNET_NO, GNUNET_YES))
1272 distribute_bandwidth_in_network (s, cur_net, NULL );
1278 * Remove an address from the solver
1280 * @param solver the solver handle
1281 * @param address the address to remove
1282 * @param session_only delete only session not whole address
1285 GAS_proportional_address_delete (void *solver, struct ATS_Address *address,
1288 struct GAS_PROPORTIONAL_Handle *s = solver;
1289 struct Network *net;
1290 struct AddressWrapper *aw;
1291 struct AddressSolverInformation *asi;
1292 const struct ATS_Address *new_address;
1295 /* Remove an adress completely, we have to:
1296 * - Remove from specific network
1297 * - Decrease number of total addresses
1299 * - decrease number of active addreses
1302 asi = address->solver_information;
1312 if (GNUNET_NO == session_only)
1314 LOG(GNUNET_ERROR_TYPE_INFO,
1315 "Deleting %s address %p for peer `%s' from network `%s' (total: %u/ active: %u)\n",
1316 (GNUNET_NO == address->active) ? "inactive" : "active", address,
1317 GNUNET_i2s (&address->peer), net->desc, net->total_addresses,
1318 net->active_addresses);
1320 /* Remove address */
1321 addresse_decrement (s, net, GNUNET_YES, GNUNET_NO);
1322 for (aw = net->head; NULL != aw; aw = aw->next)
1324 if (aw->addr == address)
1332 GNUNET_CONTAINER_DLL_remove(net->head, net->tail, aw);
1333 GNUNET_free_non_null (aw->addr->solver_information);
1338 /* Remove session only: remove if active and update */
1339 LOG(GNUNET_ERROR_TYPE_INFO,
1340 "Deleting %s session %p for peer `%s' from network `%s' (total: %u/ active: %u)\n",
1341 (GNUNET_NO == address->active) ? "inactive" : "active", address,
1342 GNUNET_i2s (&address->peer), net->desc, net->total_addresses,
1343 net->active_addresses);
1346 if (GNUNET_YES == address->active)
1348 /* Address was active, remove from network and update quotas*/
1349 address->active = GNUNET_NO;
1350 address->assigned_bw_in = BANDWIDTH_ZERO;
1351 address->assigned_bw_out = BANDWIDTH_ZERO;
1352 asi->calculated_quota_in_NBO = htonl (0);
1353 asi->calculated_quota_out_NBO = htonl (0);
1355 if (GNUNET_SYSERR == addresse_decrement (s, net, GNUNET_NO, GNUNET_YES))
1357 distribute_bandwidth_in_network (s, net, NULL);
1358 if (NULL == (new_address = GAS_proportional_get_preferred_address (s, &address->peer)))
1360 /* No alternative address found, disconnect peer */
1361 s->bw_changed (s->bw_changed_cls, address);
1365 s->bw_changed (s->bw_changed_cls, (struct ATS_Address *) new_address);
1368 LOG(GNUNET_ERROR_TYPE_INFO,
1369 "After deleting address now total %u and active %u addresses in network `%s'\n",
1370 net->total_addresses, net->active_addresses, net->desc);
1375 * Start a bulk operation
1377 * @param solver the solver
1380 GAS_proportional_bulk_start (void *solver)
1382 LOG(GNUNET_ERROR_TYPE_DEBUG, "Locking solver for bulk operation ...\n");
1383 struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) solver;
1385 GNUNET_assert(NULL != solver);
1391 * Bulk operation done
1394 GAS_proportional_bulk_stop (void *solver)
1396 LOG(GNUNET_ERROR_TYPE_DEBUG, "Unlocking solver from bulk operation ...\n");
1398 struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) solver;
1399 GNUNET_assert(NULL != solver);
1401 if (s->bulk_lock < 1)
1407 if ((0 == s->bulk_lock) && (0 < s->bulk_requests))
1409 LOG(GNUNET_ERROR_TYPE_DEBUG, "No lock pending, recalculating\n");
1410 distribute_bandwidth_in_network (s, NULL, NULL);
1411 s->bulk_requests = 0;
1417 * Add a new single address to a network
1419 * @param solver the solver Handle
1420 * @param address the address to add
1421 * @param network network type of this address
1424 GAS_proportional_address_add (void *solver, struct ATS_Address *address,
1428 * Transport properties for this address have changed
1430 * @param solver solver handle
1431 * @param address the address
1432 * @param type the ATSI type in HBO
1433 * @param abs_value the absolute value of the property
1434 * @param rel_value the normalized value
1437 GAS_proportional_address_property_changed (void *solver,
1438 struct ATS_Address *address, uint32_t type, uint32_t abs_value,
1441 struct GAS_PROPORTIONAL_Handle *s;
1443 struct AddressSolverInformation *asi;
1445 GNUNET_assert(NULL != solver);
1446 GNUNET_assert(NULL != address);
1448 s = (struct GAS_PROPORTIONAL_Handle *) solver;
1449 asi = address->solver_information;
1464 LOG(GNUNET_ERROR_TYPE_DEBUG,
1465 "Property `%s' for peer `%s' address %p changed to %.2f \n",
1466 GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
1467 address, rel_value);
1470 case GNUNET_ATS_UTILIZATION_OUT:
1471 case GNUNET_ATS_UTILIZATION_IN:
1472 case GNUNET_ATS_UTILIZATION_PAYLOAD_IN:
1473 case GNUNET_ATS_UTILIZATION_PAYLOAD_OUT:
1474 case GNUNET_ATS_QUALITY_NET_DELAY:
1475 case GNUNET_ATS_QUALITY_NET_DISTANCE:
1476 case GNUNET_ATS_COST_WAN:
1477 case GNUNET_ATS_COST_LAN:
1478 case GNUNET_ATS_COST_WLAN:
1479 distribute_bandwidth_in_network (s, n, NULL);
1485 * Transport session for this address has changed
1487 * NOTE: values in addresses are already updated
1489 * @param solver solver handle
1490 * @param address the address
1491 * @param cur_session the current session
1492 * @param new_session the new session
1495 GAS_proportional_address_session_changed (void *solver,
1496 struct ATS_Address *address, uint32_t cur_session, uint32_t new_session)
1498 if (cur_session != new_session)
1500 LOG(GNUNET_ERROR_TYPE_DEBUG, "Session changed from %u to %u\n", cur_session,
1506 * Usage for this address has changed
1508 * NOTE: values in addresses are already updated
1510 * @param solver solver handle
1511 * @param address the address
1512 * @param in_use usage state
1515 GAS_proportional_address_inuse_changed (void *solver,
1516 struct ATS_Address *address, int in_use)
1518 LOG(GNUNET_ERROR_TYPE_DEBUG, "Usage changed to %s\n",
1519 (GNUNET_YES == in_use) ? "USED" : "UNUSED");
1523 * Network scope for this address has changed
1525 * NOTE: values in addresses are already updated
1527 * @param solver solver handle
1528 * @param address the address
1529 * @param current_network the current network
1530 * @param new_network the new network
1533 GAS_proportional_address_change_network (void *solver,
1534 struct ATS_Address *address, uint32_t current_network, uint32_t new_network)
1536 struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) solver;
1537 struct AddressSolverInformation *asi;
1538 int save_active = GNUNET_NO;
1540 struct Network *new_net = NULL;
1542 if (current_network == new_network)
1548 asi = address->solver_information;
1556 /* Network changed */
1557 LOG(GNUNET_ERROR_TYPE_DEBUG,
1558 "Network type changed, moving %s address from `%s' to `%s'\n",
1559 (GNUNET_YES == address->active) ? "active" : "inactive",
1560 GNUNET_ATS_print_network_type (current_network),
1561 GNUNET_ATS_print_network_type (new_network));
1563 save_active = address->active;
1565 /* Disable and assign no bandwidth */
1566 address->active = GNUNET_NO;
1567 address->assigned_bw_in = BANDWIDTH_ZERO; /* no bandwidth assigned */
1568 address->assigned_bw_out = BANDWIDTH_ZERO; /* no bandwidth assigned */
1570 /* Remove from old network */
1571 GAS_proportional_address_delete (solver, address, GNUNET_NO);
1573 /* Set new network type */
1574 if (NULL == (new_net = get_network (solver, new_network)))
1576 /* Address changed to invalid network... */
1577 LOG(GNUNET_ERROR_TYPE_ERROR,
1578 _("Invalid network type `%u' `%s': Disconnect!\n"), new_network,
1579 GNUNET_ATS_print_network_type (new_network));
1581 /* Find new address to suggest since no bandwidth in network*/
1582 if (NULL == GAS_proportional_get_preferred_address (s, &address->peer))
1584 /* No alternative address found, disconnect peer */
1585 s->bw_changed (s->bw_changed_cls, address);
1590 /* Add to new network and update*/
1591 asi->network = new_net;
1592 GAS_proportional_address_add (solver, address, new_network);
1593 if (GNUNET_YES == save_active)
1595 /* check if bandwidth available in new network */
1596 if (GNUNET_YES == (is_bandwidth_available_in_network (new_net)))
1598 /* Assign bandwidth to updated address */
1599 address->active = GNUNET_YES;
1600 addresse_increment (s, new_net, GNUNET_NO, GNUNET_YES);
1601 distribute_bandwidth_in_network (solver, new_net, NULL);
1605 LOG(GNUNET_ERROR_TYPE_DEBUG,
1606 "Not enough bandwidth in new network, suggesting alternative address ..\n");
1607 /* Find new address to suggest since no bandwidth in network*/
1608 if (NULL == GAS_proportional_get_preferred_address (s, &address->peer))
1610 /* No alternative address found, disconnect peer */
1611 s->bw_changed (s->bw_changed_cls, address);
1618 * Add a new single address to a network
1620 * @param solver the solver Handle
1621 * @param address the address to add
1622 * @param network network type of this address
1625 GAS_proportional_address_add (void *solver, struct ATS_Address *address,
1628 struct GAS_PROPORTIONAL_Handle *s = solver;
1629 struct Network *net = NULL;
1630 struct AddressWrapper *aw = NULL;
1631 struct AddressSolverInformation *asi;
1633 GNUNET_assert(NULL != s);
1634 net = get_network (s, network);
1639 LOG(GNUNET_ERROR_TYPE_ERROR,
1640 "Unknown network %u `%s' for new address %p for peer `%s'\n",
1641 network, GNUNET_ATS_print_network_type(network),
1642 address, GNUNET_i2s(&address->peer));
1647 aw = GNUNET_new (struct AddressWrapper);
1649 GNUNET_CONTAINER_DLL_insert(net->head, net->tail, aw);
1650 addresse_increment (s, net, GNUNET_YES, GNUNET_NO);
1652 asi = GNUNET_new (struct AddressSolverInformation);
1654 asi->calculated_quota_in_NBO = htonl (0);
1655 asi->calculated_quota_out_NBO = htonl (0);
1656 aw->addr->solver_information = asi;
1658 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (s->requests, &address->peer))
1660 if (NULL == get_active_address (s, s->addresses, &address->peer))
1662 if (NULL != GAS_proportional_get_preferred_address (s, &address->peer))
1663 s->bw_changed (s->bw_changed_cls, (struct ATS_Address *) address);
1667 LOG(GNUNET_ERROR_TYPE_INFO,
1668 "Adding new address %p for peer `%s', now total %u and active %u addresses in network `%s'\n",
1669 address, GNUNET_i2s(&address->peer), net->total_addresses, net->active_addresses, net->desc);
1673 /* end of plugin_ats_proportional.c */