diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-30 20:35:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-30 20:35:10 +0000 |
commit | a0ba5b741b56036bd35bd9ba88164324b2ff7ada (patch) | |
tree | 3fd10a0fc15f9a9e7cf5415b2bec86d97d7fe825 /src/ats | |
parent | 427dd6f998fb1fde515a3b5c800f9f6d308197b2 (diff) |
-getting ATS and transport to compile again (part of #3047)
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats-solver_mlp.c | 132 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats-solver_mlp.h | 18 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats-solver_proportional.c | 88 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats-solver_proportional.h | 2 | ||||
-rwxr-xr-x | src/ats/gnunet-service-ats-solver_ril.c | 10 | ||||
-rwxr-xr-x | src/ats/gnunet-service-ats-solver_ril.h | 2 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 193 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 2 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 77 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.h | 24 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_reservations.c | 21 |
11 files changed, 332 insertions, 237 deletions
diff --git a/src/ats/gnunet-service-ats-solver_mlp.c b/src/ats/gnunet-service-ats-solver_mlp.c index f921c1b1f9..f36a3808ea 100644 --- a/src/ats/gnunet-service-ats-solver_mlp.c +++ b/src/ats/gnunet-service-ats-solver_mlp.c @@ -177,7 +177,9 @@ mlp_term_hook (void *info, const char *s) * @return GNUNET_OK */ static int -reset_peers (void *cls, const struct GNUNET_HashCode * key, void *value) +reset_peers (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct ATS_Peer *peer = value; peer->processed = GNUNET_NO; @@ -237,7 +239,8 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp) mlp->p.ci = MLP_UNDEFINED; - GNUNET_CONTAINER_multihashmap_iterate (mlp->requested_peers, &reset_peers, NULL); + GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers, + &reset_peers, NULL); } @@ -385,28 +388,34 @@ get_performance_info (struct ATS_Address *address, uint32_t type) struct CountContext { - struct GNUNET_CONTAINER_MultiHashMap * peers; + const struct GNUNET_CONTAINER_MultiPeerMap *peers; int result; }; static int -mlp_create_problem_count_addresses_it (void *cls, const struct GNUNET_HashCode *key, void *value) +mlp_create_problem_count_addresses_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct CountContext *cctx = cls; + /* Check if we have to add this peer due to a pending request */ - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(cctx->peers, key)) + if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->peers, key)) cctx->result++; return GNUNET_OK; } -static int mlp_create_problem_count_addresses ( - struct GNUNET_CONTAINER_MultiHashMap * peers, - const struct GNUNET_CONTAINER_MultiHashMap * addresses) + +static int +mlp_create_problem_count_addresses (const struct GNUNET_CONTAINER_MultiPeerMap *peers, + const struct GNUNET_CONTAINER_MultiPeerMap *addresses) { struct CountContext cctx; + cctx.peers = peers; cctx.result = 0; - GNUNET_CONTAINER_multihashmap_iterate (addresses, &mlp_create_problem_count_addresses_it, &cctx); + GNUNET_CONTAINER_multipeermap_iterate (addresses, + &mlp_create_problem_count_addresses_it, &cctx); return cctx.result; } @@ -591,7 +600,9 @@ mlp_create_problem_create_constraint (struct MLP_Problem *p, char *name, * - Set address dependent entries in problem matrix as well */ static int -mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashCode *key, void *value) +mlp_create_problem_add_address_information (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct GAS_MLP_Handle *mlp = cls; struct MLP_Problem *p = &mlp->p; @@ -604,7 +615,7 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC int c; /* Check if we have to add this peer due to a pending request */ - if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->requested_peers, key)) + if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(mlp->requested_peers, key)) return GNUNET_OK; mlpi = address->solver_information; @@ -616,7 +627,7 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC } /* Get peer */ - peer = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, key); + peer = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, key); if (peer->processed == GNUNET_NO) { /* Add peer dependent constraints */ @@ -822,14 +833,18 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp) /* create the glpk problem */ p->prob = glp_create_prob (); GNUNET_assert (NULL != p->prob); - p->num_peers = GNUNET_CONTAINER_multihashmap_size (mlp->requested_peers); + p->num_peers = GNUNET_CONTAINER_multipeermap_size (mlp->requested_peers); p->num_addresses = mlp_create_problem_count_addresses (mlp->requested_peers, mlp->addresses); /* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */ p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses + mlp->pv.m_q + p->num_peers + 2 + 1); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n", - p->num_peers, p->num_addresses, mlp->pv.m_q, p->num_elements); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n", + p->num_peers, + p->num_addresses, + mlp->pv.m_q, + p->num_elements); /* Set a problem name */ glp_set_prob_name (p->prob, "GNUnet ATS bandwidth distribution"); @@ -859,7 +874,9 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp) mlp_create_problem_add_invariant_rows (mlp, p); /* Adding address dependent columns constraint rows */ - GNUNET_CONTAINER_multihashmap_iterate (mlp->addresses, &mlp_create_problem_add_address_information, mlp); + GNUNET_CONTAINER_multipeermap_iterate (mlp->addresses, + &mlp_create_problem_add_address_information, + mlp); /* Load the matrix */ LOG (GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n"); @@ -941,10 +958,12 @@ mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp) * @param cls the MLP handle * @param key the peer identity * @param value the address - * @return GNUNET_OK to continue + * @return #GNUNET_OK to continue */ int -mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value) +mlp_propagate_results (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct GAS_MLP_Handle *mlp = cls; struct ATS_Address *address; @@ -954,7 +973,8 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value double mlp_use = MLP_NaN; /* Check if we have to add this peer due to a pending request */ - if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->requested_peers, key)) + if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mlp->requested_peers, + key)) { return GNUNET_OK; } @@ -1082,9 +1102,9 @@ GAS_mlp_solve_problem (void *solver) return GNUNET_NO; } - if (0 == GNUNET_CONTAINER_multihashmap_size(mlp->requested_peers)) + if (0 == GNUNET_CONTAINER_multipeermap_size (mlp->requested_peers)) return GNUNET_OK; /* No pending requests */ - if (0 == GNUNET_CONTAINER_multihashmap_size(mlp->addresses)) + if (0 == GNUNET_CONTAINER_multipeermap_size (mlp->addresses)) return GNUNET_OK; /* No addresses available */ if ((GNUNET_NO == mlp->mlp_prob_changed) && (GNUNET_NO == mlp->mlp_prob_updated)) @@ -1149,7 +1169,7 @@ GAS_mlp_solve_problem (void *solver) /* Propagate result*/ if ((GNUNET_OK == res_lp) && (GNUNET_OK == res_mip)) { - GNUNET_CONTAINER_multihashmap_iterate (mlp->addresses, &mlp_propagate_results, mlp); + GNUNET_CONTAINER_multipeermap_iterate (mlp->addresses, &mlp_propagate_results, mlp); } struct GNUNET_TIME_Absolute time = GNUNET_TIME_absolute_get(); @@ -1201,13 +1221,16 @@ GAS_mlp_address_add (void *solver, if (NULL == address->solver_information) { - address->solver_information = GNUNET_malloc (sizeof (struct MLP_information)); + address->solver_information = GNUNET_new (struct MLP_information); } else - LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding address for peer `%s' multiple times\n"), GNUNET_i2s(&address->peer)); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Adding address for peer `%s' multiple times\n"), + GNUNET_i2s(&address->peer)); /* Is this peer included in the problem? */ - if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, &address->peer.hashPubKey))) + if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, + &address->peer))) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer `%s' without address request \n", GNUNET_i2s(&address->peer)); return; @@ -1257,8 +1280,8 @@ GAS_mlp_address_property_changed (void *solver, return; } - if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, - &address->peer.hashPubKey))) + if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, + &address->peer))) { /* Peer is not requested, so no need to update problem */ return; @@ -1368,8 +1391,8 @@ GAS_mlp_address_change_network (void *solver, if (mlpi->c_b == MLP_UNDEFINED) return; /* This address is not yet in the matrix*/ - if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, - &address->peer.hashPubKey))) + if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, + &address->peer))) { /* Peer is not requested, so no need to update problem */ GNUNET_break (0); @@ -1467,7 +1490,8 @@ GAS_mlp_address_delete (void *solver, address->assigned_bw_out = BANDWIDTH_ZERO; /* Is this peer included in the problem? */ - if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, &address->peer.hashPubKey))) + if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, + &address->peer))) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Deleting %s for peer `%s' without address request \n", (session_only == GNUNET_YES) ? "session" : "address", @@ -1505,12 +1529,15 @@ GAS_mlp_address_delete (void *solver, * @return GNUNET_OK */ static int -mlp_get_preferred_address_it (void *cls, const struct GNUNET_HashCode * key, void *value) +mlp_get_preferred_address_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { static int counter = 0; - struct ATS_Address **aa = (struct ATS_Address **) cls; + struct ATS_Address **aa = cls; struct ATS_Address *addr = value; struct MLP_information *mlpi = addr->solver_information; + if (mlpi == NULL) return GNUNET_YES; @@ -1536,7 +1563,8 @@ mlp_get_preferred_address_it (void *cls, const struct GNUNET_HashCode * key, voi } -static double get_peer_pref_value (struct GAS_MLP_Handle *mlp, const struct GNUNET_PeerIdentity *peer) +static double +get_peer_pref_value (struct GAS_MLP_Handle *mlp, const struct GNUNET_PeerIdentity *peer) { double res; const double *preferences = NULL; @@ -1579,22 +1607,25 @@ GAS_mlp_get_preferred_address (void *solver, GNUNET_i2s (peer)); /* Is this peer included in the problem? */ - if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, &peer->hashPubKey))) - { + if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, + peer))) + { LOG (GNUNET_ERROR_TYPE_INFO, "Adding peer `%s' to list of requested_peers with requests\n", GNUNET_i2s (peer)); p = GNUNET_malloc (sizeof (struct ATS_Peer)); p->id = (*peer); p->f = get_peer_pref_value (mlp, peer); - GNUNET_CONTAINER_multihashmap_put (mlp->requested_peers, &peer->hashPubKey, p, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + GNUNET_CONTAINER_multipeermap_put (mlp->requested_peers, + peer, p, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); /* Added new peer, we have to rebuild problem before solving */ mlp->mlp_prob_changed = GNUNET_YES; if ((GNUNET_YES == mlp->mlp_auto_solve)&& - (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(mlp->addresses, - &peer->hashPubKey))) + (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->addresses, + peer))) { mlp->exclude_peer = peer; GAS_mlp_solve_problem (mlp); @@ -1603,7 +1634,7 @@ GAS_mlp_get_preferred_address (void *solver, } /* Get prefered address */ res = NULL; - GNUNET_CONTAINER_multihashmap_get_multiple (mlp->addresses, &peer->hashPubKey, + GNUNET_CONTAINER_multipeermap_get_multiple (mlp->addresses, peer, mlp_get_preferred_address_it, &res); return res; } @@ -1664,9 +1695,9 @@ GAS_mlp_stop_get_preferred_address (void *solver, GNUNET_assert (NULL != solver); GNUNET_assert (NULL != peer); - if (NULL != (p = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, &peer->hashPubKey))) + if (NULL != (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, peer))) { - GNUNET_CONTAINER_multihashmap_remove (mlp->requested_peers, &peer->hashPubKey, p); + GNUNET_CONTAINER_multipeermap_remove (mlp->requested_peers, peer, p); GNUNET_free (p); mlp->mlp_prob_changed = GNUNET_YES; @@ -1704,7 +1735,7 @@ GAS_mlp_address_change_preference (void *solver, /* Update quality constraint c7 */ /* Update relativity constraint c9 */ - if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, &peer->hashPubKey))) + if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, peer))) { LOG (GNUNET_ERROR_TYPE_ERROR, "Updating preference for unknown peer `%s'\n", GNUNET_i2s(peer)); return; @@ -1749,12 +1780,13 @@ GAS_mlp_address_preference_feedback (void *solver, static int -mlp_free_peers (void *cls, const struct GNUNET_HashCode *key, void *value) +mlp_free_peers (void *cls, + const struct GNUNET_PeerIdentity *key, void *value) { - struct GNUNET_CONTAINER_MultiHashMap *map = cls; + struct GNUNET_CONTAINER_MultiPeerMap *map = cls; struct ATS_Peer *p = value; - GNUNET_CONTAINER_multihashmap_remove (map, key, value); + GNUNET_CONTAINER_multipeermap_remove (map, key, value); GNUNET_free (p); return GNUNET_OK; @@ -1775,8 +1807,10 @@ GAS_mlp_done (void *solver) LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down mlp solver\n"); mlp_delete_problem (mlp); - GNUNET_CONTAINER_multihashmap_iterate (mlp->requested_peers, &mlp_free_peers, mlp->requested_peers); - GNUNET_CONTAINER_multihashmap_destroy (mlp->requested_peers); + GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers, + &mlp_free_peers, + mlp->requested_peers); + GNUNET_CONTAINER_multipeermap_destroy (mlp->requested_peers); mlp->requested_peers = NULL; /* Clean up GLPK environment */ @@ -1808,7 +1842,7 @@ GAS_mlp_done (void *solver) void * GAS_mlp_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_dest, unsigned long long *in_dest, @@ -2052,7 +2086,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, mlp->mlp_prob_changed = GNUNET_NO; mlp->mlp_prob_updated = GNUNET_NO; mlp->mlp_auto_solve = GNUNET_YES; - mlp->requested_peers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); + mlp->requested_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); mlp->bulk_request = 0; mlp->bulk_lock = 0; diff --git a/src/ats/gnunet-service-ats-solver_mlp.h b/src/ats/gnunet-service-ats-solver_mlp.h index c31d44b5eb..1f4f0ec8ce 100644 --- a/src/ats/gnunet-service-ats-solver_mlp.h +++ b/src/ats/gnunet-service-ats-solver_mlp.h @@ -212,7 +212,7 @@ struct GAS_MLP_Handle /** * Address hashmap for lookups */ - const struct GNUNET_CONTAINER_MultiHashMap *addresses; + const struct GNUNET_CONTAINER_MultiPeerMap *addresses; /** * Addresses' bandwidth changed callback @@ -296,7 +296,7 @@ struct GAS_MLP_Handle /** * Peers with pending address requests */ - struct GNUNET_CONTAINER_MultiHashMap *requested_peers; + struct GNUNET_CONTAINER_MultiPeerMap *requested_peers; /** * Was the problem updated since last solution @@ -355,15 +355,17 @@ struct MLP_information unsigned int r_c3; }; + /** * Solves the MLP problem * * @param solver the MLP Handle - * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure + * @return #GNUNET_OK if could be solved, GNUNET_SYSERR on failure */ int GAS_mlp_solve_problem (void *solver); + /** * Init the MLP problem solving component * @@ -383,13 +385,14 @@ GAS_mlp_solve_problem (void *solver); */ void * GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_STATISTICS_Handle *stats, - const struct GNUNET_CONTAINER_MultiHashMap *addresses, int *network, + const struct GNUNET_STATISTICS_Handle *stats, + const struct GNUNET_CONTAINER_MultiPeerMap *addresses, int *network, unsigned long long *out_dest, unsigned long long *in_dest, int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, void *bw_changed_cb_cls, GAS_get_preferences get_preference, void *get_preference_cls, GAS_get_properties get_properties, void *get_properties_cls); + /** * Add a single address within a network to the solver * @@ -401,6 +404,7 @@ void GAS_mlp_address_add (void *solver, struct ATS_Address *address, uint32_t network); + /** * Transport properties for this address have changed * @@ -414,6 +418,7 @@ void GAS_mlp_address_property_changed (void *solver, struct ATS_Address *address, uint32_t type, uint32_t abs_value, double rel_value); + /** * Transport session for this address has changed * @@ -426,7 +431,8 @@ GAS_mlp_address_property_changed (void *solver, struct ATS_Address *address, */ void GAS_mlp_address_session_changed (void *solver, struct ATS_Address *address, - uint32_t cur_session, uint32_t new_session); + uint32_t cur_session, uint32_t new_session); + /** * Usage for this address has changed diff --git a/src/ats/gnunet-service-ats-solver_proportional.c b/src/ats/gnunet-service-ats-solver_proportional.c index 31d27fd2a6..e9a553ad62 100644 --- a/src/ats/gnunet-service-ats-solver_proportional.c +++ b/src/ats/gnunet-service-ats-solver_proportional.c @@ -225,12 +225,12 @@ struct GAS_PROPORTIONAL_Handle /** * Hashmap containing all valid addresses */ - const struct GNUNET_CONTAINER_MultiHashMap *addresses; + const struct GNUNET_CONTAINER_MultiPeerMap *addresses; /** * Pending address requests */ - struct GNUNET_CONTAINER_MultiHashMap *requests; + struct GNUNET_CONTAINER_MultiPeerMap *requests; /** * Bandwidth changed callback @@ -576,8 +576,9 @@ find_property_index (uint32_t type) * @return GNUNET_OK (continue to iterate) */ static int -find_best_address_it (void *cls, const struct GNUNET_HashCode * key, - void *value) +find_best_address_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct FindBestAddressCtx *fba_ctx = (struct FindBestAddressCtx *) cls; struct ATS_Address *current = (struct ATS_Address *) value; @@ -717,11 +718,12 @@ get_network (struct GAS_PROPORTIONAL_Handle *s, uint32_t type) * @param cls last active address * @param key peer's key * @param value address to check - * @return GNUNET_NO on double active address else GNUNET_YES; + * @return #GNUNET_NO on double active address else #GNUNET_YES; */ static int -get_active_address_it (void *cls, const struct GNUNET_HashCode * key, - void *value) +get_active_address_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct ATS_Address **dest = cls; struct ATS_Address *aa = (struct ATS_Address *) value; @@ -752,16 +754,17 @@ get_active_address_it (void *cls, const struct GNUNET_HashCode * key, */ static struct ATS_Address * get_active_address (void *solver, - struct GNUNET_CONTAINER_MultiHashMap * addresses, - const struct GNUNET_PeerIdentity *peer) + const struct GNUNET_CONTAINER_MultiPeerMap * addresses, + const struct GNUNET_PeerIdentity *peer) { struct ATS_Address * dest = NULL; - GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, - &get_active_address_it, &dest); + GNUNET_CONTAINER_multipeermap_get_multiple (addresses, peer, + &get_active_address_it, &dest); return dest; } + static void addresse_increment (struct GAS_PROPORTIONAL_Handle *s, struct Network *net, int total, int active) @@ -784,6 +787,7 @@ addresse_increment (struct GAS_PROPORTIONAL_Handle *s, struct Network *net, } + static int addresse_decrement (struct GAS_PROPORTIONAL_Handle *s, struct Network *net, int total, int active) @@ -856,8 +860,9 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s, struct Network *net, */ void GAS_proportional_address_change_preference (void *solver, - const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, - double pref_rel) + const struct GNUNET_PeerIdentity *peer, + enum GNUNET_ATS_PreferenceKind kind, + double pref_rel) { struct GAS_PROPORTIONAL_Handle *s = solver; GNUNET_assert(NULL != solver); @@ -866,6 +871,7 @@ GAS_proportional_address_change_preference (void *solver, distribute_bandwidth_in_all_networks (s); } + /** * Get application feedback for a peer * @@ -910,19 +916,21 @@ GAS_proportional_get_preferred_address (void *solver, GNUNET_assert(peer != NULL); /* Add to list of pending requests */ - if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (s->requests, - &peer->hashPubKey)) + if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, + peer)) { - GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (s->requests, &peer->hashPubKey, NULL, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put (s->requests, + peer, NULL, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); } /* Get address with: stick to current address, lower distance, lower latency */ fba_ctx.s = s; fba_ctx.best = NULL; - GNUNET_CONTAINER_multihashmap_get_multiple (s->addresses, &peer->hashPubKey, - &find_best_address_it, &fba_ctx); + GNUNET_CONTAINER_multipeermap_get_multiple (s->addresses, peer, + &find_best_address_it, &fba_ctx); if (NULL == fba_ctx.best) { LOG(GNUNET_ERROR_TYPE_INFO, "Cannot suggest address for peer `%s'\n", @@ -954,7 +962,7 @@ GAS_proportional_get_preferred_address (void *solver, * - update quota for this address network */ prev = get_active_address (s, - (struct GNUNET_CONTAINER_MultiHashMap *) s->addresses, peer); + s->addresses, peer); if (NULL != prev) { net_prev = (struct Network *) prev->solver_information; @@ -993,13 +1001,13 @@ GAS_proportional_stop_get_preferred_address (void *solver, struct Network *cur_net; if (GNUNET_YES - == GNUNET_CONTAINER_multihashmap_contains (s->requests, - &peer->hashPubKey)) - GNUNET_CONTAINER_multihashmap_remove (s->requests, &peer->hashPubKey, - NULL ); + == GNUNET_CONTAINER_multipeermap_contains (s->requests, + peer)) + GNUNET_CONTAINER_multipeermap_remove (s->requests, peer, + NULL); cur = get_active_address (s, - (struct GNUNET_CONTAINER_MultiHashMap *) s->addresses, peer); + s->addresses, peer); if (NULL != cur) { /* Disabling current address */ @@ -1115,6 +1123,7 @@ GAS_proportional_bulk_start (void *solver) s->bulk_lock++; } + /** * Bulk operation done */ @@ -1140,6 +1149,7 @@ GAS_proportional_bulk_stop (void *solver) } } + /** * Add a new single address to a network * @@ -1357,9 +1367,9 @@ GAS_proportional_address_add (void *solver, struct ATS_Address *address, addresse_increment (s, net, GNUNET_YES, GNUNET_NO); aw->addr->solver_information = net; - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (s->requests, &address->peer.hashPubKey)) + if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (s->requests, &address->peer)) { - if (NULL == get_active_address (s, (struct GNUNET_CONTAINER_MultiHashMap *) s->addresses, &address->peer)) + if (NULL == get_active_address (s, s->addresses, &address->peer)) { if (NULL != (new_address = GAS_proportional_get_preferred_address (s, &address->peer))) s->bw_changed (s->bw_changed_cls, (struct ATS_Address *) address); @@ -1401,13 +1411,13 @@ GAS_proportional_address_add (void *solver, struct ATS_Address *address, */ void * GAS_proportional_init (const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_STATISTICS_Handle *stats, - const struct GNUNET_CONTAINER_MultiHashMap *addresses, int *network, - unsigned long long *out_quota, unsigned long long *in_quota, - int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, - void *bw_changed_cb_cls, GAS_get_preferences get_preference, - void *get_preference_cls, GAS_get_properties get_properties, - void *get_properties_cls) + const struct GNUNET_STATISTICS_Handle *stats, + const struct GNUNET_CONTAINER_MultiPeerMap *addresses, int *network, + unsigned long long *out_quota, unsigned long long *in_quota, + int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, + void *bw_changed_cb_cls, GAS_get_preferences get_preference, + void *get_preference_cls, GAS_get_properties get_properties, + void *get_properties_cls) { int c; struct GAS_PROPORTIONAL_Handle *s = @@ -1436,7 +1446,7 @@ GAS_proportional_init (const struct GNUNET_CONFIGURATION_Handle *cfg, s->bulk_lock = GNUNET_NO; s->addresses = addresses; - s->requests = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); + s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); for (c = 0; c < dest_length; c++) { @@ -1508,11 +1518,11 @@ GAS_proportional_done (void *solver) LOG(GNUNET_ERROR_TYPE_ERROR, "Had %u active addresses not deleted during shutdown\n", s->active_addresses); - GNUNET_break(0); + GNUNET_break (0); } - GNUNET_free(s->network_entries); - GNUNET_CONTAINER_multihashmap_destroy (s->requests); - GNUNET_free(s); + GNUNET_free (s->network_entries); + GNUNET_CONTAINER_multipeermap_destroy (s->requests); + GNUNET_free (s); } /* end of gnunet-service-ats-solver_proportional.c */ diff --git a/src/ats/gnunet-service-ats-solver_proportional.h b/src/ats/gnunet-service-ats-solver_proportional.h index 13cf54e8da..87b4488662 100644 --- a/src/ats/gnunet-service-ats-solver_proportional.h +++ b/src/ats/gnunet-service-ats-solver_proportional.h @@ -95,7 +95,7 @@ GAS_proportional_address_preference_feedback (void *solver, void *application, void * GAS_proportional_init (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_STATISTICS_Handle *stats, - const struct GNUNET_CONTAINER_MultiHashMap *addresses, int *network, + const struct GNUNET_CONTAINER_MultiPeerMap *addresses, int *network, unsigned long long *out_quota, unsigned long long *in_quota, int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, void *bw_changed_cb_cls, GAS_get_preferences get_preference, diff --git a/src/ats/gnunet-service-ats-solver_ril.c b/src/ats/gnunet-service-ats-solver_ril.c index 8cc91bdf35..5121846270 100755 --- a/src/ats/gnunet-service-ats-solver_ril.c +++ b/src/ats/gnunet-service-ats-solver_ril.c @@ -290,7 +290,7 @@ struct GAS_RIL_Handle /** * Hashmap containing all valid addresses */ - const struct GNUNET_CONTAINER_MultiHashMap *addresses; + const struct GNUNET_CONTAINER_MultiPeerMap *addresses; /** * Callbacks for the solver @@ -976,7 +976,9 @@ ril_get_agent (struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity * 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; } @@ -1129,7 +1131,7 @@ GAS_ril_address_change_preference (void *s, 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, @@ -1145,7 +1147,7 @@ GAS_ril_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 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); LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n"); diff --git a/src/ats/gnunet-service-ats-solver_ril.h b/src/ats/gnunet-service-ats-solver_ril.h index 0053e3b9d1..16f1fee5f1 100755 --- a/src/ats/gnunet-service-ats-solver_ril.h +++ b/src/ats/gnunet-service-ats-solver_ril.h @@ -80,7 +80,7 @@ GAS_ril_address_change_preference (void *solver, 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, diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 4db70dbaee..8e3692b8e3 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -294,7 +294,7 @@ struct GAS_Addresses_Handle /** * A multihashmap to store all addresses */ - struct GNUNET_CONTAINER_MultiHashMap *addresses; + struct GNUNET_CONTAINER_MultiPeerMap *addresses; /** * Configure WAN quota in @@ -574,17 +574,19 @@ struct CompareAddressContext struct ATS_Address *base_address; }; + /** * Comapre addresses * * @param cls a CompareAddressContext containin the source address * @param key peer id * @param value the address to compare with - * @return GNUNET_YES to continue, GNUNET_NO if address is founce + * @return #GNUNET_YES to continue, #GNUNET_NO if address is founce */ - static int -compare_address_it (void *cls, const struct GNUNET_HashCode * key, void *value) +compare_address_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct CompareAddressContext *cac = cls; struct ATS_Address *aa = value; @@ -672,14 +674,16 @@ find_equivalent_address (struct GAS_Addresses_Handle *handle, cac.exact_address = NULL; cac.base_address = NULL; cac.search = addr; - GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, - &peer->hashPubKey, &compare_address_it, &cac); + GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, + peer, + &compare_address_it, &cac); - if (cac.exact_address == NULL ) + if (cac.exact_address == NULL) return cac.base_address; return cac.exact_address; } + /** * Find the exact address * @@ -787,13 +791,13 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, { /* Add a new address */ GNUNET_assert( - GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (handle->addresses, - &peer->hashPubKey, - new_address, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (handle->addresses, + peer, + new_address, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); GNUNET_STATISTICS_set (handle->stat, "# addresses", - GNUNET_CONTAINER_multihashmap_size (handle->addresses), GNUNET_NO); + GNUNET_CONTAINER_multipeermap_size (handle->addresses), GNUNET_NO); GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Adding new address %p for peer `%s', length %u, session id %u, %s\n", @@ -1013,8 +1017,9 @@ struct DestroyContext * @return GNUNET_OK (continue to iterate) */ static int -destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, - void *value) +destroy_by_session_id (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct DestroyContext *dc = cls; struct GAS_Addresses_Handle *handle = dc->handle; @@ -1038,7 +1043,9 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, /* Notify solver about deletion */ GNUNET_assert( - GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->addresses, &aa->peer.hashPubKey, aa)); + GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (handle->addresses, + &aa->peer, + aa)); handle->s_del (handle->solver, aa, GNUNET_NO); free_address (aa); dc->result = GNUNET_NO; @@ -1069,7 +1076,8 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, /* Notify solver about deletion */ GNUNET_assert( - GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->addresses, &aa->peer.hashPubKey, aa)); + GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (handle->addresses, + &aa->peer, aa)); handle->s_del (handle->solver, aa, GNUNET_NO); free_address (aa); dc->result = GNUNET_NO; @@ -1091,6 +1099,7 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, return GNUNET_OK; } + /** * Remove an address or just a session for a peer. * @@ -1131,10 +1140,11 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, dc.aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id); - GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, - &peer->hashPubKey, &destroy_by_session_id, &dc); + GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, + peer, + &destroy_by_session_id, &dc); GNUNET_STATISTICS_set (handle->stat, "# addresses", - GNUNET_CONTAINER_multihashmap_size (handle->addresses), GNUNET_NO); + GNUNET_CONTAINER_multipeermap_size (handle->addresses), GNUNET_NO); free_address (dc.aa); } @@ -1308,22 +1318,26 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle, * @param cls not used * @param key the peer * @param value the address to reset - * @return GNUNET_OK to continue + * @return #GNUNET_OK to continue */ static int -reset_address_it (void *cls, const struct GNUNET_HashCode *key, void *value) +reset_address_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct ATS_Address *aa = value; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Resetting interval for peer `%s' address %p from %llu to 0\n", - GNUNET_i2s (&aa->peer), aa, aa->block_interval); - + "Resetting interval for peer `%s' address %p from %llu to 0\n", + GNUNET_i2s (&aa->peer), + aa, + aa->block_interval); aa->blocked_until = GNUNET_TIME_UNIT_ZERO_ABS; aa->block_interval = GNUNET_TIME_UNIT_ZERO; return GNUNET_OK; } + /** * Reset suggestion backoff for a peer * @@ -1341,9 +1355,12 @@ GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle, "RESET BACKOFF", GNUNET_i2s (peer)); GNUNET_break( - GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, &reset_address_it, NULL)); + GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, + peer, + &reset_address_it, NULL)); } + /** * The preference changed for a peer * @@ -1436,9 +1453,9 @@ GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle, if (GNUNET_NO == handle->running) return; - if (GNUNET_NO - == GNUNET_CONTAINER_multihashmap_contains (handle->addresses, - &peer->hashPubKey)) + if (GNUNET_NO == + GNUNET_CONTAINER_multipeermap_contains (handle->addresses, + peer)) { GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Received `%s' for unknown peer `%s' from client %p\n", @@ -1475,9 +1492,9 @@ GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle, if (GNUNET_NO == handle->running) return; - if (GNUNET_NO - == GNUNET_CONTAINER_multihashmap_contains (handle->addresses, - &peer->hashPubKey)) + if (GNUNET_NO == + GNUNET_CONTAINER_multipeermap_contains (handle->addresses, + peer)) { GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Received `%s' for unknown peer `%s' from client %p\n", @@ -1699,7 +1716,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, ah->stat = (struct GNUNET_STATISTICS_Handle *) stats; /* Initialize the addresses database */ - ah->addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); + ah->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); GNUNET_assert(NULL != ah->addresses); /* Figure out configured solution method */ @@ -1808,29 +1825,30 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, break; } - GNUNET_assert(NULL != ah->s_init); - GNUNET_assert(NULL != ah->s_add); - 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); - GNUNET_assert(NULL != ah->s_feedback); - GNUNET_assert(NULL != ah->s_del); - GNUNET_assert(NULL != ah->s_done); - GNUNET_assert(NULL != ah->s_bulk_start); - GNUNET_assert(NULL != ah->s_bulk_stop); + GNUNET_assert (NULL != ah->s_init); + GNUNET_assert (NULL != ah->s_add); + 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); + GNUNET_assert (NULL != ah->s_feedback); + GNUNET_assert (NULL != ah->s_del); + GNUNET_assert (NULL != ah->s_done); + GNUNET_assert (NULL != ah->s_bulk_start); + GNUNET_assert (NULL != ah->s_bulk_stop); GAS_normalization_start (&normalized_preference_changed_cb, ah, &normalized_property_changed_cb, ah); quota_count = load_quotas (cfg, quotas_in, quotas_out, - GNUNET_ATS_NetworkTypeCount); + GNUNET_ATS_NetworkTypeCount); ah->solver = ah->s_init (cfg, stats, ah->addresses, quotas, quotas_in, - quotas_out, quota_count, &bandwidth_changed_cb, ah, &get_preferences_cb, - NULL, &get_property_cb, NULL ); + quotas_out, quota_count, + &bandwidth_changed_cb, ah, &get_preferences_cb, + NULL, &get_property_cb, NULL ); if (NULL == ah->solver) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver!\n")); @@ -1841,7 +1859,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, ah->running = GNUNET_YES; GNUNET_STATISTICS_set (ah->stat, "# addresses", - GNUNET_CONTAINER_multihashmap_size (ah->addresses), GNUNET_NO); + GNUNET_CONTAINER_multipeermap_size (ah->addresses), GNUNET_NO); return ah; } @@ -1852,18 +1870,19 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param cls NULL * @param key peer identity (unused) * @param value the 'struct ATS_Address' to free - * @return GNUNET_OK (continue to iterate) + * @return #GNUNET_OK (continue to iterate) */ static int -destroy_all_address_it (void *cls, const struct GNUNET_HashCode * key, - void *value) +destroy_all_address_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct GAS_Addresses_Handle *handle = cls; struct ATS_Address *aa = value; /* Remove */ - GNUNET_assert( - GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->addresses, key, value)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (handle->addresses, key, value)); /* Notify */ handle->s_del (handle->solver, aa, GNUNET_NO); /* Destroy */ @@ -1872,6 +1891,7 @@ destroy_all_address_it (void *cls, const struct GNUNET_HashCode * key, return GNUNET_OK; } + /** * Remove all addresses * @@ -1886,11 +1906,13 @@ GAS_addresses_destroy_all (struct GAS_Addresses_Handle *handle) GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Destroying all addresses\n"); handle->s_bulk_start (handle->solver); if (handle->addresses != NULL ) - GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, - &destroy_all_address_it, handle); + GNUNET_CONTAINER_multipeermap_iterate (handle->addresses, + &destroy_all_address_it, + handle); handle->s_bulk_start (handle->solver); } + /** * Shutdown address subsystem. * @@ -1905,7 +1927,7 @@ GAS_addresses_done (struct GAS_Addresses_Handle *handle) GNUNET_assert(NULL != handle); GAS_addresses_destroy_all (handle); handle->running = GNUNET_NO; - GNUNET_CONTAINER_multihashmap_destroy (handle->addresses); + GNUNET_CONTAINER_multipeermap_destroy (handle->addresses); handle->addresses = NULL; while (NULL != (cur = handle->r_head)) { @@ -1918,34 +1940,36 @@ GAS_addresses_done (struct GAS_Addresses_Handle *handle) GAS_normalization_stop (); } + struct PeerIteratorContext { GNUNET_ATS_Peer_Iterator it; void *it_cls; - struct GNUNET_CONTAINER_MultiHashMap *peers_returned; + struct GNUNET_CONTAINER_MultiPeerMap *peers_returned; }; + /** * Iterator to iterate over all peers * * @param cls a PeerIteratorContext * @param key the peer id * @param value the ATS_address - * @return GNUNET_OK to continue + * @return #GNUNET_OK to continue */ static int -peer_it (void *cls, const struct GNUNET_HashCode * key, void *value) +peer_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct PeerIteratorContext *ip_ctx = cls; - struct GNUNET_PeerIdentity tmp; - if (GNUNET_NO - == GNUNET_CONTAINER_multihashmap_contains (ip_ctx->peers_returned, key)) + if (GNUNET_NO == + GNUNET_CONTAINER_multipeermap_contains (ip_ctx->peers_returned, key)) { - GNUNET_CONTAINER_multihashmap_put (ip_ctx->peers_returned, key, NULL, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - tmp.hashPubKey = (*key); - ip_ctx->it (ip_ctx->it_cls, &tmp); + GNUNET_CONTAINER_multipeermap_put (ip_ctx->peers_returned, key, NULL, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + ip_ctx->it (ip_ctx->it_cls, key); } return GNUNET_OK; @@ -1969,16 +1993,17 @@ GAS_addresses_iterate_peers (struct GAS_Addresses_Handle *handle, return; GNUNET_assert(NULL != handle->addresses); - size = GNUNET_CONTAINER_multihashmap_size (handle->addresses); + size = GNUNET_CONTAINER_multipeermap_size (handle->addresses); if (0 != size) { ip_ctx.it = p_it; ip_ctx.it_cls = p_it_cls; - ip_ctx.peers_returned = GNUNET_CONTAINER_multihashmap_create (size, - GNUNET_NO); - GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &peer_it, - &ip_ctx); - GNUNET_CONTAINER_multihashmap_destroy (ip_ctx.peers_returned); + ip_ctx.peers_returned = GNUNET_CONTAINER_multipeermap_create (size, + GNUNET_NO); + GNUNET_CONTAINER_multipeermap_iterate (handle->addresses, + &peer_it, + &ip_ctx); + GNUNET_CONTAINER_multipeermap_destroy (ip_ctx.peers_returned); } p_it (p_it_cls, NULL ); } @@ -1989,19 +2014,22 @@ struct PeerInfoIteratorContext void *it_cls; }; + /** * Iterator to iterate over a peer's addresses * - * @param cls a PeerInfoIteratorContext + * @param cls a `struct PeerInfoIteratorContext` * @param key the peer id - * @param value the ATS_address - * @return GNUNET_OK to continue + * @param value the `struct ATS_address` + * @return #GNUNET_OK to continue */ static int -peerinfo_it (void *cls, const struct GNUNET_HashCode * key, void *value) +peerinfo_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct PeerInfoIteratorContext *pi_ctx = cls; - struct ATS_Address *addr = (struct ATS_Address *) value; + struct ATS_Address *addr = value; if (NULL != pi_ctx->it) { @@ -2012,6 +2040,7 @@ peerinfo_it (void *cls, const struct GNUNET_HashCode * key, void *value) return GNUNET_YES; } + /** * Return information all peers currently known to ATS * @@ -2027,6 +2056,7 @@ GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle, { struct PeerInfoIteratorContext pi_ctx; struct GNUNET_BANDWIDTH_Value32NBO zero_bw; + GNUNET_assert(NULL != peer); GNUNET_assert(NULL != handle->addresses); if (NULL == pi_it) @@ -2036,8 +2066,9 @@ GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle, pi_ctx.it = pi_it; pi_ctx.it_cls = pi_it_cls; - GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, - &peer->hashPubKey, &peerinfo_it, &pi_ctx); + GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, + peer, + &peerinfo_it, &pi_ctx); if (NULL != pi_it) pi_it (pi_it_cls, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, zero_bw, diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index b5ae248e48..71dfde41f4 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h @@ -411,7 +411,7 @@ typedef const double * typedef void * (*GAS_solver_init) (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_STATISTICS_Handle *stats, - const struct GNUNET_CONTAINER_MultiHashMap *addresses, int *network, + const struct GNUNET_CONTAINER_MultiPeerMap *addresses, int *network, unsigned long long *out_quota, unsigned long long *in_quota, int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, void *bw_changed_cb_cls, GAS_get_preferences get_preference, diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index fabef09e47..bd9dcb706f 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c @@ -149,12 +149,13 @@ void *prop_ch_cb_cls; /** * Hashmap to store peer information for preference normalization */ -static struct GNUNET_CONTAINER_MultiHashMap *preference_peers; +static struct GNUNET_CONTAINER_MultiPeerMap *preference_peers; /** * Hashmap to store peer information for property normalization + * FIXME: this map is not used! */ -static struct GNUNET_CONTAINER_MultiHashMap *property_peers; +static struct GNUNET_CONTAINER_MultiPeerMap *property_peers; /** * Clients in DLL: head @@ -220,8 +221,8 @@ update_peers (struct GNUNET_PeerIdentity *id, count, GNUNET_i2s (id), GNUNET_ATS_print_preference_type (kind), f_rel_total); if (NULL - != (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers, - &id->hashPubKey))) + != (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, + id))) { backup = rp->f_rel[kind]; if (0 < count) @@ -302,7 +303,7 @@ recalculate_rel_preferences (struct PreferenceClient *c, { /* Value did not chang, return old value*/ GNUNET_assert( - NULL != (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers, &p->id.hashPubKey))); + NULL != (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, &p->id))); ret = rp->f_rel[kind]; } } @@ -474,14 +475,14 @@ GAS_normalization_normalize_preference (void *src, GNUNET_CONTAINER_DLL_insert(c_cur->p_head, c_cur->p_tail, p_cur); } - if (NULL == GNUNET_CONTAINER_multihashmap_get (preference_peers, - &peer->hashPubKey)) + if (NULL == GNUNET_CONTAINER_multipeermap_get (preference_peers, + peer)) { r_cur = GNUNET_malloc (sizeof (struct PeerRelative)); r_cur->id = (*peer); for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; - GNUNET_CONTAINER_multihashmap_put (preference_peers, &r_cur->id.hashPubKey, + GNUNET_CONTAINER_multipeermap_put (preference_peers, &r_cur->id, r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); } @@ -508,8 +509,8 @@ GAS_normalization_get_preferences (const struct GNUNET_PeerIdentity *id) struct PeerRelative *rp; if (NULL - == (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers, - &id->hashPubKey))) + == (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, + id))) { return defvalues.f_rel; } @@ -625,6 +626,7 @@ property_average (struct ATS_Address *address, return res; } + struct FindMinMaxCtx { struct Property *p; @@ -632,11 +634,14 @@ struct FindMinMaxCtx uint32_t max; }; + static int -find_min_max_it (void *cls, const struct GNUNET_HashCode *h, void *k) +find_min_max_it (void *cls, + const struct GNUNET_PeerIdentity *h, + void *k) { - struct ATS_Address *a = (struct ATS_Address *) k; struct FindMinMaxCtx *find_res = cls; + struct ATS_Address *a = k; if (a->atsin[find_res->p->prop_type].avg > find_res->max) find_res->max = a->atsin[find_res->p->prop_type].avg; @@ -647,11 +652,14 @@ find_min_max_it (void *cls, const struct GNUNET_HashCode *h, void *k) return GNUNET_OK; } + static int -normalize_address (void *cls, const struct GNUNET_HashCode *h, void *k) +normalize_address (void *cls, + const struct GNUNET_PeerIdentity *h, + void *k) { struct Property *p = cls; - struct ATS_Address *address = (struct ATS_Address *) k; + struct ATS_Address *address = k; double delta; uint32_t avg_value = address->atsin[p->prop_type].avg; @@ -673,6 +681,7 @@ normalize_address (void *cls, const struct GNUNET_HashCode *h, void *k) return GNUNET_OK; } + /** * Normalize avg_value to a range of values between [1.0, 2.0] * based on min max values currently known. @@ -682,10 +691,11 @@ normalize_address (void *cls, const struct GNUNET_HashCode *h, void *k) * @param address the address * @param avg_value the value to normalize */ - static void -property_normalize (struct GNUNET_CONTAINER_MultiHashMap *addresses, - struct Property *p, struct ATS_Address *address, uint32_t avg_value) +property_normalize (struct GNUNET_CONTAINER_MultiPeerMap *addresses, + struct Property *p, + struct ATS_Address *address, + uint32_t avg_value) { struct FindMinMaxCtx find_ctx; int addr_count; @@ -694,8 +704,8 @@ property_normalize (struct GNUNET_CONTAINER_MultiHashMap *addresses, find_ctx.p = p; find_ctx.max = 0; find_ctx.min = UINT32_MAX; - addr_count = GNUNET_CONTAINER_multihashmap_iterate (addresses, - &find_min_max_it, &find_ctx); + addr_count = GNUNET_CONTAINER_multipeermap_iterate (addresses, + &find_min_max_it, &find_ctx); if (0 == addr_count) { GNUNET_break(0); @@ -731,13 +741,13 @@ property_normalize (struct GNUNET_CONTAINER_MultiHashMap *addresses, if (GNUNET_NO == limits_changed) { /* normalize just this address */ - normalize_address (p, &address->peer.hashPubKey, address); + normalize_address (p, &address->peer, address); return; } else { /* limits changed, normalize all addresses */ - GNUNET_CONTAINER_multihashmap_iterate (addresses, &normalize_address, p); + GNUNET_CONTAINER_multipeermap_iterate (addresses, &normalize_address, p); return; } } @@ -751,10 +761,10 @@ property_normalize (struct GNUNET_CONTAINER_MultiHashMap *addresses, * @param atsi_count the number of atsi information in the array */ void -GAS_normalization_normalize_property ( - struct GNUNET_CONTAINER_MultiHashMap *addresses, - struct ATS_Address *address, const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count) +GAS_normalization_normalize_property (struct GNUNET_CONTAINER_MultiPeerMap *addresses, + struct ATS_Address *address, + const struct GNUNET_ATS_Information *atsi, + uint32_t atsi_count) { struct Property *cur_prop; int c1; @@ -814,8 +824,8 @@ GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, { int c1; int i; - preference_peers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); - property_peers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); + preference_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); + property_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); unsigned int existing_properties[] = GNUNET_ATS_QualityProperties; for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) @@ -840,20 +850,21 @@ GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, return; } + /** * Free a peer * * @param cls unused * @param key the key * @param value RelativePeer - * @return GNUNET_OK to continue + * @return #GNUNET_OK to continue */ static int -free_peer (void *cls, const struct GNUNET_HashCode * key, void *value) +free_peer (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { struct PeerRelative *rp = value; if (GNUNET_YES - == GNUNET_CONTAINER_multihashmap_remove (preference_peers, key, value)) + == GNUNET_CONTAINER_multipeermap_remove (preference_peers, key, value)) GNUNET_free(rp); else GNUNET_break(0); @@ -892,9 +903,9 @@ GAS_normalization_stop () GNUNET_free(pc); } - GNUNET_CONTAINER_multihashmap_iterate (preference_peers, &free_peer, NULL ); - GNUNET_CONTAINER_multihashmap_destroy (preference_peers); - GNUNET_CONTAINER_multihashmap_destroy (property_peers); + GNUNET_CONTAINER_multipeermap_iterate (preference_peers, &free_peer, NULL ); + GNUNET_CONTAINER_multipeermap_destroy (preference_peers); + GNUNET_CONTAINER_multipeermap_destroy (property_peers); return; } diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h index 969263b3e8..1f0d081d4c 100644 --- a/src/ats/gnunet-service-ats_normalization.h +++ b/src/ats/gnunet-service-ats_normalization.h @@ -51,8 +51,8 @@ typedef void /** * Get the normalized preference values for a specific peer * - * @param id the peer - * @return pointer to the values, can be indexed with GNUNET_ATS_PreferenceKind, NULL if peer does not exist + * @param id the peer @return pointer to the values, can be indexed + * with GNUNET_ATS_PreferenceKind, NULL if peer does not exist */ const double * GAS_normalization_get_preferences (const struct GNUNET_PeerIdentity *id); @@ -79,9 +79,9 @@ GAS_normalization_get_properties (struct ATS_Address *address); */ void GAS_normalization_normalize_preference (void *src, - const struct GNUNET_PeerIdentity *peer, - enum GNUNET_ATS_PreferenceKind kind, - float score_abs); + const struct GNUNET_PeerIdentity *peer, + enum GNUNET_ATS_PreferenceKind kind, + float score_abs); /** * Update and normalize a atsi performance information @@ -92,10 +92,10 @@ GAS_normalization_normalize_preference (void *src, * @param atsi_count the number of atsi information in the array */ void -GAS_normalization_normalize_property (struct GNUNET_CONTAINER_MultiHashMap *addresses, - struct ATS_Address *address, - const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count); +GAS_normalization_normalize_property (struct GNUNET_CONTAINER_MultiPeerMap *addresses, + struct ATS_Address *address, + const struct GNUNET_ATS_Information *atsi, + uint32_t atsi_count); /** @@ -108,9 +108,9 @@ GAS_normalization_normalize_property (struct GNUNET_CONTAINER_MultiHashMap *addr */ void GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, - void *pref_ch_cb_cls, - GAS_Normalization_property_changed_cb property_ch_cb, - void *property_ch_cb_cls); + void *pref_ch_cb_cls, + GAS_Normalization_property_changed_cb property_ch_cb, + void *property_ch_cb_cls); /** diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c index 0b49485761..c75577cf92 100644 --- a/src/ats/gnunet-service-ats_reservations.c +++ b/src/ats/gnunet-service-ats_reservations.c @@ -36,7 +36,7 @@ /** * Map of peer identities to 'struct GNUNET_BANDWIDTH_Tracker *'s */ -static struct GNUNET_CONTAINER_MultiHashMap *trackers; +static struct GNUNET_CONTAINER_MultiPeerMap *trackers; /** @@ -57,7 +57,7 @@ GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer, struct GNUNET_BANDWIDTH_Tracker *tracker; struct GNUNET_TIME_Relative ret; - tracker = GNUNET_CONTAINER_multihashmap_get (trackers, &peer->hashPubKey); + tracker = GNUNET_CONTAINER_multipeermap_get (trackers, peer); if (NULL == tracker) return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */ if (amount >= 0) @@ -93,14 +93,14 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, { struct GNUNET_BANDWIDTH_Tracker *tracker; - tracker = GNUNET_CONTAINER_multihashmap_get (trackers, &peer->hashPubKey); + tracker = GNUNET_CONTAINER_multipeermap_get (trackers, peer); if (0 == ntohl (bandwidth_in.value__)) { if (NULL == tracker) return; GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (trackers, - &peer->hashPubKey, + GNUNET_CONTAINER_multipeermap_remove (trackers, + peer, tracker)); GNUNET_free (tracker); return; @@ -110,7 +110,7 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, tracker = GNUNET_malloc (sizeof (struct GNUNET_BANDWIDTH_Tracker)); GNUNET_BANDWIDTH_tracker_init (tracker, bandwidth_in, MAX_BANDWIDTH_CARRY_S); - GNUNET_CONTAINER_multihashmap_put (trackers, &peer->hashPubKey, tracker, + GNUNET_CONTAINER_multipeermap_put (trackers, peer, tracker, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); return; } @@ -124,7 +124,7 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, void GAS_reservations_init () { - trackers = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); + trackers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); } @@ -137,7 +137,8 @@ GAS_reservations_init () * @return GNUNET_OK (continue to iterate) */ static int -free_tracker (void *cls, const struct GNUNET_HashCode * key, void *value) +free_tracker (void *cls, + const struct GNUNET_PeerIdentity *key, void *value) { struct GNUNET_BANDWIDTH_Tracker *tracker = value; @@ -152,8 +153,8 @@ free_tracker (void *cls, const struct GNUNET_HashCode * key, void *value) void GAS_reservations_done () { - GNUNET_CONTAINER_multihashmap_iterate (trackers, &free_tracker, NULL); - GNUNET_CONTAINER_multihashmap_destroy (trackers); + GNUNET_CONTAINER_multipeermap_iterate (trackers, &free_tracker, NULL); + GNUNET_CONTAINER_multipeermap_destroy (trackers); } /* end of gnunet-service-ats_reservations.c */ |