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/gnunet-service-ats-solver_ril.c
23 * @brief ATS reinforcement learning solver
24 * @author Fabian Oehlmann
25 * @author Matthias Wachs
29 #include "gnunet_util_lib.h"
30 #include "gnunet-service-ats_addresses.h"
31 #include "gnunet_statistics_service.h"
33 #define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__)
35 #define RIL_ACTION_INVALID -1
36 #define RIL_FEATURES_ADDRESS_COUNT (3 + GNUNET_ATS_QualityPropertiesCount)
37 #define RIL_FEATURES_NETWORK_COUNT 4
39 #define RIL_DEFAULT_STEP_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 3000)
40 #define RIL_DEFAULT_ALGORITHM RIL_ALGO_Q
41 #define RIL_DEFAULT_DISCOUNT_FACTOR 0.5
42 #define RIL_DEFAULT_GRADIENT_STEP_SIZE 0.4
43 #define RIL_DEFAULT_TRACE_DECAY 0.6
44 #define RIL_EXPLORE_RATIO 0.1
47 * ATS reinforcement learning solver
54 RIL_ACTION_NOTHING = 0,
55 RIL_ACTION_BW_IN_DBL = 1,
56 RIL_ACTION_BW_IN_HLV = 2,
57 RIL_ACTION_BW_IN_INC = 3,
58 RIL_ACTION_BW_IN_DEC = 4,
59 RIL_ACTION_BW_OUT_DBL = 5,
60 RIL_ACTION_BW_OUT_HLV = 6,
61 RIL_ACTION_BW_OUT_INC = 7,
62 RIL_ACTION_BW_OUT_DEC = 8,
63 RIL_ACTION_TYPE_NUM = 9
72 enum RIL_E_Modification
81 * Global learning parameters
83 struct RIL_Learning_Parameters
86 * The TD-algorithm to use
88 enum RIL_Algorithm algorithm;
91 * Learning discount factor in the TD-update
96 * Gradient-descent step-size
101 * Trace-decay factor for eligibility traces
107 * Wrapper for addresses to store them in agent's linked list
109 struct RIL_Address_Wrapped
114 struct RIL_Address_Wrapped *next;
119 struct RIL_Address_Wrapped *prev;
124 struct ATS_Address *address_naked;
127 struct RIL_Peer_Agent
130 * Next agent in solver's linked list
132 struct RIL_Peer_Agent *next;
135 * Previous agent in solver's linked list
137 struct RIL_Peer_Agent *prev;
142 struct GAS_RIL_Handle *envi;
147 struct GNUNET_PeerIdentity peer;
150 * Whether the agent is active or not
152 int active; //TODO? rename into "requested", since it rather depicts whether there is a request pending for it
155 * Number of performed time-steps
157 unsigned long long step_count;
160 * Experience matrix W
165 * Number of rows of W / Number of state-vector features
170 * Number of columns of W / Number of actions
175 * Last perceived state feature vector
185 * Eligibility trace vector
192 struct ATS_Address * address_inuse;
195 * Head of addresses DLL
197 struct RIL_Address_Wrapped * addresses_head;
200 * Tail of addresses DLL
202 struct RIL_Address_Wrapped * addresses_tail;
205 * Inbound bandwidth assigned by the agent
207 unsigned long long bw_in;
210 * Outbound bandwidth assigned by the agent
212 unsigned long long bw_out;
220 enum GNUNET_ATS_Network_Type type;
223 * Total available inbound bandwidth
225 unsigned long long bw_in_available;
228 * Total assigned outbound bandwidth
230 unsigned long long bw_in_assigned;
233 * Total available outbound bandwidth
235 unsigned long long bw_out_available;
238 * Total assigned outbound bandwidth
240 unsigned long long bw_out_assigned;
246 * Bandwidth changed callback
248 GAS_bandwidth_changed_cb bw_changed;
251 * Bandwidth changed callback cls
253 void *bw_changed_cls;
256 * ATS function to get preferences for a peer
258 GAS_get_preferences get_preferences;
261 * Closure for ATS function to get preferences
263 void *get_preferences_cls;
266 * ATS function to get properties of an address
268 GAS_get_properties get_properties;
271 * Closure for ATS function to get properties
273 void *get_properties_cls;
277 * A handle for the reinforcement learning solver
279 struct GAS_RIL_Handle
284 struct GNUNET_STATISTICS_Handle *stats;
287 * Hashmap containing all valid addresses
289 const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
292 * Callbacks for the solver
294 struct RIL_Callbacks *callbacks;
302 * Number of changes while solver was locked
307 * Number of performed time-steps
309 unsigned long long step_count;
312 * Interval time between steps in milliseconds //TODO? put in agent
314 struct GNUNET_TIME_Relative step_time;
317 * Task identifier of the next time-step to be executed //TODO? put in agent
319 GNUNET_SCHEDULER_TaskIdentifier next_step;
322 * Learning parameters
324 struct RIL_Learning_Parameters parameters;
327 * Array of networks with global assignment state
329 struct RIL_Network * network_entries;
334 unsigned int networks_count;
337 * List of active peer-agents
339 struct RIL_Peer_Agent * agents_head;
340 struct RIL_Peer_Agent * agents_tail;
345 * ---------------------------
349 * Estimate the current action-value for state s and action a
350 * @param agent agent performing the estimation
353 * @return estimation value
356 agent_estimate_q (struct RIL_Peer_Agent *agent, double *state, int action)
361 for (i = 0; i < agent->m; i++)
363 result += state[i] * agent->W[action][i];
370 * Decide whether to do exploration (i.e. taking a new action) or exploitation (i.e. taking the
371 * currently estimated best action) in the current step
372 * @param agent agent performing the step
373 * @return yes, if exploring
376 agent_decide_exploration (struct RIL_Peer_Agent *agent)
378 double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
379 UINT32_MAX) / (double) UINT32_MAX;
381 if (r < RIL_EXPLORE_RATIO)
389 * Get the index of the address in the agent's list.
390 * @param agent agent handle
391 * @param address address handle
392 * @return the index, starting with zero
395 agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *address)
398 struct RIL_Address_Wrapped *cur;
401 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
404 if (cur->address_naked == address)
414 * Gets the wrapped address from the agent's list
415 * @param agent agent handle
416 * @param address address handle
417 * @return wrapped address
419 static struct RIL_Address_Wrapped *
420 agent_address_get (struct RIL_Peer_Agent *agent, struct ATS_Address *address)
422 struct RIL_Address_Wrapped *cur;
424 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
426 if (cur->address_naked == address)
436 * Gets the action, with the maximal estimated Q-value (i.e. the one currently estimated to bring the
437 * most reward in the future)
438 * @param agent agent performing the calculation
439 * @param state the state from which to take the action
440 * @return the action promising most future reward
443 agent_get_action_best (struct RIL_Peer_Agent *agent, double *state)
446 int max_i = RIL_ACTION_INVALID;
448 double max_q = -DBL_MAX;
450 for (i = 0; i < agent->n; i++)
452 cur_q = agent_estimate_q (agent, state, i);
460 GNUNET_assert(RIL_ACTION_INVALID != max_i);
466 * Gets any action, to explore the action space from that state
467 * @param agent agent performing the calculation
468 * @param state the state from which to take the action
472 agent_get_action_explore (struct RIL_Peer_Agent *agent, double *state)
474 return GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, agent->n);
478 * Updates the weights (i.e. coefficients) of the weight vector in matrix W for action a
479 * @param agent the agent performing the update
480 * @param reward the reward received for the last action
481 * @param s_next the new state, the last step got the agent into
482 * @param a_prime the new
485 agent_update_weights (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a_prime)
489 double *theta = agent->W[agent->a_old];
491 delta = reward + agent_estimate_q (agent, s_next, a_prime)
492 - agent_estimate_q (agent, agent->s_old, agent->a_old);
493 for (i = 0; i < agent->m; i++)
495 theta[i] += agent->envi->parameters.alpha * delta * (agent->e)[i];
500 * Changes the eligibility trace vector e in various manners:
501 * RIL_E_ACCUMULATE - adds 1 to each component as in accumulating eligibility traces
502 * RIL_E_REPLACE - resets each component to 1 as in replacing traces
503 * RIL_E_SET - multiplies e with gamma and lambda as in the update rule
504 * RIL_E_ZERO - sets e to 0 as in Watkin's Q-learning algorithm when exploring and when initializing
509 agent_modify_eligibility (struct RIL_Peer_Agent *agent, enum RIL_E_Modification mod)
512 double *e = agent->e;
513 double gamma = agent->envi->parameters.gamma;
514 double lambda = agent->envi->parameters.lambda;
516 for (i = 0; i < agent->m; i++)
520 case RIL_E_ACCUMULATE:
527 e[i] = gamma * lambda;
537 * Changes the active assignment suggestion of the handler and invokes the bw_changed callback to
538 * notify ATS of its new decision.
539 * @param solver solver handle
540 * @param agent agent handle
541 * @param new_address the address which is to be used
542 * @param new_bw_in the new amount of inbound bandwidth set for this address
543 * @param new_bw_out the new amount of outbound bandwidth set for this address
544 * @param silent disables invocation of the bw_changed callback, if GNUNET_YES
547 envi_set_active_suggestion (struct GAS_RIL_Handle *solver,
548 struct RIL_Peer_Agent *agent,
549 struct ATS_Address *new_address,
550 unsigned long long new_bw_in,
551 unsigned long long new_bw_out,
554 int notify = GNUNET_NO;
556 LOG (GNUNET_ERROR_TYPE_DEBUG, "set_active_suggestion()\n");
559 if (agent->address_inuse != new_address)
561 if (NULL != agent->address_inuse)
563 agent->address_inuse->active = GNUNET_NO;
564 agent->address_inuse->assigned_bw_in.value__ = htonl (0);
565 agent->address_inuse->assigned_bw_out.value__ = htonl (0);
567 if (NULL != new_address)
569 LOG (GNUNET_ERROR_TYPE_DEBUG, "set address active: %s\n", agent->active ? "yes" : "no");
570 new_address->active = agent->active;
571 new_address->assigned_bw_in.value__ = htonl (agent->bw_in);
572 new_address->assigned_bw_out.value__ = htonl (agent->bw_out);
574 notify |= GNUNET_YES;
580 if (new_address->active != agent->active)
582 new_address->active = agent->active;
586 if (agent->bw_in != new_bw_in)
588 agent->bw_in = new_bw_in;
589 new_address->assigned_bw_in.value__ = htonl (new_bw_out);
590 notify |= GNUNET_YES;
592 if (agent->bw_out != new_bw_out)
594 agent->bw_out = new_bw_out;
595 new_address->assigned_bw_out.value__ = htonl (new_bw_out);
596 notify |= GNUNET_YES;
600 if (notify && agent->active && (GNUNET_NO == silent))
604 solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls, new_address);
608 GNUNET_assert (0 == ntohl(agent->address_inuse->assigned_bw_in.value__));
609 GNUNET_assert (0 == ntohl(agent->address_inuse->assigned_bw_out.value__));
613 solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls, agent->address_inuse);
616 agent->address_inuse = new_address;
620 * Allocates a state vector and fills it with the features present
621 * @param solver the solver handle
622 * @return pointer to the state vector
625 envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
629 struct RIL_Network *net;
630 double *state = GNUNET_malloc (sizeof (double) * agent->m);
631 struct RIL_Address_Wrapped *cur_address;
632 const double *properties;
634 for (i = 0; i < solver->networks_count; i++)
636 net = &solver->network_entries[i];
637 state[i * RIL_FEATURES_NETWORK_COUNT + 0] = (double) net->bw_in_assigned;
638 state[i * RIL_FEATURES_NETWORK_COUNT + 1] = (double) net->bw_in_available;
639 state[i * RIL_FEATURES_NETWORK_COUNT + 2] = (double) net->bw_out_assigned;
640 state[i * RIL_FEATURES_NETWORK_COUNT + 3] = (double) net->bw_out_available;
643 i = i * RIL_FEATURES_NETWORK_COUNT; //first address feature
645 for (cur_address = agent->addresses_head; NULL != cur_address; cur_address = cur_address->next)
647 state[i++] = cur_address->address_naked->active;
648 state[i++] = cur_address->address_naked->active ? agent->bw_in : 0;
649 state[i++] = cur_address->address_naked->active ? agent->bw_out : 0;
650 properties = solver->callbacks->get_properties (solver->callbacks->get_properties_cls, cur_address->address_naked);
651 for (k = 0; k < GNUNET_ATS_QualityPropertiesCount; k++)
653 state[i++] = properties[k];
661 * For all networks a peer has an address in, this gets the maximum bandwidth which could
662 * theoretically be available in one of the networks. This is used for bandwidth normalization.
663 * @param solver the solver handle
664 * @param agent the agent handle
665 * @param direction_in whether the inbound bandwidth should be considered. Returns the maximum outbound bandwidth if GNUNET_NO
667 static long long unsigned
668 ril_get_max_bw(struct RIL_Peer_Agent *agent, int direction_in)
671 * get the maximum bandwidth possible for a peer, e.g. among all addresses which addresses'
672 * network could provide the maximum bandwidth if all that bandwidth was used on that one peer.
675 struct RIL_Address_Wrapped *cur;
676 struct RIL_Network *net;
678 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
680 net = cur->address_naked->solver_information;
683 if (net->bw_in_available > max)
685 max = net->bw_in_available;
690 if (net->bw_out_available > max)
692 max = net->bw_out_available;
700 * Gets the reward of the last performed step
701 * @param solver solver handle
705 envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
708 * Match the preferences of the peer with the current assignment.
710 const double *preferences;
711 const double *properties;
712 double pref_match = 0;
714 struct RIL_Network *net;
716 preferences = solver->callbacks->get_preferences (solver->callbacks->get_preferences_cls, &agent->peer);
717 properties = solver->callbacks->get_properties (solver->callbacks->get_properties_cls,
718 agent->address_inuse);
719 pref_match += preferences[GNUNET_ATS_PREFERENCE_LATENCY] * properties[GNUNET_ATS_QUALITY_NET_DELAY];
720 bw_norm = GNUNET_MAX(2, (((
721 ((double) agent->bw_in / (double) ril_get_max_bw(agent, GNUNET_YES)) +
722 ((double) agent->bw_out / (double) ril_get_max_bw(agent, GNUNET_NO))
725 pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * bw_norm;
727 net = agent->address_inuse->solver_information;
728 if ((net->bw_in_assigned > net->bw_in_available) || net->bw_out_assigned > net->bw_out_available)
737 * Doubles the bandwidth for the active address
738 * @param solver solver handle
739 * @param agent agent handle
740 * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise the outbound bandwidth
743 envi_action_bw_double (struct GAS_RIL_Handle *solver,
744 struct RIL_Peer_Agent *agent,
749 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in * 2,
750 agent->bw_out, GNUNET_NO);
754 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in,
755 agent->bw_out * 2, GNUNET_NO);
760 * Cuts the bandwidth for the active address in half. The least amount of bandwidth suggested, is
761 * the minimum bandwidth for a peer, in order to not invoke a disconnect.
762 * @param solver solver handle
763 * @param agent agent handle
764 * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise change the outbound
768 envi_action_bw_halven (struct GAS_RIL_Handle *solver,
769 struct RIL_Peer_Agent *agent,
772 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
773 unsigned long long new_bw;
777 new_bw = agent->bw_in / 2;
780 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, GNUNET_NO);
784 new_bw = agent->bw_out / 2;
787 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, GNUNET_NO);
792 * Increases the bandwidth by 5 times the minimum bandwidth for the active address.
793 * @param solver solver handle
794 * @param agent agent handle
795 * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise change the outbound
799 envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in)
801 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
805 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in + (5 * min_bw),
806 agent->bw_out, GNUNET_NO);
810 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in,
811 agent->bw_out + (5 * min_bw), GNUNET_NO);
816 * Decreases the bandwidth by 5 times the minimum bandwidth for the active address. The least amount
817 * of bandwidth suggested, is the minimum bandwidth for a peer, in order to not invoke a disconnect.
818 * @param solver solver handle
819 * @param agent agent handle
820 * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise change the outbound
824 envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in)
826 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
827 unsigned long long new_bw;
831 new_bw = agent->bw_in - (5 * min_bw);
834 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, GNUNET_NO);
838 new_bw = agent->bw_out - (5 * min_bw);
841 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, GNUNET_NO);
846 * Switches to the address given by its index
847 * @param solver solver handle
848 * @param agent agent handle
849 * @param address_index index of the address as it is saved in the agent's list, starting with zero
852 envi_action_address_switch (struct GAS_RIL_Handle *solver,
853 struct RIL_Peer_Agent *agent,
854 unsigned int address_index)
856 struct RIL_Address_Wrapped *cur;
859 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
861 if (i == address_index)
863 envi_set_active_suggestion (solver, agent, cur->address_naked, agent->bw_in, agent->bw_out, GNUNET_NO);
870 //no address with address_index exists, in this case this action should not be callable
871 GNUNET_assert(GNUNET_NO);
875 * Puts the action into effect by calling the according function
876 * @param solver solver handle
877 * @param action action to perform by the solver
880 envi_do_action (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int action)
882 unsigned int address_index;
886 case RIL_ACTION_NOTHING:
888 case RIL_ACTION_BW_IN_DBL:
889 envi_action_bw_double (solver, agent, GNUNET_YES);
891 case RIL_ACTION_BW_IN_HLV:
892 envi_action_bw_halven (solver, agent, GNUNET_YES);
894 case RIL_ACTION_BW_IN_INC:
895 envi_action_bw_inc (solver, agent, GNUNET_YES);
897 case RIL_ACTION_BW_IN_DEC:
898 envi_action_bw_dec (solver, agent, GNUNET_YES);
900 case RIL_ACTION_BW_OUT_DBL:
901 envi_action_bw_double (solver, agent, GNUNET_NO);
903 case RIL_ACTION_BW_OUT_HLV:
904 envi_action_bw_halven (solver, agent, GNUNET_NO);
906 case RIL_ACTION_BW_OUT_INC:
907 envi_action_bw_inc (solver, agent, GNUNET_NO);
909 case RIL_ACTION_BW_OUT_DEC:
910 envi_action_bw_dec (solver, agent, GNUNET_NO);
913 if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action
915 address_index = action - RIL_ACTION_TYPE_NUM;
917 GNUNET_assert(address_index >= 0);
919 address_index <= agent_address_get_index (agent, agent->addresses_tail->address_naked));
921 envi_action_address_switch (solver, agent, address_index);
924 // error - action does not exist
925 GNUNET_assert(GNUNET_NO);
930 * Performs one step of the Markov Decision Process. Other than in the literature the step starts
931 * after having done the last action a_old. It observes the new state s_next and the reward
932 * received. Then the coefficient update is done according to the SARSA or Q-learning method. The
933 * next action is put into effect.
934 * @param agent the agent performing the step
937 agent_step (struct RIL_Peer_Agent *agent)
939 int a_next = RIL_ACTION_INVALID;
943 s_next = envi_get_state (agent->envi, agent);
944 reward = envi_get_reward (agent->envi, agent);
946 LOG(GNUNET_ERROR_TYPE_DEBUG, "agent_step() with algorithm %s\n",
947 agent->envi->parameters.algorithm ? "Q" : "SARSA");
949 switch (agent->envi->parameters.algorithm)
952 agent_modify_eligibility (agent, RIL_E_SET);
953 if (agent_decide_exploration (agent))
955 a_next = agent_get_action_explore (agent, s_next);
959 a_next = agent_get_action_best (agent, s_next);
961 if (RIL_ACTION_INVALID != agent->a_old)
963 //updates weights with selected action (on-policy), if not first step
964 agent_update_weights (agent, reward, s_next, a_next);
969 a_next = agent_get_action_best (agent, s_next);
970 if (RIL_ACTION_INVALID != agent->a_old)
972 //updates weights with best action, disregarding actually selected action (off-policy), if not first step
973 agent_update_weights (agent, reward, s_next, a_next);
975 if (agent_decide_exploration (agent))
977 a_next = agent_get_action_explore (agent, s_next);
978 agent_modify_eligibility (agent, RIL_E_ZERO);
982 a_next = agent_get_action_best (agent, s_next);
983 agent_modify_eligibility (agent, RIL_E_SET);
988 GNUNET_assert(RIL_ACTION_INVALID != a_next);
990 agent_modify_eligibility (agent, RIL_E_ACCUMULATE);
992 envi_do_action (agent->envi, agent, a_next);
994 GNUNET_free(agent->s_old);
995 agent->s_old = s_next;
996 agent->a_old = a_next;
998 agent->step_count += 1;
1002 * Cycles through all agents and lets the active ones do a step. Schedules the next step.
1003 * @param solver the solver handle
1004 * @param tc task context for the scheduler
1007 ril_periodic_step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1009 struct GAS_RIL_Handle *solver = cls;
1010 struct RIL_Peer_Agent *cur;
1012 LOG(GNUNET_ERROR_TYPE_DEBUG, "RIL step number %d\n", solver->step_count);
1014 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
1016 if (cur->active && cur->address_inuse)
1022 solver->step_count += 1;
1023 solver->next_step = GNUNET_SCHEDULER_add_delayed (solver->step_time, &ril_periodic_step, solver);
1027 * Initialize an agent without addresses and its knowledge base
1028 * @param s ril solver
1029 * @param peer the one in question
1030 * @return handle to the new agent
1032 static struct RIL_Peer_Agent *
1033 agent_init (void *s, const struct GNUNET_PeerIdentity *peer)
1036 struct GAS_RIL_Handle * solver = s;
1037 struct RIL_Peer_Agent * agent = GNUNET_malloc (sizeof (struct RIL_Peer_Agent));
1039 agent->envi = solver;
1040 agent->peer = *peer;
1041 agent->step_count = 0;
1042 agent->active = GNUNET_NO;
1043 agent->n = RIL_ACTION_TYPE_NUM;
1044 agent->m = solver->networks_count * RIL_FEATURES_NETWORK_COUNT;
1045 agent->W = (double **) GNUNET_malloc (sizeof (double) * agent->n);
1046 for (i = 0; i < agent->n; i++)
1048 agent->W[i] = (double *) GNUNET_malloc (sizeof (double) * agent->m);
1050 agent->a_old = RIL_ACTION_INVALID;
1051 agent->s_old = envi_get_state (solver, agent);
1052 agent->e = (double *) GNUNET_malloc (sizeof (double) * agent->m);
1053 agent_modify_eligibility (agent, RIL_E_ZERO);
1055 GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, agent);
1062 * @param s solver handle
1063 * @param agent the agent to retire
1066 agent_die (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1070 for (i = 0; i < agent->n; i++)
1072 GNUNET_free(agent->W[i]);
1074 GNUNET_free(agent->W);
1075 GNUNET_free(agent->e);
1076 GNUNET_free(agent->s_old);
1081 * Returns the agent for a peer
1082 * @param s solver handle
1083 * @param peer identity of the peer
1084 * @param create whether to create an agent if none is allocated yet
1087 static struct RIL_Peer_Agent *
1088 ril_get_agent (struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity *peer, int create)
1090 struct RIL_Peer_Agent *cur;
1092 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
1094 if (0 == memcmp (peer,
1096 sizeof (struct GNUNET_PeerIdentity)))
1104 return agent_init (solver, peer);
1110 * Lookup network struct by type
1112 * @param s the solver handle
1113 * @param type the network type
1114 * @return the network struct
1116 static struct RIL_Network *
1117 ril_get_network (struct GAS_RIL_Handle *s, uint32_t type)
1121 for (i = 0; i < s->networks_count; i++)
1123 if (s->network_entries[i].type == type)
1125 return &s->network_entries[i];
1132 * Determine whether at least the minimum bandwidth is set for the network. Otherwise the network is
1133 * considered inactive and not used. Addresses in an inactive network are ignored.
1134 * @param solver solver handle
1135 * @param network the network type
1139 ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network_Type network)
1141 struct RIL_Network *net;
1142 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1144 net = ril_get_network (solver, network);
1145 if (net->bw_out_available < min_bw)
1151 * Cuts a slice out of a vector of elements. This is used to decrease the size of the matrix storing
1152 * the reward function approximation. It copies the memory, which is not cut, to the new vector,
1153 * frees the memory of the old vector, and redirects the pointer to the new one.
1154 * @param old pointer to the pointer to the first element of the vector
1155 * @param element_size byte size of the vector elements
1156 * @param hole_start the first element to cut out
1157 * @param hole_length the number of elements to cut out
1158 * @param old_length the length of the old vector
1161 ril_cut_from_vector (void **old,
1162 size_t element_size,
1163 unsigned int hole_start,
1164 unsigned int hole_length,
1165 unsigned int old_length)
1168 char *oldptr = (char *) *old;
1170 unsigned int bytes_before;
1171 unsigned int bytes_hole;
1172 unsigned int bytes_after;
1175 GNUNET_assert(old_length > hole_length);
1176 GNUNET_assert(old_length >= (hole_start + hole_length));
1178 size = element_size * (old_length - hole_length);
1180 bytes_before = element_size * hole_start;
1181 bytes_hole = element_size * hole_length;
1182 bytes_after = element_size * (old_length - hole_start - hole_length);
1190 tmpptr = GNUNET_malloc (size);
1191 memcpy (tmpptr, oldptr, bytes_before);
1192 memcpy (tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole), bytes_after);
1198 *old = (void *) tmpptr;
1202 * Solver API functions
1203 * ---------------------------
1207 * Changes the preferences for a peer in the problem
1209 * @param solver the solver handle
1210 * @param peer the peer to change the preference for
1211 * @param kind the kind to change the preference
1212 * @param pref_rel the normalized preference value for this kind over all clients
1215 GAS_ril_address_change_preference (void *s,
1216 const struct GNUNET_PeerIdentity *peer,
1217 enum GNUNET_ATS_PreferenceKind kind,
1220 LOG(GNUNET_ERROR_TYPE_DEBUG,
1221 "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n",
1222 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), pref_rel);
1224 * Nothing to do here. Preferences are considered during reward calculation.
1229 * Init the reinforcement learning problem solver
1232 * network[i] contains the network type as type GNUNET_ATS_NetworkType[i]
1233 * out_quota[i] contains outbound quota for network type i
1234 * in_quota[i] contains inbound quota for network type i
1237 * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN}
1238 * network[2] == GNUNET_ATS_NET_LAN
1239 * out_quota[2] == 65353
1240 * in_quota[2] == 65353
1242 * @param cfg configuration handle
1243 * @param stats the GNUNET_STATISTICS handle
1244 * @param network array of GNUNET_ATS_NetworkType with length dest_length
1245 * @param addresses hashmap containing all addresses
1246 * @param out_quota array of outbound quotas
1247 * @param in_quota array of outbound quota
1248 * @param dest_length array length for quota arrays
1249 * @param bw_changed_cb callback for changed bandwidth amounts
1250 * @param bw_changed_cb_cls cls for callback
1251 * @param get_preference callback to get relative preferences for a peer
1252 * @param get_preference_cls cls for callback to get relative preferences
1253 * @param get_properties_cls for callback to get relative properties
1254 * @param get_properties_cls cls for callback to get relative properties
1255 * @return handle for the solver on success, NULL on fail
1258 GAS_ril_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1259 const struct GNUNET_STATISTICS_Handle *stats,
1260 const struct GNUNET_CONTAINER_MultiPeerMap *addresses,
1262 unsigned long long *out_quota,
1263 unsigned long long *in_quota,
1265 GAS_bandwidth_changed_cb bw_changed_cb,
1266 void *bw_changed_cb_cls,
1267 GAS_get_preferences get_preference,
1268 void *get_preference_cls,
1269 GAS_get_properties get_properties,
1270 void *get_properties_cls)
1273 unsigned long long tmp;
1275 struct RIL_Network * cur;
1276 struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
1278 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
1280 GNUNET_assert(NULL != cfg);
1281 GNUNET_assert(NULL != stats);
1282 GNUNET_assert(NULL != network);
1283 GNUNET_assert(NULL != bw_changed_cb);
1284 GNUNET_assert(NULL != get_preference);
1285 GNUNET_assert(NULL != get_properties);
1288 != GNUNET_CONFIGURATION_get_value_time (cfg, "ats", "RIL_STEP_TIME", &solver->step_time))
1290 solver->step_time = RIL_DEFAULT_STEP_TIME;
1292 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "RIL_ALGORITHM", &string)
1293 && NULL != string && 0 == strcmp (string, "SARSA"))
1295 solver->parameters.algorithm = RIL_ALGO_SARSA;
1299 solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM;
1301 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_DISCOUNT_FACTOR", &tmp))
1303 solver->parameters.gamma = (double) tmp / 100;
1307 solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_FACTOR;
1309 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_GRADIENT_STEP_SIZE", &tmp))
1311 solver->parameters.alpha = (double) tmp / 100;
1315 solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
1317 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_TRACE_DECAY", &tmp))
1319 solver->parameters.lambda = (double) tmp / 100;
1323 solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY;
1326 solver->stats = (struct GNUNET_STATISTICS_Handle *) stats;
1327 solver->callbacks = GNUNET_malloc (sizeof (struct RIL_Callbacks));
1328 solver->callbacks->bw_changed = bw_changed_cb;
1329 solver->callbacks->bw_changed_cls = bw_changed_cb_cls;
1330 solver->callbacks->get_preferences = get_preference;
1331 solver->callbacks->get_preferences_cls = get_preference_cls;
1332 solver->callbacks->get_properties = get_properties;
1333 solver->callbacks->get_properties_cls = get_properties_cls;
1334 solver->networks_count = dest_length;
1335 solver->network_entries = GNUNET_malloc (dest_length * sizeof (struct RIL_Network));
1336 solver->bulk_lock = GNUNET_NO;
1337 solver->addresses = addresses;
1338 solver->step_count = 0;
1340 for (c = 0; c < dest_length; c++)
1342 cur = &solver->network_entries[c];
1343 cur->type = network[c];
1344 cur->bw_in_available = in_quota[c];
1345 cur->bw_in_assigned = 0;
1346 cur->bw_out_available = out_quota[c];
1347 cur->bw_out_assigned = 0;
1350 solver->next_step = GNUNET_SCHEDULER_add_delayed (
1351 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_millisecond_ (), 1000),
1352 &ril_periodic_step, solver);
1358 * Shutdown the reinforcement learning problem solver
1360 * @param solver the respective handle to shutdown
1363 GAS_ril_done (void * solver)
1365 struct GAS_RIL_Handle *s = solver;
1366 struct RIL_Peer_Agent *cur_agent;
1367 struct RIL_Peer_Agent *next_agent;
1369 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
1371 cur_agent = s->agents_head;
1372 while (NULL != cur_agent)
1374 next_agent = cur_agent->next;
1375 GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent);
1376 agent_die (s, cur_agent);
1377 cur_agent = next_agent;
1380 GNUNET_SCHEDULER_cancel (s->next_step);
1381 GNUNET_free(s->callbacks);
1382 GNUNET_free(s->network_entries);
1387 * Add a single address within a network to the solver
1389 * @param solver the solver Handle
1390 * @param address the address to add
1391 * @param network network type of this address
1394 GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network)
1396 struct GAS_RIL_Handle *s = solver;
1397 struct RIL_Peer_Agent *agent;
1398 struct RIL_Address_Wrapped *address_wrapped;
1399 struct RIL_Network *net;
1406 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1408 net = ril_get_network (s, network);
1409 address->solver_information = net;
1411 if (!ril_network_is_active (s, network))
1413 LOG(GNUNET_ERROR_TYPE_DEBUG,
1414 "API_address_add() Did not add %s address %p for peer '%s', network does not have enough bandwidth\n",
1415 address->plugin, address->addr, GNUNET_i2s (&address->peer));
1419 agent = ril_get_agent (s, &address->peer, GNUNET_YES);
1422 address_wrapped = GNUNET_malloc (sizeof (struct RIL_Address_Wrapped));
1423 address_wrapped->address_naked = address;
1424 GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped);
1426 //increase size of W
1427 m_new = agent->m + RIL_FEATURES_ADDRESS_COUNT;
1429 n_new = agent->n + 1;
1432 GNUNET_array_grow(agent->W, agent->n, n_new);
1433 for (i = 0; i < n_new; i++)
1438 GNUNET_array_grow(agent->W[i], agent->m, m_new);
1443 GNUNET_array_grow(agent->W[i], zero, m_new);
1447 //increase size of old state vector
1449 GNUNET_array_grow(agent->s_old, agent->m, m_new); //TODO initialize new state features?
1452 GNUNET_array_grow(agent->e, agent->m, m_new);
1454 if (NULL == agent->address_inuse)
1456 net->bw_in_assigned += min_bw;
1457 net->bw_out_assigned += min_bw;
1458 envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO);
1461 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %p for peer '%s'\n",
1462 address->active ? "active" : "inactive",
1463 address->plugin, address->addr, GNUNET_i2s (&address->peer));
1467 * Remove an address from the solver
1469 * @param solver the solver handle
1470 * @param address the address to remove
1471 * @param session_only delete only session not whole address
1474 GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only)
1476 //TODO? use session as feature
1477 struct GAS_RIL_Handle *s = solver;
1478 struct RIL_Peer_Agent *agent;
1479 struct RIL_Address_Wrapped *address_wrapped;
1480 int address_was_used = address->active;
1485 struct RIL_Network *net;
1486 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1488 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() Delete %s%s %s address %p for peer '%s'\n",
1489 session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin,
1490 address->addr, GNUNET_i2s (&address->peer));
1492 agent = ril_get_agent (s, &address->peer, GNUNET_NO);
1495 net = address->solver_information;
1496 GNUNET_assert(!ril_network_is_active (s, net->type));
1497 LOG(GNUNET_ERROR_TYPE_DEBUG,
1498 "No agent allocated for peer yet, since address was in inactive network\n");
1502 address_index = agent_address_get_index (agent, address);
1503 address_wrapped = agent_address_get (agent, address);
1505 if (NULL == address_wrapped)
1507 net = address->solver_information;
1508 GNUNET_assert(!ril_network_is_active (s, net->type));
1509 LOG(GNUNET_ERROR_TYPE_DEBUG,
1510 "Address not considered by agent, address was in inactive network\n");
1514 GNUNET_CONTAINER_DLL_remove(agent->addresses_head, agent->addresses_tail, address_wrapped);
1515 GNUNET_free(address_wrapped);
1518 m_new = agent->m - RIL_FEATURES_ADDRESS_COUNT;
1519 n_new = agent->n - 1;
1521 for (i = 0; i < agent->n; i++)
1523 ril_cut_from_vector ((void **) &agent->W[i], sizeof(double),
1524 ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m);
1526 GNUNET_free (agent->W[RIL_ACTION_TYPE_NUM + address_index]);
1527 ril_cut_from_vector ((void **) &agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index,
1529 //correct last action
1530 if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index))
1534 else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index))
1536 agent->a_old = RIL_ACTION_INVALID;
1538 //decrease old state vector and eligibility vector
1539 ril_cut_from_vector ((void **) &agent->s_old, sizeof(double),
1540 ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m);
1541 ril_cut_from_vector ((void **) &agent->e, sizeof(double),
1542 ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m);
1546 LOG (GNUNET_ERROR_TYPE_DEBUG, "address was used: %s\n", address_was_used ? "yes" : "no");
1548 if (address_was_used)
1550 net = address->solver_information;
1551 net->bw_in_assigned -= agent->bw_in;
1552 net->bw_out_assigned -= agent->bw_out;
1554 if (NULL != agent->addresses_head) //if peer has an address left, use it
1556 LOG (GNUNET_ERROR_TYPE_DEBUG, "address left: %p\n", agent->addresses_head->address_naked->addr);
1557 //TODO? check if network/bandwidth update can be done more clever/elegant at different function
1558 envi_set_active_suggestion (s, agent, agent->addresses_head->address_naked, min_bw, min_bw, GNUNET_NO);
1559 net = agent->addresses_head->address_naked->solver_information;
1560 net->bw_in_assigned -= min_bw;
1561 net->bw_out_assigned -= min_bw;
1565 LOG (GNUNET_ERROR_TYPE_DEBUG, "no address left => disconnect\n");
1567 envi_set_active_suggestion (s, agent, NULL, 0, 0, GNUNET_NO);
1571 LOG(GNUNET_ERROR_TYPE_DEBUG, "Address deleted\n");
1575 * Transport properties for this address have changed
1577 * @param solver solver handle
1578 * @param address the address
1579 * @param type the ATSI type in HBO
1580 * @param abs_value the absolute value of the property
1581 * @param rel_value the normalized value
1584 GAS_ril_address_property_changed (void *solver,
1585 struct ATS_Address *address,
1590 LOG(GNUNET_ERROR_TYPE_DEBUG,
1591 "API_address_property_changed() Property '%s' for peer '%s' address %p changed "
1592 "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
1593 address->addr, rel_value);
1595 * Nothing to do here, properties are considered in every reward calculation
1600 * Transport session for this address has changed
1602 * NOTE: values in addresses are already updated
1604 * @param solver solver handle
1605 * @param address the address
1606 * @param cur_session the current session
1607 * @param new_session the new session
1610 GAS_ril_address_session_changed (void *solver,
1611 struct ATS_Address *address,
1612 uint32_t cur_session,
1613 uint32_t new_session)
1615 //TODO? consider session change in solver behaviour
1617 * Potentially add session activity as a feature in state vector
1619 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n");
1623 * Usage for this address has changed
1625 * NOTE: values in addresses are already updated
1627 * @param solver solver handle
1628 * @param address the address
1629 * @param in_use usage state
1632 GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use)
1634 /* Nothing to do here */
1635 LOG(GNUNET_ERROR_TYPE_DEBUG,
1636 "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n",
1637 address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED");
1641 * Network scope for this address has changed
1643 * NOTE: values in addresses are already updated
1645 * @param solver solver handle
1646 * @param address the address
1647 * @param current_network the current network
1648 * @param new_network the new network
1651 GAS_ril_address_change_network (void *solver,
1652 struct ATS_Address *address,
1653 uint32_t current_network,
1654 uint32_t new_network)
1656 struct GAS_RIL_Handle *s = solver;
1657 struct RIL_Peer_Agent *agent;
1658 struct RIL_Network *net;
1659 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1661 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_change_network() Network type changed, moving "
1662 "%s address of peer %s from '%s' to '%s'\n",
1663 (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer),
1664 GNUNET_ATS_print_network_type (current_network), GNUNET_ATS_print_network_type (new_network));
1666 if (address->active && !ril_network_is_active (solver, new_network))
1668 GAS_ril_address_delete (solver, address, GNUNET_NO);
1672 agent = ril_get_agent (s, &address->peer, GNUNET_NO);
1675 GNUNET_assert(!ril_network_is_active (solver, current_network));
1677 GAS_ril_address_add (s, address, new_network);
1681 net = ril_get_network (s, current_network);
1682 net->bw_in_assigned -= agent->bw_in;
1683 net->bw_out_assigned -= agent->bw_out;
1685 net = ril_get_network (s, new_network);
1686 net->bw_in_assigned -= min_bw;
1687 net->bw_out_assigned -= min_bw;
1688 address->solver_information = net;
1692 * Get application feedback for a peer
1694 * @param solver the solver handle
1695 * @param application the application
1696 * @param peer the peer to change the preference for
1697 * @param scope the time interval for this feedback: [now - scope .. now]
1698 * @param kind the kind to change the preference
1699 * @param score the score
1702 GAS_ril_address_preference_feedback (void *solver,
1704 const struct GNUNET_PeerIdentity *peer,
1705 const struct GNUNET_TIME_Relative scope,
1706 enum GNUNET_ATS_PreferenceKind kind,
1709 //TODO! talk to Matthias about feedback
1710 LOG(GNUNET_ERROR_TYPE_DEBUG,
1711 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
1712 "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN",
1713 GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000);
1717 * Start a bulk operation
1719 * @param solver the solver
1722 GAS_ril_bulk_start (void *solver)
1725 * Since new calculations of the assignment are not triggered by a change of preferences, as it
1726 * happens in the proportional and the mlp solver, there is no need to block this solver.
1731 * Bulk operation done
1734 GAS_ril_bulk_stop (void *solver)
1737 * Since new calculations of the assignment are not triggered by a change of preferences, as it
1738 * happens in the proportional and the mlp solver, there is no need to block this solver.
1743 * Get the preferred address for a specific peer
1745 * @param solver the solver handle
1746 * @param peer the identity of the peer
1748 const struct ATS_Address *
1749 GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
1752 * activate agent, return currently chosen address
1754 struct GAS_RIL_Handle *s = solver;
1755 struct RIL_Peer_Agent *agent;
1757 agent = ril_get_agent (s, peer, GNUNET_YES);
1759 agent->active = GNUNET_YES;
1761 envi_set_active_suggestion(s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES);
1763 if (agent->address_inuse)
1765 LOG(GNUNET_ERROR_TYPE_DEBUG,
1766 "API_get_preferred_address() Activated agent for peer '%s' with %s address %p\n",
1767 GNUNET_i2s (peer), agent->address_inuse->plugin, agent->address_inuse->addr);
1771 LOG(GNUNET_ERROR_TYPE_DEBUG,
1772 "API_get_preferred_address() Activated agent for peer '%s', but no address available\n", GNUNET_i2s (peer));
1775 return agent->address_inuse;
1779 * Stop notifying about address and bandwidth changes for this peer
1781 * @param solver the solver handle
1782 * @param peer the peer
1785 GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
1787 struct GAS_RIL_Handle *s = solver;
1788 struct RIL_Peer_Agent *agent;
1790 agent = ril_get_agent (s, peer, GNUNET_NO);
1797 if (GNUNET_NO == agent->active)
1803 agent->active = GNUNET_NO;
1804 envi_set_active_suggestion(s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES);
1806 LOG(GNUNET_ERROR_TYPE_DEBUG,
1807 "API_stop_get_preferred_address() Paused agent for peer '%s' with %s address\n",
1808 GNUNET_i2s (peer), agent->address_inuse->plugin);
1811 /* end of gnunet-service-ats-solver_ril.c */