aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-07-17 10:50:45 +0200
committerChristian Grothoff <christian@grothoff.org>2019-07-17 10:50:45 +0200
commita7ccf828ae4f7e306ffe3e7efebc0e678615f6c5 (patch)
tree71489a2649bb3c9100fccc19d135d832d3cbea05 /src
parent963c4fe2e94208a251b269e3a6918a71e8de1939 (diff)
downloadgnunet-a7ccf828ae4f7e306ffe3e7efebc0e678615f6c5.tar.gz
gnunet-a7ccf828ae4f7e306ffe3e7efebc0e678615f6c5.zip
remove duplication MQ options, make conversation build
Diffstat (limited to 'src')
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c555
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c269
-rw-r--r--src/cadet/gnunet-service-cadet_core.c501
-rw-r--r--src/conversation/gnunet-service-conversation.c415
-rw-r--r--src/fs/gnunet-service-fs_cadet_client.c243
-rw-r--r--src/include/gnunet_mq_lib.h33
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c363
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_alice.c379
-rw-r--r--src/set/gnunet-service-set.c772
-rw-r--r--src/util/mq.c22
-rw-r--r--src/vpn/gnunet-service-vpn.c2466
11 files changed, 2695 insertions, 3323 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 */
422void 425void
423GCCH_hash_port (struct GNUNET_HashCode *h_port, 426GCCH_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 */
899void 860void
900GCCH_handle_duplicate_open (struct CadetChannel *ch, 861GCCH_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 */
933static void 893static void
934send_ack_to_client (struct CadetChannel *ch, 894send_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,
973void 930void
974GCCH_bind (struct CadetChannel *ch, 931GCCH_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 */
1152void 1094void
1153GCCH_handle_channel_open_ack (struct CadetChannel *ch, 1095GCCH_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 */
1253void 1191void
1254GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, 1192GCCH_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 */
1625void 1532void
1626GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, 1533GCCH_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 */
1726void 1623void
1727GCCH_handle_remote_destroy (struct CadetChannel *ch, 1624GCCH_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 */
2115void 1980void
2116GCCH_debug (struct CadetChannel *ch, 1981GCCH_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,
232static void 230static void
233GCC_destroy (struct CadetConnection *cc) 231GCC_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
298GCC_destroy_without_tunnel (struct CadetConnection *cc) 290GCC_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 */
741static void 702static void
742manage_first_hop_mq (void *cls, 703manage_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 */
1004void 939void
1005GCC_transmit (struct CadetConnection *cc, 940GCC_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 */
1032struct CadetPeerPath * 965struct CadetPeerPath *
1033GCC_get_path (struct CadetConnection *cc, 966GCC_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 */
1093void 1026void
1094GCC_debug (struct CadetConnection *cc, 1027GCC_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 */
290static void 280static void
291discard_buffer (struct RouteDirection *dir, 281discard_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
345route_message (struct CadetPeer *prev, 326route_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 */
683static void 632static void
684dir_ready_cb (void *cls, 633dir_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 */
759static void 693static void
760send_broken_without_mqm (struct CadetPeer *target, 694send_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 */
784static void 717static void
785handle_connection_create (void *cls, 718handle_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 */
995static void 914static void
996handle_connection_create_ack (void *cls, 915handle_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 */
1041static void 958static void
1042handle_connection_broken (void *cls, 959handle_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 */
1093static void 1008static void
1094handle_connection_destroy (void *cls, 1009handle_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 */
1195static void 1104static void
1196handle_tunnel_kx_auth (void *cls, 1105handle_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 */
1302static void 1201static void
1303core_init_cb (void *cls, 1202core_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,
1367void 1260void
1368GCO_init (const struct GNUNET_CONFIGURATION_Handle *c) 1261GCO_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,
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c
index ad449a309..3e531e202 100644
--- a/src/conversation/gnunet-service-conversation.c
+++ b/src/conversation/gnunet-service-conversation.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
@@ -150,7 +150,6 @@ struct Channel
150 * #GNUNET_YES if the channel was suspended by the local client. 150 * #GNUNET_YES if the channel was suspended by the local client.
151 */ 151 */
152 int8_t suspended_local; 152 int8_t suspended_local;
153
154}; 153};
155 154
156 155
@@ -194,7 +193,6 @@ struct Line
194 * Generator for channel IDs. 193 * Generator for channel IDs.
195 */ 194 */
196 uint32_t cid_gen; 195 uint32_t cid_gen;
197
198}; 196};
199 197
200 198
@@ -223,12 +221,9 @@ static struct GNUNET_PeerIdentity my_identity;
223 * @return NULL for not found 221 * @return NULL for not found
224 */ 222 */
225static struct Channel * 223static struct Channel *
226find_channel_by_line (struct Line *line, 224find_channel_by_line (struct Line *line, uint32_t cid)
227 uint32_t cid)
228{ 225{
229 for (struct Channel *ch = line->channel_head; 226 for (struct Channel *ch = line->channel_head; NULL != ch; ch = ch->next)
230 NULL != ch;
231 ch = ch->next)
232 if (cid == ch->cid) 227 if (cid == ch->cid)
233 return ch; 228 return ch;
234 return NULL; 229 return NULL;
@@ -263,9 +258,7 @@ handle_client_pickup_message (void *cls,
263 if (NULL == ch) 258 if (NULL == ch)
264 { 259 {
265 /* could have been destroyed asynchronously, ignore message */ 260 /* could have been destroyed asynchronously, ignore message */
266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid);
267 "Channel %u not found\n",
268 msg->cid);
269 GNUNET_SERVICE_client_continue (line->client); 262 GNUNET_SERVICE_client_continue (line->client);
270 return; 263 return;
271 } 264 }
@@ -294,12 +287,10 @@ handle_client_pickup_message (void *cls,
294 return; 287 return;
295 } 288 }
296 GNUNET_break (CS_CALLEE_CONNECTED == ch->status); 289 GNUNET_break (CS_CALLEE_CONNECTED == ch->status);
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICK_UP message to cadet\n");
298 "Sending PICK_UP message to cadet\n"); 291 env =
299 env = GNUNET_MQ_msg (mppm, 292 GNUNET_MQ_msg (mppm, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP);
300 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP); 293 GNUNET_MQ_send (ch->mq, env);
301 GNUNET_MQ_send (ch->mq,
302 env);
303 GNUNET_SERVICE_client_continue (line->client); 294 GNUNET_SERVICE_client_continue (line->client);
304} 295}
305 296
@@ -329,18 +320,15 @@ clean_up_channel (struct Channel *ch)
329 case CS_CALLER_CONNECTED: 320 case CS_CALLER_CONNECTED:
330 if (NULL != line) 321 if (NULL != line)
331 { 322 {
332 env = GNUNET_MQ_msg (hup, 323 env =
333 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); 324 GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
334 hup->cid = ch->cid; 325 hup->cid = ch->cid;
335 GNUNET_MQ_send (line->mq, 326 GNUNET_MQ_send (line->mq, env);
336 env);
337 } 327 }
338 break; 328 break;
339 } 329 }
340 if (NULL != line) 330 if (NULL != line)
341 GNUNET_CONTAINER_DLL_remove (line->channel_head, 331 GNUNET_CONTAINER_DLL_remove (line->channel_head, line->channel_tail, ch);
342 line->channel_tail,
343 ch);
344 GNUNET_free (ch); 332 GNUNET_free (ch);
345} 333}
346 334
@@ -353,8 +341,7 @@ clean_up_channel (struct Channel *ch)
353static void 341static void
354destroy_line_cadet_channels (struct Channel *ch) 342destroy_line_cadet_channels (struct Channel *ch)
355{ 343{
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying cadet channels\n");
357 "Destroying cadet channels\n");
358 if (NULL != ch->channel) 345 if (NULL != ch->channel)
359 { 346 {
360 GNUNET_CADET_channel_destroy (ch->channel); 347 GNUNET_CADET_channel_destroy (ch->channel);
@@ -423,9 +410,7 @@ handle_client_hangup_message (void *cls,
423 if (NULL == ch) 410 if (NULL == ch)
424 { 411 {
425 /* could have been destroyed asynchronously, ignore message */ 412 /* could have been destroyed asynchronously, ignore message */
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid);
427 "Channel %u not found\n",
428 msg->cid);
429 GNUNET_SERVICE_client_continue (line->client); 414 GNUNET_SERVICE_client_continue (line->client);
430 return; 415 return;
431 } 416 }
@@ -460,15 +445,11 @@ handle_client_hangup_message (void *cls,
460 GNUNET_SERVICE_client_continue (line->client); 445 GNUNET_SERVICE_client_continue (line->client);
461 return; 446 return;
462 } 447 }
463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending HANG_UP message via cadet\n");
464 "Sending HANG_UP message via cadet\n"); 449 e =
465 e = GNUNET_MQ_msg (mhum, 450 GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP);
466 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP); 451 GNUNET_MQ_notify_sent (e, &mq_done_finish_caller_shutdown, ch);
467 GNUNET_MQ_notify_sent (e, 452 GNUNET_MQ_send (ch->mq, e);
468 &mq_done_finish_caller_shutdown,
469 ch);
470 GNUNET_MQ_send (ch->mq,
471 e);
472 GNUNET_SERVICE_client_continue (line->client); 453 GNUNET_SERVICE_client_continue (line->client);
473} 454}
474 455
@@ -494,9 +475,7 @@ handle_client_suspend_message (void *cls,
494 if (NULL == ch) 475 if (NULL == ch)
495 { 476 {
496 /* could have been destroyed asynchronously, ignore message */ 477 /* could have been destroyed asynchronously, ignore message */
497 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid);
498 "Channel %u not found\n",
499 msg->cid);
500 GNUNET_SERVICE_client_continue (line->client); 479 GNUNET_SERVICE_client_continue (line->client);
501 return; 480 return;
502 } 481 }
@@ -539,12 +518,10 @@ handle_client_suspend_message (void *cls,
539 GNUNET_SERVICE_client_continue (line->client); 518 GNUNET_SERVICE_client_continue (line->client);
540 return; 519 return;
541 } 520 }
542 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUSPEND message via cadet\n");
543 "Sending SUSPEND message via cadet\n"); 522 e =
544 e = GNUNET_MQ_msg (mhum, 523 GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND);
545 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND); 524 GNUNET_MQ_send (ch->mq, e);
546 GNUNET_MQ_send (ch->mq,
547 e);
548 GNUNET_SERVICE_client_continue (line->client); 525 GNUNET_SERVICE_client_continue (line->client);
549} 526}
550 527
@@ -570,9 +547,7 @@ handle_client_resume_message (void *cls,
570 if (NULL == ch) 547 if (NULL == ch)
571 { 548 {
572 /* could have been destroyed asynchronously, ignore message */ 549 /* could have been destroyed asynchronously, ignore message */
573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid);
574 "Channel %u not found\n",
575 msg->cid);
576 GNUNET_SERVICE_client_continue (line->client); 551 GNUNET_SERVICE_client_continue (line->client);
577 return; 552 return;
578 } 553 }
@@ -615,12 +590,9 @@ handle_client_resume_message (void *cls,
615 GNUNET_SERVICE_client_drop (line->client); 590 GNUNET_SERVICE_client_drop (line->client);
616 return; 591 return;
617 } 592 }
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RESUME message via cadet\n");
619 "Sending RESUME message via cadet\n"); 594 e = GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME);
620 e = GNUNET_MQ_msg (mhum, 595 GNUNET_MQ_send (ch->mq, e);
621 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME);
622 GNUNET_MQ_send (ch->mq,
623 e);
624 GNUNET_SERVICE_client_continue (line->client); 596 GNUNET_SERVICE_client_continue (line->client);
625} 597}
626 598
@@ -647,8 +619,7 @@ channel_audio_sent_notify (void *cls)
647 * @return #GNUNET_OK (any data is ok) 619 * @return #GNUNET_OK (any data is ok)
648 */ 620 */
649static int 621static int
650check_client_audio_message (void *cls, 622check_client_audio_message (void *cls, const struct ClientAudioMessage *msg)
651 const struct ClientAudioMessage *msg)
652{ 623{
653 (void) cls; 624 (void) cls;
654 (void) msg; 625 (void) msg;
@@ -663,8 +634,7 @@ check_client_audio_message (void *cls,
663 * @param msg the message from the client 634 * @param msg the message from the client
664 */ 635 */
665static void 636static void
666handle_client_audio_message (void *cls, 637handle_client_audio_message (void *cls, const struct ClientAudioMessage *msg)
667 const struct ClientAudioMessage *msg)
668{ 638{
669 struct Line *line = cls; 639 struct Line *line = cls;
670 struct CadetAudioMessage *mam; 640 struct CadetAudioMessage *mam;
@@ -672,14 +642,11 @@ handle_client_audio_message (void *cls,
672 size_t size; 642 size_t size;
673 643
674 size = ntohs (msg->header.size) - sizeof (struct ClientAudioMessage); 644 size = ntohs (msg->header.size) - sizeof (struct ClientAudioMessage);
675 ch = find_channel_by_line (line, 645 ch = find_channel_by_line (line, msg->cid);
676 msg->cid);
677 if (NULL == ch) 646 if (NULL == ch)
678 { 647 {
679 /* could have been destroyed asynchronously, ignore message */ 648 /* could have been destroyed asynchronously, ignore message */
680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid);
681 "Channel %u not found\n",
682 msg->cid);
683 GNUNET_SERVICE_client_continue (line->client); 650 GNUNET_SERVICE_client_continue (line->client);
684 return; 651 return;
685 } 652 }
@@ -726,15 +693,10 @@ handle_client_audio_message (void *cls,
726 ch->env = GNUNET_MQ_msg_extra (mam, 693 ch->env = GNUNET_MQ_msg_extra (mam,
727 size, 694 size,
728 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO); 695 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO);
729 GNUNET_memcpy (&mam[1], 696 GNUNET_memcpy (&mam[1], &msg[1], size);
730 &msg[1],
731 size);
732 /* FIXME: set options for unreliable transmission */ 697 /* FIXME: set options for unreliable transmission */
733 GNUNET_MQ_notify_sent (ch->env, 698 GNUNET_MQ_notify_sent (ch->env, &channel_audio_sent_notify, ch);
734 &channel_audio_sent_notify, 699 GNUNET_MQ_send (ch->mq, ch->env);
735 ch);
736 GNUNET_MQ_send (ch->mq,
737 ch->env);
738 GNUNET_SERVICE_client_continue (line->client); 700 GNUNET_SERVICE_client_continue (line->client);
739} 701}
740 702
@@ -746,8 +708,7 @@ handle_client_audio_message (void *cls,
746 * @param msg the incoming message 708 * @param msg the incoming message
747 */ 709 */
748static void 710static void
749handle_cadet_ring_message (void *cls, 711handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg)
750 const struct CadetPhoneRingMessage *msg)
751{ 712{
752 struct Channel *ch = cls; 713 struct Channel *ch = cls;
753 struct Line *line = ch->line; 714 struct Line *line = ch->line;
@@ -771,7 +732,9 @@ handle_cadet_ring_message (void *cls,
771 destroy_line_cadet_channels (ch); 732 destroy_line_cadet_channels (ch);
772 return; 733 return;
773 } 734 }
774 if (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (msg->expiration_time)).rel_value_us) 735 if (0 == GNUNET_TIME_absolute_get_remaining (
736 GNUNET_TIME_absolute_ntoh (msg->expiration_time))
737 .rel_value_us)
775 { 738 {
776 /* ancient call, replay? */ 739 /* ancient call, replay? */
777 GNUNET_break_op (0); 740 GNUNET_break_op (0);
@@ -789,15 +752,13 @@ handle_cadet_ring_message (void *cls,
789 } 752 }
790 GNUNET_CADET_receive_done (ch->channel); 753 GNUNET_CADET_receive_done (ch->channel);
791 ch->status = CS_CALLEE_RINGING; 754 ch->status = CS_CALLEE_RINGING;
792 env = GNUNET_MQ_msg (cring, 755 env = GNUNET_MQ_msg (cring, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING);
793 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING);
794 cring->cid = ch->cid; 756 cring->cid = ch->cid;
795 cring->caller_id = msg->caller_id; 757 cring->caller_id = msg->caller_id;
796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
797 "Sending RING message to client. CID is %u\n", 759 "Sending RING message to client. CID is %u\n",
798 (unsigned int) ch->cid); 760 (unsigned int) ch->cid);
799 GNUNET_MQ_send (line->mq, 761 GNUNET_MQ_send (line->mq, env);
800 env);
801} 762}
802 763
803 764
@@ -839,13 +800,10 @@ handle_cadet_hangup_message (void *cls,
839 case CS_CALLER_SHUTDOWN: 800 case CS_CALLER_SHUTDOWN:
840 return; 801 return;
841 } 802 }
842 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending HANG UP message to client\n");
843 "Sending HANG UP message to client\n"); 804 env = GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
844 env = GNUNET_MQ_msg (hup,
845 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
846 hup->cid = cid; 805 hup->cid = cid;
847 GNUNET_MQ_send (line->mq, 806 GNUNET_MQ_send (line->mq, env);
848 env);
849} 807}
850 808
851 809
@@ -889,13 +847,11 @@ handle_cadet_pickup_message (void *cls,
889 mq_done_finish_caller_shutdown (ch); 847 mq_done_finish_caller_shutdown (ch);
890 return; 848 return;
891 } 849 }
892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICKED UP message to client\n");
893 "Sending PICKED UP message to client\n"); 851 env =
894 env = GNUNET_MQ_msg (pick, 852 GNUNET_MQ_msg (pick, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP);
895 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP);
896 pick->cid = ch->cid; 853 pick->cid = ch->cid;
897 GNUNET_MQ_send (line->mq, 854 GNUNET_MQ_send (line->mq, env);
898 env);
899} 855}
900 856
901 857
@@ -916,9 +872,7 @@ handle_cadet_suspend_message (void *cls,
916 872
917 (void) message; 873 (void) message;
918 GNUNET_CADET_receive_done (ch->channel); 874 GNUNET_CADET_receive_done (ch->channel);
919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending channel CID: %u\n", ch->cid);
920 "Suspending channel CID: %u\n",
921 ch->cid);
922 switch (ch->status) 876 switch (ch->status)
923 { 877 {
924 case CS_CALLEE_INIT: 878 case CS_CALLEE_INIT:
@@ -941,11 +895,10 @@ handle_cadet_suspend_message (void *cls,
941 case CS_CALLER_SHUTDOWN: 895 case CS_CALLER_SHUTDOWN:
942 return; 896 return;
943 } 897 }
944 env = GNUNET_MQ_msg (suspend, 898 env =
945 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); 899 GNUNET_MQ_msg (suspend, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND);
946 suspend->cid = ch->cid; 900 suspend->cid = ch->cid;
947 GNUNET_MQ_send (line->mq, 901 GNUNET_MQ_send (line->mq, env);
948 env);
949} 902}
950 903
951 904
@@ -969,8 +922,9 @@ handle_cadet_resume_message (void *cls,
969 GNUNET_CADET_receive_done (ch->channel); 922 GNUNET_CADET_receive_done (ch->channel);
970 if (GNUNET_YES != ch->suspended_remote) 923 if (GNUNET_YES != ch->suspended_remote)
971 { 924 {
972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 925 GNUNET_log (
973 "RESUME message received for non-suspended channel, dropping channel.\n"); 926 GNUNET_ERROR_TYPE_DEBUG,
927 "RESUME message received for non-suspended channel, dropping channel.\n");
974 destroy_line_cadet_channels (ch); 928 destroy_line_cadet_channels (ch);
975 return; 929 return;
976 } 930 }
@@ -996,11 +950,10 @@ handle_cadet_resume_message (void *cls,
996 case CS_CALLER_SHUTDOWN: 950 case CS_CALLER_SHUTDOWN:
997 return; 951 return;
998 } 952 }
999 env = GNUNET_MQ_msg (resume, 953 env =
1000 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); 954 GNUNET_MQ_msg (resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME);
1001 resume->cid = ch->cid; 955 resume->cid = ch->cid;
1002 GNUNET_MQ_send (line->mq, 956 GNUNET_MQ_send (line->mq, env);
1003 env);
1004} 957}
1005 958
1006 959
@@ -1012,8 +965,7 @@ handle_cadet_resume_message (void *cls,
1012 * @return #GNUNET_OK (always) 965 * @return #GNUNET_OK (always)
1013 */ 966 */
1014static int 967static int
1015check_cadet_audio_message (void *cls, 968check_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg)
1016 const struct CadetAudioMessage *msg)
1017{ 969{
1018 (void) cls; 970 (void) cls;
1019 (void) msg; 971 (void) msg;
@@ -1028,8 +980,7 @@ check_cadet_audio_message (void *cls,
1028 * @param msg the incoming message 980 * @param msg the incoming message
1029 */ 981 */
1030static void 982static void
1031handle_cadet_audio_message (void *cls, 983handle_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg)
1032 const struct CadetAudioMessage *msg)
1033{ 984{
1034 struct Channel *ch = cls; 985 struct Channel *ch = cls;
1035 size_t msize = ntohs (msg->header.size) - sizeof (struct CadetAudioMessage); 986 size_t msize = ntohs (msg->header.size) - sizeof (struct CadetAudioMessage);
@@ -1037,28 +988,25 @@ handle_cadet_audio_message (void *cls,
1037 struct ClientAudioMessage *cam; 988 struct ClientAudioMessage *cam;
1038 989
1039 GNUNET_CADET_receive_done (ch->channel); 990 GNUNET_CADET_receive_done (ch->channel);
1040 if ( (GNUNET_YES == ch->suspended_local) || 991 if ((GNUNET_YES == ch->suspended_local) ||
1041 (GNUNET_YES == ch->suspended_remote) ) 992 (GNUNET_YES == ch->suspended_remote))
1042 { 993 {
1043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 994 GNUNET_log (
1044 "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n", 995 GNUNET_ERROR_TYPE_DEBUG,
1045 (unsigned int) msize, 996 "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n",
1046 ch->cid); 997 (unsigned int) msize,
998 ch->cid);
1047 return; 999 return;
1048 } 1000 }
1049 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1001 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1050 "Forwarding %u bytes of AUDIO data to client CID %u\n", 1002 "Forwarding %u bytes of AUDIO data to client CID %u\n",
1051 (unsigned int) msize, 1003 (unsigned int) msize,
1052 ch->cid); 1004 ch->cid);
1053 env = GNUNET_MQ_msg_extra (cam, 1005 env =
1054 msize, 1006 GNUNET_MQ_msg_extra (cam, msize, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO);
1055 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO);
1056 cam->cid = ch->cid; 1007 cam->cid = ch->cid;
1057 GNUNET_memcpy (&cam[1], 1008 GNUNET_memcpy (&cam[1], &msg[1], msize);
1058 &msg[1], 1009 GNUNET_MQ_send (ch->line->mq, env);
1059 msize);
1060 GNUNET_MQ_send (ch->line->mq,
1061 env);
1062} 1010}
1063 1011
1064 1012
@@ -1070,15 +1018,14 @@ handle_cadet_audio_message (void *cls,
1070 * @param channel connection to the other end (henceforth invalid) 1018 * @param channel connection to the other end (henceforth invalid)
1071 */ 1019 */
1072static void 1020static void
1073inbound_end (void *cls, 1021inbound_end (void *cls, const struct GNUNET_CADET_Channel *channel)
1074 const struct GNUNET_CADET_Channel *channel)
1075{ 1022{
1076 struct Channel *ch = cls; 1023 struct Channel *ch = cls;
1077 1024
1078 GNUNET_assert (channel == ch->channel); 1025 GNUNET_assert (channel == ch->channel);
1079 ch->channel = NULL; 1026 ch->channel = NULL;
1080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1081 "Channel destroyed by CADET in state %d\n", 1028 "Channel destroyed by CADET in state %d\n",
1082 ch->status); 1029 ch->status);
1083 clean_up_channel (ch); 1030 clean_up_channel (ch);
1084} 1031}
@@ -1091,34 +1038,32 @@ inbound_end (void *cls,
1091 * @param msg the message from the client 1038 * @param msg the message from the client
1092 */ 1039 */
1093static void 1040static void
1094handle_client_call_message (void *cls, 1041handle_client_call_message (void *cls, const struct ClientCallMessage *msg)
1095 const struct ClientCallMessage *msg)
1096{ 1042{
1097 struct Line *line = cls; 1043 struct Line *line = cls;
1098 struct Channel *ch = GNUNET_new (struct Channel); 1044 struct Channel *ch = GNUNET_new (struct Channel);
1099 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1045 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1100 GNUNET_MQ_hd_fixed_size (cadet_hangup_message, 1046 {GNUNET_MQ_hd_fixed_size (cadet_hangup_message,
1101 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, 1047 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP,
1102 struct CadetPhoneHangupMessage, 1048 struct CadetPhoneHangupMessage,
1103 ch), 1049 ch),
1104 GNUNET_MQ_hd_fixed_size (cadet_pickup_message, 1050 GNUNET_MQ_hd_fixed_size (cadet_pickup_message,
1105 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, 1051 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP,
1106 struct CadetPhonePickupMessage, 1052 struct CadetPhonePickupMessage,
1107 ch), 1053 ch),
1108 GNUNET_MQ_hd_fixed_size (cadet_suspend_message, 1054 GNUNET_MQ_hd_fixed_size (cadet_suspend_message,
1109 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, 1055 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND,
1110 struct CadetPhoneSuspendMessage, 1056 struct CadetPhoneSuspendMessage,
1111 ch), 1057 ch),
1112 GNUNET_MQ_hd_fixed_size (cadet_resume_message, 1058 GNUNET_MQ_hd_fixed_size (cadet_resume_message,
1113 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, 1059 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME,
1114 struct CadetPhoneResumeMessage, 1060 struct CadetPhoneResumeMessage,
1115 ch), 1061 ch),
1116 GNUNET_MQ_hd_var_size (cadet_audio_message, 1062 GNUNET_MQ_hd_var_size (cadet_audio_message,
1117 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, 1063 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO,
1118 struct CadetAudioMessage, 1064 struct CadetAudioMessage,
1119 ch), 1065 ch),
1120 GNUNET_MQ_handler_end () 1066 GNUNET_MQ_handler_end ()};
1121 };
1122 struct GNUNET_MQ_Envelope *e; 1067 struct GNUNET_MQ_Envelope *e;
1123 struct CadetPhoneRingMessage *ring; 1068 struct CadetPhoneRingMessage *ring;
1124 struct CadetPhoneRingInfoPS rs; 1069 struct CadetPhoneRingInfoPS rs;
@@ -1128,35 +1073,27 @@ handle_client_call_message (void *cls,
1128 rs.purpose.size = htonl (sizeof (struct CadetPhoneRingInfoPS)); 1073 rs.purpose.size = htonl (sizeof (struct CadetPhoneRingInfoPS));
1129 rs.line_port = line->line_port; 1074 rs.line_port = line->line_port;
1130 rs.target_peer = msg->target; 1075 rs.target_peer = msg->target;
1131 rs.expiration_time 1076 rs.expiration_time =
1132 = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (RING_TIMEOUT)); 1077 GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (RING_TIMEOUT));
1133 ch->line = line; 1078 ch->line = line;
1134 GNUNET_CONTAINER_DLL_insert (line->channel_head, 1079 GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch);
1135 line->channel_tail,
1136 ch);
1137 ch->status = CS_CALLER_CALLING; 1080 ch->status = CS_CALLER_CALLING;
1138 ch->channel = GNUNET_CADET_channel_create (cadet, 1081 ch->channel = GNUNET_CADET_channel_create (cadet,
1139 ch, 1082 ch,
1140 &msg->target, 1083 &msg->target,
1141 &msg->line_port, 1084 &msg->line_port,
1142 GNUNET_CADET_OPTION_RELIABLE,
1143 NULL, 1085 NULL,
1144 &inbound_end, 1086 &inbound_end,
1145 cadet_handlers); 1087 cadet_handlers);
1146 ch->mq = GNUNET_CADET_get_mq (ch->channel); 1088 ch->mq = GNUNET_CADET_get_mq (ch->channel);
1147 e = GNUNET_MQ_msg (ring, 1089 e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING);
1148 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); 1090 GNUNET_CRYPTO_ecdsa_key_get_public (&msg->caller_id, &ring->caller_id);
1149 GNUNET_CRYPTO_ecdsa_key_get_public (&msg->caller_id,
1150 &ring->caller_id);
1151 ring->expiration_time = rs.expiration_time; 1091 ring->expiration_time = rs.expiration_time;
1152 GNUNET_assert (GNUNET_OK == 1092 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdsa_sign (&msg->caller_id,
1153 GNUNET_CRYPTO_ecdsa_sign (&msg->caller_id, 1093 &rs.purpose,
1154 &rs.purpose, 1094 &ring->signature));
1155 &ring->signature)); 1095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n");
1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1096 GNUNET_MQ_send (ch->mq, e);
1157 "Sending RING message via CADET\n");
1158 GNUNET_MQ_send (ch->mq,
1159 e);
1160 GNUNET_SERVICE_client_continue (line->client); 1097 GNUNET_SERVICE_client_continue (line->client);
1161} 1098}
1162 1099
@@ -1188,9 +1125,7 @@ inbound_channel (void *cls,
1188 ch->channel = channel; 1125 ch->channel = channel;
1189 ch->mq = GNUNET_CADET_get_mq (ch->channel); 1126 ch->mq = GNUNET_CADET_get_mq (ch->channel);
1190 ch->cid = line->cid_gen++; 1127 ch->cid = line->cid_gen++;
1191 GNUNET_CONTAINER_DLL_insert (line->channel_head, 1128 GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch);
1192 line->channel_tail,
1193 ch);
1194 return ch; 1129 return ch;
1195} 1130}
1196 1131
@@ -1235,8 +1170,7 @@ client_disconnect_cb (void *cls,
1235 1170
1236 (void) cls; 1171 (void) cls;
1237 (void) client; 1172 (void) client;
1238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, closing line\n");
1239 "Client disconnected, closing line\n");
1240 if (NULL != line->port) 1174 if (NULL != line->port)
1241 { 1175 {
1242 GNUNET_CADET_close_port (line->port); 1176 GNUNET_CADET_close_port (line->port);
@@ -1263,33 +1197,32 @@ handle_client_register_message (void *cls,
1263 const struct ClientPhoneRegisterMessage *msg) 1197 const struct ClientPhoneRegisterMessage *msg)
1264{ 1198{
1265 struct Line *line = cls; 1199 struct Line *line = cls;
1266 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1200 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1267 GNUNET_MQ_hd_fixed_size (cadet_ring_message, 1201 {GNUNET_MQ_hd_fixed_size (cadet_ring_message,
1268 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, 1202 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING,
1269 struct CadetPhoneRingMessage, 1203 struct CadetPhoneRingMessage,
1270 NULL), 1204 NULL),
1271 GNUNET_MQ_hd_fixed_size (cadet_hangup_message, 1205 GNUNET_MQ_hd_fixed_size (cadet_hangup_message,
1272 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, 1206 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP,
1273 struct CadetPhoneHangupMessage, 1207 struct CadetPhoneHangupMessage,
1274 NULL), 1208 NULL),
1275 GNUNET_MQ_hd_fixed_size (cadet_pickup_message, 1209 GNUNET_MQ_hd_fixed_size (cadet_pickup_message,
1276 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, 1210 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP,
1277 struct CadetPhonePickupMessage, 1211 struct CadetPhonePickupMessage,
1278 NULL), 1212 NULL),
1279 GNUNET_MQ_hd_fixed_size (cadet_suspend_message, 1213 GNUNET_MQ_hd_fixed_size (cadet_suspend_message,
1280 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, 1214 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND,
1281 struct CadetPhoneSuspendMessage, 1215 struct CadetPhoneSuspendMessage,
1282 NULL), 1216 NULL),
1283 GNUNET_MQ_hd_fixed_size (cadet_resume_message, 1217 GNUNET_MQ_hd_fixed_size (cadet_resume_message,
1284 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, 1218 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME,
1285 struct CadetPhoneResumeMessage, 1219 struct CadetPhoneResumeMessage,
1286 NULL), 1220 NULL),
1287 GNUNET_MQ_hd_var_size (cadet_audio_message, 1221 GNUNET_MQ_hd_var_size (cadet_audio_message,
1288 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, 1222 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO,
1289 struct CadetAudioMessage, 1223 struct CadetAudioMessage,
1290 NULL), 1224 NULL),
1291 GNUNET_MQ_handler_end () 1225 GNUNET_MQ_handler_end ()};
1292 };
1293 1226
1294 line->line_port = msg->line_port; 1227 line->line_port = msg->line_port;
1295 line->port = GNUNET_CADET_open_port (cadet, 1228 line->port = GNUNET_CADET_open_port (cadet,
@@ -1302,7 +1235,7 @@ handle_client_register_message (void *cls,
1302 if (NULL == line->port) 1235 if (NULL == line->port)
1303 { 1236 {
1304 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1237 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1305 _("Could not open line, port %s already in use!\n"), 1238 _ ("Could not open line, port %s already in use!\n"),
1306 GNUNET_h2s (&msg->line_port)); 1239 GNUNET_h2s (&msg->line_port));
1307 GNUNET_SERVICE_client_drop (line->client); 1240 GNUNET_SERVICE_client_drop (line->client);
1308 return; 1241 return;
@@ -1344,8 +1277,7 @@ run (void *cls,
1344 (void) service; 1277 (void) service;
1345 cfg = c; 1278 cfg = c;
1346 GNUNET_assert (GNUNET_OK == 1279 GNUNET_assert (GNUNET_OK ==
1347 GNUNET_CRYPTO_get_peer_identity (cfg, 1280 GNUNET_CRYPTO_get_peer_identity (cfg, &my_identity));
1348 &my_identity));
1349 cadet = GNUNET_CADET_connect (cfg); 1281 cadet = GNUNET_CADET_connect (cfg);
1350 if (NULL == cadet) 1282 if (NULL == cadet)
1351 { 1283 {
@@ -1353,50 +1285,49 @@ run (void *cls,
1353 GNUNET_SCHEDULER_shutdown (); 1285 GNUNET_SCHEDULER_shutdown ();
1354 return; 1286 return;
1355 } 1287 }
1356 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 1288 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
1357 NULL);
1358} 1289}
1359 1290
1360 1291
1361/** 1292/**
1362 * Define "main" method using service macro. 1293 * Define "main" method using service macro.
1363 */ 1294 */
1364GNUNET_SERVICE_MAIN 1295GNUNET_SERVICE_MAIN (
1365("conversation", 1296 "conversation",
1366 GNUNET_SERVICE_OPTION_NONE, 1297 GNUNET_SERVICE_OPTION_NONE,
1367 &run, 1298 &run,
1368 &client_connect_cb, 1299 &client_connect_cb,
1369 &client_disconnect_cb, 1300 &client_disconnect_cb,
1370 NULL, 1301 NULL,
1371 GNUNET_MQ_hd_fixed_size (client_register_message, 1302 GNUNET_MQ_hd_fixed_size (client_register_message,
1372 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, 1303 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER,
1373 struct ClientPhoneRegisterMessage, 1304 struct ClientPhoneRegisterMessage,
1374 NULL), 1305 NULL),
1375 GNUNET_MQ_hd_fixed_size (client_pickup_message, 1306 GNUNET_MQ_hd_fixed_size (client_pickup_message,
1376 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP, 1307 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP,
1377 struct ClientPhonePickupMessage, 1308 struct ClientPhonePickupMessage,
1378 NULL), 1309 NULL),
1379 GNUNET_MQ_hd_fixed_size (client_suspend_message, 1310 GNUNET_MQ_hd_fixed_size (client_suspend_message,
1380 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, 1311 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND,
1381 struct ClientPhoneSuspendMessage, 1312 struct ClientPhoneSuspendMessage,
1382 NULL), 1313 NULL),
1383 GNUNET_MQ_hd_fixed_size (client_resume_message, 1314 GNUNET_MQ_hd_fixed_size (client_resume_message,
1384 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, 1315 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME,
1385 struct ClientPhoneResumeMessage, 1316 struct ClientPhoneResumeMessage,
1386 NULL), 1317 NULL),
1387 GNUNET_MQ_hd_fixed_size (client_hangup_message, 1318 GNUNET_MQ_hd_fixed_size (client_hangup_message,
1388 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, 1319 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
1389 struct ClientPhoneHangupMessage, 1320 struct ClientPhoneHangupMessage,
1390 NULL), 1321 NULL),
1391 GNUNET_MQ_hd_fixed_size (client_call_message, 1322 GNUNET_MQ_hd_fixed_size (client_call_message,
1392 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL, 1323 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL,
1393 struct ClientCallMessage, 1324 struct ClientCallMessage,
1394 NULL), 1325 NULL),
1395 GNUNET_MQ_hd_var_size (client_audio_message, 1326 GNUNET_MQ_hd_var_size (client_audio_message,
1396 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, 1327 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO,
1397 struct ClientAudioMessage, 1328 struct ClientAudioMessage,
1398 NULL), 1329 NULL),
1399 GNUNET_MQ_handler_end ()); 1330 GNUNET_MQ_handler_end ());
1400 1331
1401 1332
1402/* end of gnunet-service-conversation.c */ 1333/* end of gnunet-service-conversation.c */
diff --git a/src/fs/gnunet-service-fs_cadet_client.c b/src/fs/gnunet-service-fs_cadet_client.c
index 9f654849d..81afe0411 100644
--- a/src/fs/gnunet-service-fs_cadet_client.c
+++ b/src/fs/gnunet-service-fs_cadet_client.c
@@ -41,7 +41,8 @@
41/** 41/**
42 * After how long do we reset connections without replies? 42 * After how long do we reset connections without replies?
43 */ 43 */
44#define CLIENT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 44#define CLIENT_RETRY_TIMEOUT \
45 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
45 46
46 47
47/** 48/**
@@ -143,7 +144,6 @@ struct CadetHandle
143 * callback from the cadet API). 144 * callback from the cadet API).
144 */ 145 */
145 struct GNUNET_SCHEDULER_Task *reset_task; 146 struct GNUNET_SCHEDULER_Task *reset_task;
146
147}; 147};
148 148
149 149
@@ -181,20 +181,15 @@ transmit_pending (void *cls);
181 * @return #GNUNET_YES (continue to iterate) 181 * @return #GNUNET_YES (continue to iterate)
182 */ 182 */
183static int 183static int
184move_to_pending (void *cls, 184move_to_pending (void *cls, const struct GNUNET_HashCode *key, void *value)
185 const struct GNUNET_HashCode *key,
186 void *value)
187{ 185{
188 struct CadetHandle *mh = cls; 186 struct CadetHandle *mh = cls;
189 struct GSF_CadetRequest *sr = value; 187 struct GSF_CadetRequest *sr = value;
190 188
191 GNUNET_assert (GNUNET_YES == 189 GNUNET_assert (
192 GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, 190 GNUNET_YES ==
193 key, 191 GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, key, value));
194 value)); 192 GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr);
195 GNUNET_CONTAINER_DLL_insert (mh->pending_head,
196 mh->pending_tail,
197 sr);
198 sr->was_transmitted = GNUNET_NO; 193 sr->was_transmitted = GNUNET_NO;
199 return GNUNET_YES; 194 return GNUNET_YES;
200} 195}
@@ -209,8 +204,7 @@ move_to_pending (void *cls,
209 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 204 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
210 */ 205 */
211static int 206static int
212check_reply (void *cls, 207check_reply (void *cls, const struct CadetReplyMessage *srm)
213 const struct CadetReplyMessage *srm)
214{ 208{
215 /* We check later... */ 209 /* We check later... */
216 return GNUNET_OK; 210 return GNUNET_OK;
@@ -237,8 +231,7 @@ reset_cadet_async (struct CadetHandle *mh)
237{ 231{
238 if (NULL != mh->reset_task) 232 if (NULL != mh->reset_task)
239 GNUNET_SCHEDULER_cancel (mh->reset_task); 233 GNUNET_SCHEDULER_cancel (mh->reset_task);
240 mh->reset_task = GNUNET_SCHEDULER_add_now (&reset_cadet_task, 234 mh->reset_task = GNUNET_SCHEDULER_add_now (&reset_cadet_task, mh);
241 mh);
242} 235}
243 236
244 237
@@ -285,18 +278,16 @@ struct HandleReplyClosure
285 * @return #GNUNET_YES (continue to iterate) 278 * @return #GNUNET_YES (continue to iterate)
286 */ 279 */
287static int 280static int
288process_reply (void *cls, 281process_reply (void *cls, const struct GNUNET_HashCode *key, void *value)
289 const struct GNUNET_HashCode *key,
290 void *value)
291{ 282{
292 struct HandleReplyClosure *hrc = cls; 283 struct HandleReplyClosure *hrc = cls;
293 struct GSF_CadetRequest *sr = value; 284 struct GSF_CadetRequest *sr = value;
294 285
295 sr->proc (sr->proc_cls, 286 sr->proc (sr->proc_cls,
296 hrc->type, 287 hrc->type,
297 hrc->expiration, 288 hrc->expiration,
298 hrc->data_size, 289 hrc->data_size,
299 hrc->data); 290 hrc->data);
300 sr->proc = NULL; 291 sr->proc = NULL;
301 GSF_cadet_query_cancel (sr); 292 GSF_cadet_query_cancel (sr);
302 hrc->found = GNUNET_YES; 293 hrc->found = GNUNET_YES;
@@ -315,9 +306,7 @@ process_reply (void *cls,
315 * @return #GNUNET_YES (continue to iterate) 306 * @return #GNUNET_YES (continue to iterate)
316 */ 307 */
317static int 308static int
318free_waiting_entry (void *cls, 309free_waiting_entry (void *cls, const struct GNUNET_HashCode *key, void *value)
319 const struct GNUNET_HashCode *key,
320 void *value)
321{ 310{
322 struct GSF_CadetRequest *sr = value; 311 struct GSF_CadetRequest *sr = value;
323 312
@@ -334,8 +323,7 @@ free_waiting_entry (void *cls,
334 * @param srm the actual message 323 * @param srm the actual message
335 */ 324 */
336static void 325static void
337handle_reply (void *cls, 326handle_reply (void *cls, const struct CadetReplyMessage *srm)
338 const struct CadetReplyMessage *srm)
339{ 327{
340 struct CadetHandle *mh = cls; 328 struct CadetHandle *mh = cls;
341 struct HandleReplyClosure hrc; 329 struct HandleReplyClosure hrc;
@@ -346,43 +334,43 @@ handle_reply (void *cls,
346 msize = ntohs (srm->header.size) - sizeof (struct CadetReplyMessage); 334 msize = ntohs (srm->header.size) - sizeof (struct CadetReplyMessage);
347 type = (enum GNUNET_BLOCK_Type) ntohl (srm->type); 335 type = (enum GNUNET_BLOCK_Type) ntohl (srm->type);
348 if (GNUNET_YES != 336 if (GNUNET_YES !=
349 GNUNET_BLOCK_get_key (GSF_block_ctx, 337 GNUNET_BLOCK_get_key (GSF_block_ctx, type, &srm[1], msize, &query))
350 type,
351 &srm[1],
352 msize,
353 &query))
354 { 338 {
355 GNUNET_break_op (0); 339 GNUNET_break_op (0);
356 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 340 GNUNET_log (
357 "Received bogus reply of type %u with %u bytes via cadet from peer %s\n", 341 GNUNET_ERROR_TYPE_WARNING,
358 type, 342 "Received bogus reply of type %u with %u bytes via cadet from peer %s\n",
359 msize, 343 type,
360 GNUNET_i2s (&mh->target)); 344 msize,
345 GNUNET_i2s (&mh->target));
361 reset_cadet_async (mh); 346 reset_cadet_async (mh);
362 return; 347 return;
363 } 348 }
364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
365 "Received reply `%s' via cadet from peer %s\n", 350 "Received reply `%s' via cadet from peer %s\n",
366 GNUNET_h2s (&query), 351 GNUNET_h2s (&query),
367 GNUNET_i2s (&mh->target)); 352 GNUNET_i2s (&mh->target));
368 GNUNET_CADET_receive_done (mh->channel); 353 GNUNET_CADET_receive_done (mh->channel);
369 GNUNET_STATISTICS_update (GSF_stats, 354 GNUNET_STATISTICS_update (GSF_stats,
370 gettext_noop ("# replies received via cadet"), 1, 355 gettext_noop ("# replies received via cadet"),
371 GNUNET_NO); 356 1,
357 GNUNET_NO);
372 hrc.data = &srm[1]; 358 hrc.data = &srm[1];
373 hrc.data_size = msize; 359 hrc.data_size = msize;
374 hrc.expiration = GNUNET_TIME_absolute_ntoh (srm->expiration); 360 hrc.expiration = GNUNET_TIME_absolute_ntoh (srm->expiration);
375 hrc.type = type; 361 hrc.type = type;
376 hrc.found = GNUNET_NO; 362 hrc.found = GNUNET_NO;
377 GNUNET_CONTAINER_multihashmap_get_multiple (mh->waiting_map, 363 GNUNET_CONTAINER_multihashmap_get_multiple (mh->waiting_map,
378 &query, 364 &query,
379 &process_reply, 365 &process_reply,
380 &hrc); 366 &hrc);
381 if (GNUNET_NO == hrc.found) 367 if (GNUNET_NO == hrc.found)
382 { 368 {
383 GNUNET_STATISTICS_update (GSF_stats, 369 GNUNET_STATISTICS_update (GSF_stats,
384 gettext_noop ("# replies received via cadet dropped"), 1, 370 gettext_noop (
385 GNUNET_NO); 371 "# replies received via cadet dropped"),
372 1,
373 GNUNET_NO);
386 } 374 }
387} 375}
388 376
@@ -395,8 +383,7 @@ handle_reply (void *cls,
395 * @param channel channel of the disconnecting client 383 * @param channel channel of the disconnecting client
396 */ 384 */
397static void 385static void
398disconnect_cb (void *cls, 386disconnect_cb (void *cls, const struct GNUNET_CADET_Channel *channel)
399 const struct GNUNET_CADET_Channel *channel)
400{ 387{
401 struct CadetHandle *mh = cls; 388 struct CadetHandle *mh = cls;
402 struct GSF_CadetRequest *sr; 389 struct GSF_CadetRequest *sr;
@@ -411,19 +398,17 @@ disconnect_cb (void *cls,
411 callback from `free_waiting_entry()` happens to re-issue 398 callback from `free_waiting_entry()` happens to re-issue
412 the request, we don't immediately have it back in the 399 the request, we don't immediately have it back in the
413 `waiting_map`. */ 400 `waiting_map`. */
414 GNUNET_assert (GNUNET_OK == 401 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (cadet_map,
415 GNUNET_CONTAINER_multipeermap_remove (cadet_map, 402 &mh->target,
416 &mh->target, 403 mh));
417 mh));
418 GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, 404 GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map,
419 &free_waiting_entry, 405 &free_waiting_entry,
420 mh); 406 mh);
421 if (NULL != mh->timeout_task) 407 if (NULL != mh->timeout_task)
422 GNUNET_SCHEDULER_cancel (mh->timeout_task); 408 GNUNET_SCHEDULER_cancel (mh->timeout_task);
423 if (NULL != mh->reset_task) 409 if (NULL != mh->reset_task)
424 GNUNET_SCHEDULER_cancel (mh->reset_task); 410 GNUNET_SCHEDULER_cancel (mh->reset_task);
425 GNUNET_assert (0 == 411 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map));
426 GNUNET_CONTAINER_multihashmap_size (mh->waiting_map));
427 GNUNET_CONTAINER_multihashmap_destroy (mh->waiting_map); 412 GNUNET_CONTAINER_multihashmap_destroy (mh->waiting_map);
428 GNUNET_free (mh); 413 GNUNET_free (mh);
429} 414}
@@ -467,24 +452,21 @@ static void
467reset_cadet (struct CadetHandle *mh) 452reset_cadet (struct CadetHandle *mh)
468{ 453{
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
470 "Resetting cadet channel to %s\n", 455 "Resetting cadet channel to %s\n",
471 GNUNET_i2s (&mh->target)); 456 GNUNET_i2s (&mh->target));
472 if (NULL != mh->channel) 457 if (NULL != mh->channel)
473 { 458 {
474 GNUNET_CADET_channel_destroy (mh->channel); 459 GNUNET_CADET_channel_destroy (mh->channel);
475 mh->channel = NULL; 460 mh->channel = NULL;
476 } 461 }
477 GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, 462 GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, &move_to_pending, mh);
478 &move_to_pending,
479 mh);
480 { 463 {
481 struct GNUNET_MQ_MessageHandler handlers[] = { 464 struct GNUNET_MQ_MessageHandler handlers[] =
482 GNUNET_MQ_hd_var_size (reply, 465 {GNUNET_MQ_hd_var_size (reply,
483 GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, 466 GNUNET_MESSAGE_TYPE_FS_CADET_REPLY,
484 struct CadetReplyMessage, 467 struct CadetReplyMessage,
485 mh), 468 mh),
486 GNUNET_MQ_handler_end () 469 GNUNET_MQ_handler_end ()};
487 };
488 struct GNUNET_HashCode port; 470 struct GNUNET_HashCode port;
489 471
490 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, 472 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER,
@@ -514,8 +496,8 @@ cadet_timeout (void *cls)
514 struct GNUNET_CADET_Channel *tun; 496 struct GNUNET_CADET_Channel *tun;
515 497
516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
517 "Timeout on cadet channel to %s\n", 499 "Timeout on cadet channel to %s\n",
518 GNUNET_i2s (&mh->target)); 500 GNUNET_i2s (&mh->target));
519 mh->timeout_task = NULL; 501 mh->timeout_task = NULL;
520 tun = mh->channel; 502 tun = mh->channel;
521 mh->channel = NULL; 503 mh->channel = NULL;
@@ -553,33 +535,28 @@ transmit_pending (void *cls)
553 struct GNUNET_MQ_Envelope *env; 535 struct GNUNET_MQ_Envelope *env;
554 struct CadetQueryMessage *sqm; 536 struct CadetQueryMessage *sqm;
555 537
556 if ( (0 != GNUNET_MQ_get_length (mq)) || 538 if ((0 != GNUNET_MQ_get_length (mq)) || (NULL == (sr = mh->pending_head)))
557 (NULL == (sr = mh->pending_head)) )
558 return; 539 return;
559 GNUNET_CONTAINER_DLL_remove (mh->pending_head, 540 GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr);
560 mh->pending_tail, 541 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
561 sr); 542 mh->waiting_map,
562 GNUNET_assert (GNUNET_OK == 543 &sr->query,
563 GNUNET_CONTAINER_multihashmap_put (mh->waiting_map, 544 sr,
564 &sr->query, 545 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
565 sr,
566 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
567 sr->was_transmitted = GNUNET_YES; 546 sr->was_transmitted = GNUNET_YES;
568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
569 "Sending query for %s via cadet to %s\n", 548 "Sending query for %s via cadet to %s\n",
570 GNUNET_h2s (&sr->query), 549 GNUNET_h2s (&sr->query),
571 GNUNET_i2s (&mh->target)); 550 GNUNET_i2s (&mh->target));
572 env = GNUNET_MQ_msg (sqm, 551 env = GNUNET_MQ_msg (sqm, GNUNET_MESSAGE_TYPE_FS_CADET_QUERY);
573 GNUNET_MESSAGE_TYPE_FS_CADET_QUERY); 552 GNUNET_MQ_env_set_options (env,
574 GNUNET_MQ_env_set_options(env, 553 GNUNET_MQ_PREF_GOODPUT |
575 GNUNET_MQ_PREF_RELIABLE); 554 GNUNET_MQ_PREF_CORK_ALLOWED |
555 GNUNET_MQ_PREF_OUT_OF_ORDER);
576 sqm->type = htonl (sr->type); 556 sqm->type = htonl (sr->type);
577 sqm->query = sr->query; 557 sqm->query = sr->query;
578 GNUNET_MQ_notify_sent (env, 558 GNUNET_MQ_notify_sent (env, &transmit_pending, mh);
579 &transmit_pending, 559 GNUNET_MQ_send (mq, env);
580 mh);
581 GNUNET_MQ_send (mq,
582 env);
583} 560}
584 561
585 562
@@ -593,8 +570,7 @@ get_cadet (const struct GNUNET_PeerIdentity *target)
593{ 570{
594 struct CadetHandle *mh; 571 struct CadetHandle *mh;
595 572
596 mh = GNUNET_CONTAINER_multipeermap_get (cadet_map, 573 mh = GNUNET_CONTAINER_multipeermap_get (cadet_map, target);
597 target);
598 if (NULL != mh) 574 if (NULL != mh)
599 { 575 {
600 if (NULL != mh->timeout_task) 576 if (NULL != mh->timeout_task)
@@ -605,27 +581,26 @@ get_cadet (const struct GNUNET_PeerIdentity *target)
605 return mh; 581 return mh;
606 } 582 }
607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
608 "Creating cadet channel to %s\n", 584 "Creating cadet channel to %s\n",
609 GNUNET_i2s (target)); 585 GNUNET_i2s (target));
610 mh = GNUNET_new (struct CadetHandle); 586 mh = GNUNET_new (struct CadetHandle);
611 mh->reset_task = GNUNET_SCHEDULER_add_delayed (CLIENT_RETRY_TIMEOUT, 587 mh->reset_task =
612 &reset_cadet_task, 588 GNUNET_SCHEDULER_add_delayed (CLIENT_RETRY_TIMEOUT, &reset_cadet_task, mh);
613 mh);
614 mh->waiting_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES); 589 mh->waiting_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES);
615 mh->target = *target; 590 mh->target = *target;
616 GNUNET_assert (GNUNET_OK == 591 GNUNET_assert (GNUNET_OK ==
617 GNUNET_CONTAINER_multipeermap_put (cadet_map, 592 GNUNET_CONTAINER_multipeermap_put (
618 &mh->target, 593 cadet_map,
619 mh, 594 &mh->target,
620 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 595 mh,
596 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
621 { 597 {
622 struct GNUNET_MQ_MessageHandler handlers[] = { 598 struct GNUNET_MQ_MessageHandler handlers[] =
623 GNUNET_MQ_hd_var_size (reply, 599 {GNUNET_MQ_hd_var_size (reply,
624 GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, 600 GNUNET_MESSAGE_TYPE_FS_CADET_REPLY,
625 struct CadetReplyMessage, 601 struct CadetReplyMessage,
626 mh), 602 mh),
627 GNUNET_MQ_handler_end () 603 GNUNET_MQ_handler_end ()};
628 };
629 struct GNUNET_HashCode port; 604 struct GNUNET_HashCode port;
630 605
631 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, 606 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER,
@@ -664,9 +639,9 @@ GSF_cadet_query (const struct GNUNET_PeerIdentity *target,
664 struct GSF_CadetRequest *sr; 639 struct GSF_CadetRequest *sr;
665 640
666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 641 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
667 "Preparing to send query for %s via cadet to %s\n", 642 "Preparing to send query for %s via cadet to %s\n",
668 GNUNET_h2s (query), 643 GNUNET_h2s (query),
669 GNUNET_i2s (target)); 644 GNUNET_i2s (target));
670 mh = get_cadet (target); 645 mh = get_cadet (target);
671 sr = GNUNET_new (struct GSF_CadetRequest); 646 sr = GNUNET_new (struct GSF_CadetRequest);
672 sr->mh = mh; 647 sr->mh = mh;
@@ -674,9 +649,7 @@ GSF_cadet_query (const struct GNUNET_PeerIdentity *target,
674 sr->proc_cls = proc_cls; 649 sr->proc_cls = proc_cls;
675 sr->type = type; 650 sr->type = type;
676 sr->query = *query; 651 sr->query = *query;
677 GNUNET_CONTAINER_DLL_insert (mh->pending_head, 652 GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr);
678 mh->pending_tail,
679 sr);
680 transmit_pending (mh); 653 transmit_pending (mh);
681 return sr; 654 return sr;
682} 655}
@@ -699,29 +672,24 @@ GSF_cadet_query_cancel (struct GSF_CadetRequest *sr)
699 if (NULL != p) 672 if (NULL != p)
700 { 673 {
701 /* signal failure / cancellation to callback */ 674 /* signal failure / cancellation to callback */
702 p (sr->proc_cls, GNUNET_BLOCK_TYPE_ANY, 675 p (sr->proc_cls, GNUNET_BLOCK_TYPE_ANY, GNUNET_TIME_UNIT_ZERO_ABS, 0, NULL);
703 GNUNET_TIME_UNIT_ZERO_ABS,
704 0, NULL);
705 } 676 }
706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
707 "Cancelled query for %s via cadet to %s\n", 678 "Cancelled query for %s via cadet to %s\n",
708 GNUNET_h2s (&sr->query), 679 GNUNET_h2s (&sr->query),
709 GNUNET_i2s (&sr->mh->target)); 680 GNUNET_i2s (&sr->mh->target));
710 if (GNUNET_YES == sr->was_transmitted) 681 if (GNUNET_YES == sr->was_transmitted)
711 GNUNET_assert (GNUNET_OK == 682 GNUNET_assert (
712 GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, 683 GNUNET_OK ==
713 &sr->query, 684 GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, &sr->query, sr));
714 sr));
715 else 685 else
716 GNUNET_CONTAINER_DLL_remove (mh->pending_head, 686 GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr);
717 mh->pending_tail,
718 sr);
719 GNUNET_free (sr); 687 GNUNET_free (sr);
720 if ( (0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)) && 688 if ((0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)) &&
721 (NULL == mh->pending_head) ) 689 (NULL == mh->pending_head))
722 mh->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 690 mh->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
723 &cadet_timeout, 691 &cadet_timeout,
724 mh); 692 mh);
725} 693}
726 694
727 695
@@ -741,8 +709,8 @@ GSF_cadet_release_clients (void *cls,
741 struct CadetHandle *mh = value; 709 struct CadetHandle *mh = value;
742 710
743 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
744 "Timeout on cadet channel to %s\n", 712 "Timeout on cadet channel to %s\n",
745 GNUNET_i2s (&mh->target)); 713 GNUNET_i2s (&mh->target));
746 if (NULL != mh->channel) 714 if (NULL != mh->channel)
747 { 715 {
748 struct GNUNET_CADET_Channel *channel = mh->channel; 716 struct GNUNET_CADET_Channel *channel = mh->channel;
@@ -759,5 +727,4 @@ GSF_cadet_release_clients (void *cls,
759} 727}
760 728
761 729
762
763/* end of gnunet-service-fs_cadet_client.c */ 730/* end of gnunet-service-fs_cadet_client.c */
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index d3f4c9717..f3073d54b 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -298,21 +298,6 @@ enum GNUNET_MQ_PriorityPreferences
298 */ 298 */
299 GNUNET_MQ_PREF_OUT_OF_ORDER = 256, 299 GNUNET_MQ_PREF_OUT_OF_ORDER = 256,
300 300
301 /**
302 * Flag to indicate no buffering.
303 */
304 GNUNET_MQ_PREF_NO_BUFFER = 512,
305
306 /**
307 * Flag to indicate default
308 */
309 GNUNET_MQ_PREF_DEFAULT = 1024,
310
311 /**
312 * Flag to indicate reliable
313 */
314 GNUNET_MQ_PREF_RELIABLE = 2048
315
316}; 301};
317 302
318 303
@@ -401,6 +386,24 @@ typedef void (*GNUNET_MQ_ErrorHandler) (void *cls, enum GNUNET_MQ_Error error);
401 * @param[in|out] env element to insert at the tail 386 * @param[in|out] env element to insert at the tail
402 */ 387 */
403void 388void
389GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head,
390 struct GNUNET_MQ_Envelope **env_tail,
391 struct GNUNET_MQ_Envelope *env);
392
393
394/**
395 * Insert @a env into the envelope DLL starting at @a env_head
396 * Note that @a env must not be in any MQ while this function
397 * is used with DLLs defined outside of the MQ module. This
398 * is just in case some application needs to also manage a
399 * FIFO of envelopes independent of MQ itself and wants to
400 * re-use the pointers internal to @a env. Use with caution.
401 *
402 * @param[in|out] env_head of envelope DLL
403 * @param[in|out] env_tail tail of envelope DLL
404 * @param[in|out] env element to insert at the tail
405 */
406void
404GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head, 407GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
405 struct GNUNET_MQ_Envelope **env_tail, 408 struct GNUNET_MQ_Envelope **env_tail,
406 struct GNUNET_MQ_Envelope *env); 409 struct GNUNET_MQ_Envelope *env);
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
index 123a02188..dc2763943 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.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
@@ -36,7 +36,8 @@
36#include "scalarproduct.h" 36#include "scalarproduct.h"
37#include "gnunet-service-scalarproduct-ecc.h" 37#include "gnunet-service-scalarproduct-ecc.h"
38 38
39#define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) 39#define LOG(kind, ...) \
40 GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__)
40 41
41/** 42/**
42 * Maximum allowed result value for the scalarproduct computation. 43 * Maximum allowed result value for the scalarproduct computation.
@@ -69,7 +70,6 @@ struct MpiElement
69 * a_i value, not disclosed to Bob. 70 * a_i value, not disclosed to Bob.
70 */ 71 */
71 gcry_mpi_t value; 72 gcry_mpi_t value;
72
73}; 73};
74 74
75 75
@@ -175,7 +175,6 @@ struct AliceServiceSession
175 * doing harm. 175 * doing harm.
176 */ 176 */
177 int in_destroy; 177 int in_destroy;
178
179}; 178};
180 179
181 180
@@ -214,9 +213,7 @@ static struct GNUNET_CADET_Handle *my_cadet;
214 * @return #GNUNET_OK (continue to iterate) 213 * @return #GNUNET_OK (continue to iterate)
215 */ 214 */
216static int 215static int
217free_element_cb (void *cls, 216free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
218 const struct GNUNET_HashCode *key,
219 void *value)
220{ 217{
221 struct GNUNET_SCALARPRODUCT_Element *e = value; 218 struct GNUNET_SCALARPRODUCT_Element *e = value;
222 219
@@ -265,8 +262,7 @@ destroy_service_session (struct AliceServiceSession *s)
265 } 262 }
266 if (NULL != s->intersection_op) 263 if (NULL != s->intersection_op)
267 { 264 {
268 LOG (GNUNET_ERROR_TYPE_DEBUG, 265 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection, op still ongoing!\n");
269 "Set intersection, op still ongoing!\n");
270 GNUNET_SET_operation_cancel (s->intersection_op); 266 GNUNET_SET_operation_cancel (s->intersection_op);
271 s->intersection_op = NULL; 267 s->intersection_op = NULL;
272 } 268 }
@@ -277,7 +273,7 @@ destroy_service_session (struct AliceServiceSession *s)
277 } 273 }
278 if (NULL != s->sorted_elements) 274 if (NULL != s->sorted_elements)
279 { 275 {
280 for (i=0;i<s->used_element_count;i++) 276 for (i = 0; i < s->used_element_count; i++)
281 gcry_mpi_release (s->sorted_elements[i].value); 277 gcry_mpi_release (s->sorted_elements[i].value);
282 GNUNET_free (s->sorted_elements); 278 GNUNET_free (s->sorted_elements);
283 s->sorted_elements = NULL; 279 s->sorted_elements = NULL;
@@ -305,16 +301,15 @@ prepare_client_end_notification (struct AliceServiceSession *session)
305 301
306 if (NULL == session->client_mq) 302 if (NULL == session->client_mq)
307 return; /* no client left to be notified */ 303 return; /* no client left to be notified */
308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 304 GNUNET_log (
309 "Sending session-end notification with status %d to client for session %s\n", 305 GNUNET_ERROR_TYPE_DEBUG,
310 session->status, 306 "Sending session-end notification with status %d to client for session %s\n",
311 GNUNET_h2s (&session->session_id)); 307 session->status,
312 e = GNUNET_MQ_msg (msg, 308 GNUNET_h2s (&session->session_id));
313 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 309 e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
314 msg->product_length = htonl (0); 310 msg->product_length = htonl (0);
315 msg->status = htonl (session->status); 311 msg->status = htonl (session->status);
316 GNUNET_MQ_send (session->client_mq, 312 GNUNET_MQ_send (session->client_mq, e);
317 e);
318} 313}
319 314
320 315
@@ -347,9 +342,7 @@ transmit_client_response (struct AliceServiceSession *s)
347 if (0 > sign) 342 if (0 > sign)
348 { 343 {
349 range = -1; 344 range = -1;
350 gcry_mpi_sub (value, 345 gcry_mpi_sub (value, value, s->product);
351 value,
352 s->product);
353 } 346 }
354 else if (0 < sign) 347 else if (0 < sign)
355 { 348 {
@@ -364,15 +357,12 @@ transmit_client_response (struct AliceServiceSession *s)
364 gcry_mpi_release (s->product); 357 gcry_mpi_release (s->product);
365 s->product = NULL; 358 s->product = NULL;
366 359
367 if ( (0 != range) && 360 if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD,
368 (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, 361 &product_exported,
369 &product_exported, 362 &product_length,
370 &product_length, 363 value))))
371 value))))
372 { 364 {
373 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, 365 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
374 "gcry_mpi_scan",
375 rc);
376 prepare_client_end_notification (s); 366 prepare_client_end_notification (s);
377 return; 367 return;
378 } 368 }
@@ -385,13 +375,10 @@ transmit_client_response (struct AliceServiceSession *s)
385 msg->product_length = htonl (product_length); 375 msg->product_length = htonl (product_length);
386 if (NULL != product_exported) 376 if (NULL != product_exported)
387 { 377 {
388 GNUNET_memcpy (&msg[1], 378 GNUNET_memcpy (&msg[1], product_exported, product_length);
389 product_exported,
390 product_length);
391 GNUNET_free (product_exported); 379 GNUNET_free (product_exported);
392 } 380 }
393 GNUNET_MQ_send (s->client_mq, 381 GNUNET_MQ_send (s->client_mq, e);
394 e);
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Sent result to client, session %s has ended!\n", 383 "Sent result to client, session %s has ended!\n",
397 GNUNET_h2s (&s->session_id)); 384 GNUNET_h2s (&s->session_id));
@@ -408,8 +395,7 @@ transmit_client_response (struct AliceServiceSession *s)
408 * @param channel connection to the other end (henceforth invalid) 395 * @param channel connection to the other end (henceforth invalid)
409 */ 396 */
410static void 397static void
411cb_channel_destruction (void *cls, 398cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel)
412 const struct GNUNET_CADET_Channel *channel)
413{ 399{
414 struct AliceServiceSession *s = cls; 400 struct AliceServiceSession *s = cls;
415 401
@@ -445,15 +431,11 @@ compute_scalar_product (struct AliceServiceSession *session,
445 int ai_bi; 431 int ai_bi;
446 gcry_mpi_t ret; 432 gcry_mpi_t ret;
447 433
448 g_i_b_i_a_inv = GNUNET_CRYPTO_ecc_pmul_mpi (edc, 434 g_i_b_i_a_inv =
449 prod_g_i_b_i, 435 GNUNET_CRYPTO_ecc_pmul_mpi (edc, prod_g_i_b_i, my_privkey_inv);
450 my_privkey_inv); 436 g_ai_bi = GNUNET_CRYPTO_ecc_add (edc, g_i_b_i_a_inv, prod_h_i_b_i);
451 g_ai_bi = GNUNET_CRYPTO_ecc_add (edc,
452 g_i_b_i_a_inv,
453 prod_h_i_b_i);
454 gcry_mpi_point_release (g_i_b_i_a_inv); 437 gcry_mpi_point_release (g_i_b_i_a_inv);
455 ai_bi = GNUNET_CRYPTO_ecc_dlog (edc, 438 ai_bi = GNUNET_CRYPTO_ecc_dlog (edc, g_ai_bi);
456 g_ai_bi);
457 gcry_mpi_point_release (g_ai_bi); 439 gcry_mpi_point_release (g_ai_bi);
458 if (INT_MAX == ai_bi) 440 if (INT_MAX == ai_bi)
459 { 441 {
@@ -469,7 +451,7 @@ compute_scalar_product (struct AliceServiceSession *session,
469 } 451 }
470 else 452 else
471 { 453 {
472 gcry_mpi_set_ui (ret, - ai_bi); 454 gcry_mpi_set_ui (ret, -ai_bi);
473 gcry_mpi_neg (ret, ret); 455 gcry_mpi_neg (ret, ret);
474 } 456 }
475 return ret; 457 return ret;
@@ -518,13 +500,9 @@ handle_bobs_cryptodata_message (void *cls,
518 "Received %u crypto values from Bob\n", 500 "Received %u crypto values from Bob\n",
519 (unsigned int) contained); 501 (unsigned int) contained);
520 GNUNET_CADET_receive_done (s->channel); 502 GNUNET_CADET_receive_done (s->channel);
521 prod_g_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, 503 prod_g_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, &msg->prod_g_i_b_i);
522 &msg->prod_g_i_b_i); 504 prod_h_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, &msg->prod_h_i_b_i);
523 prod_h_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, 505 s->product = compute_scalar_product (s, prod_g_i_b_i, prod_h_i_b_i);
524 &msg->prod_h_i_b_i);
525 s->product = compute_scalar_product (s,
526 prod_g_i_b_i,
527 prod_h_i_b_i);
528 gcry_mpi_point_release (prod_g_i_b_i); 506 gcry_mpi_point_release (prod_g_i_b_i);
529 gcry_mpi_point_release (prod_h_i_b_i); 507 gcry_mpi_point_release (prod_h_i_b_i);
530 transmit_client_response (s); 508 transmit_client_response (s);
@@ -540,9 +518,7 @@ handle_bobs_cryptodata_message (void *cls,
540 * @param value the `struct GNUNET_SCALARPRODUCT_Element *` 518 * @param value the `struct GNUNET_SCALARPRODUCT_Element *`
541 */ 519 */
542static int 520static int
543copy_element_cb (void *cls, 521copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
544 const struct GNUNET_HashCode *key,
545 void *value)
546{ 522{
547 struct AliceServiceSession *s = cls; 523 struct AliceServiceSession *s = cls;
548 struct GNUNET_SCALARPRODUCT_Element *e = value; 524 struct GNUNET_SCALARPRODUCT_Element *e = value;
@@ -555,8 +531,8 @@ copy_element_cb (void *cls,
555 gcry_mpi_sub_ui (mval, mval, -val); 531 gcry_mpi_sub_ui (mval, mval, -val);
556 else 532 else
557 gcry_mpi_add_ui (mval, mval, val); 533 gcry_mpi_add_ui (mval, mval, val);
558 s->sorted_elements [s->used_element_count].value = mval; 534 s->sorted_elements[s->used_element_count].value = mval;
559 s->sorted_elements [s->used_element_count].key = &e->key; 535 s->sorted_elements[s->used_element_count].key = &e->key;
560 s->used_element_count++; 536 s->used_element_count++;
561 return GNUNET_OK; 537 return GNUNET_OK;
562} 538}
@@ -570,14 +546,12 @@ copy_element_cb (void *cls,
570 * @return -1 for a < b, 0 for a=b, 1 for a > b. 546 * @return -1 for a < b, 0 for a=b, 1 for a > b.
571 */ 547 */
572static int 548static int
573element_cmp (const void *a, 549element_cmp (const void *a, const void *b)
574 const void *b)
575{ 550{
576 const struct MpiElement *ma = a; 551 const struct MpiElement *ma = a;
577 const struct MpiElement *mb = b; 552 const struct MpiElement *mb = b;
578 553
579 return GNUNET_CRYPTO_hash_cmp (ma->key, 554 return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key);
580 mb->key);
581} 555}
582 556
583 557
@@ -585,7 +559,10 @@ element_cmp (const void *a,
585 * Maximum number of elements we can put into a single cryptodata 559 * Maximum number of elements we can put into a single cryptodata
586 * message 560 * message
587 */ 561 */
588#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct EccAliceCryptodataMessage)) / sizeof (struct GNUNET_CRYPTO_EccPoint)) 562#define ELEMENT_CAPACITY \
563 ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \
564 sizeof (struct EccAliceCryptodataMessage)) / \
565 sizeof (struct GNUNET_CRYPTO_EccPoint))
589 566
590 567
591/** 568/**
@@ -606,9 +583,9 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
606 unsigned int off; 583 unsigned int off;
607 unsigned int todo_count; 584 unsigned int todo_count;
608 585
609 s->sorted_elements 586 s->sorted_elements = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size (
610 = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements), 587 s->intersected_elements),
611 struct MpiElement); 588 struct MpiElement);
612 s->used_element_count = 0; 589 s->used_element_count = 0;
613 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, 590 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
614 &copy_element_cb, 591 &copy_element_cb,
@@ -631,11 +608,11 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
631 (unsigned int) todo_count, 608 (unsigned int) todo_count,
632 (unsigned int) s->used_element_count); 609 (unsigned int) s->used_element_count);
633 610
634 e = GNUNET_MQ_msg_extra (msg, 611 e =
635 todo_count * 2 * sizeof (struct GNUNET_CRYPTO_EccPoint), 612 GNUNET_MQ_msg_extra (msg,
636 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA); 613 todo_count * 2 *
637 GNUNET_MQ_env_set_options(e, 614 sizeof (struct GNUNET_CRYPTO_EccPoint),
638 GNUNET_MQ_PREF_RELIABLE); 615 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA);
639 msg->contained_element_count = htonl (todo_count); 616 msg->contained_element_count = htonl (todo_count);
640 payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1]; 617 payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1];
641 r_ia = gcry_mpi_new (0); 618 r_ia = gcry_mpi_new (0);
@@ -647,33 +624,22 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
647 gcry_mpi_point_t h_i; 624 gcry_mpi_point_t h_i;
648 625
649 r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc); 626 r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc);
650 g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, 627 g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_i);
651 r_i);
652 /* r_ia = r_i * a */ 628 /* r_ia = r_i * a */
653 gcry_mpi_mul (r_ia, 629 gcry_mpi_mul (r_ia, r_i, my_privkey);
654 r_i,
655 my_privkey);
656 gcry_mpi_release (r_i); 630 gcry_mpi_release (r_i);
657 /* r_ia_ai = r_ia + a_i */ 631 /* r_ia_ai = r_ia + a_i */
658 gcry_mpi_add (r_ia_ai, 632 gcry_mpi_add (r_ia_ai, r_ia, s->sorted_elements[i].value);
659 r_ia, 633 h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_ia_ai);
660 s->sorted_elements[i].value); 634 GNUNET_CRYPTO_ecc_point_to_bin (edc, g_i, &payload[(i - off) * 2]);
661 h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, 635 GNUNET_CRYPTO_ecc_point_to_bin (edc, h_i, &payload[(i - off) * 2 + 1]);
662 r_ia_ai);
663 GNUNET_CRYPTO_ecc_point_to_bin (edc,
664 g_i,
665 &payload[(i - off) * 2]);
666 GNUNET_CRYPTO_ecc_point_to_bin (edc,
667 h_i,
668 &payload[(i - off) * 2 + 1]);
669 gcry_mpi_point_release (g_i); 636 gcry_mpi_point_release (g_i);
670 gcry_mpi_point_release (h_i); 637 gcry_mpi_point_release (h_i);
671 } 638 }
672 gcry_mpi_release (r_ia); 639 gcry_mpi_release (r_ia);
673 gcry_mpi_release (r_ia_ai); 640 gcry_mpi_release (r_ia_ai);
674 off += todo_count; 641 off += todo_count;
675 GNUNET_MQ_send (s->cadet_mq, 642 GNUNET_MQ_send (s->cadet_mq, e);
676 e);
677 } 643 }
678} 644}
679 645
@@ -708,10 +674,11 @@ cb_intersection_element_removed (void *cls,
708 "Intersection removed element with key %s and value %lld\n", 674 "Intersection removed element with key %s and value %lld\n",
709 GNUNET_h2s (&se->key), 675 GNUNET_h2s (&se->key),
710 (long long) GNUNET_ntohll (se->value)); 676 (long long) GNUNET_ntohll (se->value));
711 GNUNET_assert (GNUNET_YES == 677 GNUNET_assert (
712 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, 678 GNUNET_YES ==
713 element->data, 679 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
714 se)); 680 element->data,
681 se));
715 GNUNET_free (se); 682 GNUNET_free (se);
716 return; 683 return;
717 case GNUNET_SET_STATUS_DONE: 684 case GNUNET_SET_STATUS_DONE:
@@ -729,8 +696,7 @@ cb_intersection_element_removed (void *cls,
729 return; 696 return;
730 case GNUNET_SET_STATUS_FAILURE: 697 case GNUNET_SET_STATUS_FAILURE:
731 /* unhandled status code */ 698 /* unhandled status code */
732 LOG (GNUNET_ERROR_TYPE_DEBUG, 699 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
733 "Set intersection failed!\n");
734 if (NULL != s->intersection_listen) 700 if (NULL != s->intersection_listen)
735 { 701 {
736 GNUNET_SET_listen_cancel (s->intersection_listen); 702 GNUNET_SET_listen_cancel (s->intersection_listen);
@@ -778,18 +744,16 @@ cb_intersection_request_alice (void *cls,
778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
779 "Received intersection request from %s!\n", 745 "Received intersection request from %s!\n",
780 GNUNET_i2s (other_peer)); 746 GNUNET_i2s (other_peer));
781 if (0 != GNUNET_memcmp (other_peer, 747 if (0 != GNUNET_memcmp (other_peer, &s->peer))
782 &s->peer))
783 { 748 {
784 GNUNET_break_op (0); 749 GNUNET_break_op (0);
785 return; 750 return;
786 } 751 }
787 s->intersection_op 752 s->intersection_op = GNUNET_SET_accept (request,
788 = GNUNET_SET_accept (request, 753 GNUNET_SET_RESULT_REMOVED,
789 GNUNET_SET_RESULT_REMOVED, 754 (struct GNUNET_SET_Option[]){{0}},
790 (struct GNUNET_SET_Option[]) {{ 0 }}, 755 &cb_intersection_element_removed,
791 &cb_intersection_element_removed, 756 s);
792 s);
793 if (NULL == s->intersection_op) 757 if (NULL == s->intersection_op)
794 { 758 {
795 GNUNET_break (0); 759 GNUNET_break (0);
@@ -797,9 +761,7 @@ cb_intersection_request_alice (void *cls,
797 prepare_client_end_notification (s); 761 prepare_client_end_notification (s);
798 return; 762 return;
799 } 763 }
800 if (GNUNET_OK != 764 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set))
801 GNUNET_SET_commit (s->intersection_op,
802 s->intersection_set))
803 { 765 {
804 GNUNET_break (0); 766 GNUNET_break (0);
805 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 767 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -817,13 +779,12 @@ cb_intersection_request_alice (void *cls,
817static void 779static void
818client_request_complete_alice (struct AliceServiceSession *s) 780client_request_complete_alice (struct AliceServiceSession *s)
819{ 781{
820 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 782 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
821 GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message, 783 {GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message,
822 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, 784 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA,
823 struct EccBobCryptodataMessage, 785 struct EccBobCryptodataMessage,
824 s), 786 s),
825 GNUNET_MQ_handler_end () 787 GNUNET_MQ_handler_end ()};
826 };
827 struct EccServiceRequestMessage *msg; 788 struct EccServiceRequestMessage *msg;
828 struct GNUNET_MQ_Envelope *e; 789 struct GNUNET_MQ_Envelope *e;
829 struct GNUNET_HashCode set_sid; 790 struct GNUNET_HashCode set_sid;
@@ -834,14 +795,13 @@ client_request_complete_alice (struct AliceServiceSession *s)
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
835 "Creating new channel for session with key %s.\n", 796 "Creating new channel for session with key %s.\n",
836 GNUNET_h2s (&s->session_id)); 797 GNUNET_h2s (&s->session_id));
837 s->channel 798 s->channel = GNUNET_CADET_channel_create (my_cadet,
838 = GNUNET_CADET_channel_create (my_cadet, 799 s,
839 s, 800 &s->peer,
840 &s->peer, 801 &s->session_id,
841 &s->session_id, 802 NULL,
842 NULL, 803 &cb_channel_destruction,
843 &cb_channel_destruction, 804 cadet_handlers);
844 cadet_handlers);
845 if (NULL == s->channel) 805 if (NULL == s->channel)
846 { 806 {
847 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 807 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -849,12 +809,11 @@ client_request_complete_alice (struct AliceServiceSession *s)
849 return; 809 return;
850 } 810 }
851 s->cadet_mq = GNUNET_CADET_get_mq (s->channel); 811 s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
852 s->intersection_listen 812 s->intersection_listen = GNUNET_SET_listen (cfg,
853 = GNUNET_SET_listen (cfg, 813 GNUNET_SET_OPERATION_INTERSECTION,
854 GNUNET_SET_OPERATION_INTERSECTION, 814 &set_sid,
855 &set_sid, 815 &cb_intersection_request_alice,
856 &cb_intersection_request_alice, 816 s);
857 s);
858 if (NULL == s->intersection_listen) 817 if (NULL == s->intersection_listen)
859 { 818 {
860 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 819 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -864,13 +823,12 @@ client_request_complete_alice (struct AliceServiceSession *s)
864 return; 823 return;
865 } 824 }
866 825
867 e = GNUNET_MQ_msg (msg, 826 e =
868 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION); 827 GNUNET_MQ_msg (msg,
869 GNUNET_MQ_env_set_options(e, 828 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION);
870 GNUNET_MQ_PREF_RELIABLE); 829 GNUNET_MQ_env_set_options (e, GNUNET_MQ_PRIO_CRITICAL_CONTROL);
871 msg->session_id = s->session_id; 830 msg->session_id = s->session_id;
872 GNUNET_MQ_send (s->cadet_mq, 831 GNUNET_MQ_send (s->cadet_mq, e);
873 e);
874} 832}
875 833
876 834
@@ -883,8 +841,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
883 * @return #GNUNET_OK if @a msg is well-formed 841 * @return #GNUNET_OK if @a msg is well-formed
884 */ 842 */
885static int 843static int
886check_alice_client_message_multipart (void *cls, 844check_alice_client_message_multipart (
887 const struct ComputationBobCryptodataMultipartMessage *msg) 845 void *cls,
846 const struct ComputationBobCryptodataMultipartMessage *msg)
888{ 847{
889 struct AliceServiceSession *s = cls; 848 struct AliceServiceSession *s = cls;
890 uint32_t contained_count; 849 uint32_t contained_count;
@@ -892,11 +851,12 @@ check_alice_client_message_multipart (void *cls,
892 851
893 msize = ntohs (msg->header.size); 852 msize = ntohs (msg->header.size);
894 contained_count = ntohl (msg->element_count_contained); 853 contained_count = ntohl (msg->element_count_contained);
895 if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + 854 if ((msize !=
896 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || 855 (sizeof (struct ComputationBobCryptodataMultipartMessage) +
897 (0 == contained_count) || 856 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
898 (s->total == s->client_received_element_count) || 857 (0 == contained_count) ||
899 (s->total < s->client_received_element_count + contained_count) ) 858 (s->total == s->client_received_element_count) ||
859 (s->total < s->client_received_element_count + contained_count))
900 { 860 {
901 GNUNET_break_op (0); 861 GNUNET_break_op (0);
902 return GNUNET_SYSERR; 862 return GNUNET_SYSERR;
@@ -913,8 +873,9 @@ check_alice_client_message_multipart (void *cls,
913 * @param msg the actual message 873 * @param msg the actual message
914 */ 874 */
915static void 875static void
916handle_alice_client_message_multipart (void *cls, 876handle_alice_client_message_multipart (
917 const struct ComputationBobCryptodataMultipartMessage *msg) 877 void *cls,
878 const struct ComputationBobCryptodataMultipartMessage *msg)
918{ 879{
919 struct AliceServiceSession *s = cls; 880 struct AliceServiceSession *s = cls;
920 uint32_t contained_count; 881 uint32_t contained_count;
@@ -929,13 +890,13 @@ handle_alice_client_message_multipart (void *cls,
929 { 890 {
930 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 891 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
931 GNUNET_memcpy (elem, 892 GNUNET_memcpy (elem,
932 &elements[i], 893 &elements[i],
933 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 894 sizeof (struct GNUNET_SCALARPRODUCT_Element));
934 if (GNUNET_SYSERR == 895 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
935 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 896 s->intersected_elements,
936 &elem->key, 897 &elem->key,
937 elem, 898 elem,
938 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 899 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
939 { 900 {
940 GNUNET_break (0); 901 GNUNET_break (0);
941 GNUNET_free (elem); 902 GNUNET_free (elem);
@@ -944,9 +905,7 @@ handle_alice_client_message_multipart (void *cls,
944 set_elem.data = &elem->key; 905 set_elem.data = &elem->key;
945 set_elem.size = sizeof (elem->key); 906 set_elem.size = sizeof (elem->key);
946 set_elem.element_type = 0; 907 set_elem.element_type = 0;
947 GNUNET_SET_add_element (s->intersection_set, 908 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
948 &set_elem,
949 NULL, NULL);
950 s->used_element_count++; 909 s->used_element_count++;
951 } 910 }
952 GNUNET_SERVICE_client_continue (s->client); 911 GNUNET_SERVICE_client_continue (s->client);
@@ -957,8 +916,7 @@ handle_alice_client_message_multipart (void *cls,
957 "Received client multipart data, waiting for more!\n"); 916 "Received client multipart data, waiting for more!\n");
958 return; 917 return;
959 } 918 }
960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n");
961 "Launching computation\n");
962 client_request_complete_alice (s); 920 client_request_complete_alice (s);
963} 921}
964 922
@@ -973,7 +931,7 @@ handle_alice_client_message_multipart (void *cls,
973 */ 931 */
974static int 932static int
975check_alice_client_message (void *cls, 933check_alice_client_message (void *cls,
976 const struct AliceComputationMessage *msg) 934 const struct AliceComputationMessage *msg)
977{ 935{
978 struct AliceServiceSession *s = cls; 936 struct AliceServiceSession *s = cls;
979 uint16_t msize; 937 uint16_t msize;
@@ -990,10 +948,10 @@ check_alice_client_message (void *cls,
990 msize = ntohs (msg->header.size); 948 msize = ntohs (msg->header.size);
991 total_count = ntohl (msg->element_count_total); 949 total_count = ntohl (msg->element_count_total);
992 contained_count = ntohl (msg->element_count_contained); 950 contained_count = ntohl (msg->element_count_contained);
993 if ( (0 == total_count) || 951 if ((0 == total_count) || (0 == contained_count) ||
994 (0 == contained_count) || 952 (msize !=
995 (msize != (sizeof (struct AliceComputationMessage) + 953 (sizeof (struct AliceComputationMessage) +
996 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) 954 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))))
997 { 955 {
998 GNUNET_break_op (0); 956 GNUNET_break_op (0);
999 return GNUNET_SYSERR; 957 return GNUNET_SYSERR;
@@ -1011,7 +969,7 @@ check_alice_client_message (void *cls,
1011 */ 969 */
1012static void 970static void
1013handle_alice_client_message (void *cls, 971handle_alice_client_message (void *cls,
1014 const struct AliceComputationMessage *msg) 972 const struct AliceComputationMessage *msg)
1015{ 973{
1016 struct AliceServiceSession *s = cls; 974 struct AliceServiceSession *s = cls;
1017 uint32_t contained_count; 975 uint32_t contained_count;
@@ -1028,23 +986,23 @@ handle_alice_client_message (void *cls,
1028 s->client_received_element_count = contained_count; 986 s->client_received_element_count = contained_count;
1029 s->session_id = msg->session_key; 987 s->session_id = msg->session_key;
1030 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 988 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
1031 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, 989 s->intersected_elements =
1032 GNUNET_YES); 990 GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES);
1033 s->intersection_set = GNUNET_SET_create (cfg, 991 s->intersection_set =
1034 GNUNET_SET_OPERATION_INTERSECTION); 992 GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
1035 for (uint32_t i = 0; i < contained_count; i++) 993 for (uint32_t i = 0; i < contained_count; i++)
1036 { 994 {
1037 if (0 == GNUNET_ntohll (elements[i].value)) 995 if (0 == GNUNET_ntohll (elements[i].value))
1038 continue; 996 continue;
1039 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 997 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1040 GNUNET_memcpy (elem, 998 GNUNET_memcpy (elem,
1041 &elements[i], 999 &elements[i],
1042 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1000 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1043 if (GNUNET_SYSERR == 1001 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1044 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1002 s->intersected_elements,
1045 &elem->key, 1003 &elem->key,
1046 elem, 1004 elem,
1047 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1005 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1048 { 1006 {
1049 /* element with same key encountered twice! */ 1007 /* element with same key encountered twice! */
1050 GNUNET_break (0); 1008 GNUNET_break (0);
@@ -1054,9 +1012,7 @@ handle_alice_client_message (void *cls,
1054 set_elem.data = &elem->key; 1012 set_elem.data = &elem->key;
1055 set_elem.size = sizeof (elem->key); 1013 set_elem.size = sizeof (elem->key);
1056 set_elem.element_type = 0; 1014 set_elem.element_type = 0;
1057 GNUNET_SET_add_element (s->intersection_set, 1015 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1058 &set_elem,
1059 NULL, NULL);
1060 s->used_element_count++; 1016 s->used_element_count++;
1061 } 1017 }
1062 GNUNET_SERVICE_client_continue (s->client); 1018 GNUNET_SERVICE_client_continue (s->client);
@@ -1067,8 +1023,7 @@ handle_alice_client_message (void *cls,
1067 "Received partial client request, waiting for more!\n"); 1023 "Received partial client request, waiting for more!\n");
1068 return; 1024 return;
1069 } 1025 }
1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n");
1071 "Launching computation\n");
1072 client_request_complete_alice (s); 1027 client_request_complete_alice (s);
1073} 1028}
1074 1029
@@ -1082,8 +1037,7 @@ handle_alice_client_message (void *cls,
1082static void 1037static void
1083shutdown_task (void *cls) 1038shutdown_task (void *cls)
1084{ 1039{
1085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n");
1086 "Shutting down, initiating cleanup.\n");
1087 // FIXME: we have to cut our connections to CADET first! 1041 // FIXME: we have to cut our connections to CADET first!
1088 if (NULL != my_cadet) 1042 if (NULL != my_cadet)
1089 { 1043 {
@@ -1110,8 +1064,8 @@ shutdown_task (void *cls)
1110 */ 1064 */
1111static void * 1065static void *
1112client_connect_cb (void *cls, 1066client_connect_cb (void *cls,
1113 struct GNUNET_SERVICE_Client *client, 1067 struct GNUNET_SERVICE_Client *client,
1114 struct GNUNET_MQ_Handle *mq) 1068 struct GNUNET_MQ_Handle *mq)
1115{ 1069{
1116 struct AliceServiceSession *s; 1070 struct AliceServiceSession *s;
1117 1071
@@ -1134,8 +1088,8 @@ client_connect_cb (void *cls,
1134 */ 1088 */
1135static void 1089static void
1136client_disconnect_cb (void *cls, 1090client_disconnect_cb (void *cls,
1137 struct GNUNET_SERVICE_Client *client, 1091 struct GNUNET_SERVICE_Client *client,
1138 void *app_cls) 1092 void *app_cls)
1139{ 1093{
1140 struct AliceServiceSession *s = app_cls; 1094 struct AliceServiceSession *s = app_cls;
1141 1095
@@ -1161,45 +1115,40 @@ run (void *cls,
1161 struct GNUNET_SERVICE_Handle *service) 1115 struct GNUNET_SERVICE_Handle *service)
1162{ 1116{
1163 cfg = c; 1117 cfg = c;
1164 edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, 1118 edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, MAX_RAM);
1165 MAX_RAM);
1166 /* Select a random 'a' value for Alice */ 1119 /* Select a random 'a' value for Alice */
1167 GNUNET_CRYPTO_ecc_rnd_mpi (edc, 1120 GNUNET_CRYPTO_ecc_rnd_mpi (edc, &my_privkey, &my_privkey_inv);
1168 &my_privkey,
1169 &my_privkey_inv);
1170 my_cadet = GNUNET_CADET_connect (cfg); 1121 my_cadet = GNUNET_CADET_connect (cfg);
1171 if (NULL == my_cadet) 1122 if (NULL == my_cadet)
1172 { 1123 {
1173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n"));
1174 _("Connect to CADET failed\n"));
1175 GNUNET_SCHEDULER_shutdown (); 1125 GNUNET_SCHEDULER_shutdown ();
1176 return; 1126 return;
1177 } 1127 }
1178 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1128 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1179 NULL);
1180
1181} 1129}
1182 1130
1183 1131
1184/** 1132/**
1185 * Define "main" method using service macro. 1133 * Define "main" method using service macro.
1186 */ 1134 */
1187GNUNET_SERVICE_MAIN 1135GNUNET_SERVICE_MAIN (
1188("scalarproduct-alice", 1136 "scalarproduct-alice",
1189 GNUNET_SERVICE_OPTION_NONE, 1137 GNUNET_SERVICE_OPTION_NONE,
1190 &run, 1138 &run,
1191 &client_connect_cb, 1139 &client_connect_cb,
1192 &client_disconnect_cb, 1140 &client_disconnect_cb,
1193 NULL, 1141 NULL,
1194 GNUNET_MQ_hd_var_size (alice_client_message, 1142 GNUNET_MQ_hd_var_size (alice_client_message,
1195 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, 1143 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
1196 struct AliceComputationMessage, 1144 struct AliceComputationMessage,
1197 NULL), 1145 NULL),
1198 GNUNET_MQ_hd_var_size (alice_client_message_multipart, 1146 GNUNET_MQ_hd_var_size (
1199 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, 1147 alice_client_message_multipart,
1200 struct ComputationBobCryptodataMultipartMessage, 1148 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
1201 NULL), 1149 struct ComputationBobCryptodataMultipartMessage,
1202 GNUNET_MQ_handler_end ()); 1150 NULL),
1151 GNUNET_MQ_handler_end ());
1203 1152
1204 1153
1205/* end of gnunet-service-scalarproduct-ecc_alice.c */ 1154/* end of gnunet-service-scalarproduct-ecc_alice.c */
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
index 18c5cc49a..e138876f5 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.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
@@ -36,7 +36,8 @@
36#include "scalarproduct.h" 36#include "scalarproduct.h"
37#include "gnunet-service-scalarproduct.h" 37#include "gnunet-service-scalarproduct.h"
38 38
39#define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) 39#define LOG(kind, ...) \
40 GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__)
40 41
41/** 42/**
42 * An encrypted element key-value pair. 43 * An encrypted element key-value pair.
@@ -185,7 +186,6 @@ struct AliceServiceSession
185 * doing harm. 186 * doing harm.
186 */ 187 */
187 int in_destroy; 188 int in_destroy;
188
189}; 189};
190 190
191 191
@@ -224,9 +224,7 @@ static struct GNUNET_CADET_Handle *my_cadet;
224 * @return #GNUNET_OK (continue to iterate) 224 * @return #GNUNET_OK (continue to iterate)
225 */ 225 */
226static int 226static int
227free_element_cb (void *cls, 227free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
228 const struct GNUNET_HashCode *key,
229 void *value)
230{ 228{
231 struct GNUNET_SCALARPRODUCT_Element *e = value; 229 struct GNUNET_SCALARPRODUCT_Element *e = value;
232 230
@@ -283,7 +281,7 @@ destroy_service_session (struct AliceServiceSession *s)
283 } 281 }
284 if (NULL != s->sorted_elements) 282 if (NULL != s->sorted_elements)
285 { 283 {
286 for (unsigned int i=0;i<s->used_element_count;i++) 284 for (unsigned int i = 0; i < s->used_element_count; i++)
287 gcry_mpi_release (s->sorted_elements[i].value); 285 gcry_mpi_release (s->sorted_elements[i].value);
288 GNUNET_free (s->sorted_elements); 286 GNUNET_free (s->sorted_elements);
289 s->sorted_elements = NULL; 287 s->sorted_elements = NULL;
@@ -321,16 +319,15 @@ prepare_client_end_notification (struct AliceServiceSession *session)
321 319
322 if (NULL == session->client_mq) 320 if (NULL == session->client_mq)
323 return; /* no client left to be notified */ 321 return; /* no client left to be notified */
324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 322 GNUNET_log (
325 "Sending session-end notification with status %d to client for session %s\n", 323 GNUNET_ERROR_TYPE_DEBUG,
326 session->status, 324 "Sending session-end notification with status %d to client for session %s\n",
327 GNUNET_h2s (&session->session_id)); 325 session->status,
328 e = GNUNET_MQ_msg (msg, 326 GNUNET_h2s (&session->session_id));
329 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 327 e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
330 msg->product_length = htonl (0); 328 msg->product_length = htonl (0);
331 msg->status = htonl (session->status); 329 msg->status = htonl (session->status);
332 GNUNET_MQ_send (session->client_mq, 330 GNUNET_MQ_send (session->client_mq, e);
333 e);
334} 331}
335 332
336 333
@@ -363,9 +360,7 @@ transmit_client_response (struct AliceServiceSession *s)
363 if (0 > sign) 360 if (0 > sign)
364 { 361 {
365 range = -1; 362 range = -1;
366 gcry_mpi_sub (value, 363 gcry_mpi_sub (value, value, s->product);
367 value,
368 s->product);
369 } 364 }
370 else if (0 < sign) 365 else if (0 < sign)
371 { 366 {
@@ -380,15 +375,12 @@ transmit_client_response (struct AliceServiceSession *s)
380 gcry_mpi_release (s->product); 375 gcry_mpi_release (s->product);
381 s->product = NULL; 376 s->product = NULL;
382 377
383 if ( (0 != range) && 378 if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD,
384 (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, 379 &product_exported,
385 &product_exported, 380 &product_length,
386 &product_length, 381 value))))
387 value))))
388 { 382 {
389 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, 383 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
390 "gcry_mpi_scan",
391 rc);
392 prepare_client_end_notification (s); 384 prepare_client_end_notification (s);
393 return; 385 return;
394 } 386 }
@@ -401,20 +393,16 @@ transmit_client_response (struct AliceServiceSession *s)
401 msg->product_length = htonl (product_length); 393 msg->product_length = htonl (product_length);
402 if (NULL != product_exported) 394 if (NULL != product_exported)
403 { 395 {
404 GNUNET_memcpy (&msg[1], 396 GNUNET_memcpy (&msg[1], product_exported, product_length);
405 product_exported,
406 product_length);
407 GNUNET_free (product_exported); 397 GNUNET_free (product_exported);
408 } 398 }
409 GNUNET_MQ_send (s->client_mq, 399 GNUNET_MQ_send (s->client_mq, e);
410 e);
411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
412 "Sent result to client, session %s has ended!\n", 401 "Sent result to client, session %s has ended!\n",
413 GNUNET_h2s (&s->session_id)); 402 GNUNET_h2s (&s->session_id));
414} 403}
415 404
416 405
417
418/** 406/**
419 * Function called whenever a channel is destroyed. Should clean up 407 * Function called whenever a channel is destroyed. Should clean up
420 * any associated state. 408 * any associated state.
@@ -425,8 +413,7 @@ transmit_client_response (struct AliceServiceSession *s)
425 * @param channel connection to the other end (henceforth invalid) 413 * @param channel connection to the other end (henceforth invalid)
426 */ 414 */
427static void 415static void
428cb_channel_destruction (void *cls, 416cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel)
429 const struct GNUNET_CADET_Channel *channel)
430{ 417{
431 struct AliceServiceSession *s = cls; 418 struct AliceServiceSession *s = cls;
432 419
@@ -479,8 +466,7 @@ compute_square_sum_mpi_elements (const struct MpiElement *vector,
479 * @return an MPI value containing the calculated sum, never NULL 466 * @return an MPI value containing the calculated sum, never NULL
480 */ 467 */
481static gcry_mpi_t 468static gcry_mpi_t
482compute_square_sum (const gcry_mpi_t *vector, 469compute_square_sum (const gcry_mpi_t *vector, uint32_t length)
483 uint32_t length)
484{ 470{
485 gcry_mpi_t elem; 471 gcry_mpi_t elem;
486 gcry_mpi_t sum; 472 gcry_mpi_t sum;
@@ -531,28 +517,19 @@ compute_scalar_product (struct AliceServiceSession *session)
531 &my_pubkey, 517 &my_pubkey,
532 &session->r[i], 518 &session->r[i],
533 r[i]); 519 r[i]);
534 gcry_mpi_sub (r[i], 520 gcry_mpi_sub (r[i], r[i], my_offset);
535 r[i], 521 gcry_mpi_sub (r[i], r[i], my_offset);
536 my_offset);
537 gcry_mpi_sub (r[i],
538 r[i],
539 my_offset);
540 r_prime[i] = gcry_mpi_new (0); 522 r_prime[i] = gcry_mpi_new (0);
541 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 523 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
542 &my_pubkey, 524 &my_pubkey,
543 &session->r_prime[i], 525 &session->r_prime[i],
544 r_prime[i]); 526 r_prime[i]);
545 gcry_mpi_sub (r_prime[i], 527 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset);
546 r_prime[i], 528 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset);
547 my_offset);
548 gcry_mpi_sub (r_prime[i],
549 r_prime[i],
550 my_offset);
551 } 529 }
552 530
553 // calculate t = sum(ai) 531 // calculate t = sum(ai)
554 t = compute_square_sum_mpi_elements (session->sorted_elements, 532 t = compute_square_sum_mpi_elements (session->sorted_elements, count);
555 count);
556 // calculate U 533 // calculate U
557 u = gcry_mpi_new (0); 534 u = gcry_mpi_new (0);
558 tmp = compute_square_sum (r, count); 535 tmp = compute_square_sum (r, count);
@@ -570,10 +547,7 @@ compute_scalar_product (struct AliceServiceSession *session)
570 GNUNET_assert (s_prime = gcry_mpi_new (0)); 547 GNUNET_assert (s_prime = gcry_mpi_new (0));
571 548
572 // compute P 549 // compute P
573 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 550 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, &session->s, s);
574 &my_pubkey,
575 &session->s,
576 s);
577 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 551 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
578 &my_pubkey, 552 &my_pubkey,
579 &session->s_prime, 553 &session->s_prime,
@@ -627,8 +601,9 @@ compute_scalar_product (struct AliceServiceSession *session)
627 * #GNUNET_SYSERR to close it (signal serious error) 601 * #GNUNET_SYSERR to close it (signal serious error)
628 */ 602 */
629static int 603static int
630check_bobs_cryptodata_multipart (void *cls, 604check_bobs_cryptodata_multipart (
631 const struct BobCryptodataMultipartMessage *msg) 605 void *cls,
606 const struct BobCryptodataMultipartMessage *msg)
632{ 607{
633 struct AliceServiceSession *s = cls; 608 struct AliceServiceSession *s = cls;
634 uint32_t contained; 609 uint32_t contained;
@@ -637,10 +612,11 @@ check_bobs_cryptodata_multipart (void *cls,
637 612
638 msg_size = ntohs (msg->header.size); 613 msg_size = ntohs (msg->header.size);
639 contained = ntohl (msg->contained_element_count); 614 contained = ntohl (msg->contained_element_count);
640 required_size = sizeof (struct BobCryptodataMultipartMessage) 615 required_size =
641 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 616 sizeof (struct BobCryptodataMultipartMessage) +
642 if ( (required_size != msg_size) || 617 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
643 (s->cadet_received_element_count + contained > s->used_element_count) ) 618 if ((required_size != msg_size) ||
619 (s->cadet_received_element_count + contained > s->used_element_count))
644 { 620 {
645 GNUNET_break (0); 621 GNUNET_break (0);
646 return GNUNET_SYSERR; 622 return GNUNET_SYSERR;
@@ -656,8 +632,9 @@ check_bobs_cryptodata_multipart (void *cls,
656 * @param msg the actual message 632 * @param msg the actual message
657 */ 633 */
658static void 634static void
659handle_bobs_cryptodata_multipart (void *cls, 635handle_bobs_cryptodata_multipart (
660 const struct BobCryptodataMultipartMessage *msg) 636 void *cls,
637 const struct BobCryptodataMultipartMessage *msg)
661{ 638{
662 struct AliceServiceSession *s = cls; 639 struct AliceServiceSession *s = cls;
663 const struct GNUNET_CRYPTO_PaillierCiphertext *payload; 640 const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
@@ -710,12 +687,12 @@ check_bobs_cryptodata_message (void *cls,
710 687
711 msg_size = ntohs (msg->header.size); 688 msg_size = ntohs (msg->header.size);
712 contained = ntohl (msg->contained_element_count); 689 contained = ntohl (msg->contained_element_count);
713 required_size = sizeof (struct BobCryptodataMessage) 690 required_size =
714 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) 691 sizeof (struct BobCryptodataMessage) +
715 + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 692 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) +
716 if ( (msg_size != required_size) || 693 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
717 (contained > UINT16_MAX) || 694 if ((msg_size != required_size) || (contained > UINT16_MAX) ||
718 (s->used_element_count < contained) ) 695 (s->used_element_count < contained))
719 { 696 {
720 GNUNET_break_op (0); 697 GNUNET_break_op (0);
721 return GNUNET_SYSERR; 698 return GNUNET_SYSERR;
@@ -800,9 +777,7 @@ handle_bobs_cryptodata_message (void *cls,
800 * @param value the `struct GNUNET_SCALARPRODUCT_Element *` 777 * @param value the `struct GNUNET_SCALARPRODUCT_Element *`
801 */ 778 */
802static int 779static int
803copy_element_cb (void *cls, 780copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
804 const struct GNUNET_HashCode *key,
805 void *value)
806{ 781{
807 struct AliceServiceSession *s = cls; 782 struct AliceServiceSession *s = cls;
808 struct GNUNET_SCALARPRODUCT_Element *e = value; 783 struct GNUNET_SCALARPRODUCT_Element *e = value;
@@ -815,8 +790,8 @@ copy_element_cb (void *cls,
815 gcry_mpi_sub_ui (mval, mval, -val); 790 gcry_mpi_sub_ui (mval, mval, -val);
816 else 791 else
817 gcry_mpi_add_ui (mval, mval, val); 792 gcry_mpi_add_ui (mval, mval, val);
818 s->sorted_elements [s->used_element_count].value = mval; 793 s->sorted_elements[s->used_element_count].value = mval;
819 s->sorted_elements [s->used_element_count].key = &e->key; 794 s->sorted_elements[s->used_element_count].key = &e->key;
820 s->used_element_count++; 795 s->used_element_count++;
821 return GNUNET_OK; 796 return GNUNET_OK;
822} 797}
@@ -830,14 +805,12 @@ copy_element_cb (void *cls,
830 * @return -1 for a < b, 0 for a=b, 1 for a > b. 805 * @return -1 for a < b, 0 for a=b, 1 for a > b.
831 */ 806 */
832static int 807static int
833element_cmp (const void *a, 808element_cmp (const void *a, const void *b)
834 const void *b)
835{ 809{
836 const struct MpiElement *ma = a; 810 const struct MpiElement *ma = a;
837 const struct MpiElement *mb = b; 811 const struct MpiElement *mb = b;
838 812
839 return GNUNET_CRYPTO_hash_cmp (ma->key, 813 return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key);
840 mb->key);
841} 814}
842 815
843 816
@@ -845,7 +818,10 @@ element_cmp (const void *a,
845 * Maximum number of elements we can put into a single cryptodata 818 * Maximum number of elements we can put into a single cryptodata
846 * message 819 * message
847 */ 820 */
848#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct AliceCryptodataMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) 821#define ELEMENT_CAPACITY \
822 ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \
823 sizeof (struct AliceCryptodataMessage)) / \
824 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext))
849 825
850 826
851/** 827/**
@@ -865,9 +841,9 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
865 gcry_mpi_t a; 841 gcry_mpi_t a;
866 uint32_t off; 842 uint32_t off;
867 843
868 s->sorted_elements 844 s->sorted_elements = GNUNET_malloc (
869 = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * 845 GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) *
870 sizeof (struct MpiElement)); 846 sizeof (struct MpiElement));
871 s->used_element_count = 0; 847 s->used_element_count = 0;
872 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, 848 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
873 &copy_element_cb, 849 &copy_element_cb,
@@ -890,29 +866,24 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
890 (unsigned int) todo_count, 866 (unsigned int) todo_count,
891 (unsigned int) s->used_element_count); 867 (unsigned int) s->used_element_count);
892 868
893 e = GNUNET_MQ_msg_extra (msg, 869 e =
894 todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), 870 GNUNET_MQ_msg_extra (msg,
895 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); 871 todo_count *
896 GNUNET_MQ_env_set_options(e, 872 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext),
897 GNUNET_MQ_PREF_RELIABLE); 873 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA);
898 msg->contained_element_count = htonl (todo_count); 874 msg->contained_element_count = htonl (todo_count);
899 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 875 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
900 a = gcry_mpi_new (0); 876 a = gcry_mpi_new (0);
901 for (i = off; i < off + todo_count; i++) 877 for (i = off; i < off + todo_count; i++)
902 { 878 {
903 gcry_mpi_add (a, 879 gcry_mpi_add (a, s->sorted_elements[i].value, my_offset);
904 s->sorted_elements[i].value, 880 GNUNET_assert (
905 my_offset); 881 3 ==
906 GNUNET_assert (3 == 882 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - off]));
907 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey,
908 a,
909 3,
910 &payload[i - off]));
911 } 883 }
912 gcry_mpi_release (a); 884 gcry_mpi_release (a);
913 off += todo_count; 885 off += todo_count;
914 GNUNET_MQ_send (s->cadet_mq, 886 GNUNET_MQ_send (s->cadet_mq, e);
915 e);
916 } 887 }
917} 888}
918 889
@@ -947,10 +918,11 @@ cb_intersection_element_removed (void *cls,
947 "Intersection removed element with key %s and value %lld\n", 918 "Intersection removed element with key %s and value %lld\n",
948 GNUNET_h2s (&se->key), 919 GNUNET_h2s (&se->key),
949 (long long) GNUNET_ntohll (se->value)); 920 (long long) GNUNET_ntohll (se->value));
950 GNUNET_assert (GNUNET_YES == 921 GNUNET_assert (
951 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, 922 GNUNET_YES ==
952 element->data, 923 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
953 se)); 924 element->data,
925 se));
954 GNUNET_free (se); 926 GNUNET_free (se);
955 return; 927 return;
956 case GNUNET_SET_STATUS_DONE: 928 case GNUNET_SET_STATUS_DONE:
@@ -968,8 +940,7 @@ cb_intersection_element_removed (void *cls,
968 return; 940 return;
969 case GNUNET_SET_STATUS_FAILURE: 941 case GNUNET_SET_STATUS_FAILURE:
970 /* unhandled status code */ 942 /* unhandled status code */
971 LOG (GNUNET_ERROR_TYPE_DEBUG, 943 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
972 "Set intersection failed!\n");
973 if (NULL != s->intersection_listen) 944 if (NULL != s->intersection_listen)
974 { 945 {
975 GNUNET_SET_listen_cancel (s->intersection_listen); 946 GNUNET_SET_listen_cancel (s->intersection_listen);
@@ -1014,18 +985,16 @@ cb_intersection_request_alice (void *cls,
1014{ 985{
1015 struct AliceServiceSession *s = cls; 986 struct AliceServiceSession *s = cls;
1016 987
1017 if (0 != GNUNET_memcmp (other_peer, 988 if (0 != GNUNET_memcmp (other_peer, &s->peer))
1018 &s->peer))
1019 { 989 {
1020 GNUNET_break_op (0); 990 GNUNET_break_op (0);
1021 return; 991 return;
1022 } 992 }
1023 s->intersection_op 993 s->intersection_op = GNUNET_SET_accept (request,
1024 = GNUNET_SET_accept (request, 994 GNUNET_SET_RESULT_REMOVED,
1025 GNUNET_SET_RESULT_REMOVED, 995 (struct GNUNET_SET_Option[]){{0}},
1026 (struct GNUNET_SET_Option[]) {{ 0 }}, 996 &cb_intersection_element_removed,
1027 &cb_intersection_element_removed, 997 s);
1028 s);
1029 if (NULL == s->intersection_op) 998 if (NULL == s->intersection_op)
1030 { 999 {
1031 GNUNET_break (0); 1000 GNUNET_break (0);
@@ -1033,9 +1002,7 @@ cb_intersection_request_alice (void *cls,
1033 prepare_client_end_notification (s); 1002 prepare_client_end_notification (s);
1034 return; 1003 return;
1035 } 1004 }
1036 if (GNUNET_OK != 1005 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set))
1037 GNUNET_SET_commit (s->intersection_op,
1038 s->intersection_set))
1039 { 1006 {
1040 GNUNET_break (0); 1007 GNUNET_break (0);
1041 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1008 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1053,31 +1020,30 @@ cb_intersection_request_alice (void *cls,
1053static void 1020static void
1054client_request_complete_alice (struct AliceServiceSession *s) 1021client_request_complete_alice (struct AliceServiceSession *s)
1055{ 1022{
1056 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1023 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1057 GNUNET_MQ_hd_var_size (bobs_cryptodata_message, 1024 {GNUNET_MQ_hd_var_size (bobs_cryptodata_message,
1058 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, 1025 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
1059 struct BobCryptodataMessage, 1026 struct BobCryptodataMessage,
1060 s), 1027 s),
1061 GNUNET_MQ_hd_var_size (bobs_cryptodata_multipart, 1028 GNUNET_MQ_hd_var_size (
1062 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, 1029 bobs_cryptodata_multipart,
1063 struct BobCryptodataMultipartMessage, 1030 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
1064 s), 1031 struct BobCryptodataMultipartMessage,
1065 GNUNET_MQ_handler_end () 1032 s),
1066 }; 1033 GNUNET_MQ_handler_end ()};
1067 struct ServiceRequestMessage *msg; 1034 struct ServiceRequestMessage *msg;
1068 struct GNUNET_MQ_Envelope *e; 1035 struct GNUNET_MQ_Envelope *e;
1069 1036
1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1071 "Creating new channel for session with key %s.\n", 1038 "Creating new channel for session with key %s.\n",
1072 GNUNET_h2s (&s->session_id)); 1039 GNUNET_h2s (&s->session_id));
1073 s->channel 1040 s->channel = GNUNET_CADET_channel_create (my_cadet,
1074 = GNUNET_CADET_channel_create (my_cadet, 1041 s,
1075 s, 1042 &s->peer,
1076 &s->peer, 1043 &s->session_id,
1077 &s->session_id, 1044 NULL,
1078 NULL, 1045 &cb_channel_destruction,
1079 &cb_channel_destruction, 1046 cadet_handlers);
1080 cadet_handlers);
1081 if (NULL == s->channel) 1047 if (NULL == s->channel)
1082 { 1048 {
1083 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1049 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1085,12 +1051,11 @@ client_request_complete_alice (struct AliceServiceSession *s)
1085 return; 1051 return;
1086 } 1052 }
1087 s->cadet_mq = GNUNET_CADET_get_mq (s->channel); 1053 s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
1088 s->intersection_listen 1054 s->intersection_listen = GNUNET_SET_listen (cfg,
1089 = GNUNET_SET_listen (cfg, 1055 GNUNET_SET_OPERATION_INTERSECTION,
1090 GNUNET_SET_OPERATION_INTERSECTION, 1056 &s->session_id,
1091 &s->session_id, 1057 &cb_intersection_request_alice,
1092 &cb_intersection_request_alice, 1058 s);
1093 s);
1094 if (NULL == s->intersection_listen) 1059 if (NULL == s->intersection_listen)
1095 { 1060 {
1096 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1061 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1102,12 +1067,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
1102 1067
1103 e = GNUNET_MQ_msg (msg, 1068 e = GNUNET_MQ_msg (msg,
1104 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION); 1069 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION);
1105 GNUNET_MQ_env_set_options(e,
1106 GNUNET_MQ_PREF_RELIABLE);
1107 msg->session_id = s->session_id; 1070 msg->session_id = s->session_id;
1108 msg->public_key = my_pubkey; 1071 msg->public_key = my_pubkey;
1109 GNUNET_MQ_send (s->cadet_mq, 1072 GNUNET_MQ_send (s->cadet_mq, e);
1110 e);
1111} 1073}
1112 1074
1113 1075
@@ -1120,8 +1082,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
1120 * @return #GNUNET_OK if @a msg is well-formed 1082 * @return #GNUNET_OK if @a msg is well-formed
1121 */ 1083 */
1122static int 1084static int
1123check_alice_client_message_multipart (void *cls, 1085check_alice_client_message_multipart (
1124 const struct ComputationBobCryptodataMultipartMessage *msg) 1086 void *cls,
1087 const struct ComputationBobCryptodataMultipartMessage *msg)
1125{ 1088{
1126 struct AliceServiceSession *s = cls; 1089 struct AliceServiceSession *s = cls;
1127 uint32_t contained_count; 1090 uint32_t contained_count;
@@ -1129,11 +1092,12 @@ check_alice_client_message_multipart (void *cls,
1129 1092
1130 msize = ntohs (msg->header.size); 1093 msize = ntohs (msg->header.size);
1131 contained_count = ntohl (msg->element_count_contained); 1094 contained_count = ntohl (msg->element_count_contained);
1132 if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + 1095 if ((msize !=
1133 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || 1096 (sizeof (struct ComputationBobCryptodataMultipartMessage) +
1134 (0 == contained_count) || 1097 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
1135 (s->total == s->client_received_element_count) || 1098 (0 == contained_count) ||
1136 (s->total < s->client_received_element_count + contained_count) ) 1099 (s->total == s->client_received_element_count) ||
1100 (s->total < s->client_received_element_count + contained_count))
1137 { 1101 {
1138 GNUNET_break_op (0); 1102 GNUNET_break_op (0);
1139 return GNUNET_SYSERR; 1103 return GNUNET_SYSERR;
@@ -1150,8 +1114,9 @@ check_alice_client_message_multipart (void *cls,
1150 * @param msg the actual message 1114 * @param msg the actual message
1151 */ 1115 */
1152static void 1116static void
1153handle_alice_client_message_multipart (void *cls, 1117handle_alice_client_message_multipart (
1154 const struct ComputationBobCryptodataMultipartMessage *msg) 1118 void *cls,
1119 const struct ComputationBobCryptodataMultipartMessage *msg)
1155{ 1120{
1156 struct AliceServiceSession *s = cls; 1121 struct AliceServiceSession *s = cls;
1157 uint32_t contained_count; 1122 uint32_t contained_count;
@@ -1166,13 +1131,13 @@ handle_alice_client_message_multipart (void *cls,
1166 { 1131 {
1167 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 1132 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1168 GNUNET_memcpy (elem, 1133 GNUNET_memcpy (elem,
1169 &elements[i], 1134 &elements[i],
1170 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1135 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1171 if (GNUNET_SYSERR == 1136 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1172 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1137 s->intersected_elements,
1173 &elem->key, 1138 &elem->key,
1174 elem, 1139 elem,
1175 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1140 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1176 { 1141 {
1177 GNUNET_break (0); 1142 GNUNET_break (0);
1178 GNUNET_free (elem); 1143 GNUNET_free (elem);
@@ -1181,9 +1146,7 @@ handle_alice_client_message_multipart (void *cls,
1181 set_elem.data = &elem->key; 1146 set_elem.data = &elem->key;
1182 set_elem.size = sizeof (elem->key); 1147 set_elem.size = sizeof (elem->key);
1183 set_elem.element_type = 0; 1148 set_elem.element_type = 0;
1184 GNUNET_SET_add_element (s->intersection_set, 1149 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1185 &set_elem,
1186 NULL, NULL);
1187 s->used_element_count++; 1150 s->used_element_count++;
1188 } 1151 }
1189 GNUNET_SERVICE_client_continue (s->client); 1152 GNUNET_SERVICE_client_continue (s->client);
@@ -1206,7 +1169,7 @@ handle_alice_client_message_multipart (void *cls,
1206 */ 1169 */
1207static int 1170static int
1208check_alice_client_message (void *cls, 1171check_alice_client_message (void *cls,
1209 const struct AliceComputationMessage *msg) 1172 const struct AliceComputationMessage *msg)
1210{ 1173{
1211 struct AliceServiceSession *s = cls; 1174 struct AliceServiceSession *s = cls;
1212 uint16_t msize; 1175 uint16_t msize;
@@ -1223,10 +1186,10 @@ check_alice_client_message (void *cls,
1223 msize = ntohs (msg->header.size); 1186 msize = ntohs (msg->header.size);
1224 total_count = ntohl (msg->element_count_total); 1187 total_count = ntohl (msg->element_count_total);
1225 contained_count = ntohl (msg->element_count_contained); 1188 contained_count = ntohl (msg->element_count_contained);
1226 if ( (0 == total_count) || 1189 if ((0 == total_count) || (0 == contained_count) ||
1227 (0 == contained_count) || 1190 (msize !=
1228 (msize != (sizeof (struct AliceComputationMessage) + 1191 (sizeof (struct AliceComputationMessage) +
1229 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) 1192 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))))
1230 { 1193 {
1231 GNUNET_break_op (0); 1194 GNUNET_break_op (0);
1232 return GNUNET_SYSERR; 1195 return GNUNET_SYSERR;
@@ -1244,7 +1207,7 @@ check_alice_client_message (void *cls,
1244 */ 1207 */
1245static void 1208static void
1246handle_alice_client_message (void *cls, 1209handle_alice_client_message (void *cls,
1247 const struct AliceComputationMessage *msg) 1210 const struct AliceComputationMessage *msg)
1248{ 1211{
1249 struct AliceServiceSession *s = cls; 1212 struct AliceServiceSession *s = cls;
1250 uint32_t contained_count; 1213 uint32_t contained_count;
@@ -1261,10 +1224,10 @@ handle_alice_client_message (void *cls,
1261 s->client_received_element_count = contained_count; 1224 s->client_received_element_count = contained_count;
1262 s->session_id = msg->session_key; 1225 s->session_id = msg->session_key;
1263 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 1226 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
1264 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, 1227 s->intersected_elements =
1265 GNUNET_YES); 1228 GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES);
1266 s->intersection_set = GNUNET_SET_create (cfg, 1229 s->intersection_set =
1267 GNUNET_SET_OPERATION_INTERSECTION); 1230 GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
1268 1231
1269 for (uint32_t i = 0; i < contained_count; i++) 1232 for (uint32_t i = 0; i < contained_count; i++)
1270 { 1233 {
@@ -1272,13 +1235,13 @@ handle_alice_client_message (void *cls,
1272 continue; 1235 continue;
1273 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 1236 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1274 GNUNET_memcpy (elem, 1237 GNUNET_memcpy (elem,
1275 &elements[i], 1238 &elements[i],
1276 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1239 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1277 if (GNUNET_SYSERR == 1240 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1278 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1241 s->intersected_elements,
1279 &elem->key, 1242 &elem->key,
1280 elem, 1243 elem,
1281 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1244 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1282 { 1245 {
1283 /* element with same key encountered twice! */ 1246 /* element with same key encountered twice! */
1284 GNUNET_break (0); 1247 GNUNET_break (0);
@@ -1288,9 +1251,7 @@ handle_alice_client_message (void *cls,
1288 set_elem.data = &elem->key; 1251 set_elem.data = &elem->key;
1289 set_elem.size = sizeof (elem->key); 1252 set_elem.size = sizeof (elem->key);
1290 set_elem.element_type = 0; 1253 set_elem.element_type = 0;
1291 GNUNET_SET_add_element (s->intersection_set, 1254 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1292 &set_elem,
1293 NULL, NULL);
1294 s->used_element_count++; 1255 s->used_element_count++;
1295 } 1256 }
1296 GNUNET_SERVICE_client_continue (s->client); 1257 GNUNET_SERVICE_client_continue (s->client);
@@ -1311,8 +1272,7 @@ handle_alice_client_message (void *cls,
1311static void 1272static void
1312shutdown_task (void *cls) 1273shutdown_task (void *cls)
1313{ 1274{
1314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n");
1315 "Shutting down, initiating cleanup.\n");
1316 // FIXME: we have to cut our connections to CADET first! 1276 // FIXME: we have to cut our connections to CADET first!
1317 if (NULL != my_cadet) 1277 if (NULL != my_cadet)
1318 { 1278 {
@@ -1334,8 +1294,8 @@ shutdown_task (void *cls)
1334 */ 1294 */
1335static void * 1295static void *
1336client_connect_cb (void *cls, 1296client_connect_cb (void *cls,
1337 struct GNUNET_SERVICE_Client *client, 1297 struct GNUNET_SERVICE_Client *client,
1338 struct GNUNET_MQ_Handle *mq) 1298 struct GNUNET_MQ_Handle *mq)
1339{ 1299{
1340 struct AliceServiceSession *s; 1300 struct AliceServiceSession *s;
1341 1301
@@ -1358,8 +1318,8 @@ client_connect_cb (void *cls,
1358 */ 1318 */
1359static void 1319static void
1360client_disconnect_cb (void *cls, 1320client_disconnect_cb (void *cls,
1361 struct GNUNET_SERVICE_Client *client, 1321 struct GNUNET_SERVICE_Client *client,
1362 void *app_cls) 1322 void *app_cls)
1363{ 1323{
1364 struct AliceServiceSession *s = app_cls; 1324 struct AliceServiceSession *s = app_cls;
1365 1325
@@ -1390,17 +1350,13 @@ run (void *cls,
1390 m1+m2 mod n == (S + a) + (S + b) mod n, 1350 m1+m2 mod n == (S + a) + (S + b) mod n,
1391 if we have more complex operations, this factor needs to be lowered */ 1351 if we have more complex operations, this factor needs to be lowered */
1392 my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); 1352 my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3);
1393 gcry_mpi_set_bit (my_offset, 1353 gcry_mpi_set_bit (my_offset, GNUNET_CRYPTO_PAILLIER_BITS / 3);
1394 GNUNET_CRYPTO_PAILLIER_BITS / 3); 1354 GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey);
1395 GNUNET_CRYPTO_paillier_create (&my_pubkey,
1396 &my_privkey);
1397 my_cadet = GNUNET_CADET_connect (cfg); 1355 my_cadet = GNUNET_CADET_connect (cfg);
1398 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1356 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1399 NULL);
1400 if (NULL == my_cadet) 1357 if (NULL == my_cadet)
1401 { 1358 {
1402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n"));
1403 _("Connect to CADET failed\n"));
1404 GNUNET_SCHEDULER_shutdown (); 1360 GNUNET_SCHEDULER_shutdown ();
1405 return; 1361 return;
1406 } 1362 }
@@ -1410,22 +1366,23 @@ run (void *cls,
1410/** 1366/**
1411 * Define "main" method using service macro. 1367 * Define "main" method using service macro.
1412 */ 1368 */
1413GNUNET_SERVICE_MAIN 1369GNUNET_SERVICE_MAIN (
1414("scalarproduct-alice", 1370 "scalarproduct-alice",
1415 GNUNET_SERVICE_OPTION_NONE, 1371 GNUNET_SERVICE_OPTION_NONE,
1416 &run, 1372 &run,
1417 &client_connect_cb, 1373 &client_connect_cb,
1418 &client_disconnect_cb, 1374 &client_disconnect_cb,
1419 NULL, 1375 NULL,
1420 GNUNET_MQ_hd_var_size (alice_client_message, 1376 GNUNET_MQ_hd_var_size (alice_client_message,
1421 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, 1377 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
1422 struct AliceComputationMessage, 1378 struct AliceComputationMessage,
1423 NULL), 1379 NULL),
1424 GNUNET_MQ_hd_var_size (alice_client_message_multipart, 1380 GNUNET_MQ_hd_var_size (
1425 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, 1381 alice_client_message_multipart,
1426 struct ComputationBobCryptodataMultipartMessage, 1382 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
1427 NULL), 1383 struct ComputationBobCryptodataMultipartMessage,
1428 GNUNET_MQ_handler_end ()); 1384 NULL),
1385 GNUNET_MQ_handler_end ());
1429 1386
1430 1387
1431/* end of gnunet-service-scalarproduct_alice.c */ 1388/* end of gnunet-service-scalarproduct_alice.c */
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index f1d94bef7..5becd7bd9 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.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
@@ -60,7 +60,6 @@ struct LazyCopyRequest
60 * Cookie identifying the request. 60 * Cookie identifying the request.
61 */ 61 */
62 uint32_t cookie; 62 uint32_t cookie;
63
64}; 63};
65 64
66 65
@@ -185,8 +184,7 @@ static uint32_t suggest_id;
185static struct Operation * 184static struct Operation *
186get_incoming (uint32_t id) 185get_incoming (uint32_t id)
187{ 186{
188 for (struct Listener *listener = listener_head; 187 for (struct Listener *listener = listener_head; NULL != listener;
189 NULL != listener;
190 listener = listener->next) 188 listener = listener->next)
191 { 189 {
192 for (struct Operation *op = listener->op_head; NULL != op; op = op->next) 190 for (struct Operation *op = listener->op_head; NULL != op; op = op->next)
@@ -212,9 +210,7 @@ incoming_destroy (struct Operation *op)
212 op); 210 op);
213 if (NULL != (listener = op->listener)) 211 if (NULL != (listener = op->listener))
214 { 212 {
215 GNUNET_CONTAINER_DLL_remove (listener->op_head, 213 GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op);
216 listener->op_tail,
217 op);
218 op->listener = NULL; 214 op->listener = NULL;
219 } 215 }
220 if (NULL != op->timeout_task) 216 if (NULL != op->timeout_task)
@@ -246,7 +242,6 @@ struct GarbageContext
246 * Largest generation for which an operation is still pending. 242 * Largest generation for which an operation is still pending.
247 */ 243 */
248 unsigned int max_op_generation; 244 unsigned int max_op_generation;
249
250}; 245};
251 246
252 247
@@ -260,9 +255,7 @@ struct GarbageContext
260 * @return #GNUNET_OK (continue to iterate) 255 * @return #GNUNET_OK (continue to iterate)
261 */ 256 */
262static int 257static int
263garbage_collect_cb (void *cls, 258garbage_collect_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
264 const struct GNUNET_HashCode *key,
265 void *value)
266{ 259{
267 //struct GarbageContext *gc = cls; 260 //struct GarbageContext *gc = cls;
268 //struct ElementEntry *ee = value; 261 //struct ElementEntry *ee = value;
@@ -298,10 +291,10 @@ collect_generation_garbage (struct Set *set)
298 gc.max_op_generation = 0; 291 gc.max_op_generation = 0;
299 for (struct Operation *op = set->ops_head; NULL != op; op = op->next) 292 for (struct Operation *op = set->ops_head; NULL != op; op = op->next)
300 { 293 {
301 gc.min_op_generation = GNUNET_MIN (gc.min_op_generation, 294 gc.min_op_generation =
302 op->generation_created); 295 GNUNET_MIN (gc.min_op_generation, op->generation_created);
303 gc.max_op_generation = GNUNET_MAX (gc.max_op_generation, 296 gc.max_op_generation =
304 op->generation_created); 297 GNUNET_MAX (gc.max_op_generation, op->generation_created);
305 } 298 }
306 gc.map = set->content->elements; 299 gc.map = set->content->elements;
307 GNUNET_CONTAINER_multihashmap_iterate (set->content->elements, 300 GNUNET_CONTAINER_multihashmap_iterate (set->content->elements,
@@ -324,8 +317,7 @@ is_excluded_generation (unsigned int generation,
324 unsigned int excluded_size) 317 unsigned int excluded_size)
325{ 318{
326 for (unsigned int i = 0; i < excluded_size; i++) 319 for (unsigned int i = 0; i < excluded_size; i++)
327 if ( (generation >= excluded[i].start) && 320 if ((generation >= excluded[i].start) && (generation < excluded[i].end))
328 (generation < excluded[i].end) )
329 return GNUNET_YES; 321 return GNUNET_YES;
330 return GNUNET_NO; 322 return GNUNET_NO;
331} 323}
@@ -351,9 +343,7 @@ is_element_of_generation (struct ElementEntry *ee,
351 343
352 GNUNET_assert (NULL != ee->mutations); 344 GNUNET_assert (NULL != ee->mutations);
353 if (GNUNET_YES == 345 if (GNUNET_YES ==
354 is_excluded_generation (query_generation, 346 is_excluded_generation (query_generation, excluded, excluded_size))
355 excluded,
356 excluded_size))
357 { 347 {
358 GNUNET_break (0); 348 GNUNET_break (0);
359 return GNUNET_NO; 349 return GNUNET_NO;
@@ -376,9 +366,7 @@ is_element_of_generation (struct ElementEntry *ee,
376 } 366 }
377 367
378 if (GNUNET_YES == 368 if (GNUNET_YES ==
379 is_excluded_generation (mut->generation, 369 is_excluded_generation (mut->generation, excluded, excluded_size))
380 excluded,
381 excluded_size))
382 { 370 {
383 /* The generation is excluded (because it belongs to another 371 /* The generation is excluded (because it belongs to another
384 fork via a lazy copy) and thus mutations aren't considered 372 fork via a lazy copy) and thus mutations aren't considered
@@ -387,12 +375,10 @@ is_element_of_generation (struct ElementEntry *ee,
387 } 375 }
388 376
389 /* This would be an inconsistency in how we manage mutations. */ 377 /* This would be an inconsistency in how we manage mutations. */
390 if ( (GNUNET_YES == is_present) && 378 if ((GNUNET_YES == is_present) && (GNUNET_YES == mut->added))
391 (GNUNET_YES == mut->added) )
392 GNUNET_assert (0); 379 GNUNET_assert (0);
393 /* Likewise. */ 380 /* Likewise. */
394 if ( (GNUNET_NO == is_present) && 381 if ((GNUNET_NO == is_present) && (GNUNET_NO == mut->added))
395 (GNUNET_NO == mut->added) )
396 GNUNET_assert (0); 382 GNUNET_assert (0);
397 383
398 is_present = mut->added; 384 is_present = mut->added;
@@ -410,8 +396,7 @@ is_element_of_generation (struct ElementEntry *ee,
410 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not 396 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not
411 */ 397 */
412int 398int
413_GSS_is_element_of_operation (struct ElementEntry *ee, 399_GSS_is_element_of_operation (struct ElementEntry *ee, struct Operation *op)
414 struct Operation *op)
415{ 400{
416 return is_element_of_generation (ee, 401 return is_element_of_generation (ee,
417 op->generation_created, 402 op->generation_created,
@@ -434,15 +419,12 @@ _GSS_is_element_of_operation (struct ElementEntry *ee,
434 * @param gc #GNUNET_YES to perform garbage collection on the set 419 * @param gc #GNUNET_YES to perform garbage collection on the set
435 */ 420 */
436void 421void
437_GSS_operation_destroy (struct Operation *op, 422_GSS_operation_destroy (struct Operation *op, int gc)
438 int gc)
439{ 423{
440 struct Set *set = op->set; 424 struct Set *set = op->set;
441 struct GNUNET_CADET_Channel *channel; 425 struct GNUNET_CADET_Channel *channel;
442 426
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op);
444 "Destroying operation %p\n",
445 op);
446 GNUNET_assert (NULL == op->listener); 428 GNUNET_assert (NULL == op->listener);
447 if (NULL != op->state) 429 if (NULL != op->state)
448 { 430 {
@@ -451,9 +433,7 @@ _GSS_operation_destroy (struct Operation *op,
451 } 433 }
452 if (NULL != set) 434 if (NULL != set)
453 { 435 {
454 GNUNET_CONTAINER_DLL_remove (set->ops_head, 436 GNUNET_CONTAINER_DLL_remove (set->ops_head, set->ops_tail, op);
455 set->ops_tail,
456 op);
457 op->set = NULL; 437 op->set = NULL;
458 } 438 }
459 if (NULL != op->context_msg) 439 if (NULL != op->context_msg)
@@ -468,8 +448,7 @@ _GSS_operation_destroy (struct Operation *op,
468 op->channel = NULL; 448 op->channel = NULL;
469 GNUNET_CADET_channel_destroy (channel); 449 GNUNET_CADET_channel_destroy (channel);
470 } 450 }
471 if ( (NULL != set) && 451 if ((NULL != set) && (GNUNET_YES == gc))
472 (GNUNET_YES == gc) )
473 collect_generation_garbage (set); 452 collect_generation_garbage (set);
474 /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL, 453 /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL,
475 * there was a channel end handler that will free 'op' on the call stack. */ 454 * there was a channel end handler that will free 'op' on the call stack. */
@@ -486,8 +465,8 @@ _GSS_operation_destroy (struct Operation *op,
486 */ 465 */
487static void * 466static void *
488client_connect_cb (void *cls, 467client_connect_cb (void *cls,
489 struct GNUNET_SERVICE_Client *c, 468 struct GNUNET_SERVICE_Client *c,
490 struct GNUNET_MQ_Handle *mq) 469 struct GNUNET_MQ_Handle *mq)
491{ 470{
492 struct ClientState *cs; 471 struct ClientState *cs;
493 472
@@ -537,8 +516,7 @@ client_disconnect_cb (void *cls,
537 struct Listener *listener; 516 struct Listener *listener;
538 struct Set *set; 517 struct Set *set;
539 518
540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, cleaning up\n");
541 "Client disconnected, cleaning up\n");
542 if (NULL != (set = cs->set)) 520 if (NULL != (set = cs->set))
543 { 521 {
544 struct SetContent *content = set->content; 522 struct SetContent *content = set->content;
@@ -546,12 +524,10 @@ client_disconnect_cb (void *cls,
546 struct PendingMutation *pm_current; 524 struct PendingMutation *pm_current;
547 struct LazyCopyRequest *lcr; 525 struct LazyCopyRequest *lcr;
548 526
549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's set\n");
550 "Destroying client's set\n");
551 /* Destroy pending set operations */ 528 /* Destroy pending set operations */
552 while (NULL != set->ops_head) 529 while (NULL != set->ops_head)
553 _GSS_operation_destroy (set->ops_head, 530 _GSS_operation_destroy (set->ops_head, GNUNET_NO);
554 GNUNET_NO);
555 531
556 /* Destroy operation-specific state */ 532 /* Destroy operation-specific state */
557 GNUNET_assert (NULL != set->state); 533 GNUNET_assert (NULL != set->state);
@@ -618,8 +594,7 @@ client_disconnect_cb (void *cls,
618 594
619 if (NULL != (listener = cs->listener)) 595 if (NULL != (listener = cs->listener))
620 { 596 {
621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's listener\n");
622 "Destroying client's listener\n");
623 GNUNET_CADET_close_port (listener->open_port); 598 GNUNET_CADET_close_port (listener->open_port);
624 listener->open_port = NULL; 599 listener->open_port = NULL;
625 while (NULL != (op = listener->op_head)) 600 while (NULL != (op = listener->op_head))
@@ -630,15 +605,12 @@ client_disconnect_cb (void *cls,
630 GNUNET_i2s (&op->peer)); 605 GNUNET_i2s (&op->peer));
631 incoming_destroy (op); 606 incoming_destroy (op);
632 } 607 }
633 GNUNET_CONTAINER_DLL_remove (listener_head, 608 GNUNET_CONTAINER_DLL_remove (listener_head, listener_tail, listener);
634 listener_tail,
635 listener);
636 GNUNET_free (listener); 609 GNUNET_free (listener);
637 } 610 }
638 GNUNET_free (cs); 611 GNUNET_free (cs);
639 num_clients--; 612 num_clients--;
640 if ( (GNUNET_YES == in_shutdown) && 613 if ((GNUNET_YES == in_shutdown) && (0 == num_clients))
641 (0 == num_clients) )
642 { 614 {
643 if (NULL != cadet) 615 if (NULL != cadet)
644 { 616 {
@@ -658,8 +630,7 @@ client_disconnect_cb (void *cls,
658 * #GNUNET_SYSERR to destroy the channel 630 * #GNUNET_SYSERR to destroy the channel
659 */ 631 */
660static int 632static int
661check_incoming_msg (void *cls, 633check_incoming_msg (void *cls, const struct OperationRequestMessage *msg)
662 const struct OperationRequestMessage *msg)
663{ 634{
664 struct Operation *op = cls; 635 struct Operation *op = cls;
665 struct Listener *listener = op->listener; 636 struct Listener *listener = op->listener;
@@ -677,14 +648,15 @@ check_incoming_msg (void *cls,
677 GNUNET_break (0); 648 GNUNET_break (0);
678 return GNUNET_SYSERR; 649 return GNUNET_SYSERR;
679 } 650 }
680 if (listener->operation != (enum GNUNET_SET_OperationType) ntohl (msg->operation)) 651 if (listener->operation !=
652 (enum GNUNET_SET_OperationType) ntohl (msg->operation))
681 { 653 {
682 GNUNET_break_op (0); 654 GNUNET_break_op (0);
683 return GNUNET_SYSERR; 655 return GNUNET_SYSERR;
684 } 656 }
685 nested_context = GNUNET_MQ_extract_nested_mh (msg); 657 nested_context = GNUNET_MQ_extract_nested_mh (msg);
686 if ( (NULL != nested_context) && 658 if ((NULL != nested_context) &&
687 (ntohs (nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE) ) 659 (ntohs (nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE))
688 { 660 {
689 GNUNET_break_op (0); 661 GNUNET_break_op (0);
690 return GNUNET_SYSERR; 662 return GNUNET_SYSERR;
@@ -711,8 +683,7 @@ check_incoming_msg (void *cls,
711 * #GNUNET_SYSERR to destroy the channel 683 * #GNUNET_SYSERR to destroy the channel
712 */ 684 */
713static void 685static void
714handle_incoming_msg (void *cls, 686handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg)
715 const struct OperationRequestMessage *msg)
716{ 687{
717 struct Operation *op = cls; 688 struct Operation *op = cls;
718 struct Listener *listener = op->listener; 689 struct Listener *listener = op->listener;
@@ -727,10 +698,11 @@ handle_incoming_msg (void *cls,
727 if (NULL != nested_context) 698 if (NULL != nested_context)
728 op->context_msg = GNUNET_copy_message (nested_context); 699 op->context_msg = GNUNET_copy_message (nested_context);
729 op->remote_element_count = ntohl (msg->element_count); 700 op->remote_element_count = ntohl (msg->element_count);
730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 701 GNUNET_log (
731 "Received P2P operation request (op %u, port %s) for active listener\n", 702 GNUNET_ERROR_TYPE_DEBUG,
732 (uint32_t) ntohl (msg->operation), 703 "Received P2P operation request (op %u, port %s) for active listener\n",
733 GNUNET_h2s (&op->listener->app_id)); 704 (uint32_t) ntohl (msg->operation),
705 GNUNET_h2s (&op->listener->app_id));
734 GNUNET_assert (0 == op->suggest_id); 706 GNUNET_assert (0 == op->suggest_id);
735 if (0 == suggest_id) 707 if (0 == suggest_id)
736 suggest_id++; 708 suggest_id++;
@@ -741,17 +713,15 @@ handle_incoming_msg (void *cls,
741 env = GNUNET_MQ_msg_nested_mh (cmsg, 713 env = GNUNET_MQ_msg_nested_mh (cmsg,
742 GNUNET_MESSAGE_TYPE_SET_REQUEST, 714 GNUNET_MESSAGE_TYPE_SET_REQUEST,
743 op->context_msg); 715 op->context_msg);
744 GNUNET_MQ_env_set_options(env, 716 GNUNET_log (
745 GNUNET_MQ_PREF_RELIABLE); 717 GNUNET_ERROR_TYPE_DEBUG,
746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 718 "Suggesting incoming request with accept id %u to listener %p of client %p\n",
747 "Suggesting incoming request with accept id %u to listener %p of client %p\n", 719 op->suggest_id,
748 op->suggest_id, 720 listener,
749 listener, 721 listener->cs);
750 listener->cs);
751 cmsg->accept_id = htonl (op->suggest_id); 722 cmsg->accept_id = htonl (op->suggest_id);
752 cmsg->peer_id = op->peer; 723 cmsg->peer_id = op->peer;
753 GNUNET_MQ_send (listener->cs->mq, 724 GNUNET_MQ_send (listener->cs->mq, env);
754 env);
755 /* NOTE: GNUNET_CADET_receive_done() will be called in 725 /* NOTE: GNUNET_CADET_receive_done() will be called in
756 #handle_client_accept() */ 726 #handle_client_accept() */
757} 727}
@@ -764,8 +734,7 @@ handle_incoming_msg (void *cls,
764 * @param msg message specifying the change 734 * @param msg message specifying the change
765 */ 735 */
766static void 736static void
767execute_add (struct Set *set, 737execute_add (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
768 const struct GNUNET_SET_ElementMessage *msg)
769{ 738{
770 struct GNUNET_SET_Element el; 739 struct GNUNET_SET_Element el;
771 struct ElementEntry *ee; 740 struct ElementEntry *ee;
@@ -775,10 +744,8 @@ execute_add (struct Set *set,
775 el.size = ntohs (msg->header.size) - sizeof (*msg); 744 el.size = ntohs (msg->header.size) - sizeof (*msg);
776 el.data = &msg[1]; 745 el.data = &msg[1];
777 el.element_type = ntohs (msg->element_type); 746 el.element_type = ntohs (msg->element_type);
778 GNUNET_SET_element_hash (&el, 747 GNUNET_SET_element_hash (&el, &hash);
779 &hash); 748 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash);
780 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements,
781 &hash);
782 if (NULL == ee) 749 if (NULL == ee)
783 { 750 {
784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -787,9 +754,7 @@ execute_add (struct Set *set,
787 el.size); 754 el.size);
788 ee = GNUNET_malloc (el.size + sizeof (*ee)); 755 ee = GNUNET_malloc (el.size + sizeof (*ee));
789 ee->element.size = el.size; 756 ee->element.size = el.size;
790 GNUNET_memcpy (&ee[1], 757 GNUNET_memcpy (&ee[1], el.data, el.size);
791 el.data,
792 el.size);
793 ee->element.data = &ee[1]; 758 ee->element.data = &ee[1];
794 ee->element.element_type = el.element_type; 759 ee->element.element_type = el.element_type;
795 ee->remote = GNUNET_NO; 760 ee->remote = GNUNET_NO;
@@ -797,10 +762,11 @@ execute_add (struct Set *set,
797 ee->mutations_size = 0; 762 ee->mutations_size = 0;
798 ee->element_hash = hash; 763 ee->element_hash = hash;
799 GNUNET_break (GNUNET_YES == 764 GNUNET_break (GNUNET_YES ==
800 GNUNET_CONTAINER_multihashmap_put (set->content->elements, 765 GNUNET_CONTAINER_multihashmap_put (
801 &ee->element_hash, 766 set->content->elements,
802 ee, 767 &ee->element_hash,
803 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 768 ee,
769 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
804 } 770 }
805 else if (GNUNET_YES == 771 else if (GNUNET_YES ==
806 is_element_of_generation (ee, 772 is_element_of_generation (ee,
@@ -818,16 +784,11 @@ execute_add (struct Set *set,
818 } 784 }
819 785
820 { 786 {
821 struct MutationEvent mut = { 787 struct MutationEvent mut = {.generation = set->current_generation,
822 .generation = set->current_generation, 788 .added = GNUNET_YES};
823 .added = GNUNET_YES 789 GNUNET_array_append (ee->mutations, ee->mutations_size, mut);
824 };
825 GNUNET_array_append (ee->mutations,
826 ee->mutations_size,
827 mut);
828 } 790 }
829 set->vt->add (set->state, 791 set->vt->add (set->state, ee);
830 ee);
831} 792}
832 793
833 794
@@ -838,8 +799,7 @@ execute_add (struct Set *set,
838 * @param msg message specifying the change 799 * @param msg message specifying the change
839 */ 800 */
840static void 801static void
841execute_remove (struct Set *set, 802execute_remove (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
842 const struct GNUNET_SET_ElementMessage *msg)
843{ 803{
844 struct GNUNET_SET_Element el; 804 struct GNUNET_SET_Element el;
845 struct ElementEntry *ee; 805 struct ElementEntry *ee;
@@ -850,8 +810,7 @@ execute_remove (struct Set *set,
850 el.data = &msg[1]; 810 el.data = &msg[1];
851 el.element_type = ntohs (msg->element_type); 811 el.element_type = ntohs (msg->element_type);
852 GNUNET_SET_element_hash (&el, &hash); 812 GNUNET_SET_element_hash (&el, &hash);
853 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, 813 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash);
854 &hash);
855 if (NULL == ee) 814 if (NULL == ee)
856 { 815 {
857 /* Client tried to remove non-existing element. */ 816 /* Client tried to remove non-existing element. */
@@ -860,11 +819,10 @@ execute_remove (struct Set *set,
860 el.size); 819 el.size);
861 return; 820 return;
862 } 821 }
863 if (GNUNET_NO == 822 if (GNUNET_NO == is_element_of_generation (ee,
864 is_element_of_generation (ee, 823 set->current_generation,
865 set->current_generation, 824 set->excluded_generations,
866 set->excluded_generations, 825 set->excluded_generations_size))
867 set->excluded_generations_size))
868 { 826 {
869 /* Client tried to remove element twice */ 827 /* Client tried to remove element twice */
870 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 828 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -874,21 +832,16 @@ execute_remove (struct Set *set,
874 } 832 }
875 else 833 else
876 { 834 {
877 struct MutationEvent mut = { 835 struct MutationEvent mut = {.generation = set->current_generation,
878 .generation = set->current_generation, 836 .added = GNUNET_NO};
879 .added = GNUNET_NO
880 };
881 837
882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
883 "Client removes element of size %u\n", 839 "Client removes element of size %u\n",
884 el.size); 840 el.size);
885 841
886 GNUNET_array_append (ee->mutations, 842 GNUNET_array_append (ee->mutations, ee->mutations_size, mut);
887 ee->mutations_size,
888 mut);
889 } 843 }
890 set->vt->remove (set->state, 844 set->vt->remove (set->state, ee);
891 ee);
892} 845}
893 846
894 847
@@ -899,19 +852,18 @@ execute_remove (struct Set *set,
899 * @param msg specification of what to change 852 * @param msg specification of what to change
900 */ 853 */
901static void 854static void
902execute_mutation (struct Set *set, 855execute_mutation (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
903 const struct GNUNET_SET_ElementMessage *msg)
904{ 856{
905 switch (ntohs (msg->header.type)) 857 switch (ntohs (msg->header.type))
906 { 858 {
907 case GNUNET_MESSAGE_TYPE_SET_ADD: 859 case GNUNET_MESSAGE_TYPE_SET_ADD:
908 execute_add (set, msg); 860 execute_add (set, msg);
909 break; 861 break;
910 case GNUNET_MESSAGE_TYPE_SET_REMOVE: 862 case GNUNET_MESSAGE_TYPE_SET_REMOVE:
911 execute_remove (set, msg); 863 execute_remove (set, msg);
912 break; 864 break;
913 default: 865 default:
914 GNUNET_break (0); 866 GNUNET_break (0);
915 } 867 }
916} 868}
917 869
@@ -937,8 +889,7 @@ execute_delayed_mutations (struct Set *set)
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
938 "Executing pending mutation on %p.\n", 890 "Executing pending mutation on %p.\n",
939 pm->set); 891 pm->set);
940 execute_mutation (pm->set, 892 execute_mutation (pm->set, pm->msg);
941 pm->msg);
942 GNUNET_free (pm->msg); 893 GNUNET_free (pm->msg);
943 GNUNET_free (pm); 894 GNUNET_free (pm);
944 } 895 }
@@ -967,15 +918,14 @@ send_client_element (struct Set *set)
967 struct GNUNET_SET_IterResponseMessage *msg; 918 struct GNUNET_SET_IterResponseMessage *msg;
968 919
969 GNUNET_assert (NULL != set->iter); 920 GNUNET_assert (NULL != set->iter);
970 do { 921 do
922 {
971 ret = GNUNET_CONTAINER_multihashmap_iterator_next (set->iter, 923 ret = GNUNET_CONTAINER_multihashmap_iterator_next (set->iter,
972 NULL, 924 NULL,
973 (const void **) &ee); 925 (const void **) &ee);
974 if (GNUNET_NO == ret) 926 if (GNUNET_NO == ret)
975 { 927 {
976 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration on %p done.\n", set);
977 "Iteration on %p done.\n",
978 set);
979 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE); 929 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE);
980 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); 930 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
981 set->iter = NULL; 931 set->iter = NULL;
@@ -983,8 +933,7 @@ send_client_element (struct Set *set)
983 GNUNET_assert (set->content->iterator_count > 0); 933 GNUNET_assert (set->content->iterator_count > 0);
984 set->content->iterator_count--; 934 set->content->iterator_count--;
985 execute_delayed_mutations (set); 935 execute_delayed_mutations (set);
986 GNUNET_MQ_send (set->cs->mq, 936 GNUNET_MQ_send (set->cs->mq, ev);
987 ev);
988 return; 937 return;
989 } 938 }
990 GNUNET_assert (NULL != ee); 939 GNUNET_assert (NULL != ee);
@@ -999,13 +948,10 @@ send_client_element (struct Set *set)
999 ev = GNUNET_MQ_msg_extra (msg, 948 ev = GNUNET_MQ_msg_extra (msg,
1000 ee->element.size, 949 ee->element.size,
1001 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT); 950 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT);
1002 GNUNET_memcpy (&msg[1], 951 GNUNET_memcpy (&msg[1], ee->element.data, ee->element.size);
1003 ee->element.data,
1004 ee->element.size);
1005 msg->element_type = htons (ee->element.element_type); 952 msg->element_type = htons (ee->element.element_type);
1006 msg->iteration_id = htons (set->iteration_id); 953 msg->iteration_id = htons (set->iteration_id);
1007 GNUNET_MQ_send (set->cs->mq, 954 GNUNET_MQ_send (set->cs->mq, ev);
1008 ev);
1009} 955}
1010 956
1011 957
@@ -1019,8 +965,7 @@ send_client_element (struct Set *set)
1019 * @param m message sent by the client 965 * @param m message sent by the client
1020 */ 966 */
1021static void 967static void
1022handle_client_iterate (void *cls, 968handle_client_iterate (void *cls, const struct GNUNET_MessageHeader *m)
1023 const struct GNUNET_MessageHeader *m)
1024{ 969{
1025 struct ClientState *cs = cls; 970 struct ClientState *cs = cls;
1026 struct Set *set; 971 struct Set *set;
@@ -1046,7 +991,8 @@ handle_client_iterate (void *cls,
1046 GNUNET_CONTAINER_multihashmap_size (set->content->elements)); 991 GNUNET_CONTAINER_multihashmap_size (set->content->elements));
1047 GNUNET_SERVICE_client_continue (cs->client); 992 GNUNET_SERVICE_client_continue (cs->client);
1048 set->content->iterator_count++; 993 set->content->iterator_count++;
1049 set->iter = GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements); 994 set->iter =
995 GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements);
1050 set->iter_generation = set->current_generation; 996 set->iter_generation = set->current_generation;
1051 send_client_element (set); 997 send_client_element (set);
1052} 998}
@@ -1061,8 +1007,7 @@ handle_client_iterate (void *cls,
1061 * @param m message sent by the client 1007 * @param m message sent by the client
1062 */ 1008 */
1063static void 1009static void
1064handle_client_create_set (void *cls, 1010handle_client_create_set (void *cls, const struct GNUNET_SET_CreateMessage *msg)
1065 const struct GNUNET_SET_CreateMessage *msg)
1066{ 1011{
1067 struct ClientState *cs = cls; 1012 struct ClientState *cs = cls;
1068 struct Set *set; 1013 struct Set *set;
@@ -1103,8 +1048,7 @@ handle_client_create_set (void *cls,
1103 } 1048 }
1104 set->content = GNUNET_new (struct SetContent); 1049 set->content = GNUNET_new (struct SetContent);
1105 set->content->refcount = 1; 1050 set->content->refcount = 1;
1106 set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, 1051 set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
1107 GNUNET_YES);
1108 set->cs = cs; 1052 set->cs = cs;
1109 cs->set = set; 1053 cs->set = set;
1110 GNUNET_SERVICE_client_continue (cs->client); 1054 GNUNET_SERVICE_client_continue (cs->client);
@@ -1156,22 +1100,17 @@ channel_new_cb (void *cls,
1156 struct Listener *listener = cls; 1100 struct Listener *listener = cls;
1157 struct Operation *op; 1101 struct Operation *op;
1158 1102
1159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New incoming channel\n");
1160 "New incoming channel\n");
1161 op = GNUNET_new (struct Operation); 1104 op = GNUNET_new (struct Operation);
1162 op->listener = listener; 1105 op->listener = listener;
1163 op->peer = *source; 1106 op->peer = *source;
1164 op->channel = channel; 1107 op->channel = channel;
1165 op->mq = GNUNET_CADET_get_mq (op->channel); 1108 op->mq = GNUNET_CADET_get_mq (op->channel);
1166 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1109 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1167 UINT32_MAX); 1110 op->timeout_task = GNUNET_SCHEDULER_add_delayed (INCOMING_CHANNEL_TIMEOUT,
1168 op->timeout_task 1111 &incoming_timeout_cb,
1169 = GNUNET_SCHEDULER_add_delayed (INCOMING_CHANNEL_TIMEOUT, 1112 op);
1170 &incoming_timeout_cb, 1113 GNUNET_CONTAINER_DLL_insert (listener->op_head, listener->op_tail, op);
1171 op);
1172 GNUNET_CONTAINER_DLL_insert (listener->op_head,
1173 listener->op_tail,
1174 op);
1175 return op; 1114 return op;
1176} 1115}
1177 1116
@@ -1193,8 +1132,7 @@ channel_new_cb (void *cls,
1193 * @param channel connection to the other end (henceforth invalid) 1132 * @param channel connection to the other end (henceforth invalid)
1194 */ 1133 */
1195static void 1134static void
1196channel_end_cb (void *channel_ctx, 1135channel_end_cb (void *channel_ctx, const struct GNUNET_CADET_Channel *channel)
1197 const struct GNUNET_CADET_Channel *channel)
1198{ 1136{
1199 struct Operation *op = channel_ctx; 1137 struct Operation *op = channel_ctx;
1200 1138
@@ -1213,8 +1151,7 @@ _GSS_operation_destroy2 (struct Operation *op)
1213{ 1151{
1214 struct GNUNET_CADET_Channel *channel; 1152 struct GNUNET_CADET_Channel *channel;
1215 1153
1216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n");
1217 "channel_end_cb called\n");
1218 if (NULL != (channel = op->channel)) 1155 if (NULL != (channel = op->channel))
1219 { 1156 {
1220 /* This will free op; called conditionally as this helper function 1157 /* This will free op; called conditionally as this helper function
@@ -1230,8 +1167,7 @@ _GSS_operation_destroy2 (struct Operation *op)
1230 if (NULL != op->set) 1167 if (NULL != op->set)
1231 op->set->vt->channel_death (op); 1168 op->set->vt->channel_death (op);
1232 else 1169 else
1233 _GSS_operation_destroy (op, 1170 _GSS_operation_destroy (op, GNUNET_YES);
1234 GNUNET_YES);
1235 GNUNET_free (op); 1171 GNUNET_free (op);
1236} 1172}
1237 1173
@@ -1266,77 +1202,75 @@ channel_window_cb (void *cls,
1266 * @param msg message sent by the client 1202 * @param msg message sent by the client
1267 */ 1203 */
1268static void 1204static void
1269handle_client_listen (void *cls, 1205handle_client_listen (void *cls, const struct GNUNET_SET_ListenMessage *msg)
1270 const struct GNUNET_SET_ListenMessage *msg)
1271{ 1206{
1272 struct ClientState *cs = cls; 1207 struct ClientState *cs = cls;
1273 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1208 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1274 GNUNET_MQ_hd_var_size (incoming_msg, 1209 {GNUNET_MQ_hd_var_size (incoming_msg,
1275 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 1210 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
1276 struct OperationRequestMessage, 1211 struct OperationRequestMessage,
1277 NULL), 1212 NULL),
1278 GNUNET_MQ_hd_var_size (union_p2p_ibf, 1213 GNUNET_MQ_hd_var_size (union_p2p_ibf,
1279 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 1214 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF,
1280 struct IBFMessage, 1215 struct IBFMessage,
1281 NULL), 1216 NULL),
1282 GNUNET_MQ_hd_var_size (union_p2p_elements, 1217 GNUNET_MQ_hd_var_size (union_p2p_elements,
1283 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 1218 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS,
1284 struct GNUNET_SET_ElementMessage, 1219 struct GNUNET_SET_ElementMessage,
1285 NULL), 1220 NULL),
1286 GNUNET_MQ_hd_var_size (union_p2p_offer, 1221 GNUNET_MQ_hd_var_size (union_p2p_offer,
1287 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, 1222 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER,
1288 struct GNUNET_MessageHeader, 1223 struct GNUNET_MessageHeader,
1289 NULL), 1224 NULL),
1290 GNUNET_MQ_hd_var_size (union_p2p_inquiry, 1225 GNUNET_MQ_hd_var_size (union_p2p_inquiry,
1291 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, 1226 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY,
1292 struct InquiryMessage, 1227 struct InquiryMessage,
1293 NULL), 1228 NULL),
1294 GNUNET_MQ_hd_var_size (union_p2p_demand, 1229 GNUNET_MQ_hd_var_size (union_p2p_demand,
1295 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, 1230 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND,
1296 struct GNUNET_MessageHeader, 1231 struct GNUNET_MessageHeader,
1297 NULL), 1232 NULL),
1298 GNUNET_MQ_hd_fixed_size (union_p2p_done, 1233 GNUNET_MQ_hd_fixed_size (union_p2p_done,
1299 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, 1234 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE,
1300 struct GNUNET_MessageHeader, 1235 struct GNUNET_MessageHeader,
1301 NULL), 1236 NULL),
1302 GNUNET_MQ_hd_fixed_size (union_p2p_over, 1237 GNUNET_MQ_hd_fixed_size (union_p2p_over,
1303 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, 1238 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER,
1304 struct GNUNET_MessageHeader, 1239 struct GNUNET_MessageHeader,
1305 NULL), 1240 NULL),
1306 GNUNET_MQ_hd_fixed_size (union_p2p_full_done, 1241 GNUNET_MQ_hd_fixed_size (union_p2p_full_done,
1307 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, 1242 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE,
1308 struct GNUNET_MessageHeader, 1243 struct GNUNET_MessageHeader,
1309 NULL), 1244 NULL),
1310 GNUNET_MQ_hd_fixed_size (union_p2p_request_full, 1245 GNUNET_MQ_hd_fixed_size (union_p2p_request_full,
1311 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, 1246 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1312 struct GNUNET_MessageHeader, 1247 struct GNUNET_MessageHeader,
1313 NULL), 1248 NULL),
1314 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, 1249 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1315 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, 1250 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE,
1316 struct StrataEstimatorMessage, 1251 struct StrataEstimatorMessage,
1317 NULL), 1252 NULL),
1318 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, 1253 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1319 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, 1254 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC,
1320 struct StrataEstimatorMessage, 1255 struct StrataEstimatorMessage,
1321 NULL), 1256 NULL),
1322 GNUNET_MQ_hd_var_size (union_p2p_full_element, 1257 GNUNET_MQ_hd_var_size (union_p2p_full_element,
1323 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, 1258 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT,
1324 struct GNUNET_SET_ElementMessage, 1259 struct GNUNET_SET_ElementMessage,
1325 NULL), 1260 NULL),
1326 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, 1261 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info,
1327 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, 1262 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO,
1328 struct IntersectionElementInfoMessage, 1263 struct IntersectionElementInfoMessage,
1329 NULL), 1264 NULL),
1330 GNUNET_MQ_hd_var_size (intersection_p2p_bf, 1265 GNUNET_MQ_hd_var_size (intersection_p2p_bf,
1331 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, 1266 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF,
1332 struct BFMessage, 1267 struct BFMessage,
1333 NULL), 1268 NULL),
1334 GNUNET_MQ_hd_fixed_size (intersection_p2p_done, 1269 GNUNET_MQ_hd_fixed_size (intersection_p2p_done,
1335 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, 1270 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE,
1336 struct IntersectionDoneMessage, 1271 struct IntersectionDoneMessage,
1337 NULL), 1272 NULL),
1338 GNUNET_MQ_handler_end () 1273 GNUNET_MQ_handler_end ()};
1339 };
1340 struct Listener *listener; 1274 struct Listener *listener;
1341 1275
1342 if (NULL != cs->listener) 1276 if (NULL != cs->listener)
@@ -1351,21 +1285,18 @@ handle_client_listen (void *cls,
1351 cs->listener = listener; 1285 cs->listener = listener;
1352 listener->app_id = msg->app_id; 1286 listener->app_id = msg->app_id;
1353 listener->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation); 1287 listener->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation);
1354 GNUNET_CONTAINER_DLL_insert (listener_head, 1288 GNUNET_CONTAINER_DLL_insert (listener_head, listener_tail, listener);
1355 listener_tail,
1356 listener);
1357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1358 "New listener created (op %u, port %s)\n", 1290 "New listener created (op %u, port %s)\n",
1359 listener->operation, 1291 listener->operation,
1360 GNUNET_h2s (&listener->app_id)); 1292 GNUNET_h2s (&listener->app_id));
1361 listener->open_port 1293 listener->open_port = GNUNET_CADET_open_port (cadet,
1362 = GNUNET_CADET_open_port (cadet, 1294 &msg->app_id,
1363 &msg->app_id, 1295 &channel_new_cb,
1364 &channel_new_cb, 1296 listener,
1365 listener, 1297 &channel_window_cb,
1366 &channel_window_cb, 1298 &channel_end_cb,
1367 &channel_end_cb, 1299 cadet_handlers);
1368 cadet_handlers);
1369 GNUNET_SERVICE_client_continue (cs->client); 1300 GNUNET_SERVICE_client_continue (cs->client);
1370} 1301}
1371 1302
@@ -1378,8 +1309,7 @@ handle_client_listen (void *cls,
1378 * @param msg message sent by the client 1309 * @param msg message sent by the client
1379 */ 1310 */
1380static void 1311static void
1381handle_client_reject (void *cls, 1312handle_client_reject (void *cls, const struct GNUNET_SET_RejectMessage *msg)
1382 const struct GNUNET_SET_RejectMessage *msg)
1383{ 1313{
1384 struct ClientState *cs = cls; 1314 struct ClientState *cs = cls;
1385 struct Operation *op; 1315 struct Operation *op;
@@ -1411,8 +1341,7 @@ handle_client_reject (void *cls,
1411 * @param msg message sent by the client 1341 * @param msg message sent by the client
1412 */ 1342 */
1413static int 1343static int
1414check_client_mutation (void *cls, 1344check_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg)
1415 const struct GNUNET_SET_ElementMessage *msg)
1416{ 1345{
1417 /* NOTE: Technically, we should probably check with the 1346 /* NOTE: Technically, we should probably check with the
1418 block library whether the element we are given is well-formed */ 1347 block library whether the element we are given is well-formed */
@@ -1427,8 +1356,7 @@ check_client_mutation (void *cls,
1427 * @param msg message sent by the client 1356 * @param msg message sent by the client
1428 */ 1357 */
1429static void 1358static void
1430handle_client_mutation (void *cls, 1359handle_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg)
1431 const struct GNUNET_SET_ElementMessage *msg)
1432{ 1360{
1433 struct ClientState *cs = cls; 1361 struct ClientState *cs = cls;
1434 struct Set *set; 1362 struct Set *set;
@@ -1446,20 +1374,18 @@ handle_client_mutation (void *cls,
1446 { 1374 {
1447 struct PendingMutation *pm; 1375 struct PendingMutation *pm;
1448 1376
1449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling mutation on set\n");
1450 "Scheduling mutation on set\n");
1451 pm = GNUNET_new (struct PendingMutation); 1378 pm = GNUNET_new (struct PendingMutation);
1452 pm->msg = (struct GNUNET_SET_ElementMessage *) GNUNET_copy_message (&msg->header); 1379 pm->msg =
1380 (struct GNUNET_SET_ElementMessage *) GNUNET_copy_message (&msg->header);
1453 pm->set = set; 1381 pm->set = set;
1454 GNUNET_CONTAINER_DLL_insert_tail (set->content->pending_mutations_head, 1382 GNUNET_CONTAINER_DLL_insert_tail (set->content->pending_mutations_head,
1455 set->content->pending_mutations_tail, 1383 set->content->pending_mutations_tail,
1456 pm); 1384 pm);
1457 return; 1385 return;
1458 } 1386 }
1459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing mutation on set\n");
1460 "Executing mutation on set\n"); 1388 execute_mutation (set, msg);
1461 execute_mutation (set,
1462 msg);
1463} 1389}
1464 1390
1465 1391
@@ -1503,8 +1429,7 @@ advance_generation (struct Set *set)
1503 * @return #GNUNET_OK if the message is well-formed 1429 * @return #GNUNET_OK if the message is well-formed
1504 */ 1430 */
1505static int 1431static int
1506check_client_evaluate (void *cls, 1432check_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1507 const struct GNUNET_SET_EvaluateMessage *msg)
1508{ 1433{
1509 /* FIXME: suboptimal, even if the context below could be NULL, 1434 /* FIXME: suboptimal, even if the context below could be NULL,
1510 there are malformed messages this does not check for... */ 1435 there are malformed messages this does not check for... */
@@ -1521,78 +1446,76 @@ check_client_evaluate (void *cls,
1521 * @param msg message sent by the client 1446 * @param msg message sent by the client
1522 */ 1447 */
1523static void 1448static void
1524handle_client_evaluate (void *cls, 1449handle_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1525 const struct GNUNET_SET_EvaluateMessage *msg)
1526{ 1450{
1527 struct ClientState *cs = cls; 1451 struct ClientState *cs = cls;
1528 struct Operation *op = GNUNET_new (struct Operation); 1452 struct Operation *op = GNUNET_new (struct Operation);
1529 const struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1453 const struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1530 GNUNET_MQ_hd_var_size (incoming_msg, 1454 {GNUNET_MQ_hd_var_size (incoming_msg,
1531 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 1455 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
1532 struct OperationRequestMessage, 1456 struct OperationRequestMessage,
1533 op), 1457 op),
1534 GNUNET_MQ_hd_var_size (union_p2p_ibf, 1458 GNUNET_MQ_hd_var_size (union_p2p_ibf,
1535 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 1459 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF,
1536 struct IBFMessage, 1460 struct IBFMessage,
1537 op), 1461 op),
1538 GNUNET_MQ_hd_var_size (union_p2p_elements, 1462 GNUNET_MQ_hd_var_size (union_p2p_elements,
1539 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 1463 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS,
1540 struct GNUNET_SET_ElementMessage, 1464 struct GNUNET_SET_ElementMessage,
1541 op), 1465 op),
1542 GNUNET_MQ_hd_var_size (union_p2p_offer, 1466 GNUNET_MQ_hd_var_size (union_p2p_offer,
1543 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, 1467 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER,
1544 struct GNUNET_MessageHeader, 1468 struct GNUNET_MessageHeader,
1545 op), 1469 op),
1546 GNUNET_MQ_hd_var_size (union_p2p_inquiry, 1470 GNUNET_MQ_hd_var_size (union_p2p_inquiry,
1547 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, 1471 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY,
1548 struct InquiryMessage, 1472 struct InquiryMessage,
1549 op), 1473 op),
1550 GNUNET_MQ_hd_var_size (union_p2p_demand, 1474 GNUNET_MQ_hd_var_size (union_p2p_demand,
1551 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, 1475 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND,
1552 struct GNUNET_MessageHeader, 1476 struct GNUNET_MessageHeader,
1553 op), 1477 op),
1554 GNUNET_MQ_hd_fixed_size (union_p2p_done, 1478 GNUNET_MQ_hd_fixed_size (union_p2p_done,
1555 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, 1479 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE,
1556 struct GNUNET_MessageHeader, 1480 struct GNUNET_MessageHeader,
1557 op), 1481 op),
1558 GNUNET_MQ_hd_fixed_size (union_p2p_over, 1482 GNUNET_MQ_hd_fixed_size (union_p2p_over,
1559 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, 1483 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER,
1560 struct GNUNET_MessageHeader, 1484 struct GNUNET_MessageHeader,
1561 op), 1485 op),
1562 GNUNET_MQ_hd_fixed_size (union_p2p_full_done, 1486 GNUNET_MQ_hd_fixed_size (union_p2p_full_done,
1563 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, 1487 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE,
1564 struct GNUNET_MessageHeader, 1488 struct GNUNET_MessageHeader,
1565 op), 1489 op),
1566 GNUNET_MQ_hd_fixed_size (union_p2p_request_full, 1490 GNUNET_MQ_hd_fixed_size (union_p2p_request_full,
1567 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, 1491 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1568 struct GNUNET_MessageHeader, 1492 struct GNUNET_MessageHeader,
1569 op), 1493 op),
1570 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, 1494 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1571 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, 1495 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE,
1572 struct StrataEstimatorMessage, 1496 struct StrataEstimatorMessage,
1573 op), 1497 op),
1574 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, 1498 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1575 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, 1499 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC,
1576 struct StrataEstimatorMessage, 1500 struct StrataEstimatorMessage,
1577 op), 1501 op),
1578 GNUNET_MQ_hd_var_size (union_p2p_full_element, 1502 GNUNET_MQ_hd_var_size (union_p2p_full_element,
1579 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, 1503 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT,
1580 struct GNUNET_SET_ElementMessage, 1504 struct GNUNET_SET_ElementMessage,
1581 op), 1505 op),
1582 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, 1506 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info,
1583 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, 1507 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO,
1584 struct IntersectionElementInfoMessage, 1508 struct IntersectionElementInfoMessage,
1585 op), 1509 op),
1586 GNUNET_MQ_hd_var_size (intersection_p2p_bf, 1510 GNUNET_MQ_hd_var_size (intersection_p2p_bf,
1587 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, 1511 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF,
1588 struct BFMessage, 1512 struct BFMessage,
1589 op), 1513 op),
1590 GNUNET_MQ_hd_fixed_size (intersection_p2p_done, 1514 GNUNET_MQ_hd_fixed_size (intersection_p2p_done,
1591 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, 1515 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE,
1592 struct IntersectionDoneMessage, 1516 struct IntersectionDoneMessage,
1593 op), 1517 op),
1594 GNUNET_MQ_handler_end () 1518 GNUNET_MQ_handler_end ()};
1595 };
1596 struct Set *set; 1519 struct Set *set;
1597 const struct GNUNET_MessageHeader *context; 1520 const struct GNUNET_MessageHeader *context;
1598 1521
@@ -1603,8 +1526,7 @@ handle_client_evaluate (void *cls,
1603 GNUNET_SERVICE_client_drop (cs->client); 1526 GNUNET_SERVICE_client_drop (cs->client);
1604 return; 1527 return;
1605 } 1528 }
1606 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1529 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1607 UINT32_MAX);
1608 op->peer = msg->target_peer; 1530 op->peer = msg->target_peer;
1609 op->result_mode = ntohl (msg->result_mode); 1531 op->result_mode = ntohl (msg->result_mode);
1610 op->client_request_id = ntohl (msg->request_id); 1532 op->client_request_id = ntohl (msg->request_id);
@@ -1619,9 +1541,7 @@ handle_client_evaluate (void *cls,
1619 op->set = set; 1541 op->set = set;
1620 op->generation_created = set->current_generation; 1542 op->generation_created = set->current_generation;
1621 advance_generation (set); 1543 advance_generation (set);
1622 GNUNET_CONTAINER_DLL_insert (set->ops_head, 1544 GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op);
1623 set->ops_tail,
1624 op);
1625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1626 "Creating new CADET channel to port %s for set operation type %u\n", 1546 "Creating new CADET channel to port %s for set operation type %u\n",
1627 GNUNET_h2s (&msg->app_id), 1547 GNUNET_h2s (&msg->app_id),
@@ -1634,8 +1554,7 @@ handle_client_evaluate (void *cls,
1634 &channel_end_cb, 1554 &channel_end_cb,
1635 cadet_handlers); 1555 cadet_handlers);
1636 op->mq = GNUNET_CADET_get_mq (op->channel); 1556 op->mq = GNUNET_CADET_get_mq (op->channel);
1637 op->state = set->vt->evaluate (op, 1557 op->state = set->vt->evaluate (op, context);
1638 context);
1639 if (NULL == op->state) 1558 if (NULL == op->state)
1640 { 1559 {
1641 GNUNET_break (0); 1560 GNUNET_break (0);
@@ -1655,8 +1574,7 @@ handle_client_evaluate (void *cls,
1655 * @param ack the message 1574 * @param ack the message
1656 */ 1575 */
1657static void 1576static void
1658handle_client_iter_ack (void *cls, 1577handle_client_iter_ack (void *cls, const struct GNUNET_SET_IterAckMessage *ack)
1659 const struct GNUNET_SET_IterAckMessage *ack)
1660{ 1578{
1661 struct ClientState *cs = cls; 1579 struct ClientState *cs = cls;
1662 struct Set *set; 1580 struct Set *set;
@@ -1718,14 +1636,10 @@ handle_client_copy_lazy_prepare (void *cls,
1718 cr = GNUNET_new (struct LazyCopyRequest); 1636 cr = GNUNET_new (struct LazyCopyRequest);
1719 cr->cookie = ++lazy_copy_cookie; 1637 cr->cookie = ++lazy_copy_cookie;
1720 cr->source_set = set; 1638 cr->source_set = set;
1721 GNUNET_CONTAINER_DLL_insert (lazy_copy_head, 1639 GNUNET_CONTAINER_DLL_insert (lazy_copy_head, lazy_copy_tail, cr);
1722 lazy_copy_tail, 1640 ev = GNUNET_MQ_msg (resp_msg, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE);
1723 cr);
1724 ev = GNUNET_MQ_msg (resp_msg,
1725 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE);
1726 resp_msg->cookie = cr->cookie; 1641 resp_msg->cookie = cr->cookie;
1727 GNUNET_MQ_send (set->cs->mq, 1642 GNUNET_MQ_send (set->cs->mq, ev);
1728 ev);
1729 GNUNET_SERVICE_client_continue (cs->client); 1643 GNUNET_SERVICE_client_continue (cs->client);
1730} 1644}
1731 1645
@@ -1737,8 +1651,9 @@ handle_client_copy_lazy_prepare (void *cls,
1737 * @param msg the message 1651 * @param msg the message
1738 */ 1652 */
1739static void 1653static void
1740handle_client_copy_lazy_connect (void *cls, 1654handle_client_copy_lazy_connect (
1741 const struct GNUNET_SET_CopyLazyConnectMessage *msg) 1655 void *cls,
1656 const struct GNUNET_SET_CopyLazyConnectMessage *msg)
1742{ 1657{
1743 struct ClientState *cs = cls; 1658 struct ClientState *cs = cls;
1744 struct LazyCopyRequest *cr; 1659 struct LazyCopyRequest *cr;
@@ -1768,9 +1683,7 @@ handle_client_copy_lazy_connect (void *cls,
1768 GNUNET_SERVICE_client_drop (cs->client); 1683 GNUNET_SERVICE_client_drop (cs->client);
1769 return; 1684 return;
1770 } 1685 }
1771 GNUNET_CONTAINER_DLL_remove (lazy_copy_head, 1686 GNUNET_CONTAINER_DLL_remove (lazy_copy_head, lazy_copy_tail, cr);
1772 lazy_copy_tail,
1773 cr);
1774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1775 "Client %p requested use of lazy copy\n", 1688 "Client %p requested use of lazy copy\n",
1776 cs); 1689 cs);
@@ -1805,9 +1718,10 @@ handle_client_copy_lazy_connect (void *cls,
1805 1718
1806 set->current_generation = cr->source_set->current_generation; 1719 set->current_generation = cr->source_set->current_generation;
1807 set->excluded_generations_size = cr->source_set->excluded_generations_size; 1720 set->excluded_generations_size = cr->source_set->excluded_generations_size;
1808 set->excluded_generations 1721 set->excluded_generations =
1809 = GNUNET_memdup (cr->source_set->excluded_generations, 1722 GNUNET_memdup (cr->source_set->excluded_generations,
1810 set->excluded_generations_size * sizeof (struct GenerationRange)); 1723 set->excluded_generations_size *
1724 sizeof (struct GenerationRange));
1811 1725
1812 /* Advance the generation of the new set, so that mutations to the 1726 /* Advance the generation of the new set, so that mutations to the
1813 of the cloned set and the source set are independent. */ 1727 of the cloned set and the source set are independent. */
@@ -1826,8 +1740,7 @@ handle_client_copy_lazy_connect (void *cls,
1826 * @param msg the message 1740 * @param msg the message
1827 */ 1741 */
1828static void 1742static void
1829handle_client_cancel (void *cls, 1743handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg)
1830 const struct GNUNET_SET_CancelMessage *msg)
1831{ 1744{
1832 struct ClientState *cs = cls; 1745 struct ClientState *cs = cls;
1833 struct Set *set; 1746 struct Set *set;
@@ -1866,8 +1779,7 @@ handle_client_cancel (void *cls,
1866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1867 "Client requested cancel for op %u\n", 1780 "Client requested cancel for op %u\n",
1868 (uint32_t) ntohl (msg->request_id)); 1781 (uint32_t) ntohl (msg->request_id));
1869 _GSS_operation_destroy (op, 1782 _GSS_operation_destroy (op, GNUNET_YES);
1870 GNUNET_YES);
1871 } 1783 }
1872 GNUNET_SERVICE_client_continue (cs->client); 1784 GNUNET_SERVICE_client_continue (cs->client);
1873} 1785}
@@ -1882,8 +1794,7 @@ handle_client_cancel (void *cls,
1882 * @param msg the message 1794 * @param msg the message
1883 */ 1795 */
1884static void 1796static void
1885handle_client_accept (void *cls, 1797handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg)
1886 const struct GNUNET_SET_AcceptMessage *msg)
1887{ 1798{
1888 struct ClientState *cs = cls; 1799 struct ClientState *cs = cls;
1889 struct Set *set; 1800 struct Set *set;
@@ -1904,17 +1815,16 @@ handle_client_accept (void *cls,
1904 { 1815 {
1905 /* It is not an error if the set op does not exist -- it may 1816 /* It is not an error if the set op does not exist -- it may
1906 * have been destroyed when the partner peer disconnected. */ 1817 * have been destroyed when the partner peer disconnected. */
1907 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1818 GNUNET_log (
1908 "Client %p accepted request %u of listener %p that is no longer active\n", 1819 GNUNET_ERROR_TYPE_INFO,
1909 cs, 1820 "Client %p accepted request %u of listener %p that is no longer active\n",
1910 ntohl (msg->accept_reject_id), 1821 cs,
1911 cs->listener); 1822 ntohl (msg->accept_reject_id),
1912 ev = GNUNET_MQ_msg (result_message, 1823 cs->listener);
1913 GNUNET_MESSAGE_TYPE_SET_RESULT); 1824 ev = GNUNET_MQ_msg (result_message, GNUNET_MESSAGE_TYPE_SET_RESULT);
1914 result_message->request_id = msg->request_id; 1825 result_message->request_id = msg->request_id;
1915 result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE); 1826 result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE);
1916 GNUNET_MQ_send (set->cs->mq, 1827 GNUNET_MQ_send (set->cs->mq, ev);
1917 ev);
1918 GNUNET_SERVICE_client_continue (cs->client); 1828 GNUNET_SERVICE_client_continue (cs->client);
1919 return; 1829 return;
1920 } 1830 }
@@ -1923,13 +1833,9 @@ handle_client_accept (void *cls,
1923 (uint32_t) ntohl (msg->accept_reject_id)); 1833 (uint32_t) ntohl (msg->accept_reject_id));
1924 listener = op->listener; 1834 listener = op->listener;
1925 op->listener = NULL; 1835 op->listener = NULL;
1926 GNUNET_CONTAINER_DLL_remove (listener->op_head, 1836 GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op);
1927 listener->op_tail,
1928 op);
1929 op->set = set; 1837 op->set = set;
1930 GNUNET_CONTAINER_DLL_insert (set->ops_head, 1838 GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op);
1931 set->ops_tail,
1932 op);
1933 op->client_request_id = ntohl (msg->request_id); 1839 op->client_request_id = ntohl (msg->request_id);
1934 op->result_mode = ntohl (msg->result_mode); 1840 op->result_mode = ntohl (msg->result_mode);
1935 op->byzantine = msg->byzantine; 1841 op->byzantine = msg->byzantine;
@@ -1975,10 +1881,8 @@ shutdown_task (void *cls)
1975 cadet = NULL; 1881 cadet = NULL;
1976 } 1882 }
1977 } 1883 }
1978 GNUNET_STATISTICS_destroy (_GSS_statistics, 1884 GNUNET_STATISTICS_destroy (_GSS_statistics, GNUNET_YES);
1979 GNUNET_YES); 1885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n");
1980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1981 "handled shutdown request\n");
1982} 1886}
1983 1887
1984 1888
@@ -1998,15 +1902,13 @@ run (void *cls,
1998 /* FIXME: need to modify SERVICE (!) API to allow 1902 /* FIXME: need to modify SERVICE (!) API to allow
1999 us to run a shutdown task *after* clients were 1903 us to run a shutdown task *after* clients were
2000 forcefully disconnected! */ 1904 forcefully disconnected! */
2001 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1905 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
2002 NULL); 1906 _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg);
2003 _GSS_statistics = GNUNET_STATISTICS_create ("set",
2004 cfg);
2005 cadet = GNUNET_CADET_connect (cfg); 1907 cadet = GNUNET_CADET_connect (cfg);
2006 if (NULL == cadet) 1908 if (NULL == cadet)
2007 { 1909 {
2008 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1910 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2009 _("Could not connect to CADET service\n")); 1911 _ ("Could not connect to CADET service\n"));
2010 GNUNET_SCHEDULER_shutdown (); 1912 GNUNET_SCHEDULER_shutdown ();
2011 return; 1913 return;
2012 } 1914 }
@@ -2016,62 +1918,62 @@ run (void *cls,
2016/** 1918/**
2017 * Define "main" method using service macro. 1919 * Define "main" method using service macro.
2018 */ 1920 */
2019GNUNET_SERVICE_MAIN 1921GNUNET_SERVICE_MAIN (
2020("set", 1922 "set",
2021 GNUNET_SERVICE_OPTION_NONE, 1923 GNUNET_SERVICE_OPTION_NONE,
2022 &run, 1924 &run,
2023 &client_connect_cb, 1925 &client_connect_cb,
2024 &client_disconnect_cb, 1926 &client_disconnect_cb,
2025 NULL, 1927 NULL,
2026 GNUNET_MQ_hd_fixed_size (client_accept, 1928 GNUNET_MQ_hd_fixed_size (client_accept,
2027 GNUNET_MESSAGE_TYPE_SET_ACCEPT, 1929 GNUNET_MESSAGE_TYPE_SET_ACCEPT,
2028 struct GNUNET_SET_AcceptMessage, 1930 struct GNUNET_SET_AcceptMessage,
2029 NULL), 1931 NULL),
2030 GNUNET_MQ_hd_fixed_size (client_iter_ack, 1932 GNUNET_MQ_hd_fixed_size (client_iter_ack,
2031 GNUNET_MESSAGE_TYPE_SET_ITER_ACK, 1933 GNUNET_MESSAGE_TYPE_SET_ITER_ACK,
2032 struct GNUNET_SET_IterAckMessage, 1934 struct GNUNET_SET_IterAckMessage,
2033 NULL), 1935 NULL),
2034 GNUNET_MQ_hd_var_size (client_mutation, 1936 GNUNET_MQ_hd_var_size (client_mutation,
2035 GNUNET_MESSAGE_TYPE_SET_ADD, 1937 GNUNET_MESSAGE_TYPE_SET_ADD,
2036 struct GNUNET_SET_ElementMessage, 1938 struct GNUNET_SET_ElementMessage,
2037 NULL), 1939 NULL),
2038 GNUNET_MQ_hd_fixed_size (client_create_set, 1940 GNUNET_MQ_hd_fixed_size (client_create_set,
2039 GNUNET_MESSAGE_TYPE_SET_CREATE, 1941 GNUNET_MESSAGE_TYPE_SET_CREATE,
2040 struct GNUNET_SET_CreateMessage, 1942 struct GNUNET_SET_CreateMessage,
2041 NULL), 1943 NULL),
2042 GNUNET_MQ_hd_fixed_size (client_iterate, 1944 GNUNET_MQ_hd_fixed_size (client_iterate,
2043 GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST, 1945 GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST,
2044 struct GNUNET_MessageHeader, 1946 struct GNUNET_MessageHeader,
2045 NULL), 1947 NULL),
2046 GNUNET_MQ_hd_var_size (client_evaluate, 1948 GNUNET_MQ_hd_var_size (client_evaluate,
2047 GNUNET_MESSAGE_TYPE_SET_EVALUATE, 1949 GNUNET_MESSAGE_TYPE_SET_EVALUATE,
2048 struct GNUNET_SET_EvaluateMessage, 1950 struct GNUNET_SET_EvaluateMessage,
2049 NULL), 1951 NULL),
2050 GNUNET_MQ_hd_fixed_size (client_listen, 1952 GNUNET_MQ_hd_fixed_size (client_listen,
2051 GNUNET_MESSAGE_TYPE_SET_LISTEN, 1953 GNUNET_MESSAGE_TYPE_SET_LISTEN,
2052 struct GNUNET_SET_ListenMessage, 1954 struct GNUNET_SET_ListenMessage,
2053 NULL), 1955 NULL),
2054 GNUNET_MQ_hd_fixed_size (client_reject, 1956 GNUNET_MQ_hd_fixed_size (client_reject,
2055 GNUNET_MESSAGE_TYPE_SET_REJECT, 1957 GNUNET_MESSAGE_TYPE_SET_REJECT,
2056 struct GNUNET_SET_RejectMessage, 1958 struct GNUNET_SET_RejectMessage,
2057 NULL), 1959 NULL),
2058 GNUNET_MQ_hd_var_size (client_mutation, 1960 GNUNET_MQ_hd_var_size (client_mutation,
2059 GNUNET_MESSAGE_TYPE_SET_REMOVE, 1961 GNUNET_MESSAGE_TYPE_SET_REMOVE,
2060 struct GNUNET_SET_ElementMessage, 1962 struct GNUNET_SET_ElementMessage,
2061 NULL), 1963 NULL),
2062 GNUNET_MQ_hd_fixed_size (client_cancel, 1964 GNUNET_MQ_hd_fixed_size (client_cancel,
2063 GNUNET_MESSAGE_TYPE_SET_CANCEL, 1965 GNUNET_MESSAGE_TYPE_SET_CANCEL,
2064 struct GNUNET_SET_CancelMessage, 1966 struct GNUNET_SET_CancelMessage,
2065 NULL), 1967 NULL),
2066 GNUNET_MQ_hd_fixed_size (client_copy_lazy_prepare, 1968 GNUNET_MQ_hd_fixed_size (client_copy_lazy_prepare,
2067 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE, 1969 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE,
2068 struct GNUNET_MessageHeader, 1970 struct GNUNET_MessageHeader,
2069 NULL), 1971 NULL),
2070 GNUNET_MQ_hd_fixed_size (client_copy_lazy_connect, 1972 GNUNET_MQ_hd_fixed_size (client_copy_lazy_connect,
2071 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT, 1973 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT,
2072 struct GNUNET_SET_CopyLazyConnectMessage, 1974 struct GNUNET_SET_CopyLazyConnectMessage,
2073 NULL), 1975 NULL),
2074 GNUNET_MQ_handler_end ()); 1976 GNUNET_MQ_handler_end ());
2075 1977
2076 1978
2077/* end of gnunet-service-set.c */ 1979/* end of gnunet-service-set.c */
diff --git a/src/util/mq.c b/src/util/mq.c
index c9cfad2bd..03b0f3a2a 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -1150,6 +1150,28 @@ GNUNET_MQ_destroy_notify_cancel (
1150 * @param[in|out] env element to insert at the tail 1150 * @param[in|out] env element to insert at the tail
1151 */ 1151 */
1152void 1152void
1153GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head,
1154 struct GNUNET_MQ_Envelope **env_tail,
1155 struct GNUNET_MQ_Envelope *env)
1156{
1157
1158 GNUNET_CONTAINER_DLL_insert (*env_head, *env_tail, env);
1159}
1160
1161
1162/**
1163 * Insert @a env into the envelope DLL starting at @a env_head
1164 * Note that @a env must not be in any MQ while this function
1165 * is used with DLLs defined outside of the MQ module. This
1166 * is just in case some application needs to also manage a
1167 * FIFO of envelopes independent of MQ itself and wants to
1168 * re-use the pointers internal to @a env. Use with caution.
1169 *
1170 * @param[in|out] env_head of envelope DLL
1171 * @param[in|out] env_tail tail of envelope DLL
1172 * @param[in|out] env element to insert at the tail
1173 */
1174void
1153GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head, 1175GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
1154 struct GNUNET_MQ_Envelope **env_tail, 1176 struct GNUNET_MQ_Envelope **env_tail,
1155 struct GNUNET_MQ_Envelope *env) 1177 struct GNUNET_MQ_Envelope *env)
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index 7bd26798e..e2d8a8e50 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.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
@@ -87,7 +87,6 @@ struct DestinationChannel
87 * Destination port this channel state is used for. 87 * Destination port this channel state is used for.
88 */ 88 */
89 uint16_t destination_port; 89 uint16_t destination_port;
90
91}; 90};
92 91
93 92
@@ -158,21 +157,20 @@ struct DestinationEntry
158 */ 157 */
159 union 158 union
160 { 159 {
161 /** 160 /**
162 * Address if af is AF_INET. 161 * Address if af is AF_INET.
163 */ 162 */
164 struct in_addr v4; 163 struct in_addr v4;
165 164
166 /** 165 /**
167 * Address if af is AF_INET6. 166 * Address if af is AF_INET6.
168 */ 167 */
169 struct in6_addr v6; 168 struct in6_addr v6;
170 } ip; 169 } ip;
171 170
172 } exit_destination; 171 } exit_destination;
173 172
174 } details; 173 } details;
175
176}; 174};
177 175
178 176
@@ -309,7 +307,6 @@ struct ChannelState
309 * Destination port used by the sender on our end; 0 for uninitialized. 307 * Destination port used by the sender on our end; 0 for uninitialized.
310 */ 308 */
311 uint16_t destination_port; 309 uint16_t destination_port;
312
313}; 310};
314 311
315 312
@@ -394,20 +391,16 @@ static unsigned long long max_channel_mappings;
394 */ 391 */
395static void 392static void
396get_destination_key_from_ip (int af, 393get_destination_key_from_ip (int af,
397 const void *address, 394 const void *address,
398 struct GNUNET_HashCode *key) 395 struct GNUNET_HashCode *key)
399{ 396{
400 switch (af) 397 switch (af)
401 { 398 {
402 case AF_INET: 399 case AF_INET:
403 GNUNET_CRYPTO_hash (address, 400 GNUNET_CRYPTO_hash (address, sizeof (struct in_addr), key);
404 sizeof (struct in_addr),
405 key);
406 break; 401 break;
407 case AF_INET6: 402 case AF_INET6:
408 GNUNET_CRYPTO_hash (address, 403 GNUNET_CRYPTO_hash (address, sizeof (struct in6_addr), key);
409 sizeof (struct in6_addr),
410 key);
411 break; 404 break;
412 default: 405 default:
413 GNUNET_assert (0); 406 GNUNET_assert (0);
@@ -442,7 +435,7 @@ get_channel_key_from_ips (int af,
442 memset (key, 0, sizeof (struct GNUNET_HashCode)); 435 memset (key, 0, sizeof (struct GNUNET_HashCode));
443 /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash, 436 /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash,
444 so we put the ports in there (and hope for few collisions) */ 437 so we put the ports in there (and hope for few collisions) */
445 off = (char*) key; 438 off = (char *) key;
446 GNUNET_memcpy (off, &source_port, sizeof (uint16_t)); 439 GNUNET_memcpy (off, &source_port, sizeof (uint16_t));
447 off += sizeof (uint16_t); 440 off += sizeof (uint16_t);
448 GNUNET_memcpy (off, &destination_port, sizeof (uint16_t)); 441 GNUNET_memcpy (off, &destination_port, sizeof (uint16_t));
@@ -480,9 +473,9 @@ get_channel_key_from_ips (int af,
480 */ 473 */
481static void 474static void
482send_client_reply (struct GNUNET_SERVICE_Client *client, 475send_client_reply (struct GNUNET_SERVICE_Client *client,
483 uint64_t request_id, 476 uint64_t request_id,
484 int result_af, 477 int result_af,
485 const void *addr) 478 const void *addr)
486{ 479{
487 struct GNUNET_MQ_Envelope *env; 480 struct GNUNET_MQ_Envelope *env;
488 struct RedirectToIpResponseMessage *res; 481 struct RedirectToIpResponseMessage *res;
@@ -503,16 +496,11 @@ send_client_reply (struct GNUNET_SERVICE_Client *client,
503 GNUNET_assert (0); 496 GNUNET_assert (0);
504 return; 497 return;
505 } 498 }
506 env = GNUNET_MQ_msg_extra (res, 499 env = GNUNET_MQ_msg_extra (res, rlen, GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP);
507 rlen,
508 GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP);
509 res->result_af = htonl (result_af); 500 res->result_af = htonl (result_af);
510 res->request_id = request_id; 501 res->request_id = request_id;
511 GNUNET_memcpy (&res[1], 502 GNUNET_memcpy (&res[1], addr, rlen);
512 addr, 503 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
513 rlen);
514 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
515 env);
516} 504}
517 505
518 506
@@ -528,8 +516,7 @@ free_channel_state (struct ChannelState *ts)
528 struct ChannelMessageQueueEntry *tnq; 516 struct ChannelMessageQueueEntry *tnq;
529 struct GNUNET_CADET_Channel *channel; 517 struct GNUNET_CADET_Channel *channel;
530 518
531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up channel state\n");
532 "Cleaning up channel state\n");
533 if (NULL != (channel = ts->channel)) 520 if (NULL != (channel = ts->channel))
534 { 521 {
535 ts->channel = NULL; 522 ts->channel = NULL;
@@ -537,13 +524,12 @@ free_channel_state (struct ChannelState *ts)
537 return; 524 return;
538 } 525 }
539 GNUNET_STATISTICS_update (stats, 526 GNUNET_STATISTICS_update (stats,
540 gettext_noop ("# Active channels"), 527 gettext_noop ("# Active channels"),
541 -1, GNUNET_NO); 528 -1,
529 GNUNET_NO);
542 while (NULL != (tnq = ts->tmq_head)) 530 while (NULL != (tnq = ts->tmq_head))
543 { 531 {
544 GNUNET_CONTAINER_DLL_remove (ts->tmq_head, 532 GNUNET_CONTAINER_DLL_remove (ts->tmq_head, ts->tmq_tail, tnq);
545 ts->tmq_tail,
546 tnq);
547 ts->tmq_length--; 533 ts->tmq_length--;
548 GNUNET_free (tnq); 534 GNUNET_free (tnq);
549 } 535 }
@@ -559,16 +545,15 @@ free_channel_state (struct ChannelState *ts)
559 GNUNET_CONTAINER_heap_remove_node (ts->heap_node); 545 GNUNET_CONTAINER_heap_remove_node (ts->heap_node);
560 ts->heap_node = NULL; 546 ts->heap_node = NULL;
561 get_channel_key_from_ips (ts->af, 547 get_channel_key_from_ips (ts->af,
562 ts->protocol, 548 ts->protocol,
563 &ts->source_ip, 549 &ts->source_ip,
564 ts->source_port, 550 ts->source_port,
565 &ts->destination_ip, 551 &ts->destination_ip,
566 ts->destination_port, 552 ts->destination_port,
567 &key); 553 &key);
568 GNUNET_assert (GNUNET_YES == 554 GNUNET_assert (
569 GNUNET_CONTAINER_multihashmap_remove (channel_map, 555 GNUNET_YES ==
570 &key, 556 GNUNET_CONTAINER_multihashmap_remove (channel_map, &key, ts));
571 ts));
572 } 557 }
573 GNUNET_free (ts); 558 GNUNET_free (ts);
574} 559}
@@ -582,25 +567,25 @@ free_channel_state (struct ChannelState *ts)
582 * @param env message to queue 567 * @param env message to queue
583 */ 568 */
584static void 569static void
585send_to_channel (struct ChannelState *ts, 570send_to_channel (struct ChannelState *ts, struct GNUNET_MQ_Envelope *env)
586 struct GNUNET_MQ_Envelope *env)
587{ 571{
588 struct GNUNET_MQ_Handle *mq; 572 struct GNUNET_MQ_Handle *mq;
589 573
590 GNUNET_assert (NULL != ts->channel); 574 GNUNET_assert (NULL != ts->channel);
591 mq = GNUNET_CADET_get_mq (ts->channel); 575 mq = GNUNET_CADET_get_mq (ts->channel);
592 GNUNET_MQ_env_set_options(env, 576 GNUNET_MQ_env_set_options (env,
593 GNUNET_MQ_PREF_DEFAULT); 577 GNUNET_MQ_PRIO_BEST_EFFORT |
594 GNUNET_MQ_send (mq, 578 GNUNET_MQ_PREF_OUT_OF_ORDER);
595 env); 579 GNUNET_MQ_send (mq, env);
596 if (GNUNET_MQ_get_length (mq) > MAX_MESSAGE_QUEUE_SIZE) 580 if (GNUNET_MQ_get_length (mq) > MAX_MESSAGE_QUEUE_SIZE)
597 { 581 {
598 env = GNUNET_MQ_unsent_head (mq); 582 env = GNUNET_MQ_unsent_head (mq);
599 GNUNET_assert (NULL != env); 583 GNUNET_assert (NULL != env);
600 GNUNET_STATISTICS_update (stats, 584 GNUNET_STATISTICS_update (stats,
601 gettext_noop ("# Messages dropped in cadet queue (overflow)"), 585 gettext_noop (
602 1, 586 "# Messages dropped in cadet queue (overflow)"),
603 GNUNET_NO); 587 1,
588 GNUNET_NO);
604 GNUNET_MQ_discard (env); 589 GNUNET_MQ_discard (env);
605 } 590 }
606} 591}
@@ -623,7 +608,8 @@ print_channel_destination (const struct DestinationEntry *de)
623 sizeof (dest), 608 sizeof (dest),
624 "HS: %s-%s", 609 "HS: %s-%s",
625 GNUNET_i2s (&de->details.service_destination.target), 610 GNUNET_i2s (&de->details.service_destination.target),
626 GNUNET_h2s (&de->details.service_destination.service_descriptor)); 611 GNUNET_h2s (
612 &de->details.service_destination.service_descriptor));
627 } 613 }
628 else 614 else
629 { 615 {
@@ -644,14 +630,14 @@ print_channel_destination (const struct DestinationEntry *de)
644 * @param channel connection to the other end (henceforth invalid) 630 * @param channel connection to the other end (henceforth invalid)
645 */ 631 */
646static void 632static void
647channel_cleaner (void *cls, 633channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel)
648 const struct GNUNET_CADET_Channel *channel)
649{ 634{
650 struct ChannelState *ts = cls; 635 struct ChannelState *ts = cls;
651 636
652 ts->channel = NULL; /* we must not call GNUNET_CADET_channel_destroy() anymore */ 637 ts->channel =
638 NULL; /* we must not call GNUNET_CADET_channel_destroy() anymore */
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
654 "CADET notified us about death of channel to `%s'\n", 640 "CADET notified us about death of channel to `%s'\n",
655 print_channel_destination (&ts->destination)); 641 print_channel_destination (&ts->destination));
656 free_channel_state (ts); 642 free_channel_state (ts);
657} 643}
@@ -668,14 +654,14 @@ channel_cleaner (void *cls,
668 */ 654 */
669static void 655static void
670make_up_icmpv4_payload (struct ChannelState *ts, 656make_up_icmpv4_payload (struct ChannelState *ts,
671 struct GNUNET_TUN_IPv4Header *ipp, 657 struct GNUNET_TUN_IPv4Header *ipp,
672 struct GNUNET_TUN_UdpHeader *udp) 658 struct GNUNET_TUN_UdpHeader *udp)
673{ 659{
674 GNUNET_TUN_initialize_ipv4_header (ipp, 660 GNUNET_TUN_initialize_ipv4_header (ipp,
675 ts->protocol, 661 ts->protocol,
676 sizeof (struct GNUNET_TUN_TcpHeader), 662 sizeof (struct GNUNET_TUN_TcpHeader),
677 &ts->source_ip.v4, 663 &ts->source_ip.v4,
678 &ts->destination_ip.v4); 664 &ts->destination_ip.v4);
679 udp->source_port = htons (ts->source_port); 665 udp->source_port = htons (ts->source_port);
680 udp->destination_port = htons (ts->destination_port); 666 udp->destination_port = htons (ts->destination_port);
681 udp->len = htons (0); 667 udp->len = htons (0);
@@ -694,14 +680,14 @@ make_up_icmpv4_payload (struct ChannelState *ts,
694 */ 680 */
695static void 681static void
696make_up_icmpv6_payload (struct ChannelState *ts, 682make_up_icmpv6_payload (struct ChannelState *ts,
697 struct GNUNET_TUN_IPv6Header *ipp, 683 struct GNUNET_TUN_IPv6Header *ipp,
698 struct GNUNET_TUN_UdpHeader *udp) 684 struct GNUNET_TUN_UdpHeader *udp)
699{ 685{
700 GNUNET_TUN_initialize_ipv6_header (ipp, 686 GNUNET_TUN_initialize_ipv6_header (ipp,
701 ts->protocol, 687 ts->protocol,
702 sizeof (struct GNUNET_TUN_TcpHeader), 688 sizeof (struct GNUNET_TUN_TcpHeader),
703 &ts->source_ip.v6, 689 &ts->source_ip.v6,
704 &ts->destination_ip.v6); 690 &ts->destination_ip.v6);
705 udp->source_port = htons (ts->source_port); 691 udp->source_port = htons (ts->source_port);
706 udp->destination_port = htons (ts->destination_port); 692 udp->destination_port = htons (ts->destination_port);
707 udp->len = htons (0); 693 udp->len = htons (0);
@@ -718,8 +704,7 @@ make_up_icmpv6_payload (struct ChannelState *ts,
718 * #GNUNET_SYSERR to close it (signal serious error) 704 * #GNUNET_SYSERR to close it (signal serious error)
719 */ 705 */
720static int 706static int
721check_icmp_back (void *cls, 707check_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
722 const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
723{ 708{
724 struct ChannelState *ts = cls; 709 struct ChannelState *ts = cls;
725 710
@@ -745,309 +730,323 @@ check_icmp_back (void *cls,
745 * @param message the actual message 730 * @param message the actual message
746 */ 731 */
747static void 732static void
748handle_icmp_back (void *cls, 733handle_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
749 const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
750{ 734{
751 struct ChannelState *ts = cls; 735 struct ChannelState *ts = cls;
752 size_t mlen; 736 size_t mlen;
753 737
754 GNUNET_STATISTICS_update (stats, 738 GNUNET_STATISTICS_update (stats,
755 gettext_noop ("# ICMP packets received from cadet"), 739 gettext_noop ("# ICMP packets received from cadet"),
756 1, 740 1,
757 GNUNET_NO); 741 GNUNET_NO);
758 mlen = ntohs (i2v->header.size) - sizeof (struct GNUNET_EXIT_IcmpToVPNMessage); 742 mlen =
743 ntohs (i2v->header.size) - sizeof (struct GNUNET_EXIT_IcmpToVPNMessage);
759 { 744 {
760 char sbuf[INET6_ADDRSTRLEN]; 745 char sbuf[INET6_ADDRSTRLEN];
761 char dbuf[INET6_ADDRSTRLEN]; 746 char dbuf[INET6_ADDRSTRLEN];
762 747
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 748 GNUNET_log (
764 "Received ICMP packet from cadet, sending %u bytes from %s -> %s via TUN\n", 749 GNUNET_ERROR_TYPE_DEBUG,
765 (unsigned int) mlen, 750 "Received ICMP packet from cadet, sending %u bytes from %s -> %s via TUN\n",
766 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), 751 (unsigned int) mlen,
767 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf))); 752 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)),
753 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)));
768 } 754 }
769 switch (ts->af) 755 switch (ts->af)
770 { 756 {
771 case AF_INET: 757 case AF_INET: {
758 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) +
759 sizeof (struct GNUNET_TUN_IcmpHeader) +
760 sizeof (struct GNUNET_MessageHeader) +
761 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
772 { 762 {
773 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) 763 /* reserve some extra space in case we have an ICMP type here where
774 + sizeof (struct GNUNET_TUN_IcmpHeader)
775 + sizeof (struct GNUNET_MessageHeader) +
776 sizeof (struct GNUNET_TUN_Layer2PacketHeader) +
777 mlen;
778 {
779 /* reserve some extra space in case we have an ICMP type here where
780 we will need to make up the payload ourselves */ 764 we will need to make up the payload ourselves */
781 char buf[size + sizeof (struct GNUNET_TUN_IPv4Header) + 8] GNUNET_ALIGN; 765 char buf[size + sizeof (struct GNUNET_TUN_IPv4Header) + 8] GNUNET_ALIGN;
782 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 766 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
783 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 767 struct GNUNET_TUN_Layer2PacketHeader *tun =
784 struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; 768 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
785 struct GNUNET_TUN_IcmpHeader *icmp = (struct GNUNET_TUN_IcmpHeader *) &ipv4[1]; 769 struct GNUNET_TUN_IPv4Header *ipv4 =
786 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 770 (struct GNUNET_TUN_IPv4Header *) &tun[1];
787 tun->flags = htons (0); 771 struct GNUNET_TUN_IcmpHeader *icmp =
788 tun->proto = htons (ETH_P_IPV4); 772 (struct GNUNET_TUN_IcmpHeader *) &ipv4[1];
789 GNUNET_TUN_initialize_ipv4_header (ipv4, 773 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
790 IPPROTO_ICMP, 774 tun->flags = htons (0);
791 sizeof (struct GNUNET_TUN_IcmpHeader) + mlen, 775 tun->proto = htons (ETH_P_IPV4);
792 &ts->destination_ip.v4, 776 GNUNET_TUN_initialize_ipv4_header (ipv4,
793 &ts->source_ip.v4); 777 IPPROTO_ICMP,
794 *icmp = i2v->icmp_header; 778 sizeof (struct GNUNET_TUN_IcmpHeader) +
795 GNUNET_memcpy (&icmp[1], 779 mlen,
796 &i2v[1], 780 &ts->destination_ip.v4,
797 mlen); 781 &ts->source_ip.v4);
798 /* For some ICMP types, we need to adjust (make up) the payload here. 782 *icmp = i2v->icmp_header;
783 GNUNET_memcpy (&icmp[1], &i2v[1], mlen);
784 /* For some ICMP types, we need to adjust (make up) the payload here.
799 Also, depending on the AF used on the other side, we have to 785 Also, depending on the AF used on the other side, we have to
800 do ICMP PT (translate ICMP types) */ 786 do ICMP PT (translate ICMP types) */
801 switch (ntohl (i2v->af)) 787 switch (ntohl (i2v->af))
802 { 788 {
803 case AF_INET: 789 case AF_INET:
804 switch (icmp->type) 790 switch (icmp->type)
805 { 791 {
806 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 792 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
807 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 793 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
808 break; 794 break;
809 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 795 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
810 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 796 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
811 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 797 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: {
812 { 798 struct GNUNET_TUN_IPv4Header *ipp =
813 struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; 799 (struct GNUNET_TUN_IPv4Header *) &icmp[1];
814 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 800 struct GNUNET_TUN_UdpHeader *udp =
815 801 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
816 if (mlen != 0) 802
817 { 803 if (mlen != 0)
818 /* sender did not strip ICMP payload? */ 804 {
819 GNUNET_break_op (0); 805 /* sender did not strip ICMP payload? */
820 return; 806 GNUNET_break_op (0);
821 } 807 return;
822 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; 808 }
823 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 809 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8;
824 make_up_icmpv4_payload (ts, ipp, udp); 810 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
825 } 811 make_up_icmpv4_payload (ts, ipp, udp);
826 break; 812 }
827 default: 813 break;
828 GNUNET_break_op (0); 814 default:
829 GNUNET_STATISTICS_update (stats, 815 GNUNET_break_op (0);
830 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), 816 GNUNET_STATISTICS_update (
831 1, GNUNET_NO); 817 stats,
832 return; 818 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
833 } 819 1,
834 /* end AF_INET */ 820 GNUNET_NO);
835 break; 821 return;
836 case AF_INET6: 822 }
837 /* ICMP PT 6-to-4 and possibly making up payloads */ 823 /* end AF_INET */
838 switch (icmp->type) 824 break;
839 { 825 case AF_INET6:
840 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 826 /* ICMP PT 6-to-4 and possibly making up payloads */
841 icmp->type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; 827 switch (icmp->type)
842 { 828 {
843 struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; 829 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
844 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 830 icmp->type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE;
845 831 {
846 if (mlen != 0) 832 struct GNUNET_TUN_IPv4Header *ipp =
847 { 833 (struct GNUNET_TUN_IPv4Header *) &icmp[1];
848 /* sender did not strip ICMP payload? */ 834 struct GNUNET_TUN_UdpHeader *udp =
849 GNUNET_break_op (0); 835 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
850 return; 836
851 } 837 if (mlen != 0)
852 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; 838 {
853 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 839 /* sender did not strip ICMP payload? */
854 make_up_icmpv4_payload (ts, ipp, udp); 840 GNUNET_break_op (0);
855 } 841 return;
856 break; 842 }
857 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 843 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8;
858 icmp->type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; 844 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
859 { 845 make_up_icmpv4_payload (ts, ipp, udp);
860 struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; 846 }
861 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 847 break;
862 848 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
863 if (mlen != 0) 849 icmp->type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED;
864 { 850 {
865 /* sender did not strip ICMP payload? */ 851 struct GNUNET_TUN_IPv4Header *ipp =
866 GNUNET_break_op (0); 852 (struct GNUNET_TUN_IPv4Header *) &icmp[1];
867 return; 853 struct GNUNET_TUN_UdpHeader *udp =
868 } 854 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
869 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; 855
870 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 856 if (mlen != 0)
871 make_up_icmpv4_payload (ts, ipp, udp); 857 {
872 } 858 /* sender did not strip ICMP payload? */
873 break; 859 GNUNET_break_op (0);
874 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 860 return;
875 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 861 }
876 GNUNET_STATISTICS_update (stats, 862 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8;
877 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), 863 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
878 1, GNUNET_NO); 864 make_up_icmpv4_payload (ts, ipp, udp);
879 return; 865 }
880 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 866 break;
881 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; 867 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
882 break; 868 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
883 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: 869 GNUNET_STATISTICS_update (
884 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; 870 stats,
885 break; 871 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"),
886 default: 872 1,
887 GNUNET_break_op (0); 873 GNUNET_NO);
888 GNUNET_STATISTICS_update (stats, 874 return;
889 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), 875 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
890 1, GNUNET_NO); 876 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST;
891 return; 877 break;
892 } 878 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
893 /* end AF_INET6 */ 879 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY;
894 break; 880 break;
895 default: 881 default:
896 GNUNET_break_op (0); 882 GNUNET_break_op (0);
897 return; 883 GNUNET_STATISTICS_update (
898 } 884 stats,
899 msg->size = htons (size); 885 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"),
900 GNUNET_TUN_calculate_icmp_checksum (icmp, 886 1,
901 &i2v[1], 887 GNUNET_NO);
902 mlen); 888 return;
903 (void) GNUNET_HELPER_send (helper_handle, 889 }
904 msg, 890 /* end AF_INET6 */
905 GNUNET_YES, 891 break;
906 NULL, NULL); 892 default:
893 GNUNET_break_op (0);
894 return;
907 } 895 }
896 msg->size = htons (size);
897 GNUNET_TUN_calculate_icmp_checksum (icmp, &i2v[1], mlen);
898 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
908 } 899 }
909 break; 900 }
910 case AF_INET6: 901 break;
902 case AF_INET6: {
903 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) +
904 sizeof (struct GNUNET_TUN_IcmpHeader) +
905 sizeof (struct GNUNET_MessageHeader) +
906 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
911 { 907 {
912 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) 908 char buf[size + sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN;
913 + sizeof (struct GNUNET_TUN_IcmpHeader) 909 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
914 + sizeof (struct GNUNET_MessageHeader) + 910 struct GNUNET_TUN_Layer2PacketHeader *tun =
915 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 911 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
916 mlen; 912 struct GNUNET_TUN_IPv6Header *ipv6 =
917 { 913 (struct GNUNET_TUN_IPv6Header *) &tun[1];
918 char buf[size + sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; 914 struct GNUNET_TUN_IcmpHeader *icmp =
919 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 915 (struct GNUNET_TUN_IcmpHeader *) &ipv6[1];
920 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 916 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
921 struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; 917 tun->flags = htons (0);
922 struct GNUNET_TUN_IcmpHeader *icmp = (struct GNUNET_TUN_IcmpHeader *) &ipv6[1]; 918 tun->proto = htons (ETH_P_IPV6);
923 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 919 GNUNET_TUN_initialize_ipv6_header (ipv6,
924 tun->flags = htons (0); 920 IPPROTO_ICMPV6,
925 tun->proto = htons (ETH_P_IPV6); 921 sizeof (struct GNUNET_TUN_IcmpHeader) +
926 GNUNET_TUN_initialize_ipv6_header (ipv6, 922 mlen,
927 IPPROTO_ICMPV6, 923 &ts->destination_ip.v6,
928 sizeof (struct GNUNET_TUN_IcmpHeader) + mlen, 924 &ts->source_ip.v6);
929 &ts->destination_ip.v6, 925 *icmp = i2v->icmp_header;
930 &ts->source_ip.v6); 926 GNUNET_memcpy (&icmp[1], &i2v[1], mlen);
931 *icmp = i2v->icmp_header; 927
932 GNUNET_memcpy (&icmp[1], 928 /* For some ICMP types, we need to adjust (make up) the payload here.
933 &i2v[1],
934 mlen);
935
936 /* For some ICMP types, we need to adjust (make up) the payload here.
937 Also, depending on the AF used on the other side, we have to 929 Also, depending on the AF used on the other side, we have to
938 do ICMP PT (translate ICMP types) */ 930 do ICMP PT (translate ICMP types) */
939 switch (ntohl (i2v->af)) 931 switch (ntohl (i2v->af))
940 { 932 {
941 case AF_INET: 933 case AF_INET:
942 /* ICMP PT 4-to-6 and possibly making up payloads */ 934 /* ICMP PT 4-to-6 and possibly making up payloads */
943 switch (icmp->type) 935 switch (icmp->type)
944 { 936 {
945 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 937 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
946 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; 938 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY;
947 break; 939 break;
948 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 940 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
949 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; 941 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST;
950 break; 942 break;
951 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 943 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
952 icmp->type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; 944 icmp->type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE;
953 { 945 {
954 struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; 946 struct GNUNET_TUN_IPv6Header *ipp =
955 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 947 (struct GNUNET_TUN_IPv6Header *) &icmp[1];
956 948 struct GNUNET_TUN_UdpHeader *udp =
957 if (mlen != 0) 949 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
958 { 950
959 /* sender did not strip ICMP payload? */ 951 if (mlen != 0)
960 GNUNET_break_op (0); 952 {
961 return; 953 /* sender did not strip ICMP payload? */
962 } 954 GNUNET_break_op (0);
963 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; 955 return;
964 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 956 }
965 make_up_icmpv6_payload (ts, ipp, udp); 957 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8;
966 } 958 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
967 break; 959 make_up_icmpv6_payload (ts, ipp, udp);
968 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 960 }
969 icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; 961 break;
970 { 962 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
971 struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; 963 icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED;
972 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 964 {
973 965 struct GNUNET_TUN_IPv6Header *ipp =
974 if (mlen != 0) 966 (struct GNUNET_TUN_IPv6Header *) &icmp[1];
975 { 967 struct GNUNET_TUN_UdpHeader *udp =
976 /* sender did not strip ICMP payload? */ 968 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
977 GNUNET_break_op (0); 969
978 return; 970 if (mlen != 0)
979 } 971 {
980 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; 972 /* sender did not strip ICMP payload? */
981 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 973 GNUNET_break_op (0);
982 make_up_icmpv6_payload (ts, ipp, udp); 974 return;
983 } 975 }
984 break; 976 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8;
985 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 977 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
986 GNUNET_STATISTICS_update (stats, 978 make_up_icmpv6_payload (ts, ipp, udp);
987 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), 979 }
988 1, GNUNET_NO); 980 break;
989 return; 981 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
990 default: 982 GNUNET_STATISTICS_update (
991 GNUNET_break_op (0); 983 stats,
992 GNUNET_STATISTICS_update (stats, 984 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"),
993 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), 985 1,
994 1, GNUNET_NO); 986 GNUNET_NO);
995 return; 987 return;
996 } 988 default:
997 /* end AF_INET */ 989 GNUNET_break_op (0);
998 break; 990 GNUNET_STATISTICS_update (
999 case AF_INET6: 991 stats,
1000 switch (icmp->type) 992 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
1001 { 993 1,
1002 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 994 GNUNET_NO);
1003 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 995 return;
1004 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 996 }
1005 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 997 /* end AF_INET */
1006 { 998 break;
1007 struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; 999 case AF_INET6:
1008 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 1000 switch (icmp->type)
1009 1001 {
1010 if (mlen != 0) 1002 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
1011 { 1003 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
1012 /* sender did not strip ICMP payload? */ 1004 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
1013 GNUNET_break_op (0); 1005 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: {
1014 return; 1006 struct GNUNET_TUN_IPv6Header *ipp =
1015 } 1007 (struct GNUNET_TUN_IPv6Header *) &icmp[1];
1016 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; 1008 struct GNUNET_TUN_UdpHeader *udp =
1017 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 1009 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
1018 make_up_icmpv6_payload (ts, ipp, udp); 1010
1019 } 1011 if (mlen != 0)
1020 break; 1012 {
1021 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 1013 /* sender did not strip ICMP payload? */
1022 break; 1014 GNUNET_break_op (0);
1023 default: 1015 return;
1024 GNUNET_break_op (0); 1016 }
1025 GNUNET_STATISTICS_update (stats, 1017 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8;
1026 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), 1018 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
1027 1, GNUNET_NO); 1019 make_up_icmpv6_payload (ts, ipp, udp);
1028 return; 1020 }
1029 } 1021 break;
1030 /* end AF_INET6 */ 1022 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
1031 break; 1023 break;
1032 default: 1024 default:
1033 GNUNET_break_op (0); 1025 GNUNET_break_op (0);
1034 return; 1026 GNUNET_STATISTICS_update (
1035 } 1027 stats,
1036 msg->size = htons (size); 1028 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"),
1037 GNUNET_TUN_calculate_icmp_checksum (icmp, 1029 1,
1038 &i2v[1], mlen); 1030 GNUNET_NO);
1039 (void) GNUNET_HELPER_send (helper_handle, 1031 return;
1040 msg, 1032 }
1041 GNUNET_YES, 1033 /* end AF_INET6 */
1042 NULL, NULL); 1034 break;
1035 default:
1036 GNUNET_break_op (0);
1037 return;
1043 } 1038 }
1039 msg->size = htons (size);
1040 GNUNET_TUN_calculate_icmp_checksum (icmp, &i2v[1], mlen);
1041 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1044 } 1042 }
1045 break; 1043 }
1044 break;
1046 default: 1045 default:
1047 GNUNET_assert (0); 1046 GNUNET_assert (0);
1048 } 1047 }
1049 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1048 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1050 GNUNET_TIME_absolute_get ().abs_value_us); 1049 GNUNET_TIME_absolute_get ().abs_value_us);
1051 GNUNET_CADET_receive_done (ts->channel); 1050 GNUNET_CADET_receive_done (ts->channel);
1052} 1051}
1053 1052
@@ -1061,8 +1060,7 @@ handle_icmp_back (void *cls,
1061 * #GNUNET_SYSERR to close it (signal serious error) 1060 * #GNUNET_SYSERR to close it (signal serious error)
1062 */ 1061 */
1063static int 1062static int
1064check_udp_back (void *cls, 1063check_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply)
1065 const struct GNUNET_EXIT_UdpReplyMessage *reply)
1066{ 1064{
1067 struct ChannelState *ts = cls; 1065 struct ChannelState *ts = cls;
1068 1066
@@ -1088,125 +1086,115 @@ check_udp_back (void *cls,
1088 * @param reply the actual message 1086 * @param reply the actual message
1089 */ 1087 */
1090static void 1088static void
1091handle_udp_back (void *cls, 1089handle_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply)
1092 const struct GNUNET_EXIT_UdpReplyMessage *reply)
1093{ 1090{
1094 struct ChannelState *ts = cls; 1091 struct ChannelState *ts = cls;
1095 size_t mlen; 1092 size_t mlen;
1096 1093
1097 GNUNET_STATISTICS_update (stats, 1094 GNUNET_STATISTICS_update (stats,
1098 gettext_noop ("# UDP packets received from cadet"), 1095 gettext_noop ("# UDP packets received from cadet"),
1099 1, 1096 1,
1100 GNUNET_NO); 1097 GNUNET_NO);
1101 mlen = ntohs (reply->header.size) - sizeof (struct GNUNET_EXIT_UdpReplyMessage); 1098 mlen =
1099 ntohs (reply->header.size) - sizeof (struct GNUNET_EXIT_UdpReplyMessage);
1102 { 1100 {
1103 char sbuf[INET6_ADDRSTRLEN]; 1101 char sbuf[INET6_ADDRSTRLEN];
1104 char dbuf[INET6_ADDRSTRLEN]; 1102 char dbuf[INET6_ADDRSTRLEN];
1105 1103
1106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1104 GNUNET_log (
1107 "Received UDP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", 1105 GNUNET_ERROR_TYPE_DEBUG,
1108 (unsigned int) mlen, 1106 "Received UDP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n",
1109 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), 1107 (unsigned int) mlen,
1110 ts->destination_port, 1108 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)),
1111 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)), 1109 ts->destination_port,
1112 ts->source_port); 1110 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)),
1111 ts->source_port);
1113 } 1112 }
1114 switch (ts->af) 1113 switch (ts->af)
1115 { 1114 {
1116 case AF_INET: 1115 case AF_INET: {
1116 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) +
1117 sizeof (struct GNUNET_TUN_UdpHeader) +
1118 sizeof (struct GNUNET_MessageHeader) +
1119 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
1117 { 1120 {
1118 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) 1121 char buf[size] GNUNET_ALIGN;
1119 + sizeof (struct GNUNET_TUN_UdpHeader) 1122 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1120 + sizeof (struct GNUNET_MessageHeader) + 1123 struct GNUNET_TUN_Layer2PacketHeader *tun =
1121 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1124 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1122 mlen; 1125 struct GNUNET_TUN_IPv4Header *ipv4 =
1123 { 1126 (struct GNUNET_TUN_IPv4Header *) &tun[1];
1124 char buf[size] GNUNET_ALIGN; 1127 struct GNUNET_TUN_UdpHeader *udp =
1125 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1128 (struct GNUNET_TUN_UdpHeader *) &ipv4[1];
1126 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1129 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1127 struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; 1130 msg->size = htons (size);
1128 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipv4[1]; 1131 tun->flags = htons (0);
1129 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1132 tun->proto = htons (ETH_P_IPV4);
1130 msg->size = htons (size); 1133 GNUNET_TUN_initialize_ipv4_header (ipv4,
1131 tun->flags = htons (0); 1134 IPPROTO_UDP,
1132 tun->proto = htons (ETH_P_IPV4); 1135 sizeof (struct GNUNET_TUN_UdpHeader) +
1133 GNUNET_TUN_initialize_ipv4_header (ipv4, 1136 mlen,
1134 IPPROTO_UDP, 1137 &ts->destination_ip.v4,
1135 sizeof (struct GNUNET_TUN_UdpHeader) + mlen, 1138 &ts->source_ip.v4);
1136 &ts->destination_ip.v4, 1139 if (0 == ntohs (reply->source_port))
1137 &ts->source_ip.v4); 1140 udp->source_port = htons (ts->destination_port);
1138 if (0 == ntohs (reply->source_port)) 1141 else
1139 udp->source_port = htons (ts->destination_port); 1142 udp->source_port = reply->source_port;
1140 else 1143 if (0 == ntohs (reply->destination_port))
1141 udp->source_port = reply->source_port; 1144 udp->destination_port = htons (ts->source_port);
1142 if (0 == ntohs (reply->destination_port)) 1145 else
1143 udp->destination_port = htons (ts->source_port); 1146 udp->destination_port = reply->destination_port;
1144 else 1147 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader));
1145 udp->destination_port = reply->destination_port; 1148 GNUNET_TUN_calculate_udp4_checksum (ipv4, udp, &reply[1], mlen);
1146 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); 1149 GNUNET_memcpy (&udp[1], &reply[1], mlen);
1147 GNUNET_TUN_calculate_udp4_checksum (ipv4, 1150 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1148 udp,
1149 &reply[1],
1150 mlen);
1151 GNUNET_memcpy (&udp[1],
1152 &reply[1],
1153 mlen);
1154 (void) GNUNET_HELPER_send (helper_handle,
1155 msg,
1156 GNUNET_YES,
1157 NULL, NULL);
1158 }
1159 } 1151 }
1160 break; 1152 }
1161 case AF_INET6: 1153 break;
1154 case AF_INET6: {
1155 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) +
1156 sizeof (struct GNUNET_TUN_UdpHeader) +
1157 sizeof (struct GNUNET_MessageHeader) +
1158 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
1162 { 1159 {
1163 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) 1160 char buf[size] GNUNET_ALIGN;
1164 + sizeof (struct GNUNET_TUN_UdpHeader) 1161 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1165 + sizeof (struct GNUNET_MessageHeader) + 1162 struct GNUNET_TUN_Layer2PacketHeader *tun =
1166 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1163 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1167 mlen; 1164 struct GNUNET_TUN_IPv6Header *ipv6 =
1168 { 1165 (struct GNUNET_TUN_IPv6Header *) &tun[1];
1169 char buf[size] GNUNET_ALIGN; 1166 struct GNUNET_TUN_UdpHeader *udp =
1170 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1167 (struct GNUNET_TUN_UdpHeader *) &ipv6[1];
1171 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1168 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1172 struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; 1169 msg->size = htons (size);
1173 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipv6[1]; 1170 tun->flags = htons (0);
1174 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1171 tun->proto = htons (ETH_P_IPV6);
1175 msg->size = htons (size); 1172 GNUNET_TUN_initialize_ipv6_header (ipv6,
1176 tun->flags = htons (0); 1173 IPPROTO_UDP,
1177 tun->proto = htons (ETH_P_IPV6); 1174 sizeof (struct GNUNET_TUN_UdpHeader) +
1178 GNUNET_TUN_initialize_ipv6_header (ipv6, 1175 mlen,
1179 IPPROTO_UDP, 1176 &ts->destination_ip.v6,
1180 sizeof (struct GNUNET_TUN_UdpHeader) + mlen, 1177 &ts->source_ip.v6);
1181 &ts->destination_ip.v6, 1178 if (0 == ntohs (reply->source_port))
1182 &ts->source_ip.v6); 1179 udp->source_port = htons (ts->destination_port);
1183 if (0 == ntohs (reply->source_port)) 1180 else
1184 udp->source_port = htons (ts->destination_port); 1181 udp->source_port = reply->source_port;
1185 else 1182 if (0 == ntohs (reply->destination_port))
1186 udp->source_port = reply->source_port; 1183 udp->destination_port = htons (ts->source_port);
1187 if (0 == ntohs (reply->destination_port)) 1184 else
1188 udp->destination_port = htons (ts->source_port); 1185 udp->destination_port = reply->destination_port;
1189 else 1186 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader));
1190 udp->destination_port = reply->destination_port; 1187 GNUNET_TUN_calculate_udp6_checksum (ipv6, udp, &reply[1], mlen);
1191 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); 1188 GNUNET_memcpy (&udp[1], &reply[1], mlen);
1192 GNUNET_TUN_calculate_udp6_checksum (ipv6, 1189 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1193 udp,
1194 &reply[1], mlen);
1195 GNUNET_memcpy (&udp[1],
1196 &reply[1],
1197 mlen);
1198 (void) GNUNET_HELPER_send (helper_handle,
1199 msg,
1200 GNUNET_YES,
1201 NULL, NULL);
1202 }
1203 } 1190 }
1204 break; 1191 }
1192 break;
1205 default: 1193 default:
1206 GNUNET_assert (0); 1194 GNUNET_assert (0);
1207 } 1195 }
1208 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1196 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1209 GNUNET_TIME_absolute_get ().abs_value_us); 1197 GNUNET_TIME_absolute_get ().abs_value_us);
1210 GNUNET_CADET_receive_done (ts->channel); 1198 GNUNET_CADET_receive_done (ts->channel);
1211} 1199}
1212 1200
@@ -1220,8 +1208,7 @@ handle_udp_back (void *cls,
1220 * #GNUNET_SYSERR to close it (signal serious error) 1208 * #GNUNET_SYSERR to close it (signal serious error)
1221 */ 1209 */
1222static int 1210static int
1223check_tcp_back (void *cls, 1211check_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data)
1224 const struct GNUNET_EXIT_TcpDataMessage *data)
1225{ 1212{
1226 struct ChannelState *ts = cls; 1213 struct ChannelState *ts = cls;
1227 1214
@@ -1247,112 +1234,100 @@ check_tcp_back (void *cls,
1247 * @param data the actual message 1234 * @param data the actual message
1248 */ 1235 */
1249static void 1236static void
1250handle_tcp_back (void *cls, 1237handle_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data)
1251 const struct GNUNET_EXIT_TcpDataMessage *data)
1252{ 1238{
1253 struct ChannelState *ts = cls; 1239 struct ChannelState *ts = cls;
1254 size_t mlen; 1240 size_t mlen;
1255 1241
1256 GNUNET_STATISTICS_update (stats, 1242 GNUNET_STATISTICS_update (stats,
1257 gettext_noop ("# TCP packets received from cadet"), 1243 gettext_noop ("# TCP packets received from cadet"),
1258 1, 1244 1,
1259 GNUNET_NO); 1245 GNUNET_NO);
1260 mlen = ntohs (data->header.size) - sizeof (struct GNUNET_EXIT_TcpDataMessage); 1246 mlen = ntohs (data->header.size) - sizeof (struct GNUNET_EXIT_TcpDataMessage);
1261 { 1247 {
1262 char sbuf[INET6_ADDRSTRLEN]; 1248 char sbuf[INET6_ADDRSTRLEN];
1263 char dbuf[INET6_ADDRSTRLEN]; 1249 char dbuf[INET6_ADDRSTRLEN];
1264 1250
1265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1251 GNUNET_log (
1266 "Received TCP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", 1252 GNUNET_ERROR_TYPE_DEBUG,
1267 (unsigned int) mlen, 1253 "Received TCP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n",
1268 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), 1254 (unsigned int) mlen,
1269 ts->destination_port, 1255 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)),
1270 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)), 1256 ts->destination_port,
1271 ts->source_port); 1257 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)),
1258 ts->source_port);
1272 } 1259 }
1273 switch (ts->af) 1260 switch (ts->af)
1274 { 1261 {
1275 case AF_INET: 1262 case AF_INET: {
1263 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) +
1264 sizeof (struct GNUNET_TUN_TcpHeader) +
1265 sizeof (struct GNUNET_MessageHeader) +
1266 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
1276 { 1267 {
1277 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) 1268 char buf[size] GNUNET_ALIGN;
1278 + sizeof (struct GNUNET_TUN_TcpHeader) 1269 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1279 + sizeof (struct GNUNET_MessageHeader) + 1270 struct GNUNET_TUN_Layer2PacketHeader *tun =
1280 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1271 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1281 mlen; 1272 struct GNUNET_TUN_IPv4Header *ipv4 =
1282 { 1273 (struct GNUNET_TUN_IPv4Header *) &tun[1];
1283 char buf[size] GNUNET_ALIGN; 1274 struct GNUNET_TUN_TcpHeader *tcp =
1284 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1275 (struct GNUNET_TUN_TcpHeader *) &ipv4[1];
1285 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1276 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1286 struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; 1277 msg->size = htons (size);
1287 struct GNUNET_TUN_TcpHeader *tcp = (struct GNUNET_TUN_TcpHeader *) &ipv4[1]; 1278 tun->flags = htons (0);
1288 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1279 tun->proto = htons (ETH_P_IPV4);
1289 msg->size = htons (size); 1280 GNUNET_TUN_initialize_ipv4_header (ipv4,
1290 tun->flags = htons (0); 1281 IPPROTO_TCP,
1291 tun->proto = htons (ETH_P_IPV4); 1282 sizeof (struct GNUNET_TUN_TcpHeader) +
1292 GNUNET_TUN_initialize_ipv4_header (ipv4, 1283 mlen,
1293 IPPROTO_TCP, 1284 &ts->destination_ip.v4,
1294 sizeof (struct GNUNET_TUN_TcpHeader) + mlen, 1285 &ts->source_ip.v4);
1295 &ts->destination_ip.v4, 1286 *tcp = data->tcp_header;
1296 &ts->source_ip.v4); 1287 tcp->source_port = htons (ts->destination_port);
1297 *tcp = data->tcp_header; 1288 tcp->destination_port = htons (ts->source_port);
1298 tcp->source_port = htons (ts->destination_port); 1289 GNUNET_TUN_calculate_tcp4_checksum (ipv4, tcp, &data[1], mlen);
1299 tcp->destination_port = htons (ts->source_port); 1290 GNUNET_memcpy (&tcp[1], &data[1], mlen);
1300 GNUNET_TUN_calculate_tcp4_checksum (ipv4, 1291 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1301 tcp,
1302 &data[1],
1303 mlen);
1304 GNUNET_memcpy (&tcp[1],
1305 &data[1],
1306 mlen);
1307 (void) GNUNET_HELPER_send (helper_handle,
1308 msg,
1309 GNUNET_YES,
1310 NULL, NULL);
1311 }
1312 } 1292 }
1313 break; 1293 }
1314 case AF_INET6: 1294 break;
1295 case AF_INET6: {
1296 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) +
1297 sizeof (struct GNUNET_TUN_TcpHeader) +
1298 sizeof (struct GNUNET_MessageHeader) +
1299 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
1315 { 1300 {
1316 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) 1301 char buf[size] GNUNET_ALIGN;
1317 + sizeof (struct GNUNET_TUN_TcpHeader) 1302 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1318 + sizeof (struct GNUNET_MessageHeader) + 1303 struct GNUNET_TUN_Layer2PacketHeader *tun =
1319 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1304 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1320 mlen; 1305 struct GNUNET_TUN_IPv6Header *ipv6 =
1321 { 1306 (struct GNUNET_TUN_IPv6Header *) &tun[1];
1322 char buf[size] GNUNET_ALIGN; 1307 struct GNUNET_TUN_TcpHeader *tcp =
1323 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1308 (struct GNUNET_TUN_TcpHeader *) &ipv6[1];
1324 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1309 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1325 struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; 1310 msg->size = htons (size);
1326 struct GNUNET_TUN_TcpHeader *tcp = (struct GNUNET_TUN_TcpHeader *) &ipv6[1]; 1311 tun->flags = htons (0);
1327 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1312 tun->proto = htons (ETH_P_IPV6);
1328 msg->size = htons (size); 1313 GNUNET_TUN_initialize_ipv6_header (ipv6,
1329 tun->flags = htons (0); 1314 IPPROTO_TCP,
1330 tun->proto = htons (ETH_P_IPV6); 1315 sizeof (struct GNUNET_TUN_TcpHeader) +
1331 GNUNET_TUN_initialize_ipv6_header (ipv6, 1316 mlen,
1332 IPPROTO_TCP, 1317 &ts->destination_ip.v6,
1333 sizeof (struct GNUNET_TUN_TcpHeader) + mlen, 1318 &ts->source_ip.v6);
1334 &ts->destination_ip.v6, 1319 *tcp = data->tcp_header;
1335 &ts->source_ip.v6); 1320 tcp->source_port = htons (ts->destination_port);
1336 *tcp = data->tcp_header; 1321 tcp->destination_port = htons (ts->source_port);
1337 tcp->source_port = htons (ts->destination_port); 1322 GNUNET_TUN_calculate_tcp6_checksum (ipv6, tcp, &data[1], mlen);
1338 tcp->destination_port = htons (ts->source_port); 1323 GNUNET_memcpy (&tcp[1], &data[1], mlen);
1339 GNUNET_TUN_calculate_tcp6_checksum (ipv6, 1324 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1340 tcp,
1341 &data[1],
1342 mlen);
1343 GNUNET_memcpy (&tcp[1],
1344 &data[1],
1345 mlen);
1346 (void) GNUNET_HELPER_send (helper_handle,
1347 msg,
1348 GNUNET_YES,
1349 NULL, NULL);
1350 }
1351 } 1325 }
1352 break; 1326 }
1327 break;
1353 } 1328 }
1354 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1329 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1355 GNUNET_TIME_absolute_get ().abs_value_us); 1330 GNUNET_TIME_absolute_get ().abs_value_us);
1356 GNUNET_CADET_receive_done (ts->channel); 1331 GNUNET_CADET_receive_done (ts->channel);
1357} 1332}
1358 1333
@@ -1370,21 +1345,20 @@ create_channel (struct ChannelState *ts,
1370 const struct GNUNET_PeerIdentity *target, 1345 const struct GNUNET_PeerIdentity *target,
1371 const struct GNUNET_HashCode *port) 1346 const struct GNUNET_HashCode *port)
1372{ 1347{
1373 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1348 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1374 GNUNET_MQ_hd_var_size (udp_back, 1349 {GNUNET_MQ_hd_var_size (udp_back,
1375 GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY, 1350 GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY,
1376 struct GNUNET_EXIT_UdpReplyMessage, 1351 struct GNUNET_EXIT_UdpReplyMessage,
1377 ts), 1352 ts),
1378 GNUNET_MQ_hd_var_size (tcp_back, 1353 GNUNET_MQ_hd_var_size (tcp_back,
1379 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN, 1354 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN,
1380 struct GNUNET_EXIT_TcpDataMessage, 1355 struct GNUNET_EXIT_TcpDataMessage,
1381 ts), 1356 ts),
1382 GNUNET_MQ_hd_var_size (icmp_back, 1357 GNUNET_MQ_hd_var_size (icmp_back,
1383 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN, 1358 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN,
1384 struct GNUNET_EXIT_IcmpToVPNMessage, 1359 struct GNUNET_EXIT_IcmpToVPNMessage,
1385 ts), 1360 ts),
1386 GNUNET_MQ_handler_end() 1361 GNUNET_MQ_handler_end ()};
1387 };
1388 1362
1389 return GNUNET_CADET_channel_create (cadet_handle, 1363 return GNUNET_CADET_channel_create (cadet_handle,
1390 ts, 1364 ts,
@@ -1408,11 +1382,11 @@ create_channel (struct ChannelState *ts,
1408 */ 1382 */
1409static void 1383static void
1410handle_regex_result (void *cls, 1384handle_regex_result (void *cls,
1411 const struct GNUNET_PeerIdentity *id, 1385 const struct GNUNET_PeerIdentity *id,
1412 const struct GNUNET_PeerIdentity *get_path, 1386 const struct GNUNET_PeerIdentity *get_path,
1413 unsigned int get_path_length, 1387 unsigned int get_path_length,
1414 const struct GNUNET_PeerIdentity *put_path, 1388 const struct GNUNET_PeerIdentity *put_path,
1415 unsigned int put_path_length) 1389 unsigned int put_path_length)
1416{ 1390{
1417 struct ChannelState *ts = cls; 1391 struct ChannelState *ts = cls;
1418 struct GNUNET_HashCode port; 1392 struct GNUNET_HashCode port;
@@ -1445,9 +1419,7 @@ handle_regex_result (void *cls,
1445 "Creating tunnel to %s for destination %s!\n", 1419 "Creating tunnel to %s for destination %s!\n",
1446 GNUNET_i2s (id), 1420 GNUNET_i2s (id),
1447 print_channel_destination (&ts->destination)); 1421 print_channel_destination (&ts->destination));
1448 ts->channel = create_channel (ts, 1422 ts->channel = create_channel (ts, id, &port);
1449 id,
1450 &port);
1451} 1423}
1452 1424
1453 1425
@@ -1459,14 +1431,13 @@ handle_regex_result (void *cls,
1459 * @return channel state of the channel that was created 1431 * @return channel state of the channel that was created
1460 */ 1432 */
1461static struct ChannelState * 1433static struct ChannelState *
1462create_channel_to_destination (struct DestinationChannel *dt, 1434create_channel_to_destination (struct DestinationChannel *dt, int client_af)
1463 int client_af)
1464{ 1435{
1465 struct ChannelState *ts; 1436 struct ChannelState *ts;
1466 1437
1467 GNUNET_STATISTICS_update (stats, 1438 GNUNET_STATISTICS_update (stats,
1468 gettext_noop ("# Cadet channels created"), 1439 gettext_noop ("# Cadet channels created"),
1469 1, 1440 1,
1470 GNUNET_NO); 1441 GNUNET_NO);
1471 ts = GNUNET_new (struct ChannelState); 1442 ts = GNUNET_new (struct ChannelState);
1472 ts->af = client_af; 1443 ts->af = client_af;
@@ -1477,12 +1448,15 @@ create_channel_to_destination (struct DestinationChannel *dt,
1477 { 1448 {
1478 struct GNUNET_HashCode cadet_port; 1449 struct GNUNET_HashCode cadet_port;
1479 1450
1480 GNUNET_TUN_compute_service_cadet_port (&ts->destination.details.service_destination.service_descriptor, 1451 GNUNET_TUN_compute_service_cadet_port (&ts->destination.details
1452 .service_destination
1453 .service_descriptor,
1481 ts->destination_port, 1454 ts->destination_port,
1482 &cadet_port); 1455 &cadet_port);
1483 ts->channel = create_channel (ts, 1456 ts->channel =
1484 &dt->destination->details.service_destination.target, 1457 create_channel (ts,
1485 &cadet_port); 1458 &dt->destination->details.service_destination.target,
1459 &cadet_port);
1486 1460
1487 if (NULL == ts->channel) 1461 if (NULL == ts->channel)
1488 { 1462 {
@@ -1491,9 +1465,11 @@ create_channel_to_destination (struct DestinationChannel *dt,
1491 return NULL; 1465 return NULL;
1492 } 1466 }
1493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1494 "Creating channel to peer %s offering service %s on port %u\n", 1468 "Creating channel to peer %s offering service %s on port %u\n",
1495 GNUNET_i2s (&dt->destination->details.service_destination.target), 1469 GNUNET_i2s (
1496 GNUNET_h2s (&ts->destination.details.service_destination.service_descriptor), 1470 &dt->destination->details.service_destination.target),
1471 GNUNET_h2s (&ts->destination.details.service_destination
1472 .service_descriptor),
1497 (unsigned int) ts->destination_port); 1473 (unsigned int) ts->destination_port);
1498 } 1474 }
1499 else 1475 else
@@ -1502,25 +1478,25 @@ create_channel_to_destination (struct DestinationChannel *dt,
1502 1478
1503 switch (dt->destination->details.exit_destination.af) 1479 switch (dt->destination->details.exit_destination.af)
1504 { 1480 {
1505 case AF_INET: 1481 case AF_INET: {
1506 {
1507 char address[GNUNET_TUN_IPV4_REGEXLEN]; 1482 char address[GNUNET_TUN_IPV4_REGEXLEN];
1508 1483
1509 GNUNET_TUN_ipv4toregexsearch (&dt->destination->details.exit_destination.ip.v4, 1484 GNUNET_TUN_ipv4toregexsearch (&dt->destination->details.exit_destination
1510 dt->destination_port, 1485 .ip.v4,
1511 address); 1486 dt->destination_port,
1487 address);
1512 GNUNET_asprintf (&policy, 1488 GNUNET_asprintf (&policy,
1513 "%s%s", 1489 "%s%s",
1514 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, 1490 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
1515 address); 1491 address);
1516 break; 1492 break;
1517 } 1493 }
1518 case AF_INET6: 1494 case AF_INET6: {
1519 {
1520 char address[GNUNET_TUN_IPV6_REGEXLEN]; 1495 char address[GNUNET_TUN_IPV6_REGEXLEN];
1521 1496
1522 GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination.ip.v6, 1497 GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination
1523 dt->destination_port, 1498 .ip.v6,
1499 dt->destination_port,
1524 address); 1500 address);
1525 GNUNET_asprintf (&policy, 1501 GNUNET_asprintf (&policy,
1526 "%s%s", 1502 "%s%s",
@@ -1534,12 +1510,9 @@ create_channel_to_destination (struct DestinationChannel *dt,
1534 } 1510 }
1535 1511
1536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1537 "Requesting connect by string: %s\n", 1513 "Requesting connect by string: %s\n",
1538 policy); 1514 policy);
1539 ts->search = GNUNET_REGEX_search (cfg, 1515 ts->search = GNUNET_REGEX_search (cfg, policy, &handle_regex_result, ts);
1540 policy,
1541 &handle_regex_result,
1542 ts);
1543 GNUNET_free (policy); 1516 GNUNET_free (policy);
1544 } 1517 }
1545 return ts; 1518 return ts;
@@ -1580,12 +1553,12 @@ expire_channel (struct ChannelState *except)
1580 */ 1553 */
1581static void 1554static void
1582route_packet (struct DestinationEntry *destination, 1555route_packet (struct DestinationEntry *destination,
1583 int af, 1556 int af,
1584 uint8_t protocol, 1557 uint8_t protocol,
1585 const void *source_ip, 1558 const void *source_ip,
1586 const void *destination_ip, 1559 const void *destination_ip,
1587 const void *payload, 1560 const void *payload,
1588 size_t payload_length) 1561 size_t payload_length)
1589{ 1562{
1590 struct GNUNET_HashCode key; 1563 struct GNUNET_HashCode key;
1591 struct ChannelState *ts; 1564 struct ChannelState *ts;
@@ -1601,92 +1574,89 @@ route_packet (struct DestinationEntry *destination,
1601 1574
1602 switch (protocol) 1575 switch (protocol)
1603 { 1576 {
1604 case IPPROTO_UDP: 1577 case IPPROTO_UDP: {
1578 if (payload_length < sizeof (struct GNUNET_TUN_UdpHeader))
1605 { 1579 {
1606 if (payload_length < sizeof (struct GNUNET_TUN_UdpHeader)) 1580 /* blame kernel? */
1607 { 1581 GNUNET_break (0);
1608 /* blame kernel? */ 1582 return;
1609 GNUNET_break (0);
1610 return;
1611 }
1612 tcp = NULL; /* make compiler happy */
1613 icmp = NULL; /* make compiler happy */
1614 udp = payload;
1615 if (udp->len < sizeof (struct GNUNET_TUN_UdpHeader))
1616 {
1617 GNUNET_break_op (0);
1618 return;
1619 }
1620 source_port = ntohs (udp->source_port);
1621 destination_port = ntohs (udp->destination_port);
1622 get_channel_key_from_ips (af,
1623 IPPROTO_UDP,
1624 source_ip,
1625 source_port,
1626 destination_ip,
1627 destination_port,
1628 &key);
1629 } 1583 }
1630 break; 1584 tcp = NULL; /* make compiler happy */
1631 case IPPROTO_TCP: 1585 icmp = NULL; /* make compiler happy */
1586 udp = payload;
1587 if (udp->len < sizeof (struct GNUNET_TUN_UdpHeader))
1632 { 1588 {
1633 if (payload_length < sizeof (struct GNUNET_TUN_TcpHeader)) 1589 GNUNET_break_op (0);
1634 { 1590 return;
1635 /* blame kernel? */
1636 GNUNET_break (0);
1637 return;
1638 }
1639 udp = NULL; /* make compiler happy */
1640 icmp = NULL; /* make compiler happy */
1641 tcp = payload;
1642 if (tcp->off * 4 < sizeof (struct GNUNET_TUN_TcpHeader))
1643 {
1644 GNUNET_break_op (0);
1645 return;
1646 }
1647 source_port = ntohs (tcp->source_port);
1648 destination_port = ntohs (tcp->destination_port);
1649 get_channel_key_from_ips (af,
1650 IPPROTO_TCP,
1651 source_ip,
1652 source_port,
1653 destination_ip,
1654 destination_port,
1655 &key);
1656 } 1591 }
1657 break; 1592 source_port = ntohs (udp->source_port);
1593 destination_port = ntohs (udp->destination_port);
1594 get_channel_key_from_ips (af,
1595 IPPROTO_UDP,
1596 source_ip,
1597 source_port,
1598 destination_ip,
1599 destination_port,
1600 &key);
1601 }
1602 break;
1603 case IPPROTO_TCP: {
1604 if (payload_length < sizeof (struct GNUNET_TUN_TcpHeader))
1605 {
1606 /* blame kernel? */
1607 GNUNET_break (0);
1608 return;
1609 }
1610 udp = NULL; /* make compiler happy */
1611 icmp = NULL; /* make compiler happy */
1612 tcp = payload;
1613 if (tcp->off * 4 < sizeof (struct GNUNET_TUN_TcpHeader))
1614 {
1615 GNUNET_break_op (0);
1616 return;
1617 }
1618 source_port = ntohs (tcp->source_port);
1619 destination_port = ntohs (tcp->destination_port);
1620 get_channel_key_from_ips (af,
1621 IPPROTO_TCP,
1622 source_ip,
1623 source_port,
1624 destination_ip,
1625 destination_port,
1626 &key);
1627 }
1628 break;
1658 case IPPROTO_ICMP: 1629 case IPPROTO_ICMP:
1659 case IPPROTO_ICMPV6: 1630 case IPPROTO_ICMPV6: {
1631 if ((AF_INET == af) ^ (protocol == IPPROTO_ICMP))
1660 { 1632 {
1661 if ( (AF_INET == af) ^ (protocol == IPPROTO_ICMP) ) 1633 GNUNET_break (0);
1662 { 1634 return;
1663 GNUNET_break (0);
1664 return;
1665 }
1666 if (payload_length < sizeof (struct GNUNET_TUN_IcmpHeader))
1667 {
1668 /* blame kernel? */
1669 GNUNET_break (0);
1670 return;
1671 }
1672 tcp = NULL; /* make compiler happy */
1673 udp = NULL; /* make compiler happy */
1674 icmp = payload;
1675 source_port = 0;
1676 destination_port = 0;
1677 get_channel_key_from_ips (af,
1678 protocol,
1679 source_ip,
1680 0,
1681 destination_ip,
1682 0,
1683 &key);
1684 } 1635 }
1685 break; 1636 if (payload_length < sizeof (struct GNUNET_TUN_IcmpHeader))
1637 {
1638 /* blame kernel? */
1639 GNUNET_break (0);
1640 return;
1641 }
1642 tcp = NULL; /* make compiler happy */
1643 udp = NULL; /* make compiler happy */
1644 icmp = payload;
1645 source_port = 0;
1646 destination_port = 0;
1647 get_channel_key_from_ips (af,
1648 protocol,
1649 source_ip,
1650 0,
1651 destination_ip,
1652 0,
1653 &key);
1654 }
1655 break;
1686 default: 1656 default:
1687 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1657 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1688 _("Protocol %u not supported, dropping\n"), 1658 _ ("Protocol %u not supported, dropping\n"),
1689 (unsigned int) protocol); 1659 (unsigned int) protocol);
1690 return; 1660 return;
1691 } 1661 }
1692 alen = 0; 1662 alen = 0;
@@ -1696,7 +1666,7 @@ route_packet (struct DestinationEntry *destination,
1696 { 1666 {
1697 case AF_INET: 1667 case AF_INET:
1698 alen = sizeof (struct in_addr); 1668 alen = sizeof (struct in_addr);
1699 break; 1669 break;
1700 case AF_INET6: 1670 case AF_INET6:
1701 alen = sizeof (struct in6_addr); 1671 alen = sizeof (struct in6_addr);
1702 break; 1672 break;
@@ -1709,27 +1679,23 @@ route_packet (struct DestinationEntry *destination,
1709 char dbuf[INET6_ADDRSTRLEN]; 1679 char dbuf[INET6_ADDRSTRLEN];
1710 char xbuf[INET6_ADDRSTRLEN]; 1680 char xbuf[INET6_ADDRSTRLEN];
1711 1681
1712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1682 GNUNET_log (
1713 "Routing %s packet from [%s]:%u -> [%s]:%u to destination [%s]:%u\n", 1683 GNUNET_ERROR_TYPE_DEBUG,
1714 (protocol == IPPROTO_TCP) ? "TCP" : "UDP", 1684 "Routing %s packet from [%s]:%u -> [%s]:%u to destination [%s]:%u\n",
1715 inet_ntop (af, 1685 (protocol == IPPROTO_TCP) ? "TCP" : "UDP",
1716 source_ip, 1686 inet_ntop (af, source_ip, sbuf, sizeof (sbuf)),
1717 sbuf, 1687 source_port,
1718 sizeof (sbuf)), 1688 inet_ntop (af, destination_ip, dbuf, sizeof (dbuf)),
1719 source_port, 1689 destination_port,
1720 inet_ntop (af, 1690 inet_ntop (destination->details.exit_destination.af,
1721 destination_ip, 1691 &destination->details.exit_destination.ip,
1722 dbuf, 1692 xbuf,
1723 sizeof (dbuf)), 1693 sizeof (xbuf)),
1724 destination_port, 1694 destination_port);
1725 inet_ntop (destination->details.exit_destination.af,
1726 &destination->details.exit_destination.ip,
1727 xbuf, sizeof (xbuf)),
1728 destination_port);
1729 } 1695 }
1730 for (dt = destination->dt_head; NULL != dt; dt = dt->next) 1696 for (dt = destination->dt_head; NULL != dt; dt = dt->next)
1731 if (dt->destination_port == destination_port) 1697 if (dt->destination_port == destination_port)
1732 break; 1698 break;
1733 } 1699 }
1734 else 1700 else
1735 { 1701 {
@@ -1737,39 +1703,34 @@ route_packet (struct DestinationEntry *destination,
1737 char sbuf[INET6_ADDRSTRLEN]; 1703 char sbuf[INET6_ADDRSTRLEN];
1738 char dbuf[INET6_ADDRSTRLEN]; 1704 char dbuf[INET6_ADDRSTRLEN];
1739 1705
1740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1706 GNUNET_log (
1741 "Routing %s packet from [%s]:%u -> [%s]:%u to service %s at peer %s\n", 1707 GNUNET_ERROR_TYPE_DEBUG,
1742 (protocol == IPPROTO_TCP) ? "TCP" : "UDP", 1708 "Routing %s packet from [%s]:%u -> [%s]:%u to service %s at peer %s\n",
1743 inet_ntop (af, 1709 (protocol == IPPROTO_TCP) ? "TCP" : "UDP",
1744 source_ip, 1710 inet_ntop (af, source_ip, sbuf, sizeof (sbuf)),
1745 sbuf, 1711 source_port,
1746 sizeof (sbuf)), 1712 inet_ntop (af, destination_ip, dbuf, sizeof (dbuf)),
1747 source_port, 1713 destination_port,
1748 inet_ntop (af, 1714 GNUNET_h2s (
1749 destination_ip, 1715 &destination->details.service_destination.service_descriptor),
1750 dbuf, 1716 GNUNET_i2s (&destination->details.service_destination.target));
1751 sizeof (dbuf)),
1752 destination_port,
1753 GNUNET_h2s (&destination->details.service_destination.service_descriptor),
1754 GNUNET_i2s (&destination->details.service_destination.target));
1755 } 1717 }
1756 for (dt = destination->dt_head; NULL != dt; dt = dt->next) 1718 for (dt = destination->dt_head; NULL != dt; dt = dt->next)
1757 if (dt->destination_port == destination_port) 1719 if (dt->destination_port == destination_port)
1758 break; 1720 break;
1759 } 1721 }
1760 if (NULL == dt) 1722 if (NULL == dt)
1761 { 1723 {
1762 dt = GNUNET_new (struct DestinationChannel); 1724 dt = GNUNET_new (struct DestinationChannel);
1763 dt->destination = destination; 1725 dt->destination = destination;
1764 GNUNET_CONTAINER_DLL_insert (destination->dt_head, 1726 GNUNET_CONTAINER_DLL_insert (destination->dt_head,
1765 destination->dt_tail, 1727 destination->dt_tail,
1766 dt); 1728 dt);
1767 dt->destination_port = destination_port; 1729 dt->destination_port = destination_port;
1768 } 1730 }
1769 1731
1770 /* see if we have an existing channel for this destination */ 1732 /* see if we have an existing channel for this destination */
1771 ts = GNUNET_CONTAINER_multihashmap_get (channel_map, 1733 ts = GNUNET_CONTAINER_multihashmap_get (channel_map, &key);
1772 &key);
1773 if (NULL == ts) 1734 if (NULL == ts)
1774 { 1735 {
1775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1777,8 +1738,7 @@ route_packet (struct DestinationEntry *destination,
1777 GNUNET_h2s (&key)); 1738 GNUNET_h2s (&key));
1778 /* need to either use the existing channel from the destination (if still 1739 /* need to either use the existing channel from the destination (if still
1779 available) or create a fresh one */ 1740 available) or create a fresh one */
1780 ts = create_channel_to_destination (dt, 1741 ts = create_channel_to_destination (dt, af);
1781 af);
1782 if (NULL == ts) 1742 if (NULL == ts)
1783 return; 1743 return;
1784 /* now bind existing "unbound" channel to our IP/port tuple */ 1744 /* now bind existing "unbound" channel to our IP/port tuple */
@@ -1786,46 +1746,51 @@ route_packet (struct DestinationEntry *destination,
1786 ts->af = af; 1746 ts->af = af;
1787 if (AF_INET == af) 1747 if (AF_INET == af)
1788 { 1748 {
1789 ts->source_ip.v4 = * (const struct in_addr *) source_ip; 1749 ts->source_ip.v4 = *(const struct in_addr *) source_ip;
1790 ts->destination_ip.v4 = * (const struct in_addr *) destination_ip; 1750 ts->destination_ip.v4 = *(const struct in_addr *) destination_ip;
1791 } 1751 }
1792 else 1752 else
1793 { 1753 {
1794 ts->source_ip.v6 = * (const struct in6_addr *) source_ip; 1754 ts->source_ip.v6 = *(const struct in6_addr *) source_ip;
1795 ts->destination_ip.v6 = * (const struct in6_addr *) destination_ip; 1755 ts->destination_ip.v6 = *(const struct in6_addr *) destination_ip;
1796 } 1756 }
1797 ts->source_port = source_port; 1757 ts->source_port = source_port;
1798 ts->destination_port = destination_port; 1758 ts->destination_port = destination_port;
1799 ts->heap_node = GNUNET_CONTAINER_heap_insert (channel_heap, 1759 ts->heap_node =
1800 ts, 1760 GNUNET_CONTAINER_heap_insert (channel_heap,
1801 GNUNET_TIME_absolute_get ().abs_value_us); 1761 ts,
1762 GNUNET_TIME_absolute_get ().abs_value_us);
1802 GNUNET_assert (GNUNET_YES == 1763 GNUNET_assert (GNUNET_YES ==
1803 GNUNET_CONTAINER_multihashmap_put (channel_map, 1764 GNUNET_CONTAINER_multihashmap_put (
1804 &key, 1765 channel_map,
1805 ts, 1766 &key,
1806 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1767 ts,
1768 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1807 GNUNET_STATISTICS_update (stats, 1769 GNUNET_STATISTICS_update (stats,
1808 gettext_noop ("# Active channels"), 1770 gettext_noop ("# Active channels"),
1809 1, GNUNET_NO); 1771 1,
1810 while (GNUNET_CONTAINER_multihashmap_size (channel_map) > max_channel_mappings) 1772 GNUNET_NO);
1773 while (GNUNET_CONTAINER_multihashmap_size (channel_map) >
1774 max_channel_mappings)
1811 expire_channel (ts); 1775 expire_channel (ts);
1812 } 1776 }
1813 else 1777 else
1814 { 1778 {
1815 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1779 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1816 GNUNET_TIME_absolute_get ().abs_value_us); 1780 GNUNET_TIME_absolute_get ()
1781 .abs_value_us);
1817 } 1782 }
1818 if (NULL == ts->channel) 1783 if (NULL == ts->channel)
1819 { 1784 {
1820 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1785 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1821 "Packet dropped, channel to %s not yet ready (%s)\n", 1786 "Packet dropped, channel to %s not yet ready (%s)\n",
1822 print_channel_destination (&ts->destination), 1787 print_channel_destination (&ts->destination),
1823 (NULL == ts->search) 1788 (NULL == ts->search) ? "EXIT search failed"
1824 ? "EXIT search failed" 1789 : "EXIT search active");
1825 : "EXIT search active");
1826 GNUNET_STATISTICS_update (stats, 1790 GNUNET_STATISTICS_update (stats,
1827 gettext_noop ("# Packets dropped (channel not yet online)"), 1791 gettext_noop (
1828 1, 1792 "# Packets dropped (channel not yet online)"),
1793 1,
1829 GNUNET_NO); 1794 GNUNET_NO);
1830 return; 1795 return;
1831 } 1796 }
@@ -1838,19 +1803,21 @@ route_packet (struct DestinationEntry *destination,
1838 { 1803 {
1839 struct GNUNET_EXIT_UdpServiceMessage *usm; 1804 struct GNUNET_EXIT_UdpServiceMessage *usm;
1840 1805
1841 mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) + 1806 mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) + payload_length -
1842 payload_length - sizeof (struct GNUNET_TUN_UdpHeader); 1807 sizeof (struct GNUNET_TUN_UdpHeader);
1843 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1808 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1844 { 1809 {
1845 GNUNET_break (0); 1810 GNUNET_break (0);
1846 return; 1811 return;
1847 } 1812 }
1848 env = GNUNET_MQ_msg_extra (usm, 1813 env = GNUNET_MQ_msg_extra (usm,
1849 payload_length - sizeof (struct GNUNET_TUN_UdpHeader), 1814 payload_length -
1815 sizeof (struct GNUNET_TUN_UdpHeader),
1850 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE); 1816 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE);
1851 /* if the source port is below 32000, we assume it has a special 1817 /* if the source port is below 32000, we assume it has a special
1852 meaning; if not, we pick a random port (this is a heuristic) */ 1818 meaning; if not, we pick a random port (this is a heuristic) */
1853 usm->source_port = (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; 1819 usm->source_port =
1820 (ntohs (udp->source_port) < 32000) ? udp->source_port : 0;
1854 usm->destination_port = udp->destination_port; 1821 usm->destination_port = udp->destination_port;
1855 GNUNET_memcpy (&usm[1], 1822 GNUNET_memcpy (&usm[1],
1856 &udp[1], 1823 &udp[1],
@@ -1863,33 +1830,35 @@ route_packet (struct DestinationEntry *destination,
1863 struct in6_addr *ip6dst; 1830 struct in6_addr *ip6dst;
1864 void *payload; 1831 void *payload;
1865 1832
1866 mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + 1833 mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + alen +
1867 alen + payload_length - sizeof (struct GNUNET_TUN_UdpHeader); 1834 payload_length - sizeof (struct GNUNET_TUN_UdpHeader);
1868 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1835 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1869 { 1836 {
1870 GNUNET_break (0); 1837 GNUNET_break (0);
1871 return; 1838 return;
1872 } 1839 }
1873 env = GNUNET_MQ_msg_extra (uim, 1840 env = GNUNET_MQ_msg_extra (uim,
1874 payload_length + alen - sizeof (struct GNUNET_TUN_UdpHeader), 1841 payload_length + alen -
1842 sizeof (struct GNUNET_TUN_UdpHeader),
1875 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET); 1843 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET);
1876 uim->af = htonl (destination->details.exit_destination.af); 1844 uim->af = htonl (destination->details.exit_destination.af);
1877 uim->source_port = (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; 1845 uim->source_port =
1846 (ntohs (udp->source_port) < 32000) ? udp->source_port : 0;
1878 uim->destination_port = udp->destination_port; 1847 uim->destination_port = udp->destination_port;
1879 switch (destination->details.exit_destination.af) 1848 switch (destination->details.exit_destination.af)
1880 { 1849 {
1881 case AF_INET: 1850 case AF_INET:
1882 ip4dst = (struct in_addr *) &uim[1]; 1851 ip4dst = (struct in_addr *) &uim[1];
1883 *ip4dst = destination->details.exit_destination.ip.v4; 1852 *ip4dst = destination->details.exit_destination.ip.v4;
1884 payload = &ip4dst[1]; 1853 payload = &ip4dst[1];
1885 break; 1854 break;
1886 case AF_INET6: 1855 case AF_INET6:
1887 ip6dst = (struct in6_addr *) &uim[1]; 1856 ip6dst = (struct in6_addr *) &uim[1];
1888 *ip6dst = destination->details.exit_destination.ip.v6; 1857 *ip6dst = destination->details.exit_destination.ip.v6;
1889 payload = &ip6dst[1]; 1858 payload = &ip6dst[1];
1890 break; 1859 break;
1891 default: 1860 default:
1892 GNUNET_assert (0); 1861 GNUNET_assert (0);
1893 } 1862 }
1894 GNUNET_memcpy (payload, 1863 GNUNET_memcpy (payload,
1895 &udp[1], 1864 &udp[1],
@@ -1901,59 +1870,63 @@ route_packet (struct DestinationEntry *destination,
1901 { 1870 {
1902 if (destination->is_service) 1871 if (destination->is_service)
1903 { 1872 {
1904 struct GNUNET_EXIT_TcpServiceStartMessage *tsm; 1873 struct GNUNET_EXIT_TcpServiceStartMessage *tsm;
1905 1874
1906 mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) + 1875 mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) +
1907 payload_length - sizeof (struct GNUNET_TUN_TcpHeader); 1876 payload_length - sizeof (struct GNUNET_TUN_TcpHeader);
1908 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1877 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1909 { 1878 {
1910 GNUNET_break (0); 1879 GNUNET_break (0);
1911 return; 1880 return;
1912 } 1881 }
1913 env = GNUNET_MQ_msg_extra (tsm, 1882 env =
1914 payload_length - sizeof (struct GNUNET_TUN_TcpHeader), 1883 GNUNET_MQ_msg_extra (tsm,
1915 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START); 1884 payload_length -
1916 tsm->reserved = htonl (0); 1885 sizeof (struct GNUNET_TUN_TcpHeader),
1917 tsm->tcp_header = *tcp; 1886 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START);
1918 GNUNET_memcpy (&tsm[1], 1887 tsm->reserved = htonl (0);
1888 tsm->tcp_header = *tcp;
1889 GNUNET_memcpy (&tsm[1],
1919 &tcp[1], 1890 &tcp[1],
1920 payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); 1891 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1921 } 1892 }
1922 else 1893 else
1923 { 1894 {
1924 struct GNUNET_EXIT_TcpInternetStartMessage *tim; 1895 struct GNUNET_EXIT_TcpInternetStartMessage *tim;
1925 struct in_addr *ip4dst; 1896 struct in_addr *ip4dst;
1926 struct in6_addr *ip6dst; 1897 struct in6_addr *ip6dst;
1927 void *payload; 1898 void *payload;
1928 1899
1929 mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + 1900 mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + alen +
1930 alen + payload_length - sizeof (struct GNUNET_TUN_TcpHeader); 1901 payload_length - sizeof (struct GNUNET_TUN_TcpHeader);
1931 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1902 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1932 { 1903 {
1933 GNUNET_break (0); 1904 GNUNET_break (0);
1934 return; 1905 return;
1935 } 1906 }
1936 env = GNUNET_MQ_msg_extra (tim, 1907 env =
1937 payload_length + alen - sizeof (struct GNUNET_TUN_TcpHeader), 1908 GNUNET_MQ_msg_extra (tim,
1938 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START); 1909 payload_length + alen -
1939 tim->af = htonl (destination->details.exit_destination.af); 1910 sizeof (struct GNUNET_TUN_TcpHeader),
1940 tim->tcp_header = *tcp; 1911 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START);
1941 switch (destination->details.exit_destination.af) 1912 tim->af = htonl (destination->details.exit_destination.af);
1942 { 1913 tim->tcp_header = *tcp;
1943 case AF_INET: 1914 switch (destination->details.exit_destination.af)
1944 ip4dst = (struct in_addr *) &tim[1]; 1915 {
1945 *ip4dst = destination->details.exit_destination.ip.v4; 1916 case AF_INET:
1946 payload = &ip4dst[1]; 1917 ip4dst = (struct in_addr *) &tim[1];
1947 break; 1918 *ip4dst = destination->details.exit_destination.ip.v4;
1948 case AF_INET6: 1919 payload = &ip4dst[1];
1949 ip6dst = (struct in6_addr *) &tim[1]; 1920 break;
1950 *ip6dst = destination->details.exit_destination.ip.v6; 1921 case AF_INET6:
1951 payload = &ip6dst[1]; 1922 ip6dst = (struct in6_addr *) &tim[1];
1952 break; 1923 *ip6dst = destination->details.exit_destination.ip.v6;
1953 default: 1924 payload = &ip6dst[1];
1954 GNUNET_assert (0); 1925 break;
1955 } 1926 default:
1956 GNUNET_memcpy (payload, 1927 GNUNET_assert (0);
1928 }
1929 GNUNET_memcpy (payload,
1957 &tcp[1], 1930 &tcp[1],
1958 payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); 1931 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1959 } 1932 }
@@ -1962,22 +1935,23 @@ route_packet (struct DestinationEntry *destination,
1962 { 1935 {
1963 struct GNUNET_EXIT_TcpDataMessage *tdm; 1936 struct GNUNET_EXIT_TcpDataMessage *tdm;
1964 1937
1965 mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + 1938 mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + payload_length -
1966 payload_length - sizeof (struct GNUNET_TUN_TcpHeader); 1939 sizeof (struct GNUNET_TUN_TcpHeader);
1967 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1940 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1968 { 1941 {
1969 GNUNET_break (0); 1942 GNUNET_break (0);
1970 return; 1943 return;
1971 } 1944 }
1972 env = GNUNET_MQ_msg_extra (tdm, 1945 env = GNUNET_MQ_msg_extra (tdm,
1973 payload_length - sizeof (struct GNUNET_TUN_TcpHeader), 1946 payload_length -
1947 sizeof (struct GNUNET_TUN_TcpHeader),
1974 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT); 1948 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT);
1975 tdm->reserved = htonl (0); 1949 tdm->reserved = htonl (0);
1976 tdm->tcp_header = *tcp; 1950 tdm->tcp_header = *tcp;
1977 GNUNET_memcpy (&tdm[1], 1951 GNUNET_memcpy (&tdm[1],
1978 &tcp[1], 1952 &tcp[1],
1979 payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); 1953 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1980 } 1954 }
1981 break; 1955 break;
1982 case IPPROTO_ICMP: 1956 case IPPROTO_ICMP:
1983 case IPPROTO_ICMPV6: 1957 case IPPROTO_ICMPV6:
@@ -1991,62 +1965,67 @@ route_packet (struct DestinationEntry *destination,
1991 switch (af) 1965 switch (af)
1992 { 1966 {
1993 case AF_INET: 1967 case AF_INET:
1994 switch (icmp->type) 1968 switch (icmp->type)
1995 { 1969 {
1996 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 1970 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
1997 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 1971 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
1998 break; 1972 break;
1999 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 1973 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
2000 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 1974 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
2001 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 1975 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
2002 /* throw away ICMP payload, won't be useful for the other side anyway */ 1976 /* throw away ICMP payload, won't be useful for the other side anyway */
2003 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 1977 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2004 break; 1978 break;
2005 default: 1979 default:
2006 GNUNET_STATISTICS_update (stats, 1980 GNUNET_STATISTICS_update (stats,
2007 gettext_noop ("# ICMPv4 packets dropped (not allowed)"), 1981 gettext_noop (
2008 1, GNUNET_NO); 1982 "# ICMPv4 packets dropped (not allowed)"),
2009 return; 1983 1,
2010 } 1984 GNUNET_NO);
2011 /* end of AF_INET */ 1985 return;
2012 break; 1986 }
1987 /* end of AF_INET */
1988 break;
2013 case AF_INET6: 1989 case AF_INET6:
2014 switch (icmp->type) 1990 switch (icmp->type)
2015 { 1991 {
2016 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 1992 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
2017 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 1993 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
2018 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 1994 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
2019 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 1995 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
2020 /* throw away ICMP payload, won't be useful for the other side anyway */ 1996 /* throw away ICMP payload, won't be useful for the other side anyway */
2021 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 1997 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2022 break; 1998 break;
2023 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 1999 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
2024 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: 2000 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
2025 break; 2001 break;
2026 default: 2002 default:
2027 GNUNET_STATISTICS_update (stats, 2003 GNUNET_STATISTICS_update (stats,
2028 gettext_noop ("# ICMPv6 packets dropped (not allowed)"), 2004 gettext_noop (
2029 1, GNUNET_NO); 2005 "# ICMPv6 packets dropped (not allowed)"),
2030 return; 2006 1,
2031 } 2007 GNUNET_NO);
2032 /* end of AF_INET6 */ 2008 return;
2033 break; 2009 }
2010 /* end of AF_INET6 */
2011 break;
2034 default: 2012 default:
2035 GNUNET_assert (0); 2013 GNUNET_assert (0);
2036 break; 2014 break;
2037 } 2015 }
2038 2016
2039 /* update length calculations, as payload_length may have changed */ 2017 /* update length calculations, as payload_length may have changed */
2040 mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + 2018 mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + alen +
2041 alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); 2019 payload_length - sizeof (struct GNUNET_TUN_IcmpHeader);
2042 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 2020 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
2043 { 2021 {
2044 GNUNET_break (0); 2022 GNUNET_break (0);
2045 return; 2023 return;
2046 } 2024 }
2047 2025
2048 env = GNUNET_MQ_msg_extra (ism, 2026 env = GNUNET_MQ_msg_extra (ism,
2049 payload_length - sizeof (struct GNUNET_TUN_IcmpHeader), 2027 payload_length -
2028 sizeof (struct GNUNET_TUN_IcmpHeader),
2050 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE); 2029 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE);
2051 ism->af = htonl (af); /* need to tell destination ICMP protocol family! */ 2030 ism->af = htonl (af); /* need to tell destination ICMP protocol family! */
2052 ism->icmp_header = *icmp; 2031 ism->icmp_header = *icmp;
@@ -2068,114 +2047,125 @@ route_packet (struct DestinationEntry *destination,
2068 switch (af) 2047 switch (af)
2069 { 2048 {
2070 case AF_INET: 2049 case AF_INET:
2071 switch (icmp->type) 2050 switch (icmp->type)
2072 { 2051 {
2073 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 2052 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
2074 if (destination->details.exit_destination.af == AF_INET6) 2053 if (destination->details.exit_destination.af == AF_INET6)
2075 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; 2054 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY;
2076 break; 2055 break;
2077 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 2056 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
2078 if (destination->details.exit_destination.af == AF_INET6) 2057 if (destination->details.exit_destination.af == AF_INET6)
2079 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; 2058 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST;
2080 break; 2059 break;
2081 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 2060 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
2082 if (destination->details.exit_destination.af == AF_INET6) 2061 if (destination->details.exit_destination.af == AF_INET6)
2083 new_type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; 2062 new_type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE;
2084 /* throw away IP-payload, exit will have to make it up anyway */ 2063 /* throw away IP-payload, exit will have to make it up anyway */
2085 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2064 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2086 break; 2065 break;
2087 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 2066 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
2088 if (destination->details.exit_destination.af == AF_INET6) 2067 if (destination->details.exit_destination.af == AF_INET6)
2089 new_type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; 2068 new_type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED;
2090 /* throw away IP-payload, exit will have to make it up anyway */ 2069 /* throw away IP-payload, exit will have to make it up anyway */
2091 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2070 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2092 break; 2071 break;
2093 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 2072 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
2094 if (destination->details.exit_destination.af == AF_INET6) 2073 if (destination->details.exit_destination.af == AF_INET6)
2095 { 2074 {
2096 GNUNET_STATISTICS_update (stats, 2075 GNUNET_STATISTICS_update (
2097 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), 2076 stats,
2098 1, GNUNET_NO); 2077 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"),
2099 return; 2078 1,
2100 } 2079 GNUNET_NO);
2101 /* throw away IP-payload, exit will have to make it up anyway */ 2080 return;
2102 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2081 }
2103 break; 2082 /* throw away IP-payload, exit will have to make it up anyway */
2104 default: 2083 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2105 GNUNET_STATISTICS_update (stats, 2084 break;
2106 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), 2085 default:
2107 1, GNUNET_NO); 2086 GNUNET_STATISTICS_update (
2108 return; 2087 stats,
2109 } 2088 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
2110 /* end of AF_INET */ 2089 1,
2111 break; 2090 GNUNET_NO);
2091 return;
2092 }
2093 /* end of AF_INET */
2094 break;
2112 case AF_INET6: 2095 case AF_INET6:
2113 switch (icmp->type) 2096 switch (icmp->type)
2114 { 2097 {
2115 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 2098 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
2116 if (destination->details.exit_destination.af == AF_INET) 2099 if (destination->details.exit_destination.af == AF_INET)
2117 new_type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; 2100 new_type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE;
2118 /* throw away IP-payload, exit will have to make it up anyway */ 2101 /* throw away IP-payload, exit will have to make it up anyway */
2119 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2102 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2120 break; 2103 break;
2121 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 2104 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
2122 if (destination->details.exit_destination.af == AF_INET) 2105 if (destination->details.exit_destination.af == AF_INET)
2123 new_type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; 2106 new_type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED;
2124 /* throw away IP-payload, exit will have to make it up anyway */ 2107 /* throw away IP-payload, exit will have to make it up anyway */
2125 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2108 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2126 break; 2109 break;
2127 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 2110 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
2128 if (destination->details.exit_destination.af == AF_INET) 2111 if (destination->details.exit_destination.af == AF_INET)
2129 { 2112 {
2130 GNUNET_STATISTICS_update (stats, 2113 GNUNET_STATISTICS_update (
2131 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), 2114 stats,
2132 1, GNUNET_NO); 2115 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"),
2133 return; 2116 1,
2134 } 2117 GNUNET_NO);
2135 /* throw away IP-payload, exit will have to make it up anyway */ 2118 return;
2136 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2119 }
2137 break; 2120 /* throw away IP-payload, exit will have to make it up anyway */
2138 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 2121 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2139 if (destination->details.exit_destination.af == AF_INET) 2122 break;
2140 { 2123 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
2141 GNUNET_STATISTICS_update (stats, 2124 if (destination->details.exit_destination.af == AF_INET)
2142 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), 2125 {
2143 1, GNUNET_NO); 2126 GNUNET_STATISTICS_update (
2144 return; 2127 stats,
2145 } 2128 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"),
2146 /* throw away IP-payload, exit will have to make it up anyway */ 2129 1,
2147 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2130 GNUNET_NO);
2148 break; 2131 return;
2149 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 2132 }
2150 if (destination->details.exit_destination.af == AF_INET) 2133 /* throw away IP-payload, exit will have to make it up anyway */
2151 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; 2134 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2152 break; 2135 break;
2153 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: 2136 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
2154 if (destination->details.exit_destination.af == AF_INET) 2137 if (destination->details.exit_destination.af == AF_INET)
2155 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; 2138 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST;
2156 break; 2139 break;
2157 default: 2140 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
2158 GNUNET_STATISTICS_update (stats, 2141 if (destination->details.exit_destination.af == AF_INET)
2159 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), 2142 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY;
2160 1, GNUNET_NO); 2143 break;
2161 return; 2144 default:
2162 } 2145 GNUNET_STATISTICS_update (
2163 /* end of AF_INET6 */ 2146 stats,
2164 break; 2147 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"),
2148 1,
2149 GNUNET_NO);
2150 return;
2151 }
2152 /* end of AF_INET6 */
2153 break;
2165 default: 2154 default:
2166 GNUNET_assert (0); 2155 GNUNET_assert (0);
2167 } 2156 }
2168 2157
2169 /* update length calculations, as payload_length may have changed */ 2158 /* update length calculations, as payload_length may have changed */
2170 mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + 2159 mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + alen +
2171 alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); 2160 payload_length - sizeof (struct GNUNET_TUN_IcmpHeader);
2172 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 2161 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
2173 { 2162 {
2174 GNUNET_break (0); 2163 GNUNET_break (0);
2175 return; 2164 return;
2176 } 2165 }
2177 env = GNUNET_MQ_msg_extra (iim, 2166 env = GNUNET_MQ_msg_extra (iim,
2178 alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader), 2167 alen + payload_length -
2168 sizeof (struct GNUNET_TUN_IcmpHeader),
2179 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET); 2169 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET);
2180 iim->icmp_header = *icmp; 2170 iim->icmp_header = *icmp;
2181 iim->icmp_header.type = new_type; 2171 iim->icmp_header.type = new_type;
@@ -2183,17 +2173,17 @@ route_packet (struct DestinationEntry *destination,
2183 switch (destination->details.exit_destination.af) 2173 switch (destination->details.exit_destination.af)
2184 { 2174 {
2185 case AF_INET: 2175 case AF_INET:
2186 ip4dst = (struct in_addr *) &iim[1]; 2176 ip4dst = (struct in_addr *) &iim[1];
2187 *ip4dst = destination->details.exit_destination.ip.v4; 2177 *ip4dst = destination->details.exit_destination.ip.v4;
2188 payload = &ip4dst[1]; 2178 payload = &ip4dst[1];
2189 break; 2179 break;
2190 case AF_INET6: 2180 case AF_INET6:
2191 ip6dst = (struct in6_addr *) &iim[1]; 2181 ip6dst = (struct in6_addr *) &iim[1];
2192 *ip6dst = destination->details.exit_destination.ip.v6; 2182 *ip6dst = destination->details.exit_destination.ip.v6;
2193 payload = &ip6dst[1]; 2183 payload = &ip6dst[1];
2194 break; 2184 break;
2195 default: 2185 default:
2196 GNUNET_assert (0); 2186 GNUNET_assert (0);
2197 } 2187 }
2198 GNUNET_memcpy (payload, 2188 GNUNET_memcpy (payload,
2199 &icmp[1], 2189 &icmp[1],
@@ -2206,8 +2196,7 @@ route_packet (struct DestinationEntry *destination,
2206 break; 2196 break;
2207 } 2197 }
2208 ts->is_established = GNUNET_YES; 2198 ts->is_established = GNUNET_YES;
2209 send_to_channel (ts, 2199 send_to_channel (ts, env);
2210 env);
2211} 2200}
2212 2201
2213 2202
@@ -2224,8 +2213,7 @@ route_packet (struct DestinationEntry *destination,
2224 * #GNUNET_SYSERR to stop further processing with error 2213 * #GNUNET_SYSERR to stop further processing with error
2225 */ 2214 */
2226static int 2215static int
2227message_token (void *cls, 2216message_token (void *cls, const struct GNUNET_MessageHeader *message)
2228 const struct GNUNET_MessageHeader *message)
2229{ 2217{
2230 const struct GNUNET_TUN_Layer2PacketHeader *tun; 2218 const struct GNUNET_TUN_Layer2PacketHeader *tun;
2231 size_t mlen; 2219 size_t mlen;
@@ -2233,101 +2221,96 @@ message_token (void *cls,
2233 struct DestinationEntry *de; 2221 struct DestinationEntry *de;
2234 2222
2235 GNUNET_STATISTICS_update (stats, 2223 GNUNET_STATISTICS_update (stats,
2236 gettext_noop ("# Packets received from TUN interface"), 2224 gettext_noop (
2237 1, GNUNET_NO); 2225 "# Packets received from TUN interface"),
2226 1,
2227 GNUNET_NO);
2238 mlen = ntohs (message->size); 2228 mlen = ntohs (message->size);
2239 if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || 2229 if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) ||
2240 (mlen < sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader)) ) 2230 (mlen < sizeof (struct GNUNET_MessageHeader) +
2231 sizeof (struct GNUNET_TUN_Layer2PacketHeader)))
2241 { 2232 {
2242 GNUNET_break (0); 2233 GNUNET_break (0);
2243 return GNUNET_OK; 2234 return GNUNET_OK;
2244 } 2235 }
2245 tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1]; 2236 tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1];
2246 mlen -= (sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader)); 2237 mlen -= (sizeof (struct GNUNET_MessageHeader) +
2238 sizeof (struct GNUNET_TUN_Layer2PacketHeader));
2247 switch (ntohs (tun->proto)) 2239 switch (ntohs (tun->proto))
2248 { 2240 {
2249 case ETH_P_IPV6: 2241 case ETH_P_IPV6: {
2242 const struct GNUNET_TUN_IPv6Header *pkt6;
2243
2244 if (mlen < sizeof (struct GNUNET_TUN_IPv6Header))
2245 {
2246 /* blame kernel */
2247 GNUNET_break (0);
2248 return GNUNET_OK;
2249 }
2250 pkt6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1];
2251 get_destination_key_from_ip (AF_INET6, &pkt6->destination_address, &key);
2252 de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key);
2253 if (NULL == de)
2250 { 2254 {
2251 const struct GNUNET_TUN_IPv6Header *pkt6; 2255 char buf[INET6_ADDRSTRLEN];
2252 2256
2253 if (mlen < sizeof (struct GNUNET_TUN_IPv6Header)) 2257 GNUNET_log (
2254 { 2258 GNUNET_ERROR_TYPE_INFO,
2255 /* blame kernel */ 2259 _ ("Packet received for unmapped destination `%s' (dropping it)\n"),
2256 GNUNET_break (0); 2260 inet_ntop (AF_INET6, &pkt6->destination_address, buf, sizeof (buf)));
2257 return GNUNET_OK; 2261 return GNUNET_OK;
2258 }
2259 pkt6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1];
2260 get_destination_key_from_ip (AF_INET6,
2261 &pkt6->destination_address,
2262 &key);
2263 de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key);
2264 if (NULL == de)
2265 {
2266 char buf[INET6_ADDRSTRLEN];
2267
2268 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2269 _("Packet received for unmapped destination `%s' (dropping it)\n"),
2270 inet_ntop (AF_INET6,
2271 &pkt6->destination_address,
2272 buf,
2273 sizeof (buf)));
2274 return GNUNET_OK;
2275 }
2276 route_packet (de,
2277 AF_INET6,
2278 pkt6->next_header,
2279 &pkt6->source_address,
2280 &pkt6->destination_address,
2281 &pkt6[1],
2282 mlen - sizeof (struct GNUNET_TUN_IPv6Header));
2283 } 2262 }
2284 break; 2263 route_packet (de,
2285 case ETH_P_IPV4: 2264 AF_INET6,
2265 pkt6->next_header,
2266 &pkt6->source_address,
2267 &pkt6->destination_address,
2268 &pkt6[1],
2269 mlen - sizeof (struct GNUNET_TUN_IPv6Header));
2270 }
2271 break;
2272 case ETH_P_IPV4: {
2273 struct GNUNET_TUN_IPv4Header *pkt4;
2274
2275 if (mlen < sizeof (struct GNUNET_TUN_IPv4Header))
2286 { 2276 {
2287 struct GNUNET_TUN_IPv4Header *pkt4; 2277 /* blame kernel */
2278 GNUNET_break (0);
2279 return GNUNET_OK;
2280 }
2281 pkt4 = (struct GNUNET_TUN_IPv4Header *) &tun[1];
2282 get_destination_key_from_ip (AF_INET, &pkt4->destination_address, &key);
2283 de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key);
2284 if (NULL == de)
2285 {
2286 char buf[INET_ADDRSTRLEN];
2288 2287
2289 if (mlen < sizeof (struct GNUNET_TUN_IPv4Header)) 2288 GNUNET_log (
2290 { 2289 GNUNET_ERROR_TYPE_INFO,
2291 /* blame kernel */ 2290 _ ("Packet received for unmapped destination `%s' (dropping it)\n"),
2292 GNUNET_break (0); 2291 inet_ntop (AF_INET, &pkt4->destination_address, buf, sizeof (buf)));
2293 return GNUNET_OK; 2292 return GNUNET_OK;
2294 }
2295 pkt4 = (struct GNUNET_TUN_IPv4Header *) &tun[1];
2296 get_destination_key_from_ip (AF_INET,
2297 &pkt4->destination_address,
2298 &key);
2299 de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key);
2300 if (NULL == de)
2301 {
2302 char buf[INET_ADDRSTRLEN];
2303
2304 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2305 _("Packet received for unmapped destination `%s' (dropping it)\n"),
2306 inet_ntop (AF_INET,
2307 &pkt4->destination_address,
2308 buf,
2309 sizeof (buf)));
2310 return GNUNET_OK;
2311 }
2312 if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header))
2313 {
2314 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2315 _("Received IPv4 packet with options (dropping it)\n"));
2316 return GNUNET_OK;
2317 }
2318 route_packet (de,
2319 AF_INET,
2320 pkt4->protocol,
2321 &pkt4->source_address,
2322 &pkt4->destination_address,
2323 &pkt4[1],
2324 mlen - sizeof (struct GNUNET_TUN_IPv4Header));
2325 } 2293 }
2326 break; 2294 if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header))
2295 {
2296 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2297 _ ("Received IPv4 packet with options (dropping it)\n"));
2298 return GNUNET_OK;
2299 }
2300 route_packet (de,
2301 AF_INET,
2302 pkt4->protocol,
2303 &pkt4->source_address,
2304 &pkt4->destination_address,
2305 &pkt4[1],
2306 mlen - sizeof (struct GNUNET_TUN_IPv4Header));
2307 }
2308 break;
2327 default: 2309 default:
2328 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2310 GNUNET_log (
2329 _("Received packet of unknown protocol %d from TUN (dropping it)\n"), 2311 GNUNET_ERROR_TYPE_INFO,
2330 (unsigned int) ntohs (tun->proto)); 2312 _ ("Received packet of unknown protocol %d from TUN (dropping it)\n"),
2313 (unsigned int) ntohs (tun->proto));
2331 break; 2314 break;
2332 } 2315 }
2333 return GNUNET_OK; 2316 return GNUNET_OK;
@@ -2360,27 +2343,23 @@ allocate_v4_address (struct in_addr *v4)
2360 mask.s_addr = addr.s_addr | ~mask.s_addr; 2343 mask.s_addr = addr.s_addr | ~mask.s_addr;
2361 tries = 0; 2344 tries = 0;
2362 do 2345 do
2346 {
2347 tries++;
2348 if (tries > 16)
2363 { 2349 {
2364 tries++; 2350 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2365 if (tries > 16) 2351 _ (
2366 { 2352 "Failed to find unallocated IPv4 address in VPN's range\n"));
2367 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2353 return GNUNET_SYSERR;
2368 _("Failed to find unallocated IPv4 address in VPN's range\n"));
2369 return GNUNET_SYSERR;
2370 }
2371 /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */
2372 rnd.s_addr = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2373 UINT32_MAX);
2374 v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr;
2375 get_destination_key_from_ip (AF_INET,
2376 v4,
2377 &key);
2378 } 2354 }
2379 while ( (GNUNET_YES == 2355 /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */
2380 GNUNET_CONTAINER_multihashmap_contains (destination_map, 2356 rnd.s_addr =
2381 &key)) || 2357 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
2382 (v4->s_addr == addr.s_addr) || 2358 v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr;
2383 (v4->s_addr == mask.s_addr) ); 2359 get_destination_key_from_ip (AF_INET, v4, &key);
2360 } while ((GNUNET_YES ==
2361 GNUNET_CONTAINER_multihashmap_contains (destination_map, &key)) ||
2362 (v4->s_addr == addr.s_addr) || (v4->s_addr == mask.s_addr));
2384 return GNUNET_OK; 2363 return GNUNET_OK;
2385} 2364}
2386 2365
@@ -2409,39 +2388,33 @@ allocate_v6_address (struct in6_addr *v6)
2409 /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF, 2388 /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF,
2410 thus: */ 2389 thus: */
2411 mask = addr; 2390 mask = addr;
2412 for (i=127;i>=ipv6prefix;i--) 2391 for (i = 127; i >= ipv6prefix; i--)
2413 mask.s6_addr[i / 8] |= (1 << (i % 8)); 2392 mask.s6_addr[i / 8] |= (1 << (i % 8));
2414 2393
2415 /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */ 2394 /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */
2416 tries = 0; 2395 tries = 0;
2417 do 2396 do
2397 {
2398 tries++;
2399 if (tries > 16)
2418 { 2400 {
2419 tries++; 2401 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2420 if (tries > 16) 2402 _ (
2421 { 2403 "Failed to find unallocated IPv6 address in VPN's range\n"));
2422 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2404 return GNUNET_SYSERR;
2423 _("Failed to find unallocated IPv6 address in VPN's range\n"));
2424 return GNUNET_SYSERR;
2425
2426 }
2427 for (i=0;i<16;i++)
2428 {
2429 rnd.s6_addr[i] = (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2430 256);
2431 v6->s6_addr[i]
2432 = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i];
2433 }
2434 get_destination_key_from_ip (AF_INET6,
2435 v6,
2436 &key);
2437 } 2405 }
2438 while ( (GNUNET_YES == 2406 for (i = 0; i < 16; i++)
2439 GNUNET_CONTAINER_multihashmap_contains (destination_map, 2407 {
2440 &key)) || 2408 rnd.s6_addr[i] =
2441 (0 == GNUNET_memcmp (v6, 2409 (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2442 &addr)) || 2410 256);
2443 (0 == GNUNET_memcmp (v6, 2411 v6->s6_addr[i] = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i];
2444 &mask)) ); 2412 }
2413 get_destination_key_from_ip (AF_INET6, v6, &key);
2414 } while ((GNUNET_YES ==
2415 GNUNET_CONTAINER_multihashmap_contains (destination_map, &key)) ||
2416 (0 == GNUNET_memcmp (v6, &addr)) ||
2417 (0 == GNUNET_memcmp (v6, &mask)));
2445 return GNUNET_OK; 2418 return GNUNET_OK;
2446} 2419}
2447 2420
@@ -2457,26 +2430,24 @@ free_destination_entry (struct DestinationEntry *de)
2457 struct DestinationChannel *dt; 2430 struct DestinationChannel *dt;
2458 2431
2459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2460 "Cleaning up destination entry `%s'\n", 2433 "Cleaning up destination entry `%s'\n",
2461 print_channel_destination (de)); 2434 print_channel_destination (de));
2462 GNUNET_STATISTICS_update (stats, 2435 GNUNET_STATISTICS_update (stats,
2463 gettext_noop ("# Active destinations"), 2436 gettext_noop ("# Active destinations"),
2464 -1, GNUNET_NO); 2437 -1,
2438 GNUNET_NO);
2465 while (NULL != (dt = de->dt_head)) 2439 while (NULL != (dt = de->dt_head))
2466 { 2440 {
2467 GNUNET_CONTAINER_DLL_remove (de->dt_head, 2441 GNUNET_CONTAINER_DLL_remove (de->dt_head, de->dt_tail, dt);
2468 de->dt_tail,
2469 dt);
2470 GNUNET_free (dt); 2442 GNUNET_free (dt);
2471 } 2443 }
2472 if (NULL != de->heap_node) 2444 if (NULL != de->heap_node)
2473 { 2445 {
2474 GNUNET_CONTAINER_heap_remove_node (de->heap_node); 2446 GNUNET_CONTAINER_heap_remove_node (de->heap_node);
2475 de->heap_node = NULL; 2447 de->heap_node = NULL;
2476 GNUNET_assert (GNUNET_YES == 2448 GNUNET_assert (
2477 GNUNET_CONTAINER_multihashmap_remove (destination_map, 2449 GNUNET_YES ==
2478 &de->key, 2450 GNUNET_CONTAINER_multihashmap_remove (destination_map, &de->key, de));
2479 de));
2480 } 2451 }
2481 GNUNET_free (de); 2452 GNUNET_free (de);
2482} 2453}
@@ -2516,36 +2487,32 @@ expire_destination (struct DestinationEntry *except)
2516 */ 2487 */
2517static int 2488static int
2518allocate_response_ip (int *result_af, 2489allocate_response_ip (int *result_af,
2519 void **addr, 2490 void **addr,
2520 struct in_addr *v4, 2491 struct in_addr *v4,
2521 struct in6_addr *v6) 2492 struct in6_addr *v6)
2522{ 2493{
2523 *addr = NULL; 2494 *addr = NULL;
2524 switch (*result_af) 2495 switch (*result_af)
2525 { 2496 {
2526 case AF_INET: 2497 case AF_INET:
2527 if (GNUNET_OK != 2498 if (GNUNET_OK != allocate_v4_address (v4))
2528 allocate_v4_address (v4))
2529 *result_af = AF_UNSPEC; 2499 *result_af = AF_UNSPEC;
2530 else 2500 else
2531 *addr = v4; 2501 *addr = v4;
2532 break; 2502 break;
2533 case AF_INET6: 2503 case AF_INET6:
2534 if (GNUNET_OK != 2504 if (GNUNET_OK != allocate_v6_address (v6))
2535 allocate_v6_address (v6))
2536 *result_af = AF_UNSPEC; 2505 *result_af = AF_UNSPEC;
2537 else 2506 else
2538 *addr = v6; 2507 *addr = v6;
2539 break; 2508 break;
2540 case AF_UNSPEC: 2509 case AF_UNSPEC:
2541 if (GNUNET_OK == 2510 if (GNUNET_OK == allocate_v4_address (v4))
2542 allocate_v4_address (v4))
2543 { 2511 {
2544 *addr = v4; 2512 *addr = v4;
2545 *result_af = AF_INET; 2513 *result_af = AF_INET;
2546 } 2514 }
2547 else if (GNUNET_OK == 2515 else if (GNUNET_OK == allocate_v6_address (v6))
2548 allocate_v6_address (v6))
2549 { 2516 {
2550 *addr = v6; 2517 *addr = v6;
2551 *result_af = AF_INET6; 2518 *result_af = AF_INET6;
@@ -2627,18 +2594,13 @@ handle_client_redirect_to_ip (void *cls,
2627 addr_af = (int) htonl (msg->addr_af); 2594 addr_af = (int) htonl (msg->addr_af);
2628 /* allocate response IP */ 2595 /* allocate response IP */
2629 result_af = (int) htonl (msg->result_af); 2596 result_af = (int) htonl (msg->result_af);
2630 if (GNUNET_OK != allocate_response_ip (&result_af, 2597 if (GNUNET_OK != allocate_response_ip (&result_af, &addr, &v4, &v6))
2631 &addr,
2632 &v4, &v6))
2633 { 2598 {
2634 GNUNET_SERVICE_client_drop (client); 2599 GNUNET_SERVICE_client_drop (client);
2635 return; 2600 return;
2636 } 2601 }
2637 /* send reply with our IP address */ 2602 /* send reply with our IP address */
2638 send_client_reply (client, 2603 send_client_reply (client, msg->request_id, result_af, addr);
2639 msg->request_id,
2640 result_af,
2641 addr);
2642 if (result_af == AF_UNSPEC) 2604 if (result_af == AF_UNSPEC)
2643 { 2605 {
2644 /* failure, we're done */ 2606 /* failure, we're done */
@@ -2651,40 +2613,34 @@ handle_client_redirect_to_ip (void *cls,
2651 char dbuf[INET6_ADDRSTRLEN]; 2613 char dbuf[INET6_ADDRSTRLEN];
2652 2614
2653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2654 "Allocated address %s for redirection via exit to %s\n", 2616 "Allocated address %s for redirection via exit to %s\n",
2655 inet_ntop (result_af, 2617 inet_ntop (result_af, addr, sbuf, sizeof (sbuf)),
2656 addr, 2618 inet_ntop (addr_af, &msg[1], dbuf, sizeof (dbuf)));
2657 sbuf,
2658 sizeof (sbuf)),
2659 inet_ntop (addr_af,
2660 &msg[1],
2661 dbuf,
2662 sizeof (dbuf)));
2663 } 2619 }
2664 2620
2665 /* setup destination record */ 2621 /* setup destination record */
2666 de = GNUNET_new (struct DestinationEntry); 2622 de = GNUNET_new (struct DestinationEntry);
2667 de->is_service = GNUNET_NO; 2623 de->is_service = GNUNET_NO;
2668 de->details.exit_destination.af = addr_af; 2624 de->details.exit_destination.af = addr_af;
2669 GNUNET_memcpy (&de->details.exit_destination.ip, 2625 GNUNET_memcpy (&de->details.exit_destination.ip, &msg[1], alen);
2670 &msg[1], 2626 get_destination_key_from_ip (result_af, addr, &key);
2671 alen);
2672 get_destination_key_from_ip (result_af,
2673 addr,
2674 &key);
2675 de->key = key; 2627 de->key = key;
2676 GNUNET_assert (GNUNET_OK == 2628 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
2677 GNUNET_CONTAINER_multihashmap_put (destination_map, 2629 destination_map,
2678 &key, 2630 &key,
2679 de, 2631 de,
2680 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 2632 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
2681 de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap, 2633 de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap,
2682 de, 2634 de,
2683 GNUNET_TIME_absolute_ntoh (msg->expiration_time).abs_value_us); 2635 GNUNET_TIME_absolute_ntoh (
2636 msg->expiration_time)
2637 .abs_value_us);
2684 GNUNET_STATISTICS_update (stats, 2638 GNUNET_STATISTICS_update (stats,
2685 gettext_noop ("# Active destinations"), 2639 gettext_noop ("# Active destinations"),
2686 1, GNUNET_NO); 2640 1,
2687 while (GNUNET_CONTAINER_multihashmap_size (destination_map) > max_destination_mappings) 2641 GNUNET_NO);
2642 while (GNUNET_CONTAINER_multihashmap_size (destination_map) >
2643 max_destination_mappings)
2688 expire_destination (de); 2644 expire_destination (de);
2689 GNUNET_SERVICE_client_continue (client); 2645 GNUNET_SERVICE_client_continue (client);
2690} 2646}
@@ -2699,8 +2655,9 @@ handle_client_redirect_to_ip (void *cls,
2699 * @param msg redirection request 2655 * @param msg redirection request
2700 */ 2656 */
2701static void 2657static void
2702handle_client_redirect_to_service (void *cls, 2658handle_client_redirect_to_service (
2703 const struct RedirectToServiceRequestMessage *msg) 2659 void *cls,
2660 const struct RedirectToServiceRequestMessage *msg)
2704{ 2661{
2705 struct GNUNET_SERVICE_Client *client = cls; 2662 struct GNUNET_SERVICE_Client *client = cls;
2706 int result_af; 2663 int result_af;
@@ -2713,25 +2670,18 @@ handle_client_redirect_to_service (void *cls,
2713 2670
2714 /* allocate response IP */ 2671 /* allocate response IP */
2715 result_af = (int) htonl (msg->result_af); 2672 result_af = (int) htonl (msg->result_af);
2716 if (GNUNET_OK != 2673 if (GNUNET_OK != allocate_response_ip (&result_af, &addr, &v4, &v6))
2717 allocate_response_ip (&result_af,
2718 &addr,
2719 &v4,
2720 &v6))
2721 { 2674 {
2722 GNUNET_break (0); 2675 GNUNET_break (0);
2723 GNUNET_SERVICE_client_drop (client); 2676 GNUNET_SERVICE_client_drop (client);
2724 return; 2677 return;
2725 } 2678 }
2726 send_client_reply (client, 2679 send_client_reply (client, msg->request_id, result_af, addr);
2727 msg->request_id,
2728 result_af,
2729 addr);
2730 if (result_af == AF_UNSPEC) 2680 if (result_af == AF_UNSPEC)
2731 { 2681 {
2732 /* failure, we're done */ 2682 /* failure, we're done */
2733 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2683 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2734 _("Failed to allocate IP address for new destination\n")); 2684 _ ("Failed to allocate IP address for new destination\n"));
2735 GNUNET_SERVICE_client_continue (client); 2685 GNUNET_SERVICE_client_continue (client);
2736 return; 2686 return;
2737 } 2687 }
@@ -2740,13 +2690,10 @@ handle_client_redirect_to_service (void *cls,
2740 char sbuf[INET6_ADDRSTRLEN]; 2690 char sbuf[INET6_ADDRSTRLEN];
2741 2691
2742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2743 "Allocated address %s for redirection to service %s on peer %s\n", 2693 "Allocated address %s for redirection to service %s on peer %s\n",
2744 inet_ntop (result_af, 2694 inet_ntop (result_af, addr, sbuf, sizeof (sbuf)),
2745 addr, 2695 GNUNET_h2s (&msg->service_descriptor),
2746 sbuf, 2696 GNUNET_i2s (&msg->target));
2747 sizeof (sbuf)),
2748 GNUNET_h2s (&msg->service_descriptor),
2749 GNUNET_i2s (&msg->target));
2750 } 2697 }
2751 2698
2752 /* setup destination record */ 2699 /* setup destination record */
@@ -2754,33 +2701,30 @@ handle_client_redirect_to_service (void *cls,
2754 de->is_service = GNUNET_YES; 2701 de->is_service = GNUNET_YES;
2755 de->details.service_destination.target = msg->target; 2702 de->details.service_destination.target = msg->target;
2756 de->details.service_destination.service_descriptor = msg->service_descriptor; 2703 de->details.service_destination.service_descriptor = msg->service_descriptor;
2757 get_destination_key_from_ip (result_af, 2704 get_destination_key_from_ip (result_af, addr, &key);
2758 addr,
2759 &key);
2760 de->key = key; 2705 de->key = key;
2761 GNUNET_assert (GNUNET_OK == 2706 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
2762 GNUNET_CONTAINER_multihashmap_put (destination_map, 2707 destination_map,
2763 &key, 2708 &key,
2764 de, 2709 de,
2765 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 2710 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
2766 de->heap_node 2711 de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap,
2767 = GNUNET_CONTAINER_heap_insert (destination_heap, 2712 de,
2768 de, 2713 GNUNET_TIME_absolute_ntoh (
2769 GNUNET_TIME_absolute_ntoh (msg->expiration_time).abs_value_us); 2714 msg->expiration_time)
2770 while (GNUNET_CONTAINER_multihashmap_size (destination_map) > max_destination_mappings) 2715 .abs_value_us);
2716 while (GNUNET_CONTAINER_multihashmap_size (destination_map) >
2717 max_destination_mappings)
2771 expire_destination (de); 2718 expire_destination (de);
2772 2719
2773 dt = GNUNET_new (struct DestinationChannel); 2720 dt = GNUNET_new (struct DestinationChannel);
2774 dt->destination = de; 2721 dt->destination = de;
2775 GNUNET_CONTAINER_DLL_insert (de->dt_head, 2722 GNUNET_CONTAINER_DLL_insert (de->dt_head, de->dt_tail, dt);
2776 de->dt_tail,
2777 dt);
2778 /* we're done */ 2723 /* we're done */
2779 GNUNET_SERVICE_client_continue (client); 2724 GNUNET_SERVICE_client_continue (client);
2780} 2725}
2781 2726
2782 2727
2783
2784/** 2728/**
2785 * Free memory occupied by an entry in the destination map. 2729 * Free memory occupied by an entry in the destination map.
2786 * 2730 *
@@ -2790,9 +2734,7 @@ handle_client_redirect_to_service (void *cls,
2790 * @return #GNUNET_OK (continue to iterate) 2734 * @return #GNUNET_OK (continue to iterate)
2791 */ 2735 */
2792static int 2736static int
2793cleanup_destination (void *cls, 2737cleanup_destination (void *cls, const struct GNUNET_HashCode *key, void *value)
2794 const struct GNUNET_HashCode *key,
2795 void *value)
2796{ 2738{
2797 struct DestinationEntry *de = value; 2739 struct DestinationEntry *de = value;
2798 2740
@@ -2810,14 +2752,12 @@ cleanup_destination (void *cls,
2810 * @return #GNUNET_OK (continue to iterate) 2752 * @return #GNUNET_OK (continue to iterate)
2811 */ 2753 */
2812static int 2754static int
2813cleanup_channel (void *cls, 2755cleanup_channel (void *cls, const struct GNUNET_HashCode *key, void *value)
2814 const struct GNUNET_HashCode *key,
2815 void *value)
2816{ 2756{
2817 struct ChannelState *ts = value; 2757 struct ChannelState *ts = value;
2818 2758
2819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2820 "Tearing down channel to `%s' during cleanup\n", 2760 "Tearing down channel to `%s' during cleanup\n",
2821 print_channel_destination (&ts->destination)); 2761 print_channel_destination (&ts->destination));
2822 free_channel_state (ts); 2762 free_channel_state (ts);
2823 return GNUNET_OK; 2763 return GNUNET_OK;
@@ -2834,13 +2774,12 @@ cleanup (void *cls)
2834{ 2774{
2835 unsigned int i; 2775 unsigned int i;
2836 2776
2837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "VPN is shutting down\n");
2838 "VPN is shutting down\n");
2839 if (NULL != destination_map) 2778 if (NULL != destination_map)
2840 { 2779 {
2841 GNUNET_CONTAINER_multihashmap_iterate (destination_map, 2780 GNUNET_CONTAINER_multihashmap_iterate (destination_map,
2842 &cleanup_destination, 2781 &cleanup_destination,
2843 NULL); 2782 NULL);
2844 GNUNET_CONTAINER_multihashmap_destroy (destination_map); 2783 GNUNET_CONTAINER_multihashmap_destroy (destination_map);
2845 destination_map = NULL; 2784 destination_map = NULL;
2846 } 2785 }
@@ -2851,9 +2790,7 @@ cleanup (void *cls)
2851 } 2790 }
2852 if (NULL != channel_map) 2791 if (NULL != channel_map)
2853 { 2792 {
2854 GNUNET_CONTAINER_multihashmap_iterate (channel_map, 2793 GNUNET_CONTAINER_multihashmap_iterate (channel_map, &cleanup_channel, NULL);
2855 &cleanup_channel,
2856 NULL);
2857 GNUNET_CONTAINER_multihashmap_destroy (channel_map); 2794 GNUNET_CONTAINER_multihashmap_destroy (channel_map);
2858 channel_map = NULL; 2795 channel_map = NULL;
2859 } 2796 }
@@ -2878,7 +2815,7 @@ cleanup (void *cls)
2878 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 2815 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
2879 stats = NULL; 2816 stats = NULL;
2880 } 2817 }
2881 for (i=0;i<5;i++) 2818 for (i = 0; i < 5; i++)
2882 GNUNET_free_non_null (vpn_argv[i]); 2819 GNUNET_free_non_null (vpn_argv[i]);
2883} 2820}
2884 2821
@@ -2893,8 +2830,8 @@ cleanup (void *cls)
2893 */ 2830 */
2894static void * 2831static void *
2895client_connect_cb (void *cls, 2832client_connect_cb (void *cls,
2896 struct GNUNET_SERVICE_Client *c, 2833 struct GNUNET_SERVICE_Client *c,
2897 struct GNUNET_MQ_Handle *mq) 2834 struct GNUNET_MQ_Handle *mq)
2898{ 2835{
2899 return c; 2836 return c;
2900} 2837}
@@ -2909,8 +2846,8 @@ client_connect_cb (void *cls,
2909 */ 2846 */
2910static void 2847static void
2911client_disconnect_cb (void *cls, 2848client_disconnect_cb (void *cls,
2912 struct GNUNET_SERVICE_Client *c, 2849 struct GNUNET_SERVICE_Client *c,
2913 void *internal_cls) 2850 void *internal_cls)
2914{ 2851{
2915 GNUNET_assert (c == internal_cls); 2852 GNUNET_assert (c == internal_cls);
2916} 2853}
@@ -2940,9 +2877,10 @@ run (void *cls,
2940 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn"); 2877 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn");
2941 2878
2942 if (GNUNET_YES != 2879 if (GNUNET_YES !=
2943 GNUNET_OS_check_helper_binary (binary, 2880 GNUNET_OS_check_helper_binary (
2944 GNUNET_YES, 2881 binary,
2945 "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) //ipv4 only please! 2882 GNUNET_YES,
2883 "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) //ipv4 only please!
2946 { 2884 {
2947 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2885 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2948 "`%s' is not SUID, refusing to run.\n", 2886 "`%s' is not SUID, refusing to run.\n",
@@ -2961,18 +2899,22 @@ run (void *cls,
2961 GNUNET_CONFIGURATION_get_value_number (cfg, 2899 GNUNET_CONFIGURATION_get_value_number (cfg,
2962 "VPN", 2900 "VPN",
2963 "MAX_MAPPING", 2901 "MAX_MAPPING",
2964 &max_destination_mappings)) 2902 &max_destination_mappings))
2965 max_destination_mappings = 200; 2903 max_destination_mappings = 200;
2966 if (GNUNET_OK != 2904 if (GNUNET_OK !=
2967 GNUNET_CONFIGURATION_get_value_number (cfg, 2905 GNUNET_CONFIGURATION_get_value_number (cfg,
2968 "VPN", 2906 "VPN",
2969 "MAX_TUNNELS", 2907 "MAX_TUNNELS",
2970 &max_channel_mappings)) 2908 &max_channel_mappings))
2971 max_channel_mappings = 200; 2909 max_channel_mappings = 200;
2972 2910
2973 destination_map = GNUNET_CONTAINER_multihashmap_create (max_destination_mappings * 2, GNUNET_NO); 2911 destination_map =
2974 destination_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 2912 GNUNET_CONTAINER_multihashmap_create (max_destination_mappings * 2,
2975 channel_map = GNUNET_CONTAINER_multihashmap_create (max_channel_mappings * 2, GNUNET_NO); 2913 GNUNET_NO);
2914 destination_heap =
2915 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2916 channel_map =
2917 GNUNET_CONTAINER_multihashmap_create (max_channel_mappings * 2, GNUNET_NO);
2976 channel_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 2918 channel_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2977 2919
2978 2920
@@ -2988,22 +2930,26 @@ run (void *cls,
2988 ipv6addr = NULL; 2930 ipv6addr = NULL;
2989 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6)) 2931 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6))
2990 { 2932 {
2991 if ( (GNUNET_SYSERR == 2933 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
2992 GNUNET_CONFIGURATION_get_value_string (cfg, "VPN", "IPV6ADDR", 2934 "VPN",
2993 &ipv6addr) || 2935 "IPV6ADDR",
2994 (1 != inet_pton (AF_INET6, ipv6addr, &v6))) ) 2936 &ipv6addr) ||
2937 (1 != inet_pton (AF_INET6, ipv6addr, &v6))))
2995 { 2938 {
2996 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6ADDR", 2939 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
2997 _("Must specify valid IPv6 address")); 2940 "VPN",
2941 "IPV6ADDR",
2942 _ ("Must specify valid IPv6 address"));
2998 GNUNET_SCHEDULER_shutdown (); 2943 GNUNET_SCHEDULER_shutdown ();
2999 GNUNET_free_non_null (ipv6addr); 2944 GNUNET_free_non_null (ipv6addr);
3000 return; 2945 return;
3001 } 2946 }
3002 vpn_argv[2] = ipv6addr; 2947 vpn_argv[2] = ipv6addr;
3003 ipv6prefix_s = NULL; 2948 ipv6prefix_s = NULL;
3004 if (GNUNET_SYSERR == 2949 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
3005 GNUNET_CONFIGURATION_get_value_string (cfg, "VPN", "IPV6PREFIX", 2950 "VPN",
3006 &ipv6prefix_s)) 2951 "IPV6PREFIX",
2952 &ipv6prefix_s))
3007 { 2953 {
3008 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6PREFIX"); 2954 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6PREFIX");
3009 GNUNET_SCHEDULER_shutdown (); 2955 GNUNET_SCHEDULER_shutdown ();
@@ -3011,14 +2957,16 @@ run (void *cls,
3011 return; 2957 return;
3012 } 2958 }
3013 vpn_argv[3] = ipv6prefix_s; 2959 vpn_argv[3] = ipv6prefix_s;
3014 if ( (GNUNET_OK != 2960 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
3015 GNUNET_CONFIGURATION_get_value_number (cfg, "VPN", 2961 "VPN",
3016 "IPV6PREFIX", 2962 "IPV6PREFIX",
3017 &ipv6prefix)) || 2963 &ipv6prefix)) ||
3018 (ipv6prefix >= 127) ) 2964 (ipv6prefix >= 127))
3019 { 2965 {
3020 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4MASK", 2966 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3021 _("Must specify valid IPv6 mask")); 2967 "VPN",
2968 "IPV4MASK",
2969 _ ("Must specify valid IPv6 mask"));
3022 GNUNET_SCHEDULER_shutdown (); 2970 GNUNET_SCHEDULER_shutdown ();
3023 return; 2971 return;
3024 } 2972 }
@@ -3026,33 +2974,40 @@ run (void *cls,
3026 else 2974 else
3027 { 2975 {
3028 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2976 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3029 _("IPv6 support disabled as this system does not support IPv6\n")); 2977 _ (
2978 "IPv6 support disabled as this system does not support IPv6\n"));
3030 vpn_argv[2] = GNUNET_strdup ("-"); 2979 vpn_argv[2] = GNUNET_strdup ("-");
3031 vpn_argv[3] = GNUNET_strdup ("-"); 2980 vpn_argv[3] = GNUNET_strdup ("-");
3032 } 2981 }
3033 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET)) 2982 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET))
3034 { 2983 {
3035 ipv4addr = NULL; 2984 ipv4addr = NULL;
3036 if ( (GNUNET_SYSERR == 2985 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
3037 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR", 2986 "vpn",
3038 &ipv4addr) || 2987 "IPV4ADDR",
3039 (1 != inet_pton (AF_INET, ipv4addr, &v4))) ) 2988 &ipv4addr) ||
2989 (1 != inet_pton (AF_INET, ipv4addr, &v4))))
3040 { 2990 {
3041 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4ADDR", 2991 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3042 _("Must specify valid IPv4 address")); 2992 "VPN",
2993 "IPV4ADDR",
2994 _ ("Must specify valid IPv4 address"));
3043 GNUNET_SCHEDULER_shutdown (); 2995 GNUNET_SCHEDULER_shutdown ();
3044 GNUNET_free_non_null (ipv4addr); 2996 GNUNET_free_non_null (ipv4addr);
3045 return; 2997 return;
3046 } 2998 }
3047 vpn_argv[4] = ipv4addr; 2999 vpn_argv[4] = ipv4addr;
3048 ipv4mask = NULL; 3000 ipv4mask = NULL;
3049 if ( (GNUNET_SYSERR == 3001 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
3050 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4MASK", 3002 "vpn",
3051 &ipv4mask) || 3003 "IPV4MASK",
3052 (1 != inet_pton (AF_INET, ipv4mask, &v4))) ) 3004 &ipv4mask) ||
3005 (1 != inet_pton (AF_INET, ipv4mask, &v4))))
3053 { 3006 {
3054 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4MASK", 3007 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3055 _("Must specify valid IPv4 mask")); 3008 "VPN",
3009 "IPV4MASK",
3010 _ ("Must specify valid IPv4 mask"));
3056 GNUNET_SCHEDULER_shutdown (); 3011 GNUNET_SCHEDULER_shutdown ();
3057 GNUNET_free_non_null (ipv4mask); 3012 GNUNET_free_non_null (ipv4mask);
3058 return; 3013 return;
@@ -3062,41 +3017,44 @@ run (void *cls,
3062 else 3017 else
3063 { 3018 {
3064 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3019 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3065 _("IPv4 support disabled as this system does not support IPv4\n")); 3020 _ (
3021 "IPv4 support disabled as this system does not support IPv4\n"));
3066 vpn_argv[4] = GNUNET_strdup ("-"); 3022 vpn_argv[4] = GNUNET_strdup ("-");
3067 vpn_argv[5] = GNUNET_strdup ("-"); 3023 vpn_argv[5] = GNUNET_strdup ("-");
3068 } 3024 }
3069 vpn_argv[6] = NULL; 3025 vpn_argv[6] = NULL;
3070 3026
3071 cadet_handle = GNUNET_CADET_connect (cfg_); 3027 cadet_handle = GNUNET_CADET_connect (cfg_);
3072 // FIXME never opens ports??? 3028 // FIXME never opens ports???
3073 helper_handle = GNUNET_HELPER_start (GNUNET_NO, 3029 helper_handle = GNUNET_HELPER_start (GNUNET_NO,
3074 "gnunet-helper-vpn", vpn_argv, 3030 "gnunet-helper-vpn",
3075 &message_token, NULL, NULL); 3031 vpn_argv,
3076 GNUNET_SCHEDULER_add_shutdown (&cleanup, 3032 &message_token,
3077 NULL); 3033 NULL,
3034 NULL);
3035 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
3078} 3036}
3079 3037
3080 3038
3081/** 3039/**
3082 * Define "main" method using service macro. 3040 * Define "main" method using service macro.
3083 */ 3041 */
3084GNUNET_SERVICE_MAIN 3042GNUNET_SERVICE_MAIN (
3085("vpn", 3043 "vpn",
3086 GNUNET_SERVICE_OPTION_NONE, 3044 GNUNET_SERVICE_OPTION_NONE,
3087 &run, 3045 &run,
3088 &client_connect_cb, 3046 &client_connect_cb,
3089 &client_disconnect_cb, 3047 &client_disconnect_cb,
3090 NULL, 3048 NULL,
3091 GNUNET_MQ_hd_var_size (client_redirect_to_ip, 3049 GNUNET_MQ_hd_var_size (client_redirect_to_ip,
3092 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, 3050 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP,
3093 struct RedirectToIpRequestMessage, 3051 struct RedirectToIpRequestMessage,
3094 NULL), 3052 NULL),
3095 GNUNET_MQ_hd_fixed_size (client_redirect_to_service, 3053 GNUNET_MQ_hd_fixed_size (client_redirect_to_service,
3096 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE, 3054 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE,
3097 struct RedirectToServiceRequestMessage, 3055 struct RedirectToServiceRequestMessage,
3098 NULL), 3056 NULL),
3099 GNUNET_MQ_handler_end ()); 3057 GNUNET_MQ_handler_end ());
3100 3058
3101 3059
3102/* end of gnunet-service-vpn.c */ 3060/* end of gnunet-service-vpn.c */