aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/ats_api.c')
-rw-r--r--src/ats/ats_api.c160
1 files changed, 74 insertions, 86 deletions
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