diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-07-17 10:50:45 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-07-17 10:50:45 +0200 |
commit | a7ccf828ae4f7e306ffe3e7efebc0e678615f6c5 (patch) | |
tree | 71489a2649bb3c9100fccc19d135d832d3cbea05 /src/cadet | |
parent | 963c4fe2e94208a251b269e3a6918a71e8de1939 (diff) | |
download | gnunet-a7ccf828ae4f7e306ffe3e7efebc0e678615f6c5.tar.gz gnunet-a7ccf828ae4f7e306ffe3e7efebc0e678615f6c5.zip |
remove duplication MQ options, make conversation build
Diffstat (limited to 'src/cadet')
-rw-r--r-- | src/cadet/gnunet-service-cadet_channel.c | 555 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 269 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet_core.c | 501 |
3 files changed, 504 insertions, 821 deletions
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index 847a217c7..664b8a7c1 100644 --- a/src/cadet/gnunet-service-cadet_channel.c +++ b/src/cadet/gnunet-service-cadet_channel.c | |||
@@ -41,23 +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 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) | 49 | #define CADET_INITIAL_RETRANSMIT_TIME \ |
50 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) | ||
50 | 51 | ||
51 | /** | 52 | /** |
52 | * How long do we wait before dropping state about incoming | 53 | * How long do we wait before dropping state about incoming |
53 | * connection to closed port? | 54 | * connection to closed port? |
54 | */ | 55 | */ |
55 | #define TIMEOUT_CLOSED_PORT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) | 56 | #define TIMEOUT_CLOSED_PORT \ |
57 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
56 | 58 | ||
57 | /** | 59 | /** |
58 | * How long do we wait at least before retransmitting ever? | 60 | * How long do we wait at least before retransmitting ever? |
59 | */ | 61 | */ |
60 | #define MIN_RTT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 75) | 62 | #define MIN_RTT_DELAY \ |
63 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 75) | ||
61 | 64 | ||
62 | /** | 65 | /** |
63 | * 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. |
@@ -164,7 +167,6 @@ struct CadetReliableMessage | |||
164 | * yet transmitted ever, otherwise the number of (re) transmissions. | 167 | * yet transmitted ever, otherwise the number of (re) transmissions. |
165 | */ | 168 | */ |
166 | int num_transmissions; | 169 | int num_transmissions; |
167 | |||
168 | }; | 170 | }; |
169 | 171 | ||
170 | 172 | ||
@@ -193,7 +195,6 @@ struct CadetOutOfOrderMessage | |||
193 | * The envelope with the payload of the out-of-order message | 195 | * The envelope with the payload of the out-of-order message |
194 | */ | 196 | */ |
195 | struct GNUNET_MQ_Envelope *env; | 197 | struct GNUNET_MQ_Envelope *env; |
196 | |||
197 | }; | 198 | }; |
198 | 199 | ||
199 | 200 | ||
@@ -238,7 +239,6 @@ struct CadetChannelClient | |||
238 | * Can we send data to the client? | 239 | * Can we send data to the client? |
239 | */ | 240 | */ |
240 | int client_ready; | 241 | int client_ready; |
241 | |||
242 | }; | 242 | }; |
243 | 243 | ||
244 | 244 | ||
@@ -368,7 +368,7 @@ struct CadetChannel | |||
368 | * Is the tunnel out-of-order? | 368 | * Is the tunnel out-of-order? |
369 | */ | 369 | */ |
370 | int out_of_order; | 370 | int out_of_order; |
371 | 371 | ||
372 | /** | 372 | /** |
373 | * Is this channel a loopback channel, where the destination is us again? | 373 | * Is this channel a loopback channel, where the destination is us again? |
374 | */ | 374 | */ |
@@ -380,7 +380,6 @@ struct CadetChannel | |||
380 | * empty. | 380 | * empty. |
381 | */ | 381 | */ |
382 | int destroy; | 382 | int destroy; |
383 | |||
384 | }; | 383 | }; |
385 | 384 | ||
386 | 385 | ||
@@ -400,12 +399,16 @@ GCCH_2s (const struct CadetChannel *ch) | |||
400 | sizeof (buf), | 399 | sizeof (buf), |
401 | "Channel %s:%s ctn:%X(%X/%X)", | 400 | "Channel %s:%s ctn:%X(%X/%X)", |
402 | (GNUNET_YES == ch->is_loopback) | 401 | (GNUNET_YES == ch->is_loopback) |
403 | ? "loopback" | 402 | ? "loopback" |
404 | : GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))), | 403 | : GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))), |
405 | GNUNET_h2s (&ch->port), | 404 | GNUNET_h2s (&ch->port), |
406 | ch->ctn, | 405 | ch->ctn, |
407 | (NULL == ch->owner) ? 0 : ntohl (ch->owner->ccn.channel_of_client), | 406 | (NULL == ch->owner) |
408 | (NULL == ch->dest) ? 0 : ntohl (ch->dest->ccn.channel_of_client)); | 407 | ? 0 |
408 | : ntohl (ch->owner->ccn.channel_of_client), | ||
409 | (NULL == ch->dest) | ||
410 | ? 0 | ||
411 | : ntohl (ch->dest->ccn.channel_of_client)); | ||
409 | return buf; | 412 | return buf; |
410 | } | 413 | } |
411 | 414 | ||
@@ -421,20 +424,15 @@ GCCH_2s (const struct CadetChannel *ch) | |||
421 | */ | 424 | */ |
422 | void | 425 | void |
423 | GCCH_hash_port (struct GNUNET_HashCode *h_port, | 426 | GCCH_hash_port (struct GNUNET_HashCode *h_port, |
424 | const struct GNUNET_HashCode *port, | 427 | const struct GNUNET_HashCode *port, |
425 | const struct GNUNET_PeerIdentity *listener) | 428 | const struct GNUNET_PeerIdentity *listener) |
426 | { | 429 | { |
427 | struct GNUNET_HashContext *hc; | 430 | struct GNUNET_HashContext *hc; |
428 | 431 | ||
429 | hc = GNUNET_CRYPTO_hash_context_start (); | 432 | hc = GNUNET_CRYPTO_hash_context_start (); |
430 | GNUNET_CRYPTO_hash_context_read (hc, | 433 | GNUNET_CRYPTO_hash_context_read (hc, port, sizeof (*port)); |
431 | port, | 434 | GNUNET_CRYPTO_hash_context_read (hc, listener, sizeof (*listener)); |
432 | sizeof (*port)); | 435 | GNUNET_CRYPTO_hash_context_finish (hc, h_port); |
433 | GNUNET_CRYPTO_hash_context_read (hc, | ||
434 | listener, | ||
435 | sizeof (*listener)); | ||
436 | GNUNET_CRYPTO_hash_context_finish (hc, | ||
437 | h_port); | ||
438 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 436 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
439 | "Calculated port hash %s\n", | 437 | "Calculated port hash %s\n", |
440 | GNUNET_h2s (h_port)); | 438 | GNUNET_h2s (h_port)); |
@@ -467,9 +465,7 @@ free_channel_client (struct CadetChannelClient *ccc) | |||
467 | 465 | ||
468 | while (NULL != (com = ccc->head_recv)) | 466 | while (NULL != (com = ccc->head_recv)) |
469 | { | 467 | { |
470 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, | 468 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); |
471 | ccc->tail_recv, | ||
472 | com); | ||
473 | ccc->num_recv--; | 469 | ccc->num_recv--; |
474 | GNUNET_MQ_discard (com->env); | 470 | GNUNET_MQ_discard (com->env); |
475 | GNUNET_free (com); | 471 | GNUNET_free (com); |
@@ -496,16 +492,13 @@ channel_destroy (struct CadetChannel *ch) | |||
496 | GCT_send_cancel (crm->qe); | 492 | GCT_send_cancel (crm->qe); |
497 | crm->qe = NULL; | 493 | crm->qe = NULL; |
498 | } | 494 | } |
499 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, | 495 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); |
500 | ch->tail_sent, | ||
501 | crm); | ||
502 | GNUNET_free (crm->data_message); | 496 | GNUNET_free (crm->data_message); |
503 | GNUNET_free (crm); | 497 | GNUNET_free (crm); |
504 | } | 498 | } |
505 | if (CADET_CHANNEL_LOOSE == ch->state) | 499 | if (CADET_CHANNEL_LOOSE == ch->state) |
506 | { | 500 | { |
507 | GSC_drop_loose_channel (&ch->h_port, | 501 | GSC_drop_loose_channel (&ch->h_port, ch); |
508 | ch); | ||
509 | } | 502 | } |
510 | if (NULL != ch->owner) | 503 | if (NULL != ch->owner) |
511 | { | 504 | { |
@@ -534,9 +527,7 @@ channel_destroy (struct CadetChannel *ch) | |||
534 | } | 527 | } |
535 | if (GNUNET_NO == ch->is_loopback) | 528 | if (GNUNET_NO == ch->is_loopback) |
536 | { | 529 | { |
537 | GCT_remove_channel (ch->t, | 530 | GCT_remove_channel (ch->t, ch, ch->ctn); |
538 | ch, | ||
539 | ch->ctn); | ||
540 | ch->t = NULL; | 531 | ch->t = NULL; |
541 | } | 532 | } |
542 | GNUNET_free (ch); | 533 | GNUNET_free (ch); |
@@ -572,12 +563,9 @@ channel_open_sent_cb (void *cls, | |||
572 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 563 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
573 | "Sent CADET_CHANNEL_OPEN on %s, retrying in %s\n", | 564 | "Sent CADET_CHANNEL_OPEN on %s, retrying in %s\n", |
574 | GCCH_2s (ch), | 565 | GCCH_2s (ch), |
575 | GNUNET_STRINGS_relative_time_to_string (ch->retry_time, | 566 | GNUNET_STRINGS_relative_time_to_string (ch->retry_time, GNUNET_YES)); |
576 | GNUNET_YES)); | 567 | ch->retry_control_task = |
577 | ch->retry_control_task | 568 | GNUNET_SCHEDULER_add_delayed (ch->retry_time, &send_channel_open, ch); |
578 | = GNUNET_SCHEDULER_add_delayed (ch->retry_time, | ||
579 | &send_channel_open, | ||
580 | ch); | ||
581 | } | 569 | } |
582 | 570 | ||
583 | 571 | ||
@@ -598,17 +586,15 @@ send_channel_open (void *cls) | |||
598 | GCCH_2s (ch)); | 586 | GCCH_2s (ch)); |
599 | msgcc.header.size = htons (sizeof (msgcc)); | 587 | msgcc.header.size = htons (sizeof (msgcc)); |
600 | msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); | 588 | msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); |
601 | //TODO This will be removed in a major release, because this will be a protocol breaking change. We shift here to be compatible with GNUNET_CADET_OPTION_RELIABLE that was removed, and to already use the newly introduced options. | 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. |
602 | msgcc.opt = GNUNET_MQ_PREF_RELIABLE >> 10; | 590 | msgcc.opt = 2; |
603 | msgcc.h_port = ch->h_port; | 591 | msgcc.h_port = ch->h_port; |
604 | msgcc.ctn = ch->ctn; | 592 | msgcc.ctn = ch->ctn; |
605 | ch->state = CADET_CHANNEL_OPEN_SENT; | 593 | ch->state = CADET_CHANNEL_OPEN_SENT; |
606 | if (NULL != ch->last_control_qe) | 594 | if (NULL != ch->last_control_qe) |
607 | GCT_send_cancel (ch->last_control_qe); | 595 | GCT_send_cancel (ch->last_control_qe); |
608 | ch->last_control_qe = GCT_send (ch->t, | 596 | ch->last_control_qe = |
609 | &msgcc.header, | 597 | GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch); |
610 | &channel_open_sent_cb, | ||
611 | ch); | ||
612 | GNUNET_assert (NULL == ch->retry_control_task); | 598 | GNUNET_assert (NULL == ch->retry_control_task); |
613 | } | 599 | } |
614 | 600 | ||
@@ -630,9 +616,7 @@ GCCH_tunnel_up (struct CadetChannel *ch) | |||
630 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 616 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
631 | "Tunnel up, sending CHANNEL_OPEN on %s now\n", | 617 | "Tunnel up, sending CHANNEL_OPEN on %s now\n", |
632 | GCCH_2s (ch)); | 618 | GCCH_2s (ch)); |
633 | ch->retry_control_task | 619 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_channel_open, ch); |
634 | = GNUNET_SCHEDULER_add_now (&send_channel_open, | ||
635 | ch); | ||
636 | } | 620 | } |
637 | 621 | ||
638 | 622 | ||
@@ -663,54 +647,45 @@ GCCH_channel_local_new (struct CadetClient *owner, | |||
663 | 647 | ||
664 | ch = GNUNET_new (struct CadetChannel); | 648 | ch = GNUNET_new (struct CadetChannel); |
665 | ch->mid_recv.mid = htonl (1); /* The OPEN_ACK counts as message 0! */ | 649 | ch->mid_recv.mid = htonl (1); /* The OPEN_ACK counts as message 0! */ |
666 | ch->nobuffer = GNUNET_NO ; | 650 | ch->nobuffer = GNUNET_NO; |
667 | ch->reliable = GNUNET_YES; | 651 | ch->reliable = GNUNET_YES; |
668 | ch->out_of_order = GNUNET_NO ; | 652 | ch->out_of_order = GNUNET_NO; |
669 | ch->max_pending_messages = (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ | 653 | ch->max_pending_messages = |
654 | (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ | ||
670 | ch->owner = ccco; | 655 | ch->owner = ccco; |
671 | ch->port = *port; | 656 | ch->port = *port; |
672 | GCCH_hash_port (&ch->h_port, | 657 | GCCH_hash_port (&ch->h_port, port, GCP_get_id (destination)); |
673 | port, | 658 | if (0 == GNUNET_memcmp (&my_full_id, GCP_get_id (destination))) |
674 | GCP_get_id (destination)); | ||
675 | if (0 == GNUNET_memcmp (&my_full_id, | ||
676 | GCP_get_id (destination))) | ||
677 | { | 659 | { |
678 | struct OpenPort *op; | 660 | struct OpenPort *op; |
679 | 661 | ||
680 | ch->is_loopback = GNUNET_YES; | 662 | ch->is_loopback = GNUNET_YES; |
681 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, | 663 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, &ch->h_port); |
682 | &ch->h_port); | ||
683 | if (NULL == op) | 664 | if (NULL == op) |
684 | { | 665 | { |
685 | /* port closed, wait for it to possibly open */ | 666 | /* port closed, wait for it to possibly open */ |
686 | ch->state = CADET_CHANNEL_LOOSE; | 667 | ch->state = CADET_CHANNEL_LOOSE; |
687 | (void) GNUNET_CONTAINER_multihashmap_put (loose_channels, | 668 | (void) GNUNET_CONTAINER_multihashmap_put ( |
688 | &ch->h_port, | 669 | loose_channels, |
689 | ch, | 670 | &ch->h_port, |
690 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 671 | ch, |
672 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
691 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 673 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
692 | "Created loose incoming loopback channel to port %s\n", | 674 | "Created loose incoming loopback channel to port %s\n", |
693 | GNUNET_h2s (&ch->port)); | 675 | GNUNET_h2s (&ch->port)); |
694 | } | 676 | } |
695 | else | 677 | else |
696 | { | 678 | { |
697 | GCCH_bind (ch, | 679 | GCCH_bind (ch, op->c, &op->port); |
698 | op->c, | ||
699 | &op->port); | ||
700 | } | 680 | } |
701 | } | 681 | } |
702 | else | 682 | else |
703 | { | 683 | { |
704 | ch->t = GCP_get_tunnel (destination, | 684 | ch->t = GCP_get_tunnel (destination, GNUNET_YES); |
705 | GNUNET_YES); | ||
706 | ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; | 685 | ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; |
707 | ch->ctn = GCT_add_channel (ch->t, | 686 | ch->ctn = GCT_add_channel (ch->t, ch); |
708 | ch); | ||
709 | } | 687 | } |
710 | GNUNET_STATISTICS_update (stats, | 688 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); |
711 | "# channels", | ||
712 | 1, | ||
713 | GNUNET_NO); | ||
714 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 689 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
715 | "Created channel to port %s at peer %s for %s using %s\n", | 690 | "Created channel to port %s at peer %s for %s using %s\n", |
716 | GNUNET_h2s (port), | 691 | GNUNET_h2s (port), |
@@ -767,27 +742,24 @@ GCCH_channel_incoming_new (struct CadetTunnel *t, | |||
767 | ch->nobuffer = GNUNET_NO; | 742 | ch->nobuffer = GNUNET_NO; |
768 | ch->reliable = GNUNET_YES; | 743 | ch->reliable = GNUNET_YES; |
769 | ch->out_of_order = GNUNET_NO; | 744 | ch->out_of_order = GNUNET_NO; |
770 | ch->max_pending_messages = (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ | 745 | ch->max_pending_messages = |
771 | GNUNET_STATISTICS_update (stats, | 746 | (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ |
772 | "# channels", | 747 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); |
773 | 1, | 748 | |
774 | GNUNET_NO); | 749 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, h_port); |
775 | |||
776 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, | ||
777 | h_port); | ||
778 | if (NULL == op) | 750 | if (NULL == op) |
779 | { | 751 | { |
780 | /* port closed, wait for it to possibly open */ | 752 | /* port closed, wait for it to possibly open */ |
781 | ch->state = CADET_CHANNEL_LOOSE; | 753 | ch->state = CADET_CHANNEL_LOOSE; |
782 | (void) GNUNET_CONTAINER_multihashmap_put (loose_channels, | 754 | (void) GNUNET_CONTAINER_multihashmap_put ( |
783 | &ch->h_port, | 755 | loose_channels, |
784 | ch, | 756 | &ch->h_port, |
785 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 757 | ch, |
758 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
786 | GNUNET_assert (NULL == ch->retry_control_task); | 759 | GNUNET_assert (NULL == ch->retry_control_task); |
787 | ch->retry_control_task | 760 | ch->retry_control_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, |
788 | = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, | 761 | &timeout_closed_cb, |
789 | &timeout_closed_cb, | 762 | ch); |
790 | ch); | ||
791 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 763 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
792 | "Created loose incoming channel to port %s from peer %s\n", | 764 | "Created loose incoming channel to port %s from peer %s\n", |
793 | GNUNET_h2s (&ch->port), | 765 | GNUNET_h2s (&ch->port), |
@@ -795,14 +767,9 @@ GCCH_channel_incoming_new (struct CadetTunnel *t, | |||
795 | } | 767 | } |
796 | else | 768 | else |
797 | { | 769 | { |
798 | GCCH_bind (ch, | 770 | GCCH_bind (ch, op->c, &op->port); |
799 | op->c, | ||
800 | &op->port); | ||
801 | } | 771 | } |
802 | GNUNET_STATISTICS_update (stats, | 772 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); |
803 | "# channels", | ||
804 | 1, | ||
805 | GNUNET_NO); | ||
806 | return ch; | 773 | return ch; |
807 | } | 774 | } |
808 | 775 | ||
@@ -851,10 +818,7 @@ send_channel_data_ack (struct CadetChannel *ch) | |||
851 | GCCH_2s (ch)); | 818 | GCCH_2s (ch)); |
852 | if (NULL != ch->last_control_qe) | 819 | if (NULL != ch->last_control_qe) |
853 | GCT_send_cancel (ch->last_control_qe); | 820 | GCT_send_cancel (ch->last_control_qe); |
854 | ch->last_control_qe = GCT_send (ch->t, | 821 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); |
855 | &msg.header, | ||
856 | &send_ack_cb, | ||
857 | ch); | ||
858 | } | 822 | } |
859 | 823 | ||
860 | 824 | ||
@@ -881,10 +845,7 @@ send_open_ack (void *cls) | |||
881 | msg.port = ch->port; | 845 | msg.port = ch->port; |
882 | if (NULL != ch->last_control_qe) | 846 | if (NULL != ch->last_control_qe) |
883 | GCT_send_cancel (ch->last_control_qe); | 847 | GCT_send_cancel (ch->last_control_qe); |
884 | ch->last_control_qe = GCT_send (ch->t, | 848 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); |
885 | &msg.header, | ||
886 | &send_ack_cb, | ||
887 | ch); | ||
888 | } | 849 | } |
889 | 850 | ||
890 | 851 | ||
@@ -897,8 +858,9 @@ send_open_ack (void *cls) | |||
897 | * @param cti identifier of the connection that delivered the message | 858 | * @param cti identifier of the connection that delivered the message |
898 | */ | 859 | */ |
899 | void | 860 | void |
900 | GCCH_handle_duplicate_open (struct CadetChannel *ch, | 861 | GCCH_handle_duplicate_open ( |
901 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | 862 | struct CadetChannel *ch, |
863 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | ||
902 | { | 864 | { |
903 | if (NULL == ch->dest) | 865 | if (NULL == ch->dest) |
904 | { | 866 | { |
@@ -917,9 +879,7 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch, | |||
917 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 879 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
918 | "Retransmitting CHANNEL_OPEN_ACK on %s\n", | 880 | "Retransmitting CHANNEL_OPEN_ACK on %s\n", |
919 | GCCH_2s (ch)); | 881 | GCCH_2s (ch)); |
920 | ch->retry_control_task | 882 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch); |
921 | = GNUNET_SCHEDULER_add_now (&send_open_ack, | ||
922 | ch); | ||
923 | } | 883 | } |
924 | 884 | ||
925 | 885 | ||
@@ -931,8 +891,7 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch, | |||
931 | * #GNUNET_NO to send to dest | 891 | * #GNUNET_NO to send to dest |
932 | */ | 892 | */ |
933 | static void | 893 | static void |
934 | send_ack_to_client (struct CadetChannel *ch, | 894 | send_ack_to_client (struct CadetChannel *ch, int to_owner) |
935 | int to_owner) | ||
936 | { | 895 | { |
937 | struct GNUNET_MQ_Envelope *env; | 896 | struct GNUNET_MQ_Envelope *env; |
938 | struct GNUNET_CADET_LocalAck *ack; | 897 | struct GNUNET_CADET_LocalAck *ack; |
@@ -946,8 +905,7 @@ send_ack_to_client (struct CadetChannel *ch, | |||
946 | GNUNET_assert (GNUNET_YES == ch->destroy); | 905 | GNUNET_assert (GNUNET_YES == ch->destroy); |
947 | return; | 906 | return; |
948 | } | 907 | } |
949 | env = GNUNET_MQ_msg (ack, | 908 | env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); |
950 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); | ||
951 | ack->ccn = ccc->ccn; | 909 | ack->ccn = ccc->ccn; |
952 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 910 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
953 | "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n", | 911 | "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n", |
@@ -956,8 +914,7 @@ send_ack_to_client (struct CadetChannel *ch, | |||
956 | ntohl (ack->ccn.channel_of_client), | 914 | ntohl (ack->ccn.channel_of_client), |
957 | ch->pending_messages, | 915 | ch->pending_messages, |
958 | ch->max_pending_messages); | 916 | ch->max_pending_messages); |
959 | GSC_send_to_client (ccc->c, | 917 | GSC_send_to_client (ccc->c, env); |
960 | env); | ||
961 | } | 918 | } |
962 | 919 | ||
963 | 920 | ||
@@ -973,7 +930,7 @@ send_ack_to_client (struct CadetChannel *ch, | |||
973 | void | 930 | void |
974 | GCCH_bind (struct CadetChannel *ch, | 931 | GCCH_bind (struct CadetChannel *ch, |
975 | struct CadetClient *c, | 932 | struct CadetClient *c, |
976 | const struct GNUNET_HashCode *port) | 933 | const struct GNUNET_HashCode *port) |
977 | { | 934 | { |
978 | uint32_t options; | 935 | uint32_t options; |
979 | struct CadetChannelClient *cccd; | 936 | struct CadetChannelClient *cccd; |
@@ -1000,9 +957,8 @@ GCCH_bind (struct CadetChannel *ch, | |||
1000 | cccd->ccn = GSC_bind (c, | 957 | cccd->ccn = GSC_bind (c, |
1001 | ch, | 958 | ch, |
1002 | (GNUNET_YES == ch->is_loopback) | 959 | (GNUNET_YES == ch->is_loopback) |
1003 | ? GCP_get (&my_full_id, | 960 | ? GCP_get (&my_full_id, GNUNET_YES) |
1004 | GNUNET_YES) | 961 | : GCT_get_destination (ch->t), |
1005 | : GCT_get_destination (ch->t), | ||
1006 | port, | 962 | port, |
1007 | options); | 963 | options); |
1008 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < | 964 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < |
@@ -1011,24 +967,19 @@ GCCH_bind (struct CadetChannel *ch, | |||
1011 | if (GNUNET_YES == ch->is_loopback) | 967 | if (GNUNET_YES == ch->is_loopback) |
1012 | { | 968 | { |
1013 | ch->state = CADET_CHANNEL_OPEN_SENT; | 969 | ch->state = CADET_CHANNEL_OPEN_SENT; |
1014 | GCCH_handle_channel_open_ack (ch, | 970 | GCCH_handle_channel_open_ack (ch, NULL, port); |
1015 | NULL, | ||
1016 | port); | ||
1017 | } | 971 | } |
1018 | else | 972 | else |
1019 | { | 973 | { |
1020 | /* notify other peer that we accepted the connection */ | 974 | /* notify other peer that we accepted the connection */ |
1021 | ch->state = CADET_CHANNEL_READY; | 975 | ch->state = CADET_CHANNEL_READY; |
1022 | ch->retry_control_task | 976 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch); |
1023 | = GNUNET_SCHEDULER_add_now (&send_open_ack, | ||
1024 | ch); | ||
1025 | } | 977 | } |
1026 | /* give client it's initial supply of ACKs */ | 978 | /* give client it's initial supply of ACKs */ |
1027 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < | 979 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < |
1028 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); | 980 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); |
1029 | for (unsigned int i=0;i<ch->max_pending_messages;i++) | 981 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) |
1030 | send_ack_to_client (ch, | 982 | send_ack_to_client (ch, GNUNET_NO); |
1031 | GNUNET_NO); | ||
1032 | } | 983 | } |
1033 | 984 | ||
1034 | 985 | ||
@@ -1048,9 +999,7 @@ signal_remote_destroy_cb (void *cls) | |||
1048 | /* Find which end is left... */ | 999 | /* Find which end is left... */ |
1049 | ch->retry_control_task = NULL; | 1000 | ch->retry_control_task = NULL; |
1050 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 1001 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
1051 | GSC_handle_remote_channel_destroy (ccc->c, | 1002 | GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch); |
1052 | ccc->ccn, | ||
1053 | ch); | ||
1054 | channel_destroy (ch); | 1003 | channel_destroy (ch); |
1055 | } | 1004 | } |
1056 | 1005 | ||
@@ -1073,16 +1022,14 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, | |||
1073 | GSC_2s (c), | 1022 | GSC_2s (c), |
1074 | GCCH_2s (ch)); | 1023 | GCCH_2s (ch)); |
1075 | GNUNET_assert (NULL != c); | 1024 | GNUNET_assert (NULL != c); |
1076 | if ( (NULL != ch->owner) && | 1025 | if ((NULL != ch->owner) && (c == ch->owner->c) && |
1077 | (c == ch->owner->c) && | 1026 | (ccn.channel_of_client == ch->owner->ccn.channel_of_client)) |
1078 | (ccn.channel_of_client == ch->owner->ccn.channel_of_client) ) | ||
1079 | { | 1027 | { |
1080 | free_channel_client (ch->owner); | 1028 | free_channel_client (ch->owner); |
1081 | ch->owner = NULL; | 1029 | ch->owner = NULL; |
1082 | } | 1030 | } |
1083 | else if ( (NULL != ch->dest) && | 1031 | else if ((NULL != ch->dest) && (c == ch->dest->c) && |
1084 | (c == ch->dest->c) && | 1032 | (ccn.channel_of_client == ch->dest->ccn.channel_of_client)) |
1085 | (ccn.channel_of_client == ch->dest->ccn.channel_of_client) ) | ||
1086 | { | 1033 | { |
1087 | free_channel_client (ch->dest); | 1034 | free_channel_client (ch->dest); |
1088 | ch->dest = NULL; | 1035 | ch->dest = NULL; |
@@ -1099,24 +1046,20 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, | |||
1099 | channel_destroy (ch); | 1046 | channel_destroy (ch); |
1100 | return; | 1047 | return; |
1101 | } | 1048 | } |
1102 | if ( (NULL != ch->head_sent) && | 1049 | if ((NULL != ch->head_sent) && ((NULL != ch->owner) || (NULL != ch->dest))) |
1103 | ( (NULL != ch->owner) || | ||
1104 | (NULL != ch->dest) ) ) | ||
1105 | { | 1050 | { |
1106 | /* Wait for other end to destroy us as well, | 1051 | /* Wait for other end to destroy us as well, |
1107 | and otherwise allow send queue to be transmitted first */ | 1052 | and otherwise allow send queue to be transmitted first */ |
1108 | ch->destroy = GNUNET_YES; | 1053 | ch->destroy = GNUNET_YES; |
1109 | return; | 1054 | return; |
1110 | } | 1055 | } |
1111 | if ( (GNUNET_YES == ch->is_loopback) && | 1056 | if ((GNUNET_YES == ch->is_loopback) && |
1112 | ( (NULL != ch->owner) || | 1057 | ((NULL != ch->owner) || (NULL != ch->dest))) |
1113 | (NULL != ch->dest) ) ) | ||
1114 | { | 1058 | { |
1115 | if (NULL != ch->retry_control_task) | 1059 | if (NULL != ch->retry_control_task) |
1116 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); | 1060 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); |
1117 | ch->retry_control_task | 1061 | ch->retry_control_task = |
1118 | = GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, | 1062 | GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, ch); |
1119 | ch); | ||
1120 | return; | 1063 | return; |
1121 | } | 1064 | } |
1122 | if (GNUNET_NO == ch->is_loopback) | 1065 | if (GNUNET_NO == ch->is_loopback) |
@@ -1131,8 +1074,7 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, | |||
1131 | case CADET_CHANNEL_LOOSE: | 1074 | case CADET_CHANNEL_LOOSE: |
1132 | break; | 1075 | break; |
1133 | default: | 1076 | default: |
1134 | GCT_send_channel_destroy (ch->t, | 1077 | GCT_send_channel_destroy (ch->t, ch->ctn); |
1135 | ch->ctn); | ||
1136 | } | 1078 | } |
1137 | } | 1079 | } |
1138 | /* Nothing left to do, just finish destruction */ | 1080 | /* Nothing left to do, just finish destruction */ |
@@ -1150,9 +1092,10 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, | |||
1150 | * @param port port number (needed to verify receiver knows the port) | 1092 | * @param port port number (needed to verify receiver knows the port) |
1151 | */ | 1093 | */ |
1152 | void | 1094 | void |
1153 | GCCH_handle_channel_open_ack (struct CadetChannel *ch, | 1095 | GCCH_handle_channel_open_ack ( |
1154 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1096 | struct CadetChannel *ch, |
1155 | const struct GNUNET_HashCode *port) | 1097 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1098 | const struct GNUNET_HashCode *port) | ||
1156 | { | 1099 | { |
1157 | switch (ch->state) | 1100 | switch (ch->state) |
1158 | { | 1101 | { |
@@ -1171,8 +1114,7 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch, | |||
1171 | GNUNET_break_op (0); | 1114 | GNUNET_break_op (0); |
1172 | return; | 1115 | return; |
1173 | } | 1116 | } |
1174 | if (0 != GNUNET_memcmp (&ch->port, | 1117 | if (0 != GNUNET_memcmp (&ch->port, port)) |
1175 | port)) | ||
1176 | { | 1118 | { |
1177 | /* Other peer failed to provide the right port, | 1119 | /* Other peer failed to provide the right port, |
1178 | refuse connection. */ | 1120 | refuse connection. */ |
@@ -1190,19 +1132,15 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch, | |||
1190 | ch->state = CADET_CHANNEL_READY; | 1132 | ch->state = CADET_CHANNEL_READY; |
1191 | /* On first connect, send client as many ACKs as we allow messages | 1133 | /* On first connect, send client as many ACKs as we allow messages |
1192 | to be buffered! */ | 1134 | to be buffered! */ |
1193 | for (unsigned int i=0;i<ch->max_pending_messages;i++) | 1135 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) |
1194 | send_ack_to_client (ch, | 1136 | send_ack_to_client (ch, GNUNET_YES); |
1195 | GNUNET_YES); | ||
1196 | break; | 1137 | break; |
1197 | case CADET_CHANNEL_READY: | 1138 | case CADET_CHANNEL_READY: |
1198 | /* duplicate ACK, maybe we retried the CREATE. Ignore. */ | 1139 | /* duplicate ACK, maybe we retried the CREATE. Ignore. */ |
1199 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1140 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1200 | "Received duplicate channel OPEN_ACK for %s\n", | 1141 | "Received duplicate channel OPEN_ACK for %s\n", |
1201 | GCCH_2s (ch)); | 1142 | GCCH_2s (ch)); |
1202 | GNUNET_STATISTICS_update (stats, | 1143 | GNUNET_STATISTICS_update (stats, "# duplicate CREATE_ACKs", 1, GNUNET_NO); |
1203 | "# duplicate CREATE_ACKs", | ||
1204 | 1, | ||
1205 | GNUNET_NO); | ||
1206 | break; | 1144 | break; |
1207 | } | 1145 | } |
1208 | } | 1146 | } |
@@ -1251,9 +1189,10 @@ is_before (void *cls, | |||
1251 | * @param msg message that was received | 1189 | * @param msg message that was received |
1252 | */ | 1190 | */ |
1253 | void | 1191 | void |
1254 | GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | 1192 | GCCH_handle_channel_plaintext_data ( |
1255 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1193 | struct CadetChannel *ch, |
1256 | const struct GNUNET_CADET_ChannelAppDataMessage *msg) | 1194 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1195 | const struct GNUNET_CADET_ChannelAppDataMessage *msg) | ||
1257 | { | 1196 | { |
1258 | struct GNUNET_MQ_Envelope *env; | 1197 | struct GNUNET_MQ_Envelope *env; |
1259 | struct GNUNET_CADET_LocalData *ld; | 1198 | struct GNUNET_CADET_LocalData *ld; |
@@ -1267,8 +1206,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1267 | uint32_t delta; | 1206 | uint32_t delta; |
1268 | 1207 | ||
1269 | GNUNET_assert (GNUNET_NO == ch->is_loopback); | 1208 | GNUNET_assert (GNUNET_NO == ch->is_loopback); |
1270 | if ( (NULL == ch->owner) && | 1209 | if ((NULL == ch->owner) && (NULL == ch->dest)) |
1271 | (NULL == ch->dest) ) | ||
1272 | { | 1210 | { |
1273 | /* 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 |
1274 | 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, |
@@ -1278,8 +1216,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1278 | GCCH_2s (ch)); | 1216 | GCCH_2s (ch)); |
1279 | /* send back DESTROY notification to stop further retransmissions! */ | 1217 | /* send back DESTROY notification to stop further retransmissions! */ |
1280 | if (GNUNET_YES == ch->destroy) | 1218 | if (GNUNET_YES == ch->destroy) |
1281 | GCT_send_channel_destroy (ch->t, | 1219 | GCT_send_channel_destroy (ch->t, ch->ctn); |
1282 | ch->ctn); | ||
1283 | return; | 1220 | return; |
1284 | } | 1221 | } |
1285 | payload_size = ntohs (msg->header.size) - sizeof (*msg); | 1222 | payload_size = ntohs (msg->header.size) - sizeof (*msg); |
@@ -1287,9 +1224,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1287 | payload_size, | 1224 | payload_size, |
1288 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); | 1225 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); |
1289 | ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; | 1226 | ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; |
1290 | GNUNET_memcpy (&ld[1], | 1227 | GNUNET_memcpy (&ld[1], &msg[1], payload_size); |
1291 | &msg[1], | ||
1292 | payload_size); | ||
1293 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 1228 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
1294 | if (GNUNET_YES == ccc->client_ready) | 1229 | if (GNUNET_YES == ccc->client_ready) |
1295 | { | 1230 | { |
@@ -1299,13 +1234,12 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1299 | * - The channel is reliable and MID matches next expected MID | 1234 | * - The channel is reliable and MID matches next expected MID |
1300 | * - The channel is unreliable and MID is before lowest seen MID | 1235 | * - The channel is unreliable and MID is before lowest seen MID |
1301 | */ | 1236 | */ |
1302 | if ( (GNUNET_YES == ch->out_of_order) || | 1237 | if ((GNUNET_YES == ch->out_of_order) || |
1303 | ((msg->mid.mid == ch->mid_recv.mid) && | 1238 | ((msg->mid.mid == ch->mid_recv.mid) && (GNUNET_YES == ch->reliable)) || |
1304 | (GNUNET_YES == ch->reliable)) || | 1239 | ((GNUNET_NO == ch->reliable) && |
1305 | ((GNUNET_NO == ch->reliable) && | 1240 | (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) && |
1306 | (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) && | 1241 | ((NULL == ccc->head_recv) || |
1307 | ((NULL == ccc->head_recv) || | 1242 | (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid))))) |
1308 | (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid)))) ) | ||
1309 | { | 1243 | { |
1310 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1244 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1311 | "Giving %u bytes of payload with MID %u from %s to client %s\n", | 1245 | "Giving %u bytes of payload with MID %u from %s to client %s\n", |
@@ -1314,24 +1248,22 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1314 | GCCH_2s (ch), | 1248 | GCCH_2s (ch), |
1315 | GSC_2s (ccc->c)); | 1249 | GSC_2s (ccc->c)); |
1316 | ccc->client_ready = GNUNET_NO; | 1250 | ccc->client_ready = GNUNET_NO; |
1317 | GSC_send_to_client (ccc->c, | 1251 | GSC_send_to_client (ccc->c, env); |
1318 | env); | ||
1319 | if (GNUNET_NO == ch->out_of_order) | 1252 | if (GNUNET_NO == ch->out_of_order) |
1320 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); | 1253 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); |
1321 | else | 1254 | else |
1322 | ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid)); | 1255 | ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid)); |
1323 | ch->mid_futures >>= 1; | 1256 | ch->mid_futures >>= 1; |
1324 | if ( (GNUNET_YES == ch->out_of_order) && | 1257 | if ((GNUNET_YES == ch->out_of_order) && (GNUNET_NO == ch->reliable)) |
1325 | (GNUNET_NO == ch->reliable) ) | ||
1326 | { | 1258 | { |
1327 | /* possibly shift by more if we skipped messages */ | 1259 | /* possibly shift by more if we skipped messages */ |
1328 | uint64_t delta = htonl (msg->mid.mid) - 1 - ntohl (ch->mid_recv.mid); | 1260 | uint64_t delta = htonl (msg->mid.mid) - 1 - ntohl (ch->mid_recv.mid); |
1329 | 1261 | ||
1330 | if (delta > 63) | 1262 | if (delta > 63) |
1331 | ch->mid_futures = 0; | 1263 | ch->mid_futures = 0; |
1332 | else | 1264 | else |
1333 | ch->mid_futures >>= delta; | 1265 | ch->mid_futures >>= delta; |
1334 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); | 1266 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); |
1335 | } | 1267 | } |
1336 | send_channel_data_ack (ch); | 1268 | send_channel_data_ack (ch); |
1337 | return; | 1269 | return; |
@@ -1344,8 +1276,8 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1344 | mid_min = ntohl (ch->mid_recv.mid); | 1276 | mid_min = ntohl (ch->mid_recv.mid); |
1345 | mid_max = mid_min + ch->max_pending_messages; | 1277 | mid_max = mid_min + ch->max_pending_messages; |
1346 | mid_msg = ntohl (msg->mid.mid); | 1278 | mid_msg = ntohl (msg->mid.mid); |
1347 | if ( ( (uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) || | 1279 | if (((uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) || |
1348 | ( (uint32_t) (mid_max - mid_msg) > ch->max_pending_messages) ) | 1280 | ((uint32_t) (mid_max - mid_msg) > ch->max_pending_messages)) |
1349 | { | 1281 | { |
1350 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1282 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1351 | "%s at %u drops ancient or far-future message %u\n", | 1283 | "%s at %u drops ancient or far-future message %u\n", |
@@ -1373,10 +1305,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1373 | (unsigned int) payload_size, | 1305 | (unsigned int) payload_size, |
1374 | GCCH_2s (ch), | 1306 | GCCH_2s (ch), |
1375 | ntohl (msg->mid.mid)); | 1307 | ntohl (msg->mid.mid)); |
1376 | GNUNET_STATISTICS_update (stats, | 1308 | GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO); |
1377 | "# duplicate DATA", | ||
1378 | 1, | ||
1379 | GNUNET_NO); | ||
1380 | GNUNET_MQ_discard (env); | 1309 | GNUNET_MQ_discard (env); |
1381 | send_channel_data_ack (ch); | 1310 | send_channel_data_ack (ch); |
1382 | return; | 1311 | return; |
@@ -1398,8 +1327,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1398 | * We always send if possible in this case. | 1327 | * We always send if possible in this case. |
1399 | * It is guaranteed that the queued MID < received MID | 1328 | * It is guaranteed that the queued MID < received MID |
1400 | **/ | 1329 | **/ |
1401 | if ((NULL != ccc->head_recv) && | 1330 | if ((NULL != ccc->head_recv) && (GNUNET_YES == ccc->client_ready)) |
1402 | (GNUNET_YES == ccc->client_ready)) | ||
1403 | { | 1331 | { |
1404 | next_msg = ccc->head_recv; | 1332 | next_msg = ccc->head_recv; |
1405 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1333 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1408,14 +1336,11 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1408 | GCCH_2s (ch), | 1336 | GCCH_2s (ch), |
1409 | GSC_2s (ccc->c)); | 1337 | GSC_2s (ccc->c)); |
1410 | ccc->client_ready = GNUNET_NO; | 1338 | ccc->client_ready = GNUNET_NO; |
1411 | GSC_send_to_client (ccc->c, | 1339 | GSC_send_to_client (ccc->c, next_msg->env); |
1412 | next_msg->env); | ||
1413 | ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid)); | 1340 | ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid)); |
1414 | ch->mid_futures >>= 1; | 1341 | ch->mid_futures >>= 1; |
1415 | send_channel_data_ack (ch); | 1342 | send_channel_data_ack (ch); |
1416 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, | 1343 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, next_msg); |
1417 | ccc->tail_recv, | ||
1418 | next_msg); | ||
1419 | ccc->num_recv--; | 1344 | ccc->num_recv--; |
1420 | /* Do not process duplicate MID */ | 1345 | /* Do not process duplicate MID */ |
1421 | if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */ | 1346 | if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */ |
@@ -1460,9 +1385,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1460 | GNUNET_NO); | 1385 | GNUNET_NO); |
1461 | drop = ccc->head_recv; | 1386 | drop = ccc->head_recv; |
1462 | GNUNET_assert (NULL != drop); | 1387 | GNUNET_assert (NULL != drop); |
1463 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, | 1388 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, drop); |
1464 | ccc->tail_recv, | ||
1465 | drop); | ||
1466 | ccc->num_recv--; | 1389 | ccc->num_recv--; |
1467 | GNUNET_MQ_discard (drop->env); | 1390 | GNUNET_MQ_discard (drop->env); |
1468 | GNUNET_free (drop); | 1391 | GNUNET_free (drop); |
@@ -1493,13 +1416,8 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1493 | (unsigned int) payload_size, | 1416 | (unsigned int) payload_size, |
1494 | GCCH_2s (ch), | 1417 | GCCH_2s (ch), |
1495 | ntohl (msg->mid.mid)); | 1418 | ntohl (msg->mid.mid)); |
1496 | GNUNET_STATISTICS_update (stats, | 1419 | GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO); |
1497 | "# duplicate DATA", | 1420 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); |
1498 | 1, | ||
1499 | GNUNET_NO); | ||
1500 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, | ||
1501 | ccc->tail_recv, | ||
1502 | com); | ||
1503 | ccc->num_recv--; | 1421 | ccc->num_recv--; |
1504 | GNUNET_MQ_discard (com->env); | 1422 | GNUNET_MQ_discard (com->env); |
1505 | GNUNET_free (com); | 1423 | GNUNET_free (com); |
@@ -1508,9 +1426,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1508 | } | 1426 | } |
1509 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1427 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1510 | "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", |
1511 | (GNUNET_YES == ccc->client_ready) | 1429 | (GNUNET_YES == ccc->client_ready) ? "out-of-order" : "client-not-ready", |
1512 | ? "out-of-order" | ||
1513 | : "client-not-ready", | ||
1514 | (unsigned int) payload_size, | 1430 | (unsigned int) payload_size, |
1515 | GCCH_2s (ch), | 1431 | GCCH_2s (ch), |
1516 | ntohl (ccc->ccn.channel_of_client), | 1432 | ntohl (ccc->ccn.channel_of_client), |
@@ -1558,10 +1474,7 @@ retry_transmission (void *cls) | |||
1558 | "Retrying transmission on %s of message %u\n", | 1474 | "Retrying transmission on %s of message %u\n", |
1559 | GCCH_2s (ch), | 1475 | GCCH_2s (ch), |
1560 | (unsigned int) ntohl (crm->data_message->mid.mid)); | 1476 | (unsigned int) ntohl (crm->data_message->mid.mid)); |
1561 | crm->qe = GCT_send (ch->t, | 1477 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); |
1562 | &crm->data_message->header, | ||
1563 | &data_sent_cb, | ||
1564 | crm); | ||
1565 | GNUNET_assert (NULL == ch->retry_data_task); | 1478 | GNUNET_assert (NULL == ch->retry_data_task); |
1566 | } | 1479 | } |
1567 | 1480 | ||
@@ -1579,9 +1492,7 @@ handle_matching_ack (struct CadetChannel *ch, | |||
1579 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1492 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1580 | struct CadetReliableMessage *crm) | 1493 | struct CadetReliableMessage *crm) |
1581 | { | 1494 | { |
1582 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, | 1495 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); |
1583 | ch->tail_sent, | ||
1584 | crm); | ||
1585 | ch->pending_messages--; | 1496 | ch->pending_messages--; |
1586 | GNUNET_assert (ch->pending_messages < ch->max_pending_messages); | 1497 | GNUNET_assert (ch->pending_messages < ch->max_pending_messages); |
1587 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1498 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1594,23 +1505,19 @@ handle_matching_ack (struct CadetChannel *ch, | |||
1594 | GCT_send_cancel (crm->qe); | 1505 | GCT_send_cancel (crm->qe); |
1595 | crm->qe = NULL; | 1506 | crm->qe = NULL; |
1596 | } | 1507 | } |
1597 | if ( (1 == crm->num_transmissions) && | 1508 | if ((1 == crm->num_transmissions) && (NULL != cti)) |
1598 | (NULL != cti) ) | ||
1599 | { | 1509 | { |
1600 | GCC_ack_observed (cti); | 1510 | GCC_ack_observed (cti); |
1601 | if (0 == GNUNET_memcmp (cti, | 1511 | if (0 == GNUNET_memcmp (cti, &crm->connection_taken)) |
1602 | &crm->connection_taken)) | ||
1603 | { | 1512 | { |
1604 | GCC_latency_observed (cti, | 1513 | GCC_latency_observed (cti, |
1605 | GNUNET_TIME_absolute_get_duration (crm->first_transmission_time)); | 1514 | GNUNET_TIME_absolute_get_duration ( |
1515 | crm->first_transmission_time)); | ||
1606 | } | 1516 | } |
1607 | } | 1517 | } |
1608 | GNUNET_free (crm->data_message); | 1518 | GNUNET_free (crm->data_message); |
1609 | GNUNET_free (crm); | 1519 | GNUNET_free (crm); |
1610 | send_ack_to_client (ch, | 1520 | send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); |
1611 | (NULL == ch->owner) | ||
1612 | ? GNUNET_NO | ||
1613 | : GNUNET_YES); | ||
1614 | } | 1521 | } |
1615 | 1522 | ||
1616 | 1523 | ||
@@ -1623,9 +1530,10 @@ handle_matching_ack (struct CadetChannel *ch, | |||
1623 | * @param ack details about what was received | 1530 | * @param ack details about what was received |
1624 | */ | 1531 | */ |
1625 | void | 1532 | void |
1626 | GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | 1533 | GCCH_handle_channel_plaintext_data_ack ( |
1627 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1534 | struct CadetChannel *ch, |
1628 | const struct GNUNET_CADET_ChannelDataAckMessage *ack) | 1535 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1536 | const struct GNUNET_CADET_ChannelDataAckMessage *ack) | ||
1629 | { | 1537 | { |
1630 | struct CadetReliableMessage *crm; | 1538 | struct CadetReliableMessage *crm; |
1631 | struct CadetReliableMessage *crmn; | 1539 | struct CadetReliableMessage *crmn; |
@@ -1647,9 +1555,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1647 | mid_base = ntohl (ack->mid.mid); | 1555 | mid_base = ntohl (ack->mid.mid); |
1648 | mid_mask = GNUNET_htonll (ack->futures); | 1556 | mid_mask = GNUNET_htonll (ack->futures); |
1649 | found = GNUNET_NO; | 1557 | found = GNUNET_NO; |
1650 | for (crm = ch->head_sent; | 1558 | for (crm = ch->head_sent; NULL != crm; crm = crmn) |
1651 | NULL != crm; | ||
1652 | crm = crmn) | ||
1653 | { | 1559 | { |
1654 | crmn = crm->next; | 1560 | crmn = crm->next; |
1655 | delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base); | 1561 | delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base); |
@@ -1661,9 +1567,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1661 | (unsigned int) mid_base, | 1567 | (unsigned int) mid_base, |
1662 | ntohl (crm->data_message->mid.mid), | 1568 | ntohl (crm->data_message->mid.mid), |
1663 | GCCH_2s (ch)); | 1569 | GCCH_2s (ch)); |
1664 | handle_matching_ack (ch, | 1570 | handle_matching_ack (ch, cti, crm); |
1665 | cti, | ||
1666 | crm); | ||
1667 | found = GNUNET_YES; | 1571 | found = GNUNET_YES; |
1668 | continue; | 1572 | continue; |
1669 | } | 1573 | } |
@@ -1681,9 +1585,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1681 | "Got DATA_ACK with mask for %u on %s\n", | 1585 | "Got DATA_ACK with mask for %u on %s\n", |
1682 | ntohl (crm->data_message->mid.mid), | 1586 | ntohl (crm->data_message->mid.mid), |
1683 | GCCH_2s (ch)); | 1587 | GCCH_2s (ch)); |
1684 | handle_matching_ack (ch, | 1588 | handle_matching_ack (ch, cti, crm); |
1685 | cti, | ||
1686 | crm); | ||
1687 | found = GNUNET_YES; | 1589 | found = GNUNET_YES; |
1688 | } | 1590 | } |
1689 | } | 1591 | } |
@@ -1694,10 +1596,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1694 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1596 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1695 | "Duplicate DATA_ACK on %s, ignoring\n", | 1597 | "Duplicate DATA_ACK on %s, ignoring\n", |
1696 | GCCH_2s (ch)); | 1598 | GCCH_2s (ch)); |
1697 | GNUNET_STATISTICS_update (stats, | 1599 | GNUNET_STATISTICS_update (stats, "# duplicate DATA_ACKs", 1, GNUNET_NO); |
1698 | "# duplicate DATA_ACKs", | ||
1699 | 1, | ||
1700 | GNUNET_NO); | ||
1701 | return; | 1600 | return; |
1702 | } | 1601 | } |
1703 | if (NULL != ch->retry_data_task) | 1602 | if (NULL != ch->retry_data_task) |
@@ -1705,12 +1604,10 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1705 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 1604 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
1706 | ch->retry_data_task = NULL; | 1605 | ch->retry_data_task = NULL; |
1707 | } | 1606 | } |
1708 | if ( (NULL != ch->head_sent) && | 1607 | if ((NULL != ch->head_sent) && (NULL == ch->head_sent->qe)) |
1709 | (NULL == ch->head_sent->qe) ) | 1608 | ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, |
1710 | ch->retry_data_task | 1609 | &retry_transmission, |
1711 | = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, | 1610 | ch); |
1712 | &retry_transmission, | ||
1713 | ch); | ||
1714 | } | 1611 | } |
1715 | 1612 | ||
1716 | 1613 | ||
@@ -1724,8 +1621,9 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1724 | * NULL if we are simulating receiving a destroy due to shutdown | 1621 | * NULL if we are simulating receiving a destroy due to shutdown |
1725 | */ | 1622 | */ |
1726 | void | 1623 | void |
1727 | GCCH_handle_remote_destroy (struct CadetChannel *ch, | 1624 | GCCH_handle_remote_destroy ( |
1728 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | 1625 | struct CadetChannel *ch, |
1626 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | ||
1729 | { | 1627 | { |
1730 | struct CadetChannelClient *ccc; | 1628 | struct CadetChannelClient *ccc; |
1731 | 1629 | ||
@@ -1740,8 +1638,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch, | |||
1740 | return; | 1638 | return; |
1741 | } | 1639 | } |
1742 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 1640 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
1743 | if ( (NULL != ccc) && | 1641 | if ((NULL != ccc) && (NULL != ccc->head_recv)) |
1744 | (NULL != ccc->head_recv) ) | ||
1745 | { | 1642 | { |
1746 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1643 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1747 | "Lost end of transmission due to remote shutdown on %s\n", | 1644 | "Lost end of transmission due to remote shutdown on %s\n", |
@@ -1750,9 +1647,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch, | |||
1750 | } | 1647 | } |
1751 | ch->destroy = GNUNET_YES; | 1648 | ch->destroy = GNUNET_YES; |
1752 | if (NULL != ccc) | 1649 | if (NULL != ccc) |
1753 | GSC_handle_remote_channel_destroy (ccc->c, | 1650 | GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch); |
1754 | ccc->ccn, | ||
1755 | ch); | ||
1756 | channel_destroy (ch); | 1651 | channel_destroy (ch); |
1757 | } | 1652 | } |
1758 | 1653 | ||
@@ -1770,8 +1665,7 @@ cmp_crm_by_next_retry (void *cls, | |||
1770 | struct CadetReliableMessage *crm1, | 1665 | struct CadetReliableMessage *crm1, |
1771 | struct CadetReliableMessage *crm2) | 1666 | struct CadetReliableMessage *crm2) |
1772 | { | 1667 | { |
1773 | if (crm1->next_retry.abs_value_us < | 1668 | if (crm1->next_retry.abs_value_us < crm2->next_retry.abs_value_us) |
1774 | crm2->next_retry.abs_value_us) | ||
1775 | return GNUNET_YES; | 1669 | return GNUNET_YES; |
1776 | return GNUNET_NO; | 1670 | return GNUNET_NO; |
1777 | } | 1671 | } |
@@ -1797,18 +1691,13 @@ data_sent_cb (void *cls, | |||
1797 | GNUNET_assert (GNUNET_NO == ch->is_loopback); | 1691 | GNUNET_assert (GNUNET_NO == ch->is_loopback); |
1798 | GNUNET_assert (NULL != crm->qe); | 1692 | GNUNET_assert (NULL != crm->qe); |
1799 | crm->qe = NULL; | 1693 | crm->qe = NULL; |
1800 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, | 1694 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); |
1801 | ch->tail_sent, | ||
1802 | crm); | ||
1803 | if (GNUNET_NO == ch->reliable) | 1695 | if (GNUNET_NO == ch->reliable) |
1804 | { | 1696 | { |
1805 | GNUNET_free (crm->data_message); | 1697 | GNUNET_free (crm->data_message); |
1806 | GNUNET_free (crm); | 1698 | GNUNET_free (crm); |
1807 | ch->pending_messages--; | 1699 | ch->pending_messages--; |
1808 | send_ack_to_client (ch, | 1700 | send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); |
1809 | (NULL == ch->owner) | ||
1810 | ? GNUNET_NO | ||
1811 | : GNUNET_YES); | ||
1812 | return; | 1701 | return; |
1813 | } | 1702 | } |
1814 | if (NULL == cid) | 1703 | if (NULL == cid) |
@@ -1828,8 +1717,7 @@ data_sent_cb (void *cls, | |||
1828 | GCC_ack_expected (cid); | 1717 | GCC_ack_expected (cid); |
1829 | } | 1718 | } |
1830 | } | 1719 | } |
1831 | if ( (0 == crm->retry_delay.rel_value_us) && | 1720 | if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid)) |
1832 | (NULL != cid) ) | ||
1833 | { | 1721 | { |
1834 | struct CadetConnection *cc = GCC_lookup (cid); | 1722 | struct CadetConnection *cc = GCC_lookup (cid); |
1835 | 1723 | ||
@@ -1839,8 +1727,7 @@ data_sent_cb (void *cls, | |||
1839 | crm->retry_delay = ch->retry_time; | 1727 | crm->retry_delay = ch->retry_time; |
1840 | } | 1728 | } |
1841 | crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay); | 1729 | crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay); |
1842 | crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, | 1730 | crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, MIN_RTT_DELAY); |
1843 | MIN_RTT_DELAY); | ||
1844 | crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay); | 1731 | crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay); |
1845 | 1732 | ||
1846 | GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage, | 1733 | GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage, |
@@ -1853,16 +1740,16 @@ data_sent_cb (void *cls, | |||
1853 | "Message %u sent, next transmission on %s in %s\n", | 1740 | "Message %u sent, next transmission on %s in %s\n", |
1854 | (unsigned int) ntohl (crm->data_message->mid.mid), | 1741 | (unsigned int) ntohl (crm->data_message->mid.mid), |
1855 | GCCH_2s (ch), | 1742 | GCCH_2s (ch), |
1856 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (ch->head_sent->next_retry), | 1743 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( |
1744 | ch->head_sent->next_retry), | ||
1857 | GNUNET_YES)); | 1745 | GNUNET_YES)); |
1858 | if (NULL == ch->head_sent->qe) | 1746 | if (NULL == ch->head_sent->qe) |
1859 | { | 1747 | { |
1860 | if (NULL != ch->retry_data_task) | 1748 | if (NULL != ch->retry_data_task) |
1861 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 1749 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
1862 | ch->retry_data_task | 1750 | ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, |
1863 | = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, | 1751 | &retry_transmission, |
1864 | &retry_transmission, | 1752 | ch); |
1865 | ch); | ||
1866 | } | 1753 | } |
1867 | } | 1754 | } |
1868 | 1755 | ||
@@ -1908,19 +1795,16 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1908 | struct GNUNET_CADET_LocalData *ld; | 1795 | struct GNUNET_CADET_LocalData *ld; |
1909 | int ack_to_owner; | 1796 | int ack_to_owner; |
1910 | 1797 | ||
1911 | env = GNUNET_MQ_msg_extra (ld, | 1798 | env = |
1912 | buf_len, | 1799 | GNUNET_MQ_msg_extra (ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); |
1913 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); | 1800 | if ((NULL != ch->owner) && |
1914 | if ( (NULL != ch->owner) && | 1801 | (sender_ccn.channel_of_client == ch->owner->ccn.channel_of_client)) |
1915 | (sender_ccn.channel_of_client == | ||
1916 | ch->owner->ccn.channel_of_client) ) | ||
1917 | { | 1802 | { |
1918 | receiver = ch->dest; | 1803 | receiver = ch->dest; |
1919 | ack_to_owner = GNUNET_YES; | 1804 | ack_to_owner = GNUNET_YES; |
1920 | } | 1805 | } |
1921 | else if ( (NULL != ch->dest) && | 1806 | else if ((NULL != ch->dest) && |
1922 | (sender_ccn.channel_of_client == | 1807 | (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client)) |
1923 | ch->dest->ccn.channel_of_client) ) | ||
1924 | { | 1808 | { |
1925 | receiver = ch->owner; | 1809 | receiver = ch->owner; |
1926 | ack_to_owner = GNUNET_NO; | 1810 | ack_to_owner = GNUNET_NO; |
@@ -1932,16 +1816,12 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1932 | } | 1816 | } |
1933 | GNUNET_assert (NULL != receiver); | 1817 | GNUNET_assert (NULL != receiver); |
1934 | ld->ccn = receiver->ccn; | 1818 | ld->ccn = receiver->ccn; |
1935 | GNUNET_memcpy (&ld[1], | 1819 | GNUNET_memcpy (&ld[1], buf, buf_len); |
1936 | buf, | ||
1937 | buf_len); | ||
1938 | if (GNUNET_YES == receiver->client_ready) | 1820 | if (GNUNET_YES == receiver->client_ready) |
1939 | { | 1821 | { |
1940 | ch->pending_messages--; | 1822 | ch->pending_messages--; |
1941 | GSC_send_to_client (receiver->c, | 1823 | GSC_send_to_client (receiver->c, env); |
1942 | env); | 1824 | send_ack_to_client (ch, ack_to_owner); |
1943 | send_ack_to_client (ch, | ||
1944 | ack_to_owner); | ||
1945 | } | 1825 | } |
1946 | else | 1826 | else |
1947 | { | 1827 | { |
@@ -1960,19 +1840,17 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1960 | /* Everything is correct, send the message. */ | 1840 | /* Everything is correct, send the message. */ |
1961 | crm = GNUNET_malloc (sizeof (*crm)); | 1841 | crm = GNUNET_malloc (sizeof (*crm)); |
1962 | crm->ch = ch; | 1842 | crm->ch = ch; |
1963 | crm->data_message = GNUNET_malloc (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) | 1843 | crm->data_message = GNUNET_malloc ( |
1964 | + buf_len); | 1844 | sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); |
1965 | crm->data_message->header.size = htons (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); | 1845 | crm->data_message->header.size = |
1966 | crm->data_message->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); | 1846 | htons (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); |
1847 | crm->data_message->header.type = | ||
1848 | htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); | ||
1967 | ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); | 1849 | ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); |
1968 | crm->data_message->mid = ch->mid_send; | 1850 | crm->data_message->mid = ch->mid_send; |
1969 | crm->data_message->ctn = ch->ctn; | 1851 | crm->data_message->ctn = ch->ctn; |
1970 | GNUNET_memcpy (&crm->data_message[1], | 1852 | GNUNET_memcpy (&crm->data_message[1], buf, buf_len); |
1971 | buf, | 1853 | GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, ch->tail_sent, crm); |
1972 | buf_len); | ||
1973 | GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, | ||
1974 | ch->tail_sent, | ||
1975 | crm); | ||
1976 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1854 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1977 | "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", |
1978 | ntohl (crm->data_message->mid.mid), | 1856 | ntohl (crm->data_message->mid.mid), |
@@ -1983,10 +1861,7 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1983 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 1861 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
1984 | ch->retry_data_task = NULL; | 1862 | ch->retry_data_task = NULL; |
1985 | } | 1863 | } |
1986 | crm->qe = GCT_send (ch->t, | 1864 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); |
1987 | &crm->data_message->header, | ||
1988 | &data_sent_cb, | ||
1989 | crm); | ||
1990 | GNUNET_assert (NULL == ch->retry_data_task); | 1865 | GNUNET_assert (NULL == ch->retry_data_task); |
1991 | return GNUNET_OK; | 1866 | return GNUNET_OK; |
1992 | } | 1867 | } |
@@ -2006,11 +1881,11 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
2006 | struct CadetChannelClient *ccc; | 1881 | struct CadetChannelClient *ccc; |
2007 | struct CadetOutOfOrderMessage *com; | 1882 | struct CadetOutOfOrderMessage *com; |
2008 | 1883 | ||
2009 | if ( (NULL != ch->owner) && | 1884 | if ((NULL != ch->owner) && |
2010 | (ch->owner->ccn.channel_of_client == client_ccn.channel_of_client) ) | 1885 | (ch->owner->ccn.channel_of_client == client_ccn.channel_of_client)) |
2011 | ccc = ch->owner; | 1886 | ccc = ch->owner; |
2012 | else if ( (NULL != ch->dest) && | 1887 | else if ((NULL != ch->dest) && |
2013 | (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client) ) | 1888 | (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client)) |
2014 | ccc = ch->dest; | 1889 | ccc = ch->dest; |
2015 | else | 1890 | else |
2016 | GNUNET_assert (0); | 1891 | GNUNET_assert (0); |
@@ -2032,35 +1907,28 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
2032 | int to_owner; | 1907 | int to_owner; |
2033 | 1908 | ||
2034 | /* Messages are always in-order, just send */ | 1909 | /* Messages are always in-order, just send */ |
2035 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, | 1910 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); |
2036 | ccc->tail_recv, | ||
2037 | com); | ||
2038 | ccc->num_recv--; | 1911 | ccc->num_recv--; |
2039 | GSC_send_to_client (ccc->c, | 1912 | GSC_send_to_client (ccc->c, com->env); |
2040 | com->env); | ||
2041 | /* Notify sender that we can receive more */ | 1913 | /* Notify sender that we can receive more */ |
2042 | if ( (NULL != ch->owner) && | 1914 | if ((NULL != ch->owner) && |
2043 | (ccc->ccn.channel_of_client == | 1915 | (ccc->ccn.channel_of_client == ch->owner->ccn.channel_of_client)) |
2044 | ch->owner->ccn.channel_of_client) ) | ||
2045 | { | 1916 | { |
2046 | to_owner = GNUNET_NO; | 1917 | to_owner = GNUNET_NO; |
2047 | } | 1918 | } |
2048 | else | 1919 | else |
2049 | { | 1920 | { |
2050 | GNUNET_assert ( (NULL != ch->dest) && | 1921 | GNUNET_assert ((NULL != ch->dest) && (ccc->ccn.channel_of_client == |
2051 | (ccc->ccn.channel_of_client == | 1922 | ch->dest->ccn.channel_of_client)); |
2052 | ch->dest->ccn.channel_of_client) ); | ||
2053 | to_owner = GNUNET_YES; | 1923 | to_owner = GNUNET_YES; |
2054 | } | 1924 | } |
2055 | send_ack_to_client (ch, | 1925 | send_ack_to_client (ch, to_owner); |
2056 | to_owner); | ||
2057 | GNUNET_free (com); | 1926 | GNUNET_free (com); |
2058 | return; | 1927 | return; |
2059 | } | 1928 | } |
2060 | 1929 | ||
2061 | if ( (com->mid.mid != ch->mid_recv.mid) && | 1930 | if ((com->mid.mid != ch->mid_recv.mid) && (GNUNET_NO == ch->out_of_order) && |
2062 | (GNUNET_NO == ch->out_of_order) && | 1931 | (GNUNET_YES == ch->reliable)) |
2063 | (GNUNET_YES == ch->reliable) ) | ||
2064 | { | 1932 | { |
2065 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1933 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2066 | "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", |
@@ -2079,9 +1947,7 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
2079 | GCCH_2s (ch)); | 1947 | GCCH_2s (ch)); |
2080 | 1948 | ||
2081 | /* all good, pass next message to client */ | 1949 | /* all good, pass next message to client */ |
2082 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, | 1950 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); |
2083 | ccc->tail_recv, | ||
2084 | com); | ||
2085 | ccc->num_recv--; | 1951 | ccc->num_recv--; |
2086 | /* FIXME: if unreliable, this is not aggressive | 1952 | /* FIXME: if unreliable, this is not aggressive |
2087 | enough, as it would be OK to have lost some! */ | 1953 | enough, as it would be OK to have lost some! */ |
@@ -2089,21 +1955,20 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
2089 | ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid)); | 1955 | ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid)); |
2090 | ch->mid_futures >>= 1; /* equivalent to division by 2 */ | 1956 | ch->mid_futures >>= 1; /* equivalent to division by 2 */ |
2091 | ccc->client_ready = GNUNET_NO; | 1957 | ccc->client_ready = GNUNET_NO; |
2092 | GSC_send_to_client (ccc->c, | 1958 | GSC_send_to_client (ccc->c, com->env); |
2093 | com->env); | ||
2094 | GNUNET_free (com); | 1959 | GNUNET_free (com); |
2095 | send_channel_data_ack (ch); | 1960 | send_channel_data_ack (ch); |
2096 | if (NULL != ccc->head_recv) | 1961 | if (NULL != ccc->head_recv) |
2097 | return; | 1962 | return; |
2098 | if (GNUNET_NO == ch->destroy) | 1963 | if (GNUNET_NO == ch->destroy) |
2099 | return; | 1964 | return; |
2100 | GCT_send_channel_destroy (ch->t, | 1965 | GCT_send_channel_destroy (ch->t, ch->ctn); |
2101 | ch->ctn); | ||
2102 | channel_destroy (ch); | 1966 | channel_destroy (ch); |
2103 | } | 1967 | } |
2104 | 1968 | ||
2105 | 1969 | ||
2106 | #define LOG2(level, ...) GNUNET_log_from_nocheck(level,"cadet-chn",__VA_ARGS__) | 1970 | #define LOG2(level, ...) \ |
1971 | GNUNET_log_from_nocheck (level, "cadet-chn", __VA_ARGS__) | ||
2107 | 1972 | ||
2108 | 1973 | ||
2109 | /** | 1974 | /** |
@@ -2113,15 +1978,16 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
2113 | * @param level Debug level to use. | 1978 | * @param level Debug level to use. |
2114 | */ | 1979 | */ |
2115 | void | 1980 | void |
2116 | GCCH_debug (struct CadetChannel *ch, | 1981 | GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level) |
2117 | enum GNUNET_ErrorType level) | ||
2118 | { | 1982 | { |
2119 | #if !defined(GNUNET_CULL_LOGGING) | 1983 | #if ! defined(GNUNET_CULL_LOGGING) |
2120 | int do_log; | 1984 | int do_log; |
2121 | 1985 | ||
2122 | 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), |
2123 | "cadet-chn", | 1987 | "cadet-chn", |
2124 | __FILE__, __FUNCTION__, __LINE__); | 1988 | __FILE__, |
1989 | __FUNCTION__, | ||
1990 | __LINE__); | ||
2125 | if (0 == do_log) | 1991 | if (0 == do_log) |
2126 | return; | 1992 | return; |
2127 | 1993 | ||
@@ -2130,11 +1996,7 @@ GCCH_debug (struct CadetChannel *ch, | |||
2130 | LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n"); | 1996 | LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n"); |
2131 | return; | 1997 | return; |
2132 | } | 1998 | } |
2133 | LOG2 (level, | 1999 | LOG2 (level, "CHN %s:%X (%p)\n", GCT_2s (ch->t), ch->ctn, ch); |
2134 | "CHN %s:%X (%p)\n", | ||
2135 | GCT_2s (ch->t), | ||
2136 | ch->ctn, | ||
2137 | ch); | ||
2138 | if (NULL != ch->owner) | 2000 | if (NULL != ch->owner) |
2139 | { | 2001 | { |
2140 | LOG2 (level, | 2002 | LOG2 (level, |
@@ -2160,5 +2022,4 @@ GCCH_debug (struct CadetChannel *ch, | |||
2160 | } | 2022 | } |
2161 | 2023 | ||
2162 | 2024 | ||
2163 | |||
2164 | /* end of gnunet-service-cadet-new_channel.c */ | 2025 | /* end of gnunet-service-cadet-new_channel.c */ |
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 7214dad97..8849e563f 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -35,14 +35,15 @@ | |||
35 | #include "cadet_protocol.h" | 35 | #include "cadet_protocol.h" |
36 | 36 | ||
37 | 37 | ||
38 | #define LOG(level, ...) GNUNET_log_from(level,"cadet-con",__VA_ARGS__) | 38 | #define LOG(level, ...) GNUNET_log_from (level, "cadet-con", __VA_ARGS__) |
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
42 | * How long do we wait initially before retransmitting the KX? | 42 | * How long do we wait initially before retransmitting the KX? |
43 | * TODO: replace by 2 RTT if/once we have connection-level RTT data! | 43 | * TODO: replace by 2 RTT if/once we have connection-level RTT data! |
44 | */ | 44 | */ |
45 | #define INITIAL_CONNECTION_CREATE_RETRY_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200) | 45 | #define INITIAL_CONNECTION_CREATE_RETRY_DELAY \ |
46 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200) | ||
46 | 47 | ||
47 | 48 | ||
48 | /** | 49 | /** |
@@ -174,7 +175,6 @@ struct CadetConnection | |||
174 | * Are we ready to transmit via @e mq_man right now? | 175 | * Are we ready to transmit via @e mq_man right now? |
175 | */ | 176 | */ |
176 | int mqm_ready; | 177 | int mqm_ready; |
177 | |||
178 | }; | 178 | }; |
179 | 179 | ||
180 | 180 | ||
@@ -208,18 +208,16 @@ update_state (struct CadetConnection *cc, | |||
208 | int old_ready; | 208 | int old_ready; |
209 | int new_ready; | 209 | int new_ready; |
210 | 210 | ||
211 | if ( (new_state == cc->state) && | 211 | if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready)) |
212 | (new_mqm_ready == cc->mqm_ready) ) | ||
213 | return; /* no change, nothing to do */ | 212 | return; /* no change, nothing to do */ |
214 | old_ready = ( (CADET_CONNECTION_READY == cc->state) && | 213 | old_ready = |
215 | (GNUNET_YES == cc->mqm_ready) ); | 214 | ((CADET_CONNECTION_READY == cc->state) && (GNUNET_YES == cc->mqm_ready)); |
216 | new_ready = ( (CADET_CONNECTION_READY == new_state) && | 215 | new_ready = |
217 | (GNUNET_YES == new_mqm_ready) ); | 216 | ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready)); |
218 | cc->state = new_state; | 217 | cc->state = new_state; |
219 | cc->mqm_ready = new_mqm_ready; | 218 | cc->mqm_ready = new_mqm_ready; |
220 | if (old_ready != new_ready) | 219 | if (old_ready != new_ready) |
221 | cc->ready_cb (cc->ready_cb_cls, | 220 | cc->ready_cb (cc->ready_cb_cls, new_ready); |
222 | new_ready); | ||
223 | } | 221 | } |
224 | 222 | ||
225 | 223 | ||
@@ -232,13 +230,10 @@ update_state (struct CadetConnection *cc, | |||
232 | static void | 230 | static void |
233 | GCC_destroy (struct CadetConnection *cc) | 231 | GCC_destroy (struct CadetConnection *cc) |
234 | { | 232 | { |
235 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 233 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s (cc)); |
236 | "Destroying %s\n", | ||
237 | GCC_2s (cc)); | ||
238 | if (NULL != cc->mq_man) | 234 | if (NULL != cc->mq_man) |
239 | { | 235 | { |
240 | GCP_request_mq_cancel (cc->mq_man, | 236 | GCP_request_mq_cancel (cc->mq_man, NULL); |
241 | NULL); | ||
242 | cc->mq_man = NULL; | 237 | cc->mq_man = NULL; |
243 | } | 238 | } |
244 | if (NULL != cc->task) | 239 | if (NULL != cc->task) |
@@ -251,22 +246,19 @@ GCC_destroy (struct CadetConnection *cc) | |||
251 | GCT_send_cancel (cc->keepalive_qe); | 246 | GCT_send_cancel (cc->keepalive_qe); |
252 | cc->keepalive_qe = NULL; | 247 | cc->keepalive_qe = NULL; |
253 | } | 248 | } |
254 | GCPP_del_connection (cc->path, | 249 | GCPP_del_connection (cc->path, cc->off, cc); |
255 | cc->off, | 250 | for (unsigned int i = 0; i < cc->off; i++) |
256 | cc); | 251 | GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, i), cc); |
257 | for (unsigned int i=0;i<cc->off;i++) | 252 | GNUNET_assert ( |
258 | GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, | 253 | GNUNET_YES == |
259 | i), | 254 | GNUNET_CONTAINER_multishortmap_remove (connections, |
260 | cc); | 255 | &GCC_get_id (cc) |
261 | GNUNET_assert (GNUNET_YES == | 256 | ->connection_of_tunnel, |
262 | GNUNET_CONTAINER_multishortmap_remove (connections, | 257 | cc)); |
263 | &GCC_get_id (cc)->connection_of_tunnel, | ||
264 | cc)); | ||
265 | GNUNET_free (cc); | 258 | GNUNET_free (cc); |
266 | } | 259 | } |
267 | 260 | ||
268 | 261 | ||
269 | |||
270 | /** | 262 | /** |
271 | * Destroy a connection, called when the CORE layer is already done | 263 | * Destroy a connection, called when the CORE layer is already done |
272 | * (i.e. has received a BROKEN message), but if we still have to | 264 | * (i.e. has received a BROKEN message), but if we still have to |
@@ -298,18 +290,16 @@ void | |||
298 | GCC_destroy_without_tunnel (struct CadetConnection *cc) | 290 | GCC_destroy_without_tunnel (struct CadetConnection *cc) |
299 | { | 291 | { |
300 | cc->ct = NULL; | 292 | cc->ct = NULL; |
301 | if ( (CADET_CONNECTION_SENDING_CREATE != cc->state) && | 293 | if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man)) |
302 | (NULL != cc->mq_man) ) | ||
303 | { | 294 | { |
304 | struct GNUNET_MQ_Envelope *env; | 295 | struct GNUNET_MQ_Envelope *env; |
305 | struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg; | 296 | struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg; |
306 | 297 | ||
307 | /* Need to notify next hop that we are down. */ | 298 | /* Need to notify next hop that we are down. */ |
308 | env = GNUNET_MQ_msg (destroy_msg, | 299 | env = |
309 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); | 300 | GNUNET_MQ_msg (destroy_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); |
310 | destroy_msg->cid = cc->cid; | 301 | destroy_msg->cid = cc->cid; |
311 | GCP_request_mq_cancel (cc->mq_man, | 302 | GCP_request_mq_cancel (cc->mq_man, env); |
312 | env); | ||
313 | cc->mq_man = NULL; | 303 | cc->mq_man = NULL; |
314 | } | 304 | } |
315 | GCC_destroy (cc); | 305 | GCC_destroy (cc); |
@@ -367,11 +357,9 @@ keepalive_done (void *cls, | |||
367 | struct CadetConnection *cc = cls; | 357 | struct CadetConnection *cc = cls; |
368 | 358 | ||
369 | cc->keepalive_qe = NULL; | 359 | cc->keepalive_qe = NULL; |
370 | if ( (GNUNET_YES == cc->mqm_ready) && | 360 | if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task)) |
371 | (NULL == cc->task) ) | 361 | cc->task = |
372 | cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, | 362 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); |
373 | &send_keepalive, | ||
374 | cc); | ||
375 | } | 363 | } |
376 | 364 | ||
377 | 365 | ||
@@ -391,9 +379,8 @@ send_keepalive (void *cls) | |||
391 | if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t)) | 379 | if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t)) |
392 | { | 380 | { |
393 | /* Tunnel not yet ready, wait with keepalives... */ | 381 | /* Tunnel not yet ready, wait with keepalives... */ |
394 | cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, | 382 | cc->task = |
395 | &send_keepalive, | 383 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); |
396 | cc); | ||
397 | return; | 384 | return; |
398 | } | 385 | } |
399 | GNUNET_assert (NULL != cc->ct); | 386 | GNUNET_assert (NULL != cc->ct); |
@@ -403,18 +390,11 @@ send_keepalive (void *cls) | |||
403 | "Sending KEEPALIVE on behalf of %s via %s\n", | 390 | "Sending KEEPALIVE on behalf of %s via %s\n", |
404 | GCC_2s (cc), | 391 | GCC_2s (cc), |
405 | GCT_2s (cc->ct->t)); | 392 | GCT_2s (cc->ct->t)); |
406 | GNUNET_STATISTICS_update (stats, | 393 | GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO); |
407 | "# keepalives sent", | ||
408 | 1, | ||
409 | GNUNET_NO); | ||
410 | msg.size = htons (sizeof (msg)); | 394 | msg.size = htons (sizeof (msg)); |
411 | msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); | 395 | msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); |
412 | 396 | ||
413 | cc->keepalive_qe | 397 | cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc); |
414 | = GCT_send (cc->ct->t, | ||
415 | &msg, | ||
416 | &keepalive_done, | ||
417 | cc); | ||
418 | } | 398 | } |
419 | 399 | ||
420 | 400 | ||
@@ -475,10 +455,7 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | |||
475 | cc = GCC_lookup (cid); | 455 | cc = GCC_lookup (cid); |
476 | if (NULL == cc) | 456 | if (NULL == cc) |
477 | return; /* whopise, connection alredy down? */ | 457 | return; /* whopise, connection alredy down? */ |
478 | GNUNET_STATISTICS_update (stats, | 458 | GNUNET_STATISTICS_update (stats, "# latencies observed", 1, GNUNET_NO); |
479 | "# latencies observed", | ||
480 | 1, | ||
481 | GNUNET_NO); | ||
482 | cc->latency_datapoints++; | 459 | cc->latency_datapoints++; |
483 | if (cc->latency_datapoints >= 7) | 460 | if (cc->latency_datapoints >= 7) |
484 | weight = 7.0; | 461 | weight = 7.0; |
@@ -487,7 +464,8 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | |||
487 | /* Compute weighted average, giving at MOST weight 7 to the | 464 | /* Compute weighted average, giving at MOST weight 7 to the |
488 | existing values, or less if that value is based on fewer than 7 | 465 | existing values, or less if that value is based on fewer than 7 |
489 | measurements. */ | 466 | measurements. */ |
490 | result = (weight * cc->metrics.aged_latency.rel_value_us) + 1.0 * latency.rel_value_us; | 467 | result = (weight * cc->metrics.aged_latency.rel_value_us) + |
468 | 1.0 * latency.rel_value_us; | ||
491 | result /= (weight + 1.0); | 469 | result /= (weight + 1.0); |
492 | cc->metrics.aged_latency.rel_value_us = (uint64_t) result; | 470 | cc->metrics.aged_latency.rel_value_us = (uint64_t) result; |
493 | } | 471 | } |
@@ -516,15 +494,11 @@ GCC_handle_connection_create_ack (struct CadetConnection *cc) | |||
516 | cc->task = NULL; | 494 | cc->task = NULL; |
517 | } | 495 | } |
518 | cc->metrics.age = GNUNET_TIME_absolute_get (); | 496 | cc->metrics.age = GNUNET_TIME_absolute_get (); |
519 | update_state (cc, | 497 | update_state (cc, CADET_CONNECTION_READY, cc->mqm_ready); |
520 | CADET_CONNECTION_READY, | 498 | if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) && |
521 | cc->mqm_ready); | 499 | (NULL == cc->task)) |
522 | if ( (NULL == cc->keepalive_qe) && | 500 | cc->task = |
523 | (GNUNET_YES == cc->mqm_ready) && | 501 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); |
524 | (NULL == cc->task) ) | ||
525 | cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, | ||
526 | &send_keepalive, | ||
527 | cc); | ||
528 | } | 502 | } |
529 | 503 | ||
530 | 504 | ||
@@ -552,8 +526,7 @@ GCC_handle_kx (struct CadetConnection *cc, | |||
552 | GCC_2s (cc)); | 526 | GCC_2s (cc)); |
553 | GCC_handle_connection_create_ack (cc); | 527 | GCC_handle_connection_create_ack (cc); |
554 | } | 528 | } |
555 | GCT_handle_kx (cc->ct, | 529 | GCT_handle_kx (cc->ct, msg); |
556 | msg); | ||
557 | } | 530 | } |
558 | 531 | ||
559 | 532 | ||
@@ -581,8 +554,7 @@ GCC_handle_kx_auth (struct CadetConnection *cc, | |||
581 | GCC_2s (cc)); | 554 | GCC_2s (cc)); |
582 | GCC_handle_connection_create_ack (cc); | 555 | GCC_handle_connection_create_ack (cc); |
583 | } | 556 | } |
584 | GCT_handle_kx_auth (cc->ct, | 557 | GCT_handle_kx_auth (cc->ct, msg); |
585 | msg); | ||
586 | } | 558 | } |
587 | 559 | ||
588 | 560 | ||
@@ -606,8 +578,7 @@ GCC_handle_encrypted (struct CadetConnection *cc, | |||
606 | GCC_handle_connection_create_ack (cc); | 578 | GCC_handle_connection_create_ack (cc); |
607 | } | 579 | } |
608 | cc->metrics.last_use = GNUNET_TIME_absolute_get (); | 580 | cc->metrics.last_use = GNUNET_TIME_absolute_get (); |
609 | GCT_handle_encrypted (cc->ct, | 581 | GCT_handle_encrypted (cc->ct, msg); |
610 | msg); | ||
611 | } | 582 | } |
612 | 583 | ||
613 | 584 | ||
@@ -627,17 +598,17 @@ send_create (void *cls) | |||
627 | 598 | ||
628 | cc->task = NULL; | 599 | cc->task = NULL; |
629 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); | 600 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); |
630 | env = GNUNET_MQ_msg_extra (create_msg, | 601 | env = |
631 | (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity), | 602 | GNUNET_MQ_msg_extra (create_msg, |
632 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); | 603 | (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity), |
633 | //TODO This will be removed in a major release, because this will be a protocol breaking change. We shift here to be compatible with GNUNET_CADET_OPTION_RELIABLE that was removed, and to already use the newly introduced options. | 604 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); |
634 | create_msg->options = GNUNET_MQ_PREF_RELIABLE >> 10; | 605 | //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. |
606 | create_msg->options = 2; | ||
635 | create_msg->cid = cc->cid; | 607 | create_msg->cid = cc->cid; |
636 | pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; | 608 | pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; |
637 | pids[0] = my_full_id; | 609 | pids[0] = my_full_id; |
638 | for (unsigned int i=0;i<=cc->off;i++) | 610 | for (unsigned int i = 0; i <= cc->off; i++) |
639 | pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, | 611 | pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, i)); |
640 | i)); | ||
641 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 612 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
642 | "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n", | 613 | "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n", |
643 | GCC_2s (cc), | 614 | GCC_2s (cc), |
@@ -645,11 +616,8 @@ send_create (void *cls) | |||
645 | cc->env = env; | 616 | cc->env = env; |
646 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); | 617 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); |
647 | cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); | 618 | cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); |
648 | update_state (cc, | 619 | update_state (cc, CADET_CONNECTION_SENT, GNUNET_NO); |
649 | CADET_CONNECTION_SENT, | 620 | GCP_send (cc->mq_man, env); |
650 | GNUNET_NO); | ||
651 | GCP_send (cc->mq_man, | ||
652 | env); | ||
653 | } | 621 | } |
654 | 622 | ||
655 | 623 | ||
@@ -670,22 +638,18 @@ send_create_ack (void *cls) | |||
670 | "Sending CONNECTION_CREATE_ACK message for %s\n", | 638 | "Sending CONNECTION_CREATE_ACK message for %s\n", |
671 | GCC_2s (cc)); | 639 | GCC_2s (cc)); |
672 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); | 640 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); |
673 | env = GNUNET_MQ_msg (ack_msg, | 641 | env = |
674 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); | 642 | GNUNET_MQ_msg (ack_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); |
675 | ack_msg->cid = cc->cid; | 643 | ack_msg->cid = cc->cid; |
676 | cc->env = env; | 644 | cc->env = env; |
677 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); | 645 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); |
678 | cc->create_ack_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); | 646 | cc->create_ack_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); |
679 | if (CADET_CONNECTION_CREATE_RECEIVED == cc->state) | 647 | if (CADET_CONNECTION_CREATE_RECEIVED == cc->state) |
680 | update_state (cc, | 648 | update_state (cc, CADET_CONNECTION_READY, GNUNET_NO); |
681 | CADET_CONNECTION_READY, | ||
682 | GNUNET_NO); | ||
683 | if (CADET_CONNECTION_READY == cc->state) | 649 | if (CADET_CONNECTION_READY == cc->state) |
684 | cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, | 650 | cc->task = |
685 | &send_keepalive, | 651 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); |
686 | cc); | 652 | GCP_send (cc->mq_man, env); |
687 | GCP_send (cc->mq_man, | ||
688 | env); | ||
689 | } | 653 | } |
690 | 654 | ||
691 | 655 | ||
@@ -707,14 +671,11 @@ GCC_handle_duplicate_create (struct CadetConnection *cc) | |||
707 | (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); | 671 | (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); |
708 | /* Revert back to the state of having only received the 'CREATE', | 672 | /* Revert back to the state of having only received the 'CREATE', |
709 | and immediately proceed to send the CREATE_ACK. */ | 673 | and immediately proceed to send the CREATE_ACK. */ |
710 | update_state (cc, | 674 | update_state (cc, CADET_CONNECTION_CREATE_RECEIVED, cc->mqm_ready); |
711 | CADET_CONNECTION_CREATE_RECEIVED, | ||
712 | cc->mqm_ready); | ||
713 | if (NULL != cc->task) | 675 | if (NULL != cc->task) |
714 | GNUNET_SCHEDULER_cancel (cc->task); | 676 | GNUNET_SCHEDULER_cancel (cc->task); |
715 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, | 677 | cc->task = |
716 | &send_create_ack, | 678 | GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc); |
717 | cc); | ||
718 | } | 679 | } |
719 | else | 680 | else |
720 | { | 681 | { |
@@ -739,20 +700,15 @@ GCC_handle_duplicate_create (struct CadetConnection *cc) | |||
739 | * and the last envelope was discarded | 700 | * and the last envelope was discarded |
740 | */ | 701 | */ |
741 | static void | 702 | static void |
742 | manage_first_hop_mq (void *cls, | 703 | manage_first_hop_mq (void *cls, int available) |
743 | int available) | ||
744 | { | 704 | { |
745 | struct CadetConnection *cc = cls; | 705 | struct CadetConnection *cc = cls; |
746 | 706 | ||
747 | if (GNUNET_YES != available) | 707 | if (GNUNET_YES != available) |
748 | { | 708 | { |
749 | /* Connection is down, for now... */ | 709 | /* Connection is down, for now... */ |
750 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 710 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s (cc)); |
751 | "Core MQ for %s went down\n", | 711 | update_state (cc, CADET_CONNECTION_NEW, GNUNET_NO); |
752 | GCC_2s (cc)); | ||
753 | update_state (cc, | ||
754 | CADET_CONNECTION_NEW, | ||
755 | GNUNET_NO); | ||
756 | cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY; | 712 | cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY; |
757 | if (NULL != cc->task) | 713 | if (NULL != cc->task) |
758 | { | 714 | { |
@@ -762,9 +718,7 @@ manage_first_hop_mq (void *cls, | |||
762 | return; | 718 | return; |
763 | } | 719 | } |
764 | 720 | ||
765 | update_state (cc, | 721 | update_state (cc, cc->state, GNUNET_YES); |
766 | cc->state, | ||
767 | GNUNET_YES); | ||
768 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 722 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
769 | "Core MQ for %s became available in state %d\n", | 723 | "Core MQ for %s became available in state %d\n", |
770 | GCC_2s (cc), | 724 | GCC_2s (cc), |
@@ -773,9 +727,7 @@ manage_first_hop_mq (void *cls, | |||
773 | { | 727 | { |
774 | case CADET_CONNECTION_NEW: | 728 | case CADET_CONNECTION_NEW: |
775 | /* Transmit immediately */ | 729 | /* Transmit immediately */ |
776 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, | 730 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc); |
777 | &send_create, | ||
778 | cc); | ||
779 | break; | 731 | break; |
780 | case CADET_CONNECTION_SENDING_CREATE: | 732 | case CADET_CONNECTION_SENDING_CREATE: |
781 | /* Should not be possible to be called in this state. */ | 733 | /* Should not be possible to be called in this state. */ |
@@ -783,30 +735,25 @@ manage_first_hop_mq (void *cls, | |||
783 | break; | 735 | break; |
784 | case CADET_CONNECTION_SENT: | 736 | case CADET_CONNECTION_SENT: |
785 | /* Retry a bit later... */ | 737 | /* Retry a bit later... */ |
786 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, | 738 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc); |
787 | &send_create, | ||
788 | cc); | ||
789 | break; | 739 | break; |
790 | case CADET_CONNECTION_CREATE_RECEIVED: | 740 | case CADET_CONNECTION_CREATE_RECEIVED: |
791 | /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */ | 741 | /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */ |
792 | cc->metrics.age = GNUNET_TIME_absolute_get (); | 742 | cc->metrics.age = GNUNET_TIME_absolute_get (); |
793 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, | 743 | cc->task = |
794 | &send_create_ack, | 744 | GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc); |
795 | cc); | ||
796 | break; | 745 | break; |
797 | case CADET_CONNECTION_READY: | 746 | case CADET_CONNECTION_READY: |
798 | if ( (NULL == cc->keepalive_qe) && | 747 | if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) && |
799 | (GNUNET_YES == cc->mqm_ready) && | 748 | (NULL == cc->task)) |
800 | (NULL == cc->task) ) | ||
801 | { | 749 | { |
802 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 750 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
803 | "Scheduling keepalive for %s in %s\n", | 751 | "Scheduling keepalive for %s in %s\n", |
804 | GCC_2s (cc), | 752 | GCC_2s (cc), |
805 | GNUNET_STRINGS_relative_time_to_string (keepalive_period, | 753 | GNUNET_STRINGS_relative_time_to_string (keepalive_period, |
806 | GNUNET_YES)); | 754 | GNUNET_YES)); |
807 | cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, | 755 | cc->task = |
808 | &send_keepalive, | 756 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); |
809 | cc); | ||
810 | } | 757 | } |
811 | break; | 758 | break; |
812 | } | 759 | } |
@@ -844,13 +791,14 @@ connection_create (struct CadetPeer *destination, | |||
844 | cc->state = init_state; | 791 | cc->state = init_state; |
845 | cc->ct = ct; | 792 | cc->ct = ct; |
846 | cc->cid = *cid; | 793 | cc->cid = *cid; |
847 | cc->retry_delay = GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, | 794 | cc->retry_delay = |
848 | off); | 795 | GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off); |
849 | GNUNET_assert (GNUNET_OK == | 796 | GNUNET_assert (GNUNET_OK == |
850 | GNUNET_CONTAINER_multishortmap_put (connections, | 797 | GNUNET_CONTAINER_multishortmap_put ( |
851 | &GCC_get_id (cc)->connection_of_tunnel, | 798 | connections, |
852 | cc, | 799 | &GCC_get_id (cc)->connection_of_tunnel, |
853 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 800 | cc, |
801 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
854 | cc->ready_cb = ready_cb; | 802 | cc->ready_cb = ready_cb; |
855 | cc->ready_cb_cls = ready_cb_cls; | 803 | cc->ready_cb_cls = ready_cb_cls; |
856 | cc->path = path; | 804 | cc->path = path; |
@@ -860,18 +808,11 @@ connection_create (struct CadetPeer *destination, | |||
860 | GCC_2s (cc), | 808 | GCC_2s (cc), |
861 | GCPP_2s (path), | 809 | GCPP_2s (path), |
862 | off); | 810 | off); |
863 | GCPP_add_connection (path, | 811 | GCPP_add_connection (path, off, cc); |
864 | off, | 812 | for (unsigned int i = 0; i < off; i++) |
865 | cc); | 813 | GCP_add_connection (GCPP_get_peer_at_offset (path, i), cc); |
866 | for (unsigned int i=0;i<off;i++) | 814 | first_hop = GCPP_get_peer_at_offset (path, 0); |
867 | GCP_add_connection (GCPP_get_peer_at_offset (path, | 815 | cc->mq_man = GCP_request_mq (first_hop, &manage_first_hop_mq, cc); |
868 | i), | ||
869 | cc); | ||
870 | first_hop = GCPP_get_peer_at_offset (path, | ||
871 | 0); | ||
872 | cc->mq_man = GCP_request_mq (first_hop, | ||
873 | &manage_first_hop_mq, | ||
874 | cc); | ||
875 | return cc; | 816 | return cc; |
876 | } | 817 | } |
877 | 818 | ||
@@ -900,18 +841,14 @@ GCC_create_inbound (struct CadetPeer *destination, | |||
900 | struct CadetConnection *cc; | 841 | struct CadetConnection *cc; |
901 | unsigned int off; | 842 | unsigned int off; |
902 | 843 | ||
903 | off = GCPP_find_peer (path, | 844 | off = GCPP_find_peer (path, destination); |
904 | destination); | ||
905 | GNUNET_assert (UINT_MAX != off); | 845 | GNUNET_assert (UINT_MAX != off); |
906 | cc = GCPP_get_connection (path, | 846 | cc = GCPP_get_connection (path, destination, off); |
907 | destination, | ||
908 | off); | ||
909 | if (NULL != cc) | 847 | if (NULL != cc) |
910 | { | 848 | { |
911 | int cmp; | 849 | int cmp; |
912 | 850 | ||
913 | cmp = GNUNET_memcmp (cid, | 851 | cmp = GNUNET_memcmp (cid, &cc->cid); |
914 | &cc->cid); | ||
915 | if (0 == cmp) | 852 | if (0 == cmp) |
916 | { | 853 | { |
917 | /* Two peers picked the SAME random connection identifier at the | 854 | /* Two peers picked the SAME random connection identifier at the |
@@ -977,9 +914,7 @@ GCC_create (struct CadetPeer *destination, | |||
977 | { | 914 | { |
978 | struct GNUNET_CADET_ConnectionTunnelIdentifier cid; | 915 | struct GNUNET_CADET_ConnectionTunnelIdentifier cid; |
979 | 916 | ||
980 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, | 917 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof (cid)); |
981 | &cid, | ||
982 | sizeof (cid)); | ||
983 | return connection_create (destination, | 918 | return connection_create (destination, |
984 | path, | 919 | path, |
985 | off, | 920 | off, |
@@ -1002,8 +937,7 @@ GCC_create (struct CadetPeer *destination, | |||
1002 | * yet have a #GNUNET_MQ_notify_sent() callback attached to it | 937 | * yet have a #GNUNET_MQ_notify_sent() callback attached to it |
1003 | */ | 938 | */ |
1004 | void | 939 | void |
1005 | GCC_transmit (struct CadetConnection *cc, | 940 | GCC_transmit (struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env) |
1006 | struct GNUNET_MQ_Envelope *env) | ||
1007 | { | 941 | { |
1008 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 942 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1009 | "Scheduling message for transmission on %s\n", | 943 | "Scheduling message for transmission on %s\n", |
@@ -1017,8 +951,7 @@ GCC_transmit (struct CadetConnection *cc, | |||
1017 | GNUNET_SCHEDULER_cancel (cc->task); | 951 | GNUNET_SCHEDULER_cancel (cc->task); |
1018 | cc->task = NULL; | 952 | cc->task = NULL; |
1019 | } | 953 | } |
1020 | GCP_send (cc->mq_man, | 954 | GCP_send (cc->mq_man, env); |
1021 | env); | ||
1022 | } | 955 | } |
1023 | 956 | ||
1024 | 957 | ||
@@ -1030,8 +963,7 @@ GCC_transmit (struct CadetConnection *cc, | |||
1030 | * @return path to @a cc | 963 | * @return path to @a cc |
1031 | */ | 964 | */ |
1032 | struct CadetPeerPath * | 965 | struct CadetPeerPath * |
1033 | GCC_get_path (struct CadetConnection *cc, | 966 | GCC_get_path (struct CadetConnection *cc, unsigned int *off) |
1034 | unsigned int *off) | ||
1035 | { | 967 | { |
1036 | *off = cc->off; | 968 | *off = cc->off; |
1037 | return cc->path; | 969 | return cc->path; |
@@ -1081,7 +1013,8 @@ GCC_2s (const struct CadetConnection *cc) | |||
1081 | } | 1013 | } |
1082 | 1014 | ||
1083 | 1015 | ||
1084 | #define LOG2(level, ...) GNUNET_log_from_nocheck(level,"cadet-con",__VA_ARGS__) | 1016 | #define LOG2(level, ...) \ |
1017 | GNUNET_log_from_nocheck (level, "cadet-con", __VA_ARGS__) | ||
1085 | 1018 | ||
1086 | 1019 | ||
1087 | /** | 1020 | /** |
@@ -1091,21 +1024,21 @@ GCC_2s (const struct CadetConnection *cc) | |||
1091 | * @param level Debug level to use. | 1024 | * @param level Debug level to use. |
1092 | */ | 1025 | */ |
1093 | void | 1026 | void |
1094 | GCC_debug (struct CadetConnection *cc, | 1027 | GCC_debug (struct CadetConnection *cc, enum GNUNET_ErrorType level) |
1095 | enum GNUNET_ErrorType level) | ||
1096 | { | 1028 | { |
1097 | #if !defined(GNUNET_CULL_LOGGING) | 1029 | #if ! defined(GNUNET_CULL_LOGGING) |
1098 | int do_log; | 1030 | int do_log; |
1099 | 1031 | ||
1100 | do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK), | 1032 | do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK), |
1101 | "cadet-con", | 1033 | "cadet-con", |
1102 | __FILE__, __FUNCTION__, __LINE__); | 1034 | __FILE__, |
1035 | __FUNCTION__, | ||
1036 | __LINE__); | ||
1103 | if (0 == do_log) | 1037 | if (0 == do_log) |
1104 | return; | 1038 | return; |
1105 | if (NULL == cc) | 1039 | if (NULL == cc) |
1106 | { | 1040 | { |
1107 | LOG2 (level, | 1041 | LOG2 (level, "Connection (NULL)\n"); |
1108 | "Connection (NULL)\n"); | ||
1109 | return; | 1042 | return; |
1110 | } | 1043 | } |
1111 | LOG2 (level, | 1044 | LOG2 (level, |
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c index 220a2b3cd..ec70a968b 100644 --- a/src/cadet/gnunet-service-cadet_core.c +++ b/src/cadet/gnunet-service-cadet_core.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -39,7 +39,7 @@ | |||
39 | #include "gnunet_statistics_service.h" | 39 | #include "gnunet_statistics_service.h" |
40 | #include "cadet_protocol.h" | 40 | #include "cadet_protocol.h" |
41 | 41 | ||
42 | #define LOG(level, ...) GNUNET_log_from(level,"cadet-cor",__VA_ARGS__) | 42 | #define LOG(level, ...) GNUNET_log_from (level, "cadet-cor", __VA_ARGS__) |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Information we keep per direction for a route. | 45 | * Information we keep per direction for a route. |
@@ -138,7 +138,6 @@ struct RouteDirection | |||
138 | * Is @e mqm currently ready for transmission? | 138 | * Is @e mqm currently ready for transmission? |
139 | */ | 139 | */ |
140 | int is_ready; | 140 | int is_ready; |
141 | |||
142 | }; | 141 | }; |
143 | 142 | ||
144 | 143 | ||
@@ -177,8 +176,6 @@ struct CadetRoute | |||
177 | * Position of this route in the #route_heap. | 176 | * Position of this route in the #route_heap. |
178 | */ | 177 | */ |
179 | struct GNUNET_CONTAINER_HeapNode *hn; | 178 | struct GNUNET_CONTAINER_HeapNode *hn; |
180 | |||
181 | |||
182 | }; | 179 | }; |
183 | 180 | ||
184 | 181 | ||
@@ -258,24 +255,17 @@ lower_rung (struct RouteDirection *dir) | |||
258 | struct Rung *rung = dir->rung; | 255 | struct Rung *rung = dir->rung; |
259 | struct Rung *prev; | 256 | struct Rung *prev; |
260 | 257 | ||
261 | GNUNET_CONTAINER_DLL_remove (rung->rd_head, | 258 | GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir); |
262 | rung->rd_tail, | ||
263 | dir); | ||
264 | prev = rung->prev; | 259 | prev = rung->prev; |
265 | GNUNET_assert (NULL != prev); | 260 | GNUNET_assert (NULL != prev); |
266 | if (prev->rung_off != rung->rung_off - 1) | 261 | if (prev->rung_off != rung->rung_off - 1) |
267 | { | 262 | { |
268 | prev = GNUNET_new (struct Rung); | 263 | prev = GNUNET_new (struct Rung); |
269 | prev->rung_off = rung->rung_off - 1; | 264 | prev->rung_off = rung->rung_off - 1; |
270 | GNUNET_CONTAINER_DLL_insert_after (rung_head, | 265 | GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung->prev, prev); |
271 | rung_tail, | ||
272 | rung->prev, | ||
273 | prev); | ||
274 | } | 266 | } |
275 | GNUNET_assert (NULL != prev); | 267 | GNUNET_assert (NULL != prev); |
276 | GNUNET_CONTAINER_DLL_insert (prev->rd_head, | 268 | GNUNET_CONTAINER_DLL_insert (prev->rd_head, prev->rd_tail, dir); |
277 | prev->rd_tail, | ||
278 | dir); | ||
279 | dir->rung = prev; | 269 | dir->rung = prev; |
280 | } | 270 | } |
281 | 271 | ||
@@ -288,19 +278,13 @@ lower_rung (struct RouteDirection *dir) | |||
288 | * @param env envelope to discard | 278 | * @param env envelope to discard |
289 | */ | 279 | */ |
290 | static void | 280 | static void |
291 | discard_buffer (struct RouteDirection *dir, | 281 | discard_buffer (struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env) |
292 | struct GNUNET_MQ_Envelope *env) | ||
293 | { | 282 | { |
294 | GNUNET_MQ_dll_remove (&dir->env_head, | 283 | GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env); |
295 | &dir->env_tail, | ||
296 | env); | ||
297 | cur_buffers--; | 284 | cur_buffers--; |
298 | GNUNET_MQ_discard (env); | 285 | GNUNET_MQ_discard (env); |
299 | lower_rung (dir); | 286 | lower_rung (dir); |
300 | GNUNET_STATISTICS_set (stats, | 287 | GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); |
301 | "# buffer use", | ||
302 | cur_buffers, | ||
303 | GNUNET_NO); | ||
304 | } | 288 | } |
305 | 289 | ||
306 | 290 | ||
@@ -322,12 +306,9 @@ discard_all_from_rung_tail () | |||
322 | "# messages dropped due to full buffer", | 306 | "# messages dropped due to full buffer", |
323 | 1, | 307 | 1, |
324 | GNUNET_NO); | 308 | GNUNET_NO); |
325 | discard_buffer (dir, | 309 | discard_buffer (dir, dir->env_head); |
326 | dir->env_head); | ||
327 | } | 310 | } |
328 | GNUNET_CONTAINER_DLL_remove (rung_head, | 311 | GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, tail); |
329 | rung_tail, | ||
330 | tail); | ||
331 | GNUNET_free (tail); | 312 | GNUNET_free (tail); |
332 | } | 313 | } |
333 | 314 | ||
@@ -345,7 +326,7 @@ static void | |||
345 | route_message (struct CadetPeer *prev, | 326 | route_message (struct CadetPeer *prev, |
346 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | 327 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, |
347 | const struct GNUNET_MessageHeader *msg, | 328 | const struct GNUNET_MessageHeader *msg, |
348 | const enum GNUNET_MQ_PriorityPreferences priority) | 329 | const enum GNUNET_MQ_PriorityPreferences priority) |
349 | { | 330 | { |
350 | struct CadetRoute *route; | 331 | struct CadetRoute *route; |
351 | struct RouteDirection *dir; | 332 | struct RouteDirection *dir; |
@@ -371,17 +352,14 @@ route_message (struct CadetPeer *prev, | |||
371 | /* No need to respond to these! */ | 352 | /* No need to respond to these! */ |
372 | return; | 353 | return; |
373 | } | 354 | } |
374 | env = GNUNET_MQ_msg (bm, | 355 | env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); |
375 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); | ||
376 | bm->cid = *cid; | 356 | bm->cid = *cid; |
377 | bm->peer1 = my_full_id; | 357 | bm->peer1 = my_full_id; |
378 | GCP_send_ooo (prev, | 358 | GCP_send_ooo (prev, env); |
379 | env); | ||
380 | return; | 359 | return; |
381 | } | 360 | } |
382 | route->last_use = GNUNET_TIME_absolute_get (); | 361 | route->last_use = GNUNET_TIME_absolute_get (); |
383 | GNUNET_CONTAINER_heap_update_cost (route->hn, | 362 | GNUNET_CONTAINER_heap_update_cost (route->hn, route->last_use.abs_value_us); |
384 | route->last_use.abs_value_us); | ||
385 | dir = (prev == route->prev.hop) ? &route->next : &route->prev; | 363 | dir = (prev == route->prev.hop) ? &route->next : &route->prev; |
386 | if (GNUNET_YES == dir->is_ready) | 364 | if (GNUNET_YES == dir->is_ready) |
387 | { | 365 | { |
@@ -392,27 +370,24 @@ route_message (struct CadetPeer *prev, | |||
392 | GNUNET_i2s (GCP_get_id (dir->hop)), | 370 | GNUNET_i2s (GCP_get_id (dir->hop)), |
393 | GNUNET_sh2s (&cid->connection_of_tunnel)); | 371 | GNUNET_sh2s (&cid->connection_of_tunnel)); |
394 | dir->is_ready = GNUNET_NO; | 372 | dir->is_ready = GNUNET_NO; |
395 | GCP_send (dir->mqm, | 373 | GCP_send (dir->mqm, GNUNET_MQ_msg_copy (msg)); |
396 | GNUNET_MQ_msg_copy (msg)); | ||
397 | return; | 374 | return; |
398 | } | 375 | } |
399 | /* Check if buffering is disallowed, and if so, make sure we only queue | 376 | /* Check if low latency is required and if the previous message was |
400 | one message per direction. */ | 377 | unreliable; if so, make sure we only queue one message per |
401 | if ( (0 != (priority & GNUNET_MQ_PREF_NO_BUFFER)) && | 378 | direction (no buffering). */ |
402 | (NULL != dir->env_head) ) | 379 | if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && |
403 | discard_buffer (dir, | 380 | (NULL != dir->env_head) && |
404 | dir->env_head); | 381 | (0 == |
382 | (GNUNET_MQ_env_get_options (dir->env_head) & GNUNET_MQ_PREF_UNRELIABLE))) | ||
383 | discard_buffer (dir, dir->env_head); | ||
405 | /* Check for duplicates */ | 384 | /* Check for duplicates */ |
406 | for (const struct GNUNET_MQ_Envelope *env = dir->env_head; | 385 | for (const struct GNUNET_MQ_Envelope *env = dir->env_head; NULL != env; |
407 | NULL != env; | ||
408 | env = GNUNET_MQ_env_next (env)) | 386 | env = GNUNET_MQ_env_next (env)) |
409 | { | 387 | { |
410 | const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg (env); | 388 | const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg (env); |
411 | 389 | ||
412 | if ( (hdr->size == msg->size) && | 390 | if ((hdr->size == msg->size) && (0 == memcmp (hdr, msg, ntohs (msg->size)))) |
413 | (0 == memcmp (hdr, | ||
414 | msg, | ||
415 | ntohs (msg->size))) ) | ||
416 | { | 391 | { |
417 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 392 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
418 | "Received duplicate of message already in buffer, dropping\n"); | 393 | "Received duplicate of message already in buffer, dropping\n"); |
@@ -443,31 +418,22 @@ route_message (struct CadetPeer *prev, | |||
443 | "# messages dropped due to full buffer", | 418 | "# messages dropped due to full buffer", |
444 | 1, | 419 | 1, |
445 | GNUNET_NO); | 420 | GNUNET_NO); |
446 | discard_buffer (dir, | 421 | discard_buffer (dir, dir->env_head); |
447 | dir->env_head); | ||
448 | rung = dir->rung; | 422 | rung = dir->rung; |
449 | } | 423 | } |
450 | } | 424 | } |
451 | /* remove 'dir' from current rung */ | 425 | /* remove 'dir' from current rung */ |
452 | GNUNET_CONTAINER_DLL_remove (rung->rd_head, | 426 | GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir); |
453 | rung->rd_tail, | ||
454 | dir); | ||
455 | /* make 'nxt' point to the next higher rung, create if necessary */ | 427 | /* make 'nxt' point to the next higher rung, create if necessary */ |
456 | nxt = rung->next; | 428 | nxt = rung->next; |
457 | if ( (NULL == nxt) || | 429 | if ((NULL == nxt) || (rung->rung_off + 1 != nxt->rung_off)) |
458 | (rung->rung_off + 1 != nxt->rung_off) ) | ||
459 | { | 430 | { |
460 | nxt = GNUNET_new (struct Rung); | 431 | nxt = GNUNET_new (struct Rung); |
461 | nxt->rung_off = rung->rung_off + 1; | 432 | nxt->rung_off = rung->rung_off + 1; |
462 | GNUNET_CONTAINER_DLL_insert_after (rung_head, | 433 | GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung, nxt); |
463 | rung_tail, | ||
464 | rung, | ||
465 | nxt); | ||
466 | } | 434 | } |
467 | /* insert 'dir' into next higher rung */ | 435 | /* insert 'dir' into next higher rung */ |
468 | GNUNET_CONTAINER_DLL_insert (nxt->rd_head, | 436 | GNUNET_CONTAINER_DLL_insert (nxt->rd_head, nxt->rd_tail, dir); |
469 | nxt->rd_tail, | ||
470 | dir); | ||
471 | dir->rung = nxt; | 437 | dir->rung = nxt; |
472 | 438 | ||
473 | /* add message into 'dir' buffer */ | 439 | /* add message into 'dir' buffer */ |
@@ -478,21 +444,21 @@ route_message (struct CadetPeer *prev, | |||
478 | GNUNET_i2s (GCP_get_id (dir->hop)), | 444 | GNUNET_i2s (GCP_get_id (dir->hop)), |
479 | GNUNET_sh2s (&cid->connection_of_tunnel)); | 445 | GNUNET_sh2s (&cid->connection_of_tunnel)); |
480 | env = GNUNET_MQ_msg_copy (msg); | 446 | env = GNUNET_MQ_msg_copy (msg); |
481 | GNUNET_MQ_dll_insert_tail (&dir->env_head, | 447 | GNUNET_MQ_env_set_options (env, priority); |
482 | &dir->env_tail, | 448 | if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && |
483 | env); | 449 | (0 != (priority & GNUNET_MQ_PREF_OUT_OF_ORDER)) && |
450 | (NULL != dir->env_head) && | ||
451 | (0 == (GNUNET_MQ_env_get_options (dir->env_head) & | ||
452 | GNUNET_MQ_PREF_LOW_LATENCY))) | ||
453 | GNUNET_MQ_dll_insert_head (&dir->env_head, &dir->env_tail, env); | ||
454 | else | ||
455 | GNUNET_MQ_dll_insert_tail (&dir->env_head, &dir->env_tail, env); | ||
484 | cur_buffers++; | 456 | cur_buffers++; |
485 | GNUNET_STATISTICS_set (stats, | 457 | GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); |
486 | "# buffer use", | ||
487 | cur_buffers, | ||
488 | GNUNET_NO); | ||
489 | /* Clean up 'rung' if now empty (and not head) */ | 458 | /* Clean up 'rung' if now empty (and not head) */ |
490 | if ( (NULL == rung->rd_head) && | 459 | if ((NULL == rung->rd_head) && (rung != rung_head)) |
491 | (rung != rung_head) ) | ||
492 | { | 460 | { |
493 | GNUNET_CONTAINER_DLL_remove (rung_head, | 461 | GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, rung); |
494 | rung_tail, | ||
495 | rung); | ||
496 | GNUNET_free (rung); | 462 | GNUNET_free (rung); |
497 | } | 463 | } |
498 | } | 464 | } |
@@ -537,18 +503,14 @@ destroy_direction (struct RouteDirection *dir) | |||
537 | "# messages dropped due to route destruction", | 503 | "# messages dropped due to route destruction", |
538 | 1, | 504 | 1, |
539 | GNUNET_NO); | 505 | GNUNET_NO); |
540 | discard_buffer (dir, | 506 | discard_buffer (dir, env); |
541 | env); | ||
542 | } | 507 | } |
543 | if (NULL != dir->mqm) | 508 | if (NULL != dir->mqm) |
544 | { | 509 | { |
545 | GCP_request_mq_cancel (dir->mqm, | 510 | GCP_request_mq_cancel (dir->mqm, NULL); |
546 | NULL); | ||
547 | dir->mqm = NULL; | 511 | dir->mqm = NULL; |
548 | } | 512 | } |
549 | GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, | 513 | GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, rung_head->rd_tail, dir); |
550 | rung_head->rd_tail, | ||
551 | dir); | ||
552 | } | 514 | } |
553 | 515 | ||
554 | 516 | ||
@@ -562,15 +524,15 @@ destroy_route (struct CadetRoute *route) | |||
562 | { | 524 | { |
563 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 525 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
564 | "Destroying route from %s to %s of connection %s\n", | 526 | "Destroying route from %s to %s of connection %s\n", |
565 | GNUNET_i2s (GCP_get_id (route->prev.hop)), | 527 | GNUNET_i2s (GCP_get_id (route->prev.hop)), |
566 | GNUNET_i2s2 (GCP_get_id (route->next.hop)), | 528 | GNUNET_i2s2 (GCP_get_id (route->next.hop)), |
567 | GNUNET_sh2s (&route->cid.connection_of_tunnel)); | 529 | GNUNET_sh2s (&route->cid.connection_of_tunnel)); |
568 | GNUNET_assert (route == | 530 | GNUNET_assert (route == GNUNET_CONTAINER_heap_remove_node (route->hn)); |
569 | GNUNET_CONTAINER_heap_remove_node (route->hn)); | 531 | GNUNET_assert ( |
570 | GNUNET_assert (GNUNET_YES == | 532 | GNUNET_YES == |
571 | GNUNET_CONTAINER_multishortmap_remove (routes, | 533 | GNUNET_CONTAINER_multishortmap_remove (routes, |
572 | &route->cid.connection_of_tunnel, | 534 | &route->cid.connection_of_tunnel, |
573 | route)); | 535 | route)); |
574 | GNUNET_STATISTICS_set (stats, | 536 | GNUNET_STATISTICS_set (stats, |
575 | "# routes", | 537 | "# routes", |
576 | GNUNET_CONTAINER_multishortmap_size (routes), | 538 | GNUNET_CONTAINER_multishortmap_size (routes), |
@@ -607,15 +569,13 @@ send_broken (struct RouteDirection *target, | |||
607 | GNUNET_i2s2 (peer2), | 569 | GNUNET_i2s2 (peer2), |
608 | GNUNET_sh2s (&cid->connection_of_tunnel)); | 570 | GNUNET_sh2s (&cid->connection_of_tunnel)); |
609 | 571 | ||
610 | env = GNUNET_MQ_msg (bm, | 572 | env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); |
611 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); | ||
612 | bm->cid = *cid; | 573 | bm->cid = *cid; |
613 | if (NULL != peer1) | 574 | if (NULL != peer1) |
614 | bm->peer1 = *peer1; | 575 | bm->peer1 = *peer1; |
615 | if (NULL != peer2) | 576 | if (NULL != peer2) |
616 | bm->peer2 = *peer2; | 577 | bm->peer2 = *peer2; |
617 | GCP_request_mq_cancel (target->mqm, | 578 | GCP_request_mq_cancel (target->mqm, env); |
618 | env); | ||
619 | target->mqm = NULL; | 579 | target->mqm = NULL; |
620 | } | 580 | } |
621 | 581 | ||
@@ -635,33 +595,22 @@ timeout_cb (void *cls) | |||
635 | struct GNUNET_TIME_Absolute exp; | 595 | struct GNUNET_TIME_Absolute exp; |
636 | 596 | ||
637 | timeout_task = NULL; | 597 | timeout_task = NULL; |
638 | linger = GNUNET_TIME_relative_multiply (keepalive_period, | 598 | linger = GNUNET_TIME_relative_multiply (keepalive_period, 3); |
639 | 3); | ||
640 | while (NULL != (r = GNUNET_CONTAINER_heap_peek (route_heap))) | 599 | while (NULL != (r = GNUNET_CONTAINER_heap_peek (route_heap))) |
641 | { | 600 | { |
642 | exp = GNUNET_TIME_absolute_add (r->last_use, | 601 | exp = GNUNET_TIME_absolute_add (r->last_use, linger); |
643 | linger); | ||
644 | if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us) | 602 | if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us) |
645 | { | 603 | { |
646 | /* Route not yet timed out, wait until it does. */ | 604 | /* Route not yet timed out, wait until it does. */ |
647 | timeout_task = GNUNET_SCHEDULER_add_at (exp, | 605 | timeout_task = GNUNET_SCHEDULER_add_at (exp, &timeout_cb, NULL); |
648 | &timeout_cb, | ||
649 | NULL); | ||
650 | return; | 606 | return; |
651 | } | 607 | } |
652 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 608 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
653 | "Sending BROKEN due to timeout (%s was last use, %s linger)\n", | 609 | "Sending BROKEN due to timeout (%s was last use, %s linger)\n", |
654 | GNUNET_STRINGS_absolute_time_to_string (r->last_use), | 610 | GNUNET_STRINGS_absolute_time_to_string (r->last_use), |
655 | GNUNET_STRINGS_relative_time_to_string (linger, | 611 | GNUNET_STRINGS_relative_time_to_string (linger, GNUNET_YES)); |
656 | GNUNET_YES)); | 612 | send_broken (&r->prev, &r->cid, NULL, NULL); |
657 | send_broken (&r->prev, | 613 | send_broken (&r->next, &r->cid, NULL, NULL); |
658 | &r->cid, | ||
659 | NULL, | ||
660 | NULL); | ||
661 | send_broken (&r->next, | ||
662 | &r->cid, | ||
663 | NULL, | ||
664 | NULL); | ||
665 | destroy_route (r); | 614 | destroy_route (r); |
666 | } | 615 | } |
667 | /* No more routes left, so no need for a #timeout_task */ | 616 | /* No more routes left, so no need for a #timeout_task */ |
@@ -681,8 +630,7 @@ timeout_cb (void *cls) | |||
681 | * and the last envelope was discarded | 630 | * and the last envelope was discarded |
682 | */ | 631 | */ |
683 | static void | 632 | static void |
684 | dir_ready_cb (void *cls, | 633 | dir_ready_cb (void *cls, int ready) |
685 | int ready) | ||
686 | { | 634 | { |
687 | struct RouteDirection *dir = cls; | 635 | struct RouteDirection *dir = cls; |
688 | struct CadetRoute *route = dir->my_route; | 636 | struct CadetRoute *route = dir->my_route; |
@@ -695,28 +643,18 @@ dir_ready_cb (void *cls, | |||
695 | dir->is_ready = GNUNET_YES; | 643 | dir->is_ready = GNUNET_YES; |
696 | if (NULL != (env = dir->env_head)) | 644 | if (NULL != (env = dir->env_head)) |
697 | { | 645 | { |
698 | GNUNET_MQ_dll_remove (&dir->env_head, | 646 | GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env); |
699 | &dir->env_tail, | ||
700 | env); | ||
701 | cur_buffers--; | 647 | cur_buffers--; |
702 | GNUNET_STATISTICS_set (stats, | 648 | GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); |
703 | "# buffer use", | ||
704 | cur_buffers, | ||
705 | GNUNET_NO); | ||
706 | lower_rung (dir); | 649 | lower_rung (dir); |
707 | dir->is_ready = GNUNET_NO; | 650 | dir->is_ready = GNUNET_NO; |
708 | GCP_send (dir->mqm, | 651 | GCP_send (dir->mqm, env); |
709 | env); | ||
710 | } | 652 | } |
711 | return; | 653 | return; |
712 | } | 654 | } |
713 | odir = (dir == &route->next) ? &route->prev : &route->next; | 655 | odir = (dir == &route->next) ? &route->prev : &route->next; |
714 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending BROKEN due to MQ going down\n"); |
715 | "Sending BROKEN due to MQ going down\n"); | 657 | send_broken (&route->next, &route->cid, GCP_get_id (odir->hop), &my_full_id); |
716 | send_broken (&route->next, | ||
717 | &route->cid, | ||
718 | GCP_get_id (odir->hop), | ||
719 | &my_full_id); | ||
720 | destroy_route (route); | 658 | destroy_route (route); |
721 | } | 659 | } |
722 | 660 | ||
@@ -735,12 +673,8 @@ dir_init (struct RouteDirection *dir, | |||
735 | { | 673 | { |
736 | dir->hop = hop; | 674 | dir->hop = hop; |
737 | dir->my_route = route; | 675 | dir->my_route = route; |
738 | dir->mqm = GCP_request_mq (hop, | 676 | dir->mqm = GCP_request_mq (hop, &dir_ready_cb, dir); |
739 | &dir_ready_cb, | 677 | GNUNET_CONTAINER_DLL_insert (rung_head->rd_head, rung_head->rd_tail, dir); |
740 | dir); | ||
741 | GNUNET_CONTAINER_DLL_insert (rung_head->rd_head, | ||
742 | rung_head->rd_tail, | ||
743 | dir); | ||
744 | dir->rung = rung_head; | 678 | dir->rung = rung_head; |
745 | GNUNET_assert (GNUNET_YES == dir->is_ready); | 679 | GNUNET_assert (GNUNET_YES == dir->is_ready); |
746 | } | 680 | } |
@@ -757,21 +691,20 @@ dir_init (struct RouteDirection *dir, | |||
757 | * or NULL. | 691 | * or NULL. |
758 | */ | 692 | */ |
759 | static void | 693 | static void |
760 | send_broken_without_mqm (struct CadetPeer *target, | 694 | send_broken_without_mqm ( |
761 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | 695 | struct CadetPeer *target, |
762 | const struct GNUNET_PeerIdentity *failure_at) | 696 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, |
697 | const struct GNUNET_PeerIdentity *failure_at) | ||
763 | { | 698 | { |
764 | struct GNUNET_MQ_Envelope *env; | 699 | struct GNUNET_MQ_Envelope *env; |
765 | struct GNUNET_CADET_ConnectionBrokenMessage *bm; | 700 | struct GNUNET_CADET_ConnectionBrokenMessage *bm; |
766 | 701 | ||
767 | env = GNUNET_MQ_msg (bm, | 702 | env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); |
768 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); | ||
769 | bm->cid = *cid; | 703 | bm->cid = *cid; |
770 | bm->peer1 = my_full_id; | 704 | bm->peer1 = my_full_id; |
771 | if (NULL != failure_at) | 705 | if (NULL != failure_at) |
772 | bm->peer2 = *failure_at; | 706 | bm->peer2 = *failure_at; |
773 | GCP_send_ooo (target, | 707 | GCP_send_ooo (target, env); |
774 | env); | ||
775 | } | 708 | } |
776 | 709 | ||
777 | 710 | ||
@@ -782,12 +715,14 @@ send_broken_without_mqm (struct CadetPeer *target, | |||
782 | * @param msg Message itself. | 715 | * @param msg Message itself. |
783 | */ | 716 | */ |
784 | static void | 717 | static void |
785 | handle_connection_create (void *cls, | 718 | handle_connection_create ( |
786 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) | 719 | void *cls, |
720 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) | ||
787 | { | 721 | { |
788 | struct CadetPeer *sender = cls; | 722 | struct CadetPeer *sender = cls; |
789 | struct CadetPeer *next; | 723 | struct CadetPeer *next; |
790 | const struct GNUNET_PeerIdentity *pids = (const struct GNUNET_PeerIdentity *) &msg[1]; | 724 | const struct GNUNET_PeerIdentity *pids = |
725 | (const struct GNUNET_PeerIdentity *) &msg[1]; | ||
791 | struct CadetRoute *route; | 726 | struct CadetRoute *route; |
792 | uint16_t size = ntohs (msg->header.size) - sizeof (*msg); | 727 | uint16_t size = ntohs (msg->header.size) - sizeof (*msg); |
793 | unsigned int path_length; | 728 | unsigned int path_length; |
@@ -810,20 +745,19 @@ handle_connection_create (void *cls, | |||
810 | { | 745 | { |
811 | struct GNUNET_CONTAINER_MultiPeerMap *map; | 746 | struct GNUNET_CONTAINER_MultiPeerMap *map; |
812 | 747 | ||
813 | map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, | 748 | map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, GNUNET_YES); |
814 | GNUNET_YES); | ||
815 | GNUNET_assert (NULL != map); | 749 | GNUNET_assert (NULL != map); |
816 | for (unsigned int i=0;i<path_length;i++) | 750 | for (unsigned int i = 0; i < path_length; i++) |
817 | { | 751 | { |
818 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 752 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
819 | "CADET_CONNECTION_CREATE has peer %s at offset %u\n", | 753 | "CADET_CONNECTION_CREATE has peer %s at offset %u\n", |
820 | GNUNET_i2s (&pids[i]), | 754 | GNUNET_i2s (&pids[i]), |
821 | i); | 755 | i); |
822 | if (GNUNET_SYSERR == | 756 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put ( |
823 | GNUNET_CONTAINER_multipeermap_put (map, | 757 | map, |
824 | &pids[i], | 758 | &pids[i], |
825 | NULL, | 759 | NULL, |
826 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 760 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
827 | { | 761 | { |
828 | /* bogus request */ | 762 | /* bogus request */ |
829 | GNUNET_CONTAINER_multipeermap_destroy (map); | 763 | GNUNET_CONTAINER_multipeermap_destroy (map); |
@@ -836,9 +770,8 @@ handle_connection_create (void *cls, | |||
836 | GNUNET_CONTAINER_multipeermap_destroy (map); | 770 | GNUNET_CONTAINER_multipeermap_destroy (map); |
837 | } | 771 | } |
838 | /* Initiator is at offset 0, find us */ | 772 | /* Initiator is at offset 0, find us */ |
839 | for (off=1;off<path_length;off++) | 773 | for (off = 1; off < path_length; off++) |
840 | if (0 == GNUNET_memcmp (&my_full_id, | 774 | if (0 == GNUNET_memcmp (&my_full_id, &pids[off])) |
841 | &pids[off])) | ||
842 | break; | 775 | break; |
843 | if (off == path_length) | 776 | if (off == path_length) |
844 | { | 777 | { |
@@ -848,16 +781,14 @@ handle_connection_create (void *cls, | |||
848 | return; | 781 | return; |
849 | } | 782 | } |
850 | /* Check previous hop */ | 783 | /* Check previous hop */ |
851 | if (sender != GCP_get (&pids[off - 1], | 784 | if (sender != GCP_get (&pids[off - 1], GNUNET_NO)) |
852 | GNUNET_NO)) | ||
853 | { | 785 | { |
854 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 786 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
855 | "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n"); | 787 | "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n"); |
856 | GNUNET_break_op (0); | 788 | GNUNET_break_op (0); |
857 | return; | 789 | return; |
858 | } | 790 | } |
859 | if (NULL != | 791 | if (NULL != (route = get_route (&msg->cid))) |
860 | (route = get_route (&msg->cid))) | ||
861 | { | 792 | { |
862 | /* Duplicate CREATE, pass it on, previous one might have been lost! */ | 793 | /* Duplicate CREATE, pass it on, previous one might have been lost! */ |
863 | 794 | ||
@@ -867,7 +798,8 @@ handle_connection_create (void *cls, | |||
867 | route_message (sender, | 798 | route_message (sender, |
868 | &msg->cid, | 799 | &msg->cid, |
869 | &msg->header, | 800 | &msg->header, |
870 | GNUNET_MQ_PRIO_CRITICAL_CONTROL); | 801 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | |
802 | GNUNET_MQ_PREF_LOW_LATENCY); | ||
871 | return; | 803 | return; |
872 | } | 804 | } |
873 | if (off == path_length - 1) | 805 | if (off == path_length - 1) |
@@ -887,17 +819,14 @@ handle_connection_create (void *cls, | |||
887 | return; | 819 | return; |
888 | } | 820 | } |
889 | 821 | ||
890 | origin = GCP_get (&pids[0], | 822 | origin = GCP_get (&pids[0], GNUNET_YES); |
891 | GNUNET_YES); | ||
892 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 823 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
893 | "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n", | 824 | "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n", |
894 | GCP_2s (origin), | 825 | GCP_2s (origin), |
895 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | 826 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
896 | path = GCPP_get_path_from_route (path_length - 1, | 827 | path = GCPP_get_path_from_route (path_length - 1, pids); |
897 | pids); | ||
898 | if (GNUNET_OK != | 828 | if (GNUNET_OK != |
899 | GCT_add_inbound_connection (GCP_get_tunnel (origin, | 829 | GCT_add_inbound_connection (GCP_get_tunnel (origin, GNUNET_YES), |
900 | GNUNET_YES), | ||
901 | &msg->cid, | 830 | &msg->cid, |
902 | path)) | 831 | path)) |
903 | { | 832 | { |
@@ -908,18 +837,14 @@ handle_connection_create (void *cls, | |||
908 | GCP_2s (sender), | 837 | GCP_2s (sender), |
909 | GNUNET_sh2s (&msg->cid.connection_of_tunnel), | 838 | GNUNET_sh2s (&msg->cid.connection_of_tunnel), |
910 | GCPP_2s (path)); | 839 | GCPP_2s (path)); |
911 | send_broken_without_mqm (sender, | 840 | send_broken_without_mqm (sender, &msg->cid, NULL); |
912 | &msg->cid, | ||
913 | NULL); | ||
914 | return; | 841 | return; |
915 | } | 842 | } |
916 | return; | 843 | return; |
917 | } | 844 | } |
918 | /* We are merely a hop on the way, check if we can support the route */ | 845 | /* We are merely a hop on the way, check if we can support the route */ |
919 | next = GCP_get (&pids[off + 1], | 846 | next = GCP_get (&pids[off + 1], GNUNET_NO); |
920 | GNUNET_NO); | 847 | if ((NULL == next) || (GNUNET_NO == GCP_has_core_connection (next))) |
921 | if ( (NULL == next) || | ||
922 | (GNUNET_NO == GCP_has_core_connection (next)) ) | ||
923 | { | 848 | { |
924 | /* unworkable, send back BROKEN notification */ | 849 | /* unworkable, send back BROKEN notification */ |
925 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 850 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -928,9 +853,7 @@ handle_connection_create (void *cls, | |||
928 | GNUNET_sh2s (&msg->cid.connection_of_tunnel), | 853 | GNUNET_sh2s (&msg->cid.connection_of_tunnel), |
929 | GNUNET_i2s (&pids[off + 1]), | 854 | GNUNET_i2s (&pids[off + 1]), |
930 | off + 1); | 855 | off + 1); |
931 | send_broken_without_mqm (sender, | 856 | send_broken_without_mqm (sender, &msg->cid, &pids[off + 1]); |
932 | &msg->cid, | ||
933 | &pids[off + 1]); | ||
934 | return; | 857 | return; |
935 | } | 858 | } |
936 | if (max_routes <= GNUNET_CONTAINER_multishortmap_size (routes)) | 859 | if (max_routes <= GNUNET_CONTAINER_multishortmap_size (routes)) |
@@ -939,9 +862,7 @@ handle_connection_create (void *cls, | |||
939 | "Received CADET_CONNECTION_CREATE from %s for %s. We have reached our route limit. Sending BROKEN\n", | 862 | "Received CADET_CONNECTION_CREATE from %s for %s. We have reached our route limit. Sending BROKEN\n", |
940 | GCP_2s (sender), | 863 | GCP_2s (sender), |
941 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | 864 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
942 | send_broken_without_mqm (sender, | 865 | send_broken_without_mqm (sender, &msg->cid, &pids[off - 1]); |
943 | &msg->cid, | ||
944 | &pids[off - 1]); | ||
945 | return; | 866 | return; |
946 | } | 867 | } |
947 | 868 | ||
@@ -955,17 +876,14 @@ handle_connection_create (void *cls, | |||
955 | route = GNUNET_new (struct CadetRoute); | 876 | route = GNUNET_new (struct CadetRoute); |
956 | route->cid = msg->cid; | 877 | route->cid = msg->cid; |
957 | route->last_use = GNUNET_TIME_absolute_get (); | 878 | route->last_use = GNUNET_TIME_absolute_get (); |
958 | dir_init (&route->prev, | 879 | dir_init (&route->prev, route, sender); |
959 | route, | 880 | dir_init (&route->next, route, next); |
960 | sender); | ||
961 | dir_init (&route->next, | ||
962 | route, | ||
963 | next); | ||
964 | GNUNET_assert (GNUNET_OK == | 881 | GNUNET_assert (GNUNET_OK == |
965 | GNUNET_CONTAINER_multishortmap_put (routes, | 882 | GNUNET_CONTAINER_multishortmap_put ( |
966 | &route->cid.connection_of_tunnel, | 883 | routes, |
967 | route, | 884 | &route->cid.connection_of_tunnel, |
968 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 885 | route, |
886 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
969 | GNUNET_STATISTICS_set (stats, | 887 | GNUNET_STATISTICS_set (stats, |
970 | "# routes", | 888 | "# routes", |
971 | GNUNET_CONTAINER_multishortmap_size (routes), | 889 | GNUNET_CONTAINER_multishortmap_size (routes), |
@@ -974,15 +892,16 @@ handle_connection_create (void *cls, | |||
974 | route, | 892 | route, |
975 | route->last_use.abs_value_us); | 893 | route->last_use.abs_value_us); |
976 | if (NULL == timeout_task) | 894 | if (NULL == timeout_task) |
977 | timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (keepalive_period, | 895 | timeout_task = |
978 | 3), | 896 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (keepalive_period, |
979 | &timeout_cb, | 897 | 3), |
980 | NULL); | 898 | &timeout_cb, |
899 | NULL); | ||
981 | /* also pass CREATE message along to next hop */ | 900 | /* also pass CREATE message along to next hop */ |
982 | route_message (sender, | 901 | route_message (sender, |
983 | &msg->cid, | 902 | &msg->cid, |
984 | &msg->header, | 903 | &msg->header, |
985 | GNUNET_MQ_PRIO_CRITICAL_CONTROL); | 904 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); |
986 | } | 905 | } |
987 | 906 | ||
988 | 907 | ||
@@ -993,8 +912,9 @@ handle_connection_create (void *cls, | |||
993 | * @param msg Message itself. | 912 | * @param msg Message itself. |
994 | */ | 913 | */ |
995 | static void | 914 | static void |
996 | handle_connection_create_ack (void *cls, | 915 | handle_connection_create_ack ( |
997 | const struct GNUNET_CADET_ConnectionCreateAckMessage *msg) | 916 | void *cls, |
917 | const struct GNUNET_CADET_ConnectionCreateAckMessage *msg) | ||
998 | { | 918 | { |
999 | struct CadetPeer *peer = cls; | 919 | struct CadetPeer *peer = cls; |
1000 | struct CadetConnection *cc; | 920 | struct CadetConnection *cc; |
@@ -1005,12 +925,9 @@ handle_connection_create_ack (void *cls, | |||
1005 | { | 925 | { |
1006 | /* verify ACK came from the right direction */ | 926 | /* verify ACK came from the right direction */ |
1007 | unsigned int len; | 927 | unsigned int len; |
1008 | struct CadetPeerPath *path = GCC_get_path (cc, | 928 | struct CadetPeerPath *path = GCC_get_path (cc, &len); |
1009 | &len); | ||
1010 | 929 | ||
1011 | if (peer != | 930 | if (peer != GCPP_get_peer_at_offset (path, 0)) |
1012 | GCPP_get_peer_at_offset (path, | ||
1013 | 0)) | ||
1014 | { | 931 | { |
1015 | /* received ACK from unexpected direction, ignore! */ | 932 | /* received ACK from unexpected direction, ignore! */ |
1016 | GNUNET_break_op (0); | 933 | GNUNET_break_op (0); |
@@ -1027,7 +944,7 @@ handle_connection_create_ack (void *cls, | |||
1027 | route_message (peer, | 944 | route_message (peer, |
1028 | &msg->cid, | 945 | &msg->cid, |
1029 | &msg->header, | 946 | &msg->header, |
1030 | GNUNET_MQ_PRIO_CRITICAL_CONTROL); | 947 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); |
1031 | } | 948 | } |
1032 | 949 | ||
1033 | 950 | ||
@@ -1039,8 +956,9 @@ handle_connection_create_ack (void *cls, | |||
1039 | * @deprecated duplicate logic with #handle_destroy(); dedup! | 956 | * @deprecated duplicate logic with #handle_destroy(); dedup! |
1040 | */ | 957 | */ |
1041 | static void | 958 | static void |
1042 | handle_connection_broken (void *cls, | 959 | handle_connection_broken ( |
1043 | const struct GNUNET_CADET_ConnectionBrokenMessage *msg) | 960 | void *cls, |
961 | const struct GNUNET_CADET_ConnectionBrokenMessage *msg) | ||
1044 | { | 962 | { |
1045 | struct CadetPeer *peer = cls; | 963 | struct CadetPeer *peer = cls; |
1046 | struct CadetConnection *cc; | 964 | struct CadetConnection *cc; |
@@ -1052,12 +970,9 @@ handle_connection_broken (void *cls, | |||
1052 | { | 970 | { |
1053 | /* verify message came from the right direction */ | 971 | /* verify message came from the right direction */ |
1054 | unsigned int len; | 972 | unsigned int len; |
1055 | struct CadetPeerPath *path = GCC_get_path (cc, | 973 | struct CadetPeerPath *path = GCC_get_path (cc, &len); |
1056 | &len); | ||
1057 | 974 | ||
1058 | if (peer != | 975 | if (peer != GCPP_get_peer_at_offset (path, 0)) |
1059 | GCPP_get_peer_at_offset (path, | ||
1060 | 0)) | ||
1061 | { | 976 | { |
1062 | /* received message from unexpected direction, ignore! */ | 977 | /* received message from unexpected direction, ignore! */ |
1063 | GNUNET_break_op (0); | 978 | GNUNET_break_op (0); |
@@ -1076,7 +991,7 @@ handle_connection_broken (void *cls, | |||
1076 | route_message (peer, | 991 | route_message (peer, |
1077 | &msg->cid, | 992 | &msg->cid, |
1078 | &msg->header, | 993 | &msg->header, |
1079 | GNUNET_MQ_PREF_NO_BUFFER); | 994 | GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); |
1080 | route = get_route (&msg->cid); | 995 | route = get_route (&msg->cid); |
1081 | if (NULL != route) | 996 | if (NULL != route) |
1082 | destroy_route (route); | 997 | destroy_route (route); |
@@ -1091,8 +1006,9 @@ handle_connection_broken (void *cls, | |||
1091 | * @param msg Message itself. | 1006 | * @param msg Message itself. |
1092 | */ | 1007 | */ |
1093 | static void | 1008 | static void |
1094 | handle_connection_destroy (void *cls, | 1009 | handle_connection_destroy ( |
1095 | const struct GNUNET_CADET_ConnectionDestroyMessage *msg) | 1010 | void *cls, |
1011 | const struct GNUNET_CADET_ConnectionDestroyMessage *msg) | ||
1096 | { | 1012 | { |
1097 | struct CadetPeer *peer = cls; | 1013 | struct CadetPeer *peer = cls; |
1098 | struct CadetConnection *cc; | 1014 | struct CadetConnection *cc; |
@@ -1104,12 +1020,9 @@ handle_connection_destroy (void *cls, | |||
1104 | { | 1020 | { |
1105 | /* verify message came from the right direction */ | 1021 | /* verify message came from the right direction */ |
1106 | unsigned int len; | 1022 | unsigned int len; |
1107 | struct CadetPeerPath *path = GCC_get_path (cc, | 1023 | struct CadetPeerPath *path = GCC_get_path (cc, &len); |
1108 | &len); | ||
1109 | 1024 | ||
1110 | if (peer != | 1025 | if (peer != GCPP_get_peer_at_offset (path, 0)) |
1111 | GCPP_get_peer_at_offset (path, | ||
1112 | 0)) | ||
1113 | { | 1026 | { |
1114 | /* received message from unexpected direction, ignore! */ | 1027 | /* received message from unexpected direction, ignore! */ |
1115 | GNUNET_break_op (0); | 1028 | GNUNET_break_op (0); |
@@ -1130,7 +1043,7 @@ handle_connection_destroy (void *cls, | |||
1130 | route_message (peer, | 1043 | route_message (peer, |
1131 | &msg->cid, | 1044 | &msg->cid, |
1132 | &msg->header, | 1045 | &msg->header, |
1133 | GNUNET_MQ_PREF_NO_BUFFER); | 1046 | GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); |
1134 | route = get_route (&msg->cid); | 1047 | route = get_route (&msg->cid); |
1135 | if (NULL != route) | 1048 | if (NULL != route) |
1136 | destroy_route (route); | 1049 | destroy_route (route); |
@@ -1162,19 +1075,15 @@ handle_tunnel_kx (void *cls, | |||
1162 | { | 1075 | { |
1163 | /* verify message came from the right direction */ | 1076 | /* verify message came from the right direction */ |
1164 | unsigned int len; | 1077 | unsigned int len; |
1165 | struct CadetPeerPath *path = GCC_get_path (cc, | 1078 | struct CadetPeerPath *path = GCC_get_path (cc, &len); |
1166 | &len); | ||
1167 | 1079 | ||
1168 | if (peer != | 1080 | if (peer != GCPP_get_peer_at_offset (path, 0)) |
1169 | GCPP_get_peer_at_offset (path, | ||
1170 | 0)) | ||
1171 | { | 1081 | { |
1172 | /* received message from unexpected direction, ignore! */ | 1082 | /* received message from unexpected direction, ignore! */ |
1173 | GNUNET_break_op (0); | 1083 | GNUNET_break_op (0); |
1174 | return; | 1084 | return; |
1175 | } | 1085 | } |
1176 | GCC_handle_kx (cc, | 1086 | GCC_handle_kx (cc, msg); |
1177 | msg); | ||
1178 | return; | 1087 | return; |
1179 | } | 1088 | } |
1180 | 1089 | ||
@@ -1182,7 +1091,7 @@ handle_tunnel_kx (void *cls, | |||
1182 | route_message (peer, | 1091 | route_message (peer, |
1183 | &msg->cid, | 1092 | &msg->cid, |
1184 | &msg->header, | 1093 | &msg->header, |
1185 | GNUNET_MQ_PRIO_CRITICAL_CONTROL); | 1094 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); |
1186 | } | 1095 | } |
1187 | 1096 | ||
1188 | 1097 | ||
@@ -1193,8 +1102,9 @@ handle_tunnel_kx (void *cls, | |||
1193 | * @param msg Message itself. | 1102 | * @param msg Message itself. |
1194 | */ | 1103 | */ |
1195 | static void | 1104 | static void |
1196 | handle_tunnel_kx_auth (void *cls, | 1105 | handle_tunnel_kx_auth ( |
1197 | const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) | 1106 | void *cls, |
1107 | const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) | ||
1198 | { | 1108 | { |
1199 | struct CadetPeer *peer = cls; | 1109 | struct CadetPeer *peer = cls; |
1200 | struct CadetConnection *cc; | 1110 | struct CadetConnection *cc; |
@@ -1205,19 +1115,15 @@ handle_tunnel_kx_auth (void *cls, | |||
1205 | { | 1115 | { |
1206 | /* verify message came from the right direction */ | 1116 | /* verify message came from the right direction */ |
1207 | unsigned int len; | 1117 | unsigned int len; |
1208 | struct CadetPeerPath *path = GCC_get_path (cc, | 1118 | struct CadetPeerPath *path = GCC_get_path (cc, &len); |
1209 | &len); | ||
1210 | 1119 | ||
1211 | if (peer != | 1120 | if (peer != GCPP_get_peer_at_offset (path, 0)) |
1212 | GCPP_get_peer_at_offset (path, | ||
1213 | 0)) | ||
1214 | { | 1121 | { |
1215 | /* received message from unexpected direction, ignore! */ | 1122 | /* received message from unexpected direction, ignore! */ |
1216 | GNUNET_break_op (0); | 1123 | GNUNET_break_op (0); |
1217 | return; | 1124 | return; |
1218 | } | 1125 | } |
1219 | GCC_handle_kx_auth (cc, | 1126 | GCC_handle_kx_auth (cc, msg); |
1220 | msg); | ||
1221 | return; | 1127 | return; |
1222 | } | 1128 | } |
1223 | 1129 | ||
@@ -1225,7 +1131,7 @@ handle_tunnel_kx_auth (void *cls, | |||
1225 | route_message (peer, | 1131 | route_message (peer, |
1226 | &msg->kx.cid, | 1132 | &msg->kx.cid, |
1227 | &msg->kx.header, | 1133 | &msg->kx.header, |
1228 | GNUNET_MQ_PRIO_CRITICAL_CONTROL); | 1134 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); |
1229 | } | 1135 | } |
1230 | 1136 | ||
1231 | 1137 | ||
@@ -1264,26 +1170,19 @@ handle_tunnel_encrypted (void *cls, | |||
1264 | { | 1170 | { |
1265 | /* verify message came from the right direction */ | 1171 | /* verify message came from the right direction */ |
1266 | unsigned int len; | 1172 | unsigned int len; |
1267 | struct CadetPeerPath *path = GCC_get_path (cc, | 1173 | struct CadetPeerPath *path = GCC_get_path (cc, &len); |
1268 | &len); | ||
1269 | 1174 | ||
1270 | if (peer != | 1175 | if (peer != GCPP_get_peer_at_offset (path, 0)) |
1271 | GCPP_get_peer_at_offset (path, | ||
1272 | 0)) | ||
1273 | { | 1176 | { |
1274 | /* received message from unexpected direction, ignore! */ | 1177 | /* received message from unexpected direction, ignore! */ |
1275 | GNUNET_break_op (0); | 1178 | GNUNET_break_op (0); |
1276 | return; | 1179 | return; |
1277 | } | 1180 | } |
1278 | GCC_handle_encrypted (cc, | 1181 | GCC_handle_encrypted (cc, msg); |
1279 | msg); | ||
1280 | return; | 1182 | return; |
1281 | } | 1183 | } |
1282 | /* We're just an intermediary peer, route the message along its path */ | 1184 | /* We're just an intermediary peer, route the message along its path */ |
1283 | route_message (peer, | 1185 | route_message (peer, &msg->cid, &msg->header, GNUNET_MQ_PRIO_BEST_EFFORT); |
1284 | &msg->cid, | ||
1285 | &msg->header, | ||
1286 | GNUNET_MQ_PRIO_CRITICAL_CONTROL); | ||
1287 | } | 1186 | } |
1288 | 1187 | ||
1289 | 1188 | ||
@@ -1300,17 +1199,14 @@ handle_tunnel_encrypted (void *cls, | |||
1300 | * @param my_identity ID of this peer, NULL if we failed | 1199 | * @param my_identity ID of this peer, NULL if we failed |
1301 | */ | 1200 | */ |
1302 | static void | 1201 | static void |
1303 | core_init_cb (void *cls, | 1202 | core_init_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) |
1304 | const struct GNUNET_PeerIdentity *my_identity) | ||
1305 | { | 1203 | { |
1306 | if (NULL == my_identity) | 1204 | if (NULL == my_identity) |
1307 | { | 1205 | { |
1308 | GNUNET_break (0); | 1206 | GNUNET_break (0); |
1309 | return; | 1207 | return; |
1310 | } | 1208 | } |
1311 | GNUNET_break (0 == | 1209 | GNUNET_break (0 == GNUNET_memcmp (my_identity, &my_full_id)); |
1312 | GNUNET_memcmp (my_identity, | ||
1313 | &my_full_id)); | ||
1314 | } | 1210 | } |
1315 | 1211 | ||
1316 | 1212 | ||
@@ -1330,10 +1226,8 @@ core_connect_cb (void *cls, | |||
1330 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1226 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1331 | "CORE connection to peer %s was established.\n", | 1227 | "CORE connection to peer %s was established.\n", |
1332 | GNUNET_i2s (peer)); | 1228 | GNUNET_i2s (peer)); |
1333 | cp = GCP_get (peer, | 1229 | cp = GCP_get (peer, GNUNET_YES); |
1334 | GNUNET_YES); | 1230 | GCP_set_mq (cp, mq); |
1335 | GCP_set_mq (cp, | ||
1336 | mq); | ||
1337 | return cp; | 1231 | return cp; |
1338 | } | 1232 | } |
1339 | 1233 | ||
@@ -1354,8 +1248,7 @@ core_disconnect_cb (void *cls, | |||
1354 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1248 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1355 | "CORE connection to peer %s went down.\n", | 1249 | "CORE connection to peer %s went down.\n", |
1356 | GNUNET_i2s (peer)); | 1250 | GNUNET_i2s (peer)); |
1357 | GCP_set_mq (cp, | 1251 | GCP_set_mq (cp, NULL); |
1358 | NULL); | ||
1359 | } | 1252 | } |
1360 | 1253 | ||
1361 | 1254 | ||
@@ -1367,52 +1260,48 @@ core_disconnect_cb (void *cls, | |||
1367 | void | 1260 | void |
1368 | GCO_init (const struct GNUNET_CONFIGURATION_Handle *c) | 1261 | GCO_init (const struct GNUNET_CONFIGURATION_Handle *c) |
1369 | { | 1262 | { |
1370 | struct GNUNET_MQ_MessageHandler handlers[] = { | 1263 | struct GNUNET_MQ_MessageHandler handlers[] = |
1371 | GNUNET_MQ_hd_var_size (connection_create, | 1264 | {GNUNET_MQ_hd_var_size (connection_create, |
1372 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, | 1265 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, |
1373 | struct GNUNET_CADET_ConnectionCreateMessage, | 1266 | struct GNUNET_CADET_ConnectionCreateMessage, |
1374 | NULL), | 1267 | NULL), |
1375 | GNUNET_MQ_hd_fixed_size (connection_create_ack, | 1268 | GNUNET_MQ_hd_fixed_size (connection_create_ack, |
1376 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, | 1269 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, |
1377 | struct GNUNET_CADET_ConnectionCreateAckMessage, | 1270 | struct GNUNET_CADET_ConnectionCreateAckMessage, |
1378 | NULL), | 1271 | NULL), |
1379 | GNUNET_MQ_hd_fixed_size (connection_broken, | 1272 | GNUNET_MQ_hd_fixed_size (connection_broken, |
1380 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN, | 1273 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN, |
1381 | struct GNUNET_CADET_ConnectionBrokenMessage, | 1274 | struct GNUNET_CADET_ConnectionBrokenMessage, |
1382 | NULL), | 1275 | NULL), |
1383 | GNUNET_MQ_hd_fixed_size (connection_destroy, | 1276 | GNUNET_MQ_hd_fixed_size (connection_destroy, |
1384 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, | 1277 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, |
1385 | struct GNUNET_CADET_ConnectionDestroyMessage, | 1278 | struct GNUNET_CADET_ConnectionDestroyMessage, |
1386 | NULL), | 1279 | NULL), |
1387 | GNUNET_MQ_hd_fixed_size (tunnel_kx, | 1280 | GNUNET_MQ_hd_fixed_size (tunnel_kx, |
1388 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX, | 1281 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX, |
1389 | struct GNUNET_CADET_TunnelKeyExchangeMessage, | 1282 | struct GNUNET_CADET_TunnelKeyExchangeMessage, |
1390 | NULL), | 1283 | NULL), |
1391 | GNUNET_MQ_hd_fixed_size (tunnel_kx_auth, | 1284 | GNUNET_MQ_hd_fixed_size (tunnel_kx_auth, |
1392 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH, | 1285 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH, |
1393 | struct GNUNET_CADET_TunnelKeyExchangeAuthMessage, | 1286 | struct GNUNET_CADET_TunnelKeyExchangeAuthMessage, |
1394 | NULL), | 1287 | NULL), |
1395 | GNUNET_MQ_hd_var_size (tunnel_encrypted, | 1288 | GNUNET_MQ_hd_var_size (tunnel_encrypted, |
1396 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED, | 1289 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED, |
1397 | struct GNUNET_CADET_TunnelEncryptedMessage, | 1290 | struct GNUNET_CADET_TunnelEncryptedMessage, |
1398 | NULL), | 1291 | NULL), |
1399 | GNUNET_MQ_handler_end () | 1292 | GNUNET_MQ_handler_end ()}; |
1400 | }; | 1293 | |
1401 | 1294 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, | |
1402 | if (GNUNET_OK != | 1295 | "CADET", |
1403 | GNUNET_CONFIGURATION_get_value_number (c, | 1296 | "MAX_ROUTES", |
1404 | "CADET", | 1297 | &max_routes)) |
1405 | "MAX_ROUTES", | 1298 | max_routes = 5000; |
1406 | &max_routes)) | 1299 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, |
1407 | max_routes = 5000; | 1300 | "CADET", |
1408 | if (GNUNET_OK != | 1301 | "MAX_MSGS_QUEUE", |
1409 | GNUNET_CONFIGURATION_get_value_number (c, | 1302 | &max_buffers)) |
1410 | "CADET", | 1303 | max_buffers = 10000; |
1411 | "MAX_MSGS_QUEUE", | 1304 | routes = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_NO); |
1412 | &max_buffers)) | ||
1413 | max_buffers = 10000; | ||
1414 | routes = GNUNET_CONTAINER_multishortmap_create (1024, | ||
1415 | GNUNET_NO); | ||
1416 | route_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1305 | route_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1417 | core = GNUNET_CORE_connect (c, | 1306 | core = GNUNET_CORE_connect (c, |
1418 | NULL, | 1307 | NULL, |