diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/Makefile.am | 35 | ||||
-rw-r--r-- | src/ats/ats_api_performance.c | 390 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 248 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 227 | ||||
-rw-r--r-- | src/ats/libgnunet_plugin_ats_mlp.c (renamed from src/ats/gnunet-service-ats-solver_mlp.c) | 123 | ||||
-rw-r--r-- | src/ats/libgnunet_plugin_ats_mlp.h (renamed from src/ats/gnunet-service-ats-solver_mlp.h) | 7 | ||||
-rw-r--r-- | src/ats/libgnunet_plugin_ats_proportional.c (renamed from src/ats/gnunet-service-ats-solver_proportional.c) | 281 | ||||
-rw-r--r-- | src/ats/libgnunet_plugin_ats_proportional.h (renamed from src/ats/gnunet-service-ats-solver_proportional.h) | 40 | ||||
-rw-r--r-- | src/include/gnunet_ats_plugin.h | 328 |
9 files changed, 806 insertions, 873 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 1fbd434ee..b86c53724 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -1,5 +1,7 @@ | |||
1 | AM_CPPFLAGS = -I$(top_srcdir)/src/include | 1 | AM_CPPFLAGS = -I$(top_srcdir)/src/include |
2 | 2 | ||
3 | plugindir = $(libdir)/gnunet | ||
4 | |||
3 | pkgcfgdir= $(pkgdatadir)/config.d/ | 5 | pkgcfgdir= $(pkgdatadir)/config.d/ |
4 | 6 | ||
5 | libexecdir= $(pkglibdir)/libexec/ | 7 | libexecdir= $(pkglibdir)/libexec/ |
@@ -17,7 +19,7 @@ endif | |||
17 | 19 | ||
18 | if HAVE_LIBGLPK | 20 | if HAVE_LIBGLPK |
19 | GN_LIBGLPK = -lglpk | 21 | GN_LIBGLPK = -lglpk |
20 | GN_MLP_SRC = gnunet-service-ats-solver_mlp.c gnunet-service-ats-solver_mlp.h | 22 | GN_MLP_LIB = libgnunet_plugin_ats_mlp.la |
21 | GN_MLP_TEST = test_ats_mlp | 23 | GN_MLP_TEST = test_ats_mlp |
22 | GN_MLP_TEST_UPDATE = test_ats_mlp_update | 24 | GN_MLP_TEST_UPDATE = test_ats_mlp_update |
23 | GN_MLP_TEST_AVG = test_ats_mlp_averaging | 25 | GN_MLP_TEST_AVG = test_ats_mlp_averaging |
@@ -32,6 +34,10 @@ endif | |||
32 | 34 | ||
33 | lib_LTLIBRARIES = libgnunetats.la | 35 | lib_LTLIBRARIES = libgnunetats.la |
34 | 36 | ||
37 | plugin_LTLIBRARIES = \ | ||
38 | libgnunet_plugin_ats_proportional.la \ | ||
39 | libgnunet_plugin_ats_mlp.la | ||
40 | |||
35 | libgnunetats_la_SOURCES = \ | 41 | libgnunetats_la_SOURCES = \ |
36 | ats_api_scheduling.c \ | 42 | ats_api_scheduling.c \ |
37 | ats_api_performance.c | 43 | ats_api_performance.c |
@@ -48,13 +54,14 @@ libgnunetats_la_LDFLAGS = \ | |||
48 | libexec_PROGRAMS = \ | 54 | libexec_PROGRAMS = \ |
49 | gnunet-service-ats | 55 | gnunet-service-ats |
50 | 56 | ||
57 | # gnunet-service-ats-solver_proportional.c gnunet-service-ats-solver_proportional.h | ||
58 | # $(GN_MLP_SRC) | ||
59 | # gnunet-service-ats-solver_ril.c gnunet-service-ats-solver_ril.h | ||
60 | |||
51 | gnunet_service_ats_SOURCES = \ | 61 | gnunet_service_ats_SOURCES = \ |
52 | gnunet-service-ats.c gnunet-service-ats.h\ | 62 | gnunet-service-ats.c gnunet-service-ats.h\ |
53 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ | 63 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ |
54 | gnunet-service-ats_normalization.c gnunet-service-ats_normalization.h \ | 64 | gnunet-service-ats_normalization.c gnunet-service-ats_normalization.h \ |
55 | gnunet-service-ats-solver_proportional.c gnunet-service-ats-solver_proportional.h \ | ||
56 | $(GN_MLP_SRC) \ | ||
57 | gnunet-service-ats-solver_ril.c gnunet-service-ats-solver_ril.h \ | ||
58 | gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ | 65 | gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ |
59 | gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ | 66 | gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ |
60 | gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h | 67 | gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h |
@@ -62,7 +69,6 @@ gnunet_service_ats_LDADD = \ | |||
62 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 69 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
63 | $(top_builddir)/src/util/libgnunetutil.la \ | 70 | $(top_builddir)/src/util/libgnunetutil.la \ |
64 | libgnunetats.la \ | 71 | libgnunetats.la \ |
65 | $(GN_LIBGLPK) \ | ||
66 | $(GN_LIBINTL) | 72 | $(GN_LIBINTL) |
67 | gnunet_service_ats_DEPENDENCIES = \ | 73 | gnunet_service_ats_DEPENDENCIES = \ |
68 | libgnunetats.la | 74 | libgnunetats.la |
@@ -121,6 +127,25 @@ if ENABLE_TEST_RUN | |||
121 | TESTS = $(check_PROGRAMS) | 127 | TESTS = $(check_PROGRAMS) |
122 | endif | 128 | endif |
123 | 129 | ||
130 | libgnunet_plugin_ats_proportional_la_SOURCES = \ | ||
131 | libgnunet_plugin_ats_proportional.c | ||
132 | libgnunet_plugin_ats_proportional_la_LIBADD = \ | ||
133 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
134 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
135 | $(LTLIBINTL) | ||
136 | |||
137 | if HAVE_LIBGLPK | ||
138 | endif | ||
139 | libgnunet_plugin_ats_mlp_la_SOURCES = \ | ||
140 | libgnunet_plugin_ats_mlp.c | ||
141 | libgnunet_plugin_ats_mlp_la_LIBADD = \ | ||
142 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
143 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
144 | $(GN_LIBGLPK) | ||
145 | libgnunet_plugin_ats_mlp_la_LDFLAGS = \ | ||
146 | $(GN_LIBGLPK) | ||
147 | |||
148 | |||
124 | # scheduling API tests | 149 | # scheduling API tests |
125 | 150 | ||
126 | test_ats_api_scheduling_init_SOURCES = \ | 151 | test_ats_api_scheduling_init_SOURCES = \ |
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index 838acca2f..390531d9f 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c | |||
@@ -1,33 +1,32 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010,2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2010,2011 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 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 | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/ats_api_performance.c | 21 | * @file ats/ats_api_performance.c |
22 | * @brief automatic transport selection and outbound bandwidth determination | 22 | * @brief automatic transport selection and outbound bandwidth determination |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_ats_service.h" | 27 | #include "gnunet_ats_service.h" |
28 | #include "ats.h" | 28 | #include "ats.h" |
29 | 29 | ||
30 | |||
31 | /** | 30 | /** |
32 | * Message in linked list we should send to the ATS service. The | 31 | * Message in linked list we should send to the ATS service. The |
33 | * actual binary message follows this struct. | 32 | * actual binary message follows this struct. |
@@ -56,7 +55,6 @@ struct PendingMessage | |||
56 | int is_init; | 55 | int is_init; |
57 | }; | 56 | }; |
58 | 57 | ||
59 | |||
60 | /** | 58 | /** |
61 | * Linked list of pending reservations. | 59 | * Linked list of pending reservations. |
62 | */ | 60 | */ |
@@ -104,7 +102,6 @@ struct GNUNET_ATS_ReservationContext | |||
104 | int undo; | 102 | int undo; |
105 | }; | 103 | }; |
106 | 104 | ||
107 | |||
108 | /** | 105 | /** |
109 | * Linked list of pending reservations. | 106 | * Linked list of pending reservations. |
110 | */ | 107 | */ |
@@ -157,8 +154,6 @@ struct GNUNET_ATS_AddressListHandle | |||
157 | uint32_t id; | 154 | uint32_t id; |
158 | }; | 155 | }; |
159 | 156 | ||
160 | |||
161 | |||
162 | /** | 157 | /** |
163 | * ATS Handle to obtain and/or modify performance information. | 158 | * ATS Handle to obtain and/or modify performance information. |
164 | */ | 159 | */ |
@@ -215,7 +210,6 @@ struct GNUNET_ATS_PerformanceHandle | |||
215 | */ | 210 | */ |
216 | struct GNUNET_ATS_AddressListHandle *addresslist_tail; | 211 | struct GNUNET_ATS_AddressListHandle *addresslist_tail; |
217 | 212 | ||
218 | |||
219 | /** | 213 | /** |
220 | * Current request for transmission to ATS. | 214 | * Current request for transmission to ATS. |
221 | */ | 215 | */ |
@@ -237,7 +231,6 @@ struct GNUNET_ATS_PerformanceHandle | |||
237 | uint32_t id; | 231 | uint32_t id; |
238 | }; | 232 | }; |
239 | 233 | ||
240 | |||
241 | /** | 234 | /** |
242 | * Re-establish the connection to the ATS service. | 235 | * Re-establish the connection to the ATS service. |
243 | * | 236 | * |
@@ -246,7 +239,6 @@ struct GNUNET_ATS_PerformanceHandle | |||
246 | static void | 239 | static void |
247 | reconnect (struct GNUNET_ATS_PerformanceHandle *ph); | 240 | reconnect (struct GNUNET_ATS_PerformanceHandle *ph); |
248 | 241 | ||
249 | |||
250 | /** | 242 | /** |
251 | * Re-establish the connection to the ATS service. | 243 | * Re-establish the connection to the ATS service. |
252 | * | 244 | * |
@@ -262,7 +254,6 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
262 | reconnect (ph); | 254 | reconnect (ph); |
263 | } | 255 | } |
264 | 256 | ||
265 | |||
266 | /** | 257 | /** |
267 | * Transmit messages from the message queue to the service | 258 | * Transmit messages from the message queue to the service |
268 | * (if there are any, and if we are not already trying). | 259 | * (if there are any, and if we are not already trying). |
@@ -272,7 +263,6 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
272 | static void | 263 | static void |
273 | do_transmit (struct GNUNET_ATS_PerformanceHandle *ph); | 264 | do_transmit (struct GNUNET_ATS_PerformanceHandle *ph); |
274 | 265 | ||
275 | |||
276 | /** | 266 | /** |
277 | * Type of a function to call when we receive a message | 267 | * Type of a function to call when we receive a message |
278 | * from the service. | 268 | * from the service. |
@@ -307,14 +297,13 @@ transmit_message_to_ats (void *cls, size_t size, void *buf) | |||
307 | memcpy (&cbuf[ret], &p[1], p->size); | 297 | memcpy (&cbuf[ret], &p[1], p->size); |
308 | ret += p->size; | 298 | ret += p->size; |
309 | size -= p->size; | 299 | size -= p->size; |
310 | GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p); | 300 | GNUNET_CONTAINER_DLL_remove(ph->pending_head, ph->pending_tail, p); |
311 | GNUNET_free (p); | 301 | GNUNET_free(p); |
312 | } | 302 | } |
313 | do_transmit (ph); | 303 | do_transmit (ph); |
314 | return ret; | 304 | return ret; |
315 | } | 305 | } |
316 | 306 | ||
317 | |||
318 | /** | 307 | /** |
319 | * Transmit messages from the message queue to the service | 308 | * Transmit messages from the message queue to the service |
320 | * (if there are any, and if we are not already trying). | 309 | * (if there are any, and if we are not already trying). |
@@ -331,15 +320,11 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph) | |||
331 | if (NULL == (p = ph->pending_head)) | 320 | if (NULL == (p = ph->pending_head)) |
332 | return; | 321 | return; |
333 | if (NULL == ph->client) | 322 | if (NULL == ph->client) |
334 | return; /* currently reconnecting */ | 323 | return; /* currently reconnecting */ |
335 | ph->th = | 324 | ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size, |
336 | GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size, | 325 | GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &transmit_message_to_ats, ph); |
337 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
338 | GNUNET_YES, &transmit_message_to_ats, | ||
339 | ph); | ||
340 | } | 326 | } |
341 | 327 | ||
342 | |||
343 | /** | 328 | /** |
344 | * We received a peer information message. Validate and process it. | 329 | * We received a peer information message. Validate and process it. |
345 | * | 330 | * |
@@ -349,7 +334,7 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph) | |||
349 | */ | 334 | */ |
350 | static int | 335 | static int |
351 | process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | 336 | process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, |
352 | const struct GNUNET_MessageHeader *msg) | 337 | const struct GNUNET_MessageHeader *msg) |
353 | { | 338 | { |
354 | const struct PeerInformationMessage *pi; | 339 | const struct PeerInformationMessage *pi; |
355 | const struct GNUNET_ATS_Information *atsi; | 340 | const struct GNUNET_ATS_Information *atsi; |
@@ -361,9 +346,9 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
361 | uint32_t ats_count; | 346 | uint32_t ats_count; |
362 | int addr_active; | 347 | int addr_active; |
363 | 348 | ||
364 | if (ntohs (msg->size) < sizeof (struct PeerInformationMessage)) | 349 | if (ntohs (msg->size) < sizeof(struct PeerInformationMessage)) |
365 | { | 350 | { |
366 | GNUNET_break (0); | 351 | GNUNET_break(0); |
367 | return GNUNET_SYSERR; | 352 | return GNUNET_SYSERR; |
368 | } | 353 | } |
369 | 354 | ||
@@ -375,31 +360,31 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
375 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; | 360 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; |
376 | plugin_address = (const char *) &atsi[ats_count]; | 361 | plugin_address = (const char *) &atsi[ats_count]; |
377 | plugin_name = &plugin_address[plugin_address_length]; | 362 | plugin_name = &plugin_address[plugin_address_length]; |
378 | if ((plugin_address_length + plugin_name_length + | 363 | if ((plugin_address_length + plugin_name_length |
379 | ats_count * sizeof (struct GNUNET_ATS_Information) + | 364 | + ats_count * sizeof(struct GNUNET_ATS_Information) |
380 | sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || | 365 | + sizeof(struct PeerInformationMessage) != ntohs (msg->size)) |
381 | (ats_count > | 366 | || (ats_count |
382 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) | 367 | > GNUNET_SERVER_MAX_MESSAGE_SIZE |
368 | / sizeof(struct GNUNET_ATS_Information)) | ||
383 | || (plugin_name[plugin_name_length - 1] != '\0')) | 369 | || (plugin_name[plugin_name_length - 1] != '\0')) |
384 | { | 370 | { |
385 | GNUNET_break (0); | 371 | GNUNET_break(0); |
386 | return GNUNET_SYSERR; | 372 | return GNUNET_SYSERR; |
387 | } | 373 | } |
388 | 374 | ||
389 | if (NULL != ph->addr_info_cb) | 375 | if (NULL != ph->addr_info_cb) |
390 | { | 376 | { |
391 | address.peer = pi->peer; | 377 | address.peer = pi->peer; |
392 | address.address = plugin_address; | 378 | address.address = plugin_address; |
393 | address.address_length = plugin_address_length; | 379 | address.address_length = plugin_address_length; |
394 | address.transport_name = plugin_name; | 380 | address.transport_name = plugin_name; |
395 | 381 | ||
396 | ph->addr_info_cb (ph->addr_info_cb_cls, &address, addr_active, pi->bandwidth_out, pi->bandwidth_in, | 382 | ph->addr_info_cb (ph->addr_info_cb_cls, &address, addr_active, |
397 | atsi, ats_count); | 383 | pi->bandwidth_out, pi->bandwidth_in, atsi, ats_count); |
398 | } | 384 | } |
399 | return GNUNET_OK; | 385 | return GNUNET_OK; |
400 | } | 386 | } |
401 | 387 | ||
402 | |||
403 | /** | 388 | /** |
404 | * We received a reservation result message. Validate and process it. | 389 | * We received a reservation result message. Validate and process it. |
405 | * | 390 | * |
@@ -409,47 +394,46 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
409 | */ | 394 | */ |
410 | static int | 395 | static int |
411 | process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, | 396 | process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, |
412 | const struct GNUNET_MessageHeader *msg) | 397 | const struct GNUNET_MessageHeader *msg) |
413 | { | 398 | { |
414 | const struct ReservationResultMessage *rr; | 399 | const struct ReservationResultMessage *rr; |
415 | struct GNUNET_ATS_ReservationContext *rc; | 400 | struct GNUNET_ATS_ReservationContext *rc; |
416 | int32_t amount; | 401 | int32_t amount; |
417 | 402 | ||
418 | if (ntohs (msg->size) < sizeof (struct ReservationResultMessage)) | 403 | if (ntohs (msg->size) < sizeof(struct ReservationResultMessage)) |
419 | { | 404 | { |
420 | GNUNET_break (0); | 405 | GNUNET_break(0); |
421 | return GNUNET_SYSERR; | 406 | return GNUNET_SYSERR; |
422 | } | 407 | } |
423 | rr = (const struct ReservationResultMessage *) msg; | 408 | rr = (const struct ReservationResultMessage *) msg; |
424 | amount = ntohl (rr->amount); | 409 | amount = ntohl (rr->amount); |
425 | rc = ph->reservation_head; | 410 | rc = ph->reservation_head; |
426 | if (0 != memcmp (&rr->peer, &rc->peer, sizeof (struct GNUNET_PeerIdentity))) | 411 | if (0 != memcmp (&rr->peer, &rc->peer, sizeof(struct GNUNET_PeerIdentity))) |
427 | { | 412 | { |
428 | GNUNET_break (0); | 413 | GNUNET_break(0); |
429 | return GNUNET_SYSERR; | 414 | return GNUNET_SYSERR; |
430 | } | 415 | } |
431 | GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, rc); | 416 | GNUNET_CONTAINER_DLL_remove(ph->reservation_head, ph->reservation_tail, rc); |
432 | if ((amount == 0) || (rc->rcb != NULL)) | 417 | if ((amount == 0) || (rc->rcb != NULL )) |
433 | { | 418 | { |
434 | /* tell client if not cancelled */ | 419 | /* tell client if not cancelled */ |
435 | if (rc->rcb != NULL) | 420 | if (rc->rcb != NULL ) |
436 | rc->rcb (rc->rcb_cls, &rr->peer, amount, | 421 | rc->rcb (rc->rcb_cls, &rr->peer, amount, |
437 | GNUNET_TIME_relative_ntoh (rr->res_delay)); | 422 | GNUNET_TIME_relative_ntoh (rr->res_delay)); |
438 | GNUNET_free (rc); | 423 | GNUNET_free(rc); |
439 | return GNUNET_OK; | 424 | return GNUNET_OK; |
440 | } | 425 | } |
441 | /* amount non-zero, but client cancelled, consider undo! */ | 426 | /* amount non-zero, but client cancelled, consider undo! */ |
442 | if (GNUNET_YES != rc->undo) | 427 | if (GNUNET_YES != rc->undo) |
443 | { | 428 | { |
444 | GNUNET_free (rc); | 429 | GNUNET_free(rc); |
445 | return GNUNET_OK; /* do not try to undo failed undos or negative amounts */ | 430 | return GNUNET_OK; /* do not try to undo failed undos or negative amounts */ |
446 | } | 431 | } |
447 | GNUNET_free (rc); | 432 | GNUNET_free(rc); |
448 | (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL); | 433 | (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL ); |
449 | return GNUNET_OK; | 434 | return GNUNET_OK; |
450 | } | 435 | } |
451 | 436 | ||
452 | |||
453 | /** | 437 | /** |
454 | * We received a reservation result message. Validate and process it. | 438 | * We received a reservation result message. Validate and process it. |
455 | * | 439 | * |
@@ -459,7 +443,7 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
459 | */ | 443 | */ |
460 | static int | 444 | static int |
461 | process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | 445 | process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, |
462 | const struct GNUNET_MessageHeader *msg) | 446 | const struct GNUNET_MessageHeader *msg) |
463 | { | 447 | { |
464 | const struct PeerInformationMessage *pi; | 448 | const struct PeerInformationMessage *pi; |
465 | struct GNUNET_ATS_AddressListHandle *alh; | 449 | struct GNUNET_ATS_AddressListHandle *alh; |
@@ -476,13 +460,13 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
476 | uint32_t active; | 460 | uint32_t active; |
477 | uint32_t id; | 461 | uint32_t id; |
478 | 462 | ||
479 | if (ntohs (msg->size) < sizeof (struct PeerInformationMessage)) | 463 | if (ntohs (msg->size) < sizeof(struct PeerInformationMessage)) |
480 | { | 464 | { |
481 | GNUNET_break (0); | 465 | GNUNET_break(0); |
482 | return GNUNET_SYSERR; | 466 | return GNUNET_SYSERR; |
483 | } | 467 | } |
484 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 468 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Received %s message\n"), |
485 | _("Received %s message\n"), "ATS_ADDRESSLIST_RESPONSE"); | 469 | "ATS_ADDRESSLIST_RESPONSE"); |
486 | 470 | ||
487 | pi = (const struct PeerInformationMessage *) msg; | 471 | pi = (const struct PeerInformationMessage *) msg; |
488 | id = ntohl (pi->id); | 472 | id = ntohl (pi->id); |
@@ -493,49 +477,47 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
493 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; | 477 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; |
494 | plugin_address = (const char *) &atsi[ats_count]; | 478 | plugin_address = (const char *) &atsi[ats_count]; |
495 | plugin_name = &plugin_address[plugin_address_length]; | 479 | plugin_name = &plugin_address[plugin_address_length]; |
496 | if ((plugin_address_length + plugin_name_length + | 480 | if ((plugin_address_length + plugin_name_length |
497 | ats_count * sizeof (struct GNUNET_ATS_Information) + | 481 | + ats_count * sizeof(struct GNUNET_ATS_Information) |
498 | sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || | 482 | + sizeof(struct PeerInformationMessage) != ntohs (msg->size)) |
499 | (ats_count > | 483 | || (ats_count |
500 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) | 484 | > GNUNET_SERVER_MAX_MESSAGE_SIZE |
485 | / sizeof(struct GNUNET_ATS_Information)) | ||
501 | || (plugin_name[plugin_name_length - 1] != '\0')) | 486 | || (plugin_name[plugin_name_length - 1] != '\0')) |
502 | { | 487 | { |
503 | GNUNET_break (0); | 488 | GNUNET_break(0); |
504 | return GNUNET_SYSERR; | 489 | return GNUNET_SYSERR; |
505 | } | 490 | } |
506 | 491 | ||
507 | next = ph->addresslist_head; | 492 | next = ph->addresslist_head; |
508 | while (NULL != (alh = next)) | 493 | while (NULL != (alh = next)) |
509 | { | 494 | { |
510 | next = alh->next; | 495 | next = alh->next; |
511 | if (alh->id == id) | 496 | if (alh->id == id) |
512 | break; | 497 | break; |
513 | } | 498 | } |
514 | if (NULL == alh) | 499 | if (NULL == alh) |
515 | { | 500 | { |
516 | /* was canceled */ | 501 | /* was canceled */ |
517 | return GNUNET_SYSERR; | 502 | return GNUNET_SYSERR; |
518 | } | 503 | } |
519 | 504 | ||
520 | memset (&allzeros, '\0', sizeof (allzeros)); | 505 | memset (&allzeros, '\0', sizeof(allzeros)); |
521 | if ((0 == memcmp (&allzeros, &pi->peer, sizeof (allzeros))) && | 506 | if ((0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) |
522 | (0 == plugin_name_length) && | 507 | && (0 == plugin_name_length) && (0 == plugin_address_length) |
523 | (0 == plugin_address_length) && | 508 | && (0 == ats_count)) |
524 | (0 == ats_count)) | ||
525 | { | 509 | { |
526 | /* Done */ | 510 | /* Done */ |
527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 511 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Received last message for %s \n"), |
528 | _("Received last message for %s \n"), "ATS_ADDRESSLIST_RESPONSE"); | 512 | "ATS_ADDRESSLIST_RESPONSE"); |
529 | bandwidth_zero.value__ = htonl (0); | 513 | bandwidth_zero.value__ = htonl (0); |
530 | if (NULL != alh->cb) | 514 | if (NULL != alh->cb) |
531 | alh->cb (ph->addr_info_cb_cls, | 515 | alh->cb (ph->addr_info_cb_cls, NULL, GNUNET_NO, bandwidth_zero, |
532 | NULL, | 516 | bandwidth_zero, NULL, 0); |
533 | GNUNET_NO, | 517 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, ph->addresslist_tail, |
534 | bandwidth_zero, bandwidth_zero, | 518 | alh); |
535 | NULL, 0); | 519 | GNUNET_free(alh); |
536 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, ph->addresslist_tail, alh); | 520 | return GNUNET_OK; |
537 | GNUNET_free (alh); | ||
538 | return GNUNET_OK; | ||
539 | } | 521 | } |
540 | 522 | ||
541 | address.peer = pi->peer; | 523 | address.peer = pi->peer; |
@@ -546,16 +528,12 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
546 | if ((GNUNET_YES == alh->all_addresses) || (GNUNET_YES == active)) | 528 | if ((GNUNET_YES == alh->all_addresses) || (GNUNET_YES == active)) |
547 | { | 529 | { |
548 | if (NULL != alh->cb) | 530 | if (NULL != alh->cb) |
549 | alh->cb (ph->addr_info_cb_cls, | 531 | alh->cb (ph->addr_info_cb_cls, &address, active, pi->bandwidth_out, |
550 | &address, | 532 | pi->bandwidth_in, atsi, ats_count); |
551 | active, | ||
552 | pi->bandwidth_out, pi->bandwidth_in, | ||
553 | atsi, ats_count); | ||
554 | } | 533 | } |
555 | return GNUNET_OK; | 534 | return GNUNET_OK; |
556 | } | 535 | } |
557 | 536 | ||
558 | |||
559 | /** | 537 | /** |
560 | * Type of a function to call when we receive a message | 538 | * Type of a function to call when we receive a message |
561 | * from the service. | 539 | * from the service. |
@@ -585,26 +563,23 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
585 | goto reconnect; | 563 | goto reconnect; |
586 | break; | 564 | break; |
587 | default: | 565 | default: |
588 | GNUNET_break (0); | 566 | GNUNET_break(0); |
589 | goto reconnect; | 567 | goto reconnect; |
590 | } | 568 | } |
591 | GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, | 569 | GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, |
592 | GNUNET_TIME_UNIT_FOREVER_REL); | 570 | GNUNET_TIME_UNIT_FOREVER_REL); |
593 | return; | 571 | return; |
594 | reconnect: | 572 | reconnect: if (NULL != ph->th) |
595 | if (NULL != ph->th) | ||
596 | { | 573 | { |
597 | GNUNET_CLIENT_notify_transmit_ready_cancel (ph->th); | 574 | GNUNET_CLIENT_notify_transmit_ready_cancel (ph->th); |
598 | ph->th = NULL; | 575 | ph->th = NULL; |
599 | } | 576 | } |
600 | GNUNET_CLIENT_disconnect (ph->client); | 577 | GNUNET_CLIENT_disconnect (ph->client); |
601 | ph->client = NULL; | 578 | ph->client = NULL; |
602 | ph->task = | 579 | ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
603 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task, | 580 | &reconnect_task, ph); |
604 | ph); | ||
605 | } | 581 | } |
606 | 582 | ||
607 | |||
608 | /** | 583 | /** |
609 | * Re-establish the connection to the ATS service. | 584 | * Re-establish the connection to the ATS service. |
610 | * | 585 | * |
@@ -616,30 +591,28 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
616 | struct PendingMessage *p; | 591 | struct PendingMessage *p; |
617 | struct ClientStartMessage *init; | 592 | struct ClientStartMessage *init; |
618 | 593 | ||
619 | GNUNET_assert (NULL == ph->client); | 594 | GNUNET_assert(NULL == ph->client); |
620 | ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg); | 595 | ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg); |
621 | GNUNET_assert (NULL != ph->client); | 596 | GNUNET_assert(NULL != ph->client); |
622 | GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, | 597 | GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, |
623 | GNUNET_TIME_UNIT_FOREVER_REL); | 598 | GNUNET_TIME_UNIT_FOREVER_REL); |
624 | if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init)) | 599 | if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init)) |
625 | { | 600 | { |
626 | p = GNUNET_malloc (sizeof (struct PendingMessage) + | 601 | p = GNUNET_malloc (sizeof (struct PendingMessage) + |
627 | sizeof (struct ClientStartMessage)); | 602 | sizeof (struct ClientStartMessage)); |
628 | p->size = sizeof (struct ClientStartMessage); | 603 | p->size = sizeof(struct ClientStartMessage); |
629 | p->is_init = GNUNET_YES; | 604 | p->is_init = GNUNET_YES; |
630 | init = (struct ClientStartMessage *) &p[1]; | 605 | init = (struct ClientStartMessage *) &p[1]; |
631 | init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); | 606 | init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); |
632 | init->header.size = htons (sizeof (struct ClientStartMessage)); | 607 | init->header.size = htons (sizeof(struct ClientStartMessage)); |
633 | init->start_flag = | 608 | init->start_flag = htonl ( |
634 | htonl ((NULL ==ph->addr_info_cb) ? | 609 | (NULL == ph->addr_info_cb) ? |
635 | START_FLAG_PERFORMANCE_NO_PIC : START_FLAG_PERFORMANCE_WITH_PIC); | 610 | START_FLAG_PERFORMANCE_NO_PIC : START_FLAG_PERFORMANCE_WITH_PIC); |
636 | GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p); | 611 | GNUNET_CONTAINER_DLL_insert(ph->pending_head, ph->pending_tail, p); |
637 | } | 612 | } |
638 | do_transmit (ph); | 613 | do_transmit (ph); |
639 | } | 614 | } |
640 | 615 | ||
641 | |||
642 | |||
643 | /** | 616 | /** |
644 | * Get handle to access performance API of the ATS subsystem. | 617 | * Get handle to access performance API of the ATS subsystem. |
645 | * | 618 | * |
@@ -651,8 +624,7 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
651 | */ | 624 | */ |
652 | struct GNUNET_ATS_PerformanceHandle * | 625 | struct GNUNET_ATS_PerformanceHandle * |
653 | GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | 626 | GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, |
654 | GNUNET_ATS_AddressInformationCallback addr_info_cb, | 627 | GNUNET_ATS_AddressInformationCallback addr_info_cb, void *addr_info_cb_cls) |
655 | void *addr_info_cb_cls) | ||
656 | { | 628 | { |
657 | struct GNUNET_ATS_PerformanceHandle *ph; | 629 | struct GNUNET_ATS_PerformanceHandle *ph; |
658 | 630 | ||
@@ -660,7 +632,7 @@ GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
660 | ph->cfg = cfg; | 632 | ph->cfg = cfg; |
661 | ph->addr_info_cb = addr_info_cb; | 633 | ph->addr_info_cb = addr_info_cb; |
662 | ph->addr_info_cb_cls = addr_info_cb_cls; | 634 | ph->addr_info_cb_cls = addr_info_cb_cls; |
663 | ph->id = 0; | 635 | ph->id = 0; |
664 | reconnect (ph); | 636 | reconnect (ph); |
665 | return ph; | 637 | return ph; |
666 | } | 638 | } |
@@ -679,21 +651,20 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
679 | 651 | ||
680 | while (NULL != (p = ph->pending_head)) | 652 | while (NULL != (p = ph->pending_head)) |
681 | { | 653 | { |
682 | GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p); | 654 | GNUNET_CONTAINER_DLL_remove(ph->pending_head, ph->pending_tail, p); |
683 | GNUNET_free (p); | 655 | GNUNET_free(p); |
684 | } | 656 | } |
685 | while (NULL != (alh = ph->addresslist_head)) | 657 | while (NULL != (alh = ph->addresslist_head)) |
686 | { | 658 | { |
687 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, ph->addresslist_tail, | 659 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, ph->addresslist_tail, |
688 | alh); | 660 | alh); |
689 | GNUNET_free (alh); | 661 | GNUNET_free(alh); |
690 | } | 662 | } |
691 | while (NULL != (rc = ph->reservation_head)) | 663 | while (NULL != (rc = ph->reservation_head)) |
692 | { | 664 | { |
693 | GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, | 665 | GNUNET_CONTAINER_DLL_remove(ph->reservation_head, ph->reservation_tail, rc); |
694 | rc); | 666 | GNUNET_break(NULL == rc->rcb); |
695 | GNUNET_break (NULL == rc->rcb); | 667 | GNUNET_free(rc); |
696 | GNUNET_free (rc); | ||
697 | } | 668 | } |
698 | 669 | ||
699 | if (GNUNET_SCHEDULER_NO_TASK != ph->task) | 670 | if (GNUNET_SCHEDULER_NO_TASK != ph->task) |
@@ -706,10 +677,9 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
706 | GNUNET_CLIENT_disconnect (ph->client); | 677 | GNUNET_CLIENT_disconnect (ph->client); |
707 | ph->client = NULL; | 678 | ph->client = NULL; |
708 | } | 679 | } |
709 | GNUNET_free (ph); | 680 | GNUNET_free(ph); |
710 | } | 681 | } |
711 | 682 | ||
712 | |||
713 | /** | 683 | /** |
714 | * Reserve inbound bandwidth from the given peer. ATS will look at | 684 | * Reserve inbound bandwidth from the given peer. ATS will look at |
715 | * the current amount of traffic we receive from the peer and ensure | 685 | * the current amount of traffic we receive from the peer and ensure |
@@ -726,9 +696,8 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
726 | */ | 696 | */ |
727 | struct GNUNET_ATS_ReservationContext * | 697 | struct GNUNET_ATS_ReservationContext * |
728 | GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | 698 | GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, |
729 | const struct GNUNET_PeerIdentity *peer, | 699 | const struct GNUNET_PeerIdentity *peer, int32_t amount, |
730 | int32_t amount, | 700 | GNUNET_ATS_ReservationCallback rcb, void *rcb_cls) |
731 | GNUNET_ATS_ReservationCallback rcb, void *rcb_cls) | ||
732 | { | 701 | { |
733 | struct GNUNET_ATS_ReservationContext *rc; | 702 | struct GNUNET_ATS_ReservationContext *rc; |
734 | struct PendingMessage *p; | 703 | struct PendingMessage *p; |
@@ -739,26 +708,24 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | |||
739 | rc->peer = *peer; | 708 | rc->peer = *peer; |
740 | rc->rcb = rcb; | 709 | rc->rcb = rcb; |
741 | rc->rcb_cls = rcb_cls; | 710 | rc->rcb_cls = rcb_cls; |
742 | if ((rcb != NULL) && (amount > 0)) | 711 | if ((rcb != NULL )&& (amount > 0))rc->undo = GNUNET_YES; |
743 | rc->undo = GNUNET_YES; | 712 | GNUNET_CONTAINER_DLL_insert_tail(ph->reservation_head, ph->reservation_tail, |
744 | GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, ph->reservation_tail, | 713 | rc); |
745 | rc); | ||
746 | 714 | ||
747 | p = GNUNET_malloc (sizeof (struct PendingMessage) + | 715 | p = GNUNET_malloc (sizeof (struct PendingMessage) + |
748 | sizeof (struct ReservationRequestMessage)); | 716 | sizeof (struct ReservationRequestMessage)); |
749 | p->size = sizeof (struct ReservationRequestMessage); | 717 | p->size = sizeof(struct ReservationRequestMessage); |
750 | p->is_init = GNUNET_NO; | 718 | p->is_init = GNUNET_NO; |
751 | m = (struct ReservationRequestMessage *) &p[1]; | 719 | m = (struct ReservationRequestMessage *) &p[1]; |
752 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); | 720 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); |
753 | m->header.size = htons (sizeof (struct ReservationRequestMessage)); | 721 | m->header.size = htons (sizeof(struct ReservationRequestMessage)); |
754 | m->amount = htonl (amount); | 722 | m->amount = htonl (amount); |
755 | m->peer = *peer; | 723 | m->peer = *peer; |
756 | GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p); | 724 | GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p); |
757 | do_transmit (ph); | 725 | do_transmit (ph); |
758 | return rc; | 726 | return rc; |
759 | } | 727 | } |
760 | 728 | ||
761 | |||
762 | /** | 729 | /** |
763 | * Cancel request for reserving bandwidth. | 730 | * Cancel request for reserving bandwidth. |
764 | * | 731 | * |
@@ -783,23 +750,22 @@ GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc) | |||
783 | * @return ats performance context | 750 | * @return ats performance context |
784 | */ | 751 | */ |
785 | struct GNUNET_ATS_AddressListHandle* | 752 | struct GNUNET_ATS_AddressListHandle* |
786 | GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle, | 753 | GNUNET_ATS_performance_list_addresses ( |
787 | const struct GNUNET_PeerIdentity *peer, | 754 | struct GNUNET_ATS_PerformanceHandle *handle, |
788 | int all, | 755 | const struct GNUNET_PeerIdentity *peer, int all, |
789 | GNUNET_ATS_AddressInformationCallback infocb, | 756 | GNUNET_ATS_AddressInformationCallback infocb, void *infocb_cls) |
790 | void *infocb_cls) | ||
791 | { | 757 | { |
792 | struct GNUNET_ATS_AddressListHandle *alh; | 758 | struct GNUNET_ATS_AddressListHandle *alh; |
793 | struct PendingMessage *p; | 759 | struct PendingMessage *p; |
794 | struct AddressListRequestMessage *m; | 760 | struct AddressListRequestMessage *m; |
795 | 761 | ||
796 | GNUNET_assert (NULL != handle); | 762 | GNUNET_assert(NULL != handle); |
797 | if (NULL == infocb) | 763 | if (NULL == infocb) |
798 | return NULL; | 764 | return NULL ; |
799 | 765 | ||
800 | alh = GNUNET_malloc (sizeof (struct GNUNET_ATS_AddressListHandle)); | 766 | alh = GNUNET_malloc (sizeof (struct GNUNET_ATS_AddressListHandle)); |
801 | alh->id = handle->id; | 767 | alh->id = handle->id; |
802 | handle->id ++; | 768 | handle->id++; |
803 | alh->cb = infocb; | 769 | alh->cb = infocb; |
804 | alh->cb_cls = infocb_cls; | 770 | alh->cb_cls = infocb_cls; |
805 | alh->ph = handle; | 771 | alh->ph = handle; |
@@ -808,49 +774,51 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *hand | |||
808 | alh->all_peers = GNUNET_YES; | 774 | alh->all_peers = GNUNET_YES; |
809 | else | 775 | else |
810 | { | 776 | { |
811 | alh->all_peers = GNUNET_NO; | 777 | alh->all_peers = GNUNET_NO; |
812 | alh->peer = (*peer); | 778 | alh->peer = (*peer); |
813 | } | 779 | } |
814 | 780 | ||
815 | GNUNET_CONTAINER_DLL_insert (handle->addresslist_head, handle->addresslist_tail, alh); | 781 | GNUNET_CONTAINER_DLL_insert(handle->addresslist_head, |
782 | handle->addresslist_tail, alh); | ||
816 | 783 | ||
817 | p = GNUNET_malloc (sizeof (struct PendingMessage) + | 784 | p = GNUNET_malloc (sizeof (struct PendingMessage) + |
818 | sizeof (struct AddressListRequestMessage)); | 785 | sizeof (struct AddressListRequestMessage)); |
819 | p->size = sizeof (struct AddressListRequestMessage); | 786 | p->size = sizeof(struct AddressListRequestMessage); |
820 | m = (struct AddressListRequestMessage *) &p[1]; | 787 | m = (struct AddressListRequestMessage *) &p[1]; |
821 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); | 788 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); |
822 | m->header.size = htons (sizeof (struct AddressListRequestMessage)); | 789 | m->header.size = htons (sizeof(struct AddressListRequestMessage)); |
823 | m->all = htonl (all); | 790 | m->all = htonl (all); |
824 | m->id = htonl (alh->id); | 791 | m->id = htonl (alh->id); |
825 | if (NULL != peer) | 792 | if (NULL != peer) |
826 | m->peer = *peer; | 793 | m->peer = *peer; |
827 | else | 794 | else |
828 | { | 795 | { |
829 | memset (&m->peer, '\0', sizeof (struct GNUNET_PeerIdentity)); | 796 | memset (&m->peer, '\0', sizeof(struct GNUNET_PeerIdentity)); |
830 | } | 797 | } |
831 | GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail, p); | 798 | GNUNET_CONTAINER_DLL_insert_tail(handle->pending_head, handle->pending_tail, |
799 | p); | ||
832 | 800 | ||
833 | do_transmit (handle); | 801 | do_transmit (handle); |
834 | 802 | ||
835 | return alh; | 803 | return alh; |
836 | } | 804 | } |
837 | 805 | ||
838 | |||
839 | /** | 806 | /** |
840 | * Cancel a pending address listing operation | 807 | * Cancel a pending address listing operation |
841 | * | 808 | * |
842 | * @param handle the GNUNET_ATS_AddressListHandle handle to cancel | 809 | * @param handle the GNUNET_ATS_AddressListHandle handle to cancel |
843 | */ | 810 | */ |
844 | void | 811 | void |
845 | GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle) | 812 | GNUNET_ATS_performance_list_addresses_cancel ( |
813 | struct GNUNET_ATS_AddressListHandle *handle) | ||
846 | { | 814 | { |
847 | GNUNET_assert (NULL != handle); | 815 | GNUNET_assert(NULL != handle); |
848 | 816 | ||
849 | GNUNET_CONTAINER_DLL_remove (handle->ph->addresslist_head, handle->ph->addresslist_tail, handle); | 817 | GNUNET_CONTAINER_DLL_remove(handle->ph->addresslist_head, |
850 | GNUNET_free (handle); | 818 | handle->ph->addresslist_tail, handle); |
819 | GNUNET_free(handle); | ||
851 | } | 820 | } |
852 | 821 | ||
853 | |||
854 | /** | 822 | /** |
855 | * Convert a GNUNET_ATS_PreferenceType to a string | 823 | * Convert a GNUNET_ATS_PreferenceType to a string |
856 | * | 824 | * |
@@ -863,10 +831,9 @@ GNUNET_ATS_print_preference_type (uint32_t type) | |||
863 | char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; | 831 | char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; |
864 | if (type < GNUNET_ATS_PreferenceCount) | 832 | if (type < GNUNET_ATS_PreferenceCount) |
865 | return prefs[type]; | 833 | return prefs[type]; |
866 | return NULL; | 834 | return NULL ; |
867 | } | 835 | } |
868 | 836 | ||
869 | |||
870 | /** | 837 | /** |
871 | * Change preferences for the given peer. Preference changes are forgotten if peers | 838 | * Change preferences for the given peer. Preference changes are forgotten if peers |
872 | * disconnect. | 839 | * disconnect. |
@@ -876,8 +843,9 @@ GNUNET_ATS_print_preference_type (uint32_t type) | |||
876 | * @param ... 0-terminated specification of the desired changes | 843 | * @param ... 0-terminated specification of the desired changes |
877 | */ | 844 | */ |
878 | void | 845 | void |
879 | GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, | 846 | GNUNET_ATS_performance_change_preference ( |
880 | const struct GNUNET_PeerIdentity *peer, ...) | 847 | struct GNUNET_ATS_PerformanceHandle *ph, |
848 | const struct GNUNET_PeerIdentity *peer, ...) | ||
881 | { | 849 | { |
882 | struct PendingMessage *p; | 850 | struct PendingMessage *p; |
883 | struct ChangePreferenceMessage *m; | 851 | struct ChangePreferenceMessage *m; |
@@ -888,9 +856,9 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
888 | enum GNUNET_ATS_PreferenceKind kind; | 856 | enum GNUNET_ATS_PreferenceKind kind; |
889 | 857 | ||
890 | count = 0; | 858 | count = 0; |
891 | va_start (ap, peer); | 859 | va_start(ap, peer); |
892 | while (GNUNET_ATS_PREFERENCE_END != | 860 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
893 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) | 861 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
894 | { | 862 | { |
895 | switch (kind) | 863 | switch (kind) |
896 | { | 864 | { |
@@ -905,13 +873,12 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
905 | 873 | ||
906 | break; | 874 | break; |
907 | default: | 875 | default: |
908 | GNUNET_assert (0); | 876 | GNUNET_assert(0); |
909 | } | 877 | } |
910 | } | 878 | } |
911 | va_end (ap); | 879 | va_end(ap); |
912 | msize = | 880 | msize = count * sizeof(struct PreferenceInformation) |
913 | count * sizeof (struct PreferenceInformation) + | 881 | + sizeof(struct ChangePreferenceMessage); |
914 | sizeof (struct ChangePreferenceMessage); | ||
915 | p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); | 882 | p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); |
916 | p->size = msize; | 883 | p->size = msize; |
917 | p->is_init = GNUNET_NO; | 884 | p->is_init = GNUNET_NO; |
@@ -922,9 +889,9 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
922 | m->peer = *peer; | 889 | m->peer = *peer; |
923 | pi = (struct PreferenceInformation *) &m[1]; | 890 | pi = (struct PreferenceInformation *) &m[1]; |
924 | count = 0; | 891 | count = 0; |
925 | va_start (ap, peer); | 892 | va_start(ap, peer); |
926 | while (GNUNET_ATS_PREFERENCE_END != | 893 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
927 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) | 894 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
928 | { | 895 | { |
929 | pi[count].preference_kind = htonl (kind); | 896 | pi[count].preference_kind = htonl (kind); |
930 | switch (kind) | 897 | switch (kind) |
@@ -940,11 +907,11 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
940 | count++; | 907 | count++; |
941 | break; | 908 | break; |
942 | default: | 909 | default: |
943 | GNUNET_assert (0); | 910 | GNUNET_assert(0); |
944 | } | 911 | } |
945 | } | 912 | } |
946 | va_end (ap); | 913 | va_end(ap); |
947 | GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p); | 914 | GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p); |
948 | do_transmit (ph); | 915 | do_transmit (ph); |
949 | } | 916 | } |
950 | 917 | ||
@@ -959,8 +926,8 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
959 | */ | 926 | */ |
960 | void | 927 | void |
961 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | 928 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, |
962 | const struct GNUNET_PeerIdentity *peer, | 929 | const struct GNUNET_PeerIdentity *peer, |
963 | const struct GNUNET_TIME_Relative scope, ...) | 930 | const struct GNUNET_TIME_Relative scope, ...) |
964 | { | 931 | { |
965 | struct PendingMessage *p; | 932 | struct PendingMessage *p; |
966 | struct FeedbackPreferenceMessage *m; | 933 | struct FeedbackPreferenceMessage *m; |
@@ -971,9 +938,9 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
971 | enum GNUNET_ATS_PreferenceKind kind; | 938 | enum GNUNET_ATS_PreferenceKind kind; |
972 | 939 | ||
973 | count = 0; | 940 | count = 0; |
974 | va_start (ap, scope); | 941 | va_start(ap, scope); |
975 | while (GNUNET_ATS_PREFERENCE_END != | 942 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
976 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) | 943 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
977 | { | 944 | { |
978 | switch (kind) | 945 | switch (kind) |
979 | { | 946 | { |
@@ -988,13 +955,12 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
988 | 955 | ||
989 | break; | 956 | break; |
990 | default: | 957 | default: |
991 | GNUNET_assert (0); | 958 | GNUNET_assert(0); |
992 | } | 959 | } |
993 | } | 960 | } |
994 | va_end (ap); | 961 | va_end(ap); |
995 | msize = | 962 | msize = count * sizeof(struct PreferenceInformation) |
996 | count * sizeof (struct PreferenceInformation) + | 963 | + sizeof(struct FeedbackPreferenceMessage); |
997 | sizeof (struct FeedbackPreferenceMessage); | ||
998 | p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); | 964 | p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); |
999 | p->size = msize; | 965 | p->size = msize; |
1000 | p->is_init = GNUNET_NO; | 966 | p->is_init = GNUNET_NO; |
@@ -1006,9 +972,9 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
1006 | m->peer = *peer; | 972 | m->peer = *peer; |
1007 | pi = (struct PreferenceInformation *) &m[1]; | 973 | pi = (struct PreferenceInformation *) &m[1]; |
1008 | count = 0; | 974 | count = 0; |
1009 | va_start (ap, scope); | 975 | va_start(ap, scope); |
1010 | while (GNUNET_ATS_PREFERENCE_END != | 976 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
1011 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) | 977 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
1012 | { | 978 | { |
1013 | pi[count].preference_kind = htonl (kind); | 979 | pi[count].preference_kind = htonl (kind); |
1014 | switch (kind) | 980 | switch (kind) |
@@ -1024,11 +990,11 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
1024 | count++; | 990 | count++; |
1025 | break; | 991 | break; |
1026 | default: | 992 | default: |
1027 | GNUNET_assert (0); | 993 | GNUNET_assert(0); |
1028 | } | 994 | } |
1029 | } | 995 | } |
1030 | va_end (ap); | 996 | va_end(ap); |
1031 | GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p); | 997 | GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p); |
1032 | do_transmit (ph); | 998 | do_transmit (ph); |
1033 | } | 999 | } |
1034 | 1000 | ||
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index f55bb4611..8f823a428 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -26,17 +26,21 @@ | |||
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_ats_service.h" | 28 | #include "gnunet_ats_service.h" |
29 | #include "gnunet_ats_plugin.h" | ||
29 | #include "gnunet-service-ats.h" | 30 | #include "gnunet-service-ats.h" |
30 | #include "gnunet-service-ats_addresses.h" | 31 | #include "gnunet-service-ats_addresses.h" |
31 | #include "gnunet-service-ats_normalization.h" | 32 | #include "gnunet-service-ats_normalization.h" |
32 | #include "gnunet-service-ats_performance.h" | 33 | #include "gnunet-service-ats_performance.h" |
33 | #include "gnunet-service-ats_scheduling.h" | 34 | #include "gnunet-service-ats_scheduling.h" |
34 | #include "gnunet-service-ats_reservations.h" | 35 | #include "gnunet-service-ats_reservations.h" |
36 | |||
37 | #if 0 | ||
35 | #if HAVE_LIBGLPK | 38 | #if HAVE_LIBGLPK |
36 | #include "gnunet-service-ats-solver_mlp.h" | 39 | #include "gnunet-service-ats-solver_mlp.h" |
37 | #endif | 40 | #endif |
38 | #include "gnunet-service-ats-solver_proportional.h" | 41 | #include "gnunet-service-ats-solver_proportional.h" |
39 | #include "gnunet-service-ats-solver_ril.h" | 42 | #include "gnunet-service-ats-solver_ril.h" |
43 | #endif | ||
40 | 44 | ||
41 | /** | 45 | /** |
42 | * NOTE: Do not change this documentation. This documentation is based on | 46 | * NOTE: Do not change this documentation. This documentation is based on |
@@ -332,64 +336,9 @@ struct GAS_Addresses_Handle | |||
332 | struct GAS_Addresses_Suggestion_Requests *r_tail; | 336 | struct GAS_Addresses_Suggestion_Requests *r_tail; |
333 | 337 | ||
334 | /* Solver functions */ | 338 | /* Solver functions */ |
339 | struct GNUNET_ATS_PluginEnvironment env; | ||
335 | 340 | ||
336 | /** | 341 | char *plugin; |
337 | * Initialize solver | ||
338 | */ | ||
339 | GAS_solver_init s_init; | ||
340 | |||
341 | /** | ||
342 | * Add an address to the solver | ||
343 | */ | ||
344 | GAS_solver_address_add s_add; | ||
345 | |||
346 | GAS_solver_address_property_changed s_address_update_property; | ||
347 | |||
348 | GAS_solver_address_session_changed s_address_update_session; | ||
349 | |||
350 | GAS_solver_address_inuse_changed s_address_update_inuse; | ||
351 | |||
352 | GAS_solver_address_network_changed s_address_update_network; | ||
353 | |||
354 | /** | ||
355 | * Get address from solver | ||
356 | */ | ||
357 | GAS_solver_get_preferred_address s_get; | ||
358 | |||
359 | /** | ||
360 | * Get address from solver | ||
361 | */ | ||
362 | GAS_solver_stop_get_preferred_address s_get_stop; | ||
363 | |||
364 | /** | ||
365 | * Delete address in solver | ||
366 | */ | ||
367 | GAS_solver_address_delete s_del; | ||
368 | |||
369 | /** | ||
370 | * Change relative preference for quality in solver | ||
371 | */ | ||
372 | GAS_solver_address_change_preference s_pref; | ||
373 | |||
374 | /** | ||
375 | * Give feedback about the current assignment | ||
376 | */ | ||
377 | GAS_solver_address_feedback_preference s_feedback; | ||
378 | |||
379 | /** | ||
380 | * Start a bulk operation | ||
381 | */ | ||
382 | GAS_solver_bulk_start s_bulk_start; | ||
383 | |||
384 | /** | ||
385 | * Bulk operation done | ||
386 | */ | ||
387 | GAS_solver_bulk_stop s_bulk_stop; | ||
388 | |||
389 | /** | ||
390 | * Shutdown solver | ||
391 | */ | ||
392 | GAS_solver_done s_done; | ||
393 | }; | 342 | }; |
394 | 343 | ||
395 | /** | 344 | /** |
@@ -805,12 +754,12 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
805 | GNUNET_ATS_print_network_type (addr_net)); | 754 | GNUNET_ATS_print_network_type (addr_net)); |
806 | 755 | ||
807 | /* Tell solver about new address */ | 756 | /* Tell solver about new address */ |
808 | handle->s_add (handle->solver, new_address, addr_net); | 757 | handle->env.sf.s_add (handle->solver, new_address, addr_net); |
809 | 758 | ||
810 | handle->s_bulk_start (handle->solver); | 759 | handle->env.sf.s_bulk_start (handle->solver); |
811 | GAS_normalization_normalize_property (handle->addresses, new_address, atsi, | 760 | GAS_normalization_normalize_property (handle->addresses, new_address, atsi, |
812 | atsi_count); | 761 | atsi_count); |
813 | handle->s_bulk_stop (handle->solver); | 762 | handle->env.sf.s_bulk_stop (handle->solver); |
814 | 763 | ||
815 | /* Notify performance clients about new address */ | 764 | /* Notify performance clients about new address */ |
816 | GAS_performance_notify_all_clients (&new_address->peer, new_address->plugin, | 765 | GAS_performance_notify_all_clients (&new_address->peer, new_address->plugin, |
@@ -866,7 +815,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
866 | GNUNET_i2s (peer), existing_address, | 815 | GNUNET_i2s (peer), existing_address, |
867 | GNUNET_ATS_print_network_type (addr_net), | 816 | GNUNET_ATS_print_network_type (addr_net), |
868 | GNUNET_ATS_print_network_type (ntohl (atsi_delta[c1].value))); | 817 | GNUNET_ATS_print_network_type (ntohl (atsi_delta[c1].value))); |
869 | handle->s_address_update_network (handle->solver, existing_address, | 818 | handle->env.sf.s_address_update_network (handle->solver, existing_address, |
870 | ntohl (atsi_delta[c1].value), | 819 | ntohl (atsi_delta[c1].value), |
871 | get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE)); | 820 | get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE)); |
872 | addr_net = get_performance_info (existing_address, | 821 | addr_net = get_performance_info (existing_address, |
@@ -874,10 +823,10 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
874 | } | 823 | } |
875 | } | 824 | } |
876 | /* Notify solver about update with atsi information and session */ | 825 | /* Notify solver about update with atsi information and session */ |
877 | handle->s_bulk_start (handle->solver); | 826 | handle->env.sf.s_bulk_start (handle->solver); |
878 | GAS_normalization_normalize_property (handle->addresses, existing_address, | 827 | GAS_normalization_normalize_property (handle->addresses, existing_address, |
879 | atsi, atsi_count); | 828 | atsi, atsi_count); |
880 | handle->s_bulk_stop (handle->solver); | 829 | handle->env.sf.s_bulk_stop (handle->solver); |
881 | } | 830 | } |
882 | GNUNET_free_non_null(atsi_delta); | 831 | GNUNET_free_non_null(atsi_delta); |
883 | 832 | ||
@@ -887,7 +836,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
887 | 836 | ||
888 | previous_session = existing_address->session_id; | 837 | previous_session = existing_address->session_id; |
889 | existing_address->session_id = session_id; | 838 | existing_address->session_id = session_id; |
890 | handle->s_address_update_session (handle->solver, existing_address, | 839 | handle->env.sf.s_address_update_session (handle->solver, existing_address, |
891 | previous_session, session_id); | 840 | previous_session, session_id); |
892 | 841 | ||
893 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 842 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
@@ -956,7 +905,7 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
956 | /* Session changed */ | 905 | /* Session changed */ |
957 | prev_session = aa->session_id; | 906 | prev_session = aa->session_id; |
958 | aa->session_id = session_id; | 907 | aa->session_id = session_id; |
959 | handle->s_address_update_session (handle->solver, aa, prev_session, | 908 | handle->env.sf.s_address_update_session (handle->solver, aa, prev_session, |
960 | aa->session_id); | 909 | aa->session_id); |
961 | } | 910 | } |
962 | 911 | ||
@@ -972,7 +921,7 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
972 | if (GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) | 921 | if (GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) |
973 | { | 922 | { |
974 | /* Network type changed */ | 923 | /* Network type changed */ |
975 | handle->s_address_update_network (handle->solver, aa, | 924 | handle->env.sf.s_address_update_network (handle->solver, aa, |
976 | ntohl (atsi_delta[c1].value), | 925 | ntohl (atsi_delta[c1].value), |
977 | get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE)); | 926 | get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE)); |
978 | } | 927 | } |
@@ -983,10 +932,10 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
983 | aa->addr_len, aa->session_id, aa->atsi, aa->atsi_count, | 932 | aa->addr_len, aa->session_id, aa->atsi, aa->atsi_count, |
984 | aa->assigned_bw_out, aa->assigned_bw_in); | 933 | aa->assigned_bw_out, aa->assigned_bw_in); |
985 | 934 | ||
986 | handle->s_bulk_start (handle->solver); | 935 | handle->env.sf.s_bulk_start (handle->solver); |
987 | GAS_normalization_normalize_property (handle->addresses, aa, atsi, | 936 | GAS_normalization_normalize_property (handle->addresses, aa, atsi, |
988 | atsi_count); | 937 | atsi_count); |
989 | handle->s_bulk_stop (handle->solver); | 938 | handle->env.sf.s_bulk_stop (handle->solver); |
990 | } | 939 | } |
991 | GNUNET_free_non_null(atsi_delta); | 940 | GNUNET_free_non_null(atsi_delta); |
992 | } | 941 | } |
@@ -1046,7 +995,7 @@ destroy_by_session_id (void *cls, | |||
1046 | GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (handle->addresses, | 995 | GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (handle->addresses, |
1047 | &aa->peer, | 996 | &aa->peer, |
1048 | aa)); | 997 | aa)); |
1049 | handle->s_del (handle->solver, aa, GNUNET_NO); | 998 | handle->env.sf.s_del (handle->solver, aa, GNUNET_NO); |
1050 | free_address (aa); | 999 | free_address (aa); |
1051 | dc->result = GNUNET_NO; | 1000 | dc->result = GNUNET_NO; |
1052 | return GNUNET_OK; /* Continue iteration */ | 1001 | return GNUNET_OK; /* Continue iteration */ |
@@ -1078,7 +1027,7 @@ destroy_by_session_id (void *cls, | |||
1078 | GNUNET_assert( | 1027 | GNUNET_assert( |
1079 | GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (handle->addresses, | 1028 | GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (handle->addresses, |
1080 | &aa->peer, aa)); | 1029 | &aa->peer, aa)); |
1081 | handle->s_del (handle->solver, aa, GNUNET_NO); | 1030 | handle->env.sf.s_del (handle->solver, aa, GNUNET_NO); |
1082 | free_address (aa); | 1031 | free_address (aa); |
1083 | dc->result = GNUNET_NO; | 1032 | dc->result = GNUNET_NO; |
1084 | return GNUNET_OK; /* Continue iteration */ | 1033 | return GNUNET_OK; /* Continue iteration */ |
@@ -1090,7 +1039,7 @@ destroy_by_session_id (void *cls, | |||
1090 | "Deleting session for peer `%s': `%s' %u\n", GNUNET_i2s (&aa->peer), | 1039 | "Deleting session for peer `%s': `%s' %u\n", GNUNET_i2s (&aa->peer), |
1091 | aa->plugin, aa->session_id); | 1040 | aa->plugin, aa->session_id); |
1092 | /* Notify solver to delete session */ | 1041 | /* Notify solver to delete session */ |
1093 | handle->s_del (handle->solver, aa, GNUNET_YES); | 1042 | handle->env.sf.s_del (handle->solver, aa, GNUNET_YES); |
1094 | aa->session_id = 0; | 1043 | aa->session_id = 0; |
1095 | aa->active = GNUNET_NO; | 1044 | aa->active = GNUNET_NO; |
1096 | return GNUNET_OK; | 1045 | return GNUNET_OK; |
@@ -1203,7 +1152,7 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | |||
1203 | 1152 | ||
1204 | /* Tell solver about update */ | 1153 | /* Tell solver about update */ |
1205 | ea->used = in_use; | 1154 | ea->used = in_use; |
1206 | handle->s_address_update_inuse (handle->solver, ea, ea->used); | 1155 | handle->env.sf.s_address_update_inuse (handle->solver, ea, ea->used); |
1207 | return GNUNET_OK; | 1156 | return GNUNET_OK; |
1208 | } | 1157 | } |
1209 | 1158 | ||
@@ -1236,7 +1185,7 @@ GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle, | |||
1236 | GNUNET_i2s (peer)); | 1185 | GNUNET_i2s (peer)); |
1237 | return; | 1186 | return; |
1238 | } | 1187 | } |
1239 | handle->s_get_stop (handle->solver, peer); | 1188 | handle->env.sf.s_get_stop (handle->solver, peer); |
1240 | GAS_addresses_handle_backoff_reset (handle, peer); | 1189 | GAS_addresses_handle_backoff_reset (handle, peer); |
1241 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Removed request pending for peer `%s\n", | 1190 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Removed request pending for peer `%s\n", |
1242 | GNUNET_i2s (peer)); | 1191 | GNUNET_i2s (peer)); |
@@ -1287,7 +1236,7 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle, | |||
1287 | */ | 1236 | */ |
1288 | 1237 | ||
1289 | /* Get prefered address from solver */ | 1238 | /* Get prefered address from solver */ |
1290 | aa = (struct ATS_Address *) handle->s_get (handle->solver, peer); | 1239 | aa = (struct ATS_Address *) handle->env.sf.s_get (handle->solver, peer); |
1291 | if (NULL == aa) | 1240 | if (NULL == aa) |
1292 | { | 1241 | { |
1293 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Cannot suggest address for peer `%s'\n", | 1242 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Cannot suggest address for peer `%s'\n", |
@@ -1378,7 +1327,7 @@ normalized_preference_changed_cb (void *cls, | |||
1378 | struct GAS_Addresses_Handle *handle = cls; | 1327 | struct GAS_Addresses_Handle *handle = cls; |
1379 | 1328 | ||
1380 | /* Tell solver about update */ | 1329 | /* Tell solver about update */ |
1381 | handle->s_pref (handle->solver, peer, kind, pref_rel); | 1330 | handle->env.sf.s_pref (handle->solver, peer, kind, pref_rel); |
1382 | } | 1331 | } |
1383 | 1332 | ||
1384 | /** | 1333 | /** |
@@ -1401,7 +1350,7 @@ normalized_property_changed_cb (void *cls, struct ATS_Address *address, | |||
1401 | GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer), | 1350 | GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer), |
1402 | prop_rel); | 1351 | prop_rel); |
1403 | 1352 | ||
1404 | ah->s_address_update_property (ah->solver, address, type, 0, prop_rel); | 1353 | ah->env.sf.s_address_update_property (ah->solver, address, type, 0, prop_rel); |
1405 | } | 1354 | } |
1406 | 1355 | ||
1407 | /** | 1356 | /** |
@@ -1463,10 +1412,10 @@ GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle, | |||
1463 | return; | 1412 | return; |
1464 | } | 1413 | } |
1465 | 1414 | ||
1466 | handle->s_bulk_start (handle->solver); | 1415 | handle->env.sf.s_bulk_start (handle->solver); |
1467 | /* Tell normalization about change, normalization will call callback if preference changed */ | 1416 | /* Tell normalization about change, normalization will call callback if preference changed */ |
1468 | GAS_normalization_normalize_preference (client, peer, kind, score_abs); | 1417 | GAS_normalization_normalize_preference (client, peer, kind, score_abs); |
1469 | handle->s_bulk_stop (handle->solver); | 1418 | handle->env.sf.s_bulk_stop (handle->solver); |
1470 | } | 1419 | } |
1471 | 1420 | ||
1472 | /** | 1421 | /** |
@@ -1502,7 +1451,7 @@ GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle, | |||
1502 | return; | 1451 | return; |
1503 | } | 1452 | } |
1504 | 1453 | ||
1505 | handle->s_feedback (handle->solver, application, peer, scope, kind, | 1454 | handle->env.sf.s_feedback (handle->solver, application, peer, scope, kind, |
1506 | score_abs); | 1455 | score_abs); |
1507 | } | 1456 | } |
1508 | 1457 | ||
@@ -1704,11 +1653,10 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1704 | const struct GNUNET_STATISTICS_Handle *stats) | 1653 | const struct GNUNET_STATISTICS_Handle *stats) |
1705 | { | 1654 | { |
1706 | struct GAS_Addresses_Handle *ah; | 1655 | struct GAS_Addresses_Handle *ah; |
1707 | int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; | ||
1708 | unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount]; | 1656 | unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount]; |
1709 | unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount]; | 1657 | unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount]; |
1710 | int quota_count; | ||
1711 | char *mode_str; | 1658 | char *mode_str; |
1659 | char *plugin_short; | ||
1712 | int c; | 1660 | int c; |
1713 | 1661 | ||
1714 | ah = GNUNET_malloc (sizeof (struct GAS_Addresses_Handle)); | 1662 | ah = GNUNET_malloc (sizeof (struct GAS_Addresses_Handle)); |
@@ -1734,20 +1682,24 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1734 | if (0 == strcmp (mode_str, "PROPORTIONAL")) | 1682 | if (0 == strcmp (mode_str, "PROPORTIONAL")) |
1735 | { | 1683 | { |
1736 | ah->ats_mode = MODE_PROPORTIONAL; | 1684 | ah->ats_mode = MODE_PROPORTIONAL; |
1685 | plugin_short = "proportional"; | ||
1737 | } | 1686 | } |
1738 | else if (0 == strcmp (mode_str, "MLP")) | 1687 | else if (0 == strcmp (mode_str, "MLP")) |
1739 | { | 1688 | { |
1740 | ah->ats_mode = MODE_MLP; | 1689 | ah->ats_mode = MODE_MLP; |
1690 | plugin_short = "mlp"; | ||
1741 | #if !HAVE_LIBGLPK | 1691 | #if !HAVE_LIBGLPK |
1742 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1692 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1743 | "Assignment method `%s' configured, but GLPK is not available, please install \n", | 1693 | "Assignment method `%s' configured, but GLPK is not available, please install \n", |
1744 | mode_str); | 1694 | mode_str); |
1745 | ah->ats_mode = MODE_PROPORTIONAL; | 1695 | ah->ats_mode = MODE_PROPORTIONAL; |
1696 | plugin_short = "proportional"; | ||
1746 | #endif | 1697 | #endif |
1747 | } | 1698 | } |
1748 | else if (0 == strcmp (mode_str, "RIL")) | 1699 | else if (0 == strcmp (mode_str, "RIL")) |
1749 | { | 1700 | { |
1750 | ah->ats_mode = MODE_RIL; | 1701 | ah->ats_mode = MODE_RIL; |
1702 | plugin_short = "ril"; | ||
1751 | } | 1703 | } |
1752 | else | 1704 | else |
1753 | { | 1705 | { |
@@ -1755,100 +1707,56 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1755 | "Invalid resource assignment method `%s' configured, using proportional approach\n", | 1707 | "Invalid resource assignment method `%s' configured, using proportional approach\n", |
1756 | mode_str); | 1708 | mode_str); |
1757 | ah->ats_mode = MODE_PROPORTIONAL; | 1709 | ah->ats_mode = MODE_PROPORTIONAL; |
1710 | plugin_short = "proportional"; | ||
1758 | } | 1711 | } |
1759 | GNUNET_free(mode_str); | 1712 | GNUNET_free(mode_str); |
1760 | } | 1713 | } |
1761 | /* Start configured solution method */ | 1714 | |
1762 | switch (ah->ats_mode) | 1715 | load_quotas (cfg, quotas_in, quotas_out, GNUNET_ATS_NetworkTypeCount); |
1716 | ah->env.bandwidth_changed_cb = &bandwidth_changed_cb; | ||
1717 | ah->env.bw_changed_cb_cls = ah; | ||
1718 | ah->env.get_preferences_cb = &get_preferences_cb; | ||
1719 | ah->env.get_preference_cls = ah; | ||
1720 | ah->env.get_property_cb = &get_property_cb; | ||
1721 | ah->env.get_property_cls = ah; | ||
1722 | ah->env.cfg = cfg; | ||
1723 | ah->env.stats = stats; | ||
1724 | ah->env.addresses = ah->addresses; | ||
1725 | |||
1726 | ah->env.network_count = GNUNET_ATS_NetworkTypeCount; | ||
1727 | int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; | ||
1728 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | ||
1763 | { | 1729 | { |
1764 | case MODE_MLP: | 1730 | ah->env.networks[c] = networks[c]; |
1765 | /* Init the MLP solver with default values */ | 1731 | ah->env.out_quota[c] = quotas_out[c]; |
1766 | #if HAVE_LIBGLPK | 1732 | ah->env.in_quota[c] = quotas_in[c]; |
1767 | ah->s_init = &GAS_mlp_init; | ||
1768 | ah->s_add = &GAS_mlp_address_add; | ||
1769 | ah->s_address_update_property = &GAS_mlp_address_property_changed; | ||
1770 | ah->s_address_update_session = &GAS_mlp_address_session_changed; | ||
1771 | ah->s_address_update_inuse = &GAS_mlp_address_inuse_changed; | ||
1772 | ah->s_address_update_network = &GAS_mlp_address_change_network; | ||
1773 | ah->s_get = &GAS_mlp_get_preferred_address; | ||
1774 | ah->s_get_stop = &GAS_mlp_stop_get_preferred_address; | ||
1775 | ah->s_pref = &GAS_mlp_address_change_preference; | ||
1776 | ah->s_feedback = &GAS_mlp_address_preference_feedback; | ||
1777 | ah->s_del = &GAS_mlp_address_delete; | ||
1778 | ah->s_bulk_start = &GAS_mlp_bulk_start; | ||
1779 | ah->s_bulk_stop = &GAS_mlp_bulk_stop; | ||
1780 | ah->s_done = &GAS_mlp_done; | ||
1781 | #else | ||
1782 | GNUNET_free(ah); | ||
1783 | return NULL ; | ||
1784 | #endif | ||
1785 | break; | ||
1786 | case MODE_PROPORTIONAL: | ||
1787 | /* Init the proportional solver with default values */ | ||
1788 | ah->s_init = &GAS_proportional_init; | ||
1789 | ah->s_add = &GAS_proportional_address_add; | ||
1790 | ah->s_address_update_property = &GAS_proportional_address_property_changed; | ||
1791 | ah->s_address_update_session = &GAS_proportional_address_session_changed; | ||
1792 | ah->s_address_update_inuse = &GAS_proportional_address_inuse_changed; | ||
1793 | ah->s_address_update_network = &GAS_proportional_address_change_network; | ||
1794 | ah->s_get = &GAS_proportional_get_preferred_address; | ||
1795 | ah->s_get_stop = &GAS_proportional_stop_get_preferred_address; | ||
1796 | ah->s_pref = &GAS_proportional_address_change_preference; | ||
1797 | ah->s_feedback = &GAS_proportional_address_preference_feedback; | ||
1798 | ah->s_del = &GAS_proportional_address_delete; | ||
1799 | ah->s_bulk_start = &GAS_proportional_bulk_start; | ||
1800 | ah->s_bulk_stop = &GAS_proportional_bulk_stop; | ||
1801 | ah->s_done = &GAS_proportional_done; | ||
1802 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "ATS started in %s mode\n", | ||
1803 | "PROPORTIONAL"); | ||
1804 | break; | ||
1805 | case MODE_RIL: | ||
1806 | /* Init the ril solver with default values */ | ||
1807 | ah->s_init = &GAS_ril_init; | ||
1808 | ah->s_add = &GAS_ril_address_add; | ||
1809 | ah->s_address_update_property = &GAS_ril_address_property_changed; | ||
1810 | ah->s_address_update_session = &GAS_ril_address_session_changed; | ||
1811 | ah->s_address_update_inuse = &GAS_ril_address_inuse_changed; | ||
1812 | ah->s_address_update_network = &GAS_ril_address_change_network; | ||
1813 | ah->s_get = &GAS_ril_get_preferred_address; | ||
1814 | ah->s_get_stop = &GAS_ril_stop_get_preferred_address; | ||
1815 | ah->s_pref = &GAS_ril_address_change_preference; | ||
1816 | ah->s_feedback = &GAS_ril_address_preference_feedback; | ||
1817 | ah->s_del = &GAS_ril_address_delete; | ||
1818 | ah->s_bulk_start = &GAS_ril_bulk_start; | ||
1819 | ah->s_bulk_stop = &GAS_ril_bulk_stop; | ||
1820 | ah->s_done = &GAS_ril_done; | ||
1821 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "ATS started in %s mode\n", "RIL"); | ||
1822 | break; | ||
1823 | default: | ||
1824 | return NULL ; | ||
1825 | break; | ||
1826 | } | 1733 | } |
1827 | 1734 | ||
1828 | GNUNET_assert (NULL != ah->s_init); | 1735 | GNUNET_asprintf (&ah->plugin, "libgnunet_plugin_ats_%s", plugin_short); |
1829 | GNUNET_assert (NULL != ah->s_add); | 1736 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s '`%s'\n"), plugin_short, ah->plugin); |
1830 | GNUNET_assert (NULL != ah->s_address_update_inuse); | 1737 | if (NULL == (ah->solver = GNUNET_PLUGIN_load (ah->plugin, &ah->env))) |
1831 | GNUNET_assert (NULL != ah->s_address_update_property); | 1738 | { |
1832 | GNUNET_assert (NULL != ah->s_address_update_session); | 1739 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), ah->plugin); |
1833 | GNUNET_assert (NULL != ah->s_address_update_network); | 1740 | return NULL; |
1834 | GNUNET_assert (NULL != ah->s_get); | 1741 | } |
1835 | GNUNET_assert (NULL != ah->s_get_stop); | 1742 | |
1836 | GNUNET_assert (NULL != ah->s_pref); | 1743 | GNUNET_assert (NULL != ah->env.sf.s_add); |
1837 | GNUNET_assert (NULL != ah->s_feedback); | 1744 | GNUNET_assert (NULL != ah->env.sf.s_address_update_inuse); |
1838 | GNUNET_assert (NULL != ah->s_del); | 1745 | GNUNET_assert (NULL != ah->env.sf.s_address_update_property); |
1839 | GNUNET_assert (NULL != ah->s_done); | 1746 | GNUNET_assert (NULL != ah->env.sf.s_address_update_session); |
1840 | GNUNET_assert (NULL != ah->s_bulk_start); | 1747 | GNUNET_assert (NULL != ah->env.sf.s_address_update_network); |
1841 | GNUNET_assert (NULL != ah->s_bulk_stop); | 1748 | GNUNET_assert (NULL != ah->env.sf.s_get); |
1749 | GNUNET_assert (NULL != ah->env.sf.s_get_stop); | ||
1750 | GNUNET_assert (NULL != ah->env.sf.s_pref); | ||
1751 | GNUNET_assert (NULL != ah->env.sf.s_feedback); | ||
1752 | GNUNET_assert (NULL != ah->env.sf.s_del); | ||
1753 | GNUNET_assert (NULL != ah->env.sf.s_bulk_start); | ||
1754 | GNUNET_assert (NULL != ah->env.sf.s_bulk_stop); | ||
1755 | |||
1842 | 1756 | ||
1843 | GAS_normalization_start (&normalized_preference_changed_cb, ah, | 1757 | GAS_normalization_start (&normalized_preference_changed_cb, ah, |
1844 | &normalized_property_changed_cb, ah); | 1758 | &normalized_property_changed_cb, ah); |
1845 | quota_count = load_quotas (cfg, quotas_in, quotas_out, | ||
1846 | GNUNET_ATS_NetworkTypeCount); | ||
1847 | 1759 | ||
1848 | ah->solver = ah->s_init (cfg, stats, ah->addresses, quotas, quotas_in, | ||
1849 | quotas_out, quota_count, | ||
1850 | &bandwidth_changed_cb, ah, &get_preferences_cb, | ||
1851 | NULL, &get_property_cb, NULL ); | ||
1852 | if (NULL == ah->solver) | 1760 | if (NULL == ah->solver) |
1853 | { | 1761 | { |
1854 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver!\n")); | 1762 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver!\n")); |
@@ -1884,7 +1792,7 @@ destroy_all_address_it (void *cls, | |||
1884 | GNUNET_assert(GNUNET_YES == | 1792 | GNUNET_assert(GNUNET_YES == |
1885 | GNUNET_CONTAINER_multipeermap_remove (handle->addresses, key, value)); | 1793 | GNUNET_CONTAINER_multipeermap_remove (handle->addresses, key, value)); |
1886 | /* Notify */ | 1794 | /* Notify */ |
1887 | handle->s_del (handle->solver, aa, GNUNET_NO); | 1795 | handle->env.sf.s_del (handle->solver, aa, GNUNET_NO); |
1888 | /* Destroy */ | 1796 | /* Destroy */ |
1889 | free_address (aa); | 1797 | free_address (aa); |
1890 | 1798 | ||
@@ -1904,12 +1812,12 @@ GAS_addresses_destroy_all (struct GAS_Addresses_Handle *handle) | |||
1904 | return; | 1812 | return; |
1905 | 1813 | ||
1906 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Destroying all addresses\n"); | 1814 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Destroying all addresses\n"); |
1907 | handle->s_bulk_start (handle->solver); | 1815 | handle->env.sf.s_bulk_start (handle->solver); |
1908 | if (handle->addresses != NULL ) | 1816 | if (handle->addresses != NULL ) |
1909 | GNUNET_CONTAINER_multipeermap_iterate (handle->addresses, | 1817 | GNUNET_CONTAINER_multipeermap_iterate (handle->addresses, |
1910 | &destroy_all_address_it, | 1818 | &destroy_all_address_it, |
1911 | handle); | 1819 | handle); |
1912 | handle->s_bulk_start (handle->solver); | 1820 | handle->env.sf.s_bulk_start (handle->solver); |
1913 | } | 1821 | } |
1914 | 1822 | ||
1915 | 1823 | ||
@@ -1934,7 +1842,9 @@ GAS_addresses_done (struct GAS_Addresses_Handle *handle) | |||
1934 | GNUNET_CONTAINER_DLL_remove(handle->r_head, handle->r_tail, cur); | 1842 | GNUNET_CONTAINER_DLL_remove(handle->r_head, handle->r_tail, cur); |
1935 | GNUNET_free(cur); | 1843 | GNUNET_free(cur); |
1936 | } | 1844 | } |
1937 | handle->s_done (handle->solver); | 1845 | |
1846 | GNUNET_PLUGIN_unload (handle->plugin, handle->solver); | ||
1847 | GNUNET_free (handle->plugin); | ||
1938 | GNUNET_free(handle); | 1848 | GNUNET_free(handle); |
1939 | /* Stop configured solution method */ | 1849 | /* Stop configured solution method */ |
1940 | GAS_normalization_stop (); | 1850 | GAS_normalization_stop (); |
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 38ccd95c3..6d3377f1b 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -348,234 +348,7 @@ struct ATS_Address | |||
348 | struct GAS_NormalizationInfo atsin[GNUNET_ATS_QualityPropertiesCount]; | 348 | struct GAS_NormalizationInfo atsin[GNUNET_ATS_QualityPropertiesCount]; |
349 | }; | 349 | }; |
350 | 350 | ||
351 | /** | ||
352 | * Callback to call from solver when bandwidth for address has changed | ||
353 | * | ||
354 | * @param address the with changed bandwidth assigned | ||
355 | */ | ||
356 | typedef void | ||
357 | (*GAS_bandwidth_changed_cb) (void *cls, struct ATS_Address *address); | ||
358 | |||
359 | /** | ||
360 | * Callback to call from solver to obtain application preference values for a | ||
361 | * peer | ||
362 | * | ||
363 | * @param cls the cls | ||
364 | * @param id the peer id | ||
365 | * @return carry of double values containing the preferences with | ||
366 | * GNUNET_ATS_PreferenceCount elements | ||
367 | */ | ||
368 | typedef const double * | ||
369 | (*GAS_get_preferences) (void *cls, const struct GNUNET_PeerIdentity *id); | ||
370 | |||
371 | /** | ||
372 | * Callback to call from solver to obtain transport properties for an | ||
373 | * address | ||
374 | * | ||
375 | * @param cls the cls | ||
376 | * @param address the address | ||
377 | * @return carry of double values containing the preferences with | ||
378 | * GNUNET_ATS_PreferenceCount elements | ||
379 | */ | ||
380 | typedef const double * | ||
381 | (*GAS_get_properties) (void *cls, const struct ATS_Address *address); | ||
382 | |||
383 | /* | ||
384 | * Solver API | ||
385 | * ---------- | ||
386 | */ | ||
387 | |||
388 | /** | ||
389 | * Init the problem solving component | ||
390 | * | ||
391 | * Quotas: | ||
392 | * network[i] contains the network type as type GNUNET_ATS_NetworkType[i] | ||
393 | * out_quota[i] contains outbound quota for network type i | ||
394 | * in_quota[i] contains inbound quota for network type i | ||
395 | * | ||
396 | * Example | ||
397 | * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN} | ||
398 | * network[2] == GNUNET_ATS_NET_LAN | ||
399 | * out_quota[2] == 65353 | ||
400 | * in_quota[2] == 65353 | ||
401 | * | ||
402 | * @param cfg configuration handle | ||
403 | * @param stats the GNUNET_STATISTICS handle | ||
404 | * @param addresses hashmap containing all addresses | ||
405 | * @param network array of GNUNET_ATS_NetworkType with length dest_length | ||
406 | * @param out_quota array of outbound quotas | ||
407 | * @param in_quota array of outbound quota | ||
408 | * @param bw_changed_cb callback to call when assigned changes | ||
409 | * @return handle for the solver on success, NULL on fail | ||
410 | */ | ||
411 | typedef void * | ||
412 | (*GAS_solver_init) (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
413 | const struct GNUNET_STATISTICS_Handle *stats, | ||
414 | const struct GNUNET_CONTAINER_MultiPeerMap *addresses, int *network, | ||
415 | unsigned long long *out_quota, unsigned long long *in_quota, | ||
416 | int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, | ||
417 | void *bw_changed_cb_cls, GAS_get_preferences get_preference, | ||
418 | void *get_preference_cls, GAS_get_properties get_properties, | ||
419 | void *get_properties_cls); | ||
420 | |||
421 | /** | ||
422 | * Change the preference for a peer | ||
423 | * | ||
424 | * @param handle the solver handle | ||
425 | * @param client the client sending this request | ||
426 | * @param peer the peer id | ||
427 | * @param kind the preference kind to change | ||
428 | * @param score the new preference score | ||
429 | * @param pref_rel the normalized preference value for this kind over all clients | ||
430 | */ | ||
431 | typedef void | ||
432 | (*GAS_solver_address_change_preference) (void *solver, | ||
433 | const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, | ||
434 | double pref_rel); | ||
435 | |||
436 | /** | ||
437 | * Give feedback about the current assignment | ||
438 | * | ||
439 | * @param handle the solver handle | ||
440 | * @param application the application sending this request | ||
441 | * @param peer the peer id | ||
442 | * @param scope the time interval for this feedback: [now - scope .. now] | ||
443 | * @param kind the preference kind for this feedback | ||
444 | * @param score the feedback score | ||
445 | */ | ||
446 | typedef void | ||
447 | (*GAS_solver_address_feedback_preference) (void *solver, void *application, | ||
448 | const struct GNUNET_PeerIdentity *peer, | ||
449 | const struct GNUNET_TIME_Relative scope, | ||
450 | enum GNUNET_ATS_PreferenceKind kind, double score); | ||
451 | |||
452 | /** | ||
453 | * Notify the solver about a bulk operation changing possibly a lot of values | ||
454 | * Solver will not resolve until all bulk operations are marked as done | ||
455 | * | ||
456 | * @param solver the solver | ||
457 | */ | ||
458 | typedef void | ||
459 | (*GAS_solver_bulk_start) (void *solver); | ||
460 | |||
461 | /** | ||
462 | * Mark a bulk operation as done | ||
463 | * Solver will resolve if values have changed | ||
464 | * | ||
465 | * @param solver the solver | ||
466 | */ | ||
467 | typedef void | ||
468 | (*GAS_solver_bulk_stop) (void *solver); | ||
469 | |||
470 | /** | ||
471 | * Add a single address within a network to the solver | ||
472 | * | ||
473 | * @param solver the solver Handle | ||
474 | * @param addresses the address hashmap containing all addresses | ||
475 | * @param address the address to add | ||
476 | * @param network network type of this address | ||
477 | */ | ||
478 | typedef void | ||
479 | (*GAS_solver_address_add) (void *solver, struct ATS_Address *address, | ||
480 | uint32_t network); | ||
481 | |||
482 | /** | ||
483 | * Delete an address or just the session from the solver | ||
484 | * | ||
485 | * @param solver the solver Handle | ||
486 | * @param addresses the address hashmap containing all addresses | ||
487 | * @param address the address to delete | ||
488 | * @param session_only remove address or just session | ||
489 | */ | ||
490 | typedef void | ||
491 | (*GAS_solver_address_delete) (void *solver, struct ATS_Address *address, | ||
492 | int session_only); | ||
493 | |||
494 | /** | ||
495 | * Transport properties for this address have changed | ||
496 | * | ||
497 | * @param solver solver handle | ||
498 | * @param address the address | ||
499 | * @param type the ATSI type in HBO | ||
500 | * @param abs_value the absolute value of the property | ||
501 | * @param rel_value the normalized value | ||
502 | */ | ||
503 | typedef void | ||
504 | (*GAS_solver_address_property_changed) (void *solver, | ||
505 | struct ATS_Address *address, uint32_t type, uint32_t abs_value, | ||
506 | double rel_value); | ||
507 | |||
508 | /** | ||
509 | * Transport session for this address has changed | ||
510 | * | ||
511 | * NOTE: values in addresses are already updated | ||
512 | * | ||
513 | * @param solver solver handle | ||
514 | * @param address the address | ||
515 | * @param cur_session the current session | ||
516 | * @param new_session the new session | ||
517 | */ | ||
518 | typedef void | ||
519 | (*GAS_solver_address_session_changed) (void *solver, | ||
520 | struct ATS_Address *address, uint32_t cur_session, uint32_t new_session); | ||
521 | |||
522 | /** | ||
523 | * Transport session for this address has changed | ||
524 | * | ||
525 | * NOTE: values in addresses are already updated | ||
526 | * | ||
527 | * @param solver solver handle | ||
528 | * @param address the address | ||
529 | * @param in_use usage state | ||
530 | */ | ||
531 | typedef void | ||
532 | (*GAS_solver_address_inuse_changed) (void *solver, struct ATS_Address *address, | ||
533 | int in_use); | ||
534 | |||
535 | /** | ||
536 | * Network scope for this address has changed | ||
537 | * | ||
538 | * NOTE: values in addresses are already updated | ||
539 | * | ||
540 | * @param solver solver handle | ||
541 | * @param address the address | ||
542 | * @param current_network the current network | ||
543 | * @param new_network the new network | ||
544 | */ | ||
545 | typedef void | ||
546 | (*GAS_solver_address_network_changed) (void *solver, | ||
547 | struct ATS_Address *address, uint32_t current_network, uint32_t new_network); | ||
548 | |||
549 | /** | ||
550 | * Get the prefered address for a peer from solver | ||
551 | * | ||
552 | * @param solver the solver to use | ||
553 | * @param addresses the address hashmap containing all addresses | ||
554 | * @param peer the peer | ||
555 | */ | ||
556 | typedef const struct ATS_Address * | ||
557 | (*GAS_solver_get_preferred_address) (void *solver, | ||
558 | const struct GNUNET_PeerIdentity *peer); | ||
559 | |||
560 | /** | ||
561 | * Stop getting the prefered address for a peer from solver | ||
562 | * | ||
563 | * @param solver the solver to use | ||
564 | * @param addresses the address hashmap containing all addresses | ||
565 | * @param peer the peer | ||
566 | */ | ||
567 | typedef void | ||
568 | (*GAS_solver_stop_get_preferred_address) (void *solver, | ||
569 | const struct GNUNET_PeerIdentity *peer); | ||
570 | |||
571 | /** | ||
572 | * Shutdown solver | ||
573 | * | ||
574 | * @param solver the solver to shutdown | ||
575 | */ | ||
576 | 351 | ||
577 | typedef void | ||
578 | (*GAS_solver_done) (void *solver); | ||
579 | 352 | ||
580 | /** | 353 | /** |
581 | * Initialize address subsystem. The addresses subsystem manages the addresses | 354 | * Initialize address subsystem. The addresses subsystem manages the addresses |
diff --git a/src/ats/gnunet-service-ats-solver_mlp.c b/src/ats/libgnunet_plugin_ats_mlp.c index f32ad101a..02bf18287 100644 --- a/src/ats/gnunet-service-ats-solver_mlp.c +++ b/src/ats/libgnunet_plugin_ats_mlp.c | |||
@@ -24,11 +24,9 @@ | |||
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | |
28 | #include "gnunet_util_lib.h" | 28 | #include "libgnunet_plugin_ats_mlp.h" |
29 | #include "gnunet-service-ats-solver_mlp.h" | 29 | |
30 | #include "gnunet_statistics_service.h" | ||
31 | #include "glpk.h" | ||
32 | 30 | ||
33 | /** | 31 | /** |
34 | * | 32 | * |
@@ -1798,10 +1796,10 @@ mlp_free_peers (void *cls, | |||
1798 | * | 1796 | * |
1799 | * @param solver the solver handle | 1797 | * @param solver the solver handle |
1800 | */ | 1798 | */ |
1801 | void | 1799 | void * |
1802 | GAS_mlp_done (void *solver) | 1800 | libgnunet_plugin_ats_mlp_done (void *cls) |
1803 | { | 1801 | { |
1804 | struct GAS_MLP_Handle *mlp = solver; | 1802 | struct GAS_MLP_Handle *mlp = cls; |
1805 | GNUNET_assert (mlp != NULL); | 1803 | GNUNET_assert (mlp != NULL); |
1806 | 1804 | ||
1807 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down mlp solver\n"); | 1805 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down mlp solver\n"); |
@@ -1818,42 +1816,14 @@ GAS_mlp_done (void *solver) | |||
1818 | GNUNET_free (mlp); | 1816 | GNUNET_free (mlp); |
1819 | 1817 | ||
1820 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutdown down of mlp solver complete\n"); | 1818 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutdown down of mlp solver complete\n"); |
1819 | return NULL; | ||
1821 | } | 1820 | } |
1822 | 1821 | ||
1823 | 1822 | ||
1824 | /** | ||
1825 | * Init the MLP problem solving component | ||
1826 | * | ||
1827 | * @param cfg the GNUNET_CONFIGURATION_Handle handle | ||
1828 | * @param stats the GNUNET_STATISTICS handle | ||
1829 | * @param addresses the address hashmap | ||
1830 | * @param network array of GNUNET_ATS_NetworkType with length dest_length | ||
1831 | * @param out_dest array of outbound quotas | ||
1832 | * @param in_dest array of outbound quota | ||
1833 | * @param dest_length array length for quota arrays | ||
1834 | * @param bw_changed_cb callback for changed bandwidth amounts | ||
1835 | * @param bw_changed_cb_cls cls for callback | ||
1836 | * @param get_preference callback to get relative preferences for a peer | ||
1837 | * @param get_preference_cls cls for callback to get relative preferences | ||
1838 | * @param get_properties callback to get relative properties | ||
1839 | * @param get_properties_cls cls for callback to get relative properties | ||
1840 | * @return struct GAS_MLP_Handle on success, NULL on fail | ||
1841 | */ | ||
1842 | void * | 1823 | void * |
1843 | GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1824 | libgnunet_plugin_ats_mlp_init (void *cls) |
1844 | const struct GNUNET_STATISTICS_Handle *stats, | ||
1845 | const struct GNUNET_CONTAINER_MultiPeerMap *addresses, | ||
1846 | int *network, | ||
1847 | unsigned long long *out_dest, | ||
1848 | unsigned long long *in_dest, | ||
1849 | int dest_length, | ||
1850 | GAS_bandwidth_changed_cb bw_changed_cb, | ||
1851 | void *bw_changed_cb_cls, | ||
1852 | GAS_get_preferences get_preference, | ||
1853 | void *get_preference_cls, | ||
1854 | GAS_get_properties get_properties, | ||
1855 | void *get_properties_cls) | ||
1856 | { | 1825 | { |
1826 | struct GNUNET_ATS_PluginEnvironment *env = cls; | ||
1857 | struct GAS_MLP_Handle * mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle)); | 1827 | struct GAS_MLP_Handle * mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle)); |
1858 | 1828 | ||
1859 | double D; | 1829 | double D; |
@@ -1869,12 +1839,12 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1869 | struct GNUNET_TIME_Relative max_duration; | 1839 | struct GNUNET_TIME_Relative max_duration; |
1870 | long long unsigned int max_iterations; | 1840 | long long unsigned int max_iterations; |
1871 | 1841 | ||
1872 | GNUNET_assert (NULL != cfg); | 1842 | GNUNET_assert (NULL != env->cfg); |
1873 | GNUNET_assert (NULL != stats); | 1843 | GNUNET_assert (NULL != env->stats); |
1874 | GNUNET_assert (NULL != addresses); | 1844 | GNUNET_assert (NULL != env->addresses); |
1875 | GNUNET_assert (NULL != bw_changed_cb); | 1845 | GNUNET_assert (NULL != env->bandwidth_changed_cb); |
1876 | GNUNET_assert (NULL != get_preference); | 1846 | GNUNET_assert (NULL != env->get_preferences_cb); |
1877 | GNUNET_assert (NULL != get_properties); | 1847 | GNUNET_assert (NULL != env->get_property_cb); |
1878 | 1848 | ||
1879 | /* Init GLPK environment */ | 1849 | /* Init GLPK environment */ |
1880 | int res = glp_init_env(); | 1850 | int res = glp_init_env(); |
@@ -1903,11 +1873,11 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1903 | break; | 1873 | break; |
1904 | } | 1874 | } |
1905 | 1875 | ||
1906 | mlp->write_mip_mps = GNUNET_CONFIGURATION_get_value_yesno (cfg, "ats", | 1876 | mlp->write_mip_mps = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "ats", |
1907 | "DUMP_MLP"); | 1877 | "DUMP_MLP"); |
1908 | if (GNUNET_SYSERR == mlp->write_mip_mps) | 1878 | if (GNUNET_SYSERR == mlp->write_mip_mps) |
1909 | mlp->write_mip_mps = GNUNET_NO; | 1879 | mlp->write_mip_mps = GNUNET_NO; |
1910 | mlp->write_mip_sol = GNUNET_CONFIGURATION_get_value_yesno (cfg, "ats", | 1880 | mlp->write_mip_sol = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "ats", |
1911 | "DUMP_SOLUTION"); | 1881 | "DUMP_SOLUTION"); |
1912 | if (GNUNET_SYSERR == mlp->write_mip_sol) | 1882 | if (GNUNET_SYSERR == mlp->write_mip_sol) |
1913 | mlp->write_mip_sol = GNUNET_NO; | 1883 | mlp->write_mip_sol = GNUNET_NO; |
@@ -1915,19 +1885,19 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1915 | mlp->pv.BIG_M = (double) BIG_M_VALUE; | 1885 | mlp->pv.BIG_M = (double) BIG_M_VALUE; |
1916 | 1886 | ||
1917 | /* Get timeout for iterations */ | 1887 | /* Get timeout for iterations */ |
1918 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(cfg, "ats", "MLP_MAX_DURATION", &max_duration)) | 1888 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats", "MLP_MAX_DURATION", &max_duration)) |
1919 | { | 1889 | { |
1920 | max_duration = MLP_MAX_EXEC_DURATION; | 1890 | max_duration = MLP_MAX_EXEC_DURATION; |
1921 | } | 1891 | } |
1922 | 1892 | ||
1923 | /* Get maximum number of iterations */ | 1893 | /* Get maximum number of iterations */ |
1924 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_size(cfg, "ats", "MLP_MAX_ITERATIONS", &max_iterations)) | 1894 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", "MLP_MAX_ITERATIONS", &max_iterations)) |
1925 | { | 1895 | { |
1926 | max_iterations = MLP_MAX_ITERATIONS; | 1896 | max_iterations = MLP_MAX_ITERATIONS; |
1927 | } | 1897 | } |
1928 | 1898 | ||
1929 | /* Get diversity coefficient from configuration */ | 1899 | /* Get diversity coefficient from configuration */ |
1930 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", | 1900 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", |
1931 | "MLP_COEFFICIENT_D", | 1901 | "MLP_COEFFICIENT_D", |
1932 | &tmp)) | 1902 | &tmp)) |
1933 | D = (double) tmp / 100; | 1903 | D = (double) tmp / 100; |
@@ -1935,7 +1905,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1935 | D = DEFAULT_D; | 1905 | D = DEFAULT_D; |
1936 | 1906 | ||
1937 | /* Get proportionality coefficient from configuration */ | 1907 | /* Get proportionality coefficient from configuration */ |
1938 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", | 1908 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", |
1939 | "MLP_COEFFICIENT_R", | 1909 | "MLP_COEFFICIENT_R", |
1940 | &tmp)) | 1910 | &tmp)) |
1941 | R = (double) tmp / 100; | 1911 | R = (double) tmp / 100; |
@@ -1943,7 +1913,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1943 | R = DEFAULT_R; | 1913 | R = DEFAULT_R; |
1944 | 1914 | ||
1945 | /* Get utilization coefficient from configuration */ | 1915 | /* Get utilization coefficient from configuration */ |
1946 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", | 1916 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", |
1947 | "MLP_COEFFICIENT_U", | 1917 | "MLP_COEFFICIENT_U", |
1948 | &tmp)) | 1918 | &tmp)) |
1949 | U = (double) tmp / 100; | 1919 | U = (double) tmp / 100; |
@@ -1966,7 +1936,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1966 | i_distance = c; | 1936 | i_distance = c; |
1967 | } | 1937 | } |
1968 | 1938 | ||
1969 | if ((i_delay != MLP_NaN) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", | 1939 | if ((i_delay != MLP_NaN) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", |
1970 | "MLP_COEFFICIENT_QUALITY_DELAY", | 1940 | "MLP_COEFFICIENT_QUALITY_DELAY", |
1971 | &tmp))) | 1941 | &tmp))) |
1972 | 1942 | ||
@@ -1974,7 +1944,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1974 | else | 1944 | else |
1975 | mlp->pv.co_Q[i_delay] = DEFAULT_QUALITY; | 1945 | mlp->pv.co_Q[i_delay] = DEFAULT_QUALITY; |
1976 | 1946 | ||
1977 | if ((i_distance != MLP_NaN) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", | 1947 | if ((i_distance != MLP_NaN) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", |
1978 | "MLP_COEFFICIENT_QUALITY_DISTANCE", | 1948 | "MLP_COEFFICIENT_QUALITY_DISTANCE", |
1979 | &tmp))) | 1949 | &tmp))) |
1980 | mlp->pv.co_Q[i_distance] = (double) tmp / 100; | 1950 | mlp->pv.co_Q[i_distance] = (double) tmp / 100; |
@@ -1982,7 +1952,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1982 | mlp->pv.co_Q[i_distance] = DEFAULT_QUALITY; | 1952 | mlp->pv.co_Q[i_distance] = DEFAULT_QUALITY; |
1983 | 1953 | ||
1984 | /* Get minimum bandwidth per used address from configuration */ | 1954 | /* Get minimum bandwidth per used address from configuration */ |
1985 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", | 1955 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", |
1986 | "MLP_MIN_BANDWIDTH", | 1956 | "MLP_MIN_BANDWIDTH", |
1987 | &tmp)) | 1957 | &tmp)) |
1988 | b_min = tmp; | 1958 | b_min = tmp; |
@@ -1992,7 +1962,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1992 | } | 1962 | } |
1993 | 1963 | ||
1994 | /* Get minimum number of connections from configuration */ | 1964 | /* Get minimum number of connections from configuration */ |
1995 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", | 1965 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", |
1996 | "MLP_MIN_CONNECTIONS", | 1966 | "MLP_MIN_CONNECTIONS", |
1997 | &tmp)) | 1967 | &tmp)) |
1998 | n_min = tmp; | 1968 | n_min = tmp; |
@@ -2004,13 +1974,13 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2004 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | 1974 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) |
2005 | { | 1975 | { |
2006 | found = GNUNET_NO; | 1976 | found = GNUNET_NO; |
2007 | for (c2 = 0; c2 < dest_length; c2++) | 1977 | for (c2 = 0; c2 < env->network_count; c2++) |
2008 | { | 1978 | { |
2009 | if (quotas[c] == network[c2]) | 1979 | if (quotas[c] == env->networks[c2]) |
2010 | { | 1980 | { |
2011 | mlp->pv.quota_index[c] = network[c2]; | 1981 | mlp->pv.quota_index[c] = env->networks[c2]; |
2012 | mlp->pv.quota_out[c] = out_dest[c2]; | 1982 | mlp->pv.quota_out[c] = env->out_quota[c2]; |
2013 | mlp->pv.quota_in[c] = in_dest[c2]; | 1983 | mlp->pv.quota_in[c] = env->in_quota[c2]; |
2014 | found = GNUNET_YES; | 1984 | found = GNUNET_YES; |
2015 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Quota for network `%s' (in/out) %llu/%llu\n", | 1985 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Quota for network `%s' (in/out) %llu/%llu\n", |
2016 | GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), | 1986 | GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), |
@@ -2066,17 +2036,32 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2066 | mlp->pv.quota_out[c]); | 2036 | mlp->pv.quota_out[c]); |
2067 | } | 2037 | } |
2068 | } | 2038 | } |
2039 | mlp->env = env; | ||
2040 | env->sf.s_add = &GAS_mlp_address_add; | ||
2041 | env->sf.s_address_update_property = &GAS_mlp_address_property_changed; | ||
2042 | env->sf.s_address_update_session = &GAS_mlp_address_session_changed; | ||
2043 | env->sf.s_address_update_inuse = &GAS_mlp_address_inuse_changed; | ||
2044 | env->sf.s_address_update_network = &GAS_mlp_address_change_network; | ||
2045 | env->sf.s_get = &GAS_mlp_get_preferred_address; | ||
2046 | env->sf.s_get_stop = &GAS_mlp_stop_get_preferred_address; | ||
2047 | env->sf.s_pref = &GAS_mlp_address_change_preference; | ||
2048 | env->sf.s_feedback = &GAS_mlp_address_preference_feedback; | ||
2049 | env->sf.s_del = &GAS_mlp_address_delete; | ||
2050 | env->sf.s_bulk_start = &GAS_mlp_bulk_start; | ||
2051 | env->sf.s_bulk_stop = &GAS_mlp_bulk_stop; | ||
2052 | |||
2069 | 2053 | ||
2070 | /* Assign options to handle */ | 2054 | /* Assign options to handle */ |
2071 | mlp->stats = (struct GNUNET_STATISTICS_Handle *) stats; | 2055 | mlp->stats = (struct GNUNET_STATISTICS_Handle *) env->stats; |
2072 | mlp->addresses = addresses; | 2056 | mlp->addresses = env->addresses; |
2073 | mlp->bw_changed_cb = bw_changed_cb; | 2057 | mlp->bw_changed_cb = env->bandwidth_changed_cb; |
2074 | mlp->bw_changed_cb_cls = bw_changed_cb_cls; | 2058 | mlp->bw_changed_cb_cls = env->bw_changed_cb_cls; |
2075 | mlp->get_preferences = get_preference; | 2059 | mlp->get_preferences = env->get_preferences_cb; |
2076 | mlp->get_preferences_cls = get_preference_cls; | 2060 | mlp->get_preferences_cls = env->get_preference_cls; |
2077 | mlp->get_properties = get_properties; | 2061 | mlp->get_properties = env->get_property_cb; |
2078 | mlp->get_properties_cls = get_properties_cls; | 2062 | mlp->get_properties_cls = env->get_property_cls; |
2079 | /* Setting MLP Input variables */ | 2063 | /* Setting MLP Input variables */ |
2064 | |||
2080 | mlp->pv.co_D = D; | 2065 | mlp->pv.co_D = D; |
2081 | mlp->pv.co_R = R; | 2066 | mlp->pv.co_R = R; |
2082 | mlp->pv.co_U = U; | 2067 | mlp->pv.co_U = U; |
diff --git a/src/ats/gnunet-service-ats-solver_mlp.h b/src/ats/libgnunet_plugin_ats_mlp.h index 1f4f0ec8c..6d04bbe80 100644 --- a/src/ats/gnunet-service-ats-solver_mlp.h +++ b/src/ats/libgnunet_plugin_ats_mlp.h | |||
@@ -24,8 +24,11 @@ | |||
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_statistics_service.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_ats_service.h" | ||
29 | #include "gnunet_ats_plugin.h" | ||
28 | #include "gnunet-service-ats_addresses.h" | 30 | #include "gnunet-service-ats_addresses.h" |
31 | #include "gnunet_statistics_service.h" | ||
29 | #if HAVE_LIBGLPK | 32 | #if HAVE_LIBGLPK |
30 | #include "glpk.h" | 33 | #include "glpk.h" |
31 | #endif | 34 | #endif |
@@ -204,6 +207,8 @@ struct MLP_Variables | |||
204 | */ | 207 | */ |
205 | struct GAS_MLP_Handle | 208 | struct GAS_MLP_Handle |
206 | { | 209 | { |
210 | struct GNUNET_ATS_PluginEnvironment *env; | ||
211 | |||
207 | /** | 212 | /** |
208 | * Statistics handle | 213 | * Statistics handle |
209 | */ | 214 | */ |
diff --git a/src/ats/gnunet-service-ats-solver_proportional.c b/src/ats/libgnunet_plugin_ats_proportional.c index db9fcff85..f5f0f2fef 100644 --- a/src/ats/gnunet-service-ats-solver_proportional.c +++ b/src/ats/libgnunet_plugin_ats_proportional.c | |||
@@ -24,13 +24,11 @@ | |||
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "libgnunet_plugin_ats_proportional.h" |
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet-service-ats_addresses.h" | ||
30 | #include "gnunet_statistics_service.h" | ||
31 | 28 | ||
32 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-proportional",__VA_ARGS__) | 29 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-proportional",__VA_ARGS__) |
33 | 30 | ||
31 | |||
34 | /** | 32 | /** |
35 | * | 33 | * |
36 | * NOTE: Do not change this documentation. This documentation is based | 34 | * NOTE: Do not change this documentation. This documentation is based |
@@ -217,6 +215,8 @@ | |||
217 | */ | 215 | */ |
218 | struct GAS_PROPORTIONAL_Handle | 216 | struct GAS_PROPORTIONAL_Handle |
219 | { | 217 | { |
218 | struct GNUNET_ATS_PluginEnvironment *env; | ||
219 | |||
220 | /** | 220 | /** |
221 | * Statistics handle | 221 | * Statistics handle |
222 | */ | 222 | */ |
@@ -290,7 +290,7 @@ struct GAS_PROPORTIONAL_Handle | |||
290 | /** | 290 | /** |
291 | * Number of networks | 291 | * Number of networks |
292 | */ | 292 | */ |
293 | unsigned int networks; | 293 | unsigned int network_count; |
294 | 294 | ||
295 | }; | 295 | }; |
296 | 296 | ||
@@ -371,6 +371,129 @@ struct AddressWrapper | |||
371 | * --------------------------- | 371 | * --------------------------- |
372 | */ | 372 | */ |
373 | 373 | ||
374 | void * | ||
375 | libgnunet_plugin_ats_proportional_init (void *cls) | ||
376 | { | ||
377 | struct GNUNET_ATS_PluginEnvironment *env = cls; | ||
378 | struct GAS_PROPORTIONAL_Handle *s; | ||
379 | struct Network * cur; | ||
380 | char * net_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; | ||
381 | int c; | ||
382 | |||
383 | GNUNET_assert (NULL != env); | ||
384 | GNUNET_assert(NULL != env->cfg); | ||
385 | GNUNET_assert(NULL != env->stats); | ||
386 | GNUNET_assert(NULL != env->bandwidth_changed_cb); | ||
387 | GNUNET_assert(NULL != env->get_preferences_cb); | ||
388 | GNUNET_assert(NULL != env->get_property_cb); | ||
389 | |||
390 | s = GNUNET_malloc (sizeof (struct GAS_PROPORTIONAL_Handle)); | ||
391 | s->env = env; | ||
392 | env->sf.s_add = &GAS_proportional_address_add; | ||
393 | env->sf.s_address_update_property = &GAS_proportional_address_property_changed; | ||
394 | env->sf.s_address_update_session = &GAS_proportional_address_session_changed; | ||
395 | env->sf.s_address_update_inuse = &GAS_proportional_address_inuse_changed; | ||
396 | env->sf.s_address_update_network = &GAS_proportional_address_change_network; | ||
397 | env->sf.s_get = &GAS_proportional_get_preferred_address; | ||
398 | env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address; | ||
399 | env->sf.s_pref = &GAS_proportional_address_change_preference; | ||
400 | env->sf.s_feedback = &GAS_proportional_address_preference_feedback; | ||
401 | env->sf.s_del = &GAS_proportional_address_delete; | ||
402 | env->sf.s_bulk_start = &GAS_proportional_bulk_start; | ||
403 | env->sf.s_bulk_stop = &GAS_proportional_bulk_stop; | ||
404 | |||
405 | s->stats = (struct GNUNET_STATISTICS_Handle *) env->stats; | ||
406 | s->bw_changed = env->bandwidth_changed_cb; | ||
407 | s->bw_changed_cls = env->bw_changed_cb_cls; | ||
408 | s->get_preferences = env->get_preferences_cb; | ||
409 | s->get_preferences_cls = env->get_preference_cls; | ||
410 | s->get_properties = env->get_property_cb; | ||
411 | s->get_properties_cls = env->get_property_cls; | ||
412 | s->network_count = env->network_count; | ||
413 | s->network_entries = GNUNET_malloc (env->network_count * sizeof (struct Network)); | ||
414 | |||
415 | /* Init */ | ||
416 | s->active_addresses = 0; | ||
417 | s->total_addresses = 0; | ||
418 | s->bulk_lock = GNUNET_NO; | ||
419 | s->addresses = env->addresses; | ||
420 | s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | ||
421 | |||
422 | for (c = 0; c < env->network_count; c++) | ||
423 | { | ||
424 | cur = &s->network_entries[c]; | ||
425 | cur->total_addresses = 0; | ||
426 | cur->active_addresses = 0; | ||
427 | cur->type = env->networks[c]; | ||
428 | cur->total_quota_in = env->in_quota[c]; | ||
429 | cur->total_quota_out = env->out_quota[c]; | ||
430 | cur->desc = net_str[c]; | ||
431 | GNUNET_asprintf (&cur->stat_total, | ||
432 | "# ATS addresses %s total", cur->desc); | ||
433 | GNUNET_asprintf (&cur->stat_active, | ||
434 | "# ATS active addresses %s total", cur->desc); | ||
435 | LOG (GNUNET_ERROR_TYPE_INFO, "Added network %u `%s' %p\n", c, cur->desc, s); | ||
436 | } | ||
437 | return s; | ||
438 | } | ||
439 | |||
440 | void * | ||
441 | libgnunet_plugin_ats_proportional_done (void *cls) | ||
442 | { | ||
443 | struct GAS_PROPORTIONAL_Handle *s = cls; | ||
444 | struct AddressWrapper *cur; | ||
445 | struct AddressWrapper *next; | ||
446 | int c; | ||
447 | GNUNET_assert(s != NULL); | ||
448 | for (c = 0; c < s->network_count; c++) | ||
449 | { | ||
450 | if (s->network_entries[c].total_addresses > 0) | ||
451 | { | ||
452 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
453 | "Had %u addresses for network `%s' not deleted during shutdown\n", | ||
454 | s->network_entries[c].total_addresses, s->network_entries[c].desc); | ||
455 | GNUNET_break(0); | ||
456 | } | ||
457 | |||
458 | if (s->network_entries[c].active_addresses > 0) | ||
459 | { | ||
460 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
461 | "Had %u active addresses for network `%s' not deleted during shutdown\n", | ||
462 | s->network_entries[c].active_addresses, s->network_entries[c].desc); | ||
463 | GNUNET_break(0); | ||
464 | } | ||
465 | |||
466 | next = s->network_entries[c].head; | ||
467 | while (NULL != (cur = next)) | ||
468 | { | ||
469 | next = cur->next; | ||
470 | GNUNET_CONTAINER_DLL_remove(s->network_entries[c].head, | ||
471 | s->network_entries[c].tail, cur); | ||
472 | GNUNET_free(cur); | ||
473 | } | ||
474 | GNUNET_free(s->network_entries[c].stat_total); | ||
475 | GNUNET_free(s->network_entries[c].stat_active); | ||
476 | } | ||
477 | if (s->total_addresses > 0) | ||
478 | { | ||
479 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
480 | "Had %u addresses not deleted during shutdown\n", s->total_addresses); | ||
481 | GNUNET_break(0); | ||
482 | } | ||
483 | if (s->active_addresses > 0) | ||
484 | { | ||
485 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
486 | "Had %u active addresses not deleted during shutdown\n", | ||
487 | s->active_addresses); | ||
488 | GNUNET_break (0); | ||
489 | } | ||
490 | GNUNET_free (s->network_entries); | ||
491 | GNUNET_CONTAINER_multipeermap_destroy (s->requests); | ||
492 | GNUNET_free (s); | ||
493 | return NULL; | ||
494 | } | ||
495 | |||
496 | |||
374 | /** | 497 | /** |
375 | * Test if bandwidth is available in this network to add an additional address | 498 | * Test if bandwidth is available in this network to add an additional address |
376 | * | 499 | * |
@@ -688,7 +811,7 @@ static void | |||
688 | distribute_bandwidth_in_all_networks (struct GAS_PROPORTIONAL_Handle *s) | 811 | distribute_bandwidth_in_all_networks (struct GAS_PROPORTIONAL_Handle *s) |
689 | { | 812 | { |
690 | int i; | 813 | int i; |
691 | for (i = 0; i < s->networks; i++) | 814 | for (i = 0; i < s->network_count; i++) |
692 | distribute_bandwidth_in_network (s, &s->network_entries[i], NULL ); | 815 | distribute_bandwidth_in_network (s, &s->network_entries[i], NULL ); |
693 | } | 816 | } |
694 | 817 | ||
@@ -703,7 +826,7 @@ static struct Network * | |||
703 | get_network (struct GAS_PROPORTIONAL_Handle *s, uint32_t type) | 826 | get_network (struct GAS_PROPORTIONAL_Handle *s, uint32_t type) |
704 | { | 827 | { |
705 | int c; | 828 | int c; |
706 | for (c = 0; c < s->networks; c++) | 829 | for (c = 0; c < s->network_count; c++) |
707 | { | 830 | { |
708 | if (s->network_entries[c].type == type) | 831 | if (s->network_entries[c].type == type) |
709 | return &s->network_entries[c]; | 832 | return &s->network_entries[c]; |
@@ -1380,149 +1503,5 @@ GAS_proportional_address_add (void *solver, struct ATS_Address *address, | |||
1380 | net->total_addresses, net->active_addresses, net->desc); | 1503 | net->total_addresses, net->active_addresses, net->desc); |
1381 | } | 1504 | } |
1382 | 1505 | ||
1383 | /** | ||
1384 | * Init the proportional problem solver | ||
1385 | * | ||
1386 | * Quotas: | ||
1387 | * network[i] contains the network type as type GNUNET_ATS_NetworkType[i] | ||
1388 | * out_quota[i] contains outbound quota for network type i | ||
1389 | * in_quota[i] contains inbound quota for network type i | ||
1390 | * | ||
1391 | * Example | ||
1392 | * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN} | ||
1393 | * network[2] == GNUNET_ATS_NET_LAN | ||
1394 | * out_quota[2] == 65353 | ||
1395 | * in_quota[2] == 65353 | ||
1396 | * | ||
1397 | * @param cfg configuration handle | ||
1398 | * @param stats the GNUNET_STATISTICS handle | ||
1399 | * @param addresses hashmap containing all addresses | ||
1400 | * @param network array of GNUNET_ATS_NetworkType with length dest_length | ||
1401 | * @param out_quota array of outbound quotas | ||
1402 | * @param in_quota array of outbound quota | ||
1403 | * @param dest_length array length for quota arrays | ||
1404 | * @param bw_changed_cb callback for changed bandwidth amounts | ||
1405 | * @param bw_changed_cb_cls cls for callback | ||
1406 | * @param get_preference callback to get relative preferences for a peer | ||
1407 | * @param get_preference_cls cls for callback to get relative preferences | ||
1408 | * @param get_properties for callback to get relative properties | ||
1409 | * @param get_properties_cls cls for callback to get relative properties | ||
1410 | * @return handle for the solver on success, NULL on fail | ||
1411 | */ | ||
1412 | void * | ||
1413 | GAS_proportional_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
1414 | const struct GNUNET_STATISTICS_Handle *stats, | ||
1415 | const struct GNUNET_CONTAINER_MultiPeerMap *addresses, int *network, | ||
1416 | unsigned long long *out_quota, unsigned long long *in_quota, | ||
1417 | int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, | ||
1418 | void *bw_changed_cb_cls, GAS_get_preferences get_preference, | ||
1419 | void *get_preference_cls, GAS_get_properties get_properties, | ||
1420 | void *get_properties_cls) | ||
1421 | { | ||
1422 | int c; | ||
1423 | struct GAS_PROPORTIONAL_Handle *s = | ||
1424 | GNUNET_malloc (sizeof (struct GAS_PROPORTIONAL_Handle)); | ||
1425 | struct Network * cur; | ||
1426 | char * net_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; | ||
1427 | |||
1428 | GNUNET_assert(NULL != cfg); | ||
1429 | GNUNET_assert(NULL != stats); | ||
1430 | GNUNET_assert(NULL != network); | ||
1431 | GNUNET_assert(NULL != bw_changed_cb); | ||
1432 | GNUNET_assert(NULL != get_preference); | ||
1433 | GNUNET_assert(NULL != get_properties); | ||
1434 | |||
1435 | s->stats = (struct GNUNET_STATISTICS_Handle *) stats; | ||
1436 | s->bw_changed = bw_changed_cb; | ||
1437 | s->bw_changed_cls = bw_changed_cb_cls; | ||
1438 | s->get_preferences = get_preference; | ||
1439 | s->get_preferences_cls = get_preference_cls; | ||
1440 | s->get_properties = get_properties; | ||
1441 | s->get_properties_cls = get_properties_cls; | ||
1442 | s->networks = dest_length; | ||
1443 | s->network_entries = GNUNET_malloc (dest_length * sizeof (struct Network)); | ||
1444 | s->active_addresses = 0; | ||
1445 | s->total_addresses = 0; | ||
1446 | s->bulk_lock = GNUNET_NO; | ||
1447 | s->addresses = addresses; | ||
1448 | |||
1449 | s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | ||
1450 | |||
1451 | for (c = 0; c < dest_length; c++) | ||
1452 | { | ||
1453 | cur = &s->network_entries[c]; | ||
1454 | cur->total_addresses = 0; | ||
1455 | cur->active_addresses = 0; | ||
1456 | cur->type = network[c]; | ||
1457 | cur->total_quota_in = in_quota[c]; | ||
1458 | cur->total_quota_out = out_quota[c]; | ||
1459 | cur->desc = net_str[c]; | ||
1460 | GNUNET_asprintf (&cur->stat_total, "# ATS addresses %s total", cur->desc); | ||
1461 | GNUNET_asprintf (&cur->stat_active, "# ATS active addresses %s total", | ||
1462 | cur->desc); | ||
1463 | } | ||
1464 | return s; | ||
1465 | } | ||
1466 | |||
1467 | /** | ||
1468 | * Shutdown the proportional problem solver | ||
1469 | * | ||
1470 | * @param solver the respective handle to shutdown | ||
1471 | */ | ||
1472 | void | ||
1473 | GAS_proportional_done (void *solver) | ||
1474 | { | ||
1475 | struct GAS_PROPORTIONAL_Handle *s = solver; | ||
1476 | struct AddressWrapper *cur; | ||
1477 | struct AddressWrapper *next; | ||
1478 | int c; | ||
1479 | GNUNET_assert(s != NULL); | ||
1480 | |||
1481 | for (c = 0; c < s->networks; c++) | ||
1482 | { | ||
1483 | if (s->network_entries[c].total_addresses > 0) | ||
1484 | { | ||
1485 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1486 | "Had %u addresses for network `%s' not deleted during shutdown\n", | ||
1487 | s->network_entries[c].total_addresses, s->network_entries[c].desc); | ||
1488 | GNUNET_break(0); | ||
1489 | } | ||
1490 | |||
1491 | if (s->network_entries[c].active_addresses > 0) | ||
1492 | { | ||
1493 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1494 | "Had %u active addresses for network `%s' not deleted during shutdown\n", | ||
1495 | s->network_entries[c].active_addresses, s->network_entries[c].desc); | ||
1496 | GNUNET_break(0); | ||
1497 | } | ||
1498 | |||
1499 | next = s->network_entries[c].head; | ||
1500 | while (NULL != (cur = next)) | ||
1501 | { | ||
1502 | next = cur->next; | ||
1503 | GNUNET_CONTAINER_DLL_remove(s->network_entries[c].head, | ||
1504 | s->network_entries[c].tail, cur); | ||
1505 | GNUNET_free(cur); | ||
1506 | } | ||
1507 | GNUNET_free(s->network_entries[c].stat_total); | ||
1508 | GNUNET_free(s->network_entries[c].stat_active); | ||
1509 | } | ||
1510 | if (s->total_addresses > 0) | ||
1511 | { | ||
1512 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1513 | "Had %u addresses not deleted during shutdown\n", s->total_addresses); | ||
1514 | GNUNET_break(0); | ||
1515 | } | ||
1516 | if (s->active_addresses > 0) | ||
1517 | { | ||
1518 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1519 | "Had %u active addresses not deleted during shutdown\n", | ||
1520 | s->active_addresses); | ||
1521 | GNUNET_break (0); | ||
1522 | } | ||
1523 | GNUNET_free (s->network_entries); | ||
1524 | GNUNET_CONTAINER_multipeermap_destroy (s->requests); | ||
1525 | GNUNET_free (s); | ||
1526 | } | ||
1527 | 1506 | ||
1528 | /* end of gnunet-service-ats-solver_proportional.c */ | 1507 | /* end of gnunet-service-ats-solver_proportional.c */ |
diff --git a/src/ats/gnunet-service-ats-solver_proportional.h b/src/ats/libgnunet_plugin_ats_proportional.h index 87b448866..1de64a808 100644 --- a/src/ats/gnunet-service-ats-solver_proportional.h +++ b/src/ats/libgnunet_plugin_ats_proportional.h | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_statistics_service.h" | 28 | #include "gnunet_statistics_service.h" |
29 | #include "gnunet_ats_plugin.h" | ||
29 | #include "gnunet-service-ats_addresses.h" | 30 | #include "gnunet-service-ats_addresses.h" |
30 | 31 | ||
31 | /** | 32 | /** |
@@ -64,45 +65,6 @@ GAS_proportional_address_preference_feedback (void *solver, void *application, | |||
64 | enum GNUNET_ATS_PreferenceKind kind, double score); | 65 | enum GNUNET_ATS_PreferenceKind kind, double score); |
65 | 66 | ||
66 | /** | 67 | /** |
67 | * Init the proportional problem solver | ||
68 | * | ||
69 | * Quotas: | ||
70 | * network[i] contains the network type as type GNUNET_ATS_NetworkType[i] | ||
71 | * out_quota[i] contains outbound quota for network type i | ||
72 | * in_quota[i] contains inbound quota for network type i | ||
73 | * | ||
74 | * Example | ||
75 | * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN} | ||
76 | * network[2] == GNUNET_ATS_NET_LAN | ||
77 | * out_quota[2] == 65353 | ||
78 | * in_quota[2] == 65353 | ||
79 | * | ||
80 | * @param cfg configuration handle | ||
81 | * @param stats the GNUNET_STATISTICS handle | ||
82 | * @param network array of GNUNET_ATS_NetworkType with length dest_length | ||
83 | * @param addresses hashmap containing all addresses | ||
84 | * @param out_quota array of outbound quotas | ||
85 | * @param in_quota array of outbound quota | ||
86 | * @param dest_length array length for quota arrays | ||
87 | * @param bw_changed_cb callback for changed bandwidth amounts | ||
88 | * @param bw_changed_cb_cls cls for callback | ||
89 | * @param get_preference callback to get relative preferences for a peer | ||
90 | * @param get_preference_cls cls for callback to get relative preferences | ||
91 | * @param get_properties_cls for callback to get relative properties | ||
92 | * @param get_properties_cls cls for callback to get relative properties | ||
93 | * @return handle for the solver on success, NULL on fail | ||
94 | */ | ||
95 | void * | ||
96 | GAS_proportional_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
97 | const struct GNUNET_STATISTICS_Handle *stats, | ||
98 | const struct GNUNET_CONTAINER_MultiPeerMap *addresses, int *network, | ||
99 | unsigned long long *out_quota, unsigned long long *in_quota, | ||
100 | int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, | ||
101 | void *bw_changed_cb_cls, GAS_get_preferences get_preference, | ||
102 | void *get_preference_cls, GAS_get_properties get_properties, | ||
103 | void *get_properties_cls); | ||
104 | |||
105 | /** | ||
106 | * Shutdown the proportional problem solver | 68 | * Shutdown the proportional problem solver |
107 | * | 69 | * |
108 | * @param solver the respective handle to shutdown | 70 | * @param solver the respective handle to shutdown |
diff --git a/src/include/gnunet_ats_plugin.h b/src/include/gnunet_ats_plugin.h new file mode 100644 index 000000000..e6c22d3c8 --- /dev/null +++ b/src/include/gnunet_ats_plugin.h | |||
@@ -0,0 +1,328 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2009, 2010 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 include/gnunet_solver_plugin.h | ||
23 | * @brief API for the ATS solvers. This header | ||
24 | * specifies the struct that is given to the plugin's entry | ||
25 | * method and the other struct that must be returned. | ||
26 | * Note that the destructors of ATS plugins will | ||
27 | * be given the value returned by the constructor | ||
28 | * and is expected to return a NULL pointer. | ||
29 | * @author Christian Grothoff | ||
30 | */ | ||
31 | #ifndef PLUGIN_ATS_H | ||
32 | #define PLUGIN_ATS_H | ||
33 | |||
34 | #include "gnunet_ats_service.h" | ||
35 | #include "gnunet_statistics_service.h" | ||
36 | |||
37 | struct ATS_Address; | ||
38 | |||
39 | |||
40 | /* | ||
41 | * Solver API | ||
42 | * ---------- | ||
43 | */ | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Change the preference for a peer | ||
48 | * | ||
49 | * @param handle the solver handle | ||
50 | * @param client the client sending this request | ||
51 | * @param peer the peer id | ||
52 | * @param kind the preference kind to change | ||
53 | * @param score the new preference score | ||
54 | * @param pref_rel the normalized preference value for this kind over all clients | ||
55 | */ | ||
56 | typedef void | ||
57 | (*GAS_solver_address_change_preference) (void *solver, | ||
58 | const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, | ||
59 | double pref_rel); | ||
60 | |||
61 | /** | ||
62 | * Give feedback about the current assignment | ||
63 | * | ||
64 | * @param handle the solver handle | ||
65 | * @param application the application sending this request | ||
66 | * @param peer the peer id | ||
67 | * @param scope the time interval for this feedback: [now - scope .. now] | ||
68 | * @param kind the preference kind for this feedback | ||
69 | * @param score the feedback score | ||
70 | */ | ||
71 | typedef void | ||
72 | (*GAS_solver_address_feedback_preference) (void *solver, void *application, | ||
73 | const struct GNUNET_PeerIdentity *peer, | ||
74 | const struct GNUNET_TIME_Relative scope, | ||
75 | enum GNUNET_ATS_PreferenceKind kind, double score); | ||
76 | |||
77 | /** | ||
78 | * Notify the solver about a bulk operation changing possibly a lot of values | ||
79 | * Solver will not resolve until all bulk operations are marked as done | ||
80 | * | ||
81 | * @param solver the solver | ||
82 | */ | ||
83 | typedef void | ||
84 | (*GAS_solver_bulk_start) (void *solver); | ||
85 | |||
86 | /** | ||
87 | * Mark a bulk operation as done | ||
88 | * Solver will resolve if values have changed | ||
89 | * | ||
90 | * @param solver the solver | ||
91 | */ | ||
92 | typedef void | ||
93 | (*GAS_solver_bulk_stop) (void *solver); | ||
94 | |||
95 | /** | ||
96 | * Add a single address within a network to the solver | ||
97 | * | ||
98 | * @param solver the solver Handle | ||
99 | * @param addresses the address hashmap containing all addresses | ||
100 | * @param address the address to add | ||
101 | * @param network network type of this address | ||
102 | */ | ||
103 | typedef void | ||
104 | (*GAS_solver_address_add) (void *solver, struct ATS_Address *address, | ||
105 | uint32_t network); | ||
106 | |||
107 | /** | ||
108 | * Delete an address or just the session from the solver | ||
109 | * | ||
110 | * @param solver the solver Handle | ||
111 | * @param addresses the address hashmap containing all addresses | ||
112 | * @param address the address to delete | ||
113 | * @param session_only remove address or just session | ||
114 | */ | ||
115 | typedef void | ||
116 | (*GAS_solver_address_delete) (void *solver, struct ATS_Address *address, | ||
117 | int session_only); | ||
118 | |||
119 | /** | ||
120 | * Transport properties for this address have changed | ||
121 | * | ||
122 | * @param solver solver handle | ||
123 | * @param address the address | ||
124 | * @param type the ATSI type in HBO | ||
125 | * @param abs_value the absolute value of the property | ||
126 | * @param rel_value the normalized value | ||
127 | */ | ||
128 | typedef void | ||
129 | (*GAS_solver_address_property_changed) (void *solver, | ||
130 | struct ATS_Address *address, uint32_t type, uint32_t abs_value, | ||
131 | double rel_value); | ||
132 | |||
133 | /** | ||
134 | * Transport session for this address has changed | ||
135 | * | ||
136 | * NOTE: values in addresses are already updated | ||
137 | * | ||
138 | * @param solver solver handle | ||
139 | * @param address the address | ||
140 | * @param cur_session the current session | ||
141 | * @param new_session the new session | ||
142 | */ | ||
143 | typedef void | ||
144 | (*GAS_solver_address_session_changed) (void *solver, | ||
145 | struct ATS_Address *address, uint32_t cur_session, uint32_t new_session); | ||
146 | |||
147 | /** | ||
148 | * Transport session for this address has changed | ||
149 | * | ||
150 | * NOTE: values in addresses are already updated | ||
151 | * | ||
152 | * @param solver solver handle | ||
153 | * @param address the address | ||
154 | * @param in_use usage state | ||
155 | */ | ||
156 | typedef void | ||
157 | (*GAS_solver_address_inuse_changed) (void *solver, struct ATS_Address *address, | ||
158 | int in_use); | ||
159 | |||
160 | /** | ||
161 | * Network scope for this address has changed | ||
162 | * | ||
163 | * NOTE: values in addresses are already updated | ||
164 | * | ||
165 | * @param solver solver handle | ||
166 | * @param address the address | ||
167 | * @param current_network the current network | ||
168 | * @param new_network the new network | ||
169 | */ | ||
170 | typedef void | ||
171 | (*GAS_solver_address_network_changed) (void *solver, | ||
172 | struct ATS_Address *address, uint32_t current_network, uint32_t new_network); | ||
173 | |||
174 | /** | ||
175 | * Get the prefered address for a peer from solver | ||
176 | * | ||
177 | * @param solver the solver to use | ||
178 | * @param addresses the address hashmap containing all addresses | ||
179 | * @param peer the peer | ||
180 | */ | ||
181 | typedef const struct ATS_Address * | ||
182 | (*GAS_solver_get_preferred_address) (void *solver, | ||
183 | const struct GNUNET_PeerIdentity *peer); | ||
184 | |||
185 | /** | ||
186 | * Stop getting the prefered address for a peer from solver | ||
187 | * | ||
188 | * @param solver the solver to use | ||
189 | * @param addresses the address hashmap containing all addresses | ||
190 | * @param peer the peer | ||
191 | */ | ||
192 | typedef void | ||
193 | (*GAS_solver_stop_get_preferred_address) (void *solver, | ||
194 | const struct GNUNET_PeerIdentity *peer); | ||
195 | |||
196 | |||
197 | /** | ||
198 | * Each plugin is required to return a pointer to a struct of this | ||
199 | * type as the return value from its entry point. | ||
200 | */ | ||
201 | struct GNUNET_ATS_SolverFunctions | ||
202 | { | ||
203 | |||
204 | /** | ||
205 | * Closure for all of the callbacks. | ||
206 | */ | ||
207 | void *cls; | ||
208 | |||
209 | /** | ||
210 | * Add an address to the solver | ||
211 | */ | ||
212 | GAS_solver_address_add s_add; | ||
213 | |||
214 | GAS_solver_address_property_changed s_address_update_property; | ||
215 | |||
216 | GAS_solver_address_session_changed s_address_update_session; | ||
217 | |||
218 | GAS_solver_address_inuse_changed s_address_update_inuse; | ||
219 | |||
220 | GAS_solver_address_network_changed s_address_update_network; | ||
221 | |||
222 | /** | ||
223 | * Get address from solver | ||
224 | */ | ||
225 | GAS_solver_get_preferred_address s_get; | ||
226 | |||
227 | /** | ||
228 | * Get address from solver | ||
229 | */ | ||
230 | GAS_solver_stop_get_preferred_address s_get_stop; | ||
231 | |||
232 | /** | ||
233 | * Delete address in solver | ||
234 | */ | ||
235 | GAS_solver_address_delete s_del; | ||
236 | |||
237 | /** | ||
238 | * Change relative preference for quality in solver | ||
239 | */ | ||
240 | GAS_solver_address_change_preference s_pref; | ||
241 | |||
242 | /** | ||
243 | * Give feedback about the current assignment | ||
244 | */ | ||
245 | GAS_solver_address_feedback_preference s_feedback; | ||
246 | |||
247 | /** | ||
248 | * Start a bulk operation | ||
249 | */ | ||
250 | GAS_solver_bulk_start s_bulk_start; | ||
251 | |||
252 | /** | ||
253 | * Bulk operation done | ||
254 | */ | ||
255 | GAS_solver_bulk_stop s_bulk_stop; | ||
256 | |||
257 | }; | ||
258 | |||
259 | |||
260 | /** | ||
261 | * Callback to call from solver when bandwidth for address has changed | ||
262 | * | ||
263 | * @param address the with changed bandwidth assigned | ||
264 | */ | ||
265 | typedef void | ||
266 | (*GAS_bandwidth_changed_cb) (void *cls, struct ATS_Address *address); | ||
267 | |||
268 | /** | ||
269 | * Callback to call from solver to obtain application preference values for a | ||
270 | * peer | ||
271 | * | ||
272 | * @param cls the cls | ||
273 | * @param id the peer id | ||
274 | * @return carry of double values containing the preferences with | ||
275 | * GNUNET_ATS_PreferenceCount elements | ||
276 | */ | ||
277 | typedef const double * | ||
278 | (*GAS_get_preferences) (void *cls, const struct GNUNET_PeerIdentity *id); | ||
279 | |||
280 | /** | ||
281 | * Callback to call from solver to obtain transport properties for an | ||
282 | * address | ||
283 | * | ||
284 | * @param cls the cls | ||
285 | * @param address the address | ||
286 | * @return carry of double values containing the preferences with | ||
287 | * GNUNET_ATS_PreferenceCount elements | ||
288 | */ | ||
289 | typedef const double * | ||
290 | (*GAS_get_properties) (void *cls, const struct ATS_Address *address); | ||
291 | |||
292 | |||
293 | /** | ||
294 | * The transport service will pass a pointer to a struct | ||
295 | * of this type as the first and only argument to the | ||
296 | * entry point of each transport plugin. | ||
297 | */ | ||
298 | struct GNUNET_ATS_PluginEnvironment | ||
299 | { | ||
300 | /** | ||
301 | * Closure for the various callbacks. | ||
302 | */ | ||
303 | void *cls; | ||
304 | |||
305 | GAS_bandwidth_changed_cb bandwidth_changed_cb; | ||
306 | void *bw_changed_cb_cls; | ||
307 | |||
308 | GAS_get_preferences get_preferences_cb; | ||
309 | void *get_preference_cls; | ||
310 | |||
311 | GAS_get_properties get_property_cb; | ||
312 | void *get_property_cls; | ||
313 | |||
314 | struct GNUNET_ATS_SolverFunctions sf; | ||
315 | |||
316 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
317 | struct GNUNET_STATISTICS_Handle *stats; | ||
318 | struct GNUNET_CONTAINER_MultiPeerMap *addresses; | ||
319 | |||
320 | /* Available networks */ | ||
321 | int networks[GNUNET_ATS_NetworkTypeCount]; | ||
322 | int network_count; | ||
323 | |||
324 | unsigned long long out_quota[GNUNET_ATS_NetworkTypeCount]; | ||
325 | unsigned long long in_quota[GNUNET_ATS_NetworkTypeCount]; | ||
326 | }; | ||
327 | |||
328 | #endif | ||