diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_channel.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_channel.c | 1870 |
1 files changed, 935 insertions, 935 deletions
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index 664b8a7c1..dad5325fc 100644 --- a/src/cadet/gnunet-service-cadet_channel.c +++ b/src/cadet/gnunet-service-cadet_channel.c | |||
@@ -16,7 +16,7 @@ | |||
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 | */ |
20 | /** | 20 | /** |
21 | * @file cadet/gnunet-service-cadet_channel.c | 21 | * @file cadet/gnunet-service-cadet_channel.c |
22 | * @brief logical links between CADET clients | 22 | * @brief logical links between CADET clients |
@@ -41,26 +41,26 @@ | |||
41 | #include "gnunet-service-cadet_tunnels.h" | 41 | #include "gnunet-service-cadet_tunnels.h" |
42 | #include "gnunet-service-cadet_paths.h" | 42 | #include "gnunet-service-cadet_paths.h" |
43 | 43 | ||
44 | #define LOG(level, ...) GNUNET_log_from (level, "cadet-chn", __VA_ARGS__) | 44 | #define LOG(level, ...) GNUNET_log_from(level, "cadet-chn", __VA_ARGS__) |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * How long do we initially wait before retransmitting? | 47 | * How long do we initially wait before retransmitting? |
48 | */ | 48 | */ |
49 | #define CADET_INITIAL_RETRANSMIT_TIME \ | 49 | #define CADET_INITIAL_RETRANSMIT_TIME \ |
50 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) | 50 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * How long do we wait before dropping state about incoming | 53 | * How long do we wait before dropping state about incoming |
54 | * connection to closed port? | 54 | * connection to closed port? |
55 | */ | 55 | */ |
56 | #define TIMEOUT_CLOSED_PORT \ | 56 | #define TIMEOUT_CLOSED_PORT \ |
57 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 57 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * How long do we wait at least before retransmitting ever? | 60 | * How long do we wait at least before retransmitting ever? |
61 | */ | 61 | */ |
62 | #define MIN_RTT_DELAY \ | 62 | #define MIN_RTT_DELAY \ |
63 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 75) | 63 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 75) |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Maximum message ID into the future we accept for out-of-order messages. | 66 | * Maximum message ID into the future we accept for out-of-order messages. |
@@ -78,8 +78,7 @@ | |||
78 | /** | 78 | /** |
79 | * All the states a channel can be in. | 79 | * All the states a channel can be in. |
80 | */ | 80 | */ |
81 | enum CadetChannelState | 81 | enum CadetChannelState { |
82 | { | ||
83 | /** | 82 | /** |
84 | * Uninitialized status, should never appear in operation. | 83 | * Uninitialized status, should never appear in operation. |
85 | */ | 84 | */ |
@@ -108,8 +107,7 @@ enum CadetChannelState | |||
108 | * Note that we DO use this structure also for unreliable | 107 | * Note that we DO use this structure also for unreliable |
109 | * messages. | 108 | * messages. |
110 | */ | 109 | */ |
111 | struct CadetReliableMessage | 110 | struct CadetReliableMessage { |
112 | { | ||
113 | /** | 111 | /** |
114 | * Double linked list, FIFO style | 112 | * Double linked list, FIFO style |
115 | */ | 113 | */ |
@@ -173,8 +171,7 @@ struct CadetReliableMessage | |||
173 | /** | 171 | /** |
174 | * List of received out-of-order data messages. | 172 | * List of received out-of-order data messages. |
175 | */ | 173 | */ |
176 | struct CadetOutOfOrderMessage | 174 | struct CadetOutOfOrderMessage { |
177 | { | ||
178 | /** | 175 | /** |
179 | * Double linked list, FIFO style | 176 | * Double linked list, FIFO style |
180 | */ | 177 | */ |
@@ -203,8 +200,7 @@ struct CadetOutOfOrderMessage | |||
203 | * loopback channel, in which case it has two of these endpoints. | 200 | * loopback channel, in which case it has two of these endpoints. |
204 | * Note that flow control also is required in both directions. | 201 | * Note that flow control also is required in both directions. |
205 | */ | 202 | */ |
206 | struct CadetChannelClient | 203 | struct CadetChannelClient { |
207 | { | ||
208 | /** | 204 | /** |
209 | * Client handle. Not by itself sufficient to designate | 205 | * Client handle. Not by itself sufficient to designate |
210 | * the client endpoint, as the same client handle may | 206 | * the client endpoint, as the same client handle may |
@@ -245,8 +241,7 @@ struct CadetChannelClient | |||
245 | /** | 241 | /** |
246 | * Struct containing all information regarding a channel to a remote client. | 242 | * Struct containing all information regarding a channel to a remote client. |
247 | */ | 243 | */ |
248 | struct CadetChannel | 244 | struct CadetChannel { |
249 | { | ||
250 | /** | 245 | /** |
251 | * Tunnel this channel is in. | 246 | * Tunnel this channel is in. |
252 | */ | 247 | */ |
@@ -391,24 +386,24 @@ struct CadetChannel | |||
391 | * @return Static string with the channel IDs. | 386 | * @return Static string with the channel IDs. |
392 | */ | 387 | */ |
393 | const char * | 388 | const char * |
394 | GCCH_2s (const struct CadetChannel *ch) | 389 | GCCH_2s(const struct CadetChannel *ch) |
395 | { | 390 | { |
396 | static char buf[128]; | 391 | static char buf[128]; |
397 | 392 | ||
398 | GNUNET_snprintf (buf, | 393 | GNUNET_snprintf(buf, |
399 | sizeof (buf), | 394 | sizeof(buf), |
400 | "Channel %s:%s ctn:%X(%X/%X)", | 395 | "Channel %s:%s ctn:%X(%X/%X)", |
401 | (GNUNET_YES == ch->is_loopback) | 396 | (GNUNET_YES == ch->is_loopback) |
402 | ? "loopback" | 397 | ? "loopback" |
403 | : GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))), | 398 | : GNUNET_i2s(GCP_get_id(GCT_get_destination(ch->t))), |
404 | GNUNET_h2s (&ch->port), | 399 | GNUNET_h2s(&ch->port), |
405 | ch->ctn, | 400 | ch->ctn, |
406 | (NULL == ch->owner) | 401 | (NULL == ch->owner) |
407 | ? 0 | 402 | ? 0 |
408 | : ntohl (ch->owner->ccn.channel_of_client), | 403 | : ntohl(ch->owner->ccn.channel_of_client), |
409 | (NULL == ch->dest) | 404 | (NULL == ch->dest) |
410 | ? 0 | 405 | ? 0 |
411 | : ntohl (ch->dest->ccn.channel_of_client)); | 406 | : ntohl(ch->dest->ccn.channel_of_client)); |
412 | return buf; | 407 | return buf; |
413 | } | 408 | } |
414 | 409 | ||
@@ -423,19 +418,19 @@ GCCH_2s (const struct CadetChannel *ch) | |||
423 | * @param listener peer that is listining on @a port | 418 | * @param listener peer that is listining on @a port |
424 | */ | 419 | */ |
425 | void | 420 | void |
426 | GCCH_hash_port (struct GNUNET_HashCode *h_port, | 421 | GCCH_hash_port(struct GNUNET_HashCode *h_port, |
427 | const struct GNUNET_HashCode *port, | 422 | const struct GNUNET_HashCode *port, |
428 | const struct GNUNET_PeerIdentity *listener) | 423 | const struct GNUNET_PeerIdentity *listener) |
429 | { | 424 | { |
430 | struct GNUNET_HashContext *hc; | 425 | struct GNUNET_HashContext *hc; |
431 | 426 | ||
432 | hc = GNUNET_CRYPTO_hash_context_start (); | 427 | hc = GNUNET_CRYPTO_hash_context_start(); |
433 | GNUNET_CRYPTO_hash_context_read (hc, port, sizeof (*port)); | 428 | GNUNET_CRYPTO_hash_context_read(hc, port, sizeof(*port)); |
434 | GNUNET_CRYPTO_hash_context_read (hc, listener, sizeof (*listener)); | 429 | GNUNET_CRYPTO_hash_context_read(hc, listener, sizeof(*listener)); |
435 | GNUNET_CRYPTO_hash_context_finish (hc, h_port); | 430 | GNUNET_CRYPTO_hash_context_finish(hc, h_port); |
436 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 431 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
437 | "Calculated port hash %s\n", | 432 | "Calculated port hash %s\n", |
438 | GNUNET_h2s (h_port)); | 433 | GNUNET_h2s(h_port)); |
439 | } | 434 | } |
440 | 435 | ||
441 | 436 | ||
@@ -447,7 +442,7 @@ GCCH_hash_port (struct GNUNET_HashCode *h_port, | |||
447 | * @return ID used to identify the channel with the remote peer. | 442 | * @return ID used to identify the channel with the remote peer. |
448 | */ | 443 | */ |
449 | struct GNUNET_CADET_ChannelTunnelNumber | 444 | struct GNUNET_CADET_ChannelTunnelNumber |
450 | GCCH_get_id (const struct CadetChannel *ch) | 445 | GCCH_get_id(const struct CadetChannel *ch) |
451 | { | 446 | { |
452 | return ch->ctn; | 447 | return ch->ctn; |
453 | } | 448 | } |
@@ -459,18 +454,18 @@ GCCH_get_id (const struct CadetChannel *ch) | |||
459 | * @param ccc data structure to clean up | 454 | * @param ccc data structure to clean up |
460 | */ | 455 | */ |
461 | static void | 456 | static void |
462 | free_channel_client (struct CadetChannelClient *ccc) | 457 | free_channel_client(struct CadetChannelClient *ccc) |
463 | { | 458 | { |
464 | struct CadetOutOfOrderMessage *com; | 459 | struct CadetOutOfOrderMessage *com; |
465 | 460 | ||
466 | while (NULL != (com = ccc->head_recv)) | 461 | while (NULL != (com = ccc->head_recv)) |
467 | { | 462 | { |
468 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); | 463 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com); |
469 | ccc->num_recv--; | 464 | ccc->num_recv--; |
470 | GNUNET_MQ_discard (com->env); | 465 | GNUNET_MQ_discard(com->env); |
471 | GNUNET_free (com); | 466 | GNUNET_free(com); |
472 | } | 467 | } |
473 | GNUNET_free (ccc); | 468 | GNUNET_free(ccc); |
474 | } | 469 | } |
475 | 470 | ||
476 | 471 | ||
@@ -480,57 +475,57 @@ free_channel_client (struct CadetChannelClient *ccc) | |||
480 | * @param ch channel to destroy | 475 | * @param ch channel to destroy |
481 | */ | 476 | */ |
482 | static void | 477 | static void |
483 | channel_destroy (struct CadetChannel *ch) | 478 | channel_destroy(struct CadetChannel *ch) |
484 | { | 479 | { |
485 | struct CadetReliableMessage *crm; | 480 | struct CadetReliableMessage *crm; |
486 | 481 | ||
487 | while (NULL != (crm = ch->head_sent)) | 482 | while (NULL != (crm = ch->head_sent)) |
488 | { | ||
489 | GNUNET_assert (ch == crm->ch); | ||
490 | if (NULL != crm->qe) | ||
491 | { | 483 | { |
492 | GCT_send_cancel (crm->qe); | 484 | GNUNET_assert(ch == crm->ch); |
493 | crm->qe = NULL; | 485 | if (NULL != crm->qe) |
486 | { | ||
487 | GCT_send_cancel(crm->qe); | ||
488 | crm->qe = NULL; | ||
489 | } | ||
490 | GNUNET_CONTAINER_DLL_remove(ch->head_sent, ch->tail_sent, crm); | ||
491 | GNUNET_free(crm->data_message); | ||
492 | GNUNET_free(crm); | ||
494 | } | 493 | } |
495 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); | ||
496 | GNUNET_free (crm->data_message); | ||
497 | GNUNET_free (crm); | ||
498 | } | ||
499 | if (CADET_CHANNEL_LOOSE == ch->state) | 494 | if (CADET_CHANNEL_LOOSE == ch->state) |
500 | { | 495 | { |
501 | GSC_drop_loose_channel (&ch->h_port, ch); | 496 | GSC_drop_loose_channel(&ch->h_port, ch); |
502 | } | 497 | } |
503 | if (NULL != ch->owner) | 498 | if (NULL != ch->owner) |
504 | { | 499 | { |
505 | free_channel_client (ch->owner); | 500 | free_channel_client(ch->owner); |
506 | ch->owner = NULL; | 501 | ch->owner = NULL; |
507 | } | 502 | } |
508 | if (NULL != ch->dest) | 503 | if (NULL != ch->dest) |
509 | { | 504 | { |
510 | free_channel_client (ch->dest); | 505 | free_channel_client(ch->dest); |
511 | ch->dest = NULL; | 506 | ch->dest = NULL; |
512 | } | 507 | } |
513 | if (NULL != ch->last_control_qe) | 508 | if (NULL != ch->last_control_qe) |
514 | { | 509 | { |
515 | GCT_send_cancel (ch->last_control_qe); | 510 | GCT_send_cancel(ch->last_control_qe); |
516 | ch->last_control_qe = NULL; | 511 | ch->last_control_qe = NULL; |
517 | } | 512 | } |
518 | if (NULL != ch->retry_data_task) | 513 | if (NULL != ch->retry_data_task) |
519 | { | 514 | { |
520 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 515 | GNUNET_SCHEDULER_cancel(ch->retry_data_task); |
521 | ch->retry_data_task = NULL; | 516 | ch->retry_data_task = NULL; |
522 | } | 517 | } |
523 | if (NULL != ch->retry_control_task) | 518 | if (NULL != ch->retry_control_task) |
524 | { | 519 | { |
525 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); | 520 | GNUNET_SCHEDULER_cancel(ch->retry_control_task); |
526 | ch->retry_control_task = NULL; | 521 | ch->retry_control_task = NULL; |
527 | } | 522 | } |
528 | if (GNUNET_NO == ch->is_loopback) | 523 | if (GNUNET_NO == ch->is_loopback) |
529 | { | 524 | { |
530 | GCT_remove_channel (ch->t, ch, ch->ctn); | 525 | GCT_remove_channel(ch->t, ch, ch->ctn); |
531 | ch->t = NULL; | 526 | ch->t = NULL; |
532 | } | 527 | } |
533 | GNUNET_free (ch); | 528 | GNUNET_free(ch); |
534 | } | 529 | } |
535 | 530 | ||
536 | 531 | ||
@@ -540,7 +535,7 @@ channel_destroy (struct CadetChannel *ch) | |||
540 | * @param cls Channel for which to send. | 535 | * @param cls Channel for which to send. |
541 | */ | 536 | */ |
542 | static void | 537 | static void |
543 | send_channel_open (void *cls); | 538 | send_channel_open(void *cls); |
544 | 539 | ||
545 | 540 | ||
546 | /** | 541 | /** |
@@ -552,20 +547,20 @@ send_channel_open (void *cls); | |||
552 | * if transmission failed | 547 | * if transmission failed |
553 | */ | 548 | */ |
554 | static void | 549 | static void |
555 | channel_open_sent_cb (void *cls, | 550 | channel_open_sent_cb(void *cls, |
556 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 551 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
557 | { | 552 | { |
558 | struct CadetChannel *ch = cls; | 553 | struct CadetChannel *ch = cls; |
559 | 554 | ||
560 | GNUNET_assert (NULL != ch->last_control_qe); | 555 | GNUNET_assert(NULL != ch->last_control_qe); |
561 | ch->last_control_qe = NULL; | 556 | ch->last_control_qe = NULL; |
562 | ch->retry_time = GNUNET_TIME_STD_BACKOFF (ch->retry_time); | 557 | ch->retry_time = GNUNET_TIME_STD_BACKOFF(ch->retry_time); |
563 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 558 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
564 | "Sent CADET_CHANNEL_OPEN on %s, retrying in %s\n", | 559 | "Sent CADET_CHANNEL_OPEN on %s, retrying in %s\n", |
565 | GCCH_2s (ch), | 560 | GCCH_2s(ch), |
566 | GNUNET_STRINGS_relative_time_to_string (ch->retry_time, GNUNET_YES)); | 561 | GNUNET_STRINGS_relative_time_to_string(ch->retry_time, GNUNET_YES)); |
567 | ch->retry_control_task = | 562 | ch->retry_control_task = |
568 | GNUNET_SCHEDULER_add_delayed (ch->retry_time, &send_channel_open, ch); | 563 | GNUNET_SCHEDULER_add_delayed(ch->retry_time, &send_channel_open, ch); |
569 | } | 564 | } |
570 | 565 | ||
571 | 566 | ||
@@ -575,27 +570,27 @@ channel_open_sent_cb (void *cls, | |||
575 | * @param cls Channel for which to send. | 570 | * @param cls Channel for which to send. |
576 | */ | 571 | */ |
577 | static void | 572 | static void |
578 | send_channel_open (void *cls) | 573 | send_channel_open(void *cls) |
579 | { | 574 | { |
580 | struct CadetChannel *ch = cls; | 575 | struct CadetChannel *ch = cls; |
581 | struct GNUNET_CADET_ChannelOpenMessage msgcc; | 576 | struct GNUNET_CADET_ChannelOpenMessage msgcc; |
582 | 577 | ||
583 | ch->retry_control_task = NULL; | 578 | ch->retry_control_task = NULL; |
584 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 579 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
585 | "Sending CHANNEL_OPEN message for %s\n", | 580 | "Sending CHANNEL_OPEN message for %s\n", |
586 | GCCH_2s (ch)); | 581 | GCCH_2s(ch)); |
587 | msgcc.header.size = htons (sizeof (msgcc)); | 582 | msgcc.header.size = htons(sizeof(msgcc)); |
588 | msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); | 583 | msgcc.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); |
589 | //TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated "reliable" bit here that was removed. | 584 | //TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated "reliable" bit here that was removed. |
590 | msgcc.opt = 2; | 585 | msgcc.opt = 2; |
591 | msgcc.h_port = ch->h_port; | 586 | msgcc.h_port = ch->h_port; |
592 | msgcc.ctn = ch->ctn; | 587 | msgcc.ctn = ch->ctn; |
593 | ch->state = CADET_CHANNEL_OPEN_SENT; | 588 | ch->state = CADET_CHANNEL_OPEN_SENT; |
594 | if (NULL != ch->last_control_qe) | 589 | if (NULL != ch->last_control_qe) |
595 | GCT_send_cancel (ch->last_control_qe); | 590 | GCT_send_cancel(ch->last_control_qe); |
596 | ch->last_control_qe = | 591 | ch->last_control_qe = |
597 | GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch); | 592 | GCT_send(ch->t, &msgcc.header, &channel_open_sent_cb, ch); |
598 | GNUNET_assert (NULL == ch->retry_control_task); | 593 | GNUNET_assert(NULL == ch->retry_control_task); |
599 | } | 594 | } |
600 | 595 | ||
601 | 596 | ||
@@ -610,13 +605,13 @@ send_channel_open (void *cls) | |||
610 | * @param ch the channel for which the tunnel is now ready | 605 | * @param ch the channel for which the tunnel is now ready |
611 | */ | 606 | */ |
612 | void | 607 | void |
613 | GCCH_tunnel_up (struct CadetChannel *ch) | 608 | GCCH_tunnel_up(struct CadetChannel *ch) |
614 | { | 609 | { |
615 | GNUNET_assert (NULL == ch->retry_control_task); | 610 | GNUNET_assert(NULL == ch->retry_control_task); |
616 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 611 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
617 | "Tunnel up, sending CHANNEL_OPEN on %s now\n", | 612 | "Tunnel up, sending CHANNEL_OPEN on %s now\n", |
618 | GCCH_2s (ch)); | 613 | GCCH_2s(ch)); |
619 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_channel_open, ch); | 614 | ch->retry_control_task = GNUNET_SCHEDULER_add_now(&send_channel_open, ch); |
620 | } | 615 | } |
621 | 616 | ||
622 | 617 | ||
@@ -631,22 +626,22 @@ GCCH_tunnel_up (struct CadetChannel *ch) | |||
631 | * @return handle to the new channel | 626 | * @return handle to the new channel |
632 | */ | 627 | */ |
633 | struct CadetChannel * | 628 | struct CadetChannel * |
634 | GCCH_channel_local_new (struct CadetClient *owner, | 629 | GCCH_channel_local_new(struct CadetClient *owner, |
635 | struct GNUNET_CADET_ClientChannelNumber ccn, | 630 | struct GNUNET_CADET_ClientChannelNumber ccn, |
636 | struct CadetPeer *destination, | 631 | struct CadetPeer *destination, |
637 | const struct GNUNET_HashCode *port, | 632 | const struct GNUNET_HashCode *port, |
638 | uint32_t options) | 633 | uint32_t options) |
639 | { | 634 | { |
640 | struct CadetChannel *ch; | 635 | struct CadetChannel *ch; |
641 | struct CadetChannelClient *ccco; | 636 | struct CadetChannelClient *ccco; |
642 | 637 | ||
643 | ccco = GNUNET_new (struct CadetChannelClient); | 638 | ccco = GNUNET_new(struct CadetChannelClient); |
644 | ccco->c = owner; | 639 | ccco->c = owner; |
645 | ccco->ccn = ccn; | 640 | ccco->ccn = ccn; |
646 | ccco->client_ready = GNUNET_YES; | 641 | ccco->client_ready = GNUNET_YES; |
647 | 642 | ||
648 | ch = GNUNET_new (struct CadetChannel); | 643 | ch = GNUNET_new(struct CadetChannel); |
649 | ch->mid_recv.mid = htonl (1); /* The OPEN_ACK counts as message 0! */ | 644 | ch->mid_recv.mid = htonl(1); /* The OPEN_ACK counts as message 0! */ |
650 | ch->nobuffer = GNUNET_NO; | 645 | ch->nobuffer = GNUNET_NO; |
651 | ch->reliable = GNUNET_YES; | 646 | ch->reliable = GNUNET_YES; |
652 | ch->out_of_order = GNUNET_NO; | 647 | ch->out_of_order = GNUNET_NO; |
@@ -654,44 +649,44 @@ GCCH_channel_local_new (struct CadetClient *owner, | |||
654 | (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ | 649 | (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ |
655 | ch->owner = ccco; | 650 | ch->owner = ccco; |
656 | ch->port = *port; | 651 | ch->port = *port; |
657 | GCCH_hash_port (&ch->h_port, port, GCP_get_id (destination)); | 652 | GCCH_hash_port(&ch->h_port, port, GCP_get_id(destination)); |
658 | if (0 == GNUNET_memcmp (&my_full_id, GCP_get_id (destination))) | 653 | if (0 == GNUNET_memcmp(&my_full_id, GCP_get_id(destination))) |
659 | { | ||
660 | struct OpenPort *op; | ||
661 | |||
662 | ch->is_loopback = GNUNET_YES; | ||
663 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, &ch->h_port); | ||
664 | if (NULL == op) | ||
665 | { | 654 | { |
666 | /* port closed, wait for it to possibly open */ | 655 | struct OpenPort *op; |
667 | ch->state = CADET_CHANNEL_LOOSE; | 656 | |
668 | (void) GNUNET_CONTAINER_multihashmap_put ( | 657 | ch->is_loopback = GNUNET_YES; |
669 | loose_channels, | 658 | op = GNUNET_CONTAINER_multihashmap_get(open_ports, &ch->h_port); |
670 | &ch->h_port, | 659 | if (NULL == op) |
671 | ch, | 660 | { |
672 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 661 | /* port closed, wait for it to possibly open */ |
673 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 662 | ch->state = CADET_CHANNEL_LOOSE; |
674 | "Created loose incoming loopback channel to port %s\n", | 663 | (void)GNUNET_CONTAINER_multihashmap_put( |
675 | GNUNET_h2s (&ch->port)); | 664 | loose_channels, |
665 | &ch->h_port, | ||
666 | ch, | ||
667 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
668 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
669 | "Created loose incoming loopback channel to port %s\n", | ||
670 | GNUNET_h2s(&ch->port)); | ||
671 | } | ||
672 | else | ||
673 | { | ||
674 | GCCH_bind(ch, op->c, &op->port); | ||
675 | } | ||
676 | } | 676 | } |
677 | else | 677 | else |
678 | { | 678 | { |
679 | GCCH_bind (ch, op->c, &op->port); | 679 | ch->t = GCP_get_tunnel(destination, GNUNET_YES); |
680 | ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; | ||
681 | ch->ctn = GCT_add_channel(ch->t, ch); | ||
680 | } | 682 | } |
681 | } | 683 | GNUNET_STATISTICS_update(stats, "# channels", 1, GNUNET_NO); |
682 | else | 684 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
683 | { | 685 | "Created channel to port %s at peer %s for %s using %s\n", |
684 | ch->t = GCP_get_tunnel (destination, GNUNET_YES); | 686 | GNUNET_h2s(port), |
685 | ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; | 687 | GCP_2s(destination), |
686 | ch->ctn = GCT_add_channel (ch->t, ch); | 688 | GSC_2s(owner), |
687 | } | 689 | (GNUNET_YES == ch->is_loopback) ? "loopback" : GCT_2s(ch->t)); |
688 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); | ||
689 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
690 | "Created channel to port %s at peer %s for %s using %s\n", | ||
691 | GNUNET_h2s (port), | ||
692 | GCP_2s (destination), | ||
693 | GSC_2s (owner), | ||
694 | (GNUNET_YES == ch->is_loopback) ? "loopback" : GCT_2s (ch->t)); | ||
695 | return ch; | 690 | return ch; |
696 | } | 691 | } |
697 | 692 | ||
@@ -703,16 +698,16 @@ GCCH_channel_local_new (struct CadetClient *owner, | |||
703 | * @param cls the channel to drop | 698 | * @param cls the channel to drop |
704 | */ | 699 | */ |
705 | static void | 700 | static void |
706 | timeout_closed_cb (void *cls) | 701 | timeout_closed_cb(void *cls) |
707 | { | 702 | { |
708 | struct CadetChannel *ch = cls; | 703 | struct CadetChannel *ch = cls; |
709 | 704 | ||
710 | ch->retry_control_task = NULL; | 705 | ch->retry_control_task = NULL; |
711 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 706 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
712 | "Closing incoming channel to port %s from peer %s due to timeout\n", | 707 | "Closing incoming channel to port %s from peer %s due to timeout\n", |
713 | GNUNET_h2s (&ch->port), | 708 | GNUNET_h2s(&ch->port), |
714 | GCP_2s (GCT_get_destination (ch->t))); | 709 | GCP_2s(GCT_get_destination(ch->t))); |
715 | channel_destroy (ch); | 710 | channel_destroy(ch); |
716 | } | 711 | } |
717 | 712 | ||
718 | 713 | ||
@@ -726,15 +721,15 @@ timeout_closed_cb (void *cls) | |||
726 | * @return handle to the new channel | 721 | * @return handle to the new channel |
727 | */ | 722 | */ |
728 | struct CadetChannel * | 723 | struct CadetChannel * |
729 | GCCH_channel_incoming_new (struct CadetTunnel *t, | 724 | GCCH_channel_incoming_new(struct CadetTunnel *t, |
730 | struct GNUNET_CADET_ChannelTunnelNumber ctn, | 725 | struct GNUNET_CADET_ChannelTunnelNumber ctn, |
731 | const struct GNUNET_HashCode *h_port, | 726 | const struct GNUNET_HashCode *h_port, |
732 | uint32_t options) | 727 | uint32_t options) |
733 | { | 728 | { |
734 | struct CadetChannel *ch; | 729 | struct CadetChannel *ch; |
735 | struct OpenPort *op; | 730 | struct OpenPort *op; |
736 | 731 | ||
737 | ch = GNUNET_new (struct CadetChannel); | 732 | ch = GNUNET_new(struct CadetChannel); |
738 | ch->h_port = *h_port; | 733 | ch->h_port = *h_port; |
739 | ch->t = t; | 734 | ch->t = t; |
740 | ch->ctn = ctn; | 735 | ch->ctn = ctn; |
@@ -744,32 +739,32 @@ GCCH_channel_incoming_new (struct CadetTunnel *t, | |||
744 | ch->out_of_order = GNUNET_NO; | 739 | ch->out_of_order = GNUNET_NO; |
745 | ch->max_pending_messages = | 740 | ch->max_pending_messages = |
746 | (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ | 741 | (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ |
747 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); | 742 | GNUNET_STATISTICS_update(stats, "# channels", 1, GNUNET_NO); |
748 | 743 | ||
749 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, h_port); | 744 | op = GNUNET_CONTAINER_multihashmap_get(open_ports, h_port); |
750 | if (NULL == op) | 745 | if (NULL == op) |
751 | { | 746 | { |
752 | /* port closed, wait for it to possibly open */ | 747 | /* port closed, wait for it to possibly open */ |
753 | ch->state = CADET_CHANNEL_LOOSE; | 748 | ch->state = CADET_CHANNEL_LOOSE; |
754 | (void) GNUNET_CONTAINER_multihashmap_put ( | 749 | (void)GNUNET_CONTAINER_multihashmap_put( |
755 | loose_channels, | 750 | loose_channels, |
756 | &ch->h_port, | 751 | &ch->h_port, |
757 | ch, | 752 | ch, |
758 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 753 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
759 | GNUNET_assert (NULL == ch->retry_control_task); | 754 | GNUNET_assert(NULL == ch->retry_control_task); |
760 | ch->retry_control_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, | 755 | ch->retry_control_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT_CLOSED_PORT, |
761 | &timeout_closed_cb, | 756 | &timeout_closed_cb, |
762 | ch); | 757 | ch); |
763 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 758 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
764 | "Created loose incoming channel to port %s from peer %s\n", | 759 | "Created loose incoming channel to port %s from peer %s\n", |
765 | GNUNET_h2s (&ch->port), | 760 | GNUNET_h2s(&ch->port), |
766 | GCP_2s (GCT_get_destination (ch->t))); | 761 | GCP_2s(GCT_get_destination(ch->t))); |
767 | } | 762 | } |
768 | else | 763 | else |
769 | { | 764 | { |
770 | GCCH_bind (ch, op->c, &op->port); | 765 | GCCH_bind(ch, op->c, &op->port); |
771 | } | 766 | } |
772 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); | 767 | GNUNET_STATISTICS_update(stats, "# channels", 1, GNUNET_NO); |
773 | return ch; | 768 | return ch; |
774 | } | 769 | } |
775 | 770 | ||
@@ -784,12 +779,12 @@ GCCH_channel_incoming_new (struct CadetTunnel *t, | |||
784 | * if transmission failed | 779 | * if transmission failed |
785 | */ | 780 | */ |
786 | static void | 781 | static void |
787 | send_ack_cb (void *cls, | 782 | send_ack_cb(void *cls, |
788 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 783 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
789 | { | 784 | { |
790 | struct CadetChannel *ch = cls; | 785 | struct CadetChannel *ch = cls; |
791 | 786 | ||
792 | GNUNET_assert (NULL != ch->last_control_qe); | 787 | GNUNET_assert(NULL != ch->last_control_qe); |
793 | ch->last_control_qe = NULL; | 788 | ch->last_control_qe = NULL; |
794 | } | 789 | } |
795 | 790 | ||
@@ -800,25 +795,25 @@ send_ack_cb (void *cls, | |||
800 | * @param ch channel to send the #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK for | 795 | * @param ch channel to send the #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK for |
801 | */ | 796 | */ |
802 | static void | 797 | static void |
803 | send_channel_data_ack (struct CadetChannel *ch) | 798 | send_channel_data_ack(struct CadetChannel *ch) |
804 | { | 799 | { |
805 | struct GNUNET_CADET_ChannelDataAckMessage msg; | 800 | struct GNUNET_CADET_ChannelDataAckMessage msg; |
806 | 801 | ||
807 | if (GNUNET_NO == ch->reliable) | 802 | if (GNUNET_NO == ch->reliable) |
808 | return; /* no ACKs */ | 803 | return; /* no ACKs */ |
809 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); | 804 | msg.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); |
810 | msg.header.size = htons (sizeof (msg)); | 805 | msg.header.size = htons(sizeof(msg)); |
811 | msg.ctn = ch->ctn; | 806 | msg.ctn = ch->ctn; |
812 | msg.mid.mid = htonl (ntohl (ch->mid_recv.mid)); | 807 | msg.mid.mid = htonl(ntohl(ch->mid_recv.mid)); |
813 | msg.futures = GNUNET_htonll (ch->mid_futures); | 808 | msg.futures = GNUNET_htonll(ch->mid_futures); |
814 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 809 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
815 | "Sending DATA_ACK %u:%llX via %s\n", | 810 | "Sending DATA_ACK %u:%llX via %s\n", |
816 | (unsigned int) ntohl (msg.mid.mid), | 811 | (unsigned int)ntohl(msg.mid.mid), |
817 | (unsigned long long) ch->mid_futures, | 812 | (unsigned long long)ch->mid_futures, |
818 | GCCH_2s (ch)); | 813 | GCCH_2s(ch)); |
819 | if (NULL != ch->last_control_qe) | 814 | if (NULL != ch->last_control_qe) |
820 | GCT_send_cancel (ch->last_control_qe); | 815 | GCT_send_cancel(ch->last_control_qe); |
821 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); | 816 | ch->last_control_qe = GCT_send(ch->t, &msg.header, &send_ack_cb, ch); |
822 | } | 817 | } |
823 | 818 | ||
824 | 819 | ||
@@ -829,23 +824,23 @@ send_channel_data_ack (struct CadetChannel *ch) | |||
829 | * @param cls the `struct CadetChannel` | 824 | * @param cls the `struct CadetChannel` |
830 | */ | 825 | */ |
831 | static void | 826 | static void |
832 | send_open_ack (void *cls) | 827 | send_open_ack(void *cls) |
833 | { | 828 | { |
834 | struct CadetChannel *ch = cls; | 829 | struct CadetChannel *ch = cls; |
835 | struct GNUNET_CADET_ChannelOpenAckMessage msg; | 830 | struct GNUNET_CADET_ChannelOpenAckMessage msg; |
836 | 831 | ||
837 | ch->retry_control_task = NULL; | 832 | ch->retry_control_task = NULL; |
838 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 833 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
839 | "Sending CHANNEL_OPEN_ACK on %s\n", | 834 | "Sending CHANNEL_OPEN_ACK on %s\n", |
840 | GCCH_2s (ch)); | 835 | GCCH_2s(ch)); |
841 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK); | 836 | msg.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK); |
842 | msg.header.size = htons (sizeof (msg)); | 837 | msg.header.size = htons(sizeof(msg)); |
843 | msg.reserved = htonl (0); | 838 | msg.reserved = htonl(0); |
844 | msg.ctn = ch->ctn; | 839 | msg.ctn = ch->ctn; |
845 | msg.port = ch->port; | 840 | msg.port = ch->port; |
846 | if (NULL != ch->last_control_qe) | 841 | if (NULL != ch->last_control_qe) |
847 | GCT_send_cancel (ch->last_control_qe); | 842 | GCT_send_cancel(ch->last_control_qe); |
848 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); | 843 | ch->last_control_qe = GCT_send(ch->t, &msg.header, &send_ack_cb, ch); |
849 | } | 844 | } |
850 | 845 | ||
851 | 846 | ||
@@ -858,28 +853,28 @@ send_open_ack (void *cls) | |||
858 | * @param cti identifier of the connection that delivered the message | 853 | * @param cti identifier of the connection that delivered the message |
859 | */ | 854 | */ |
860 | void | 855 | void |
861 | GCCH_handle_duplicate_open ( | 856 | GCCH_handle_duplicate_open( |
862 | struct CadetChannel *ch, | 857 | struct CadetChannel *ch, |
863 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | 858 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) |
864 | { | 859 | { |
865 | if (NULL == ch->dest) | 860 | if (NULL == ch->dest) |
866 | { | 861 | { |
867 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 862 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
868 | "Ignoring duplicate CHANNEL_OPEN on %s: port is closed\n", | 863 | "Ignoring duplicate CHANNEL_OPEN on %s: port is closed\n", |
869 | GCCH_2s (ch)); | 864 | GCCH_2s(ch)); |
870 | return; | 865 | return; |
871 | } | 866 | } |
872 | if (NULL != ch->retry_control_task) | 867 | if (NULL != ch->retry_control_task) |
873 | { | 868 | { |
874 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 869 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
875 | "Ignoring duplicate CHANNEL_OPEN on %s: control message is pending\n", | 870 | "Ignoring duplicate CHANNEL_OPEN on %s: control message is pending\n", |
876 | GCCH_2s (ch)); | 871 | GCCH_2s(ch)); |
877 | return; | 872 | return; |
878 | } | 873 | } |
879 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 874 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
880 | "Retransmitting CHANNEL_OPEN_ACK on %s\n", | 875 | "Retransmitting CHANNEL_OPEN_ACK on %s\n", |
881 | GCCH_2s (ch)); | 876 | GCCH_2s(ch)); |
882 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch); | 877 | ch->retry_control_task = GNUNET_SCHEDULER_add_now(&send_open_ack, ch); |
883 | } | 878 | } |
884 | 879 | ||
885 | 880 | ||
@@ -891,7 +886,7 @@ GCCH_handle_duplicate_open ( | |||
891 | * #GNUNET_NO to send to dest | 886 | * #GNUNET_NO to send to dest |
892 | */ | 887 | */ |
893 | static void | 888 | static void |
894 | send_ack_to_client (struct CadetChannel *ch, int to_owner) | 889 | send_ack_to_client(struct CadetChannel *ch, int to_owner) |
895 | { | 890 | { |
896 | struct GNUNET_MQ_Envelope *env; | 891 | struct GNUNET_MQ_Envelope *env; |
897 | struct GNUNET_CADET_LocalAck *ack; | 892 | struct GNUNET_CADET_LocalAck *ack; |
@@ -899,22 +894,22 @@ send_ack_to_client (struct CadetChannel *ch, int to_owner) | |||
899 | 894 | ||
900 | ccc = (GNUNET_YES == to_owner) ? ch->owner : ch->dest; | 895 | ccc = (GNUNET_YES == to_owner) ? ch->owner : ch->dest; |
901 | if (NULL == ccc) | 896 | if (NULL == ccc) |
902 | { | 897 | { |
903 | /* This can happen if we are just getting ACKs after | 898 | /* This can happen if we are just getting ACKs after |
904 | our local client already disconnected. */ | 899 | our local client already disconnected. */ |
905 | GNUNET_assert (GNUNET_YES == ch->destroy); | 900 | GNUNET_assert(GNUNET_YES == ch->destroy); |
906 | return; | 901 | return; |
907 | } | 902 | } |
908 | env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); | 903 | env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); |
909 | ack->ccn = ccc->ccn; | 904 | ack->ccn = ccc->ccn; |
910 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 905 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
911 | "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n", | 906 | "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n", |
912 | GSC_2s (ccc->c), | 907 | GSC_2s(ccc->c), |
913 | (GNUNET_YES == to_owner) ? "owner" : "dest", | 908 | (GNUNET_YES == to_owner) ? "owner" : "dest", |
914 | ntohl (ack->ccn.channel_of_client), | 909 | ntohl(ack->ccn.channel_of_client), |
915 | ch->pending_messages, | 910 | ch->pending_messages, |
916 | ch->max_pending_messages); | 911 | ch->max_pending_messages); |
917 | GSC_send_to_client (ccc->c, env); | 912 | GSC_send_to_client(ccc->c, env); |
918 | } | 913 | } |
919 | 914 | ||
920 | 915 | ||
@@ -928,58 +923,58 @@ send_ack_to_client (struct CadetChannel *ch, int to_owner) | |||
928 | * @param port the port @a is listening on | 923 | * @param port the port @a is listening on |
929 | */ | 924 | */ |
930 | void | 925 | void |
931 | GCCH_bind (struct CadetChannel *ch, | 926 | GCCH_bind(struct CadetChannel *ch, |
932 | struct CadetClient *c, | 927 | struct CadetClient *c, |
933 | const struct GNUNET_HashCode *port) | 928 | const struct GNUNET_HashCode *port) |
934 | { | 929 | { |
935 | uint32_t options; | 930 | uint32_t options; |
936 | struct CadetChannelClient *cccd; | 931 | struct CadetChannelClient *cccd; |
937 | 932 | ||
938 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 933 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
939 | "Binding %s from %s to port %s of %s\n", | 934 | "Binding %s from %s to port %s of %s\n", |
940 | GCCH_2s (ch), | 935 | GCCH_2s(ch), |
941 | GCT_2s (ch->t), | 936 | GCT_2s(ch->t), |
942 | GNUNET_h2s (&ch->port), | 937 | GNUNET_h2s(&ch->port), |
943 | GSC_2s (c)); | 938 | GSC_2s(c)); |
944 | if (NULL != ch->retry_control_task) | 939 | if (NULL != ch->retry_control_task) |
945 | { | 940 | { |
946 | /* there might be a timeout task here */ | 941 | /* there might be a timeout task here */ |
947 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); | 942 | GNUNET_SCHEDULER_cancel(ch->retry_control_task); |
948 | ch->retry_control_task = NULL; | 943 | ch->retry_control_task = NULL; |
949 | } | 944 | } |
950 | options = 0; | 945 | options = 0; |
951 | cccd = GNUNET_new (struct CadetChannelClient); | 946 | cccd = GNUNET_new(struct CadetChannelClient); |
952 | GNUNET_assert (NULL == ch->dest); | 947 | GNUNET_assert(NULL == ch->dest); |
953 | ch->dest = cccd; | 948 | ch->dest = cccd; |
954 | ch->port = *port; | 949 | ch->port = *port; |
955 | cccd->c = c; | 950 | cccd->c = c; |
956 | cccd->client_ready = GNUNET_YES; | 951 | cccd->client_ready = GNUNET_YES; |
957 | cccd->ccn = GSC_bind (c, | 952 | cccd->ccn = GSC_bind(c, |
958 | ch, | 953 | ch, |
959 | (GNUNET_YES == ch->is_loopback) | 954 | (GNUNET_YES == ch->is_loopback) |
960 | ? GCP_get (&my_full_id, GNUNET_YES) | 955 | ? GCP_get(&my_full_id, GNUNET_YES) |
961 | : GCT_get_destination (ch->t), | 956 | : GCT_get_destination(ch->t), |
962 | port, | 957 | port, |
963 | options); | 958 | options); |
964 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < | 959 | GNUNET_assert(ntohl(cccd->ccn.channel_of_client) < |
965 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); | 960 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); |
966 | ch->mid_recv.mid = htonl (1); /* The OPEN counts as message 0! */ | 961 | ch->mid_recv.mid = htonl(1); /* The OPEN counts as message 0! */ |
967 | if (GNUNET_YES == ch->is_loopback) | 962 | if (GNUNET_YES == ch->is_loopback) |
968 | { | 963 | { |
969 | ch->state = CADET_CHANNEL_OPEN_SENT; | 964 | ch->state = CADET_CHANNEL_OPEN_SENT; |
970 | GCCH_handle_channel_open_ack (ch, NULL, port); | 965 | GCCH_handle_channel_open_ack(ch, NULL, port); |
971 | } | 966 | } |
972 | else | 967 | else |
973 | { | 968 | { |
974 | /* notify other peer that we accepted the connection */ | 969 | /* notify other peer that we accepted the connection */ |
975 | ch->state = CADET_CHANNEL_READY; | 970 | ch->state = CADET_CHANNEL_READY; |
976 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch); | 971 | ch->retry_control_task = GNUNET_SCHEDULER_add_now(&send_open_ack, ch); |
977 | } | 972 | } |
978 | /* give client it's initial supply of ACKs */ | 973 | /* give client it's initial supply of ACKs */ |
979 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < | 974 | GNUNET_assert(ntohl(cccd->ccn.channel_of_client) < |
980 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); | 975 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); |
981 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) | 976 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) |
982 | send_ack_to_client (ch, GNUNET_NO); | 977 | send_ack_to_client(ch, GNUNET_NO); |
983 | } | 978 | } |
984 | 979 | ||
985 | 980 | ||
@@ -991,7 +986,7 @@ GCCH_bind (struct CadetChannel *ch, | |||
991 | * @param cls the `struct CadetChannel` where one of the ends is now dead | 986 | * @param cls the `struct CadetChannel` where one of the ends is now dead |
992 | */ | 987 | */ |
993 | static void | 988 | static void |
994 | signal_remote_destroy_cb (void *cls) | 989 | signal_remote_destroy_cb(void *cls) |
995 | { | 990 | { |
996 | struct CadetChannel *ch = cls; | 991 | struct CadetChannel *ch = cls; |
997 | struct CadetChannelClient *ccc; | 992 | struct CadetChannelClient *ccc; |
@@ -999,8 +994,8 @@ signal_remote_destroy_cb (void *cls) | |||
999 | /* Find which end is left... */ | 994 | /* Find which end is left... */ |
1000 | ch->retry_control_task = NULL; | 995 | ch->retry_control_task = NULL; |
1001 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 996 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
1002 | GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch); | 997 | GSC_handle_remote_channel_destroy(ccc->c, ccc->ccn, ch); |
1003 | channel_destroy (ch); | 998 | channel_destroy(ch); |
1004 | } | 999 | } |
1005 | 1000 | ||
1006 | 1001 | ||
@@ -1013,72 +1008,74 @@ signal_remote_destroy_cb (void *cls) | |||
1013 | * @param ccn client number of the client @a c | 1008 | * @param ccn client number of the client @a c |
1014 | */ | 1009 | */ |
1015 | void | 1010 | void |
1016 | GCCH_channel_local_destroy (struct CadetChannel *ch, | 1011 | GCCH_channel_local_destroy(struct CadetChannel *ch, |
1017 | struct CadetClient *c, | 1012 | struct CadetClient *c, |
1018 | struct GNUNET_CADET_ClientChannelNumber ccn) | 1013 | struct GNUNET_CADET_ClientChannelNumber ccn) |
1019 | { | 1014 | { |
1020 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1015 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1021 | "%s asks for destruction of %s\n", | 1016 | "%s asks for destruction of %s\n", |
1022 | GSC_2s (c), | 1017 | GSC_2s(c), |
1023 | GCCH_2s (ch)); | 1018 | GCCH_2s(ch)); |
1024 | GNUNET_assert (NULL != c); | 1019 | GNUNET_assert(NULL != c); |
1025 | if ((NULL != ch->owner) && (c == ch->owner->c) && | 1020 | if ((NULL != ch->owner) && (c == ch->owner->c) && |
1026 | (ccn.channel_of_client == ch->owner->ccn.channel_of_client)) | 1021 | (ccn.channel_of_client == ch->owner->ccn.channel_of_client)) |
1027 | { | 1022 | { |
1028 | free_channel_client (ch->owner); | 1023 | free_channel_client(ch->owner); |
1029 | ch->owner = NULL; | 1024 | ch->owner = NULL; |
1030 | } | 1025 | } |
1031 | else if ((NULL != ch->dest) && (c == ch->dest->c) && | 1026 | else if ((NULL != ch->dest) && (c == ch->dest->c) && |
1032 | (ccn.channel_of_client == ch->dest->ccn.channel_of_client)) | 1027 | (ccn.channel_of_client == ch->dest->ccn.channel_of_client)) |
1033 | { | 1028 | { |
1034 | free_channel_client (ch->dest); | 1029 | free_channel_client(ch->dest); |
1035 | ch->dest = NULL; | 1030 | ch->dest = NULL; |
1036 | } | 1031 | } |
1037 | else | 1032 | else |
1038 | { | 1033 | { |
1039 | GNUNET_assert (0); | 1034 | GNUNET_assert(0); |
1040 | } | 1035 | } |
1041 | 1036 | ||
1042 | if (GNUNET_YES == ch->destroy) | 1037 | if (GNUNET_YES == ch->destroy) |
1043 | { | 1038 | { |
1044 | /* other end already destroyed, with the local client gone, no need | 1039 | /* other end already destroyed, with the local client gone, no need |
1045 | to finish transmissions, just destroy immediately. */ | 1040 | to finish transmissions, just destroy immediately. */ |
1046 | channel_destroy (ch); | 1041 | channel_destroy(ch); |
1047 | return; | 1042 | return; |
1048 | } | 1043 | } |
1049 | if ((NULL != ch->head_sent) && ((NULL != ch->owner) || (NULL != ch->dest))) | 1044 | if ((NULL != ch->head_sent) && ((NULL != ch->owner) || (NULL != ch->dest))) |
1050 | { | 1045 | { |
1051 | /* Wait for other end to destroy us as well, | 1046 | /* Wait for other end to destroy us as well, |
1052 | and otherwise allow send queue to be transmitted first */ | 1047 | and otherwise allow send queue to be transmitted first */ |
1053 | ch->destroy = GNUNET_YES; | 1048 | ch->destroy = GNUNET_YES; |
1054 | return; | 1049 | return; |
1055 | } | 1050 | } |
1056 | if ((GNUNET_YES == ch->is_loopback) && | 1051 | if ((GNUNET_YES == ch->is_loopback) && |
1057 | ((NULL != ch->owner) || (NULL != ch->dest))) | 1052 | ((NULL != ch->owner) || (NULL != ch->dest))) |
1058 | { | 1053 | { |
1059 | if (NULL != ch->retry_control_task) | 1054 | if (NULL != ch->retry_control_task) |
1060 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); | 1055 | GNUNET_SCHEDULER_cancel(ch->retry_control_task); |
1061 | ch->retry_control_task = | 1056 | ch->retry_control_task = |
1062 | GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, ch); | 1057 | GNUNET_SCHEDULER_add_now(&signal_remote_destroy_cb, ch); |
1063 | return; | 1058 | return; |
1064 | } | 1059 | } |
1065 | if (GNUNET_NO == ch->is_loopback) | 1060 | if (GNUNET_NO == ch->is_loopback) |
1066 | { | ||
1067 | /* If the we ever sent the CHANNEL_CREATE, we need to send a destroy message. */ | ||
1068 | switch (ch->state) | ||
1069 | { | 1061 | { |
1070 | case CADET_CHANNEL_NEW: | 1062 | /* If the we ever sent the CHANNEL_CREATE, we need to send a destroy message. */ |
1071 | /* We gave up on a channel that we created as a client to a remote | 1063 | switch (ch->state) |
1072 | target, but that never went anywhere. Nothing to do here. */ | 1064 | { |
1073 | break; | 1065 | case CADET_CHANNEL_NEW: |
1074 | case CADET_CHANNEL_LOOSE: | 1066 | /* We gave up on a channel that we created as a client to a remote |
1075 | break; | 1067 | target, but that never went anywhere. Nothing to do here. */ |
1076 | default: | 1068 | break; |
1077 | GCT_send_channel_destroy (ch->t, ch->ctn); | 1069 | |
1070 | case CADET_CHANNEL_LOOSE: | ||
1071 | break; | ||
1072 | |||
1073 | default: | ||
1074 | GCT_send_channel_destroy(ch->t, ch->ctn); | ||
1075 | } | ||
1078 | } | 1076 | } |
1079 | } | ||
1080 | /* Nothing left to do, just finish destruction */ | 1077 | /* Nothing left to do, just finish destruction */ |
1081 | channel_destroy (ch); | 1078 | channel_destroy(ch); |
1082 | } | 1079 | } |
1083 | 1080 | ||
1084 | 1081 | ||
@@ -1092,57 +1089,60 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, | |||
1092 | * @param port port number (needed to verify receiver knows the port) | 1089 | * @param port port number (needed to verify receiver knows the port) |
1093 | */ | 1090 | */ |
1094 | void | 1091 | void |
1095 | GCCH_handle_channel_open_ack ( | 1092 | GCCH_handle_channel_open_ack( |
1096 | struct CadetChannel *ch, | 1093 | struct CadetChannel *ch, |
1097 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1094 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1098 | const struct GNUNET_HashCode *port) | 1095 | const struct GNUNET_HashCode *port) |
1099 | { | 1096 | { |
1100 | switch (ch->state) | 1097 | switch (ch->state) |
1101 | { | ||
1102 | case CADET_CHANNEL_NEW: | ||
1103 | /* this should be impossible */ | ||
1104 | GNUNET_break (0); | ||
1105 | break; | ||
1106 | case CADET_CHANNEL_LOOSE: | ||
1107 | /* This makes no sense. */ | ||
1108 | GNUNET_break_op (0); | ||
1109 | break; | ||
1110 | case CADET_CHANNEL_OPEN_SENT: | ||
1111 | if (NULL == ch->owner) | ||
1112 | { | ||
1113 | /* We're not the owner, wrong direction! */ | ||
1114 | GNUNET_break_op (0); | ||
1115 | return; | ||
1116 | } | ||
1117 | if (0 != GNUNET_memcmp (&ch->port, port)) | ||
1118 | { | ||
1119 | /* Other peer failed to provide the right port, | ||
1120 | refuse connection. */ | ||
1121 | GNUNET_break_op (0); | ||
1122 | return; | ||
1123 | } | ||
1124 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1125 | "Received CHANNEL_OPEN_ACK for waiting %s, entering READY state\n", | ||
1126 | GCCH_2s (ch)); | ||
1127 | if (NULL != ch->retry_control_task) /* can be NULL if ch->is_loopback */ | ||
1128 | { | 1098 | { |
1129 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); | 1099 | case CADET_CHANNEL_NEW: |
1130 | ch->retry_control_task = NULL; | 1100 | /* this should be impossible */ |
1101 | GNUNET_break(0); | ||
1102 | break; | ||
1103 | |||
1104 | case CADET_CHANNEL_LOOSE: | ||
1105 | /* This makes no sense. */ | ||
1106 | GNUNET_break_op(0); | ||
1107 | break; | ||
1108 | |||
1109 | case CADET_CHANNEL_OPEN_SENT: | ||
1110 | if (NULL == ch->owner) | ||
1111 | { | ||
1112 | /* We're not the owner, wrong direction! */ | ||
1113 | GNUNET_break_op(0); | ||
1114 | return; | ||
1115 | } | ||
1116 | if (0 != GNUNET_memcmp(&ch->port, port)) | ||
1117 | { | ||
1118 | /* Other peer failed to provide the right port, | ||
1119 | refuse connection. */ | ||
1120 | GNUNET_break_op(0); | ||
1121 | return; | ||
1122 | } | ||
1123 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1124 | "Received CHANNEL_OPEN_ACK for waiting %s, entering READY state\n", | ||
1125 | GCCH_2s(ch)); | ||
1126 | if (NULL != ch->retry_control_task) /* can be NULL if ch->is_loopback */ | ||
1127 | { | ||
1128 | GNUNET_SCHEDULER_cancel(ch->retry_control_task); | ||
1129 | ch->retry_control_task = NULL; | ||
1130 | } | ||
1131 | ch->state = CADET_CHANNEL_READY; | ||
1132 | /* On first connect, send client as many ACKs as we allow messages | ||
1133 | to be buffered! */ | ||
1134 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) | ||
1135 | send_ack_to_client(ch, GNUNET_YES); | ||
1136 | break; | ||
1137 | |||
1138 | case CADET_CHANNEL_READY: | ||
1139 | /* duplicate ACK, maybe we retried the CREATE. Ignore. */ | ||
1140 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1141 | "Received duplicate channel OPEN_ACK for %s\n", | ||
1142 | GCCH_2s(ch)); | ||
1143 | GNUNET_STATISTICS_update(stats, "# duplicate CREATE_ACKs", 1, GNUNET_NO); | ||
1144 | break; | ||
1131 | } | 1145 | } |
1132 | ch->state = CADET_CHANNEL_READY; | ||
1133 | /* On first connect, send client as many ACKs as we allow messages | ||
1134 | to be buffered! */ | ||
1135 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) | ||
1136 | send_ack_to_client (ch, GNUNET_YES); | ||
1137 | break; | ||
1138 | case CADET_CHANNEL_READY: | ||
1139 | /* duplicate ACK, maybe we retried the CREATE. Ignore. */ | ||
1140 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1141 | "Received duplicate channel OPEN_ACK for %s\n", | ||
1142 | GCCH_2s (ch)); | ||
1143 | GNUNET_STATISTICS_update (stats, "# duplicate CREATE_ACKs", 1, GNUNET_NO); | ||
1144 | break; | ||
1145 | } | ||
1146 | } | 1146 | } |
1147 | 1147 | ||
1148 | 1148 | ||
@@ -1155,28 +1155,28 @@ GCCH_handle_channel_open_ack ( | |||
1155 | * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO | 1155 | * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO |
1156 | */ | 1156 | */ |
1157 | static int | 1157 | static int |
1158 | is_before (void *cls, | 1158 | is_before(void *cls, |
1159 | struct CadetOutOfOrderMessage *m1, | 1159 | struct CadetOutOfOrderMessage *m1, |
1160 | struct CadetOutOfOrderMessage *m2) | 1160 | struct CadetOutOfOrderMessage *m2) |
1161 | { | 1161 | { |
1162 | int *duplicate = cls; | 1162 | int *duplicate = cls; |
1163 | uint32_t v1 = ntohl (m1->mid.mid); | 1163 | uint32_t v1 = ntohl(m1->mid.mid); |
1164 | uint32_t v2 = ntohl (m2->mid.mid); | 1164 | uint32_t v2 = ntohl(m2->mid.mid); |
1165 | uint32_t delta; | 1165 | uint32_t delta; |
1166 | 1166 | ||
1167 | delta = v2 - v1; | 1167 | delta = v2 - v1; |
1168 | if (0 == delta) | 1168 | if (0 == delta) |
1169 | *duplicate = GNUNET_YES; | 1169 | *duplicate = GNUNET_YES; |
1170 | if (delta > (uint32_t) INT_MAX) | 1170 | if (delta > (uint32_t)INT_MAX) |
1171 | { | 1171 | { |
1172 | /* in overflow range, we can safely assume we wrapped around */ | 1172 | /* in overflow range, we can safely assume we wrapped around */ |
1173 | return GNUNET_NO; | 1173 | return GNUNET_NO; |
1174 | } | 1174 | } |
1175 | else | 1175 | else |
1176 | { | 1176 | { |
1177 | /* result is small, thus v2 > v1, thus m1 < m2 */ | 1177 | /* result is small, thus v2 > v1, thus m1 < m2 */ |
1178 | return GNUNET_YES; | 1178 | return GNUNET_YES; |
1179 | } | 1179 | } |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | 1182 | ||
@@ -1189,7 +1189,7 @@ is_before (void *cls, | |||
1189 | * @param msg message that was received | 1189 | * @param msg message that was received |
1190 | */ | 1190 | */ |
1191 | void | 1191 | void |
1192 | GCCH_handle_channel_plaintext_data ( | 1192 | GCCH_handle_channel_plaintext_data( |
1193 | struct CadetChannel *ch, | 1193 | struct CadetChannel *ch, |
1194 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1194 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1195 | const struct GNUNET_CADET_ChannelAppDataMessage *msg) | 1195 | const struct GNUNET_CADET_ChannelAppDataMessage *msg) |
@@ -1205,239 +1205,239 @@ GCCH_handle_channel_plaintext_data ( | |||
1205 | uint32_t mid_msg; | 1205 | uint32_t mid_msg; |
1206 | uint32_t delta; | 1206 | uint32_t delta; |
1207 | 1207 | ||
1208 | GNUNET_assert (GNUNET_NO == ch->is_loopback); | 1208 | GNUNET_assert(GNUNET_NO == ch->is_loopback); |
1209 | if ((NULL == ch->owner) && (NULL == ch->dest)) | 1209 | if ((NULL == ch->owner) && (NULL == ch->dest)) |
1210 | { | 1210 | { |
1211 | /* This client is gone, but we still have messages to send to | 1211 | /* This client is gone, but we still have messages to send to |
1212 | the other end (which is why @a ch is not yet dead). However, | 1212 | the other end (which is why @a ch is not yet dead). However, |
1213 | we cannot pass messages to our client anymore. */ | 1213 | we cannot pass messages to our client anymore. */ |
1214 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1214 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1215 | "Dropping incoming payload on %s as this end is already closed\n", | 1215 | "Dropping incoming payload on %s as this end is already closed\n", |
1216 | GCCH_2s (ch)); | 1216 | GCCH_2s(ch)); |
1217 | /* send back DESTROY notification to stop further retransmissions! */ | 1217 | /* send back DESTROY notification to stop further retransmissions! */ |
1218 | if (GNUNET_YES == ch->destroy) | 1218 | if (GNUNET_YES == ch->destroy) |
1219 | GCT_send_channel_destroy (ch->t, ch->ctn); | 1219 | GCT_send_channel_destroy(ch->t, ch->ctn); |
1220 | return; | 1220 | return; |
1221 | } | 1221 | } |
1222 | payload_size = ntohs (msg->header.size) - sizeof (*msg); | 1222 | payload_size = ntohs(msg->header.size) - sizeof(*msg); |
1223 | env = GNUNET_MQ_msg_extra (ld, | 1223 | env = GNUNET_MQ_msg_extra(ld, |
1224 | payload_size, | 1224 | payload_size, |
1225 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); | 1225 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); |
1226 | ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; | 1226 | ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; |
1227 | GNUNET_memcpy (&ld[1], &msg[1], payload_size); | 1227 | GNUNET_memcpy(&ld[1], &msg[1], payload_size); |
1228 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 1228 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
1229 | if (GNUNET_YES == ccc->client_ready) | 1229 | if (GNUNET_YES == ccc->client_ready) |
1230 | { | ||
1231 | /* | ||
1232 | * We ad-hoc send the message if | ||
1233 | * - The channel is out-of-order | ||
1234 | * - The channel is reliable and MID matches next expected MID | ||
1235 | * - The channel is unreliable and MID is before lowest seen MID | ||
1236 | */ | ||
1237 | if ((GNUNET_YES == ch->out_of_order) || | ||
1238 | ((msg->mid.mid == ch->mid_recv.mid) && (GNUNET_YES == ch->reliable)) || | ||
1239 | ((GNUNET_NO == ch->reliable) && | ||
1240 | (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) && | ||
1241 | ((NULL == ccc->head_recv) || | ||
1242 | (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid))))) | ||
1243 | { | 1230 | { |
1244 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1231 | /* |
1245 | "Giving %u bytes of payload with MID %u from %s to client %s\n", | 1232 | * We ad-hoc send the message if |
1246 | (unsigned int) payload_size, | 1233 | * - The channel is out-of-order |
1247 | ntohl (msg->mid.mid), | 1234 | * - The channel is reliable and MID matches next expected MID |
1248 | GCCH_2s (ch), | 1235 | * - The channel is unreliable and MID is before lowest seen MID |
1249 | GSC_2s (ccc->c)); | 1236 | */ |
1250 | ccc->client_ready = GNUNET_NO; | 1237 | if ((GNUNET_YES == ch->out_of_order) || |
1251 | GSC_send_to_client (ccc->c, env); | 1238 | ((msg->mid.mid == ch->mid_recv.mid) && (GNUNET_YES == ch->reliable)) || |
1252 | if (GNUNET_NO == ch->out_of_order) | 1239 | ((GNUNET_NO == ch->reliable) && |
1253 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); | 1240 | (ntohl(msg->mid.mid) >= ntohl(ch->mid_recv.mid)) && |
1254 | else | 1241 | ((NULL == ccc->head_recv) || |
1255 | ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid)); | 1242 | (ntohl(msg->mid.mid) < ntohl(ccc->head_recv->mid.mid))))) |
1256 | ch->mid_futures >>= 1; | 1243 | { |
1257 | if ((GNUNET_YES == ch->out_of_order) && (GNUNET_NO == ch->reliable)) | 1244 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1258 | { | 1245 | "Giving %u bytes of payload with MID %u from %s to client %s\n", |
1259 | /* possibly shift by more if we skipped messages */ | 1246 | (unsigned int)payload_size, |
1260 | uint64_t delta = htonl (msg->mid.mid) - 1 - ntohl (ch->mid_recv.mid); | 1247 | ntohl(msg->mid.mid), |
1261 | 1248 | GCCH_2s(ch), | |
1262 | if (delta > 63) | 1249 | GSC_2s(ccc->c)); |
1263 | ch->mid_futures = 0; | 1250 | ccc->client_ready = GNUNET_NO; |
1264 | else | 1251 | GSC_send_to_client(ccc->c, env); |
1265 | ch->mid_futures >>= delta; | 1252 | if (GNUNET_NO == ch->out_of_order) |
1266 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); | 1253 | ch->mid_recv.mid = htonl(1 + ntohl(msg->mid.mid)); |
1267 | } | 1254 | else |
1268 | send_channel_data_ack (ch); | 1255 | ch->mid_recv.mid = htonl(1 + ntohl(ch->mid_recv.mid)); |
1269 | return; | 1256 | ch->mid_futures >>= 1; |
1257 | if ((GNUNET_YES == ch->out_of_order) && (GNUNET_NO == ch->reliable)) | ||
1258 | { | ||
1259 | /* possibly shift by more if we skipped messages */ | ||
1260 | uint64_t delta = htonl(msg->mid.mid) - 1 - ntohl(ch->mid_recv.mid); | ||
1261 | |||
1262 | if (delta > 63) | ||
1263 | ch->mid_futures = 0; | ||
1264 | else | ||
1265 | ch->mid_futures >>= delta; | ||
1266 | ch->mid_recv.mid = htonl(1 + ntohl(msg->mid.mid)); | ||
1267 | } | ||
1268 | send_channel_data_ack(ch); | ||
1269 | return; | ||
1270 | } | ||
1270 | } | 1271 | } |
1271 | } | ||
1272 | 1272 | ||
1273 | if (GNUNET_YES == ch->reliable) | 1273 | if (GNUNET_YES == ch->reliable) |
1274 | { | ||
1275 | /* check if message ought to be dropped because it is ancient/too distant/duplicate */ | ||
1276 | mid_min = ntohl (ch->mid_recv.mid); | ||
1277 | mid_max = mid_min + ch->max_pending_messages; | ||
1278 | mid_msg = ntohl (msg->mid.mid); | ||
1279 | if (((uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) || | ||
1280 | ((uint32_t) (mid_max - mid_msg) > ch->max_pending_messages)) | ||
1281 | { | ||
1282 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1283 | "%s at %u drops ancient or far-future message %u\n", | ||
1284 | GCCH_2s (ch), | ||
1285 | (unsigned int) mid_min, | ||
1286 | ntohl (msg->mid.mid)); | ||
1287 | |||
1288 | GNUNET_STATISTICS_update (stats, | ||
1289 | "# duplicate DATA (ancient or future)", | ||
1290 | 1, | ||
1291 | GNUNET_NO); | ||
1292 | GNUNET_MQ_discard (env); | ||
1293 | send_channel_data_ack (ch); | ||
1294 | return; | ||
1295 | } | ||
1296 | /* mark bit for future ACKs */ | ||
1297 | delta = mid_msg - mid_min - 1; /* overflow/underflow are OK here */ | ||
1298 | if (delta < 64) | ||
1299 | { | 1274 | { |
1300 | if (0 != (ch->mid_futures & (1LLU << delta))) | 1275 | /* check if message ought to be dropped because it is ancient/too distant/duplicate */ |
1301 | { | 1276 | mid_min = ntohl(ch->mid_recv.mid); |
1302 | /* Duplicate within the queue, drop also */ | 1277 | mid_max = mid_min + ch->max_pending_messages; |
1303 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1278 | mid_msg = ntohl(msg->mid.mid); |
1304 | "Duplicate payload of %u bytes on %s (mid %u) dropped\n", | 1279 | if (((uint32_t)(mid_msg - mid_min) > ch->max_pending_messages) || |
1305 | (unsigned int) payload_size, | 1280 | ((uint32_t)(mid_max - mid_msg) > ch->max_pending_messages)) |
1306 | GCCH_2s (ch), | 1281 | { |
1307 | ntohl (msg->mid.mid)); | 1282 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1308 | GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO); | 1283 | "%s at %u drops ancient or far-future message %u\n", |
1309 | GNUNET_MQ_discard (env); | 1284 | GCCH_2s(ch), |
1310 | send_channel_data_ack (ch); | 1285 | (unsigned int)mid_min, |
1311 | return; | 1286 | ntohl(msg->mid.mid)); |
1312 | } | 1287 | |
1313 | ch->mid_futures |= (1LLU << delta); | 1288 | GNUNET_STATISTICS_update(stats, |
1314 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1289 | "# duplicate DATA (ancient or future)", |
1315 | "Marked bit %llX for mid %u (base: %u); now: %llX\n", | 1290 | 1, |
1316 | (1LLU << delta), | 1291 | GNUNET_NO); |
1317 | mid_msg, | 1292 | GNUNET_MQ_discard(env); |
1318 | mid_min, | 1293 | send_channel_data_ack(ch); |
1319 | ch->mid_futures); | 1294 | return; |
1295 | } | ||
1296 | /* mark bit for future ACKs */ | ||
1297 | delta = mid_msg - mid_min - 1; /* overflow/underflow are OK here */ | ||
1298 | if (delta < 64) | ||
1299 | { | ||
1300 | if (0 != (ch->mid_futures & (1LLU << delta))) | ||
1301 | { | ||
1302 | /* Duplicate within the queue, drop also */ | ||
1303 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1304 | "Duplicate payload of %u bytes on %s (mid %u) dropped\n", | ||
1305 | (unsigned int)payload_size, | ||
1306 | GCCH_2s(ch), | ||
1307 | ntohl(msg->mid.mid)); | ||
1308 | GNUNET_STATISTICS_update(stats, "# duplicate DATA", 1, GNUNET_NO); | ||
1309 | GNUNET_MQ_discard(env); | ||
1310 | send_channel_data_ack(ch); | ||
1311 | return; | ||
1312 | } | ||
1313 | ch->mid_futures |= (1LLU << delta); | ||
1314 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1315 | "Marked bit %llX for mid %u (base: %u); now: %llX\n", | ||
1316 | (1LLU << delta), | ||
1317 | mid_msg, | ||
1318 | mid_min, | ||
1319 | ch->mid_futures); | ||
1320 | } | ||
1320 | } | 1321 | } |
1321 | } | ||
1322 | else /* ! ch->reliable */ | 1322 | else /* ! ch->reliable */ |
1323 | { | ||
1324 | struct CadetOutOfOrderMessage *next_msg; | ||
1325 | |||
1326 | /** | ||
1327 | * We always send if possible in this case. | ||
1328 | * It is guaranteed that the queued MID < received MID | ||
1329 | **/ | ||
1330 | if ((NULL != ccc->head_recv) && (GNUNET_YES == ccc->client_ready)) | ||
1331 | { | ||
1332 | next_msg = ccc->head_recv; | ||
1333 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1334 | "Giving queued MID %u from %s to client %s\n", | ||
1335 | ntohl (next_msg->mid.mid), | ||
1336 | GCCH_2s (ch), | ||
1337 | GSC_2s (ccc->c)); | ||
1338 | ccc->client_ready = GNUNET_NO; | ||
1339 | GSC_send_to_client (ccc->c, next_msg->env); | ||
1340 | ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid)); | ||
1341 | ch->mid_futures >>= 1; | ||
1342 | send_channel_data_ack (ch); | ||
1343 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, next_msg); | ||
1344 | ccc->num_recv--; | ||
1345 | /* Do not process duplicate MID */ | ||
1346 | if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */ | ||
1347 | { | ||
1348 | /* Duplicate within the queue, drop */ | ||
1349 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1350 | "Message on %s (mid %u) dropped, duplicate\n", | ||
1351 | GCCH_2s (ch), | ||
1352 | ntohl (msg->mid.mid)); | ||
1353 | GNUNET_free (next_msg); | ||
1354 | GNUNET_MQ_discard (env); | ||
1355 | return; | ||
1356 | } | ||
1357 | GNUNET_free (next_msg); | ||
1358 | } | ||
1359 | |||
1360 | if (ntohl (msg->mid.mid) < ntohl (ch->mid_recv.mid)) /* Old */ | ||
1361 | { | ||
1362 | /* Duplicate within the queue, drop */ | ||
1363 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1364 | "Message on %s (mid %u) dropped, old.\n", | ||
1365 | GCCH_2s (ch), | ||
1366 | ntohl (msg->mid.mid)); | ||
1367 | GNUNET_MQ_discard (env); | ||
1368 | return; | ||
1369 | } | ||
1370 | |||
1371 | /* Channel is unreliable, so we do not ACK. But we also cannot | ||
1372 | allow buffering everything, so check if we have space... */ | ||
1373 | if (ccc->num_recv >= ch->max_pending_messages) | ||
1374 | { | 1323 | { |
1375 | struct CadetOutOfOrderMessage *drop; | 1324 | struct CadetOutOfOrderMessage *next_msg; |
1376 | 1325 | ||
1377 | /* Yep, need to drop. Drop the oldest message in | 1326 | /** |
1378 | the buffer. */ | 1327 | * We always send if possible in this case. |
1379 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1328 | * It is guaranteed that the queued MID < received MID |
1380 | "Queue full due slow client on %s, dropping oldest message\n", | 1329 | **/ |
1381 | GCCH_2s (ch)); | 1330 | if ((NULL != ccc->head_recv) && (GNUNET_YES == ccc->client_ready)) |
1382 | GNUNET_STATISTICS_update (stats, | 1331 | { |
1383 | "# messages dropped due to slow client", | 1332 | next_msg = ccc->head_recv; |
1384 | 1, | 1333 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1385 | GNUNET_NO); | 1334 | "Giving queued MID %u from %s to client %s\n", |
1386 | drop = ccc->head_recv; | 1335 | ntohl(next_msg->mid.mid), |
1387 | GNUNET_assert (NULL != drop); | 1336 | GCCH_2s(ch), |
1388 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, drop); | 1337 | GSC_2s(ccc->c)); |
1389 | ccc->num_recv--; | 1338 | ccc->client_ready = GNUNET_NO; |
1390 | GNUNET_MQ_discard (drop->env); | 1339 | GSC_send_to_client(ccc->c, next_msg->env); |
1391 | GNUNET_free (drop); | 1340 | ch->mid_recv.mid = htonl(1 + ntohl(next_msg->mid.mid)); |
1341 | ch->mid_futures >>= 1; | ||
1342 | send_channel_data_ack(ch); | ||
1343 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, next_msg); | ||
1344 | ccc->num_recv--; | ||
1345 | /* Do not process duplicate MID */ | ||
1346 | if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */ | ||
1347 | { | ||
1348 | /* Duplicate within the queue, drop */ | ||
1349 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1350 | "Message on %s (mid %u) dropped, duplicate\n", | ||
1351 | GCCH_2s(ch), | ||
1352 | ntohl(msg->mid.mid)); | ||
1353 | GNUNET_free(next_msg); | ||
1354 | GNUNET_MQ_discard(env); | ||
1355 | return; | ||
1356 | } | ||
1357 | GNUNET_free(next_msg); | ||
1358 | } | ||
1359 | |||
1360 | if (ntohl(msg->mid.mid) < ntohl(ch->mid_recv.mid)) /* Old */ | ||
1361 | { | ||
1362 | /* Duplicate within the queue, drop */ | ||
1363 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1364 | "Message on %s (mid %u) dropped, old.\n", | ||
1365 | GCCH_2s(ch), | ||
1366 | ntohl(msg->mid.mid)); | ||
1367 | GNUNET_MQ_discard(env); | ||
1368 | return; | ||
1369 | } | ||
1370 | |||
1371 | /* Channel is unreliable, so we do not ACK. But we also cannot | ||
1372 | allow buffering everything, so check if we have space... */ | ||
1373 | if (ccc->num_recv >= ch->max_pending_messages) | ||
1374 | { | ||
1375 | struct CadetOutOfOrderMessage *drop; | ||
1376 | |||
1377 | /* Yep, need to drop. Drop the oldest message in | ||
1378 | the buffer. */ | ||
1379 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1380 | "Queue full due slow client on %s, dropping oldest message\n", | ||
1381 | GCCH_2s(ch)); | ||
1382 | GNUNET_STATISTICS_update(stats, | ||
1383 | "# messages dropped due to slow client", | ||
1384 | 1, | ||
1385 | GNUNET_NO); | ||
1386 | drop = ccc->head_recv; | ||
1387 | GNUNET_assert(NULL != drop); | ||
1388 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, drop); | ||
1389 | ccc->num_recv--; | ||
1390 | GNUNET_MQ_discard(drop->env); | ||
1391 | GNUNET_free(drop); | ||
1392 | } | ||
1392 | } | 1393 | } |
1393 | } | ||
1394 | 1394 | ||
1395 | /* Insert message into sorted out-of-order queue */ | 1395 | /* Insert message into sorted out-of-order queue */ |
1396 | com = GNUNET_new (struct CadetOutOfOrderMessage); | 1396 | com = GNUNET_new(struct CadetOutOfOrderMessage); |
1397 | com->mid = msg->mid; | 1397 | com->mid = msg->mid; |
1398 | com->env = env; | 1398 | com->env = env; |
1399 | duplicate = GNUNET_NO; | 1399 | duplicate = GNUNET_NO; |
1400 | GNUNET_CONTAINER_DLL_insert_sorted (struct CadetOutOfOrderMessage, | 1400 | GNUNET_CONTAINER_DLL_insert_sorted(struct CadetOutOfOrderMessage, |
1401 | is_before, | 1401 | is_before, |
1402 | &duplicate, | 1402 | &duplicate, |
1403 | ccc->head_recv, | 1403 | ccc->head_recv, |
1404 | ccc->tail_recv, | 1404 | ccc->tail_recv, |
1405 | com); | 1405 | com); |
1406 | ccc->num_recv++; | 1406 | ccc->num_recv++; |
1407 | if (GNUNET_YES == duplicate) | 1407 | if (GNUNET_YES == duplicate) |
1408 | { | 1408 | { |
1409 | /* Duplicate within the queue, drop also (this is not covered by | 1409 | /* Duplicate within the queue, drop also (this is not covered by |
1410 | the case above if "delta" >= 64, which could be the case if | 1410 | the case above if "delta" >= 64, which could be the case if |
1411 | max_pending_messages is also >= 64 or if our client is unready | 1411 | max_pending_messages is also >= 64 or if our client is unready |
1412 | and we are seeing retransmissions of the message our client is | 1412 | and we are seeing retransmissions of the message our client is |
1413 | blocked on. */ | 1413 | blocked on. */ |
1414 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1414 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1415 | "Duplicate payload of %u bytes on %s (mid %u) dropped\n", | 1415 | "Duplicate payload of %u bytes on %s (mid %u) dropped\n", |
1416 | (unsigned int) payload_size, | 1416 | (unsigned int)payload_size, |
1417 | GCCH_2s (ch), | 1417 | GCCH_2s(ch), |
1418 | ntohl (msg->mid.mid)); | 1418 | ntohl(msg->mid.mid)); |
1419 | GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO); | 1419 | GNUNET_STATISTICS_update(stats, "# duplicate DATA", 1, GNUNET_NO); |
1420 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); | 1420 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com); |
1421 | ccc->num_recv--; | 1421 | ccc->num_recv--; |
1422 | GNUNET_MQ_discard (com->env); | 1422 | GNUNET_MQ_discard(com->env); |
1423 | GNUNET_free (com); | 1423 | GNUNET_free(com); |
1424 | send_channel_data_ack (ch); | 1424 | send_channel_data_ack(ch); |
1425 | return; | 1425 | return; |
1426 | } | 1426 | } |
1427 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1427 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1428 | "Queued %s payload of %u bytes on %s-%X(%p) (mid %u, need %u first)\n", | 1428 | "Queued %s payload of %u bytes on %s-%X(%p) (mid %u, need %u first)\n", |
1429 | (GNUNET_YES == ccc->client_ready) ? "out-of-order" : "client-not-ready", | 1429 | (GNUNET_YES == ccc->client_ready) ? "out-of-order" : "client-not-ready", |
1430 | (unsigned int) payload_size, | 1430 | (unsigned int)payload_size, |
1431 | GCCH_2s (ch), | 1431 | GCCH_2s(ch), |
1432 | ntohl (ccc->ccn.channel_of_client), | 1432 | ntohl(ccc->ccn.channel_of_client), |
1433 | ccc, | 1433 | ccc, |
1434 | ntohl (msg->mid.mid), | 1434 | ntohl(msg->mid.mid), |
1435 | ntohl (ch->mid_recv.mid)); | 1435 | ntohl(ch->mid_recv.mid)); |
1436 | /* NOTE: this ACK we _could_ skip, as the packet is out-of-order and | 1436 | /* NOTE: this ACK we _could_ skip, as the packet is out-of-order and |
1437 | the sender may already be transmitting the previous one. Needs | 1437 | the sender may already be transmitting the previous one. Needs |
1438 | experimental evaluation to see if/when this ACK helps or | 1438 | experimental evaluation to see if/when this ACK helps or |
1439 | hurts. (We might even want another option.) */ | 1439 | hurts. (We might even want another option.) */ |
1440 | send_channel_data_ack (ch); | 1440 | send_channel_data_ack(ch); |
1441 | } | 1441 | } |
1442 | 1442 | ||
1443 | 1443 | ||
@@ -1452,8 +1452,8 @@ GCCH_handle_channel_plaintext_data ( | |||
1452 | * if transmission failed | 1452 | * if transmission failed |
1453 | */ | 1453 | */ |
1454 | static void | 1454 | static void |
1455 | data_sent_cb (void *cls, | 1455 | data_sent_cb(void *cls, |
1456 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid); | 1456 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid); |
1457 | 1457 | ||
1458 | 1458 | ||
1459 | /** | 1459 | /** |
@@ -1463,19 +1463,19 @@ data_sent_cb (void *cls, | |||
1463 | * @param cls the `struct CadetChannel` where we need to retransmit | 1463 | * @param cls the `struct CadetChannel` where we need to retransmit |
1464 | */ | 1464 | */ |
1465 | static void | 1465 | static void |
1466 | retry_transmission (void *cls) | 1466 | retry_transmission(void *cls) |
1467 | { | 1467 | { |
1468 | struct CadetChannel *ch = cls; | 1468 | struct CadetChannel *ch = cls; |
1469 | struct CadetReliableMessage *crm = ch->head_sent; | 1469 | struct CadetReliableMessage *crm = ch->head_sent; |
1470 | 1470 | ||
1471 | ch->retry_data_task = NULL; | 1471 | ch->retry_data_task = NULL; |
1472 | GNUNET_assert (NULL == crm->qe); | 1472 | GNUNET_assert(NULL == crm->qe); |
1473 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1473 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1474 | "Retrying transmission on %s of message %u\n", | 1474 | "Retrying transmission on %s of message %u\n", |
1475 | GCCH_2s (ch), | 1475 | GCCH_2s(ch), |
1476 | (unsigned int) ntohl (crm->data_message->mid.mid)); | 1476 | (unsigned int)ntohl(crm->data_message->mid.mid)); |
1477 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); | 1477 | crm->qe = GCT_send(ch->t, &crm->data_message->header, &data_sent_cb, crm); |
1478 | GNUNET_assert (NULL == ch->retry_data_task); | 1478 | GNUNET_assert(NULL == ch->retry_data_task); |
1479 | } | 1479 | } |
1480 | 1480 | ||
1481 | 1481 | ||
@@ -1488,36 +1488,36 @@ retry_transmission (void *cls) | |||
1488 | * @param crm the message that got acknowledged | 1488 | * @param crm the message that got acknowledged |
1489 | */ | 1489 | */ |
1490 | static void | 1490 | static void |
1491 | handle_matching_ack (struct CadetChannel *ch, | 1491 | handle_matching_ack(struct CadetChannel *ch, |
1492 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1492 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1493 | struct CadetReliableMessage *crm) | 1493 | struct CadetReliableMessage *crm) |
1494 | { | 1494 | { |
1495 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); | 1495 | GNUNET_CONTAINER_DLL_remove(ch->head_sent, ch->tail_sent, crm); |
1496 | ch->pending_messages--; | 1496 | ch->pending_messages--; |
1497 | GNUNET_assert (ch->pending_messages < ch->max_pending_messages); | 1497 | GNUNET_assert(ch->pending_messages < ch->max_pending_messages); |
1498 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1498 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1499 | "Received DATA_ACK on %s for message %u (%u ACKs pending)\n", | 1499 | "Received DATA_ACK on %s for message %u (%u ACKs pending)\n", |
1500 | GCCH_2s (ch), | 1500 | GCCH_2s(ch), |
1501 | (unsigned int) ntohl (crm->data_message->mid.mid), | 1501 | (unsigned int)ntohl(crm->data_message->mid.mid), |
1502 | ch->pending_messages); | 1502 | ch->pending_messages); |
1503 | if (NULL != crm->qe) | 1503 | if (NULL != crm->qe) |
1504 | { | 1504 | { |
1505 | GCT_send_cancel (crm->qe); | 1505 | GCT_send_cancel(crm->qe); |
1506 | crm->qe = NULL; | 1506 | crm->qe = NULL; |
1507 | } | 1507 | } |
1508 | if ((1 == crm->num_transmissions) && (NULL != cti)) | 1508 | if ((1 == crm->num_transmissions) && (NULL != cti)) |
1509 | { | ||
1510 | GCC_ack_observed (cti); | ||
1511 | if (0 == GNUNET_memcmp (cti, &crm->connection_taken)) | ||
1512 | { | 1509 | { |
1513 | GCC_latency_observed (cti, | 1510 | GCC_ack_observed(cti); |
1514 | GNUNET_TIME_absolute_get_duration ( | 1511 | if (0 == GNUNET_memcmp(cti, &crm->connection_taken)) |
1515 | crm->first_transmission_time)); | 1512 | { |
1513 | GCC_latency_observed(cti, | ||
1514 | GNUNET_TIME_absolute_get_duration( | ||
1515 | crm->first_transmission_time)); | ||
1516 | } | ||
1516 | } | 1517 | } |
1517 | } | 1518 | GNUNET_free(crm->data_message); |
1518 | GNUNET_free (crm->data_message); | 1519 | GNUNET_free(crm); |
1519 | GNUNET_free (crm); | 1520 | send_ack_to_client(ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); |
1520 | send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); | ||
1521 | } | 1521 | } |
1522 | 1522 | ||
1523 | 1523 | ||
@@ -1530,7 +1530,7 @@ handle_matching_ack (struct CadetChannel *ch, | |||
1530 | * @param ack details about what was received | 1530 | * @param ack details about what was received |
1531 | */ | 1531 | */ |
1532 | void | 1532 | void |
1533 | GCCH_handle_channel_plaintext_data_ack ( | 1533 | GCCH_handle_channel_plaintext_data_ack( |
1534 | struct CadetChannel *ch, | 1534 | struct CadetChannel *ch, |
1535 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1535 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1536 | const struct GNUNET_CADET_ChannelDataAckMessage *ack) | 1536 | const struct GNUNET_CADET_ChannelDataAckMessage *ack) |
@@ -1542,72 +1542,72 @@ GCCH_handle_channel_plaintext_data_ack ( | |||
1542 | uint64_t mid_mask; | 1542 | uint64_t mid_mask; |
1543 | unsigned int delta; | 1543 | unsigned int delta; |
1544 | 1544 | ||
1545 | GNUNET_break (GNUNET_NO == ch->is_loopback); | 1545 | GNUNET_break(GNUNET_NO == ch->is_loopback); |
1546 | if (GNUNET_NO == ch->reliable) | 1546 | if (GNUNET_NO == ch->reliable) |
1547 | { | 1547 | { |
1548 | /* not expecting ACKs on unreliable channel, odd */ | 1548 | /* not expecting ACKs on unreliable channel, odd */ |
1549 | GNUNET_break_op (0); | 1549 | GNUNET_break_op(0); |
1550 | return; | 1550 | return; |
1551 | } | 1551 | } |
1552 | /* mid_base is the MID of the next message that the | 1552 | /* mid_base is the MID of the next message that the |
1553 | other peer expects (i.e. that is missing!), everything | 1553 | other peer expects (i.e. that is missing!), everything |
1554 | LOWER (but excluding mid_base itself) was received. */ | 1554 | LOWER (but excluding mid_base itself) was received. */ |
1555 | mid_base = ntohl (ack->mid.mid); | 1555 | mid_base = ntohl(ack->mid.mid); |
1556 | mid_mask = GNUNET_htonll (ack->futures); | 1556 | mid_mask = GNUNET_htonll(ack->futures); |
1557 | found = GNUNET_NO; | 1557 | found = GNUNET_NO; |
1558 | for (crm = ch->head_sent; NULL != crm; crm = crmn) | 1558 | for (crm = ch->head_sent; NULL != crm; crm = crmn) |
1559 | { | ||
1560 | crmn = crm->next; | ||
1561 | delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base); | ||
1562 | if (delta >= UINT_MAX - ch->max_pending_messages) | ||
1563 | { | 1559 | { |
1564 | /* overflow, means crm was a bit in the past, so this ACK counts for it. */ | 1560 | crmn = crm->next; |
1565 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1561 | delta = (unsigned int)(ntohl(crm->data_message->mid.mid) - mid_base); |
1566 | "Got DATA_ACK with base %u satisfying past message %u on %s\n", | 1562 | if (delta >= UINT_MAX - ch->max_pending_messages) |
1567 | (unsigned int) mid_base, | 1563 | { |
1568 | ntohl (crm->data_message->mid.mid), | 1564 | /* overflow, means crm was a bit in the past, so this ACK counts for it. */ |
1569 | GCCH_2s (ch)); | 1565 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1570 | handle_matching_ack (ch, cti, crm); | 1566 | "Got DATA_ACK with base %u satisfying past message %u on %s\n", |
1571 | found = GNUNET_YES; | 1567 | (unsigned int)mid_base, |
1572 | continue; | 1568 | ntohl(crm->data_message->mid.mid), |
1569 | GCCH_2s(ch)); | ||
1570 | handle_matching_ack(ch, cti, crm); | ||
1571 | found = GNUNET_YES; | ||
1572 | continue; | ||
1573 | } | ||
1574 | delta--; | ||
1575 | if (delta >= 64) | ||
1576 | continue; | ||
1577 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1578 | "Testing bit %llX for mid %u (base: %u)\n", | ||
1579 | (1LLU << delta), | ||
1580 | ntohl(crm->data_message->mid.mid), | ||
1581 | mid_base); | ||
1582 | if (0 != (mid_mask & (1LLU << delta))) | ||
1583 | { | ||
1584 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1585 | "Got DATA_ACK with mask for %u on %s\n", | ||
1586 | ntohl(crm->data_message->mid.mid), | ||
1587 | GCCH_2s(ch)); | ||
1588 | handle_matching_ack(ch, cti, crm); | ||
1589 | found = GNUNET_YES; | ||
1590 | } | ||
1573 | } | 1591 | } |
1574 | delta--; | 1592 | if (GNUNET_NO == found) |
1575 | if (delta >= 64) | ||
1576 | continue; | ||
1577 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1578 | "Testing bit %llX for mid %u (base: %u)\n", | ||
1579 | (1LLU << delta), | ||
1580 | ntohl (crm->data_message->mid.mid), | ||
1581 | mid_base); | ||
1582 | if (0 != (mid_mask & (1LLU << delta))) | ||
1583 | { | 1593 | { |
1584 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1594 | /* ACK for message we already dropped, might have been a |
1585 | "Got DATA_ACK with mask for %u on %s\n", | 1595 | duplicate ACK? Ignore. */ |
1586 | ntohl (crm->data_message->mid.mid), | 1596 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1587 | GCCH_2s (ch)); | 1597 | "Duplicate DATA_ACK on %s, ignoring\n", |
1588 | handle_matching_ack (ch, cti, crm); | 1598 | GCCH_2s(ch)); |
1589 | found = GNUNET_YES; | 1599 | GNUNET_STATISTICS_update(stats, "# duplicate DATA_ACKs", 1, GNUNET_NO); |
1600 | return; | ||
1590 | } | 1601 | } |
1591 | } | ||
1592 | if (GNUNET_NO == found) | ||
1593 | { | ||
1594 | /* ACK for message we already dropped, might have been a | ||
1595 | duplicate ACK? Ignore. */ | ||
1596 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1597 | "Duplicate DATA_ACK on %s, ignoring\n", | ||
1598 | GCCH_2s (ch)); | ||
1599 | GNUNET_STATISTICS_update (stats, "# duplicate DATA_ACKs", 1, GNUNET_NO); | ||
1600 | return; | ||
1601 | } | ||
1602 | if (NULL != ch->retry_data_task) | 1602 | if (NULL != ch->retry_data_task) |
1603 | { | 1603 | { |
1604 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 1604 | GNUNET_SCHEDULER_cancel(ch->retry_data_task); |
1605 | ch->retry_data_task = NULL; | 1605 | ch->retry_data_task = NULL; |
1606 | } | 1606 | } |
1607 | if ((NULL != ch->head_sent) && (NULL == ch->head_sent->qe)) | 1607 | if ((NULL != ch->head_sent) && (NULL == ch->head_sent->qe)) |
1608 | ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, | 1608 | ch->retry_data_task = GNUNET_SCHEDULER_add_at(ch->head_sent->next_retry, |
1609 | &retry_transmission, | 1609 | &retry_transmission, |
1610 | ch); | 1610 | ch); |
1611 | } | 1611 | } |
1612 | 1612 | ||
1613 | 1613 | ||
@@ -1621,34 +1621,34 @@ GCCH_handle_channel_plaintext_data_ack ( | |||
1621 | * NULL if we are simulating receiving a destroy due to shutdown | 1621 | * NULL if we are simulating receiving a destroy due to shutdown |
1622 | */ | 1622 | */ |
1623 | void | 1623 | void |
1624 | GCCH_handle_remote_destroy ( | 1624 | GCCH_handle_remote_destroy( |
1625 | struct CadetChannel *ch, | 1625 | struct CadetChannel *ch, |
1626 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | 1626 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) |
1627 | { | 1627 | { |
1628 | struct CadetChannelClient *ccc; | 1628 | struct CadetChannelClient *ccc; |
1629 | 1629 | ||
1630 | GNUNET_assert (GNUNET_NO == ch->is_loopback); | 1630 | GNUNET_assert(GNUNET_NO == ch->is_loopback); |
1631 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1631 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1632 | "Received remote channel DESTROY for %s\n", | 1632 | "Received remote channel DESTROY for %s\n", |
1633 | GCCH_2s (ch)); | 1633 | GCCH_2s(ch)); |
1634 | if (GNUNET_YES == ch->destroy) | 1634 | if (GNUNET_YES == ch->destroy) |
1635 | { | 1635 | { |
1636 | /* Local client already gone, this is instant-death. */ | 1636 | /* Local client already gone, this is instant-death. */ |
1637 | channel_destroy (ch); | 1637 | channel_destroy(ch); |
1638 | return; | 1638 | return; |
1639 | } | 1639 | } |
1640 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 1640 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
1641 | if ((NULL != ccc) && (NULL != ccc->head_recv)) | 1641 | if ((NULL != ccc) && (NULL != ccc->head_recv)) |
1642 | { | 1642 | { |
1643 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1643 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1644 | "Lost end of transmission due to remote shutdown on %s\n", | 1644 | "Lost end of transmission due to remote shutdown on %s\n", |
1645 | GCCH_2s (ch)); | 1645 | GCCH_2s(ch)); |
1646 | /* FIXME: change API to notify client about truncated transmission! */ | 1646 | /* FIXME: change API to notify client about truncated transmission! */ |
1647 | } | 1647 | } |
1648 | ch->destroy = GNUNET_YES; | 1648 | ch->destroy = GNUNET_YES; |
1649 | if (NULL != ccc) | 1649 | if (NULL != ccc) |
1650 | GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch); | 1650 | GSC_handle_remote_channel_destroy(ccc->c, ccc->ccn, ch); |
1651 | channel_destroy (ch); | 1651 | channel_destroy(ch); |
1652 | } | 1652 | } |
1653 | 1653 | ||
1654 | 1654 | ||
@@ -1661,9 +1661,9 @@ GCCH_handle_remote_destroy ( | |||
1661 | * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO | 1661 | * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO |
1662 | */ | 1662 | */ |
1663 | static int | 1663 | static int |
1664 | cmp_crm_by_next_retry (void *cls, | 1664 | cmp_crm_by_next_retry(void *cls, |
1665 | struct CadetReliableMessage *crm1, | 1665 | struct CadetReliableMessage *crm1, |
1666 | struct CadetReliableMessage *crm2) | 1666 | struct CadetReliableMessage *crm2) |
1667 | { | 1667 | { |
1668 | if (crm1->next_retry.abs_value_us < crm2->next_retry.abs_value_us) | 1668 | if (crm1->next_retry.abs_value_us < crm2->next_retry.abs_value_us) |
1669 | return GNUNET_YES; | 1669 | return GNUNET_YES; |
@@ -1682,75 +1682,75 @@ cmp_crm_by_next_retry (void *cls, | |||
1682 | * if transmission failed | 1682 | * if transmission failed |
1683 | */ | 1683 | */ |
1684 | static void | 1684 | static void |
1685 | data_sent_cb (void *cls, | 1685 | data_sent_cb(void *cls, |
1686 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 1686 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
1687 | { | 1687 | { |
1688 | struct CadetReliableMessage *crm = cls; | 1688 | struct CadetReliableMessage *crm = cls; |
1689 | struct CadetChannel *ch = crm->ch; | 1689 | struct CadetChannel *ch = crm->ch; |
1690 | 1690 | ||
1691 | GNUNET_assert (GNUNET_NO == ch->is_loopback); | 1691 | GNUNET_assert(GNUNET_NO == ch->is_loopback); |
1692 | GNUNET_assert (NULL != crm->qe); | 1692 | GNUNET_assert(NULL != crm->qe); |
1693 | crm->qe = NULL; | 1693 | crm->qe = NULL; |
1694 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); | 1694 | GNUNET_CONTAINER_DLL_remove(ch->head_sent, ch->tail_sent, crm); |
1695 | if (GNUNET_NO == ch->reliable) | 1695 | if (GNUNET_NO == ch->reliable) |
1696 | { | 1696 | { |
1697 | GNUNET_free (crm->data_message); | 1697 | GNUNET_free(crm->data_message); |
1698 | GNUNET_free (crm); | 1698 | GNUNET_free(crm); |
1699 | ch->pending_messages--; | 1699 | ch->pending_messages--; |
1700 | send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); | 1700 | send_ack_to_client(ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); |
1701 | return; | 1701 | return; |
1702 | } | 1702 | } |
1703 | if (NULL == cid) | 1703 | if (NULL == cid) |
1704 | { | 1704 | { |
1705 | /* There was an error sending. */ | 1705 | /* There was an error sending. */ |
1706 | crm->num_transmissions = GNUNET_SYSERR; | 1706 | crm->num_transmissions = GNUNET_SYSERR; |
1707 | } | 1707 | } |
1708 | else if (GNUNET_SYSERR != crm->num_transmissions) | 1708 | else if (GNUNET_SYSERR != crm->num_transmissions) |
1709 | { | ||
1710 | /* Increment transmission counter, and possibly store @a cid | ||
1711 | if this was the first transmission. */ | ||
1712 | crm->num_transmissions++; | ||
1713 | if (1 == crm->num_transmissions) | ||
1714 | { | 1709 | { |
1715 | crm->first_transmission_time = GNUNET_TIME_absolute_get (); | 1710 | /* Increment transmission counter, and possibly store @a cid |
1716 | crm->connection_taken = *cid; | 1711 | if this was the first transmission. */ |
1717 | GCC_ack_expected (cid); | 1712 | crm->num_transmissions++; |
1713 | if (1 == crm->num_transmissions) | ||
1714 | { | ||
1715 | crm->first_transmission_time = GNUNET_TIME_absolute_get(); | ||
1716 | crm->connection_taken = *cid; | ||
1717 | GCC_ack_expected(cid); | ||
1718 | } | ||
1718 | } | 1719 | } |
1719 | } | ||
1720 | if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid)) | 1720 | if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid)) |
1721 | { | 1721 | { |
1722 | struct CadetConnection *cc = GCC_lookup (cid); | 1722 | struct CadetConnection *cc = GCC_lookup(cid); |
1723 | 1723 | ||
1724 | if (NULL != cc) | 1724 | if (NULL != cc) |
1725 | crm->retry_delay = GCC_get_metrics (cc)->aged_latency; | 1725 | crm->retry_delay = GCC_get_metrics(cc)->aged_latency; |
1726 | else | 1726 | else |
1727 | crm->retry_delay = ch->retry_time; | 1727 | crm->retry_delay = ch->retry_time; |
1728 | } | 1728 | } |
1729 | crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay); | 1729 | crm->retry_delay = GNUNET_TIME_STD_BACKOFF(crm->retry_delay); |
1730 | crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, MIN_RTT_DELAY); | 1730 | crm->retry_delay = GNUNET_TIME_relative_max(crm->retry_delay, MIN_RTT_DELAY); |
1731 | crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay); | 1731 | crm->next_retry = GNUNET_TIME_relative_to_absolute(crm->retry_delay); |
1732 | 1732 | ||
1733 | GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage, | 1733 | GNUNET_CONTAINER_DLL_insert_sorted(struct CadetReliableMessage, |
1734 | cmp_crm_by_next_retry, | 1734 | cmp_crm_by_next_retry, |
1735 | NULL, | 1735 | NULL, |
1736 | ch->head_sent, | 1736 | ch->head_sent, |
1737 | ch->tail_sent, | 1737 | ch->tail_sent, |
1738 | crm); | 1738 | crm); |
1739 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1739 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1740 | "Message %u sent, next transmission on %s in %s\n", | 1740 | "Message %u sent, next transmission on %s in %s\n", |
1741 | (unsigned int) ntohl (crm->data_message->mid.mid), | 1741 | (unsigned int)ntohl(crm->data_message->mid.mid), |
1742 | GCCH_2s (ch), | 1742 | GCCH_2s(ch), |
1743 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( | 1743 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining( |
1744 | ch->head_sent->next_retry), | 1744 | ch->head_sent->next_retry), |
1745 | GNUNET_YES)); | 1745 | GNUNET_YES)); |
1746 | if (NULL == ch->head_sent->qe) | 1746 | if (NULL == ch->head_sent->qe) |
1747 | { | 1747 | { |
1748 | if (NULL != ch->retry_data_task) | 1748 | if (NULL != ch->retry_data_task) |
1749 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 1749 | GNUNET_SCHEDULER_cancel(ch->retry_data_task); |
1750 | ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, | 1750 | ch->retry_data_task = GNUNET_SCHEDULER_add_at(ch->head_sent->next_retry, |
1751 | &retry_transmission, | 1751 | &retry_transmission, |
1752 | ch); | 1752 | ch); |
1753 | } | 1753 | } |
1754 | } | 1754 | } |
1755 | 1755 | ||
1756 | 1756 | ||
@@ -1769,100 +1769,100 @@ data_sent_cb (void *cls, | |||
1769 | * #GNUNET_SYSERR in case of an error. | 1769 | * #GNUNET_SYSERR in case of an error. |
1770 | */ | 1770 | */ |
1771 | int | 1771 | int |
1772 | GCCH_handle_local_data (struct CadetChannel *ch, | 1772 | GCCH_handle_local_data(struct CadetChannel *ch, |
1773 | struct GNUNET_CADET_ClientChannelNumber sender_ccn, | 1773 | struct GNUNET_CADET_ClientChannelNumber sender_ccn, |
1774 | const char *buf, | 1774 | const char *buf, |
1775 | size_t buf_len) | 1775 | size_t buf_len) |
1776 | { | 1776 | { |
1777 | struct CadetReliableMessage *crm; | 1777 | struct CadetReliableMessage *crm; |
1778 | 1778 | ||
1779 | if (ch->pending_messages >= ch->max_pending_messages) | 1779 | if (ch->pending_messages >= ch->max_pending_messages) |
1780 | { | ||
1781 | GNUNET_break (0); /* Fails: #5370 */ | ||
1782 | return GNUNET_SYSERR; | ||
1783 | } | ||
1784 | if (GNUNET_YES == ch->destroy) | ||
1785 | { | ||
1786 | /* we are going down, drop messages */ | ||
1787 | return GNUNET_OK; | ||
1788 | } | ||
1789 | ch->pending_messages++; | ||
1790 | |||
1791 | if (GNUNET_YES == ch->is_loopback) | ||
1792 | { | ||
1793 | struct CadetChannelClient *receiver; | ||
1794 | struct GNUNET_MQ_Envelope *env; | ||
1795 | struct GNUNET_CADET_LocalData *ld; | ||
1796 | int ack_to_owner; | ||
1797 | |||
1798 | env = | ||
1799 | GNUNET_MQ_msg_extra (ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); | ||
1800 | if ((NULL != ch->owner) && | ||
1801 | (sender_ccn.channel_of_client == ch->owner->ccn.channel_of_client)) | ||
1802 | { | ||
1803 | receiver = ch->dest; | ||
1804 | ack_to_owner = GNUNET_YES; | ||
1805 | } | ||
1806 | else if ((NULL != ch->dest) && | ||
1807 | (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client)) | ||
1808 | { | ||
1809 | receiver = ch->owner; | ||
1810 | ack_to_owner = GNUNET_NO; | ||
1811 | } | ||
1812 | else | ||
1813 | { | 1780 | { |
1814 | GNUNET_break (0); | 1781 | GNUNET_break(0); /* Fails: #5370 */ |
1815 | return GNUNET_SYSERR; | 1782 | return GNUNET_SYSERR; |
1816 | } | 1783 | } |
1817 | GNUNET_assert (NULL != receiver); | 1784 | if (GNUNET_YES == ch->destroy) |
1818 | ld->ccn = receiver->ccn; | ||
1819 | GNUNET_memcpy (&ld[1], buf, buf_len); | ||
1820 | if (GNUNET_YES == receiver->client_ready) | ||
1821 | { | 1785 | { |
1822 | ch->pending_messages--; | 1786 | /* we are going down, drop messages */ |
1823 | GSC_send_to_client (receiver->c, env); | 1787 | return GNUNET_OK; |
1824 | send_ack_to_client (ch, ack_to_owner); | ||
1825 | } | 1788 | } |
1826 | else | 1789 | ch->pending_messages++; |
1790 | |||
1791 | if (GNUNET_YES == ch->is_loopback) | ||
1827 | { | 1792 | { |
1828 | struct CadetOutOfOrderMessage *oom; | 1793 | struct CadetChannelClient *receiver; |
1829 | 1794 | struct GNUNET_MQ_Envelope *env; | |
1830 | oom = GNUNET_new (struct CadetOutOfOrderMessage); | 1795 | struct GNUNET_CADET_LocalData *ld; |
1831 | oom->env = env; | 1796 | int ack_to_owner; |
1832 | GNUNET_CONTAINER_DLL_insert_tail (receiver->head_recv, | 1797 | |
1833 | receiver->tail_recv, | 1798 | env = |
1834 | oom); | 1799 | GNUNET_MQ_msg_extra(ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); |
1835 | receiver->num_recv++; | 1800 | if ((NULL != ch->owner) && |
1801 | (sender_ccn.channel_of_client == ch->owner->ccn.channel_of_client)) | ||
1802 | { | ||
1803 | receiver = ch->dest; | ||
1804 | ack_to_owner = GNUNET_YES; | ||
1805 | } | ||
1806 | else if ((NULL != ch->dest) && | ||
1807 | (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client)) | ||
1808 | { | ||
1809 | receiver = ch->owner; | ||
1810 | ack_to_owner = GNUNET_NO; | ||
1811 | } | ||
1812 | else | ||
1813 | { | ||
1814 | GNUNET_break(0); | ||
1815 | return GNUNET_SYSERR; | ||
1816 | } | ||
1817 | GNUNET_assert(NULL != receiver); | ||
1818 | ld->ccn = receiver->ccn; | ||
1819 | GNUNET_memcpy(&ld[1], buf, buf_len); | ||
1820 | if (GNUNET_YES == receiver->client_ready) | ||
1821 | { | ||
1822 | ch->pending_messages--; | ||
1823 | GSC_send_to_client(receiver->c, env); | ||
1824 | send_ack_to_client(ch, ack_to_owner); | ||
1825 | } | ||
1826 | else | ||
1827 | { | ||
1828 | struct CadetOutOfOrderMessage *oom; | ||
1829 | |||
1830 | oom = GNUNET_new(struct CadetOutOfOrderMessage); | ||
1831 | oom->env = env; | ||
1832 | GNUNET_CONTAINER_DLL_insert_tail(receiver->head_recv, | ||
1833 | receiver->tail_recv, | ||
1834 | oom); | ||
1835 | receiver->num_recv++; | ||
1836 | } | ||
1837 | return GNUNET_OK; | ||
1836 | } | 1838 | } |
1837 | return GNUNET_OK; | ||
1838 | } | ||
1839 | 1839 | ||
1840 | /* Everything is correct, send the message. */ | 1840 | /* Everything is correct, send the message. */ |
1841 | crm = GNUNET_malloc (sizeof (*crm)); | 1841 | crm = GNUNET_malloc(sizeof(*crm)); |
1842 | crm->ch = ch; | 1842 | crm->ch = ch; |
1843 | crm->data_message = GNUNET_malloc ( | 1843 | crm->data_message = GNUNET_malloc( |
1844 | sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); | 1844 | sizeof(struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); |
1845 | crm->data_message->header.size = | 1845 | crm->data_message->header.size = |
1846 | htons (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); | 1846 | htons(sizeof(struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); |
1847 | crm->data_message->header.type = | 1847 | crm->data_message->header.type = |
1848 | htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); | 1848 | htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); |
1849 | ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); | 1849 | ch->mid_send.mid = htonl(ntohl(ch->mid_send.mid) + 1); |
1850 | crm->data_message->mid = ch->mid_send; | 1850 | crm->data_message->mid = ch->mid_send; |
1851 | crm->data_message->ctn = ch->ctn; | 1851 | crm->data_message->ctn = ch->ctn; |
1852 | GNUNET_memcpy (&crm->data_message[1], buf, buf_len); | 1852 | GNUNET_memcpy(&crm->data_message[1], buf, buf_len); |
1853 | GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, ch->tail_sent, crm); | 1853 | GNUNET_CONTAINER_DLL_insert_tail(ch->head_sent, ch->tail_sent, crm); |
1854 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1854 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1855 | "Sending message %u from local client to %s with %u bytes\n", | 1855 | "Sending message %u from local client to %s with %u bytes\n", |
1856 | ntohl (crm->data_message->mid.mid), | 1856 | ntohl(crm->data_message->mid.mid), |
1857 | GCCH_2s (ch), | 1857 | GCCH_2s(ch), |
1858 | buf_len); | 1858 | buf_len); |
1859 | if (NULL != ch->retry_data_task) | 1859 | if (NULL != ch->retry_data_task) |
1860 | { | 1860 | { |
1861 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 1861 | GNUNET_SCHEDULER_cancel(ch->retry_data_task); |
1862 | ch->retry_data_task = NULL; | 1862 | ch->retry_data_task = NULL; |
1863 | } | 1863 | } |
1864 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); | 1864 | crm->qe = GCT_send(ch->t, &crm->data_message->header, &data_sent_cb, crm); |
1865 | GNUNET_assert (NULL == ch->retry_data_task); | 1865 | GNUNET_assert(NULL == ch->retry_data_task); |
1866 | return GNUNET_OK; | 1866 | return GNUNET_OK; |
1867 | } | 1867 | } |
1868 | 1868 | ||
@@ -1875,8 +1875,8 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1875 | * @param client_ccn ccn of the client sending the ack | 1875 | * @param client_ccn ccn of the client sending the ack |
1876 | */ | 1876 | */ |
1877 | void | 1877 | void |
1878 | GCCH_handle_local_ack (struct CadetChannel *ch, | 1878 | GCCH_handle_local_ack(struct CadetChannel *ch, |
1879 | struct GNUNET_CADET_ClientChannelNumber client_ccn) | 1879 | struct GNUNET_CADET_ClientChannelNumber client_ccn) |
1880 | { | 1880 | { |
1881 | struct CadetChannelClient *ccc; | 1881 | struct CadetChannelClient *ccc; |
1882 | struct CadetOutOfOrderMessage *com; | 1882 | struct CadetOutOfOrderMessage *com; |
@@ -1888,87 +1888,87 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
1888 | (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client)) | 1888 | (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client)) |
1889 | ccc = ch->dest; | 1889 | ccc = ch->dest; |
1890 | else | 1890 | else |
1891 | GNUNET_assert (0); | 1891 | GNUNET_assert(0); |
1892 | ccc->client_ready = GNUNET_YES; | 1892 | ccc->client_ready = GNUNET_YES; |
1893 | com = ccc->head_recv; | 1893 | com = ccc->head_recv; |
1894 | if (NULL == com) | 1894 | if (NULL == com) |
1895 | { | ||
1896 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1897 | "Got LOCAL_ACK, %s-%X ready to receive more data, but none pending on %s-%X(%p)!\n", | ||
1898 | GSC_2s (ccc->c), | ||
1899 | ntohl (client_ccn.channel_of_client), | ||
1900 | GCCH_2s (ch), | ||
1901 | ntohl (ccc->ccn.channel_of_client), | ||
1902 | ccc); | ||
1903 | return; /* none pending */ | ||
1904 | } | ||
1905 | if (GNUNET_YES == ch->is_loopback) | ||
1906 | { | ||
1907 | int to_owner; | ||
1908 | |||
1909 | /* Messages are always in-order, just send */ | ||
1910 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); | ||
1911 | ccc->num_recv--; | ||
1912 | GSC_send_to_client (ccc->c, com->env); | ||
1913 | /* Notify sender that we can receive more */ | ||
1914 | if ((NULL != ch->owner) && | ||
1915 | (ccc->ccn.channel_of_client == ch->owner->ccn.channel_of_client)) | ||
1916 | { | 1895 | { |
1917 | to_owner = GNUNET_NO; | 1896 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1897 | "Got LOCAL_ACK, %s-%X ready to receive more data, but none pending on %s-%X(%p)!\n", | ||
1898 | GSC_2s(ccc->c), | ||
1899 | ntohl(client_ccn.channel_of_client), | ||
1900 | GCCH_2s(ch), | ||
1901 | ntohl(ccc->ccn.channel_of_client), | ||
1902 | ccc); | ||
1903 | return; /* none pending */ | ||
1918 | } | 1904 | } |
1919 | else | 1905 | if (GNUNET_YES == ch->is_loopback) |
1920 | { | 1906 | { |
1921 | GNUNET_assert ((NULL != ch->dest) && (ccc->ccn.channel_of_client == | 1907 | int to_owner; |
1922 | ch->dest->ccn.channel_of_client)); | 1908 | |
1923 | to_owner = GNUNET_YES; | 1909 | /* Messages are always in-order, just send */ |
1910 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com); | ||
1911 | ccc->num_recv--; | ||
1912 | GSC_send_to_client(ccc->c, com->env); | ||
1913 | /* Notify sender that we can receive more */ | ||
1914 | if ((NULL != ch->owner) && | ||
1915 | (ccc->ccn.channel_of_client == ch->owner->ccn.channel_of_client)) | ||
1916 | { | ||
1917 | to_owner = GNUNET_NO; | ||
1918 | } | ||
1919 | else | ||
1920 | { | ||
1921 | GNUNET_assert((NULL != ch->dest) && (ccc->ccn.channel_of_client == | ||
1922 | ch->dest->ccn.channel_of_client)); | ||
1923 | to_owner = GNUNET_YES; | ||
1924 | } | ||
1925 | send_ack_to_client(ch, to_owner); | ||
1926 | GNUNET_free(com); | ||
1927 | return; | ||
1924 | } | 1928 | } |
1925 | send_ack_to_client (ch, to_owner); | ||
1926 | GNUNET_free (com); | ||
1927 | return; | ||
1928 | } | ||
1929 | 1929 | ||
1930 | if ((com->mid.mid != ch->mid_recv.mid) && (GNUNET_NO == ch->out_of_order) && | 1930 | if ((com->mid.mid != ch->mid_recv.mid) && (GNUNET_NO == ch->out_of_order) && |
1931 | (GNUNET_YES == ch->reliable)) | 1931 | (GNUNET_YES == ch->reliable)) |
1932 | { | 1932 | { |
1933 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1933 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1934 | "Got LOCAL_ACK, %s-%X ready to receive more data (but next one is out-of-order %u vs. %u)!\n", | 1934 | "Got LOCAL_ACK, %s-%X ready to receive more data (but next one is out-of-order %u vs. %u)!\n", |
1935 | GSC_2s (ccc->c), | 1935 | GSC_2s(ccc->c), |
1936 | ntohl (ccc->ccn.channel_of_client), | 1936 | ntohl(ccc->ccn.channel_of_client), |
1937 | ntohl (com->mid.mid), | 1937 | ntohl(com->mid.mid), |
1938 | ntohl (ch->mid_recv.mid)); | 1938 | ntohl(ch->mid_recv.mid)); |
1939 | return; /* missing next one in-order */ | 1939 | return; /* missing next one in-order */ |
1940 | } | 1940 | } |
1941 | 1941 | ||
1942 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1942 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1943 | "Got LOCAL_ACK, giving payload message %u to %s-%X on %s\n", | 1943 | "Got LOCAL_ACK, giving payload message %u to %s-%X on %s\n", |
1944 | ntohl (com->mid.mid), | 1944 | ntohl(com->mid.mid), |
1945 | GSC_2s (ccc->c), | 1945 | GSC_2s(ccc->c), |
1946 | ntohl (ccc->ccn.channel_of_client), | 1946 | ntohl(ccc->ccn.channel_of_client), |
1947 | GCCH_2s (ch)); | 1947 | GCCH_2s(ch)); |
1948 | 1948 | ||
1949 | /* all good, pass next message to client */ | 1949 | /* all good, pass next message to client */ |
1950 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); | 1950 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com); |
1951 | ccc->num_recv--; | 1951 | ccc->num_recv--; |
1952 | /* FIXME: if unreliable, this is not aggressive | 1952 | /* FIXME: if unreliable, this is not aggressive |
1953 | enough, as it would be OK to have lost some! */ | 1953 | enough, as it would be OK to have lost some! */ |
1954 | 1954 | ||
1955 | ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid)); | 1955 | ch->mid_recv.mid = htonl(1 + ntohl(com->mid.mid)); |
1956 | ch->mid_futures >>= 1; /* equivalent to division by 2 */ | 1956 | ch->mid_futures >>= 1; /* equivalent to division by 2 */ |
1957 | ccc->client_ready = GNUNET_NO; | 1957 | ccc->client_ready = GNUNET_NO; |
1958 | GSC_send_to_client (ccc->c, com->env); | 1958 | GSC_send_to_client(ccc->c, com->env); |
1959 | GNUNET_free (com); | 1959 | GNUNET_free(com); |
1960 | send_channel_data_ack (ch); | 1960 | send_channel_data_ack(ch); |
1961 | if (NULL != ccc->head_recv) | 1961 | if (NULL != ccc->head_recv) |
1962 | return; | 1962 | return; |
1963 | if (GNUNET_NO == ch->destroy) | 1963 | if (GNUNET_NO == ch->destroy) |
1964 | return; | 1964 | return; |
1965 | GCT_send_channel_destroy (ch->t, ch->ctn); | 1965 | GCT_send_channel_destroy(ch->t, ch->ctn); |
1966 | channel_destroy (ch); | 1966 | channel_destroy(ch); |
1967 | } | 1967 | } |
1968 | 1968 | ||
1969 | 1969 | ||
1970 | #define LOG2(level, ...) \ | 1970 | #define LOG2(level, ...) \ |
1971 | GNUNET_log_from_nocheck (level, "cadet-chn", __VA_ARGS__) | 1971 | GNUNET_log_from_nocheck(level, "cadet-chn", __VA_ARGS__) |
1972 | 1972 | ||
1973 | 1973 | ||
1974 | /** | 1974 | /** |
@@ -1978,46 +1978,46 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
1978 | * @param level Debug level to use. | 1978 | * @param level Debug level to use. |
1979 | */ | 1979 | */ |
1980 | void | 1980 | void |
1981 | GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level) | 1981 | GCCH_debug(struct CadetChannel *ch, enum GNUNET_ErrorType level) |
1982 | { | 1982 | { |
1983 | #if ! defined(GNUNET_CULL_LOGGING) | 1983 | #if !defined(GNUNET_CULL_LOGGING) |
1984 | int do_log; | 1984 | int do_log; |
1985 | 1985 | ||
1986 | do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK), | 1986 | do_log = GNUNET_get_log_call_status(level & (~GNUNET_ERROR_TYPE_BULK), |
1987 | "cadet-chn", | 1987 | "cadet-chn", |
1988 | __FILE__, | 1988 | __FILE__, |
1989 | __FUNCTION__, | 1989 | __FUNCTION__, |
1990 | __LINE__); | 1990 | __LINE__); |
1991 | if (0 == do_log) | 1991 | if (0 == do_log) |
1992 | return; | 1992 | return; |
1993 | 1993 | ||
1994 | if (NULL == ch) | 1994 | if (NULL == ch) |
1995 | { | 1995 | { |
1996 | LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n"); | 1996 | LOG2(level, "CHN *** DEBUG NULL CHANNEL ***\n"); |
1997 | return; | 1997 | return; |
1998 | } | 1998 | } |
1999 | LOG2 (level, "CHN %s:%X (%p)\n", GCT_2s (ch->t), ch->ctn, ch); | 1999 | LOG2(level, "CHN %s:%X (%p)\n", GCT_2s(ch->t), ch->ctn, ch); |
2000 | if (NULL != ch->owner) | 2000 | if (NULL != ch->owner) |
2001 | { | 2001 | { |
2002 | LOG2 (level, | 2002 | LOG2(level, |
2003 | "CHN origin %s ready %s local-id: %u\n", | 2003 | "CHN origin %s ready %s local-id: %u\n", |
2004 | GSC_2s (ch->owner->c), | 2004 | GSC_2s(ch->owner->c), |
2005 | ch->owner->client_ready ? "YES" : "NO", | 2005 | ch->owner->client_ready ? "YES" : "NO", |
2006 | ntohl (ch->owner->ccn.channel_of_client)); | 2006 | ntohl(ch->owner->ccn.channel_of_client)); |
2007 | } | 2007 | } |
2008 | if (NULL != ch->dest) | 2008 | if (NULL != ch->dest) |
2009 | { | 2009 | { |
2010 | LOG2 (level, | 2010 | LOG2(level, |
2011 | "CHN destination %s ready %s local-id: %u\n", | 2011 | "CHN destination %s ready %s local-id: %u\n", |
2012 | GSC_2s (ch->dest->c), | 2012 | GSC_2s(ch->dest->c), |
2013 | ch->dest->client_ready ? "YES" : "NO", | 2013 | ch->dest->client_ready ? "YES" : "NO", |
2014 | ntohl (ch->dest->ccn.channel_of_client)); | 2014 | ntohl(ch->dest->ccn.channel_of_client)); |
2015 | } | 2015 | } |
2016 | LOG2 (level, | 2016 | LOG2(level, |
2017 | "CHN Message IDs recv: %d (%LLX), send: %d\n", | 2017 | "CHN Message IDs recv: %d (%LLX), send: %d\n", |
2018 | ntohl (ch->mid_recv.mid), | 2018 | ntohl(ch->mid_recv.mid), |
2019 | (unsigned long long) ch->mid_futures, | 2019 | (unsigned long long)ch->mid_futures, |
2020 | ntohl (ch->mid_send.mid)); | 2020 | ntohl(ch->mid_send.mid)); |
2021 | #endif | 2021 | #endif |
2022 | } | 2022 | } |
2023 | 2023 | ||