#include "gnunet-service-ats_addresses.h"
#include "gnunet_statistics_service.h"
+#define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__)
+
+#define RIL_ACTION_INVALID -1
+#define RIL_FEATURES_ADDRESS_COUNT (3 + GNUNET_ATS_QualityPropertiesCount)
+#define RIL_FEATURES_NETWORK_COUNT 4
+
#define RIL_DEFAULT_STEP_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 3000)
#define RIL_DEFAULT_ALGORITHM RIL_ALGO_Q
#define RIL_DEFAULT_DISCOUNT_FACTOR 0.5
* General description
*/
+/**
+ * TODO! implement reward calculation 1 and 2 (i.e. meeting preferences and taking scores)
+ */
+
enum RIL_Action_Type
{
- RIL_ACTION_BW_IN_DBL = 0,
- RIL_ACTION_BW_OUT_DBL = 1,
+ RIL_ACTION_NOTHING = 0,
+ RIL_ACTION_BW_IN_DBL = 1,
RIL_ACTION_BW_IN_HLV = 2,
- RIL_ACTION_BW_OUT_HLV = 3,
- RIL_ACTION_TYPE_NUM = 4
+ RIL_ACTION_BW_IN_INC = 3,
+ RIL_ACTION_BW_IN_DEC = 4,
+ RIL_ACTION_BW_OUT_DBL = 5,
+ RIL_ACTION_BW_OUT_HLV = 6,
+ RIL_ACTION_BW_OUT_INC = 7,
+ RIL_ACTION_BW_OUT_DEC = 8,
+ RIL_ACTION_TYPE_NUM = 9
};
-//TODO! add the rest of the actions
enum RIL_Algorithm
{
enum RIL_E_Modification
{
- RIL_E_SET, RIL_E_ZERO, RIL_E_ACCUMULATE, RIL_E_REPLACE
+ RIL_E_SET,
+ RIL_E_ZERO,
+ RIL_E_ACCUMULATE,
+ RIL_E_REPLACE
};
/**
float lambda;
};
+/**
+ * Wrapper for addresses to store them in agent's linked list
+ */
+struct RIL_Address_Wrapped
+{
+ /**
+ * Next in DLL
+ */
+ struct RIL_Address_Wrapped *next;
+
+ /**
+ * Previous in DLL
+ */
+ struct RIL_Address_Wrapped *prev;
+
+ /**
+ * The address
+ */
+ struct ATS_Address *address_naked;
+};
+
struct RIL_Peer_Agent
{
/**
/**
* Whether the agent is active or not
*/
- int active;
+ int active; //TODO? rename into "requested", since it rather depicts whether there is a request pending for it
/**
* Number of performed time-steps
/**
* Number of rows of W / Number of state-vector features
*/
- int m;
+ unsigned int m;
/**
* Number of columns of W / Number of actions
*/
- int n;
+ unsigned int n;
/**
* Last perceived state feature vector
/**
* Address in use
*/
- struct ATS_Address * address;
+ struct ATS_Address * address_inuse;
+
+ /**
+ * Head of addresses DLL
+ */
+ struct RIL_Address_Wrapped * addresses_head;
+
+ /**
+ * Tail of addresses DLL
+ */
+ struct RIL_Address_Wrapped * addresses_tail;
/**
* Inbound bandwidth assigned by the agent
/**
* Hashmap containing all valid addresses
*/
- const struct GNUNET_CONTAINER_MultiHashMap *addresses;
+ const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
/**
* Callbacks for the solver
double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
UINT32_MAX) / (double) UINT32_MAX;
- if (r < RIL_EXPLORE_RATIO)
+if (r < RIL_EXPLORE_RATIO)
{
return GNUNET_YES;
}
return GNUNET_NO;
}
+static int
+agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *address)
+{
+ int i;
+ struct RIL_Address_Wrapped *cur;
+
+ i = -1;
+ for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
+ {
+ i++;
+ if (cur->address_naked == address)
+ {
+ return i;
+ }
+ }
+
+ return i;
+}
+
+static struct RIL_Address_Wrapped *
+agent_address_get (struct RIL_Peer_Agent *agent, struct ATS_Address *address)
+{
+ struct RIL_Address_Wrapped *cur;
+
+ for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
+ {
+ if (cur->address_naked == address)
+ {
+ return cur;
+ }
+ }
+
+ return NULL ;
+}
+
/**
* Gets the action, with the maximal estimated Q-value (i.e. the one currently estimated to bring the
* most reward in the future)
agent_get_action_best (struct RIL_Peer_Agent *agent, double *state)
{
int i;
- int max_i = -1;
+ int max_i = RIL_ACTION_INVALID;
double cur_q;
double max_q = -DBL_MAX;
}
}
- GNUNET_assert(-1 != max_i);
+ GNUNET_assert(RIL_ACTION_INVALID != max_i);
return max_i;
}
* @param a_prime the new
*/
static void
-agent_update_weights (struct RIL_Peer_Agent *agent,
- double reward,
- double *s_next,
- int a_prime)
+agent_update_weights (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a_prime)
{
int i;
double delta;
double *theta = agent->W[agent->a_old];
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "agent_update_weights() MUH a_old = %d\n", agent->a_old);
delta = reward + agent_estimate_q (agent, s_next, a_prime)
- agent_estimate_q (agent, agent->s_old, agent->a_old);
for (i = 0; i < agent->m; i++)
* @param mod
*/
static void
-agent_modify_eligibility (struct RIL_Peer_Agent *agent,
- enum RIL_E_Modification mod)
+agent_modify_eligibility (struct RIL_Peer_Agent *agent, enum RIL_E_Modification mod)
{
int i;
double *e = agent->e;
}
}
+static void
+envi_set_active_suggestion (struct GAS_RIL_Handle *solver,
+ struct RIL_Peer_Agent *agent,
+ struct ATS_Address *new_address,
+ unsigned long long new_bw_in,
+ unsigned long long new_bw_out,
+ int silent)
+{
+ int notify = GNUNET_NO;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "set_active_suggestion()\n");
+
+ //address change
+ if (agent->address_inuse != new_address)
+ {
+ if (NULL != agent->address_inuse)
+ {
+ agent->address_inuse->active = GNUNET_NO;
+ agent->address_inuse->assigned_bw_in.value__ = htonl (0);
+ agent->address_inuse->assigned_bw_out.value__ = htonl (0);
+ }
+ if (NULL != new_address)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "set address active: %s\n", agent->active ? "yes" : "no");
+ new_address->active = agent->active;
+ new_address->assigned_bw_in.value__ = htonl (agent->bw_in);
+ new_address->assigned_bw_out.value__ = htonl (agent->bw_out);
+ }
+ notify |= GNUNET_YES;
+ }
+
+ if (new_address)
+ {
+ //activity change
+ if (new_address->active != agent->active)
+ {
+ new_address->active = agent->active;
+ }
+
+ //bw change
+ if (agent->bw_in != new_bw_in)
+ {
+ agent->bw_in = new_bw_in;
+ new_address->assigned_bw_in.value__ = htonl (new_bw_out);
+ notify |= GNUNET_YES;
+ }
+ if (agent->bw_out != new_bw_out)
+ {
+ agent->bw_out = new_bw_out;
+ new_address->assigned_bw_out.value__ = htonl (new_bw_out);
+ notify |= GNUNET_YES;
+ }
+ }
+
+ if (notify && agent->active && (GNUNET_NO == silent))
+ {
+ if (new_address)
+ {
+ solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls, new_address);
+ }
+ else
+ {
+ GNUNET_assert (0 == ntohl(agent->address_inuse->assigned_bw_in.value__));
+ GNUNET_assert (0 == ntohl(agent->address_inuse->assigned_bw_out.value__));
+ agent->bw_in = 0;
+ agent->bw_out = 0;
+ //disconnect
+ solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls, agent->address_inuse);
+ }
+ }
+ agent->address_inuse = new_address;
+}
+
/**
* Allocates a state vector and fills it with the features present
* @param solver the solver handle
* @return pointer to the state vector
*/
static double *
-envi_get_state (struct GAS_RIL_Handle *solver)
+envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
{
int i;
+ int k;
struct RIL_Network *net;
- double *state = GNUNET_malloc (sizeof (double) * solver->networks_count * 4);
+ double *state = GNUNET_malloc (sizeof (double) * agent->m);
+ struct RIL_Address_Wrapped *cur_address;
+ const double *properties;
for (i = 0; i < solver->networks_count; i++)
{
net = &solver->network_entries[i];
- state[i*4 + 0] = (double) net->bw_in_assigned;
- state[i*4 + 1] = (double) net->bw_in_available;
- state[i*4 + 2] = (double) net->bw_out_assigned;
- state[i*4 + 3] = (double) net->bw_out_available;
+ state[i * RIL_FEATURES_NETWORK_COUNT + 0] = (double) net->bw_in_assigned;
+ state[i * RIL_FEATURES_NETWORK_COUNT + 1] = (double) net->bw_in_available;
+ state[i * RIL_FEATURES_NETWORK_COUNT + 2] = (double) net->bw_out_assigned;
+ state[i * RIL_FEATURES_NETWORK_COUNT + 3] = (double) net->bw_out_available;
+ }
+
+ i = i * RIL_FEATURES_NETWORK_COUNT; //first address feature
+
+ for (cur_address = agent->addresses_head; NULL != cur_address; cur_address = cur_address->next)
+ {
+ state[i++] = cur_address->address_naked->active;
+ state[i++] = cur_address->address_naked->active ? agent->bw_in : 0;
+ state[i++] = cur_address->address_naked->active ? agent->bw_out : 0;
+ properties = solver->callbacks->get_properties (solver->callbacks->get_properties_cls, cur_address->address_naked);
+ for (k = 0; k < GNUNET_ATS_QualityPropertiesCount; k++)
+ {
+ state[i++] = properties[k];
+ }
}
return state;
{
//TODO! implement reward calculation
- return (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT32_MAX) / (double) UINT32_MAX;
+ return (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)
+ / (double) UINT32_MAX;
}
static void
{
if (direction_in)
{
- agent->bw_in *= 2;
- agent->address->assigned_bw_in.value__ = htonl (agent->bw_in);
- solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls,
- agent->address);
+ envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in * 2,
+ agent->bw_out, GNUNET_NO);
}
else
{
- agent->bw_out *= 2;
- agent->address->assigned_bw_out.value__ = htonl (agent->bw_out);
- solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls,
- agent->address);
+ envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in,
+ agent->bw_out * 2, GNUNET_NO);
}
}
struct RIL_Peer_Agent *agent,
int direction_in)
{
- if ((direction_in && 1 == agent->bw_in)
- || (!direction_in && 1 == agent->bw_out))
+ uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
+ unsigned long long new_bw;
+
+ if (direction_in)
{
- return;
+ new_bw = agent->bw_in / 2;
+ if (new_bw < min_bw)
+ new_bw = min_bw;
+ envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, GNUNET_NO);
+ }
+ else
+ {
+ new_bw = agent->bw_out / 2;
+ if (new_bw < min_bw)
+ new_bw = min_bw;
+ envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, GNUNET_NO);
+ }
+}
+
+static void
+envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in)
+{
+ uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
+
+ if (direction_in)
+ {
+ envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in + (5 * min_bw),
+ agent->bw_out, GNUNET_NO);
}
+ else
+ {
+ envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in,
+ agent->bw_out + (5 * min_bw), GNUNET_NO);
+ }
+}
+
+static void
+envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in)
+{
+ uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
+ unsigned long long new_bw;
+
if (direction_in)
{
- agent->bw_in /= 2;
- agent->address->assigned_bw_in.value__ = htonl (agent->bw_in);
- solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls,
- agent->address);
+ new_bw = agent->bw_in - (5 * min_bw);
+ if (new_bw < min_bw)
+ new_bw = min_bw;
+ envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, GNUNET_NO);
}
else
{
- agent->bw_out /= 2;
- agent->address->assigned_bw_out.value__ = htonl (agent->bw_out);
- solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls,
- agent->address);
+ new_bw = agent->bw_out - (5 * min_bw);
+ if (new_bw < min_bw)
+ new_bw = min_bw;
+ envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, GNUNET_NO);
}
}
+static void
+envi_action_address_switch (struct GAS_RIL_Handle *solver,
+ struct RIL_Peer_Agent *agent,
+ unsigned int address_index)
+{
+ struct RIL_Address_Wrapped *cur;
+ int i = 0;
+
+ for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
+ {
+ if (i == address_index)
+ {
+ envi_set_active_suggestion (solver, agent, cur->address_naked, agent->bw_in, agent->bw_out, GNUNET_NO);
+ return;
+ }
+
+ i++;
+ }
+
+ //no address with address_index exists
+ GNUNET_assert(GNUNET_NO);
+}
+
/**
* Puts the action into effect
* @param solver solver handle
* @param action action to perform by the solver
*/
static void
-envi_do_action (struct GAS_RIL_Handle *solver,
- struct RIL_Peer_Agent *agent,
- int action)
+envi_do_action (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int action)
{
+ unsigned int address_index;
+
switch (action)
{
+ case RIL_ACTION_NOTHING:
+ break;
case RIL_ACTION_BW_IN_DBL:
envi_action_bw_double (solver, agent, GNUNET_YES);
break;
case RIL_ACTION_BW_IN_HLV:
envi_action_bw_halven (solver, agent, GNUNET_YES);
break;
+ case RIL_ACTION_BW_IN_INC:
+ envi_action_bw_inc (solver, agent, GNUNET_YES);
+ break;
+ case RIL_ACTION_BW_IN_DEC:
+ envi_action_bw_dec (solver, agent, GNUNET_YES);
+ break;
case RIL_ACTION_BW_OUT_DBL:
envi_action_bw_double (solver, agent, GNUNET_NO);
break;
case RIL_ACTION_BW_OUT_HLV:
envi_action_bw_halven (solver, agent, GNUNET_NO);
break;
+ case RIL_ACTION_BW_OUT_INC:
+ envi_action_bw_inc (solver, agent, GNUNET_NO);
+ break;
+ case RIL_ACTION_BW_OUT_DEC:
+ envi_action_bw_dec (solver, agent, GNUNET_NO);
+ break;
+ default:
+ if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n))
+ {
+ address_index = agent->n - RIL_ACTION_TYPE_NUM;
+
+ GNUNET_assert(address_index >= 0);
+ GNUNET_assert(
+ address_index <= agent_address_get_index (agent, agent->addresses_tail->address_naked));
+
+ envi_action_address_switch (solver, agent, address_index);
+ break;
+ }
+ // error - action does not exist
+ GNUNET_assert(GNUNET_NO);
}
}
static void
agent_step (struct RIL_Peer_Agent *agent)
{
- int a_next = -1;
+ int a_next = RIL_ACTION_INVALID;
double *s_next;
double reward;
- s_next = envi_get_state (agent->envi);
+ s_next = envi_get_state (agent->envi, agent);
reward = envi_get_reward (agent->envi, agent);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "agent_step() with algorithm %s\n",
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "agent_step() with algorithm %s\n",
agent->envi->parameters.algorithm ? "Q" : "SARSA");
switch (agent->envi->parameters.algorithm)
{
a_next = agent_get_action_best (agent, s_next);
}
- //updates weights with selected action (on-policy), if not first step
- if (-1 != agent->a_old)
+ if (RIL_ACTION_INVALID != agent->a_old)
+ {
+ //updates weights with selected action (on-policy), if not first step
agent_update_weights (agent, reward, s_next, a_next);
+ }
break;
case RIL_ALGO_Q:
- //updates weights with best action, disregarding actually selected action (off-policy), if not first step
a_next = agent_get_action_best (agent, s_next);
- if (-1 != agent->a_old)
+ if (RIL_ACTION_INVALID != agent->a_old)
+ {
+ //updates weights with best action, disregarding actually selected action (off-policy), if not first step
agent_update_weights (agent, reward, s_next, a_next);
+ }
if (agent_decide_exploration (agent))
{
a_next = agent_get_action_explore (agent, s_next);
break;
}
- GNUNET_assert(-1 != a_next);
+ GNUNET_assert(RIL_ACTION_INVALID != a_next);
agent_modify_eligibility (agent, RIL_E_ACCUMULATE);
struct GAS_RIL_Handle *solver = cls;
struct RIL_Peer_Agent *cur;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "RIL step number %d\n",
- solver->step_count);
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "RIL step number %d\n", solver->step_count);
for (cur = solver->agents_head; NULL != cur; cur = cur->next)
{
- if (cur->active)
+ if (cur->active && cur->address_inuse)
{
agent_step (cur);
}
}
solver->step_count += 1;
- solver->next_step = GNUNET_SCHEDULER_add_delayed (solver->step_time,
- &ril_periodic_step, solver);
+ solver->next_step = GNUNET_SCHEDULER_add_delayed (solver->step_time, &ril_periodic_step, solver);
}
/**
agent->peer = *peer;
agent->step_count = 0;
agent->active = GNUNET_NO;
- agent->s_old = envi_get_state (solver);
agent->n = RIL_ACTION_TYPE_NUM;
- agent->m = solver->networks_count * 4;
+ agent->m = solver->networks_count * RIL_FEATURES_NETWORK_COUNT;
agent->W = (double **) GNUNET_malloc (sizeof (double) * agent->n);
for (i = 0; i < agent->n; i++)
{
agent->W[i] = (double *) GNUNET_malloc (sizeof (double) * agent->m);
}
- agent->a_old = -1;
+ agent->a_old = RIL_ACTION_INVALID;
+ agent->s_old = envi_get_state (solver, agent);
agent->e = (double *) GNUNET_malloc (sizeof (double) * agent->m);
agent_modify_eligibility (agent, RIL_E_ZERO);
- GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail,
- agent);
+ GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, agent);
return agent;
}
GNUNET_free(agent->W);
GNUNET_free(agent->e);
GNUNET_free(agent->s_old);
-}
-
-static void
-ril_remove_agent (struct GAS_RIL_Handle *s, struct RIL_Peer_Agent *agent)
-{
- struct RIL_Peer_Agent *cur_agent;
- struct RIL_Peer_Agent *next_agent;
-
- cur_agent = s->agents_head;
- while (NULL != cur_agent)
- {
- next_agent = cur_agent->next;
-
- if (agent == cur_agent)
- GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent);
- agent_die (s, cur_agent);
-
- cur_agent = next_agent;
- }
-}
-
-/**
- * Counts the (active) agents
- * @param solver solver handle
- * @param active_only whether only active agents should be counted
- * @return number of agents
- */
-static int
-ril_count_agents (struct GAS_RIL_Handle *solver, int active_only)
-{
- int c;
- struct RIL_Peer_Agent *cur;
-
- c = 0;
- for (cur = solver->agents_head; NULL != cur; cur = cur->next)
- {
- if ((!active_only) || (active_only && cur->active))
- {
- c += 1;
- }
- }
- return c;
+ GNUNET_free(agent);
}
/**
* @return agent
*/
static struct RIL_Peer_Agent *
-ril_get_agent (struct GAS_RIL_Handle *solver,
- const struct GNUNET_PeerIdentity *peer,
- int create)
+ril_get_agent (struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity *peer, int create)
{
struct RIL_Peer_Agent *cur;
for (cur = solver->agents_head; NULL != cur; cur = cur->next)
{
- if (0 == GNUNET_CRYPTO_hash_cmp (&peer->hashPubKey, &cur->peer.hashPubKey))
+ if (0 == memcmp (peer,
+ &cur->peer,
+ sizeof (struct GNUNET_PeerIdentity)))
{
return cur;
}
}
if (create)
- return agent_init (solver, peer);
- return NULL;
-}
-
-static int
-ril_network_is_active (struct RIL_Network *network)
-{
- uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
-
- if (network->bw_out_available < min_bw)
- return GNUNET_NO;
- return GNUNET_YES;
-}
-
-/**
- * Iterator, which allocates one agent per peer
- *
- * @param cls solver
- * @param key peer identity
- * @param value address
- * @return whether iterator should continue
- */
-static int
-ril_init_agents_it (void *cls, const struct GNUNET_HashCode *key, void *value)
-{
- struct GAS_RIL_Handle *solver = cls;
- struct ATS_Address *address = value;
- struct RIL_Peer_Agent *agent = NULL;
- uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
-
- if (ril_network_is_active(address->solver_information))
{
- agent = ril_get_agent (solver, &address->peer, GNUNET_YES);
-
- GNUNET_assert(NULL != agent);
-
- if (NULL == agent->address)
- {
- agent->address = address;
- agent->address->active = GNUNET_YES;
- agent->bw_in = min_bw;
- agent->address->assigned_bw_in.value__ = htonl (min_bw);
- agent->bw_out = min_bw;
- agent->address->assigned_bw_out.value__ = htonl (min_bw);
- }
+ return agent_init (solver, peer);
}
- return GNUNET_YES;
+ return NULL ;
}
/**
for (i = 0; i < s->networks_count; i++)
{
- if (s->network_entries[i].type == type) {
+ if (s->network_entries[i].type == type)
+ {
return &s->network_entries[i];
}
}
- return NULL;
+ return NULL ;
+}
+
+static int
+ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network_Type network)
+{
+ struct RIL_Network *net;
+ uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
+
+ net = ril_get_network (solver, network);
+ if (net->bw_out_available < min_bw)
+ return GNUNET_NO;
+ return GNUNET_YES;
+}
+
+static void
+ril_cut_from_vector (void **old,
+ size_t element_size,
+ unsigned int hole_start,
+ unsigned int hole_length,
+ unsigned int old_length)
+{
+ char *tmpptr;
+ char *oldptr = (char *) *old;
+ size_t size;
+ unsigned int bytes_before;
+ unsigned int bytes_hole;
+ unsigned int bytes_after;
+
+
+ GNUNET_assert(old_length > hole_length);
+ GNUNET_assert(old_length >= (hole_start + hole_length));
+
+ size = element_size * (old_length - hole_length);
+
+ bytes_before = element_size * hole_start;
+ bytes_hole = element_size * hole_length;
+ bytes_after = element_size * (old_length - hole_start - hole_length);
+
+ if (0 == size)
+ {
+ tmpptr = NULL;
+ }
+ else
+ {
+// LOG(GNUNET_ERROR_TYPE_DEBUG, "hole_start = %d, hole_length = %d, old_length = %d\n", hole_start, hole_length, old_length);
+// LOG(GNUNET_ERROR_TYPE_DEBUG, "bytes_before = %d, bytes_hole = %d, bytes_after = %d\n", bytes_before, bytes_hole, bytes_after);
+// LOG(GNUNET_ERROR_TYPE_DEBUG, "element_size = %d, bytes_old = %d, bytes_new = %d\n", element_size, old_length * element_size, size);
+
+ tmpptr = GNUNET_malloc (size);
+// LOG(GNUNET_ERROR_TYPE_DEBUG, "first\n");
+ memcpy (tmpptr, oldptr, bytes_before);
+// LOG(GNUNET_ERROR_TYPE_DEBUG, "second\n");
+ memcpy (tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole), bytes_after);
+ }
+ if (NULL != *old)
+ {
+ GNUNET_free(*old);
+ }
+ *old = (void *) tmpptr;
}
/**
enum GNUNET_ATS_PreferenceKind kind,
double pref_rel)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_change_preference() Preference `%s' for peer `%s' changed to %.2f \n",
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n",
GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), pref_rel);
/*
* Nothing to do here. Preferences are considered during reward calculation.
void *
GAS_ril_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
const struct GNUNET_STATISTICS_Handle *stats,
- const struct GNUNET_CONTAINER_MultiHashMap *addresses,
+ const struct GNUNET_CONTAINER_MultiPeerMap *addresses,
int *network,
unsigned long long *out_quota,
unsigned long long *in_quota,
unsigned long long tmp;
char *string;
struct RIL_Network * cur;
- struct GAS_RIL_Handle *solver = GNUNET_malloc (sizeof (struct GAS_RIL_Handle));
+ struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
GNUNET_assert(NULL != cfg);
GNUNET_assert(NULL != stats);
GNUNET_assert(NULL != get_properties);
if (GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_time (cfg, "ats", "RIL_STEP_TIME",
- &solver->step_time))
+ != GNUNET_CONFIGURATION_get_value_time (cfg, "ats", "RIL_STEP_TIME", &solver->step_time))
{
solver->step_time = RIL_DEFAULT_STEP_TIME;
}
- if (GNUNET_OK
- == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "RIL_ALGORITHM",
- &string) && NULL != string && 0 == strcmp (string, "SARSA"))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "RIL_ALGORITHM", &string)
+ && NULL != string && 0 == strcmp (string, "SARSA"))
{
solver->parameters.algorithm = RIL_ALGO_SARSA;
}
{
solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM;
}
- if (GNUNET_OK
- == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_DISCOUNT_FACTOR",
- &tmp))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_DISCOUNT_FACTOR", &tmp))
{
solver->parameters.gamma = (double) tmp / 100;
}
{
solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_FACTOR;
}
- if (GNUNET_OK
- == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
- "RIL_GRADIENT_STEP_SIZE", &tmp))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_GRADIENT_STEP_SIZE", &tmp))
{
solver->parameters.alpha = (double) tmp / 100;
}
{
solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
}
- if (GNUNET_OK
- == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_TRACE_DECAY",
- &tmp))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_TRACE_DECAY", &tmp))
{
solver->parameters.lambda = (double) tmp / 100;
}
solver->callbacks->get_properties = get_properties;
solver->callbacks->get_properties_cls = get_properties_cls;
solver->networks_count = dest_length;
- solver->network_entries =
- GNUNET_malloc (dest_length * sizeof (struct RIL_Network));
+ solver->network_entries = GNUNET_malloc (dest_length * sizeof (struct RIL_Network));
solver->bulk_lock = GNUNET_NO;
solver->addresses = addresses;
solver->step_count = 0;
}
solver->next_step = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_millisecond_ (),
- 1000), &ril_periodic_step, solver);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_millisecond_ (), 1000),
+ &ril_periodic_step, solver);
return solver;
}
struct RIL_Peer_Agent *cur_agent;
struct RIL_Peer_Agent *next_agent;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
cur_agent = s->agents_head;
while (NULL != cur_agent)
* @param network network type of this address
*/
void
-GAS_ril_address_add (void *solver,
- struct ATS_Address *address,
- uint32_t network)
+GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network)
{
struct GAS_RIL_Handle *s = solver;
- //TODO! implement solver address add
- /*
- * if (new peer)
- * initialize new agent
- * Add address
- * increase state vector
- * knowledge matrix
- * and action vector
- */
+ struct RIL_Peer_Agent *agent;
+ struct RIL_Address_Wrapped *address_wrapped;
+ unsigned int m_new;
+ unsigned int m_old;
+ unsigned int n_new;
+ unsigned int n_old;
+ int i;
+ unsigned int zero;
+ uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
- address->solver_information = ril_get_network(s, network);
+ address->solver_information = ril_get_network (s, network);
- /*
- * reiterate all addresses, create new agent if necessary and give the agent the address
- */
- GNUNET_CONTAINER_multihashmap_iterate (s->addresses, &ril_init_agents_it,
- solver);
+ if (!ril_network_is_active (s, network))
+ {
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_add() Did not add %s address %p for peer '%s', network does not have enough bandwidth\n",
+ address->plugin, address->addr, GNUNET_i2s (&address->peer));
+ return;
+ }
+
+ agent = ril_get_agent (s, &address->peer, GNUNET_YES);
+
+ //add address
+ address_wrapped = GNUNET_malloc (sizeof (struct RIL_Address_Wrapped));
+ address_wrapped->address_naked = address;
+ GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_add() Added %s address for peer '%s'\n", address->plugin,
- GNUNET_i2s (&address->peer));
+ //increase size of W
+ m_new = agent->m + RIL_FEATURES_ADDRESS_COUNT;
+ m_old = agent->m;
+ n_new = agent->n + 1;
+ n_old = agent->n;
+
+ GNUNET_array_grow(agent->W, agent->n, n_new);
+ for (i = 0; i < n_new; i++)
+ {
+ if (i < n_old)
+ {
+ agent->m = m_old;
+ GNUNET_array_grow(agent->W[i], agent->m, m_new);
+ }
+ else
+ {
+ zero = 0;
+ GNUNET_array_grow(agent->W[i], zero, m_new);
+ }
+ }
+
+ //increase size of old state vector
+ agent->m = m_old;
+ GNUNET_array_grow(agent->s_old, agent->m, m_new); //TODO initialize new state features?
+
+ agent->m = m_old;
+ GNUNET_array_grow(agent->e, agent->m, m_new);
+
+ if (NULL == agent->address_inuse)
+ {
+ envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO);
+ }
+
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %p for peer '%s'\n",
+ address->active ? "active" : "inactive",
+ address->plugin, address->addr, GNUNET_i2s (&address->peer));
}
/**
* @param session_only delete only session not whole address
*/
void
-GAS_ril_address_delete (void *solver,
- struct ATS_Address *address,
- int session_only)
+GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only)
{
- //TODO! implement solver address delete
//TODO! delete session only
- /*
- * remove address
- * if (last address of peer)
- * remove agent
- * else
- * decrease state vector
- * decrease knowledge matrix
- * decrease action vector
- */
struct GAS_RIL_Handle *s = solver;
struct RIL_Peer_Agent *agent;
+ struct RIL_Address_Wrapped *address_wrapped;
+ int address_was_used = address->active;
+ int address_index;
+ unsigned int m_new;
+ unsigned int n_new;
+ int i;
+ struct RIL_Network *net;
+ uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
- agent = ril_get_agent (s, &address->peer, GNUNET_NO);
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() Delete %s%s %s address %p for peer '%s'\n",
+ session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin,
+ address->addr, GNUNET_i2s (&address->peer));
+ agent = ril_get_agent (s, &address->peer, GNUNET_NO);
if (NULL == agent)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() deleting address for unallocated agent");
+ net = address->solver_information;
+ GNUNET_assert(!ril_network_is_active (s, net->type));
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "No agent allocated for peer yet, since address was in inactive network\n");
+ return;
+ }
+
+ address_index = agent_address_get_index (agent, address);
+ address_wrapped = agent_address_get (agent, address);
+
+ if (NULL == address_wrapped)
+ {
+ net = address->solver_information;
+ GNUNET_assert(!ril_network_is_active (s, net->type));
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "Address not considered by agent, address was in inactive network\n");
return;
}
- if (0 == memcmp (agent->address->addr, address->addr, address->addr_len)) //if used address deleted
+ GNUNET_CONTAINER_DLL_remove(agent->addresses_head, agent->addresses_tail, address_wrapped);
+ GNUNET_free(address_wrapped);
+
+ //decrease W
+ m_new = agent->m - RIL_FEATURES_ADDRESS_COUNT;
+ n_new = agent->n - 1;
+
+ for (i = 0; i < agent->n; i++)
{
- agent->address = NULL; //delete address
- GNUNET_CONTAINER_multihashmap_iterate (s->addresses, &ril_init_agents_it,
- solver); //put another address
- if (NULL == agent->address) //no other address available
+// LOG (GNUNET_ERROR_TYPE_DEBUG, "first - cut vectors in W\n");
+ ril_cut_from_vector ((void **) &agent->W[i], sizeof(double),
+ ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m);
+ }
+// LOG (GNUNET_ERROR_TYPE_DEBUG, "second - cut action vector out of W\n");
+ GNUNET_free (agent->W[RIL_ACTION_TYPE_NUM + address_index]);
+ ril_cut_from_vector ((void **) &agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index,
+ 1, agent->n);
+ //correct last action
+ if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index))
+ {
+ agent->a_old -= 1;
+ }
+ else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index))
+ {
+ agent->a_old = RIL_ACTION_INVALID;
+ }
+ //decrease old state vector and eligibility vector
+// LOG (GNUNET_ERROR_TYPE_DEBUG, "third - cut state vector\n");
+ ril_cut_from_vector ((void **) &agent->s_old, sizeof(double),
+ ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m);
+// LOG (GNUNET_ERROR_TYPE_DEBUG, "fourth - cut eligibility vector\n");
+ ril_cut_from_vector ((void **) &agent->e, sizeof(double),
+ ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m);
+ agent->m = m_new;
+ agent->n = n_new;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "address was used: %s\n", address_was_used ? "yes" : "no");
+
+ if (address_was_used)
+ {
+ net = address->solver_information;
+ net->bw_in_assigned -= agent->bw_in;
+ net->bw_out_assigned -= agent->bw_out;
+
+ if (NULL != agent->addresses_head) //if peer has an address left, use it
{
- agent->active = GNUNET_NO;
- ril_remove_agent (solver, agent);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "address left: %p\n", agent->addresses_head->address_naked->addr);
+ //TODO? check if network/bandwidth update can be done more clever/elegant at different function
+ envi_set_active_suggestion (s, agent, agent->addresses_head->address_naked, min_bw, min_bw, GNUNET_NO);
+ net = agent->addresses_head->address_naked->solver_information;
+ net->bw_in_assigned -= min_bw;
+ net->bw_out_assigned -= min_bw;
+ }
+ else
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "no address left => disconnect\n");
+
+ envi_set_active_suggestion (s, agent, NULL, 0, 0, GNUNET_NO);
}
}
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_delete() Deleted %s%s address for peer '%s'\n",
- session_only ? "session for " : "", address->plugin,
- GNUNET_i2s (&address->peer));
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "Address deleted\n");
}
/**
uint32_t abs_value,
double rel_value)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_property_changed() Property `%s' for peer `%s' address %p changed "
- "to %.2f \n", GNUNET_ATS_print_property_type (type),
- GNUNET_i2s (&address->peer), address, rel_value);
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_property_changed() Property '%s' for peer '%s' address %p changed "
+ "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
+ address->addr, rel_value);
/*
* Nothing to do here, properties are considered in every reward calculation
*/
/*
* Potentially add session activity as a feature in state vector
*/
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n");
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n");
}
/**
* @param in_use usage state
*/
void
-GAS_ril_address_inuse_changed (void *solver,
- struct ATS_Address *address,
- int in_use)
+GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use)
{
//TODO! consider address_inuse_changed according to matthias' email
/**
* See matthias' email
*/
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
"API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n",
- address->plugin, GNUNET_i2s (&address->peer),
- (GNUNET_YES == in_use) ? "USED" : "UNUSED");
+ address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED");
}
/**
struct GAS_RIL_Handle *s = solver;
struct RIL_Peer_Agent *agent;
struct RIL_Network *net;
+ uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_change_network() Network type changed, moving "
- "%s address of peer %s from `%s' to `%s'\n",
- (GNUNET_YES == address->active) ? "active" : "inactive",
- GNUNET_i2s (&address->peer),
- GNUNET_ATS_print_network_type (current_network),
- GNUNET_ATS_print_network_type (new_network));
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_change_network() Network type changed, moving "
+ "%s address of peer %s from '%s' to '%s'\n",
+ (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer),
+ GNUNET_ATS_print_network_type (current_network), GNUNET_ATS_print_network_type (new_network));
- address->solver_information = ril_get_network(solver, new_network);
+ if (address->active && !ril_network_is_active (solver, new_network))
+ {
+ GAS_ril_address_delete (solver, address, GNUNET_NO);
+ return;
+ }
- if (address->active)
+ agent = ril_get_agent (s, &address->peer, GNUNET_NO);
+ if (NULL == agent)
{
- agent = ril_get_agent(solver, &address->peer, GNUNET_NO);
+ //no agent there yet, so add as if address is new
+ address->solver_information = ril_get_network (s, new_network);
+ GAS_ril_address_add (s, address, new_network);
+ return;
+ }
- //remove from old network
- net = ril_get_network (s, current_network);
- net->bw_in_assigned -= agent->bw_in;
- net->bw_out_assigned -= agent->bw_out;
+ net = ril_get_network (s, current_network);
+ net->bw_in_assigned -= agent->bw_in;
+ net->bw_out_assigned -= agent->bw_out;
- if (ril_network_is_active(ril_get_network(s, new_network)))
- {
- //add to new network
- net = ril_get_network (s, new_network);
- net->bw_in_assigned += agent->bw_in;
- net->bw_out_assigned += agent->bw_out;
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_change_network() Moved %d inbound and %d "
- "outbound\n", agent->bw_in, agent->bw_out);
- }
- else //new network for this address is not active => address must not be considered
- {
- address->active = GNUNET_NO;
- agent->address = NULL; //delete address
- GNUNET_CONTAINER_multihashmap_iterate (s->addresses, &ril_init_agents_it,
- solver); //put another address
- if (NULL == agent->address) //no other address available
- {
- agent->active = GNUNET_NO;
- ril_remove_agent(s, agent);
- }
- }
- }
+ net = ril_get_network (s, new_network);
+ net->bw_in_assigned -= min_bw;
+ net->bw_out_assigned -= min_bw;
+ address->solver_information = net;
}
/**
double score)
{
//TODO! collect reward until next reward calculation
- //TODO! Find out application
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
"API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
"preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN",
GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000);
* they want. Consideration: Step-pause during bulk-start-stop period...
*/
- //GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start()\n");
+ //LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start()\n");
}
/**
* bulk counter down, see bulk_start()
*/
- //GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop()\n");
+ //LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop()\n");
}
/**
* @param peer the identity of the peer
*/
const struct ATS_Address *
-GAS_ril_get_preferred_address (void *solver,
- const struct GNUNET_PeerIdentity *peer)
+GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
{
/*
* activate agent, return currently chosen address
struct GAS_RIL_Handle *s = solver;
struct RIL_Peer_Agent *agent;
- agent = ril_get_agent (s, peer, GNUNET_NO);
-
- if (NULL == agent)
- {
- return NULL;
- }
+ agent = ril_get_agent (s, peer, GNUNET_YES);
agent->active = GNUNET_YES;
- GNUNET_assert(NULL != agent->address);
+ envi_set_active_suggestion(s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "API_get_preferred_address() Activated agent for peer '%s' with %s address\n",
- GNUNET_i2s (peer), agent->address->plugin);
+ if (agent->address_inuse)
+ {
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_get_preferred_address() Activated agent for peer '%s' with %s address %p\n",
+ GNUNET_i2s (peer), agent->address_inuse->plugin, agent->address_inuse->addr);
+ }
+ else
+ {
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_get_preferred_address() Activated agent for peer '%s', but no address available\n", GNUNET_i2s (peer));
+ }
- return agent->address;
+ return agent->address_inuse;
}
/**
* @param peer the peer
*/
void
-GAS_ril_stop_get_preferred_address (void *solver,
- const struct GNUNET_PeerIdentity *peer)
+GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
{
struct GAS_RIL_Handle *s = solver;
struct RIL_Peer_Agent *agent;
agent = ril_get_agent (s, peer, GNUNET_NO);
+
+ if (NULL == agent)
+ {
+ GNUNET_break(0);
+ return;
+ }
+ if (GNUNET_NO == agent->active)
+ {
+ GNUNET_break(0);
+ return;
+ }
+
agent->active = GNUNET_NO;
+ envi_set_active_suggestion(s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
"API_stop_get_preferred_address() Paused agent for peer '%s' with %s address\n",
- GNUNET_i2s (peer), agent->address->plugin);
+ GNUNET_i2s (peer), agent->address_inuse->plugin);
}
/* end of gnunet-service-ats-solver_ril.c */