2 This file is part of GNUnet.
3 Copyright (C) 2011-2015, 2018 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_ats2_simple.c
22 * @brief ATS simple solver
23 * @author Matthias Wachs
24 * @author Christian Grothoff
30 #include "gnunet_ats_plugin_new.h"
31 #include "gnunet_hello_lib.h"
32 #include "gnunet_peerstore_service.h"
34 #define LOG(kind,...) GNUNET_log_from (kind, "ats-simple",__VA_ARGS__)
38 * Base frequency at which we suggest addresses to transport.
39 * Multiplied by the square of the number of active connections
40 * (and randomized) to calculate the actual frequency at which
41 * we will suggest addresses to the transport. Furthermore, each
42 * address is also bounded by an exponential back-off.
44 #define SUGGEST_FREQ GNUNET_TIME_UNIT_SECONDS
47 * What is the minimum bandwidth we always try to allocate for
48 * any session that is up? (May still be scaled down lower if
49 * the number of sessions is so high that the total bandwidth
50 * is insufficient to allow for this value to be granted.)
52 #define MIN_BANDWIDTH_PER_SESSION 1024
56 * A handle for the proportional solver
62 * Information about preferences and sessions we track
69 * Entry in list of addresses we could try per peer.
85 * Peer this hello belongs to.
90 * The address we could try.
95 * Is a session with this address already up?
96 * If not, set to NULL.
98 struct GNUNET_ATS_SessionHandle *sh;
101 * When does the HELLO expire?
103 struct GNUNET_TIME_Absolute expiration;
106 * When did we try it last?
108 struct GNUNET_TIME_Absolute last_attempt;
111 * Current exponential backoff value.
113 struct GNUNET_TIME_Relative backoff;
116 * Type of the network for this HELLO.
118 enum GNUNET_NetworkType nt;
124 * Internal representation of a session by the plugin.
125 * (If desired, plugin may just use NULL.)
127 struct GNUNET_ATS_SessionHandle
131 * Kept in DLL per peer.
133 struct GNUNET_ATS_SessionHandle *next;
136 * Kept in DLL per peer.
138 struct GNUNET_ATS_SessionHandle *prev;
141 * The session in the main ATS service.
143 struct GNUNET_ATS_Session *session;
146 * Current performance data for this @e session
148 const struct GNUNET_ATS_SessionData *data;
151 * Hello matching this session, or NULL for none.
156 * Peer this session is for.
161 * Address used by this session (largely for debugging).
166 * When did we last update transport about the allocation?
167 * Used to dampen the frequency of updates.
169 struct GNUNET_TIME_Absolute last_allocation;
172 * Last BW-in allocation given to the transport service.
174 struct GNUNET_BANDWIDTH_Value32NBO bw_in;
177 * Last BW-out allocation given to the transport service.
179 struct GNUNET_BANDWIDTH_Value32NBO bw_out;
182 * New BW-in allocation given to the transport service.
187 * New BW-out allocation given to the transport service.
195 * Information about preferences and sessions we track
202 * Kept in DLL per peer.
204 struct GNUNET_ATS_SessionHandle *sh_head;
207 * Kept in DLL per peer.
209 struct GNUNET_ATS_SessionHandle *sh_tail;
214 struct Hello *h_head;
219 struct Hello *h_tail;
222 * The handle for the proportional solver
224 struct SimpleHandle *h;
227 * Watch context where we are currently looking for HELLOs for
230 struct GNUNET_PEERSTORE_WatchContext *wc;
233 * Task used to try again to suggest an address for this peer.
235 struct GNUNET_SCHEDULER_Task *task;
238 * Which peer is this for?
240 struct GNUNET_PeerIdentity pid;
243 * When did we last suggest an address to connect to for this peer?
245 struct GNUNET_TIME_Absolute last_suggestion;
248 * Array where we sum up the bandwidth requests received indexed
249 * by preference kind (see `enum GNUNET_MQ_PreferenceKind`)
251 uint64_t bw_by_pk[GNUNET_MQ_PREFERENCE_COUNT];
257 * Representation of a network (to be expanded...)
263 * Total inbound quota
265 unsigned long long total_quota_in;
268 * Total outbound quota
270 unsigned long long total_quota_out;
275 enum GNUNET_NetworkType type;
281 * A handle for the proportional solver
287 * Our execution environment.
289 struct GNUNET_ATS_PluginEnvironment *env;
292 * Information we track for each peer.
294 struct GNUNET_CONTAINER_MultiPeerMap *peers;
297 * Handle to the peerstore service.
299 struct GNUNET_PEERSTORE_Handle *ps;
302 * Array where we sum up the bandwidth requests received indexed
303 * by preference kind (see `enum GNUNET_MQ_PreferenceKind`) (sums
306 uint64_t bw_by_pk[GNUNET_MQ_PREFERENCE_COUNT];
309 * Information we track per network type (quotas).
311 struct Network networks[GNUNET_NT_COUNT];
317 * Lookup peer in the peers map.
319 * @param h handle to look up in
320 * @param pid peer identity to look up by
321 * @return NULL for not found
324 lookup_peer (struct SimpleHandle *h,
325 const struct GNUNET_PeerIdentity *pid)
327 return GNUNET_CONTAINER_multipeermap_get (h->peers,
333 * Check if there is _any_ interesting information left we
334 * store about the peer in @a p.
336 * @param p peer to test if we can drop the data structure
337 * @return #GNUNET_YES if no information is left in @a p
340 peer_test_dead (struct Peer *p)
342 for (enum GNUNET_MQ_PreferenceKind pk = 0;
343 pk < GNUNET_MQ_PREFERENCE_COUNT;
345 if (0 != p->bw_by_pk[pk])
347 if (NULL != p->sh_head)
354 * Contact the transport service and suggest to it to
355 * try connecting to the address of @a hello. Updates
356 * backoff and timestamp values in the @a hello.
358 * @param hello[in,out] address suggestion to make
361 suggest_hello (struct Hello *hello)
363 struct Peer *p = hello->peer;
364 struct SimpleHandle *h = p->h;
367 = hello->last_attempt
368 = GNUNET_TIME_absolute_get ();
369 hello->backoff = GNUNET_TIME_randomized_backoff (hello->backoff,
370 GNUNET_TIME_absolute_get_remaining (hello->expiration));
371 h->env->suggest_cb (h->env->cls,
378 * Consider suggesting a HELLO (without a session) to transport.
379 * We look at how many active sessions we have for the peer, and
380 * if there are many, reduce the frequency of trying new addresses.
381 * Also, for each address we consider when we last tried it, and
382 * its exponential backoff if the attempt failed. Note that it
383 * is possible that this function is called when no suggestion
386 * In this case, we only calculate the time until we make the next
389 * @param cls a `struct Peer`
392 suggest_start_cb (void *cls)
394 struct Peer *p = cls;
395 struct GNUNET_TIME_Relative delay = GNUNET_TIME_UNIT_ZERO;
396 struct Hello *hello = NULL;
397 struct GNUNET_TIME_Absolute hpt = GNUNET_TIME_UNIT_FOREVER_ABS;
398 struct GNUNET_TIME_Relative xdelay;
399 struct GNUNET_TIME_Absolute xnext;
400 unsigned int num_sessions = 0;
403 /* count number of active sessions */
404 for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head;
408 /* calculate square of number of sessions */
409 num_sessions++; /* start with 1, even if we have zero sessions */
410 if (num_sessions < UINT16_MAX)
411 sq = num_sessions * (uint32_t) num_sessions;
414 xdelay = GNUNET_TIME_randomized_backoff (GNUNET_TIME_relative_multiply (SUGGEST_FREQ,
416 GNUNET_TIME_UNIT_FOREVER_REL);
417 xnext = GNUNET_TIME_relative_to_absolute (xdelay);
420 while (0 == delay.rel_value_us)
423 struct GNUNET_TIME_Absolute xmax;
427 /* We went through the loop already once and found
428 a HELLO that is due *now*, so make a suggestion! */
429 GNUNET_break (NULL == hello->sh);
430 suggest_hello (hello);
432 hpt = GNUNET_TIME_UNIT_FOREVER_ABS;
434 for (struct Hello *pos = p->h_head; NULL != pos; pos = next)
436 struct GNUNET_TIME_Absolute pt;
441 if (0 == GNUNET_TIME_absolute_get_remaining (pos->expiration).rel_value_us)
443 /* expired, remove! */
444 GNUNET_CONTAINER_DLL_remove (p->h_head,
450 pt = GNUNET_TIME_absolute_add (pos->last_attempt,
452 if ( (NULL == hello) ||
453 (pt.abs_value_us < hpt.abs_value_us) )
460 return; /* no HELLOs that could still be tried */
462 /* hpt is now the *earliest* possible time for any HELLO
463 but we might not want to go for as early as possible for
464 this peer. So the actual time is the max of the earliest
465 HELLO and the 'xnext' */
466 xmax = GNUNET_TIME_absolute_max (hpt,
468 delay = GNUNET_TIME_absolute_get_remaining (xmax);
470 p->task = GNUNET_SCHEDULER_add_delayed (delay,
477 * Function called by PEERSTORE for each matching record.
479 * @param cls closure with a `struct Peer`
480 * @param record peerstore record information
481 * @param emsg error message, or NULL if no errors
485 const struct GNUNET_PEERSTORE_Record *record,
488 struct Peer *p = cls;
491 enum GNUNET_NetworkType nt;
492 struct GNUNET_TIME_Absolute expiration;
495 if (0 != GNUNET_memcmp (&p->pid,
501 if (0 != strcmp (record->key,
502 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY))
507 addr = GNUNET_HELLO_extract_address (record->value,
513 return; /* invalid hello, bad signature, other problem */
514 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
516 /* expired, ignore */
520 /* check if addr is already known */
521 for (struct Hello *he = p->h_head;
525 if (0 != strcmp (he->address,
528 if (he->expiration.abs_value_us < expiration.abs_value_us)
530 he->expiration = expiration;
536 /* create new HELLO */
537 alen = strlen (addr) + 1;
538 hello = GNUNET_malloc (sizeof (struct Hello) + alen);
539 hello->address = (const char *) &hello[1];
540 hello->expiration = expiration;
547 GNUNET_CONTAINER_DLL_insert (p->h_head,
550 /* check if sh for this HELLO already exists */
551 for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head;
555 if ( (NULL == sh->address) ||
556 (0 != strcmp (sh->address,
559 GNUNET_assert (NULL == sh->hello);
565 p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb,
571 * Find or add peer if necessary.
573 * @param h our plugin handle
574 * @param pid the peer identity to add/look for
575 * @return a peer handle
578 peer_add (struct SimpleHandle *h,
579 const struct GNUNET_PeerIdentity *pid)
581 struct Peer *p = lookup_peer (h,
586 p = GNUNET_new (struct Peer);
589 p->wc = GNUNET_PEERSTORE_watch (h->ps,
592 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
595 GNUNET_assert (GNUNET_YES ==
596 GNUNET_CONTAINER_multipeermap_put (h->peers,
599 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
606 * Free the entry (and associated tasks) of peer @a p.
607 * Note that @a p must be dead already (see #peer_test_dead()).
609 * @param p the peer to free
612 peer_free (struct Peer *p)
614 struct SimpleHandle *h = p->h;
617 GNUNET_assert (NULL == p->sh_head);
618 while (NULL != (hello = p->h_head))
620 GNUNET_CONTAINER_DLL_remove (p->h_head,
623 GNUNET_assert (NULL == hello->sh);
628 GNUNET_SCHEDULER_cancel (p->task);
633 GNUNET_PEERSTORE_watch_cancel (p->wc);
636 GNUNET_assert (GNUNET_YES ==
637 GNUNET_CONTAINER_multipeermap_remove (h->peers,
645 * Check if the new allocation for @a sh is significantly different
646 * from the last one, and if so, tell transport.
648 * @param sh session handle to consider updating transport for
651 consider_notify_transport (struct GNUNET_ATS_SessionHandle *sh)
653 struct Peer *peer = sh->peer;
654 struct SimpleHandle *h = peer->h;
655 enum GNUNET_NetworkType nt = sh->data->prop.nt;
656 struct GNUNET_TIME_Relative delay;
662 delay = GNUNET_TIME_absolute_get_duration (sh->last_allocation);
663 /* A significant change is more than 10% of the quota,
664 which is given in bytes/second */
666 = h->networks[nt].total_quota_in * (delay.rel_value_us / 1000LL) / 1000LL / 10;
668 = h->networks[nt].total_quota_out * (delay.rel_value_us / 1000LL) / 1000LL / 10;
669 delta_in = ( (int64_t) ntohl (sh->bw_in.value__)) - ((int64_t) sh->target_in);
670 delta_out = ( (int64_t) ntohl (sh->bw_in.value__)) - ((int64_t) sh->target_in);
671 /* we want the absolute values */
673 delta_in = - delta_in;
674 if (INT64_MIN == delta_in)
675 delta_in = INT64_MAX; /* Handle corner case: INT_MIN == - INT_MIN */
677 delta_out = - delta_out;
678 if (INT64_MIN == delta_out)
679 delta_out = INT64_MAX; /* Handle corner case: INT_MIN == - INT_MIN */
680 if ( (sig_in > delta_in) &&
681 (sig_out > delta_out) )
682 return; /* insignificant change */
683 /* change is significant, tell transport! */
684 if (sh->target_in > UINT32_MAX)
685 sh->target_in = UINT32_MAX;
686 sh->bw_in.value__ = htonl ((uint32_t) sh->target_in);
687 if (sh->target_out > UINT32_MAX)
688 sh->target_out = UINT32_MAX;
689 sh->bw_out.value__ = htonl ((uint32_t) sh->target_out);
690 sh->last_allocation = GNUNET_TIME_absolute_get ();
691 h->env->allocate_cb (h->env->cls,
700 * Closure for #update_counters and #update_allocation.
707 struct SimpleHandle *h;
710 * Bandwidth that applications would prefer to allocate in this
711 * network type. We initially add all requested allocations to the
712 * respective network type where the given preference is best
713 * satisfied. Later we may rebalance.
715 uint64_t bw_out_by_nt[GNUNET_NT_COUNT];
718 * Current bandwidth utilization for this network type. We simply
719 * add the current goodput up (with some fairness considerations).
721 uint64_t bw_in_by_nt[GNUNET_NT_COUNT];
724 * By how much do we have to scale (up or down) our expectations
725 * for outbound bandwidth?
727 double scale_out[GNUNET_NT_COUNT];
730 * By how much do we have to scale (up or down) our expectations
731 * for inbound bandwidth?
733 double scale_in[GNUNET_NT_COUNT];
739 * Function used to iterate over all peers and collect
742 * @param cls a `struct Counters *`
743 * @param pid identity of the peer we process, unused
744 * @param value a `struct Peer *`
745 * @return #GNUNET_YES (continue to iterate)
748 update_counters (void *cls,
749 const struct GNUNET_PeerIdentity *pid,
752 struct Counters *c = cls;
753 struct Peer *peer = value;
754 struct GNUNET_ATS_SessionHandle *best[GNUNET_MQ_PREFERENCE_COUNT];
757 if (NULL == peer->sh_head)
758 return GNUNET_YES; /* no available session, cannot allocate bandwidth */
762 for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head;
766 enum GNUNET_NetworkType nt = sh->data->prop.nt;
768 sh->target_out = MIN_BANDWIDTH_PER_SESSION;
769 c->bw_out_by_nt[nt] += MIN_BANDWIDTH_PER_SESSION;
770 c->bw_in_by_nt[nt] += GNUNET_MAX (MIN_BANDWIDTH_PER_SESSION,
771 sh->data->prop.goodput_in);
772 for (enum GNUNET_MQ_PreferenceKind pk = 0;
773 pk < GNUNET_MQ_PREFERENCE_COUNT;
776 /* General rule: always prefer smaller distance if possible,
777 otherwise decide by pk: */
779 case GNUNET_MQ_PREFERENCE_NONE:
781 case GNUNET_MQ_PREFERENCE_BANDWIDTH:
782 /* For bandwidth, we compare the sum of transmitted bytes and
783 confirmed transmitted bytes, so confirmed data counts twice */
784 if ( (NULL == best[pk]) ||
785 (sh->data->prop.distance < best[pk]->data->prop.distance) ||
786 (sh->data->prop.utilization_out + sh->data->prop.goodput_out >
787 best[pk]->data->prop.utilization_out + best[pk]->data->prop.goodput_out) )
789 /* If both are equal (i.e. usually this happens if there is a zero), use
790 latency as a yardstick */
791 if ( (sh->data->prop.utilization_out + sh->data->prop.goodput_out ==
792 best[pk]->data->prop.utilization_out + best[pk]->data->prop.goodput_out) &&
793 (sh->data->prop.distance == best[pk]->data->prop.distance) &&
794 (sh->data->prop.delay.rel_value_us <
795 best[pk]->data->prop.delay.rel_value_us) )
798 case GNUNET_MQ_PREFERENCE_LATENCY:
799 if ( (NULL == best[pk]) ||
800 (sh->data->prop.distance < best[pk]->data->prop.distance) ||
801 ( (sh->data->prop.distance == best[pk]->data->prop.distance) &&
802 (sh->data->prop.delay.rel_value_us <
803 best[pk]->data->prop.delay.rel_value_us) ) )
806 case GNUNET_MQ_PREFERENCE_RELIABILITY:
807 /* For reliability, we consider the ratio of goodput to utilization
808 (but use multiplicative formultations to avoid division by zero) */
809 if ( (NULL == best[pk]) ||
810 (1ULL * sh->data->prop.goodput_out * best[pk]->data->prop.utilization_out >
811 1ULL * sh->data->prop.utilization_out * best[pk]->data->prop.goodput_out) )
813 /* If both are equal (i.e. usually this happens if there is a zero), use
814 latency as a yardstick */
815 if ( (1ULL * sh->data->prop.goodput_out * best[pk]->data->prop.utilization_out ==
816 1ULL * sh->data->prop.utilization_out * best[pk]->data->prop.goodput_out) &&
817 (sh->data->prop.distance == best[pk]->data->prop.distance) &&
818 (sh->data->prop.delay.rel_value_us <
819 best[pk]->data->prop.delay.rel_value_us) )
825 /* for first round, assign target bandwidth simply to sum of
826 requested bandwidth */
827 for (enum GNUNET_MQ_PreferenceKind pk = 1 /* skip GNUNET_MQ_PREFERENCE_NONE */;
828 pk < GNUNET_MQ_PREFERENCE_COUNT;
831 const struct GNUNET_ATS_SessionData *data = best[pk]->data;
832 enum GNUNET_NetworkType nt;
834 GNUNET_assert (NULL != data);
836 best[pk]->target_out = GNUNET_MIN (peer->bw_by_pk[pk],
837 MIN_BANDWIDTH_PER_SESSION);
838 c->bw_out_by_nt[nt] += (uint64_t) (best[pk]->target_out - MIN_BANDWIDTH_PER_SESSION);
845 * Function used to iterate over all peers and collect
848 * @param cls a `struct Counters *`
849 * @param pid identity of the peer we process, unused
850 * @param value a `struct Peer *`
851 * @return #GNUNET_YES (continue to iterate)
854 update_allocation (void *cls,
855 const struct GNUNET_PeerIdentity *pid,
858 struct Counters *c = cls;
859 struct Peer *peer = value;
862 for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head;
866 enum GNUNET_NetworkType nt = sh->data->prop.nt;
868 sh->target_out = (uint64_t) (c->scale_out[nt] * sh->target_out);
869 sh->target_in = (uint64_t) (c->scale_in[nt] * sh->target_in);
870 consider_notify_transport (sh);
877 * The world changed, recalculate our allocations.
880 update (struct SimpleHandle *h)
882 struct Counters cnt = {
886 GNUNET_CONTAINER_multipeermap_iterate (h->peers,
889 /* calculate how badly the missmatch between requested
890 allocations and available bandwidth is per network type */
891 for (enum GNUNET_NetworkType nt = 0;
892 nt < GNUNET_NT_COUNT;
895 cnt.scale_out[nt] = 1.0 * cnt.bw_out_by_nt[nt] / h->networks[nt].total_quota_out;
896 cnt.scale_in[nt] = 1.0 * cnt.bw_in_by_nt[nt] / h->networks[nt].total_quota_in;
898 /* recalculate allocations, considering scaling factor, and
899 update transport if the change is significant */
900 GNUNET_CONTAINER_multipeermap_iterate (h->peers,
907 * The plugin should begin to respect a new preference.
909 * @param cls the closure
910 * @param pref the preference to add
911 * @return plugin's internal representation, or NULL
913 static struct GNUNET_ATS_PreferenceHandle *
914 simple_preference_add (void *cls,
915 const struct GNUNET_ATS_Preference *pref)
917 struct SimpleHandle *h = cls;
918 struct Peer *p = peer_add (h,
921 GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT);
922 p->bw_by_pk[pref->pk] += ntohl (pref->bw.value__);
923 h->bw_by_pk[pref->pk] += ntohl (pref->bw.value__);
930 * The plugin should end respecting a preference.
932 * @param cls the closure
933 * @param ph whatever @e preference_add returned
934 * @param pref the preference to delete
935 * @return plugin's internal representation, or NULL
938 simple_preference_del (void *cls,
939 struct GNUNET_ATS_PreferenceHandle *ph,
940 const struct GNUNET_ATS_Preference *pref)
942 struct SimpleHandle *h = cls;
943 struct Peer *p = lookup_peer (h,
946 GNUNET_assert (NULL != p);
947 GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT);
948 p->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__);
949 h->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__);
950 if ( (0 == p->bw_by_pk[pref->pk]) &&
951 (GNUNET_YES == peer_test_dead (p)) )
958 * Transport established a new session with performance
959 * characteristics given in @a data.
962 * @param data performance characteristics of @a sh
963 * @param address address information (for debugging)
964 * @return handle by which the plugin will identify this session
966 static struct GNUNET_ATS_SessionHandle *
967 simple_session_add (void *cls,
968 const struct GNUNET_ATS_SessionData *data,
971 struct SimpleHandle *h = cls;
972 struct Peer *p = peer_add (h,
976 struct GNUNET_ATS_SessionHandle *sh;
978 /* setup session handle */
979 GNUNET_assert (NULL != data);
983 alen = strlen (address) + 1;
984 sh = GNUNET_malloc (sizeof (struct GNUNET_ATS_SessionHandle) + alen);
986 sh->session = data->session;
997 sh->address = (const char *) &sh[1];
999 GNUNET_CONTAINER_DLL_insert (p->sh_head,
1004 while ( (NULL != hello) &&
1005 (0 != strcmp (address,
1007 hello = hello->next;
1011 hello->backoff = GNUNET_TIME_UNIT_ZERO;
1020 * @a data changed for a given @a sh, solver should consider
1021 * the updated performance characteristics.
1023 * @param cls closure
1024 * @param sh session this is about
1025 * @param data performance characteristics of @a sh
1028 simple_session_update (void *cls,
1029 struct GNUNET_ATS_SessionHandle *sh,
1030 const struct GNUNET_ATS_SessionData *data)
1032 struct SimpleHandle *h = cls;
1034 GNUNET_assert (NULL != data);
1035 sh->data = data; /* this statement should not really do anything... */
1041 * A session went away. Solver should update accordingly.
1043 * @param cls closure
1044 * @param sh session this is about
1045 * @param data (last) performance characteristics of @a sh
1048 simple_session_del (void *cls,
1049 struct GNUNET_ATS_SessionHandle *sh,
1050 const struct GNUNET_ATS_SessionData *data)
1052 struct SimpleHandle *h = cls;
1053 struct Peer *p = sh->peer;
1054 struct Hello *hello = sh->hello;
1057 GNUNET_CONTAINER_DLL_remove (p->sh_head,
1062 GNUNET_assert (sh == hello->sh);
1064 /* session went down, if necessary restart suggesting
1066 if (NULL == p->task)
1067 p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb,
1071 /* del peer if otherwise dead */
1072 if ( (NULL == p->sh_head) &&
1073 (GNUNET_YES == peer_test_dead (p)) )
1079 #include "plugin_ats2_common.c"
1083 * Function invoked when the plugin is loaded.
1085 * @param[in,out] cls the `struct GNUNET_ATS_PluginEnvironment *` to use;
1086 * modified to return the API functions (ugh).
1087 * @return the `struct SimpleHandle` to pass as a closure
1090 libgnunet_plugin_ats2_simple_init (void *cls)
1092 static struct GNUNET_ATS_SolverFunctions sf;
1093 struct GNUNET_ATS_PluginEnvironment *env = cls;
1094 struct SimpleHandle *s;
1096 s = GNUNET_new (struct SimpleHandle);
1098 s->peers = GNUNET_CONTAINER_multipeermap_create (128,
1100 s->ps = GNUNET_PEERSTORE_connect (env->cfg);
1102 sf.preference_add = &simple_preference_add;
1103 sf.preference_del = &simple_preference_del;
1104 sf.session_add = &simple_session_add;
1105 sf.session_update = &simple_session_update;
1106 sf.session_del = &simple_session_del;
1107 for (enum GNUNET_NetworkType nt = 0;
1108 nt < GNUNET_NT_COUNT;
1111 const char *name = GNUNET_NT_to_string (nt);
1118 get_quota (env->cfg,
1121 &s->networks[nt].total_quota_in);
1122 get_quota (env->cfg,
1125 &s->networks[nt].total_quota_out);
1126 s->networks[nt].type = nt;
1133 * Function used to unload the plugin.
1135 * @param cls return value from #libgnunet_plugin_ats_proportional_init()
1138 libgnunet_plugin_ats2_simple_done (void *cls)
1140 struct GNUNET_ATS_SolverFunctions *sf = cls;
1141 struct SimpleHandle *s = sf->cls;
1144 GNUNET_CONTAINER_multipeermap_size (s->peers));
1145 GNUNET_CONTAINER_multipeermap_destroy (s->peers);
1146 GNUNET_PEERSTORE_disconnect (s->ps,
1153 /* end of plugin_ats2_simple.c */