diff options
40 files changed, 590 insertions, 515 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 */ diff --git a/src/include/gnunet_constants.h b/src/include/gnunet_constants.h index fda99ed67e..5f37f8922d 100644 --- a/src/include/gnunet_constants.h +++ b/src/include/gnunet_constants.h @@ -35,8 +35,6 @@ extern "C" #endif #endif -#include "gnunet_bandwidth_lib.h" - /** * Bandwidth (in/out) to assume initially (before either peer has * communicated any particular preference). Should be rather low; set diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index d728414e79..910be8c726 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h @@ -23,12 +23,9 @@ * @brief basic low-level networking interface * @author Nils Durner */ - #ifndef GNUNET_NETWORK_LIB_H #define GNUNET_NETWORK_LIB_H -#include "platform.h" - #ifdef __cplusplus extern "C" { diff --git a/src/include/gnunet_statistics_service.h b/src/include/gnunet_statistics_service.h index 75c7bd18a1..25562580a9 100644 --- a/src/include/gnunet_statistics_service.h +++ b/src/include/gnunet_statistics_service.h @@ -39,9 +39,7 @@ extern "C" #endif #endif -#include "gnunet_common.h" -#include "gnunet_configuration_lib.h" -#include "gnunet_scheduler_lib.h" +#include "gnunet_util_lib.h" /** * Version of the statistics API. diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h index 025dbed901..0f62ba8db4 100644 --- a/src/include/gnunet_util_lib.h +++ b/src/include/gnunet_util_lib.h @@ -37,29 +37,23 @@ extern "C" #endif #include "gnunet_crypto_lib.h" -#include "gnunet_common.h" #include "gnunet_bandwidth_lib.h" #include "gnunet_bio_lib.h" #include "gnunet_connection_lib.h" #include "gnunet_client_lib.h" -#include "gnunet_configuration_lib.h" #include "gnunet_container_lib.h" -#include "gnunet_disk_lib.h" #include "gnunet_getopt_lib.h" #include "gnunet_helper_lib.h" #include "gnunet_mq_lib.h" -#include "gnunet_network_lib.h" #include "gnunet_os_lib.h" #include "gnunet_peer_lib.h" #include "gnunet_plugin_lib.h" #include "gnunet_program_lib.h" #include "gnunet_protocols.h" -#include "gnunet_scheduler_lib.h" #include "gnunet_server_lib.h" #include "gnunet_service_lib.h" #include "gnunet_signal_lib.h" #include "gnunet_strings_lib.h" -#include "gnunet_time_lib.h" #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/transport/gnunet-helper-transport-wlan.c b/src/transport/gnunet-helper-transport-wlan.c index b23f43dde3..7f472b3be7 100644 --- a/src/transport/gnunet-helper-transport-wlan.c +++ b/src/transport/gnunet-helper-transport-wlan.c @@ -110,6 +110,8 @@ * parts taken from aircrack-ng, parts changend. */ #include "gnunet_config.h" +#define SOCKTYPE int +#define FDTYPE int #include <sys/socket.h> #include <sys/ioctl.h> #include <sys/types.h> diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index acf3561491..3adf5b35d4 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -68,11 +68,6 @@ struct GNUNET_PEERINFO_Handle *GST_peerinfo; static struct GNUNET_SERVER_Handle *GST_server; /** - * Our public key. - */ -struct GNUNET_CRYPTO_EccPublicSignKey GST_my_public_key; - -/** * Our private key. */ struct GNUNET_CRYPTO_EccPrivateKey *GST_my_private_key; @@ -790,9 +785,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg); - GNUNET_CRYPTO_ecc_key_get_public_for_signature (GST_my_private_key, &GST_my_public_key); - GNUNET_CRYPTO_hash (&GST_my_public_key, sizeof (GST_my_public_key), - &GST_my_identity.hashPubKey); + GNUNET_CRYPTO_ecc_key_get_public_for_signature (GST_my_private_key, + &GST_my_identity.public_key); GNUNET_assert (NULL != GST_my_private_key); GNUNET_log (GNUNET_ERROR_TYPE_INFO, diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h index 44b375dd89..9b68cb2583 100644 --- a/src/transport/gnunet-service-transport.h +++ b/src/transport/gnunet-service-transport.h @@ -26,9 +26,9 @@ #ifndef GNUNET_SERVICE_TRANSPORT_H #define GNUNET_SERVICE_TRANSPORT_H +#include "gnunet_util_lib.h" #include "gnunet_statistics_service.h" #include "gnunet_transport_service.h" -#include "gnunet_util_lib.h" #define VERBOSE_VALIDATION GNUNET_YES @@ -53,11 +53,6 @@ extern struct GNUNET_PeerIdentity GST_my_identity; extern struct GNUNET_PEERINFO_Handle *GST_peerinfo; /** - * Our public key. - */ -extern struct GNUNET_CRYPTO_EccPublicSignKey GST_my_public_key; - -/** * Our private key. */ extern struct GNUNET_CRYPTO_EccPrivateKey *GST_my_private_key; diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c index 2bec6cb710..628943a42d 100644 --- a/src/transport/gnunet-service-transport_blacklist.c +++ b/src/transport/gnunet-service-transport_blacklist.c @@ -182,7 +182,7 @@ static struct Blacklisters *bl_tail; * Hashmap of blacklisted peers. Values are of type 'char *' (transport names), * can be NULL if we have no static blacklist. */ -static struct GNUNET_CONTAINER_MultiHashMap *blacklist; +static struct GNUNET_CONTAINER_MultiPeerMap *blacklist; /** @@ -254,9 +254,9 @@ blacklist_cfg_iter (void *cls, const char *section, char *plugs; char *pos; - if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string2 (option, - strlen (option), - &peer.hashPubKey)) + if (GNUNET_OK != GNUNET_CRYPTO_ecc_public_sign_key_from_string (option, + strlen (option), + &peer.public_key)) return; if ((NULL == value) || (0 == strcmp(value, ""))) @@ -334,7 +334,9 @@ GST_blacklist_start (struct GNUNET_SERVER_Handle *server, * @return GNUNET_OK (continue to iterate) */ static int -free_blacklist_entry (void *cls, const struct GNUNET_HashCode * key, void *value) +free_blacklist_entry (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { char *be = value; @@ -351,9 +353,9 @@ GST_blacklist_stop () { if (NULL != blacklist) { - GNUNET_CONTAINER_multihashmap_iterate (blacklist, &free_blacklist_entry, + GNUNET_CONTAINER_multipeermap_iterate (blacklist, &free_blacklist_entry, NULL); - GNUNET_CONTAINER_multihashmap_destroy (blacklist); + GNUNET_CONTAINER_multipeermap_destroy (blacklist); blacklist = NULL; } } @@ -617,24 +619,25 @@ void GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, const char *transport_name) { - char * transport = NULL; - if (NULL != transport_name) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Adding peer `%s' with plugin `%s' to blacklist\n", - GNUNET_i2s (peer), transport_name); - transport = GNUNET_strdup (transport_name); - } - else - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Adding peer `%s' with all plugins to blacklist\n", - GNUNET_i2s (peer)); + char * transport = NULL; + + if (NULL != transport_name) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Adding peer `%s' with plugin `%s' to blacklist\n", + GNUNET_i2s (peer), transport_name); + transport = GNUNET_strdup (transport_name); + } + else + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Adding peer `%s' with all plugins to blacklist\n", + GNUNET_i2s (peer)); if (blacklist == NULL) blacklist = - GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE, + GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE, GNUNET_NO); - - GNUNET_CONTAINER_multihashmap_put (blacklist, &peer->hashPubKey, + + GNUNET_CONTAINER_multipeermap_put (blacklist, peer, transport, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); } @@ -647,10 +650,12 @@ GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, * @param cls the transport name to match (const char*) * @param key the key (unused) * @param value the 'char *' (name of a blacklisted transport) - * @return GNUNET_OK if the entry does not match, GNUNET_NO if it matches + * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches */ static int -test_blacklisted (void *cls, const struct GNUNET_HashCode * key, void *value) +test_blacklisted (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { const char *transport_name = cls; char *be = value; @@ -665,10 +670,10 @@ test_blacklisted (void *cls, const struct GNUNET_HashCode * key, void *value) */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n", - GNUNET_h2s (key), - (NULL == transport_name) ? "unspecified" : transport_name, - (NULL == be) ? "all plugins" : be); + "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n", + GNUNET_i2s (key), + (NULL == transport_name) ? "unspecified" : transport_name, + (NULL == be) ? "all plugins" : be); /* all plugins for this peer were blacklisted: disallow */ if (NULL == value) return GNUNET_NO; @@ -708,7 +713,7 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, * If iteration is aborted, we found a matching blacklist entry */ if ((blacklist != NULL) && (GNUNET_SYSERR == - GNUNET_CONTAINER_multihashmap_get_multiple (blacklist, &peer->hashPubKey, + GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, peer, &test_blacklisted, (void *) transport_name))) { diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c index 8c8d7854f1..0347d67a54 100644 --- a/src/transport/gnunet-service-transport_hello.c +++ b/src/transport/gnunet-service-transport_hello.c @@ -170,7 +170,9 @@ refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) friend_only = GNUNET_HELLO_is_friend_only (our_hello); GNUNET_free (our_hello); - our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator, &gc, friend_only); + our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key, + &address_generator, + &gc, friend_only); GNUNET_assert (NULL != our_hello); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Refreshed my %s `%s', new size is %d\n", @@ -213,7 +215,8 @@ GST_hello_start (int friend_only, GST_HelloCallback cb, void *cb_cls) { hello_cb = cb; hello_cb_cls = cb_cls; - our_hello = GNUNET_HELLO_create (&GST_my_public_key, NULL, NULL, friend_only); + our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key, + NULL, NULL, friend_only); GNUNET_assert (NULL != our_hello); refresh_hello (); } diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c index 0ebe18c55b..7762d18114 100644 --- a/src/transport/gnunet-service-transport_manipulation.c +++ b/src/transport/gnunet-service-transport_manipulation.c @@ -114,7 +114,7 @@ struct GST_ManipulationHandle /** * Hashmap contain all peers currently manipulated */ - struct GNUNET_CONTAINER_MultiHashMap *peers; + struct GNUNET_CONTAINER_MultiPeerMap *peers; /** * Peer containing information for general manipulation @@ -325,7 +325,7 @@ GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received traffic metrics for peer `%s'\n", GNUNET_i2s(&tm->peer)); - if (NULL == (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &tm->peer.hashPubKey))) + if (NULL == (tmp = GNUNET_CONTAINER_multipeermap_get (man_handle.peers, &tm->peer))) { tmp = GNUNET_malloc (sizeof (struct TM_Peer)); tmp->peer = (tm->peer); @@ -336,7 +336,9 @@ GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client, tmp->metrics[c][c2] = UINT32_MAX; } } - GNUNET_CONTAINER_multihashmap_put (man_handle.peers, &tm->peer.hashPubKey, tmp, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + GNUNET_CONTAINER_multipeermap_put (man_handle.peers, + &tm->peer, tmp, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); } ats = (struct GNUNET_ATS_Information *) &tm[1]; @@ -411,7 +413,7 @@ GST_manipulation_send (const struct GNUNET_PeerIdentity *target, const void *msg struct DelayQueueEntry *dqe; struct GNUNET_TIME_Relative delay; - if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &target->hashPubKey))) + if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get (man_handle.peers, target))) { GNUNET_break (GNUNET_YES == GST_neighbours_test_connected(target)); /* Manipulate here */ @@ -494,7 +496,7 @@ GST_manipulation_manipulate_metrics (const struct GNUNET_PeerIdentity *peer, uint32_t m_tmp; uint32_t g_tmp; int d; - tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &peer->hashPubKey); + tmp = GNUNET_CONTAINER_multipeermap_get (man_handle.peers, peer); for (d = 0; d < ats_count; d++) { @@ -546,7 +548,7 @@ GST_manipulation_recv (void *cls, else m_delay = GNUNET_TIME_UNIT_ZERO; - if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &peer->hashPubKey))) + if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get (man_handle.peers, peer))) { /* Manipulate receive delay */ p_recv_delay = find_metric (tmp, GNUNET_ATS_QUALITY_NET_DELAY, TM_RECEIVE); @@ -632,13 +634,13 @@ GST_manipulation_init (const struct GNUNET_CONFIGURATION_Handle *GST_cfg) GNUNET_ATS_QUALITY_NET_DELAY, delay.rel_value_us); } - man_handle.peers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); + man_handle.peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); } static int free_tmps (void *cls, - const struct GNUNET_HashCode * key, + const struct GNUNET_PeerIdentity *key, void *value) { struct DelayQueueEntry *dqe; @@ -648,7 +650,7 @@ free_tmps (void *cls, { struct TM_Peer *tmp = (struct TM_Peer *) value; - if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (man_handle.peers, key, value)) + if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove (man_handle.peers, key, value)) GNUNET_break (0); free_metric (tmp); next = tmp->send_head; @@ -683,7 +685,7 @@ GST_manipulation_peer_disconnect (const struct GNUNET_PeerIdentity *peer) struct DelayQueueEntry *dqe; struct DelayQueueEntry *next; - if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &peer->hashPubKey))) + if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get (man_handle.peers, peer))) { next = tmp->send_head; while (NULL != (dqe = next)) @@ -729,8 +731,8 @@ GST_manipulation_stop () { struct DelayQueueEntry *cur; struct DelayQueueEntry *next; - GNUNET_CONTAINER_multihashmap_iterate (man_handle.peers, &free_tmps,NULL); - GNUNET_CONTAINER_multihashmap_destroy (man_handle.peers); + GNUNET_CONTAINER_multipeermap_iterate (man_handle.peers, &free_tmps,NULL); + GNUNET_CONTAINER_multipeermap_destroy (man_handle.peers); next = generic_dqe_head; while (NULL != (cur = next)) diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 1a6a87853a..90f45f126c 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -739,7 +739,7 @@ struct BlackListCheckContext /** * Hash map from peer identities to the respective 'struct NeighbourMapEntry'. */ -static struct GNUNET_CONTAINER_MultiHashMap *neighbours; +static struct GNUNET_CONTAINER_MultiPeerMap *neighbours; /** * We keep blacklist checks in a DLL so that we can find @@ -795,7 +795,7 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid) { if (NULL == neighbours) return NULL; - return GNUNET_CONTAINER_multihashmap_get (neighbours, &pid->hashPubKey); + return GNUNET_CONTAINER_multipeermap_get (neighbours, pid); } static const char * @@ -1077,8 +1077,8 @@ free_neighbour (struct NeighbourMapEntry *n, int keep_sessions) MEMDEBUG_free_non_null (backup_primary, __LINE__); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (neighbours, - &n->id.hashPubKey, n)); + GNUNET_CONTAINER_multipeermap_remove (neighbours, + &n->id, n)); // FIXME-ATS-API: we might want to be more specific about // which states we do this from in the future (ATS should @@ -1201,7 +1201,7 @@ send_disconnect (struct NeighbourMapEntry *n) htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); disconnect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); - disconnect_msg.public_key = GST_my_public_key; + disconnect_msg.public_key = GST_my_identity.public_key; GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecc_sign (GST_my_private_key, &disconnect_msg.purpose, @@ -1799,8 +1799,8 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer) MAX_BANDWIDTH_CARRY_S); n->task = GNUNET_SCHEDULER_add_now (&master_task, n); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (neighbours, - &n->id.hashPubKey, n, + GNUNET_CONTAINER_multipeermap_put (neighbours, + &n->id, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); return n; } @@ -3223,7 +3223,7 @@ struct IteratorContext * @return GNUNET_OK (continue to iterate) */ static int -neighbours_iterate (void *cls, const struct GNUNET_HashCode * key, void *value) +neighbours_iterate (void *cls, const struct GNUNET_PeerIdentity * key, void *value) { struct IteratorContext *ic = cls; struct NeighbourMapEntry *n = value; @@ -3267,7 +3267,7 @@ GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls) return; /* can happen during shutdown */ ic.cb = cb; ic.cb_cls = cb_cls; - GNUNET_CONTAINER_multihashmap_iterate (neighbours, &neighbours_iterate, &ic); + GNUNET_CONTAINER_multipeermap_iterate (neighbours, &neighbours_iterate, &ic); } @@ -3375,7 +3375,7 @@ GST_neighbours_start (void *cls, connect_notify_cb = connect_cb; disconnect_notify_cb = disconnect_cb; address_change_cb = peer_address_cb; - neighbours = GNUNET_CONTAINER_multihashmap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO); + neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO); } @@ -3388,7 +3388,9 @@ GST_neighbours_start (void *cls, * @return GNUNET_OK (continue to iterate) */ static int -disconnect_all_neighbours (void *cls, const struct GNUNET_HashCode * key, void *value) +disconnect_all_neighbours (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct NeighbourMapEntry *n = value; @@ -3409,10 +3411,10 @@ GST_neighbours_stop () { if (NULL == neighbours) return; - GNUNET_CONTAINER_multihashmap_iterate (neighbours, + GNUNET_CONTAINER_multipeermap_iterate (neighbours, &disconnect_all_neighbours, NULL); - GNUNET_CONTAINER_multihashmap_destroy (neighbours); + GNUNET_CONTAINER_multipeermap_destroy (neighbours); neighbours = NULL; callback_cls = NULL; connect_notify_cb = NULL; diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index fe493f822e..54393d7530 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c @@ -311,7 +311,7 @@ static struct CheckHelloValidatedContext *chvc_tail; * of the given peer that we are currently validating, have validated * or are blocked from re-validation for a while). */ -static struct GNUNET_CONTAINER_MultiHashMap *validation_map; +static struct GNUNET_CONTAINER_MultiPeerMap *validation_map; /** * Context for peerinfo iteration. @@ -367,7 +367,7 @@ struct ValidationEntryMatchContext * GNUNET_NO if the entry does match */ static int -validation_entry_match (void *cls, const struct GNUNET_HashCode * key, void *value) +validation_entry_match (void *cls, const struct GNUNET_PeerIdentity * key, void *value) { struct ValidationEntryMatchContext *vemc = cls; struct ValidationEntry *ve = value; @@ -390,7 +390,7 @@ validation_entry_match (void *cls, const struct GNUNET_HashCode * key, void *val * @return GNUNET_YES (continue to iterate) */ static int -cleanup_validation_entry (void *cls, const struct GNUNET_HashCode * key, void *value) +cleanup_validation_entry (void *cls, const struct GNUNET_PeerIdentity * key, void *value) { struct ValidationEntry *ve = value; @@ -400,8 +400,8 @@ cleanup_validation_entry (void *cls, const struct GNUNET_HashCode * key, void *v ve->bc = NULL; } GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (validation_map, - &ve->pid.hashPubKey, ve)); + GNUNET_CONTAINER_multipeermap_remove (validation_map, + &ve->pid, ve)); GNUNET_HELLO_address_free (ve->address); if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) { @@ -454,7 +454,7 @@ timeout_hello_validation (void *cls, GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# address records discarded"), 1, GNUNET_NO); - cleanup_validation_entry (NULL, &ve->pid.hashPubKey, ve); + cleanup_validation_entry (NULL, &ve->pid, ve); } @@ -686,8 +686,8 @@ find_validation_entry (const struct GNUNET_CRYPTO_EccPublicSignKey *public_key, vemc.ve = NULL; vemc.address = address; - GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, - &address->peer.hashPubKey, + GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, + &address->peer, &validation_entry_match, &vemc); if (NULL != (ve = vemc.ve)) return ve; @@ -708,7 +708,7 @@ find_validation_entry (const struct GNUNET_CRYPTO_EccPublicSignKey *public_key, ve->timeout_task = GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE, &timeout_hello_validation, ve); - GNUNET_CONTAINER_multihashmap_put (validation_map, &address->peer.hashPubKey, + GNUNET_CONTAINER_multipeermap_put (validation_map, &address->peer, ve, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); ve->expecting_pong = GNUNET_NO; @@ -814,7 +814,7 @@ GST_validation_start (unsigned int max_fds) validations_fast_start_threshold, GNUNET_STRINGS_relative_time_to_string (validation_delay, GNUNET_YES)); - validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE, + validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE, GNUNET_NO); pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES, &process_peerinfo_hello, NULL); } @@ -828,9 +828,9 @@ GST_validation_stop () { struct CheckHelloValidatedContext *chvc; - GNUNET_CONTAINER_multihashmap_iterate (validation_map, + GNUNET_CONTAINER_multipeermap_iterate (validation_map, &cleanup_validation_entry, NULL); - GNUNET_CONTAINER_multihashmap_destroy (validation_map); + GNUNET_CONTAINER_multipeermap_destroy (validation_map); validation_map = NULL; while (NULL != (chvc = chvc_head)) { @@ -1031,7 +1031,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am `%s', sending PONG to peer `%s'\n", - GNUNET_h2s (&GST_my_identity.hashPubKey), + GNUNET_i2s_full (&GST_my_identity), GNUNET_i2s (sender)); /* message with structure: @@ -1404,10 +1404,10 @@ struct IteratorContext * @param cls the 'struct GST_ValidationIteratorContext' * @param key the peer's identity * @param value the 'struct ValidationEntry' - * @return GNUNET_OK (continue to iterate) + * @return #GNUNET_OK (continue to iterate) */ static int -iterate_addresses (void *cls, const struct GNUNET_HashCode * key, void *value) +iterate_addresses (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { struct IteratorContext *ic = cls; struct ValidationEntry *ve = value; @@ -1434,8 +1434,8 @@ GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, ic.cb = cb; ic.cb_cls = cb_cls; - GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, - &target->hashPubKey, + GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, + target, &iterate_addresses, &ic); } diff --git a/src/transport/gnunet-transport-wlan-sender.c b/src/transport/gnunet-transport-wlan-sender.c index 05d1d1eef6..0ab6c9fd17 100644 --- a/src/transport/gnunet-transport-wlan-sender.c +++ b/src/transport/gnunet-transport-wlan-sender.c @@ -24,8 +24,8 @@ * @author David Brodski */ #include "platform.h" -#include "gnunet_protocols.h" #include "plugin_transport_wlan.h" +#include "gnunet_protocols.h" #define WLAN_MTU 1500 diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 641261c052..4fc1622b37 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c @@ -166,8 +166,6 @@ static GNUNET_SCHEDULER_TaskIdentifier end; static GNUNET_SCHEDULER_TaskIdentifier op_timeout; -static struct GNUNET_CONTAINER_MultiHashMap *peers; - /** * Selected level of verbosity. */ @@ -255,11 +253,6 @@ shutdown_task (void *cls, GNUNET_TRANSPORT_disconnect(handle); handle = NULL; } - if (NULL != peers) - { - GNUNET_CONTAINER_multihashmap_destroy (peers); - peers = NULL; - } if (benchmark_send) { duration = GNUNET_TIME_absolute_get_duration (start_time); @@ -300,7 +293,7 @@ operation_timeout (void *cls, if ((try_connect) || (benchmark_send) || (benchmark_receive)) { - FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_h2s_full (&pid.hashPubKey)); + FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid)); if (GNUNET_SCHEDULER_NO_TASK != end) GNUNET_SCHEDULER_cancel (end); end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); @@ -525,7 +518,9 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) if (try_connect) { /* all done, terminate instantly */ - FPRINTF (stdout, _("Successfully connected to `%s'\n"), GNUNET_h2s_full (&peer->hashPubKey)); + FPRINTF (stdout, + _("Successfully connected to `%s'\n"), + GNUNET_i2s_full (peer)); ret = 0; if (GNUNET_SCHEDULER_NO_TASK != op_timeout) @@ -814,7 +809,9 @@ testservice_task (void *cls, } if ( (NULL != cpid) && - (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))) + (GNUNET_OK != GNUNET_CRYPTO_ecc_public_sign_key_from_string (cpid, + strlen (cpid), + &pid.public_key))) { FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid); return; @@ -914,7 +911,6 @@ testservice_task (void *cls, } else if (iterate_connections) /* -i: List all active addresses once */ { - peers = GNUNET_CONTAINER_multihashmap_create (20, GNUNET_NO); address_resolution_in_progress = GNUNET_YES; pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, (NULL == cpid) ? NULL : &pid, @@ -926,7 +922,6 @@ testservice_task (void *cls, } else if (monitor_connections) /* -m: List all active addresses continously */ { - peers = GNUNET_CONTAINER_multihashmap_create (20, GNUNET_NO); address_resolution_in_progress = GNUNET_YES; pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, (NULL == cpid) ? NULL : &pid, diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index 2d112d4fe1..d6db3d22dd 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c @@ -42,9 +42,8 @@ #define ENABLE_GET GNUNET_YES #include "platform.h" +#include "gnunet_util_lib.h" #include "gnunet_protocols.h" -#include "gnunet_common.h" -#include "gnunet_server_lib.h" #include "gnunet_transport_plugin.h" #include "plugin_transport_http_common.h" #include <curl/curl.h> @@ -1405,9 +1404,9 @@ client_connect (struct Session *s) } GNUNET_asprintf (&s->url, "%s/%s;%u", - http_common_plugin_address_to_url (NULL, s->addr, s->addrlen), - GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey), - plugin->last_tag); + http_common_plugin_address_to_url (NULL, s->addr, s->addrlen), + GNUNET_i2s_full (plugin->env->my_identity), + plugin->last_tag); plugin->last_tag++; diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index 7a7f9ad0c2..569a472559 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c @@ -23,9 +23,8 @@ * @brief functionality shared by http client and server transport service plugin * @author Matthias Wachs */ - #include "platform.h" -#include "gnunet_common.h" +#include "gnunet_util_lib.h" #include "gnunet_transport_plugin.h" #include "plugin_transport_http_common.h" @@ -37,16 +36,17 @@ struct SplittedHTTPAddress int port; }; + static void http_clean_splitted (struct SplittedHTTPAddress *spa) { - if (NULL != spa) - { - GNUNET_free_non_null (spa->protocol); - GNUNET_free_non_null (spa->host); - GNUNET_free_non_null (spa->path); - GNUNET_free_non_null (spa); - } + if (NULL != spa) + { + GNUNET_free_non_null (spa->protocol); + GNUNET_free_non_null (spa->host); + GNUNET_free_non_null (spa->path); + GNUNET_free_non_null (spa); + } } struct SplittedHTTPAddress * diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 4d879e1661..58e5db46af 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -25,8 +25,7 @@ */ #include "platform.h" -#include "gnunet_common.h" -#include "gnunet_server_lib.h" +#include "gnunet_util_lib.h" #include "gnunet_statistics_service.h" #include "gnunet_transport_plugin.h" #include "gnunet_nat_lib.h" @@ -924,14 +923,16 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, */ static int -server_parse_url (struct HTTP_Server_Plugin *plugin, const char * url, struct GNUNET_PeerIdentity * target, uint32_t *tag) +server_parse_url (struct HTTP_Server_Plugin *plugin, + const char *url, + struct GNUNET_PeerIdentity *target, + uint32_t *tag) { char * tag_start = NULL; char * tag_end = NULL; char * target_start = NULL; char * separator = NULL; - char hash[plugin->peer_id_length+1]; - int hash_length; + unsigned int hash_length; unsigned long int ctag; /* URL parsing @@ -1011,18 +1012,19 @@ server_parse_url (struct HTTP_Server_Plugin *plugin, const char * url, struct GN if (DEBUG_URL_PARSE) GNUNET_break (0); return GNUNET_SYSERR; } - memcpy (hash, target_start, hash_length); - hash[hash_length] = '\0'; - - if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((const char *) hash, &(target->hashPubKey))) - { + if (GNUNET_OK != + GNUNET_CRYPTO_ecc_public_sign_key_from_string (target_start, + hash_length, + &target->public_key)) + { /* hash conversion failed */ if (DEBUG_URL_PARSE) GNUNET_break (0); return GNUNET_SYSERR; } - - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Found target `%s' in url\n", GNUNET_h2s_full(&target->hashPubKey)); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + plugin->name, + "Found target `%s' in URL\n", + GNUNET_i2s_full (target)); return GNUNET_OK; } @@ -2879,7 +2881,7 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin) plugin->max_connections); - plugin->peer_id_length = strlen (GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey)); + plugin->peer_id_length = strlen (GNUNET_i2s_full (plugin->env->my_identity)); return GNUNET_OK; } diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 37a4aa7cdf..0e49300b00 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -358,7 +358,7 @@ struct Plugin /** * Map from peer identities to sessions for the given peer. */ - struct GNUNET_CONTAINER_MultiHashMap *sessionmap; + struct GNUNET_CONTAINER_MultiPeerMap *sessionmap; /** * Handle to the network service. @@ -379,7 +379,7 @@ struct Plugin /** * Map of peers we have tried to contact behind a NAT */ - struct GNUNET_CONTAINER_MultiHashMap *nat_wait_conns; + struct GNUNET_CONTAINER_MultiPeerMap *nat_wait_conns; /** * List of active TCP probes. @@ -458,7 +458,7 @@ static void inc_sessions (struct Plugin *plugin, struct Session *session, int line) { sessions++; - unsigned int size = GNUNET_CONTAINER_multihashmap_size(plugin->sessionmap); + unsigned int size = GNUNET_CONTAINER_multipeermap_size(plugin->sessionmap); if (sessions != size) LOG (GNUNET_ERROR_TYPE_DEBUG, "Inconsistent sessions %u <-> session map size: %u\n", sessions, size); @@ -475,7 +475,7 @@ static void dec_sessions (struct Plugin *plugin, struct Session *session, int line) { GNUNET_assert (sessions > 0); - unsigned int size = GNUNET_CONTAINER_multihashmap_size(plugin->sessionmap); + unsigned int size = GNUNET_CONTAINER_multipeermap_size(plugin->sessionmap); sessions--; if (sessions != size) LOG (GNUNET_ERROR_TYPE_DEBUG, "Inconsistent sessions %u <-> session map size: %u\n", @@ -751,7 +751,7 @@ struct SessionClientCtx static int session_lookup_by_client_it (void *cls, - const struct GNUNET_HashCode * key, + const struct GNUNET_PeerIdentity *key, void *value) { struct SessionClientCtx *sc_ctx = cls; @@ -781,7 +781,7 @@ lookup_session_by_client (struct Plugin *plugin, sc_ctx.client = client; sc_ctx.ret = NULL; - GNUNET_CONTAINER_multihashmap_iterate (plugin->sessionmap, &session_lookup_by_client_it, &sc_ctx); + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, &session_lookup_by_client_it, &sc_ctx); return sc_ctx.ret; } @@ -1024,14 +1024,14 @@ disconnect_session (struct Session *session) stop_session_timeout (session); - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (plugin->sessionmap, &session->target.hashPubKey, session)) + if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, &session->target, session)) { GNUNET_STATISTICS_update (session->plugin->env->stats, gettext_noop ("# TCP sessions active"), -1, GNUNET_NO); dec_sessions (plugin, session, __LINE__); } - else GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (plugin->nat_wait_conns, &session->target.hashPubKey, session)); + else GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, &session->target, session)); /* clean up state */ if (session->transmit_handle != NULL) @@ -1093,32 +1093,36 @@ struct FindSessionContext int res; }; -int session_it (void *cls, - const struct GNUNET_HashCode * key, - void *value) + +static int +session_it (void *cls, + const struct GNUNET_PeerIdentity * key, + void *value) { struct FindSessionContext *res = cls; + if (res->s == value) { res->res = GNUNET_OK; return GNUNET_NO; } - else - return GNUNET_YES; + return GNUNET_YES; } -int find_session (struct Plugin *plugin, struct Session *session) + +static int +find_session (struct Plugin *plugin, struct Session *session) { struct FindSessionContext session_map_res; struct FindSessionContext nat_map_res; session_map_res.s = session; session_map_res.res = GNUNET_SYSERR; - GNUNET_CONTAINER_multihashmap_iterate (plugin->sessionmap, &session_it, &session_map_res); + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, &session_it, &session_map_res); nat_map_res.s = session; nat_map_res.res = GNUNET_SYSERR; - GNUNET_CONTAINER_multihashmap_iterate (plugin->nat_wait_conns, &session_it, &nat_map_res); + GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, &session_it, &nat_map_res); if ((session_map_res.res == GNUNET_SYSERR) && (nat_map_res.res == GNUNET_SYSERR)) { @@ -1190,8 +1194,8 @@ tcp_plugin_send (void *cls, "Asked to transmit %u bytes to `%s', added message to list.\n", msgbuf_size, GNUNET_i2s (&session->target)); - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value (plugin->sessionmap, - &session->target.hashPubKey, + if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, + &session->target, session)) { GNUNET_assert (session->client != NULL); @@ -1209,7 +1213,7 @@ tcp_plugin_send (void *cls, process_pending_messages (session); return msgbuf_size; } - else if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(plugin->nat_wait_conns, &session->target.hashPubKey, session)) + else if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains_value(plugin->nat_wait_conns, &session->target, session)) { LOG (GNUNET_ERROR_TYPE_DEBUG, "This NAT WAIT session for peer `%s' is not yet ready!\n", @@ -1247,7 +1251,7 @@ struct SessionItCtx static int session_lookup_it (void *cls, - const struct GNUNET_HashCode *key, + const struct GNUNET_PeerIdentity *key, void *value) { struct SessionItCtx * si_ctx = cls; @@ -1343,8 +1347,8 @@ tcp_plugin_get_session (void *cls, /* look for existing session */ if (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (plugin->sessionmap, - &address->peer.hashPubKey)) + GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, + &address->peer)) { struct SessionItCtx si_ctx; @@ -1353,8 +1357,8 @@ tcp_plugin_get_session (void *cls, si_ctx.result = NULL; - GNUNET_CONTAINER_multihashmap_get_multiple (plugin->sessionmap, - &address->peer.hashPubKey, + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, + &address->peer, &session_lookup_it, &si_ctx); if (si_ctx.result != NULL) { @@ -1431,8 +1435,8 @@ tcp_plugin_get_session (void *cls, if ((is_natd == GNUNET_YES) && (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns, - &address->peer.hashPubKey))) + GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, + &address->peer))) { /* Only do one NAT punch attempt per peer identity */ return NULL; @@ -1440,8 +1444,8 @@ tcp_plugin_get_session (void *cls, if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && (GNUNET_NO == - GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns, - &address->peer.hashPubKey))) + GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, + &address->peer))) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Found valid IPv4 NAT address (creating session)!\n") ; @@ -1454,8 +1458,8 @@ tcp_plugin_get_session (void *cls, session); GNUNET_assert (session != NULL); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (plugin->nat_wait_conns, - &session->target.hashPubKey, + GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns, + &session->target, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); @@ -1502,8 +1506,8 @@ tcp_plugin_get_session (void *cls, session->addrlen = addrlen; session->ats_address_network_type = ats.value; - GNUNET_CONTAINER_multihashmap_put (plugin->sessionmap, - &session->target.hashPubKey, + GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, + &session->target, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); inc_sessions (plugin, session, __LINE__); LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -1520,7 +1524,7 @@ tcp_plugin_get_session (void *cls, static int session_disconnect_it (void *cls, - const struct GNUNET_HashCode * key, + const struct GNUNET_PeerIdentity *key, void *value) { struct Session *session = value; @@ -1557,8 +1561,10 @@ tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s'\n", GNUNET_i2s (target)); - GNUNET_CONTAINER_multihashmap_get_multiple (plugin->sessionmap, &target->hashPubKey, &session_disconnect_it, plugin); - GNUNET_CONTAINER_multihashmap_get_multiple (plugin->nat_wait_conns, &target->hashPubKey, &session_disconnect_it, plugin); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, target, + &session_disconnect_it, plugin); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->nat_wait_conns, target, + &session_disconnect_it, plugin); } @@ -1933,9 +1939,9 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, } session = - GNUNET_CONTAINER_multihashmap_get (plugin->nat_wait_conns, + GNUNET_CONTAINER_multipeermap_get (plugin->nat_wait_conns, &tcp_nat_probe-> - clientIdentity.hashPubKey); + clientIdentity); if (session == NULL) { LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -1959,12 +1965,12 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, disconnect_session (session); return; } - GNUNET_assert (GNUNET_CONTAINER_multihashmap_remove + GNUNET_assert (GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, - &tcp_nat_probe->clientIdentity.hashPubKey, + &tcp_nat_probe->clientIdentity, session) == GNUNET_YES); - GNUNET_CONTAINER_multihashmap_put (plugin->sessionmap, - &session->target.hashPubKey, session, + GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, + &session->target, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); session->last_activity = GNUNET_TIME_absolute_get (); session->inbound = GNUNET_NO; @@ -2110,8 +2116,8 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, session, GNUNET_a2s (vaddr, alen)); GNUNET_free (vaddr); - GNUNET_CONTAINER_multihashmap_put (plugin->sessionmap, - &session->target.hashPubKey, + GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, + &session->target, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); inc_sessions (plugin, session, __LINE__); @@ -2247,9 +2253,9 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, distance.value = session->ats_address_network_type; GNUNET_break (ntohl(session->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); - GNUNET_assert (GNUNET_CONTAINER_multihashmap_contains_value (plugin->sessionmap, - &session->target.hashPubKey, - session)); + GNUNET_assert (GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, + &session->target, + session)); delay = plugin->env->receive (plugin->env->cls, &session->target, @@ -2592,7 +2598,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) myoptions = 0; plugin = GNUNET_malloc (sizeof (struct Plugin)); - plugin->sessionmap = GNUNET_CONTAINER_multihashmap_create (max_connections, GNUNET_YES); + plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); plugin->max_connections = max_connections; plugin->cur_connections = 0; plugin->open_port = bport; @@ -2671,7 +2677,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); - plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES); + plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); if (bport != 0) LOG (GNUNET_ERROR_TYPE_INFO, _("TCP transport listening on port %llu\n"), bport); @@ -2713,9 +2719,9 @@ libgnunet_plugin_transport_tcp_done (void *cls) LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); /* Removing leftover sessions */ - GNUNET_CONTAINER_multihashmap_iterate(plugin->sessionmap, &session_disconnect_it, NULL); + GNUNET_CONTAINER_multipeermap_iterate(plugin->sessionmap, &session_disconnect_it, NULL); /* Removing leftover NAT sessions */ - GNUNET_CONTAINER_multihashmap_iterate(plugin->nat_wait_conns, &session_disconnect_it, NULL); + GNUNET_CONTAINER_multipeermap_iterate(plugin->nat_wait_conns, &session_disconnect_it, NULL); next = ppc_dll_head; for (cur = next; NULL != cur; cur = next) @@ -2743,8 +2749,8 @@ libgnunet_plugin_transport_tcp_done (void *cls) GNUNET_CONNECTION_destroy (tcp_probe->sock); GNUNET_free (tcp_probe); } - GNUNET_CONTAINER_multihashmap_destroy (plugin->nat_wait_conns); - GNUNET_CONTAINER_multihashmap_destroy (plugin->sessionmap); + GNUNET_CONTAINER_multipeermap_destroy (plugin->nat_wait_conns); + GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); GNUNET_free (plugin); GNUNET_free (api); return NULL; diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c index 75554a0db0..faee0c38d5 100644 --- a/src/transport/plugin_transport_template.c +++ b/src/transport/plugin_transport_template.c @@ -25,10 +25,8 @@ */ #include "platform.h" +#include "gnunet_util_lib.h" #include "gnunet_protocols.h" -#include "gnunet_connection_lib.h" -#include "gnunet_server_lib.h" -#include "gnunet_service_lib.h" #include "gnunet_statistics_service.h" #include "gnunet_transport_service.h" #include "gnunet_transport_plugin.h" diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index bc64fd5d25..4fe4d94cfd 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -1271,12 +1271,12 @@ disconnect_session (struct Session *s) } GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (plugin->sessions, - &s->target.hashPubKey, + GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, + &s->target, s)); GNUNET_STATISTICS_set(plugin->env->stats, "# UDP, sessions active", - GNUNET_CONTAINER_multihashmap_size(plugin->sessions), + GNUNET_CONTAINER_multipeermap_size(plugin->sessions), GNUNET_NO); if (s->rc > 0) s->in_destroy = GNUNET_YES; @@ -1293,7 +1293,7 @@ disconnect_session (struct Session *s) * @return GNUNET_OK (continue to iterate) */ static int -disconnect_and_free_it (void *cls, const struct GNUNET_HashCode * key, void *value) +disconnect_and_free_it (void *cls, const struct GNUNET_PeerIdentity * key, void *value) { disconnect_session(value); return GNUNET_OK; @@ -1317,7 +1317,8 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer `%s'\n", GNUNET_i2s (target)); /* Clean up sessions */ - GNUNET_CONTAINER_multihashmap_get_multiple (plugin->sessions, &target->hashPubKey, &disconnect_and_free_it, plugin); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, + &disconnect_and_free_it, plugin); } @@ -1466,7 +1467,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, static int session_cmp_it (void *cls, - const struct GNUNET_HashCode * key, + const struct GNUNET_PeerIdentity * key, void *value) { struct SessionCompareContext * cctx = cls; @@ -1591,7 +1592,7 @@ udp_plugin_lookup_session (void *cls, "Looking for existing session for peer `%s' `%s' \n", GNUNET_i2s (&address->peer), udp_address_to_string(NULL, address->address, address->address_length)); - GNUNET_CONTAINER_multihashmap_get_multiple(plugin->sessions, &address->peer.hashPubKey, session_cmp_it, &cctx); + GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, &address->peer, session_cmp_it, &cctx); if (cctx.res != NULL) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res); @@ -1623,13 +1624,13 @@ udp_plugin_create_session (void *cls, GNUNET_i2s(&address->peer), udp_address_to_string(NULL,address->address,address->address_length)); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (plugin->sessions, - &s->target.hashPubKey, + GNUNET_CONTAINER_multipeermap_put (plugin->sessions, + &s->target, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); GNUNET_STATISTICS_set(plugin->env->stats, "# UDP, sessions active", - GNUNET_CONTAINER_multihashmap_size(plugin->sessions), + GNUNET_CONTAINER_multipeermap_size(plugin->sessions), GNUNET_NO); return s; } @@ -1800,7 +1801,7 @@ udp_plugin_send (void *cls, GNUNET_break (0); return GNUNET_SYSERR; } - if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains_value(plugin->sessions, &s->target.hashPubKey, s)) + if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions, &s->target, s)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -2137,7 +2138,9 @@ struct LookupContext static int -lookup_session_by_addr_it (void *cls, const struct GNUNET_HashCode * key, void *value) +lookup_session_by_addr_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct LookupContext *l_ctx = cls; struct Session * s = value; @@ -2184,7 +2187,7 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) l_ctx.addrlen = rc->addr_len; l_ctx.res = NULL; l_ctx.must_have_frag_ctx = GNUNET_NO; - GNUNET_CONTAINER_multihashmap_iterate (rc->plugin->sessions, + GNUNET_CONTAINER_multipeermap_iterate (rc->plugin->sessions, &lookup_session_by_addr_it, &l_ctx); s = l_ctx.res; @@ -2259,7 +2262,7 @@ read_process_ack (struct Plugin *plugin, l_ctx.addrlen = fromlen; l_ctx.res = NULL; l_ctx.must_have_frag_ctx = GNUNET_YES; - GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions, + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, &lookup_session_by_addr_it, &l_ctx); s = l_ctx.res; @@ -3111,7 +3114,7 @@ libgnunet_plugin_transport_udp_init (void *cls) p->enable_ipv6 = enable_v6; p->enable_ipv4 = GNUNET_YES; /* default */ p->env = env; - p->sessions = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); + p->sessions = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); p->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, p); GNUNET_BANDWIDTH_tracker_init (&p->tracker, @@ -3125,7 +3128,7 @@ libgnunet_plugin_transport_udp_init (void *cls) { LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to create network sockets, plugin failed\n")); - GNUNET_CONTAINER_multihashmap_destroy (p->sessions); + GNUNET_CONTAINER_multipeermap_destroy (p->sessions); GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); GNUNET_SERVER_mst_destroy (p->mst); GNUNET_free (p); @@ -3267,8 +3270,8 @@ libgnunet_plugin_transport_udp_done (void *cls) /* Clean up sessions */ LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up sessions\n"); - GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions, &disconnect_and_free_it, plugin); - GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, &disconnect_and_free_it, plugin); + GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); next = ppc_dll_head; for (cur = next; NULL != cur; cur = next) diff --git a/src/transport/plugin_transport_udp.h b/src/transport/plugin_transport_udp.h index e168a534c9..6fb573690b 100644 --- a/src/transport/plugin_transport_udp.h +++ b/src/transport/plugin_transport_udp.h @@ -135,7 +135,7 @@ struct Plugin * Session of peers with whom we are currently connected, * map of peer identity to 'struct PeerSession'. */ - struct GNUNET_CONTAINER_MultiHashMap *sessions; + struct GNUNET_CONTAINER_MultiPeerMap *sessions; /** * Heap with all of our defragmentation activities. diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index beed32d8d2..4e153aab4e 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -276,7 +276,7 @@ struct Plugin /** * Sessions */ - struct GNUNET_CONTAINER_MultiHashMap *session_map; + struct GNUNET_CONTAINER_MultiPeerMap *session_map; /** * FD Read set @@ -454,7 +454,7 @@ struct LookupCtx */ static int lookup_session_it (void *cls, - const struct GNUNET_HashCode * key, + const struct GNUNET_PeerIdentity * key, void *value) { struct LookupCtx *lctx = cls; @@ -498,8 +498,8 @@ lookup_session (struct Plugin *plugin, lctx.s = NULL; lctx.ua = ua; lctx.ua_len = ua_len; - GNUNET_CONTAINER_multihashmap_get_multiple (plugin->session_map, - &sender->hashPubKey, + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, + sender, &lookup_session_it, &lctx); return lctx.s; } @@ -542,12 +542,12 @@ disconnect_session (struct Session *s) removed = GNUNET_YES; } GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (plugin->session_map, - &s->target.hashPubKey, + GNUNET_CONTAINER_multipeermap_remove (plugin->session_map, + &s->target, s)); GNUNET_STATISTICS_set (plugin->env->stats, "# UNIX sessions active", - GNUNET_CONTAINER_multihashmap_size (plugin->session_map), + GNUNET_CONTAINER_multipeermap_size (plugin->session_map), GNUNET_NO); if ((GNUNET_YES == removed) && (NULL == plugin->msg_head)) reschedule_select (plugin); @@ -712,7 +712,7 @@ struct GetSessionIteratorContext */ static int get_session_it (void *cls, - const struct GNUNET_HashCode *key, + const struct GNUNET_PeerIdentity *key, void *value) { struct GetSessionIteratorContext *gsi = cls; @@ -818,8 +818,8 @@ unix_plugin_get_session (void *cls, gsi.address = (const char *) address->address; gsi.addrlen = address->address_length; gsi.res = NULL; - GNUNET_CONTAINER_multihashmap_get_multiple (plugin->session_map, - &address->peer.hashPubKey, + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, + &address->peer, &get_session_it, &gsi); if (NULL != gsi.res) { @@ -843,12 +843,12 @@ unix_plugin_get_session (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating a new session %p for address `%s'\n", s, unix_address_to_string (NULL, address->address, address->address_length)); - (void) GNUNET_CONTAINER_multihashmap_put (plugin->session_map, - &address->peer.hashPubKey, s, + (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map, + &address->peer, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); GNUNET_STATISTICS_set (plugin->env->stats, "# UNIX sessions active", - GNUNET_CONTAINER_multihashmap_size (plugin->session_map), + GNUNET_CONTAINER_multipeermap_size (plugin->session_map), GNUNET_NO); return s; } @@ -898,8 +898,8 @@ unix_plugin_send (void *cls, GNUNET_assert (NULL != session); if (GNUNET_OK != - GNUNET_CONTAINER_multihashmap_contains_value (plugin->session_map, - &session->target.hashPubKey, + GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, + &session->target, session)) { LOG (GNUNET_ERROR_TYPE_ERROR, @@ -1553,7 +1553,9 @@ reschedule_session_timeout (struct Session *s) * @return GNUNET_YES (always, continue to iterate) */ static int -get_session_delete_it (void *cls, const struct GNUNET_HashCode * key, void *value) +get_session_delete_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct Session *s = value; @@ -1567,7 +1569,7 @@ get_session_delete_it (void *cls, const struct GNUNET_HashCode * key, void *valu * * @param cls closure for this call (should be handle to Plugin) * @param target the peeridentity of the peer to disconnect - * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed + * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed */ static void unix_disconnect (void *cls, @@ -1576,8 +1578,8 @@ unix_disconnect (void *cls, struct Plugin *plugin = cls; GNUNET_assert (plugin != NULL); - GNUNET_CONTAINER_multihashmap_get_multiple (plugin->session_map, - &target->hashPubKey, + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, + target, &get_session_delete_it, plugin); } @@ -1638,7 +1640,7 @@ libgnunet_plugin_transport_unix_init (void *cls) if (0 == sockets_created) LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UNIX listen socket\n")); - plugin->session_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); + plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); plugin->address_update_task = GNUNET_SCHEDULER_add_now (&address_notification, plugin); return api; } @@ -1701,9 +1703,9 @@ libgnunet_plugin_transport_unix_done (void *cls) plugin->unix_sock.desc = NULL; plugin->with_ws = GNUNET_NO; } - GNUNET_CONTAINER_multihashmap_iterate (plugin->session_map, + GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, &get_session_delete_it, plugin); - GNUNET_CONTAINER_multihashmap_destroy (plugin->session_map); + GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map); if (NULL != plugin->rs) GNUNET_NETWORK_fdset_destroy (plugin->rs); if (NULL != plugin->ws) diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h index c6f990058e..044c6818a0 100644 --- a/src/transport/plugin_transport_wlan.h +++ b/src/transport/plugin_transport_wlan.h @@ -26,7 +26,7 @@ #ifndef PLUGIN_TRANSPORT_WLAN #define PLUGIN_TRANSPORT_WLAN -#include <stdint.h> +#include "gnunet_crypto_lib.h" #include "gnunet_common.h" /** diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 7c33ad4ca6..30cb878329 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c @@ -24,7 +24,6 @@ * * @author Matthias Wachs */ - #include "transport-testing.h" diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index f3906b4956..99225936a1 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h @@ -24,12 +24,9 @@ * * @author Matthias Wachs */ - #include "platform.h" -#include "gnunet_common.h" +#include "gnunet_util_lib.h" #include "gnunet_hello_lib.h" -#include "gnunet_program_lib.h" -#include "gnunet_container_lib.h" #include "gnunet_transport_service.h" #include "gnunet_testing_lib.h" diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index f83b6c0984..cb6cefdb18 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -29,16 +29,11 @@ * - test test test */ #include "platform.h" +#include "gnunet_util_lib.h" #include "gnunet_constants.h" -#include "gnunet_bandwidth_lib.h" -#include "gnunet_client_lib.h" -#include "gnunet_constants.h" -#include "gnunet_container_lib.h" #include "gnunet_arm_service.h" #include "gnunet_hello_lib.h" #include "gnunet_protocols.h" -#include "gnunet_server_lib.h" -#include "gnunet_time_lib.h" #include "gnunet_transport_service.h" #include "transport.h" @@ -320,7 +315,7 @@ struct GNUNET_TRANSPORT_Handle * Hash map of the current connected neighbours of this peer. * Maps peer identities to 'struct Neighbour' entries. */ - struct GNUNET_CONTAINER_MultiHashMap *neighbours; + struct GNUNET_CONTAINER_MultiPeerMap *neighbours; /** * Heap sorting peers with pending messages by the timestamps that @@ -398,7 +393,7 @@ static struct Neighbour * neighbour_find (struct GNUNET_TRANSPORT_Handle *h, const struct GNUNET_PeerIdentity *peer) { - return GNUNET_CONTAINER_multihashmap_get (h->neighbours, &peer->hashPubKey); + return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer); } @@ -424,8 +419,8 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h, GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, MAX_BANDWIDTH_CARRY_S); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (h->neighbours, - &n->id.hashPubKey, n, + GNUNET_CONTAINER_multipeermap_put (h->neighbours, + &n->id, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); return n; } @@ -442,7 +437,8 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h, * GNUNET_NO if not. */ static int -neighbour_delete (void *cls, const struct GNUNET_HashCode * key, void *value) +neighbour_delete (void *cls, + const struct GNUNET_PeerIdentity *key, void *value) { struct GNUNET_TRANSPORT_Handle *handle = cls; struct Neighbour *n = value; @@ -452,7 +448,7 @@ neighbour_delete (void *cls, const struct GNUNET_HashCode * key, void *value) GNUNET_assert (NULL == n->th); GNUNET_assert (NULL == n->hn); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (handle->neighbours, key, + GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n)); GNUNET_free (n); return GNUNET_YES; @@ -568,7 +564,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) GNUNET_break (0); break; } - neighbour_delete (h, &dim->peer.hashPubKey, n); + neighbour_delete (h, &dim->peer, n); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK: if (size != sizeof (struct SendOkMessage)) @@ -994,7 +990,7 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h) h->client = NULL; } /* Forget about all neighbours that we used to be connected to */ - GNUNET_CONTAINER_multihashmap_iterate (h->neighbours, &neighbour_delete, h); + GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h); if (h->quota_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (h->quota_task); @@ -1341,15 +1337,15 @@ GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *o int GNUNET_TRANSPORT_check_neighbour_connected (struct GNUNET_TRANSPORT_Handle *handle, - const struct GNUNET_PeerIdentity *peer) + const struct GNUNET_PeerIdentity *peer) { - GNUNET_assert (NULL != handle); - GNUNET_assert (NULL != peer); - - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(handle->neighbours, &peer->hashPubKey)) - return GNUNET_YES; - else - return GNUNET_NO; + GNUNET_assert (NULL != handle); + GNUNET_assert (NULL != peer); + + if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (handle->neighbours, peer)) + return GNUNET_YES; + else + return GNUNET_NO; } @@ -1455,7 +1451,7 @@ GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, ret->nd_cb = nd; ret->reconnect_delay = GNUNET_TIME_UNIT_ZERO; ret->neighbours = - GNUNET_CONTAINER_multihashmap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); + GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); ret->ready_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); @@ -1488,7 +1484,7 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle) GNUNET_SCHEDULER_cancel (handle->reconnect_task); handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; } - GNUNET_CONTAINER_multihashmap_destroy (handle->neighbours); + GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours); handle->neighbours = NULL; if (handle->quota_task != GNUNET_SCHEDULER_NO_TASK) { diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index 217aecdb5e..9c1301ed2c 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c @@ -28,14 +28,11 @@ * transport plugin, and whether or not the address given is currently * in the 'connected' state (according to the transport service). */ - #include "platform.h" -#include "gnunet_client_lib.h" +#include "gnunet_util_lib.h" #include "gnunet_arm_service.h" #include "gnunet_hello_lib.h" #include "gnunet_protocols.h" -#include "gnunet_server_lib.h" -#include "gnunet_time_lib.h" #include "gnunet_transport_service.h" #include "transport.h" diff --git a/src/transport/transport_api_address_to_string.c b/src/transport/transport_api_address_to_string.c index 152e573cd7..94c9ac45aa 100644 --- a/src/transport/transport_api_address_to_string.c +++ b/src/transport/transport_api_address_to_string.c @@ -18,12 +18,10 @@ Boston, MA 02111-1307, USA. */ #include "platform.h" -#include "gnunet_client_lib.h" +#include "gnunet_util_lib.h" #include "gnunet_arm_service.h" #include "gnunet_hello_lib.h" #include "gnunet_protocols.h" -#include "gnunet_server_lib.h" -#include "gnunet_time_lib.h" #include "gnunet_transport_service.h" #include "transport.h" diff --git a/src/transport/transport_api_blacklist.c b/src/transport/transport_api_blacklist.c index 04646204f0..dcd1ae7818 100644 --- a/src/transport/transport_api_blacklist.c +++ b/src/transport/transport_api_blacklist.c @@ -24,12 +24,10 @@ * @author Christian Grothoff */ #include "platform.h" -#include "gnunet_client_lib.h" +#include "gnunet_util_lib.h" #include "gnunet_arm_service.h" #include "gnunet_hello_lib.h" #include "gnunet_protocols.h" -#include "gnunet_server_lib.h" -#include "gnunet_time_lib.h" #include "gnunet_transport_service.h" #include "transport.h" |