diff options
Diffstat (limited to 'src/ats/plugin_ats2_simple.c')
-rw-r--r-- | src/ats/plugin_ats2_simple.c | 718 |
1 files changed, 355 insertions, 363 deletions
diff --git a/src/ats/plugin_ats2_simple.c b/src/ats/plugin_ats2_simple.c index 14bd2b99d..90566c561 100644 --- a/src/ats/plugin_ats2_simple.c +++ b/src/ats/plugin_ats2_simple.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2015, 2018 GNUnet e.V. | 3 | Copyright (C) 2011-2015, 2018 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -31,7 +31,7 @@ | |||
31 | #include "gnunet_hello_lib.h" | 31 | #include "gnunet_hello_lib.h" |
32 | #include "gnunet_peerstore_service.h" | 32 | #include "gnunet_peerstore_service.h" |
33 | 33 | ||
34 | #define LOG(kind, ...) GNUNET_log_from (kind, "ats-simple", __VA_ARGS__) | 34 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-simple", __VA_ARGS__) |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
@@ -68,9 +68,7 @@ struct Peer; | |||
68 | /** | 68 | /** |
69 | * Entry in list of addresses we could try per peer. | 69 | * Entry in list of addresses we could try per peer. |
70 | */ | 70 | */ |
71 | struct Hello | 71 | struct Hello { |
72 | { | ||
73 | |||
74 | /** | 72 | /** |
75 | * Kept in a DLL. | 73 | * Kept in a DLL. |
76 | */ | 74 | */ |
@@ -123,9 +121,7 @@ struct Hello | |||
123 | * Internal representation of a session by the plugin. | 121 | * Internal representation of a session by the plugin. |
124 | * (If desired, plugin may just use NULL.) | 122 | * (If desired, plugin may just use NULL.) |
125 | */ | 123 | */ |
126 | struct GNUNET_ATS_SessionHandle | 124 | struct GNUNET_ATS_SessionHandle { |
127 | { | ||
128 | |||
129 | /** | 125 | /** |
130 | * Kept in DLL per peer. | 126 | * Kept in DLL per peer. |
131 | */ | 127 | */ |
@@ -193,9 +189,7 @@ struct GNUNET_ATS_SessionHandle | |||
193 | * Information about preferences and sessions we track | 189 | * Information about preferences and sessions we track |
194 | * per peer. | 190 | * per peer. |
195 | */ | 191 | */ |
196 | struct Peer | 192 | struct Peer { |
197 | { | ||
198 | |||
199 | /** | 193 | /** |
200 | * Kept in DLL per peer. | 194 | * Kept in DLL per peer. |
201 | */ | 195 | */ |
@@ -253,9 +247,7 @@ struct Peer | |||
253 | /** | 247 | /** |
254 | * Representation of a network (to be expanded...) | 248 | * Representation of a network (to be expanded...) |
255 | */ | 249 | */ |
256 | struct Network | 250 | struct Network { |
257 | { | ||
258 | |||
259 | /** | 251 | /** |
260 | * Total inbound quota | 252 | * Total inbound quota |
261 | */ | 253 | */ |
@@ -276,9 +268,7 @@ struct Network | |||
276 | /** | 268 | /** |
277 | * A handle for the proportional solver | 269 | * A handle for the proportional solver |
278 | */ | 270 | */ |
279 | struct SimpleHandle | 271 | struct SimpleHandle { |
280 | { | ||
281 | |||
282 | /** | 272 | /** |
283 | * Our execution environment. | 273 | * Our execution environment. |
284 | */ | 274 | */ |
@@ -316,9 +306,9 @@ struct SimpleHandle | |||
316 | * @return NULL for not found | 306 | * @return NULL for not found |
317 | */ | 307 | */ |
318 | struct Peer * | 308 | struct Peer * |
319 | lookup_peer (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) | 309 | lookup_peer(struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) |
320 | { | 310 | { |
321 | return GNUNET_CONTAINER_multipeermap_get (h->peers, pid); | 311 | return GNUNET_CONTAINER_multipeermap_get(h->peers, pid); |
322 | } | 312 | } |
323 | 313 | ||
324 | 314 | ||
@@ -330,7 +320,7 @@ lookup_peer (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) | |||
330 | * @return #GNUNET_YES if no information is left in @a p | 320 | * @return #GNUNET_YES if no information is left in @a p |
331 | */ | 321 | */ |
332 | static int | 322 | static int |
333 | peer_test_dead (struct Peer *p) | 323 | peer_test_dead(struct Peer *p) |
334 | { | 324 | { |
335 | for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; | 325 | for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; |
336 | pk++) | 326 | pk++) |
@@ -350,17 +340,17 @@ peer_test_dead (struct Peer *p) | |||
350 | * @param hello[in,out] address suggestion to make | 340 | * @param hello[in,out] address suggestion to make |
351 | */ | 341 | */ |
352 | static void | 342 | static void |
353 | suggest_hello (struct Hello *hello) | 343 | suggest_hello(struct Hello *hello) |
354 | { | 344 | { |
355 | struct Peer *p = hello->peer; | 345 | struct Peer *p = hello->peer; |
356 | struct SimpleHandle *h = p->h; | 346 | struct SimpleHandle *h = p->h; |
357 | 347 | ||
358 | p->last_suggestion = hello->last_attempt = GNUNET_TIME_absolute_get (); | 348 | p->last_suggestion = hello->last_attempt = GNUNET_TIME_absolute_get(); |
359 | hello->backoff = | 349 | hello->backoff = |
360 | GNUNET_TIME_randomized_backoff (hello->backoff, | 350 | GNUNET_TIME_randomized_backoff(hello->backoff, |
361 | GNUNET_TIME_absolute_get_remaining ( | 351 | GNUNET_TIME_absolute_get_remaining( |
362 | hello->expiration)); | 352 | hello->expiration)); |
363 | h->env->suggest_cb (h->env->cls, &p->pid, hello->address); | 353 | h->env->suggest_cb(h->env->cls, &p->pid, hello->address); |
364 | } | 354 | } |
365 | 355 | ||
366 | 356 | ||
@@ -379,7 +369,7 @@ suggest_hello (struct Hello *hello) | |||
379 | * @param cls a `struct Peer` | 369 | * @param cls a `struct Peer` |
380 | */ | 370 | */ |
381 | static void | 371 | static void |
382 | suggest_start_cb (void *cls) | 372 | suggest_start_cb(void *cls) |
383 | { | 373 | { |
384 | struct Peer *p = cls; | 374 | struct Peer *p = cls; |
385 | struct GNUNET_TIME_Relative delay = GNUNET_TIME_UNIT_ZERO; | 375 | struct GNUNET_TIME_Relative delay = GNUNET_TIME_UNIT_ZERO; |
@@ -397,63 +387,63 @@ suggest_start_cb (void *cls) | |||
397 | /* calculate square of number of sessions */ | 387 | /* calculate square of number of sessions */ |
398 | num_sessions++; /* start with 1, even if we have zero sessions */ | 388 | num_sessions++; /* start with 1, even if we have zero sessions */ |
399 | if (num_sessions < UINT16_MAX) | 389 | if (num_sessions < UINT16_MAX) |
400 | sq = num_sessions * (uint32_t) num_sessions; | 390 | sq = num_sessions * (uint32_t)num_sessions; |
401 | else | 391 | else |
402 | sq = UINT32_MAX; | 392 | sq = UINT32_MAX; |
403 | xdelay = | 393 | xdelay = |
404 | GNUNET_TIME_randomized_backoff (GNUNET_TIME_relative_multiply (SUGGEST_FREQ, | 394 | GNUNET_TIME_randomized_backoff(GNUNET_TIME_relative_multiply(SUGGEST_FREQ, |
405 | sq), | 395 | sq), |
406 | GNUNET_TIME_UNIT_FOREVER_REL); | 396 | GNUNET_TIME_UNIT_FOREVER_REL); |
407 | xnext = GNUNET_TIME_relative_to_absolute (xdelay); | 397 | xnext = GNUNET_TIME_relative_to_absolute(xdelay); |
408 | 398 | ||
409 | p->task = NULL; | 399 | p->task = NULL; |
410 | while (0 == delay.rel_value_us) | 400 | while (0 == delay.rel_value_us) |
411 | { | ||
412 | struct Hello *next; | ||
413 | struct GNUNET_TIME_Absolute xmax; | ||
414 | |||
415 | if (NULL != hello) | ||
416 | { | ||
417 | /* We went through the loop already once and found | ||
418 | a HELLO that is due *now*, so make a suggestion! */ | ||
419 | GNUNET_break (NULL == hello->sh); | ||
420 | suggest_hello (hello); | ||
421 | hello = NULL; | ||
422 | hpt = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
423 | } | ||
424 | for (struct Hello *pos = p->h_head; NULL != pos; pos = next) | ||
425 | { | 401 | { |
426 | struct GNUNET_TIME_Absolute pt; | 402 | struct Hello *next; |
427 | 403 | struct GNUNET_TIME_Absolute xmax; | |
428 | next = pos->next; | 404 | |
429 | if (NULL != pos->sh) | 405 | if (NULL != hello) |
430 | continue; | 406 | { |
431 | if (0 == | 407 | /* We went through the loop already once and found |
432 | GNUNET_TIME_absolute_get_remaining (pos->expiration).rel_value_us) | 408 | a HELLO that is due *now*, so make a suggestion! */ |
433 | { | 409 | GNUNET_break(NULL == hello->sh); |
434 | /* expired, remove! */ | 410 | suggest_hello(hello); |
435 | GNUNET_CONTAINER_DLL_remove (p->h_head, p->h_tail, pos); | 411 | hello = NULL; |
436 | GNUNET_free (pos); | 412 | hpt = GNUNET_TIME_UNIT_FOREVER_ABS; |
437 | continue; | 413 | } |
438 | } | 414 | for (struct Hello *pos = p->h_head; NULL != pos; pos = next) |
439 | pt = GNUNET_TIME_absolute_add (pos->last_attempt, pos->backoff); | 415 | { |
440 | if ((NULL == hello) || (pt.abs_value_us < hpt.abs_value_us)) | 416 | struct GNUNET_TIME_Absolute pt; |
441 | { | 417 | |
442 | hello = pos; | 418 | next = pos->next; |
443 | hpt = pt; | 419 | if (NULL != pos->sh) |
444 | } | 420 | continue; |
421 | if (0 == | ||
422 | GNUNET_TIME_absolute_get_remaining(pos->expiration).rel_value_us) | ||
423 | { | ||
424 | /* expired, remove! */ | ||
425 | GNUNET_CONTAINER_DLL_remove(p->h_head, p->h_tail, pos); | ||
426 | GNUNET_free(pos); | ||
427 | continue; | ||
428 | } | ||
429 | pt = GNUNET_TIME_absolute_add(pos->last_attempt, pos->backoff); | ||
430 | if ((NULL == hello) || (pt.abs_value_us < hpt.abs_value_us)) | ||
431 | { | ||
432 | hello = pos; | ||
433 | hpt = pt; | ||
434 | } | ||
435 | } | ||
436 | if (NULL == hello) | ||
437 | return; /* no HELLOs that could still be tried */ | ||
438 | |||
439 | /* hpt is now the *earliest* possible time for any HELLO | ||
440 | but we might not want to go for as early as possible for | ||
441 | this peer. So the actual time is the max of the earliest | ||
442 | HELLO and the 'xnext' */ | ||
443 | xmax = GNUNET_TIME_absolute_max(hpt, xnext); | ||
444 | delay = GNUNET_TIME_absolute_get_remaining(xmax); | ||
445 | } | 445 | } |
446 | if (NULL == hello) | 446 | p->task = GNUNET_SCHEDULER_add_delayed(delay, &suggest_start_cb, p); |
447 | return; /* no HELLOs that could still be tried */ | ||
448 | |||
449 | /* hpt is now the *earliest* possible time for any HELLO | ||
450 | but we might not want to go for as early as possible for | ||
451 | this peer. So the actual time is the max of the earliest | ||
452 | HELLO and the 'xnext' */ | ||
453 | xmax = GNUNET_TIME_absolute_max (hpt, xnext); | ||
454 | delay = GNUNET_TIME_absolute_get_remaining (xmax); | ||
455 | } | ||
456 | p->task = GNUNET_SCHEDULER_add_delayed (delay, &suggest_start_cb, p); | ||
457 | } | 447 | } |
458 | 448 | ||
459 | 449 | ||
@@ -465,9 +455,9 @@ suggest_start_cb (void *cls) | |||
465 | * @param emsg error message, or NULL if no errors | 455 | * @param emsg error message, or NULL if no errors |
466 | */ | 456 | */ |
467 | static void | 457 | static void |
468 | watch_cb (void *cls, | 458 | watch_cb(void *cls, |
469 | const struct GNUNET_PEERSTORE_Record *record, | 459 | const struct GNUNET_PEERSTORE_Record *record, |
470 | const char *emsg) | 460 | const char *emsg) |
471 | { | 461 | { |
472 | struct Peer *p = cls; | 462 | struct Peer *p = cls; |
473 | char *addr; | 463 | char *addr; |
@@ -476,65 +466,65 @@ watch_cb (void *cls, | |||
476 | struct GNUNET_TIME_Absolute expiration; | 466 | struct GNUNET_TIME_Absolute expiration; |
477 | struct Hello *hello; | 467 | struct Hello *hello; |
478 | 468 | ||
479 | if (0 != GNUNET_memcmp (&p->pid, &record->peer)) | 469 | if (0 != GNUNET_memcmp(&p->pid, &record->peer)) |
480 | { | 470 | { |
481 | GNUNET_break (0); | 471 | GNUNET_break(0); |
482 | return; | 472 | return; |
483 | } | 473 | } |
484 | if (0 != strcmp (record->key, GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY)) | 474 | if (0 != strcmp(record->key, GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY)) |
485 | { | 475 | { |
486 | GNUNET_break (0); | 476 | GNUNET_break(0); |
487 | return; | 477 | return; |
488 | } | 478 | } |
489 | addr = GNUNET_HELLO_extract_address (record->value, | 479 | addr = GNUNET_HELLO_extract_address(record->value, |
490 | record->value_size, | 480 | record->value_size, |
491 | &p->pid, | 481 | &p->pid, |
492 | &nt, | 482 | &nt, |
493 | &expiration); | 483 | &expiration); |
494 | if (NULL == addr) | 484 | if (NULL == addr) |
495 | return; /* invalid hello, bad signature, other problem */ | 485 | return; /* invalid hello, bad signature, other problem */ |
496 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) | 486 | if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) |
497 | { | 487 | { |
498 | /* expired, ignore */ | 488 | /* expired, ignore */ |
499 | GNUNET_free (addr); | 489 | GNUNET_free(addr); |
500 | return; | 490 | return; |
501 | } | 491 | } |
502 | /* check if addr is already known */ | 492 | /* check if addr is already known */ |
503 | for (struct Hello *he = p->h_head; NULL != he; he = he->next) | 493 | for (struct Hello *he = p->h_head; NULL != he; he = he->next) |
504 | { | ||
505 | if (0 != strcmp (he->address, addr)) | ||
506 | continue; | ||
507 | if (he->expiration.abs_value_us < expiration.abs_value_us) | ||
508 | { | 494 | { |
509 | he->expiration = expiration; | 495 | if (0 != strcmp(he->address, addr)) |
510 | he->nt = nt; | 496 | continue; |
497 | if (he->expiration.abs_value_us < expiration.abs_value_us) | ||
498 | { | ||
499 | he->expiration = expiration; | ||
500 | he->nt = nt; | ||
501 | } | ||
502 | GNUNET_free(addr); | ||
503 | return; | ||
511 | } | 504 | } |
512 | GNUNET_free (addr); | ||
513 | return; | ||
514 | } | ||
515 | /* create new HELLO */ | 505 | /* create new HELLO */ |
516 | alen = strlen (addr) + 1; | 506 | alen = strlen(addr) + 1; |
517 | hello = GNUNET_malloc (sizeof (struct Hello) + alen); | 507 | hello = GNUNET_malloc(sizeof(struct Hello) + alen); |
518 | hello->address = (const char *) &hello[1]; | 508 | hello->address = (const char *)&hello[1]; |
519 | hello->expiration = expiration; | 509 | hello->expiration = expiration; |
520 | hello->nt = nt; | 510 | hello->nt = nt; |
521 | hello->peer = p; | 511 | hello->peer = p; |
522 | memcpy (&hello[1], addr, alen); | 512 | memcpy(&hello[1], addr, alen); |
523 | GNUNET_CONTAINER_DLL_insert (p->h_head, p->h_tail, hello); | 513 | GNUNET_CONTAINER_DLL_insert(p->h_head, p->h_tail, hello); |
524 | /* check if sh for this HELLO already exists */ | 514 | /* check if sh for this HELLO already exists */ |
525 | for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head; NULL != sh; | 515 | for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head; NULL != sh; |
526 | sh = sh->next) | 516 | sh = sh->next) |
527 | { | 517 | { |
528 | if ((NULL == sh->address) || (0 != strcmp (sh->address, addr))) | 518 | if ((NULL == sh->address) || (0 != strcmp(sh->address, addr))) |
529 | continue; | 519 | continue; |
530 | GNUNET_assert (NULL == sh->hello); | 520 | GNUNET_assert(NULL == sh->hello); |
531 | sh->hello = hello; | 521 | sh->hello = hello; |
532 | hello->sh = sh; | 522 | hello->sh = sh; |
533 | break; | 523 | break; |
534 | } | 524 | } |
535 | GNUNET_free (addr); | 525 | GNUNET_free(addr); |
536 | if (NULL == p->task) | 526 | if (NULL == p->task) |
537 | p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb, p); | 527 | p->task = GNUNET_SCHEDULER_add_now(&suggest_start_cb, p); |
538 | } | 528 | } |
539 | 529 | ||
540 | 530 | ||
@@ -546,27 +536,27 @@ watch_cb (void *cls, | |||
546 | * @return a peer handle | 536 | * @return a peer handle |
547 | */ | 537 | */ |
548 | static struct Peer * | 538 | static struct Peer * |
549 | peer_add (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) | 539 | peer_add(struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) |
550 | { | 540 | { |
551 | struct Peer *p = lookup_peer (h, pid); | 541 | struct Peer *p = lookup_peer(h, pid); |
552 | 542 | ||
553 | if (NULL != p) | 543 | if (NULL != p) |
554 | return p; | 544 | return p; |
555 | p = GNUNET_new (struct Peer); | 545 | p = GNUNET_new(struct Peer); |
556 | p->h = h; | 546 | p->h = h; |
557 | p->pid = *pid; | 547 | p->pid = *pid; |
558 | p->wc = GNUNET_PEERSTORE_watch (h->ps, | 548 | p->wc = GNUNET_PEERSTORE_watch(h->ps, |
559 | "transport", | 549 | "transport", |
560 | &p->pid, | 550 | &p->pid, |
561 | GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, | 551 | GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, |
562 | &watch_cb, | 552 | &watch_cb, |
563 | p); | 553 | p); |
564 | GNUNET_assert (GNUNET_YES == | 554 | GNUNET_assert(GNUNET_YES == |
565 | GNUNET_CONTAINER_multipeermap_put ( | 555 | GNUNET_CONTAINER_multipeermap_put( |
566 | h->peers, | 556 | h->peers, |
567 | &p->pid, | 557 | &p->pid, |
568 | p, | 558 | p, |
569 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 559 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
570 | 560 | ||
571 | return p; | 561 | return p; |
572 | } | 562 | } |
@@ -579,31 +569,31 @@ peer_add (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) | |||
579 | * @param p the peer to free | 569 | * @param p the peer to free |
580 | */ | 570 | */ |
581 | static void | 571 | static void |
582 | peer_free (struct Peer *p) | 572 | peer_free(struct Peer *p) |
583 | { | 573 | { |
584 | struct SimpleHandle *h = p->h; | 574 | struct SimpleHandle *h = p->h; |
585 | struct Hello *hello; | 575 | struct Hello *hello; |
586 | 576 | ||
587 | GNUNET_assert (NULL == p->sh_head); | 577 | GNUNET_assert(NULL == p->sh_head); |
588 | while (NULL != (hello = p->h_head)) | 578 | while (NULL != (hello = p->h_head)) |
589 | { | 579 | { |
590 | GNUNET_CONTAINER_DLL_remove (p->h_head, p->h_tail, hello); | 580 | GNUNET_CONTAINER_DLL_remove(p->h_head, p->h_tail, hello); |
591 | GNUNET_assert (NULL == hello->sh); | 581 | GNUNET_assert(NULL == hello->sh); |
592 | GNUNET_free (hello); | 582 | GNUNET_free(hello); |
593 | } | 583 | } |
594 | if (NULL != p->task) | 584 | if (NULL != p->task) |
595 | { | 585 | { |
596 | GNUNET_SCHEDULER_cancel (p->task); | 586 | GNUNET_SCHEDULER_cancel(p->task); |
597 | p->task = NULL; | 587 | p->task = NULL; |
598 | } | 588 | } |
599 | if (NULL != p->wc) | 589 | if (NULL != p->wc) |
600 | { | 590 | { |
601 | GNUNET_PEERSTORE_watch_cancel (p->wc); | 591 | GNUNET_PEERSTORE_watch_cancel(p->wc); |
602 | p->wc = NULL; | 592 | p->wc = NULL; |
603 | } | 593 | } |
604 | GNUNET_assert (GNUNET_YES == | 594 | GNUNET_assert(GNUNET_YES == |
605 | GNUNET_CONTAINER_multipeermap_remove (h->peers, &p->pid, p)); | 595 | GNUNET_CONTAINER_multipeermap_remove(h->peers, &p->pid, p)); |
606 | GNUNET_free (p); | 596 | GNUNET_free(p); |
607 | } | 597 | } |
608 | 598 | ||
609 | 599 | ||
@@ -614,7 +604,7 @@ peer_free (struct Peer *p) | |||
614 | * @param sh session handle to consider updating transport for | 604 | * @param sh session handle to consider updating transport for |
615 | */ | 605 | */ |
616 | static void | 606 | static void |
617 | consider_notify_transport (struct GNUNET_ATS_SessionHandle *sh) | 607 | consider_notify_transport(struct GNUNET_ATS_SessionHandle *sh) |
618 | { | 608 | { |
619 | struct Peer *peer = sh->peer; | 609 | struct Peer *peer = sh->peer; |
620 | struct SimpleHandle *h = peer->h; | 610 | struct SimpleHandle *h = peer->h; |
@@ -625,15 +615,15 @@ consider_notify_transport (struct GNUNET_ATS_SessionHandle *sh) | |||
625 | int64_t delta_in; | 615 | int64_t delta_in; |
626 | int64_t delta_out; | 616 | int64_t delta_out; |
627 | 617 | ||
628 | delay = GNUNET_TIME_absolute_get_duration (sh->last_allocation); | 618 | delay = GNUNET_TIME_absolute_get_duration(sh->last_allocation); |
629 | /* A significant change is more than 10% of the quota, | 619 | /* A significant change is more than 10% of the quota, |
630 | which is given in bytes/second */ | 620 | which is given in bytes/second */ |
631 | sig_in = h->networks[nt].total_quota_in * (delay.rel_value_us / 1000LL) / | 621 | sig_in = h->networks[nt].total_quota_in * (delay.rel_value_us / 1000LL) / |
632 | 1000LL / 10; | 622 | 1000LL / 10; |
633 | sig_out = h->networks[nt].total_quota_out * (delay.rel_value_us / 1000LL) / | 623 | sig_out = h->networks[nt].total_quota_out * (delay.rel_value_us / 1000LL) / |
634 | 1000LL / 10; | 624 | 1000LL / 10; |
635 | delta_in = ((int64_t) ntohl (sh->bw_in.value__)) - ((int64_t) sh->target_in); | 625 | delta_in = ((int64_t)ntohl(sh->bw_in.value__)) - ((int64_t)sh->target_in); |
636 | delta_out = ((int64_t) ntohl (sh->bw_in.value__)) - ((int64_t) sh->target_in); | 626 | delta_out = ((int64_t)ntohl(sh->bw_in.value__)) - ((int64_t)sh->target_in); |
637 | /* we want the absolute values */ | 627 | /* we want the absolute values */ |
638 | if (delta_in < 0) | 628 | if (delta_in < 0) |
639 | delta_in = -delta_in; | 629 | delta_in = -delta_in; |
@@ -648,24 +638,23 @@ consider_notify_transport (struct GNUNET_ATS_SessionHandle *sh) | |||
648 | /* change is significant, tell transport! */ | 638 | /* change is significant, tell transport! */ |
649 | if (sh->target_in > UINT32_MAX) | 639 | if (sh->target_in > UINT32_MAX) |
650 | sh->target_in = UINT32_MAX; | 640 | sh->target_in = UINT32_MAX; |
651 | sh->bw_in.value__ = htonl ((uint32_t) sh->target_in); | 641 | sh->bw_in.value__ = htonl((uint32_t)sh->target_in); |
652 | if (sh->target_out > UINT32_MAX) | 642 | if (sh->target_out > UINT32_MAX) |
653 | sh->target_out = UINT32_MAX; | 643 | sh->target_out = UINT32_MAX; |
654 | sh->bw_out.value__ = htonl ((uint32_t) sh->target_out); | 644 | sh->bw_out.value__ = htonl((uint32_t)sh->target_out); |
655 | sh->last_allocation = GNUNET_TIME_absolute_get (); | 645 | sh->last_allocation = GNUNET_TIME_absolute_get(); |
656 | h->env->allocate_cb (h->env->cls, | 646 | h->env->allocate_cb(h->env->cls, |
657 | sh->session, | 647 | sh->session, |
658 | &peer->pid, | 648 | &peer->pid, |
659 | sh->bw_in, | 649 | sh->bw_in, |
660 | sh->bw_out); | 650 | sh->bw_out); |
661 | } | 651 | } |
662 | 652 | ||
663 | 653 | ||
664 | /** | 654 | /** |
665 | * Closure for #update_counters and #update_allocation. | 655 | * Closure for #update_counters and #update_allocation. |
666 | */ | 656 | */ |
667 | struct Counters | 657 | struct Counters { |
668 | { | ||
669 | /** | 658 | /** |
670 | * Plugin's state. | 659 | * Plugin's state. |
671 | */ | 660 | */ |
@@ -709,100 +698,103 @@ struct Counters | |||
709 | * @return #GNUNET_YES (continue to iterate) | 698 | * @return #GNUNET_YES (continue to iterate) |
710 | */ | 699 | */ |
711 | static int | 700 | static int |
712 | update_counters (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | 701 | update_counters(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) |
713 | { | 702 | { |
714 | struct Counters *c = cls; | 703 | struct Counters *c = cls; |
715 | struct Peer *peer = value; | 704 | struct Peer *peer = value; |
716 | struct GNUNET_ATS_SessionHandle *best[GNUNET_MQ_PREFERENCE_COUNT]; | 705 | struct GNUNET_ATS_SessionHandle *best[GNUNET_MQ_PREFERENCE_COUNT]; |
717 | 706 | ||
718 | (void) pid; | 707 | (void)pid; |
719 | if (NULL == peer->sh_head) | 708 | if (NULL == peer->sh_head) |
720 | return GNUNET_YES; /* no available session, cannot allocate bandwidth */ | 709 | return GNUNET_YES; /* no available session, cannot allocate bandwidth */ |
721 | memset (best, 0, sizeof (best)); | 710 | memset(best, 0, sizeof(best)); |
722 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; | 711 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; |
723 | sh = sh->next) | 712 | sh = sh->next) |
724 | { | ||
725 | enum GNUNET_NetworkType nt = sh->data->prop.nt; | ||
726 | |||
727 | sh->target_out = MIN_BANDWIDTH_PER_SESSION; | ||
728 | c->bw_out_by_nt[nt] += MIN_BANDWIDTH_PER_SESSION; | ||
729 | c->bw_in_by_nt[nt] += | ||
730 | GNUNET_MAX (MIN_BANDWIDTH_PER_SESSION, sh->data->prop.goodput_in); | ||
731 | for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; | ||
732 | pk++) | ||
733 | { | 713 | { |
734 | /* General rule: always prefer smaller distance if possible, | 714 | enum GNUNET_NetworkType nt = sh->data->prop.nt; |
735 | otherwise decide by pk: */ | 715 | |
736 | switch (pk) | 716 | sh->target_out = MIN_BANDWIDTH_PER_SESSION; |
737 | { | 717 | c->bw_out_by_nt[nt] += MIN_BANDWIDTH_PER_SESSION; |
738 | case GNUNET_MQ_PREFERENCE_NONE: | 718 | c->bw_in_by_nt[nt] += |
739 | break; | 719 | GNUNET_MAX(MIN_BANDWIDTH_PER_SESSION, sh->data->prop.goodput_in); |
740 | case GNUNET_MQ_PREFERENCE_BANDWIDTH: | 720 | for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; |
741 | /* For bandwidth, we compare the sum of transmitted bytes and | 721 | pk++) |
742 | confirmed transmitted bytes, so confirmed data counts twice */ | 722 | { |
743 | if ((NULL == best[pk]) || | 723 | /* General rule: always prefer smaller distance if possible, |
744 | (sh->data->prop.distance < best[pk]->data->prop.distance) || | 724 | otherwise decide by pk: */ |
745 | (sh->data->prop.utilization_out + sh->data->prop.goodput_out > | 725 | switch (pk) |
746 | best[pk]->data->prop.utilization_out + | 726 | { |
747 | best[pk]->data->prop.goodput_out)) | 727 | case GNUNET_MQ_PREFERENCE_NONE: |
748 | best[pk] = sh; | 728 | break; |
749 | /* If both are equal (i.e. usually this happens if there is a zero), use | 729 | |
750 | latency as a yardstick */ | 730 | case GNUNET_MQ_PREFERENCE_BANDWIDTH: |
751 | if ((sh->data->prop.utilization_out + sh->data->prop.goodput_out == | 731 | /* For bandwidth, we compare the sum of transmitted bytes and |
752 | best[pk]->data->prop.utilization_out + | 732 | confirmed transmitted bytes, so confirmed data counts twice */ |
753 | best[pk]->data->prop.goodput_out) && | 733 | if ((NULL == best[pk]) || |
754 | (sh->data->prop.distance == best[pk]->data->prop.distance) && | 734 | (sh->data->prop.distance < best[pk]->data->prop.distance) || |
755 | (sh->data->prop.delay.rel_value_us < | 735 | (sh->data->prop.utilization_out + sh->data->prop.goodput_out > |
756 | best[pk]->data->prop.delay.rel_value_us)) | 736 | best[pk]->data->prop.utilization_out + |
757 | best[pk] = sh; | 737 | best[pk]->data->prop.goodput_out)) |
758 | break; | 738 | best[pk] = sh; |
759 | case GNUNET_MQ_PREFERENCE_LATENCY: | 739 | /* If both are equal (i.e. usually this happens if there is a zero), use |
760 | if ((NULL == best[pk]) || | 740 | latency as a yardstick */ |
761 | (sh->data->prop.distance < best[pk]->data->prop.distance) || | 741 | if ((sh->data->prop.utilization_out + sh->data->prop.goodput_out == |
762 | ((sh->data->prop.distance == best[pk]->data->prop.distance) && | 742 | best[pk]->data->prop.utilization_out + |
763 | (sh->data->prop.delay.rel_value_us < | 743 | best[pk]->data->prop.goodput_out) && |
764 | best[pk]->data->prop.delay.rel_value_us))) | 744 | (sh->data->prop.distance == best[pk]->data->prop.distance) && |
765 | best[pk] = sh; | 745 | (sh->data->prop.delay.rel_value_us < |
766 | break; | 746 | best[pk]->data->prop.delay.rel_value_us)) |
767 | case GNUNET_MQ_PREFERENCE_RELIABILITY: | 747 | best[pk] = sh; |
768 | /* For reliability, we consider the ratio of goodput to utilization | 748 | break; |
769 | (but use multiplicative formultations to avoid division by zero) */ | 749 | |
770 | if ((NULL == best[pk]) || (1ULL * sh->data->prop.goodput_out * | 750 | case GNUNET_MQ_PREFERENCE_LATENCY: |
771 | best[pk]->data->prop.utilization_out > | 751 | if ((NULL == best[pk]) || |
772 | 1ULL * sh->data->prop.utilization_out * | 752 | (sh->data->prop.distance < best[pk]->data->prop.distance) || |
773 | best[pk]->data->prop.goodput_out)) | 753 | ((sh->data->prop.distance == best[pk]->data->prop.distance) && |
774 | best[pk] = sh; | 754 | (sh->data->prop.delay.rel_value_us < |
775 | /* If both are equal (i.e. usually this happens if there is a zero), use | 755 | best[pk]->data->prop.delay.rel_value_us))) |
776 | latency as a yardstick */ | 756 | best[pk] = sh; |
777 | if ((1ULL * sh->data->prop.goodput_out * | 757 | break; |
778 | best[pk]->data->prop.utilization_out == | 758 | |
779 | 1ULL * sh->data->prop.utilization_out * | 759 | case GNUNET_MQ_PREFERENCE_RELIABILITY: |
780 | best[pk]->data->prop.goodput_out) && | 760 | /* For reliability, we consider the ratio of goodput to utilization |
781 | (sh->data->prop.distance == best[pk]->data->prop.distance) && | 761 | (but use multiplicative formultations to avoid division by zero) */ |
782 | (sh->data->prop.delay.rel_value_us < | 762 | if ((NULL == best[pk]) || (1ULL * sh->data->prop.goodput_out * |
783 | best[pk]->data->prop.delay.rel_value_us)) | 763 | best[pk]->data->prop.utilization_out > |
784 | best[pk] = sh; | 764 | 1ULL * sh->data->prop.utilization_out * |
785 | break; | 765 | best[pk]->data->prop.goodput_out)) |
786 | } | 766 | best[pk] = sh; |
767 | /* If both are equal (i.e. usually this happens if there is a zero), use | ||
768 | latency as a yardstick */ | ||
769 | if ((1ULL * sh->data->prop.goodput_out * | ||
770 | best[pk]->data->prop.utilization_out == | ||
771 | 1ULL * sh->data->prop.utilization_out * | ||
772 | best[pk]->data->prop.goodput_out) && | ||
773 | (sh->data->prop.distance == best[pk]->data->prop.distance) && | ||
774 | (sh->data->prop.delay.rel_value_us < | ||
775 | best[pk]->data->prop.delay.rel_value_us)) | ||
776 | best[pk] = sh; | ||
777 | break; | ||
778 | } | ||
779 | } | ||
787 | } | 780 | } |
788 | } | ||
789 | /* for first round, assign target bandwidth simply to sum of | 781 | /* for first round, assign target bandwidth simply to sum of |
790 | requested bandwidth */ | 782 | requested bandwidth */ |
791 | for (enum GNUNET_MQ_PreferenceKind pk = | 783 | for (enum GNUNET_MQ_PreferenceKind pk = |
792 | 1 /* skip GNUNET_MQ_PREFERENCE_NONE */; | 784 | 1 /* skip GNUNET_MQ_PREFERENCE_NONE */; |
793 | pk < GNUNET_MQ_PREFERENCE_COUNT; | 785 | pk < GNUNET_MQ_PREFERENCE_COUNT; |
794 | pk++) | 786 | pk++) |
795 | { | 787 | { |
796 | const struct GNUNET_ATS_SessionData *data = best[pk]->data; | 788 | const struct GNUNET_ATS_SessionData *data = best[pk]->data; |
797 | enum GNUNET_NetworkType nt; | 789 | enum GNUNET_NetworkType nt; |
798 | 790 | ||
799 | GNUNET_assert (NULL != data); | 791 | GNUNET_assert(NULL != data); |
800 | nt = data->prop.nt; | 792 | nt = data->prop.nt; |
801 | best[pk]->target_out = | 793 | best[pk]->target_out = |
802 | GNUNET_MIN (peer->bw_by_pk[pk], MIN_BANDWIDTH_PER_SESSION); | 794 | GNUNET_MIN(peer->bw_by_pk[pk], MIN_BANDWIDTH_PER_SESSION); |
803 | c->bw_out_by_nt[nt] += | 795 | c->bw_out_by_nt[nt] += |
804 | (uint64_t) (best[pk]->target_out - MIN_BANDWIDTH_PER_SESSION); | 796 | (uint64_t)(best[pk]->target_out - MIN_BANDWIDTH_PER_SESSION); |
805 | } | 797 | } |
806 | return GNUNET_YES; | 798 | return GNUNET_YES; |
807 | } | 799 | } |
808 | 800 | ||
@@ -817,23 +809,23 @@ update_counters (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | |||
817 | * @return #GNUNET_YES (continue to iterate) | 809 | * @return #GNUNET_YES (continue to iterate) |
818 | */ | 810 | */ |
819 | static int | 811 | static int |
820 | update_allocation (void *cls, | 812 | update_allocation(void *cls, |
821 | const struct GNUNET_PeerIdentity *pid, | 813 | const struct GNUNET_PeerIdentity *pid, |
822 | void *value) | 814 | void *value) |
823 | { | 815 | { |
824 | struct Counters *c = cls; | 816 | struct Counters *c = cls; |
825 | struct Peer *peer = value; | 817 | struct Peer *peer = value; |
826 | 818 | ||
827 | (void) pid; | 819 | (void)pid; |
828 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; | 820 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; |
829 | sh = sh->next) | 821 | sh = sh->next) |
830 | { | 822 | { |
831 | enum GNUNET_NetworkType nt = sh->data->prop.nt; | 823 | enum GNUNET_NetworkType nt = sh->data->prop.nt; |
832 | 824 | ||
833 | sh->target_out = (uint64_t) (c->scale_out[nt] * sh->target_out); | 825 | sh->target_out = (uint64_t)(c->scale_out[nt] * sh->target_out); |
834 | sh->target_in = (uint64_t) (c->scale_in[nt] * sh->target_in); | 826 | sh->target_in = (uint64_t)(c->scale_in[nt] * sh->target_in); |
835 | consider_notify_transport (sh); | 827 | consider_notify_transport(sh); |
836 | } | 828 | } |
837 | return GNUNET_YES; | 829 | return GNUNET_YES; |
838 | } | 830 | } |
839 | 831 | ||
@@ -842,23 +834,23 @@ update_allocation (void *cls, | |||
842 | * The world changed, recalculate our allocations. | 834 | * The world changed, recalculate our allocations. |
843 | */ | 835 | */ |
844 | static void | 836 | static void |
845 | update (struct SimpleHandle *h) | 837 | update(struct SimpleHandle *h) |
846 | { | 838 | { |
847 | struct Counters cnt = {.h = h}; | 839 | struct Counters cnt = { .h = h }; |
848 | 840 | ||
849 | GNUNET_CONTAINER_multipeermap_iterate (h->peers, &update_counters, &cnt); | 841 | GNUNET_CONTAINER_multipeermap_iterate(h->peers, &update_counters, &cnt); |
850 | /* calculate how badly the missmatch between requested | 842 | /* calculate how badly the missmatch between requested |
851 | allocations and available bandwidth is per network type */ | 843 | allocations and available bandwidth is per network type */ |
852 | for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) | 844 | for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) |
853 | { | 845 | { |
854 | cnt.scale_out[nt] = | 846 | cnt.scale_out[nt] = |
855 | 1.0 * cnt.bw_out_by_nt[nt] / h->networks[nt].total_quota_out; | 847 | 1.0 * cnt.bw_out_by_nt[nt] / h->networks[nt].total_quota_out; |
856 | cnt.scale_in[nt] = | 848 | cnt.scale_in[nt] = |
857 | 1.0 * cnt.bw_in_by_nt[nt] / h->networks[nt].total_quota_in; | 849 | 1.0 * cnt.bw_in_by_nt[nt] / h->networks[nt].total_quota_in; |
858 | } | 850 | } |
859 | /* recalculate allocations, considering scaling factor, and | 851 | /* recalculate allocations, considering scaling factor, and |
860 | update transport if the change is significant */ | 852 | update transport if the change is significant */ |
861 | GNUNET_CONTAINER_multipeermap_iterate (h->peers, &update_allocation, &cnt); | 853 | GNUNET_CONTAINER_multipeermap_iterate(h->peers, &update_allocation, &cnt); |
862 | } | 854 | } |
863 | 855 | ||
864 | 856 | ||
@@ -870,15 +862,15 @@ update (struct SimpleHandle *h) | |||
870 | * @return plugin's internal representation, or NULL | 862 | * @return plugin's internal representation, or NULL |
871 | */ | 863 | */ |
872 | static struct GNUNET_ATS_PreferenceHandle * | 864 | static struct GNUNET_ATS_PreferenceHandle * |
873 | simple_preference_add (void *cls, const struct GNUNET_ATS_Preference *pref) | 865 | simple_preference_add(void *cls, const struct GNUNET_ATS_Preference *pref) |
874 | { | 866 | { |
875 | struct SimpleHandle *h = cls; | 867 | struct SimpleHandle *h = cls; |
876 | struct Peer *p = peer_add (h, &pref->peer); | 868 | struct Peer *p = peer_add(h, &pref->peer); |
877 | 869 | ||
878 | GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT); | 870 | GNUNET_assert(pref->pk < GNUNET_MQ_PREFERENCE_COUNT); |
879 | p->bw_by_pk[pref->pk] += ntohl (pref->bw.value__); | 871 | p->bw_by_pk[pref->pk] += ntohl(pref->bw.value__); |
880 | h->bw_by_pk[pref->pk] += ntohl (pref->bw.value__); | 872 | h->bw_by_pk[pref->pk] += ntohl(pref->bw.value__); |
881 | update (h); | 873 | update(h); |
882 | return NULL; | 874 | return NULL; |
883 | } | 875 | } |
884 | 876 | ||
@@ -892,20 +884,20 @@ simple_preference_add (void *cls, const struct GNUNET_ATS_Preference *pref) | |||
892 | * @return plugin's internal representation, or NULL | 884 | * @return plugin's internal representation, or NULL |
893 | */ | 885 | */ |
894 | static void | 886 | static void |
895 | simple_preference_del (void *cls, | 887 | simple_preference_del(void *cls, |
896 | struct GNUNET_ATS_PreferenceHandle *ph, | 888 | struct GNUNET_ATS_PreferenceHandle *ph, |
897 | const struct GNUNET_ATS_Preference *pref) | 889 | const struct GNUNET_ATS_Preference *pref) |
898 | { | 890 | { |
899 | struct SimpleHandle *h = cls; | 891 | struct SimpleHandle *h = cls; |
900 | struct Peer *p = lookup_peer (h, &pref->peer); | 892 | struct Peer *p = lookup_peer(h, &pref->peer); |
901 | 893 | ||
902 | GNUNET_assert (NULL != p); | 894 | GNUNET_assert(NULL != p); |
903 | GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT); | 895 | GNUNET_assert(pref->pk < GNUNET_MQ_PREFERENCE_COUNT); |
904 | p->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__); | 896 | p->bw_by_pk[pref->pk] -= ntohl(pref->bw.value__); |
905 | h->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__); | 897 | h->bw_by_pk[pref->pk] -= ntohl(pref->bw.value__); |
906 | if ((0 == p->bw_by_pk[pref->pk]) && (GNUNET_YES == peer_test_dead (p))) | 898 | if ((0 == p->bw_by_pk[pref->pk]) && (GNUNET_YES == peer_test_dead(p))) |
907 | peer_free (p); | 899 | peer_free(p); |
908 | update (h); | 900 | update(h); |
909 | } | 901 | } |
910 | 902 | ||
911 | 903 | ||
@@ -919,50 +911,50 @@ simple_preference_del (void *cls, | |||
919 | * @return handle by which the plugin will identify this session | 911 | * @return handle by which the plugin will identify this session |
920 | */ | 912 | */ |
921 | static struct GNUNET_ATS_SessionHandle * | 913 | static struct GNUNET_ATS_SessionHandle * |
922 | simple_session_add (void *cls, | 914 | simple_session_add(void *cls, |
923 | const struct GNUNET_ATS_SessionData *data, | 915 | const struct GNUNET_ATS_SessionData *data, |
924 | const char *address) | 916 | const char *address) |
925 | { | 917 | { |
926 | struct SimpleHandle *h = cls; | 918 | struct SimpleHandle *h = cls; |
927 | struct Peer *p = peer_add (h, &data->peer); | 919 | struct Peer *p = peer_add(h, &data->peer); |
928 | struct Hello *hello; | 920 | struct Hello *hello; |
929 | size_t alen; | 921 | size_t alen; |
930 | struct GNUNET_ATS_SessionHandle *sh; | 922 | struct GNUNET_ATS_SessionHandle *sh; |
931 | 923 | ||
932 | /* setup session handle */ | 924 | /* setup session handle */ |
933 | GNUNET_assert (NULL != data); | 925 | GNUNET_assert(NULL != data); |
934 | if (NULL == address) | 926 | if (NULL == address) |
935 | alen = 0; | 927 | alen = 0; |
936 | else | 928 | else |
937 | alen = strlen (address) + 1; | 929 | alen = strlen(address) + 1; |
938 | sh = GNUNET_malloc (sizeof (struct GNUNET_ATS_SessionHandle) + alen); | 930 | sh = GNUNET_malloc(sizeof(struct GNUNET_ATS_SessionHandle) + alen); |
939 | sh->peer = p; | 931 | sh->peer = p; |
940 | sh->session = data->session; | 932 | sh->session = data->session; |
941 | sh->data = data; | 933 | sh->data = data; |
942 | if (NULL == address) | 934 | if (NULL == address) |
943 | { | 935 | { |
944 | sh->address = NULL; | 936 | sh->address = NULL; |
945 | } | 937 | } |
946 | else | 938 | else |
947 | { | 939 | { |
948 | memcpy (&sh[1], address, alen); | 940 | memcpy(&sh[1], address, alen); |
949 | sh->address = (const char *) &sh[1]; | 941 | sh->address = (const char *)&sh[1]; |
950 | } | 942 | } |
951 | GNUNET_CONTAINER_DLL_insert (p->sh_head, p->sh_tail, sh); | 943 | GNUNET_CONTAINER_DLL_insert(p->sh_head, p->sh_tail, sh); |
952 | if (NULL != address) | 944 | if (NULL != address) |
953 | { | ||
954 | /* match HELLO */ | ||
955 | hello = p->h_head; | ||
956 | while ((NULL != hello) && (0 != strcmp (address, hello->address))) | ||
957 | hello = hello->next; | ||
958 | if (NULL != hello) | ||
959 | { | 945 | { |
960 | hello->sh = sh; | 946 | /* match HELLO */ |
961 | hello->backoff = GNUNET_TIME_UNIT_ZERO; | 947 | hello = p->h_head; |
962 | sh->hello = hello; | 948 | while ((NULL != hello) && (0 != strcmp(address, hello->address))) |
949 | hello = hello->next; | ||
950 | if (NULL != hello) | ||
951 | { | ||
952 | hello->sh = sh; | ||
953 | hello->backoff = GNUNET_TIME_UNIT_ZERO; | ||
954 | sh->hello = hello; | ||
955 | } | ||
963 | } | 956 | } |
964 | } | 957 | update(h); |
965 | update (h); | ||
966 | return sh; | 958 | return sh; |
967 | } | 959 | } |
968 | 960 | ||
@@ -976,15 +968,15 @@ simple_session_add (void *cls, | |||
976 | * @param data performance characteristics of @a sh | 968 | * @param data performance characteristics of @a sh |
977 | */ | 969 | */ |
978 | static void | 970 | static void |
979 | simple_session_update (void *cls, | 971 | simple_session_update(void *cls, |
980 | struct GNUNET_ATS_SessionHandle *sh, | 972 | struct GNUNET_ATS_SessionHandle *sh, |
981 | const struct GNUNET_ATS_SessionData *data) | 973 | const struct GNUNET_ATS_SessionData *data) |
982 | { | 974 | { |
983 | struct SimpleHandle *h = cls; | 975 | struct SimpleHandle *h = cls; |
984 | 976 | ||
985 | GNUNET_assert (NULL != data); | 977 | GNUNET_assert(NULL != data); |
986 | sh->data = data; /* this statement should not really do anything... */ | 978 | sh->data = data; /* this statement should not really do anything... */ |
987 | update (h); | 979 | update(h); |
988 | } | 980 | } |
989 | 981 | ||
990 | 982 | ||
@@ -996,30 +988,30 @@ simple_session_update (void *cls, | |||
996 | * @param data (last) performance characteristics of @a sh | 988 | * @param data (last) performance characteristics of @a sh |
997 | */ | 989 | */ |
998 | static void | 990 | static void |
999 | simple_session_del (void *cls, | 991 | simple_session_del(void *cls, |
1000 | struct GNUNET_ATS_SessionHandle *sh, | 992 | struct GNUNET_ATS_SessionHandle *sh, |
1001 | const struct GNUNET_ATS_SessionData *data) | 993 | const struct GNUNET_ATS_SessionData *data) |
1002 | { | 994 | { |
1003 | struct SimpleHandle *h = cls; | 995 | struct SimpleHandle *h = cls; |
1004 | struct Peer *p = sh->peer; | 996 | struct Peer *p = sh->peer; |
1005 | struct Hello *hello = sh->hello; | 997 | struct Hello *hello = sh->hello; |
1006 | 998 | ||
1007 | /* clean up sh */ | 999 | /* clean up sh */ |
1008 | GNUNET_CONTAINER_DLL_remove (p->sh_head, p->sh_tail, sh); | 1000 | GNUNET_CONTAINER_DLL_remove(p->sh_head, p->sh_tail, sh); |
1009 | if (NULL != hello) | 1001 | if (NULL != hello) |
1010 | { | 1002 | { |
1011 | GNUNET_assert (sh == hello->sh); | 1003 | GNUNET_assert(sh == hello->sh); |
1012 | hello->sh = NULL; | 1004 | hello->sh = NULL; |
1013 | /* session went down, if necessary restart suggesting | 1005 | /* session went down, if necessary restart suggesting |
1014 | addresses */ | 1006 | addresses */ |
1015 | if (NULL == p->task) | 1007 | if (NULL == p->task) |
1016 | p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb, p); | 1008 | p->task = GNUNET_SCHEDULER_add_now(&suggest_start_cb, p); |
1017 | } | 1009 | } |
1018 | GNUNET_free (sh); | 1010 | GNUNET_free(sh); |
1019 | /* del peer if otherwise dead */ | 1011 | /* del peer if otherwise dead */ |
1020 | if ((NULL == p->sh_head) && (GNUNET_YES == peer_test_dead (p))) | 1012 | if ((NULL == p->sh_head) && (GNUNET_YES == peer_test_dead(p))) |
1021 | peer_free (p); | 1013 | peer_free(p); |
1022 | update (h); | 1014 | update(h); |
1023 | } | 1015 | } |
1024 | 1016 | ||
1025 | 1017 | ||
@@ -1034,16 +1026,16 @@ simple_session_del (void *cls, | |||
1034 | * @return the `struct SimpleHandle` to pass as a closure | 1026 | * @return the `struct SimpleHandle` to pass as a closure |
1035 | */ | 1027 | */ |
1036 | void * | 1028 | void * |
1037 | libgnunet_plugin_ats2_simple_init (void *cls) | 1029 | libgnunet_plugin_ats2_simple_init(void *cls) |
1038 | { | 1030 | { |
1039 | static struct GNUNET_ATS_SolverFunctions sf; | 1031 | static struct GNUNET_ATS_SolverFunctions sf; |
1040 | struct GNUNET_ATS_PluginEnvironment *env = cls; | 1032 | struct GNUNET_ATS_PluginEnvironment *env = cls; |
1041 | struct SimpleHandle *s; | 1033 | struct SimpleHandle *s; |
1042 | 1034 | ||
1043 | s = GNUNET_new (struct SimpleHandle); | 1035 | s = GNUNET_new(struct SimpleHandle); |
1044 | s->env = env; | 1036 | s->env = env; |
1045 | s->peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); | 1037 | s->peers = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); |
1046 | s->ps = GNUNET_PEERSTORE_connect (env->cfg); | 1038 | s->ps = GNUNET_PEERSTORE_connect(env->cfg); |
1047 | sf.cls = s; | 1039 | sf.cls = s; |
1048 | sf.preference_add = &simple_preference_add; | 1040 | sf.preference_add = &simple_preference_add; |
1049 | sf.preference_del = &simple_preference_del; | 1041 | sf.preference_del = &simple_preference_del; |
@@ -1051,18 +1043,18 @@ libgnunet_plugin_ats2_simple_init (void *cls) | |||
1051 | sf.session_update = &simple_session_update; | 1043 | sf.session_update = &simple_session_update; |
1052 | sf.session_del = &simple_session_del; | 1044 | sf.session_del = &simple_session_del; |
1053 | for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) | 1045 | for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) |
1054 | { | ||
1055 | const char *name = GNUNET_NT_to_string (nt); | ||
1056 | |||
1057 | if (NULL == name) | ||
1058 | { | 1046 | { |
1059 | GNUNET_break (0); | 1047 | const char *name = GNUNET_NT_to_string(nt); |
1060 | break; | 1048 | |
1049 | if (NULL == name) | ||
1050 | { | ||
1051 | GNUNET_break(0); | ||
1052 | break; | ||
1053 | } | ||
1054 | get_quota(env->cfg, name, "IN", &s->networks[nt].total_quota_in); | ||
1055 | get_quota(env->cfg, name, "OUT", &s->networks[nt].total_quota_out); | ||
1056 | s->networks[nt].type = nt; | ||
1061 | } | 1057 | } |
1062 | get_quota (env->cfg, name, "IN", &s->networks[nt].total_quota_in); | ||
1063 | get_quota (env->cfg, name, "OUT", &s->networks[nt].total_quota_out); | ||
1064 | s->networks[nt].type = nt; | ||
1065 | } | ||
1066 | return &sf; | 1058 | return &sf; |
1067 | } | 1059 | } |
1068 | 1060 | ||
@@ -1073,15 +1065,15 @@ libgnunet_plugin_ats2_simple_init (void *cls) | |||
1073 | * @param cls return value from #libgnunet_plugin_ats_proportional_init() | 1065 | * @param cls return value from #libgnunet_plugin_ats_proportional_init() |
1074 | */ | 1066 | */ |
1075 | void * | 1067 | void * |
1076 | libgnunet_plugin_ats2_simple_done (void *cls) | 1068 | libgnunet_plugin_ats2_simple_done(void *cls) |
1077 | { | 1069 | { |
1078 | struct GNUNET_ATS_SolverFunctions *sf = cls; | 1070 | struct GNUNET_ATS_SolverFunctions *sf = cls; |
1079 | struct SimpleHandle *s = sf->cls; | 1071 | struct SimpleHandle *s = sf->cls; |
1080 | 1072 | ||
1081 | GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (s->peers)); | 1073 | GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(s->peers)); |
1082 | GNUNET_CONTAINER_multipeermap_destroy (s->peers); | 1074 | GNUNET_CONTAINER_multipeermap_destroy(s->peers); |
1083 | GNUNET_PEERSTORE_disconnect (s->ps, GNUNET_NO); | 1075 | GNUNET_PEERSTORE_disconnect(s->ps, GNUNET_NO); |
1084 | GNUNET_free (s); | 1076 | GNUNET_free(s); |
1085 | return NULL; | 1077 | return NULL; |
1086 | } | 1078 | } |
1087 | 1079 | ||