aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-10-24 14:37:18 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-10-24 14:37:18 +0000
commit90fe9d740ea1be4f8c3f91534a196fd376d9cc9f (patch)
tree9569e38c5da2e4da3424427cf17d4ab31f58ffa8 /src/ats
parent5c3ed7bd316e53dbc47a44f7d8e5fc1937ad11bc (diff)
downloadgnunet-90fe9d740ea1be4f8c3f91534a196fd376d9cc9f.tar.gz
gnunet-90fe9d740ea1be4f8c3f91534a196fd376d9cc9f.zip
- changes but not complete
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/gnunet-service-ats_addresses.c82
-rw-r--r--src/ats/gnunet-service-ats_addresses.h13
-rw-r--r--src/ats/gnunet-service-ats_performance.c30
3 files changed, 125 insertions, 0 deletions
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 ()
1051 GAS_mlp_done (mlp); 1051 GAS_mlp_done (mlp);
1052 } 1052 }
1053#endif 1053#endif
1054}
1055
1056struct PeerIteratorContext
1057{
1058 GNUNET_ATS_Peer_Iterator it;
1059 void *it_cls;
1060 struct GNUNET_CONTAINER_MultiHashMap *peers_returned;
1061};
1062
1063static int
1064peer_it (void *cls,
1065 const struct GNUNET_HashCode * key,
1066 void *value)
1067{
1068 struct PeerIteratorContext *ip_ctx = cls;
1069 struct GNUNET_PeerIdentity tmp;
1070
1071 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(ip_ctx->peers_returned, key))
1072 {
1073 GNUNET_CONTAINER_multihashmap_put(ip_ctx->peers_returned, key, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1074 tmp.hashPubKey = (*key);
1075 ip_ctx->it (ip_ctx, &tmp);
1076 }
1077
1078 return GNUNET_OK;
1079}
1080
1081
1082void
1083GAS_addresses_iterate_peers (GNUNET_ATS_Peer_Iterator it, void *it_cls)
1084{
1085 struct PeerIteratorContext ip_ctx;
1086 unsigned int size;
1087
1088 if (NULL == it)
1089 return;
1090 GNUNET_assert (NULL != addresses);
1091
1092 size = GNUNET_CONTAINER_multihashmap_size(addresses);
1093 if (0 != size)
1094 {
1095 ip_ctx.it = it;
1096 ip_ctx.it_cls = it_cls;
1097 ip_ctx.peers_returned = GNUNET_CONTAINER_multihashmap_create (size, GNUNET_NO);
1098 GNUNET_CONTAINER_multihashmap_iterate (addresses, &peer_it, &ip_ctx);
1099 GNUNET_CONTAINER_multihashmap_destroy (ip_ctx.peers_returned);
1100 }
1101 it (it_cls, NULL);
1102}
1103
1104struct PeerInfoIteratorContext
1105{
1106 GNUNET_ATS_PeerInfo_Iterator it;
1107 void *it_cls;
1108};
1109
1110int peerinfo_it (void *cls,
1111 const struct GNUNET_HashCode * key,
1112 void *value)
1113{
1114 struct PeerInfoIteratorContext *pi_ctx = cls;
1115 struct ATS_Address *addr = (struct ATS_Address *) value;
1116
1117 if (NULL != pi_ctx->it)
1118 pi_ctx->it (pi_ctx->it_cls, &addr->peer, addr->plugin);
1119 return GNUNET_YES;
1120}
1121
1122void
1123GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it, void *pi_it_cls)
1124{
1125 struct PeerInfoIteratorContext pi_ctx;
1126 GNUNET_assert (NULL != peer);
1127 GNUNET_assert (NULL != addresses);
1128
1129 pi_ctx.it = pi_it;
1130 pi_ctx.it_cls = pi_it_cls;
1131
1132 GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, &peerinfo_it, &pi_ctx);
1133
1134 if (NULL != pi_it)
1135 pi_it (pi_it_cls, NULL, NULL);
1054 1136
1055} 1137}
1056 1138
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,
165 165
166/* FIXME: add performance request API */ 166/* FIXME: add performance request API */
167 167
168typedef void (*GNUNET_ATS_Peer_Iterator) (void *cls,
169 const struct GNUNET_PeerIdentity *id);
170
171void
172GAS_addresses_iterate_peers (GNUNET_ATS_Peer_Iterator p_it, void *cls);
173
174typedef void (*GNUNET_ATS_PeerInfo_Iterator) (void *cls,
175 const struct GNUNET_PeerIdentity *id,
176 const char *plugin);
177
178void
179GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it, void *pi_it_cls);
180
168#endif 181#endif
169 182
170/* end of gnunet-service-ats_addresses.h */ 183/* 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)
94} 94}
95 95
96 96
97static void
98peerinfo_it (void *cls,
99 const struct GNUNET_PeerIdentity *id,
100 const char *plugin)
101{
102 struct PerformanceClient *pc = cls;
103 GNUNET_assert (NULL != pc);
104 if (NULL != id)
105 {
106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s' plugin `%s'\n", GNUNET_i2s (id), plugin);
107 /* TODO: Notify client here! */
108 //GNUNET_break (0);
109 }
110
111}
112
113static void
114peer_it (void *cls,
115 const struct GNUNET_PeerIdentity *id)
116{
117 if (NULL != id)
118 {
119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s'\n", GNUNET_i2s (id));
120 GAS_addresses_get_peer_info (id, &peerinfo_it, cls);
121 }
122}
123
97/** 124/**
98 * Register a new performance client. 125 * Register a new performance client.
99 * 126 *
@@ -113,6 +140,9 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
113 GNUNET_SERVER_notification_context_add (nc, client); 140 GNUNET_SERVER_notification_context_add (nc, client);
114 GNUNET_SERVER_client_keep (client); 141 GNUNET_SERVER_client_keep (client);
115 GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc); 142 GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc);
143
144 /* Send information about clients */
145 GAS_addresses_iterate_peers (&peer_it, pc);
116} 146}
117 147
118 148