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/libgnunet_plugin_ats_ril.c
23 * @brief ATS reinforcement learning solver
24 * @author Fabian Oehlmann
25 * @author Matthias Wachs
27 #include "libgnunet_plugin_ats_ril.h"
29 #define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__)
31 #define RIL_ACTION_INVALID -1
32 #define RIL_FEATURES_ADDRESS_COUNT (3 + GNUNET_ATS_QualityPropertiesCount)
33 #define RIL_FEATURES_NETWORK_COUNT 4
35 #define RIL_DEFAULT_STEP_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 3000)
36 #define RIL_DEFAULT_ALGORITHM RIL_ALGO_Q
37 #define RIL_DEFAULT_DISCOUNT_FACTOR 0.5
38 #define RIL_DEFAULT_GRADIENT_STEP_SIZE 0.4
39 #define RIL_DEFAULT_TRACE_DECAY 0.6
40 #define RIL_EXPLORE_RATIO 0.1
43 * ATS reinforcement learning solver
49 * The actions, how an agent can manipulate the current assignment. I.e. how the bandwidth can be
50 * changed for the currently chosen address. Not depicted in the enum are the actions of switching
51 * to a particular address. The action of switching to address with index i is depicted by the
52 * number (RIL_ACTION_TYPE_NUM + i).
56 RIL_ACTION_NOTHING = 0,
57 RIL_ACTION_BW_IN_DBL = 1,
58 RIL_ACTION_BW_IN_HLV = 2,
59 RIL_ACTION_BW_IN_INC = 3,
60 RIL_ACTION_BW_IN_DEC = 4,
61 RIL_ACTION_BW_OUT_DBL = 5,
62 RIL_ACTION_BW_OUT_HLV = 6,
63 RIL_ACTION_BW_OUT_INC = 7,
64 RIL_ACTION_BW_OUT_DEC = 8,
65 RIL_ACTION_TYPE_NUM = 9
74 enum RIL_E_Modification
83 * Global learning parameters
85 struct RIL_Learning_Parameters
88 * The TD-algorithm to use
90 enum RIL_Algorithm algorithm;
93 * Learning discount factor in the TD-update
98 * Gradient-descent step-size
103 * Trace-decay factor for eligibility traces
109 * Wrapper for addresses to store them in agent's linked list
111 struct RIL_Address_Wrapped
116 struct RIL_Address_Wrapped *next;
121 struct RIL_Address_Wrapped *prev;
126 struct ATS_Address *address_naked;
129 struct RIL_Peer_Agent
132 * Next agent in solver's linked list
134 struct RIL_Peer_Agent *next;
137 * Previous agent in solver's linked list
139 struct RIL_Peer_Agent *prev;
144 struct GAS_RIL_Handle *envi;
149 struct GNUNET_PeerIdentity peer;
152 * Whether the agent is active or not
154 int active; //TODO? rename into something better. It reflects the state whether get_preferred_address() has been called for the according peer or not
157 * Number of performed time-steps
159 unsigned long long step_count;
162 * Experience matrix W
167 * Number of rows of W / Number of state-vector features
172 * Number of columns of W / Number of actions
177 * Last perceived state feature vector
187 * Eligibility trace vector
194 struct ATS_Address * address_inuse;
197 * Head of addresses DLL
199 struct RIL_Address_Wrapped * addresses_head;
202 * Tail of addresses DLL
204 struct RIL_Address_Wrapped * addresses_tail;
207 * Inbound bandwidth assigned by the agent
209 unsigned long long bw_in;
212 * Outbound bandwidth assigned by the agent
214 unsigned long long bw_out;
222 enum GNUNET_ATS_Network_Type type;
225 * Total available inbound bandwidth
227 unsigned long long bw_in_available;
230 * Total assigned outbound bandwidth
232 unsigned long long bw_in_assigned;
235 * Total available outbound bandwidth
237 unsigned long long bw_out_available;
240 * Total assigned outbound bandwidth
242 unsigned long long bw_out_assigned;
248 * Bandwidth changed callback
250 GAS_bandwidth_changed_cb bw_changed;
253 * Bandwidth changed callback cls
255 void *bw_changed_cls;
258 * ATS function to get preferences for a peer
260 GAS_get_preferences get_preferences;
263 * Closure for ATS function to get preferences
265 void *get_preferences_cls;
268 * ATS function to get properties of an address
270 GAS_get_properties get_properties;
273 * Closure for ATS function to get properties
275 void *get_properties_cls;
279 * A handle for the reinforcement learning solver
281 struct GAS_RIL_Handle
286 struct GNUNET_ATS_PluginEnvironment *plugin_envi;
291 struct GNUNET_STATISTICS_Handle *stats;
294 * Hashmap containing all valid addresses
296 const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
299 * Callbacks for the solver
301 struct RIL_Callbacks *callbacks;
304 * Number of performed time-steps
306 unsigned long long step_count;
309 * Interval time between steps in milliseconds //TODO? Future Work: Heterogeneous stepping among agents
311 struct GNUNET_TIME_Relative step_time;
314 * Task identifier of the next time-step to be executed
316 GNUNET_SCHEDULER_TaskIdentifier next_step;
319 * Learning parameters
321 struct RIL_Learning_Parameters parameters;
324 * Array of networks with global assignment state
326 struct RIL_Network * network_entries;
331 unsigned int networks_count;
334 * List of active peer-agents
336 struct RIL_Peer_Agent * agents_head;
337 struct RIL_Peer_Agent * agents_tail;
342 * ---------------------------
346 * Estimate the current action-value for state s and action a
347 * @param agent agent performing the estimation
350 * @return estimation value
353 agent_estimate_q (struct RIL_Peer_Agent *agent, double *state, int action)
358 for (i = 0; i < agent->m; i++)
360 result += state[i] * agent->W[action][i];
367 * Decide whether to do exploration (i.e. taking a new action) or exploitation (i.e. taking the
368 * currently estimated best action) in the current step
369 * @param agent agent performing the step
370 * @return yes, if exploring
373 agent_decide_exploration (struct RIL_Peer_Agent *agent)
375 //TODO? Future Work: Improve exploration/exploitation trade-off by different mechanisms than e-greedy
377 * An e-greedy replacement could be based on the accuracy of the prediction of the Q-value
379 double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
380 UINT32_MAX) / (double) UINT32_MAX;
382 if (r < RIL_EXPLORE_RATIO)
390 * Get the index of the address in the agent's list.
391 * @param agent agent handle
392 * @param address address handle
393 * @return the index, starting with zero
396 agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *address)
399 struct RIL_Address_Wrapped *cur;
402 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
405 if (cur->address_naked == address)
415 * Gets the wrapped address from the agent's list
416 * @param agent agent handle
417 * @param address address handle
418 * @return wrapped address
420 static struct RIL_Address_Wrapped *
421 agent_address_get (struct RIL_Peer_Agent *agent, struct ATS_Address *address)
423 struct RIL_Address_Wrapped *cur;
425 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
427 if (cur->address_naked == address)
437 * Gets the action, with the maximal estimated Q-value (i.e. the one currently estimated to bring the
438 * most reward in the future)
439 * @param agent agent performing the calculation
440 * @param state the state from which to take the action
441 * @return the action promising most future reward
444 agent_get_action_best (struct RIL_Peer_Agent *agent, double *state)
447 int max_i = RIL_ACTION_INVALID;
449 double max_q = -DBL_MAX;
451 for (i = 0; i < agent->n; i++)
453 cur_q = agent_estimate_q (agent, state, i);
461 GNUNET_assert(RIL_ACTION_INVALID != max_i);
467 * Gets any action, to explore the action space from that state
468 * @param agent agent performing the calculation
469 * @param state the state from which to take the action
473 agent_get_action_explore (struct RIL_Peer_Agent *agent, double *state)
475 // TODO?: Future Work: Choose the action for exploration, which has been explored the least in this state
476 return GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, agent->n);
480 * Updates the weights (i.e. coefficients) of the weight vector in matrix W for action a
481 * @param agent the agent performing the update
482 * @param reward the reward received for the last action
483 * @param s_next the new state, the last step got the agent into
484 * @param a_prime the new
487 agent_update_weights (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a_prime)
491 double *theta = agent->W[agent->a_old];
493 delta = reward + agent_estimate_q (agent, s_next, a_prime)
494 - agent_estimate_q (agent, agent->s_old, agent->a_old);
495 for (i = 0; i < agent->m; i++)
497 theta[i] += agent->envi->parameters.alpha * delta * (agent->e)[i];
502 * Changes the eligibility trace vector e in various manners:
503 * RIL_E_ACCUMULATE - adds 1 to each component as in accumulating eligibility traces
504 * RIL_E_REPLACE - resets each component to 1 as in replacing traces
505 * RIL_E_SET - multiplies e with gamma and lambda as in the update rule
506 * RIL_E_ZERO - sets e to 0 as in Watkin's Q-learning algorithm when exploring and when initializing
511 agent_modify_eligibility (struct RIL_Peer_Agent *agent, enum RIL_E_Modification mod)
514 double *e = agent->e;
515 double gamma = agent->envi->parameters.gamma;
516 double lambda = agent->envi->parameters.lambda;
518 for (i = 0; i < agent->m; i++)
522 case RIL_E_ACCUMULATE:
529 e[i] = gamma * lambda;
539 * Changes the active assignment suggestion of the handler and invokes the bw_changed callback to
540 * notify ATS of its new decision.
541 * @param solver solver handle
542 * @param agent agent handle
543 * @param new_address the address which is to be used
544 * @param new_bw_in the new amount of inbound bandwidth set for this address
545 * @param new_bw_out the new amount of outbound bandwidth set for this address
546 * @param silent disables invocation of the bw_changed callback, if GNUNET_YES
549 envi_set_active_suggestion (struct GAS_RIL_Handle *solver,
550 struct RIL_Peer_Agent *agent,
551 struct ATS_Address *new_address,
552 unsigned long long new_bw_in,
553 unsigned long long new_bw_out,
556 int notify = GNUNET_NO;
558 LOG (GNUNET_ERROR_TYPE_DEBUG, "set_active_suggestion()\n");
561 if (agent->address_inuse != new_address)
563 if (NULL != agent->address_inuse)
565 agent->address_inuse->active = GNUNET_NO;
566 agent->address_inuse->assigned_bw_in.value__ = htonl (0);
567 agent->address_inuse->assigned_bw_out.value__ = htonl (0);
569 if (NULL != new_address)
571 LOG (GNUNET_ERROR_TYPE_DEBUG, "set address active: %s\n", agent->active ? "yes" : "no");
572 new_address->active = agent->active;
573 new_address->assigned_bw_in.value__ = htonl (agent->bw_in);
574 new_address->assigned_bw_out.value__ = htonl (agent->bw_out);
576 notify |= GNUNET_YES;
582 if (new_address->active != agent->active)
584 new_address->active = agent->active;
588 if (agent->bw_in != new_bw_in)
590 agent->bw_in = new_bw_in;
591 new_address->assigned_bw_in.value__ = htonl (new_bw_out);
592 notify |= GNUNET_YES;
594 if (agent->bw_out != new_bw_out)
596 agent->bw_out = new_bw_out;
597 new_address->assigned_bw_out.value__ = htonl (new_bw_out);
598 notify |= GNUNET_YES;
602 if (notify && agent->active && (GNUNET_NO == silent))
606 solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls, new_address);
610 GNUNET_assert (0 == ntohl(agent->address_inuse->assigned_bw_in.value__));
611 GNUNET_assert (0 == ntohl(agent->address_inuse->assigned_bw_out.value__));
615 solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls, agent->address_inuse);
618 agent->address_inuse = new_address;
622 * Allocates a state vector and fills it with the features present
623 * @param solver the solver handle
624 * @return pointer to the state vector
627 envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
631 struct RIL_Network *net;
632 double *state = GNUNET_malloc (sizeof (double) * agent->m);
633 struct RIL_Address_Wrapped *cur_address;
634 const double *properties;
636 for (i = 0; i < solver->networks_count; i++)
638 net = &solver->network_entries[i];
639 state[i * RIL_FEATURES_NETWORK_COUNT + 0] = (double) net->bw_in_assigned;
640 state[i * RIL_FEATURES_NETWORK_COUNT + 1] = (double) net->bw_in_available;
641 state[i * RIL_FEATURES_NETWORK_COUNT + 2] = (double) net->bw_out_assigned;
642 state[i * RIL_FEATURES_NETWORK_COUNT + 3] = (double) net->bw_out_available;
645 i = i * RIL_FEATURES_NETWORK_COUNT; //first address feature
647 for (cur_address = agent->addresses_head; NULL != cur_address; cur_address = cur_address->next)
649 state[i++] = cur_address->address_naked->active;
650 state[i++] = cur_address->address_naked->active ? agent->bw_in : 0;
651 state[i++] = cur_address->address_naked->active ? agent->bw_out : 0;
652 properties = solver->callbacks->get_properties (solver->callbacks->get_properties_cls, cur_address->address_naked);
653 for (k = 0; k < GNUNET_ATS_QualityPropertiesCount; k++)
655 state[i++] = properties[k];
663 * For all networks a peer has an address in, this gets the maximum bandwidth which could
664 * theoretically be available in one of the networks. This is used for bandwidth normalization.
665 * @param solver the solver handle
666 * @param agent the agent handle
667 * @param direction_in whether the inbound bandwidth should be considered. Returns the maximum outbound bandwidth if GNUNET_NO
669 static long long unsigned
670 ril_get_max_bw(struct RIL_Peer_Agent *agent, int direction_in)
673 * get the maximum bandwidth possible for a peer, e.g. among all addresses which addresses'
674 * network could provide the maximum bandwidth if all that bandwidth was used on that one peer.
677 struct RIL_Address_Wrapped *cur;
678 struct RIL_Network *net;
680 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
682 net = cur->address_naked->solver_information;
685 if (net->bw_in_available > max)
687 max = net->bw_in_available;
692 if (net->bw_out_available > max)
694 max = net->bw_out_available;
702 * Get the index of the quality-property in question
703 * @param type the quality property type
707 ril_find_property_index (uint32_t type)
709 int existing_types[] = GNUNET_ATS_QualityProperties;
711 for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
712 if (existing_types[c] == type)
714 return GNUNET_SYSERR;
718 * Gets the reward of the last performed step
719 * @param solver solver handle
723 envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
726 * Match the preferences of the peer with the current assignment.
728 const double *preferences;
729 const double *properties;
730 double pref_match = 0;
732 struct RIL_Network *net;
735 preferences = solver->callbacks->get_preferences (solver->callbacks->get_preferences_cls, &agent->peer);
736 properties = solver->callbacks->get_properties (solver->callbacks->get_properties_cls,
737 agent->address_inuse);
738 prop_index = ril_find_property_index(GNUNET_ATS_QUALITY_NET_DELAY);
739 pref_match += preferences[GNUNET_ATS_PREFERENCE_LATENCY] * properties[prop_index];
740 bw_norm = GNUNET_MAX(2, (((
741 ((double) agent->bw_in / (double) ril_get_max_bw(agent, GNUNET_YES)) +
742 ((double) agent->bw_out / (double) ril_get_max_bw(agent, GNUNET_NO))
745 pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * bw_norm;
747 net = agent->address_inuse->solver_information;
748 if ((net->bw_in_assigned > net->bw_in_available) || net->bw_out_assigned > net->bw_out_available)
757 * Doubles the bandwidth for the active address
758 * @param solver solver handle
759 * @param agent agent handle
760 * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise the outbound bandwidth
763 envi_action_bw_double (struct GAS_RIL_Handle *solver,
764 struct RIL_Peer_Agent *agent,
769 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in * 2,
770 agent->bw_out, GNUNET_NO);
774 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in,
775 agent->bw_out * 2, GNUNET_NO);
780 * Cuts the bandwidth for the active address in half. The least amount of bandwidth suggested, is
781 * the minimum bandwidth for a peer, in order to not invoke a disconnect.
782 * @param solver solver handle
783 * @param agent agent handle
784 * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise change the outbound
788 envi_action_bw_halven (struct GAS_RIL_Handle *solver,
789 struct RIL_Peer_Agent *agent,
792 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
793 unsigned long long new_bw;
797 new_bw = agent->bw_in / 2;
800 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, GNUNET_NO);
804 new_bw = agent->bw_out / 2;
807 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, GNUNET_NO);
812 * Increases the bandwidth by 5 times the minimum bandwidth for the active address.
813 * @param solver solver handle
814 * @param agent agent handle
815 * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise change the outbound
819 envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in)
821 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
825 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in + (5 * min_bw),
826 agent->bw_out, GNUNET_NO);
830 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in,
831 agent->bw_out + (5 * min_bw), GNUNET_NO);
836 * Decreases the bandwidth by 5 times the minimum bandwidth for the active address. The least amount
837 * of bandwidth suggested, is the minimum bandwidth for a peer, in order to not invoke a disconnect.
838 * @param solver solver handle
839 * @param agent agent handle
840 * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise change the outbound
844 envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in)
846 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
847 unsigned long long new_bw;
851 new_bw = agent->bw_in - (5 * min_bw);
854 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, GNUNET_NO);
858 new_bw = agent->bw_out - (5 * min_bw);
861 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, GNUNET_NO);
866 * Switches to the address given by its index
867 * @param solver solver handle
868 * @param agent agent handle
869 * @param address_index index of the address as it is saved in the agent's list, starting with zero
872 envi_action_address_switch (struct GAS_RIL_Handle *solver,
873 struct RIL_Peer_Agent *agent,
874 unsigned int address_index)
876 struct RIL_Address_Wrapped *cur;
879 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
881 if (i == address_index)
883 envi_set_active_suggestion (solver, agent, cur->address_naked, agent->bw_in, agent->bw_out, GNUNET_NO);
890 //no address with address_index exists, in this case this action should not be callable
891 GNUNET_assert(GNUNET_NO);
895 * Puts the action into effect by calling the according function
896 * @param solver solver handle
897 * @param action action to perform by the solver
900 envi_do_action (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int action)
902 unsigned int address_index;
906 case RIL_ACTION_NOTHING:
908 case RIL_ACTION_BW_IN_DBL:
909 envi_action_bw_double (solver, agent, GNUNET_YES);
911 case RIL_ACTION_BW_IN_HLV:
912 envi_action_bw_halven (solver, agent, GNUNET_YES);
914 case RIL_ACTION_BW_IN_INC:
915 envi_action_bw_inc (solver, agent, GNUNET_YES);
917 case RIL_ACTION_BW_IN_DEC:
918 envi_action_bw_dec (solver, agent, GNUNET_YES);
920 case RIL_ACTION_BW_OUT_DBL:
921 envi_action_bw_double (solver, agent, GNUNET_NO);
923 case RIL_ACTION_BW_OUT_HLV:
924 envi_action_bw_halven (solver, agent, GNUNET_NO);
926 case RIL_ACTION_BW_OUT_INC:
927 envi_action_bw_inc (solver, agent, GNUNET_NO);
929 case RIL_ACTION_BW_OUT_DEC:
930 envi_action_bw_dec (solver, agent, GNUNET_NO);
933 if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action
935 address_index = action - RIL_ACTION_TYPE_NUM;
937 GNUNET_assert(address_index >= 0);
939 address_index <= agent_address_get_index (agent, agent->addresses_tail->address_naked));
941 envi_action_address_switch (solver, agent, address_index);
944 // error - action does not exist
945 GNUNET_assert(GNUNET_NO);
950 * Performs one step of the Markov Decision Process. Other than in the literature the step starts
951 * after having done the last action a_old. It observes the new state s_next and the reward
952 * received. Then the coefficient update is done according to the SARSA or Q-learning method. The
953 * next action is put into effect.
954 * @param agent the agent performing the step
957 agent_step (struct RIL_Peer_Agent *agent)
959 int a_next = RIL_ACTION_INVALID;
963 s_next = envi_get_state (agent->envi, agent);
964 reward = envi_get_reward (agent->envi, agent);
966 LOG(GNUNET_ERROR_TYPE_DEBUG, "agent_step() with algorithm %s\n",
967 agent->envi->parameters.algorithm ? "Q" : "SARSA");
969 switch (agent->envi->parameters.algorithm)
972 agent_modify_eligibility (agent, RIL_E_SET);
973 if (agent_decide_exploration (agent))
975 a_next = agent_get_action_explore (agent, s_next);
979 a_next = agent_get_action_best (agent, s_next);
981 if (RIL_ACTION_INVALID != agent->a_old)
983 //updates weights with selected action (on-policy), if not first step
984 agent_update_weights (agent, reward, s_next, a_next);
989 a_next = agent_get_action_best (agent, s_next);
990 if (RIL_ACTION_INVALID != agent->a_old)
992 //updates weights with best action, disregarding actually selected action (off-policy), if not first step
993 agent_update_weights (agent, reward, s_next, a_next);
995 if (agent_decide_exploration (agent))
997 a_next = agent_get_action_explore (agent, s_next);
998 agent_modify_eligibility (agent, RIL_E_ZERO);
1002 a_next = agent_get_action_best (agent, s_next);
1003 agent_modify_eligibility (agent, RIL_E_SET);
1008 GNUNET_assert(RIL_ACTION_INVALID != a_next);
1010 agent_modify_eligibility (agent, RIL_E_ACCUMULATE);
1012 envi_do_action (agent->envi, agent, a_next);
1014 GNUNET_free(agent->s_old);
1015 agent->s_old = s_next;
1016 agent->a_old = a_next;
1018 agent->step_count += 1;
1022 * Cycles through all agents and lets the active ones do a step. Schedules the next step.
1023 * @param solver the solver handle
1024 * @param tc task context for the scheduler
1027 ril_periodic_step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1029 struct GAS_RIL_Handle *solver = cls;
1030 struct RIL_Peer_Agent *cur;
1032 LOG(GNUNET_ERROR_TYPE_DEBUG, "RIL step number %d\n", solver->step_count);
1034 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
1036 if (cur->active && cur->address_inuse)
1042 solver->step_count += 1;
1043 solver->next_step = GNUNET_SCHEDULER_add_delayed (solver->step_time, &ril_periodic_step, solver);
1047 * Initialize an agent without addresses and its knowledge base
1048 * @param s ril solver
1049 * @param peer the one in question
1050 * @return handle to the new agent
1052 static struct RIL_Peer_Agent *
1053 agent_init (void *s, const struct GNUNET_PeerIdentity *peer)
1056 struct GAS_RIL_Handle * solver = s;
1057 struct RIL_Peer_Agent * agent = GNUNET_malloc (sizeof (struct RIL_Peer_Agent));
1059 agent->envi = solver;
1060 agent->peer = *peer;
1061 agent->step_count = 0;
1062 agent->active = GNUNET_NO;
1063 agent->n = RIL_ACTION_TYPE_NUM;
1064 agent->m = solver->networks_count * RIL_FEATURES_NETWORK_COUNT;
1065 agent->W = (double **) GNUNET_malloc (sizeof (double) * agent->n);
1066 for (i = 0; i < agent->n; i++)
1068 agent->W[i] = (double *) GNUNET_malloc (sizeof (double) * agent->m);
1070 agent->a_old = RIL_ACTION_INVALID;
1071 agent->s_old = envi_get_state (solver, agent);
1072 agent->e = (double *) GNUNET_malloc (sizeof (double) * agent->m);
1073 agent_modify_eligibility (agent, RIL_E_ZERO);
1075 GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, agent);
1082 * @param s solver handle
1083 * @param agent the agent to retire
1086 agent_die (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1090 for (i = 0; i < agent->n; i++)
1092 GNUNET_free(agent->W[i]);
1094 GNUNET_free(agent->W);
1095 GNUNET_free(agent->e);
1096 GNUNET_free(agent->s_old);
1101 * Returns the agent for a peer
1102 * @param s solver handle
1103 * @param peer identity of the peer
1104 * @param create whether to create an agent if none is allocated yet
1107 static struct RIL_Peer_Agent *
1108 ril_get_agent (struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity *peer, int create)
1110 struct RIL_Peer_Agent *cur;
1112 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
1114 if (0 == memcmp (peer,
1116 sizeof (struct GNUNET_PeerIdentity)))
1124 return agent_init (solver, peer);
1130 * Lookup network struct by type
1132 * @param s the solver handle
1133 * @param type the network type
1134 * @return the network struct
1136 static struct RIL_Network *
1137 ril_get_network (struct GAS_RIL_Handle *s, uint32_t type)
1141 for (i = 0; i < s->networks_count; i++)
1143 if (s->network_entries[i].type == type)
1145 return &s->network_entries[i];
1152 * Determine whether at least the minimum bandwidth is set for the network. Otherwise the network is
1153 * considered inactive and not used. Addresses in an inactive network are ignored.
1154 * @param solver solver handle
1155 * @param network the network type
1159 ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network_Type network)
1161 struct RIL_Network *net;
1162 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1164 net = ril_get_network (solver, network);
1165 if (net->bw_out_available < min_bw)
1171 * Cuts a slice out of a vector of elements. This is used to decrease the size of the matrix storing
1172 * the reward function approximation. It copies the memory, which is not cut, to the new vector,
1173 * frees the memory of the old vector, and redirects the pointer to the new one.
1174 * @param old pointer to the pointer to the first element of the vector
1175 * @param element_size byte size of the vector elements
1176 * @param hole_start the first element to cut out
1177 * @param hole_length the number of elements to cut out
1178 * @param old_length the length of the old vector
1181 ril_cut_from_vector (void **old,
1182 size_t element_size,
1183 unsigned int hole_start,
1184 unsigned int hole_length,
1185 unsigned int old_length)
1188 char *oldptr = (char *) *old;
1190 unsigned int bytes_before;
1191 unsigned int bytes_hole;
1192 unsigned int bytes_after;
1194 GNUNET_assert(old_length > hole_length);
1195 GNUNET_assert(old_length >= (hole_start + hole_length));
1197 size = element_size * (old_length - hole_length);
1199 bytes_before = element_size * hole_start;
1200 bytes_hole = element_size * hole_length;
1201 bytes_after = element_size * (old_length - hole_start - hole_length);
1209 tmpptr = GNUNET_malloc (size);
1210 memcpy (tmpptr, oldptr, bytes_before);
1211 memcpy (tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole), bytes_after);
1217 *old = (void *) tmpptr;
1221 * Solver API functions
1222 * ---------------------------
1226 * Changes the preferences for a peer in the problem
1228 * @param solver the solver handle
1229 * @param peer the peer to change the preference for
1230 * @param kind the kind to change the preference
1231 * @param pref_rel the normalized preference value for this kind over all clients
1234 GAS_ril_address_change_preference (void *s,
1235 const struct GNUNET_PeerIdentity *peer,
1236 enum GNUNET_ATS_PreferenceKind kind,
1239 LOG(GNUNET_ERROR_TYPE_DEBUG,
1240 "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n",
1241 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), pref_rel);
1243 * Nothing to do here. Preferences are considered during reward calculation.
1249 libgnunet_plugin_ats_ril_init (void *cls)
1251 struct GNUNET_ATS_PluginEnvironment *env = cls;
1252 struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);;
1253 struct RIL_Network * cur;
1255 unsigned long long tmp;
1258 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
1260 GNUNET_assert(NULL != env);
1261 GNUNET_assert(NULL != env->cfg);
1262 GNUNET_assert(NULL != env->stats);
1263 GNUNET_assert(NULL != env->bandwidth_changed_cb);
1264 GNUNET_assert(NULL != env->get_preferences_cb);
1265 GNUNET_assert(NULL != env->get_property_cb);
1268 != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME", &solver->step_time))
1270 solver->step_time = RIL_DEFAULT_STEP_TIME;
1272 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_ALGORITHM", &string)
1273 && NULL != string && 0 == strcmp (string, "SARSA"))
1275 solver->parameters.algorithm = RIL_ALGO_SARSA;
1279 solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM;
1281 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", "RIL_DISCOUNT_FACTOR", &tmp))
1283 solver->parameters.gamma = (double) tmp / 100;
1287 solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_FACTOR;
1289 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", "RIL_GRADIENT_STEP_SIZE", &tmp))
1291 solver->parameters.alpha = (double) tmp / 100;
1295 solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
1297 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", "RIL_TRACE_DECAY", &tmp))
1299 solver->parameters.lambda = (double) tmp / 100;
1303 solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY;
1306 env->sf.s_add = &GAS_ril_address_add;
1307 env->sf.s_address_update_property = &GAS_ril_address_property_changed;
1308 env->sf.s_address_update_session = &GAS_ril_address_session_changed;
1309 env->sf.s_address_update_inuse = &GAS_ril_address_inuse_changed;
1310 env->sf.s_address_update_network = &GAS_ril_address_change_network;
1311 env->sf.s_get = &GAS_ril_get_preferred_address;
1312 env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
1313 env->sf.s_pref = &GAS_ril_address_change_preference;
1314 env->sf.s_feedback = &GAS_ril_address_preference_feedback;
1315 env->sf.s_del = &GAS_ril_address_delete;
1316 env->sf.s_bulk_start = &GAS_ril_bulk_start;
1317 env->sf.s_bulk_stop = &GAS_ril_bulk_stop;
1319 solver->plugin_envi = env;
1320 solver->stats = (struct GNUNET_STATISTICS_Handle *) env->stats;
1321 solver->callbacks = GNUNET_malloc (sizeof (struct RIL_Callbacks));
1322 solver->callbacks->bw_changed = env->bandwidth_changed_cb;
1323 solver->callbacks->bw_changed_cls = env->bw_changed_cb_cls;
1324 solver->callbacks->get_preferences = env->get_preferences_cb;
1325 solver->callbacks->get_preferences_cls = env->get_preference_cls;
1326 solver->callbacks->get_properties = env->get_property_cb;
1327 solver->callbacks->get_properties_cls = env->get_property_cls;
1328 solver->networks_count = env->network_count;
1329 solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Network));
1330 solver->addresses = env->addresses;
1331 solver->step_count = 0;
1333 for (c = 0; c < env->network_count; c++)
1335 cur = &solver->network_entries[c];
1336 cur->type = env->networks[c];
1337 cur->bw_in_available = env->in_quota[c];
1338 cur->bw_in_assigned = 0;
1339 cur->bw_out_available = env->out_quota[c];
1340 cur->bw_out_assigned = 0;
1343 solver->next_step = GNUNET_SCHEDULER_add_delayed (
1344 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_millisecond_ (), 1000),
1345 &ril_periodic_step, solver);
1352 libgnunet_plugin_ats_ril_done (void *cls)
1354 struct GAS_RIL_Handle *s = cls;
1355 struct RIL_Peer_Agent *cur_agent;
1356 struct RIL_Peer_Agent *next_agent;
1358 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
1360 cur_agent = s->agents_head;
1361 while (NULL != cur_agent)
1363 next_agent = cur_agent->next;
1364 GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent);
1365 agent_die (s, cur_agent);
1366 cur_agent = next_agent;
1369 GNUNET_SCHEDULER_cancel (s->next_step);
1370 GNUNET_free(s->callbacks);
1371 GNUNET_free(s->network_entries);
1378 * Add a single address within a network to the solver
1380 * @param solver the solver Handle
1381 * @param address the address to add
1382 * @param network network type of this address
1385 GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network)
1387 struct GAS_RIL_Handle *s = solver;
1388 struct RIL_Peer_Agent *agent;
1389 struct RIL_Address_Wrapped *address_wrapped;
1390 struct RIL_Network *net;
1397 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1399 net = ril_get_network (s, network);
1400 address->solver_information = net;
1402 if (!ril_network_is_active (s, network))
1404 LOG(GNUNET_ERROR_TYPE_DEBUG,
1405 "API_address_add() Did not add %s address %p for peer '%s', network does not have enough bandwidth\n",
1406 address->plugin, address->addr, GNUNET_i2s (&address->peer));
1410 agent = ril_get_agent (s, &address->peer, GNUNET_YES);
1413 address_wrapped = GNUNET_malloc (sizeof (struct RIL_Address_Wrapped));
1414 address_wrapped->address_naked = address;
1415 GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped);
1417 //increase size of W
1418 m_new = agent->m + RIL_FEATURES_ADDRESS_COUNT;
1420 n_new = agent->n + 1;
1423 GNUNET_array_grow(agent->W, agent->n, n_new);
1424 for (i = 0; i < n_new; i++)
1429 GNUNET_array_grow(agent->W[i], agent->m, m_new);
1434 GNUNET_array_grow(agent->W[i], zero, m_new);
1438 //increase size of old state vector
1440 GNUNET_array_grow(agent->s_old, agent->m, m_new); //TODO random instead of zero-initialization of state features
1443 GNUNET_array_grow(agent->e, agent->m, m_new);
1445 if (NULL == agent->address_inuse)
1447 net->bw_in_assigned += min_bw;
1448 net->bw_out_assigned += min_bw;
1449 envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO);
1452 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %p for peer '%s'\n",
1453 address->active ? "active" : "inactive",
1454 address->plugin, address->addr, GNUNET_i2s (&address->peer));
1458 * Remove an address from the solver
1460 * @param solver the solver handle
1461 * @param address the address to remove
1462 * @param session_only delete only session not whole address
1465 GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only)
1467 struct GAS_RIL_Handle *s = solver;
1468 struct RIL_Peer_Agent *agent;
1469 struct RIL_Address_Wrapped *address_wrapped;
1470 int address_was_used = address->active;
1475 struct RIL_Network *net;
1476 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1478 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() Delete %s%s %s address %p for peer '%s'\n",
1479 session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin,
1480 address->addr, GNUNET_i2s (&address->peer));
1482 agent = ril_get_agent (s, &address->peer, GNUNET_NO);
1485 net = address->solver_information;
1486 GNUNET_assert(!ril_network_is_active (s, net->type));
1487 LOG(GNUNET_ERROR_TYPE_DEBUG,
1488 "No agent allocated for peer yet, since address was in inactive network\n");
1492 address_index = agent_address_get_index (agent, address);
1493 address_wrapped = agent_address_get (agent, address);
1495 if (NULL == address_wrapped)
1497 net = address->solver_information;
1498 GNUNET_assert(!ril_network_is_active (s, net->type));
1499 LOG(GNUNET_ERROR_TYPE_DEBUG,
1500 "Address not considered by agent, address was in inactive network\n");
1504 GNUNET_CONTAINER_DLL_remove(agent->addresses_head, agent->addresses_tail, address_wrapped);
1505 GNUNET_free(address_wrapped);
1508 m_new = agent->m - RIL_FEATURES_ADDRESS_COUNT;
1509 n_new = agent->n - 1;
1511 for (i = 0; i < agent->n; i++)
1513 ril_cut_from_vector ((void **) &agent->W[i], sizeof(double),
1514 ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m);
1516 GNUNET_free (agent->W[RIL_ACTION_TYPE_NUM + address_index]);
1517 ril_cut_from_vector ((void **) &agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index,
1519 //correct last action
1520 if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index))
1524 else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index))
1526 agent->a_old = RIL_ACTION_INVALID;
1528 //decrease old state vector and eligibility vector
1529 ril_cut_from_vector ((void **) &agent->s_old, sizeof(double),
1530 ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m);
1531 ril_cut_from_vector ((void **) &agent->e, sizeof(double),
1532 ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m);
1536 LOG (GNUNET_ERROR_TYPE_DEBUG, "address was used: %s\n", address_was_used ? "yes" : "no");
1538 if (address_was_used)
1540 net = address->solver_information;
1541 net->bw_in_assigned -= agent->bw_in;
1542 net->bw_out_assigned -= agent->bw_out;
1544 if (NULL != agent->addresses_head) //if peer has an address left, use it
1546 LOG (GNUNET_ERROR_TYPE_DEBUG, "address left: %p\n", agent->addresses_head->address_naked->addr);
1547 //TODO? check if network/bandwidth update can be done more clever/elegant at different function
1548 envi_set_active_suggestion (s, agent, agent->addresses_head->address_naked, min_bw, min_bw, GNUNET_NO);
1549 net = agent->addresses_head->address_naked->solver_information;
1550 net->bw_in_assigned -= min_bw;
1551 net->bw_out_assigned -= min_bw;
1555 LOG (GNUNET_ERROR_TYPE_DEBUG, "no address left => disconnect\n");
1557 envi_set_active_suggestion (s, agent, NULL, 0, 0, GNUNET_NO);
1561 LOG(GNUNET_ERROR_TYPE_DEBUG, "Address deleted\n");
1565 * Transport properties for this address have changed
1567 * @param solver solver handle
1568 * @param address the address
1569 * @param type the ATSI type in HBO
1570 * @param abs_value the absolute value of the property
1571 * @param rel_value the normalized value
1574 GAS_ril_address_property_changed (void *solver,
1575 struct ATS_Address *address,
1580 LOG(GNUNET_ERROR_TYPE_DEBUG,
1581 "API_address_property_changed() Property '%s' for peer '%s' address %p changed "
1582 "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
1583 address->addr, rel_value);
1585 * Nothing to do here, properties are considered in every reward calculation
1590 * Transport session for this address has changed
1592 * NOTE: values in addresses are already updated
1594 * @param solver solver handle
1595 * @param address the address
1596 * @param cur_session the current session
1597 * @param new_session the new session
1600 GAS_ril_address_session_changed (void *solver,
1601 struct ATS_Address *address,
1602 uint32_t cur_session,
1603 uint32_t new_session)
1606 * TODO? Future Work: Potentially add session activity as a feature in state vector
1608 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n");
1612 * Usage for this address has changed
1614 * NOTE: values in addresses are already updated
1616 * @param solver solver handle
1617 * @param address the address
1618 * @param in_use usage state
1621 GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use)
1623 /* Nothing to do here */
1624 LOG(GNUNET_ERROR_TYPE_DEBUG,
1625 "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n",
1626 address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED");
1630 * Network scope for this address has changed
1632 * NOTE: values in addresses are already updated
1634 * @param solver solver handle
1635 * @param address the address
1636 * @param current_network the current network
1637 * @param new_network the new network
1640 GAS_ril_address_change_network (void *solver,
1641 struct ATS_Address *address,
1642 uint32_t current_network,
1643 uint32_t new_network)
1645 struct GAS_RIL_Handle *s = solver;
1646 struct RIL_Peer_Agent *agent;
1647 struct RIL_Network *net;
1648 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1650 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_change_network() Network type changed, moving "
1651 "%s address of peer %s from '%s' to '%s'\n",
1652 (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer),
1653 GNUNET_ATS_print_network_type (current_network), GNUNET_ATS_print_network_type (new_network));
1655 if (address->active && !ril_network_is_active (solver, new_network))
1657 GAS_ril_address_delete (solver, address, GNUNET_NO);
1661 agent = ril_get_agent (s, &address->peer, GNUNET_NO);
1664 GNUNET_assert(!ril_network_is_active (solver, current_network));
1666 GAS_ril_address_add (s, address, new_network);
1670 net = ril_get_network (s, current_network);
1671 net->bw_in_assigned -= agent->bw_in;
1672 net->bw_out_assigned -= agent->bw_out;
1674 net = ril_get_network (s, new_network);
1675 net->bw_in_assigned -= min_bw;
1676 net->bw_out_assigned -= min_bw;
1677 address->solver_information = net;
1681 * Get application feedback for a peer
1683 * @param solver the solver handle
1684 * @param application the application
1685 * @param peer the peer to change the preference for
1686 * @param scope the time interval for this feedback: [now - scope .. now]
1687 * @param kind the kind to change the preference
1688 * @param score the score
1691 GAS_ril_address_preference_feedback (void *solver,
1693 const struct GNUNET_PeerIdentity *peer,
1694 const struct GNUNET_TIME_Relative scope,
1695 enum GNUNET_ATS_PreferenceKind kind,
1698 //TODO! collect feedback
1699 LOG(GNUNET_ERROR_TYPE_DEBUG,
1700 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
1701 "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN",
1702 GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000);
1706 * Start a bulk operation
1708 * @param solver the solver
1711 GAS_ril_bulk_start (void *solver)
1714 * Since new calculations of the assignment are not triggered by a change of preferences, as it
1715 * happens in the proportional and the mlp solver, there is no need to block this solver.
1720 * Bulk operation done
1723 GAS_ril_bulk_stop (void *solver)
1726 * Since new calculations of the assignment are not triggered by a change of preferences, as it
1727 * happens in the proportional and the mlp solver, there is no need to block this solver.
1732 * Get the preferred address for a specific peer
1734 * @param solver the solver handle
1735 * @param peer the identity of the peer
1737 const struct ATS_Address *
1738 GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
1741 * activate agent, return currently chosen address
1743 struct GAS_RIL_Handle *s = solver;
1744 struct RIL_Peer_Agent *agent;
1746 agent = ril_get_agent (s, peer, GNUNET_YES);
1748 agent->active = GNUNET_YES;
1750 envi_set_active_suggestion(s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES);
1752 if (agent->address_inuse)
1754 LOG(GNUNET_ERROR_TYPE_DEBUG,
1755 "API_get_preferred_address() Activated agent for peer '%s' with %s address %p\n",
1756 GNUNET_i2s (peer), agent->address_inuse->plugin, agent->address_inuse->addr);
1760 LOG(GNUNET_ERROR_TYPE_DEBUG,
1761 "API_get_preferred_address() Activated agent for peer '%s', but no address available\n", GNUNET_i2s (peer));
1764 return agent->address_inuse;
1768 * Stop notifying about address and bandwidth changes for this peer
1770 * @param solver the solver handle
1771 * @param peer the peer
1774 GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
1776 struct GAS_RIL_Handle *s = solver;
1777 struct RIL_Peer_Agent *agent;
1779 agent = ril_get_agent (s, peer, GNUNET_NO);
1786 if (GNUNET_NO == agent->active)
1792 agent->active = GNUNET_NO;
1793 envi_set_active_suggestion(s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES);
1795 LOG(GNUNET_ERROR_TYPE_DEBUG,
1796 "API_stop_get_preferred_address() Paused agent for peer '%s' with %s address\n",
1797 GNUNET_i2s (peer), agent->address_inuse->plugin);
1800 /* end of libgnunet_plugin_ats_ril.c */