diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-10-25 12:33:59 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-10-25 12:33:59 +0000 |
commit | f3df83c6329619d841ec44feaaff0ad366fa1eda (patch) | |
tree | 93b32662090498136b3770d1bfde06f0553b414d | |
parent | 9ac6dc6bfcd74b44d7096e2f99d16f47a35fe75a (diff) | |
download | gnunet-f3df83c6329619d841ec44feaaff0ad366fa1eda.tar.gz gnunet-f3df83c6329619d841ec44feaaff0ad366fa1eda.zip |
gnunet-ats working and bug 0002593
-rw-r--r-- | src/ats/gnunet-ats.c | 11 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 4 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_performance.c | 191 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_performance.h | 2 |
4 files changed, 125 insertions, 83 deletions
diff --git a/src/ats/gnunet-ats.c b/src/ats/gnunet-ats.c index 8770a085f..2de08e2d1 100644 --- a/src/ats/gnunet-ats.c +++ b/src/ats/gnunet-ats.c | |||
@@ -51,7 +51,9 @@ void ats_perf_cb (void *cls, | |||
51 | GNUNET_ATS_Information * | 51 | GNUNET_ATS_Information * |
52 | ats, uint32_t ats_count) | 52 | ats, uint32_t ats_count) |
53 | { | 53 | { |
54 | fprintf (stderr, "Peer `%s'\n", GNUNET_i2s (&address->peer)); | 54 | fprintf (stderr, "Peer `%s' plugin `%s', bandwidth out: %u Bytes/s, bandwidth in %u Bytes/s\n", |
55 | GNUNET_i2s (&address->peer), address->transport_name, | ||
56 | ntohl (bandwidth_out.value__), ntohl (bandwidth_in.value__)); | ||
55 | results++; | 57 | results++; |
56 | } | 58 | } |
57 | 59 | ||
@@ -60,8 +62,7 @@ void end (void *cls, | |||
60 | { | 62 | { |
61 | GNUNET_ATS_performance_done (ph); | 63 | GNUNET_ATS_performance_done (ph); |
62 | ph = NULL; | 64 | ph = NULL; |
63 | /*FIXME */fprintf (stderr, "NOT IMPLEMENTED!\n"); | 65 | fprintf (stderr, "ATS returned results for %u addresses\n", results); |
64 | fprintf (stderr, "ATS returned %u addresses\n", results); | ||
65 | ret = 0; | 66 | ret = 0; |
66 | } | 67 | } |
67 | 68 | ||
@@ -76,7 +77,7 @@ void testservice_task (void *cls, | |||
76 | return; | 77 | return; |
77 | } | 78 | } |
78 | 79 | ||
79 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); | 80 | ph = GNUNET_ATS_performance_init (cfg, ats_perf_cb, NULL); |
80 | if (NULL == ph) | 81 | if (NULL == ph) |
81 | fprintf (stderr, "Cannot connect to ATS service, exiting...\n"); | 82 | fprintf (stderr, "Cannot connect to ATS service, exiting...\n"); |
82 | 83 | ||
@@ -97,7 +98,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
97 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 98 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
98 | { | 99 | { |
99 | GNUNET_CLIENT_service_test ("ats", cfg, | 100 | GNUNET_CLIENT_service_test ("ats", cfg, |
100 | GNUNET_TIME_UNIT_SECONDS, | 101 | GNUNET_TIME_UNIT_MINUTES, |
101 | &testservice_task, | 102 | &testservice_task, |
102 | (void *) cfg); | 103 | (void *) cfg); |
103 | } | 104 | } |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 22afbebb9..bee833be7 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -83,7 +83,7 @@ send_bw_notification (struct ATS_Address *aa) | |||
83 | aa->assigned_bw_out, | 83 | aa->assigned_bw_out, |
84 | aa->assigned_bw_in); | 84 | aa->assigned_bw_in); |
85 | GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in); | 85 | GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in); |
86 | GAS_performance_notify_clients (&aa->peer, aa->plugin, aa->addr, aa->addr_len, | 86 | GAS_performance_notify_all_clients (&aa->peer, aa->plugin, aa->addr, aa->addr_len, |
87 | aa->ats, aa->ats_count, aa->assigned_bw_out, | 87 | aa->ats, aa->ats_count, aa->assigned_bw_out, |
88 | aa->assigned_bw_in); | 88 | aa->assigned_bw_in); |
89 | } | 89 | } |
@@ -1072,7 +1072,7 @@ peer_it (void *cls, | |||
1072 | { | 1072 | { |
1073 | GNUNET_CONTAINER_multihashmap_put(ip_ctx->peers_returned, key, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 1073 | GNUNET_CONTAINER_multihashmap_put(ip_ctx->peers_returned, key, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
1074 | tmp.hashPubKey = (*key); | 1074 | tmp.hashPubKey = (*key); |
1075 | ip_ctx->it (ip_ctx, &tmp); | 1075 | ip_ctx->it (ip_ctx->it_cls, &tmp); |
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | return GNUNET_OK; | 1078 | return GNUNET_OK; |
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index 5bc4b9fe2..932e7184b 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c | |||
@@ -93,65 +93,6 @@ find_client (struct GNUNET_SERVER_Client *client) | |||
93 | return NULL; | 93 | return NULL; |
94 | } | 94 | } |
95 | 95 | ||
96 | static void | ||
97 | peerinfo_it (void *cls, | ||
98 | const struct GNUNET_PeerIdentity *id, | ||
99 | const char *plugin_name, | ||
100 | const void *plugin_addr, size_t plugin_addr_len, | ||
101 | const struct GNUNET_ATS_Information *atsi, | ||
102 | uint32_t atsi_count, | ||
103 | struct GNUNET_BANDWIDTH_Value32NBO | ||
104 | bandwidth_out, | ||
105 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
106 | { | ||
107 | struct PerformanceClient *pc = cls; | ||
108 | GNUNET_assert (NULL != pc); | ||
109 | if (NULL != id) | ||
110 | { | ||
111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s' plugin `%s' BW out %llu, BW in %llu \n", | ||
112 | GNUNET_i2s (id), | ||
113 | plugin_name, ntohl (bandwidth_out.value__), ntohl (bandwidth_in.value__)); | ||
114 | /* TODO: Notify client here! */ | ||
115 | } | ||
116 | |||
117 | } | ||
118 | |||
119 | static void | ||
120 | peer_it (void *cls, | ||
121 | const struct GNUNET_PeerIdentity *id) | ||
122 | { | ||
123 | if (NULL != id) | ||
124 | { | ||
125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s'\n", GNUNET_i2s (id)); | ||
126 | GAS_addresses_get_peer_info (id, &peerinfo_it, cls); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * Register a new performance client. | ||
132 | * | ||
133 | * @param client handle of the new client | ||
134 | * @param flag flag specifying the type of the client | ||
135 | */ | ||
136 | void | ||
137 | GAS_performance_add_client (struct GNUNET_SERVER_Client *client, | ||
138 | enum StartFlag flag) | ||
139 | { | ||
140 | struct PerformanceClient *pc; | ||
141 | |||
142 | GNUNET_break (NULL == find_client (client)); | ||
143 | pc = GNUNET_malloc (sizeof (struct PerformanceClient)); | ||
144 | pc->client = client; | ||
145 | pc->flag = flag; | ||
146 | GNUNET_SERVER_notification_context_add (nc, client); | ||
147 | GNUNET_SERVER_client_keep (client); | ||
148 | GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc); | ||
149 | |||
150 | /* Send information about clients */ | ||
151 | GAS_addresses_iterate_peers (&peer_it, pc); | ||
152 | } | ||
153 | |||
154 | |||
155 | /** | 96 | /** |
156 | * Unregister a client (which may have been a performance client, | 97 | * Unregister a client (which may have been a performance client, |
157 | * but this is not assured). | 98 | * but this is not assured). |
@@ -162,7 +103,6 @@ void | |||
162 | GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) | 103 | GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) |
163 | { | 104 | { |
164 | struct PerformanceClient *pc; | 105 | struct PerformanceClient *pc; |
165 | |||
166 | pc = find_client (client); | 106 | pc = find_client (client); |
167 | if (NULL == pc) | 107 | if (NULL == pc) |
168 | return; | 108 | return; |
@@ -171,11 +111,11 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) | |||
171 | GNUNET_free (pc); | 111 | GNUNET_free (pc); |
172 | } | 112 | } |
173 | 113 | ||
174 | |||
175 | /** | 114 | /** |
176 | * Transmit the given performance information to all performance | 115 | * Transmit the given performance information to all performance |
177 | * clients. | 116 | * clients. |
178 | * | 117 | * |
118 | * @param pc performance client to send to | ||
179 | * @param peer peer for which this is an address suggestion | 119 | * @param peer peer for which this is an address suggestion |
180 | * @param plugin_name 0-termintated string specifying the transport plugin | 120 | * @param plugin_name 0-termintated string specifying the transport plugin |
181 | * @param plugin_addr binary address for the plugin to use | 121 | * @param plugin_addr binary address for the plugin to use |
@@ -186,16 +126,17 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) | |||
186 | * @param bandwidth_in assigned inbound bandwidth | 126 | * @param bandwidth_in assigned inbound bandwidth |
187 | */ | 127 | */ |
188 | void | 128 | void |
189 | GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, | 129 | GAS_performance_notify_client (struct PerformanceClient *pc, |
190 | const char *plugin_name, | 130 | const struct GNUNET_PeerIdentity *peer, |
191 | const void *plugin_addr, size_t plugin_addr_len, | 131 | const char *plugin_name, |
192 | const struct GNUNET_ATS_Information *atsi, | 132 | const void *plugin_addr, size_t plugin_addr_len, |
193 | uint32_t atsi_count, | 133 | const struct GNUNET_ATS_Information *atsi, |
194 | struct GNUNET_BANDWIDTH_Value32NBO | 134 | uint32_t atsi_count, |
195 | bandwidth_out, | 135 | struct GNUNET_BANDWIDTH_Value32NBO |
196 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 136 | bandwidth_out, |
137 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
197 | { | 138 | { |
198 | struct PerformanceClient *pc; | 139 | |
199 | struct PeerInformationMessage *msg; | 140 | struct PeerInformationMessage *msg; |
200 | size_t plugin_name_length = strlen (plugin_name) + 1; | 141 | size_t plugin_name_length = strlen (plugin_name) + 1; |
201 | size_t msize = | 142 | size_t msize = |
@@ -206,6 +147,10 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, | |||
206 | struct GNUNET_ATS_Information *atsp; | 147 | struct GNUNET_ATS_Information *atsp; |
207 | char *addrp; | 148 | char *addrp; |
208 | 149 | ||
150 | GNUNET_assert (NULL != pc); | ||
151 | if (NULL == find_client (pc->client)) | ||
152 | return; /* Client disconnected */ | ||
153 | |||
209 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 154 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); |
210 | GNUNET_assert (atsi_count < | 155 | GNUNET_assert (atsi_count < |
211 | GNUNET_SERVER_MAX_MESSAGE_SIZE / | 156 | GNUNET_SERVER_MAX_MESSAGE_SIZE / |
@@ -224,17 +169,113 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, | |||
224 | addrp = (char *) &atsp[atsi_count]; | 169 | addrp = (char *) &atsp[atsi_count]; |
225 | memcpy (addrp, plugin_addr, plugin_addr_len); | 170 | memcpy (addrp, plugin_addr, plugin_addr_len); |
226 | strcpy (&addrp[plugin_addr_len], plugin_name); | 171 | strcpy (&addrp[plugin_addr_len], plugin_name); |
172 | GNUNET_SERVER_notification_context_unicast (nc, pc->client, &msg->header, | ||
173 | GNUNET_YES); | ||
174 | } | ||
175 | |||
176 | |||
177 | /** | ||
178 | * Transmit the given performance information to all performance | ||
179 | * clients. | ||
180 | * | ||
181 | * @param peer peer for which this is an address suggestion | ||
182 | * @param plugin_name 0-termintated string specifying the transport plugin | ||
183 | * @param plugin_addr binary address for the plugin to use | ||
184 | * @param plugin_addr_len number of bytes in plugin_addr | ||
185 | * @param atsi performance data for the address | ||
186 | * @param atsi_count number of performance records in 'ats' | ||
187 | * @param bandwidth_out assigned outbound bandwidth | ||
188 | * @param bandwidth_in assigned inbound bandwidth | ||
189 | */ | ||
190 | void | ||
191 | GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, | ||
192 | const char *plugin_name, | ||
193 | const void *plugin_addr, size_t plugin_addr_len, | ||
194 | const struct GNUNET_ATS_Information *atsi, | ||
195 | uint32_t atsi_count, | ||
196 | struct GNUNET_BANDWIDTH_Value32NBO | ||
197 | bandwidth_out, | ||
198 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
199 | { | ||
200 | struct PerformanceClient *pc; | ||
201 | |||
227 | for (pc = pc_head; pc != NULL; pc = pc->next) | 202 | for (pc = pc_head; pc != NULL; pc = pc->next) |
228 | if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC) | 203 | if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC) |
229 | { | 204 | { |
230 | GNUNET_SERVER_notification_context_unicast (nc, pc->client, &msg->header, | 205 | GAS_performance_notify_client (pc, |
231 | GNUNET_YES); | 206 | peer, |
232 | GNUNET_STATISTICS_update (GSA_stats, | 207 | plugin_name, plugin_addr, plugin_addr_len, |
233 | "# performance updates given to clients", 1, | 208 | atsi, atsi_count, |
234 | GNUNET_NO); | 209 | bandwidth_out, bandwidth_in); |
235 | } | 210 | } |
211 | |||
212 | GNUNET_STATISTICS_update (GSA_stats, | ||
213 | "# performance updates given to clients", 1, | ||
214 | GNUNET_NO); | ||
236 | } | 215 | } |
237 | 216 | ||
217 | static void | ||
218 | peerinfo_it (void *cls, | ||
219 | const struct GNUNET_PeerIdentity *id, | ||
220 | const char *plugin_name, | ||
221 | const void *plugin_addr, size_t plugin_addr_len, | ||
222 | const struct GNUNET_ATS_Information *atsi, | ||
223 | uint32_t atsi_count, | ||
224 | struct GNUNET_BANDWIDTH_Value32NBO | ||
225 | bandwidth_out, | ||
226 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
227 | { | ||
228 | GNUNET_assert (NULL != cls); | ||
229 | if (NULL != id) | ||
230 | { | ||
231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s' plugin `%s' BW out %llu, BW in %llu \n", | ||
232 | GNUNET_i2s (id), | ||
233 | plugin_name, ntohl (bandwidth_out.value__), ntohl (bandwidth_in.value__)); | ||
234 | GAS_performance_notify_client(cls, | ||
235 | id, | ||
236 | plugin_name, plugin_addr, plugin_addr_len, | ||
237 | atsi, atsi_count, | ||
238 | bandwidth_out, bandwidth_in); | ||
239 | } | ||
240 | |||
241 | } | ||
242 | |||
243 | static void | ||
244 | peer_it (void *cls, | ||
245 | const struct GNUNET_PeerIdentity *id) | ||
246 | { | ||
247 | if (NULL != id) | ||
248 | { | ||
249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s'\n", GNUNET_i2s (id)); | ||
250 | GAS_addresses_get_peer_info (id, &peerinfo_it, cls); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * Register a new performance client. | ||
256 | * | ||
257 | * @param client handle of the new client | ||
258 | * @param flag flag specifying the type of the client | ||
259 | */ | ||
260 | void | ||
261 | GAS_performance_add_client (struct GNUNET_SERVER_Client *client, | ||
262 | enum StartFlag flag) | ||
263 | { | ||
264 | struct PerformanceClient *pc; | ||
265 | |||
266 | GNUNET_break (NULL == find_client (client)); | ||
267 | pc = GNUNET_malloc (sizeof (struct PerformanceClient)); | ||
268 | pc->client = client; | ||
269 | pc->flag = flag; | ||
270 | GNUNET_SERVER_notification_context_add (nc, client); | ||
271 | GNUNET_SERVER_client_keep (client); | ||
272 | GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc); | ||
273 | |||
274 | /* Send information about clients */ | ||
275 | GAS_addresses_iterate_peers (&peer_it, pc); | ||
276 | } | ||
277 | |||
278 | |||
238 | 279 | ||
239 | /** | 280 | /** |
240 | * Handle 'reservation request' messages from clients. | 281 | * Handle 'reservation request' messages from clients. |
diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h index 75d555a6c..35b7ad3ea 100644 --- a/src/ats/gnunet-service-ats_performance.h +++ b/src/ats/gnunet-service-ats_performance.h | |||
@@ -66,7 +66,7 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client); | |||
66 | * @param bandwidth_in assigned inbound bandwidth | 66 | * @param bandwidth_in assigned inbound bandwidth |
67 | */ | 67 | */ |
68 | void | 68 | void |
69 | GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, | 69 | GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, |
70 | const char *plugin_name, | 70 | const char *plugin_name, |
71 | const void *plugin_addr, size_t plugin_addr_len, | 71 | const void *plugin_addr, size_t plugin_addr_len, |
72 | const struct GNUNET_ATS_Information *atsi, | 72 | const struct GNUNET_ATS_Information *atsi, |