diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-07-04 15:27:59 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-07-04 15:27:59 +0000 |
commit | 9bde041f15f890cb36d67cc0d085e6bc143112cb (patch) | |
tree | b34c08077c07e1fe6a338263e29084d2b42a871f | |
parent | 0151f4b4c92002f7f3e712d1d0bce3d7b2077312 (diff) |
major change to solver api: split _update function since it combined 3 different functionalities
proportional almost done, mlp to do
-rw-r--r-- | src/ats/gnunet-service-ats-solver_mlp.c | 67 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats-solver_mlp.h | 49 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats-solver_proportional.c | 286 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats-solver_proportional.h | 41 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 242 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 42 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 2 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.h | 2 | ||||
-rw-r--r-- | src/ats/test_ats_api.conf | 1 |
9 files changed, 396 insertions, 336 deletions
diff --git a/src/ats/gnunet-service-ats-solver_mlp.c b/src/ats/gnunet-service-ats-solver_mlp.c index 1e2237eee9..5a7fbfc78d 100644 --- a/src/ats/gnunet-service-ats-solver_mlp.c +++ b/src/ats/gnunet-service-ats-solver_mlp.c @@ -1401,6 +1401,45 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, mlp->mlp_prob_updated = GNUNET_YES; } +void +GAS_mlp_address_property_changed (void *solver, + struct ATS_Address *address, + uint32_t type, + uint32_t abs_value, + double rel_value) +{ + GNUNET_break (0); +} + + +void +GAS_mlp_address_session_changed (void *solver, + struct ATS_Address *address, + uint32_t cur_session, + uint32_t new_session) +{ + GNUNET_break (0); +} + +void +GAS_mlp_address_inuse_changed (void *solver, + struct ATS_Address *address, + uint32_t session, + int in_use) +{ + GNUNET_break (0); +} + + +void +GAS_mlp_address_change_network (void *solver, + struct ATS_Address *address, + uint32_t current_network, + uint32_t new_network) +{ + GNUNET_break (0); +} + /** * Updates a single address in the MLP problem * @@ -1432,6 +1471,7 @@ GAS_mlp_address_update (void *solver, struct ATS_Peer *p; struct GAS_MLP_Handle *mlp = solver; struct MLP_information *mlpi = address->solver_information; + int c1; GNUNET_assert (NULL != solver); GNUNET_assert (NULL != address); @@ -1442,22 +1482,37 @@ GAS_mlp_address_update (void *solver, LOG (GNUNET_ERROR_TYPE_ERROR, _("Updating address for peer `%s' not added before\n"), GNUNET_i2s(&address->peer)); return; } - mlp_update_quality (mlp, mlp->addresses, address, prev_atsi, prev_atsi_count); + + if (address->session_id != prev_session) + { + /* Session changed */ + + } + if ((NULL != prev_atsi) && (0 != prev_atsi_count)) + { + /* Properties changed */ + for (c1 = 0; c1 < prev_atsi_count; c1++ ) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating `%s'\n", + GNUNET_ATS_print_property_type (ntohl(prev_atsi[c1].type))); + //mlp->get_properties (mlp->get_properties_cls ); + } + //mlp_update_quality (mlp, mlp->addresses, address, prev_atsi, prev_atsi_count); + } /* Is this peer included in the problem? */ if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, &address->peer.hashPubKey))) { - LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s' without address request \n", GNUNET_i2s(&address->peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s' without address request \n", + GNUNET_i2s(&address->peer)); return; } - LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s' with address request \n", GNUNET_i2s(&address->peer)); - - /* Problem size changed: new address for peer with pending request */ + LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s' with address request \n", + GNUNET_i2s(&address->peer)); mlp->mlp_prob_updated = GNUNET_YES; if (GNUNET_YES == mlp->mlp_auto_solve) GAS_mlp_solve_problem (solver); - return; } /** diff --git a/src/ats/gnunet-service-ats-solver_mlp.h b/src/ats/gnunet-service-ats-solver_mlp.h index 3771bd2cee..9a8b8efdf4 100644 --- a/src/ats/gnunet-service-ats-solver_mlp.h +++ b/src/ats/gnunet-service-ats-solver_mlp.h @@ -415,34 +415,31 @@ GAS_mlp_address_add (void *solver, struct ATS_Address *address, uint32_t network); -/** - * Updates a single address in the MLP problem - * - * If the address did not exist before in the problem: - * The MLP problem has to be recreated and the problem has to be resolved - * - * ATS performance information in address are already updated, delta + previous - * values are included in atsi_prev (value GNUNET_ATS_VALUE_UNDEFINED if not existing before) - * - * Otherwise the addresses' values can be updated and the existing base can - * be reused - * - * @param solver the solver Handle - * @param addresses the address hashmap containing all addresses - * @param address the update address - * @param prev_session the new session (if changed otherwise current) - * @param prev_in_use the new address in use state (if changed otherwise current) - * @param prev_atsi ATS information updated + previous values, GNUNET_ATS_VALUE_UNDEFINED if not existing before - * @param prev_atsi_count number of atsi values updated - */ void -GAS_mlp_address_update (void *solver, - struct ATS_Address *address, - uint32_t prev_session, - int prev_in_use, - const struct GNUNET_ATS_Information *prev_atsi, - uint32_t prev_atsi_count); +GAS_mlp_address_property_changed (void *solver, + struct ATS_Address *address, + uint32_t type, + uint32_t abs_value, + double rel_value); + + +void +GAS_mlp_address_session_changed (void *solver, + struct ATS_Address *address, + uint32_t cur_session, + uint32_t new_session); + +void +GAS_mlp_address_inuse_changed (void *solver, + struct ATS_Address *address, + uint32_t session, + int in_use); +void +GAS_proportional_address_change_network (void *solver, + struct ATS_Address *address, + uint32_t current_network, + uint32_t new_network); /** * Deletes a single address in the MLP problem diff --git a/src/ats/gnunet-service-ats-solver_proportional.c b/src/ats/gnunet-service-ats-solver_proportional.c index 3aca611568..03cba6eb1a 100644 --- a/src/ats/gnunet-service-ats-solver_proportional.c +++ b/src/ats/gnunet-service-ats-solver_proportional.c @@ -431,7 +431,6 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, unsigned long long assigned_quota_out = 0; struct AddressWrapper *cur; - if (GNUNET_YES == s->bulk_lock) { s->bulk_requests++; @@ -556,18 +555,6 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, } -/** - * Extract an ATS performance info from an address - * - * @param address the address - * @param type the type to extract in HBO - * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist - */ -static int -get_performance_info (struct ATS_Address *address, uint32_t type); - - - struct FindBestAddressCtx { struct GAS_PROPORTIONAL_Handle *s; @@ -871,31 +858,6 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s, /** - * Extract an ATS performance info from an address - * - * @param address the address - * @param type the type to extract in HBO - * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist - */ -static int -get_performance_info (struct ATS_Address *address, uint32_t type) -{ - int c1; - GNUNET_assert (NULL != address); - - if ((NULL == address->atsi) || (0 == address->atsi_count)) - return GNUNET_ATS_VALUE_UNDEFINED; - - for (c1 = 0; c1 < address->atsi_count; c1++) - { - if (ntohl(address->atsi[c1].type) == type) - return ntohl(address->atsi[c1].value); - } - return GNUNET_ATS_VALUE_UNDEFINED; -} - - -/** * Solver API functions * --------------------------- */ @@ -1146,140 +1108,146 @@ GAS_proportional_address_add (void *solver, struct ATS_Address *address, uint32_t network); -/** - * Updates a single address in the solver and checks previous values - * - * @param solver the solver Handle - * @param addresses the address hashmap containing all addresses - * @param address the update address - * @param session the previous session - * @param in_use the previous address in use state - * @param prev_ats previous ATS information - * @param prev_atsi_count the previous atsi count - */ + void -GAS_proportional_address_update (void *solver, - struct ATS_Address *address, - uint32_t session, - int in_use, - const struct GNUNET_ATS_Information *prev_ats, - uint32_t prev_atsi_count) +GAS_proportional_address_property_changed (void *solver, + struct ATS_Address *address, + uint32_t type, + uint32_t abs_value, + double rel_value) { - struct ATS_Address *new; - struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) solver; - int i; - uint32_t prev_value; - uint32_t prev_type; - uint32_t addr_net; - int save_active = GNUNET_NO; - struct Network *new_net = NULL; + struct GAS_PROPORTIONAL_Handle *s; + struct Network *n; - /* Check updates to performance information */ - for (i = 0; i < prev_atsi_count; i++) - { - prev_type = ntohl (prev_ats[i].type); - prev_value = ntohl (prev_ats[i].value); - switch (prev_type) - { - case GNUNET_ATS_UTILIZATION_UP: - case GNUNET_ATS_UTILIZATION_DOWN: - case GNUNET_ATS_QUALITY_NET_DELAY: - case GNUNET_ATS_QUALITY_NET_DISTANCE: - case GNUNET_ATS_COST_WAN: - case GNUNET_ATS_COST_LAN: - case GNUNET_ATS_COST_WLAN: - /* No actions required here*/ - break; - case GNUNET_ATS_NETWORK_TYPE: - - addr_net = get_performance_info (address, GNUNET_ATS_NETWORK_TYPE); - if (GNUNET_ATS_VALUE_UNDEFINED == addr_net) - { - GNUNET_break (0); - addr_net = GNUNET_ATS_NET_UNSPECIFIED; - } - if (addr_net != prev_value) - { - /* Network changed */ - LOG (GNUNET_ERROR_TYPE_DEBUG, "Network type changed, moving %s address from `%s' to `%s'\n", - (GNUNET_YES == address->active) ? "active" : "inactive", - GNUNET_ATS_print_network_type(prev_value), - GNUNET_ATS_print_network_type(addr_net)); - - save_active = address->active; - /* remove from old network */ - GAS_proportional_address_delete (solver, address, GNUNET_NO); - - /* set new network type */ - new_net = get_network (solver, addr_net); - if (NULL == new_net) - { - /* Address changed to invalid network... */ - LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot find network of type `%u' %s\n"), - addr_net, GNUNET_ATS_print_network_type (addr_net)); - address->assigned_bw_in = GNUNET_BANDWIDTH_value_init (0); - address->assigned_bw_out = GNUNET_BANDWIDTH_value_init (0); - s->bw_changed (s->bw_changed_cls, address); - return; - } - address->solver_information = new_net; - - /* Add to new network and update*/ - GAS_proportional_address_add (solver, address, addr_net); - if (GNUNET_YES == save_active) - { - /* check if bandwidth available in new network */ - if (GNUNET_YES == (is_bandwidth_available_in_network (new_net))) - { - /* Suggest updated address */ - address->active = GNUNET_YES; - addresse_increment (s, new_net, GNUNET_NO, GNUNET_YES); - distribute_bandwidth_in_network (solver, new_net, NULL); - } - else - { - LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough bandwidth in new network, suggesting alternative address ..\n"); - - /* Set old address to zero bw */ - address->assigned_bw_in = GNUNET_BANDWIDTH_value_init (0); - address->assigned_bw_out = GNUNET_BANDWIDTH_value_init (0); - s->bw_changed (s->bw_changed_cls, address); - - /* Find new address to suggest since no bandwidth in network*/ - new = (struct ATS_Address *) GAS_proportional_get_preferred_address (s, &address->peer); - if (NULL != new) - { - /* Have an alternative address to suggest */ - s->bw_changed (s->bw_changed_cls, new); - } - } - } - } - break; - case GNUNET_ATS_ARRAY_TERMINATOR: - break; - default: - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received unsupported ATS type %u\n", prev_type); - GNUNET_break (0); - break; + GNUNET_assert (NULL != solver); + GNUNET_assert (NULL != address); - } + s = (struct GAS_PROPORTIONAL_Handle *) solver; + n = (struct Network *) address->solver_information; - } - if (address->session_id != session) + if (NULL == n) + { + GNUNET_break (0); + return; + } + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Property `%s' for peer `%s' address %p changed to %.2f %p %p %p\n", + GNUNET_ATS_print_property_type (type), + GNUNET_i2s (&address->peer), + address, + rel_value, s, n, &distribute_bandwidth_in_network); + switch (type) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Session changed from %u to %u\n", session, address->session_id); + case GNUNET_ATS_UTILIZATION_UP: + case GNUNET_ATS_UTILIZATION_DOWN: + case GNUNET_ATS_QUALITY_NET_DELAY: + case GNUNET_ATS_QUALITY_NET_DISTANCE: + case GNUNET_ATS_COST_WAN: + case GNUNET_ATS_COST_LAN: + case GNUNET_ATS_COST_WLAN: + + //FIXME distribute_bandwidth_in_network (s, n, GNUNET_NO); + break; } - if (address->used != in_use) +} + + +void +GAS_proportional_address_session_changed (void *solver, + struct ATS_Address *address, + uint32_t cur_session, + uint32_t new_session) +{ + if (cur_session!= new_session) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Usage changed from %u to %u\n", in_use, address->used); + "Session changed from %u to %u\n", cur_session, new_session); } +} +void +GAS_proportional_address_inuse_changed (void *solver, + struct ATS_Address *address, + int in_use) +{ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Usage changed to %s\n", + (GNUNET_YES == in_use) ? "USED" : "UNUSED"); } +void +GAS_proportional_address_change_network (void *solver, + struct ATS_Address *address, + uint32_t current_network, + uint32_t new_network) +{ + struct ATS_Address *new; + struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) solver; + int save_active = GNUNET_NO; + struct Network *new_net = NULL; + + if (current_network == new_network) + { + GNUNET_break (0); + return; + } + + /* Network changed */ + LOG (GNUNET_ERROR_TYPE_DEBUG, "Network type changed, moving %s address from `%s' to `%s'\n", + (GNUNET_YES == address->active) ? "active" : "inactive", + GNUNET_ATS_print_network_type (current_network), + GNUNET_ATS_print_network_type (new_network)); + + save_active = address->active; + /* remove from old network */ + GAS_proportional_address_delete (solver, address, GNUNET_NO); + + /* set new network type */ + new_net = get_network (solver, new_network); + if (NULL == new_net) + { + /* Address changed to invalid network... */ + LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot find network of type `%u' %s\n"), + new_network, GNUNET_ATS_print_network_type (new_network)); + address->assigned_bw_in = GNUNET_BANDWIDTH_value_init (0); + address->assigned_bw_out = GNUNET_BANDWIDTH_value_init (0); + s->bw_changed (s->bw_changed_cls, address); + return; + } + address->solver_information = new_net; + + /* Add to new network and update*/ + GAS_proportional_address_add (solver, address, new_network); + if (GNUNET_YES == save_active) + { + /* check if bandwidth available in new network */ + if (GNUNET_YES == (is_bandwidth_available_in_network (new_net))) + { + /* Suggest updated address */ + address->active = GNUNET_YES; + addresse_increment (s, new_net, GNUNET_NO, GNUNET_YES); + distribute_bandwidth_in_network (solver, new_net, NULL); + } + else + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough bandwidth in new network, suggesting alternative address ..\n"); + + /* Set old address to zero bw */ + address->assigned_bw_in = GNUNET_BANDWIDTH_value_init (0); + address->assigned_bw_out = GNUNET_BANDWIDTH_value_init (0); + s->bw_changed (s->bw_changed_cls, address); + + /* Find new address to suggest since no bandwidth in network*/ + new = (struct ATS_Address *) GAS_proportional_get_preferred_address (s, &address->peer); + if (NULL != new) + { + /* Have an alternative address to suggest */ + s->bw_changed (s->bw_changed_cls, new); + } + } + } +} /** * Add a new single address to a network diff --git a/src/ats/gnunet-service-ats-solver_proportional.h b/src/ats/gnunet-service-ats-solver_proportional.h index 9a185b21af..8ce3418477 100644 --- a/src/ats/gnunet-service-ats-solver_proportional.h +++ b/src/ats/gnunet-service-ats-solver_proportional.h @@ -114,26 +114,31 @@ GAS_proportional_address_add (void *solver, struct ATS_Address *address, uint32_t network); +void +GAS_proportional_address_property_changed (void *solver, + struct ATS_Address *address, + uint32_t type, + uint32_t abs_value, + double rel_value); + -/** - * Updates a single address in the solve - * - * @param solver the solver Handle - * @param addresses the address hashmap containing all addresses - * @param address the update address - * @param session the new session (if changed otherwise current) - * @param in_use the new address in use state (if changed otherwise current) - * @param prev_ats the latest ATS information - * @param prev_atsi_count the atsi count - */ void -GAS_proportional_address_update (void *solver, - struct ATS_Address *address, - uint32_t session, - int in_use, - const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count); +GAS_proportional_address_session_changed (void *solver, + struct ATS_Address *address, + uint32_t cur_session, + uint32_t new_session); +void +GAS_proportional_address_inuse_changed (void *solver, + struct ATS_Address *address, + uint32_t session, + int in_use); + +void +GAS_proportional_address_change_network (void *solver, + struct ATS_Address *address, + uint32_t current_network, + uint32_t new_network); /** * Remove an address from the solver @@ -166,7 +171,7 @@ GAS_proportional_bulk_stop (void *solver); /** * Stop notifying about address and bandwidth changes for this peer * - * @param solver the MLP handle + * @param solver the proportional handle * @param addresses address hashmap * @param peer the peer */ diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 6adb447983..dd12613fd0 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -338,10 +338,14 @@ struct GAS_Addresses_Handle */ GAS_solver_address_add s_add; - /** - * Update address in solver - */ - GAS_solver_address_update s_update; + + GAS_solver_address_property_changed s_address_update_property; + + GAS_solver_address_session_changed s_address_update_session; + + GAS_solver_address_inuse_changed s_address_update_inuse; + + GAS_solver_address_network_changed s_address_update_network; /** * Get address from solver @@ -666,8 +670,7 @@ find_equivalent_address (struct GAS_Addresses_Handle *handle, /** - * Lookup an ATS address by the address properties and session or return an - * equivalent address with a session == 0 + * Find the exact address * * @param handle the address handle to use * @param peer peer @@ -681,14 +684,12 @@ find_equivalent_address (struct GAS_Addresses_Handle *handle, */ static struct ATS_Address * -lookup_address (struct GAS_Addresses_Handle *handle, +find_exact_address (struct GAS_Addresses_Handle *handle, const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, - uint32_t session_id, - const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count) + uint32_t session_id) { struct ATS_Address *aa; struct ATS_Address *ea; @@ -702,13 +703,9 @@ lookup_address (struct GAS_Addresses_Handle *handle, ea = find_equivalent_address (handle, peer, aa); free_address (aa); if (ea == NULL) - { return NULL; - } else if (ea->session_id != session_id) - { return NULL; - } return ea; } @@ -754,16 +751,19 @@ get_performance_info (struct ATS_Address *address, uint32_t type) void GAS_addresses_add (struct GAS_Addresses_Handle *handle, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *plugin_addr, - size_t plugin_addr_len, uint32_t session_id, + const char *plugin_name, + const void *plugin_addr, + size_t plugin_addr_len, + uint32_t session_id, const struct GNUNET_ATS_Information *atsi, uint32_t atsi_count) { - struct ATS_Address *aa; - struct ATS_Address *ea; + struct ATS_Address *new_address; + struct ATS_Address *existing_address; struct GNUNET_ATS_Information *atsi_delta; uint32_t atsi_delta_count; uint32_t addr_net; + uint32_t previous_session; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -776,54 +776,55 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, GNUNET_assert (NULL != handle->addresses); - aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, + new_address = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id); atsi_delta = NULL; - disassemble_ats_information (aa, atsi, atsi_count, &atsi_delta, &atsi_delta_count); + disassemble_ats_information (new_address, atsi, atsi_count, &atsi_delta, &atsi_delta_count); GNUNET_free_non_null (atsi_delta); - addr_net = get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE); + addr_net = get_performance_info (new_address, GNUNET_ATS_NETWORK_TYPE); if (GNUNET_ATS_VALUE_UNDEFINED == addr_net) addr_net = GNUNET_ATS_NET_UNSPECIFIED; /* Get existing address or address with session == 0 */ - ea = find_equivalent_address (handle, peer, aa); - if (ea == NULL) + existing_address = find_equivalent_address (handle, peer, new_address); + if (existing_address == NULL) { - /* We have a new address */ + /* Add a new address */ GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (handle->addresses, - &peer->hashPubKey, aa, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' session id %u, %p\n", - GNUNET_i2s (peer), session_id, aa); + &peer->hashPubKey, new_address, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding new address for peer `%s' session id %u, %p\n", + GNUNET_i2s (peer), session_id, new_address); + /* Tell solver about new address */ + handle->s_add (handle->solver, new_address, addr_net); + handle->s_bulk_start (handle->solver); - GAS_normalization_normalize_property (handle->addresses, aa, atsi, atsi_count); + GAS_normalization_normalize_property (handle->addresses, new_address, atsi, atsi_count); handle->s_bulk_stop (handle->solver); - handle->s_add (handle->solver, aa, addr_net); + /* Notify performance clients about new address */ - GAS_performance_notify_all_clients (&aa->peer, - aa->plugin, - aa->addr, aa->addr_len, - aa->session_id, - aa->atsi, aa->atsi_count, - aa->assigned_bw_out, - aa->assigned_bw_in); + GAS_performance_notify_all_clients (&new_address->peer, + new_address->plugin, + new_address->addr, new_address->addr_len, + new_address->session_id, + new_address->atsi, new_address->atsi_count, + new_address->assigned_bw_out, + new_address->assigned_bw_in); return; } - GNUNET_free (aa->plugin); - GNUNET_free_non_null (aa->atsi); - GNUNET_free (aa); - aa = NULL; + /* We have an existing address we can use, clean up new */ + GNUNET_free (new_address->plugin); + GNUNET_free_non_null (new_address->atsi); + GNUNET_free (new_address); + new_address = NULL; - if (ea->session_id != 0) + if (0 != existing_address->session_id) { - /* This address with the same session is already existing - * Should not happen */ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Added already existing address for peer `%s' `%s' %p with new session %u\n", - GNUNET_i2s (peer), plugin_name, session_id); + /* Should not happen */ GNUNET_break (0); return; } @@ -831,29 +832,33 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, /* We have an address without an session, update this address */ atsi_delta = NULL; atsi_delta_count = 0; - if (GNUNET_YES == disassemble_ats_information (ea, atsi, atsi_count, &atsi_delta, &atsi_delta_count)) + if (GNUNET_YES == disassemble_ats_information (existing_address, atsi, atsi_count, &atsi_delta, &atsi_delta_count)) { - GAS_performance_notify_all_clients (&ea->peer, - ea->plugin, - ea->addr, ea->addr_len, - ea->session_id, - ea->atsi, ea->atsi_count, - ea->assigned_bw_out, - ea->assigned_bw_in); + /* Notify performance clients about properties */ + GAS_performance_notify_all_clients (&existing_address->peer, + existing_address->plugin, + existing_address->addr, existing_address->addr_len, + existing_address->session_id, + existing_address->atsi, existing_address->atsi_count, + existing_address->assigned_bw_out, + existing_address->assigned_bw_in); + + /* Notify solver about update with atsi information and session */ + handle->s_bulk_start (handle->solver); + GAS_normalization_normalize_property (handle->addresses, existing_address, atsi, atsi_count); + handle->s_bulk_stop (handle->solver); } - - /* Notify solver about update with atsi information and session */ - handle->s_bulk_start (handle->solver); - GAS_normalization_normalize_property (handle->addresses, ea, atsi, atsi_count); - handle->s_bulk_stop (handle->solver); - handle->s_update (handle->solver, ea, session_id, ea->used, atsi_delta, atsi_delta_count); GNUNET_free_non_null (atsi_delta); - /* Do the update */ - ea->session_id = session_id; + /* Notify solver about new session */ + previous_session = existing_address->session_id; + existing_address->session_id = session_id; + handle->s_address_update_session (handle->solver, existing_address, + previous_session, session_id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updated existing address for peer `%s' %p with new session %u\n", - GNUNET_i2s (peer), ea, session_id); + GNUNET_i2s (peer), existing_address, session_id); } @@ -884,6 +889,7 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, struct GNUNET_ATS_Information *atsi_delta; uint32_t atsi_delta_count; uint32_t prev_session; + int c1; if (GNUNET_NO == handle->running) return; @@ -891,8 +897,8 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, GNUNET_assert (NULL != handle->addresses); /* Get existing address */ - aa = lookup_address (handle, peer, plugin_name, plugin_addr, plugin_addr_len, - session_id, atsi, atsi_count); + aa = find_exact_address (handle, peer, plugin_name, + plugin_addr, plugin_addr_len, session_id); if (aa == NULL) { /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tried to update unknown address for peer `%s' `%s' session id %u\n", */ @@ -914,28 +920,44 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, GNUNET_i2s (peer), aa); /* Update address */ + if (session_id != aa->session_id) + { + /* Session changed */ + prev_session = aa->session_id; + aa->session_id = session_id; + handle->s_address_update_session (handle->solver, aa, prev_session, aa->session_id); + } + atsi_delta = NULL; atsi_delta_count = 0; if (GNUNET_YES == disassemble_ats_information (aa, atsi, atsi_count, &atsi_delta, &atsi_delta_count)) { - /* Notify performance clients about updated address */ - GAS_performance_notify_all_clients (&aa->peer, - aa->plugin, - aa->addr, aa->addr_len, - aa->session_id, - aa->atsi, aa->atsi_count, - aa->assigned_bw_out, - aa->assigned_bw_in); - } - prev_session = aa->session_id; - aa->session_id = session_id; + /* ATS properties changed */ - handle->s_bulk_start (handle->solver); - GAS_normalization_normalize_property (handle->addresses, aa, atsi, atsi_count); - handle->s_bulk_stop (handle->solver); + for (c1 = 0; c1 < atsi_delta_count; c1++) + { + if (GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) + { + /* Network type changed */ + handle->s_address_update_network (handle->solver, aa, + ntohl (atsi_delta[c1].value), + get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE)); + } + } - /* Tell solver about update */ - handle->s_update (handle->solver, aa, prev_session, aa->used, atsi_delta, atsi_delta_count); + /* Notify performance clients about updated address */ + GAS_performance_notify_all_clients (&aa->peer, + aa->plugin, + aa->addr, aa->addr_len, + aa->session_id, + aa->atsi, aa->atsi_count, + aa->assigned_bw_out, + aa->assigned_bw_in); + + handle->s_bulk_start (handle->solver); + GAS_normalization_normalize_property (handle->addresses, aa, atsi, atsi_count); + handle->s_bulk_stop (handle->solver); + } GNUNET_free_non_null (atsi_delta); } @@ -986,7 +1008,7 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, void *valu (0 == memcmp (des->addr, aa->addr, aa->addr_len))) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting full address for peer `%s' session %u %p\n", GNUNET_i2s (&aa->peer), aa->session_id, aa); @@ -1072,8 +1094,8 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, return; /* Get existing address */ - ea = lookup_address (handle, peer, plugin_name, plugin_addr, plugin_addr_len, - session_id, NULL, 0); + ea = find_exact_address (handle, peer, plugin_name, plugin_addr, + plugin_addr_len, session_id); if (ea == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Tried to destroy unknown address for peer `%s' `%s' session id %u\n", @@ -1081,7 +1103,7 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, return; } - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' for peer `%s' address %p session %u\n", "ADDRESS DESTROY", GNUNET_i2s (peer), ea, session_id); @@ -1125,8 +1147,6 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, int in_use) { struct ATS_Address *ea; - int prev_inuse; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' for peer `%s'\n", "ADDRESS IN USE", @@ -1135,9 +1155,8 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, if (GNUNET_NO == handle->running) return GNUNET_SYSERR; - ea = lookup_address (handle, peer, plugin_name, - plugin_addr, plugin_addr_len, - session_id, NULL, 0); + ea = find_exact_address (handle, peer, plugin_name, + plugin_addr, plugin_addr_len, session_id); if (NULL == ea) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -1160,11 +1179,8 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, } /* Tell solver about update */ - prev_inuse = ea->used; ea->used = in_use; - handle->s_update (handle->solver, ea, session_id, prev_inuse, NULL, 0); - - + handle->s_address_update_inuse (handle->solver, ea, ea->session_id, ea->used); return GNUNET_OK; } @@ -1340,25 +1356,30 @@ normalized_preference_changed_cb (void *cls, /** * The relative value for a property changed * - * @param cls the address handle + * @param solver the address handle * @param peer the peer * @param type the ATS type * @param prop_rel the new relative preference value */ static void -normalized_property_changed_cb (void *cls, - const struct ATS_Address *peer, +normalized_property_changed_cb (void *solver, + struct ATS_Address *address, uint32_t type, double prop_rel) { - GNUNET_assert (NULL != cls); - //struct GAS_Addresses_Handle *handle = cls; - /* Tell solver about update */ + GNUNET_assert (NULL != solver); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Normalized property %s for peer `%s' changed to %.3f \n", GNUNET_ATS_print_property_type (type), - GNUNET_i2s (&peer->peer), + GNUNET_i2s (&address->peer), prop_rel); + + GAS_proportional_address_property_changed (solver, + address, + type, + 0, + prop_rel); } @@ -1654,7 +1675,9 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, ah->ats_mode = MODE_MLP; ah->s_init = &GAS_mlp_init; ah->s_add = &GAS_mlp_address_add; - ah->s_update = &GAS_mlp_address_update; + ah->s_address_update_property = &GAS_mlp_address_property_changed; + ah->s_address_update_session = &GAS_mlp_address_session_changed; + ah->s_address_update_inuse = &GAS_mlp_address_inuse_changed; ah->s_get = &GAS_mlp_get_preferred_address; ah->s_get_stop = &GAS_mlp_stop_get_preferred_address; ah->s_pref = &GAS_mlp_address_change_preference; @@ -1663,7 +1686,6 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, ah->s_bulk_stop = &GAS_mlp_bulk_stop; ah->s_done = &GAS_mlp_done; #else - GNUNET_free (ah); return NULL; #endif @@ -1673,7 +1695,10 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, ah->ats_mode = MODE_SIMPLISTIC; ah->s_init = &GAS_proportional_init; ah->s_add = &GAS_proportional_address_add; - ah->s_update = &GAS_proportional_address_update; + ah->s_address_update_property = &GAS_proportional_address_property_changed; + ah->s_address_update_session = &GAS_proportional_address_session_changed; + ah->s_address_update_inuse = &GAS_proportional_address_inuse_changed; + ah->s_address_update_network = &GAS_proportional_address_change_network; ah->s_get = &GAS_proportional_get_preferred_address; ah->s_get_stop = &GAS_proportional_stop_get_preferred_address; ah->s_pref = &GAS_proportional_address_change_preference; @@ -1690,7 +1715,10 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_assert (NULL != ah->s_init); GNUNET_assert (NULL != ah->s_add); - GNUNET_assert (NULL != ah->s_update); + GNUNET_assert (NULL != ah->s_address_update_inuse); + GNUNET_assert (NULL != ah->s_address_update_property); + GNUNET_assert (NULL != ah->s_address_update_session); + GNUNET_assert (NULL != ah->s_address_update_network); GNUNET_assert (NULL != ah->s_get); GNUNET_assert (NULL != ah->s_get_stop); GNUNET_assert (NULL != ah->s_pref); @@ -1710,7 +1738,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, &get_property_cb, NULL); if (NULL == ah->solver) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize solver!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver!\n")); GNUNET_free (ah); return NULL; } diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index a01f67d13f..f5e42193bd 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h @@ -464,25 +464,31 @@ typedef void struct ATS_Address *address, int session_only); -/** - * Notify the solver about an update for an address - * - * @param solver the solver to use - * @param addresses the address hashmap containing all addresses - * @param address the address - * @param session the previous session - * @param in_use previous address used state: yes or no - * @param atsi ats previous performance information - * @param atsi_count previous number of ats performance information - * - */ + +typedef void +(*GAS_solver_address_property_changed) (void *solver, + struct ATS_Address *address, + uint32_t type, + uint32_t abs_value, + double rel_value); + +typedef void +(*GAS_solver_address_session_changed) (void *solver, + struct ATS_Address *address, + uint32_t cur_session, + uint32_t new_session); + +typedef void +(*GAS_solver_address_inuse_changed) (void *solver, + struct ATS_Address *address, + uint32_t session, + int in_use); + typedef void -(*GAS_solver_address_update) (void *solver, - struct ATS_Address *address, - uint32_t prev_session, - int in_use, - const struct GNUNET_ATS_Information *prev_atsi, - uint32_t prev_atsi_count); +(*GAS_solver_address_network_changed) (void *solver, + struct ATS_Address *address, + uint32_t current_network, + uint32_t new_network); /** diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index 6ced1b49e0..7a2876810d 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c @@ -745,7 +745,7 @@ property_normalize (struct GNUNET_CONTAINER_MultiHashMap *addresses, /** - * Update and normalize a atsi performance information + * Update and normalize atsi performance information * * @param addresses hashmap containing all addresses * @param address the address to update diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h index 551c47cd31..ed94530f95 100644 --- a/src/ats/gnunet-service-ats_normalization.h +++ b/src/ats/gnunet-service-ats_normalization.h @@ -43,7 +43,7 @@ typedef void typedef void (*GAS_Normalization_property_changed_cb) (void *cls, - const struct ATS_Address *peer, + struct ATS_Address *peer, uint32_t type, double prop_rel); diff --git a/src/ats/test_ats_api.conf b/src/ats/test_ats_api.conf index 9e00a15d7a..c71ec9c1c4 100644 --- a/src/ats/test_ats_api.conf +++ b/src/ats/test_ats_api.conf @@ -21,6 +21,7 @@ UNIX_MATCH_GID = YES # Enable MLP mode (default: NO) MODE = SIMPLISTIC +#MODE = MLP # Network specific inbound/outbound quotas # UNSPECIFIED UNSPECIFIED_QUOTA_IN = 64 KiB |