aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
commit83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch)
treed0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/ats
parent28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff)
downloadgnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz
gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip
curly wars / auto-indentation
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/ats.h53
-rw-r--r--src/ats/ats_api.c160
-rw-r--r--src/ats/ats_api_peer_change_preference.c51
-rw-r--r--src/ats/ats_api_performance.c225
-rw-r--r--src/ats/ats_api_scheduling.c302
-rw-r--r--src/ats/gnunet-service-ats.c49
-rw-r--r--src/ats/gnunet-service-ats_addresses.c236
-rw-r--r--src/ats/gnunet-service-ats_addresses.h20
-rw-r--r--src/ats/gnunet-service-ats_math.h9
-rw-r--r--src/ats/gnunet-service-ats_performance.c109
-rw-r--r--src/ats/gnunet-service-ats_performance.h20
-rw-r--r--src/ats/gnunet-service-ats_reservations.c56
-rw-r--r--src/ats/gnunet-service-ats_reservations.h7
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c177
-rw-r--r--src/ats/gnunet-service-ats_scheduling.h27
-rw-r--r--src/ats/test_ats_api_bandwidth_consumption.c131
-rw-r--r--src/ats/test_ats_api_scheduling.c105
-rw-r--r--src/ats/test_ats_api_update_address.c3
18 files changed, 779 insertions, 961 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h
index 3ae6fdb65..5b9fa8696 100644
--- a/src/ats/ats.h
+++ b/src/ats/ats.h
@@ -31,13 +31,12 @@
31 31
32enum StartFlag 32enum StartFlag
33{ 33{
34 34
35 START_FLAG_SCHEDULING = 0, 35 START_FLAG_SCHEDULING = 0,
36 36
37 START_FLAG_PERFORMANCE_WITH_PIC = 1, 37 START_FLAG_PERFORMANCE_WITH_PIC = 1,
38 38
39 START_FLAG_PERFORMANCE_NO_PIC = 2 39 START_FLAG_PERFORMANCE_NO_PIC = 2
40
41}; 40};
42 41
43 42
@@ -55,7 +54,7 @@ struct ClientStartMessage
55struct RequestAddressMessage 54struct RequestAddressMessage
56{ 55{
57 struct GNUNET_MessageHeader header; 56 struct GNUNET_MessageHeader header;
58 57
59 uint32_t reserved GNUNET_PACKED; 58 uint32_t reserved GNUNET_PACKED;
60 59
61 struct GNUNET_PeerIdentity peer; 60 struct GNUNET_PeerIdentity peer;
@@ -77,10 +76,10 @@ struct AddressUpdateMessage
77 uint32_t session_id GNUNET_PACKED; 76 uint32_t session_id GNUNET_PACKED;
78 77
79 /* followed by: 78 /* followed by:
80 - struct GNUNET_ATS_Information [ats_count]; 79 * - struct GNUNET_ATS_Information [ats_count];
81 - char address[address_length] 80 * - char address[address_length]
82 - char plugin_name[plugin_name_length] (including '\0'-termination). 81 * - char plugin_name[plugin_name_length] (including '\0'-termination).
83 */ 82 */
84 83
85}; 84};
86 85
@@ -99,9 +98,9 @@ struct AddressUseMessage
99 uint32_t session_id GNUNET_PACKED; 98 uint32_t session_id GNUNET_PACKED;
100 99
101 /* followed by: 100 /* followed by:
102 - char address[address_length] 101 * - char address[address_length]
103 - char plugin_name[plugin_name_length] (including '\0'-termination). 102 * - char plugin_name[plugin_name_length] (including '\0'-termination).
104 */ 103 */
105 104
106}; 105};
107 106
@@ -121,9 +120,9 @@ struct AddressDestroyedMessage
121 uint32_t session_id GNUNET_PACKED; 120 uint32_t session_id GNUNET_PACKED;
122 121
123 /* followed by: 122 /* followed by:
124 - char address[address_length] 123 * - char address[address_length]
125 - char plugin_name[plugin_name_length] (including '\0'-termination). 124 * - char plugin_name[plugin_name_length] (including '\0'-termination).
126 */ 125 */
127 126
128}; 127};
129 128
@@ -143,14 +142,14 @@ struct AddressSuggestionMessage
143 uint32_t session_id GNUNET_PACKED; 142 uint32_t session_id GNUNET_PACKED;
144 143
145 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; 144 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
146 145
147 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; 146 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
148 147
149 /* followed by: 148 /* followed by:
150 - struct GNUNET_ATS_Information [ats_count]; 149 * - struct GNUNET_ATS_Information [ats_count];
151 - char address[address_length] 150 * - char address[address_length]
152 - char plugin_name[plugin_name_length] (including '\0'-termination). 151 * - char plugin_name[plugin_name_length] (including '\0'-termination).
153 */ 152 */
154 153
155}; 154};
156 155
@@ -168,14 +167,14 @@ struct PeerInformationMessage
168 uint16_t plugin_name_length GNUNET_PACKED; 167 uint16_t plugin_name_length GNUNET_PACKED;
169 168
170 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; 169 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
171 170
172 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; 171 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
173 172
174 /* followed by: 173 /* followed by:
175 - struct GNUNET_ATS_Information [ats_count]; 174 * - struct GNUNET_ATS_Information [ats_count];
176 - char address[address_length] 175 * - char address[address_length]
177 - char plugin_name[plugin_name_length] (including '\0'-termination). 176 * - char plugin_name[plugin_name_length] (including '\0'-termination).
178 */ 177 */
179 178
180}; 179};
181 180
@@ -222,7 +221,7 @@ struct PreferenceInformation
222 uint32_t preference_kind GNUNET_PACKED; 221 uint32_t preference_kind GNUNET_PACKED;
223 222
224 float preference_value GNUNET_PACKED; 223 float preference_value GNUNET_PACKED;
225 224
226}; 225};
227 226
228 227
@@ -234,8 +233,8 @@ struct ChangePreferenceMessage
234 233
235 struct GNUNET_PeerIdentity peer; 234 struct GNUNET_PeerIdentity peer;
236 235
237 /* followed by 'num_preferences' 236 /* followed by 'num_preferences'
238 struct PreferenceInformation values */ 237 * struct PreferenceInformation values */
239}; 238};
240 239
241 240
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c
index 61d3895d2..e25f9a8ec 100644
--- a/src/ats/ats_api.c
+++ b/src/ats/ats_api.c
@@ -138,26 +138,22 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
138 138
139 GNUNET_assert (GNUNET_SYSERR != ar->connected); 139 GNUNET_assert (GNUNET_SYSERR != ar->connected);
140 /* FIXME: ||1 because we currently NEVER get 'connected' events... */ 140 /* FIXME: ||1 because we currently NEVER get 'connected' events... */
141 if ( (GNUNET_YES == ar->connected) || 1) 141 if ((GNUNET_YES == ar->connected) || 1)
142 { 142 {
143 ar->bandwidth_in = sbc->bw_in; 143 ar->bandwidth_in = sbc->bw_in;
144 ar->bandwidth_out = sbc->bw_out; 144 ar->bandwidth_out = sbc->bw_out;
145 GNUNET_BANDWIDTH_tracker_update_quota (&ar->available_recv_window, 145 GNUNET_BANDWIDTH_tracker_update_quota (&ar->available_recv_window,
146 ar->bandwidth_in); 146 ar->bandwidth_in);
147 LOG (GNUNET_ERROR_TYPE_DEBUG, 147 LOG (GNUNET_ERROR_TYPE_DEBUG,
148 "Bandwidth assigned to peer %s is i:%u/o:%u bytes/s\n", 148 "Bandwidth assigned to peer %s is i:%u/o:%u bytes/s\n",
149 GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key), 149 GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key),
150 ntohl (ar->bandwidth_in.value__), 150 ntohl (ar->bandwidth_in.value__), ntohl (ar->bandwidth_out.value__));
151 ntohl (ar->bandwidth_out.value__));
152 if (NULL != sbc->atc->alloc_cb) 151 if (NULL != sbc->atc->alloc_cb)
153 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, 152 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
154 (const struct GNUNET_PeerIdentity *) key, 153 (const struct GNUNET_PeerIdentity *) key,
155 ar->plugin_name, ar->plugin_addr, 154 ar->plugin_name, ar->plugin_addr, ar->plugin_addr_len,
156 ar->plugin_addr_len, 155 ar->session, ar->bandwidth_out, ar->bandwidth_in,
157 ar->session, 156 NULL, 0);
158 ar->bandwidth_out,
159 ar->bandwidth_in,
160 NULL, 0);
161 } 157 }
162 else if (ntohl (ar->bandwidth_out.value__) > 0) 158 else if (ntohl (ar->bandwidth_out.value__) > 0)
163 { 159 {
@@ -166,17 +162,16 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
166 if (NULL != sbc->atc->alloc_cb) 162 if (NULL != sbc->atc->alloc_cb)
167 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, 163 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
168 (const struct GNUNET_PeerIdentity *) key, 164 (const struct GNUNET_PeerIdentity *) key,
169 ar->plugin_name, ar->plugin_addr, 165 ar->plugin_name, ar->plugin_addr, ar->plugin_addr_len,
170 ar->plugin_addr_len, ar->session, ar->bandwidth_out, 166 ar->session, ar->bandwidth_out, ar->bandwidth_in,
171 ar->bandwidth_in, NULL, 0); 167 NULL, 0);
172 } 168 }
173 else 169 else
174 LOG (GNUNET_ERROR_TYPE_DEBUG, 170 LOG (GNUNET_ERROR_TYPE_DEBUG,
175 "Not communicating bandwidth assigned to peer %s: not connected and bw is: i:%u/o:%u bytes/s\n", 171 "Not communicating bandwidth assigned to peer %s: not connected and bw is: i:%u/o:%u bytes/s\n",
176 GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key), 172 GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key),
177 ntohl (ar->bandwidth_in.value__), 173 ntohl (ar->bandwidth_in.value__), ntohl (ar->bandwidth_out.value__));
178 ntohl (ar->bandwidth_out.value__)); 174
179
180 return GNUNET_YES; 175 return GNUNET_YES;
181} 176}
182 177
@@ -205,9 +200,8 @@ update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
205 bwc.bw_out = GNUNET_BANDWIDTH_value_init (atc->total_bps_out / ac); 200 bwc.bw_out = GNUNET_BANDWIDTH_value_init (atc->total_bps_out / ac);
206 LOG (GNUNET_ERROR_TYPE_DEBUG, 201 LOG (GNUNET_ERROR_TYPE_DEBUG,
207 "Trivial implementation: bandwidth assigned to each peer is i:%u/o:%u bytes/s\n", 202 "Trivial implementation: bandwidth assigned to each peer is i:%u/o:%u bytes/s\n",
208 ntohl (bwc.bw_in.value__), 203 ntohl (bwc.bw_in.value__), ntohl (bwc.bw_out.value__));
209 ntohl (bwc.bw_out.value__)); 204 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc);
210 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc);
211} 205}
212 206
213 207
@@ -244,9 +238,8 @@ suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
244#if DEBUG_ATS 238#if DEBUG_ATS
245 LOG (GNUNET_ERROR_TYPE_DEBUG, 239 LOG (GNUNET_ERROR_TYPE_DEBUG,
246 "Suggesting address for peer `%s', starting with i:%u/o:%u bytes/s\n", 240 "Suggesting address for peer `%s', starting with i:%u/o:%u bytes/s\n",
247 GNUNET_h2s (key), 241 GNUNET_h2s (key), asc->atc->total_bps_in / 32,
248 asc->atc->total_bps_in/32, 242 asc->atc->total_bps_out / 32);
249 asc->atc->total_bps_out/32);
250#endif 243#endif
251 244
252 /* trivial strategy: pick first available address... */ 245 /* trivial strategy: pick first available address... */
@@ -285,8 +278,8 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *atc,
285 struct GNUNET_ATS_SuggestionContext *asc; 278 struct GNUNET_ATS_SuggestionContext *asc;
286 279
287#if DEBUG_ATS 280#if DEBUG_ATS
288 LOG (GNUNET_ERROR_TYPE_DEBUG, 281 LOG (GNUNET_ERROR_TYPE_DEBUG, "Looking up suggested address for peer `%s'\n",
289 "Looking up suggested address for peer `%s'\n", GNUNET_i2s (peer)); 282 GNUNET_i2s (peer));
290#endif 283#endif
291 asc = GNUNET_malloc (sizeof (struct GNUNET_ATS_SuggestionContext)); 284 asc = GNUNET_malloc (sizeof (struct GNUNET_ATS_SuggestionContext));
292 asc->cb = cb; 285 asc->cb = cb;
@@ -441,70 +434,70 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value)
441 434
442 if (0 != strcmp (arnew->plugin_name, arold->plugin_name)) 435 if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
443 return GNUNET_YES; 436 return GNUNET_YES;
444 if (! (((arnew->session == arold->session) && (arnew->session != NULL)) || 437 if (!
445 ((arold->session == NULL) && 438 (((arnew->session == arold->session) && (arnew->session != NULL)) ||
446 (arold->plugin_addr_len == arnew->plugin_addr_len) && 439 ((arold->session == NULL) &&
447 (0 == 440 (arold->plugin_addr_len == arnew->plugin_addr_len) &&
448 memcmp (arold->plugin_addr, arnew->plugin_addr, 441 (0 ==
449 arnew->plugin_addr_len))))) 442 memcmp (arold->plugin_addr, arnew->plugin_addr,
450 return GNUNET_YES; /* no match */ 443 arnew->plugin_addr_len)))))
444 return GNUNET_YES; /* no match */
451 /* records match */ 445 /* records match */
452#if DEBUG_ATS 446#if DEBUG_ATS
453 LOG (GNUNET_ERROR_TYPE_DEBUG, 447 LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating session for peer `%s' plugin `%s'\n",
454 "Updating session for peer `%s' plugin `%s'\n", GNUNET_h2s (key), 448 GNUNET_h2s (key), arold->plugin_name);
455 arold->plugin_name);
456#endif 449#endif
457 if (arnew->session != arold->session) 450 if (arnew->session != arold->session)
458 { 451 {
459 arold->session = arnew->session; 452 arold->session = arnew->session;
460 } 453 }
461 if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO)) 454 if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO))
462 { 455 {
463 arold->connected = GNUNET_YES; 456 arold->connected = GNUNET_YES;
464 } 457 }
465 458
466 /* Update existing value */ 459 /* Update existing value */
467 c_new = 0; 460 c_new = 0;
468 while (c_new < arnew->ats_count) 461 while (c_new < arnew->ats_count)
462 {
463 c_old = 0;
464 found = GNUNET_NO;
465 while (c_old < arold->ats_count)
469 { 466 {
470 c_old = 0; 467 if (arold->ats[c_old].type == arnew->ats[c_new].type)
471 found = GNUNET_NO;
472 while (c_old < arold->ats_count)
473 { 468 {
474 if (arold->ats[c_old].type == arnew->ats[c_new].type)
475 {
476#if DEBUG_ATS 469#if DEBUG_ATS
477 LOG (GNUNET_ERROR_TYPE_DEBUG, 470 LOG (GNUNET_ERROR_TYPE_DEBUG,
478 "Found type %i, old value=%i new value=%i\n", 471 "Found type %i, old value=%i new value=%i\n",
479 ntohl (arold->ats[c_old].type), ntohl (arold->ats[c_old].value), 472 ntohl (arold->ats[c_old].type), ntohl (arold->ats[c_old].value),
480 ntohl (arnew->ats[c_new].value)); 473 ntohl (arnew->ats[c_new].value));
481#endif 474#endif
482 arold->ats[c_old].value = arnew->ats[c_new].value; 475 arold->ats[c_old].value = arnew->ats[c_new].value;
483 found = GNUNET_YES; 476 found = GNUNET_YES;
484 }
485 c_old++;
486 } 477 }
487 /* Add new value */ 478 c_old++;
488 if (found == GNUNET_NO) 479 }
489 { 480 /* Add new value */
481 if (found == GNUNET_NO)
482 {
490#if DEBUG_ATS 483#if DEBUG_ATS
491 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added new type %i new value=%i\n", 484 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added new type %i new value=%i\n",
492 ntohl (arnew->ats[c_new].type), ntohl (arnew->ats[c_new].value)); 485 ntohl (arnew->ats[c_new].type), ntohl (arnew->ats[c_new].value));
493 LOG (GNUNET_ERROR_TYPE_DEBUG, "Old array size: %u\n", arold->ats_count); 486 LOG (GNUNET_ERROR_TYPE_DEBUG, "Old array size: %u\n", arold->ats_count);
494#endif 487#endif
495 GNUNET_array_grow (arold->ats, arold->ats_count, arold->ats_count + 1); 488 GNUNET_array_grow (arold->ats, arold->ats_count, arold->ats_count + 1);
496 GNUNET_assert (arold->ats_count >= 2); 489 GNUNET_assert (arold->ats_count >= 2);
497 arold->ats[arold->ats_count - 2].type = arnew->ats[c_new].type; 490 arold->ats[arold->ats_count - 2].type = arnew->ats[c_new].type;
498 arold->ats[arold->ats_count - 2].value = arnew->ats[c_new].value; 491 arold->ats[arold->ats_count - 2].value = arnew->ats[c_new].value;
499 arold->ats[arold->ats_count - 1].type = htonl (0); 492 arold->ats[arold->ats_count - 1].type = htonl (0);
500 arold->ats[arold->ats_count - 1].value = htonl (0); 493 arold->ats[arold->ats_count - 1].value = htonl (0);
501#if DEBUG_ATS 494#if DEBUG_ATS
502 LOG (GNUNET_ERROR_TYPE_DEBUG, "New array size: %i\n", arold->ats_count); 495 LOG (GNUNET_ERROR_TYPE_DEBUG, "New array size: %i\n", arold->ats_count);
503#endif 496#endif
504 }
505 c_new++;
506 } 497 }
507 498 c_new++;
499 }
500
508 update_bandwidth_assignment (usc->atc, arold); 501 update_bandwidth_assignment (usc->atc, arold);
509 return GNUNET_NO; 502 return GNUNET_NO;
510} 503}
@@ -538,9 +531,8 @@ create_allocation_record (const char *plugin_name, struct Session *session,
538 MAX_WINDOW_TIME_S); 531 MAX_WINDOW_TIME_S);
539 GNUNET_assert (ats_count > 0); 532 GNUNET_assert (ats_count > 0);
540 GNUNET_array_grow (ar->ats, ar->ats_count, ats_count); 533 GNUNET_array_grow (ar->ats, ar->ats_count, ats_count);
541 memcpy (ar->ats, ats, 534 memcpy (ar->ats, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
542 ats_count * sizeof (struct GNUNET_ATS_Information)); 535 ar->connected = GNUNET_SYSERR; /* aka: not known / no change */
543 ar->connected = GNUNET_SYSERR; /* aka: not known / no change */
544 return ar; 536 return ar;
545} 537}
546 538
@@ -594,11 +586,9 @@ GNUNET_ATS_peer_connect (struct GNUNET_ATS_SchedulingHandle *atc,
594 struct UpdateSessionContext usc; 586 struct UpdateSessionContext usc;
595 587
596#if DEBUG_ATS 588#if DEBUG_ATS
597 LOG (GNUNET_ERROR_TYPE_DEBUG, 589 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s\n", GNUNET_i2s (peer));
598 "Connected to peer %s\n",
599 GNUNET_i2s (peer));
600#endif 590#endif
601 591
602 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &disconnect_peer, 592 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &disconnect_peer,
603 atc); 593 atc);
604 ar = create_allocation_record (plugin_name, session, plugin_addr, 594 ar = create_allocation_record (plugin_name, session, plugin_addr,
@@ -632,8 +622,7 @@ GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_SchedulingHandle *atc,
632 const struct GNUNET_PeerIdentity *peer) 622 const struct GNUNET_PeerIdentity *peer)
633{ 623{
634#if DEBUG_ATS 624#if DEBUG_ATS
635 LOG (GNUNET_ERROR_TYPE_DEBUG, 625 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnected from peer %s\n",
636 "Disconnected from peer %s\n",
637 GNUNET_i2s (peer)); 626 GNUNET_i2s (peer));
638#endif 627#endif
639 (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, 628 (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
@@ -768,9 +757,8 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *atc,
768 struct UpdateSessionContext usc; 757 struct UpdateSessionContext usc;
769 758
770#if DEBUG_ATS 759#if DEBUG_ATS
771 LOG (GNUNET_ERROR_TYPE_DEBUG, 760 LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s', plugin `%s'\n",
772 "Updating address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer), 761 GNUNET_i2s (peer), plugin_name);
773 plugin_name);
774#endif 762#endif
775 ar = create_allocation_record (plugin_name, session, plugin_addr, 763 ar = create_allocation_record (plugin_name, session, plugin_addr,
776 plugin_addr_len, ats, ats_count); 764 plugin_addr_len, ats, ats_count);
@@ -783,7 +771,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *atc,
783 return; 771 return;
784 } 772 }
785#if DEBUG_ATS 773#if DEBUG_ATS
786 LOG (GNUNET_ERROR_TYPE_DEBUG, 774 LOG (GNUNET_ERROR_TYPE_DEBUG,
787 "Adding new address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer), 775 "Adding new address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer),
788 plugin_name); 776 plugin_name);
789#endif 777#endif
diff --git a/src/ats/ats_api_peer_change_preference.c b/src/ats/ats_api_peer_change_preference.c
index 322727e63..7290ebb7a 100644
--- a/src/ats/ats_api_peer_change_preference.c
+++ b/src/ats/ats_api_peer_change_preference.c
@@ -49,17 +49,16 @@ struct GNUNET_ATS_InformationRequestContext
49 GNUNET_ATS_PeerConfigurationInfoCallback info; 49 GNUNET_ATS_PeerConfigurationInfoCallback info;
50 50
51 void *info_cls; 51 void *info_cls;
52 52
53 struct GNUNET_PeerIdentity peer; 53 struct GNUNET_PeerIdentity peer;
54 54
55 GNUNET_SCHEDULER_TaskIdentifier task; 55 GNUNET_SCHEDULER_TaskIdentifier task;
56 56
57}; 57};
58 58
59 59
60static void 60static void
61exec_pcp (void *cls, 61exec_pcp (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
62 const struct GNUNET_SCHEDULER_TaskContext *tc)
63{ 62{
64 struct GNUNET_ATS_InformationRequestContext *irc = cls; 63 struct GNUNET_ATS_InformationRequestContext *irc = cls;
65 int32_t want_reserv; 64 int32_t want_reserv;
@@ -69,16 +68,13 @@ exec_pcp (void *cls,
69 68
70 rdelay = GNUNET_TIME_UNIT_ZERO; 69 rdelay = GNUNET_TIME_UNIT_ZERO;
71 want_reserv = irc->amount; 70 want_reserv = irc->amount;
72 ar = GNUNET_CONTAINER_multihashmap_get (irc->h->peers, &irc->peer.hashPubKey); 71 ar = GNUNET_CONTAINER_multihashmap_get (irc->h->peers, &irc->peer.hashPubKey);
73 if (NULL == ar) 72 if (NULL == ar)
74 { 73 {
75 /* attempt to change preference on peer that is not connected */ 74 /* attempt to change preference on peer that is not connected */
76 /* FIXME: this can happen if the 'service' didn't yet tell us about 75 /* FIXME: this can happen if the 'service' didn't yet tell us about
77 a new connection, fake it! */ 76 * a new connection, fake it! */
78 irc->info (irc->info_cls, 77 irc->info (irc->info_cls, &irc->peer, want_reserv, rdelay);
79 &irc->peer,
80 want_reserv,
81 rdelay);
82 GNUNET_free (irc); 78 GNUNET_free (irc);
83 return; 79 return;
84 } 80 }
@@ -89,21 +85,18 @@ exec_pcp (void *cls,
89 else if (want_reserv > 0) 85 else if (want_reserv > 0)
90 { 86 {
91 rdelay = 87 rdelay =
92 GNUNET_BANDWIDTH_tracker_get_delay (&ar->available_recv_window, 88 GNUNET_BANDWIDTH_tracker_get_delay (&ar->available_recv_window,
93 want_reserv); 89 want_reserv);
94 if (rdelay.rel_value == 0) 90 if (rdelay.rel_value == 0)
95 got_reserv = want_reserv; 91 got_reserv = want_reserv;
96 else 92 else
97 got_reserv = 0; /* all or nothing */ 93 got_reserv = 0; /* all or nothing */
98 } 94 }
99 else 95 else
100 got_reserv = 0; 96 got_reserv = 0;
101 GNUNET_BANDWIDTH_tracker_consume (&ar->available_recv_window, got_reserv); 97 GNUNET_BANDWIDTH_tracker_consume (&ar->available_recv_window, got_reserv);
102 98
103 irc->info (irc->info_cls, 99 irc->info (irc->info_cls, &irc->peer, got_reserv, rdelay);
104 &irc->peer,
105 got_reserv,
106 rdelay);
107 GNUNET_free (irc); 100 GNUNET_free (irc);
108} 101}
109 102
@@ -125,10 +118,10 @@ exec_pcp (void *cls,
125 */ 118 */
126struct GNUNET_ATS_InformationRequestContext * 119struct GNUNET_ATS_InformationRequestContext *
127GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h, 120GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h,
128 const struct GNUNET_PeerIdentity *peer, 121 const struct GNUNET_PeerIdentity *peer,
129 int32_t amount, uint64_t preference, 122 int32_t amount, uint64_t preference,
130 GNUNET_ATS_PeerConfigurationInfoCallback 123 GNUNET_ATS_PeerConfigurationInfoCallback
131 info, void *info_cls) 124 info, void *info_cls)
132{ 125{
133 struct GNUNET_ATS_InformationRequestContext *irc; 126 struct GNUNET_ATS_InformationRequestContext *irc;
134 127
@@ -157,8 +150,8 @@ GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h,
157 */ 150 */
158void 151void
159GNUNET_ATS_peer_change_preference_cancel (struct 152GNUNET_ATS_peer_change_preference_cancel (struct
160 GNUNET_ATS_InformationRequestContext 153 GNUNET_ATS_InformationRequestContext
161 *irc) 154 *irc)
162{ 155{
163 GNUNET_SCHEDULER_cancel (irc->task); 156 GNUNET_SCHEDULER_cancel (irc->task);
164 GNUNET_free (irc); 157 GNUNET_free (irc);
@@ -219,10 +212,10 @@ change_preference_send_continuation (void *cls, int success)
219 */ 212 */
220struct GNUNET_ATS_InformationRequestContext * 213struct GNUNET_ATS_InformationRequestContext *
221GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h, 214GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h,
222 const struct GNUNET_PeerIdentity *peer, 215 const struct GNUNET_PeerIdentity *peer,
223 int32_t amount, uint64_t preference, 216 int32_t amount, uint64_t preference,
224 GNUNET_ATS_PeerConfigurationInfoCallback 217 GNUNET_ATS_PeerConfigurationInfoCallback
225 info, void *info_cls) 218 info, void *info_cls)
226{ 219{
227 struct GNUNET_ATS_InformationRequestContext *irc; 220 struct GNUNET_ATS_InformationRequestContext *irc;
228 struct PeerRecord *pr; 221 struct PeerRecord *pr;
@@ -287,8 +280,8 @@ GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h,
287 */ 280 */
288void 281void
289GNUNET_ATS_peer_change_preference_cancel (struct 282GNUNET_ATS_peer_change_preference_cancel (struct
290 GNUNET_ATS_InformationRequestContext 283 GNUNET_ATS_InformationRequestContext
291 *irc) 284 *irc)
292{ 285{
293 struct GNUNET_ATS_SchedulingHandle *h = irc->h; 286 struct GNUNET_ATS_SchedulingHandle *h = irc->h;
294 struct PeerRecord *pr = irc->pr; 287 struct PeerRecord *pr = irc->pr;
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c
index ba124fe21..ca489e4a6 100644
--- a/src/ats/ats_api_performance.c
+++ b/src/ats/ats_api_performance.c
@@ -37,12 +37,12 @@ struct PendingMessage
37 37
38 /** 38 /**
39 * Kept in a DLL. 39 * Kept in a DLL.
40 */ 40 */
41 struct PendingMessage *next; 41 struct PendingMessage *next;
42 42
43 /** 43 /**
44 * Kept in a DLL. 44 * Kept in a DLL.
45 */ 45 */
46 struct PendingMessage *prev; 46 struct PendingMessage *prev;
47 47
48 /** 48 /**
@@ -52,7 +52,7 @@ struct PendingMessage
52 52
53 /** 53 /**
54 * Is this the 'ATS_START' message? 54 * Is this the 'ATS_START' message?
55 */ 55 */
56 int is_init; 56 int is_init;
57}; 57};
58 58
@@ -65,19 +65,19 @@ struct GNUNET_ATS_ReservationContext
65 65
66 /** 66 /**
67 * Kept in a DLL. 67 * Kept in a DLL.
68 */ 68 */
69 struct GNUNET_ATS_ReservationContext *next; 69 struct GNUNET_ATS_ReservationContext *next;
70 70
71 /** 71 /**
72 * Kept in a DLL. 72 * Kept in a DLL.
73 */ 73 */
74 struct GNUNET_ATS_ReservationContext *prev; 74 struct GNUNET_ATS_ReservationContext *prev;
75 75
76 /** 76 /**
77 * Target peer. 77 * Target peer.
78 */ 78 */
79 struct GNUNET_PeerIdentity peer; 79 struct GNUNET_PeerIdentity peer;
80 80
81 /** 81 /**
82 * Desired reservation 82 * Desired reservation
83 */ 83 */
@@ -110,7 +110,7 @@ struct GNUNET_ATS_ReservationContext
110 */ 110 */
111struct GNUNET_ATS_PerformanceHandle 111struct GNUNET_ATS_PerformanceHandle
112{ 112{
113 113
114 /** 114 /**
115 * Our configuration. 115 * Our configuration.
116 */ 116 */
@@ -120,7 +120,7 @@ struct GNUNET_ATS_PerformanceHandle
120 * Callback to invoke on performance changes. 120 * Callback to invoke on performance changes.
121 */ 121 */
122 GNUNET_ATS_PeerInformationCallback infocb; 122 GNUNET_ATS_PeerInformationCallback infocb;
123 123
124 /** 124 /**
125 * Closure for 'infocb'. 125 * Closure for 'infocb'.
126 */ 126 */
@@ -158,9 +158,9 @@ struct GNUNET_ATS_PerformanceHandle
158 158
159 /** 159 /**
160 * Task to trigger reconnect. 160 * Task to trigger reconnect.
161 */ 161 */
162 GNUNET_SCHEDULER_TaskIdentifier task; 162 GNUNET_SCHEDULER_TaskIdentifier task;
163 163
164}; 164};
165 165
166 166
@@ -180,8 +180,7 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph);
180 * @param tc scheduler context 180 * @param tc scheduler context
181 */ 181 */
182static void 182static void
183reconnect_task (void *cls, 183reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184 const struct GNUNET_SCHEDULER_TaskContext *tc)
185{ 184{
186 struct GNUNET_ATS_PerformanceHandle *ph = cls; 185 struct GNUNET_ATS_PerformanceHandle *ph = cls;
187 186
@@ -209,9 +208,7 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph);
209 * @return number of bytes copied into buf 208 * @return number of bytes copied into buf
210 */ 209 */
211static size_t 210static size_t
212transmit_message_to_ats (void *cls, 211transmit_message_to_ats (void *cls, size_t size, void *buf)
213 size_t size,
214 void *buf)
215{ 212{
216 struct GNUNET_ATS_PerformanceHandle *ph = cls; 213 struct GNUNET_ATS_PerformanceHandle *ph = cls;
217 struct PendingMessage *p; 214 struct PendingMessage *p;
@@ -221,15 +218,12 @@ transmit_message_to_ats (void *cls,
221 ph->th = NULL; 218 ph->th = NULL;
222 ret = 0; 219 ret = 0;
223 cbuf = buf; 220 cbuf = buf;
224 while ( (NULL != (p = ph->pending_head)) && 221 while ((NULL != (p = ph->pending_head)) && (p->size <= size))
225 (p->size <= size) )
226 { 222 {
227 memcpy (&cbuf[ret], &p[1], p->size); 223 memcpy (&cbuf[ret], &p[1], p->size);
228 ret += p->size; 224 ret += p->size;
229 size -= p->size; 225 size -= p->size;
230 GNUNET_CONTAINER_DLL_remove (ph->pending_head, 226 GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p);
231 ph->pending_tail,
232 p);
233 GNUNET_free (p); 227 GNUNET_free (p);
234 } 228 }
235 do_transmit (ph); 229 do_transmit (ph);
@@ -253,12 +247,12 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph)
253 if (NULL == (p = ph->pending_head)) 247 if (NULL == (p = ph->pending_head))
254 return; 248 return;
255 if (NULL == ph->client) 249 if (NULL == ph->client)
256 return; /* currently reconnecting */ 250 return; /* currently reconnecting */
257 ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client, 251 ph->th =
258 p->size, 252 GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size,
259 GNUNET_TIME_UNIT_FOREVER_REL, 253 GNUNET_TIME_UNIT_FOREVER_REL,
260 GNUNET_YES, 254 GNUNET_YES, &transmit_message_to_ats,
261 &transmit_message_to_ats, ph); 255 ph);
262} 256}
263 257
264 258
@@ -271,7 +265,7 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph)
271 */ 265 */
272static int 266static int
273process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, 267process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
274 const struct GNUNET_MessageHeader *msg) 268 const struct GNUNET_MessageHeader *msg)
275{ 269{
276 const struct PeerInformationMessage *pi; 270 const struct PeerInformationMessage *pi;
277 const struct GNUNET_ATS_Information *atsi; 271 const struct GNUNET_ATS_Information *atsi;
@@ -285,37 +279,31 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
285 { 279 {
286 GNUNET_break (0); 280 GNUNET_break (0);
287 return GNUNET_SYSERR; 281 return GNUNET_SYSERR;
288 } 282 }
289 if (ntohs (msg->size) < sizeof (struct PeerInformationMessage)) 283 if (ntohs (msg->size) < sizeof (struct PeerInformationMessage))
290 { 284 {
291 GNUNET_break (0); 285 GNUNET_break (0);
292 return GNUNET_SYSERR; 286 return GNUNET_SYSERR;
293 } 287 }
294 pi = (const struct PeerInformationMessage*) msg; 288 pi = (const struct PeerInformationMessage *) msg;
295 ats_count = ntohl (pi->ats_count); 289 ats_count = ntohl (pi->ats_count);
296 address_length = ntohs (pi->address_length); 290 address_length = ntohs (pi->address_length);
297 plugin_name_length = ntohs (pi->plugin_name_length); 291 plugin_name_length = ntohs (pi->plugin_name_length);
298 atsi = (const struct GNUNET_ATS_Information*) &pi[1]; 292 atsi = (const struct GNUNET_ATS_Information *) &pi[1];
299 address = (const char*) &atsi[ats_count]; 293 address = (const char *) &atsi[ats_count];
300 plugin_name = &address[address_length]; 294 plugin_name = &address[address_length];
301 if ( (address_length + 295 if ((address_length + plugin_name_length +
302 plugin_name_length + 296 ats_count * sizeof (struct GNUNET_ATS_Information) +
303 ats_count * sizeof (struct GNUNET_ATS_Information) + 297 sizeof (struct PeerInformationMessage) != ntohs (msg->size)) ||
304 sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || 298 (ats_count >
305 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || 299 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
306 (plugin_name[plugin_name_length - 1] != '\0') ) 300 || (plugin_name[plugin_name_length - 1] != '\0'))
307 { 301 {
308 GNUNET_break (0); 302 GNUNET_break (0);
309 return GNUNET_SYSERR; 303 return GNUNET_SYSERR;
310 } 304 }
311 ph->infocb (ph->infocb_cls, 305 ph->infocb (ph->infocb_cls, &pi->peer, plugin_name, address, address_length,
312 &pi->peer, 306 pi->bandwidth_out, pi->bandwidth_in, atsi, ats_count);
313 plugin_name,
314 address, address_length,
315 pi->bandwidth_out,
316 pi->bandwidth_in,
317 atsi,
318 ats_count);
319 return GNUNET_OK; 307 return GNUNET_OK;
320} 308}
321 309
@@ -329,7 +317,7 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
329 */ 317 */
330static int 318static int
331process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, 319process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
332 const struct GNUNET_MessageHeader *msg) 320 const struct GNUNET_MessageHeader *msg)
333{ 321{
334 const struct ReservationResultMessage *rr; 322 const struct ReservationResultMessage *rr;
335 struct GNUNET_ATS_ReservationContext *rc; 323 struct GNUNET_ATS_ReservationContext *rc;
@@ -340,28 +328,21 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
340 GNUNET_break (0); 328 GNUNET_break (0);
341 return GNUNET_SYSERR; 329 return GNUNET_SYSERR;
342 } 330 }
343 rr = (const struct ReservationResultMessage*) msg; 331 rr = (const struct ReservationResultMessage *) msg;
344 amount = ntohl (rr->amount); 332 amount = ntohl (rr->amount);
345 rc = ph->reservation_head; 333 rc = ph->reservation_head;
346 if (0 != memcmp (&rr->peer, 334 if (0 != memcmp (&rr->peer, &rc->peer, sizeof (struct GNUNET_PeerIdentity)))
347 &rc->peer,
348 sizeof (struct GNUNET_PeerIdentity)))
349 { 335 {
350 GNUNET_break (0); 336 GNUNET_break (0);
351 return GNUNET_SYSERR; 337 return GNUNET_SYSERR;
352 } 338 }
353 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, 339 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, rc);
354 ph->reservation_tail, 340 if ((amount == 0) || (rc->rcb != NULL))
355 rc);
356 if ( (amount == 0) ||
357 (rc->rcb != NULL) )
358 { 341 {
359 /* tell client if not cancelled */ 342 /* tell client if not cancelled */
360 if (rc->rcb != NULL) 343 if (rc->rcb != NULL)
361 rc->rcb (rc->rcb_cls, 344 rc->rcb (rc->rcb_cls, &rr->peer, amount,
362 &rr->peer, 345 GNUNET_TIME_relative_ntoh (rr->res_delay));
363 amount,
364 GNUNET_TIME_relative_ntoh (rr->res_delay));
365 GNUNET_free (rc); 346 GNUNET_free (rc);
366 return GNUNET_OK; 347 return GNUNET_OK;
367 } 348 }
@@ -369,7 +350,7 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
369 if (GNUNET_YES != rc->undo) 350 if (GNUNET_YES != rc->undo)
370 { 351 {
371 GNUNET_free (rc); 352 GNUNET_free (rc);
372 return GNUNET_OK; /* do not try to undo failed undos or negative amounts */ 353 return GNUNET_OK; /* do not try to undo failed undos or negative amounts */
373 } 354 }
374 GNUNET_free (rc); 355 GNUNET_free (rc);
375 (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL); 356 (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL);
@@ -385,12 +366,11 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
385 * @param msg message received, NULL on timeout or fatal error 366 * @param msg message received, NULL on timeout or fatal error
386 */ 367 */
387static void 368static void
388process_ats_message (void *cls, 369process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
389 const struct GNUNET_MessageHeader *msg)
390{ 370{
391 struct GNUNET_ATS_PerformanceHandle *ph = cls; 371 struct GNUNET_ATS_PerformanceHandle *ph = cls;
392 372
393 if (NULL == msg) 373 if (NULL == msg)
394 goto reconnect; 374 goto reconnect;
395 switch (ntohs (msg->type)) 375 switch (ntohs (msg->type))
396 { 376 {
@@ -400,22 +380,22 @@ process_ats_message (void *cls,
400 break; 380 break;
401 case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT: 381 case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT:
402 if (GNUNET_OK != process_rr_message (ph, msg)) 382 if (GNUNET_OK != process_rr_message (ph, msg))
403 goto reconnect; 383 goto reconnect;
404 break; 384 break;
405 default: 385 default:
406 GNUNET_break (0); 386 GNUNET_break (0);
407 goto reconnect; 387 goto reconnect;
408 return; 388 return;
409 } 389 }
410 GNUNET_CLIENT_receive (ph->client, 390 GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
411 &process_ats_message, ph, 391 GNUNET_TIME_UNIT_FOREVER_REL);
412 GNUNET_TIME_UNIT_FOREVER_REL);
413 return; 392 return;
414 reconnect: 393reconnect:
415 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO); 394 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
416 ph->client = NULL; 395 ph->client = NULL;
417 ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 396 ph->task =
418 &reconnect_task, ph); 397 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
398 ph);
419} 399}
420 400
421 401
@@ -433,25 +413,22 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
433 GNUNET_assert (NULL == ph->client); 413 GNUNET_assert (NULL == ph->client);
434 ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg); 414 ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg);
435 GNUNET_assert (NULL != ph->client); 415 GNUNET_assert (NULL != ph->client);
436 GNUNET_CLIENT_receive (ph->client, 416 GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
437 &process_ats_message, ph, 417 GNUNET_TIME_UNIT_FOREVER_REL);
438 GNUNET_TIME_UNIT_FOREVER_REL); 418 if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init))
439 if ( (NULL == (p = ph->pending_head)) ||
440 (GNUNET_YES != p->is_init) )
441 { 419 {
442 p = GNUNET_malloc (sizeof (struct PendingMessage) + 420 p = GNUNET_malloc (sizeof (struct PendingMessage) +
443 sizeof (struct ClientStartMessage)); 421 sizeof (struct ClientStartMessage));
444 p->size = sizeof (struct ClientStartMessage); 422 p->size = sizeof (struct ClientStartMessage);
445 p->is_init = GNUNET_YES; 423 p->is_init = GNUNET_YES;
446 init = (struct ClientStartMessage *) &p[1]; 424 init = (struct ClientStartMessage *) &p[1];
447 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); 425 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
448 init->header.size = htons (sizeof (struct ClientStartMessage)); 426 init->header.size = htons (sizeof (struct ClientStartMessage));
449 init->start_flag = htonl ((ph->infocb == NULL) 427 init->start_flag =
450 ? START_FLAG_PERFORMANCE_NO_PIC 428 htonl ((ph->infocb ==
451 : START_FLAG_PERFORMANCE_WITH_PIC); 429 NULL) ? START_FLAG_PERFORMANCE_NO_PIC :
452 GNUNET_CONTAINER_DLL_insert (ph->pending_head, 430 START_FLAG_PERFORMANCE_WITH_PIC);
453 ph->pending_tail, 431 GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p);
454 p);
455 } 432 }
456 do_transmit (ph); 433 do_transmit (ph);
457} 434}
@@ -468,8 +445,8 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
468 */ 445 */
469struct GNUNET_ATS_PerformanceHandle * 446struct GNUNET_ATS_PerformanceHandle *
470GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 447GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
471 GNUNET_ATS_PeerInformationCallback infocb, 448 GNUNET_ATS_PeerInformationCallback infocb,
472 void *infocb_cls) 449 void *infocb_cls)
473{ 450{
474 struct GNUNET_ATS_PerformanceHandle *ph; 451 struct GNUNET_ATS_PerformanceHandle *ph;
475 452
@@ -492,22 +469,19 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
492{ 469{
493 struct PendingMessage *p; 470 struct PendingMessage *p;
494 struct GNUNET_ATS_ReservationContext *rc; 471 struct GNUNET_ATS_ReservationContext *rc;
495 472
496 while (NULL != (p = ph->pending_head)) 473 while (NULL != (p = ph->pending_head))
497 { 474 {
498 GNUNET_CONTAINER_DLL_remove (ph->pending_head, 475 GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p);
499 ph->pending_tail,
500 p);
501 GNUNET_free (p); 476 GNUNET_free (p);
502 } 477 }
503 while (NULL != (rc = ph->reservation_head)) 478 while (NULL != (rc = ph->reservation_head))
504 { 479 {
505 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, 480 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail,
506 ph->reservation_tail, 481 rc);
507 rc);
508 GNUNET_break (NULL == rc->rcb); 482 GNUNET_break (NULL == rc->rcb);
509 GNUNET_free (rc); 483 GNUNET_free (rc);
510 } 484 }
511 if (GNUNET_SCHEDULER_NO_TASK != ph->task) 485 if (GNUNET_SCHEDULER_NO_TASK != ph->task)
512 { 486 {
513 GNUNET_SCHEDULER_cancel (ph->task); 487 GNUNET_SCHEDULER_cancel (ph->task);
@@ -538,10 +512,9 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
538 */ 512 */
539struct GNUNET_ATS_ReservationContext * 513struct GNUNET_ATS_ReservationContext *
540GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, 514GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
541 const struct GNUNET_PeerIdentity *peer, 515 const struct GNUNET_PeerIdentity *peer,
542 int32_t amount, 516 int32_t amount,
543 GNUNET_ATS_ReservationCallback rcb, 517 GNUNET_ATS_ReservationCallback rcb, void *rcb_cls)
544 void *rcb_cls)
545{ 518{
546 struct GNUNET_ATS_ReservationContext *rc; 519 struct GNUNET_ATS_ReservationContext *rc;
547 struct PendingMessage *p; 520 struct PendingMessage *p;
@@ -552,24 +525,21 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
552 rc->peer = *peer; 525 rc->peer = *peer;
553 rc->rcb = rcb; 526 rc->rcb = rcb;
554 rc->rcb_cls = rcb_cls; 527 rc->rcb_cls = rcb_cls;
555 if ( (rcb != NULL) && (amount > 0) ) 528 if ((rcb != NULL) && (amount > 0))
556 rc->undo = GNUNET_YES; 529 rc->undo = GNUNET_YES;
557 GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, 530 GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, ph->reservation_tail,
558 ph->reservation_tail, 531 rc);
559 rc); 532
560 533 p = GNUNET_malloc (sizeof (struct PendingMessage) +
561 p = GNUNET_malloc (sizeof (struct PendingMessage) + 534 sizeof (struct ReservationRequestMessage));
562 sizeof (struct ReservationRequestMessage));
563 p->size = sizeof (struct ReservationRequestMessage); 535 p->size = sizeof (struct ReservationRequestMessage);
564 p->is_init = GNUNET_NO; 536 p->is_init = GNUNET_NO;
565 m = (struct ReservationRequestMessage*) &p[1]; 537 m = (struct ReservationRequestMessage *) &p[1];
566 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); 538 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST);
567 m->header.size = htons (sizeof (struct ReservationRequestMessage)); 539 m->header.size = htons (sizeof (struct ReservationRequestMessage));
568 m->amount = htonl (amount); 540 m->amount = htonl (amount);
569 m->peer = *peer; 541 m->peer = *peer;
570 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, 542 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
571 ph->pending_tail,
572 p);
573 do_transmit (ph); 543 do_transmit (ph);
574 return rc; 544 return rc;
575} 545}
@@ -581,8 +551,7 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
581 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call 551 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
582 */ 552 */
583void 553void
584GNUNET_ATS_reserve_bandwidth_cancel (struct 554GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc)
585 GNUNET_ATS_ReservationContext *rc)
586{ 555{
587 rc->rcb = NULL; 556 rc->rcb = NULL;
588} 557}
@@ -591,15 +560,14 @@ GNUNET_ATS_reserve_bandwidth_cancel (struct
591/** 560/**
592 * Change preferences for the given peer. Preference changes are forgotten if peers 561 * Change preferences for the given peer. Preference changes are forgotten if peers
593 * disconnect. 562 * disconnect.
594 * 563 *
595 * @param ph performance handle 564 * @param ph performance handle
596 * @param peer identifies the peer 565 * @param peer identifies the peer
597 * @param ... 0-terminated specification of the desired changes 566 * @param ... 0-terminated specification of the desired changes
598 */ 567 */
599void 568void
600GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, 569GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
601 const struct GNUNET_PeerIdentity *peer, 570 const struct GNUNET_PeerIdentity *peer, ...)
602 ...)
603{ 571{
604 struct PendingMessage *p; 572 struct PendingMessage *p;
605 struct ChangePreferenceMessage *m; 573 struct ChangePreferenceMessage *m;
@@ -611,60 +579,63 @@ GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
611 579
612 count = 0; 580 count = 0;
613 va_start (ap, peer); 581 va_start (ap, peer);
614 while (GNUNET_ATS_PREFERENCE_END != (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) 582 while (GNUNET_ATS_PREFERENCE_END !=
583 (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
615 { 584 {
616 switch (kind) 585 switch (kind)
617 { 586 {
618 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 587 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
619 count++; 588 count++;
620 (void) va_arg (ap, double); 589 (void) va_arg (ap, double);
590
621 break; 591 break;
622 case GNUNET_ATS_PREFERENCE_LATENCY: 592 case GNUNET_ATS_PREFERENCE_LATENCY:
623 count++; 593 count++;
624 (void) va_arg (ap, double); 594 (void) va_arg (ap, double);
595
625 break; 596 break;
626 default: 597 default:
627 GNUNET_assert (0); 598 GNUNET_assert (0);
628 } 599 }
629 } 600 }
630 va_end (ap); 601 va_end (ap);
631 msize = count * sizeof (struct PreferenceInformation) + 602 msize =
632 sizeof (struct ChangePreferenceMessage); 603 count * sizeof (struct PreferenceInformation) +
633 p = GNUNET_malloc (sizeof (struct PendingMessage) + 604 sizeof (struct ChangePreferenceMessage);
634 msize); 605 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
635 p->size = msize; 606 p->size = msize;
636 p->is_init = GNUNET_NO; 607 p->is_init = GNUNET_NO;
637 m = (struct ChangePreferenceMessage*) &p[1]; 608 m = (struct ChangePreferenceMessage *) &p[1];
638 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE); 609 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE);
639 m->header.size = htons (msize); 610 m->header.size = htons (msize);
640 m->num_preferences = htonl (count); 611 m->num_preferences = htonl (count);
641 m->peer = *peer; 612 m->peer = *peer;
642 pi = (struct PreferenceInformation*) &m[1]; 613 pi = (struct PreferenceInformation *) &m[1];
643 count = 0; 614 count = 0;
644 va_start (ap, peer); 615 va_start (ap, peer);
645 while (GNUNET_ATS_PREFERENCE_END != (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) 616 while (GNUNET_ATS_PREFERENCE_END !=
617 (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
646 { 618 {
647 pi[count].preference_kind = htonl (kind); 619 pi[count].preference_kind = htonl (kind);
648 switch (kind) 620 switch (kind)
649 { 621 {
650 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 622 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
651 pi[count].preference_value = (float) va_arg (ap, double); 623 pi[count].preference_value = (float) va_arg (ap, double);
624
652 count++; 625 count++;
653 break; 626 break;
654 case GNUNET_ATS_PREFERENCE_LATENCY: 627 case GNUNET_ATS_PREFERENCE_LATENCY:
655 pi[count].preference_value = (float) va_arg (ap, double); 628 pi[count].preference_value = (float) va_arg (ap, double);
629
656 count++; 630 count++;
657 break; 631 break;
658 default: 632 default:
659 GNUNET_assert (0); 633 GNUNET_assert (0);
660 } 634 }
661 } 635 }
662 va_end (ap); 636 va_end (ap);
663 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, 637 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
664 ph->pending_tail,
665 p);
666 do_transmit (ph); 638 do_transmit (ph);
667} 639}
668 640
669/* end of ats_api_performance.c */ 641/* end of ats_api_performance.c */
670
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index b342d9657..2eeb99dad 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -37,12 +37,12 @@ struct PendingMessage
37 37
38 /** 38 /**
39 * Kept in a DLL. 39 * Kept in a DLL.
40 */ 40 */
41 struct PendingMessage *next; 41 struct PendingMessage *next;
42 42
43 /** 43 /**
44 * Kept in a DLL. 44 * Kept in a DLL.
45 */ 45 */
46 struct PendingMessage *prev; 46 struct PendingMessage *prev;
47 47
48 /** 48 /**
@@ -52,7 +52,7 @@ struct PendingMessage
52 52
53 /** 53 /**
54 * Is this the 'ATS_START' message? 54 * Is this the 'ATS_START' message?
55 */ 55 */
56 int is_init; 56 int is_init;
57}; 57};
58 58
@@ -84,7 +84,7 @@ struct SessionRecord
84 */ 84 */
85struct GNUNET_ATS_SchedulingHandle 85struct GNUNET_ATS_SchedulingHandle
86{ 86{
87 87
88 /** 88 /**
89 * Our configuration. 89 * Our configuration.
90 */ 90 */
@@ -94,7 +94,7 @@ struct GNUNET_ATS_SchedulingHandle
94 * Callback to invoke on suggestions. 94 * Callback to invoke on suggestions.
95 */ 95 */
96 GNUNET_ATS_AddressSuggestionCallback suggest_cb; 96 GNUNET_ATS_AddressSuggestionCallback suggest_cb;
97 97
98 /** 98 /**
99 * Closure for 'suggest_cb'. 99 * Closure for 'suggest_cb'.
100 */ 100 */
@@ -130,9 +130,9 @@ struct GNUNET_ATS_SchedulingHandle
130 130
131 /** 131 /**
132 * Task to trigger reconnect. 132 * Task to trigger reconnect.
133 */ 133 */
134 GNUNET_SCHEDULER_TaskIdentifier task; 134 GNUNET_SCHEDULER_TaskIdentifier task;
135 135
136 /** 136 /**
137 * Size of the session array. 137 * Size of the session array.
138 */ 138 */
@@ -161,8 +161,7 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh);
161 * @param tc scheduler context 161 * @param tc scheduler context
162 */ 162 */
163static void 163static void
164reconnect_task (void *cls, 164reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
165 const struct GNUNET_SCHEDULER_TaskContext *tc)
166{ 165{
167 struct GNUNET_ATS_SchedulingHandle *sh = cls; 166 struct GNUNET_ATS_SchedulingHandle *sh = cls;
168 167
@@ -182,8 +181,9 @@ force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
182 sh->reconnect = GNUNET_NO; 181 sh->reconnect = GNUNET_NO;
183 GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); 182 GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
184 sh->client = NULL; 183 sh->client = NULL;
185 sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 184 sh->task =
186 &reconnect_task, sh); 185 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
186 sh);
187} 187}
188 188
189 189
@@ -205,8 +205,7 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh);
205 * @param msg message received, NULL on timeout or fatal error 205 * @param msg message received, NULL on timeout or fatal error
206 */ 206 */
207static void 207static void
208process_ats_message (void *cls, 208process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg);
209 const struct GNUNET_MessageHeader *msg);
210 209
211 210
212/** 211/**
@@ -218,9 +217,7 @@ process_ats_message (void *cls,
218 * @return number of bytes copied into buf 217 * @return number of bytes copied into buf
219 */ 218 */
220static size_t 219static size_t
221transmit_message_to_ats (void *cls, 220transmit_message_to_ats (void *cls, size_t size, void *buf)
222 size_t size,
223 void *buf)
224{ 221{
225 struct GNUNET_ATS_SchedulingHandle *sh = cls; 222 struct GNUNET_ATS_SchedulingHandle *sh = cls;
226 struct PendingMessage *p; 223 struct PendingMessage *p;
@@ -228,26 +225,22 @@ transmit_message_to_ats (void *cls,
228 char *cbuf; 225 char *cbuf;
229 226
230 sh->th = NULL; 227 sh->th = NULL;
231 if ( (size == 0) || (buf == NULL)) 228 if ((size == 0) || (buf == NULL))
232 { 229 {
233 force_reconnect (sh); 230 force_reconnect (sh);
234 return 0; 231 return 0;
235 } 232 }
236 ret = 0; 233 ret = 0;
237 cbuf = buf; 234 cbuf = buf;
238 while ( (NULL != (p = sh->pending_head)) && 235 while ((NULL != (p = sh->pending_head)) && (p->size <= size))
239 (p->size <= size) )
240 { 236 {
241 memcpy (&cbuf[ret], &p[1], p->size); 237 memcpy (&cbuf[ret], &p[1], p->size);
242 ret += p->size; 238 ret += p->size;
243 size -= p->size; 239 size -= p->size;
244 GNUNET_CONTAINER_DLL_remove (sh->pending_head, 240 GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p);
245 sh->pending_tail,
246 p);
247 if (GNUNET_YES == p->is_init) 241 if (GNUNET_YES == p->is_init)
248 GNUNET_CLIENT_receive (sh->client, 242 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
249 &process_ats_message, sh, 243 GNUNET_TIME_UNIT_FOREVER_REL);
250 GNUNET_TIME_UNIT_FOREVER_REL);
251 GNUNET_free (p); 244 GNUNET_free (p);
252 } 245 }
253 do_transmit (sh); 246 do_transmit (sh);
@@ -271,12 +264,12 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh)
271 if (NULL == (p = sh->pending_head)) 264 if (NULL == (p = sh->pending_head))
272 return; 265 return;
273 if (NULL == sh->client) 266 if (NULL == sh->client)
274 return; /* currently reconnecting */ 267 return; /* currently reconnecting */
275 sh->th = GNUNET_CLIENT_notify_transmit_ready (sh->client, 268 sh->th =
276 p->size, 269 GNUNET_CLIENT_notify_transmit_ready (sh->client, p->size,
277 GNUNET_TIME_UNIT_FOREVER_REL, 270 GNUNET_TIME_UNIT_FOREVER_REL,
278 GNUNET_NO, 271 GNUNET_NO, &transmit_message_to_ats,
279 &transmit_message_to_ats, sh); 272 sh);
280} 273}
281 274
282 275
@@ -288,10 +281,9 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh)
288 * @param peer peer the session belongs to 281 * @param peer peer the session belongs to
289 * @return the session object (or NULL) 282 * @return the session object (or NULL)
290 */ 283 */
291static struct Session* 284static struct Session *
292find_session (struct GNUNET_ATS_SchedulingHandle *sh, 285find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
293 uint32_t session_id, 286 const struct GNUNET_PeerIdentity *peer)
294 const struct GNUNET_PeerIdentity *peer)
295{ 287{
296 if (session_id >= sh->session_array_size) 288 if (session_id >= sh->session_array_size)
297 { 289 {
@@ -300,9 +292,9 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh,
300 } 292 }
301 if (session_id == 0) 293 if (session_id == 0)
302 return NULL; 294 return NULL;
303 if (0 != memcmp (peer, 295 if (0 !=
304 &sh->session_array[session_id].peer, 296 memcmp (peer, &sh->session_array[session_id].peer,
305 sizeof (struct GNUNET_PeerIdentity))) 297 sizeof (struct GNUNET_PeerIdentity)))
306 { 298 {
307 GNUNET_break (0); 299 GNUNET_break (0);
308 sh->reconnect = GNUNET_YES; 300 sh->reconnect = GNUNET_YES;
@@ -321,36 +313,33 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh,
321 * @param peer peer the session belongs to 313 * @param peer peer the session belongs to
322 * @return the session id 314 * @return the session id
323 */ 315 */
324static uint32_t 316static uint32_t
325get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, 317get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session,
326 struct Session *session, 318 const struct GNUNET_PeerIdentity *peer)
327 const struct GNUNET_PeerIdentity *peer)
328{ 319{
329 unsigned int i; 320 unsigned int i;
330 unsigned int f; 321 unsigned int f;
331 322
332 if (NULL == session) 323 if (NULL == session)
333 return 0; 324 return 0;
334 f = 0; 325 f = 0;
335 for (i=1;i<sh->session_array_size;i++) 326 for (i = 1; i < sh->session_array_size; i++)
336 { 327 {
337 if (session == sh->session_array[i].session) 328 if (session == sh->session_array[i].session)
338 { 329 {
339 GNUNET_assert (0 == memcmp (peer, 330 GNUNET_assert (0 ==
340 &sh->session_array[i].peer, 331 memcmp (peer, &sh->session_array[i].peer,
341 sizeof (struct GNUNET_PeerIdentity))); 332 sizeof (struct GNUNET_PeerIdentity)));
342 return i; 333 return i;
343 } 334 }
344 if ( (f == 0) && 335 if ((f == 0) && (sh->session_array[i].slot_used == GNUNET_NO))
345 (sh->session_array[i].slot_used == GNUNET_NO) )
346 f = i; 336 f = i;
347 } 337 }
348 if (f == 0) 338 if (f == 0)
349 { 339 {
350 f = sh->session_array_size; 340 f = sh->session_array_size;
351 GNUNET_array_grow (sh->session_array, 341 GNUNET_array_grow (sh->session_array, sh->session_array_size,
352 sh->session_array_size, 342 sh->session_array_size * 2);
353 sh->session_array_size * 2);
354 } 343 }
355 GNUNET_assert (f > 0); 344 GNUNET_assert (f > 0);
356 sh->session_array[f].session = session; 345 sh->session_array[f].session = session;
@@ -369,17 +358,16 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
369 * @param peer peer the session belongs to 358 * @param peer peer the session belongs to
370 */ 359 */
371static void 360static void
372remove_session (struct GNUNET_ATS_SchedulingHandle *sh, 361remove_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
373 uint32_t session_id, 362 const struct GNUNET_PeerIdentity *peer)
374 const struct GNUNET_PeerIdentity *peer)
375{ 363{
376 if (0 == session_id) 364 if (0 == session_id)
377 return; 365 return;
378 GNUNET_assert (session_id < sh->session_array_size); 366 GNUNET_assert (session_id < sh->session_array_size);
379 GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used); 367 GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used);
380 GNUNET_assert (0 == memcmp (peer, 368 GNUNET_assert (0 ==
381 &sh->session_array[session_id].peer, 369 memcmp (peer, &sh->session_array[session_id].peer,
382 sizeof (struct GNUNET_PeerIdentity))); 370 sizeof (struct GNUNET_PeerIdentity)));
383 sh->session_array[session_id].session = NULL; 371 sh->session_array[session_id].session = NULL;
384} 372}
385 373
@@ -393,9 +381,8 @@ remove_session (struct GNUNET_ATS_SchedulingHandle *sh,
393 * @param peer peer the session belongs to 381 * @param peer peer the session belongs to
394 */ 382 */
395static void 383static void
396release_session (struct GNUNET_ATS_SchedulingHandle *sh, 384release_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
397 uint32_t session_id, 385 const struct GNUNET_PeerIdentity *peer)
398 const struct GNUNET_PeerIdentity *peer)
399{ 386{
400 if (session_id >= sh->session_array_size) 387 if (session_id >= sh->session_array_size)
401 { 388 {
@@ -403,28 +390,25 @@ release_session (struct GNUNET_ATS_SchedulingHandle *sh,
403 sh->reconnect = GNUNET_YES; 390 sh->reconnect = GNUNET_YES;
404 return; 391 return;
405 } 392 }
406 if (0 != memcmp (peer, 393 if (0 !=
407 &sh->session_array[session_id].peer, 394 memcmp (peer, &sh->session_array[session_id].peer,
408 sizeof (struct GNUNET_PeerIdentity))) 395 sizeof (struct GNUNET_PeerIdentity)))
409 { 396 {
410 GNUNET_break (0); 397 GNUNET_break (0);
411 sh->reconnect = GNUNET_YES; 398 sh->reconnect = GNUNET_YES;
412 return; 399 return;
413 } 400 }
414 sh->session_array[session_id].slot_used = GNUNET_NO; 401 sh->session_array[session_id].slot_used = GNUNET_NO;
415 memset (&sh->session_array[session_id].peer, 402 memset (&sh->session_array[session_id].peer, 0,
416 0, 403 sizeof (struct GNUNET_PeerIdentity));
417 sizeof (struct GNUNET_PeerIdentity));
418} 404}
419 405
420 406
421static void 407static void
422process_release_message (struct GNUNET_ATS_SchedulingHandle *sh, 408process_release_message (struct GNUNET_ATS_SchedulingHandle *sh,
423 const struct SessionReleaseMessage *srm) 409 const struct SessionReleaseMessage *srm)
424{ 410{
425 release_session (sh, 411 release_session (sh, ntohl (srm->session_id), &srm->peer);
426 ntohl (srm->session_id),
427 &srm->peer);
428} 412}
429 413
430 414
@@ -436,8 +420,7 @@ process_release_message (struct GNUNET_ATS_SchedulingHandle *sh,
436 * @param msg message received, NULL on timeout or fatal error 420 * @param msg message received, NULL on timeout or fatal error
437 */ 421 */
438static void 422static void
439process_ats_message (void *cls, 423process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
440 const struct GNUNET_MessageHeader *msg)
441{ 424{
442 struct GNUNET_ATS_SchedulingHandle *sh = cls; 425 struct GNUNET_ATS_SchedulingHandle *sh = cls;
443 const struct AddressSuggestionMessage *m; 426 const struct AddressSuggestionMessage *m;
@@ -448,60 +431,52 @@ process_ats_message (void *cls,
448 uint16_t plugin_name_length; 431 uint16_t plugin_name_length;
449 uint32_t ats_count; 432 uint32_t ats_count;
450 433
451 if (NULL == msg) 434 if (NULL == msg)
452 { 435 {
453 force_reconnect (sh); 436 force_reconnect (sh);
454 return; 437 return;
455 } 438 }
456 if ( (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) && 439 if ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) &&
457 (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)) ) 440 (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)))
458 { 441 {
459 process_release_message (sh, 442 process_release_message (sh, (const struct SessionReleaseMessage *) msg);
460 (const struct SessionReleaseMessage*) msg); 443 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
461 GNUNET_CLIENT_receive (sh->client, 444 GNUNET_TIME_UNIT_FOREVER_REL);
462 &process_ats_message, sh,
463 GNUNET_TIME_UNIT_FOREVER_REL);
464 if (GNUNET_YES == sh->reconnect) 445 if (GNUNET_YES == sh->reconnect)
465 force_reconnect (sh); 446 force_reconnect (sh);
466 return; 447 return;
467 } 448 }
468 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) || 449 if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) ||
469 (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) ) 450 (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)))
470 { 451 {
471 GNUNET_break (0); 452 GNUNET_break (0);
472 force_reconnect (sh); 453 force_reconnect (sh);
473 return; 454 return;
474 } 455 }
475 m = (const struct AddressSuggestionMessage*) msg; 456 m = (const struct AddressSuggestionMessage *) msg;
476 ats_count = ntohl (m->ats_count); 457 ats_count = ntohl (m->ats_count);
477 address_length = ntohs (m->address_length); 458 address_length = ntohs (m->address_length);
478 atsi = (const struct GNUNET_ATS_Information*) &m[1]; 459 atsi = (const struct GNUNET_ATS_Information *) &m[1];
479 address = (const char*) &atsi[ats_count]; 460 address = (const char *) &atsi[ats_count];
480 plugin_name = &address[address_length]; 461 plugin_name = &address[address_length];
481 plugin_name_length = ntohs (m->plugin_name_length); 462 plugin_name_length = ntohs (m->plugin_name_length);
482 if ( (address_length + 463 if ((address_length + plugin_name_length +
483 plugin_name_length + 464 ats_count * sizeof (struct GNUNET_ATS_Information) +
484 ats_count * sizeof (struct GNUNET_ATS_Information) + 465 sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) ||
485 sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) || 466 (ats_count >
486 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || 467 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
487 (plugin_name[plugin_name_length - 1] != '\0') ) 468 || (plugin_name[plugin_name_length - 1] != '\0'))
488 { 469 {
489 GNUNET_break (0); 470 GNUNET_break (0);
490 force_reconnect (sh); 471 force_reconnect (sh);
491 return; 472 return;
492 } 473 }
493 sh->suggest_cb (sh->suggest_cb_cls, 474 sh->suggest_cb (sh->suggest_cb_cls, &m->peer, plugin_name, address,
494 &m->peer, 475 address_length, find_session (sh, ntohl (m->session_id),
495 plugin_name, 476 &m->peer), m->bandwidth_out,
496 address, address_length, 477 m->bandwidth_in, atsi, ats_count);
497 find_session (sh, ntohl (m->session_id), &m->peer), 478 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
498 m->bandwidth_out, 479 GNUNET_TIME_UNIT_FOREVER_REL);
499 m->bandwidth_in,
500 atsi,
501 ats_count);
502 GNUNET_CLIENT_receive (sh->client,
503 &process_ats_message, sh,
504 GNUNET_TIME_UNIT_FOREVER_REL);
505 if (GNUNET_YES == sh->reconnect) 480 if (GNUNET_YES == sh->reconnect)
506 force_reconnect (sh); 481 force_reconnect (sh);
507} 482}
@@ -521,20 +496,17 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
521 GNUNET_assert (NULL == sh->client); 496 GNUNET_assert (NULL == sh->client);
522 sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg); 497 sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg);
523 GNUNET_assert (NULL != sh->client); 498 GNUNET_assert (NULL != sh->client);
524 if ( (NULL == (p = sh->pending_head)) || 499 if ((NULL == (p = sh->pending_head)) || (GNUNET_YES != p->is_init))
525 (GNUNET_YES != p->is_init) )
526 { 500 {
527 p = GNUNET_malloc (sizeof (struct PendingMessage) + 501 p = GNUNET_malloc (sizeof (struct PendingMessage) +
528 sizeof (struct ClientStartMessage)); 502 sizeof (struct ClientStartMessage));
529 p->size = sizeof (struct ClientStartMessage); 503 p->size = sizeof (struct ClientStartMessage);
530 p->is_init = GNUNET_YES; 504 p->is_init = GNUNET_YES;
531 init = (struct ClientStartMessage *) &p[1]; 505 init = (struct ClientStartMessage *) &p[1];
532 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); 506 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
533 init->header.size = htons (sizeof (struct ClientStartMessage)); 507 init->header.size = htons (sizeof (struct ClientStartMessage));
534 init->start_flag = htonl (START_FLAG_SCHEDULING); 508 init->start_flag = htonl (START_FLAG_SCHEDULING);
535 GNUNET_CONTAINER_DLL_insert (sh->pending_head, 509 GNUNET_CONTAINER_DLL_insert (sh->pending_head, sh->pending_tail, p);
536 sh->pending_tail,
537 p);
538 } 510 }
539 do_transmit (sh); 511 do_transmit (sh);
540} 512}
@@ -550,8 +522,8 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
550 */ 522 */
551struct GNUNET_ATS_SchedulingHandle * 523struct GNUNET_ATS_SchedulingHandle *
552GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 524GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
553 GNUNET_ATS_AddressSuggestionCallback suggest_cb, 525 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
554 void *suggest_cb_cls) 526 void *suggest_cb_cls)
555{ 527{
556 struct GNUNET_ATS_SchedulingHandle *sh; 528 struct GNUNET_ATS_SchedulingHandle *sh;
557 529
@@ -559,9 +531,7 @@ GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
559 sh->cfg = cfg; 531 sh->cfg = cfg;
560 sh->suggest_cb = suggest_cb; 532 sh->suggest_cb = suggest_cb;
561 sh->suggest_cb_cls = suggest_cb_cls; 533 sh->suggest_cb_cls = suggest_cb_cls;
562 GNUNET_array_grow (sh->session_array, 534 GNUNET_array_grow (sh->session_array, sh->session_array_size, 4);
563 sh->session_array_size,
564 4);
565 reconnect (sh); 535 reconnect (sh);
566 return sh; 536 return sh;
567} 537}
@@ -579,9 +549,7 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
579 549
580 while (NULL != (p = sh->pending_head)) 550 while (NULL != (p = sh->pending_head))
581 { 551 {
582 GNUNET_CONTAINER_DLL_remove (sh->pending_head, 552 GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p);
583 sh->pending_tail,
584 p);
585 GNUNET_free (p); 553 GNUNET_free (p);
586 } 554 }
587 if (NULL != sh->client) 555 if (NULL != sh->client)
@@ -594,9 +562,7 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
594 GNUNET_SCHEDULER_cancel (sh->task); 562 GNUNET_SCHEDULER_cancel (sh->task);
595 sh->task = GNUNET_SCHEDULER_NO_TASK; 563 sh->task = GNUNET_SCHEDULER_NO_TASK;
596 } 564 }
597 GNUNET_array_grow (sh->session_array, 565 GNUNET_array_grow (sh->session_array, sh->session_array_size, 0);
598 sh->session_array_size,
599 0);
600 GNUNET_free (sh); 566 GNUNET_free (sh);
601} 567}
602 568
@@ -616,17 +582,15 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
616 struct RequestAddressMessage *m; 582 struct RequestAddressMessage *m;
617 583
618 p = GNUNET_malloc (sizeof (struct PendingMessage) + 584 p = GNUNET_malloc (sizeof (struct PendingMessage) +
619 sizeof (struct RequestAddressMessage)); 585 sizeof (struct RequestAddressMessage));
620 p->size = sizeof (struct RequestAddressMessage); 586 p->size = sizeof (struct RequestAddressMessage);
621 p->is_init = GNUNET_NO; 587 p->is_init = GNUNET_NO;
622 m = (struct RequestAddressMessage*) &p[1]; 588 m = (struct RequestAddressMessage *) &p[1];
623 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); 589 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS);
624 m->header.size = htons (sizeof (struct RequestAddressMessage)); 590 m->header.size = htons (sizeof (struct RequestAddressMessage));
625 m->reserved = htonl (0); 591 m->reserved = htonl (0);
626 m->peer = *peer; 592 m->peer = *peer;
627 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 593 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
628 sh->pending_tail,
629 p);
630 do_transmit (sh); 594 do_transmit (sh);
631} 595}
632 596
@@ -651,9 +615,8 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
651void 615void
652GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, 616GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
653 const struct GNUNET_PeerIdentity *peer, 617 const struct GNUNET_PeerIdentity *peer,
654 const char *plugin_name, 618 const char *plugin_name, const void *plugin_addr,
655 const void *plugin_addr, size_t plugin_addr_len, 619 size_t plugin_addr_len, struct Session *session,
656 struct Session *session,
657 const struct GNUNET_ATS_Information *ats, 620 const struct GNUNET_ATS_Information *ats,
658 uint32_t ats_count) 621 uint32_t ats_count)
659{ 622{
@@ -664,21 +627,23 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
664 size_t namelen; 627 size_t namelen;
665 size_t msize; 628 size_t msize;
666 629
667 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; 630 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
668 msize = sizeof (struct AddressUpdateMessage) + plugin_addr_len + 631 msize =
669 ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; 632 sizeof (struct AddressUpdateMessage) + plugin_addr_len +
670 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 633 ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
671 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 634 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
672 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 635 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
673 (ats_count >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) ) 636 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
637 (ats_count >=
638 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)))
674 { 639 {
675 GNUNET_break (0); 640 GNUNET_break (0);
676 return; 641 return;
677 } 642 }
678 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 643 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
679 p->size = msize; 644 p->size = msize;
680 p->is_init = GNUNET_NO; 645 p->is_init = GNUNET_NO;
681 m = (struct AddressUpdateMessage*) &p[1]; 646 m = (struct AddressUpdateMessage *) &p[1];
682 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); 647 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
683 m->header.size = htons (msize); 648 m->header.size = htons (msize);
684 m->ats_count = htonl (ats_count); 649 m->ats_count = htonl (ats_count);
@@ -686,14 +651,12 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
686 m->address_length = htons (plugin_addr_len); 651 m->address_length = htons (plugin_addr_len);
687 m->plugin_name_length = htons (namelen); 652 m->plugin_name_length = htons (namelen);
688 m->session_id = htonl (get_session_id (sh, session, peer)); 653 m->session_id = htonl (get_session_id (sh, session, peer));
689 am = (struct GNUNET_ATS_Information*) &m[1]; 654 am = (struct GNUNET_ATS_Information *) &m[1];
690 memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); 655 memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
691 pm = (char *) &am[ats_count]; 656 pm = (char *) &am[ats_count];
692 memcpy (pm, plugin_addr, plugin_addr_len); 657 memcpy (pm, plugin_addr, plugin_addr_len);
693 memcpy (&pm[plugin_addr_len], plugin_name, namelen); 658 memcpy (&pm[plugin_addr_len], plugin_name, namelen);
694 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 659 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
695 sh->pending_tail,
696 p);
697 do_transmit (sh); 660 do_transmit (sh);
698} 661}
699 662
@@ -712,12 +675,10 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
712 */ 675 */
713void 676void
714GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, 677GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
715 const struct GNUNET_PeerIdentity *peer, 678 const struct GNUNET_PeerIdentity *peer,
716 const char *plugin_name, 679 const char *plugin_name, const void *plugin_addr,
717 const void *plugin_addr, 680 size_t plugin_addr_len, struct Session *session,
718 size_t plugin_addr_len, 681 int in_use)
719 struct Session *session,
720 int in_use)
721{ 682{
722 struct PendingMessage *p; 683 struct PendingMessage *p;
723 struct AddressUseMessage *m; 684 struct AddressUseMessage *m;
@@ -727,30 +688,28 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
727 688
728 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; 689 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
729 msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen; 690 msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen;
730 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 691 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
731 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 692 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
732 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ) 693 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
733 { 694 {
734 GNUNET_break (0); 695 GNUNET_break (0);
735 return; 696 return;
736 } 697 }
737 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 698 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
738 p->size = msize; 699 p->size = msize;
739 p->is_init = GNUNET_NO; 700 p->is_init = GNUNET_NO;
740 m = (struct AddressUseMessage*) &p[1]; 701 m = (struct AddressUseMessage *) &p[1];
741 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE); 702 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE);
742 m->header.size = htons (msize); 703 m->header.size = htons (msize);
743 m->peer = *peer; 704 m->peer = *peer;
744 m->in_use = htons(in_use); 705 m->in_use = htons (in_use);
745 m->address_length = htons (plugin_addr_len); 706 m->address_length = htons (plugin_addr_len);
746 m->plugin_name_length = htons (namelen); 707 m->plugin_name_length = htons (namelen);
747 m->session_id = htonl (get_session_id (sh, session, peer)); 708 m->session_id = htonl (get_session_id (sh, session, peer));
748 pm = (char *) &m[1]; 709 pm = (char *) &m[1];
749 memcpy (pm, plugin_addr, plugin_addr_len); 710 memcpy (pm, plugin_addr, plugin_addr_len);
750 memcpy (&pm[plugin_addr_len], plugin_name, namelen); 711 memcpy (&pm[plugin_addr_len], plugin_name, namelen);
751 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 712 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
752 sh->pending_tail,
753 p);
754 713
755 do_transmit (sh); 714 do_transmit (sh);
756} 715}
@@ -768,10 +727,8 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
768void 727void
769GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, 728GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
770 const struct GNUNET_PeerIdentity *peer, 729 const struct GNUNET_PeerIdentity *peer,
771 const char *plugin_name, 730 const char *plugin_name, const void *plugin_addr,
772 const void *plugin_addr, 731 size_t plugin_addr_len, struct Session *session)
773 size_t plugin_addr_len,
774 struct Session *session)
775{ 732{
776 struct PendingMessage *p; 733 struct PendingMessage *p;
777 struct AddressDestroyedMessage *m; 734 struct AddressDestroyedMessage *m;
@@ -780,20 +737,19 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
780 size_t msize; 737 size_t msize;
781 uint32_t session_id; 738 uint32_t session_id;
782 739
783 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; 740 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
784 msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + 741 msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + namelen;
785 namelen; 742 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
786 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 743 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
787 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 744 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
788 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) )
789 { 745 {
790 GNUNET_break (0); 746 GNUNET_break (0);
791 return; 747 return;
792 } 748 }
793 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 749 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
794 p->size = msize; 750 p->size = msize;
795 p->is_init = GNUNET_NO; 751 p->is_init = GNUNET_NO;
796 m = (struct AddressDestroyedMessage*) &p[1]; 752 m = (struct AddressDestroyedMessage *) &p[1];
797 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); 753 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
798 m->header.size = htons (msize); 754 m->header.size = htons (msize);
799 m->reserved = htonl (0); 755 m->reserved = htonl (0);
@@ -804,9 +760,7 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
804 pm = (char *) &m[1]; 760 pm = (char *) &m[1];
805 memcpy (pm, plugin_addr, plugin_addr_len); 761 memcpy (pm, plugin_addr, plugin_addr_len);
806 memcpy (&pm[plugin_addr_len], plugin_name, namelen); 762 memcpy (&pm[plugin_addr_len], plugin_name, namelen);
807 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 763 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
808 sh->pending_tail,
809 p);
810 do_transmit (sh); 764 do_transmit (sh);
811 remove_session (sh, session_id, peer); 765 remove_session (sh, session_id, peer);
812} 766}
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c
index 563550ece..ec374aef8 100644
--- a/src/ats/gnunet-service-ats.c
+++ b/src/ats/gnunet-service-ats.c
@@ -48,14 +48,13 @@ struct GNUNET_STATISTICS_Handle *GSA_stats;
48 */ 48 */
49static void 49static void
50handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, 50handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client,
51 const struct GNUNET_MessageHeader *message) 51 const struct GNUNET_MessageHeader *message)
52{ 52{
53 const struct ClientStartMessage * msg = (const struct ClientStartMessage *) message; 53 const struct ClientStartMessage *msg =
54 (const struct ClientStartMessage *) message;
54 enum StartFlag flag; 55 enum StartFlag flag;
55 56
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 57 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ATS_START");
57 "Received `%s' message\n",
58 "ATS_START");
59 flag = ntohl (msg->start_flag); 58 flag = ntohl (msg->start_flag);
60 switch (flag) 59 switch (flag)
61 { 60 {
@@ -77,7 +76,7 @@ handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client,
77 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 76 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
78 return; 77 return;
79 } 78 }
80 GNUNET_SERVER_receive_done (client, GNUNET_OK); 79 GNUNET_SERVER_receive_done (client, GNUNET_OK);
81} 80}
82 81
83 82
@@ -131,20 +130,22 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
131 const struct GNUNET_CONFIGURATION_Handle *cfg) 130 const struct GNUNET_CONFIGURATION_Handle *cfg)
132{ 131{
133 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 132 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
134 { &handle_ats_start, NULL, 133 {&handle_ats_start, NULL,
135 GNUNET_MESSAGE_TYPE_ATS_START, sizeof (struct ClientStartMessage)}, 134 GNUNET_MESSAGE_TYPE_ATS_START, sizeof (struct ClientStartMessage)},
136 { &GAS_handle_request_address, NULL, 135 {&GAS_handle_request_address, NULL,
137 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, sizeof (struct RequestAddressMessage)}, 136 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS,
138 { &GAS_handle_address_update, NULL, 137 sizeof (struct RequestAddressMessage)},
139 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0}, 138 {&GAS_handle_address_update, NULL,
140 { &GAS_handle_address_in_use, NULL, 139 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0},
141 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0}, 140 {&GAS_handle_address_in_use, NULL,
142 { &GAS_handle_address_destroyed, NULL, 141 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0},
143 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0}, 142 {&GAS_handle_address_destroyed, NULL,
144 { &GAS_handle_reservation_request, NULL, 143 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0},
145 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, sizeof (struct ReservationRequestMessage)}, 144 {&GAS_handle_reservation_request, NULL,
146 { &GAS_handle_preference_change, NULL, 145 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST,
147 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, 146 sizeof (struct ReservationRequestMessage)},
147 {&GAS_handle_preference_change, NULL,
148 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0},
148 {NULL, NULL, 0, 0} 149 {NULL, NULL, 0, 0}
149 }; 150 };
150 GSA_stats = GNUNET_STATISTICS_create ("ats", cfg); 151 GSA_stats = GNUNET_STATISTICS_create ("ats", cfg);
@@ -152,9 +153,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
152 GAS_performance_init (server); 153 GAS_performance_init (server);
153 GAS_scheduling_init (server); 154 GAS_scheduling_init (server);
154 GAS_addresses_init (cfg); 155 GAS_addresses_init (cfg);
155 GNUNET_SERVER_disconnect_notify (server, 156 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_handler, NULL);
156 &client_disconnect_handler,
157 NULL);
158 GNUNET_SERVER_add_handlers (server, handlers); 157 GNUNET_SERVER_add_handlers (server, handlers);
159 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, 158 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
160 NULL); 159 NULL);
@@ -172,8 +171,8 @@ int
172main (int argc, char *const *argv) 171main (int argc, char *const *argv)
173{ 172{
174 return (GNUNET_OK == 173 return (GNUNET_OK ==
175 GNUNET_SERVICE_run (argc, argv, "ats", 174 GNUNET_SERVICE_run (argc, argv, "ats", GNUNET_SERVICE_OPTION_NONE,
176 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; 175 &run, NULL)) ? 0 : 1;
177} 176}
178 177
179/* end of gnunet-service-ats.c */ 178/* end of gnunet-service-ats.c */
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 99dc0e17a..22304aa6d 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -42,11 +42,11 @@ struct ATS_Address
42 42
43 uint32_t ats_count; 43 uint32_t ats_count;
44 44
45 const void * addr; 45 const void *addr;
46 46
47 char * plugin; 47 char *plugin;
48 48
49 struct GNUNET_ATS_Information * ats; 49 struct GNUNET_ATS_Information *ats;
50 50
51 struct GNUNET_TIME_Relative atsp_latency; 51 struct GNUNET_TIME_Relative atsp_latency;
52 52
@@ -74,7 +74,7 @@ struct ATS_Address
74}; 74};
75 75
76 76
77static struct GNUNET_CONTAINER_MultiHashMap * addresses; 77static struct GNUNET_CONTAINER_MultiHashMap *addresses;
78 78
79static unsigned long long total_quota_in; 79static unsigned long long total_quota_in;
80 80
@@ -92,10 +92,8 @@ static unsigned int active_addr_count;
92 * @param value the 'struct ATS_Address' 92 * @param value the 'struct ATS_Address'
93 * @return GNUNET_OK (continue to iterate) 93 * @return GNUNET_OK (continue to iterate)
94 */ 94 */
95static int 95static int
96update_bw_it (void *cls, 96update_bw_it (void *cls, const GNUNET_HashCode * key, void *value)
97 const GNUNET_HashCode * key,
98 void *value)
99{ 97{
100 struct ATS_Address *aa = value; 98 struct ATS_Address *aa = value;
101 99
@@ -104,24 +102,18 @@ update_bw_it (void *cls,
104 GNUNET_assert (active_addr_count > 0); 102 GNUNET_assert (active_addr_count > 0);
105 aa->assigned_bw_in.value__ = htonl (total_quota_in / active_addr_count); 103 aa->assigned_bw_in.value__ = htonl (total_quota_in / active_addr_count);
106 aa->assigned_bw_out.value__ = htonl (total_quota_out / active_addr_count); 104 aa->assigned_bw_out.value__ = htonl (total_quota_out / active_addr_count);
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n",
108 "New bandwidth for peer %s is %u/%u\n", 106 GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__),
109 GNUNET_i2s (&aa->peer), 107 ntohl (aa->assigned_bw_out.value__));
110 ntohl (aa->assigned_bw_in.value__), 108 GAS_scheduling_transmit_address_suggestion (&aa->peer, aa->plugin, aa->addr,
111 ntohl (aa->assigned_bw_out.value__)); 109 aa->addr_len, aa->session_id,
112 GAS_scheduling_transmit_address_suggestion (&aa->peer, 110 aa->ats, aa->ats_count,
113 aa->plugin, 111 aa->assigned_bw_out,
114 aa->addr, aa->addr_len, 112 aa->assigned_bw_in);
115 aa->session_id, 113 GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in);
116 aa->ats, aa->ats_count, 114 GAS_performance_notify_clients (&aa->peer, aa->plugin, aa->addr, aa->addr_len,
117 aa->assigned_bw_out, aa->assigned_bw_in); 115 aa->ats, aa->ats_count, aa->assigned_bw_out,
118 GAS_reservations_set_bandwidth (&aa->peer, 116 aa->assigned_bw_in);
119 aa->assigned_bw_in);
120 GAS_performance_notify_clients (&aa->peer,
121 aa->plugin,
122 aa->addr, aa->addr_len,
123 aa->ats, aa->ats_count,
124 aa->assigned_bw_out, aa->assigned_bw_in);
125 return GNUNET_OK; 117 return GNUNET_OK;
126} 118}
127 119
@@ -134,18 +126,12 @@ static void
134recalculate_assigned_bw () 126recalculate_assigned_bw ()
135{ 127{
136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
137 "Recalculating bandwidth for all active connections\n"); 129 "Recalculating bandwidth for all active connections\n");
138 GNUNET_STATISTICS_update (GSA_stats, 130 GNUNET_STATISTICS_update (GSA_stats, "# bandwidth recalculations performed",
139 "# bandwidth recalculations performed", 131 1, GNUNET_NO);
140 1, 132 GNUNET_STATISTICS_set (GSA_stats, "# active addresses", active_addr_count,
141 GNUNET_NO); 133 GNUNET_NO);
142 GNUNET_STATISTICS_set (GSA_stats, 134 GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_it, NULL);
143 "# active addresses",
144 active_addr_count,
145 GNUNET_NO);
146 GNUNET_CONTAINER_multihashmap_iterate (addresses,
147 &update_bw_it,
148 NULL);
149} 135}
150 136
151 137
@@ -161,10 +147,10 @@ destroy_address (struct ATS_Address *addr)
161 int ret; 147 int ret;
162 148
163 ret = GNUNET_NO; 149 ret = GNUNET_NO;
164 GNUNET_assert (GNUNET_YES == 150 GNUNET_assert (GNUNET_YES ==
165 GNUNET_CONTAINER_multihashmap_remove(addresses, 151 GNUNET_CONTAINER_multihashmap_remove (addresses,
166 &addr->peer.hashPubKey, 152 &addr->peer.hashPubKey,
167 addr)); 153 addr));
168 if (GNUNET_YES == addr->active) 154 if (GNUNET_YES == addr->active)
169 { 155 {
170 active_addr_count--; 156 active_addr_count--;
@@ -180,24 +166,22 @@ destroy_address (struct ATS_Address *addr)
180 166
181struct CompareAddressContext 167struct CompareAddressContext
182{ 168{
183 const struct ATS_Address * search; 169 const struct ATS_Address *search;
184 struct ATS_Address * result; 170 struct ATS_Address *result;
185}; 171};
186 172
187 173
188static int 174static int
189compare_address_it (void *cls, 175compare_address_it (void *cls, const GNUNET_HashCode * key, void *value)
190 const GNUNET_HashCode * key,
191 void *value)
192{ 176{
193 struct CompareAddressContext * cac = cls; 177 struct CompareAddressContext *cac = cls;
194 struct ATS_Address * aa = value; 178 struct ATS_Address *aa = value;
195 179
196 if ( ( (aa->addr_len != cac->search->addr_len) || 180 if (((aa->addr_len != cac->search->addr_len) ||
197 (0 != strcmp(aa->plugin, cac->search->plugin)) || 181 (0 != strcmp (aa->plugin, cac->search->plugin)) ||
198 (0 != memcmp (aa->addr, cac->search->addr, aa->addr_len)) ) && 182 (0 != memcmp (aa->addr, cac->search->addr, aa->addr_len))) &&
199 ( (aa->session_id != cac->search->session_id) || 183 ((aa->session_id != cac->search->session_id) ||
200 (cac->search->session_id == 0) )) 184 (cac->search->session_id == 0)))
201 return GNUNET_YES; 185 return GNUNET_YES;
202 cac->result = aa; 186 cac->result = aa;
203 return GNUNET_NO; 187 return GNUNET_NO;
@@ -205,7 +189,7 @@ compare_address_it (void *cls,
205 189
206 190
207/** 191/**
208 * Find an existing equivalent address record. 192 * Find an existing equivalent address record.
209 * Compares by peer identity and network address OR by session ID 193 * Compares by peer identity and network address OR by session ID
210 * (one of the two must match). 194 * (one of the two must match).
211 * 195 *
@@ -215,34 +199,31 @@ compare_address_it (void *cls,
215 */ 199 */
216struct ATS_Address * 200struct ATS_Address *
217find_address (const struct GNUNET_PeerIdentity *peer, 201find_address (const struct GNUNET_PeerIdentity *peer,
218 const struct ATS_Address * addr) 202 const struct ATS_Address *addr)
219{ 203{
220 struct CompareAddressContext cac; 204 struct CompareAddressContext cac;
221 205
222 cac.result = NULL; 206 cac.result = NULL;
223 cac.search = addr; 207 cac.search = addr;
224 GNUNET_CONTAINER_multihashmap_get_multiple(addresses, 208 GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
225 &peer->hashPubKey, 209 compare_address_it, &cac);
226 compare_address_it,
227 &cac);
228 return cac.result; 210 return cac.result;
229} 211}
230 212
231 213
232void 214void
233GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, 215GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
234 const char *plugin_name, 216 const char *plugin_name, const void *plugin_addr,
235 const void *plugin_addr, size_t plugin_addr_len, 217 size_t plugin_addr_len, uint32_t session_id,
236 uint32_t session_id, 218 const struct GNUNET_ATS_Information *atsi,
237 const struct GNUNET_ATS_Information *atsi, 219 uint32_t atsi_count)
238 uint32_t atsi_count)
239{ 220{
240 struct ATS_Address * aa; 221 struct ATS_Address *aa;
241 struct ATS_Address * old; 222 struct ATS_Address *old;
242 uint32_t i; 223 uint32_t i;
243 224
244 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); 225 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len);
245 aa->ats = GNUNET_malloc(atsi_count * sizeof (struct GNUNET_ATS_Information)); 226 aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information));
246 aa->peer = *peer; 227 aa->peer = *peer;
247 aa->addr_len = plugin_addr_len; 228 aa->addr_len = plugin_addr_len;
248 aa->ats_count = atsi_count; 229 aa->ats_count = atsi_count;
@@ -256,19 +237,17 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
256 { 237 {
257 GNUNET_assert (GNUNET_OK == 238 GNUNET_assert (GNUNET_OK ==
258 GNUNET_CONTAINER_multihashmap_put (addresses, 239 GNUNET_CONTAINER_multihashmap_put (addresses,
259 &peer->hashPubKey, 240 &peer->hashPubKey, aa,
260 aa, 241 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
261 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' %X\n",
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 243 GNUNET_i2s (peer), aa);
263 "Added new address for peer `%s' %X\n",
264 GNUNET_i2s (peer), aa);
265 old = aa; 244 old = aa;
266 } 245 }
267 else 246 else
268 { 247 {
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
270 "Updated existing address for peer `%s' %X \n", 249 "Updated existing address for peer `%s' %X \n",
271 GNUNET_i2s (peer), old); 250 GNUNET_i2s (peer), old);
272 GNUNET_free_non_null (old->ats); 251 GNUNET_free_non_null (old->ats);
273 old->session_id = session_id; 252 old->session_id = session_id;
274 old->ats = NULL; 253 old->ats = NULL;
@@ -278,7 +257,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
278 GNUNET_free (aa->plugin); 257 GNUNET_free (aa->plugin);
279 GNUNET_free (aa); 258 GNUNET_free (aa);
280 } 259 }
281 for (i=0;i<atsi_count;i++) 260 for (i = 0; i < atsi_count; i++)
282 switch (ntohl (atsi[i].type)) 261 switch (ntohl (atsi[i].type))
283 { 262 {
284 case GNUNET_ATS_UTILIZATION_UP: 263 case GNUNET_ATS_UTILIZATION_UP:
@@ -304,8 +283,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
304 break; 283 break;
305 default: 284 default:
306 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 285 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
307 "Received unsupported ATS type %u\n", 286 "Received unsupported ATS type %u\n", ntohl (atsi[i].type));
308 ntohl (atsi[i].type));
309 GNUNET_break (0); 287 GNUNET_break (0);
310 break; 288 break;
311 } 289 }
@@ -314,9 +292,8 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
314 292
315void 293void
316GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, 294GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
317 const char *plugin_name, 295 const char *plugin_name, const void *plugin_addr,
318 const void *plugin_addr, size_t plugin_addr_len, 296 size_t plugin_addr_len, uint32_t session_id)
319 uint32_t session_id)
320{ 297{
321 struct ATS_Address aa; 298 struct ATS_Address aa;
322 struct ATS_Address *res; 299 struct ATS_Address *res;
@@ -324,20 +301,18 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
324 aa.peer = *peer; 301 aa.peer = *peer;
325 aa.addr_len = plugin_addr_len; 302 aa.addr_len = plugin_addr_len;
326 aa.addr = plugin_addr; 303 aa.addr = plugin_addr;
327 aa.plugin = (char*) plugin_name; 304 aa.plugin = (char *) plugin_name;
328 aa.session_id = session_id; 305 aa.session_id = session_id;
329 res = find_address (peer, &aa); 306 res = find_address (peer, &aa);
330 if (res == NULL) 307 if (res == NULL)
331 { 308 {
332 /* we don't even know this one, can this happen? */ 309 /* we don't even know this one, can this happen? */
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 "Asked to delete unknown address for peer `%s'\n", 311 "Asked to delete unknown address for peer `%s'\n",
335 GNUNET_i2s (peer)); 312 GNUNET_i2s (peer));
336 return; 313 return;
337 } 314 }
338 if ( (aa.session_id == session_id) && 315 if ((aa.session_id == session_id) && (session_id != 0) && (res->addr_len > 0))
339 (session_id != 0) &&
340 (res->addr_len > 0) )
341 { 316 {
342 /* just session died */ 317 /* just session died */
343 res->session_id = 0; 318 res->session_id = 0;
@@ -350,10 +325,9 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
350 return; 325 return;
351 } 326 }
352 /* destroy address entirely (either was only session or was 327 /* destroy address entirely (either was only session or was
353 not even with a session) */ 328 * not even with a session) */
354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting address for peer `%s': `%s'\n",
355 "Deleting address for peer `%s': `%s'\n", 330 GNUNET_i2s (peer), plugin_name);
356 GNUNET_i2s (peer), plugin_name);
357 if (GNUNET_YES == destroy_address (res)) 331 if (GNUNET_YES == destroy_address (res))
358 recalculate_assigned_bw (); 332 recalculate_assigned_bw ();
359} 333}
@@ -362,29 +336,27 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
362/** 336/**
363 * Find a "good" address to use for a peer. If we already have an existing 337 * Find a "good" address to use for a peer. If we already have an existing
364 * address, we stick to it. Otherwise, we pick by lowest distance and then 338 * address, we stick to it. Otherwise, we pick by lowest distance and then
365 * by lowest latency. 339 * by lowest latency.
366 * 340 *
367 * @param cls the 'struct ATS_Address**' where we store the result 341 * @param cls the 'struct ATS_Address**' where we store the result
368 * @param key unused 342 * @param key unused
369 * @param value another 'struct ATS_Address*' to consider using 343 * @param value another 'struct ATS_Address*' to consider using
370 * @return GNUNET_OK (continue to iterate) 344 * @return GNUNET_OK (continue to iterate)
371 */ 345 */
372static int 346static int
373find_address_it (void *cls, 347find_address_it (void *cls, const GNUNET_HashCode * key, void *value)
374 const GNUNET_HashCode * key,
375 void *value)
376{ 348{
377 struct ATS_Address **ap = cls; 349 struct ATS_Address **ap = cls;
378 struct ATS_Address * aa = (struct ATS_Address *) value; 350 struct ATS_Address *aa = (struct ATS_Address *) value;
379 struct ATS_Address * ab = *ap; 351 struct ATS_Address *ab = *ap;
380 352
381 if (NULL == ab) 353 if (NULL == ab)
382 { 354 {
383 *ap = aa; 355 *ap = aa;
384 return GNUNET_OK; 356 return GNUNET_OK;
385 } 357 }
386 if ( (ntohl (ab->assigned_bw_in.value__) == 0) && 358 if ((ntohl (ab->assigned_bw_in.value__) == 0) &&
387 (ntohl (aa->assigned_bw_in.value__) > 0) ) 359 (ntohl (aa->assigned_bw_in.value__) > 0))
388 { 360 {
389 /* stick to existing connection */ 361 /* stick to existing connection */
390 *ap = aa; 362 *ap = aa;
@@ -410,19 +382,16 @@ find_address_it (void *cls,
410void 382void
411GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) 383GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
412{ 384{
413 struct ATS_Address * aa; 385 struct ATS_Address *aa;
414 386
415 aa = NULL; 387 aa = NULL;
416 GNUNET_CONTAINER_multihashmap_get_multiple (addresses, 388 GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
417 &peer->hashPubKey, 389 &find_address_it, &aa);
418 &find_address_it,
419 &aa);
420 if (aa == NULL) 390 if (aa == NULL)
421 { 391 {
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
423 "Cannot suggest address for peer `%s'\n", 393 "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer));
424 GNUNET_i2s (peer)); 394 return;
425 return;
426 } 395 }
427 if (aa->active == GNUNET_NO) 396 if (aa->active == GNUNET_NO)
428 { 397 {
@@ -433,11 +402,11 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
433 else 402 else
434 { 403 {
435 /* just to be sure... */ 404 /* just to be sure... */
436 GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, 405 GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr,
437 aa->addr, aa->addr_len, 406 aa->addr_len, aa->session_id,
438 aa->session_id, 407 aa->ats, aa->ats_count,
439 aa->ats, aa->ats_count, 408 aa->assigned_bw_out,
440 aa->assigned_bw_out, aa->assigned_bw_in); 409 aa->assigned_bw_in);
441 } 410 }
442} 411}
443 412
@@ -446,8 +415,8 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
446// not with 'addresses' in the future... 415// not with 'addresses' in the future...
447void 416void
448GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer, 417GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer,
449 enum GNUNET_ATS_PreferenceKind kind, 418 enum GNUNET_ATS_PreferenceKind kind,
450 float score) 419 float score)
451{ 420{
452 // do nothing for now... 421 // do nothing for now...
453} 422}
@@ -462,16 +431,14 @@ void
462GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg) 431GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
463{ 432{
464 GNUNET_assert (GNUNET_OK == 433 GNUNET_assert (GNUNET_OK ==
465 GNUNET_CONFIGURATION_get_value_number (cfg, 434 GNUNET_CONFIGURATION_get_value_number (cfg, "core",
466 "core", 435 "TOTAL_QUOTA_IN",
467 "TOTAL_QUOTA_IN", 436 &total_quota_in));
468 &total_quota_in));
469 GNUNET_assert (GNUNET_OK == 437 GNUNET_assert (GNUNET_OK ==
470 GNUNET_CONFIGURATION_get_value_number (cfg, 438 GNUNET_CONFIGURATION_get_value_number (cfg, "core",
471 "core", 439 "TOTAL_QUOTA_OUT",
472 "TOTAL_QUOTA_OUT", 440 &total_quota_out));
473 &total_quota_out)); 441 addresses = GNUNET_CONTAINER_multihashmap_create (128);
474 addresses = GNUNET_CONTAINER_multihashmap_create(128);
475} 442}
476 443
477 444
@@ -483,12 +450,10 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
483 * @param value the 'struct ATS_Address' to free 450 * @param value the 'struct ATS_Address' to free
484 * @return GNUNET_OK (continue to iterate) 451 * @return GNUNET_OK (continue to iterate)
485 */ 452 */
486static int 453static int
487free_address_it (void *cls, 454free_address_it (void *cls, const GNUNET_HashCode * key, void *value)
488 const GNUNET_HashCode * key,
489 void *value)
490{ 455{
491 struct ATS_Address * aa = value; 456 struct ATS_Address *aa = value;
492 457
493 destroy_address (aa); 458 destroy_address (aa);
494 return GNUNET_OK; 459 return GNUNET_OK;
@@ -499,8 +464,7 @@ void
499GAS_addresses_destroy_all () 464GAS_addresses_destroy_all ()
500{ 465{
501 if (addresses != NULL) 466 if (addresses != NULL)
502 GNUNET_CONTAINER_multihashmap_iterate(addresses, 467 GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL);
503 &free_address_it, NULL);
504 GNUNET_assert (active_addr_count == 0); 468 GNUNET_assert (active_addr_count == 0);
505} 469}
506 470
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h
index 1d218ba57..7fde42d96 100644
--- a/src/ats/gnunet-service-ats_addresses.h
+++ b/src/ats/gnunet-service-ats_addresses.h
@@ -28,7 +28,7 @@
28#define GNUNET_SERVICE_ATS_ADDRESSES_H 28#define GNUNET_SERVICE_ATS_ADDRESSES_H
29 29
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_ats_service.h" 31#include "gnunet_ats_service.h"
32#include "ats.h" 32#include "ats.h"
33 33
34/** 34/**
@@ -48,18 +48,16 @@ GAS_addresses_done (void);
48 48
49void 49void
50GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, 50GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
51 const char *plugin_name, 51 const char *plugin_name, const void *plugin_addr,
52 const void *plugin_addr, size_t plugin_addr_len, 52 size_t plugin_addr_len, uint32_t session_id,
53 uint32_t session_id, 53 const struct GNUNET_ATS_Information *atsi,
54 const struct GNUNET_ATS_Information *atsi, 54 uint32_t atsi_count);
55 uint32_t atsi_count);
56 55
57 56
58void 57void
59GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, 58GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
60 const char *plugin_name, 59 const char *plugin_name, const void *plugin_addr,
61 const void *plugin_addr, size_t plugin_addr_len, 60 size_t plugin_addr_len, uint32_t session_id);
62 uint32_t session_id);
63 61
64 62
65void 63void
@@ -78,8 +76,8 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer);
78// not with 'addresses' in the future... 76// not with 'addresses' in the future...
79void 77void
80GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer, 78GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer,
81 enum GNUNET_ATS_PreferenceKind kind, 79 enum GNUNET_ATS_PreferenceKind kind,
82 float score); 80 float score);
83 81
84 82
85/* FIXME: add performance request API */ 83/* FIXME: add performance request API */
diff --git a/src/ats/gnunet-service-ats_math.h b/src/ats/gnunet-service-ats_math.h
index 1324c30d0..0ec85f3f0 100644
--- a/src/ats/gnunet-service-ats_math.h
+++ b/src/ats/gnunet-service-ats_math.h
@@ -67,11 +67,10 @@
67struct ATS_mechanism; 67struct ATS_mechanism;
68struct ATS_peer; 68struct ATS_peer;
69 69
70typedef void (*GNUNET_ATS_AddressNotification) (struct ATS_peer ** 70typedef void (*GNUNET_ATS_AddressNotification) (struct ATS_peer ** peers,
71 peers, int *c_p, 71 int *c_p,
72 struct ATS_mechanism 72 struct ATS_mechanism **
73 ** mechanisms, 73 mechanisms, int *c_m);
74 int *c_m);
75 74
76typedef void (*GNUNET_ATS_ResultCallback) (void); 75typedef void (*GNUNET_ATS_ResultCallback) (void);
77 76
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index 0fa08ac4b..4b8d23720 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -40,13 +40,13 @@ struct PerformanceClient
40 /** 40 /**
41 * Next in doubly-linked list. 41 * Next in doubly-linked list.
42 */ 42 */
43 struct PerformanceClient * next; 43 struct PerformanceClient *next;
44 44
45 /** 45 /**
46 * Previous in doubly-linked list. 46 * Previous in doubly-linked list.
47 */ 47 */
48 struct PerformanceClient * prev; 48 struct PerformanceClient *prev;
49 49
50 /** 50 /**
51 * Actual handle to the client. 51 * Actual handle to the client.
52 */ 52 */
@@ -69,7 +69,7 @@ static struct PerformanceClient *pc_head;
69 * Tail of linked list of all clients to this service. 69 * Tail of linked list of all clients to this service.
70 */ 70 */
71static struct PerformanceClient *pc_tail; 71static struct PerformanceClient *pc_tail;
72 72
73/** 73/**
74 * Context for sending messages to performance clients. 74 * Context for sending messages to performance clients.
75 */ 75 */
@@ -82,10 +82,10 @@ static struct GNUNET_SERVER_NotificationContext *nc;
82 * @param client server handle 82 * @param client server handle
83 * @return internal handle 83 * @return internal handle
84 */ 84 */
85static struct PerformanceClient * 85static struct PerformanceClient *
86find_client (struct GNUNET_SERVER_Client *client) 86find_client (struct GNUNET_SERVER_Client *client)
87{ 87{
88 struct PerformanceClient * pc; 88 struct PerformanceClient *pc;
89 89
90 for (pc = pc_head; pc != NULL; pc = pc->next) 90 for (pc = pc_head; pc != NULL; pc = pc->next)
91 if (pc->client == client) 91 if (pc->client == client)
@@ -101,9 +101,9 @@ find_client (struct GNUNET_SERVER_Client *client)
101 */ 101 */
102void 102void
103GAS_performance_add_client (struct GNUNET_SERVER_Client *client, 103GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
104 enum StartFlag flag) 104 enum StartFlag flag)
105{ 105{
106 struct PerformanceClient * pc; 106 struct PerformanceClient *pc;
107 107
108 GNUNET_break (NULL == find_client (client)); 108 GNUNET_break (NULL == find_client (client));
109 pc = GNUNET_malloc (sizeof (struct PerformanceClient)); 109 pc = GNUNET_malloc (sizeof (struct PerformanceClient));
@@ -111,7 +111,7 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
111 pc->flag = flag; 111 pc->flag = flag;
112 GNUNET_SERVER_notification_context_add (nc, client); 112 GNUNET_SERVER_notification_context_add (nc, client);
113 GNUNET_SERVER_client_keep (client); 113 GNUNET_SERVER_client_keep (client);
114 GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc); 114 GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc);
115} 115}
116 116
117 117
@@ -124,7 +124,7 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
124void 124void
125GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) 125GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
126{ 126{
127 struct PerformanceClient * pc; 127 struct PerformanceClient *pc;
128 128
129 pc = find_client (client); 129 pc = find_client (client);
130 if (NULL == pc) 130 if (NULL == pc)
@@ -150,25 +150,30 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
150 */ 150 */
151void 151void
152GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, 152GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
153 const char *plugin_name, 153 const char *plugin_name,
154 const void *plugin_addr, size_t plugin_addr_len, 154 const void *plugin_addr, size_t plugin_addr_len,
155 const struct GNUNET_ATS_Information *atsi, 155 const struct GNUNET_ATS_Information *atsi,
156 uint32_t atsi_count, 156 uint32_t atsi_count,
157 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 157 struct GNUNET_BANDWIDTH_Value32NBO
158 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 158 bandwidth_out,
159 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
159{ 160{
160 struct PerformanceClient *pc; 161 struct PerformanceClient *pc;
161 struct PeerInformationMessage *msg; 162 struct PeerInformationMessage *msg;
162 size_t plugin_name_length = strlen (plugin_name) + 1; 163 size_t plugin_name_length = strlen (plugin_name) + 1;
163 size_t msize = sizeof (struct PeerInformationMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information) 164 size_t msize =
164 + plugin_addr_len + plugin_name_length; 165 sizeof (struct PeerInformationMessage) +
166 atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
167 plugin_name_length;
165 char buf[msize]; 168 char buf[msize];
166 struct GNUNET_ATS_Information *atsp; 169 struct GNUNET_ATS_Information *atsp;
167 char *addrp; 170 char *addrp;
168 171
169 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 172 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
170 GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)); 173 GNUNET_assert (atsi_count <
171 msg = (struct PeerInformationMessage*) buf; 174 GNUNET_SERVER_MAX_MESSAGE_SIZE /
175 sizeof (struct GNUNET_ATS_Information));
176 msg = (struct PeerInformationMessage *) buf;
172 msg->header.size = htons (msize); 177 msg->header.size = htons (msize);
173 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION); 178 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION);
174 msg->ats_count = htonl (atsi_count); 179 msg->ats_count = htonl (atsi_count);
@@ -177,22 +182,19 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
177 msg->plugin_name_length = htons (plugin_name_length); 182 msg->plugin_name_length = htons (plugin_name_length);
178 msg->bandwidth_out = bandwidth_out; 183 msg->bandwidth_out = bandwidth_out;
179 msg->bandwidth_in = bandwidth_in; 184 msg->bandwidth_in = bandwidth_in;
180 atsp = (struct GNUNET_ATS_Information* ) &msg[1]; 185 atsp = (struct GNUNET_ATS_Information *) &msg[1];
181 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); 186 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
182 addrp = (char*) &atsp[atsi_count]; 187 addrp = (char *) &atsp[atsi_count];
183 memcpy (addrp, plugin_addr, plugin_addr_len); 188 memcpy (addrp, plugin_addr, plugin_addr_len);
184 strcpy (&addrp[plugin_addr_len], plugin_name); 189 strcpy (&addrp[plugin_addr_len], plugin_name);
185 for (pc = pc_head; pc != NULL; pc = pc->next) 190 for (pc = pc_head; pc != NULL; pc = pc->next)
186 if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC) 191 if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC)
187 { 192 {
188 GNUNET_SERVER_notification_context_unicast (nc, 193 GNUNET_SERVER_notification_context_unicast (nc, pc->client, &msg->header,
189 pc->client, 194 GNUNET_YES);
190 &msg->header,
191 GNUNET_YES);
192 GNUNET_STATISTICS_update (GSA_stats, 195 GNUNET_STATISTICS_update (GSA_stats,
193 "# performance updates given to clients", 196 "# performance updates given to clients", 1,
194 1, 197 GNUNET_NO);
195 GNUNET_NO);
196 } 198 }
197} 199}
198 200
@@ -206,9 +208,10 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
206 */ 208 */
207void 209void
208GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, 210GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
209 const struct GNUNET_MessageHeader *message) 211 const struct GNUNET_MessageHeader *message)
210{ 212{
211 const struct ReservationRequestMessage * msg = (const struct ReservationRequestMessage *) message; 213 const struct ReservationRequestMessage *msg =
214 (const struct ReservationRequestMessage *) message;
212 struct ReservationResultMessage result; 215 struct ReservationResultMessage result;
213 int32_t amount; 216 int32_t amount;
214 struct GNUNET_TIME_Relative res_delay; 217 struct GNUNET_TIME_Relative res_delay;
@@ -220,12 +223,10 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
220 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 223 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
221 return; 224 return;
222 } 225 }
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
224 "Received `%s' message\n", 227 "RESERVATION_REQUEST");
225 "RESERVATION_REQUEST");
226 amount = (int32_t) ntohl (msg->amount); 228 amount = (int32_t) ntohl (msg->amount);
227 res_delay = GAS_reservations_reserve (&msg->peer, 229 res_delay = GAS_reservations_reserve (&msg->peer, amount);
228 amount);
229 if (res_delay.rel_value > 0) 230 if (res_delay.rel_value > 0)
230 amount = 0; 231 amount = 0;
231 result.header.size = htons (sizeof (struct ReservationResultMessage)); 232 result.header.size = htons (sizeof (struct ReservationResultMessage));
@@ -233,14 +234,10 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
233 result.amount = htonl (amount); 234 result.amount = htonl (amount);
234 result.peer = msg->peer; 235 result.peer = msg->peer;
235 result.res_delay = GNUNET_TIME_relative_hton (res_delay); 236 result.res_delay = GNUNET_TIME_relative_hton (res_delay);
236 GNUNET_STATISTICS_update (GSA_stats, 237 GNUNET_STATISTICS_update (GSA_stats, "# reservation requests processed", 1,
237 "# reservation requests processed", 238 GNUNET_NO);
238 1, 239 GNUNET_SERVER_notification_context_unicast (nc, client, &result.header,
239 GNUNET_NO); 240 GNUNET_NO);
240 GNUNET_SERVER_notification_context_unicast (nc,
241 client,
242 &result.header,
243 GNUNET_NO);
244 GNUNET_SERVER_receive_done (client, GNUNET_OK); 241 GNUNET_SERVER_receive_done (client, GNUNET_OK);
245} 242}
246 243
@@ -254,15 +251,16 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
254 */ 251 */
255void 252void
256GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, 253GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
257 const struct GNUNET_MessageHeader *message) 254 const struct GNUNET_MessageHeader *message)
258{ 255{
259 const struct ChangePreferenceMessage * msg; 256 const struct ChangePreferenceMessage *msg;
260 const struct PreferenceInformation *pi; 257 const struct PreferenceInformation *pi;
261 uint16_t msize; 258 uint16_t msize;
262 uint32_t nump; 259 uint32_t nump;
263 uint32_t i; 260 uint32_t i;
264 261
265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "PREFERENCE_CHANGE"); 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
263 "PREFERENCE_CHANGE");
266 msize = ntohs (message->size); 264 msize = ntohs (message->size);
267 if (msize < sizeof (struct ChangePreferenceMessage)) 265 if (msize < sizeof (struct ChangePreferenceMessage))
268 { 266 {
@@ -272,21 +270,22 @@ GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
272 } 270 }
273 msg = (const struct ChangePreferenceMessage *) message; 271 msg = (const struct ChangePreferenceMessage *) message;
274 nump = ntohl (msg->num_preferences); 272 nump = ntohl (msg->num_preferences);
275 if (msize != sizeof (struct ChangePreferenceMessage) + nump * sizeof (struct PreferenceInformation)) 273 if (msize !=
274 sizeof (struct ChangePreferenceMessage) +
275 nump * sizeof (struct PreferenceInformation))
276 { 276 {
277 GNUNET_break (0); 277 GNUNET_break (0);
278 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 278 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
279 return; 279 return;
280 } 280 }
281 GNUNET_STATISTICS_update (GSA_stats, 281 GNUNET_STATISTICS_update (GSA_stats, "# preference change requests processed",
282 "# preference change requests processed", 282 1, GNUNET_NO);
283 1,
284 GNUNET_NO);
285 pi = (const struct PreferenceInformation *) &msg[1]; 283 pi = (const struct PreferenceInformation *) &msg[1];
286 for (i=0;i<nump;i++) 284 for (i = 0; i < nump; i++)
287 GAS_addresses_change_preference (&msg->peer, 285 GAS_addresses_change_preference (&msg->peer,
288 (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind), 286 (enum GNUNET_ATS_PreferenceKind)
289 pi[i].preference_value); 287 ntohl (pi[i].preference_kind),
288 pi[i].preference_value);
290 GNUNET_SERVER_receive_done (client, GNUNET_OK); 289 GNUNET_SERVER_receive_done (client, GNUNET_OK);
291} 290}
292 291
diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h
index 5988bff44..44d02452b 100644
--- a/src/ats/gnunet-service-ats_performance.h
+++ b/src/ats/gnunet-service-ats_performance.h
@@ -39,7 +39,7 @@
39 */ 39 */
40void 40void
41GAS_performance_add_client (struct GNUNET_SERVER_Client *client, 41GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
42 enum StartFlag flag); 42 enum StartFlag flag);
43 43
44 44
45/** 45/**
@@ -67,12 +67,14 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client);
67 */ 67 */
68void 68void
69GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, 69GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
70 const char *plugin_name, 70 const char *plugin_name,
71 const void *plugin_addr, size_t plugin_addr_len, 71 const void *plugin_addr, size_t plugin_addr_len,
72 const struct GNUNET_ATS_Information *atsi, 72 const struct GNUNET_ATS_Information *atsi,
73 uint32_t atsi_count, 73 uint32_t atsi_count,
74 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 74 struct GNUNET_BANDWIDTH_Value32NBO
75 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); 75 bandwidth_out,
76 struct GNUNET_BANDWIDTH_Value32NBO
77 bandwidth_in);
76 78
77 79
78/** 80/**
@@ -84,7 +86,7 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
84 */ 86 */
85void 87void
86GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, 88GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
87 const struct GNUNET_MessageHeader *message); 89 const struct GNUNET_MessageHeader *message);
88 90
89 91
90/** 92/**
@@ -96,7 +98,7 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
96 */ 98 */
97void 99void
98GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, 100GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
99 const struct GNUNET_MessageHeader *message); 101 const struct GNUNET_MessageHeader *message);
100 102
101 103
102/** 104/**
diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c
index 492751254..f40e54516 100644
--- a/src/ats/gnunet-service-ats_reservations.c
+++ b/src/ats/gnunet-service-ats_reservations.c
@@ -27,7 +27,7 @@
27#include "gnunet-service-ats_reservations.h" 27#include "gnunet-service-ats_reservations.h"
28 28
29/** 29/**
30 * Number of seconds that available bandwidth carries over 30 * Number of seconds that available bandwidth carries over
31 * (can accumulate). 31 * (can accumulate).
32 */ 32 */
33#define MAX_BANDWIDTH_CARRY_S 5 33#define MAX_BANDWIDTH_CARRY_S 5
@@ -52,32 +52,27 @@ static struct GNUNET_CONTAINER_MultiHashMap *trackers;
52 */ 52 */
53struct GNUNET_TIME_Relative 53struct GNUNET_TIME_Relative
54GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer, 54GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer,
55 int32_t amount) 55 int32_t amount)
56{ 56{
57 struct GNUNET_BANDWIDTH_Tracker *tracker; 57 struct GNUNET_BANDWIDTH_Tracker *tracker;
58 struct GNUNET_TIME_Relative ret; 58 struct GNUNET_TIME_Relative ret;
59 59
60 tracker = GNUNET_CONTAINER_multihashmap_get (trackers, 60 tracker = GNUNET_CONTAINER_multihashmap_get (trackers, &peer->hashPubKey);
61 &peer->hashPubKey);
62 if (NULL == tracker) 61 if (NULL == tracker)
63 return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */ 62 return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */
64 if (amount >= 0) 63 if (amount >= 0)
65 { 64 {
66 ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker, 65 ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker, amount);
67 amount);
68 if (ret.rel_value > 0) 66 if (ret.rel_value > 0)
69 { 67 {
70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
71 "Delay to satisfy reservation for %d bytes is %llu ms\n", 69 "Delay to satisfy reservation for %d bytes is %llu ms\n",
72 (int) amount, 70 (int) amount, (unsigned long long) ret.rel_value);
73 (unsigned long long) ret.rel_value);
74 return ret; 71 return ret;
75 } 72 }
76 } 73 }
77 (void) GNUNET_BANDWIDTH_tracker_consume (tracker, amount); 74 (void) GNUNET_BANDWIDTH_tracker_consume (tracker, amount);
78 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reserved %d bytes\n", (int) amount);
79 "Reserved %d bytes\n",
80 (int) amount);
81 return GNUNET_TIME_UNIT_ZERO; 76 return GNUNET_TIME_UNIT_ZERO;
82} 77}
83 78
@@ -85,42 +80,37 @@ GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer,
85/** 80/**
86 * Set the amount of bandwidth the other peer could currently transmit 81 * Set the amount of bandwidth the other peer could currently transmit
87 * to us (as far as we know) to the given value. 82 * to us (as far as we know) to the given value.
88 * 83 *
89 * @param peer identity of the peer 84 * @param peer identity of the peer
90 * @param bandwidth_in currently available bandwidth from that peer to 85 * @param bandwidth_in currently available bandwidth from that peer to
91 * this peer (estimate) 86 * this peer (estimate)
92 */ 87 */
93void 88void
94GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, 89GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
95 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 90 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
96{ 91{
97 struct GNUNET_BANDWIDTH_Tracker *tracker; 92 struct GNUNET_BANDWIDTH_Tracker *tracker;
98 93
99 tracker = GNUNET_CONTAINER_multihashmap_get (trackers, 94 tracker = GNUNET_CONTAINER_multihashmap_get (trackers, &peer->hashPubKey);
100 &peer->hashPubKey);
101 if (0 == ntohl (bandwidth_in.value__)) 95 if (0 == ntohl (bandwidth_in.value__))
102 { 96 {
103 GNUNET_assert (GNUNET_YES == 97 GNUNET_assert (GNUNET_YES ==
104 GNUNET_CONTAINER_multihashmap_remove (trackers, 98 GNUNET_CONTAINER_multihashmap_remove (trackers,
105 &peer->hashPubKey, 99 &peer->hashPubKey,
106 tracker)); 100 tracker));
107 GNUNET_free (tracker); 101 GNUNET_free (tracker);
108 return; 102 return;
109 } 103 }
110 if (NULL == tracker) 104 if (NULL == tracker)
111 { 105 {
112 tracker = GNUNET_malloc (sizeof (struct GNUNET_BANDWIDTH_Tracker)); 106 tracker = GNUNET_malloc (sizeof (struct GNUNET_BANDWIDTH_Tracker));
113 GNUNET_BANDWIDTH_tracker_init (tracker, 107 GNUNET_BANDWIDTH_tracker_init (tracker, bandwidth_in,
114 bandwidth_in, 108 MAX_BANDWIDTH_CARRY_S);
115 MAX_BANDWIDTH_CARRY_S); 109 GNUNET_CONTAINER_multihashmap_put (trackers, &peer->hashPubKey, tracker,
116 GNUNET_CONTAINER_multihashmap_put (trackers, 110 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
117 &peer->hashPubKey,
118 tracker,
119 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
120 return; 111 return;
121 } 112 }
122 GNUNET_BANDWIDTH_tracker_update_quota (tracker, 113 GNUNET_BANDWIDTH_tracker_update_quota (tracker, bandwidth_in);
123 bandwidth_in);
124} 114}
125 115
126 116
@@ -130,7 +120,7 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
130void 120void
131GAS_reservations_init () 121GAS_reservations_init ()
132{ 122{
133 trackers = GNUNET_CONTAINER_multihashmap_create(128); 123 trackers = GNUNET_CONTAINER_multihashmap_create (128);
134} 124}
135 125
136 126
@@ -142,10 +132,8 @@ GAS_reservations_init ()
142 * @param value the 'struct GNUNET_BANDWIDTH_Tracker' to free 132 * @param value the 'struct GNUNET_BANDWIDTH_Tracker' to free
143 * @return GNUNET_OK (continue to iterate) 133 * @return GNUNET_OK (continue to iterate)
144 */ 134 */
145static int 135static int
146free_tracker (void *cls, 136free_tracker (void *cls, const GNUNET_HashCode * key, void *value)
147 const GNUNET_HashCode * key,
148 void *value)
149{ 137{
150 struct GNUNET_BANDWIDTH_Tracker *tracker = value; 138 struct GNUNET_BANDWIDTH_Tracker *tracker = value;
151 139
diff --git a/src/ats/gnunet-service-ats_reservations.h b/src/ats/gnunet-service-ats_reservations.h
index 5112f8213..5ddec9bd6 100644
--- a/src/ats/gnunet-service-ats_reservations.h
+++ b/src/ats/gnunet-service-ats_reservations.h
@@ -32,14 +32,15 @@
32/** 32/**
33 * Set the amount of bandwidth the other peer could currently transmit 33 * Set the amount of bandwidth the other peer could currently transmit
34 * to us (as far as we know) to the given value. 34 * to us (as far as we know) to the given value.
35 * 35 *
36 * @param peer identity of the peer 36 * @param peer identity of the peer
37 * @param bandwidth_in currently available bandwidth from that peer to 37 * @param bandwidth_in currently available bandwidth from that peer to
38 * this peer (estimate) 38 * this peer (estimate)
39 */ 39 */
40void 40void
41GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, 41GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
42 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); 42 struct GNUNET_BANDWIDTH_Value32NBO
43 bandwidth_in);
43 44
44 45
45/** 46/**
@@ -55,7 +56,7 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
55 */ 56 */
56struct GNUNET_TIME_Relative 57struct GNUNET_TIME_Relative
57GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer, 58GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer,
58 int32_t amount); 59 int32_t amount);
59 60
60 61
61/** 62/**
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index bb95182c8..4af44e29b 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -46,7 +46,7 @@ static struct GNUNET_SERVER_Client *my_client;
46 * Register a new scheduling client. 46 * Register a new scheduling client.
47 * 47 *
48 * @param client handle of the new client 48 * @param client handle of the new client
49 * @return GNUNET_OK on success, GNUNET_SYSERR on error 49 * @return GNUNET_OK on success, GNUNET_SYSERR on error
50 */ 50 */
51int 51int
52GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) 52GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
@@ -54,7 +54,7 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
54 if (my_client != NULL) 54 if (my_client != NULL)
55 { 55 {
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
57 "This ATS already has a scheduling client, refusing new scheduling client for now.\n"); 57 "This ATS already has a scheduling client, refusing new scheduling client for now.\n");
58 return GNUNET_SYSERR; 58 return GNUNET_SYSERR;
59 } 59 }
60 my_client = client; 60 my_client = client;
@@ -96,32 +96,37 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client)
96 * @param bandwidth_in assigned inbound bandwidth 96 * @param bandwidth_in assigned inbound bandwidth
97 */ 97 */
98void 98void
99GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer, 99GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity
100 const char *plugin_name, 100 *peer, const char *plugin_name,
101 const void *plugin_addr, size_t plugin_addr_len, 101 const void *plugin_addr,
102 uint32_t session_id, 102 size_t plugin_addr_len,
103 const struct GNUNET_ATS_Information *atsi, 103 uint32_t session_id,
104 uint32_t atsi_count, 104 const struct GNUNET_ATS_Information
105 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 105 *atsi, uint32_t atsi_count,
106 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 106 struct GNUNET_BANDWIDTH_Value32NBO
107 bandwidth_out,
108 struct GNUNET_BANDWIDTH_Value32NBO
109 bandwidth_in)
107{ 110{
108 struct AddressSuggestionMessage *msg; 111 struct AddressSuggestionMessage *msg;
109 size_t plugin_name_length = strlen (plugin_name) + 1; 112 size_t plugin_name_length = strlen (plugin_name) + 1;
110 size_t msize = sizeof (struct AddressSuggestionMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information) 113 size_t msize =
111 + plugin_addr_len + plugin_name_length; 114 sizeof (struct AddressSuggestionMessage) +
115 atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
116 plugin_name_length;
112 char buf[msize]; 117 char buf[msize];
113 struct GNUNET_ATS_Information *atsp; 118 struct GNUNET_ATS_Information *atsp;
114 char *addrp; 119 char *addrp;
115 120
116 if (my_client == NULL) 121 if (my_client == NULL)
117 return; 122 return;
118 GNUNET_STATISTICS_update (GSA_stats, 123 GNUNET_STATISTICS_update (GSA_stats, "# address suggestions made", 1,
119 "# address suggestions made", 124 GNUNET_NO);
120 1,
121 GNUNET_NO);
122 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 125 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
123 GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)); 126 GNUNET_assert (atsi_count <
124 msg = (struct AddressSuggestionMessage*) buf; 127 GNUNET_SERVER_MAX_MESSAGE_SIZE /
128 sizeof (struct GNUNET_ATS_Information));
129 msg = (struct AddressSuggestionMessage *) buf;
125 msg->header.size = htons (msize); 130 msg->header.size = htons (msize);
126 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); 131 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
127 msg->ats_count = htonl (atsi_count); 132 msg->ats_count = htonl (atsi_count);
@@ -131,15 +136,13 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
131 msg->session_id = htonl (session_id); 136 msg->session_id = htonl (session_id);
132 msg->bandwidth_out = bandwidth_out; 137 msg->bandwidth_out = bandwidth_out;
133 msg->bandwidth_in = bandwidth_in; 138 msg->bandwidth_in = bandwidth_in;
134 atsp = (struct GNUNET_ATS_Information* ) &msg[1]; 139 atsp = (struct GNUNET_ATS_Information *) &msg[1];
135 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); 140 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
136 addrp = (char*) &atsp[atsi_count]; 141 addrp = (char *) &atsp[atsi_count];
137 memcpy (addrp, plugin_addr, plugin_addr_len); 142 memcpy (addrp, plugin_addr, plugin_addr_len);
138 strcpy (&addrp[plugin_addr_len], plugin_name); 143 strcpy (&addrp[plugin_addr_len], plugin_name);
139 GNUNET_SERVER_notification_context_unicast (nc, 144 GNUNET_SERVER_notification_context_unicast (nc, my_client, &msg->header,
140 my_client, 145 GNUNET_YES);
141 &msg->header,
142 GNUNET_YES);
143} 146}
144 147
145 148
@@ -152,16 +155,15 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
152 */ 155 */
153void 156void
154GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, 157GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
155 const struct GNUNET_MessageHeader *message) 158 const struct GNUNET_MessageHeader *message)
156
157{ 159{
158 const struct RequestAddressMessage * msg = (const struct RequestAddressMessage *) message; 160 const struct RequestAddressMessage *msg =
161 (const struct RequestAddressMessage *) message;
159 162
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "REQUEST_ADDRESS"); 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
161 GNUNET_STATISTICS_update (GSA_stats, 164 "REQUEST_ADDRESS");
162 "# address requests received", 165 GNUNET_STATISTICS_update (GSA_stats, "# address requests received", 1,
163 1, 166 GNUNET_NO);
164 GNUNET_NO);
165 GNUNET_break (0 == ntohl (msg->reserved)); 167 GNUNET_break (0 == ntohl (msg->reserved));
166 GAS_addresses_request_address (&msg->peer); 168 GAS_addresses_request_address (&msg->peer);
167 GNUNET_SERVER_receive_done (client, GNUNET_OK); 169 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -177,9 +179,9 @@ GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
177 */ 179 */
178void 180void
179GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, 181GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
180 const struct GNUNET_MessageHeader *message) 182 const struct GNUNET_MessageHeader *message)
181{ 183{
182 const struct AddressUpdateMessage * m; 184 const struct AddressUpdateMessage *m;
183 const struct GNUNET_ATS_Information *atsi; 185 const struct GNUNET_ATS_Information *atsi;
184 const char *address; 186 const char *address;
185 const char *plugin_name; 187 const char *plugin_name;
@@ -188,9 +190,8 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
188 uint32_t ats_count; 190 uint32_t ats_count;
189 uint16_t size; 191 uint16_t size;
190 192
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
192 "Received `%s' message\n", 194 "ADDRESS_UPDATE");
193 "ADDRESS_UPDATE");
194 size = ntohs (message->size); 195 size = ntohs (message->size);
195 if (size < sizeof (struct AddressUpdateMessage)) 196 if (size < sizeof (struct AddressUpdateMessage))
196 { 197 {
@@ -198,38 +199,31 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
198 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 199 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
199 return; 200 return;
200 } 201 }
201 m = (const struct AddressUpdateMessage*) message; 202 m = (const struct AddressUpdateMessage *) message;
202 ats_count = ntohl (m->ats_count); 203 ats_count = ntohl (m->ats_count);
203 address_length = ntohs (m->address_length); 204 address_length = ntohs (m->address_length);
204 plugin_name_length = ntohs (m->plugin_name_length); 205 plugin_name_length = ntohs (m->plugin_name_length);
205 atsi = (const struct GNUNET_ATS_Information*) &m[1]; 206 atsi = (const struct GNUNET_ATS_Information *) &m[1];
206 address = (const char*) &atsi[ats_count]; 207 address = (const char *) &atsi[ats_count];
207 if (plugin_name_length != 0) 208 if (plugin_name_length != 0)
208 plugin_name = &address[address_length]; 209 plugin_name = &address[address_length];
209 else 210 else
210 plugin_name = ""; 211 plugin_name = "";
211 if ( (address_length + 212 if ((address_length + plugin_name_length +
212 plugin_name_length + 213 ats_count * sizeof (struct GNUNET_ATS_Information) +
213 ats_count * sizeof (struct GNUNET_ATS_Information) + 214 sizeof (struct AddressUpdateMessage) != ntohs (message->size)) ||
214 sizeof (struct AddressUpdateMessage) != ntohs (message->size)) || 215 (ats_count >
215 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || 216 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
216 (plugin_name[plugin_name_length - 1] != '\0') ) 217 || (plugin_name[plugin_name_length - 1] != '\0'))
217 { 218 {
218 GNUNET_break (0); 219 GNUNET_break (0);
219 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 220 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
220 return; 221 return;
221 } 222 }
222 GNUNET_STATISTICS_update (GSA_stats, 223 GNUNET_STATISTICS_update (GSA_stats, "# address updates received", 1,
223 "# address updates received", 224 GNUNET_NO);
224 1, 225 GAS_addresses_update (&m->peer, plugin_name, address, address_length,
225 GNUNET_NO); 226 ntohl (m->session_id), atsi, ats_count);
226 GAS_addresses_update (&m->peer,
227 plugin_name,
228 address,
229 address_length,
230 ntohl (m->session_id),
231 atsi,
232 ats_count);
233 GNUNET_SERVER_receive_done (client, GNUNET_OK); 227 GNUNET_SERVER_receive_done (client, GNUNET_OK);
234} 228}
235 229
@@ -245,7 +239,7 @@ void
245GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, 239GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
246 const struct GNUNET_MessageHeader *message) 240 const struct GNUNET_MessageHeader *message)
247{ 241{
248 const struct AddressUseMessage * m; 242 const struct AddressUseMessage *m;
249 const char *address; 243 const char *address;
250 const char *plugin_name; 244 const char *plugin_name;
251 uint16_t address_length; 245 uint16_t address_length;
@@ -253,8 +247,7 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
253 247
254 uint16_t size; 248 uint16_t size;
255 249
256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
257 "Received `%s' message\n",
258 "ADDRESS_IN_USE"); 251 "ADDRESS_IN_USE");
259 size = ntohs (message->size); 252 size = ntohs (message->size);
260 if (size < sizeof (struct AddressUseMessage)) 253 if (size < sizeof (struct AddressUseMessage))
@@ -263,21 +256,20 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
263 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 256 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
264 return; 257 return;
265 } 258 }
266 m = (const struct AddressUseMessage*) message; 259 m = (const struct AddressUseMessage *) message;
267 260
268 address_length = ntohs (m->address_length); 261 address_length = ntohs (m->address_length);
269 plugin_name_length = ntohs (m->plugin_name_length); 262 plugin_name_length = ntohs (m->plugin_name_length);
270 263
271 address = (const char*) &m[1]; 264 address = (const char *) &m[1];
272 if (plugin_name_length != 0) 265 if (plugin_name_length != 0)
273 plugin_name = &address[address_length]; 266 plugin_name = &address[address_length];
274 else 267 else
275 plugin_name = ""; 268 plugin_name = "";
276 269
277 if ( (address_length + 270 if ((address_length + plugin_name_length +
278 plugin_name_length + 271 sizeof (struct AddressUseMessage) != ntohs (message->size)) ||
279 sizeof (struct AddressUseMessage) != ntohs (message->size)) || 272 (plugin_name[plugin_name_length - 1] != '\0'))
280 (plugin_name[plugin_name_length - 1] != '\0') )
281 { 273 {
282 GNUNET_break (0); 274 GNUNET_break (0);
283 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 275 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -306,10 +298,9 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
306 */ 298 */
307void 299void
308GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, 300GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
309 const struct GNUNET_MessageHeader *message) 301 const struct GNUNET_MessageHeader *message)
310
311{ 302{
312 const struct AddressDestroyedMessage * m; 303 const struct AddressDestroyedMessage *m;
313 struct SessionReleaseMessage srm; 304 struct SessionReleaseMessage srm;
314 const char *address; 305 const char *address;
315 const char *plugin_name; 306 const char *plugin_name;
@@ -317,60 +308,50 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
317 uint16_t plugin_name_length; 308 uint16_t plugin_name_length;
318 uint16_t size; 309 uint16_t size;
319 310
320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message of size %u %u\n",
321 "Received `%s' message of size %u %u\n", 312 "ADDRESS_DESTROYED", ntohs (message->size),
322 "ADDRESS_DESTROYED", ntohs (message->size), sizeof (struct AddressDestroyedMessage)); 313 sizeof (struct AddressDestroyedMessage));
323 size = ntohs (message->size); 314 size = ntohs (message->size);
324 if ( (size < sizeof (struct AddressDestroyedMessage)) || 315 if ((size < sizeof (struct AddressDestroyedMessage)) || (client != my_client))
325 (client != my_client) )
326 { 316 {
327 GNUNET_break (0); 317 GNUNET_break (0);
328 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 318 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
329 return; 319 return;
330 } 320 }
331 m = (const struct AddressDestroyedMessage*) message; 321 m = (const struct AddressDestroyedMessage *) message;
332 GNUNET_break (0 == ntohl (m->reserved)); 322 GNUNET_break (0 == ntohl (m->reserved));
333 address_length = ntohs (m->address_length); 323 address_length = ntohs (m->address_length);
334 plugin_name_length = ntohs (m->plugin_name_length); 324 plugin_name_length = ntohs (m->plugin_name_length);
335 address = (const char*) &m[1]; 325 address = (const char *) &m[1];
336 if (plugin_name_length != 0) 326 if (plugin_name_length != 0)
337 plugin_name = &address[address_length]; 327 plugin_name = &address[address_length];
338 else 328 else
339 plugin_name = ""; 329 plugin_name = "";
340 if ( (address_length + 330 if ((address_length + plugin_name_length +
341 plugin_name_length + 331 sizeof (struct AddressDestroyedMessage) != ntohs (message->size)))
342 sizeof (struct AddressDestroyedMessage) != ntohs (message->size)))
343 { 332 {
344 GNUNET_break (0); 333 GNUNET_break (0);
345 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 334 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
346 return; 335 return;
347 } 336 }
348 if ( (plugin_name_length != 0) && 337 if ((plugin_name_length != 0) &&
349 (plugin_name[plugin_name_length - 1] != '\0') ) 338 (plugin_name[plugin_name_length - 1] != '\0'))
350 { 339 {
351 GNUNET_break (0); 340 GNUNET_break (0);
352 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 341 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
353 return; 342 return;
354 } 343 }
355 GNUNET_STATISTICS_update (GSA_stats, 344 GNUNET_STATISTICS_update (GSA_stats, "# addresses destroyed", 1, GNUNET_NO);
356 "# addresses destroyed", 345 GAS_addresses_destroy (&m->peer, plugin_name, address, address_length,
357 1, 346 ntohl (m->session_id));
358 GNUNET_NO);
359 GAS_addresses_destroy (&m->peer,
360 plugin_name,
361 address,
362 address_length,
363 ntohl (m->session_id));
364 if (0 != ntohl (m->session_id)) 347 if (0 != ntohl (m->session_id))
365 { 348 {
366 srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); 349 srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
367 srm.header.size = ntohs (sizeof (struct SessionReleaseMessage)); 350 srm.header.size = ntohs (sizeof (struct SessionReleaseMessage));
368 srm.session_id = m->session_id; 351 srm.session_id = m->session_id;
369 srm.peer = m->peer; 352 srm.peer = m->peer;
370 GNUNET_SERVER_notification_context_unicast (nc, 353 GNUNET_SERVER_notification_context_unicast (nc, client, &srm.header,
371 client, 354 GNUNET_NO);
372 &srm.header,
373 GNUNET_NO);
374 } 355 }
375 GNUNET_SERVER_receive_done (client, GNUNET_OK); 356 GNUNET_SERVER_receive_done (client, GNUNET_OK);
376} 357}
@@ -382,7 +363,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
382 * @param server handle to our server 363 * @param server handle to our server
383 */ 364 */
384void 365void
385GAS_scheduling_init (struct GNUNET_SERVER_Handle *server) 366GAS_scheduling_init (struct GNUNET_SERVER_Handle *server)
386{ 367{
387 nc = GNUNET_SERVER_notification_context_create (server, 128); 368 nc = GNUNET_SERVER_notification_context_create (server, 128);
388} 369}
diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h
index 7eeaba8b3..44ac705e3 100644
--- a/src/ats/gnunet-service-ats_scheduling.h
+++ b/src/ats/gnunet-service-ats_scheduling.h
@@ -34,7 +34,7 @@
34 * Register a new scheduling client. 34 * Register a new scheduling client.
35 * 35 *
36 * @param client handle of the new client 36 * @param client handle of the new client
37 * @return GNUNET_OK on success, GNUNET_SYSERR on error 37 * @return GNUNET_OK on success, GNUNET_SYSERR on error
38 */ 38 */
39int 39int
40GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client); 40GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client);
@@ -65,14 +65,17 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client);
65 * @param bandwidth_in assigned inbound bandwidth 65 * @param bandwidth_in assigned inbound bandwidth
66 */ 66 */
67void 67void
68GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer, 68GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity
69 const char *plugin_name, 69 *peer, const char *plugin_name,
70 const void *plugin_addr, size_t plugin_addr_len, 70 const void *plugin_addr,
71 uint32_t session_id, 71 size_t plugin_addr_len,
72 const struct GNUNET_ATS_Information *atsi, 72 uint32_t session_id,
73 uint32_t atsi_count, 73 const struct GNUNET_ATS_Information
74 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 74 *atsi, uint32_t atsi_count,
75 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); 75 struct GNUNET_BANDWIDTH_Value32NBO
76 bandwidth_out,
77 struct GNUNET_BANDWIDTH_Value32NBO
78 bandwidth_in);
76 79
77 80
78/** 81/**
@@ -84,7 +87,7 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
84 */ 87 */
85void 88void
86GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, 89GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
87 const struct GNUNET_MessageHeader *message); 90 const struct GNUNET_MessageHeader *message);
88 91
89 92
90 93
@@ -97,7 +100,7 @@ GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
97 */ 100 */
98void 101void
99GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, 102GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
100 const struct GNUNET_MessageHeader *message); 103 const struct GNUNET_MessageHeader *message);
101 104
102 105
103/** 106/**
@@ -120,7 +123,7 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
120 */ 123 */
121void 124void
122GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, 125GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
123 const struct GNUNET_MessageHeader *message); 126 const struct GNUNET_MessageHeader *message);
124 127
125 128
126/** 129/**
diff --git a/src/ats/test_ats_api_bandwidth_consumption.c b/src/ats/test_ats_api_bandwidth_consumption.c
index d2a7b53dc..1eb57fcc8 100644
--- a/src/ats/test_ats_api_bandwidth_consumption.c
+++ b/src/ats/test_ats_api_bandwidth_consumption.c
@@ -44,9 +44,9 @@ static struct GNUNET_ATS_PerformanceHandle *atp;
44 44
45struct GNUNET_ATS_ReservationContext *sh; 45struct GNUNET_ATS_ReservationContext *sh;
46 46
47static struct GNUNET_OS_Process * arm_proc; 47static struct GNUNET_OS_Process *arm_proc;
48 48
49static struct PeerContext * p; 49static struct PeerContext *p;
50 50
51static uint32_t bw_in; 51static uint32_t bw_in;
52 52
@@ -56,23 +56,23 @@ static int ret;
56 56
57struct Address 57struct Address
58{ 58{
59 char * plugin; 59 char *plugin;
60 size_t plugin_len; 60 size_t plugin_len;
61 61
62 void * addr; 62 void *addr;
63 size_t addr_len; 63 size_t addr_len;
64 64
65 struct GNUNET_ATS_Information * ats; 65 struct GNUNET_ATS_Information *ats;
66 int ats_count; 66 int ats_count;
67 67
68 void *session; 68 void *session;
69}; 69};
70 70
71struct PeerContext 71struct PeerContext
72{ 72{
73 struct GNUNET_PeerIdentity id; 73 struct GNUNET_PeerIdentity id;
74 74
75 struct Address * addr; 75 struct Address *addr;
76}; 76};
77 77
78 78
@@ -94,12 +94,12 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94 94
95 if (consume_task != GNUNET_SCHEDULER_NO_TASK) 95 if (consume_task != GNUNET_SCHEDULER_NO_TASK)
96 { 96 {
97 GNUNET_SCHEDULER_cancel(consume_task); 97 GNUNET_SCHEDULER_cancel (consume_task);
98 consume_task = GNUNET_SCHEDULER_NO_TASK; 98 consume_task = GNUNET_SCHEDULER_NO_TASK;
99 } 99 }
100 100
101 if (sh != NULL) 101 if (sh != NULL)
102 GNUNET_ATS_reserve_bandwidth_cancel(sh); 102 GNUNET_ATS_reserve_bandwidth_cancel (sh);
103 103
104 if (ats != NULL) 104 if (ats != NULL)
105 GNUNET_ATS_scheduling_done (ats); 105 GNUNET_ATS_scheduling_done (ats);
@@ -120,13 +120,13 @@ end ()
120{ 120{
121 if (die_task != GNUNET_SCHEDULER_NO_TASK) 121 if (die_task != GNUNET_SCHEDULER_NO_TASK)
122 { 122 {
123 GNUNET_SCHEDULER_cancel(die_task); 123 GNUNET_SCHEDULER_cancel (die_task);
124 die_task = GNUNET_SCHEDULER_NO_TASK; 124 die_task = GNUNET_SCHEDULER_NO_TASK;
125 } 125 }
126 126
127 if (consume_task != GNUNET_SCHEDULER_NO_TASK) 127 if (consume_task != GNUNET_SCHEDULER_NO_TASK)
128 { 128 {
129 GNUNET_SCHEDULER_cancel(consume_task); 129 GNUNET_SCHEDULER_cancel (consume_task);
130 consume_task = GNUNET_SCHEDULER_NO_TASK; 130 consume_task = GNUNET_SCHEDULER_NO_TASK;
131 } 131 }
132 132
@@ -142,41 +142,25 @@ end ()
142 stop_arm (); 142 stop_arm ();
143} 143}
144 144
145void performance_cb (void *cls, 145void
146 const struct 146performance_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
147 GNUNET_PeerIdentity * 147 const char *plugin_name, const void *plugin_addr,
148 peer, 148 size_t plugin_addr_len,
149 const char *plugin_name, 149 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
150 const void *plugin_addr, 150 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
151 size_t plugin_addr_len, 151 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
152 struct
153 GNUNET_BANDWIDTH_Value32NBO
154 bandwidth_out,
155 struct
156 GNUNET_BANDWIDTH_Value32NBO
157 bandwidth_in,
158 const struct
159 GNUNET_ATS_Information
160 * ats,
161 uint32_t ats_count)
162{ 152{
163 153
164} 154}
165 155
166void reservation_cb (void *cls, 156void
167 const struct 157reservation_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
168 GNUNET_PeerIdentity * 158 int32_t amount, struct GNUNET_TIME_Relative res_delay)
169 peer,
170 int32_t amount,
171 struct
172 GNUNET_TIME_Relative
173 res_delay)
174{ 159{
175 sh = NULL; 160 sh = NULL;
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS reserved bandwidth of %i to peer `%s' in %llu ms\n", 161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
177 amount, 162 "ATS reserved bandwidth of %i to peer `%s' in %llu ms\n", amount,
178 GNUNET_i2s (peer), 163 GNUNET_i2s (peer), res_delay.rel_value);
179 res_delay.rel_value);
180} 164}
181 165
182static void 166static void
@@ -184,51 +168,43 @@ consume_bandwidth (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184{ 168{
185 consume_task = GNUNET_SCHEDULER_NO_TASK; 169 consume_task = GNUNET_SCHEDULER_NO_TASK;
186 int32_t to_reserve = 500; 170 int32_t to_reserve = 500;
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to reserver bandwidth of %i to peer `%s' in %llu ms\n",
188 to_reserve,
189 GNUNET_i2s (&p->id));
190 171
191 sh = GNUNET_ATS_reserve_bandwidth (atp, &p->id, to_reserve, &reservation_cb, NULL); 172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
173 "Trying to reserver bandwidth of %i to peer `%s' in %llu ms\n",
174 to_reserve, GNUNET_i2s (&p->id));
175
176 sh = GNUNET_ATS_reserve_bandwidth (atp, &p->id, to_reserve, &reservation_cb,
177 NULL);
192} 178}
193 179
194static void 180static void
195address_suggest_cb (void *cls, 181address_suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
196 const struct 182 const char *plugin_name, const void *plugin_addr,
197 GNUNET_PeerIdentity * 183 size_t plugin_addr_len, struct Session *session,
198 peer, 184 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
199 const char *plugin_name, 185 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
200 const void *plugin_addr, 186 const struct GNUNET_ATS_Information *ats,
201 size_t plugin_addr_len,
202 struct Session * session,
203 struct
204 GNUNET_BANDWIDTH_Value32NBO
205 bandwidth_out,
206 struct
207 GNUNET_BANDWIDTH_Value32NBO
208 bandwidth_in,
209 const struct
210 GNUNET_ATS_Information
211 * ats,
212 uint32_t ats_count) 187 uint32_t ats_count)
213
214{ 188{
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n", GNUNET_i2s (peer)); 189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n",
190 GNUNET_i2s (peer));
216 191
217 bw_in = ntohl (bandwidth_in.value__); 192 bw_in = ntohl (bandwidth_in.value__);
218 bw_out = ntohl (bandwidth_out.value__); 193 bw_out = ntohl (bandwidth_out.value__);
219 194
220 consume_task = GNUNET_SCHEDULER_add_now(&consume_bandwidth, NULL); 195 consume_task = GNUNET_SCHEDULER_add_now (&consume_bandwidth, NULL);
221} 196}
222 197
223void 198void
224start_arm (const char *cfgname) 199start_arm (const char *cfgname)
225{ 200{
226 arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 201 arm_proc =
227 "gnunet-service-arm", 202 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
203 "gnunet-service-arm",
228#if VERBOSE_ARM 204#if VERBOSE_ARM
229 "-L", "DEBUG", 205 "-L", "DEBUG",
230#endif 206#endif
231 "-c", cfgname, NULL); 207 "-c", cfgname, NULL);
232} 208}
233 209
234static void 210static void
@@ -238,7 +214,7 @@ check (void *cls, char *const *args, const char *cfgfile,
238 ret = GNUNET_SYSERR; 214 ret = GNUNET_SYSERR;
239 struct Address *addr; 215 struct Address *addr;
240 216
241 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); 217 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
242 start_arm (cfgfile); 218 start_arm (cfgfile);
243 219
244 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); 220 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
@@ -257,25 +233,28 @@ check (void *cls, char *const *args, const char *cfgfile,
257 { 233 {
258 ret = GNUNET_SYSERR; 234 ret = GNUNET_SYSERR;
259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init ATS performance\n"); 235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init ATS performance\n");
260 end_badly(NULL, NULL); 236 end_badly (NULL, NULL);
261 GNUNET_free (p); 237 GNUNET_free (p);
262 GNUNET_free (addr); 238 GNUNET_free (addr);
263 return; 239 return;
264 } 240 }
265 241
266 /* set up peer */ 242 /* set up peer */
267 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p->id.hashPubKey); 243 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
244 &p->id.hashPubKey);
268 245
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p->id)); 246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
247 GNUNET_i2s (&p->id));
270 p->addr = addr; 248 p->addr = addr;
271 addr->plugin = "test"; 249 addr->plugin = "test";
272 addr->session = NULL; 250 addr->session = NULL;
273 addr->addr = NULL; 251 addr->addr = NULL;
274 addr->addr_len = 0; 252 addr->addr_len = 0;
275 253
276 GNUNET_ATS_address_update(ats, &p->id, addr->plugin, addr->addr, addr->addr_len, addr->session, NULL, 0); 254 GNUNET_ATS_address_update (ats, &p->id, addr->plugin, addr->addr,
255 addr->addr_len, addr->session, NULL, 0);
277 256
278 GNUNET_ATS_suggest_address(ats, &p->id); 257 GNUNET_ATS_suggest_address (ats, &p->id);
279} 258}
280 259
281int 260int
@@ -297,8 +276,8 @@ main (int argc, char *argv[])
297 }; 276 };
298 277
299 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 278 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
300 "test_ats_api_bandwidth_consumption", "nohelp", options, &check, 279 "test_ats_api_bandwidth_consumption", "nohelp", options,
301 NULL); 280 &check, NULL);
302 281
303 282
304 return ret; 283 return ret;
diff --git a/src/ats/test_ats_api_scheduling.c b/src/ats/test_ats_api_scheduling.c
index 201855283..a2ee7f060 100644
--- a/src/ats/test_ats_api_scheduling.c
+++ b/src/ats/test_ats_api_scheduling.c
@@ -44,7 +44,7 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task;
44 44
45static struct GNUNET_ATS_SchedulingHandle *ats; 45static struct GNUNET_ATS_SchedulingHandle *ats;
46 46
47struct GNUNET_OS_Process * arm_proc; 47struct GNUNET_OS_Process *arm_proc;
48 48
49 49
50 50
@@ -52,23 +52,23 @@ static int ret;
52 52
53struct Address 53struct Address
54{ 54{
55 char * plugin; 55 char *plugin;
56 size_t plugin_len; 56 size_t plugin_len;
57 57
58 void * addr; 58 void *addr;
59 size_t addr_len; 59 size_t addr_len;
60 60
61 struct GNUNET_ATS_Information * ats; 61 struct GNUNET_ATS_Information *ats;
62 int ats_count; 62 int ats_count;
63 63
64 void *session; 64 void *session;
65}; 65};
66 66
67struct PeerContext 67struct PeerContext
68{ 68{
69 struct GNUNET_PeerIdentity id; 69 struct GNUNET_PeerIdentity id;
70 70
71 struct Address * addr; 71 struct Address *addr;
72}; 72};
73 73
74struct Address addr[2]; 74struct Address addr[2];
@@ -105,7 +105,7 @@ end ()
105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); 105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
106 if (die_task != GNUNET_SCHEDULER_NO_TASK) 106 if (die_task != GNUNET_SCHEDULER_NO_TASK)
107 { 107 {
108 GNUNET_SCHEDULER_cancel(die_task); 108 GNUNET_SCHEDULER_cancel (die_task);
109 die_task = GNUNET_SCHEDULER_NO_TASK; 109 die_task = GNUNET_SCHEDULER_NO_TASK;
110 } 110 }
111 111
@@ -118,29 +118,19 @@ end ()
118 118
119 119
120static void 120static void
121address_suggest_cb (void *cls, 121address_suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
122 const struct 122 const char *plugin_name, const void *plugin_addr,
123 GNUNET_PeerIdentity * 123 size_t plugin_addr_len, struct Session *session,
124 peer, 124 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
125 const char *plugin_name, 125 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
126 const void *plugin_addr, 126 const struct GNUNET_ATS_Information *ats,
127 size_t plugin_addr_len,
128 struct Session * session,
129 struct
130 GNUNET_BANDWIDTH_Value32NBO
131 bandwidth_out,
132 struct
133 GNUNET_BANDWIDTH_Value32NBO
134 bandwidth_in,
135 const struct
136 GNUNET_ATS_Information
137 * ats,
138 uint32_t ats_count) 127 uint32_t ats_count)
139
140{ 128{
141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n", GNUNET_i2s (peer)); 129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n",
130 GNUNET_i2s (peer));
142 131
143 GNUNET_assert (0 == memcmp (peer, &p[0].id, sizeof (struct GNUNET_PeerIdentity))); 132 GNUNET_assert (0 ==
133 memcmp (peer, &p[0].id, sizeof (struct GNUNET_PeerIdentity)));
144 GNUNET_assert (0 == strcmp (plugin_name, addr[0].plugin)); 134 GNUNET_assert (0 == strcmp (plugin_name, addr[0].plugin));
145 GNUNET_assert (plugin_addr_len == addr[0].addr_len); 135 GNUNET_assert (plugin_addr_len == addr[0].addr_len);
146 GNUNET_assert (0 == memcmp (plugin_addr, addr[0].plugin, plugin_addr_len)); 136 GNUNET_assert (0 == memcmp (plugin_addr, addr[0].plugin, plugin_addr_len));
@@ -148,27 +138,28 @@ address_suggest_cb (void *cls,
148 138
149 139
150 /* TODO ats merge 140 /* TODO ats merge
151 GNUNET_assert (ats_count == 2); 141 * GNUNET_assert (ats_count == 2);
152 GNUNET_assert (atsi[0].type == htons (1)); 142 * GNUNET_assert (atsi[0].type == htons (1));
153 GNUNET_assert (atsi[0].type == htons (2)); 143 * GNUNET_assert (atsi[0].type == htons (2));
154 GNUNET_assert (atsi[1].type == htons (2)); 144 * GNUNET_assert (atsi[1].type == htons (2));
155 GNUNET_assert (atsi[1].type == htons (2)); 145 * GNUNET_assert (atsi[1].type == htons (2));
156 */ 146 */
157 147
158 ret = 0; 148 ret = 0;
159 149
160 GNUNET_SCHEDULER_add_now(&end, NULL); 150 GNUNET_SCHEDULER_add_now (&end, NULL);
161} 151}
162 152
163void 153void
164start_arm (const char *cfgname) 154start_arm (const char *cfgname)
165{ 155{
166 arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 156 arm_proc =
167 "gnunet-service-arm", 157 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
158 "gnunet-service-arm",
168#if VERBOSE_ARM 159#if VERBOSE_ARM
169 "-L", "DEBUG", 160 "-L", "DEBUG",
170#endif 161#endif
171 "-c", cfgname, NULL); 162 "-c", cfgname, NULL);
172} 163}
173 164
174static void 165static void
@@ -177,7 +168,7 @@ check (void *cls, char *const *args, const char *cfgfile,
177{ 168{
178 ret = GNUNET_SYSERR; 169 ret = GNUNET_SYSERR;
179 170
180 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); 171 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
181 start_arm (cfgfile); 172 start_arm (cfgfile);
182 173
183 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); 174 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
@@ -190,27 +181,33 @@ check (void *cls, char *const *args, const char *cfgfile,
190 } 181 }
191 182
192 /* set up peer */ 183 /* set up peer */
193 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[0].id.hashPubKey); 184 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p[0].id)); 185 &p[0].id.hashPubKey);
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
187 GNUNET_i2s (&p[0].id));
195 188
196 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[1].id.hashPubKey); 189 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p[1].id)); 190 &p[1].id.hashPubKey);
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
192 GNUNET_i2s (&p[1].id));
198 193
199 addr[0].plugin = "test"; 194 addr[0].plugin = "test";
200 addr[0].session = NULL; 195 addr[0].session = NULL;
201 addr[0].addr = strdup("test"); 196 addr[0].addr = strdup ("test");
202 addr[0].addr_len = 4; 197 addr[0].addr_len = 4;
203 198
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing address creation\n"); 199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing address creation\n");
205 200
206 GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, NULL, 0); 201 GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr,
202 addr[0].addr_len, addr[0].session, NULL, 0);
207 203
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info creation\n"); 204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info creation\n");
209 205
210 atsi[0].type = htonl (GNUNET_ATS_UTILIZATION_UP); 206 atsi[0].type = htonl (GNUNET_ATS_UTILIZATION_UP);
211 atsi[0].value = htonl (1024); 207 atsi[0].value = htonl (1024);
212 208
213 GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, atsi, 1); 209 GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr,
210 addr[0].addr_len, addr[0].session, atsi, 1);
214 211
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info update\n"); 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info update\n");
216 213
@@ -220,14 +217,18 @@ check (void *cls, char *const *args, const char *cfgfile,
220 atsi[1].type = htonl (GNUNET_ATS_UTILIZATION_DOWN); 217 atsi[1].type = htonl (GNUNET_ATS_UTILIZATION_DOWN);
221 atsi[1].value = htonl (1024); 218 atsi[1].value = htonl (1024);
222 219
223 GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, atsi, 2); 220 GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr,
221 addr[0].addr_len, addr[0].session, atsi, 2);
224 222
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing manual address deletion \n"); 223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing manual address deletion \n");
226 GNUNET_ATS_address_update(ats, &p[1].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, NULL, 0); 224 GNUNET_ATS_address_update (ats, &p[1].id, addr[0].plugin, addr[0].addr,
227 GNUNET_ATS_address_destroyed (ats, &p[1].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session ); 225 addr[0].addr_len, addr[0].session, NULL, 0);
228 226 GNUNET_ATS_address_destroyed (ats, &p[1].id, addr[0].plugin, addr[0].addr,
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", GNUNET_i2s (&p[0].id)); 227 addr[0].addr_len, addr[0].session);
230 GNUNET_ATS_suggest_address(ats, &p[0].id); 228
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n",
230 GNUNET_i2s (&p[0].id));
231 GNUNET_ATS_suggest_address (ats, &p[0].id);
231} 232}
232 233
233int 234int
diff --git a/src/ats/test_ats_api_update_address.c b/src/ats/test_ats_api_update_address.c
index 78011d492..f23747962 100644
--- a/src/ats/test_ats_api_update_address.c
+++ b/src/ats/test_ats_api_update_address.c
@@ -121,8 +121,7 @@ suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
121 const char *plugin_name, const void *plugin_addr, 121 const char *plugin_name, const void *plugin_addr,
122 size_t plugin_addr_len, struct Session *session, 122 size_t plugin_addr_len, struct Session *session,
123 struct GNUNET_BANDWIDTH_Value32NBO bandwidth, 123 struct GNUNET_BANDWIDTH_Value32NBO bandwidth,
124 const struct GNUNET_ATS_Information *ats, 124 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
125 uint32_t ats_count)
126{ 125{
127 struct ExpectedValues *ex = cls; 126 struct ExpectedValues *ex = cls;
128 127