diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-10 23:24:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-10 23:24:01 +0000 |
commit | 1c323bd4cbb388a9e7515a1f733a3062bf093aee (patch) | |
tree | 7cc525d79149d44840b9f7a0040aaf3e69ecd665 /src/ats | |
parent | aedaaed687db1ff20b447378f01ad7306921450c (diff) | |
download | gnunet-1c323bd4cbb388a9e7515a1f733a3062bf093aee.tar.gz gnunet-1c323bd4cbb388a9e7515a1f733a3062bf093aee.zip |
fixing #3657 (replace ATS_Information with struct), but WIHTOUT fixing ATS testcases yet
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/Makefile.am | 34 | ||||
-rw-r--r-- | src/ats/ats.h | 54 | ||||
-rw-r--r-- | src/ats/ats_api_performance.c | 58 | ||||
-rw-r--r-- | src/ats/ats_api_scanner.c | 52 | ||||
-rw-r--r-- | src/ats/ats_api_scheduling.c | 77 | ||||
-rw-r--r-- | src/ats/gnunet-ats-solver-eval.c | 40 | ||||
-rw-r--r-- | src/ats/gnunet-ats-solver-eval.h | 6 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats.c | 3 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 465 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 43 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 299 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.h | 8 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_performance.c | 39 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_performance.h | 6 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_plugins.c | 24 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_plugins.h | 11 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_preferences.c | 20 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_scheduling.c | 53 | ||||
-rw-r--r-- | src/ats/plugin_ats_mlp.c | 230 | ||||
-rw-r--r-- | src/ats/plugin_ats_proportional.c | 45 | ||||
-rw-r--r-- | src/ats/plugin_ats_ril.c | 50 | ||||
-rw-r--r-- | src/ats/test_ats_api_common.h | 7 |
22 files changed, 512 insertions, 1112 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 4491b08a2..2a14ae73f 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -18,8 +18,8 @@ if USE_COVERAGE | |||
18 | AM_CFLAGS = -fprofile-arcs -ftest-coverage | 18 | AM_CFLAGS = -fprofile-arcs -ftest-coverage |
19 | endif | 19 | endif |
20 | 20 | ||
21 | noinst_PROGRAMS = \ | 21 | #noinst_PROGRAMS = \ |
22 | gnunet-ats-solver-eval | 22 | # gnunet-ats-solver-eval |
23 | 23 | ||
24 | if HAVE_LIBGLPK | 24 | if HAVE_LIBGLPK |
25 | GN_LIBGLPK = -lglpk | 25 | GN_LIBGLPK = -lglpk |
@@ -42,21 +42,21 @@ plugin_LTLIBRARIES = \ | |||
42 | $(GN_MLP_LIB) \ | 42 | $(GN_MLP_LIB) \ |
43 | libgnunet_plugin_ats_ril.la | 43 | libgnunet_plugin_ats_ril.la |
44 | 44 | ||
45 | gnunet_ats_solver_eval_SOURCES = \ | 45 | #gnunet_ats_solver_eval_SOURCES = \ |
46 | gnunet-ats-solver-eval.c gnunet-ats-solver-eval.h \ | 46 | # gnunet-ats-solver-eval.c gnunet-ats-solver-eval.h \ |
47 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ | 47 | # gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ |
48 | gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ | 48 | # gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ |
49 | gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ | 49 | # gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ |
50 | gnunet-service-ats_feedback.c gnunet-service-ats_feedback.h \ | 50 | # gnunet-service-ats_feedback.c gnunet-service-ats_feedback.h \ |
51 | gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ | 51 | # gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ |
52 | gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h \ | 52 | # gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h \ |
53 | gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ | 53 | # gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ |
54 | gnunet-service-ats_normalization.c | 54 | # gnunet-service-ats_normalization.c |
55 | gnunet_ats_solver_eval_LDADD = \ | 55 | #gnunet_ats_solver_eval_LDADD = \ |
56 | $(top_builddir)/src/util/libgnunetutil.la \ | 56 | # $(top_builddir)/src/util/libgnunetutil.la \ |
57 | libgnunetats.la \ | 57 | # libgnunetats.la \ |
58 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 58 | # $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
59 | $(LTLIBINTL) | 59 | # $(LTLIBINTL) |
60 | 60 | ||
61 | libgnunetats_la_SOURCES = \ | 61 | libgnunetats_la_SOURCES = \ |
62 | ats_api_connectivity.c \ | 62 | ats_api_connectivity.c \ |
diff --git a/src/ats/ats.h b/src/ats/ats.h index d5d5d6c3f..7e411fb98 100644 --- a/src/ats/ats.h +++ b/src/ats/ats.h | |||
@@ -27,6 +27,8 @@ | |||
27 | #define ATS_H | 27 | #define ATS_H |
28 | 28 | ||
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_ats_service.h" | ||
31 | |||
30 | 32 | ||
31 | /** | 33 | /** |
32 | * Flag used to indicate which type of client is connecting | 34 | * Flag used to indicate which type of client is connecting |
@@ -115,16 +117,6 @@ struct AddressAddMessage | |||
115 | struct GNUNET_MessageHeader header; | 117 | struct GNUNET_MessageHeader header; |
116 | 118 | ||
117 | /** | 119 | /** |
118 | * Length of the `struct GNUNET_ATS_Information` array that follows this struct. | ||
119 | */ | ||
120 | uint32_t ats_count GNUNET_PACKED; | ||
121 | |||
122 | /** | ||
123 | * Identity of the peer that this address is for. | ||
124 | */ | ||
125 | struct GNUNET_PeerIdentity peer; | ||
126 | |||
127 | /** | ||
128 | * Number of bytes in the address that follows this struct. | 120 | * Number of bytes in the address that follows this struct. |
129 | */ | 121 | */ |
130 | uint16_t address_length GNUNET_PACKED; | 122 | uint16_t address_length GNUNET_PACKED; |
@@ -135,6 +127,11 @@ struct AddressAddMessage | |||
135 | uint16_t plugin_name_length GNUNET_PACKED; | 127 | uint16_t plugin_name_length GNUNET_PACKED; |
136 | 128 | ||
137 | /** | 129 | /** |
130 | * Identity of the peer that this address is for. | ||
131 | */ | ||
132 | struct GNUNET_PeerIdentity peer; | ||
133 | |||
134 | /** | ||
138 | * Internal number this client will henceforth use to | 135 | * Internal number this client will henceforth use to |
139 | * refer to this address. | 136 | * refer to this address. |
140 | */ | 137 | */ |
@@ -146,8 +143,12 @@ struct AddressAddMessage | |||
146 | */ | 143 | */ |
147 | uint32_t address_local_info GNUNET_PACKED; | 144 | uint32_t address_local_info GNUNET_PACKED; |
148 | 145 | ||
146 | /** | ||
147 | * Performance properties of the address. | ||
148 | */ | ||
149 | struct GNUNET_ATS_PropertiesNBO properties; | ||
150 | |||
149 | /* followed by: | 151 | /* followed by: |
150 | * - struct GNUNET_ATS_Information [ats_count]; | ||
151 | * - char address[address_length] | 152 | * - char address[address_length] |
152 | * - char plugin_name[plugin_name_length] (including '\0'-termination). | 153 | * - char plugin_name[plugin_name_length] (including '\0'-termination). |
153 | */ | 154 | */ |
@@ -167,9 +168,9 @@ struct AddressUpdateMessage | |||
167 | struct GNUNET_MessageHeader header; | 168 | struct GNUNET_MessageHeader header; |
168 | 169 | ||
169 | /** | 170 | /** |
170 | * Length of the `struct GNUNET_ATS_Information` array that follows. | 171 | * Internal number this client uses to refer to this address. |
171 | */ | 172 | */ |
172 | uint32_t ats_count GNUNET_PACKED; | 173 | uint32_t session_id GNUNET_PACKED; |
173 | 174 | ||
174 | /** | 175 | /** |
175 | * Which peer is this about? (Technically redundant, as the | 176 | * Which peer is this about? (Technically redundant, as the |
@@ -179,13 +180,9 @@ struct AddressUpdateMessage | |||
179 | struct GNUNET_PeerIdentity peer; | 180 | struct GNUNET_PeerIdentity peer; |
180 | 181 | ||
181 | /** | 182 | /** |
182 | * Internal number this client uses to refer to this address. | 183 | * Performance properties of the address. |
183 | */ | ||
184 | uint32_t session_id GNUNET_PACKED; | ||
185 | |||
186 | /* followed by: | ||
187 | * - struct GNUNET_ATS_Information [ats_count]; | ||
188 | */ | 184 | */ |
185 | struct GNUNET_ATS_PropertiesNBO properties; | ||
189 | 186 | ||
190 | }; | 187 | }; |
191 | 188 | ||
@@ -294,17 +291,12 @@ struct PeerInformationMessage | |||
294 | /** | 291 | /** |
295 | * | 292 | * |
296 | */ | 293 | */ |
297 | uint32_t ats_count GNUNET_PACKED; | 294 | uint16_t address_length GNUNET_PACKED; |
298 | |||
299 | /** | ||
300 | * | ||
301 | */ | ||
302 | uint32_t address_active GNUNET_PACKED; | ||
303 | 295 | ||
304 | /** | 296 | /** |
305 | * | 297 | * |
306 | */ | 298 | */ |
307 | uint32_t id GNUNET_PACKED; | 299 | uint16_t plugin_name_length GNUNET_PACKED; |
308 | 300 | ||
309 | /** | 301 | /** |
310 | * | 302 | * |
@@ -314,12 +306,12 @@ struct PeerInformationMessage | |||
314 | /** | 306 | /** |
315 | * | 307 | * |
316 | */ | 308 | */ |
317 | uint16_t address_length GNUNET_PACKED; | 309 | uint32_t address_active GNUNET_PACKED; |
318 | 310 | ||
319 | /** | 311 | /** |
320 | * | 312 | * |
321 | */ | 313 | */ |
322 | uint16_t plugin_name_length GNUNET_PACKED; | 314 | uint32_t id GNUNET_PACKED; |
323 | 315 | ||
324 | /** | 316 | /** |
325 | * | 317 | * |
@@ -331,8 +323,12 @@ struct PeerInformationMessage | |||
331 | */ | 323 | */ |
332 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; | 324 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; |
333 | 325 | ||
326 | /** | ||
327 | * Performance properties of the address. | ||
328 | */ | ||
329 | struct GNUNET_ATS_PropertiesNBO properties; | ||
330 | |||
334 | /* followed by: | 331 | /* followed by: |
335 | * - struct GNUNET_ATS_Information [ats_count]; | ||
336 | * - char address[address_length] | 332 | * - char address[address_length] |
337 | * - char plugin_name[plugin_name_length] (including '\0'-termination). | 333 | * - char plugin_name[plugin_name_length] (including '\0'-termination). |
338 | */ | 334 | */ |
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index 51980f079..aaaaee089 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c | |||
@@ -364,35 +364,27 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
364 | const struct GNUNET_MessageHeader *msg) | 364 | const struct GNUNET_MessageHeader *msg) |
365 | { | 365 | { |
366 | const struct PeerInformationMessage *pi; | 366 | const struct PeerInformationMessage *pi; |
367 | const struct GNUNET_ATS_Information *atsi; | ||
368 | const char *plugin_address; | 367 | const char *plugin_address; |
369 | const char *plugin_name; | 368 | const char *plugin_name; |
370 | struct GNUNET_HELLO_Address address; | 369 | struct GNUNET_HELLO_Address address; |
371 | uint16_t plugin_address_length; | 370 | uint16_t plugin_address_length; |
372 | uint16_t plugin_name_length; | 371 | uint16_t plugin_name_length; |
373 | uint32_t ats_count; | ||
374 | int addr_active; | 372 | int addr_active; |
373 | struct GNUNET_ATS_Properties prop; | ||
375 | 374 | ||
376 | if (ntohs (msg->size) < sizeof(struct PeerInformationMessage)) | 375 | if (ntohs (msg->size) < sizeof(struct PeerInformationMessage)) |
377 | { | 376 | { |
378 | GNUNET_break(0); | 377 | GNUNET_break(0); |
379 | return GNUNET_SYSERR; | 378 | return GNUNET_SYSERR; |
380 | } | 379 | } |
381 | |||
382 | pi = (const struct PeerInformationMessage *) msg; | 380 | pi = (const struct PeerInformationMessage *) msg; |
383 | ats_count = ntohl (pi->ats_count); | ||
384 | plugin_address_length = ntohs (pi->address_length); | 381 | plugin_address_length = ntohs (pi->address_length); |
385 | plugin_name_length = ntohs (pi->plugin_name_length); | 382 | plugin_name_length = ntohs (pi->plugin_name_length); |
386 | addr_active = (int) ntohl (pi->address_active); | 383 | addr_active = (int) ntohl (pi->address_active); |
387 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; | 384 | plugin_address = (const char *) &pi[1]; |
388 | plugin_address = (const char *) &atsi[ats_count]; | ||
389 | plugin_name = &plugin_address[plugin_address_length]; | 385 | plugin_name = &plugin_address[plugin_address_length]; |
390 | if ((plugin_address_length + plugin_name_length | 386 | if ((plugin_address_length + plugin_name_length |
391 | + ats_count * sizeof(struct GNUNET_ATS_Information) | ||
392 | + sizeof(struct PeerInformationMessage) != ntohs (msg->size)) | 387 | + sizeof(struct PeerInformationMessage) != ntohs (msg->size)) |
393 | || (ats_count | ||
394 | > GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
395 | / sizeof(struct GNUNET_ATS_Information)) | ||
396 | || (plugin_name[plugin_name_length - 1] != '\0')) | 388 | || (plugin_name[plugin_name_length - 1] != '\0')) |
397 | { | 389 | { |
398 | GNUNET_break(0); | 390 | GNUNET_break(0); |
@@ -401,6 +393,8 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
401 | 393 | ||
402 | if (NULL != ph->addr_info_cb) | 394 | if (NULL != ph->addr_info_cb) |
403 | { | 395 | { |
396 | GNUNET_ATS_properties_ntoh (&prop, | ||
397 | &pi->properties); | ||
404 | address.peer = pi->peer; | 398 | address.peer = pi->peer; |
405 | address.address = plugin_address; | 399 | address.address = plugin_address; |
406 | address.address_length = plugin_address_length; | 400 | address.address_length = plugin_address_length; |
@@ -410,7 +404,7 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
410 | addr_active, | 404 | addr_active, |
411 | pi->bandwidth_out, | 405 | pi->bandwidth_out, |
412 | pi->bandwidth_in, | 406 | pi->bandwidth_in, |
413 | atsi, ats_count); | 407 | &prop); |
414 | } | 408 | } |
415 | return GNUNET_OK; | 409 | return GNUNET_OK; |
416 | } | 410 | } |
@@ -488,15 +482,14 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
488 | const struct PeerInformationMessage *pi; | 482 | const struct PeerInformationMessage *pi; |
489 | struct GNUNET_ATS_AddressListHandle *alh; | 483 | struct GNUNET_ATS_AddressListHandle *alh; |
490 | struct GNUNET_ATS_AddressListHandle *next; | 484 | struct GNUNET_ATS_AddressListHandle *next; |
491 | const struct GNUNET_ATS_Information *atsi; | ||
492 | const char *plugin_address; | 485 | const char *plugin_address; |
493 | const char *plugin_name; | 486 | const char *plugin_name; |
494 | struct GNUNET_HELLO_Address address; | 487 | struct GNUNET_HELLO_Address address; |
495 | struct GNUNET_PeerIdentity allzeros; | 488 | struct GNUNET_PeerIdentity allzeros; |
496 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; | 489 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; |
490 | struct GNUNET_ATS_Properties prop; | ||
497 | uint16_t plugin_address_length; | 491 | uint16_t plugin_address_length; |
498 | uint16_t plugin_name_length; | 492 | uint16_t plugin_name_length; |
499 | uint32_t ats_count; | ||
500 | uint32_t active; | 493 | uint32_t active; |
501 | uint32_t id; | 494 | uint32_t id; |
502 | 495 | ||
@@ -507,18 +500,13 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
507 | } | 500 | } |
508 | pi = (const struct PeerInformationMessage *) msg; | 501 | pi = (const struct PeerInformationMessage *) msg; |
509 | id = ntohl (pi->id); | 502 | id = ntohl (pi->id); |
510 | ats_count = ntohl (pi->ats_count); | ||
511 | active = ntohl (pi->address_active); | 503 | active = ntohl (pi->address_active); |
512 | plugin_address_length = ntohs (pi->address_length); | 504 | plugin_address_length = ntohs (pi->address_length); |
513 | plugin_name_length = ntohs (pi->plugin_name_length); | 505 | plugin_name_length = ntohs (pi->plugin_name_length); |
514 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; | 506 | plugin_address = (const char *) &pi[1]; |
515 | plugin_address = (const char *) &atsi[ats_count]; | ||
516 | plugin_name = &plugin_address[plugin_address_length]; | 507 | plugin_name = &plugin_address[plugin_address_length]; |
517 | if ( (plugin_address_length + plugin_name_length | 508 | if ( (plugin_address_length + plugin_name_length |
518 | + ats_count * sizeof(struct GNUNET_ATS_Information) | ||
519 | + sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || | 509 | + sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || |
520 | (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
521 | / sizeof(struct GNUNET_ATS_Information)) || | ||
522 | (plugin_name[plugin_name_length - 1] != '\0') ) | 510 | (plugin_name[plugin_name_length - 1] != '\0') ) |
523 | { | 511 | { |
524 | GNUNET_break(0); | 512 | GNUNET_break(0); |
@@ -545,8 +533,7 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
545 | memset (&allzeros, '\0', sizeof (allzeros)); | 533 | memset (&allzeros, '\0', sizeof (allzeros)); |
546 | if ( (0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) && | 534 | if ( (0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) && |
547 | (0 == plugin_name_length) && | 535 | (0 == plugin_name_length) && |
548 | (0 == plugin_address_length) && | 536 | (0 == plugin_address_length) ) |
549 | (0 == ats_count) ) | ||
550 | { | 537 | { |
551 | /* Done */ | 538 | /* Done */ |
552 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 539 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -561,7 +548,7 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
561 | GNUNET_NO, | 548 | GNUNET_NO, |
562 | bandwidth_zero, | 549 | bandwidth_zero, |
563 | bandwidth_zero, | 550 | bandwidth_zero, |
564 | NULL, 0); | 551 | NULL); |
565 | GNUNET_free (alh); | 552 | GNUNET_free (alh); |
566 | return GNUNET_OK; | 553 | return GNUNET_OK; |
567 | } | 554 | } |
@@ -573,12 +560,16 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
573 | if ( ( (GNUNET_YES == alh->all_addresses) || | 560 | if ( ( (GNUNET_YES == alh->all_addresses) || |
574 | (GNUNET_YES == active) ) && | 561 | (GNUNET_YES == active) ) && |
575 | (NULL != alh->cb) ) | 562 | (NULL != alh->cb) ) |
563 | { | ||
564 | GNUNET_ATS_properties_ntoh (&prop, | ||
565 | &pi->properties); | ||
576 | alh->cb (ph->addr_info_cb_cls, | 566 | alh->cb (ph->addr_info_cb_cls, |
577 | &address, | 567 | &address, |
578 | active, | 568 | active, |
579 | pi->bandwidth_out, | 569 | pi->bandwidth_out, |
580 | pi->bandwidth_in, | 570 | pi->bandwidth_in, |
581 | atsi, ats_count); | 571 | &prop); |
572 | } | ||
582 | return GNUNET_OK; | 573 | return GNUNET_OK; |
583 | } | 574 | } |
584 | 575 | ||
@@ -641,7 +632,7 @@ process_ats_message (void *cls, | |||
641 | GNUNET_NO, | 632 | GNUNET_NO, |
642 | GNUNET_BANDWIDTH_value_init (0), | 633 | GNUNET_BANDWIDTH_value_init (0), |
643 | GNUNET_BANDWIDTH_value_init (0), | 634 | GNUNET_BANDWIDTH_value_init (0), |
644 | NULL, 0); | 635 | NULL); |
645 | } | 636 | } |
646 | ph->backoff = GNUNET_TIME_STD_BACKOFF (ph->backoff); | 637 | ph->backoff = GNUNET_TIME_STD_BACKOFF (ph->backoff); |
647 | ph->task = GNUNET_SCHEDULER_add_delayed (ph->backoff, | 638 | ph->task = GNUNET_SCHEDULER_add_delayed (ph->backoff, |
@@ -917,8 +908,9 @@ GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandl | |||
917 | const char * | 908 | const char * |
918 | GNUNET_ATS_print_preference_type (uint32_t type) | 909 | GNUNET_ATS_print_preference_type (uint32_t type) |
919 | { | 910 | { |
920 | char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; | 911 | const char *prefs[] = GNUNET_ATS_PreferenceTypeString; |
921 | if (type < GNUNET_ATS_PreferenceCount) | 912 | |
913 | if (type < GNUNET_ATS_PREFERENCE_END) | ||
922 | return prefs[type]; | 914 | return prefs[type]; |
923 | return NULL; | 915 | return NULL; |
924 | } | 916 | } |
@@ -930,7 +922,7 @@ GNUNET_ATS_print_preference_type (uint32_t type) | |||
930 | * | 922 | * |
931 | * @param ph performance handle | 923 | * @param ph performance handle |
932 | * @param peer identifies the peer | 924 | * @param peer identifies the peer |
933 | * @param ... 0-terminated specification of the desired changes | 925 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes |
934 | */ | 926 | */ |
935 | void | 927 | void |
936 | GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, | 928 | GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, |
@@ -946,20 +938,18 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
946 | 938 | ||
947 | count = 0; | 939 | count = 0; |
948 | va_start(ap, peer); | 940 | va_start(ap, peer); |
949 | while (GNUNET_ATS_PREFERENCE_END != (kind = | 941 | while (GNUNET_ATS_PREFERENCE_END != |
950 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) | 942 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
951 | { | 943 | { |
952 | switch (kind) | 944 | switch (kind) |
953 | { | 945 | { |
954 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 946 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
955 | count++; | 947 | count++; |
956 | (void) va_arg (ap, double); | 948 | (void) va_arg (ap, double); |
957 | |||
958 | break; | 949 | break; |
959 | case GNUNET_ATS_PREFERENCE_LATENCY: | 950 | case GNUNET_ATS_PREFERENCE_LATENCY: |
960 | count++; | 951 | count++; |
961 | (void) va_arg (ap, double); | 952 | (void) va_arg (ap, double); |
962 | |||
963 | break; | 953 | break; |
964 | default: | 954 | default: |
965 | GNUNET_assert(0); | 955 | GNUNET_assert(0); |
@@ -1012,7 +1002,7 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
1012 | * @param ph performance handle | 1002 | * @param ph performance handle |
1013 | * @param scope the time interval this valid for: [now - scope .. now] | 1003 | * @param scope the time interval this valid for: [now - scope .. now] |
1014 | * @param peer identifies the peer | 1004 | * @param peer identifies the peer |
1015 | * @param ... 0-terminated specification of the desired changes | 1005 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes |
1016 | */ | 1006 | */ |
1017 | void | 1007 | void |
1018 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | 1008 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, |
@@ -1029,8 +1019,8 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
1029 | 1019 | ||
1030 | count = 0; | 1020 | count = 0; |
1031 | va_start(ap, scope); | 1021 | va_start(ap, scope); |
1032 | while (GNUNET_ATS_PREFERENCE_END != (kind = | 1022 | while (GNUNET_ATS_PREFERENCE_END != |
1033 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) | 1023 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
1034 | { | 1024 | { |
1035 | switch (kind) | 1025 | switch (kind) |
1036 | { | 1026 | { |
diff --git a/src/ats/ats_api_scanner.c b/src/ats/ats_api_scanner.c index 64c02acf6..f9c30770e 100644 --- a/src/ats/ats_api_scanner.c +++ b/src/ats/ats_api_scanner.c | |||
@@ -62,32 +62,38 @@ GNUNET_ATS_print_network_type (enum GNUNET_ATS_Network_Type net) | |||
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Convert a ATS property to a string | 65 | * Convert ATS properties from host to network byte order. |
66 | * | 66 | * |
67 | * @param type the property type | 67 | * @param nbo[OUT] value written |
68 | * @return a string or NULL if invalid | 68 | * @param hbo value read |
69 | */ | 69 | */ |
70 | const char * | 70 | void |
71 | GNUNET_ATS_print_property_type (enum GNUNET_ATS_Property type) | 71 | GNUNET_ATS_properties_hton (struct GNUNET_ATS_PropertiesNBO *nbo, |
72 | const struct GNUNET_ATS_Properties *hbo) | ||
72 | { | 73 | { |
73 | switch (type) | 74 | nbo->utilization_out = htonl (hbo->utilization_out); |
74 | { | 75 | nbo->utilization_in = htonl (hbo->utilization_in); |
75 | case GNUNET_ATS_ARRAY_TERMINATOR: | 76 | nbo->scope = htonl ((uint32_t) hbo->scope); |
76 | return "TERMINATOR"; | 77 | nbo->distance = htonl (hbo->distance); |
77 | case GNUNET_ATS_UTILIZATION_OUT: | 78 | nbo->delay = GNUNET_TIME_relative_hton (hbo->delay); |
78 | return "UTILIZATION_UP"; | 79 | } |
79 | case GNUNET_ATS_UTILIZATION_IN: | 80 | |
80 | return "UTILIZATION_DOWN"; | 81 | |
81 | case GNUNET_ATS_NETWORK_TYPE: | 82 | /** |
82 | return "NETWORK_TYPE"; | 83 | * Convert ATS properties from network to host byte order. |
83 | case GNUNET_ATS_QUALITY_NET_DELAY: | 84 | * |
84 | return "DELAY"; | 85 | * @param hbo[OUT] value written |
85 | case GNUNET_ATS_QUALITY_NET_DISTANCE: | 86 | * @param nbo value read |
86 | return "DISTANCE"; | 87 | */ |
87 | default: | 88 | void |
88 | GNUNET_break (0); | 89 | GNUNET_ATS_properties_ntoh (struct GNUNET_ATS_Properties *hbo, |
89 | return NULL; | 90 | const struct GNUNET_ATS_PropertiesNBO *nbo) |
90 | } | 91 | { |
92 | hbo->utilization_out = ntohl (nbo->utilization_out); | ||
93 | hbo->utilization_in = ntohl (nbo->utilization_in); | ||
94 | hbo->scope = ntohl ((uint32_t) nbo->scope); | ||
95 | hbo->distance = ntohl (nbo->distance); | ||
96 | hbo->delay = GNUNET_TIME_relative_ntoh (nbo->delay); | ||
91 | } | 97 | } |
92 | 98 | ||
93 | 99 | ||
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index ed82dd2ad..f02e4a9e7 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c | |||
@@ -73,14 +73,9 @@ struct GNUNET_ATS_AddressRecord | |||
73 | struct Session *session; | 73 | struct Session *session; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Array with performance data about the address. | 76 | * Performance data about the address. |
77 | */ | 77 | */ |
78 | struct GNUNET_ATS_Information *ats; | 78 | struct GNUNET_ATS_PropertiesNBO properties; |
79 | |||
80 | /** | ||
81 | * Number of entries in @e ats. | ||
82 | */ | ||
83 | uint32_t ats_count; | ||
84 | 79 | ||
85 | /** | 80 | /** |
86 | * Which slot (index) in the session array does | 81 | * Which slot (index) in the session array does |
@@ -487,7 +482,6 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, | |||
487 | { | 482 | { |
488 | struct GNUNET_MQ_Envelope *ev; | 483 | struct GNUNET_MQ_Envelope *ev; |
489 | struct AddressAddMessage *m; | 484 | struct AddressAddMessage *m; |
490 | struct GNUNET_ATS_Information *am; | ||
491 | char *pm; | 485 | char *pm; |
492 | size_t namelen; | 486 | size_t namelen; |
493 | size_t msize; | 487 | size_t msize; |
@@ -497,16 +491,14 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, | |||
497 | namelen = (NULL == ar->address->transport_name) | 491 | namelen = (NULL == ar->address->transport_name) |
498 | ? 0 | 492 | ? 0 |
499 | : strlen (ar->address->transport_name) + 1; | 493 | : strlen (ar->address->transport_name) + 1; |
500 | msize = ar->address->address_length + | 494 | msize = ar->address->address_length + namelen; |
501 | ar->ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; | ||
502 | |||
503 | ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD); | 495 | ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD); |
504 | m->ats_count = htonl (ar->ats_count); | ||
505 | m->peer = ar->address->peer; | 496 | m->peer = ar->address->peer; |
506 | m->address_length = htons (ar->address->address_length); | 497 | m->address_length = htons (ar->address->address_length); |
507 | m->address_local_info = htonl ((uint32_t) ar->address->local_info); | 498 | m->address_local_info = htonl ((uint32_t) ar->address->local_info); |
508 | m->plugin_name_length = htons (namelen); | 499 | m->plugin_name_length = htons (namelen); |
509 | m->session_id = htonl (ar->slot); | 500 | m->session_id = htonl (ar->slot); |
501 | m->properties = ar->properties; | ||
510 | 502 | ||
511 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 503 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
512 | "Adding address for peer `%s', plugin `%s', session %p slot %u\n", | 504 | "Adding address for peer `%s', plugin `%s', session %p slot %u\n", |
@@ -514,11 +506,7 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, | |||
514 | ar->address->transport_name, | 506 | ar->address->transport_name, |
515 | ar->session, | 507 | ar->session, |
516 | ar->slot); | 508 | ar->slot); |
517 | am = (struct GNUNET_ATS_Information *) &m[1]; | 509 | pm = (char *) &m[1]; |
518 | memcpy (am, | ||
519 | ar->ats, | ||
520 | ar->ats_count * sizeof (struct GNUNET_ATS_Information)); | ||
521 | pm = (char *) &am[ar->ats_count]; | ||
522 | memcpy (pm, | 510 | memcpy (pm, |
523 | ar->address->address, | 511 | ar->address->address, |
524 | ar->address->address_length); | 512 | ar->address->address_length); |
@@ -675,8 +663,7 @@ GNUNET_ATS_session_known (struct GNUNET_ATS_SchedulingHandle *sh, | |||
675 | * @param sh handle | 663 | * @param sh handle |
676 | * @param address the address | 664 | * @param address the address |
677 | * @param session session handle, can be NULL | 665 | * @param session session handle, can be NULL |
678 | * @param ats performance data for the address | 666 | * @param prop performance data for the address |
679 | * @param ats_count number of performance records in @a ats | ||
680 | * @return handle to the address representation inside ATS, NULL | 667 | * @return handle to the address representation inside ATS, NULL |
681 | * on error (i.e. ATS knows this exact address already) | 668 | * on error (i.e. ATS knows this exact address already) |
682 | */ | 669 | */ |
@@ -684,8 +671,7 @@ struct GNUNET_ATS_AddressRecord * | |||
684 | GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | 671 | GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, |
685 | const struct GNUNET_HELLO_Address *address, | 672 | const struct GNUNET_HELLO_Address *address, |
686 | struct Session *session, | 673 | struct Session *session, |
687 | const struct GNUNET_ATS_Information *ats, | 674 | const struct GNUNET_ATS_Properties *prop) |
688 | uint32_t ats_count) | ||
689 | { | 675 | { |
690 | struct GNUNET_ATS_AddressRecord *ar; | 676 | struct GNUNET_ATS_AddressRecord *ar; |
691 | size_t namelen; | 677 | size_t namelen; |
@@ -701,13 +687,10 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
701 | namelen = (NULL == address->transport_name) | 687 | namelen = (NULL == address->transport_name) |
702 | ? 0 | 688 | ? 0 |
703 | : strlen (address->transport_name) + 1; | 689 | : strlen (address->transport_name) + 1; |
704 | msize = address->address_length + | 690 | msize = address->address_length + namelen; |
705 | ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; | ||
706 | if ((msize + sizeof (struct AddressUpdateMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || | 691 | if ((msize + sizeof (struct AddressUpdateMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || |
707 | (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || | 692 | (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || |
708 | (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || | 693 | (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ) |
709 | (ats_count >= | ||
710 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))) | ||
711 | { | 694 | { |
712 | /* address too large for us, this should not happen */ | 695 | /* address too large for us, this should not happen */ |
713 | GNUNET_break (0); | 696 | GNUNET_break (0); |
@@ -729,12 +712,8 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
729 | ar->slot = s; | 712 | ar->slot = s; |
730 | ar->session = session; | 713 | ar->session = session; |
731 | ar->address = GNUNET_HELLO_address_copy (address); | 714 | ar->address = GNUNET_HELLO_address_copy (address); |
732 | GNUNET_array_grow (ar->ats, | 715 | GNUNET_ATS_properties_hton (&ar->properties, |
733 | ar->ats_count, | 716 | prop); |
734 | ats_count); | ||
735 | memcpy (ar->ats, | ||
736 | ats, | ||
737 | ats_count * sizeof (struct GNUNET_ATS_Information)); | ||
738 | sh->session_array[s] = ar; | 717 | sh->session_array[s] = ar; |
739 | send_add_address_message (sh, ar); | 718 | send_add_address_message (sh, ar); |
740 | return ar; | 719 | return ar; |
@@ -793,19 +772,15 @@ GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar, | |||
793 | * for later use). Update bandwidth assignments. | 772 | * for later use). Update bandwidth assignments. |
794 | * | 773 | * |
795 | * @param ar address record to update information for | 774 | * @param ar address record to update information for |
796 | * @param ats performance data for the address | 775 | * @param prop performance data for the address |
797 | * @param ats_count number of performance records in @a ats | ||
798 | */ | 776 | */ |
799 | void | 777 | void |
800 | GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, | 778 | GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, |
801 | const struct GNUNET_ATS_Information *ats, | 779 | const struct GNUNET_ATS_Properties *prop) |
802 | uint32_t ats_count) | ||
803 | { | 780 | { |
804 | struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; | 781 | struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; |
805 | struct GNUNET_MQ_Envelope *ev; | 782 | struct GNUNET_MQ_Envelope *ev; |
806 | struct AddressUpdateMessage *m; | 783 | struct AddressUpdateMessage *m; |
807 | struct GNUNET_ATS_Information *am; | ||
808 | size_t msize; | ||
809 | 784 | ||
810 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 785 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
811 | "Updating address for peer `%s', plugin `%s', session %p slot %u\n", | 786 | "Updating address for peer `%s', plugin `%s', session %p slot %u\n", |
@@ -813,25 +788,16 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, | |||
813 | ar->address->transport_name, | 788 | ar->address->transport_name, |
814 | ar->session, | 789 | ar->session, |
815 | ar->slot); | 790 | ar->slot); |
816 | GNUNET_array_grow (ar->ats, | 791 | GNUNET_ATS_properties_hton (&ar->properties, |
817 | ar->ats_count, | 792 | prop); |
818 | ats_count); | ||
819 | memcpy (ar->ats, | ||
820 | ats, | ||
821 | ats_count * sizeof (struct GNUNET_ATS_Information)); | ||
822 | |||
823 | if (NULL == sh->mq) | 793 | if (NULL == sh->mq) |
824 | return; /* disconnected, skip for now */ | 794 | return; /* disconnected, skip for now */ |
825 | msize = ar->ats_count * sizeof (struct GNUNET_ATS_Information); | 795 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); |
826 | ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); | ||
827 | m->ats_count = htonl (ar->ats_count); | ||
828 | m->peer = ar->address->peer; | ||
829 | m->session_id = htonl (ar->slot); | 796 | m->session_id = htonl (ar->slot); |
830 | am = (struct GNUNET_ATS_Information *) &m[1]; | 797 | m->peer = ar->address->peer; |
831 | memcpy (am, | 798 | m->properties = ar->properties; |
832 | ar->ats, | 799 | GNUNET_MQ_send (sh->mq, |
833 | ar->ats_count * sizeof (struct GNUNET_ATS_Information)); | 800 | ev); |
834 | GNUNET_MQ_send (sh->mq, ev); | ||
835 | } | 801 | } |
836 | 802 | ||
837 | 803 | ||
@@ -857,9 +823,6 @@ GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar) | |||
857 | GNUNET_break (NULL == ar->session); | 823 | GNUNET_break (NULL == ar->session); |
858 | ar->session = NULL; | 824 | ar->session = NULL; |
859 | ar->in_destroy = GNUNET_YES; | 825 | ar->in_destroy = GNUNET_YES; |
860 | GNUNET_array_grow (ar->ats, | ||
861 | ar->ats_count, | ||
862 | 0); | ||
863 | if (NULL == sh->mq) | 826 | if (NULL == sh->mq) |
864 | return; | 827 | return; |
865 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); | 828 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); |
diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c index 8cf4b115b..5645e81c5 100644 --- a/src/ats/gnunet-ats-solver-eval.c +++ b/src/ats/gnunet-ats-solver-eval.c | |||
@@ -166,7 +166,8 @@ GNUNET_ATS_solver_logging_now (struct LoggingHandle *l) | |||
166 | /* Store logging data here */ | 166 | /* Store logging data here */ |
167 | for (cur = peer_head; NULL != cur; cur = cur->next) | 167 | for (cur = peer_head; NULL != cur; cur = cur->next) |
168 | { | 168 | { |
169 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu\n", cur->id); | 169 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
170 | "Logging peer id %llu\n", cur->id); | ||
170 | 171 | ||
171 | log_p = GNUNET_new (struct LoggingPeer); | 172 | log_p = GNUNET_new (struct LoggingPeer); |
172 | log_p->id = cur->id; | 173 | log_p->id = cur->id; |
@@ -176,16 +177,18 @@ GNUNET_ATS_solver_logging_now (struct LoggingHandle *l) | |||
176 | { | 177 | { |
177 | log_p->pref_abs[c] = cur->pref_abs[c]; | 178 | log_p->pref_abs[c] = cur->pref_abs[c]; |
178 | log_p->pref_norm[c] = cur->pref_norm[c]; | 179 | log_p->pref_norm[c] = cur->pref_norm[c]; |
179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n", | 180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
180 | GNUNET_ATS_print_preference_type(c), | 181 | "\t %s = %.2f %.2f [abs/rel]\n", |
181 | log_p->pref_abs[c], log_p->pref_norm[c]); | 182 | GNUNET_ATS_print_preference_type(c), |
183 | log_p->pref_abs[c], log_p->pref_norm[c]); | ||
182 | } | 184 | } |
183 | GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p); | 185 | GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p); |
184 | 186 | ||
185 | for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next) | 187 | for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next) |
186 | { | 188 | { |
187 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu address %llu \n", | 189 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
188 | cur->id, cur_addr->aid); | 190 | "Logging peer id %llu address %llu\n", |
191 | cur->id, cur_addr->aid); | ||
189 | log_a = GNUNET_new (struct LoggingAddress); | 192 | log_a = GNUNET_new (struct LoggingAddress); |
190 | log_a->aid = cur_addr->aid; | 193 | log_a->aid = cur_addr->aid; |
191 | log_a->active = cur_addr->ats_addr->active; | 194 | log_a->active = cur_addr->ats_addr->active; |
@@ -196,9 +199,11 @@ GNUNET_ATS_solver_logging_now (struct LoggingHandle *l) | |||
196 | { | 199 | { |
197 | log_a->prop_abs[c] = cur_addr->prop_abs[c]; | 200 | log_a->prop_abs[c] = cur_addr->prop_abs[c]; |
198 | log_a->prop_norm[c] = cur_addr->prop_norm[c]; | 201 | log_a->prop_norm[c] = cur_addr->prop_norm[c]; |
199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n", | 202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
200 | GNUNET_ATS_print_property_type(c), | 203 | "\t %s = %.2f %.2f [abs/rel]\n", |
201 | log_a->prop_abs[c], log_a->prop_norm[c]); | 204 | GNUNET_ATS_print_property_type(c), |
205 | log_a->prop_abs[c], | ||
206 | log_a->prop_norm[c]); | ||
202 | } | 207 | } |
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active); | 208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active); |
204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", log_a->assigned_bw_in); | 209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", log_a->assigned_bw_in); |
@@ -209,16 +214,17 @@ GNUNET_ATS_solver_logging_now (struct LoggingHandle *l) | |||
209 | } | 214 | } |
210 | } | 215 | } |
211 | 216 | ||
217 | |||
212 | static void | 218 | static void |
213 | logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 219 | logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
214 | { | 220 | { |
215 | struct LoggingHandle *l = cls; | 221 | struct LoggingHandle *l = cls; |
216 | l->logging_task = NULL; | ||
217 | 222 | ||
223 | l->logging_task = NULL; | ||
218 | GNUNET_ATS_solver_logging_now (l); | 224 | GNUNET_ATS_solver_logging_now (l); |
219 | 225 | l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, | |
220 | l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l); | 226 | &logging_task, |
221 | 227 | l); | |
222 | } | 228 | } |
223 | 229 | ||
224 | struct LoggingHandle * | 230 | struct LoggingHandle * |
@@ -395,7 +401,9 @@ GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l, int add_time_s | |||
395 | GNUNET_ATS_print_property_type(c), | 401 | GNUNET_ATS_print_property_type(c), |
396 | log_a->prop_abs[c], log_a->prop_norm[c]);*/ | 402 | log_a->prop_abs[c], log_a->prop_norm[c]);*/ |
397 | GNUNET_asprintf(&propstring_tmp,"%s%.3f;%.3f;", | 403 | GNUNET_asprintf(&propstring_tmp,"%s%.3f;%.3f;", |
398 | propstring, log_a->prop_abs[c], log_a->prop_norm[c]); | 404 | propstring, |
405 | log_a->prop_abs[c], | ||
406 | log_a->prop_norm[c]); | ||
399 | GNUNET_free (propstring); | 407 | GNUNET_free (propstring); |
400 | propstring = GNUNET_strdup(propstring_tmp); | 408 | propstring = GNUNET_strdup(propstring_tmp); |
401 | GNUNET_free (propstring_tmp); | 409 | GNUNET_free (propstring_tmp); |
@@ -519,10 +527,10 @@ GNUNET_ATS_solver_logging_free (struct LoggingHandle *l) | |||
519 | /** | 527 | /** |
520 | * Property Generators | 528 | * Property Generators |
521 | */ | 529 | */ |
522 | |||
523 | static struct PropertyGenerator *prop_gen_head; | 530 | static struct PropertyGenerator *prop_gen_head; |
524 | static struct PropertyGenerator *prop_gen_tail; | 531 | static struct PropertyGenerator *prop_gen_tail; |
525 | 532 | ||
533 | |||
526 | static double | 534 | static double |
527 | get_property (struct PropertyGenerator *pg) | 535 | get_property (struct PropertyGenerator *pg) |
528 | { | 536 | { |
@@ -3001,7 +3009,7 @@ get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | |||
3001 | } | 3009 | } |
3002 | else | 3010 | else |
3003 | return GAS_preference_get_by_peer (NULL, | 3011 | return GAS_preference_get_by_peer (NULL, |
3004 | id); | 3012 | id); |
3005 | } | 3013 | } |
3006 | 3014 | ||
3007 | 3015 | ||
diff --git a/src/ats/gnunet-ats-solver-eval.h b/src/ats/gnunet-ats-solver-eval.h index bc5083e34..44ccfe081 100644 --- a/src/ats/gnunet-ats-solver-eval.h +++ b/src/ats/gnunet-ats-solver-eval.h | |||
@@ -120,8 +120,8 @@ struct LoggingPeer | |||
120 | 120 | ||
121 | long long unsigned int id; | 121 | long long unsigned int id; |
122 | struct GNUNET_PeerIdentity peer_id; | 122 | struct GNUNET_PeerIdentity peer_id; |
123 | double pref_abs[GNUNET_ATS_PreferenceCount]; | 123 | double pref_abs[GNUNET_ATS_PREFERENCE_END]; |
124 | double pref_norm[GNUNET_ATS_PreferenceCount]; | 124 | double pref_norm[GNUNET_ATS_PREFERENCE_END]; |
125 | int is_requested; | 125 | int is_requested; |
126 | 126 | ||
127 | struct LoggingAddress *addr_head; | 127 | struct LoggingAddress *addr_head; |
@@ -215,7 +215,7 @@ struct GNUNET_ATS_TEST_Operation | |||
215 | enum OperationType type; | 215 | enum OperationType type; |
216 | enum GeneratorType gen_type; | 216 | enum GeneratorType gen_type; |
217 | enum GNUNET_ATS_PreferenceKind pref_type; | 217 | enum GNUNET_ATS_PreferenceKind pref_type; |
218 | enum GNUNET_ATS_Property prop_type; | 218 | // enum GNUNET_ATS_Property prop_type; |
219 | }; | 219 | }; |
220 | 220 | ||
221 | struct Episode | 221 | struct Episode |
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 716bd6332..8570b57b6 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c | |||
@@ -177,7 +177,8 @@ run (void *cls, | |||
177 | {&GAS_handle_address_add, NULL, | 177 | {&GAS_handle_address_add, NULL, |
178 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD, 0}, | 178 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD, 0}, |
179 | {&GAS_handle_address_update, NULL, | 179 | {&GAS_handle_address_update, NULL, |
180 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0}, | 180 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, |
181 | sizeof (struct AddressUpdateMessage) }, | ||
181 | {&GAS_handle_address_destroyed, NULL, | 182 | {&GAS_handle_address_destroyed, NULL, |
182 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, | 183 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, |
183 | sizeof (struct AddressDestroyedMessage) }, | 184 | sizeof (struct AddressDestroyedMessage) }, |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index c4d7f2da9..17f030a6c 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -32,186 +32,6 @@ | |||
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * NOTE: Do not change this documentation. This documentation is based on | ||
36 | * gnunet.org:/vcs/fsnsg/2014-p2p-ats.git/tech-doku/ats-tech-guide.tex | ||
37 | * use build_txt.sh to generate plaintext output | ||
38 | * | ||
39 | * 1 ATS addresses : ATS address management | ||
40 | * | ||
41 | * This ATS addresses ("addresses") component manages the addresses known to | ||
42 | * ATS service and suggests addresses to transport service when it is | ||
43 | * interested in address suggestion for a peer. ATS addresses also | ||
44 | * instantiates the bandwidth assignment mechanism (solver), notifies it | ||
45 | * about changes to addresses and forwards changes to bandwidth assignments | ||
46 | * to transport, depending if transport is interested in this change. | ||
47 | * | ||
48 | * 1.1 Input data | ||
49 | * | ||
50 | * 1.1.1 Addresses | ||
51 | * | ||
52 | * Addresses are added by specifying peer ID, plugin, address, address length | ||
53 | * and session, if available. ATS information can be specified if available. | ||
54 | * | ||
55 | * 1.1.2 Networks | ||
56 | * | ||
57 | * ATS specifies a fix set of networks an address can belong to. For each | ||
58 | * network an inbound and outbound quota will be specified. The available | ||
59 | * networks and addtional helper varaibles are defined in | ||
60 | * gnunet_ats_service.h. At the moment 5 networks are defined: | ||
61 | * * GNUNET_ATS_NET_UNSPECIFIED | ||
62 | * * GNUNET_ATS_NET_LOOPBACK | ||
63 | * * GNUNET_ATS_NET_LAN | ||
64 | * * GNUNET_ATS_NET_WAN | ||
65 | * * GNUNET_ATS_NET_WLAN | ||
66 | * | ||
67 | * The total number of networks defined is stored in | ||
68 | * GNUNET_ATS_NetworkTypeCount GNUNET_ATS_NetworkType can be used array | ||
69 | * initializer for an int array, while GNUNET_ATS_NetworkType is an | ||
70 | * initializer for a char array containing a string description of all | ||
71 | * networks | ||
72 | * | ||
73 | * 1.1.3 Quotas | ||
74 | * | ||
75 | * An inbound and outbound quota for each of the networks mentioned in 1.1.2 | ||
76 | * is loaded from ats configuration during initialization. This quota defines | ||
77 | * to total amount of inbound and outbound traffic allowed for a specific | ||
78 | * network. The configuration values used are in section ats: | ||
79 | * * "NETWORK"_QUOTA_IN = <value> | ||
80 | * * "NETWORK"_QUOTA_IN = <value> | ||
81 | * | ||
82 | * You can specify quotas by setting the <value> to a: | ||
83 | * * unrestricted: unlimited | ||
84 | * * number of bytes: e.g. 10240 | ||
85 | * * fancy value: e.g. 64 Kib | ||
86 | * | ||
87 | * unlimited is defined as GNUNET_ATS_MaxBandwidthString and equivalent to | ||
88 | * the value GNUNET_ATS_MaxBandwidth Important predefined values for quotas | ||
89 | * are: | ||
90 | * * GNUNET_ATS_DefaultBandwidth: 65536 | ||
91 | * * GNUNET_ATS_MaxBandwidth: UINT32_MAX | ||
92 | * * GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT: 1024 | ||
93 | * | ||
94 | * Details of loading quotas and default values will be described on | ||
95 | * | ||
96 | * 1.1.4 Preference values | ||
97 | * | ||
98 | * 1.2 Data structures used | ||
99 | * | ||
100 | * Addresse uses struct ATS_Address for each address. The structs are stored | ||
101 | * in a linked list and provides a pointer void *solver_information for the | ||
102 | * solver to store address specific information. It provides the int values | ||
103 | * active which is set to GNUNET_YES if the address is select for transport | ||
104 | * use and used, representing that transport service is actively using this | ||
105 | * address. Address information are stored in peer, addr, addr_len, plugin. | ||
106 | * | ||
107 | * 1.3 Initialization | ||
108 | * | ||
109 | * During initialization a hashmap to store addresses is created. The quotas | ||
110 | * for all networks defined for ATS are loaded from configuration. For each | ||
111 | * network first the logic will check if the string | ||
112 | * GNUNET_ATS_MaxBandwidthString is configured, if not it will try to convert | ||
113 | * the configured value as a fancy size and if this fails it will try to use | ||
114 | * it as a value_number. If no configuration value is found it will assign | ||
115 | * GNUNET_ATS_DefaultBandwidth. The most important step is to load the | ||
116 | * configured solver using configuration "[ats]:MODE". Current solvers are | ||
117 | * MODE_PROPORTIONAL, MODE_MLP. Interaction is done using a solver API | ||
118 | * | ||
119 | * 1.4 Solver API | ||
120 | * | ||
121 | * Solver functions: | ||
122 | * * s_init: init the solver with required information | ||
123 | * * s_add: add a new address | ||
124 | * * s_update: update ATS values or session for an address | ||
125 | * * s_get: get prefered address for a peer | ||
126 | * * s_del: delete an address | ||
127 | * * s_pref: change preference value for a peer | ||
128 | * * s_done: shutdown solver | ||
129 | * | ||
130 | * Callbacks: addresses provides a bandwidth_changed_cb callback to the | ||
131 | * solver which is called when bandwidth assigned to peer has changed | ||
132 | * | ||
133 | * 1.5 Shutdown | ||
134 | * | ||
135 | * During shutdown all addresses are freed and the solver told to shutdown | ||
136 | * | ||
137 | * 1.6 Addresses and sessions | ||
138 | * | ||
139 | * Addresses consist of the address itself and a numerical session. When a | ||
140 | * new address without a session is added it has no session, so it gets | ||
141 | * session 0 assigned. When an address with a session is added and an address | ||
142 | * object with session 0 is found, this object is updated with the session | ||
143 | * otherwise a new address object with this session assigned is created. | ||
144 | * | ||
145 | * 1.6.1 Terminology | ||
146 | * | ||
147 | * Addresses a1,a2 with session s1, s2 are "exact" if: | ||
148 | * (a1 == a2)&&(s1 == s2) | ||
149 | * Addresses a1,a2 with session s1, s2 are "equivalent" if: | ||
150 | * (a1 == a2)&&((s1 == s2)||(s1 == 0)||(s2 == 0) | ||
151 | * | ||
152 | * 1.7 Address management | ||
153 | * | ||
154 | * Transport service notifies ATS about changes to the addresses known to | ||
155 | * him. | ||
156 | * | ||
157 | * 1.7.1 Adding an address | ||
158 | * | ||
159 | * When transport learns a new address it tells ATS and ATS is telling | ||
160 | * addresses about it using GAS_address_add. If not known to addresses it | ||
161 | * creates a new address object and calls solver's s_add. ATS information are | ||
162 | * deserialized and solver is notified about the session and ATS information | ||
163 | * using s_update. | ||
164 | * | ||
165 | * 1.7.2 Updating an address | ||
166 | * | ||
167 | * Addresses does an lookup up for the existing address with the given | ||
168 | * session. If disassembles included ATS information and notifies the solver | ||
169 | * using s_update about the update. | ||
170 | * | ||
171 | * 1.7.3 Deleting an address | ||
172 | * | ||
173 | * Addresses does an lookup for the exact address and session and if removes | ||
174 | * this address. If session != 0 the session is set to 0 and the address is | ||
175 | * kept. If session == 0, the addresses is removed. | ||
176 | * | ||
177 | * 1.7.4 Requesting an address suggestion | ||
178 | * | ||
179 | * The address client issues a request address message to be notified about | ||
180 | * address suggestions for a specific peer. Addresses asks the solver with | ||
181 | * s_get. If no address is available, it will not send a response, otherwise | ||
182 | * it will respond with the choosen address. | ||
183 | * | ||
184 | * 1.7.5 Address suggestions | ||
185 | * | ||
186 | * Addresses will notify the client automatically on any bandwidth_changed_cb | ||
187 | * by the solver if a address suggestion request is pending. If no address is | ||
188 | * available it will not respond at all If the client is not interested | ||
189 | * anymore, it has to cancel the address suggestion request. | ||
190 | * | ||
191 | * 1.7.6 Address lifecycle | ||
192 | * | ||
193 | * * (add address) | ||
194 | * * (updated address) | ||
195 | * * (delete address) | ||
196 | * | ||
197 | * 1.8 Bandwidth assignment | ||
198 | * | ||
199 | * The addresses are used to perform resource allocation operations. ATS | ||
200 | * addresses takes care of instantiating the solver configured and notifies | ||
201 | * the respective solver about address changes and receives changes to the | ||
202 | * bandwidth assignment from the solver. The current bandwidth assignment is | ||
203 | * sent to transport. The specific solvers will be described in the specific | ||
204 | * section. | ||
205 | * | ||
206 | * 1.9 Changing peer preferences | ||
207 | * | ||
208 | * The bandwidth assigned to a peer can be influenced by setting a preference | ||
209 | * for a peer. The prefernce will be given to to the solver with s_pref which | ||
210 | * has to take care of the preference value | ||
211 | */ | ||
212 | |||
213 | |||
214 | /** | ||
215 | * A multihashmap to store all addresses | 35 | * A multihashmap to store all addresses |
216 | */ | 36 | */ |
217 | struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses; | 37 | struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses; |
@@ -231,124 +51,6 @@ update_addresses_stat () | |||
231 | 51 | ||
232 | 52 | ||
233 | /** | 53 | /** |
234 | * Disassemble ATS information and update performance information in address | ||
235 | * | ||
236 | * Updates existing information and adds new information | ||
237 | * | ||
238 | * @param dest destination address | ||
239 | * @param update source ATS information | ||
240 | * @param update_count number of ATS information in @a update | ||
241 | * @param delta_dest ats performance information which were updated | ||
242 | * including previous value | ||
243 | * @param delta_count number of ATS information in the @a delta_dest | ||
244 | * @return #GNUNET_YES if address was address updated, GNUNET_NO otherwise | ||
245 | */ | ||
246 | static unsigned int | ||
247 | disassemble_ats_information (struct ATS_Address *dest, | ||
248 | const struct GNUNET_ATS_Information *update, | ||
249 | uint32_t update_count, | ||
250 | struct GNUNET_ATS_Information **delta_dest, | ||
251 | uint32_t *delta_count) | ||
252 | { | ||
253 | int c1; | ||
254 | int c2; | ||
255 | int found; | ||
256 | int change; | ||
257 | struct GNUNET_ATS_Information add_atsi[update_count]; | ||
258 | struct GNUNET_ATS_Information delta_atsi[update_count]; | ||
259 | struct GNUNET_ATS_Information *tmp_atsi; | ||
260 | uint32_t add_atsi_count; | ||
261 | uint32_t delta_atsi_count; | ||
262 | |||
263 | change = GNUNET_NO; | ||
264 | add_atsi_count = 0; | ||
265 | delta_atsi_count = 0; | ||
266 | |||
267 | if (0 == update_count) | ||
268 | return GNUNET_NO; | ||
269 | |||
270 | if (NULL == dest->atsi) | ||
271 | { | ||
272 | /* Create performance information */ | ||
273 | dest->atsi = | ||
274 | GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information)); | ||
275 | dest->atsi_count = update_count; | ||
276 | memcpy (dest->atsi, | ||
277 | update, | ||
278 | update_count * sizeof(struct GNUNET_ATS_Information)); | ||
279 | *delta_dest = | ||
280 | GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information)); | ||
281 | for (c1 = 0; c1 < update_count; c1++) | ||
282 | { | ||
283 | (*delta_dest)[c1].type = update[c1].type; | ||
284 | (*delta_dest)[c1].value = htonl (GNUNET_ATS_VALUE_UNDEFINED); | ||
285 | } | ||
286 | (*delta_count) = update_count; | ||
287 | return GNUNET_YES; | ||
288 | } | ||
289 | |||
290 | for (c1 = 0; c1 < update_count; c1++) | ||
291 | { | ||
292 | /* Update existing performance information */ | ||
293 | found = GNUNET_NO; | ||
294 | for (c2 = 0; c2 < dest->atsi_count; c2++) | ||
295 | { | ||
296 | if (update[c1].type == dest->atsi[c2].type) | ||
297 | { | ||
298 | if (update[c1].value != dest->atsi[c2].value) | ||
299 | { | ||
300 | /* Save previous value in delta */ | ||
301 | delta_atsi[delta_atsi_count] = dest->atsi[c2]; | ||
302 | delta_atsi_count++; | ||
303 | /* Set new value */ | ||
304 | dest->atsi[c2].value = update[c1].value; | ||
305 | change = GNUNET_YES; | ||
306 | } | ||
307 | found = GNUNET_YES; | ||
308 | break; | ||
309 | } | ||
310 | } | ||
311 | if (GNUNET_NO == found) | ||
312 | { | ||
313 | add_atsi[add_atsi_count] = update[c1]; | ||
314 | add_atsi_count++; | ||
315 | delta_atsi[delta_atsi_count].type = update[c1].type; | ||
316 | delta_atsi[delta_atsi_count].value = htonl (GNUNET_ATS_VALUE_UNDEFINED); | ||
317 | delta_atsi_count++; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | if (add_atsi_count > 0) | ||
322 | { | ||
323 | /* Extend ats performance information */ | ||
324 | |||
325 | tmp_atsi = GNUNET_malloc ((dest->atsi_count + add_atsi_count) * | ||
326 | (sizeof (struct GNUNET_ATS_Information))); | ||
327 | memcpy (tmp_atsi, dest->atsi, | ||
328 | dest->atsi_count * sizeof(struct GNUNET_ATS_Information)); | ||
329 | memcpy (&tmp_atsi[dest->atsi_count], add_atsi, | ||
330 | add_atsi_count * sizeof(struct GNUNET_ATS_Information)); | ||
331 | GNUNET_free (dest->atsi); | ||
332 | dest->atsi = tmp_atsi; | ||
333 | dest->atsi_count = dest->atsi_count + add_atsi_count; | ||
334 | change = GNUNET_YES; | ||
335 | } | ||
336 | |||
337 | if (delta_atsi_count > 0) | ||
338 | { | ||
339 | /* Copy delta */ | ||
340 | (*delta_dest) = | ||
341 | GNUNET_malloc (delta_atsi_count * sizeof (struct GNUNET_ATS_Information)); | ||
342 | memcpy ((*delta_dest), delta_atsi, | ||
343 | delta_atsi_count * sizeof(struct GNUNET_ATS_Information)); | ||
344 | (*delta_count) = delta_atsi_count; | ||
345 | } | ||
346 | |||
347 | return change; | ||
348 | } | ||
349 | |||
350 | |||
351 | /** | ||
352 | * Free the given address | 54 | * Free the given address |
353 | * | 55 | * |
354 | * @param addr address to destroy | 56 | * @param addr address to destroy |
@@ -366,16 +68,30 @@ free_address (struct ATS_Address *addr) | |||
366 | addr->addr, | 68 | addr->addr, |
367 | addr->addr_len, | 69 | addr->addr_len, |
368 | GNUNET_NO, | 70 | GNUNET_NO, |
369 | NULL, 0, | 71 | NULL, |
370 | GNUNET_BANDWIDTH_ZERO, | 72 | GNUNET_BANDWIDTH_ZERO, |
371 | GNUNET_BANDWIDTH_ZERO); | 73 | GNUNET_BANDWIDTH_ZERO); |
372 | GNUNET_free (addr->plugin); | 74 | GNUNET_free (addr->plugin); |
373 | GNUNET_free_non_null (addr->atsi); | ||
374 | GNUNET_free (addr); | 75 | GNUNET_free (addr); |
375 | } | 76 | } |
376 | 77 | ||
377 | 78 | ||
378 | /** | 79 | /** |
80 | * Initialize @a norm. Sets all historic values to undefined. | ||
81 | * | ||
82 | * @param norm normalization data to initialize | ||
83 | */ | ||
84 | static void | ||
85 | init_norm (struct GAS_NormalizationInfo *norm) | ||
86 | { | ||
87 | unsigned int c; | ||
88 | |||
89 | for (c = 0; c < GAS_normalization_queue_length; c++) | ||
90 | norm->atsi_abs[c] = UINT64_MAX; | ||
91 | } | ||
92 | |||
93 | |||
94 | /** | ||
379 | * Create a ATS_address with the given information | 95 | * Create a ATS_address with the given information |
380 | * | 96 | * |
381 | * @param peer peer | 97 | * @param peer peer |
@@ -395,8 +111,6 @@ create_address (const struct GNUNET_PeerIdentity *peer, | |||
395 | uint32_t session_id) | 111 | uint32_t session_id) |
396 | { | 112 | { |
397 | struct ATS_Address *aa; | 113 | struct ATS_Address *aa; |
398 | unsigned int c1; | ||
399 | unsigned int c2; | ||
400 | 114 | ||
401 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); | 115 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); |
402 | aa->peer = *peer; | 116 | aa->peer = *peer; |
@@ -408,14 +122,10 @@ create_address (const struct GNUNET_PeerIdentity *peer, | |||
408 | aa->plugin = GNUNET_strdup (plugin_name); | 122 | aa->plugin = GNUNET_strdup (plugin_name); |
409 | aa->session_id = session_id; | 123 | aa->session_id = session_id; |
410 | aa->local_address_info = local_address_info; | 124 | aa->local_address_info = local_address_info; |
411 | 125 | init_norm (&aa->norm_delay); | |
412 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) | 126 | init_norm (&aa->norm_distance); |
413 | { | 127 | init_norm (&aa->norm_utilization_in); |
414 | aa->atsin[c1].avg_queue_index = 0; | 128 | init_norm (&aa->norm_utilization_out); |
415 | aa->atsin[c1].norm = DEFAULT_REL_QUALITY; | ||
416 | for (c2 = 0; c2 < GAS_normalization_queue_length; c2++) | ||
417 | aa->atsin[c1].atsi_abs[c2] = GNUNET_ATS_VALUE_UNDEFINED; | ||
418 | } | ||
419 | return aa; | 129 | return aa; |
420 | } | 130 | } |
421 | 131 | ||
@@ -486,31 +196,6 @@ find_exact_address (const struct GNUNET_PeerIdentity *peer, | |||
486 | 196 | ||
487 | 197 | ||
488 | /** | 198 | /** |
489 | * Extract an ATS performance info from an address | ||
490 | * | ||
491 | * @param address the address | ||
492 | * @param type the type to extract in HBO | ||
493 | * @return the value in HBO or #GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist | ||
494 | */ | ||
495 | static int | ||
496 | get_performance_info (struct ATS_Address *address, | ||
497 | uint32_t type) | ||
498 | { | ||
499 | uint32_t c1; | ||
500 | |||
501 | if ((NULL == address->atsi) || (0 == address->atsi_count)) | ||
502 | return GNUNET_ATS_VALUE_UNDEFINED; | ||
503 | |||
504 | for (c1 = 0; c1 < address->atsi_count; c1++) | ||
505 | { | ||
506 | if (ntohl (address->atsi[c1].type) == type) | ||
507 | return ntohl (address->atsi[c1].value); | ||
508 | } | ||
509 | return GNUNET_ATS_VALUE_UNDEFINED; | ||
510 | } | ||
511 | |||
512 | |||
513 | /** | ||
514 | * Add a new address for a peer. | 199 | * Add a new address for a peer. |
515 | * | 200 | * |
516 | * @param peer peer | 201 | * @param peer peer |
@@ -519,8 +204,7 @@ get_performance_info (struct ATS_Address *address, | |||
519 | * @param plugin_addr_len length of the plugin address in @a plugin_addr | 204 | * @param plugin_addr_len length of the plugin address in @a plugin_addr |
520 | * @param local_address_info the local address for the address | 205 | * @param local_address_info the local address for the address |
521 | * @param session_id session id, can be 0 | 206 | * @param session_id session id, can be 0 |
522 | * @param atsi performance information for this address | 207 | * @param prop performance information for this address |
523 | * @param atsi_count number of performance information contained in @a atsi | ||
524 | */ | 208 | */ |
525 | void | 209 | void |
526 | GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | 210 | GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, |
@@ -529,15 +213,12 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
529 | size_t plugin_addr_len, | 213 | size_t plugin_addr_len, |
530 | uint32_t local_address_info, | 214 | uint32_t local_address_info, |
531 | uint32_t session_id, | 215 | uint32_t session_id, |
532 | const struct GNUNET_ATS_Information *atsi, | 216 | const struct GNUNET_ATS_Properties *prop) |
533 | uint32_t atsi_count) | ||
534 | { | 217 | { |
535 | struct ATS_Address *new_address; | 218 | struct ATS_Address *new_address; |
536 | struct GNUNET_ATS_Information *atsi_delta; | ||
537 | uint32_t atsi_delta_count; | ||
538 | uint32_t addr_net; | ||
539 | 219 | ||
540 | if (NULL != find_exact_address (peer, session_id)) | 220 | if (NULL != find_exact_address (peer, |
221 | session_id)) | ||
541 | { | 222 | { |
542 | GNUNET_break (0); | 223 | GNUNET_break (0); |
543 | return; | 224 | return; |
@@ -548,17 +229,8 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
548 | plugin_addr_len, | 229 | plugin_addr_len, |
549 | local_address_info, | 230 | local_address_info, |
550 | session_id); | 231 | session_id); |
551 | atsi_delta = NULL; | ||
552 | disassemble_ats_information (new_address, | ||
553 | atsi, atsi_count, | ||
554 | &atsi_delta, | ||
555 | &atsi_delta_count); | ||
556 | GNUNET_free_non_null (atsi_delta); | ||
557 | addr_net = get_performance_info (new_address, GNUNET_ATS_NETWORK_TYPE); | ||
558 | if (GNUNET_ATS_VALUE_UNDEFINED == addr_net) | ||
559 | addr_net = GNUNET_ATS_NET_UNSPECIFIED; | ||
560 | |||
561 | /* Add a new address */ | 232 | /* Add a new address */ |
233 | new_address->properties = *prop; | ||
562 | new_address->t_added = GNUNET_TIME_absolute_get(); | 234 | new_address->t_added = GNUNET_TIME_absolute_get(); |
563 | new_address->t_last_activity = GNUNET_TIME_absolute_get(); | 235 | new_address->t_last_activity = GNUNET_TIME_absolute_get(); |
564 | GNUNET_assert(GNUNET_OK == | 236 | GNUNET_assert(GNUNET_OK == |
@@ -573,11 +245,8 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
573 | session_id); | 245 | session_id); |
574 | /* Tell solver about new address */ | 246 | /* Tell solver about new address */ |
575 | GAS_plugin_solver_lock (); | 247 | GAS_plugin_solver_lock (); |
576 | GAS_plugin_new_address (new_address, | 248 | GAS_plugin_new_address (new_address); |
577 | addr_net); | 249 | GAS_normalization_update_property (new_address); // FIXME: needed? |
578 | GAS_normalization_update_property (new_address, | ||
579 | atsi, | ||
580 | atsi_count); | ||
581 | GAS_plugin_solver_unlock (); | 250 | GAS_plugin_solver_unlock (); |
582 | /* Notify performance clients about new address */ | 251 | /* Notify performance clients about new address */ |
583 | GAS_performance_notify_all_clients (&new_address->peer, | 252 | GAS_performance_notify_all_clients (&new_address->peer, |
@@ -585,8 +254,7 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
585 | new_address->addr, | 254 | new_address->addr, |
586 | new_address->addr_len, | 255 | new_address->addr_len, |
587 | new_address->active, | 256 | new_address->active, |
588 | new_address->atsi, | 257 | &new_address->properties, |
589 | new_address->atsi_count, | ||
590 | GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_out), | 258 | GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_out), |
591 | GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_in)); | 259 | GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_in)); |
592 | } | 260 | } |
@@ -597,18 +265,14 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
597 | * | 265 | * |
598 | * @param peer peer | 266 | * @param peer peer |
599 | * @param session_id session id, never 0 | 267 | * @param session_id session id, never 0 |
600 | * @param atsi performance information for this address | 268 | * @param prop performance information for this address |
601 | * @param atsi_count number of performance information contained in @a atsi | ||
602 | */ | 269 | */ |
603 | void | 270 | void |
604 | GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | 271 | GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, |
605 | uint32_t session_id, | 272 | uint32_t session_id, |
606 | const struct GNUNET_ATS_Information *atsi, | 273 | const struct GNUNET_ATS_Properties *prop) |
607 | uint32_t atsi_count) | ||
608 | { | 274 | { |
609 | struct ATS_Address *aa; | 275 | struct ATS_Address *aa; |
610 | struct GNUNET_ATS_Information *atsi_delta; | ||
611 | uint32_t atsi_delta_count; | ||
612 | 276 | ||
613 | /* Get existing address */ | 277 | /* Get existing address */ |
614 | aa = find_exact_address (peer, | 278 | aa = find_exact_address (peer, |
@@ -630,30 +294,18 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
630 | 294 | ||
631 | /* Update address */ | 295 | /* Update address */ |
632 | aa->t_last_activity = GNUNET_TIME_absolute_get(); | 296 | aa->t_last_activity = GNUNET_TIME_absolute_get(); |
633 | atsi_delta = NULL; | 297 | aa->properties = *prop; |
634 | atsi_delta_count = 0; | 298 | /* Notify performance clients about updated address */ |
635 | if (GNUNET_YES == | 299 | GAS_performance_notify_all_clients (&aa->peer, |
636 | disassemble_ats_information (aa, atsi, | 300 | aa->plugin, |
637 | atsi_count, | 301 | aa->addr, |
638 | &atsi_delta, | 302 | aa->addr_len, |
639 | &atsi_delta_count)) | 303 | aa->active, |
640 | { | 304 | prop, |
641 | /* Notify performance clients about updated address */ | 305 | GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out), |
642 | GAS_performance_notify_all_clients (&aa->peer, | 306 | GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in)); |
643 | aa->plugin, | 307 | |
644 | aa->addr, | 308 | GAS_normalization_update_property (aa); |
645 | aa->addr_len, | ||
646 | aa->active, | ||
647 | aa->atsi, | ||
648 | aa->atsi_count, | ||
649 | GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out), | ||
650 | GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in)); | ||
651 | |||
652 | GAS_normalization_update_property (aa, | ||
653 | atsi, | ||
654 | atsi_count); | ||
655 | } | ||
656 | GNUNET_free_non_null (atsi_delta); | ||
657 | } | 309 | } |
658 | 310 | ||
659 | 311 | ||
@@ -793,7 +445,7 @@ peerinfo_it (void *cls, | |||
793 | addr->addr, | 445 | addr->addr, |
794 | addr->addr_len, | 446 | addr->addr_len, |
795 | addr->active, | 447 | addr->active, |
796 | addr->atsi, addr->atsi_count, | 448 | &addr->properties, |
797 | GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out), | 449 | GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out), |
798 | GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in)); | 450 | GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in)); |
799 | return GNUNET_OK; | 451 | return GNUNET_OK; |
@@ -839,7 +491,7 @@ GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, | |||
839 | pi_it (pi_it_cls, | 491 | pi_it (pi_it_cls, |
840 | NULL, NULL, NULL, 0, | 492 | NULL, NULL, NULL, 0, |
841 | GNUNET_NO, | 493 | GNUNET_NO, |
842 | NULL, 0, | 494 | NULL, |
843 | GNUNET_BANDWIDTH_ZERO, | 495 | GNUNET_BANDWIDTH_ZERO, |
844 | GNUNET_BANDWIDTH_ZERO); | 496 | GNUNET_BANDWIDTH_ZERO); |
845 | } | 497 | } |
@@ -879,8 +531,7 @@ struct AddressIteration | |||
879 | * @param plugin_addr address | 531 | * @param plugin_addr address |
880 | * @param plugin_addr_len length of @a plugin_addr | 532 | * @param plugin_addr_len length of @a plugin_addr |
881 | * @param active #GNUNET_YES if this address is actively used | 533 | * @param active #GNUNET_YES if this address is actively used |
882 | * @param atsi ats performance information | 534 | * @param prop performance information |
883 | * @param atsi_count number of ats performance elements in @a atsi | ||
884 | * @param bandwidth_out current outbound bandwidth assigned to address | 535 | * @param bandwidth_out current outbound bandwidth assigned to address |
885 | * @param bandwidth_in current inbound bandwidth assigned to address | 536 | * @param bandwidth_in current inbound bandwidth assigned to address |
886 | */ | 537 | */ |
@@ -891,13 +542,11 @@ transmit_req_addr (struct AddressIteration *ai, | |||
891 | const void *plugin_addr, | 542 | const void *plugin_addr, |
892 | size_t plugin_addr_len, | 543 | size_t plugin_addr_len, |
893 | int active, | 544 | int active, |
894 | const struct GNUNET_ATS_Information *atsi, | 545 | const struct GNUNET_ATS_Properties *prop, |
895 | uint32_t atsi_count, | ||
896 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 546 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
897 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 547 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
898 | 548 | ||
899 | { | 549 | { |
900 | struct GNUNET_ATS_Information *atsp; | ||
901 | struct PeerInformationMessage *msg; | 550 | struct PeerInformationMessage *msg; |
902 | char *addrp; | 551 | char *addrp; |
903 | size_t plugin_name_length; | 552 | size_t plugin_name_length; |
@@ -909,18 +558,13 @@ transmit_req_addr (struct AddressIteration *ai, | |||
909 | else | 558 | else |
910 | plugin_name_length = 0; | 559 | plugin_name_length = 0; |
911 | msize = sizeof (struct PeerInformationMessage) + | 560 | msize = sizeof (struct PeerInformationMessage) + |
912 | atsi_count * sizeof (struct GNUNET_ATS_Information) + | ||
913 | plugin_addr_len + plugin_name_length; | 561 | plugin_addr_len + plugin_name_length; |
914 | char buf[msize] GNUNET_ALIGN; | 562 | char buf[msize] GNUNET_ALIGN; |
915 | 563 | ||
916 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 564 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); |
917 | GNUNET_assert (atsi_count < | ||
918 | GNUNET_SERVER_MAX_MESSAGE_SIZE / | ||
919 | sizeof (struct GNUNET_ATS_Information)); | ||
920 | msg = (struct PeerInformationMessage *) buf; | 565 | msg = (struct PeerInformationMessage *) buf; |
921 | msg->header.size = htons (msize); | 566 | msg->header.size = htons (msize); |
922 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); | 567 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); |
923 | msg->ats_count = htonl (atsi_count); | ||
924 | msg->id = htonl (ai->id); | 568 | msg->id = htonl (ai->id); |
925 | if (NULL != id) | 569 | if (NULL != id) |
926 | msg->peer = *id; | 570 | msg->peer = *id; |
@@ -931,9 +575,9 @@ transmit_req_addr (struct AddressIteration *ai, | |||
931 | msg->plugin_name_length = htons (plugin_name_length); | 575 | msg->plugin_name_length = htons (plugin_name_length); |
932 | msg->bandwidth_out = bandwidth_out; | 576 | msg->bandwidth_out = bandwidth_out; |
933 | msg->bandwidth_in = bandwidth_in; | 577 | msg->bandwidth_in = bandwidth_in; |
934 | atsp = (struct GNUNET_ATS_Information *) &msg[1]; | 578 | GNUNET_ATS_properties_hton (&msg->properties, |
935 | memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); | 579 | prop); |
936 | addrp = (char *) &atsp[atsi_count]; | 580 | addrp = (char *) &msg[1]; |
937 | if (NULL != plugin_addr) | 581 | if (NULL != plugin_addr) |
938 | memcpy (addrp, plugin_addr, plugin_addr_len); | 582 | memcpy (addrp, plugin_addr, plugin_addr_len); |
939 | if (NULL != plugin_name) | 583 | if (NULL != plugin_name) |
@@ -962,8 +606,7 @@ transmit_req_addr (struct AddressIteration *ai, | |||
962 | * @param plugin_addr address | 606 | * @param plugin_addr address |
963 | * @param plugin_addr_len length of @a plugin_addr | 607 | * @param plugin_addr_len length of @a plugin_addr |
964 | * @param active is address actively used | 608 | * @param active is address actively used |
965 | * @param atsi ats performance information | 609 | * @param prop performance information |
966 | * @param atsi_count number of ats performance elements in @a atsi | ||
967 | * @param bandwidth_out current outbound bandwidth assigned to address | 610 | * @param bandwidth_out current outbound bandwidth assigned to address |
968 | * @param bandwidth_in current inbound bandwidth assigned to address | 611 | * @param bandwidth_in current inbound bandwidth assigned to address |
969 | */ | 612 | */ |
@@ -974,8 +617,7 @@ req_addr_peerinfo_it (void *cls, | |||
974 | const void *plugin_addr, | 617 | const void *plugin_addr, |
975 | size_t plugin_addr_len, | 618 | size_t plugin_addr_len, |
976 | int active, | 619 | int active, |
977 | const struct GNUNET_ATS_Information *atsi, | 620 | const struct GNUNET_ATS_Properties *prop, |
978 | uint32_t atsi_count, | ||
979 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 621 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
980 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 622 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
981 | { | 623 | { |
@@ -1006,8 +648,7 @@ req_addr_peerinfo_it (void *cls, | |||
1006 | plugin_name, | 648 | plugin_name, |
1007 | plugin_addr, plugin_addr_len, | 649 | plugin_addr, plugin_addr_len, |
1008 | active, | 650 | active, |
1009 | atsi, | 651 | prop, |
1010 | atsi_count, | ||
1011 | bandwidth_out, | 652 | bandwidth_out, |
1012 | bandwidth_in); | 653 | bandwidth_in); |
1013 | } | 654 | } |
@@ -1061,7 +702,7 @@ GAS_handle_request_address_list (void *cls, | |||
1061 | transmit_req_addr (&ai, | 702 | transmit_req_addr (&ai, |
1062 | NULL, NULL, NULL, | 703 | NULL, NULL, NULL, |
1063 | 0, GNUNET_NO, | 704 | 0, GNUNET_NO, |
1064 | NULL, 0, | 705 | NULL, |
1065 | GNUNET_BANDWIDTH_ZERO, | 706 | GNUNET_BANDWIDTH_ZERO, |
1066 | GNUNET_BANDWIDTH_ZERO); | 707 | GNUNET_BANDWIDTH_ZERO); |
1067 | GNUNET_SERVER_receive_done (client, | 708 | GNUNET_SERVER_receive_done (client, |
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 2be8277e1..072a3d078 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -235,12 +235,12 @@ struct GAS_NormalizationInfo | |||
235 | /** | 235 | /** |
236 | * Averaging queue | 236 | * Averaging queue |
237 | */ | 237 | */ |
238 | uint32_t atsi_abs[GAS_normalization_queue_length]; | 238 | uint64_t atsi_abs[GAS_normalization_queue_length]; |
239 | 239 | ||
240 | /** | 240 | /** |
241 | * Averaged ATSI values from queue | 241 | * Averaged ATSI values from queue |
242 | */ | 242 | */ |
243 | uint32_t avg; | 243 | uint64_t avg; |
244 | 244 | ||
245 | /** | 245 | /** |
246 | * Normalized values from queue to a range of values [1.0...2.0] | 246 | * Normalized values from queue to a range of values [1.0...2.0] |
@@ -277,7 +277,7 @@ struct ATS_Address | |||
277 | /** | 277 | /** |
278 | * ATS performance information for this address | 278 | * ATS performance information for this address |
279 | */ | 279 | */ |
280 | struct GNUNET_ATS_Information *atsi; | 280 | struct GNUNET_ATS_Properties properties; |
281 | 281 | ||
282 | /** | 282 | /** |
283 | * Time when address had last activity (update, in uses) | 283 | * Time when address had last activity (update, in uses) |
@@ -336,10 +336,25 @@ struct ATS_Address | |||
336 | int active; | 336 | int active; |
337 | 337 | ||
338 | /** | 338 | /** |
339 | * Normalized ATS performance information for this address | 339 | * Normalized delay information for this address. |
340 | * Each entry can be accessed using the GNUNET_ATS_QualityProperties avg_queue_index | ||
341 | */ | 340 | */ |
342 | struct GAS_NormalizationInfo atsin[GNUNET_ATS_QualityPropertiesCount]; | 341 | struct GAS_NormalizationInfo norm_delay; |
342 | |||
343 | /** | ||
344 | * Normalized distance information for this address. | ||
345 | */ | ||
346 | struct GAS_NormalizationInfo norm_distance; | ||
347 | |||
348 | /** | ||
349 | * Normalized utilization inbound for this address. | ||
350 | */ | ||
351 | struct GAS_NormalizationInfo norm_utilization_in; | ||
352 | |||
353 | /** | ||
354 | * Normalized utilization outbound for this address. | ||
355 | */ | ||
356 | struct GAS_NormalizationInfo norm_utilization_out; | ||
357 | |||
343 | }; | 358 | }; |
344 | 359 | ||
345 | 360 | ||
@@ -375,8 +390,7 @@ GAS_addresses_done (void); | |||
375 | * @param plugin_addr_len length of the @a plugin_addr | 390 | * @param plugin_addr_len length of the @a plugin_addr |
376 | * @param local_address_info the local address for the address | 391 | * @param local_address_info the local address for the address |
377 | * @param session_id session id, can never be 0. | 392 | * @param session_id session id, can never be 0. |
378 | * @param atsi performance information for this address | 393 | * @param prop performance information for this address |
379 | * @param atsi_count number of performance information contained in @a atsi | ||
380 | */ | 394 | */ |
381 | void | 395 | void |
382 | GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | 396 | GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, |
@@ -385,8 +399,7 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
385 | size_t plugin_addr_len, | 399 | size_t plugin_addr_len, |
386 | uint32_t local_address_info, | 400 | uint32_t local_address_info, |
387 | uint32_t session_id, | 401 | uint32_t session_id, |
388 | const struct GNUNET_ATS_Information *atsi, | 402 | const struct GNUNET_ATS_Properties *prop); |
389 | uint32_t atsi_count); | ||
390 | 403 | ||
391 | 404 | ||
392 | /** | 405 | /** |
@@ -394,14 +407,12 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
394 | * | 407 | * |
395 | * @param peer peer | 408 | * @param peer peer |
396 | * @param session_id session id, can never be 0 | 409 | * @param session_id session id, can never be 0 |
397 | * @param atsi performance information for this address | 410 | * @param prop performance information for this address |
398 | * @param atsi_count number of performance information contained in @a atsi | ||
399 | */ | 411 | */ |
400 | void | 412 | void |
401 | GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | 413 | GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, |
402 | uint32_t session_id, | 414 | uint32_t session_id, |
403 | const struct GNUNET_ATS_Information *atsi, | 415 | const struct GNUNET_ATS_Properties *prop); |
404 | uint32_t atsi_count); | ||
405 | 416 | ||
406 | 417 | ||
407 | /** | 418 | /** |
@@ -432,7 +443,6 @@ GAS_addresses_destroy_all (void); | |||
432 | * @param plugin_addr_len length of @a plugin_addr | 443 | * @param plugin_addr_len length of @a plugin_addr |
433 | * @param address_active is address actively used | 444 | * @param address_active is address actively used |
434 | * @param atsi ats performance information | 445 | * @param atsi ats performance information |
435 | * @param atsi_count number of ats performance elements in @a atsi | ||
436 | * @param bandwidth_out current outbound bandwidth assigned to address | 446 | * @param bandwidth_out current outbound bandwidth assigned to address |
437 | * @param bandwidth_in current inbound bandwidth assigned to address | 447 | * @param bandwidth_in current inbound bandwidth assigned to address |
438 | */ | 448 | */ |
@@ -443,8 +453,7 @@ typedef void | |||
443 | const void *plugin_addr, | 453 | const void *plugin_addr, |
444 | size_t plugin_addr_len, | 454 | size_t plugin_addr_len, |
445 | const int address_active, | 455 | const int address_active, |
446 | const struct GNUNET_ATS_Information *atsi, | 456 | const struct GNUNET_ATS_Properties *prop, |
447 | uint32_t atsi_count, | ||
448 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 457 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
449 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); | 458 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); |
450 | 459 | ||
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index 936f8ca34..c10e5070f 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c | |||
@@ -37,103 +37,65 @@ | |||
37 | /** | 37 | /** |
38 | * Range information for normalization of quality properties. | 38 | * Range information for normalization of quality properties. |
39 | */ | 39 | */ |
40 | struct Property | 40 | struct PropertyRange |
41 | { | 41 | { |
42 | /** | 42 | /** |
43 | * Index into the properties array. | ||
44 | */ | ||
45 | uint32_t prop_type; | ||
46 | |||
47 | /** | ||
48 | * Corresponding enum value of the respective quality property. | ||
49 | */ | ||
50 | enum GNUNET_ATS_Property atsi_type; | ||
51 | |||
52 | /** | ||
53 | * Minimum value we see for this property across all addresses. | 43 | * Minimum value we see for this property across all addresses. |
54 | */ | 44 | */ |
55 | uint32_t min; | 45 | struct GNUNET_ATS_Properties min; |
56 | 46 | ||
57 | /** | 47 | /** |
58 | * Maximum value we see for this property across all addresses. | 48 | * Maximum value we see for this property across all addresses. |
59 | */ | 49 | */ |
60 | uint32_t max; | 50 | struct GNUNET_ATS_Properties max; |
61 | }; | 51 | }; |
62 | 52 | ||
63 | 53 | ||
64 | /** | 54 | /** |
65 | * Range information for all quality properties we see. | 55 | * Range information for all quality properties we see. |
66 | */ | 56 | */ |
67 | static struct Property properties[GNUNET_ATS_QualityPropertiesCount]; | 57 | static struct PropertyRange property_range; |
68 | |||
69 | 58 | ||
70 | 59 | ||
71 | /** | 60 | /** |
72 | * Add the value from @a atsi to the running average of the | 61 | * Add the value from @a atsi to the running average of the |
73 | * given @a ni quality property. | 62 | * given @a ni quality property. |
74 | * | 63 | * |
64 | * @param current_val the updated value | ||
75 | * @param ni normalization information to update | 65 | * @param ni normalization information to update |
76 | * @param atsi the ats information | ||
77 | */ | 66 | */ |
78 | static void | 67 | static void |
79 | property_average (struct GAS_NormalizationInfo *ni, | 68 | update_avg (uint64_t current_val, |
80 | const struct GNUNET_ATS_Information *atsi) | 69 | struct GAS_NormalizationInfo *ni) |
81 | { | 70 | { |
82 | uint32_t current_val; | 71 | double sum; |
83 | uint32_t res; | ||
84 | uint64_t sum; | ||
85 | uint32_t count; | 72 | uint32_t count; |
86 | unsigned int c1; | 73 | unsigned int c1; |
87 | 74 | ||
88 | current_val = ntohl (atsi->value); | ||
89 | GNUNET_assert (GNUNET_ATS_VALUE_UNDEFINED != current_val); | ||
90 | ni->atsi_abs[ni->avg_queue_index++] = current_val; | 75 | ni->atsi_abs[ni->avg_queue_index++] = current_val; |
91 | if (GAS_normalization_queue_length == ni->avg_queue_index) | 76 | if (GAS_normalization_queue_length == ni->avg_queue_index) |
92 | ni->avg_queue_index = 0; | 77 | ni->avg_queue_index = 0; |
93 | count = 0; | 78 | count = 0; |
94 | sum = 0; | 79 | sum = 0.0; |
95 | for (c1 = 0; c1 < GAS_normalization_queue_length; c1++) | 80 | for (c1 = 0; c1 < GAS_normalization_queue_length; c1++) |
96 | { | 81 | { |
97 | if (GNUNET_ATS_VALUE_UNDEFINED != ni->atsi_abs[c1]) | 82 | if (UINT64_MAX != ni->atsi_abs[c1]) |
98 | { | 83 | { |
99 | count++; | 84 | count++; |
100 | sum += ni->atsi_abs[c1]; | 85 | sum += (double) ni->atsi_abs[c1]; |
101 | } | 86 | } |
102 | } | 87 | } |
103 | GNUNET_assert (0 != count); | 88 | GNUNET_assert (0 != count); |
104 | res = sum / count; | 89 | ni->avg = sum / count; |
105 | ni->avg = res; | ||
106 | } | 90 | } |
107 | 91 | ||
108 | 92 | ||
109 | /** | 93 | /** |
110 | * Closure for #find_min_max_it(). | ||
111 | */ | ||
112 | struct FindMinMaxCtx | ||
113 | { | ||
114 | /** | ||
115 | * Property we are looking for. | ||
116 | */ | ||
117 | struct Property *p; | ||
118 | |||
119 | /** | ||
120 | * Set to mimimum value observed. | ||
121 | */ | ||
122 | uint32_t min; | ||
123 | |||
124 | /** | ||
125 | * Set to maximum value observed. | ||
126 | */ | ||
127 | uint32_t max; | ||
128 | }; | ||
129 | |||
130 | |||
131 | /** | ||
132 | * Function called for all addresses and peers to find the minimum and | 94 | * Function called for all addresses and peers to find the minimum and |
133 | * maximum (averaged) values for a given quality property. Given | 95 | * maximum (averaged) values for a given quality property. Given |
134 | * those, we can then calculate the normalized score. | 96 | * those, we can then calculate the normalized score. |
135 | * | 97 | * |
136 | * @param cls the `struct FindMinMaxCtx` | 98 | * @param cls the `struct PropertyRange` |
137 | * @param h which peer are we looking at (ignored) | 99 | * @param h which peer are we looking at (ignored) |
138 | * @param k the address for that peer | 100 | * @param k the address for that peer |
139 | * @return #GNUNET_OK (continue to iterate) | 101 | * @return #GNUNET_OK (continue to iterate) |
@@ -143,23 +105,55 @@ find_min_max_it (void *cls, | |||
143 | const struct GNUNET_PeerIdentity *h, | 105 | const struct GNUNET_PeerIdentity *h, |
144 | void *k) | 106 | void *k) |
145 | { | 107 | { |
146 | struct FindMinMaxCtx *find_res = cls; | 108 | struct PropertyRange *pr = cls; |
147 | const struct ATS_Address *a = k; | 109 | const struct ATS_Address *a = k; |
148 | 110 | ||
149 | find_res->max = GNUNET_MAX (find_res->max, | 111 | pr->max.utilization_out = GNUNET_MAX (pr->max.utilization_out, |
150 | a->atsin[find_res->p->prop_type].avg); | 112 | a->properties.utilization_out); |
151 | find_res->min = GNUNET_MIN (find_res->min, | 113 | pr->max.utilization_in = GNUNET_MAX (pr->max.utilization_in, |
152 | a->atsin[find_res->p->prop_type].avg); | 114 | a->properties.utilization_in); |
115 | pr->max.distance = GNUNET_MAX (pr->max.distance, | ||
116 | a->properties.distance); | ||
117 | pr->max.delay = GNUNET_TIME_relative_max (pr->max.delay, | ||
118 | a->properties.delay); | ||
119 | pr->min.utilization_out = GNUNET_MIN (pr->min.utilization_out, | ||
120 | a->properties.utilization_out); | ||
121 | pr->min.utilization_in = GNUNET_MIN (pr->min.utilization_in, | ||
122 | a->properties.utilization_in); | ||
123 | pr->min.distance = GNUNET_MIN (pr->min.distance, | ||
124 | a->properties.distance); | ||
125 | pr->min.delay = GNUNET_TIME_relative_min (pr->min.delay, | ||
126 | a->properties.delay); | ||
153 | return GNUNET_OK; | 127 | return GNUNET_OK; |
154 | } | 128 | } |
155 | 129 | ||
156 | 130 | ||
157 | /** | 131 | /** |
132 | * Compute the normalized value from the given @a ni range | ||
133 | * data and the average value. | ||
134 | * | ||
135 | * @param min minimum value | ||
136 | * @param max maximum value | ||
137 | * @param ni normalization information to update | ||
138 | */ | ||
139 | static void | ||
140 | update_norm (uint64_t min, | ||
141 | uint64_t max, | ||
142 | struct GAS_NormalizationInfo *ni) | ||
143 | { | ||
144 | /* max - 2 * min + avg_value / (max - min) */ | ||
145 | if (min < max) | ||
146 | ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double) (max - min); | ||
147 | else | ||
148 | ni->norm = DEFAULT_REL_QUALITY; | ||
149 | } | ||
150 | |||
151 | |||
152 | /** | ||
158 | * Normalize the property value for a given address based | 153 | * Normalize the property value for a given address based |
159 | * on the range we know that property value has globally. | 154 | * on the range we know that property values have globally. |
160 | * | 155 | * |
161 | * @param cls the `struct Property` with details on the | 156 | * @param cls NULL |
162 | * property and its global range | ||
163 | * @param key which peer are we looking at (ignored) | 157 | * @param key which peer are we looking at (ignored) |
164 | * @param value the address for that peer, from where we get | 158 | * @param value the address for that peer, from where we get |
165 | * the original value and where we write the | 159 | * the original value and where we write the |
@@ -171,33 +165,20 @@ normalize_address (void *cls, | |||
171 | const struct GNUNET_PeerIdentity *key, | 165 | const struct GNUNET_PeerIdentity *key, |
172 | void *value) | 166 | void *value) |
173 | { | 167 | { |
174 | struct Property *p = cls; | ||
175 | struct ATS_Address *address = value; | 168 | struct ATS_Address *address = value; |
176 | double delta; | ||
177 | double update; | ||
178 | uint32_t avg_value; | ||
179 | |||
180 | avg_value = address->atsin[p->prop_type].avg; | ||
181 | delta = p->max - p->min; | ||
182 | /* max - 2 * min + avg_value / (max - min) */ | ||
183 | if (delta > DBL_EPSILON) | ||
184 | update = DEFAULT_REL_QUALITY + (avg_value - p->min) / delta; | ||
185 | else | ||
186 | update = DEFAULT_REL_QUALITY; | ||
187 | 169 | ||
188 | if (update == address->atsin[p->prop_type].norm) | 170 | update_norm (property_range.min.delay.rel_value_us, |
189 | return GNUNET_OK; | 171 | property_range.max.delay.rel_value_us, |
190 | address->atsin[p->prop_type].norm = update; | 172 | &address->norm_delay); |
191 | 173 | update_norm (property_range.min.distance, | |
192 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 174 | property_range.max.distance, |
193 | "Normalize `%s' address %p's '%s' with value %u to range [%u..%u] = %.3f\n", | 175 | &address->norm_distance); |
194 | GNUNET_i2s (&address->peer), | 176 | update_norm (property_range.min.utilization_in, |
195 | address, | 177 | property_range.max.utilization_in, |
196 | GNUNET_ATS_print_property_type (p->atsi_type), | 178 | &address->norm_utilization_in); |
197 | address->atsin[p->prop_type].avg, | 179 | update_norm (property_range.min.utilization_out, |
198 | p->min, | 180 | property_range.max.utilization_out, |
199 | p->max, | 181 | &address->norm_utilization_out); |
200 | address->atsin[p->prop_type].norm); | ||
201 | return GNUNET_OK; | 182 | return GNUNET_OK; |
202 | } | 183 | } |
203 | 184 | ||
@@ -205,8 +186,7 @@ normalize_address (void *cls, | |||
205 | /** | 186 | /** |
206 | * Notify about change in normalized property. | 187 | * Notify about change in normalized property. |
207 | * | 188 | * |
208 | * @param cls the `struct Property` with details on the | 189 | * @param cls NULL |
209 | * property and its global range | ||
210 | * @param key which peer are we looking at (ignored) | 190 | * @param key which peer are we looking at (ignored) |
211 | * @param value the address for that peer | 191 | * @param value the address for that peer |
212 | * @return #GNUNET_OK (continue to iterate) | 192 | * @return #GNUNET_OK (continue to iterate) |
@@ -216,104 +196,84 @@ notify_change (void *cls, | |||
216 | const struct GNUNET_PeerIdentity *key, | 196 | const struct GNUNET_PeerIdentity *key, |
217 | void *value) | 197 | void *value) |
218 | { | 198 | { |
219 | struct Property *p = cls; | ||
220 | struct ATS_Address *address = value; | 199 | struct ATS_Address *address = value; |
221 | 200 | ||
222 | GAS_plugin_notify_property_changed (address, | 201 | GAS_plugin_notify_property_changed (address); |
223 | p->atsi_type, | ||
224 | address->atsin[p->prop_type].norm); | ||
225 | return GNUNET_OK; | 202 | return GNUNET_OK; |
226 | } | 203 | } |
227 | 204 | ||
228 | 205 | ||
229 | /** | 206 | /** |
207 | * Initialize property range to the values corresponding | ||
208 | * to an empty set. | ||
209 | * | ||
210 | * @param pr range to initialize | ||
211 | */ | ||
212 | static void | ||
213 | init_range (struct PropertyRange *pr) | ||
214 | { | ||
215 | memset (pr, 0, sizeof (struct PropertyRange)); | ||
216 | pr->min.utilization_out = UINT32_MAX; | ||
217 | pr->min.utilization_in = UINT32_MAX; | ||
218 | pr->min.distance = UINT32_MAX; | ||
219 | pr->min.delay = GNUNET_TIME_UNIT_FOREVER_REL; | ||
220 | } | ||
221 | |||
222 | |||
223 | /** | ||
230 | * Update and normalize atsi performance information | 224 | * Update and normalize atsi performance information |
231 | * | 225 | * |
232 | * @param address the address to update | 226 | * @param address the address to update |
233 | * @param atsi the array of performance information | ||
234 | * @param atsi_count the number of atsi information in the array | ||
235 | */ | 227 | */ |
236 | void | 228 | void |
237 | GAS_normalization_update_property (struct ATS_Address *address, | 229 | GAS_normalization_update_property (struct ATS_Address *address) |
238 | const struct GNUNET_ATS_Information *atsi, | ||
239 | uint32_t atsi_count) | ||
240 | { | 230 | { |
241 | unsigned int c1; | 231 | const struct GNUNET_ATS_Properties *prop = &address->properties; |
242 | unsigned int c2; | 232 | struct PropertyRange range; |
243 | uint32_t current_type; | ||
244 | uint32_t old; | ||
245 | struct FindMinMaxCtx find_ctx; | ||
246 | int range_changed; | 233 | int range_changed; |
247 | 234 | ||
248 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 235 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
249 | "Updating %u elements for peer `%s'\n", | 236 | "Updating properties for peer `%s'\n", |
250 | atsi_count, | ||
251 | GNUNET_i2s (&address->peer)); | 237 | GNUNET_i2s (&address->peer)); |
252 | GAS_plugin_solver_lock (); | 238 | GAS_plugin_solver_lock (); |
253 | for (c1 = 0; c1 < atsi_count; c1++) | 239 | update_avg (prop->delay.rel_value_us, |
240 | &address->norm_delay); | ||
241 | update_avg (prop->distance, | ||
242 | &address->norm_distance); | ||
243 | update_avg (prop->utilization_in, | ||
244 | &address->norm_utilization_in); | ||
245 | update_avg (prop->utilization_in, | ||
246 | &address->norm_utilization_out); | ||
247 | |||
248 | init_range (&range); | ||
249 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | ||
250 | &find_min_max_it, | ||
251 | &range); | ||
252 | if (0 != memcmp (&range, | ||
253 | &property_range, | ||
254 | sizeof (struct PropertyRange))) | ||
254 | { | 255 | { |
255 | current_type = ntohl (atsi[c1].type); | 256 | /* limits changed, (re)normalize all addresses */ |
256 | 257 | property_range = range; | |
257 | for (c2 = 0; c2 < GNUNET_ATS_QualityPropertiesCount; c2++) | 258 | range_changed = GNUNET_YES; |
258 | if (current_type == properties[c2].atsi_type) | ||
259 | break; | ||
260 | if (GNUNET_ATS_QualityPropertiesCount == c2) | ||
261 | { | ||
262 | /* Not a quality property, continue with next element */ | ||
263 | continue; | ||
264 | } | ||
265 | /* Calculate running average */ | ||
266 | old = address->atsin[c2].avg; | ||
267 | property_average (&address->atsin[c2], | ||
268 | &atsi[c1]); | ||
269 | if (old == address->atsin[c2].avg) | ||
270 | continue; /* no change */ | ||
271 | range_changed = GNUNET_NO; | ||
272 | if ( (old == properties[c2].min) || | ||
273 | (old == properties[c2].max) || | ||
274 | (address->atsin[c2].avg < properties[c2].min) || | ||
275 | (address->atsin[c2].avg > properties[c2].max) ) | ||
276 | { | ||
277 | /* need to re-calculate min/max range, as it may have changed */ | ||
278 | find_ctx.p = &properties[c2]; | ||
279 | find_ctx.max = 0; | ||
280 | find_ctx.min = UINT32_MAX; | ||
281 | if (0 == | ||
282 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | ||
283 | &find_min_max_it, | ||
284 | &find_ctx)) | ||
285 | { | ||
286 | GNUNET_break(0); | ||
287 | continue; | ||
288 | } | ||
289 | if ( (find_ctx.min != properties[c2].min) || | ||
290 | (find_ctx.max != properties[c2].max) ) | ||
291 | { | ||
292 | properties[c2].min = find_ctx.min; | ||
293 | properties[c2].max = find_ctx.max; | ||
294 | /* limits changed, (re)normalize all addresses */ | ||
295 | range_changed = GNUNET_YES; | ||
296 | } | ||
297 | } | ||
298 | if (GNUNET_YES == range_changed) | ||
299 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | ||
300 | &normalize_address, | ||
301 | &properties[c2]); | ||
302 | else | ||
303 | normalize_address (&properties[c2], | ||
304 | &address->peer, | ||
305 | address); | ||
306 | /* after all peers have been updated, notify about changes */ | ||
307 | if (GNUNET_YES == range_changed) | ||
308 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | ||
309 | ¬ify_change, | ||
310 | &properties[c2]); | ||
311 | else | ||
312 | notify_change (&properties[c2], | ||
313 | &address->peer, | ||
314 | address); | ||
315 | |||
316 | } | 259 | } |
260 | if (GNUNET_YES == range_changed) | ||
261 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | ||
262 | &normalize_address, | ||
263 | NULL); | ||
264 | else | ||
265 | normalize_address (NULL, | ||
266 | &address->peer, | ||
267 | address); | ||
268 | /* after all peers have been updated, notify about changes */ | ||
269 | if (GNUNET_YES == range_changed) | ||
270 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | ||
271 | ¬ify_change, | ||
272 | NULL); | ||
273 | else | ||
274 | notify_change (NULL, | ||
275 | &address->peer, | ||
276 | address); | ||
317 | GAS_plugin_solver_unlock (); | 277 | GAS_plugin_solver_unlock (); |
318 | } | 278 | } |
319 | 279 | ||
@@ -324,16 +284,7 @@ GAS_normalization_update_property (struct ATS_Address *address, | |||
324 | void | 284 | void |
325 | GAS_normalization_start () | 285 | GAS_normalization_start () |
326 | { | 286 | { |
327 | unsigned int c1; | 287 | init_range (&property_range); |
328 | const unsigned int existing_properties[] = GNUNET_ATS_QualityProperties; | ||
329 | |||
330 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) | ||
331 | { | ||
332 | properties[c1].prop_type = c1; | ||
333 | properties[c1].atsi_type = existing_properties[c1]; | ||
334 | properties[c1].min = UINT32_MAX; | ||
335 | properties[c1].max = 0; | ||
336 | } | ||
337 | } | 288 | } |
338 | 289 | ||
339 | 290 | ||
diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h index 2ce9d726f..2a9f68b60 100644 --- a/src/ats/gnunet-service-ats_normalization.h +++ b/src/ats/gnunet-service-ats_normalization.h | |||
@@ -35,16 +35,12 @@ | |||
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Update and normalize a @a atsi performance information | 38 | * Update and normalize a @a prop performance information |
39 | * | 39 | * |
40 | * @param address the address to update | 40 | * @param address the address to update |
41 | * @param atsi the array of performance information | ||
42 | * @param atsi_count the number of atsi information in the array | ||
43 | */ | 41 | */ |
44 | void | 42 | void |
45 | GAS_normalization_update_property (struct ATS_Address *address, | 43 | GAS_normalization_update_property (struct ATS_Address *address); |
46 | const struct GNUNET_ATS_Information *atsi, | ||
47 | uint32_t atsi_count); | ||
48 | 44 | ||
49 | 45 | ||
50 | /** | 46 | /** |
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index 0f17f0bec..c3d9e78eb 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c | |||
@@ -54,8 +54,7 @@ static struct GNUNET_SERVER_NotificationContext *nc_pic; | |||
54 | * to maintain a connection to a peer; | 54 | * to maintain a connection to a peer; |
55 | * #GNUNET_NO if the address is not actively used; | 55 | * #GNUNET_NO if the address is not actively used; |
56 | * #GNUNET_SYSERR if this address is no longer available for ATS | 56 | * #GNUNET_SYSERR if this address is no longer available for ATS |
57 | * @param atsi performance data for the address | 57 | * @param prop performance data for the address |
58 | * @param atsi_count number of performance records in @a atsi | ||
59 | * @param bandwidth_out assigned outbound bandwidth | 58 | * @param bandwidth_out assigned outbound bandwidth |
60 | * @param bandwidth_in assigned inbound bandwidth | 59 | * @param bandwidth_in assigned inbound bandwidth |
61 | */ | 60 | */ |
@@ -66,40 +65,34 @@ notify_client (struct GNUNET_SERVER_Client *client, | |||
66 | const void *plugin_addr, | 65 | const void *plugin_addr, |
67 | size_t plugin_addr_len, | 66 | size_t plugin_addr_len, |
68 | int active, | 67 | int active, |
69 | const struct GNUNET_ATS_Information *atsi, | 68 | const struct GNUNET_ATS_Properties *prop, |
70 | uint32_t atsi_count, | ||
71 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 69 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
72 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 70 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
73 | { | 71 | { |
74 | struct PeerInformationMessage *msg; | 72 | struct PeerInformationMessage *msg; |
75 | size_t plugin_name_length = strlen (plugin_name) + 1; | 73 | size_t plugin_name_length = strlen (plugin_name) + 1; |
76 | size_t msize = | 74 | size_t msize = |
77 | sizeof (struct PeerInformationMessage) + | 75 | sizeof (struct PeerInformationMessage) + |
78 | atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len + | 76 | plugin_addr_len + |
79 | plugin_name_length; | 77 | plugin_name_length; |
80 | char buf[msize] GNUNET_ALIGN; | 78 | char buf[msize] GNUNET_ALIGN; |
81 | struct GNUNET_ATS_Information *atsp; | ||
82 | struct GNUNET_SERVER_NotificationContext *nc; | 79 | struct GNUNET_SERVER_NotificationContext *nc; |
83 | char *addrp; | 80 | char *addrp; |
84 | 81 | ||
85 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 82 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); |
86 | GNUNET_assert (atsi_count < | ||
87 | GNUNET_SERVER_MAX_MESSAGE_SIZE / | ||
88 | sizeof (struct GNUNET_ATS_Information)); | ||
89 | msg = (struct PeerInformationMessage *) buf; | 83 | msg = (struct PeerInformationMessage *) buf; |
90 | msg->header.size = htons (msize); | 84 | msg->header.size = htons (msize); |
91 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION); | 85 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION); |
92 | msg->id = htonl (0); | 86 | msg->id = htonl (0); |
93 | msg->ats_count = htonl (atsi_count); | ||
94 | msg->peer = *peer; | 87 | msg->peer = *peer; |
95 | msg->address_length = htons (plugin_addr_len); | 88 | msg->address_length = htons (plugin_addr_len); |
96 | msg->address_active = ntohl ((uint32_t) active); | 89 | msg->address_active = ntohl ((uint32_t) active); |
97 | msg->plugin_name_length = htons (plugin_name_length); | 90 | msg->plugin_name_length = htons (plugin_name_length); |
98 | msg->bandwidth_out = bandwidth_out; | 91 | msg->bandwidth_out = bandwidth_out; |
99 | msg->bandwidth_in = bandwidth_in; | 92 | msg->bandwidth_in = bandwidth_in; |
100 | atsp = (struct GNUNET_ATS_Information *) &msg[1]; | 93 | GNUNET_ATS_properties_hton (&msg->properties, |
101 | memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); | 94 | prop); |
102 | addrp = (char *) &atsp[atsi_count]; | 95 | addrp = (char *) &msg[1]; |
103 | memcpy (addrp, plugin_addr, plugin_addr_len); | 96 | memcpy (addrp, plugin_addr, plugin_addr_len); |
104 | strcpy (&addrp[plugin_addr_len], plugin_name); | 97 | strcpy (&addrp[plugin_addr_len], plugin_name); |
105 | if (NULL == client) | 98 | if (NULL == client) |
@@ -137,8 +130,7 @@ notify_client (struct GNUNET_SERVER_Client *client, | |||
137 | * to maintain a connection to a peer; | 130 | * to maintain a connection to a peer; |
138 | * #GNUNET_NO if the address is not actively used; | 131 | * #GNUNET_NO if the address is not actively used; |
139 | * #GNUNET_SYSERR if this address is no longer available for ATS | 132 | * #GNUNET_SYSERR if this address is no longer available for ATS |
140 | * @param atsi performance data for the address | 133 | * @param prop performance data for the address |
141 | * @param atsi_count number of performance records in @a atsi | ||
142 | * @param bandwidth_out assigned outbound bandwidth | 134 | * @param bandwidth_out assigned outbound bandwidth |
143 | * @param bandwidth_in assigned inbound bandwidth | 135 | * @param bandwidth_in assigned inbound bandwidth |
144 | */ | 136 | */ |
@@ -148,8 +140,7 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, | |||
148 | const void *plugin_addr, | 140 | const void *plugin_addr, |
149 | size_t plugin_addr_len, | 141 | size_t plugin_addr_len, |
150 | int active, | 142 | int active, |
151 | const struct GNUNET_ATS_Information *atsi, | 143 | const struct GNUNET_ATS_Properties *prop, |
152 | uint32_t atsi_count, | ||
153 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 144 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
154 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 145 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
155 | { | 146 | { |
@@ -159,7 +150,7 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, | |||
159 | plugin_addr, | 150 | plugin_addr, |
160 | plugin_addr_len, | 151 | plugin_addr_len, |
161 | active, | 152 | active, |
162 | atsi, atsi_count, | 153 | prop, |
163 | bandwidth_out, | 154 | bandwidth_out, |
164 | bandwidth_in); | 155 | bandwidth_in); |
165 | GNUNET_STATISTICS_update (GSA_stats, | 156 | GNUNET_STATISTICS_update (GSA_stats, |
@@ -178,8 +169,7 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, | |||
178 | * @param plugin_addr address | 169 | * @param plugin_addr address |
179 | * @param plugin_addr_len length of @a plugin_addr | 170 | * @param plugin_addr_len length of @a plugin_addr |
180 | * @param active is address actively used | 171 | * @param active is address actively used |
181 | * @param atsi ats performance information | 172 | * @param prop performance information |
182 | * @param atsi_count number of ats performance elements in @a atsi | ||
183 | * @param bandwidth_out current outbound bandwidth assigned to address | 173 | * @param bandwidth_out current outbound bandwidth assigned to address |
184 | * @param bandwidth_in current inbound bandwidth assigned to address | 174 | * @param bandwidth_in current inbound bandwidth assigned to address |
185 | */ | 175 | */ |
@@ -190,8 +180,7 @@ peerinfo_it (void *cls, | |||
190 | const void *plugin_addr, | 180 | const void *plugin_addr, |
191 | size_t plugin_addr_len, | 181 | size_t plugin_addr_len, |
192 | int active, | 182 | int active, |
193 | const struct GNUNET_ATS_Information *atsi, | 183 | const struct GNUNET_ATS_Properties *prop, |
194 | uint32_t atsi_count, | ||
195 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 184 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
196 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 185 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
197 | { | 186 | { |
@@ -211,7 +200,7 @@ peerinfo_it (void *cls, | |||
211 | plugin_addr, | 200 | plugin_addr, |
212 | plugin_addr_len, | 201 | plugin_addr_len, |
213 | active, | 202 | active, |
214 | atsi, atsi_count, | 203 | prop, |
215 | bandwidth_out, | 204 | bandwidth_out, |
216 | bandwidth_in); | 205 | bandwidth_in); |
217 | } | 206 | } |
diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h index 87712552f..abdeb975f 100644 --- a/src/ats/gnunet-service-ats_performance.h +++ b/src/ats/gnunet-service-ats_performance.h | |||
@@ -44,8 +44,7 @@ | |||
44 | * to maintain a connection to a peer; | 44 | * to maintain a connection to a peer; |
45 | * #GNUNET_NO if the address is not actively used; | 45 | * #GNUNET_NO if the address is not actively used; |
46 | * #GNUNET_SYSERR if this address is no longer available for ATS | 46 | * #GNUNET_SYSERR if this address is no longer available for ATS |
47 | * @param atsi performance data for the address | 47 | * @param prop performance data for the address |
48 | * @param atsi_count number of performance records in @a atsi | ||
49 | * @param bandwidth_out assigned outbound bandwidth | 48 | * @param bandwidth_out assigned outbound bandwidth |
50 | * @param bandwidth_in assigned inbound bandwidth | 49 | * @param bandwidth_in assigned inbound bandwidth |
51 | */ | 50 | */ |
@@ -55,8 +54,7 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, | |||
55 | const void *plugin_addr, | 54 | const void *plugin_addr, |
56 | size_t plugin_addr_len, | 55 | size_t plugin_addr_len, |
57 | int active, | 56 | int active, |
58 | const struct GNUNET_ATS_Information *atsi, | 57 | const struct GNUNET_ATS_Properties *prop, |
59 | uint32_t atsi_count, | ||
60 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 58 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
61 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); | 59 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); |
62 | 60 | ||
diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c index fbc047a33..b0bbb910b 100644 --- a/src/ats/gnunet-service-ats_plugins.c +++ b/src/ats/gnunet-service-ats_plugins.c | |||
@@ -70,22 +70,15 @@ GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer, | |||
70 | 70 | ||
71 | 71 | ||
72 | /** | 72 | /** |
73 | * The relative value for a property changed | 73 | * The relative value for a property changed. |
74 | * | 74 | * |
75 | * @param address the peer | 75 | * @param address the peer for which a property changed |
76 | * @param type the ATS type | ||
77 | * @param prop_rel the new relative preference value | ||
78 | */ | 76 | */ |
79 | void | 77 | void |
80 | GAS_plugin_notify_property_changed (struct ATS_Address *address, | 78 | GAS_plugin_notify_property_changed (struct ATS_Address *address) |
81 | enum GNUNET_ATS_Property type, | ||
82 | double prop_rel) | ||
83 | { | 79 | { |
84 | sf->s_address_update_property (sf->cls, | 80 | sf->s_address_update_property (sf->cls, |
85 | address, | 81 | address); |
86 | type, | ||
87 | 0, | ||
88 | prop_rel); | ||
89 | } | 82 | } |
90 | 83 | ||
91 | 84 | ||
@@ -221,8 +214,7 @@ bandwidth_changed_cb (void *cls, | |||
221 | address->addr, | 214 | address->addr, |
222 | address->addr_len, | 215 | address->addr_len, |
223 | address->active, | 216 | address->active, |
224 | address->atsi, | 217 | &address->properties, |
225 | address->atsi_count, | ||
226 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_out), | 218 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_out), |
227 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); | 219 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); |
228 | 220 | ||
@@ -481,15 +473,13 @@ GAS_plugin_done () | |||
481 | * for talking to the respective peer. | 473 | * for talking to the respective peer. |
482 | * | 474 | * |
483 | * @param new_address the new address | 475 | * @param new_address the new address |
484 | * @param addr_net network scope the address is in | ||
485 | */ | 476 | */ |
486 | void | 477 | void |
487 | GAS_plugin_new_address (struct ATS_Address *new_address, | 478 | GAS_plugin_new_address (struct ATS_Address *new_address) |
488 | enum GNUNET_ATS_Network_Type addr_net) | ||
489 | { | 479 | { |
490 | sf->s_add (sf->cls, | 480 | sf->s_add (sf->cls, |
491 | new_address, | 481 | new_address, |
492 | addr_net); | 482 | new_address->properties.scope); /* FIXME: remove 3rd arg here! */ |
493 | } | 483 | } |
494 | 484 | ||
495 | 485 | ||
diff --git a/src/ats/gnunet-service-ats_plugins.h b/src/ats/gnunet-service-ats_plugins.h index 7d76f6431..66eafa4c8 100644 --- a/src/ats/gnunet-service-ats_plugins.h +++ b/src/ats/gnunet-service-ats_plugins.h | |||
@@ -65,16 +65,12 @@ GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer, | |||
65 | 65 | ||
66 | 66 | ||
67 | /** | 67 | /** |
68 | * The relative value for a property changed | 68 | * The relative value for a property changed. |
69 | * | 69 | * |
70 | * @param address the peer | 70 | * @param address the peer |
71 | * @param type the ATS type | ||
72 | * @param prop_rel the new relative property value | ||
73 | */ | 71 | */ |
74 | void | 72 | void |
75 | GAS_plugin_notify_property_changed (struct ATS_Address *address, | 73 | GAS_plugin_notify_property_changed (struct ATS_Address *address); |
76 | enum GNUNET_ATS_Property type, | ||
77 | double prop_rel); | ||
78 | 74 | ||
79 | 75 | ||
80 | /** | 76 | /** |
@@ -85,8 +81,7 @@ GAS_plugin_notify_property_changed (struct ATS_Address *address, | |||
85 | * @param addr_net network scope the address is in | 81 | * @param addr_net network scope the address is in |
86 | */ | 82 | */ |
87 | void | 83 | void |
88 | GAS_plugin_new_address (struct ATS_Address *new_address, | 84 | GAS_plugin_new_address (struct ATS_Address *new_address); |
89 | enum GNUNET_ATS_Network_Type addr_net); | ||
90 | 85 | ||
91 | 86 | ||
92 | /** | 87 | /** |
diff --git a/src/ats/gnunet-service-ats_preferences.c b/src/ats/gnunet-service-ats_preferences.c index 3be6d3525..8c0b13ab0 100644 --- a/src/ats/gnunet-service-ats_preferences.c +++ b/src/ats/gnunet-service-ats_preferences.c | |||
@@ -62,7 +62,7 @@ struct PeerRelative | |||
62 | * Array of relative preference values, to be indexed by | 62 | * Array of relative preference values, to be indexed by |
63 | * an `enum GNUNET_ATS_PreferenceKind`. | 63 | * an `enum GNUNET_ATS_PreferenceKind`. |
64 | */ | 64 | */ |
65 | double f_rel[GNUNET_ATS_PreferenceCount]; | 65 | double f_rel[GNUNET_ATS_PREFERENCE_END]; |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Number of clients that are expressing a preference for | 68 | * Number of clients that are expressing a preference for |
@@ -99,14 +99,14 @@ struct PreferencePeer | |||
99 | * Absolute preference values for all preference types | 99 | * Absolute preference values for all preference types |
100 | * as expressed by this client for this peer. | 100 | * as expressed by this client for this peer. |
101 | */ | 101 | */ |
102 | double f_abs[GNUNET_ATS_PreferenceCount]; | 102 | double f_abs[GNUNET_ATS_PREFERENCE_END]; |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * Relative preference values for all preference types, | 105 | * Relative preference values for all preference types, |
106 | * normalized in [0..1] based on how the respective | 106 | * normalized in [0..1] based on how the respective |
107 | * client scored other peers. | 107 | * client scored other peers. |
108 | */ | 108 | */ |
109 | double f_rel[GNUNET_ATS_PreferenceCount]; | 109 | double f_rel[GNUNET_ATS_PREFERENCE_END]; |
110 | 110 | ||
111 | }; | 111 | }; |
112 | 112 | ||
@@ -144,7 +144,7 @@ struct PreferenceClient | |||
144 | * Array of sums of absolute preferences for all | 144 | * Array of sums of absolute preferences for all |
145 | * peers as expressed by this client. | 145 | * peers as expressed by this client. |
146 | */ | 146 | */ |
147 | double f_abs_sum[GNUNET_ATS_PreferenceCount]; | 147 | double f_abs_sum[GNUNET_ATS_PREFERENCE_END]; |
148 | 148 | ||
149 | }; | 149 | }; |
150 | 150 | ||
@@ -353,7 +353,7 @@ age_values (void *cls, | |||
353 | int dead; | 353 | int dead; |
354 | 354 | ||
355 | dead = GNUNET_YES; | 355 | dead = GNUNET_YES; |
356 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 356 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) |
357 | { | 357 | { |
358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
359 | "Aging preference for peer `%s'\n", | 359 | "Aging preference for peer `%s'\n", |
@@ -563,7 +563,7 @@ update_preference (struct GNUNET_SERVER_Client *client, | |||
563 | struct PeerRelative *r_cur; | 563 | struct PeerRelative *r_cur; |
564 | unsigned int i; | 564 | unsigned int i; |
565 | 565 | ||
566 | if (kind >= GNUNET_ATS_PreferenceCount) | 566 | if (kind >= GNUNET_ATS_PREFERENCE_END) |
567 | { | 567 | { |
568 | GNUNET_break(0); | 568 | GNUNET_break(0); |
569 | return; | 569 | return; |
@@ -584,7 +584,7 @@ update_preference (struct GNUNET_SERVER_Client *client, | |||
584 | c_cur = GNUNET_new (struct PreferenceClient); | 584 | c_cur = GNUNET_new (struct PreferenceClient); |
585 | c_cur->peer2pref = GNUNET_CONTAINER_multipeermap_create (16, | 585 | c_cur->peer2pref = GNUNET_CONTAINER_multipeermap_create (16, |
586 | GNUNET_NO); | 586 | GNUNET_NO); |
587 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 587 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) |
588 | c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE; | 588 | c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE; |
589 | GNUNET_CONTAINER_DLL_insert (pc_head, | 589 | GNUNET_CONTAINER_DLL_insert (pc_head, |
590 | pc_tail, | 590 | pc_tail, |
@@ -598,7 +598,7 @@ update_preference (struct GNUNET_SERVER_Client *client, | |||
598 | { | 598 | { |
599 | /* Create struct for peer */ | 599 | /* Create struct for peer */ |
600 | r_cur = GNUNET_new (struct PeerRelative); | 600 | r_cur = GNUNET_new (struct PeerRelative); |
601 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 601 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) |
602 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; | 602 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; |
603 | GNUNET_assert (GNUNET_OK == | 603 | GNUNET_assert (GNUNET_OK == |
604 | GNUNET_CONTAINER_multipeermap_put (preference_peers, | 604 | GNUNET_CONTAINER_multipeermap_put (preference_peers, |
@@ -614,7 +614,7 @@ update_preference (struct GNUNET_SERVER_Client *client, | |||
614 | { | 614 | { |
615 | /* Not found: create new peer entry */ | 615 | /* Not found: create new peer entry */ |
616 | p_cur = GNUNET_new (struct PreferencePeer); | 616 | p_cur = GNUNET_new (struct PreferencePeer); |
617 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 617 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) |
618 | { | 618 | { |
619 | /* Default value per peer absolute preference for a preference*/ | 619 | /* Default value per peer absolute preference for a preference*/ |
620 | p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE; | 620 | p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE; |
@@ -710,7 +710,7 @@ GAS_preference_init () | |||
710 | 710 | ||
711 | preference_peers = GNUNET_CONTAINER_multipeermap_create (16, | 711 | preference_peers = GNUNET_CONTAINER_multipeermap_create (16, |
712 | GNUNET_NO); | 712 | GNUNET_NO); |
713 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 713 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) |
714 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; | 714 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; |
715 | } | 715 | } |
716 | 716 | ||
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index 74b83bf45..c5539897b 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c | |||
@@ -135,13 +135,12 @@ GAS_handle_address_add (void *cls, | |||
135 | const struct GNUNET_MessageHeader *message) | 135 | const struct GNUNET_MessageHeader *message) |
136 | { | 136 | { |
137 | const struct AddressAddMessage *m; | 137 | const struct AddressAddMessage *m; |
138 | const struct GNUNET_ATS_Information *atsi; | ||
139 | const char *address; | 138 | const char *address; |
140 | const char *plugin_name; | 139 | const char *plugin_name; |
141 | uint16_t address_length; | 140 | uint16_t address_length; |
142 | uint16_t plugin_name_length; | 141 | uint16_t plugin_name_length; |
143 | uint32_t ats_count; | ||
144 | uint16_t size; | 142 | uint16_t size; |
143 | struct GNUNET_ATS_Properties prop; | ||
145 | 144 | ||
146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
147 | "Received `%s' message\n", | 146 | "Received `%s' message\n", |
@@ -154,38 +153,38 @@ GAS_handle_address_add (void *cls, | |||
154 | return; | 153 | return; |
155 | } | 154 | } |
156 | m = (const struct AddressAddMessage *) message; | 155 | m = (const struct AddressAddMessage *) message; |
157 | ats_count = ntohl (m->ats_count); | ||
158 | address_length = ntohs (m->address_length); | 156 | address_length = ntohs (m->address_length); |
159 | plugin_name_length = ntohs (m->plugin_name_length); | 157 | plugin_name_length = ntohs (m->plugin_name_length); |
160 | atsi = (const struct GNUNET_ATS_Information *) &m[1]; | 158 | address = (const char *) &m[1]; |
161 | address = (const char *) &atsi[ats_count]; | ||
162 | if (plugin_name_length != 0) | 159 | if (plugin_name_length != 0) |
163 | plugin_name = &address[address_length]; | 160 | plugin_name = &address[address_length]; |
164 | else | 161 | else |
165 | plugin_name = ""; | 162 | plugin_name = ""; |
166 | 163 | ||
167 | if ((address_length + plugin_name_length + | 164 | if ((address_length + plugin_name_length + |
168 | ats_count * sizeof (struct GNUNET_ATS_Information) + | ||
169 | sizeof (struct AddressAddMessage) != ntohs (message->size)) || | 165 | sizeof (struct AddressAddMessage) != ntohs (message->size)) || |
170 | (ats_count > | 166 | ( (plugin_name_length > 0) && |
171 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || | 167 | (plugin_name[plugin_name_length - 1] != '\0') ) ) |
172 | ((plugin_name_length > 0) && (plugin_name[plugin_name_length - 1] != '\0'))) | ||
173 | { | 168 | { |
174 | GNUNET_break (0); | 169 | GNUNET_break (0); |
175 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 170 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
176 | return; | 171 | return; |
177 | } | 172 | } |
178 | GNUNET_STATISTICS_update (GSA_stats, | 173 | GNUNET_STATISTICS_update (GSA_stats, |
179 | "# addresses created", 1, | 174 | "# addresses created", |
175 | 1, | ||
180 | GNUNET_NO); | 176 | GNUNET_NO); |
177 | GNUNET_ATS_properties_ntoh (&prop, | ||
178 | &m->properties); | ||
181 | GAS_addresses_add (&m->peer, | 179 | GAS_addresses_add (&m->peer, |
182 | plugin_name, | 180 | plugin_name, |
183 | address, | 181 | address, |
184 | address_length, | 182 | address_length, |
185 | ntohl (m->address_local_info), | 183 | ntohl (m->address_local_info), |
186 | ntohl (m->session_id), | 184 | ntohl (m->session_id), |
187 | atsi, ats_count); | 185 | &prop); |
188 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 186 | GNUNET_SERVER_receive_done (client, |
187 | GNUNET_OK); | ||
189 | } | 188 | } |
190 | 189 | ||
191 | 190 | ||
@@ -202,38 +201,20 @@ GAS_handle_address_update (void *cls, | |||
202 | const struct GNUNET_MessageHeader *message) | 201 | const struct GNUNET_MessageHeader *message) |
203 | { | 202 | { |
204 | const struct AddressUpdateMessage *m; | 203 | const struct AddressUpdateMessage *m; |
205 | const struct GNUNET_ATS_Information *atsi; | 204 | struct GNUNET_ATS_Properties prop; |
206 | uint32_t ats_count; | ||
207 | uint16_t size; | ||
208 | 205 | ||
209 | size = ntohs (message->size); | ||
210 | if (size < sizeof (struct AddressUpdateMessage)) | ||
211 | { | ||
212 | GNUNET_break (0); | ||
213 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
214 | return; | ||
215 | } | ||
216 | m = (const struct AddressUpdateMessage *) message; | 206 | m = (const struct AddressUpdateMessage *) message; |
217 | ats_count = ntohl (m->ats_count); | ||
218 | atsi = (const struct GNUNET_ATS_Information *) &m[1]; | ||
219 | |||
220 | if ((ats_count * sizeof (struct GNUNET_ATS_Information) + | ||
221 | sizeof (struct AddressUpdateMessage) != ntohs (message->size)) || | ||
222 | (ats_count > | ||
223 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))) | ||
224 | { | ||
225 | GNUNET_break (0); | ||
226 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
227 | return; | ||
228 | } | ||
229 | GNUNET_STATISTICS_update (GSA_stats, | 207 | GNUNET_STATISTICS_update (GSA_stats, |
230 | "# address updates received", | 208 | "# address updates received", |
231 | 1, | 209 | 1, |
232 | GNUNET_NO); | 210 | GNUNET_NO); |
211 | GNUNET_ATS_properties_ntoh (&prop, | ||
212 | &m->properties); | ||
233 | GAS_addresses_update (&m->peer, | 213 | GAS_addresses_update (&m->peer, |
234 | ntohl (m->session_id), | 214 | ntohl (m->session_id), |
235 | atsi, ats_count); | 215 | &prop); |
236 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 216 | GNUNET_SERVER_receive_done (client, |
217 | GNUNET_OK); | ||
237 | } | 218 | } |
238 | 219 | ||
239 | 220 | ||
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c index b97261d46..7d402044f 100644 --- a/src/ats/plugin_ats_mlp.c +++ b/src/ats/plugin_ats_mlp.c | |||
@@ -62,6 +62,29 @@ enum MLP_Output_Format | |||
62 | }; | 62 | }; |
63 | 63 | ||
64 | 64 | ||
65 | enum QualityMetrics | ||
66 | { | ||
67 | RQ_QUALITY_METRIC_DELAY = 0, | ||
68 | RQ_QUALITY_METRIC_DISTANCE = 1, | ||
69 | RQ_QUALITY_METRIC_COUNT = 2 | ||
70 | }; | ||
71 | |||
72 | |||
73 | static const char * | ||
74 | print_quality_type (enum QualityMetrics qm) | ||
75 | { | ||
76 | switch (qm){ | ||
77 | case RQ_QUALITY_METRIC_DELAY: | ||
78 | return "delay"; | ||
79 | case RQ_QUALITY_METRIC_DISTANCE: | ||
80 | return "distance"; | ||
81 | default: | ||
82 | GNUNET_break (0); | ||
83 | return NULL; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | |||
65 | struct MLP_Solution | 88 | struct MLP_Solution |
66 | { | 89 | { |
67 | int lp_res; | 90 | int lp_res; |
@@ -125,7 +148,7 @@ struct MLP_Problem | |||
125 | /* Row index constraint 9: relativity*/ | 148 | /* Row index constraint 9: relativity*/ |
126 | unsigned int r_c9; | 149 | unsigned int r_c9; |
127 | /* Row indices quality metrics */ | 150 | /* Row indices quality metrics */ |
128 | int r_q[GNUNET_ATS_QualityPropertiesCount]; | 151 | int r_q[RQ_QUALITY_METRIC_COUNT]; |
129 | /* Row indices ATS network quotas */ | 152 | /* Row indices ATS network quotas */ |
130 | int r_quota[GNUNET_ATS_NetworkTypeCount]; | 153 | int r_quota[GNUNET_ATS_NetworkTypeCount]; |
131 | 154 | ||
@@ -136,7 +159,7 @@ struct MLP_Problem | |||
136 | /* Column index Proportionality (R) column */ | 159 | /* Column index Proportionality (R) column */ |
137 | int c_r; | 160 | int c_r; |
138 | /* Column index quality metrics */ | 161 | /* Column index quality metrics */ |
139 | int c_q[GNUNET_ATS_QualityPropertiesCount]; | 162 | int c_q[RQ_QUALITY_METRIC_COUNT]; |
140 | 163 | ||
141 | /* Problem matrix */ | 164 | /* Problem matrix */ |
142 | /* Current index */ | 165 | /* Current index */ |
@@ -161,23 +184,17 @@ struct MLP_Variables | |||
161 | /* LP MIP Gap */ | 184 | /* LP MIP Gap */ |
162 | double lp_mip_gap; | 185 | double lp_mip_gap; |
163 | 186 | ||
164 | /* ATS Quality metrics | 187 | /* Number of quality metrics @deprecated, use RQ_QUALITY_METRIC_COUNT */ |
165 | * | ||
166 | * Array with GNUNET_ATS_QualityPropertiesCount elements | ||
167 | * contains mapping to GNUNET_ATS_Property*/ | ||
168 | int q[GNUNET_ATS_QualityPropertiesCount]; | ||
169 | |||
170 | /* Number of quality metrics */ | ||
171 | int m_q; | 188 | int m_q; |
172 | 189 | ||
173 | /* Number of quality metrics */ | 190 | /* Number of quality metrics */ |
174 | int m_rc; | 191 | int m_rc; |
175 | 192 | ||
176 | /* Quality metric coefficients*/ | 193 | /* Quality metric coefficients*/ |
177 | double co_Q[GNUNET_ATS_QualityPropertiesCount]; | 194 | double co_Q[RQ_QUALITY_METRIC_COUNT]; |
178 | 195 | ||
179 | /* Ressource costs coefficients*/ | 196 | /* Ressource costs coefficients*/ |
180 | double co_RC[GNUNET_ATS_QualityPropertiesCount]; | 197 | double co_RC[RQ_QUALITY_METRIC_COUNT]; |
181 | 198 | ||
182 | /* Diversity coefficient */ | 199 | /* Diversity coefficient */ |
183 | double co_D; | 200 | double co_D; |
@@ -207,7 +224,7 @@ struct MLP_Variables | |||
207 | * array with GNUNET_ATS_QualityPropertiesCount elements | 224 | * array with GNUNET_ATS_QualityPropertiesCount elements |
208 | * contains mapping to GNUNET_ATS_Property | 225 | * contains mapping to GNUNET_ATS_Property |
209 | * */ | 226 | * */ |
210 | int rc[GNUNET_ATS_QualityPropertiesCount]; | 227 | int rc[RQ_QUALITY_METRIC_COUNT]; |
211 | 228 | ||
212 | }; | 229 | }; |
213 | 230 | ||
@@ -584,7 +601,7 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp) | |||
584 | mlp->p.r_c4 = MLP_UNDEFINED; | 601 | mlp->p.r_c4 = MLP_UNDEFINED; |
585 | mlp->p.r_c6 = MLP_UNDEFINED; | 602 | mlp->p.r_c6 = MLP_UNDEFINED; |
586 | mlp->p.r_c9 = MLP_UNDEFINED; | 603 | mlp->p.r_c9 = MLP_UNDEFINED; |
587 | for (c = 0; c < mlp->pv.m_q ; c ++) | 604 | for (c = 0; c < RQ_QUALITY_METRIC_COUNT ; c ++) |
588 | mlp->p.r_q[c] = MLP_UNDEFINED; | 605 | mlp->p.r_q[c] = MLP_UNDEFINED; |
589 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c ++) | 606 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c ++) |
590 | mlp->p.r_quota[c] = MLP_UNDEFINED; | 607 | mlp->p.r_quota[c] = MLP_UNDEFINED; |
@@ -679,30 +696,6 @@ mlp_solve_to_string (int retcode) | |||
679 | } | 696 | } |
680 | } | 697 | } |
681 | 698 | ||
682 | /** | ||
683 | * Extract an ATS performance info from an address | ||
684 | * | ||
685 | * @param address the address | ||
686 | * @param type the type to extract in HBO | ||
687 | * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist | ||
688 | */ | ||
689 | static uint32_t | ||
690 | get_performance_info (struct ATS_Address *address, uint32_t type) | ||
691 | { | ||
692 | int c1; | ||
693 | GNUNET_assert (NULL != address); | ||
694 | |||
695 | if ((NULL == address->atsi) || (0 == address->atsi_count)) | ||
696 | return GNUNET_ATS_VALUE_UNDEFINED; | ||
697 | |||
698 | for (c1 = 0; c1 < address->atsi_count; c1++) | ||
699 | { | ||
700 | if (ntohl (address->atsi[c1].type) == type) | ||
701 | return ntohl (address->atsi[c1].value); | ||
702 | } | ||
703 | return GNUNET_ATS_VALUE_UNDEFINED; | ||
704 | } | ||
705 | |||
706 | 699 | ||
707 | struct CountContext | 700 | struct CountContext |
708 | { | 701 | { |
@@ -960,7 +953,6 @@ mlp_create_problem_add_address_information (void *cls, | |||
960 | struct ATS_Peer *peer; | 953 | struct ATS_Peer *peer; |
961 | struct MLP_information *mlpi; | 954 | struct MLP_information *mlpi; |
962 | char *name; | 955 | char *name; |
963 | double prop; | ||
964 | double cur_bigm; | 956 | double cur_bigm; |
965 | uint32_t addr_net; | 957 | uint32_t addr_net; |
966 | uint32_t addr_net_index; | 958 | uint32_t addr_net_index; |
@@ -979,7 +971,7 @@ mlp_create_problem_add_address_information (void *cls, | |||
979 | return GNUNET_OK; | 971 | return GNUNET_OK; |
980 | } | 972 | } |
981 | 973 | ||
982 | addr_net = get_performance_info (address, GNUNET_ATS_NETWORK_TYPE); | 974 | addr_net = address->properties.scope; |
983 | for (addr_net_index = 0; addr_net_index < GNUNET_ATS_NetworkTypeCount; addr_net_index++) | 975 | for (addr_net_index = 0; addr_net_index < GNUNET_ATS_NetworkTypeCount; addr_net_index++) |
984 | { | 976 | { |
985 | if (mlp->pv.quota_index[addr_net_index] == addr_net) | 977 | if (mlp->pv.quota_index[addr_net_index] == addr_net) |
@@ -1110,22 +1102,16 @@ mlp_create_problem_add_address_information (void *cls, | |||
1110 | /* For all quality metrics, set quality of this address */ | 1102 | /* For all quality metrics, set quality of this address */ |
1111 | if (GNUNET_YES == mlp->opt_dbg_optimize_quality) | 1103 | if (GNUNET_YES == mlp->opt_dbg_optimize_quality) |
1112 | { | 1104 | { |
1113 | for (c = 0; c < mlp->pv.m_q; c++) | 1105 | mlp_create_problem_set_value (p, |
1114 | { | 1106 | p->r_q[RQ_QUALITY_METRIC_DELAY], |
1115 | prop = address->atsin[c].norm; | 1107 | mlpi->c_b, |
1116 | if ((prop < 1.0) && (prop > 2.0)) | 1108 | address->norm_delay.norm, |
1117 | { | 1109 | __LINE__); |
1118 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1110 | mlp_create_problem_set_value (p, |
1119 | "PROP == %.3f \t ", | 1111 | p->r_q[RQ_QUALITY_METRIC_DISTANCE], |
1120 | prop); | 1112 | mlpi->c_b, |
1121 | GNUNET_break (0); | 1113 | address->norm_distance.norm, |
1122 | } | 1114 | __LINE__); |
1123 | mlp_create_problem_set_value (p, | ||
1124 | p->r_q[c], | ||
1125 | mlpi->c_b, | ||
1126 | prop, | ||
1127 | __LINE__); | ||
1128 | } | ||
1129 | } | 1115 | } |
1130 | } | 1116 | } |
1131 | 1117 | ||
@@ -1183,11 +1169,14 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr | |||
1183 | { | 1169 | { |
1184 | for (c = 0; c < mlp->pv.m_q; c++) | 1170 | for (c = 0; c < mlp->pv.m_q; c++) |
1185 | { | 1171 | { |
1186 | GNUNET_asprintf (&name, "c7_q%i_%s", c, | 1172 | GNUNET_asprintf (&name, |
1187 | GNUNET_ATS_print_property_type (mlp->pv.q[c])); | 1173 | "c7_q%i_%s", c, |
1174 | print_quality_type (c)); | ||
1188 | p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0, 0.0); | 1175 | p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0, 0.0); |
1189 | GNUNET_free (name); | 1176 | GNUNET_free (name); |
1190 | mlp_create_problem_set_value (p, p->r_q[c], p->c_q[c], -1, __LINE__); | 1177 | mlp_create_problem_set_value (p, |
1178 | p->r_q[c], | ||
1179 | p->c_q[c], -1, __LINE__); | ||
1191 | } | 1180 | } |
1192 | } | 1181 | } |
1193 | } | 1182 | } |
@@ -1222,7 +1211,7 @@ mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct MLP | |||
1222 | { | 1211 | { |
1223 | for (c = 0; c < mlp->pv.m_q; c++) | 1212 | for (c = 0; c < mlp->pv.m_q; c++) |
1224 | { | 1213 | { |
1225 | GNUNET_asprintf (&name, "q_%u", mlp->pv.q[c]); | 1214 | GNUNET_asprintf (&name, "q_%u", c); |
1226 | p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]); | 1215 | p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]); |
1227 | GNUNET_free (name); | 1216 | GNUNET_free (name); |
1228 | } | 1217 | } |
@@ -1866,13 +1855,10 @@ GAS_mlp_address_add (void *solver, | |||
1866 | { | 1855 | { |
1867 | struct GAS_MLP_Handle *mlp = solver; | 1856 | struct GAS_MLP_Handle *mlp = solver; |
1868 | 1857 | ||
1869 | GNUNET_assert (NULL != solver); | ||
1870 | GNUNET_assert (NULL != address); | ||
1871 | |||
1872 | if (GNUNET_ATS_NetworkTypeCount <= network) | 1858 | if (GNUNET_ATS_NetworkTypeCount <= network) |
1873 | { | 1859 | { |
1874 | GNUNET_break (0); | 1860 | GNUNET_break (0); |
1875 | return; | 1861 | return; |
1876 | } | 1862 | } |
1877 | 1863 | ||
1878 | if (NULL == address->solver_information) | 1864 | if (NULL == address->solver_information) |
@@ -1911,36 +1897,23 @@ GAS_mlp_address_add (void *solver, | |||
1911 | * | 1897 | * |
1912 | * @param solver solver handle | 1898 | * @param solver solver handle |
1913 | * @param address the address | 1899 | * @param address the address |
1914 | * @param type the ATSI type in HBO | ||
1915 | * @param abs_value the absolute value of the property | ||
1916 | * @param rel_value the normalized value | ||
1917 | */ | 1900 | */ |
1918 | static void | 1901 | static void |
1919 | GAS_mlp_address_property_changed (void *solver, | 1902 | GAS_mlp_address_property_changed (void *solver, |
1920 | struct ATS_Address *address, | 1903 | struct ATS_Address *address) |
1921 | enum GNUNET_ATS_Property type, | ||
1922 | uint32_t abs_value, | ||
1923 | double rel_value) | ||
1924 | { | 1904 | { |
1925 | struct MLP_information *mlpi = address->solver_information; | 1905 | struct MLP_information *mlpi = address->solver_information; |
1926 | struct GAS_MLP_Handle *mlp = solver; | 1906 | struct GAS_MLP_Handle *mlp = solver; |
1927 | int c1; | ||
1928 | int type_index; | ||
1929 | |||
1930 | GNUNET_assert (NULL != solver); | ||
1931 | GNUNET_assert (NULL != address); | ||
1932 | 1907 | ||
1933 | if (NULL == mlpi) | 1908 | if (NULL == mlpi) |
1934 | { | 1909 | { |
1935 | LOG (GNUNET_ERROR_TYPE_INFO, | 1910 | LOG (GNUNET_ERROR_TYPE_INFO, |
1936 | _("Updating address property `%s' for peer `%s' %p not added before\n"), | 1911 | _("Updating address property for peer `%s' %p not added before\n"), |
1937 | GNUNET_ATS_print_property_type (type), | 1912 | GNUNET_i2s (&address->peer), |
1938 | GNUNET_i2s(&address->peer), | 1913 | address); |
1939 | address); | 1914 | GNUNET_break (0); |
1940 | GNUNET_break (0); | 1915 | return; |
1941 | return; | ||
1942 | } | 1916 | } |
1943 | |||
1944 | if (NULL == | 1917 | if (NULL == |
1945 | GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, | 1918 | GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, |
1946 | &address->peer)) | 1919 | &address->peer)) |
@@ -1948,34 +1921,26 @@ GAS_mlp_address_property_changed (void *solver, | |||
1948 | /* Peer is not requested, so no need to update problem */ | 1921 | /* Peer is not requested, so no need to update problem */ |
1949 | return; | 1922 | return; |
1950 | } | 1923 | } |
1951 | LOG (GNUNET_ERROR_TYPE_INFO, "Updating property `%s' address for peer `%s' to abs %llu rel %.3f\n", | 1924 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1952 | GNUNET_ATS_print_property_type (type), | 1925 | "Updating properties for peer `%s'\n", |
1953 | GNUNET_i2s(&address->peer), | 1926 | GNUNET_i2s(&address->peer)); |
1954 | abs_value, | ||
1955 | rel_value); | ||
1956 | 1927 | ||
1957 | if (GNUNET_YES == mlp->opt_dbg_feasibility_only) | 1928 | if (GNUNET_YES == mlp->opt_dbg_feasibility_only) |
1958 | return; | 1929 | return; |
1959 | 1930 | ||
1960 | /* Find row index */ | ||
1961 | type_index = -1; | ||
1962 | for (c1 = 0; c1 < mlp->pv.m_q; c1++) | ||
1963 | { | ||
1964 | if (type == mlp->pv.q[c1]) | ||
1965 | { | ||
1966 | type_index = c1; | ||
1967 | break; | ||
1968 | } | ||
1969 | } | ||
1970 | if (-1 == type_index) | ||
1971 | { | ||
1972 | GNUNET_break (0); | ||
1973 | return; /* quality index not found */ | ||
1974 | } | ||
1975 | |||
1976 | /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */ | 1931 | /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */ |
1977 | if (GNUNET_YES == mlp_create_problem_update_value (&mlp->p, | 1932 | if ( (GNUNET_YES == |
1978 | mlp->p.r_q[type_index], mlpi->c_b, rel_value, __LINE__)) | 1933 | mlp_create_problem_update_value (&mlp->p, |
1934 | mlp->p.r_q[RQ_QUALITY_METRIC_DELAY], | ||
1935 | mlpi->c_b, | ||
1936 | address->norm_delay.norm, | ||
1937 | __LINE__)) || | ||
1938 | (GNUNET_YES == | ||
1939 | mlp_create_problem_update_value (&mlp->p, | ||
1940 | mlp->p.r_q[RQ_QUALITY_METRIC_DISTANCE], | ||
1941 | mlpi->c_b, | ||
1942 | address->norm_distance.norm, | ||
1943 | __LINE__)) ) | ||
1979 | { | 1944 | { |
1980 | mlp->stat_mlp_prob_updated = GNUNET_YES; | 1945 | mlp->stat_mlp_prob_updated = GNUNET_YES; |
1981 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) | 1946 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) |
@@ -2037,17 +2002,14 @@ get_peer_pref_value (struct GAS_MLP_Handle *mlp, | |||
2037 | 2002 | ||
2038 | preferences = mlp->env->get_preferences (mlp->env->cls, peer); | 2003 | preferences = mlp->env->get_preferences (mlp->env->cls, peer); |
2039 | res = 0.0; | 2004 | res = 0.0; |
2040 | for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) | 2005 | for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++) |
2041 | { | 2006 | { |
2042 | if (c != GNUNET_ATS_PREFERENCE_END) | 2007 | /* fprintf (stderr, "VALUE[%u] %s %.3f \n", |
2043 | { | 2008 | * c, GNUNET_i2s (&cur->addr->peer), t[c]); */ |
2044 | /* fprintf (stderr, "VALUE[%u] %s %.3f \n", | 2009 | res += preferences[c]; |
2045 | * c, GNUNET_i2s (&cur->addr->peer), t[c]); */ | ||
2046 | res += preferences[c]; | ||
2047 | } | ||
2048 | } | 2010 | } |
2049 | 2011 | ||
2050 | res /= (GNUNET_ATS_PreferenceCount -1); | 2012 | res /= GNUNET_ATS_PREFERENCE_END; |
2051 | res += 1.0; | 2013 | res += 1.0; |
2052 | 2014 | ||
2053 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2015 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2646,34 +2608,28 @@ libgnunet_plugin_ats_mlp_init (void *cls) | |||
2646 | } | 2608 | } |
2647 | 2609 | ||
2648 | /* Get quality metric coefficients from configuration */ | 2610 | /* Get quality metric coefficients from configuration */ |
2649 | int i_delay = MLP_NaN; | 2611 | for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++) |
2650 | int i_distance = MLP_NaN; | ||
2651 | int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties; | ||
2652 | for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) | ||
2653 | { | 2612 | { |
2654 | /* initialize quality coefficients with default value 1.0 */ | 2613 | /* initialize quality coefficients with default value 1.0 */ |
2655 | mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY; | 2614 | mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY; |
2656 | |||
2657 | mlp->pv.q[c] = q[c]; | ||
2658 | if (q[c] == GNUNET_ATS_QUALITY_NET_DELAY) | ||
2659 | i_delay = c; | ||
2660 | if (q[c] == GNUNET_ATS_QUALITY_NET_DISTANCE) | ||
2661 | i_distance = c; | ||
2662 | } | 2615 | } |
2663 | 2616 | ||
2664 | if ( (i_delay != MLP_NaN) && | 2617 | |
2665 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", | 2618 | if (GNUNET_OK == |
2666 | "MLP_COEFFICIENT_QUALITY_DELAY", &tmp)) ) | 2619 | GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", |
2667 | mlp->pv.co_Q[i_delay] = (double) tmp / 100; | 2620 | "MLP_COEFFICIENT_QUALITY_DELAY", |
2621 | &tmp)) | ||
2622 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = (double) tmp / 100; | ||
2668 | else | 2623 | else |
2669 | mlp->pv.co_Q[i_delay] = MLP_DEFAULT_QUALITY; | 2624 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = MLP_DEFAULT_QUALITY; |
2670 | 2625 | ||
2671 | if ( (i_distance != MLP_NaN) && | 2626 | if (GNUNET_OK == |
2672 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", | 2627 | GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", |
2673 | "MLP_COEFFICIENT_QUALITY_DISTANCE", &tmp)) ) | 2628 | "MLP_COEFFICIENT_QUALITY_DISTANCE", |
2674 | mlp->pv.co_Q[i_distance] = (double) tmp / 100; | 2629 | &tmp)) |
2630 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = (double) tmp / 100; | ||
2675 | else | 2631 | else |
2676 | mlp->pv.co_Q[i_distance] = MLP_DEFAULT_QUALITY; | 2632 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = MLP_DEFAULT_QUALITY; |
2677 | 2633 | ||
2678 | /* Get minimum bandwidth per used address from configuration */ | 2634 | /* Get minimum bandwidth per used address from configuration */ |
2679 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", | 2635 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", |
@@ -2759,7 +2715,7 @@ libgnunet_plugin_ats_mlp_init (void *cls) | |||
2759 | /* Setting MLP Input variables */ | 2715 | /* Setting MLP Input variables */ |
2760 | mlp->pv.b_min = b_min; | 2716 | mlp->pv.b_min = b_min; |
2761 | mlp->pv.n_min = n_min; | 2717 | mlp->pv.n_min = n_min; |
2762 | mlp->pv.m_q = GNUNET_ATS_QualityPropertiesCount; | 2718 | mlp->pv.m_q = RQ_QUALITY_METRIC_COUNT; |
2763 | mlp->stat_mlp_prob_changed = GNUNET_NO; | 2719 | mlp->stat_mlp_prob_changed = GNUNET_NO; |
2764 | mlp->stat_mlp_prob_updated = GNUNET_NO; | 2720 | mlp->stat_mlp_prob_updated = GNUNET_NO; |
2765 | mlp->opt_mlp_auto_solve = GNUNET_YES; | 2721 | mlp->opt_mlp_auto_solve = GNUNET_YES; |
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index 69afa8a52..9ad00bbb3 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c | |||
@@ -25,8 +25,8 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_statistics_service.h" | 27 | #include "gnunet_statistics_service.h" |
28 | #include "gnunet_ats_plugin.h" | ||
29 | #include "gnunet_ats_service.h" | 28 | #include "gnunet_ats_service.h" |
29 | #include "gnunet_ats_plugin.h" | ||
30 | #include "gnunet-service-ats_addresses.h" | 30 | #include "gnunet-service-ats_addresses.h" |
31 | 31 | ||
32 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-proportional",__VA_ARGS__) | 32 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-proportional",__VA_ARGS__) |
@@ -308,7 +308,8 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | |||
308 | continue; | 308 | continue; |
309 | peer_relative_prefs = s->env->get_preferences (s->env->cls, | 309 | peer_relative_prefs = s->env->get_preferences (s->env->cls, |
310 | &aw->addr->peer); | 310 | &aw->addr->peer); |
311 | sum_relative_peer_prefences += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; | 311 | sum_relative_peer_prefences |
312 | += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; | ||
312 | count_addresses++; | 313 | count_addresses++; |
313 | } | 314 | } |
314 | if (count_addresses != net->active_addresses) | 315 | if (count_addresses != net->active_addresses) |
@@ -504,27 +505,6 @@ struct FindBestAddressCtx | |||
504 | 505 | ||
505 | 506 | ||
506 | /** | 507 | /** |
507 | * Find index of a ATS property type in the quality properties array. | ||
508 | * | ||
509 | * @param type ATS property type | ||
510 | * @return index in the quality array, #GNUNET_SYSERR if the type | ||
511 | * was not a quality property | ||
512 | */ | ||
513 | static int | ||
514 | find_quality_property_index (enum GNUNET_ATS_Property type) | ||
515 | { | ||
516 | enum GNUNET_ATS_Property existing_types[] = GNUNET_ATS_QualityProperties; | ||
517 | unsigned int c; | ||
518 | |||
519 | for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) | ||
520 | if (existing_types[c] == type) | ||
521 | return c; | ||
522 | GNUNET_break (0); | ||
523 | return GNUNET_SYSERR; | ||
524 | } | ||
525 | |||
526 | |||
527 | /** | ||
528 | * Find a "good" address to use for a peer by iterating over the | 508 | * Find a "good" address to use for a peer by iterating over the |
529 | * addresses for this peer. If we already have an existing address, | 509 | * addresses for this peer. If we already have an existing address, |
530 | * we stick to it. Otherwise, we pick by lowest distance and then by | 510 | * we stick to it. Otherwise, we pick by lowest distance and then by |
@@ -548,7 +528,6 @@ find_best_address_it (void *cls, | |||
548 | double best_distance; | 528 | double best_distance; |
549 | double cur_delay; | 529 | double cur_delay; |
550 | double cur_distance; | 530 | double cur_distance; |
551 | int index; | ||
552 | unsigned int con; | 531 | unsigned int con; |
553 | int bw_available; | 532 | int bw_available; |
554 | int need; | 533 | int need; |
@@ -601,12 +580,10 @@ find_best_address_it (void *cls, | |||
601 | } | 580 | } |
602 | 581 | ||
603 | /* Now compare ATS information */ | 582 | /* Now compare ATS information */ |
604 | index = find_quality_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE); | 583 | cur_distance = current->norm_distance.norm; |
605 | cur_distance = current->atsin[index].norm; | 584 | best_distance = ctx->best->norm_distance.norm; |
606 | best_distance = ctx->best->atsin[index].norm; | 585 | cur_delay = current->norm_delay.norm; |
607 | index = find_quality_property_index (GNUNET_ATS_QUALITY_NET_DELAY); | 586 | best_delay = ctx->best->norm_delay.norm; |
608 | cur_delay = current->atsin[index].norm; | ||
609 | best_delay = ctx->best->atsin[index].norm; | ||
610 | 587 | ||
611 | /* user shorter distance */ | 588 | /* user shorter distance */ |
612 | if (cur_distance < best_distance) | 589 | if (cur_distance < best_distance) |
@@ -1006,16 +983,10 @@ GAS_proportional_bulk_stop (void *solver) | |||
1006 | * | 983 | * |
1007 | * @param solver solver handle | 984 | * @param solver solver handle |
1008 | * @param address the address | 985 | * @param address the address |
1009 | * @param type the ATSI type | ||
1010 | * @param abs_value the absolute value of the property | ||
1011 | * @param rel_value the normalized value | ||
1012 | */ | 986 | */ |
1013 | static void | 987 | static void |
1014 | GAS_proportional_address_property_changed (void *solver, | 988 | GAS_proportional_address_property_changed (void *solver, |
1015 | struct ATS_Address *address, | 989 | struct ATS_Address *address) |
1016 | enum GNUNET_ATS_Property type, | ||
1017 | uint32_t abs_value, | ||
1018 | double rel_value) | ||
1019 | { | 990 | { |
1020 | struct GAS_PROPORTIONAL_Handle *s = solver; | 991 | struct GAS_PROPORTIONAL_Handle *s = solver; |
1021 | struct AddressWrapper *asi = address->solver_information; | 992 | struct AddressWrapper *asi = address->solver_information; |
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c index 78f58e609..0d8b2290c 100644 --- a/src/ats/plugin_ats_ril.c +++ b/src/ats/plugin_ats_ril.c | |||
@@ -934,29 +934,6 @@ envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
934 | return state; | 934 | return state; |
935 | } | 935 | } |
936 | 936 | ||
937 | /** | ||
938 | * Retrieves an ATS information value of an address | ||
939 | * | ||
940 | * @param address the address in question | ||
941 | * @param type the ATS information type | ||
942 | * @return the value | ||
943 | */ | ||
944 | static unsigned int | ||
945 | ril_get_atsi (struct ATS_Address *address, uint32_t type) | ||
946 | { | ||
947 | int c1; | ||
948 | GNUNET_assert(NULL != address); | ||
949 | |||
950 | if ((NULL == address->atsi) || (0 == address->atsi_count)) | ||
951 | return GNUNET_ATS_QUALITY_NET_DELAY == type ? UINT32_MAX : 1; | ||
952 | |||
953 | for (c1 = 0; c1 < address->atsi_count; c1++) | ||
954 | { | ||
955 | if (ntohl (address->atsi[c1].type) == type) | ||
956 | return ntohl (address->atsi[c1].value); | ||
957 | } | ||
958 | return GNUNET_ATS_QUALITY_NET_DELAY == type ? UINT32_MAX : 1; | ||
959 | } | ||
960 | 937 | ||
961 | /** | 938 | /** |
962 | * Returns the utility value of the connection an agent manages | 939 | * Returns the utility value of the connection an agent manages |
@@ -975,16 +952,12 @@ agent_get_utility (struct RIL_Peer_Agent *agent) | |||
975 | preferences = agent->envi->env->get_preferences (agent->envi->env->cls, | 952 | preferences = agent->envi->env->get_preferences (agent->envi->env->cls, |
976 | &agent->peer); | 953 | &agent->peer); |
977 | 954 | ||
978 | delay_atsi = (double) ril_get_atsi (agent->address_inuse, GNUNET_ATS_QUALITY_NET_DELAY); | 955 | delay_atsi = agent->address_inuse->norm_delay.norm; |
979 | delay_norm = RIL_UTILITY_DELAY_MAX*exp(-delay_atsi*0.00001); | 956 | delay_norm = RIL_UTILITY_DELAY_MAX*exp(-delay_atsi*0.00001); |
980 | 957 | ||
981 | pref_match = preferences[GNUNET_ATS_PREFERENCE_LATENCY] * delay_norm; | 958 | pref_match = preferences[GNUNET_ATS_PREFERENCE_LATENCY] * delay_norm; |
982 | pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * | 959 | pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * |
983 | sqrt((double) (agent->bw_in/RIL_MIN_BW) * (double) (agent->bw_out/RIL_MIN_BW)); | 960 | sqrt((double) (agent->bw_in/RIL_MIN_BW) * (double) (agent->bw_out/RIL_MIN_BW)); |
984 | // sqrt((double) (ril_get_atsi (agent->address_inuse, GNUNET_ATS_UTILIZATION_IN)/RIL_MIN_BW) * (double) (ril_get_atsi (agent->address_inuse, GNUNET_ATS_UTILIZATION_OUT)/RIL_MIN_BW)); | ||
985 | |||
986 | // return (double) (agent->bw_in/RIL_MIN_BW); | ||
987 | // return sqrt((double) (agent->bw_in/RIL_MIN_BW) * (double) (agent->bw_out/RIL_MIN_BW)); | ||
988 | return pref_match; | 961 | return pref_match; |
989 | } | 962 | } |
990 | 963 | ||
@@ -1799,9 +1772,9 @@ ril_network_get_utilized (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network | |||
1799 | if (net->type == type) | 1772 | if (net->type == type) |
1800 | { | 1773 | { |
1801 | if (direction_in) | 1774 | if (direction_in) |
1802 | sum += ril_get_atsi (cur->address_inuse, GNUNET_ATS_UTILIZATION_IN); | 1775 | sum += cur->address_inuse->norm_utilization_in.norm; |
1803 | else | 1776 | else |
1804 | sum += ril_get_atsi (cur->address_inuse, GNUNET_ATS_UTILIZATION_OUT); | 1777 | sum += cur->address_inuse->norm_utilization_out.norm; |
1805 | } | 1778 | } |
1806 | } | 1779 | } |
1807 | } | 1780 | } |
@@ -2373,27 +2346,16 @@ GAS_ril_address_delete (void *solver, | |||
2373 | * | 2346 | * |
2374 | * @param solver solver handle | 2347 | * @param solver solver handle |
2375 | * @param address the address | 2348 | * @param address the address |
2376 | * @param type the ATSI type | ||
2377 | * @param abs_value the absolute value of the property | ||
2378 | * @param rel_value the normalized value | ||
2379 | */ | 2349 | */ |
2380 | static void | 2350 | static void |
2381 | GAS_ril_address_property_changed (void *solver, | 2351 | GAS_ril_address_property_changed (void *solver, |
2382 | struct ATS_Address *address, | 2352 | struct ATS_Address *address) |
2383 | enum GNUNET_ATS_Property type, | ||
2384 | uint32_t abs_value, | ||
2385 | double rel_value) | ||
2386 | { | 2353 | { |
2387 | struct GAS_RIL_Handle *s = solver; | 2354 | struct GAS_RIL_Handle *s = solver; |
2388 | 2355 | ||
2389 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2356 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2390 | "API_address_property_changed() Property '%s' for peer '%s' address %s changed " | 2357 | "Properties for peer '%s' address changed\n", |
2391 | "to %.2f \n", | 2358 | GNUNET_i2s (&address->peer)); |
2392 | GNUNET_ATS_print_property_type (type), | ||
2393 | GNUNET_i2s (&address->peer), | ||
2394 | address->addr, rel_value); | ||
2395 | |||
2396 | |||
2397 | s->parameters.temperature = s->parameters.temperature_init; | 2359 | s->parameters.temperature = s->parameters.temperature_init; |
2398 | s->parameters.epsilon = s->parameters.epsilon_init; | 2360 | s->parameters.epsilon = s->parameters.epsilon_init; |
2399 | ril_step (s); | 2361 | ril_step (s); |
diff --git a/src/ats/test_ats_api_common.h b/src/ats/test_ats_api_common.h index 233af72cd..091eb59b6 100644 --- a/src/ats/test_ats_api_common.h +++ b/src/ats/test_ats_api_common.h | |||
@@ -38,8 +38,7 @@ struct Test_Address | |||
38 | void *addr; | 38 | void *addr; |
39 | size_t addr_len; | 39 | size_t addr_len; |
40 | 40 | ||
41 | struct GNUNET_ATS_Information *ats; | 41 | struct GNUNET_ATS_Properties properties; |
42 | int ats_count; | ||
43 | 42 | ||
44 | void *session; | 43 | void *session; |
45 | }; | 44 | }; |
@@ -61,13 +60,11 @@ free_test_address (struct Test_Address *dest); | |||
61 | void | 60 | void |
62 | create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen); | 61 | create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen); |
63 | 62 | ||
63 | |||
64 | int | 64 | int |
65 | compare_addresses (const struct GNUNET_HELLO_Address *address1, void *session1, | 65 | compare_addresses (const struct GNUNET_HELLO_Address *address1, void *session1, |
66 | const struct GNUNET_HELLO_Address *address2, void *session2); | 66 | const struct GNUNET_HELLO_Address *address2, void *session2); |
67 | 67 | ||
68 | int | ||
69 | compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is, | ||
70 | const struct GNUNET_ATS_Information *ats_should, uint32_t ats_count_should); | ||
71 | 68 | ||
72 | struct ATS_Address * | 69 | struct ATS_Address * |
73 | create_address (const struct GNUNET_PeerIdentity *peer, | 70 | create_address (const struct GNUNET_PeerIdentity *peer, |