2 This file is part of GNUnet.
3 Copyright (C) 2011-2015 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file ats/plugin_ats_proportional.c
22 * @brief ATS proportional solver
23 * @author Matthias Wachs
24 * @author Christian Grothoff
27 #include "gnunet_statistics_service.h"
28 #include "gnunet_ats_service.h"
29 #include "gnunet_ats_plugin.h"
30 #include "gnunet-service-ats_addresses.h"
32 #define LOG(kind, ...) GNUNET_log_from(kind, "ats-proportional", __VA_ARGS__)
35 * How much do we value stability over adaptation by default. A low
36 * value (close to 1.0) means we adapt as soon as possible, a larger
37 * value means that we have to have the respective factor of an
38 * advantage (or delay) before we adapt and sacrifice stability.
40 #define PROP_STABILITY_FACTOR 1.25
44 * Default value to assume for the proportionality factor, if none is
45 * given in the configuration. This factor determines how strong the
46 * bandwidth allocation will orient itself on the application
47 * preferences. A lower factor means a more balanced bandwidth
48 * distribution while a larger number means a distribution more in
49 * line with application (bandwidth) preferences.
51 #define PROPORTIONALITY_FACTOR 2.0
55 * Address information stored for the proportional solver in the
56 * `solver_information` member of `struct GNUNET_ATS_Address`.
58 * They are also stored in the respective `struct Network`'s linked
61 struct AddressWrapper {
65 struct AddressWrapper *next;
70 struct AddressWrapper *prev;
75 struct ATS_Address *addr;
78 * Network scope this address is in
80 struct Network *network;
85 uint32_t calculated_quota_in;
90 uint32_t calculated_quota_out;
93 * When was this address activated
95 struct GNUNET_TIME_Absolute activated;
100 * Representation of a network
104 * Network description
109 * String for statistics total addresses
114 * String for statistics active addresses
119 * Linked list of addresses in this network: head
121 struct AddressWrapper *head;
124 * Linked list of addresses in this network: tail
126 struct AddressWrapper *tail;
129 * Total inbound quota
131 unsigned long long total_quota_in;
134 * Total outbound quota
136 unsigned long long total_quota_out;
141 enum GNUNET_NetworkType type;
144 * Number of active addresses for this network
146 unsigned int active_addresses;
149 * Number of total addresses for this network
151 unsigned int total_addresses;
156 * A handle for the proportional solver
158 struct GAS_PROPORTIONAL_Handle {
160 * Our execution environment.
162 struct GNUNET_ATS_PluginEnvironment *env;
167 struct Network *network_entries;
170 * Proportionality factor
177 double stability_factor;
180 * Bulk lock counter. If zero, we are not locked.
182 unsigned int bulk_lock;
185 * Number of changes made while solver was locked. We really only
186 * use 0/non-zero to check on unlock if we have to run the update.
188 unsigned int bulk_requests;
191 * Number of active addresses for solver
193 unsigned int active_addresses;
198 * Test if bandwidth is available in this network to add an additional address.
200 * @param net the network type to check
201 * @param extra for how many extra addresses do we check?
202 * @return #GNUNET_YES or #GNUNET_NO
205 is_bandwidth_available_in_network(struct Network *net,
209 uint32_t min_bw = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
211 GNUNET_assert(((int)net->active_addresses) + extra >= 0);
212 na = net->active_addresses + extra;
215 if (((net->total_quota_in / na) > min_bw) &&
216 ((net->total_quota_out / na) > min_bw))
223 * Test if all peers in this network require connectivity at level at
226 * @param s the solver handle
227 * @param net the network type to check
228 * @param con connection return value threshold to check
229 * @return #GNUNET_YES or #GNUNET_NO
232 all_require_connectivity(struct GAS_PROPORTIONAL_Handle *s,
236 struct AddressWrapper *aw;
238 for (aw = net->head; NULL != aw; aw = aw->next)
240 s->env->get_connectivity(s->env->cls,
248 * Update bandwidth assigned to peers in this network. The basic idea
249 * is to assign every peer in the network the minimum bandwidth, and
250 * then distribute the remaining bandwidth proportional to application
253 * @param s the solver handle
254 * @param net the network type to update
257 distribute_bandwidth(struct GAS_PROPORTIONAL_Handle *s,
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;
270 const double *peer_relative_prefs;
272 LOG(GNUNET_ERROR_TYPE_INFO,
273 "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n",
275 net->active_addresses,
277 net->total_quota_in);
279 if (0 == net->active_addresses)
280 return; /* no addresses to update */
283 if ((net->active_addresses * min_bw) > net->total_quota_in)
288 if ((net->active_addresses * min_bw) > net->total_quota_out)
294 /* Calculate sum of relative preference for active addresses in this
296 sum_relative_peer_prefences = 0.0;
298 for (aw = net->head; NULL != aw; aw = aw->next)
300 if (GNUNET_YES != aw->addr->active)
302 peer_relative_prefs = s->env->get_preferences(s->env->cls,
304 sum_relative_peer_prefences
305 += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
308 if (count_addresses != net->active_addresses)
311 LOG(GNUNET_ERROR_TYPE_WARNING,
312 "%s: Counted %u active addresses, expected %u active addresses\n",
315 net->active_addresses);
317 net->active_addresses = count_addresses;
319 LOG(GNUNET_ERROR_TYPE_INFO,
320 "Total relative preference %.3f for %u addresses in network %s\n",
321 sum_relative_peer_prefences,
322 net->active_addresses,
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);
328 LOG(GNUNET_ERROR_TYPE_DEBUG,
329 "Proportionally distributable bandwidth (in/out): %llu/%llu\n",
331 remaining_quota_out);
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;
340 for (aw = net->head; NULL != aw; aw = aw->next)
342 if (GNUNET_YES != aw->addr->active)
344 /* set to 0, just to be sure */
345 aw->calculated_quota_in = 0;
346 aw->calculated_quota_out = 0;
349 peer_relative_prefs = s->env->get_preferences(s->env->cls,
352 + s->prop_factor * peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
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;
359 LOG(GNUNET_ERROR_TYPE_INFO,
360 "New quotas for peer `%s' with weight (cur/total) %.3f/%.3f (in/out) are: %u/%u\n",
361 GNUNET_i2s(&aw->addr->peer),
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;
369 LOG(GNUNET_ERROR_TYPE_DEBUG,
370 "Total bandwidth assigned is (in/out): %llu /%llu\n",
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);
380 * Notify ATS service of bandwidth changes to addresses.
382 * @param s solver handle
383 * @param net the network to propagate changes in
386 propagate_bandwidth(struct GAS_PROPORTIONAL_Handle *s,
389 struct AddressWrapper *cur;
391 for (cur = net->head; NULL != cur; cur = cur->next)
393 if ((cur->addr->assigned_bw_in == cur->calculated_quota_in) &&
394 (cur->addr->assigned_bw_out == cur->calculated_quota_out))
396 cur->addr->assigned_bw_in = cur->calculated_quota_in;
397 cur->addr->assigned_bw_out = cur->calculated_quota_out;
398 if (GNUNET_YES == cur->addr->active)
399 s->env->bandwidth_changed_cb(s->env->cls,
406 * Distribute bandwidth. The addresses have already been selected,
407 * this is merely distributed the bandwidth among the addresses.
409 * @param s the solver handle
410 * @param n the network, can be NULL for all networks
413 distribute_bandwidth_in_network(struct GAS_PROPORTIONAL_Handle *s,
418 if (0 != s->bulk_lock)
425 LOG(GNUNET_ERROR_TYPE_DEBUG,
426 "Redistributing bandwidth in network %s with %u active and %u total addresses\n",
427 GNUNET_NT_to_string(n->type),
430 s->env->info_cb(s->env->cls,
433 GAS_INFO_PROP_SINGLE);
434 distribute_bandwidth(s,
436 s->env->info_cb(s->env->cls,
439 GAS_INFO_PROP_SINGLE);
440 s->env->info_cb(s->env->cls,
441 GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
443 GAS_INFO_PROP_SINGLE);
444 propagate_bandwidth(s,
447 s->env->info_cb(s->env->cls,
448 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
450 GAS_INFO_PROP_SINGLE);
454 LOG(GNUNET_ERROR_TYPE_DEBUG,
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++)
462 distribute_bandwidth(s,
463 &s->network_entries[i]);
464 s->env->info_cb(s->env->cls,
468 s->env->info_cb(s->env->cls,
469 GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
472 for (i = 0; i < s->env->network_count; i++)
473 propagate_bandwidth(s,
474 &s->network_entries[i]);
475 s->env->info_cb(s->env->cls,
476 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
484 * Context for finding the best address* Linked list of addresses in this network: head
486 struct FindBestAddressCtx {
490 struct GAS_PROPORTIONAL_Handle *s;
493 * The currently best address
495 struct ATS_Address *best;
500 * Find a "good" address to use for a peer by iterating over the
501 * addresses for this peer. If we already have an existing address,
502 * we stick to it. Otherwise, we pick by lowest distance and then by
505 * @param cls the `struct FindBestAddressCtx *' where we store the result
506 * @param key the peer we are trying to find the best address for
507 * @param value another `struct ATS_Address*` to consider using
508 * @return #GNUNET_OK (continue to iterate)
511 find_best_address_it(void *cls,
512 const struct GNUNET_PeerIdentity *key,
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;
520 double best_distance;
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 ==
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,
542 all_require_connectivity(ctx->s,
546 /* test if minimum bandwidth for 'current' would be available */
548 = is_bandwidth_available_in_network(asi->network,
552 /* Bandwidth for this address is unavailable, so we cannot use
556 if (GNUNET_YES == current->active)
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)
562 /* Keep active address for stability reasons */
567 if (NULL == ctx->best)
569 /* We so far have nothing else, so go with it! */
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;
580 /* user shorter distance */
581 if (cur_distance < best_distance)
583 if (GNUNET_NO == ctx->best->active)
585 /* Activity doesn't influence the equation, use current */
588 else if ((best_distance / cur_distance) > ctx->s->stability_factor)
590 /* Distance change is significant, switch active address! */
595 /* User connection with less delay */
596 if (cur_delay < best_delay)
598 if (GNUNET_NO == ctx->best->active)
600 /* Activity doesn't influence the equation, use current */
603 else if ((best_delay / cur_delay) > ctx->s->stability_factor)
605 /* Latency change is significant, switch active address! */
614 * Find the currently best address for a peer from the set of
615 * addresses available or return NULL of no address is available.
617 * @param s the proportional handle
618 * @param addresses the address hashmap
619 * @param id the peer id
620 * @return the address or NULL
623 get_best_address(struct GAS_PROPORTIONAL_Handle *s,
624 struct GNUNET_CONTAINER_MultiPeerMap *addresses,
625 const struct GNUNET_PeerIdentity *id)
627 struct FindBestAddressCtx fba_ctx;
631 GNUNET_CONTAINER_multipeermap_get_multiple(addresses,
633 &find_best_address_it,
640 * Decrease number of active addresses in network.
642 * @param s the solver handle
643 * @param net the network type
646 address_decrement_active(struct GAS_PROPORTIONAL_Handle *s,
649 GNUNET_assert(net->active_addresses > 0);
650 net->active_addresses--;
651 GNUNET_STATISTICS_update(s->env->stats,
655 GNUNET_assert(s->active_addresses > 0);
656 s->active_addresses--;
657 GNUNET_STATISTICS_update(s->env->stats,
658 "# ATS addresses total",
665 * Address map iterator to find current active address for peer.
666 * Asserts that only one address is active per peer.
668 * @param cls last active address
669 * @param key peer's key
670 * @param value address to check
671 * @return #GNUNET_NO on double active address else #GNUNET_YES;
674 get_active_address_it(void *cls,
675 const struct GNUNET_PeerIdentity *key,
678 struct ATS_Address **dest = cls;
679 struct ATS_Address *aa = value;
681 if (GNUNET_YES != aa->active)
683 GNUNET_assert(NULL == (*dest));
690 * Find current active address for peer
692 * @param s the solver handle
693 * @param peer the peer
694 * @return active address or NULL
696 static struct ATS_Address *
697 get_active_address(struct GAS_PROPORTIONAL_Handle *s,
698 const struct GNUNET_PeerIdentity *peer)
700 struct ATS_Address *dest;
703 GNUNET_CONTAINER_multipeermap_get_multiple(s->env->addresses,
705 &get_active_address_it,
712 * Update active address for a peer. Check if active address exists
713 * and what the best address is, if addresses are different switch.
714 * Then reallocate bandwidth within the affected network scopes.
716 * @param s solver handle
717 * @param current_address the address currently active for the peer,
719 * @param peer the peer to check
722 update_active_address(struct GAS_PROPORTIONAL_Handle *s,
723 struct ATS_Address *current_address,
724 const struct GNUNET_PeerIdentity *peer)
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;
732 unsigned int con_min;
734 best_address = get_best_address(s,
737 if (NULL != best_address)
738 asi_best = best_address->solver_information;
741 if (current_address == best_address)
742 return; /* no changes */
743 if (NULL != current_address)
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);
749 LOG(GNUNET_ERROR_TYPE_INFO,
750 "Disabling previous active address for peer `%s'\n",
752 asi_cur->activated = GNUNET_TIME_UNIT_ZERO_ABS;
753 current_address->active = GNUNET_NO;
754 current_address->assigned_bw_in = 0;
755 current_address->assigned_bw_out = 0;
756 address_decrement_active(s,
758 if ((NULL == best_address) ||
759 (asi_best->network != asi_cur->network))
760 distribute_bandwidth_in_network(s,
762 if (NULL == best_address)
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. */
769 LOG(GNUNET_ERROR_TYPE_DEBUG,
770 "Disconnecting peer `%s'.\n",
772 s->env->bandwidth_changed_cb(s->env->cls,
777 if (NULL == best_address)
779 /* We do not have a new address, so we are done. */
780 LOG(GNUNET_ERROR_TYPE_DEBUG,
781 "Cannot suggest address for peer `%s'\n",
785 /* We do have a new address, activate it */
786 LOG(GNUNET_ERROR_TYPE_DEBUG,
787 "Selecting new address %p for peer `%s'\n",
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++;
795 GNUNET_STATISTICS_update(s->env->stats,
796 "# ATS active addresses total",
799 GNUNET_STATISTICS_update(s->env->stats,
800 asi_best->network->stat_active,
803 LOG(GNUNET_ERROR_TYPE_INFO,
804 "Address %p for peer `%s' is now active\n",
809 is_bandwidth_available_in_network(asi_best->network,
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;
817 for (aw = asi_best->network->head; NULL != aw; aw = aw->next)
820 (a_con = s->env->get_connectivity(s->env->cls,
821 &aw->addr->peer))) &&
822 (GNUNET_YES == aw->addr->active))
830 update_active_address(s,
832 &aw_min->addr->peer);
834 distribute_bandwidth_in_network(s,
840 * The preferences for a peer in the problem changed.
842 * @param solver the solver handle
843 * @param peer the peer to change the preference for
844 * @param kind the kind to change the preference
845 * @param pref_rel the normalized preference value for this kind over all clients
848 GAS_proportional_change_preference(void *solver,
849 const struct GNUNET_PeerIdentity *peer,
850 enum GNUNET_ATS_PreferenceKind kind,
853 struct GAS_PROPORTIONAL_Handle *s = solver;
855 if (GNUNET_ATS_PREFERENCE_BANDWIDTH != kind)
856 return; /* we do not care */
857 distribute_bandwidth_in_network(s,
863 * Get application feedback for a peer
865 * @param solver the solver handle
866 * @param application the application
867 * @param peer the peer to change the preference for
868 * @param scope the time interval for this feedback: [now - scope .. now]
869 * @param kind the kind to change the preference
870 * @param score the score
873 GAS_proportional_feedback(void *solver,
874 struct GNUNET_SERVICE_Client *application,
875 const struct GNUNET_PeerIdentity *peer,
876 const struct GNUNET_TIME_Relative scope,
877 enum GNUNET_ATS_PreferenceKind kind,
880 /* Proportional does not care about feedback */
885 * Get the preferred address for a specific peer
887 * @param solver the solver handle
888 * @param peer the identity of the peer
891 GAS_proportional_start_get_address(void *solver,
892 const struct GNUNET_PeerIdentity *peer)
894 struct GAS_PROPORTIONAL_Handle *s = solver;
896 update_active_address(s,
897 get_active_address(s,
904 * Stop notifying about address and bandwidth changes for this peer
906 * @param solver the solver handle
907 * @param peer the peer
910 GAS_proportional_stop_get_address(void *solver,
911 const struct GNUNET_PeerIdentity *peer)
913 struct GAS_PROPORTIONAL_Handle *s = solver;
914 struct ATS_Address *cur;
915 struct AddressWrapper *asi;
917 cur = get_active_address(s,
921 asi = cur->solver_information;
922 distribute_bandwidth_in_network(s,
928 * Start a bulk operation
930 * @param solver the solver
933 GAS_proportional_bulk_start(void *solver)
935 struct GAS_PROPORTIONAL_Handle *s = solver;
937 LOG(GNUNET_ERROR_TYPE_DEBUG,
938 "Locking solver for bulk operation ...\n");
939 GNUNET_assert(NULL != solver);
945 * Bulk operation done.
947 * @param solver our `struct GAS_PROPORTIONAL_Handle *`
950 GAS_proportional_bulk_stop(void *solver)
952 struct GAS_PROPORTIONAL_Handle *s = solver;
954 LOG(GNUNET_ERROR_TYPE_DEBUG,
955 "Unlocking solver from bulk operation ...\n");
956 if (s->bulk_lock < 1)
962 if ((0 == s->bulk_lock) &&
963 (0 < s->bulk_requests))
965 LOG(GNUNET_ERROR_TYPE_INFO,
966 "No lock pending, recalculating\n");
967 distribute_bandwidth_in_network(s,
969 s->bulk_requests = 0;
975 * Transport properties for this address have changed
977 * @param solver solver handle
978 * @param address the address
981 GAS_proportional_address_property_changed(void *solver,
982 struct ATS_Address *address)
984 struct GAS_PROPORTIONAL_Handle *s = solver;
985 struct AddressWrapper *asi = address->solver_information;
987 distribute_bandwidth_in_network(s,
993 * Add a new single address to a network
995 * @param solver the solver Handle
996 * @param address the address to add
997 * @param network network type of this address
1000 GAS_proportional_address_add(void *solver,
1001 struct ATS_Address *address,
1004 struct GAS_PROPORTIONAL_Handle *s = solver;
1005 struct Network *net;
1006 struct AddressWrapper *aw;
1008 GNUNET_assert(network < s->env->network_count);
1009 net = &s->network_entries[network];
1010 net->total_addresses++;
1012 aw = GNUNET_new(struct AddressWrapper);
1015 address->solver_information = aw;
1016 GNUNET_CONTAINER_DLL_insert(net->head,
1019 GNUNET_STATISTICS_update(s->env->stats,
1020 "# ATS addresses total",
1023 GNUNET_STATISTICS_update(s->env->stats,
1027 update_active_address(s,
1028 get_active_address(s,
1031 LOG(GNUNET_ERROR_TYPE_INFO,
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,
1041 * Remove an address from the solver. To do so, we:
1042 * - Removed it from specific network
1043 * - Decrease the number of total addresses
1045 * - decrease number of active addreses
1048 * @param solver the solver handle
1049 * @param address the address to remove
1052 GAS_proportional_address_delete(void *solver,
1053 struct ATS_Address *address)
1055 struct GAS_PROPORTIONAL_Handle *s = solver;
1056 struct AddressWrapper *aw = address->solver_information;
1057 struct Network *net = aw->network;
1059 LOG(GNUNET_ERROR_TYPE_DEBUG,
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),
1064 net->total_addresses,
1065 net->active_addresses);
1067 GNUNET_CONTAINER_DLL_remove(net->head,
1070 GNUNET_assert(net->total_addresses > 0);
1071 net->total_addresses--;
1072 GNUNET_STATISTICS_update(s->env->stats,
1076 if (GNUNET_YES == address->active)
1078 /* Address was active, remove from network and update quotas */
1079 update_active_address(s,
1082 distribute_bandwidth_in_network(s, net);
1085 address->solver_information = NULL;
1086 LOG(GNUNET_ERROR_TYPE_DEBUG,
1087 "After deleting address now total %u and active %u addresses in network `%s'\n",
1088 net->total_addresses,
1089 net->active_addresses,
1095 * Function invoked when the plugin is loaded.
1097 * @param[in,out] cls the `struct GNUNET_ATS_PluginEnvironment *` to use;
1098 * modified to return the API functions (ugh).
1099 * @return the `struct GAS_PROPORTIONAL_Handle` to pass as a closure
1102 libgnunet_plugin_ats_proportional_init(void *cls)
1104 static struct GNUNET_ATS_SolverFunctions sf;
1105 struct GNUNET_ATS_PluginEnvironment *env = cls;
1106 struct GAS_PROPORTIONAL_Handle *s;
1107 struct Network * cur;
1111 s = GNUNET_new(struct GAS_PROPORTIONAL_Handle);
1114 sf.s_add = &GAS_proportional_address_add;
1115 sf.s_address_update_property = &GAS_proportional_address_property_changed;
1116 sf.s_get = &GAS_proportional_start_get_address;
1117 sf.s_get_stop = &GAS_proportional_stop_get_address;
1118 sf.s_pref = &GAS_proportional_change_preference;
1119 sf.s_feedback = &GAS_proportional_feedback;
1120 sf.s_del = &GAS_proportional_address_delete;
1121 sf.s_bulk_start = &GAS_proportional_bulk_start;
1122 sf.s_bulk_stop = &GAS_proportional_bulk_stop;
1123 s->stability_factor = PROP_STABILITY_FACTOR;
1124 if (GNUNET_SYSERR !=
1125 GNUNET_CONFIGURATION_get_value_float(env->cfg,
1127 "PROP_STABILITY_FACTOR",
1130 if ((f_tmp < 1.0) || (f_tmp > 2.0))
1132 LOG(GNUNET_ERROR_TYPE_ERROR,
1133 _("Invalid %s configuration %f \n"),
1134 "PROP_STABILITY_FACTOR",
1139 s->stability_factor = f_tmp;
1140 LOG(GNUNET_ERROR_TYPE_INFO,
1141 "Using %s of %.3f\n",
1142 "PROP_STABILITY_FACTOR",
1146 s->prop_factor = PROPORTIONALITY_FACTOR;
1147 if (GNUNET_SYSERR !=
1148 GNUNET_CONFIGURATION_get_value_float(env->cfg,
1150 "PROP_PROPORTIONALITY_FACTOR",
1155 LOG(GNUNET_ERROR_TYPE_ERROR,
1156 _("Invalid %s configuration %f\n"),
1157 "PROP_PROPORTIONALITY_FACTOR",
1162 s->prop_factor = f_tmp;
1163 LOG(GNUNET_ERROR_TYPE_INFO,
1164 "Using %s of %.3f\n",
1165 "PROP_PROPORTIONALITY_FACTOR",
1170 s->network_entries = GNUNET_malloc(env->network_count *
1171 sizeof(struct Network));
1172 for (c = 0; c < env->network_count; c++)
1174 cur = &s->network_entries[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);
1179 GNUNET_asprintf(&cur->stat_total,
1180 "# ATS addresses %s total",
1182 GNUNET_asprintf(&cur->stat_active,
1183 "# ATS active addresses %s total",
1185 LOG(GNUNET_ERROR_TYPE_INFO,
1186 "Added network %u `%s' (%llu/%llu)\n",
1189 cur->total_quota_in,
1190 cur->total_quota_out);
1197 * Function used to unload the plugin.
1199 * @param cls return value from #libgnunet_plugin_ats_proportional_init()
1202 libgnunet_plugin_ats_proportional_done(void *cls)
1204 struct GNUNET_ATS_SolverFunctions *sf = cls;
1205 struct GAS_PROPORTIONAL_Handle *s = sf->cls;
1206 struct AddressWrapper *cur;
1207 struct AddressWrapper *next;
1210 for (c = 0; c < s->env->network_count; c++)
1212 GNUNET_break(0 == s->network_entries[c].total_addresses);
1213 GNUNET_break(0 == s->network_entries[c].active_addresses);
1214 next = s->network_entries[c].head;
1215 while (NULL != (cur = next))
1218 GNUNET_CONTAINER_DLL_remove(s->network_entries[c].head,
1219 s->network_entries[c].tail,
1221 GNUNET_free_non_null(cur->addr->solver_information);
1224 GNUNET_free(s->network_entries[c].stat_total);
1225 GNUNET_free(s->network_entries[c].stat_active);
1227 GNUNET_break(0 == s->active_addresses);
1228 GNUNET_free(s->network_entries);
1234 /* end of plugin_ats_proportional.c */