diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-03 14:11:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-03 14:11:03 +0000 |
commit | b2e99dd91c01b5fcc16b3b1031df897aeec05eef (patch) | |
tree | 31caea8a19fd943f8a9f7f7f3c19e52e11d95a77 | |
parent | 55cecdea8638fa23c68e7ade7a8d5629da658f9e (diff) | |
download | gnunet-b2e99dd91c01b5fcc16b3b1031df897aeec05eef.tar.gz gnunet-b2e99dd91c01b5fcc16b3b1031df897aeec05eef.zip |
separate ATS connectivity suggestions from ATS scheduling API
21 files changed, 729 insertions, 303 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index a165cebb7..27dd80a0d 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -51,6 +51,7 @@ gnunet_ats_solver_eval_LDADD = \ | |||
51 | $(LTLIBINTL) | 51 | $(LTLIBINTL) |
52 | 52 | ||
53 | libgnunetats_la_SOURCES = \ | 53 | libgnunetats_la_SOURCES = \ |
54 | ats_api_connectivity.c \ | ||
54 | ats_api_scheduling.c \ | 55 | ats_api_scheduling.c \ |
55 | ats_api_performance.c | 56 | ats_api_performance.c |
56 | libgnunetats_la_LIBADD = \ | 57 | libgnunetats_la_LIBADD = \ |
@@ -99,6 +100,7 @@ libexec_PROGRAMS = \ | |||
99 | gnunet_service_ats_SOURCES = \ | 100 | gnunet_service_ats_SOURCES = \ |
100 | gnunet-service-ats.c gnunet-service-ats.h\ | 101 | gnunet-service-ats.c gnunet-service-ats.h\ |
101 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ | 102 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ |
103 | gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ | ||
102 | gnunet-service-ats_normalization.c gnunet-service-ats_normalization.h \ | 104 | gnunet-service-ats_normalization.c gnunet-service-ats_normalization.h \ |
103 | gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ | 105 | gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ |
104 | gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ | 106 | gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ |
diff --git a/src/ats/ats.h b/src/ats/ats.h index b6750da10..482b7b4b3 100644 --- a/src/ats/ats.h +++ b/src/ats/ats.h | |||
@@ -50,7 +50,12 @@ enum StartFlag | |||
50 | * Performance monitoring client that does NOT want to learn | 50 | * Performance monitoring client that does NOT want to learn |
51 | * about changes in performance characteristics. | 51 | * about changes in performance characteristics. |
52 | */ | 52 | */ |
53 | START_FLAG_PERFORMANCE_NO_PIC = 2 | 53 | START_FLAG_PERFORMANCE_NO_PIC = 2, |
54 | |||
55 | /** | ||
56 | * Connection suggestion handle. | ||
57 | */ | ||
58 | START_FLAG_CONNECTION_SUGGESTION = 3 | ||
54 | }; | 59 | }; |
55 | 60 | ||
56 | 61 | ||
diff --git a/src/ats/ats_api_connectivity.c b/src/ats/ats_api_connectivity.c new file mode 100644 index 000000000..9198118a4 --- /dev/null +++ b/src/ats/ats_api_connectivity.c | |||
@@ -0,0 +1,356 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010-2015 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file ats/ats_api_connectivity.c | ||
22 | * @brief enable clients to ask ATS about establishing connections to peers | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "ats.h" | ||
29 | |||
30 | |||
31 | /** | ||
32 | * Handle for ATS address suggestion requests. | ||
33 | */ | ||
34 | struct GNUNET_ATS_ConnectivitySuggestHandle | ||
35 | { | ||
36 | /** | ||
37 | * ID of the peer for which address suggestion was requested. | ||
38 | */ | ||
39 | struct GNUNET_PeerIdentity id; | ||
40 | |||
41 | /** | ||
42 | * Connecitivity handle this suggestion handle belongs to. | ||
43 | */ | ||
44 | struct GNUNET_ATS_ConnectivityHandle *ch; | ||
45 | }; | ||
46 | |||
47 | |||
48 | /** | ||
49 | * Handle to the ATS subsystem for connectivity management. | ||
50 | */ | ||
51 | struct GNUNET_ATS_ConnectivityHandle | ||
52 | { | ||
53 | |||
54 | /** | ||
55 | * Our configuration. | ||
56 | */ | ||
57 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
58 | |||
59 | /** | ||
60 | * Map with the identities of all the peers for which we would | ||
61 | * like to have address suggestions. The key is the PID, the | ||
62 | * value is currently the `struct GNUNET_ATS_ConnectivitySuggestHandle` | ||
63 | */ | ||
64 | struct GNUNET_CONTAINER_MultiPeerMap *sug_requests; | ||
65 | |||
66 | /** | ||
67 | * Connection to ATS service. | ||
68 | */ | ||
69 | struct GNUNET_CLIENT_Connection *client; | ||
70 | |||
71 | /** | ||
72 | * Message queue for sending requests to the ATS service. | ||
73 | */ | ||
74 | struct GNUNET_MQ_Handle *mq; | ||
75 | |||
76 | /** | ||
77 | * Task to trigger reconnect. | ||
78 | */ | ||
79 | struct GNUNET_SCHEDULER_Task *task; | ||
80 | |||
81 | }; | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Re-establish the connection to the ATS service. | ||
86 | * | ||
87 | * @param ch handle to use to re-connect. | ||
88 | */ | ||
89 | static void | ||
90 | reconnect (struct GNUNET_ATS_ConnectivityHandle *ch); | ||
91 | |||
92 | |||
93 | /** | ||
94 | * Re-establish the connection to the ATS service. | ||
95 | * | ||
96 | * @param cls handle to use to re-connect. | ||
97 | * @param tc scheduler context | ||
98 | */ | ||
99 | static void | ||
100 | reconnect_task (void *cls, | ||
101 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
102 | { | ||
103 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; | ||
104 | |||
105 | ch->task = NULL; | ||
106 | reconnect (ch); | ||
107 | } | ||
108 | |||
109 | |||
110 | /** | ||
111 | * Disconnect from ATS and then reconnect. | ||
112 | * | ||
113 | * @param ch our handle | ||
114 | */ | ||
115 | static void | ||
116 | force_reconnect (struct GNUNET_ATS_ConnectivityHandle *ch) | ||
117 | { | ||
118 | if (NULL != ch->mq) | ||
119 | { | ||
120 | GNUNET_MQ_destroy (ch->mq); | ||
121 | ch->mq = NULL; | ||
122 | } | ||
123 | if (NULL != ch->client) | ||
124 | { | ||
125 | GNUNET_CLIENT_disconnect (ch->client); | ||
126 | ch->client = NULL; | ||
127 | } | ||
128 | ch->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
129 | &reconnect_task, | ||
130 | ch); | ||
131 | } | ||
132 | |||
133 | |||
134 | /** | ||
135 | * We encountered an error handling the MQ to the | ||
136 | * ATS service. Reconnect. | ||
137 | * | ||
138 | * @param cls the `struct GNUNET_ATS_ConnectivityHandle` | ||
139 | * @param error details about the error | ||
140 | */ | ||
141 | static void | ||
142 | error_handler (void *cls, | ||
143 | enum GNUNET_MQ_Error error) | ||
144 | { | ||
145 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; | ||
146 | |||
147 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
148 | "ATS connection died (code %d), reconnecting\n", | ||
149 | (int) error); | ||
150 | force_reconnect (ch); | ||
151 | } | ||
152 | |||
153 | |||
154 | /** | ||
155 | * Transmit request for an address suggestion. | ||
156 | * | ||
157 | * @param cls the `struct GNUNET_ATS_ConnectivityHandle` | ||
158 | * @param peer peer to ask for an address suggestion for | ||
159 | * @param value the `struct GNUNET_ATS_SuggestHandle` | ||
160 | * @return #GNUNET_OK (continue to iterate), #GNUNET_SYSERR on | ||
161 | * failure (message queue no longer exists) | ||
162 | */ | ||
163 | static int | ||
164 | transmit_suggestion (void *cls, | ||
165 | const struct GNUNET_PeerIdentity *peer, | ||
166 | void *value) | ||
167 | { | ||
168 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; | ||
169 | struct GNUNET_MQ_Envelope *ev; | ||
170 | struct RequestAddressMessage *m; | ||
171 | |||
172 | if (NULL == ch->mq) | ||
173 | return GNUNET_SYSERR; | ||
174 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); | ||
175 | m->reserved = htonl (0); | ||
176 | m->peer = *peer; | ||
177 | GNUNET_MQ_send (ch->mq, ev); | ||
178 | return GNUNET_OK; | ||
179 | } | ||
180 | |||
181 | |||
182 | /** | ||
183 | * Re-establish the connection to the ATS service. | ||
184 | * | ||
185 | * @param ch handle to use to re-connect. | ||
186 | */ | ||
187 | static void | ||
188 | reconnect (struct GNUNET_ATS_ConnectivityHandle *ch) | ||
189 | { | ||
190 | static const struct GNUNET_MQ_MessageHandler handlers[] = | ||
191 | { { NULL, 0, 0 } }; | ||
192 | struct GNUNET_MQ_Envelope *ev; | ||
193 | struct ClientStartMessage *init; | ||
194 | |||
195 | GNUNET_assert (NULL == ch->client); | ||
196 | ch->client = GNUNET_CLIENT_connect ("ats", ch->cfg); | ||
197 | if (NULL == ch->client) | ||
198 | { | ||
199 | force_reconnect (ch); | ||
200 | return; | ||
201 | } | ||
202 | ch->mq = GNUNET_MQ_queue_for_connection_client (ch->client, | ||
203 | handlers, | ||
204 | &error_handler, | ||
205 | ch); | ||
206 | ev = GNUNET_MQ_msg (init, | ||
207 | GNUNET_MESSAGE_TYPE_ATS_START); | ||
208 | init->start_flag = htonl (START_FLAG_CONNECTION_SUGGESTION); | ||
209 | GNUNET_MQ_send (ch->mq, ev); | ||
210 | if (NULL == ch->mq) | ||
211 | return; | ||
212 | GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, | ||
213 | &transmit_suggestion, | ||
214 | ch); | ||
215 | } | ||
216 | |||
217 | |||
218 | /** | ||
219 | * Initialize the ATS connectivity suggestion client handle. | ||
220 | * | ||
221 | * @param cfg configuration to use | ||
222 | * @return ats connectivity handle, NULL on error | ||
223 | */ | ||
224 | struct GNUNET_ATS_ConnectivityHandle * | ||
225 | GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
226 | { | ||
227 | struct GNUNET_ATS_ConnectivityHandle *ch; | ||
228 | |||
229 | ch = GNUNET_new (struct GNUNET_ATS_ConnectivityHandle); | ||
230 | ch->cfg = cfg; | ||
231 | ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32, | ||
232 | GNUNET_YES); | ||
233 | reconnect (ch); | ||
234 | return ch; | ||
235 | } | ||
236 | |||
237 | |||
238 | /** | ||
239 | * Function called to free all `struct GNUNET_ATS_SuggestHandles` | ||
240 | * in the map. | ||
241 | * | ||
242 | * @param cls NULL | ||
243 | * @param key the key | ||
244 | * @param value the value to free | ||
245 | * @return #GNUNET_OK (continue to iterate) | ||
246 | */ | ||
247 | static int | ||
248 | free_sug_handle (void *cls, | ||
249 | const struct GNUNET_PeerIdentity *key, | ||
250 | void *value) | ||
251 | { | ||
252 | struct GNUNET_ATS_ConnectivitySuggestHandle *cur = value; | ||
253 | |||
254 | GNUNET_free (cur); | ||
255 | return GNUNET_OK; | ||
256 | } | ||
257 | |||
258 | |||
259 | /** | ||
260 | * Client is done with ATS connectivity management, release resources. | ||
261 | * | ||
262 | * @param ch handle to release | ||
263 | */ | ||
264 | void | ||
265 | GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch) | ||
266 | { | ||
267 | if (NULL != ch->mq) | ||
268 | { | ||
269 | GNUNET_MQ_destroy (ch->mq); | ||
270 | ch->mq = NULL; | ||
271 | } | ||
272 | if (NULL != ch->client) | ||
273 | { | ||
274 | GNUNET_CLIENT_disconnect (ch->client); | ||
275 | ch->client = NULL; | ||
276 | } | ||
277 | if (NULL != ch->task) | ||
278 | { | ||
279 | GNUNET_SCHEDULER_cancel (ch->task); | ||
280 | ch->task = NULL; | ||
281 | } | ||
282 | GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, | ||
283 | &free_sug_handle, | ||
284 | NULL); | ||
285 | GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests); | ||
286 | GNUNET_free (ch); | ||
287 | } | ||
288 | |||
289 | |||
290 | /** | ||
291 | * We would like to receive address suggestions for a peer. ATS will | ||
292 | * respond with a call to the continuation immediately containing an address or | ||
293 | * no address if none is available. ATS can suggest more addresses until we call | ||
294 | * #GNUNET_ATS_connectivity_suggest_cancel(). | ||
295 | * | ||
296 | * @param ch handle | ||
297 | * @param peer identity of the peer we need an address for | ||
298 | * @return suggest handle, NULL if a request is already pending | ||
299 | */ | ||
300 | struct GNUNET_ATS_ConnectivitySuggestHandle * | ||
301 | GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch, | ||
302 | const struct GNUNET_PeerIdentity *peer) | ||
303 | { | ||
304 | struct GNUNET_ATS_ConnectivitySuggestHandle *s; | ||
305 | |||
306 | s = GNUNET_new (struct GNUNET_ATS_ConnectivitySuggestHandle); | ||
307 | s->ch = ch; | ||
308 | s->id = *peer; | ||
309 | if (GNUNET_OK != | ||
310 | GNUNET_CONTAINER_multipeermap_put (ch->sug_requests, | ||
311 | &s->id, | ||
312 | s, | ||
313 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
314 | { | ||
315 | GNUNET_break (0); | ||
316 | return NULL; | ||
317 | } | ||
318 | if (NULL == ch->mq) | ||
319 | return s; | ||
320 | (void) transmit_suggestion (ch, | ||
321 | &s->id, | ||
322 | s); | ||
323 | return s; | ||
324 | } | ||
325 | |||
326 | |||
327 | /** | ||
328 | * We no longer care about being connected to a peer. | ||
329 | * | ||
330 | * @param sh handle to stop | ||
331 | */ | ||
332 | void | ||
333 | GNUNET_ATS_connectivity_suggest_cancel (struct GNUNET_ATS_ConnectivitySuggestHandle *sh) | ||
334 | { | ||
335 | struct GNUNET_ATS_ConnectivityHandle *ch = sh->ch; | ||
336 | struct GNUNET_MQ_Envelope *ev; | ||
337 | struct RequestAddressMessage *m; | ||
338 | |||
339 | GNUNET_assert (GNUNET_OK == | ||
340 | GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, | ||
341 | &sh->id, | ||
342 | sh)); | ||
343 | if (NULL == ch->mq) | ||
344 | { | ||
345 | GNUNET_free (sh); | ||
346 | return; | ||
347 | } | ||
348 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL); | ||
349 | m->reserved = htonl (0); | ||
350 | m->peer = sh->id; | ||
351 | GNUNET_MQ_send (ch->mq, ev); | ||
352 | GNUNET_free (sh); | ||
353 | } | ||
354 | |||
355 | |||
356 | /* end of ats_api_connectivity.c */ | ||
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index 21fb583de..2daa45a73 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c | |||
@@ -146,18 +146,6 @@ struct ATS_Network | |||
146 | 146 | ||
147 | 147 | ||
148 | /** | 148 | /** |
149 | * Handle for ATS address suggestion requests. | ||
150 | */ | ||
151 | struct GNUNET_ATS_SuggestHandle | ||
152 | { | ||
153 | /** | ||
154 | * ID of the peer for which address suggestion was requested. | ||
155 | */ | ||
156 | struct GNUNET_PeerIdentity id; | ||
157 | }; | ||
158 | |||
159 | |||
160 | /** | ||
161 | * Handle to the ATS subsystem for bandwidth/transport scheduling information. | 149 | * Handle to the ATS subsystem for bandwidth/transport scheduling information. |
162 | */ | 150 | */ |
163 | struct GNUNET_ATS_SchedulingHandle | 151 | struct GNUNET_ATS_SchedulingHandle |
@@ -179,13 +167,6 @@ struct GNUNET_ATS_SchedulingHandle | |||
179 | void *suggest_cb_cls; | 167 | void *suggest_cb_cls; |
180 | 168 | ||
181 | /** | 169 | /** |
182 | * Map with the identities of all the peers for which we would | ||
183 | * like to have address suggestions. The key is the PID, the | ||
184 | * value is currently the `struct GNUNET_ATS_SuggestHandle` | ||
185 | */ | ||
186 | struct GNUNET_CONTAINER_MultiPeerMap *sug_requests; | ||
187 | |||
188 | /** | ||
189 | * Connection to ATS service. | 170 | * Connection to ATS service. |
190 | */ | 171 | */ |
191 | struct GNUNET_CLIENT_Connection *client; | 172 | struct GNUNET_CLIENT_Connection *client; |
@@ -588,34 +569,6 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, | |||
588 | 569 | ||
589 | 570 | ||
590 | /** | 571 | /** |
591 | * Transmit request for an address suggestion. | ||
592 | * | ||
593 | * @param cls the `struct GNUNET_ATS_SchedulingHandle` | ||
594 | * @param peer peer to ask for an address suggestion for | ||
595 | * @param value the `struct GNUNET_ATS_SuggestHandle` | ||
596 | * @return #GNUNET_OK (continue to iterate), #GNUNET_SYSERR on | ||
597 | * failure (message queue no longer exists) | ||
598 | */ | ||
599 | static int | ||
600 | transmit_suggestion (void *cls, | ||
601 | const struct GNUNET_PeerIdentity *peer, | ||
602 | void *value) | ||
603 | { | ||
604 | struct GNUNET_ATS_SchedulingHandle *sh = cls; | ||
605 | struct GNUNET_MQ_Envelope *ev; | ||
606 | struct RequestAddressMessage *m; | ||
607 | |||
608 | if (NULL == sh->mq) | ||
609 | return GNUNET_SYSERR; | ||
610 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); | ||
611 | m->reserved = htonl (0); | ||
612 | m->peer = *peer; | ||
613 | GNUNET_MQ_send (sh->mq, ev); | ||
614 | return GNUNET_OK; | ||
615 | } | ||
616 | |||
617 | |||
618 | /** | ||
619 | * Generate and transmit the `struct AddressUseMessage` for the given | 572 | * Generate and transmit the `struct AddressUseMessage` for the given |
620 | * address record. | 573 | * address record. |
621 | * | 574 | * |
@@ -687,9 +640,6 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | |||
687 | if (NULL == sh->mq) | 640 | if (NULL == sh->mq) |
688 | return; | 641 | return; |
689 | } | 642 | } |
690 | GNUNET_CONTAINER_multipeermap_iterate (sh->sug_requests, | ||
691 | &transmit_suggestion, | ||
692 | sh); | ||
693 | } | 643 | } |
694 | 644 | ||
695 | 645 | ||
@@ -1034,8 +984,6 @@ GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1034 | GNUNET_array_grow (sh->session_array, | 984 | GNUNET_array_grow (sh->session_array, |
1035 | sh->session_array_size, | 985 | sh->session_array_size, |
1036 | 4); | 986 | 4); |
1037 | sh->sug_requests = GNUNET_CONTAINER_multipeermap_create (32, | ||
1038 | GNUNET_YES); | ||
1039 | GNUNET_OS_network_interfaces_list (&interface_proc, | 987 | GNUNET_OS_network_interfaces_list (&interface_proc, |
1040 | sh); | 988 | sh); |
1041 | sh->interface_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_PROCESSING_INTERVAL, | 989 | sh->interface_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_PROCESSING_INTERVAL, |
@@ -1047,27 +995,6 @@ GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1047 | 995 | ||
1048 | 996 | ||
1049 | /** | 997 | /** |
1050 | * Function called to free all `struct GNUNET_ATS_SuggestHandles` | ||
1051 | * in the map. | ||
1052 | * | ||
1053 | * @param cls NULL | ||
1054 | * @param key the key | ||
1055 | * @param value the value to free | ||
1056 | * @return #GNUNET_OK (continue to iterate) | ||
1057 | */ | ||
1058 | static int | ||
1059 | free_sug_handle (void *cls, | ||
1060 | const struct GNUNET_PeerIdentity *key, | ||
1061 | void *value) | ||
1062 | { | ||
1063 | struct GNUNET_ATS_SuggestHandle *cur = value; | ||
1064 | |||
1065 | GNUNET_free (cur); | ||
1066 | return GNUNET_OK; | ||
1067 | } | ||
1068 | |||
1069 | |||
1070 | /** | ||
1071 | * Client is done with ATS scheduling, release resources. | 998 | * Client is done with ATS scheduling, release resources. |
1072 | * | 999 | * |
1073 | * @param sh handle to release | 1000 | * @param sh handle to release |
@@ -1090,10 +1017,6 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh) | |||
1090 | GNUNET_SCHEDULER_cancel (sh->task); | 1017 | GNUNET_SCHEDULER_cancel (sh->task); |
1091 | sh->task = NULL; | 1018 | sh->task = NULL; |
1092 | } | 1019 | } |
1093 | GNUNET_CONTAINER_multipeermap_iterate (sh->sug_requests, | ||
1094 | &free_sug_handle, | ||
1095 | NULL); | ||
1096 | GNUNET_CONTAINER_multipeermap_destroy (sh->sug_requests); | ||
1097 | if (NULL != sh->interface_task) | 1020 | if (NULL != sh->interface_task) |
1098 | { | 1021 | { |
1099 | GNUNET_SCHEDULER_cancel (sh->interface_task); | 1022 | GNUNET_SCHEDULER_cancel (sh->interface_task); |
@@ -1129,77 +1052,6 @@ GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1129 | 1052 | ||
1130 | 1053 | ||
1131 | /** | 1054 | /** |
1132 | * We would like to receive address suggestions for a peer. ATS will | ||
1133 | * respond with a call to the continuation immediately containing an address or | ||
1134 | * no address if none is available. ATS can suggest more addresses until we call | ||
1135 | * #GNUNET_ATS_suggest_address_cancel(). | ||
1136 | * | ||
1137 | * @param sh handle | ||
1138 | * @param peer identity of the peer we need an address for | ||
1139 | * @return suggest handle, NULL if a request is already pending | ||
1140 | */ | ||
1141 | struct GNUNET_ATS_SuggestHandle * | ||
1142 | GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, | ||
1143 | const struct GNUNET_PeerIdentity *peer) | ||
1144 | { | ||
1145 | struct GNUNET_ATS_SuggestHandle *s; | ||
1146 | |||
1147 | s = GNUNET_new (struct GNUNET_ATS_SuggestHandle); | ||
1148 | s->id = *peer; | ||
1149 | if (GNUNET_OK != | ||
1150 | GNUNET_CONTAINER_multipeermap_put (sh->sug_requests, | ||
1151 | &s->id, | ||
1152 | s, | ||
1153 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1154 | { | ||
1155 | GNUNET_break (0); | ||
1156 | return NULL; | ||
1157 | } | ||
1158 | if (NULL == sh->mq) | ||
1159 | return s; | ||
1160 | (void) transmit_suggestion (sh, | ||
1161 | &s->id, | ||
1162 | s); | ||
1163 | return s; | ||
1164 | } | ||
1165 | |||
1166 | |||
1167 | /** | ||
1168 | * We would like to stop receiving address updates for this peer | ||
1169 | * | ||
1170 | * @param sh handle | ||
1171 | * @param peer identity of the peer | ||
1172 | */ | ||
1173 | void | ||
1174 | GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh, | ||
1175 | const struct GNUNET_PeerIdentity *peer) | ||
1176 | { | ||
1177 | struct GNUNET_MQ_Envelope *ev; | ||
1178 | struct RequestAddressMessage *m; | ||
1179 | struct GNUNET_ATS_SuggestHandle *s; | ||
1180 | |||
1181 | s = GNUNET_CONTAINER_multipeermap_get (sh->sug_requests, | ||
1182 | peer); | ||
1183 | if (NULL == s) | ||
1184 | { | ||
1185 | GNUNET_break (0); | ||
1186 | return; | ||
1187 | } | ||
1188 | GNUNET_assert (GNUNET_OK == | ||
1189 | GNUNET_CONTAINER_multipeermap_remove (sh->sug_requests, | ||
1190 | &s->id, | ||
1191 | s)); | ||
1192 | GNUNET_free (s); | ||
1193 | if (NULL == sh->mq) | ||
1194 | return; | ||
1195 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL); | ||
1196 | m->reserved = htonl (0); | ||
1197 | m->peer = *peer; | ||
1198 | GNUNET_MQ_send (sh->mq, ev); | ||
1199 | } | ||
1200 | |||
1201 | |||
1202 | /** | ||
1203 | * Test if a address and a session is known to ATS | 1055 | * Test if a address and a session is known to ATS |
1204 | * | 1056 | * |
1205 | * @param sh the scheduling handle | 1057 | * @param sh the scheduling handle |
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index edc3b51af..83fa42b35 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet-service-ats.h" | 29 | #include "gnunet-service-ats.h" |
30 | #include "gnunet-service-ats_addresses.h" | 30 | #include "gnunet-service-ats_addresses.h" |
31 | #include "gnunet-service-ats_connectivity.h" | ||
31 | #include "gnunet-service-ats_performance.h" | 32 | #include "gnunet-service-ats_performance.h" |
32 | #include "gnunet-service-ats_scheduling.h" | 33 | #include "gnunet-service-ats_scheduling.h" |
33 | #include "gnunet-service-ats_reservations.h" | 34 | #include "gnunet-service-ats_reservations.h" |
@@ -80,6 +81,9 @@ handle_ats_start (void *cls, | |||
80 | case START_FLAG_PERFORMANCE_NO_PIC: | 81 | case START_FLAG_PERFORMANCE_NO_PIC: |
81 | GAS_performance_add_client (client, flag); | 82 | GAS_performance_add_client (client, flag); |
82 | break; | 83 | break; |
84 | case START_FLAG_CONNECTION_SUGGESTION: | ||
85 | /* This client won't receive messages from us, no need to 'add' */ | ||
86 | break; | ||
83 | default: | 87 | default: |
84 | GNUNET_break (0); | 88 | GNUNET_break (0); |
85 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 89 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
diff --git a/src/ats/gnunet-service-ats_connectivity.c b/src/ats/gnunet-service-ats_connectivity.c new file mode 100644 index 000000000..da943f984 --- /dev/null +++ b/src/ats/gnunet-service-ats_connectivity.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011-2015 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file ats/gnunet-service-ats_connectivity.c | ||
23 | * @brief ats service, interaction with 'connecivity' API | ||
24 | * @author Matthias Wachs | ||
25 | * @author Christian Grothoff | ||
26 | * | ||
27 | * FIXME: | ||
28 | * - we should track requests by client, and if a client | ||
29 | * disconnects cancel all associated requests; right | ||
30 | * now, they will persist forever unless the client | ||
31 | * explicitly sends us a cancel before disconnecting! | ||
32 | */ | ||
33 | #include "platform.h" | ||
34 | #include "gnunet-service-ats.h" | ||
35 | #include "gnunet-service-ats_addresses.h" | ||
36 | #include "gnunet-service-ats_connectivity.h" | ||
37 | #include "ats.h" | ||
38 | |||
39 | /** | ||
40 | * Handle 'request address' messages from clients. | ||
41 | * | ||
42 | * @param cls unused, NULL | ||
43 | * @param client client that sent the request | ||
44 | * @param message the request message | ||
45 | */ | ||
46 | void | ||
47 | GAS_handle_request_address (void *cls, | ||
48 | struct GNUNET_SERVER_Client *client, | ||
49 | const struct GNUNET_MessageHeader *message) | ||
50 | { | ||
51 | const struct RequestAddressMessage *msg = | ||
52 | (const struct RequestAddressMessage *) message; | ||
53 | |||
54 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
55 | "Received `%s' message\n", | ||
56 | "REQUEST_ADDRESS"); | ||
57 | GNUNET_break (0 == ntohl (msg->reserved)); | ||
58 | GAS_addresses_request_address (&msg->peer); | ||
59 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
60 | } | ||
61 | |||
62 | |||
63 | /** | ||
64 | * Handle 'request address' messages from clients. | ||
65 | * | ||
66 | * @param cls unused, NULL | ||
67 | * @param client client that sent the request | ||
68 | * @param message the request message | ||
69 | */ | ||
70 | void | ||
71 | GAS_handle_request_address_cancel (void *cls, | ||
72 | struct GNUNET_SERVER_Client *client, | ||
73 | const struct GNUNET_MessageHeader *message) | ||
74 | { | ||
75 | const struct RequestAddressMessage *msg = | ||
76 | (const struct RequestAddressMessage *) message; | ||
77 | |||
78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
79 | "Received `%s' message\n", | ||
80 | "REQUEST_ADDRESS_CANCEL"); | ||
81 | GNUNET_break (0 == ntohl (msg->reserved)); | ||
82 | GAS_addresses_request_address_cancel (&msg->peer); | ||
83 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
84 | } | ||
85 | |||
86 | /* end of gnunet-service-ats_connectivity.c */ | ||
diff --git a/src/ats/gnunet-service-ats_connectivity.h b/src/ats/gnunet-service-ats_connectivity.h new file mode 100644 index 000000000..c6b50f445 --- /dev/null +++ b/src/ats/gnunet-service-ats_connectivity.h | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011-2015 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file ats/gnunet-service-ats_connectivity.h | ||
23 | * @brief ats service, interaction with 'connecivity' API | ||
24 | * @author Matthias Wachs | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | #ifndef GNUNET_SERVICE_ATS_CONNECTIVITY_H | ||
28 | #define GNUNET_SERVICE_ATS_CONNECTIVITY_H | ||
29 | |||
30 | |||
31 | /** | ||
32 | * Handle 'request address' messages from clients. | ||
33 | * | ||
34 | * @param cls unused, NULL | ||
35 | * @param client client that sent the request | ||
36 | * @param message the request message | ||
37 | */ | ||
38 | void | ||
39 | GAS_handle_request_address (void *cls, | ||
40 | struct GNUNET_SERVER_Client *client, | ||
41 | const struct GNUNET_MessageHeader *message); | ||
42 | |||
43 | |||
44 | /** | ||
45 | * Cancel 'request address' messages from clients. | ||
46 | * | ||
47 | * @param cls unused, NULL | ||
48 | * @param client client that sent the request | ||
49 | * @param message the request message | ||
50 | */ | ||
51 | void | ||
52 | GAS_handle_request_address_cancel (void *cls, | ||
53 | struct GNUNET_SERVER_Client *client, | ||
54 | const struct GNUNET_MessageHeader *message); | ||
55 | |||
56 | |||
57 | #endif | ||
58 | /* end of gnunet-service-ats_connectivity.h */ | ||
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index 2e11296e3..6b6b6c24f 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c | |||
@@ -120,53 +120,6 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe | |||
120 | 120 | ||
121 | 121 | ||
122 | /** | 122 | /** |
123 | * Handle 'request address' messages from clients. | ||
124 | * | ||
125 | * @param cls unused, NULL | ||
126 | * @param client client that sent the request | ||
127 | * @param message the request message | ||
128 | */ | ||
129 | void | ||
130 | GAS_handle_request_address (void *cls, | ||
131 | struct GNUNET_SERVER_Client *client, | ||
132 | const struct GNUNET_MessageHeader *message) | ||
133 | { | ||
134 | const struct RequestAddressMessage *msg = | ||
135 | (const struct RequestAddressMessage *) message; | ||
136 | |||
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", | ||
138 | "REQUEST_ADDRESS"); | ||
139 | GNUNET_break (0 == ntohl (msg->reserved)); | ||
140 | GAS_addresses_request_address (&msg->peer); | ||
141 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
142 | } | ||
143 | |||
144 | |||
145 | /** | ||
146 | * Handle 'request address' messages from clients. | ||
147 | * | ||
148 | * @param cls unused, NULL | ||
149 | * @param client client that sent the request | ||
150 | * @param message the request message | ||
151 | */ | ||
152 | void | ||
153 | GAS_handle_request_address_cancel (void *cls, | ||
154 | struct GNUNET_SERVER_Client *client, | ||
155 | const struct GNUNET_MessageHeader *message) | ||
156 | { | ||
157 | const struct RequestAddressMessage *msg = | ||
158 | (const struct RequestAddressMessage *) message; | ||
159 | |||
160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
161 | "Received `%s' message\n", | ||
162 | "REQUEST_ADDRESS_CANCEL"); | ||
163 | GNUNET_break (0 == ntohl (msg->reserved)); | ||
164 | GAS_addresses_request_address_cancel (&msg->peer); | ||
165 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
166 | } | ||
167 | |||
168 | |||
169 | /** | ||
170 | * Handle 'reset backoff' messages from clients. | 123 | * Handle 'reset backoff' messages from clients. |
171 | * | 124 | * |
172 | * @param cls unused, NULL | 125 | * @param cls unused, NULL |
diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h index 38ade2ae8..fe8adc8c5 100644 --- a/src/ats/gnunet-service-ats_scheduling.h +++ b/src/ats/gnunet-service-ats_scheduling.h | |||
@@ -80,32 +80,6 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe | |||
80 | 80 | ||
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Handle 'request address' messages from clients. | ||
84 | * | ||
85 | * @param cls unused, NULL | ||
86 | * @param client client that sent the request | ||
87 | * @param message the request message | ||
88 | */ | ||
89 | void | ||
90 | GAS_handle_request_address (void *cls, | ||
91 | struct GNUNET_SERVER_Client *client, | ||
92 | const struct GNUNET_MessageHeader *message); | ||
93 | |||
94 | |||
95 | /** | ||
96 | * Cancel 'request address' messages from clients. | ||
97 | * | ||
98 | * @param cls unused, NULL | ||
99 | * @param client client that sent the request | ||
100 | * @param message the request message | ||
101 | */ | ||
102 | void | ||
103 | GAS_handle_request_address_cancel (void *cls, | ||
104 | struct GNUNET_SERVER_Client *client, | ||
105 | const struct GNUNET_MessageHeader *message); | ||
106 | |||
107 | |||
108 | /** | ||
109 | * Handle 'address add' messages from clients. | 83 | * Handle 'address add' messages from clients. |
110 | * | 84 | * |
111 | * @param cls unused, NULL | 85 | * @param cls unused, NULL |
diff --git a/src/ats/test_ats_api_bandwidth_consumption.c b/src/ats/test_ats_api_bandwidth_consumption.c index 9ab0de7a9..366f293ca 100644 --- a/src/ats/test_ats_api_bandwidth_consumption.c +++ b/src/ats/test_ats_api_bandwidth_consumption.c | |||
@@ -39,7 +39,12 @@ static struct GNUNET_ATS_SchedulingHandle *ats; | |||
39 | 39 | ||
40 | static struct GNUNET_ATS_PerformanceHandle *atp; | 40 | static struct GNUNET_ATS_PerformanceHandle *atp; |
41 | 41 | ||
42 | struct GNUNET_ATS_ReservationContext *sh; | 42 | /** |
43 | * Connectivity handle | ||
44 | */ | ||
45 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
46 | |||
47 | static struct GNUNET_ATS_ReservationContext *sh; | ||
43 | 48 | ||
44 | static struct PeerContext *p; | 49 | static struct PeerContext *p; |
45 | 50 | ||
@@ -75,44 +80,51 @@ struct PeerContext | |||
75 | 80 | ||
76 | 81 | ||
77 | static void | 82 | static void |
78 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 83 | end () |
79 | { | 84 | { |
80 | die_task = NULL; | 85 | if (NULL != connect_ats) |
86 | { | ||
87 | GNUNET_ATS_connectivity_done (connect_ats); | ||
88 | connect_ats = NULL; | ||
89 | } | ||
90 | if (die_task != NULL) | ||
91 | { | ||
92 | GNUNET_SCHEDULER_cancel (die_task); | ||
93 | die_task = NULL; | ||
94 | } | ||
81 | if (consume_task != NULL) | 95 | if (consume_task != NULL) |
82 | { | 96 | { |
83 | GNUNET_SCHEDULER_cancel (consume_task); | 97 | GNUNET_SCHEDULER_cancel (consume_task); |
84 | consume_task = NULL; | 98 | consume_task = NULL; |
85 | } | 99 | } |
86 | if (sh != NULL) | 100 | if (sh != NULL) |
101 | { | ||
87 | GNUNET_ATS_reserve_bandwidth_cancel (sh); | 102 | GNUNET_ATS_reserve_bandwidth_cancel (sh); |
103 | sh = NULL; | ||
104 | } | ||
88 | if (ats != NULL) | 105 | if (ats != NULL) |
106 | { | ||
89 | GNUNET_ATS_scheduling_done (ats); | 107 | GNUNET_ATS_scheduling_done (ats); |
108 | ats = NULL; | ||
109 | } | ||
90 | if (atp != NULL) | 110 | if (atp != NULL) |
111 | { | ||
91 | GNUNET_ATS_performance_done (atp); | 112 | GNUNET_ATS_performance_done (atp); |
113 | atp = NULL; | ||
114 | } | ||
92 | GNUNET_free (p->addr); | 115 | GNUNET_free (p->addr); |
93 | GNUNET_free (p); | 116 | GNUNET_free (p); |
94 | ret = GNUNET_SYSERR; | 117 | p = NULL; |
118 | ret = 0; | ||
95 | } | 119 | } |
96 | 120 | ||
97 | 121 | ||
98 | static void | 122 | static void |
99 | end () | 123 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
100 | { | 124 | { |
101 | if (die_task != NULL) | 125 | die_task = NULL; |
102 | { | 126 | end (); |
103 | GNUNET_SCHEDULER_cancel (die_task); | 127 | ret = GNUNET_SYSERR; |
104 | die_task = NULL; | ||
105 | } | ||
106 | if (consume_task != NULL) | ||
107 | { | ||
108 | GNUNET_SCHEDULER_cancel (consume_task); | ||
109 | consume_task = NULL; | ||
110 | } | ||
111 | GNUNET_ATS_scheduling_done (ats); | ||
112 | GNUNET_ATS_performance_done (atp); | ||
113 | GNUNET_free (p->addr); | ||
114 | GNUNET_free (p); | ||
115 | ret = 0; | ||
116 | } | 128 | } |
117 | 129 | ||
118 | 130 | ||
@@ -182,6 +194,8 @@ run (void *cls, | |||
182 | 194 | ||
183 | ret = GNUNET_SYSERR; | 195 | ret = GNUNET_SYSERR; |
184 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 196 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
197 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | ||
198 | |||
185 | ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | 199 | ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); |
186 | if (ats == NULL) | 200 | if (ats == NULL) |
187 | { | 201 | { |
@@ -218,7 +232,7 @@ run (void *cls, | |||
218 | GNUNET_ATS_address_update (ats, &p->id, addr->plugin, addr->addr, | 232 | GNUNET_ATS_address_update (ats, &p->id, addr->plugin, addr->addr, |
219 | addr->addr_len, addr->session, NULL, 0); | 233 | addr->addr_len, addr->session, NULL, 0); |
220 | 234 | ||
221 | GNUNET_ATS_suggest_address (ats, &p->id); | 235 | GNUNET_ATS_connectivity_suggest (connect_ats, &p->id); |
222 | } | 236 | } |
223 | 237 | ||
224 | 238 | ||
diff --git a/src/ats/test_ats_simplistic_pref_aging.c b/src/ats/test_ats_simplistic_pref_aging.c index 855e22fbf..654abfa5b 100644 --- a/src/ats/test_ats_simplistic_pref_aging.c +++ b/src/ats/test_ats_simplistic_pref_aging.c | |||
@@ -48,6 +48,11 @@ static struct GNUNET_SCHEDULER_Task * die_task; | |||
48 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | 48 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Connectivity handle | ||
52 | */ | ||
53 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
54 | |||
55 | /** | ||
51 | * Performance handle | 56 | * Performance handle |
52 | */ | 57 | */ |
53 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; | 58 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; |
@@ -67,11 +72,15 @@ static struct Test_Address test_addr[2]; | |||
67 | */ | 72 | */ |
68 | static struct PeerContext p[2]; | 73 | static struct PeerContext p[2]; |
69 | 74 | ||
75 | /** | ||
76 | * Connectivity suggestion handles. | ||
77 | */ | ||
78 | static struct GNUNET_ATS_ConnectivitySuggestHandle *sh[2]; | ||
70 | 79 | ||
71 | /** | 80 | /** |
72 | * HELLO address | 81 | * HELLO address |
73 | */ | 82 | */ |
74 | struct GNUNET_HELLO_Address test_hello_address[2]; | 83 | static struct GNUNET_HELLO_Address test_hello_address[2]; |
75 | 84 | ||
76 | /** | 85 | /** |
77 | * Session | 86 | * Session |
@@ -81,22 +90,22 @@ static void *test_session[2]; | |||
81 | /** | 90 | /** |
82 | * Test ats info | 91 | * Test ats info |
83 | */ | 92 | */ |
84 | struct GNUNET_ATS_Information test_ats_info[2]; | 93 | static struct GNUNET_ATS_Information test_ats_info[2]; |
85 | 94 | ||
86 | /** | 95 | /** |
87 | * Test ats count | 96 | * Test ats count |
88 | */ | 97 | */ |
89 | uint32_t test_ats_count; | 98 | static uint32_t test_ats_count; |
90 | 99 | ||
91 | /** | 100 | /** |
92 | * Configured WAN out quota | 101 | * Configured WAN out quota |
93 | */ | 102 | */ |
94 | unsigned long long wan_quota_out; | 103 | static unsigned long long wan_quota_out; |
95 | 104 | ||
96 | /** | 105 | /** |
97 | * Configured WAN in quota | 106 | * Configured WAN in quota |
98 | */ | 107 | */ |
99 | unsigned long long wan_quota_in; | 108 | static unsigned long long wan_quota_in; |
100 | 109 | ||
101 | 110 | ||
102 | static void | 111 | static void |
@@ -109,6 +118,11 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
109 | GNUNET_ATS_scheduling_done (sched_ats); | 118 | GNUNET_ATS_scheduling_done (sched_ats); |
110 | sched_ats = NULL; | 119 | sched_ats = NULL; |
111 | } | 120 | } |
121 | if (NULL != connect_ats) | ||
122 | { | ||
123 | GNUNET_ATS_connectivity_done (connect_ats); | ||
124 | connect_ats = NULL; | ||
125 | } | ||
112 | if (perf_ats != NULL) | 126 | if (perf_ats != NULL) |
113 | { | 127 | { |
114 | GNUNET_ATS_performance_done (perf_ats); | 128 | GNUNET_ATS_performance_done (perf_ats); |
@@ -129,8 +143,8 @@ end () | |||
129 | die_task = NULL; | 143 | die_task = NULL; |
130 | } | 144 | } |
131 | 145 | ||
132 | GNUNET_ATS_suggest_address_cancel (sched_ats, &p[0].id); | 146 | GNUNET_ATS_connectivity_suggest_cancel (sh[0]); |
133 | GNUNET_ATS_suggest_address_cancel (sched_ats, &p[1].id); | 147 | GNUNET_ATS_connectivity_suggest_cancel (sh[1]); |
134 | 148 | ||
135 | if (NULL != sched_ats) | 149 | if (NULL != sched_ats) |
136 | GNUNET_ATS_scheduling_done (sched_ats); | 150 | GNUNET_ATS_scheduling_done (sched_ats); |
@@ -366,6 +380,7 @@ run (void *cls, | |||
366 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 380 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
367 | 381 | ||
368 | /* Connect to ATS scheduling */ | 382 | /* Connect to ATS scheduling */ |
383 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | ||
369 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | 384 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); |
370 | if (sched_ats == NULL) | 385 | if (sched_ats == NULL) |
371 | { | 386 | { |
@@ -439,8 +454,8 @@ run (void *cls, | |||
439 | test_hello_address[1].address_length = test_addr[1].addr_len; | 454 | test_hello_address[1].address_length = test_addr[1].addr_len; |
440 | GNUNET_ATS_address_add (sched_ats, &test_hello_address[1], test_session[1], test_ats_info, test_ats_count); | 455 | GNUNET_ATS_address_add (sched_ats, &test_hello_address[1], test_session[1], test_ats_info, test_ats_count); |
441 | 456 | ||
442 | GNUNET_ATS_suggest_address (sched_ats, &p[0].id); | 457 | sh[0] = GNUNET_ATS_connectivity_suggest (connect_ats, &p[0].id); |
443 | GNUNET_ATS_suggest_address (sched_ats, &p[1].id); | 458 | sh[1] = GNUNET_ATS_connectivity_suggest (connect_ats, &p[1].id); |
444 | } | 459 | } |
445 | 460 | ||
446 | 461 | ||
diff --git a/src/ats/test_ats_solver_add_address_and_request.c b/src/ats/test_ats_solver_add_address_and_request.c index 34ade7d60..6d63cd990 100644 --- a/src/ats/test_ats_solver_add_address_and_request.c +++ b/src/ats/test_ats_solver_add_address_and_request.c | |||
@@ -51,6 +51,11 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
51 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | 51 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Connectivity handle | ||
55 | */ | ||
56 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
57 | |||
58 | /** | ||
54 | * Return value | 59 | * Return value |
55 | */ | 60 | */ |
56 | static int ret; | 61 | static int ret; |
@@ -106,6 +111,11 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
106 | GNUNET_ATS_scheduling_done (sched_ats); | 111 | GNUNET_ATS_scheduling_done (sched_ats); |
107 | sched_ats = NULL; | 112 | sched_ats = NULL; |
108 | } | 113 | } |
114 | if (NULL != connect_ats) | ||
115 | { | ||
116 | GNUNET_ATS_connectivity_done (connect_ats); | ||
117 | connect_ats = NULL; | ||
118 | } | ||
109 | 119 | ||
110 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | 120 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); |
111 | if (NULL != stats) | 121 | if (NULL != stats) |
@@ -154,7 +164,7 @@ stat_cb (void *cls, const char *subsystem, | |||
154 | const char *name, uint64_t value, | 164 | const char *name, uint64_t value, |
155 | int is_persistent) | 165 | int is_persistent) |
156 | { | 166 | { |
157 | static struct GNUNET_ATS_SuggestHandle *sh; | 167 | static struct GNUNET_ATS_ConnectivitySuggestHandle *sh; |
158 | 168 | ||
159 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 169 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
160 | "ATS statistics: `%s' `%s' %llu\n", | 170 | "ATS statistics: `%s' `%s' %llu\n", |
@@ -162,7 +172,7 @@ stat_cb (void *cls, const char *subsystem, | |||
162 | name, | 172 | name, |
163 | value); | 173 | value); |
164 | if (NULL == sh) | 174 | if (NULL == sh) |
165 | sh = GNUNET_ATS_suggest_address (sched_ats, &p.id); | 175 | sh = GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); |
166 | return GNUNET_OK; | 176 | return GNUNET_OK; |
167 | } | 177 | } |
168 | 178 | ||
@@ -177,6 +187,7 @@ run (void *cls, | |||
177 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | 187 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); |
178 | 188 | ||
179 | 189 | ||
190 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | ||
180 | /* Connect to ATS scheduling */ | 191 | /* Connect to ATS scheduling */ |
181 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | 192 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); |
182 | if (sched_ats == NULL) | 193 | if (sched_ats == NULL) |
diff --git a/src/ats/test_ats_solver_alternative_after_delete_address.c b/src/ats/test_ats_solver_alternative_after_delete_address.c index 8a14b384e..907ecbfcb 100644 --- a/src/ats/test_ats_solver_alternative_after_delete_address.c +++ b/src/ats/test_ats_solver_alternative_after_delete_address.c | |||
@@ -45,6 +45,11 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
45 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | 45 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Connectivity handle | ||
49 | */ | ||
50 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
51 | |||
52 | /** | ||
48 | * Return value | 53 | * Return value |
49 | */ | 54 | */ |
50 | static int ret; | 55 | static int ret; |
@@ -125,12 +130,16 @@ stat_cb (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
125 | static void | 130 | static void |
126 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 131 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
127 | { | 132 | { |
128 | if (die_task != NULL) | 133 | if (NULL != die_task) |
129 | { | 134 | { |
130 | GNUNET_SCHEDULER_cancel (die_task); | 135 | GNUNET_SCHEDULER_cancel (die_task); |
131 | die_task = NULL; | 136 | die_task = NULL; |
132 | } | 137 | } |
133 | 138 | if (NULL != connect_ats) | |
139 | { | ||
140 | GNUNET_ATS_connectivity_done (connect_ats); | ||
141 | connect_ats = NULL; | ||
142 | } | ||
134 | if (NULL != sched_ats) | 143 | if (NULL != sched_ats) |
135 | { | 144 | { |
136 | GNUNET_ATS_scheduling_done (sched_ats); | 145 | GNUNET_ATS_scheduling_done (sched_ats); |
@@ -313,7 +322,7 @@ stat_cb(void *cls, const char *subsystem, | |||
313 | "All addresses added, requesting....\n"); | 322 | "All addresses added, requesting....\n"); |
314 | /* We have 2 addresses, so we can request */ | 323 | /* We have 2 addresses, so we can request */ |
315 | addresses_added = GNUNET_YES; | 324 | addresses_added = GNUNET_YES; |
316 | GNUNET_ATS_suggest_address (sched_ats, &p.id); | 325 | GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); |
317 | } | 326 | } |
318 | return GNUNET_OK; | 327 | return GNUNET_OK; |
319 | } | 328 | } |
@@ -328,6 +337,7 @@ run (void *cls, | |||
328 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | 337 | stats = GNUNET_STATISTICS_create ("ats", mycfg); |
329 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | 338 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); |
330 | 339 | ||
340 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | ||
331 | 341 | ||
332 | /* Connect to ATS scheduling */ | 342 | /* Connect to ATS scheduling */ |
333 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | 343 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); |
diff --git a/src/ats/test_ats_solver_convergence.c b/src/ats/test_ats_solver_convergence.c index e33b138ac..c75ea543d 100644 --- a/src/ats/test_ats_solver_convergence.c +++ b/src/ats/test_ats_solver_convergence.c | |||
@@ -46,6 +46,11 @@ struct GNUNET_STATISTICS_Handle *stats; | |||
46 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | 46 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Connectivity handle | ||
50 | */ | ||
51 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
52 | |||
53 | /** | ||
49 | * Return value | 54 | * Return value |
50 | */ | 55 | */ |
51 | static int ret; | 56 | static int ret; |
@@ -125,6 +130,11 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
125 | sched_ats = NULL; | 130 | sched_ats = NULL; |
126 | } | 131 | } |
127 | 132 | ||
133 | if (NULL != connect_ats) | ||
134 | { | ||
135 | GNUNET_ATS_connectivity_done (connect_ats); | ||
136 | connect_ats = NULL; | ||
137 | } | ||
128 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | 138 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); |
129 | if (NULL != stats) | 139 | if (NULL != stats) |
130 | { | 140 | { |
@@ -219,7 +229,7 @@ stat_cb(void *cls, const char *subsystem, | |||
219 | "ATS statistics: `%s' `%s' %llu\n", | 229 | "ATS statistics: `%s' `%s' %llu\n", |
220 | subsystem,name, | 230 | subsystem,name, |
221 | (unsigned long long) value); | 231 | (unsigned long long) value); |
222 | GNUNET_ATS_suggest_address (sched_ats, &p.id); | 232 | GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); |
223 | return GNUNET_OK; | 233 | return GNUNET_OK; |
224 | } | 234 | } |
225 | 235 | ||
@@ -233,6 +243,7 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
233 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | 243 | stats = GNUNET_STATISTICS_create ("ats", mycfg); |
234 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | 244 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); |
235 | 245 | ||
246 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | ||
236 | /* Connect to ATS scheduling */ | 247 | /* Connect to ATS scheduling */ |
237 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | 248 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); |
238 | if (sched_ats == NULL) | 249 | if (sched_ats == NULL) |
diff --git a/src/ats/test_ats_solver_preferences.c b/src/ats/test_ats_solver_preferences.c index 611f639bf..5c2206c26 100644 --- a/src/ats/test_ats_solver_preferences.c +++ b/src/ats/test_ats_solver_preferences.c | |||
@@ -51,7 +51,12 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
51 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | 51 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Scheduling handle | 54 | * Connectivity handle |
55 | */ | ||
56 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
57 | |||
58 | /** | ||
59 | * Performance handle | ||
55 | */ | 60 | */ |
56 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; | 61 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; |
57 | 62 | ||
@@ -95,6 +100,7 @@ static int | |||
95 | stat_cb (void *cls, const char *subsystem, const char *name, uint64_t value, | 100 | stat_cb (void *cls, const char *subsystem, const char *name, uint64_t value, |
96 | int is_persistent); | 101 | int is_persistent); |
97 | 102 | ||
103 | |||
98 | static void | 104 | static void |
99 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 105 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
100 | { | 106 | { |
@@ -111,7 +117,11 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
111 | GNUNET_ATS_scheduling_done (sched_ats); | 117 | GNUNET_ATS_scheduling_done (sched_ats); |
112 | sched_ats = NULL; | 118 | sched_ats = NULL; |
113 | } | 119 | } |
114 | 120 | if (NULL != connect_ats) | |
121 | { | ||
122 | GNUNET_ATS_connectivity_done (connect_ats); | ||
123 | connect_ats = NULL; | ||
124 | } | ||
115 | if (NULL != perf_ats) | 125 | if (NULL != perf_ats) |
116 | { | 126 | { |
117 | GNUNET_ATS_performance_done (perf_ats); | 127 | GNUNET_ATS_performance_done (perf_ats); |
@@ -203,6 +213,7 @@ stat_cb (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
203 | return GNUNET_OK; | 213 | return GNUNET_OK; |
204 | } | 214 | } |
205 | 215 | ||
216 | |||
206 | static void | 217 | static void |
207 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | 218 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, |
208 | struct GNUNET_TESTING_Peer *peer) | 219 | struct GNUNET_TESTING_Peer *peer) |
@@ -212,6 +223,8 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
212 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | 223 | stats = GNUNET_STATISTICS_create ("ats", mycfg); |
213 | GNUNET_STATISTICS_watch (stats, "ats", "# active performance clients", &stat_cb, NULL ); | 224 | GNUNET_STATISTICS_watch (stats, "ats", "# active performance clients", &stat_cb, NULL ); |
214 | 225 | ||
226 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | ||
227 | |||
215 | /* Connect to ATS scheduling */ | 228 | /* Connect to ATS scheduling */ |
216 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL ); | 229 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL ); |
217 | if (sched_ats == NULL ) | 230 | if (sched_ats == NULL ) |
@@ -258,7 +271,7 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
258 | /* Adding address */ | 271 | /* Adding address */ |
259 | GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, | 272 | GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, |
260 | test_ats_info, test_ats_count); | 273 | test_ats_info, test_ats_count); |
261 | GNUNET_ATS_suggest_address(sched_ats, &test_hello_address.peer); | 274 | GNUNET_ATS_connectivity_suggest (connect_ats, &test_hello_address.peer); |
262 | } | 275 | } |
263 | 276 | ||
264 | 277 | ||
diff --git a/src/ats/test_ats_solver_request_and_add_address.c b/src/ats/test_ats_solver_request_and_add_address.c index 664861b82..75f6bfb99 100644 --- a/src/ats/test_ats_solver_request_and_add_address.c +++ b/src/ats/test_ats_solver_request_and_add_address.c | |||
@@ -51,6 +51,11 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
51 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | 51 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Connectivity handle | ||
55 | */ | ||
56 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
57 | |||
58 | /** | ||
54 | * Return value | 59 | * Return value |
55 | */ | 60 | */ |
56 | static int ret; | 61 | static int ret; |
@@ -105,7 +110,11 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
105 | GNUNET_ATS_scheduling_done (sched_ats); | 110 | GNUNET_ATS_scheduling_done (sched_ats); |
106 | sched_ats = NULL; | 111 | sched_ats = NULL; |
107 | } | 112 | } |
108 | 113 | if (NULL != connect_ats) | |
114 | { | ||
115 | GNUNET_ATS_connectivity_done (connect_ats); | ||
116 | connect_ats = NULL; | ||
117 | } | ||
109 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | 118 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); |
110 | if (NULL != stats) | 119 | if (NULL != stats) |
111 | { | 120 | { |
@@ -165,7 +174,7 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
165 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | 174 | stats = GNUNET_STATISTICS_create ("ats", mycfg); |
166 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | 175 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); |
167 | 176 | ||
168 | 177 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | |
169 | /* Connect to ATS scheduling */ | 178 | /* Connect to ATS scheduling */ |
170 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | 179 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); |
171 | if (sched_ats == NULL) | 180 | if (sched_ats == NULL) |
@@ -196,7 +205,7 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
196 | test_hello_address.address_length = test_addr.addr_len; | 205 | test_hello_address.address_length = test_addr.addr_len; |
197 | 206 | ||
198 | /* Request */ | 207 | /* Request */ |
199 | GNUNET_ATS_suggest_address (sched_ats, &p.id); | 208 | GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); |
200 | 209 | ||
201 | 210 | ||
202 | /* Adding address */ | 211 | /* Adding address */ |
diff --git a/src/ats/test_ats_solver_request_and_delete_address.c b/src/ats/test_ats_solver_request_and_delete_address.c index 037d26971..089b4b015 100644 --- a/src/ats/test_ats_solver_request_and_delete_address.c +++ b/src/ats/test_ats_solver_request_and_delete_address.c | |||
@@ -45,6 +45,11 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
45 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | 45 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Connectivity handle | ||
49 | */ | ||
50 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
51 | |||
52 | /** | ||
48 | * Return value | 53 | * Return value |
49 | */ | 54 | */ |
50 | static int ret; | 55 | static int ret; |
@@ -108,6 +113,11 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
108 | sched_ats = NULL; | 113 | sched_ats = NULL; |
109 | } | 114 | } |
110 | 115 | ||
116 | if (NULL != connect_ats) | ||
117 | { | ||
118 | GNUNET_ATS_connectivity_done (connect_ats); | ||
119 | connect_ats = NULL; | ||
120 | } | ||
111 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | 121 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); |
112 | if (NULL != stats) | 122 | if (NULL != stats) |
113 | { | 123 | { |
@@ -178,7 +188,7 @@ stat_cb (void *cls, const char *subsystem, | |||
178 | const char *name, uint64_t value, | 188 | const char *name, uint64_t value, |
179 | int is_persistent) | 189 | int is_persistent) |
180 | { | 190 | { |
181 | static struct GNUNET_ATS_SuggestHandle *sh; | 191 | static struct GNUNET_ATS_ConnectivitySuggestHandle *sh; |
182 | 192 | ||
183 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 193 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
184 | "ATS statistics: `%s' `%s' %llu\n", | 194 | "ATS statistics: `%s' `%s' %llu\n", |
@@ -186,7 +196,7 @@ stat_cb (void *cls, const char *subsystem, | |||
186 | name, | 196 | name, |
187 | value); | 197 | value); |
188 | if (NULL == sh) | 198 | if (NULL == sh) |
189 | sh = GNUNET_ATS_suggest_address (sched_ats, &p.id); | 199 | sh = GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); |
190 | return GNUNET_OK; | 200 | return GNUNET_OK; |
191 | } | 201 | } |
192 | 202 | ||
@@ -200,6 +210,7 @@ run (void *cls, | |||
200 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | 210 | stats = GNUNET_STATISTICS_create ("ats", mycfg); |
201 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | 211 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); |
202 | 212 | ||
213 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | ||
203 | 214 | ||
204 | /* Connect to ATS scheduling */ | 215 | /* Connect to ATS scheduling */ |
205 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | 216 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); |
diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 74e7c7c80..d506f41ff 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h | |||
@@ -304,17 +304,68 @@ struct GNUNET_ATS_Information | |||
304 | }; | 304 | }; |
305 | GNUNET_NETWORK_STRUCT_END | 305 | GNUNET_NETWORK_STRUCT_END |
306 | 306 | ||
307 | /* ******************************** Scheduling API ***************************** */ | 307 | |
308 | /* ********************Connection Suggestion API ***************************** */ | ||
308 | 309 | ||
309 | /** | 310 | /** |
310 | * Handle to the ATS subsystem for bandwidth/transport scheduling information. | 311 | * Handle to the ATS subsystem for making suggestions about |
312 | * connections the peer would like to have. | ||
311 | */ | 313 | */ |
312 | struct GNUNET_ATS_SchedulingHandle; | 314 | struct GNUNET_ATS_ConnectivityHandle; |
315 | |||
316 | /** | ||
317 | * Handle for address suggestion requests. | ||
318 | */ | ||
319 | struct GNUNET_ATS_ConnectivitySuggestHandle; | ||
320 | |||
321 | |||
322 | /** | ||
323 | * Initialize the ATS connectivity suggestion client handle. | ||
324 | * | ||
325 | * @param cfg configuration to use | ||
326 | * @return ats connectivity handle, NULL on error | ||
327 | */ | ||
328 | struct GNUNET_ATS_ConnectivityHandle * | ||
329 | GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
330 | |||
313 | 331 | ||
314 | /** | 332 | /** |
315 | * Handle for address suggestion requests | 333 | * Shutdown ATS connectivity suggestion client. |
334 | * | ||
335 | * @param ch handle to destroy | ||
336 | */ | ||
337 | void | ||
338 | GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch); | ||
339 | |||
340 | |||
341 | /** | ||
342 | * We would like to establish a new connection with a peer. ATS | ||
343 | * should suggest a good address to begin with. | ||
344 | * | ||
345 | * @param ch handle | ||
346 | * @param peer identity of the peer we need an address for | ||
347 | * @return suggestion handle, NULL if request is already pending | ||
316 | */ | 348 | */ |
317 | struct GNUNET_ATS_SuggestHandle; | 349 | struct GNUNET_ATS_ConnectivitySuggestHandle * |
350 | GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch, | ||
351 | const struct GNUNET_PeerIdentity *peer); | ||
352 | |||
353 | |||
354 | /** | ||
355 | * We no longer care about being connected to a peer. | ||
356 | * | ||
357 | * @param sh handle | ||
358 | */ | ||
359 | void | ||
360 | GNUNET_ATS_connectivity_suggest_cancel (struct GNUNET_ATS_ConnectivitySuggestHandle *sh); | ||
361 | |||
362 | |||
363 | /* ******************************** Scheduling API ***************************** */ | ||
364 | |||
365 | /** | ||
366 | * Handle to the ATS subsystem for bandwidth/transport scheduling information. | ||
367 | */ | ||
368 | struct GNUNET_ATS_SchedulingHandle; | ||
318 | 369 | ||
319 | /** | 370 | /** |
320 | * Opaque session handle, defined by plugins. Contents not known to ATS. | 371 | * Opaque session handle, defined by plugins. Contents not known to ATS. |
@@ -343,7 +394,7 @@ typedef void | |||
343 | 394 | ||
344 | 395 | ||
345 | /** | 396 | /** |
346 | * Initialize the ATS subsystem. | 397 | * Initialize the ATS scheduling subsystem. |
347 | * | 398 | * |
348 | * @param cfg configuration to use | 399 | * @param cfg configuration to use |
349 | * @param suggest_cb notification to call whenever the suggestation changed | 400 | * @param suggest_cb notification to call whenever the suggestation changed |
@@ -377,30 +428,6 @@ GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh, | |||
377 | 428 | ||
378 | 429 | ||
379 | /** | 430 | /** |
380 | * We would like to establish a new connection with a peer. ATS | ||
381 | * should suggest a good address to begin with. | ||
382 | * | ||
383 | * @param sh handle | ||
384 | * @param peer identity of the peer we need an address for | ||
385 | * @return suggestion handle, NULL if a request is already pending | ||
386 | */ | ||
387 | struct GNUNET_ATS_SuggestHandle * | ||
388 | GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, | ||
389 | const struct GNUNET_PeerIdentity *peer); | ||
390 | |||
391 | |||
392 | /** | ||
393 | * We want to cancel ATS suggesting addresses for a peer. | ||
394 | * | ||
395 | * @param sh handle | ||
396 | * @param peer identity of the peer | ||
397 | */ | ||
398 | void | ||
399 | GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh, | ||
400 | const struct GNUNET_PeerIdentity *peer); | ||
401 | |||
402 | |||
403 | /** | ||
404 | * Convert a ATS property to a string | 431 | * Convert a ATS property to a string |
405 | * | 432 | * |
406 | * @param type the property type | 433 | * @param type the property type |
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 2f0a17360..e65af664c 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -122,11 +122,16 @@ static struct GNUNET_SERVER_Handle *GST_server; | |||
122 | struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key; | 122 | struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key; |
123 | 123 | ||
124 | /** | 124 | /** |
125 | * ATS handle. | 125 | * ATS scheduling handle. |
126 | */ | 126 | */ |
127 | struct GNUNET_ATS_SchedulingHandle *GST_ats; | 127 | struct GNUNET_ATS_SchedulingHandle *GST_ats; |
128 | 128 | ||
129 | /** | 129 | /** |
130 | * ATS connectivity handle. | ||
131 | */ | ||
132 | struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect; | ||
133 | |||
134 | /** | ||
130 | * Hello address expiration | 135 | * Hello address expiration |
131 | */ | 136 | */ |
132 | struct GNUNET_TIME_Relative hello_expiration; | 137 | struct GNUNET_TIME_Relative hello_expiration; |
@@ -857,6 +862,8 @@ shutdown_task (void *cls, | |||
857 | GST_ats_done (); | 862 | GST_ats_done (); |
858 | GNUNET_ATS_scheduling_done (GST_ats); | 863 | GNUNET_ATS_scheduling_done (GST_ats); |
859 | GST_ats = NULL; | 864 | GST_ats = NULL; |
865 | GNUNET_ATS_connectivity_done (GST_ats_connect); | ||
866 | GST_ats_connect = NULL; | ||
860 | GST_clients_stop (); | 867 | GST_clients_stop (); |
861 | GST_blacklist_stop (); | 868 | GST_blacklist_stop (); |
862 | GST_hello_stop (); | 869 | GST_hello_stop (); |
@@ -986,6 +993,7 @@ run (void *cls, | |||
986 | GST_hello_start (friend_only, &process_hello_update, NULL ); | 993 | GST_hello_start (friend_only, &process_hello_update, NULL ); |
987 | GNUNET_assert(NULL != GST_hello_get()); | 994 | GNUNET_assert(NULL != GST_hello_get()); |
988 | GST_blacklist_start (GST_server, GST_cfg, &GST_my_identity); | 995 | GST_blacklist_start (GST_server, GST_cfg, &GST_my_identity); |
996 | GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg); | ||
989 | GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, | 997 | GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, |
990 | &ats_request_address_change, | 998 | &ats_request_address_change, |
991 | NULL); | 999 | NULL); |
diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h index 350ae5b6c..f60f18692 100644 --- a/src/transport/gnunet-service-transport.h +++ b/src/transport/gnunet-service-transport.h | |||
@@ -63,6 +63,11 @@ extern struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key; | |||
63 | */ | 63 | */ |
64 | extern struct GNUNET_ATS_SchedulingHandle *GST_ats; | 64 | extern struct GNUNET_ATS_SchedulingHandle *GST_ats; |
65 | 65 | ||
66 | /** | ||
67 | * ATS connectivity handle. | ||
68 | */ | ||
69 | extern struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect; | ||
70 | |||
66 | 71 | ||
67 | /** | 72 | /** |
68 | * Function to call when a peer's address has changed | 73 | * Function to call when a peer's address has changed |
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index bcbc4601e..49b026e7a 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -373,7 +373,7 @@ struct NeighbourMapEntry | |||
373 | /** | 373 | /** |
374 | * ATS address suggest handle | 374 | * ATS address suggest handle |
375 | */ | 375 | */ |
376 | struct GNUNET_ATS_SuggestHandle *suggest_handle; | 376 | struct GNUNET_ATS_ConnectivitySuggestHandle *suggest_handle; |
377 | 377 | ||
378 | /** | 378 | /** |
379 | * Time where we should cut the connection (timeout) if we don't | 379 | * Time where we should cut the connection (timeout) if we don't |
@@ -1047,7 +1047,7 @@ free_neighbour (struct NeighbourMapEntry *n, | |||
1047 | /* Cancel address requests for this peer */ | 1047 | /* Cancel address requests for this peer */ |
1048 | if (NULL != n->suggest_handle) | 1048 | if (NULL != n->suggest_handle) |
1049 | { | 1049 | { |
1050 | GNUNET_ATS_suggest_address_cancel (GST_ats, &n->id); | 1050 | GNUNET_ATS_connectivity_suggest_cancel (n->suggest_handle); |
1051 | n->suggest_handle = NULL; | 1051 | n->suggest_handle = NULL; |
1052 | } | 1052 | } |
1053 | 1053 | ||
@@ -2173,8 +2173,8 @@ try_connect_bl_check_cont (void *cls, | |||
2173 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 2173 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); |
2174 | GNUNET_ATS_reset_backoff (GST_ats, peer); | 2174 | GNUNET_ATS_reset_backoff (GST_ats, peer); |
2175 | GNUNET_assert (NULL == n->suggest_handle); | 2175 | GNUNET_assert (NULL == n->suggest_handle); |
2176 | n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, | 2176 | n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect, |
2177 | peer); | 2177 | peer); |
2178 | } | 2178 | } |
2179 | 2179 | ||
2180 | 2180 | ||
@@ -2321,7 +2321,8 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, | |||
2321 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, | 2321 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, |
2322 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 2322 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); |
2323 | if (NULL == n->suggest_handle) | 2323 | if (NULL == n->suggest_handle) |
2324 | n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, peer); | 2324 | n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect, |
2325 | peer); | ||
2325 | break; | 2326 | break; |
2326 | case GNUNET_TRANSPORT_PS_INIT_ATS: | 2327 | case GNUNET_TRANSPORT_PS_INIT_ATS: |
2327 | /* SYN message takes priority over us asking ATS for address: | 2328 | /* SYN message takes priority over us asking ATS for address: |
@@ -2375,7 +2376,8 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, | |||
2375 | n->ack_state = ACK_SEND_SYN_ACK; | 2376 | n->ack_state = ACK_SEND_SYN_ACK; |
2376 | n->connect_ack_timestamp = ts; | 2377 | n->connect_ack_timestamp = ts; |
2377 | /* Request an address for the peer */ | 2378 | /* Request an address for the peer */ |
2378 | n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, peer); | 2379 | n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect, |
2380 | peer); | ||
2379 | GNUNET_ATS_reset_backoff (GST_ats, peer); | 2381 | GNUNET_ATS_reset_backoff (GST_ats, peer); |
2380 | set_state (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS); | 2382 | set_state (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS); |
2381 | break; | 2383 | break; |