From 90fe9d740ea1be4f8c3f91534a196fd376d9cc9f Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 24 Oct 2012 14:37:18 +0000 Subject: [PATCH] - changes but not complete --- src/ats/gnunet-service-ats_addresses.c | 82 ++++++++++++++++++++++++ src/ats/gnunet-service-ats_addresses.h | 13 ++++ src/ats/gnunet-service-ats_performance.c | 30 +++++++++ 3 files changed, 125 insertions(+) diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 075324762..448b9eb20 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -1051,6 +1051,88 @@ GAS_addresses_done () GAS_mlp_done (mlp); } #endif +} + +struct PeerIteratorContext +{ + GNUNET_ATS_Peer_Iterator it; + void *it_cls; + struct GNUNET_CONTAINER_MultiHashMap *peers_returned; +}; + +static int +peer_it (void *cls, + const struct GNUNET_HashCode * key, + void *value) +{ + struct PeerIteratorContext *ip_ctx = cls; + struct GNUNET_PeerIdentity tmp; + + if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_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, &tmp); + } + + return GNUNET_OK; +} + + +void +GAS_addresses_iterate_peers (GNUNET_ATS_Peer_Iterator it, void *it_cls) +{ + struct PeerIteratorContext ip_ctx; + unsigned int size; + + if (NULL == it) + return; + GNUNET_assert (NULL != addresses); + + size = GNUNET_CONTAINER_multihashmap_size(addresses); + if (0 != size) + { + ip_ctx.it = it; + ip_ctx.it_cls = it_cls; + ip_ctx.peers_returned = GNUNET_CONTAINER_multihashmap_create (size, GNUNET_NO); + GNUNET_CONTAINER_multihashmap_iterate (addresses, &peer_it, &ip_ctx); + GNUNET_CONTAINER_multihashmap_destroy (ip_ctx.peers_returned); + } + it (it_cls, NULL); +} + +struct PeerInfoIteratorContext +{ + GNUNET_ATS_PeerInfo_Iterator it; + void *it_cls; +}; + +int peerinfo_it (void *cls, + const struct GNUNET_HashCode * key, + void *value) +{ + struct PeerInfoIteratorContext *pi_ctx = cls; + struct ATS_Address *addr = (struct ATS_Address *) value; + + if (NULL != pi_ctx->it) + pi_ctx->it (pi_ctx->it_cls, &addr->peer, addr->plugin); + return GNUNET_YES; +} + +void +GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it, void *pi_it_cls) +{ + struct PeerInfoIteratorContext pi_ctx; + GNUNET_assert (NULL != peer); + GNUNET_assert (NULL != addresses); + + pi_ctx.it = pi_it; + pi_ctx.it_cls = pi_it_cls; + + GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, &peerinfo_it, &pi_ctx); + + if (NULL != pi_it) + pi_it (pi_it_cls, NULL, NULL); } diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 866d25663..4c64239be 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h @@ -165,6 +165,19 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, /* FIXME: add performance request API */ +typedef void (*GNUNET_ATS_Peer_Iterator) (void *cls, + const struct GNUNET_PeerIdentity *id); + +void +GAS_addresses_iterate_peers (GNUNET_ATS_Peer_Iterator p_it, void *cls); + +typedef void (*GNUNET_ATS_PeerInfo_Iterator) (void *cls, + const struct GNUNET_PeerIdentity *id, + const char *plugin); + +void +GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it, void *pi_it_cls); + #endif /* end of gnunet-service-ats_addresses.h */ diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index 7ab8e9ae1..a4b50513a 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c @@ -94,6 +94,33 @@ find_client (struct GNUNET_SERVER_Client *client) } +static void +peerinfo_it (void *cls, + const struct GNUNET_PeerIdentity *id, + const char *plugin) +{ + struct PerformanceClient *pc = cls; + GNUNET_assert (NULL != pc); + if (NULL != id) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s' plugin `%s'\n", GNUNET_i2s (id), plugin); + /* TODO: Notify client here! */ + //GNUNET_break (0); + } + +} + +static void +peer_it (void *cls, + const struct GNUNET_PeerIdentity *id) +{ + if (NULL != id) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s'\n", GNUNET_i2s (id)); + GAS_addresses_get_peer_info (id, &peerinfo_it, cls); + } +} + /** * Register a new performance client. * @@ -113,6 +140,9 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client, GNUNET_SERVER_notification_context_add (nc, client); GNUNET_SERVER_client_keep (client); GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc); + + /* Send information about clients */ + GAS_addresses_iterate_peers (&peer_it, pc); } -- 2.25.1