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.c371
1 files changed, 161 insertions, 210 deletions
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c
index 9400b1f30..6cd8a82ba 100644
--- a/src/ats/ats_api.c
+++ b/src/ats/ats_api.c
@@ -67,7 +67,7 @@ struct AllocationRecord
67 /** 67 /**
68 * Number of bytes in plugin_addr. 68 * Number of bytes in plugin_addr.
69 */ 69 */
70 size_t plugin_addr_len; 70 size_t plugin_addr_len;
71 71
72 /** 72 /**
73 * Number of entries in 'ats'. 73 * Number of entries in 'ats'.
@@ -105,12 +105,12 @@ struct GNUNET_ATS_SuggestionContext
105 105
106 /** 106 /**
107 * Global ATS handle. 107 * Global ATS handle.
108 */ 108 */
109 struct GNUNET_ATS_Handle *atc; 109 struct GNUNET_ATS_Handle *atc;
110 110
111 /** 111 /**
112 * Which peer are we monitoring? 112 * Which peer are we monitoring?
113 */ 113 */
114 struct GNUNET_PeerIdentity target; 114 struct GNUNET_PeerIdentity target;
115 115
116}; 116};
@@ -169,13 +169,11 @@ struct GNUNET_ATS_Handle
169 * @return GNUNET_YES (continue iteration) 169 * @return GNUNET_YES (continue iteration)
170 */ 170 */
171static int 171static int
172count_connections (void *cls, 172count_connections (void *cls, const GNUNET_HashCode * key, void *value)
173 const GNUNET_HashCode *key,
174 void *value)
175{ 173{
176 unsigned int *ac = cls; 174 unsigned int *ac = cls;
177 struct AllocationRecord *ar = value; 175 struct AllocationRecord *ar = value;
178 176
179 if (GNUNET_YES == ar->connected) 177 if (GNUNET_YES == ar->connected)
180 (*ac)++; 178 (*ac)++;
181 return GNUNET_YES; 179 return GNUNET_YES;
@@ -208,35 +206,29 @@ struct SetBandwidthContext
208 * @return GNUNET_YES (continue iteration) 206 * @return GNUNET_YES (continue iteration)
209 */ 207 */
210static int 208static int
211set_bw_connections (void *cls, 209set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
212 const GNUNET_HashCode *key,
213 void *value)
214{ 210{
215 struct SetBandwidthContext *sbc = cls; 211 struct SetBandwidthContext *sbc = cls;
216 struct AllocationRecord *ar = value; 212 struct AllocationRecord *ar = value;
217 213
218 if (GNUNET_YES == ar->connected) 214 if (GNUNET_YES == ar->connected)
219 { 215 {
220 ar->bandwidth = sbc->bw; 216 ar->bandwidth = sbc->bw;
221 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, 217 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
222 (const struct GNUNET_PeerIdentity*) key, 218 (const struct GNUNET_PeerIdentity *) key,
223 ar->plugin_name, 219 ar->plugin_name,
224 ar->session, 220 ar->session,
225 ar->plugin_addr, 221 ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
226 ar->plugin_addr_len, 222 }
227 ar->bandwidth); 223 else if (ntohl (ar->bandwidth.value__) > 0)
228 } 224 {
229 else if (ntohl(ar->bandwidth.value__) > 0) 225 ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
230 { 226 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
231 ar->bandwidth = GNUNET_BANDWIDTH_value_init (0); 227 (const struct GNUNET_PeerIdentity *) key,
232 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, 228 ar->plugin_name,
233 (const struct GNUNET_PeerIdentity*) key, 229 ar->session,
234 ar->plugin_name, 230 ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
235 ar->session, 231 }
236 ar->plugin_addr,
237 ar->plugin_addr_len,
238 ar->bandwidth);
239 }
240 return GNUNET_YES; 232 return GNUNET_YES;
241} 233}
242 234
@@ -246,10 +238,9 @@ set_bw_connections (void *cls,
246 * 238 *
247 * @param cls the 'struct GNUNET_ATS_Handle' 239 * @param cls the 'struct GNUNET_ATS_Handle'
248 * @param tc scheduler context 240 * @param tc scheduler context
249 */ 241 */
250static void 242static void
251update_bandwidth_task (void *cls, 243update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
252 const struct GNUNET_SCHEDULER_TaskContext *tc)
253{ 244{
254 struct GNUNET_ATS_Handle *atc = cls; 245 struct GNUNET_ATS_Handle *atc = cls;
255 unsigned int ac; 246 unsigned int ac;
@@ -257,14 +248,10 @@ update_bandwidth_task (void *cls,
257 248
258 atc->ba_task = GNUNET_SCHEDULER_NO_TASK; 249 atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
259 /* FIXME: update calculations NICELY; what follows is a naive version */ 250 /* FIXME: update calculations NICELY; what follows is a naive version */
260 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 251 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &count_connections, &ac);
261 &count_connections,
262 &ac);
263 bwc.atc = atc; 252 bwc.atc = atc;
264 bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac); 253 bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac);
265 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 254 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc);
266 &set_bw_connections,
267 &bwc);
268} 255}
269 256
270 257
@@ -276,12 +263,11 @@ update_bandwidth_task (void *cls,
276 */ 263 */
277static void 264static void
278update_bandwidth_assignment (struct GNUNET_ATS_Handle *atc, 265update_bandwidth_assignment (struct GNUNET_ATS_Handle *atc,
279 struct AllocationRecord *change) 266 struct AllocationRecord *change)
280{ 267{
281 /* FIXME: based on the 'change', update the LP-problem... */ 268 /* FIXME: based on the 'change', update the LP-problem... */
282 if (atc->ba_task == GNUNET_SCHEDULER_NO_TASK) 269 if (atc->ba_task == GNUNET_SCHEDULER_NO_TASK)
283 atc->ba_task = GNUNET_SCHEDULER_add_now (&update_bandwidth_task, 270 atc->ba_task = GNUNET_SCHEDULER_add_now (&update_bandwidth_task, atc);
284 atc);
285} 271}
286 272
287 273
@@ -294,21 +280,19 @@ update_bandwidth_assignment (struct GNUNET_ATS_Handle *atc,
294 * @return GNUNET_NO if we're done, GNUNET_YES if we did not suggest an address yet 280 * @return GNUNET_NO if we're done, GNUNET_YES if we did not suggest an address yet
295 */ 281 */
296static int 282static int
297suggest_address (void *cls, 283suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
298 const GNUNET_HashCode *key,
299 void *value)
300{ 284{
301 struct GNUNET_ATS_SuggestionContext *asc = cls; 285 struct GNUNET_ATS_SuggestionContext *asc = cls;
302 struct AllocationRecord *ar = value; 286 struct AllocationRecord *ar = value;
303 287
304 /* trivial strategy: pick first available address... */ 288 /* trivial strategy: pick first available address... */
305 asc->cb (asc->cb_cls, 289 asc->cb (asc->cb_cls,
306 &asc->target, 290 &asc->target,
307 ar->plugin_name, 291 ar->plugin_name,
308 ar->plugin_addr, 292 ar->plugin_addr,
309 ar->plugin_addr_len, 293 ar->plugin_addr_len,
310 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), 294 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
311 ar->ats, ar->ats_count); 295 ar->ats, ar->ats_count);
312 asc->cb = NULL; 296 asc->cb = NULL;
313 return GNUNET_NO; 297 return GNUNET_NO;
314} 298}
@@ -325,9 +309,9 @@ suggest_address (void *cls,
325 */ 309 */
326struct GNUNET_ATS_SuggestionContext * 310struct GNUNET_ATS_SuggestionContext *
327GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc, 311GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
328 const struct GNUNET_PeerIdentity *peer, 312 const struct GNUNET_PeerIdentity *peer,
329 GNUNET_ATS_AddressSuggestionCallback cb, 313 GNUNET_ATS_AddressSuggestionCallback cb,
330 void *cb_cls) 314 void *cb_cls)
331{ 315{
332 struct GNUNET_ATS_SuggestionContext *asc; 316 struct GNUNET_ATS_SuggestionContext *asc;
333 317
@@ -338,17 +322,16 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
338 asc->target = *peer; 322 asc->target = *peer;
339 GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, 323 GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
340 &peer->hashPubKey, 324 &peer->hashPubKey,
341 &suggest_address, 325 &suggest_address, asc);
342 asc);
343 if (NULL == asc->cb) 326 if (NULL == asc->cb)
344 { 327 {
345 GNUNET_free (asc); 328 GNUNET_free (asc);
346 return NULL; 329 return NULL;
347 } 330 }
348 GNUNET_CONTAINER_multihashmap_put (atc->notify_map, 331 GNUNET_CONTAINER_multihashmap_put (atc->notify_map,
349 &peer->hashPubKey, 332 &peer->hashPubKey,
350 asc, 333 asc,
351 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 334 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
352 return asc; 335 return asc;
353} 336}
354 337
@@ -362,9 +345,9 @@ void
362GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc) 345GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc)
363{ 346{
364 GNUNET_assert (GNUNET_OK == 347 GNUNET_assert (GNUNET_OK ==
365 GNUNET_CONTAINER_multihashmap_remove (asc->atc->notify_map, 348 GNUNET_CONTAINER_multihashmap_remove (asc->atc->notify_map,
366 &asc->target.hashPubKey, 349 &asc->target.hashPubKey,
367 asc)); 350 asc));
368 GNUNET_free (asc); 351 GNUNET_free (asc);
369} 352}
370 353
@@ -379,8 +362,8 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc)
379 */ 362 */
380struct GNUNET_ATS_Handle * 363struct GNUNET_ATS_Handle *
381GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 364GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
382 GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb, 365 GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb,
383 void *alloc_cb_cls) 366 void *alloc_cb_cls)
384{ 367{
385 struct GNUNET_ATS_Handle *atc; 368 struct GNUNET_ATS_Handle *atc;
386 369
@@ -390,9 +373,8 @@ GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
390 atc->alloc_cb_cls = alloc_cb_cls; 373 atc->alloc_cb_cls = alloc_cb_cls;
391 atc->peers = GNUNET_CONTAINER_multihashmap_create (256); 374 atc->peers = GNUNET_CONTAINER_multihashmap_create (256);
392 GNUNET_CONFIGURATION_get_value_number (cfg, 375 GNUNET_CONFIGURATION_get_value_number (cfg,
393 "core", 376 "core",
394 "TOTAL_QUOTA_OUT", 377 "TOTAL_QUOTA_OUT", &atc->total_bps);
395 &atc->total_bps);
396 return atc; 378 return atc;
397} 379}
398 380
@@ -406,9 +388,7 @@ GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
406 * @return GNUNET_OK (continue to iterate) 388 * @return GNUNET_OK (continue to iterate)
407 */ 389 */
408static int 390static int
409destroy_allocation_record (void *cls, 391destroy_allocation_record (void *cls, const GNUNET_HashCode * key, void *value)
410 const GNUNET_HashCode *key,
411 void *value)
412{ 392{
413 struct AllocationRecord *ar = value; 393 struct AllocationRecord *ar = value;
414 394
@@ -428,13 +408,12 @@ void
428GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc) 408GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc)
429{ 409{
430 if (GNUNET_SCHEDULER_NO_TASK != atc->ba_task) 410 if (GNUNET_SCHEDULER_NO_TASK != atc->ba_task)
431 { 411 {
432 GNUNET_SCHEDULER_cancel (atc->ba_task); 412 GNUNET_SCHEDULER_cancel (atc->ba_task);
433 atc->ba_task = GNUNET_SCHEDULER_NO_TASK; 413 atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
434 } 414 }
435 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 415 GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
436 &destroy_allocation_record, 416 &destroy_allocation_record, NULL);
437 NULL);
438 GNUNET_CONTAINER_multihashmap_destroy (atc->peers); 417 GNUNET_CONTAINER_multihashmap_destroy (atc->peers);
439 GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0); 418 GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0);
440 GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map); 419 GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map);
@@ -470,9 +449,7 @@ struct UpdateSessionContext
470 * GNUNET_NO if the record do match and 'old' was updated 449 * GNUNET_NO if the record do match and 'old' was updated
471 */ 450 */
472static int 451static int
473update_session (void *cls, 452update_session (void *cls, const GNUNET_HashCode * key, void *value)
474 const GNUNET_HashCode *key,
475 void *value)
476{ 453{
477 struct UpdateSessionContext *usc = cls; 454 struct UpdateSessionContext *usc = cls;
478 struct AllocationRecord *arnew = usc->arnew; 455 struct AllocationRecord *arnew = usc->arnew;
@@ -481,32 +458,30 @@ update_session (void *cls,
481 458
482 if (0 != strcmp (arnew->plugin_name, arold->plugin_name)) 459 if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
483 return GNUNET_YES; 460 return GNUNET_YES;
484 if ( (arnew->session == arold->session) || 461 if ((arnew->session == arold->session) ||
485 ( (arold->session == NULL) && 462 ((arold->session == NULL) &&
486 (arold->plugin_addr_len == arnew->plugin_addr_len) && 463 (arold->plugin_addr_len == arnew->plugin_addr_len) &&
487 (0 == memcmp (arold->plugin_addr, 464 (0 == memcmp (arold->plugin_addr,
488 arnew->plugin_addr, 465 arnew->plugin_addr, arnew->plugin_addr_len))))
489 arnew->plugin_addr_len)) ) ) 466 {
467 change = GNUNET_NO;
468 /* records match */
469 if (arnew->session != arold->session)
470 {
471 arold->session = arnew->session;
472 change = GNUNET_YES;
473 }
474 if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO))
490 { 475 {
491 change = GNUNET_NO; 476 arold->connected = GNUNET_YES;
492 /* records match */ 477 change = GNUNET_YES;
493 if (arnew->session != arold->session)
494 {
495 arold->session = arnew->session;
496 change = GNUNET_YES;
497 }
498 if ( (arnew->connected == GNUNET_YES) &&
499 (arold->connected == GNUNET_NO) )
500 {
501 arold->connected = GNUNET_YES;
502 change = GNUNET_YES;
503 }
504 // FIXME: merge ats arrays of (arold, arnew);
505
506 if (GNUNET_YES == change)
507 update_bandwidth_assignment (usc->atc, arold);
508 return GNUNET_NO;
509 } 478 }
479 // FIXME: merge ats arrays of (arold, arnew);
480
481 if (GNUNET_YES == change)
482 update_bandwidth_assignment (usc->atc, arold);
483 return GNUNET_NO;
484 }
510 return GNUNET_YES; 485 return GNUNET_YES;
511} 486}
512 487
@@ -523,11 +498,11 @@ update_session (void *cls,
523 */ 498 */
524static struct AllocationRecord * 499static struct AllocationRecord *
525create_allocation_record (const char *plugin_name, 500create_allocation_record (const char *plugin_name,
526 struct Session *session, 501 struct Session *session,
527 const void *plugin_addr, 502 const void *plugin_addr,
528 size_t plugin_addr_len, 503 size_t plugin_addr_len,
529 const struct GNUNET_TRANSPORT_ATS_Information *ats, 504 const struct GNUNET_TRANSPORT_ATS_Information *ats,
530 uint32_t ats_count) 505 uint32_t ats_count)
531{ 506{
532 struct AllocationRecord *ar; 507 struct AllocationRecord *ar;
533 508
@@ -537,12 +512,9 @@ create_allocation_record (const char *plugin_name,
537 memcpy (&ar[1], plugin_addr, plugin_addr_len); 512 memcpy (&ar[1], plugin_addr, plugin_addr_len);
538 ar->session = session; 513 ar->session = session;
539 ar->plugin_addr_len = plugin_addr_len; 514 ar->plugin_addr_len = plugin_addr_len;
540 GNUNET_array_grow (ar->ats, 515 GNUNET_array_grow (ar->ats, ar->ats_count, ats_count);
541 ar->ats_count, 516 memcpy (ar->ats,
542 ats_count); 517 ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
543 memcpy (ar->ats,
544 ats,
545 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
546 return ar; 518 return ar;
547} 519}
548 520
@@ -556,18 +528,16 @@ create_allocation_record (const char *plugin_name,
556 * @return GNUNET_OK (continue to iterate) 528 * @return GNUNET_OK (continue to iterate)
557 */ 529 */
558static int 530static int
559disconnect_peer (void *cls, 531disconnect_peer (void *cls, const GNUNET_HashCode * key, void *value)
560 const GNUNET_HashCode *key,
561 void *value)
562{ 532{
563 struct GNUNET_ATS_Handle *atc = cls; 533 struct GNUNET_ATS_Handle *atc = cls;
564 struct AllocationRecord *ar = value; 534 struct AllocationRecord *ar = value;
565 535
566 if (GNUNET_YES == ar->connected) 536 if (GNUNET_YES == ar->connected)
567 { 537 {
568 ar->connected = GNUNET_NO; 538 ar->connected = GNUNET_NO;
569 update_bandwidth_assignment (atc, ar); 539 update_bandwidth_assignment (atc, ar);
570 } 540 }
571 return GNUNET_OK; 541 return GNUNET_OK;
572} 542}
573 543
@@ -588,42 +558,36 @@ disconnect_peer (void *cls,
588 */ 558 */
589void 559void
590GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, 560GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
591 const struct GNUNET_PeerIdentity *peer, 561 const struct GNUNET_PeerIdentity *peer,
592 const char *plugin_name, 562 const char *plugin_name,
593 struct Session *session, 563 struct Session *session,
594 const void *plugin_addr, 564 const void *plugin_addr,
595 size_t plugin_addr_len, 565 size_t plugin_addr_len,
596 const struct GNUNET_TRANSPORT_ATS_Information *ats, 566 const struct GNUNET_TRANSPORT_ATS_Information *ats,
597 uint32_t ats_count) 567 uint32_t ats_count)
598{ 568{
599 struct AllocationRecord *ar; 569 struct AllocationRecord *ar;
600 struct UpdateSessionContext usc; 570 struct UpdateSessionContext usc;
601 571
602 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 572 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
603 &disconnect_peer, 573 &disconnect_peer, atc);
604 atc);
605 ar = create_allocation_record (plugin_name, 574 ar = create_allocation_record (plugin_name,
606 session, 575 session,
607 plugin_addr, 576 plugin_addr, plugin_addr_len, ats, ats_count);
608 plugin_addr_len,
609 ats,
610 ats_count);
611 ar->connected = GNUNET_YES; 577 ar->connected = GNUNET_YES;
612 usc.atc = atc; 578 usc.atc = atc;
613 usc.arnew = ar; 579 usc.arnew = ar;
614 if (GNUNET_SYSERR == 580 if (GNUNET_SYSERR ==
615 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 581 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &update_session, &usc))
616 &update_session, 582 {
617 &usc)) 583 destroy_allocation_record (NULL, &peer->hashPubKey, ar);
618 { 584 return;
619 destroy_allocation_record (NULL, &peer->hashPubKey, ar); 585 }
620 return;
621 }
622 GNUNET_assert (GNUNET_OK == 586 GNUNET_assert (GNUNET_OK ==
623 GNUNET_CONTAINER_multihashmap_put (atc->peers, 587 GNUNET_CONTAINER_multihashmap_put (atc->peers,
624 &peer->hashPubKey, 588 &peer->hashPubKey,
625 ar, 589 ar,
626 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 590 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
627} 591}
628 592
629 593
@@ -637,12 +601,11 @@ GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
637 */ 601 */
638void 602void
639GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc, 603GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc,
640 const struct GNUNET_PeerIdentity *peer) 604 const struct GNUNET_PeerIdentity *peer)
641{ 605{
642 (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, 606 (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
643 &peer->hashPubKey, 607 &peer->hashPubKey,
644 &disconnect_peer, 608 &disconnect_peer, atc);
645 atc);
646} 609}
647 610
648 611
@@ -672,9 +635,7 @@ struct SessionDestroyContext
672 * @return GNUNET_OK (continue to iterate) 635 * @return GNUNET_OK (continue to iterate)
673 */ 636 */
674static int 637static int
675destroy_session (void *cls, 638destroy_session (void *cls, const GNUNET_HashCode * key, void *value)
676 const GNUNET_HashCode *key,
677 void *value)
678{ 639{
679 struct SessionDestroyContext *sdc = cls; 640 struct SessionDestroyContext *sdc = cls;
680 struct AllocationRecord *ar = value; 641 struct AllocationRecord *ar = value;
@@ -685,14 +646,13 @@ destroy_session (void *cls,
685 if (ar->plugin_addr != NULL) 646 if (ar->plugin_addr != NULL)
686 return GNUNET_OK; 647 return GNUNET_OK;
687 GNUNET_assert (GNUNET_OK == 648 GNUNET_assert (GNUNET_OK ==
688 GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers, 649 GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers,
689 key, 650 key, ar));
690 ar)); 651 if (GNUNET_YES == ar->connected) ;
691 if (GNUNET_YES == ar->connected); 652 {
692 { 653 /* FIXME: is this supposed to be allowed? What to do then? */
693 /* FIXME: is this supposed to be allowed? What to do then? */ 654 GNUNET_break (0);
694 GNUNET_break (0); 655 }
695 }
696 destroy_allocation_record (NULL, key, ar); 656 destroy_allocation_record (NULL, key, ar);
697 return GNUNET_OK; 657 return GNUNET_OK;
698} 658}
@@ -707,16 +667,15 @@ destroy_session (void *cls,
707 */ 667 */
708void 668void
709GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc, 669GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
710 const struct GNUNET_PeerIdentity *peer, 670 const struct GNUNET_PeerIdentity *peer,
711 const struct Session *session) 671 const struct Session *session)
712{ 672{
713 struct SessionDestroyContext sdc; 673 struct SessionDestroyContext sdc;
714 674
715 sdc.atc = atc; 675 sdc.atc = atc;
716 sdc.session = session; 676 sdc.session = session;
717 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 677 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
718 &destroy_session, 678 &destroy_session, &sdc);
719 &sdc);
720} 679}
721 680
722 681
@@ -729,20 +688,18 @@ GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
729 * @return GNUNET_YES (continue to iterate) 688 * @return GNUNET_YES (continue to iterate)
730 */ 689 */
731static int 690static int
732notify_valid (void *cls, 691notify_valid (void *cls, const GNUNET_HashCode * key, void *value)
733 const GNUNET_HashCode *key,
734 void *value)
735{ 692{
736 struct AllocationRecord *ar = cls; 693 struct AllocationRecord *ar = cls;
737 struct GNUNET_ATS_SuggestionContext *asc = value; 694 struct GNUNET_ATS_SuggestionContext *asc = value;
738 695
739 asc->cb (asc->cb_cls, 696 asc->cb (asc->cb_cls,
740 &asc->target, 697 &asc->target,
741 ar->plugin_name, 698 ar->plugin_name,
742 ar->plugin_addr, 699 ar->plugin_addr,
743 ar->plugin_addr_len, 700 ar->plugin_addr_len,
744 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), 701 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
745 ar->ats, ar->ats_count); 702 ar->ats, ar->ats_count);
746 GNUNET_ATS_suggest_address_cancel (asc); 703 GNUNET_ATS_suggest_address_cancel (asc);
747 return GNUNET_OK; 704 return GNUNET_OK;
748} 705}
@@ -768,43 +725,37 @@ notify_valid (void *cls,
768 */ 725 */
769void 726void
770GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, 727GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
771 const struct GNUNET_PeerIdentity *peer, 728 const struct GNUNET_PeerIdentity *peer,
772 struct GNUNET_TIME_Absolute valid_until, 729 struct GNUNET_TIME_Absolute valid_until,
773 const char *plugin_name, 730 const char *plugin_name,
774 struct Session *session, 731 struct Session *session,
775 const void *plugin_addr, 732 const void *plugin_addr,
776 size_t plugin_addr_len, 733 size_t plugin_addr_len,
777 const struct GNUNET_TRANSPORT_ATS_Information *ats, 734 const struct GNUNET_TRANSPORT_ATS_Information *ats,
778 uint32_t ats_count) 735 uint32_t ats_count)
779{ 736{
780 struct AllocationRecord *ar; 737 struct AllocationRecord *ar;
781 struct UpdateSessionContext usc; 738 struct UpdateSessionContext usc;
782 739
783 ar = create_allocation_record (plugin_name, 740 ar = create_allocation_record (plugin_name,
784 session, 741 session,
785 plugin_addr, 742 plugin_addr, plugin_addr_len, ats, ats_count);
786 plugin_addr_len,
787 ats,
788 ats_count);
789 usc.atc = atc; 743 usc.atc = atc;
790 usc.arnew = ar; 744 usc.arnew = ar;
791 if (GNUNET_SYSERR == 745 if (GNUNET_SYSERR ==
792 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 746 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &update_session, &usc))
793 &update_session, 747 {
794 &usc)) 748 destroy_allocation_record (NULL, &peer->hashPubKey, ar);
795 { 749 return;
796 destroy_allocation_record (NULL, &peer->hashPubKey, ar); 750 }
797 return;
798 }
799 GNUNET_assert (GNUNET_OK == 751 GNUNET_assert (GNUNET_OK ==
800 GNUNET_CONTAINER_multihashmap_put (atc->peers, 752 GNUNET_CONTAINER_multihashmap_put (atc->peers,
801 &peer->hashPubKey, 753 &peer->hashPubKey,
802 ar, 754 ar,
803 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 755 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
804 GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map, 756 GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map,
805 &peer->hashPubKey, 757 &peer->hashPubKey,
806 &notify_valid, 758 &notify_valid, ar);
807 ar);
808} 759}
809 760
810/* end of file gnunet-service-transport_ats.c */ 761/* end of file gnunet-service-transport_ats.c */