aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2019-07-21 20:18:24 +0200
committert3sserakt <t3ss@posteo.de>2019-07-21 20:18:24 +0200
commitf096bdce8eaeaabc42f2a015bf29c422b3d25719 (patch)
tree694c140bd741f7b1c24b5e55e8644002ae53cae4 /src
parentdfeef02bf7882cdfb952430cfbdb9793ecd780e2 (diff)
parent160edc4127f1698cca25d5708157ea3187421596 (diff)
downloadgnunet-f096bdce8eaeaabc42f2a015bf29c422b3d25719.tar.gz
gnunet-f096bdce8eaeaabc42f2a015bf29c422b3d25719.zip
Merge branch 'cadet-new-options'
Diffstat (limited to 'src')
-rw-r--r--src/cadet/cadet_api.c25
-rw-r--r--src/cadet/gnunet-cadet-profiler.c7
-rw-r--r--src/cadet/gnunet-cadet.c3
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c574
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c282
-rw-r--r--src/cadet/gnunet-service-cadet_connection.h5
-rw-r--r--src/cadet/gnunet-service-cadet_core.c513
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.c3
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.h2
-rw-r--r--src/cadet/test_cadet.c7
-rw-r--r--src/cadet/test_cadet_local_mq.c1
-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_cadet_service.h58
-rw-r--r--src/include/gnunet_mq_lib.h20
-rw-r--r--src/pt/gnunet-daemon-pt.c1
-rw-r--r--src/rps/gnunet-service-rps.c1
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c360
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_alice.c376
-rw-r--r--src/set/gnunet-service-set.c771
-rw-r--r--src/util/mq.c22
-rw-r--r--src/vpn/gnunet-service-vpn.c2484
22 files changed, 2726 insertions, 3447 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index e141787a0..ff6f15543 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.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
@@ -134,11 +134,6 @@ struct GNUNET_CADET_Channel
134 struct GNUNET_CADET_ClientChannelNumber ccn; 134 struct GNUNET_CADET_ClientChannelNumber ccn;
135 135
136 /** 136 /**
137 * Channel options: reliability, etc.
138 */
139 enum GNUNET_CADET_ChannelOption options;
140
141 /**
142 * How many messages are we allowed to send to the service right now? 137 * How many messages are we allowed to send to the service right now?
143 */ 138 */
144 unsigned int allow_send; 139 unsigned int allow_send;
@@ -578,7 +573,6 @@ handle_channel_created (
578 ch = create_channel (h, &ccn); 573 ch = create_channel (h, &ccn);
579 ch->peer = msg->peer; 574 ch->peer = msg->peer;
580 ch->incoming_port = port; 575 ch->incoming_port = port;
581 ch->options = ntohl (msg->opt);
582 LOG (GNUNET_ERROR_TYPE_DEBUG, 576 LOG (GNUNET_ERROR_TYPE_DEBUG,
583 "Creating incoming channel %X [%s] %p\n", 577 "Creating incoming channel %X [%s] %p\n",
584 ntohl (ccn.channel_of_client), 578 ntohl (ccn.channel_of_client),
@@ -938,25 +932,13 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel)
938 */ 932 */
939const union GNUNET_CADET_ChannelInfo * 933const union GNUNET_CADET_ChannelInfo *
940GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel, 934GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel,
941 enum GNUNET_CADET_ChannelOption option, 935 enum GNUNET_CADET_ChannelInfoOption option,
942 ...) 936 ...)
943{ 937{
944 static int bool_flag;
945
946 switch (option) 938 switch (option)
947 { 939 {
948 case GNUNET_CADET_OPTION_NOBUFFER:
949 case GNUNET_CADET_OPTION_RELIABLE:
950 case GNUNET_CADET_OPTION_OUT_OF_ORDER:
951 if (0 != (option & channel->options))
952 bool_flag = GNUNET_YES;
953 else
954 bool_flag = GNUNET_NO;
955 return (const union GNUNET_CADET_ChannelInfo *) &bool_flag;
956 break;
957 case GNUNET_CADET_OPTION_PEER: 940 case GNUNET_CADET_OPTION_PEER:
958 return (const union GNUNET_CADET_ChannelInfo *) &channel->peer; 941 return (const union GNUNET_CADET_ChannelInfo *) &channel->peer;
959 break;
960 default: 942 default:
961 GNUNET_break (0); 943 GNUNET_break (0);
962 return NULL; 944 return NULL;
@@ -1089,7 +1071,6 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
1089 void *channel_cls, 1071 void *channel_cls,
1090 const struct GNUNET_PeerIdentity *destination, 1072 const struct GNUNET_PeerIdentity *destination,
1091 const struct GNUNET_HashCode *port, 1073 const struct GNUNET_HashCode *port,
1092 enum GNUNET_CADET_ChannelOption options,
1093 GNUNET_CADET_WindowSizeEventHandler window_changes, 1074 GNUNET_CADET_WindowSizeEventHandler window_changes,
1094 GNUNET_CADET_DisconnectEventHandler disconnects, 1075 GNUNET_CADET_DisconnectEventHandler disconnects,
1095 const struct GNUNET_MQ_MessageHandler *handlers) 1076 const struct GNUNET_MQ_MessageHandler *handlers)
@@ -1106,7 +1087,6 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
1106 ch = create_channel (h, NULL); 1087 ch = create_channel (h, NULL);
1107 ch->ctx = channel_cls; 1088 ch->ctx = channel_cls;
1108 ch->peer = *destination; 1089 ch->peer = *destination;
1109 ch->options = options;
1110 ch->window_changes = window_changes; 1090 ch->window_changes = window_changes;
1111 ch->disconnects = disconnects; 1091 ch->disconnects = disconnects;
1112 1092
@@ -1125,7 +1105,6 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
1125 msg->ccn = ch->ccn; 1105 msg->ccn = ch->ccn;
1126 msg->port = *port; 1106 msg->port = *port;
1127 msg->peer = *destination; 1107 msg->peer = *destination;
1128 msg->opt = htonl (options);
1129 GNUNET_MQ_send (h->mq, env); 1108 GNUNET_MQ_send (h->mq, env);
1130 return ch; 1109 return ch;
1131} 1110}
diff --git a/src/cadet/gnunet-cadet-profiler.c b/src/cadet/gnunet-cadet-profiler.c
index 920d8d830..2de17dc9e 100644
--- a/src/cadet/gnunet-cadet-profiler.c
+++ b/src/cadet/gnunet-cadet-profiler.c
@@ -912,19 +912,18 @@ select_random_peer (struct CadetPeer *peer)
912static void 912static void
913start_test (void *cls) 913start_test (void *cls)
914{ 914{
915 enum GNUNET_CADET_ChannelOption flags;
916 unsigned long i; 915 unsigned long i;
917 916
918 test_task = NULL; 917 test_task = NULL;
919 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n"); 918 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
920 919
921 flags = GNUNET_CADET_OPTION_DEFAULT; 920
922 for (i = 0; i < peers_pinging; i++) 921 for (i = 0; i < peers_pinging; i++)
923 { 922 {
924 peers[i].dest = select_random_peer (&peers[i]); 923 peers[i].dest = select_random_peer (&peers[i]);
925 peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL, 924 peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL,
926 &peers[i].dest->id, 925 &peers[i].dest->id,
927 GC_u2h (1), flags); 926 GC_u2h (1));
928 if (NULL == peers[i].ch) 927 if (NULL == peers[i].ch)
929 { 928 {
930 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i); 929 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
@@ -969,7 +968,7 @@ warmup (void)
969 i, get_index (peer)); 968 i, get_index (peer));
970 peers[i].warmup_ch = 969 peers[i].warmup_ch =
971 GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id, 970 GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id,
972 GC_u2h (1), GNUNET_CADET_OPTION_DEFAULT); 971 GC_u2h (1));
973 if (NULL == peers[i].warmup_ch) 972 if (NULL == peers[i].warmup_ch)
974 { 973 {
975 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i); 974 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index 932d069a1..262cdf64d 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -784,7 +784,6 @@ run (void *cls,
784 if (NULL != target_id) 784 if (NULL != target_id)
785 { 785 {
786 struct GNUNET_PeerIdentity pid; 786 struct GNUNET_PeerIdentity pid;
787 enum GNUNET_CADET_ChannelOption opt;
788 787
789 if (GNUNET_OK != 788 if (GNUNET_OK !=
790 GNUNET_CRYPTO_eddsa_public_key_from_string (target_id, 789 GNUNET_CRYPTO_eddsa_public_key_from_string (target_id,
@@ -801,7 +800,6 @@ run (void *cls,
801 "Connecting to `%s:%s'\n", 800 "Connecting to `%s:%s'\n",
802 target_id, 801 target_id,
803 target_port); 802 target_port);
804 opt = GNUNET_CADET_OPTION_DEFAULT | GNUNET_CADET_OPTION_RELIABLE;
805 GNUNET_CRYPTO_hash (target_port, 803 GNUNET_CRYPTO_hash (target_port,
806 strlen(target_port), 804 strlen(target_port),
807 &porthash); 805 &porthash);
@@ -809,7 +807,6 @@ run (void *cls,
809 NULL, 807 NULL,
810 &pid, 808 &pid,
811 &porthash, 809 &porthash,
812 opt,
813 NULL /* window changes */, 810 NULL /* window changes */,
814 &channel_ended, 811 &channel_ended,
815 handlers); 812 handlers);
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index a1f6e37c2..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
@@ -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
@@ -591,31 +579,22 @@ send_channel_open (void *cls)
591{ 579{
592 struct CadetChannel *ch = cls; 580 struct CadetChannel *ch = cls;
593 struct GNUNET_CADET_ChannelOpenMessage msgcc; 581 struct GNUNET_CADET_ChannelOpenMessage msgcc;
594 uint32_t options;
595 582
596 ch->retry_control_task = NULL; 583 ch->retry_control_task = NULL;
597 LOG (GNUNET_ERROR_TYPE_DEBUG, 584 LOG (GNUNET_ERROR_TYPE_DEBUG,
598 "Sending CHANNEL_OPEN message for %s\n", 585 "Sending CHANNEL_OPEN message for %s\n",
599 GCCH_2s (ch)); 586 GCCH_2s (ch));
600 options = 0;
601 if (ch->nobuffer)
602 options |= GNUNET_CADET_OPTION_NOBUFFER;
603 if (ch->reliable)
604 options |= GNUNET_CADET_OPTION_RELIABLE;
605 if (ch->out_of_order)
606 options |= GNUNET_CADET_OPTION_OUT_OF_ORDER;
607 msgcc.header.size = htons (sizeof (msgcc)); 587 msgcc.header.size = htons (sizeof (msgcc));
608 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); 588 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN);
609 msgcc.opt = htonl (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.
590 msgcc.opt = 2;
610 msgcc.h_port = ch->h_port; 591 msgcc.h_port = ch->h_port;
611 msgcc.ctn = ch->ctn; 592 msgcc.ctn = ch->ctn;
612 ch->state = CADET_CHANNEL_OPEN_SENT; 593 ch->state = CADET_CHANNEL_OPEN_SENT;
613 if (NULL != ch->last_control_qe) 594 if (NULL != ch->last_control_qe)
614 GCT_send_cancel (ch->last_control_qe); 595 GCT_send_cancel (ch->last_control_qe);
615 ch->last_control_qe = GCT_send (ch->t, 596 ch->last_control_qe =
616 &msgcc.header, 597 GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch);
617 &channel_open_sent_cb,
618 ch);
619 GNUNET_assert (NULL == ch->retry_control_task); 598 GNUNET_assert (NULL == ch->retry_control_task);
620} 599}
621 600
@@ -637,9 +616,7 @@ GCCH_tunnel_up (struct CadetChannel *ch)
637 LOG (GNUNET_ERROR_TYPE_DEBUG, 616 LOG (GNUNET_ERROR_TYPE_DEBUG,
638 "Tunnel up, sending CHANNEL_OPEN on %s now\n", 617 "Tunnel up, sending CHANNEL_OPEN on %s now\n",
639 GCCH_2s (ch)); 618 GCCH_2s (ch));
640 ch->retry_control_task 619 ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_channel_open, ch);
641 = GNUNET_SCHEDULER_add_now (&send_channel_open,
642 ch);
643} 620}
644 621
645 622
@@ -670,54 +647,45 @@ GCCH_channel_local_new (struct CadetClient *owner,
670 647
671 ch = GNUNET_new (struct CadetChannel); 648 ch = GNUNET_new (struct CadetChannel);
672 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! */
673 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER)); 650 ch->nobuffer = GNUNET_NO;
674 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE)); 651 ch->reliable = GNUNET_YES;
675 ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER)); 652 ch->out_of_order = GNUNET_NO;
676 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! */
677 ch->owner = ccco; 655 ch->owner = ccco;
678 ch->port = *port; 656 ch->port = *port;
679 GCCH_hash_port (&ch->h_port, 657 GCCH_hash_port (&ch->h_port, port, GCP_get_id (destination));
680 port, 658 if (0 == GNUNET_memcmp (&my_full_id, GCP_get_id (destination)))
681 GCP_get_id (destination));
682 if (0 == GNUNET_memcmp (&my_full_id,
683 GCP_get_id (destination)))
684 { 659 {
685 struct OpenPort *op; 660 struct OpenPort *op;
686 661
687 ch->is_loopback = GNUNET_YES; 662 ch->is_loopback = GNUNET_YES;
688 op = GNUNET_CONTAINER_multihashmap_get (open_ports, 663 op = GNUNET_CONTAINER_multihashmap_get (open_ports, &ch->h_port);
689 &ch->h_port);
690 if (NULL == op) 664 if (NULL == op)
691 { 665 {
692 /* port closed, wait for it to possibly open */ 666 /* port closed, wait for it to possibly open */
693 ch->state = CADET_CHANNEL_LOOSE; 667 ch->state = CADET_CHANNEL_LOOSE;
694 (void) GNUNET_CONTAINER_multihashmap_put (loose_channels, 668 (void) GNUNET_CONTAINER_multihashmap_put (
695 &ch->h_port, 669 loose_channels,
696 ch, 670 &ch->h_port,
697 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 671 ch,
672 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
698 LOG (GNUNET_ERROR_TYPE_DEBUG, 673 LOG (GNUNET_ERROR_TYPE_DEBUG,
699 "Created loose incoming loopback channel to port %s\n", 674 "Created loose incoming loopback channel to port %s\n",
700 GNUNET_h2s (&ch->port)); 675 GNUNET_h2s (&ch->port));
701 } 676 }
702 else 677 else
703 { 678 {
704 GCCH_bind (ch, 679 GCCH_bind (ch, op->c, &op->port);
705 op->c,
706 &op->port);
707 } 680 }
708 } 681 }
709 else 682 else
710 { 683 {
711 ch->t = GCP_get_tunnel (destination, 684 ch->t = GCP_get_tunnel (destination, GNUNET_YES);
712 GNUNET_YES);
713 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; 685 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
714 ch->ctn = GCT_add_channel (ch->t, 686 ch->ctn = GCT_add_channel (ch->t, ch);
715 ch);
716 } 687 }
717 GNUNET_STATISTICS_update (stats, 688 GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO);
718 "# channels",
719 1,
720 GNUNET_NO);
721 LOG (GNUNET_ERROR_TYPE_DEBUG, 689 LOG (GNUNET_ERROR_TYPE_DEBUG,
722 "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",
723 GNUNET_h2s (port), 691 GNUNET_h2s (port),
@@ -771,30 +739,27 @@ GCCH_channel_incoming_new (struct CadetTunnel *t,
771 ch->t = t; 739 ch->t = t;
772 ch->ctn = ctn; 740 ch->ctn = ctn;
773 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; 741 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
774 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER)); 742 ch->nobuffer = GNUNET_NO;
775 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE)); 743 ch->reliable = GNUNET_YES;
776 ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER)); 744 ch->out_of_order = GNUNET_NO;
777 ch->max_pending_messages = (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ 745 ch->max_pending_messages =
778 GNUNET_STATISTICS_update (stats, 746 (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */
779 "# channels", 747 GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO);
780 1, 748
781 GNUNET_NO); 749 op = GNUNET_CONTAINER_multihashmap_get (open_ports, h_port);
782
783 op = GNUNET_CONTAINER_multihashmap_get (open_ports,
784 h_port);
785 if (NULL == op) 750 if (NULL == op)
786 { 751 {
787 /* port closed, wait for it to possibly open */ 752 /* port closed, wait for it to possibly open */
788 ch->state = CADET_CHANNEL_LOOSE; 753 ch->state = CADET_CHANNEL_LOOSE;
789 (void) GNUNET_CONTAINER_multihashmap_put (loose_channels, 754 (void) GNUNET_CONTAINER_multihashmap_put (
790 &ch->h_port, 755 loose_channels,
791 ch, 756 &ch->h_port,
792 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 757 ch,
758 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
793 GNUNET_assert (NULL == ch->retry_control_task); 759 GNUNET_assert (NULL == ch->retry_control_task);
794 ch->retry_control_task 760 ch->retry_control_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT,
795 = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, 761 &timeout_closed_cb,
796 &timeout_closed_cb, 762 ch);
797 ch);
798 LOG (GNUNET_ERROR_TYPE_DEBUG, 763 LOG (GNUNET_ERROR_TYPE_DEBUG,
799 "Created loose incoming channel to port %s from peer %s\n", 764 "Created loose incoming channel to port %s from peer %s\n",
800 GNUNET_h2s (&ch->port), 765 GNUNET_h2s (&ch->port),
@@ -802,14 +767,9 @@ GCCH_channel_incoming_new (struct CadetTunnel *t,
802 } 767 }
803 else 768 else
804 { 769 {
805 GCCH_bind (ch, 770 GCCH_bind (ch, op->c, &op->port);
806 op->c,
807 &op->port);
808 } 771 }
809 GNUNET_STATISTICS_update (stats, 772 GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO);
810 "# channels",
811 1,
812 GNUNET_NO);
813 return ch; 773 return ch;
814} 774}
815 775
@@ -858,10 +818,7 @@ send_channel_data_ack (struct CadetChannel *ch)
858 GCCH_2s (ch)); 818 GCCH_2s (ch));
859 if (NULL != ch->last_control_qe) 819 if (NULL != ch->last_control_qe)
860 GCT_send_cancel (ch->last_control_qe); 820 GCT_send_cancel (ch->last_control_qe);
861 ch->last_control_qe = GCT_send (ch->t, 821 ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch);
862 &msg.header,
863 &send_ack_cb,
864 ch);
865} 822}
866 823
867 824
@@ -888,10 +845,7 @@ send_open_ack (void *cls)
888 msg.port = ch->port; 845 msg.port = ch->port;
889 if (NULL != ch->last_control_qe) 846 if (NULL != ch->last_control_qe)
890 GCT_send_cancel (ch->last_control_qe); 847 GCT_send_cancel (ch->last_control_qe);
891 ch->last_control_qe = GCT_send (ch->t, 848 ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch);
892 &msg.header,
893 &send_ack_cb,
894 ch);
895} 849}
896 850
897 851
@@ -904,8 +858,9 @@ send_open_ack (void *cls)
904 * @param cti identifier of the connection that delivered the message 858 * @param cti identifier of the connection that delivered the message
905 */ 859 */
906void 860void
907GCCH_handle_duplicate_open (struct CadetChannel *ch, 861GCCH_handle_duplicate_open (
908 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) 862 struct CadetChannel *ch,
863 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti)
909{ 864{
910 if (NULL == ch->dest) 865 if (NULL == ch->dest)
911 { 866 {
@@ -924,9 +879,7 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch,
924 LOG (GNUNET_ERROR_TYPE_DEBUG, 879 LOG (GNUNET_ERROR_TYPE_DEBUG,
925 "Retransmitting CHANNEL_OPEN_ACK on %s\n", 880 "Retransmitting CHANNEL_OPEN_ACK on %s\n",
926 GCCH_2s (ch)); 881 GCCH_2s (ch));
927 ch->retry_control_task 882 ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch);
928 = GNUNET_SCHEDULER_add_now (&send_open_ack,
929 ch);
930} 883}
931 884
932 885
@@ -938,8 +891,7 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch,
938 * #GNUNET_NO to send to dest 891 * #GNUNET_NO to send to dest
939 */ 892 */
940static void 893static void
941send_ack_to_client (struct CadetChannel *ch, 894send_ack_to_client (struct CadetChannel *ch, int to_owner)
942 int to_owner)
943{ 895{
944 struct GNUNET_MQ_Envelope *env; 896 struct GNUNET_MQ_Envelope *env;
945 struct GNUNET_CADET_LocalAck *ack; 897 struct GNUNET_CADET_LocalAck *ack;
@@ -953,8 +905,7 @@ send_ack_to_client (struct CadetChannel *ch,
953 GNUNET_assert (GNUNET_YES == ch->destroy); 905 GNUNET_assert (GNUNET_YES == ch->destroy);
954 return; 906 return;
955 } 907 }
956 env = GNUNET_MQ_msg (ack, 908 env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
957 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
958 ack->ccn = ccc->ccn; 909 ack->ccn = ccc->ccn;
959 LOG (GNUNET_ERROR_TYPE_DEBUG, 910 LOG (GNUNET_ERROR_TYPE_DEBUG,
960 "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",
@@ -963,8 +914,7 @@ send_ack_to_client (struct CadetChannel *ch,
963 ntohl (ack->ccn.channel_of_client), 914 ntohl (ack->ccn.channel_of_client),
964 ch->pending_messages, 915 ch->pending_messages,
965 ch->max_pending_messages); 916 ch->max_pending_messages);
966 GSC_send_to_client (ccc->c, 917 GSC_send_to_client (ccc->c, env);
967 env);
968} 918}
969 919
970 920
@@ -980,7 +930,7 @@ send_ack_to_client (struct CadetChannel *ch,
980void 930void
981GCCH_bind (struct CadetChannel *ch, 931GCCH_bind (struct CadetChannel *ch,
982 struct CadetClient *c, 932 struct CadetClient *c,
983 const struct GNUNET_HashCode *port) 933 const struct GNUNET_HashCode *port)
984{ 934{
985 uint32_t options; 935 uint32_t options;
986 struct CadetChannelClient *cccd; 936 struct CadetChannelClient *cccd;
@@ -998,12 +948,6 @@ GCCH_bind (struct CadetChannel *ch,
998 ch->retry_control_task = NULL; 948 ch->retry_control_task = NULL;
999 } 949 }
1000 options = 0; 950 options = 0;
1001 if (ch->nobuffer)
1002 options |= GNUNET_CADET_OPTION_NOBUFFER;
1003 if (ch->reliable)
1004 options |= GNUNET_CADET_OPTION_RELIABLE;
1005 if (ch->out_of_order)
1006 options |= GNUNET_CADET_OPTION_OUT_OF_ORDER;
1007 cccd = GNUNET_new (struct CadetChannelClient); 951 cccd = GNUNET_new (struct CadetChannelClient);
1008 GNUNET_assert (NULL == ch->dest); 952 GNUNET_assert (NULL == ch->dest);
1009 ch->dest = cccd; 953 ch->dest = cccd;
@@ -1013,9 +957,8 @@ GCCH_bind (struct CadetChannel *ch,
1013 cccd->ccn = GSC_bind (c, 957 cccd->ccn = GSC_bind (c,
1014 ch, 958 ch,
1015 (GNUNET_YES == ch->is_loopback) 959 (GNUNET_YES == ch->is_loopback)
1016 ? GCP_get (&my_full_id, 960 ? GCP_get (&my_full_id, GNUNET_YES)
1017 GNUNET_YES) 961 : GCT_get_destination (ch->t),
1018 : GCT_get_destination (ch->t),
1019 port, 962 port,
1020 options); 963 options);
1021 GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < 964 GNUNET_assert (ntohl (cccd->ccn.channel_of_client) <
@@ -1024,24 +967,19 @@ GCCH_bind (struct CadetChannel *ch,
1024 if (GNUNET_YES == ch->is_loopback) 967 if (GNUNET_YES == ch->is_loopback)
1025 { 968 {
1026 ch->state = CADET_CHANNEL_OPEN_SENT; 969 ch->state = CADET_CHANNEL_OPEN_SENT;
1027 GCCH_handle_channel_open_ack (ch, 970 GCCH_handle_channel_open_ack (ch, NULL, port);
1028 NULL,
1029 port);
1030 } 971 }
1031 else 972 else
1032 { 973 {
1033 /* notify other peer that we accepted the connection */ 974 /* notify other peer that we accepted the connection */
1034 ch->state = CADET_CHANNEL_READY; 975 ch->state = CADET_CHANNEL_READY;
1035 ch->retry_control_task 976 ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch);
1036 = GNUNET_SCHEDULER_add_now (&send_open_ack,
1037 ch);
1038 } 977 }
1039 /* give client it's initial supply of ACKs */ 978 /* give client it's initial supply of ACKs */
1040 GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < 979 GNUNET_assert (ntohl (cccd->ccn.channel_of_client) <
1041 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); 980 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
1042 for (unsigned int i=0;i<ch->max_pending_messages;i++) 981 for (unsigned int i = 0; i < ch->max_pending_messages; i++)
1043 send_ack_to_client (ch, 982 send_ack_to_client (ch, GNUNET_NO);
1044 GNUNET_NO);
1045} 983}
1046 984
1047 985
@@ -1061,9 +999,7 @@ signal_remote_destroy_cb (void *cls)
1061 /* Find which end is left... */ 999 /* Find which end is left... */
1062 ch->retry_control_task = NULL; 1000 ch->retry_control_task = NULL;
1063 ccc = (NULL != ch->owner) ? ch->owner : ch->dest; 1001 ccc = (NULL != ch->owner) ? ch->owner : ch->dest;
1064 GSC_handle_remote_channel_destroy (ccc->c, 1002 GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch);
1065 ccc->ccn,
1066 ch);
1067 channel_destroy (ch); 1003 channel_destroy (ch);
1068} 1004}
1069 1005
@@ -1086,16 +1022,14 @@ GCCH_channel_local_destroy (struct CadetChannel *ch,
1086 GSC_2s (c), 1022 GSC_2s (c),
1087 GCCH_2s (ch)); 1023 GCCH_2s (ch));
1088 GNUNET_assert (NULL != c); 1024 GNUNET_assert (NULL != c);
1089 if ( (NULL != ch->owner) && 1025 if ((NULL != ch->owner) && (c == ch->owner->c) &&
1090 (c == ch->owner->c) && 1026 (ccn.channel_of_client == ch->owner->ccn.channel_of_client))
1091 (ccn.channel_of_client == ch->owner->ccn.channel_of_client) )
1092 { 1027 {
1093 free_channel_client (ch->owner); 1028 free_channel_client (ch->owner);
1094 ch->owner = NULL; 1029 ch->owner = NULL;
1095 } 1030 }
1096 else if ( (NULL != ch->dest) && 1031 else if ((NULL != ch->dest) && (c == ch->dest->c) &&
1097 (c == ch->dest->c) && 1032 (ccn.channel_of_client == ch->dest->ccn.channel_of_client))
1098 (ccn.channel_of_client == ch->dest->ccn.channel_of_client) )
1099 { 1033 {
1100 free_channel_client (ch->dest); 1034 free_channel_client (ch->dest);
1101 ch->dest = NULL; 1035 ch->dest = NULL;
@@ -1112,24 +1046,20 @@ GCCH_channel_local_destroy (struct CadetChannel *ch,
1112 channel_destroy (ch); 1046 channel_destroy (ch);
1113 return; 1047 return;
1114 } 1048 }
1115 if ( (NULL != ch->head_sent) && 1049 if ((NULL != ch->head_sent) && ((NULL != ch->owner) || (NULL != ch->dest)))
1116 ( (NULL != ch->owner) ||
1117 (NULL != ch->dest) ) )
1118 { 1050 {
1119 /* Wait for other end to destroy us as well, 1051 /* Wait for other end to destroy us as well,
1120 and otherwise allow send queue to be transmitted first */ 1052 and otherwise allow send queue to be transmitted first */
1121 ch->destroy = GNUNET_YES; 1053 ch->destroy = GNUNET_YES;
1122 return; 1054 return;
1123 } 1055 }
1124 if ( (GNUNET_YES == ch->is_loopback) && 1056 if ((GNUNET_YES == ch->is_loopback) &&
1125 ( (NULL != ch->owner) || 1057 ((NULL != ch->owner) || (NULL != ch->dest)))
1126 (NULL != ch->dest) ) )
1127 { 1058 {
1128 if (NULL != ch->retry_control_task) 1059 if (NULL != ch->retry_control_task)
1129 GNUNET_SCHEDULER_cancel (ch->retry_control_task); 1060 GNUNET_SCHEDULER_cancel (ch->retry_control_task);
1130 ch->retry_control_task 1061 ch->retry_control_task =
1131 = GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, 1062 GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, ch);
1132 ch);
1133 return; 1063 return;
1134 } 1064 }
1135 if (GNUNET_NO == ch->is_loopback) 1065 if (GNUNET_NO == ch->is_loopback)
@@ -1144,8 +1074,7 @@ GCCH_channel_local_destroy (struct CadetChannel *ch,
1144 case CADET_CHANNEL_LOOSE: 1074 case CADET_CHANNEL_LOOSE:
1145 break; 1075 break;
1146 default: 1076 default:
1147 GCT_send_channel_destroy (ch->t, 1077 GCT_send_channel_destroy (ch->t, ch->ctn);
1148 ch->ctn);
1149 } 1078 }
1150 } 1079 }
1151 /* Nothing left to do, just finish destruction */ 1080 /* Nothing left to do, just finish destruction */
@@ -1163,9 +1092,10 @@ GCCH_channel_local_destroy (struct CadetChannel *ch,
1163 * @param port port number (needed to verify receiver knows the port) 1092 * @param port port number (needed to verify receiver knows the port)
1164 */ 1093 */
1165void 1094void
1166GCCH_handle_channel_open_ack (struct CadetChannel *ch, 1095GCCH_handle_channel_open_ack (
1167 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1096 struct CadetChannel *ch,
1168 const struct GNUNET_HashCode *port) 1097 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1098 const struct GNUNET_HashCode *port)
1169{ 1099{
1170 switch (ch->state) 1100 switch (ch->state)
1171 { 1101 {
@@ -1184,8 +1114,7 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch,
1184 GNUNET_break_op (0); 1114 GNUNET_break_op (0);
1185 return; 1115 return;
1186 } 1116 }
1187 if (0 != GNUNET_memcmp (&ch->port, 1117 if (0 != GNUNET_memcmp (&ch->port, port))
1188 port))
1189 { 1118 {
1190 /* Other peer failed to provide the right port, 1119 /* Other peer failed to provide the right port,
1191 refuse connection. */ 1120 refuse connection. */
@@ -1203,19 +1132,15 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch,
1203 ch->state = CADET_CHANNEL_READY; 1132 ch->state = CADET_CHANNEL_READY;
1204 /* 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
1205 to be buffered! */ 1134 to be buffered! */
1206 for (unsigned int i=0;i<ch->max_pending_messages;i++) 1135 for (unsigned int i = 0; i < ch->max_pending_messages; i++)
1207 send_ack_to_client (ch, 1136 send_ack_to_client (ch, GNUNET_YES);
1208 GNUNET_YES);
1209 break; 1137 break;
1210 case CADET_CHANNEL_READY: 1138 case CADET_CHANNEL_READY:
1211 /* duplicate ACK, maybe we retried the CREATE. Ignore. */ 1139 /* duplicate ACK, maybe we retried the CREATE. Ignore. */
1212 LOG (GNUNET_ERROR_TYPE_DEBUG, 1140 LOG (GNUNET_ERROR_TYPE_DEBUG,
1213 "Received duplicate channel OPEN_ACK for %s\n", 1141 "Received duplicate channel OPEN_ACK for %s\n",
1214 GCCH_2s (ch)); 1142 GCCH_2s (ch));
1215 GNUNET_STATISTICS_update (stats, 1143 GNUNET_STATISTICS_update (stats, "# duplicate CREATE_ACKs", 1, GNUNET_NO);
1216 "# duplicate CREATE_ACKs",
1217 1,
1218 GNUNET_NO);
1219 break; 1144 break;
1220 } 1145 }
1221} 1146}
@@ -1264,9 +1189,10 @@ is_before (void *cls,
1264 * @param msg message that was received 1189 * @param msg message that was received
1265 */ 1190 */
1266void 1191void
1267GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, 1192GCCH_handle_channel_plaintext_data (
1268 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1193 struct CadetChannel *ch,
1269 const struct GNUNET_CADET_ChannelAppDataMessage *msg) 1194 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1195 const struct GNUNET_CADET_ChannelAppDataMessage *msg)
1270{ 1196{
1271 struct GNUNET_MQ_Envelope *env; 1197 struct GNUNET_MQ_Envelope *env;
1272 struct GNUNET_CADET_LocalData *ld; 1198 struct GNUNET_CADET_LocalData *ld;
@@ -1280,8 +1206,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1280 uint32_t delta; 1206 uint32_t delta;
1281 1207
1282 GNUNET_assert (GNUNET_NO == ch->is_loopback); 1208 GNUNET_assert (GNUNET_NO == ch->is_loopback);
1283 if ( (NULL == ch->owner) && 1209 if ((NULL == ch->owner) && (NULL == ch->dest))
1284 (NULL == ch->dest) )
1285 { 1210 {
1286 /* 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
1287 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,
@@ -1291,8 +1216,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1291 GCCH_2s (ch)); 1216 GCCH_2s (ch));
1292 /* send back DESTROY notification to stop further retransmissions! */ 1217 /* send back DESTROY notification to stop further retransmissions! */
1293 if (GNUNET_YES == ch->destroy) 1218 if (GNUNET_YES == ch->destroy)
1294 GCT_send_channel_destroy (ch->t, 1219 GCT_send_channel_destroy (ch->t, ch->ctn);
1295 ch->ctn);
1296 return; 1220 return;
1297 } 1221 }
1298 payload_size = ntohs (msg->header.size) - sizeof (*msg); 1222 payload_size = ntohs (msg->header.size) - sizeof (*msg);
@@ -1300,9 +1224,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1300 payload_size, 1224 payload_size,
1301 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 1225 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
1302 ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; 1226 ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn;
1303 GNUNET_memcpy (&ld[1], 1227 GNUNET_memcpy (&ld[1], &msg[1], payload_size);
1304 &msg[1],
1305 payload_size);
1306 ccc = (NULL != ch->owner) ? ch->owner : ch->dest; 1228 ccc = (NULL != ch->owner) ? ch->owner : ch->dest;
1307 if (GNUNET_YES == ccc->client_ready) 1229 if (GNUNET_YES == ccc->client_ready)
1308 { 1230 {
@@ -1312,13 +1234,12 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1312 * - The channel is reliable and MID matches next expected MID 1234 * - The channel is reliable and MID matches next expected MID
1313 * - The channel is unreliable and MID is before lowest seen MID 1235 * - The channel is unreliable and MID is before lowest seen MID
1314 */ 1236 */
1315 if ( (GNUNET_YES == ch->out_of_order) || 1237 if ((GNUNET_YES == ch->out_of_order) ||
1316 ((msg->mid.mid == ch->mid_recv.mid) && 1238 ((msg->mid.mid == ch->mid_recv.mid) && (GNUNET_YES == ch->reliable)) ||
1317 (GNUNET_YES == ch->reliable)) || 1239 ((GNUNET_NO == ch->reliable) &&
1318 ((GNUNET_NO == ch->reliable) && 1240 (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) &&
1319 (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) && 1241 ((NULL == ccc->head_recv) ||
1320 ((NULL == ccc->head_recv) || 1242 (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid)))))
1321 (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid)))) )
1322 { 1243 {
1323 LOG (GNUNET_ERROR_TYPE_DEBUG, 1244 LOG (GNUNET_ERROR_TYPE_DEBUG,
1324 "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",
@@ -1327,24 +1248,22 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1327 GCCH_2s (ch), 1248 GCCH_2s (ch),
1328 GSC_2s (ccc->c)); 1249 GSC_2s (ccc->c));
1329 ccc->client_ready = GNUNET_NO; 1250 ccc->client_ready = GNUNET_NO;
1330 GSC_send_to_client (ccc->c, 1251 GSC_send_to_client (ccc->c, env);
1331 env);
1332 if (GNUNET_NO == ch->out_of_order) 1252 if (GNUNET_NO == ch->out_of_order)
1333 ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); 1253 ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid));
1334 else 1254 else
1335 ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid)); 1255 ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid));
1336 ch->mid_futures >>= 1; 1256 ch->mid_futures >>= 1;
1337 if ( (GNUNET_YES == ch->out_of_order) && 1257 if ((GNUNET_YES == ch->out_of_order) && (GNUNET_NO == ch->reliable))
1338 (GNUNET_NO == ch->reliable) )
1339 { 1258 {
1340 /* possibly shift by more if we skipped messages */ 1259 /* possibly shift by more if we skipped messages */
1341 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);
1342 1261
1343 if (delta > 63) 1262 if (delta > 63)
1344 ch->mid_futures = 0; 1263 ch->mid_futures = 0;
1345 else 1264 else
1346 ch->mid_futures >>= delta; 1265 ch->mid_futures >>= delta;
1347 ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); 1266 ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid));
1348 } 1267 }
1349 send_channel_data_ack (ch); 1268 send_channel_data_ack (ch);
1350 return; 1269 return;
@@ -1357,8 +1276,8 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1357 mid_min = ntohl (ch->mid_recv.mid); 1276 mid_min = ntohl (ch->mid_recv.mid);
1358 mid_max = mid_min + ch->max_pending_messages; 1277 mid_max = mid_min + ch->max_pending_messages;
1359 mid_msg = ntohl (msg->mid.mid); 1278 mid_msg = ntohl (msg->mid.mid);
1360 if ( ( (uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) || 1279 if (((uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) ||
1361 ( (uint32_t) (mid_max - mid_msg) > ch->max_pending_messages) ) 1280 ((uint32_t) (mid_max - mid_msg) > ch->max_pending_messages))
1362 { 1281 {
1363 LOG (GNUNET_ERROR_TYPE_DEBUG, 1282 LOG (GNUNET_ERROR_TYPE_DEBUG,
1364 "%s at %u drops ancient or far-future message %u\n", 1283 "%s at %u drops ancient or far-future message %u\n",
@@ -1386,10 +1305,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1386 (unsigned int) payload_size, 1305 (unsigned int) payload_size,
1387 GCCH_2s (ch), 1306 GCCH_2s (ch),
1388 ntohl (msg->mid.mid)); 1307 ntohl (msg->mid.mid));
1389 GNUNET_STATISTICS_update (stats, 1308 GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO);
1390 "# duplicate DATA",
1391 1,
1392 GNUNET_NO);
1393 GNUNET_MQ_discard (env); 1309 GNUNET_MQ_discard (env);
1394 send_channel_data_ack (ch); 1310 send_channel_data_ack (ch);
1395 return; 1311 return;
@@ -1411,8 +1327,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1411 * We always send if possible in this case. 1327 * We always send if possible in this case.
1412 * It is guaranteed that the queued MID < received MID 1328 * It is guaranteed that the queued MID < received MID
1413 **/ 1329 **/
1414 if ((NULL != ccc->head_recv) && 1330 if ((NULL != ccc->head_recv) && (GNUNET_YES == ccc->client_ready))
1415 (GNUNET_YES == ccc->client_ready))
1416 { 1331 {
1417 next_msg = ccc->head_recv; 1332 next_msg = ccc->head_recv;
1418 LOG (GNUNET_ERROR_TYPE_DEBUG, 1333 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1421,14 +1336,11 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1421 GCCH_2s (ch), 1336 GCCH_2s (ch),
1422 GSC_2s (ccc->c)); 1337 GSC_2s (ccc->c));
1423 ccc->client_ready = GNUNET_NO; 1338 ccc->client_ready = GNUNET_NO;
1424 GSC_send_to_client (ccc->c, 1339 GSC_send_to_client (ccc->c, next_msg->env);
1425 next_msg->env);
1426 ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid)); 1340 ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid));
1427 ch->mid_futures >>= 1; 1341 ch->mid_futures >>= 1;
1428 send_channel_data_ack (ch); 1342 send_channel_data_ack (ch);
1429 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, 1343 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, next_msg);
1430 ccc->tail_recv,
1431 next_msg);
1432 ccc->num_recv--; 1344 ccc->num_recv--;
1433 /* Do not process duplicate MID */ 1345 /* Do not process duplicate MID */
1434 if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */ 1346 if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */
@@ -1473,9 +1385,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1473 GNUNET_NO); 1385 GNUNET_NO);
1474 drop = ccc->head_recv; 1386 drop = ccc->head_recv;
1475 GNUNET_assert (NULL != drop); 1387 GNUNET_assert (NULL != drop);
1476 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, 1388 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, drop);
1477 ccc->tail_recv,
1478 drop);
1479 ccc->num_recv--; 1389 ccc->num_recv--;
1480 GNUNET_MQ_discard (drop->env); 1390 GNUNET_MQ_discard (drop->env);
1481 GNUNET_free (drop); 1391 GNUNET_free (drop);
@@ -1506,13 +1416,8 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1506 (unsigned int) payload_size, 1416 (unsigned int) payload_size,
1507 GCCH_2s (ch), 1417 GCCH_2s (ch),
1508 ntohl (msg->mid.mid)); 1418 ntohl (msg->mid.mid));
1509 GNUNET_STATISTICS_update (stats, 1419 GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO);
1510 "# duplicate DATA", 1420 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
1511 1,
1512 GNUNET_NO);
1513 GNUNET_CONTAINER_DLL_remove (ccc->head_recv,
1514 ccc->tail_recv,
1515 com);
1516 ccc->num_recv--; 1421 ccc->num_recv--;
1517 GNUNET_MQ_discard (com->env); 1422 GNUNET_MQ_discard (com->env);
1518 GNUNET_free (com); 1423 GNUNET_free (com);
@@ -1521,9 +1426,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1521 } 1426 }
1522 LOG (GNUNET_ERROR_TYPE_DEBUG, 1427 LOG (GNUNET_ERROR_TYPE_DEBUG,
1523 "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",
1524 (GNUNET_YES == ccc->client_ready) 1429 (GNUNET_YES == ccc->client_ready) ? "out-of-order" : "client-not-ready",
1525 ? "out-of-order"
1526 : "client-not-ready",
1527 (unsigned int) payload_size, 1430 (unsigned int) payload_size,
1528 GCCH_2s (ch), 1431 GCCH_2s (ch),
1529 ntohl (ccc->ccn.channel_of_client), 1432 ntohl (ccc->ccn.channel_of_client),
@@ -1571,10 +1474,7 @@ retry_transmission (void *cls)
1571 "Retrying transmission on %s of message %u\n", 1474 "Retrying transmission on %s of message %u\n",
1572 GCCH_2s (ch), 1475 GCCH_2s (ch),
1573 (unsigned int) ntohl (crm->data_message->mid.mid)); 1476 (unsigned int) ntohl (crm->data_message->mid.mid));
1574 crm->qe = GCT_send (ch->t, 1477 crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm);
1575 &crm->data_message->header,
1576 &data_sent_cb,
1577 crm);
1578 GNUNET_assert (NULL == ch->retry_data_task); 1478 GNUNET_assert (NULL == ch->retry_data_task);
1579} 1479}
1580 1480
@@ -1592,9 +1492,7 @@ handle_matching_ack (struct CadetChannel *ch,
1592 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1492 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1593 struct CadetReliableMessage *crm) 1493 struct CadetReliableMessage *crm)
1594{ 1494{
1595 GNUNET_CONTAINER_DLL_remove (ch->head_sent, 1495 GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm);
1596 ch->tail_sent,
1597 crm);
1598 ch->pending_messages--; 1496 ch->pending_messages--;
1599 GNUNET_assert (ch->pending_messages < ch->max_pending_messages); 1497 GNUNET_assert (ch->pending_messages < ch->max_pending_messages);
1600 LOG (GNUNET_ERROR_TYPE_DEBUG, 1498 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1607,23 +1505,19 @@ handle_matching_ack (struct CadetChannel *ch,
1607 GCT_send_cancel (crm->qe); 1505 GCT_send_cancel (crm->qe);
1608 crm->qe = NULL; 1506 crm->qe = NULL;
1609 } 1507 }
1610 if ( (1 == crm->num_transmissions) && 1508 if ((1 == crm->num_transmissions) && (NULL != cti))
1611 (NULL != cti) )
1612 { 1509 {
1613 GCC_ack_observed (cti); 1510 GCC_ack_observed (cti);
1614 if (0 == GNUNET_memcmp (cti, 1511 if (0 == GNUNET_memcmp (cti, &crm->connection_taken))
1615 &crm->connection_taken))
1616 { 1512 {
1617 GCC_latency_observed (cti, 1513 GCC_latency_observed (cti,
1618 GNUNET_TIME_absolute_get_duration (crm->first_transmission_time)); 1514 GNUNET_TIME_absolute_get_duration (
1515 crm->first_transmission_time));
1619 } 1516 }
1620 } 1517 }
1621 GNUNET_free (crm->data_message); 1518 GNUNET_free (crm->data_message);
1622 GNUNET_free (crm); 1519 GNUNET_free (crm);
1623 send_ack_to_client (ch, 1520 send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES);
1624 (NULL == ch->owner)
1625 ? GNUNET_NO
1626 : GNUNET_YES);
1627} 1521}
1628 1522
1629 1523
@@ -1636,9 +1530,10 @@ handle_matching_ack (struct CadetChannel *ch,
1636 * @param ack details about what was received 1530 * @param ack details about what was received
1637 */ 1531 */
1638void 1532void
1639GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, 1533GCCH_handle_channel_plaintext_data_ack (
1640 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1534 struct CadetChannel *ch,
1641 const struct GNUNET_CADET_ChannelDataAckMessage *ack) 1535 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1536 const struct GNUNET_CADET_ChannelDataAckMessage *ack)
1642{ 1537{
1643 struct CadetReliableMessage *crm; 1538 struct CadetReliableMessage *crm;
1644 struct CadetReliableMessage *crmn; 1539 struct CadetReliableMessage *crmn;
@@ -1660,9 +1555,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1660 mid_base = ntohl (ack->mid.mid); 1555 mid_base = ntohl (ack->mid.mid);
1661 mid_mask = GNUNET_htonll (ack->futures); 1556 mid_mask = GNUNET_htonll (ack->futures);
1662 found = GNUNET_NO; 1557 found = GNUNET_NO;
1663 for (crm = ch->head_sent; 1558 for (crm = ch->head_sent; NULL != crm; crm = crmn)
1664 NULL != crm;
1665 crm = crmn)
1666 { 1559 {
1667 crmn = crm->next; 1560 crmn = crm->next;
1668 delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base); 1561 delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base);
@@ -1674,9 +1567,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1674 (unsigned int) mid_base, 1567 (unsigned int) mid_base,
1675 ntohl (crm->data_message->mid.mid), 1568 ntohl (crm->data_message->mid.mid),
1676 GCCH_2s (ch)); 1569 GCCH_2s (ch));
1677 handle_matching_ack (ch, 1570 handle_matching_ack (ch, cti, crm);
1678 cti,
1679 crm);
1680 found = GNUNET_YES; 1571 found = GNUNET_YES;
1681 continue; 1572 continue;
1682 } 1573 }
@@ -1694,9 +1585,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1694 "Got DATA_ACK with mask for %u on %s\n", 1585 "Got DATA_ACK with mask for %u on %s\n",
1695 ntohl (crm->data_message->mid.mid), 1586 ntohl (crm->data_message->mid.mid),
1696 GCCH_2s (ch)); 1587 GCCH_2s (ch));
1697 handle_matching_ack (ch, 1588 handle_matching_ack (ch, cti, crm);
1698 cti,
1699 crm);
1700 found = GNUNET_YES; 1589 found = GNUNET_YES;
1701 } 1590 }
1702 } 1591 }
@@ -1707,10 +1596,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1707 LOG (GNUNET_ERROR_TYPE_DEBUG, 1596 LOG (GNUNET_ERROR_TYPE_DEBUG,
1708 "Duplicate DATA_ACK on %s, ignoring\n", 1597 "Duplicate DATA_ACK on %s, ignoring\n",
1709 GCCH_2s (ch)); 1598 GCCH_2s (ch));
1710 GNUNET_STATISTICS_update (stats, 1599 GNUNET_STATISTICS_update (stats, "# duplicate DATA_ACKs", 1, GNUNET_NO);
1711 "# duplicate DATA_ACKs",
1712 1,
1713 GNUNET_NO);
1714 return; 1600 return;
1715 } 1601 }
1716 if (NULL != ch->retry_data_task) 1602 if (NULL != ch->retry_data_task)
@@ -1718,12 +1604,10 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1718 GNUNET_SCHEDULER_cancel (ch->retry_data_task); 1604 GNUNET_SCHEDULER_cancel (ch->retry_data_task);
1719 ch->retry_data_task = NULL; 1605 ch->retry_data_task = NULL;
1720 } 1606 }
1721 if ( (NULL != ch->head_sent) && 1607 if ((NULL != ch->head_sent) && (NULL == ch->head_sent->qe))
1722 (NULL == ch->head_sent->qe) ) 1608 ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry,
1723 ch->retry_data_task 1609 &retry_transmission,
1724 = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, 1610 ch);
1725 &retry_transmission,
1726 ch);
1727} 1611}
1728 1612
1729 1613
@@ -1737,8 +1621,9 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1737 * NULL if we are simulating receiving a destroy due to shutdown 1621 * NULL if we are simulating receiving a destroy due to shutdown
1738 */ 1622 */
1739void 1623void
1740GCCH_handle_remote_destroy (struct CadetChannel *ch, 1624GCCH_handle_remote_destroy (
1741 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) 1625 struct CadetChannel *ch,
1626 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti)
1742{ 1627{
1743 struct CadetChannelClient *ccc; 1628 struct CadetChannelClient *ccc;
1744 1629
@@ -1753,8 +1638,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch,
1753 return; 1638 return;
1754 } 1639 }
1755 ccc = (NULL != ch->owner) ? ch->owner : ch->dest; 1640 ccc = (NULL != ch->owner) ? ch->owner : ch->dest;
1756 if ( (NULL != ccc) && 1641 if ((NULL != ccc) && (NULL != ccc->head_recv))
1757 (NULL != ccc->head_recv) )
1758 { 1642 {
1759 LOG (GNUNET_ERROR_TYPE_WARNING, 1643 LOG (GNUNET_ERROR_TYPE_WARNING,
1760 "Lost end of transmission due to remote shutdown on %s\n", 1644 "Lost end of transmission due to remote shutdown on %s\n",
@@ -1763,9 +1647,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch,
1763 } 1647 }
1764 ch->destroy = GNUNET_YES; 1648 ch->destroy = GNUNET_YES;
1765 if (NULL != ccc) 1649 if (NULL != ccc)
1766 GSC_handle_remote_channel_destroy (ccc->c, 1650 GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch);
1767 ccc->ccn,
1768 ch);
1769 channel_destroy (ch); 1651 channel_destroy (ch);
1770} 1652}
1771 1653
@@ -1783,8 +1665,7 @@ cmp_crm_by_next_retry (void *cls,
1783 struct CadetReliableMessage *crm1, 1665 struct CadetReliableMessage *crm1,
1784 struct CadetReliableMessage *crm2) 1666 struct CadetReliableMessage *crm2)
1785{ 1667{
1786 if (crm1->next_retry.abs_value_us < 1668 if (crm1->next_retry.abs_value_us < crm2->next_retry.abs_value_us)
1787 crm2->next_retry.abs_value_us)
1788 return GNUNET_YES; 1669 return GNUNET_YES;
1789 return GNUNET_NO; 1670 return GNUNET_NO;
1790} 1671}
@@ -1810,18 +1691,13 @@ data_sent_cb (void *cls,
1810 GNUNET_assert (GNUNET_NO == ch->is_loopback); 1691 GNUNET_assert (GNUNET_NO == ch->is_loopback);
1811 GNUNET_assert (NULL != crm->qe); 1692 GNUNET_assert (NULL != crm->qe);
1812 crm->qe = NULL; 1693 crm->qe = NULL;
1813 GNUNET_CONTAINER_DLL_remove (ch->head_sent, 1694 GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm);
1814 ch->tail_sent,
1815 crm);
1816 if (GNUNET_NO == ch->reliable) 1695 if (GNUNET_NO == ch->reliable)
1817 { 1696 {
1818 GNUNET_free (crm->data_message); 1697 GNUNET_free (crm->data_message);
1819 GNUNET_free (crm); 1698 GNUNET_free (crm);
1820 ch->pending_messages--; 1699 ch->pending_messages--;
1821 send_ack_to_client (ch, 1700 send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES);
1822 (NULL == ch->owner)
1823 ? GNUNET_NO
1824 : GNUNET_YES);
1825 return; 1701 return;
1826 } 1702 }
1827 if (NULL == cid) 1703 if (NULL == cid)
@@ -1841,8 +1717,7 @@ data_sent_cb (void *cls,
1841 GCC_ack_expected (cid); 1717 GCC_ack_expected (cid);
1842 } 1718 }
1843 } 1719 }
1844 if ( (0 == crm->retry_delay.rel_value_us) && 1720 if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid))
1845 (NULL != cid) )
1846 { 1721 {
1847 struct CadetConnection *cc = GCC_lookup (cid); 1722 struct CadetConnection *cc = GCC_lookup (cid);
1848 1723
@@ -1852,8 +1727,7 @@ data_sent_cb (void *cls,
1852 crm->retry_delay = ch->retry_time; 1727 crm->retry_delay = ch->retry_time;
1853 } 1728 }
1854 crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay); 1729 crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay);
1855 crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, 1730 crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, MIN_RTT_DELAY);
1856 MIN_RTT_DELAY);
1857 crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay); 1731 crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay);
1858 1732
1859 GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage, 1733 GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage,
@@ -1866,16 +1740,16 @@ data_sent_cb (void *cls,
1866 "Message %u sent, next transmission on %s in %s\n", 1740 "Message %u sent, next transmission on %s in %s\n",
1867 (unsigned int) ntohl (crm->data_message->mid.mid), 1741 (unsigned int) ntohl (crm->data_message->mid.mid),
1868 GCCH_2s (ch), 1742 GCCH_2s (ch),
1869 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),
1870 GNUNET_YES)); 1745 GNUNET_YES));
1871 if (NULL == ch->head_sent->qe) 1746 if (NULL == ch->head_sent->qe)
1872 { 1747 {
1873 if (NULL != ch->retry_data_task) 1748 if (NULL != ch->retry_data_task)
1874 GNUNET_SCHEDULER_cancel (ch->retry_data_task); 1749 GNUNET_SCHEDULER_cancel (ch->retry_data_task);
1875 ch->retry_data_task 1750 ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry,
1876 = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, 1751 &retry_transmission,
1877 &retry_transmission, 1752 ch);
1878 ch);
1879 } 1753 }
1880} 1754}
1881 1755
@@ -1921,19 +1795,16 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1921 struct GNUNET_CADET_LocalData *ld; 1795 struct GNUNET_CADET_LocalData *ld;
1922 int ack_to_owner; 1796 int ack_to_owner;
1923 1797
1924 env = GNUNET_MQ_msg_extra (ld, 1798 env =
1925 buf_len, 1799 GNUNET_MQ_msg_extra (ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
1926 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 1800 if ((NULL != ch->owner) &&
1927 if ( (NULL != ch->owner) && 1801 (sender_ccn.channel_of_client == ch->owner->ccn.channel_of_client))
1928 (sender_ccn.channel_of_client ==
1929 ch->owner->ccn.channel_of_client) )
1930 { 1802 {
1931 receiver = ch->dest; 1803 receiver = ch->dest;
1932 ack_to_owner = GNUNET_YES; 1804 ack_to_owner = GNUNET_YES;
1933 } 1805 }
1934 else if ( (NULL != ch->dest) && 1806 else if ((NULL != ch->dest) &&
1935 (sender_ccn.channel_of_client == 1807 (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client))
1936 ch->dest->ccn.channel_of_client) )
1937 { 1808 {
1938 receiver = ch->owner; 1809 receiver = ch->owner;
1939 ack_to_owner = GNUNET_NO; 1810 ack_to_owner = GNUNET_NO;
@@ -1945,16 +1816,12 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1945 } 1816 }
1946 GNUNET_assert (NULL != receiver); 1817 GNUNET_assert (NULL != receiver);
1947 ld->ccn = receiver->ccn; 1818 ld->ccn = receiver->ccn;
1948 GNUNET_memcpy (&ld[1], 1819 GNUNET_memcpy (&ld[1], buf, buf_len);
1949 buf,
1950 buf_len);
1951 if (GNUNET_YES == receiver->client_ready) 1820 if (GNUNET_YES == receiver->client_ready)
1952 { 1821 {
1953 ch->pending_messages--; 1822 ch->pending_messages--;
1954 GSC_send_to_client (receiver->c, 1823 GSC_send_to_client (receiver->c, env);
1955 env); 1824 send_ack_to_client (ch, ack_to_owner);
1956 send_ack_to_client (ch,
1957 ack_to_owner);
1958 } 1825 }
1959 else 1826 else
1960 { 1827 {
@@ -1973,19 +1840,17 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1973 /* Everything is correct, send the message. */ 1840 /* Everything is correct, send the message. */
1974 crm = GNUNET_malloc (sizeof (*crm)); 1841 crm = GNUNET_malloc (sizeof (*crm));
1975 crm->ch = ch; 1842 crm->ch = ch;
1976 crm->data_message = GNUNET_malloc (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) 1843 crm->data_message = GNUNET_malloc (
1977 + buf_len); 1844 sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len);
1978 crm->data_message->header.size = htons (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); 1845 crm->data_message->header.size =
1979 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);
1980 ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); 1849 ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1);
1981 crm->data_message->mid = ch->mid_send; 1850 crm->data_message->mid = ch->mid_send;
1982 crm->data_message->ctn = ch->ctn; 1851 crm->data_message->ctn = ch->ctn;
1983 GNUNET_memcpy (&crm->data_message[1], 1852 GNUNET_memcpy (&crm->data_message[1], buf, buf_len);
1984 buf, 1853 GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, ch->tail_sent, crm);
1985 buf_len);
1986 GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent,
1987 ch->tail_sent,
1988 crm);
1989 LOG (GNUNET_ERROR_TYPE_DEBUG, 1854 LOG (GNUNET_ERROR_TYPE_DEBUG,
1990 "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",
1991 ntohl (crm->data_message->mid.mid), 1856 ntohl (crm->data_message->mid.mid),
@@ -1996,10 +1861,7 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1996 GNUNET_SCHEDULER_cancel (ch->retry_data_task); 1861 GNUNET_SCHEDULER_cancel (ch->retry_data_task);
1997 ch->retry_data_task = NULL; 1862 ch->retry_data_task = NULL;
1998 } 1863 }
1999 crm->qe = GCT_send (ch->t, 1864 crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm);
2000 &crm->data_message->header,
2001 &data_sent_cb,
2002 crm);
2003 GNUNET_assert (NULL == ch->retry_data_task); 1865 GNUNET_assert (NULL == ch->retry_data_task);
2004 return GNUNET_OK; 1866 return GNUNET_OK;
2005} 1867}
@@ -2019,11 +1881,11 @@ GCCH_handle_local_ack (struct CadetChannel *ch,
2019 struct CadetChannelClient *ccc; 1881 struct CadetChannelClient *ccc;
2020 struct CadetOutOfOrderMessage *com; 1882 struct CadetOutOfOrderMessage *com;
2021 1883
2022 if ( (NULL != ch->owner) && 1884 if ((NULL != ch->owner) &&
2023 (ch->owner->ccn.channel_of_client == client_ccn.channel_of_client) ) 1885 (ch->owner->ccn.channel_of_client == client_ccn.channel_of_client))
2024 ccc = ch->owner; 1886 ccc = ch->owner;
2025 else if ( (NULL != ch->dest) && 1887 else if ((NULL != ch->dest) &&
2026 (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client) ) 1888 (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client))
2027 ccc = ch->dest; 1889 ccc = ch->dest;
2028 else 1890 else
2029 GNUNET_assert (0); 1891 GNUNET_assert (0);
@@ -2045,35 +1907,28 @@ GCCH_handle_local_ack (struct CadetChannel *ch,
2045 int to_owner; 1907 int to_owner;
2046 1908
2047 /* Messages are always in-order, just send */ 1909 /* Messages are always in-order, just send */
2048 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, 1910 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
2049 ccc->tail_recv,
2050 com);
2051 ccc->num_recv--; 1911 ccc->num_recv--;
2052 GSC_send_to_client (ccc->c, 1912 GSC_send_to_client (ccc->c, com->env);
2053 com->env);
2054 /* Notify sender that we can receive more */ 1913 /* Notify sender that we can receive more */
2055 if ( (NULL != ch->owner) && 1914 if ((NULL != ch->owner) &&
2056 (ccc->ccn.channel_of_client == 1915 (ccc->ccn.channel_of_client == ch->owner->ccn.channel_of_client))
2057 ch->owner->ccn.channel_of_client) )
2058 { 1916 {
2059 to_owner = GNUNET_NO; 1917 to_owner = GNUNET_NO;
2060 } 1918 }
2061 else 1919 else
2062 { 1920 {
2063 GNUNET_assert ( (NULL != ch->dest) && 1921 GNUNET_assert ((NULL != ch->dest) && (ccc->ccn.channel_of_client ==
2064 (ccc->ccn.channel_of_client == 1922 ch->dest->ccn.channel_of_client));
2065 ch->dest->ccn.channel_of_client) );
2066 to_owner = GNUNET_YES; 1923 to_owner = GNUNET_YES;
2067 } 1924 }
2068 send_ack_to_client (ch, 1925 send_ack_to_client (ch, to_owner);
2069 to_owner);
2070 GNUNET_free (com); 1926 GNUNET_free (com);
2071 return; 1927 return;
2072 } 1928 }
2073 1929
2074 if ( (com->mid.mid != ch->mid_recv.mid) && 1930 if ((com->mid.mid != ch->mid_recv.mid) && (GNUNET_NO == ch->out_of_order) &&
2075 (GNUNET_NO == ch->out_of_order) && 1931 (GNUNET_YES == ch->reliable))
2076 (GNUNET_YES == ch->reliable) )
2077 { 1932 {
2078 LOG (GNUNET_ERROR_TYPE_DEBUG, 1933 LOG (GNUNET_ERROR_TYPE_DEBUG,
2079 "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",
@@ -2092,9 +1947,7 @@ GCCH_handle_local_ack (struct CadetChannel *ch,
2092 GCCH_2s (ch)); 1947 GCCH_2s (ch));
2093 1948
2094 /* all good, pass next message to client */ 1949 /* all good, pass next message to client */
2095 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, 1950 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
2096 ccc->tail_recv,
2097 com);
2098 ccc->num_recv--; 1951 ccc->num_recv--;
2099 /* FIXME: if unreliable, this is not aggressive 1952 /* FIXME: if unreliable, this is not aggressive
2100 enough, as it would be OK to have lost some! */ 1953 enough, as it would be OK to have lost some! */
@@ -2102,21 +1955,20 @@ GCCH_handle_local_ack (struct CadetChannel *ch,
2102 ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid)); 1955 ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid));
2103 ch->mid_futures >>= 1; /* equivalent to division by 2 */ 1956 ch->mid_futures >>= 1; /* equivalent to division by 2 */
2104 ccc->client_ready = GNUNET_NO; 1957 ccc->client_ready = GNUNET_NO;
2105 GSC_send_to_client (ccc->c, 1958 GSC_send_to_client (ccc->c, com->env);
2106 com->env);
2107 GNUNET_free (com); 1959 GNUNET_free (com);
2108 send_channel_data_ack (ch); 1960 send_channel_data_ack (ch);
2109 if (NULL != ccc->head_recv) 1961 if (NULL != ccc->head_recv)
2110 return; 1962 return;
2111 if (GNUNET_NO == ch->destroy) 1963 if (GNUNET_NO == ch->destroy)
2112 return; 1964 return;
2113 GCT_send_channel_destroy (ch->t, 1965 GCT_send_channel_destroy (ch->t, ch->ctn);
2114 ch->ctn);
2115 channel_destroy (ch); 1966 channel_destroy (ch);
2116} 1967}
2117 1968
2118 1969
2119#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__)
2120 1972
2121 1973
2122/** 1974/**
@@ -2126,15 +1978,16 @@ GCCH_handle_local_ack (struct CadetChannel *ch,
2126 * @param level Debug level to use. 1978 * @param level Debug level to use.
2127 */ 1979 */
2128void 1980void
2129GCCH_debug (struct CadetChannel *ch, 1981GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level)
2130 enum GNUNET_ErrorType level)
2131{ 1982{
2132#if !defined(GNUNET_CULL_LOGGING) 1983#if ! defined(GNUNET_CULL_LOGGING)
2133 int do_log; 1984 int do_log;
2134 1985
2135 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),
2136 "cadet-chn", 1987 "cadet-chn",
2137 __FILE__, __FUNCTION__, __LINE__); 1988 __FILE__,
1989 __FUNCTION__,
1990 __LINE__);
2138 if (0 == do_log) 1991 if (0 == do_log)
2139 return; 1992 return;
2140 1993
@@ -2143,11 +1996,7 @@ GCCH_debug (struct CadetChannel *ch,
2143 LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n"); 1996 LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n");
2144 return; 1997 return;
2145 } 1998 }
2146 LOG2 (level, 1999 LOG2 (level, "CHN %s:%X (%p)\n", GCT_2s (ch->t), ch->ctn, ch);
2147 "CHN %s:%X (%p)\n",
2148 GCT_2s (ch->t),
2149 ch->ctn,
2150 ch);
2151 if (NULL != ch->owner) 2000 if (NULL != ch->owner)
2152 { 2001 {
2153 LOG2 (level, 2002 LOG2 (level,
@@ -2173,5 +2022,4 @@ GCCH_debug (struct CadetChannel *ch,
2173} 2022}
2174 2023
2175 2024
2176
2177/* 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 1f7e86d60..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/**
@@ -161,11 +162,6 @@ struct CadetConnection
161 enum CadetConnectionState state; 162 enum CadetConnectionState state;
162 163
163 /** 164 /**
164 * Options for the route, control buffering.
165 */
166 enum GNUNET_CADET_ChannelOption options;
167
168 /**
169 * How many latency observations did we make for this connection? 165 * How many latency observations did we make for this connection?
170 */ 166 */
171 unsigned int latency_datapoints; 167 unsigned int latency_datapoints;
@@ -179,7 +175,6 @@ struct CadetConnection
179 * Are we ready to transmit via @e mq_man right now? 175 * Are we ready to transmit via @e mq_man right now?
180 */ 176 */
181 int mqm_ready; 177 int mqm_ready;
182
183}; 178};
184 179
185 180
@@ -213,18 +208,16 @@ update_state (struct CadetConnection *cc,
213 int old_ready; 208 int old_ready;
214 int new_ready; 209 int new_ready;
215 210
216 if ( (new_state == cc->state) && 211 if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready))
217 (new_mqm_ready == cc->mqm_ready) )
218 return; /* no change, nothing to do */ 212 return; /* no change, nothing to do */
219 old_ready = ( (CADET_CONNECTION_READY == cc->state) && 213 old_ready =
220 (GNUNET_YES == cc->mqm_ready) ); 214 ((CADET_CONNECTION_READY == cc->state) && (GNUNET_YES == cc->mqm_ready));
221 new_ready = ( (CADET_CONNECTION_READY == new_state) && 215 new_ready =
222 (GNUNET_YES == new_mqm_ready) ); 216 ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready));
223 cc->state = new_state; 217 cc->state = new_state;
224 cc->mqm_ready = new_mqm_ready; 218 cc->mqm_ready = new_mqm_ready;
225 if (old_ready != new_ready) 219 if (old_ready != new_ready)
226 cc->ready_cb (cc->ready_cb_cls, 220 cc->ready_cb (cc->ready_cb_cls, new_ready);
227 new_ready);
228} 221}
229 222
230 223
@@ -237,13 +230,10 @@ update_state (struct CadetConnection *cc,
237static void 230static void
238GCC_destroy (struct CadetConnection *cc) 231GCC_destroy (struct CadetConnection *cc)
239{ 232{
240 LOG (GNUNET_ERROR_TYPE_DEBUG, 233 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s (cc));
241 "Destroying %s\n",
242 GCC_2s (cc));
243 if (NULL != cc->mq_man) 234 if (NULL != cc->mq_man)
244 { 235 {
245 GCP_request_mq_cancel (cc->mq_man, 236 GCP_request_mq_cancel (cc->mq_man, NULL);
246 NULL);
247 cc->mq_man = NULL; 237 cc->mq_man = NULL;
248 } 238 }
249 if (NULL != cc->task) 239 if (NULL != cc->task)
@@ -256,22 +246,19 @@ GCC_destroy (struct CadetConnection *cc)
256 GCT_send_cancel (cc->keepalive_qe); 246 GCT_send_cancel (cc->keepalive_qe);
257 cc->keepalive_qe = NULL; 247 cc->keepalive_qe = NULL;
258 } 248 }
259 GCPP_del_connection (cc->path, 249 GCPP_del_connection (cc->path, cc->off, cc);
260 cc->off, 250 for (unsigned int i = 0; i < cc->off; i++)
261 cc); 251 GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, i), cc);
262 for (unsigned int i=0;i<cc->off;i++) 252 GNUNET_assert (
263 GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, 253 GNUNET_YES ==
264 i), 254 GNUNET_CONTAINER_multishortmap_remove (connections,
265 cc); 255 &GCC_get_id (cc)
266 GNUNET_assert (GNUNET_YES == 256 ->connection_of_tunnel,
267 GNUNET_CONTAINER_multishortmap_remove (connections, 257 cc));
268 &GCC_get_id (cc)->connection_of_tunnel,
269 cc));
270 GNUNET_free (cc); 258 GNUNET_free (cc);
271} 259}
272 260
273 261
274
275/** 262/**
276 * Destroy a connection, called when the CORE layer is already done 263 * Destroy a connection, called when the CORE layer is already done
277 * (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
@@ -303,18 +290,16 @@ void
303GCC_destroy_without_tunnel (struct CadetConnection *cc) 290GCC_destroy_without_tunnel (struct CadetConnection *cc)
304{ 291{
305 cc->ct = NULL; 292 cc->ct = NULL;
306 if ( (CADET_CONNECTION_SENDING_CREATE != cc->state) && 293 if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man))
307 (NULL != cc->mq_man) )
308 { 294 {
309 struct GNUNET_MQ_Envelope *env; 295 struct GNUNET_MQ_Envelope *env;
310 struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg; 296 struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg;
311 297
312 /* Need to notify next hop that we are down. */ 298 /* Need to notify next hop that we are down. */
313 env = GNUNET_MQ_msg (destroy_msg, 299 env =
314 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); 300 GNUNET_MQ_msg (destroy_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY);
315 destroy_msg->cid = cc->cid; 301 destroy_msg->cid = cc->cid;
316 GCP_request_mq_cancel (cc->mq_man, 302 GCP_request_mq_cancel (cc->mq_man, env);
317 env);
318 cc->mq_man = NULL; 303 cc->mq_man = NULL;
319 } 304 }
320 GCC_destroy (cc); 305 GCC_destroy (cc);
@@ -372,11 +357,9 @@ keepalive_done (void *cls,
372 struct CadetConnection *cc = cls; 357 struct CadetConnection *cc = cls;
373 358
374 cc->keepalive_qe = NULL; 359 cc->keepalive_qe = NULL;
375 if ( (GNUNET_YES == cc->mqm_ready) && 360 if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task))
376 (NULL == cc->task) ) 361 cc->task =
377 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, 362 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
378 &send_keepalive,
379 cc);
380} 363}
381 364
382 365
@@ -396,9 +379,8 @@ send_keepalive (void *cls)
396 if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t)) 379 if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t))
397 { 380 {
398 /* Tunnel not yet ready, wait with keepalives... */ 381 /* Tunnel not yet ready, wait with keepalives... */
399 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, 382 cc->task =
400 &send_keepalive, 383 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
401 cc);
402 return; 384 return;
403 } 385 }
404 GNUNET_assert (NULL != cc->ct); 386 GNUNET_assert (NULL != cc->ct);
@@ -408,18 +390,11 @@ send_keepalive (void *cls)
408 "Sending KEEPALIVE on behalf of %s via %s\n", 390 "Sending KEEPALIVE on behalf of %s via %s\n",
409 GCC_2s (cc), 391 GCC_2s (cc),
410 GCT_2s (cc->ct->t)); 392 GCT_2s (cc->ct->t));
411 GNUNET_STATISTICS_update (stats, 393 GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO);
412 "# keepalives sent",
413 1,
414 GNUNET_NO);
415 msg.size = htons (sizeof (msg)); 394 msg.size = htons (sizeof (msg));
416 msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); 395 msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE);
417 396
418 cc->keepalive_qe 397 cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc);
419 = GCT_send (cc->ct->t,
420 &msg,
421 &keepalive_done,
422 cc);
423} 398}
424 399
425 400
@@ -480,10 +455,7 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
480 cc = GCC_lookup (cid); 455 cc = GCC_lookup (cid);
481 if (NULL == cc) 456 if (NULL == cc)
482 return; /* whopise, connection alredy down? */ 457 return; /* whopise, connection alredy down? */
483 GNUNET_STATISTICS_update (stats, 458 GNUNET_STATISTICS_update (stats, "# latencies observed", 1, GNUNET_NO);
484 "# latencies observed",
485 1,
486 GNUNET_NO);
487 cc->latency_datapoints++; 459 cc->latency_datapoints++;
488 if (cc->latency_datapoints >= 7) 460 if (cc->latency_datapoints >= 7)
489 weight = 7.0; 461 weight = 7.0;
@@ -492,7 +464,8 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
492 /* Compute weighted average, giving at MOST weight 7 to the 464 /* Compute weighted average, giving at MOST weight 7 to the
493 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
494 measurements. */ 466 measurements. */
495 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;
496 result /= (weight + 1.0); 469 result /= (weight + 1.0);
497 cc->metrics.aged_latency.rel_value_us = (uint64_t) result; 470 cc->metrics.aged_latency.rel_value_us = (uint64_t) result;
498} 471}
@@ -521,15 +494,11 @@ GCC_handle_connection_create_ack (struct CadetConnection *cc)
521 cc->task = NULL; 494 cc->task = NULL;
522 } 495 }
523 cc->metrics.age = GNUNET_TIME_absolute_get (); 496 cc->metrics.age = GNUNET_TIME_absolute_get ();
524 update_state (cc, 497 update_state (cc, CADET_CONNECTION_READY, cc->mqm_ready);
525 CADET_CONNECTION_READY, 498 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
526 cc->mqm_ready); 499 (NULL == cc->task))
527 if ( (NULL == cc->keepalive_qe) && 500 cc->task =
528 (GNUNET_YES == cc->mqm_ready) && 501 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
529 (NULL == cc->task) )
530 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period,
531 &send_keepalive,
532 cc);
533} 502}
534 503
535 504
@@ -557,8 +526,7 @@ GCC_handle_kx (struct CadetConnection *cc,
557 GCC_2s (cc)); 526 GCC_2s (cc));
558 GCC_handle_connection_create_ack (cc); 527 GCC_handle_connection_create_ack (cc);
559 } 528 }
560 GCT_handle_kx (cc->ct, 529 GCT_handle_kx (cc->ct, msg);
561 msg);
562} 530}
563 531
564 532
@@ -586,8 +554,7 @@ GCC_handle_kx_auth (struct CadetConnection *cc,
586 GCC_2s (cc)); 554 GCC_2s (cc));
587 GCC_handle_connection_create_ack (cc); 555 GCC_handle_connection_create_ack (cc);
588 } 556 }
589 GCT_handle_kx_auth (cc->ct, 557 GCT_handle_kx_auth (cc->ct, msg);
590 msg);
591} 558}
592 559
593 560
@@ -611,8 +578,7 @@ GCC_handle_encrypted (struct CadetConnection *cc,
611 GCC_handle_connection_create_ack (cc); 578 GCC_handle_connection_create_ack (cc);
612 } 579 }
613 cc->metrics.last_use = GNUNET_TIME_absolute_get (); 580 cc->metrics.last_use = GNUNET_TIME_absolute_get ();
614 GCT_handle_encrypted (cc->ct, 581 GCT_handle_encrypted (cc->ct, msg);
615 msg);
616} 582}
617 583
618 584
@@ -632,16 +598,17 @@ send_create (void *cls)
632 598
633 cc->task = NULL; 599 cc->task = NULL;
634 GNUNET_assert (GNUNET_YES == cc->mqm_ready); 600 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
635 env = GNUNET_MQ_msg_extra (create_msg, 601 env =
636 (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity), 602 GNUNET_MQ_msg_extra (create_msg,
637 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); 603 (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity),
638 create_msg->options = htonl ((uint32_t) cc->options); 604 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE);
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;
639 create_msg->cid = cc->cid; 607 create_msg->cid = cc->cid;
640 pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; 608 pids = (struct GNUNET_PeerIdentity *) &create_msg[1];
641 pids[0] = my_full_id; 609 pids[0] = my_full_id;
642 for (unsigned int i=0;i<=cc->off;i++) 610 for (unsigned int i = 0; i <= cc->off; i++)
643 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));
644 i));
645 LOG (GNUNET_ERROR_TYPE_DEBUG, 612 LOG (GNUNET_ERROR_TYPE_DEBUG,
646 "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n", 613 "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n",
647 GCC_2s (cc), 614 GCC_2s (cc),
@@ -649,11 +616,8 @@ send_create (void *cls)
649 cc->env = env; 616 cc->env = env;
650 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); 617 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay);
651 cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); 618 cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay);
652 update_state (cc, 619 update_state (cc, CADET_CONNECTION_SENT, GNUNET_NO);
653 CADET_CONNECTION_SENT, 620 GCP_send (cc->mq_man, env);
654 GNUNET_NO);
655 GCP_send (cc->mq_man,
656 env);
657} 621}
658 622
659 623
@@ -674,22 +638,18 @@ send_create_ack (void *cls)
674 "Sending CONNECTION_CREATE_ACK message for %s\n", 638 "Sending CONNECTION_CREATE_ACK message for %s\n",
675 GCC_2s (cc)); 639 GCC_2s (cc));
676 GNUNET_assert (GNUNET_YES == cc->mqm_ready); 640 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
677 env = GNUNET_MQ_msg (ack_msg, 641 env =
678 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); 642 GNUNET_MQ_msg (ack_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK);
679 ack_msg->cid = cc->cid; 643 ack_msg->cid = cc->cid;
680 cc->env = env; 644 cc->env = env;
681 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); 645 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay);
682 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);
683 if (CADET_CONNECTION_CREATE_RECEIVED == cc->state) 647 if (CADET_CONNECTION_CREATE_RECEIVED == cc->state)
684 update_state (cc, 648 update_state (cc, CADET_CONNECTION_READY, GNUNET_NO);
685 CADET_CONNECTION_READY,
686 GNUNET_NO);
687 if (CADET_CONNECTION_READY == cc->state) 649 if (CADET_CONNECTION_READY == cc->state)
688 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, 650 cc->task =
689 &send_keepalive, 651 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
690 cc); 652 GCP_send (cc->mq_man, env);
691 GCP_send (cc->mq_man,
692 env);
693} 653}
694 654
695 655
@@ -711,14 +671,11 @@ GCC_handle_duplicate_create (struct CadetConnection *cc)
711 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); 671 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
712 /* Revert back to the state of having only received the 'CREATE', 672 /* Revert back to the state of having only received the 'CREATE',
713 and immediately proceed to send the CREATE_ACK. */ 673 and immediately proceed to send the CREATE_ACK. */
714 update_state (cc, 674 update_state (cc, CADET_CONNECTION_CREATE_RECEIVED, cc->mqm_ready);
715 CADET_CONNECTION_CREATE_RECEIVED,
716 cc->mqm_ready);
717 if (NULL != cc->task) 675 if (NULL != cc->task)
718 GNUNET_SCHEDULER_cancel (cc->task); 676 GNUNET_SCHEDULER_cancel (cc->task);
719 cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, 677 cc->task =
720 &send_create_ack, 678 GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc);
721 cc);
722 } 679 }
723 else 680 else
724 { 681 {
@@ -743,20 +700,15 @@ GCC_handle_duplicate_create (struct CadetConnection *cc)
743 * and the last envelope was discarded 700 * and the last envelope was discarded
744 */ 701 */
745static void 702static void
746manage_first_hop_mq (void *cls, 703manage_first_hop_mq (void *cls, int available)
747 int available)
748{ 704{
749 struct CadetConnection *cc = cls; 705 struct CadetConnection *cc = cls;
750 706
751 if (GNUNET_YES != available) 707 if (GNUNET_YES != available)
752 { 708 {
753 /* Connection is down, for now... */ 709 /* Connection is down, for now... */
754 LOG (GNUNET_ERROR_TYPE_DEBUG, 710 LOG (GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s (cc));
755 "Core MQ for %s went down\n", 711 update_state (cc, CADET_CONNECTION_NEW, GNUNET_NO);
756 GCC_2s (cc));
757 update_state (cc,
758 CADET_CONNECTION_NEW,
759 GNUNET_NO);
760 cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY; 712 cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY;
761 if (NULL != cc->task) 713 if (NULL != cc->task)
762 { 714 {
@@ -766,9 +718,7 @@ manage_first_hop_mq (void *cls,
766 return; 718 return;
767 } 719 }
768 720
769 update_state (cc, 721 update_state (cc, cc->state, GNUNET_YES);
770 cc->state,
771 GNUNET_YES);
772 LOG (GNUNET_ERROR_TYPE_DEBUG, 722 LOG (GNUNET_ERROR_TYPE_DEBUG,
773 "Core MQ for %s became available in state %d\n", 723 "Core MQ for %s became available in state %d\n",
774 GCC_2s (cc), 724 GCC_2s (cc),
@@ -777,9 +727,7 @@ manage_first_hop_mq (void *cls,
777 { 727 {
778 case CADET_CONNECTION_NEW: 728 case CADET_CONNECTION_NEW:
779 /* Transmit immediately */ 729 /* Transmit immediately */
780 cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, 730 cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc);
781 &send_create,
782 cc);
783 break; 731 break;
784 case CADET_CONNECTION_SENDING_CREATE: 732 case CADET_CONNECTION_SENDING_CREATE:
785 /* Should not be possible to be called in this state. */ 733 /* Should not be possible to be called in this state. */
@@ -787,30 +735,25 @@ manage_first_hop_mq (void *cls,
787 break; 735 break;
788 case CADET_CONNECTION_SENT: 736 case CADET_CONNECTION_SENT:
789 /* Retry a bit later... */ 737 /* Retry a bit later... */
790 cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, 738 cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc);
791 &send_create,
792 cc);
793 break; 739 break;
794 case CADET_CONNECTION_CREATE_RECEIVED: 740 case CADET_CONNECTION_CREATE_RECEIVED:
795 /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */ 741 /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */
796 cc->metrics.age = GNUNET_TIME_absolute_get (); 742 cc->metrics.age = GNUNET_TIME_absolute_get ();
797 cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, 743 cc->task =
798 &send_create_ack, 744 GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc);
799 cc);
800 break; 745 break;
801 case CADET_CONNECTION_READY: 746 case CADET_CONNECTION_READY:
802 if ( (NULL == cc->keepalive_qe) && 747 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
803 (GNUNET_YES == cc->mqm_ready) && 748 (NULL == cc->task))
804 (NULL == cc->task) )
805 { 749 {
806 LOG (GNUNET_ERROR_TYPE_DEBUG, 750 LOG (GNUNET_ERROR_TYPE_DEBUG,
807 "Scheduling keepalive for %s in %s\n", 751 "Scheduling keepalive for %s in %s\n",
808 GCC_2s (cc), 752 GCC_2s (cc),
809 GNUNET_STRINGS_relative_time_to_string (keepalive_period, 753 GNUNET_STRINGS_relative_time_to_string (keepalive_period,
810 GNUNET_YES)); 754 GNUNET_YES));
811 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, 755 cc->task =
812 &send_keepalive, 756 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
813 cc);
814 } 757 }
815 break; 758 break;
816 } 759 }
@@ -825,7 +768,6 @@ manage_first_hop_mq (void *cls,
825 * @param destination where to go 768 * @param destination where to go
826 * @param path which path to take (may not be the full path) 769 * @param path which path to take (may not be the full path)
827 * @param off offset of @a destination on @a path 770 * @param off offset of @a destination on @a path
828 * @param options options for the connection
829 * @param ct which tunnel uses this connection 771 * @param ct which tunnel uses this connection
830 * @param init_state initial state for the connection 772 * @param init_state initial state for the connection
831 * @param ready_cb function to call when ready to transmit 773 * @param ready_cb function to call when ready to transmit
@@ -836,7 +778,6 @@ static struct CadetConnection *
836connection_create (struct CadetPeer *destination, 778connection_create (struct CadetPeer *destination,
837 struct CadetPeerPath *path, 779 struct CadetPeerPath *path,
838 unsigned int off, 780 unsigned int off,
839 enum GNUNET_CADET_ChannelOption options,
840 struct CadetTConnection *ct, 781 struct CadetTConnection *ct,
841 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 782 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
842 enum CadetConnectionState init_state, 783 enum CadetConnectionState init_state,
@@ -847,17 +788,17 @@ connection_create (struct CadetPeer *destination,
847 struct CadetPeer *first_hop; 788 struct CadetPeer *first_hop;
848 789
849 cc = GNUNET_new (struct CadetConnection); 790 cc = GNUNET_new (struct CadetConnection);
850 cc->options = options;
851 cc->state = init_state; 791 cc->state = init_state;
852 cc->ct = ct; 792 cc->ct = ct;
853 cc->cid = *cid; 793 cc->cid = *cid;
854 cc->retry_delay = GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, 794 cc->retry_delay =
855 off); 795 GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off);
856 GNUNET_assert (GNUNET_OK == 796 GNUNET_assert (GNUNET_OK ==
857 GNUNET_CONTAINER_multishortmap_put (connections, 797 GNUNET_CONTAINER_multishortmap_put (
858 &GCC_get_id (cc)->connection_of_tunnel, 798 connections,
859 cc, 799 &GCC_get_id (cc)->connection_of_tunnel,
860 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 800 cc,
801 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
861 cc->ready_cb = ready_cb; 802 cc->ready_cb = ready_cb;
862 cc->ready_cb_cls = ready_cb_cls; 803 cc->ready_cb_cls = ready_cb_cls;
863 cc->path = path; 804 cc->path = path;
@@ -867,18 +808,11 @@ connection_create (struct CadetPeer *destination,
867 GCC_2s (cc), 808 GCC_2s (cc),
868 GCPP_2s (path), 809 GCPP_2s (path),
869 off); 810 off);
870 GCPP_add_connection (path, 811 GCPP_add_connection (path, off, cc);
871 off, 812 for (unsigned int i = 0; i < off; i++)
872 cc); 813 GCP_add_connection (GCPP_get_peer_at_offset (path, i), cc);
873 for (unsigned int i=0;i<off;i++) 814 first_hop = GCPP_get_peer_at_offset (path, 0);
874 GCP_add_connection (GCPP_get_peer_at_offset (path, 815 cc->mq_man = GCP_request_mq (first_hop, &manage_first_hop_mq, cc);
875 i),
876 cc);
877 first_hop = GCPP_get_peer_at_offset (path,
878 0);
879 cc->mq_man = GCP_request_mq (first_hop,
880 &manage_first_hop_mq,
881 cc);
882 return cc; 816 return cc;
883} 817}
884 818
@@ -890,7 +824,6 @@ connection_create (struct CadetPeer *destination,
890 * 824 *
891 * @param destination where to go 825 * @param destination where to go
892 * @param path which path to take (may not be the full path) 826 * @param path which path to take (may not be the full path)
893 * @param options options for the connection
894 * @param ct which tunnel uses this connection 827 * @param ct which tunnel uses this connection
895 * @param ready_cb function to call when ready to transmit 828 * @param ready_cb function to call when ready to transmit
896 * @param ready_cb_cls closure for @a cb 829 * @param ready_cb_cls closure for @a cb
@@ -900,7 +833,6 @@ connection_create (struct CadetPeer *destination,
900struct CadetConnection * 833struct CadetConnection *
901GCC_create_inbound (struct CadetPeer *destination, 834GCC_create_inbound (struct CadetPeer *destination,
902 struct CadetPeerPath *path, 835 struct CadetPeerPath *path,
903 enum GNUNET_CADET_ChannelOption options,
904 struct CadetTConnection *ct, 836 struct CadetTConnection *ct,
905 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 837 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
906 GCC_ReadyCallback ready_cb, 838 GCC_ReadyCallback ready_cb,
@@ -909,18 +841,14 @@ GCC_create_inbound (struct CadetPeer *destination,
909 struct CadetConnection *cc; 841 struct CadetConnection *cc;
910 unsigned int off; 842 unsigned int off;
911 843
912 off = GCPP_find_peer (path, 844 off = GCPP_find_peer (path, destination);
913 destination);
914 GNUNET_assert (UINT_MAX != off); 845 GNUNET_assert (UINT_MAX != off);
915 cc = GCPP_get_connection (path, 846 cc = GCPP_get_connection (path, destination, off);
916 destination,
917 off);
918 if (NULL != cc) 847 if (NULL != cc)
919 { 848 {
920 int cmp; 849 int cmp;
921 850
922 cmp = GNUNET_memcmp (cid, 851 cmp = GNUNET_memcmp (cid, &cc->cid);
923 &cc->cid);
924 if (0 == cmp) 852 if (0 == cmp)
925 { 853 {
926 /* Two peers picked the SAME random connection identifier at the 854 /* Two peers picked the SAME random connection identifier at the
@@ -956,7 +884,6 @@ GCC_create_inbound (struct CadetPeer *destination,
956 return connection_create (destination, 884 return connection_create (destination,
957 path, 885 path,
958 off, 886 off,
959 options,
960 ct, 887 ct,
961 cid, 888 cid,
962 CADET_CONNECTION_CREATE_RECEIVED, 889 CADET_CONNECTION_CREATE_RECEIVED,
@@ -972,7 +899,6 @@ GCC_create_inbound (struct CadetPeer *destination,
972 * @param destination where to go 899 * @param destination where to go
973 * @param path which path to take (may not be the full path) 900 * @param path which path to take (may not be the full path)
974 * @param off offset of @a destination on @a path 901 * @param off offset of @a destination on @a path
975 * @param options options for the connection
976 * @param ct tunnel that uses the connection 902 * @param ct tunnel that uses the connection
977 * @param ready_cb function to call when ready to transmit 903 * @param ready_cb function to call when ready to transmit
978 * @param ready_cb_cls closure for @a cb 904 * @param ready_cb_cls closure for @a cb
@@ -982,20 +908,16 @@ struct CadetConnection *
982GCC_create (struct CadetPeer *destination, 908GCC_create (struct CadetPeer *destination,
983 struct CadetPeerPath *path, 909 struct CadetPeerPath *path,
984 unsigned int off, 910 unsigned int off,
985 enum GNUNET_CADET_ChannelOption options,
986 struct CadetTConnection *ct, 911 struct CadetTConnection *ct,
987 GCC_ReadyCallback ready_cb, 912 GCC_ReadyCallback ready_cb,
988 void *ready_cb_cls) 913 void *ready_cb_cls)
989{ 914{
990 struct GNUNET_CADET_ConnectionTunnelIdentifier cid; 915 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
991 916
992 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 917 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof (cid));
993 &cid,
994 sizeof (cid));
995 return connection_create (destination, 918 return connection_create (destination,
996 path, 919 path,
997 off, 920 off,
998 options,
999 ct, 921 ct,
1000 &cid, 922 &cid,
1001 CADET_CONNECTION_NEW, 923 CADET_CONNECTION_NEW,
@@ -1015,8 +937,7 @@ GCC_create (struct CadetPeer *destination,
1015 * yet have a #GNUNET_MQ_notify_sent() callback attached to it 937 * yet have a #GNUNET_MQ_notify_sent() callback attached to it
1016 */ 938 */
1017void 939void
1018GCC_transmit (struct CadetConnection *cc, 940GCC_transmit (struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env)
1019 struct GNUNET_MQ_Envelope *env)
1020{ 941{
1021 LOG (GNUNET_ERROR_TYPE_DEBUG, 942 LOG (GNUNET_ERROR_TYPE_DEBUG,
1022 "Scheduling message for transmission on %s\n", 943 "Scheduling message for transmission on %s\n",
@@ -1030,8 +951,7 @@ GCC_transmit (struct CadetConnection *cc,
1030 GNUNET_SCHEDULER_cancel (cc->task); 951 GNUNET_SCHEDULER_cancel (cc->task);
1031 cc->task = NULL; 952 cc->task = NULL;
1032 } 953 }
1033 GCP_send (cc->mq_man, 954 GCP_send (cc->mq_man, env);
1034 env);
1035} 955}
1036 956
1037 957
@@ -1043,8 +963,7 @@ GCC_transmit (struct CadetConnection *cc,
1043 * @return path to @a cc 963 * @return path to @a cc
1044 */ 964 */
1045struct CadetPeerPath * 965struct CadetPeerPath *
1046GCC_get_path (struct CadetConnection *cc, 966GCC_get_path (struct CadetConnection *cc, unsigned int *off)
1047 unsigned int *off)
1048{ 967{
1049 *off = cc->off; 968 *off = cc->off;
1050 return cc->path; 969 return cc->path;
@@ -1094,7 +1013,8 @@ GCC_2s (const struct CadetConnection *cc)
1094} 1013}
1095 1014
1096 1015
1097#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__)
1098 1018
1099 1019
1100/** 1020/**
@@ -1104,21 +1024,21 @@ GCC_2s (const struct CadetConnection *cc)
1104 * @param level Debug level to use. 1024 * @param level Debug level to use.
1105 */ 1025 */
1106void 1026void
1107GCC_debug (struct CadetConnection *cc, 1027GCC_debug (struct CadetConnection *cc, enum GNUNET_ErrorType level)
1108 enum GNUNET_ErrorType level)
1109{ 1028{
1110#if !defined(GNUNET_CULL_LOGGING) 1029#if ! defined(GNUNET_CULL_LOGGING)
1111 int do_log; 1030 int do_log;
1112 1031
1113 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),
1114 "cadet-con", 1033 "cadet-con",
1115 __FILE__, __FUNCTION__, __LINE__); 1034 __FILE__,
1035 __FUNCTION__,
1036 __LINE__);
1116 if (0 == do_log) 1037 if (0 == do_log)
1117 return; 1038 return;
1118 if (NULL == cc) 1039 if (NULL == cc)
1119 { 1040 {
1120 LOG2 (level, 1041 LOG2 (level, "Connection (NULL)\n");
1121 "Connection (NULL)\n");
1122 return; 1042 return;
1123 } 1043 }
1124 LOG2 (level, 1044 LOG2 (level,
diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h
index 7cdbc9dee..d3de3347c 100644
--- a/src/cadet/gnunet-service-cadet_connection.h
+++ b/src/cadet/gnunet-service-cadet_connection.h
@@ -1,4 +1,3 @@
1
2/* 1/*
3 This file is part of GNUnet. 2 This file is part of GNUnet.
4 Copyright (C) 2001-2017 GNUnet e.V. 3 Copyright (C) 2001-2017 GNUnet e.V.
@@ -89,7 +88,6 @@ GCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
89 * @param destination where to go 88 * @param destination where to go
90 * @param path which path to take (may not be the full path) 89 * @param path which path to take (may not be the full path)
91 * @param off offset of @a destination on @a path 90 * @param off offset of @a destination on @a path
92 * @param options options for the connection
93 * @param ct which tunnel uses this connection 91 * @param ct which tunnel uses this connection
94 * @param ready_cb function to call when ready to transmit 92 * @param ready_cb function to call when ready to transmit
95 * @param ready_cb_cls closure for @a cb 93 * @param ready_cb_cls closure for @a cb
@@ -99,7 +97,6 @@ struct CadetConnection *
99GCC_create (struct CadetPeer *destination, 97GCC_create (struct CadetPeer *destination,
100 struct CadetPeerPath *path, 98 struct CadetPeerPath *path,
101 unsigned int off, 99 unsigned int off,
102 enum GNUNET_CADET_ChannelOption options,
103 struct CadetTConnection *ct, 100 struct CadetTConnection *ct,
104 GCC_ReadyCallback ready_cb, 101 GCC_ReadyCallback ready_cb,
105 void *ready_cb_cls); 102 void *ready_cb_cls);
@@ -112,7 +109,6 @@ GCC_create (struct CadetPeer *destination,
112 * 109 *
113 * @param destination where to go 110 * @param destination where to go
114 * @param path which path to take (may not be the full path) 111 * @param path which path to take (may not be the full path)
115 * @param options options for the connection
116 * @param ct which tunnel uses this connection 112 * @param ct which tunnel uses this connection
117 * @param ready_cb function to call when ready to transmit 113 * @param ready_cb function to call when ready to transmit
118 * @param ready_cb_cls closure for @a cb 114 * @param ready_cb_cls closure for @a cb
@@ -122,7 +118,6 @@ GCC_create (struct CadetPeer *destination,
122struct CadetConnection * 118struct CadetConnection *
123GCC_create_inbound (struct CadetPeer *destination, 119GCC_create_inbound (struct CadetPeer *destination,
124 struct CadetPeerPath *path, 120 struct CadetPeerPath *path,
125 enum GNUNET_CADET_ChannelOption options,
126 struct CadetTConnection *ct, 121 struct CadetTConnection *ct,
127 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 122 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
128 GCC_ReadyCallback ready_cb, 123 GCC_ReadyCallback ready_cb,
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c
index 879230d29..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,15 +39,13 @@
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 42#define LOG(level, ...) GNUNET_log_from (level, "cadet-cor", __VA_ARGS__)
43#define LOG(level, ...) GNUNET_log_from(level,"cadet-cor",__VA_ARGS__)
44 43
45/** 44/**
46 * Information we keep per direction for a route. 45 * Information we keep per direction for a route.
47 */ 46 */
48struct RouteDirection; 47struct RouteDirection;
49 48
50
51/** 49/**
52 * Set of CadetRoutes that have exactly the same number of messages 50 * Set of CadetRoutes that have exactly the same number of messages
53 * in their buffer. Used so we can efficiently find all of those 51 * in their buffer. Used so we can efficiently find all of those
@@ -140,7 +138,6 @@ struct RouteDirection
140 * Is @e mqm currently ready for transmission? 138 * Is @e mqm currently ready for transmission?
141 */ 139 */
142 int is_ready; 140 int is_ready;
143
144}; 141};
145 142
146 143
@@ -179,11 +176,6 @@ struct CadetRoute
179 * Position of this route in the #route_heap. 176 * Position of this route in the #route_heap.
180 */ 177 */
181 struct GNUNET_CONTAINER_HeapNode *hn; 178 struct GNUNET_CONTAINER_HeapNode *hn;
182
183 /**
184 * Options for the route, control buffering.
185 */
186 enum GNUNET_CADET_ChannelOption options;
187}; 179};
188 180
189 181
@@ -263,24 +255,17 @@ lower_rung (struct RouteDirection *dir)
263 struct Rung *rung = dir->rung; 255 struct Rung *rung = dir->rung;
264 struct Rung *prev; 256 struct Rung *prev;
265 257
266 GNUNET_CONTAINER_DLL_remove (rung->rd_head, 258 GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir);
267 rung->rd_tail,
268 dir);
269 prev = rung->prev; 259 prev = rung->prev;
270 GNUNET_assert (NULL != prev); 260 GNUNET_assert (NULL != prev);
271 if (prev->rung_off != rung->rung_off - 1) 261 if (prev->rung_off != rung->rung_off - 1)
272 { 262 {
273 prev = GNUNET_new (struct Rung); 263 prev = GNUNET_new (struct Rung);
274 prev->rung_off = rung->rung_off - 1; 264 prev->rung_off = rung->rung_off - 1;
275 GNUNET_CONTAINER_DLL_insert_after (rung_head, 265 GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung->prev, prev);
276 rung_tail,
277 rung->prev,
278 prev);
279 } 266 }
280 GNUNET_assert (NULL != prev); 267 GNUNET_assert (NULL != prev);
281 GNUNET_CONTAINER_DLL_insert (prev->rd_head, 268 GNUNET_CONTAINER_DLL_insert (prev->rd_head, prev->rd_tail, dir);
282 prev->rd_tail,
283 dir);
284 dir->rung = prev; 269 dir->rung = prev;
285} 270}
286 271
@@ -293,19 +278,13 @@ lower_rung (struct RouteDirection *dir)
293 * @param env envelope to discard 278 * @param env envelope to discard
294 */ 279 */
295static void 280static void
296discard_buffer (struct RouteDirection *dir, 281discard_buffer (struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env)
297 struct GNUNET_MQ_Envelope *env)
298{ 282{
299 GNUNET_MQ_dll_remove (&dir->env_head, 283 GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env);
300 &dir->env_tail,
301 env);
302 cur_buffers--; 284 cur_buffers--;
303 GNUNET_MQ_discard (env); 285 GNUNET_MQ_discard (env);
304 lower_rung (dir); 286 lower_rung (dir);
305 GNUNET_STATISTICS_set (stats, 287 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO);
306 "# buffer use",
307 cur_buffers,
308 GNUNET_NO);
309} 288}
310 289
311 290
@@ -327,12 +306,9 @@ discard_all_from_rung_tail ()
327 "# messages dropped due to full buffer", 306 "# messages dropped due to full buffer",
328 1, 307 1,
329 GNUNET_NO); 308 GNUNET_NO);
330 discard_buffer (dir, 309 discard_buffer (dir, dir->env_head);
331 dir->env_head);
332 } 310 }
333 GNUNET_CONTAINER_DLL_remove (rung_head, 311 GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, tail);
334 rung_tail,
335 tail);
336 GNUNET_free (tail); 312 GNUNET_free (tail);
337} 313}
338 314
@@ -349,7 +325,8 @@ discard_all_from_rung_tail ()
349static void 325static void
350route_message (struct CadetPeer *prev, 326route_message (struct CadetPeer *prev,
351 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 327 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
352 const struct GNUNET_MessageHeader *msg) 328 const struct GNUNET_MessageHeader *msg,
329 const enum GNUNET_MQ_PriorityPreferences priority)
353{ 330{
354 struct CadetRoute *route; 331 struct CadetRoute *route;
355 struct RouteDirection *dir; 332 struct RouteDirection *dir;
@@ -375,17 +352,14 @@ route_message (struct CadetPeer *prev,
375 /* No need to respond to these! */ 352 /* No need to respond to these! */
376 return; 353 return;
377 } 354 }
378 env = GNUNET_MQ_msg (bm, 355 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
379 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
380 bm->cid = *cid; 356 bm->cid = *cid;
381 bm->peer1 = my_full_id; 357 bm->peer1 = my_full_id;
382 GCP_send_ooo (prev, 358 GCP_send_ooo (prev, env);
383 env);
384 return; 359 return;
385 } 360 }
386 route->last_use = GNUNET_TIME_absolute_get (); 361 route->last_use = GNUNET_TIME_absolute_get ();
387 GNUNET_CONTAINER_heap_update_cost (route->hn, 362 GNUNET_CONTAINER_heap_update_cost (route->hn, route->last_use.abs_value_us);
388 route->last_use.abs_value_us);
389 dir = (prev == route->prev.hop) ? &route->next : &route->prev; 363 dir = (prev == route->prev.hop) ? &route->next : &route->prev;
390 if (GNUNET_YES == dir->is_ready) 364 if (GNUNET_YES == dir->is_ready)
391 { 365 {
@@ -396,27 +370,24 @@ route_message (struct CadetPeer *prev,
396 GNUNET_i2s (GCP_get_id (dir->hop)), 370 GNUNET_i2s (GCP_get_id (dir->hop)),
397 GNUNET_sh2s (&cid->connection_of_tunnel)); 371 GNUNET_sh2s (&cid->connection_of_tunnel));
398 dir->is_ready = GNUNET_NO; 372 dir->is_ready = GNUNET_NO;
399 GCP_send (dir->mqm, 373 GCP_send (dir->mqm, GNUNET_MQ_msg_copy (msg));
400 GNUNET_MQ_msg_copy (msg));
401 return; 374 return;
402 } 375 }
403 /* 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
404 one message per direction. */ 377 unreliable; if so, make sure we only queue one message per
405 if ( (0 != (route->options & GNUNET_CADET_OPTION_NOBUFFER)) && 378 direction (no buffering). */
406 (NULL != dir->env_head) ) 379 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) &&
407 discard_buffer (dir, 380 (NULL != dir->env_head) &&
408 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);
409 /* Check for duplicates */ 384 /* Check for duplicates */
410 for (const struct GNUNET_MQ_Envelope *env = dir->env_head; 385 for (const struct GNUNET_MQ_Envelope *env = dir->env_head; NULL != env;
411 NULL != env;
412 env = GNUNET_MQ_env_next (env)) 386 env = GNUNET_MQ_env_next (env))
413 { 387 {
414 const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg (env); 388 const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg (env);
415 389
416 if ( (hdr->size == msg->size) && 390 if ((hdr->size == msg->size) && (0 == memcmp (hdr, msg, ntohs (msg->size))))
417 (0 == memcmp (hdr,
418 msg,
419 ntohs (msg->size))) )
420 { 391 {
421 LOG (GNUNET_ERROR_TYPE_DEBUG, 392 LOG (GNUNET_ERROR_TYPE_DEBUG,
422 "Received duplicate of message already in buffer, dropping\n"); 393 "Received duplicate of message already in buffer, dropping\n");
@@ -447,31 +418,22 @@ route_message (struct CadetPeer *prev,
447 "# messages dropped due to full buffer", 418 "# messages dropped due to full buffer",
448 1, 419 1,
449 GNUNET_NO); 420 GNUNET_NO);
450 discard_buffer (dir, 421 discard_buffer (dir, dir->env_head);
451 dir->env_head);
452 rung = dir->rung; 422 rung = dir->rung;
453 } 423 }
454 } 424 }
455 /* remove 'dir' from current rung */ 425 /* remove 'dir' from current rung */
456 GNUNET_CONTAINER_DLL_remove (rung->rd_head, 426 GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir);
457 rung->rd_tail,
458 dir);
459 /* make 'nxt' point to the next higher rung, create if necessary */ 427 /* make 'nxt' point to the next higher rung, create if necessary */
460 nxt = rung->next; 428 nxt = rung->next;
461 if ( (NULL == nxt) || 429 if ((NULL == nxt) || (rung->rung_off + 1 != nxt->rung_off))
462 (rung->rung_off + 1 != nxt->rung_off) )
463 { 430 {
464 nxt = GNUNET_new (struct Rung); 431 nxt = GNUNET_new (struct Rung);
465 nxt->rung_off = rung->rung_off + 1; 432 nxt->rung_off = rung->rung_off + 1;
466 GNUNET_CONTAINER_DLL_insert_after (rung_head, 433 GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung, nxt);
467 rung_tail,
468 rung,
469 nxt);
470 } 434 }
471 /* insert 'dir' into next higher rung */ 435 /* insert 'dir' into next higher rung */
472 GNUNET_CONTAINER_DLL_insert (nxt->rd_head, 436 GNUNET_CONTAINER_DLL_insert (nxt->rd_head, nxt->rd_tail, dir);
473 nxt->rd_tail,
474 dir);
475 dir->rung = nxt; 437 dir->rung = nxt;
476 438
477 /* add message into 'dir' buffer */ 439 /* add message into 'dir' buffer */
@@ -482,21 +444,21 @@ route_message (struct CadetPeer *prev,
482 GNUNET_i2s (GCP_get_id (dir->hop)), 444 GNUNET_i2s (GCP_get_id (dir->hop)),
483 GNUNET_sh2s (&cid->connection_of_tunnel)); 445 GNUNET_sh2s (&cid->connection_of_tunnel));
484 env = GNUNET_MQ_msg_copy (msg); 446 env = GNUNET_MQ_msg_copy (msg);
485 GNUNET_MQ_dll_insert_tail (&dir->env_head, 447 GNUNET_MQ_env_set_options (env, priority);
486 &dir->env_tail, 448 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) &&
487 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);
488 cur_buffers++; 456 cur_buffers++;
489 GNUNET_STATISTICS_set (stats, 457 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO);
490 "# buffer use",
491 cur_buffers,
492 GNUNET_NO);
493 /* Clean up 'rung' if now empty (and not head) */ 458 /* Clean up 'rung' if now empty (and not head) */
494 if ( (NULL == rung->rd_head) && 459 if ((NULL == rung->rd_head) && (rung != rung_head))
495 (rung != rung_head) )
496 { 460 {
497 GNUNET_CONTAINER_DLL_remove (rung_head, 461 GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, rung);
498 rung_tail,
499 rung);
500 GNUNET_free (rung); 462 GNUNET_free (rung);
501 } 463 }
502} 464}
@@ -541,18 +503,14 @@ destroy_direction (struct RouteDirection *dir)
541 "# messages dropped due to route destruction", 503 "# messages dropped due to route destruction",
542 1, 504 1,
543 GNUNET_NO); 505 GNUNET_NO);
544 discard_buffer (dir, 506 discard_buffer (dir, env);
545 env);
546 } 507 }
547 if (NULL != dir->mqm) 508 if (NULL != dir->mqm)
548 { 509 {
549 GCP_request_mq_cancel (dir->mqm, 510 GCP_request_mq_cancel (dir->mqm, NULL);
550 NULL);
551 dir->mqm = NULL; 511 dir->mqm = NULL;
552 } 512 }
553 GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, 513 GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, rung_head->rd_tail, dir);
554 rung_head->rd_tail,
555 dir);
556} 514}
557 515
558 516
@@ -566,15 +524,15 @@ destroy_route (struct CadetRoute *route)
566{ 524{
567 LOG (GNUNET_ERROR_TYPE_DEBUG, 525 LOG (GNUNET_ERROR_TYPE_DEBUG,
568 "Destroying route from %s to %s of connection %s\n", 526 "Destroying route from %s to %s of connection %s\n",
569 GNUNET_i2s (GCP_get_id (route->prev.hop)), 527 GNUNET_i2s (GCP_get_id (route->prev.hop)),
570 GNUNET_i2s2 (GCP_get_id (route->next.hop)), 528 GNUNET_i2s2 (GCP_get_id (route->next.hop)),
571 GNUNET_sh2s (&route->cid.connection_of_tunnel)); 529 GNUNET_sh2s (&route->cid.connection_of_tunnel));
572 GNUNET_assert (route == 530 GNUNET_assert (route == GNUNET_CONTAINER_heap_remove_node (route->hn));
573 GNUNET_CONTAINER_heap_remove_node (route->hn)); 531 GNUNET_assert (
574 GNUNET_assert (GNUNET_YES == 532 GNUNET_YES ==
575 GNUNET_CONTAINER_multishortmap_remove (routes, 533 GNUNET_CONTAINER_multishortmap_remove (routes,
576 &route->cid.connection_of_tunnel, 534 &route->cid.connection_of_tunnel,
577 route)); 535 route));
578 GNUNET_STATISTICS_set (stats, 536 GNUNET_STATISTICS_set (stats,
579 "# routes", 537 "# routes",
580 GNUNET_CONTAINER_multishortmap_size (routes), 538 GNUNET_CONTAINER_multishortmap_size (routes),
@@ -611,15 +569,13 @@ send_broken (struct RouteDirection *target,
611 GNUNET_i2s2 (peer2), 569 GNUNET_i2s2 (peer2),
612 GNUNET_sh2s (&cid->connection_of_tunnel)); 570 GNUNET_sh2s (&cid->connection_of_tunnel));
613 571
614 env = GNUNET_MQ_msg (bm, 572 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
615 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
616 bm->cid = *cid; 573 bm->cid = *cid;
617 if (NULL != peer1) 574 if (NULL != peer1)
618 bm->peer1 = *peer1; 575 bm->peer1 = *peer1;
619 if (NULL != peer2) 576 if (NULL != peer2)
620 bm->peer2 = *peer2; 577 bm->peer2 = *peer2;
621 GCP_request_mq_cancel (target->mqm, 578 GCP_request_mq_cancel (target->mqm, env);
622 env);
623 target->mqm = NULL; 579 target->mqm = NULL;
624} 580}
625 581
@@ -639,33 +595,22 @@ timeout_cb (void *cls)
639 struct GNUNET_TIME_Absolute exp; 595 struct GNUNET_TIME_Absolute exp;
640 596
641 timeout_task = NULL; 597 timeout_task = NULL;
642 linger = GNUNET_TIME_relative_multiply (keepalive_period, 598 linger = GNUNET_TIME_relative_multiply (keepalive_period, 3);
643 3);
644 while (NULL != (r = GNUNET_CONTAINER_heap_peek (route_heap))) 599 while (NULL != (r = GNUNET_CONTAINER_heap_peek (route_heap)))
645 { 600 {
646 exp = GNUNET_TIME_absolute_add (r->last_use, 601 exp = GNUNET_TIME_absolute_add (r->last_use, linger);
647 linger);
648 if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us) 602 if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
649 { 603 {
650 /* Route not yet timed out, wait until it does. */ 604 /* Route not yet timed out, wait until it does. */
651 timeout_task = GNUNET_SCHEDULER_add_at (exp, 605 timeout_task = GNUNET_SCHEDULER_add_at (exp, &timeout_cb, NULL);
652 &timeout_cb,
653 NULL);
654 return; 606 return;
655 } 607 }
656 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 608 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
657 "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",
658 GNUNET_STRINGS_absolute_time_to_string (r->last_use), 610 GNUNET_STRINGS_absolute_time_to_string (r->last_use),
659 GNUNET_STRINGS_relative_time_to_string (linger, 611 GNUNET_STRINGS_relative_time_to_string (linger, GNUNET_YES));
660 GNUNET_YES)); 612 send_broken (&r->prev, &r->cid, NULL, NULL);
661 send_broken (&r->prev, 613 send_broken (&r->next, &r->cid, NULL, NULL);
662 &r->cid,
663 NULL,
664 NULL);
665 send_broken (&r->next,
666 &r->cid,
667 NULL,
668 NULL);
669 destroy_route (r); 614 destroy_route (r);
670 } 615 }
671 /* No more routes left, so no need for a #timeout_task */ 616 /* No more routes left, so no need for a #timeout_task */
@@ -685,8 +630,7 @@ timeout_cb (void *cls)
685 * and the last envelope was discarded 630 * and the last envelope was discarded
686 */ 631 */
687static void 632static void
688dir_ready_cb (void *cls, 633dir_ready_cb (void *cls, int ready)
689 int ready)
690{ 634{
691 struct RouteDirection *dir = cls; 635 struct RouteDirection *dir = cls;
692 struct CadetRoute *route = dir->my_route; 636 struct CadetRoute *route = dir->my_route;
@@ -699,28 +643,18 @@ dir_ready_cb (void *cls,
699 dir->is_ready = GNUNET_YES; 643 dir->is_ready = GNUNET_YES;
700 if (NULL != (env = dir->env_head)) 644 if (NULL != (env = dir->env_head))
701 { 645 {
702 GNUNET_MQ_dll_remove (&dir->env_head, 646 GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env);
703 &dir->env_tail,
704 env);
705 cur_buffers--; 647 cur_buffers--;
706 GNUNET_STATISTICS_set (stats, 648 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO);
707 "# buffer use",
708 cur_buffers,
709 GNUNET_NO);
710 lower_rung (dir); 649 lower_rung (dir);
711 dir->is_ready = GNUNET_NO; 650 dir->is_ready = GNUNET_NO;
712 GCP_send (dir->mqm, 651 GCP_send (dir->mqm, env);
713 env);
714 } 652 }
715 return; 653 return;
716 } 654 }
717 odir = (dir == &route->next) ? &route->prev : &route->next; 655 odir = (dir == &route->next) ? &route->prev : &route->next;
718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending BROKEN due to MQ going down\n");
719 "Sending BROKEN due to MQ going down\n"); 657 send_broken (&route->next, &route->cid, GCP_get_id (odir->hop), &my_full_id);
720 send_broken (&route->next,
721 &route->cid,
722 GCP_get_id (odir->hop),
723 &my_full_id);
724 destroy_route (route); 658 destroy_route (route);
725} 659}
726 660
@@ -739,12 +673,8 @@ dir_init (struct RouteDirection *dir,
739{ 673{
740 dir->hop = hop; 674 dir->hop = hop;
741 dir->my_route = route; 675 dir->my_route = route;
742 dir->mqm = GCP_request_mq (hop, 676 dir->mqm = GCP_request_mq (hop, &dir_ready_cb, dir);
743 &dir_ready_cb, 677 GNUNET_CONTAINER_DLL_insert (rung_head->rd_head, rung_head->rd_tail, dir);
744 dir);
745 GNUNET_CONTAINER_DLL_insert (rung_head->rd_head,
746 rung_head->rd_tail,
747 dir);
748 dir->rung = rung_head; 678 dir->rung = rung_head;
749 GNUNET_assert (GNUNET_YES == dir->is_ready); 679 GNUNET_assert (GNUNET_YES == dir->is_ready);
750} 680}
@@ -761,21 +691,20 @@ dir_init (struct RouteDirection *dir,
761 * or NULL. 691 * or NULL.
762 */ 692 */
763static void 693static void
764send_broken_without_mqm (struct CadetPeer *target, 694send_broken_without_mqm (
765 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 695 struct CadetPeer *target,
766 const struct GNUNET_PeerIdentity *failure_at) 696 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
697 const struct GNUNET_PeerIdentity *failure_at)
767{ 698{
768 struct GNUNET_MQ_Envelope *env; 699 struct GNUNET_MQ_Envelope *env;
769 struct GNUNET_CADET_ConnectionBrokenMessage *bm; 700 struct GNUNET_CADET_ConnectionBrokenMessage *bm;
770 701
771 env = GNUNET_MQ_msg (bm, 702 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
772 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
773 bm->cid = *cid; 703 bm->cid = *cid;
774 bm->peer1 = my_full_id; 704 bm->peer1 = my_full_id;
775 if (NULL != failure_at) 705 if (NULL != failure_at)
776 bm->peer2 = *failure_at; 706 bm->peer2 = *failure_at;
777 GCP_send_ooo (target, 707 GCP_send_ooo (target, env);
778 env);
779} 708}
780 709
781 710
@@ -786,19 +715,19 @@ send_broken_without_mqm (struct CadetPeer *target,
786 * @param msg Message itself. 715 * @param msg Message itself.
787 */ 716 */
788static void 717static void
789handle_connection_create (void *cls, 718handle_connection_create (
790 const struct GNUNET_CADET_ConnectionCreateMessage *msg) 719 void *cls,
720 const struct GNUNET_CADET_ConnectionCreateMessage *msg)
791{ 721{
792 struct CadetPeer *sender = cls; 722 struct CadetPeer *sender = cls;
793 struct CadetPeer *next; 723 struct CadetPeer *next;
794 const struct GNUNET_PeerIdentity *pids = (const struct GNUNET_PeerIdentity *) &msg[1]; 724 const struct GNUNET_PeerIdentity *pids =
725 (const struct GNUNET_PeerIdentity *) &msg[1];
795 struct CadetRoute *route; 726 struct CadetRoute *route;
796 uint16_t size = ntohs (msg->header.size) - sizeof (*msg); 727 uint16_t size = ntohs (msg->header.size) - sizeof (*msg);
797 unsigned int path_length; 728 unsigned int path_length;
798 unsigned int off; 729 unsigned int off;
799 enum GNUNET_CADET_ChannelOption options;
800 730
801 options = (enum GNUNET_CADET_ChannelOption) ntohl (msg->options);
802 path_length = size / sizeof (struct GNUNET_PeerIdentity); 731 path_length = size / sizeof (struct GNUNET_PeerIdentity);
803 if (0 == path_length) 732 if (0 == path_length)
804 { 733 {
@@ -816,20 +745,19 @@ handle_connection_create (void *cls,
816 { 745 {
817 struct GNUNET_CONTAINER_MultiPeerMap *map; 746 struct GNUNET_CONTAINER_MultiPeerMap *map;
818 747
819 map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, 748 map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, GNUNET_YES);
820 GNUNET_YES);
821 GNUNET_assert (NULL != map); 749 GNUNET_assert (NULL != map);
822 for (unsigned int i=0;i<path_length;i++) 750 for (unsigned int i = 0; i < path_length; i++)
823 { 751 {
824 LOG (GNUNET_ERROR_TYPE_DEBUG, 752 LOG (GNUNET_ERROR_TYPE_DEBUG,
825 "CADET_CONNECTION_CREATE has peer %s at offset %u\n", 753 "CADET_CONNECTION_CREATE has peer %s at offset %u\n",
826 GNUNET_i2s (&pids[i]), 754 GNUNET_i2s (&pids[i]),
827 i); 755 i);
828 if (GNUNET_SYSERR == 756 if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put (
829 GNUNET_CONTAINER_multipeermap_put (map, 757 map,
830 &pids[i], 758 &pids[i],
831 NULL, 759 NULL,
832 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 760 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
833 { 761 {
834 /* bogus request */ 762 /* bogus request */
835 GNUNET_CONTAINER_multipeermap_destroy (map); 763 GNUNET_CONTAINER_multipeermap_destroy (map);
@@ -842,9 +770,8 @@ handle_connection_create (void *cls,
842 GNUNET_CONTAINER_multipeermap_destroy (map); 770 GNUNET_CONTAINER_multipeermap_destroy (map);
843 } 771 }
844 /* Initiator is at offset 0, find us */ 772 /* Initiator is at offset 0, find us */
845 for (off=1;off<path_length;off++) 773 for (off = 1; off < path_length; off++)
846 if (0 == GNUNET_memcmp (&my_full_id, 774 if (0 == GNUNET_memcmp (&my_full_id, &pids[off]))
847 &pids[off]))
848 break; 775 break;
849 if (off == path_length) 776 if (off == path_length)
850 { 777 {
@@ -854,16 +781,14 @@ handle_connection_create (void *cls,
854 return; 781 return;
855 } 782 }
856 /* Check previous hop */ 783 /* Check previous hop */
857 if (sender != GCP_get (&pids[off - 1], 784 if (sender != GCP_get (&pids[off - 1], GNUNET_NO))
858 GNUNET_NO))
859 { 785 {
860 LOG (GNUNET_ERROR_TYPE_DEBUG, 786 LOG (GNUNET_ERROR_TYPE_DEBUG,
861 "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");
862 GNUNET_break_op (0); 788 GNUNET_break_op (0);
863 return; 789 return;
864 } 790 }
865 if (NULL != 791 if (NULL != (route = get_route (&msg->cid)))
866 (route = get_route (&msg->cid)))
867 { 792 {
868 /* Duplicate CREATE, pass it on, previous one might have been lost! */ 793 /* Duplicate CREATE, pass it on, previous one might have been lost! */
869 794
@@ -872,7 +797,9 @@ handle_connection_create (void *cls,
872 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 797 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
873 route_message (sender, 798 route_message (sender,
874 &msg->cid, 799 &msg->cid,
875 &msg->header); 800 &msg->header,
801 GNUNET_MQ_PRIO_CRITICAL_CONTROL |
802 GNUNET_MQ_PREF_LOW_LATENCY);
876 return; 803 return;
877 } 804 }
878 if (off == path_length - 1) 805 if (off == path_length - 1)
@@ -892,19 +819,15 @@ handle_connection_create (void *cls,
892 return; 819 return;
893 } 820 }
894 821
895 origin = GCP_get (&pids[0], 822 origin = GCP_get (&pids[0], GNUNET_YES);
896 GNUNET_YES);
897 LOG (GNUNET_ERROR_TYPE_DEBUG, 823 LOG (GNUNET_ERROR_TYPE_DEBUG,
898 "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",
899 GCP_2s (origin), 825 GCP_2s (origin),
900 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 826 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
901 path = GCPP_get_path_from_route (path_length - 1, 827 path = GCPP_get_path_from_route (path_length - 1, pids);
902 pids);
903 if (GNUNET_OK != 828 if (GNUNET_OK !=
904 GCT_add_inbound_connection (GCP_get_tunnel (origin, 829 GCT_add_inbound_connection (GCP_get_tunnel (origin, GNUNET_YES),
905 GNUNET_YES),
906 &msg->cid, 830 &msg->cid,
907 (enum GNUNET_CADET_ChannelOption) ntohl (msg->options),
908 path)) 831 path))
909 { 832 {
910 /* Send back BROKEN: duplicate connection on the same path, 833 /* Send back BROKEN: duplicate connection on the same path,
@@ -914,18 +837,14 @@ handle_connection_create (void *cls,
914 GCP_2s (sender), 837 GCP_2s (sender),
915 GNUNET_sh2s (&msg->cid.connection_of_tunnel), 838 GNUNET_sh2s (&msg->cid.connection_of_tunnel),
916 GCPP_2s (path)); 839 GCPP_2s (path));
917 send_broken_without_mqm (sender, 840 send_broken_without_mqm (sender, &msg->cid, NULL);
918 &msg->cid,
919 NULL);
920 return; 841 return;
921 } 842 }
922 return; 843 return;
923 } 844 }
924 /* 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 */
925 next = GCP_get (&pids[off + 1], 846 next = GCP_get (&pids[off + 1], GNUNET_NO);
926 GNUNET_NO); 847 if ((NULL == next) || (GNUNET_NO == GCP_has_core_connection (next)))
927 if ( (NULL == next) ||
928 (GNUNET_NO == GCP_has_core_connection (next)) )
929 { 848 {
930 /* unworkable, send back BROKEN notification */ 849 /* unworkable, send back BROKEN notification */
931 LOG (GNUNET_ERROR_TYPE_DEBUG, 850 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -934,9 +853,7 @@ handle_connection_create (void *cls,
934 GNUNET_sh2s (&msg->cid.connection_of_tunnel), 853 GNUNET_sh2s (&msg->cid.connection_of_tunnel),
935 GNUNET_i2s (&pids[off + 1]), 854 GNUNET_i2s (&pids[off + 1]),
936 off + 1); 855 off + 1);
937 send_broken_without_mqm (sender, 856 send_broken_without_mqm (sender, &msg->cid, &pids[off + 1]);
938 &msg->cid,
939 &pids[off + 1]);
940 return; 857 return;
941 } 858 }
942 if (max_routes <= GNUNET_CONTAINER_multishortmap_size (routes)) 859 if (max_routes <= GNUNET_CONTAINER_multishortmap_size (routes))
@@ -945,9 +862,7 @@ handle_connection_create (void *cls,
945 "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",
946 GCP_2s (sender), 863 GCP_2s (sender),
947 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 864 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
948 send_broken_without_mqm (sender, 865 send_broken_without_mqm (sender, &msg->cid, &pids[off - 1]);
949 &msg->cid,
950 &pids[off - 1]);
951 return; 866 return;
952 } 867 }
953 868
@@ -959,20 +874,16 @@ handle_connection_create (void *cls,
959 GNUNET_i2s (&pids[off + 1]), 874 GNUNET_i2s (&pids[off + 1]),
960 off + 1); 875 off + 1);
961 route = GNUNET_new (struct CadetRoute); 876 route = GNUNET_new (struct CadetRoute);
962 route->options = options;
963 route->cid = msg->cid; 877 route->cid = msg->cid;
964 route->last_use = GNUNET_TIME_absolute_get (); 878 route->last_use = GNUNET_TIME_absolute_get ();
965 dir_init (&route->prev, 879 dir_init (&route->prev, route, sender);
966 route, 880 dir_init (&route->next, route, next);
967 sender);
968 dir_init (&route->next,
969 route,
970 next);
971 GNUNET_assert (GNUNET_OK == 881 GNUNET_assert (GNUNET_OK ==
972 GNUNET_CONTAINER_multishortmap_put (routes, 882 GNUNET_CONTAINER_multishortmap_put (
973 &route->cid.connection_of_tunnel, 883 routes,
974 route, 884 &route->cid.connection_of_tunnel,
975 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 885 route,
886 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
976 GNUNET_STATISTICS_set (stats, 887 GNUNET_STATISTICS_set (stats,
977 "# routes", 888 "# routes",
978 GNUNET_CONTAINER_multishortmap_size (routes), 889 GNUNET_CONTAINER_multishortmap_size (routes),
@@ -981,14 +892,16 @@ handle_connection_create (void *cls,
981 route, 892 route,
982 route->last_use.abs_value_us); 893 route->last_use.abs_value_us);
983 if (NULL == timeout_task) 894 if (NULL == timeout_task)
984 timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (keepalive_period, 895 timeout_task =
985 3), 896 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (keepalive_period,
986 &timeout_cb, 897 3),
987 NULL); 898 &timeout_cb,
899 NULL);
988 /* also pass CREATE message along to next hop */ 900 /* also pass CREATE message along to next hop */
989 route_message (sender, 901 route_message (sender,
990 &msg->cid, 902 &msg->cid,
991 &msg->header); 903 &msg->header,
904 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
992} 905}
993 906
994 907
@@ -999,8 +912,9 @@ handle_connection_create (void *cls,
999 * @param msg Message itself. 912 * @param msg Message itself.
1000 */ 913 */
1001static void 914static void
1002handle_connection_create_ack (void *cls, 915handle_connection_create_ack (
1003 const struct GNUNET_CADET_ConnectionCreateAckMessage *msg) 916 void *cls,
917 const struct GNUNET_CADET_ConnectionCreateAckMessage *msg)
1004{ 918{
1005 struct CadetPeer *peer = cls; 919 struct CadetPeer *peer = cls;
1006 struct CadetConnection *cc; 920 struct CadetConnection *cc;
@@ -1011,12 +925,9 @@ handle_connection_create_ack (void *cls,
1011 { 925 {
1012 /* verify ACK came from the right direction */ 926 /* verify ACK came from the right direction */
1013 unsigned int len; 927 unsigned int len;
1014 struct CadetPeerPath *path = GCC_get_path (cc, 928 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1015 &len);
1016 929
1017 if (peer != 930 if (peer != GCPP_get_peer_at_offset (path, 0))
1018 GCPP_get_peer_at_offset (path,
1019 0))
1020 { 931 {
1021 /* received ACK from unexpected direction, ignore! */ 932 /* received ACK from unexpected direction, ignore! */
1022 GNUNET_break_op (0); 933 GNUNET_break_op (0);
@@ -1032,7 +943,8 @@ handle_connection_create_ack (void *cls,
1032 /* We're just an intermediary peer, route the message along its path */ 943 /* We're just an intermediary peer, route the message along its path */
1033 route_message (peer, 944 route_message (peer,
1034 &msg->cid, 945 &msg->cid,
1035 &msg->header); 946 &msg->header,
947 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
1036} 948}
1037 949
1038 950
@@ -1044,8 +956,9 @@ handle_connection_create_ack (void *cls,
1044 * @deprecated duplicate logic with #handle_destroy(); dedup! 956 * @deprecated duplicate logic with #handle_destroy(); dedup!
1045 */ 957 */
1046static void 958static void
1047handle_connection_broken (void *cls, 959handle_connection_broken (
1048 const struct GNUNET_CADET_ConnectionBrokenMessage *msg) 960 void *cls,
961 const struct GNUNET_CADET_ConnectionBrokenMessage *msg)
1049{ 962{
1050 struct CadetPeer *peer = cls; 963 struct CadetPeer *peer = cls;
1051 struct CadetConnection *cc; 964 struct CadetConnection *cc;
@@ -1057,12 +970,9 @@ handle_connection_broken (void *cls,
1057 { 970 {
1058 /* verify message came from the right direction */ 971 /* verify message came from the right direction */
1059 unsigned int len; 972 unsigned int len;
1060 struct CadetPeerPath *path = GCC_get_path (cc, 973 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1061 &len);
1062 974
1063 if (peer != 975 if (peer != GCPP_get_peer_at_offset (path, 0))
1064 GCPP_get_peer_at_offset (path,
1065 0))
1066 { 976 {
1067 /* received message from unexpected direction, ignore! */ 977 /* received message from unexpected direction, ignore! */
1068 GNUNET_break_op (0); 978 GNUNET_break_op (0);
@@ -1080,7 +990,8 @@ handle_connection_broken (void *cls,
1080 /* We're just an intermediary peer, route the message along its path */ 990 /* We're just an intermediary peer, route the message along its path */
1081 route_message (peer, 991 route_message (peer,
1082 &msg->cid, 992 &msg->cid,
1083 &msg->header); 993 &msg->header,
994 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
1084 route = get_route (&msg->cid); 995 route = get_route (&msg->cid);
1085 if (NULL != route) 996 if (NULL != route)
1086 destroy_route (route); 997 destroy_route (route);
@@ -1095,8 +1006,9 @@ handle_connection_broken (void *cls,
1095 * @param msg Message itself. 1006 * @param msg Message itself.
1096 */ 1007 */
1097static void 1008static void
1098handle_connection_destroy (void *cls, 1009handle_connection_destroy (
1099 const struct GNUNET_CADET_ConnectionDestroyMessage *msg) 1010 void *cls,
1011 const struct GNUNET_CADET_ConnectionDestroyMessage *msg)
1100{ 1012{
1101 struct CadetPeer *peer = cls; 1013 struct CadetPeer *peer = cls;
1102 struct CadetConnection *cc; 1014 struct CadetConnection *cc;
@@ -1108,12 +1020,9 @@ handle_connection_destroy (void *cls,
1108 { 1020 {
1109 /* verify message came from the right direction */ 1021 /* verify message came from the right direction */
1110 unsigned int len; 1022 unsigned int len;
1111 struct CadetPeerPath *path = GCC_get_path (cc, 1023 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1112 &len);
1113 1024
1114 if (peer != 1025 if (peer != GCPP_get_peer_at_offset (path, 0))
1115 GCPP_get_peer_at_offset (path,
1116 0))
1117 { 1026 {
1118 /* received message from unexpected direction, ignore! */ 1027 /* received message from unexpected direction, ignore! */
1119 GNUNET_break_op (0); 1028 GNUNET_break_op (0);
@@ -1133,7 +1042,8 @@ handle_connection_destroy (void *cls,
1133 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 1042 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
1134 route_message (peer, 1043 route_message (peer,
1135 &msg->cid, 1044 &msg->cid,
1136 &msg->header); 1045 &msg->header,
1046 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
1137 route = get_route (&msg->cid); 1047 route = get_route (&msg->cid);
1138 if (NULL != route) 1048 if (NULL != route)
1139 destroy_route (route); 1049 destroy_route (route);
@@ -1165,26 +1075,23 @@ handle_tunnel_kx (void *cls,
1165 { 1075 {
1166 /* verify message came from the right direction */ 1076 /* verify message came from the right direction */
1167 unsigned int len; 1077 unsigned int len;
1168 struct CadetPeerPath *path = GCC_get_path (cc, 1078 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1169 &len);
1170 1079
1171 if (peer != 1080 if (peer != GCPP_get_peer_at_offset (path, 0))
1172 GCPP_get_peer_at_offset (path,
1173 0))
1174 { 1081 {
1175 /* received message from unexpected direction, ignore! */ 1082 /* received message from unexpected direction, ignore! */
1176 GNUNET_break_op (0); 1083 GNUNET_break_op (0);
1177 return; 1084 return;
1178 } 1085 }
1179 GCC_handle_kx (cc, 1086 GCC_handle_kx (cc, msg);
1180 msg);
1181 return; 1087 return;
1182 } 1088 }
1183 1089
1184 /* We're just an intermediary peer, route the message along its path */ 1090 /* We're just an intermediary peer, route the message along its path */
1185 route_message (peer, 1091 route_message (peer,
1186 &msg->cid, 1092 &msg->cid,
1187 &msg->header); 1093 &msg->header,
1094 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
1188} 1095}
1189 1096
1190 1097
@@ -1195,8 +1102,9 @@ handle_tunnel_kx (void *cls,
1195 * @param msg Message itself. 1102 * @param msg Message itself.
1196 */ 1103 */
1197static void 1104static void
1198handle_tunnel_kx_auth (void *cls, 1105handle_tunnel_kx_auth (
1199 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) 1106 void *cls,
1107 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
1200{ 1108{
1201 struct CadetPeer *peer = cls; 1109 struct CadetPeer *peer = cls;
1202 struct CadetConnection *cc; 1110 struct CadetConnection *cc;
@@ -1207,26 +1115,23 @@ handle_tunnel_kx_auth (void *cls,
1207 { 1115 {
1208 /* verify message came from the right direction */ 1116 /* verify message came from the right direction */
1209 unsigned int len; 1117 unsigned int len;
1210 struct CadetPeerPath *path = GCC_get_path (cc, 1118 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1211 &len);
1212 1119
1213 if (peer != 1120 if (peer != GCPP_get_peer_at_offset (path, 0))
1214 GCPP_get_peer_at_offset (path,
1215 0))
1216 { 1121 {
1217 /* received message from unexpected direction, ignore! */ 1122 /* received message from unexpected direction, ignore! */
1218 GNUNET_break_op (0); 1123 GNUNET_break_op (0);
1219 return; 1124 return;
1220 } 1125 }
1221 GCC_handle_kx_auth (cc, 1126 GCC_handle_kx_auth (cc, msg);
1222 msg);
1223 return; 1127 return;
1224 } 1128 }
1225 1129
1226 /* We're just an intermediary peer, route the message along its path */ 1130 /* We're just an intermediary peer, route the message along its path */
1227 route_message (peer, 1131 route_message (peer,
1228 &msg->kx.cid, 1132 &msg->kx.cid,
1229 &msg->kx.header); 1133 &msg->kx.header,
1134 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
1230} 1135}
1231 1136
1232 1137
@@ -1265,25 +1170,19 @@ handle_tunnel_encrypted (void *cls,
1265 { 1170 {
1266 /* verify message came from the right direction */ 1171 /* verify message came from the right direction */
1267 unsigned int len; 1172 unsigned int len;
1268 struct CadetPeerPath *path = GCC_get_path (cc, 1173 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1269 &len);
1270 1174
1271 if (peer != 1175 if (peer != GCPP_get_peer_at_offset (path, 0))
1272 GCPP_get_peer_at_offset (path,
1273 0))
1274 { 1176 {
1275 /* received message from unexpected direction, ignore! */ 1177 /* received message from unexpected direction, ignore! */
1276 GNUNET_break_op (0); 1178 GNUNET_break_op (0);
1277 return; 1179 return;
1278 } 1180 }
1279 GCC_handle_encrypted (cc, 1181 GCC_handle_encrypted (cc, msg);
1280 msg);
1281 return; 1182 return;
1282 } 1183 }
1283 /* 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 */
1284 route_message (peer, 1185 route_message (peer, &msg->cid, &msg->header, GNUNET_MQ_PRIO_BEST_EFFORT);
1285 &msg->cid,
1286 &msg->header);
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",
1406 &max_routes))
1407 max_routes = 5000; 1298 max_routes = 5000;
1408 if (GNUNET_OK != 1299 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c,
1409 GNUNET_CONFIGURATION_get_value_number (c, 1300 "CADET",
1410 "CADET", 1301 "MAX_MSGS_QUEUE",
1411 "MAX_MSGS_QUEUE", 1302 &max_buffers))
1412 &max_buffers))
1413 max_buffers = 10000; 1303 max_buffers = 10000;
1414 routes = GNUNET_CONTAINER_multishortmap_create (1024, 1304 routes = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_NO);
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/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c
index a2a493ebd..11be2bce0 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.c
+++ b/src/cadet/gnunet-service-cadet_tunnels.c
@@ -2731,7 +2731,6 @@ consider_path_cb (void *cls,
2731 ct->cc = GCC_create (t->destination, 2731 ct->cc = GCC_create (t->destination,
2732 path, 2732 path,
2733 off, 2733 off,
2734 GNUNET_CADET_OPTION_DEFAULT, /* FIXME: set based on what channels want/need! */
2735 ct, 2734 ct,
2736 &connection_ready_cb, 2735 &connection_ready_cb,
2737 ct); 2736 ct);
@@ -3204,7 +3203,6 @@ GCT_create_tunnel (struct CadetPeer *destination)
3204int 3203int
3205GCT_add_inbound_connection (struct CadetTunnel *t, 3204GCT_add_inbound_connection (struct CadetTunnel *t,
3206 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 3205 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
3207 enum GNUNET_CADET_ChannelOption options,
3208 struct CadetPeerPath *path) 3206 struct CadetPeerPath *path)
3209{ 3207{
3210 struct CadetTConnection *ct; 3208 struct CadetTConnection *ct;
@@ -3214,7 +3212,6 @@ GCT_add_inbound_connection (struct CadetTunnel *t,
3214 ct->t = t; 3212 ct->t = t;
3215 ct->cc = GCC_create_inbound (t->destination, 3213 ct->cc = GCC_create_inbound (t->destination,
3216 path, 3214 path,
3217 options,
3218 ct, 3215 ct,
3219 cid, 3216 cid,
3220 &connection_ready_cb, 3217 &connection_ready_cb,
diff --git a/src/cadet/gnunet-service-cadet_tunnels.h b/src/cadet/gnunet-service-cadet_tunnels.h
index c1bf2fcd5..47d9f98bf 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.h
+++ b/src/cadet/gnunet-service-cadet_tunnels.h
@@ -119,7 +119,6 @@ GCT_destroy_tunnel_now (struct CadetTunnel *t);
119 * 119 *
120 * @param t a tunnel 120 * @param t a tunnel
121 * @param cid connection identifer to use for the connection 121 * @param cid connection identifer to use for the connection
122 * @param options options for the connection
123 * @param path path to use for the connection 122 * @param path path to use for the connection
124 * @return #GNUNET_OK on success, 123 * @return #GNUNET_OK on success,
125 * #GNUNET_SYSERR on failure (duplicate connection) 124 * #GNUNET_SYSERR on failure (duplicate connection)
@@ -127,7 +126,6 @@ GCT_destroy_tunnel_now (struct CadetTunnel *t);
127int 126int
128GCT_add_inbound_connection (struct CadetTunnel *t, 127GCT_add_inbound_connection (struct CadetTunnel *t,
129 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 128 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
130 enum GNUNET_CADET_ChannelOption options,
131 struct CadetPeerPath *path); 129 struct CadetPeerPath *path);
132 130
133 131
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index 72c18cf9c..e87e173be 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -532,7 +532,6 @@ reconnect_op (void *cls)
532 }; 532 };
533 long l = (long) cls; 533 long l = (long) cls;
534 struct CadetTestChannelWrapper *ch; 534 struct CadetTestChannelWrapper *ch;
535 enum GNUNET_CADET_ChannelOption flags;
536 535
537 reconnect_task = NULL; 536 reconnect_task = NULL;
538 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 537 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -543,13 +542,11 @@ reconnect_op (void *cls)
543 GNUNET_CADET_channel_destroy (outgoing_ch); 542 GNUNET_CADET_channel_destroy (outgoing_ch);
544 outgoing_ch = NULL; 543 outgoing_ch = NULL;
545 } 544 }
546 flags = GNUNET_CADET_OPTION_DEFAULT;
547 ch = GNUNET_new (struct CadetTestChannelWrapper); 545 ch = GNUNET_new (struct CadetTestChannelWrapper);
548 outgoing_ch = GNUNET_CADET_channel_create (h1, 546 outgoing_ch = GNUNET_CADET_channel_create (h1,
549 ch, 547 ch,
550 p_id[1], 548 p_id[1],
551 &port, 549 &port,
552 flags,
553 NULL, 550 NULL,
554 &disconnect_handler, 551 &disconnect_handler,
555 handlers); 552 handlers);
@@ -998,7 +995,6 @@ start_test (void *cls)
998 GNUNET_MQ_handler_end () 995 GNUNET_MQ_handler_end ()
999 }; 996 };
1000 struct CadetTestChannelWrapper *ch; 997 struct CadetTestChannelWrapper *ch;
1001 enum GNUNET_CADET_ChannelOption flags;
1002 998
1003 test_task = NULL; 999 test_task = NULL;
1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name); 1000 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name);
@@ -1008,11 +1004,9 @@ start_test (void *cls)
1008 disconnect_task = NULL; 1004 disconnect_task = NULL;
1009 } 1005 }
1010 1006
1011 flags = GNUNET_CADET_OPTION_DEFAULT;
1012 if (SPEED_REL == test) 1007 if (SPEED_REL == test)
1013 { 1008 {
1014 test = SPEED; 1009 test = SPEED;
1015 flags |= GNUNET_CADET_OPTION_RELIABLE;
1016 } 1010 }
1017 1011
1018 ch = GNUNET_new (struct CadetTestChannelWrapper); 1012 ch = GNUNET_new (struct CadetTestChannelWrapper);
@@ -1020,7 +1014,6 @@ start_test (void *cls)
1020 ch, 1014 ch,
1021 p_id[1], 1015 p_id[1],
1022 &port, 1016 &port,
1023 flags,
1024 NULL, 1017 NULL,
1025 &disconnect_handler, 1018 &disconnect_handler,
1026 handlers); 1019 handlers);
diff --git a/src/cadet/test_cadet_local_mq.c b/src/cadet/test_cadet_local_mq.c
index fc5561044..b2fed5bd6 100644
--- a/src/cadet/test_cadet_local_mq.c
+++ b/src/cadet/test_cadet_local_mq.c
@@ -243,7 +243,6 @@ do_connect (void *cls)
243 NULL, /* channel cls */ 243 NULL, /* channel cls */
244 &id, /* destination */ 244 &id, /* destination */
245 GC_u2h (TEST_MESSAGE_TYPE), /* port */ 245 GC_u2h (TEST_MESSAGE_TYPE), /* port */
246 GNUNET_CADET_OPTION_DEFAULT, /* opt */
247 NULL, /* window change */ 246 NULL, /* window change */
248 &disconnected, /* disconnect handler */ 247 &disconnected, /* disconnect handler */
249 handlers /* traffic handlers */ 248 handlers /* traffic handlers */
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 9ba250dfa..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,
@@ -494,7 +476,6 @@ reset_cadet (struct CadetHandle *mh)
494 mh, 476 mh,
495 &mh->target, 477 &mh->target,
496 &port, 478 &port,
497 GNUNET_CADET_OPTION_RELIABLE,
498 &window_change_cb, 479 &window_change_cb,
499 &disconnect_cb, 480 &disconnect_cb,
500 handlers); 481 handlers);
@@ -515,8 +496,8 @@ cadet_timeout (void *cls)
515 struct GNUNET_CADET_Channel *tun; 496 struct GNUNET_CADET_Channel *tun;
516 497
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
518 "Timeout on cadet channel to %s\n", 499 "Timeout on cadet channel to %s\n",
519 GNUNET_i2s (&mh->target)); 500 GNUNET_i2s (&mh->target));
520 mh->timeout_task = NULL; 501 mh->timeout_task = NULL;
521 tun = mh->channel; 502 tun = mh->channel;
522 mh->channel = NULL; 503 mh->channel = NULL;
@@ -554,31 +535,28 @@ transmit_pending (void *cls)
554 struct GNUNET_MQ_Envelope *env; 535 struct GNUNET_MQ_Envelope *env;
555 struct CadetQueryMessage *sqm; 536 struct CadetQueryMessage *sqm;
556 537
557 if ( (0 != GNUNET_MQ_get_length (mq)) || 538 if ((0 != GNUNET_MQ_get_length (mq)) || (NULL == (sr = mh->pending_head)))
558 (NULL == (sr = mh->pending_head)) )
559 return; 539 return;
560 GNUNET_CONTAINER_DLL_remove (mh->pending_head, 540 GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr);
561 mh->pending_tail, 541 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
562 sr); 542 mh->waiting_map,
563 GNUNET_assert (GNUNET_OK == 543 &sr->query,
564 GNUNET_CONTAINER_multihashmap_put (mh->waiting_map, 544 sr,
565 &sr->query, 545 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
566 sr,
567 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
568 sr->was_transmitted = GNUNET_YES; 546 sr->was_transmitted = GNUNET_YES;
569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
570 "Sending query for %s via cadet to %s\n", 548 "Sending query for %s via cadet to %s\n",
571 GNUNET_h2s (&sr->query), 549 GNUNET_h2s (&sr->query),
572 GNUNET_i2s (&mh->target)); 550 GNUNET_i2s (&mh->target));
573 env = GNUNET_MQ_msg (sqm, 551 env = GNUNET_MQ_msg (sqm, GNUNET_MESSAGE_TYPE_FS_CADET_QUERY);
574 GNUNET_MESSAGE_TYPE_FS_CADET_QUERY); 552 GNUNET_MQ_env_set_options (env,
553 GNUNET_MQ_PREF_GOODPUT |
554 GNUNET_MQ_PREF_CORK_ALLOWED |
555 GNUNET_MQ_PREF_OUT_OF_ORDER);
575 sqm->type = htonl (sr->type); 556 sqm->type = htonl (sr->type);
576 sqm->query = sr->query; 557 sqm->query = sr->query;
577 GNUNET_MQ_notify_sent (env, 558 GNUNET_MQ_notify_sent (env, &transmit_pending, mh);
578 &transmit_pending, 559 GNUNET_MQ_send (mq, env);
579 mh);
580 GNUNET_MQ_send (mq,
581 env);
582} 560}
583 561
584 562
@@ -592,8 +570,7 @@ get_cadet (const struct GNUNET_PeerIdentity *target)
592{ 570{
593 struct CadetHandle *mh; 571 struct CadetHandle *mh;
594 572
595 mh = GNUNET_CONTAINER_multipeermap_get (cadet_map, 573 mh = GNUNET_CONTAINER_multipeermap_get (cadet_map, target);
596 target);
597 if (NULL != mh) 574 if (NULL != mh)
598 { 575 {
599 if (NULL != mh->timeout_task) 576 if (NULL != mh->timeout_task)
@@ -604,27 +581,26 @@ get_cadet (const struct GNUNET_PeerIdentity *target)
604 return mh; 581 return mh;
605 } 582 }
606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
607 "Creating cadet channel to %s\n", 584 "Creating cadet channel to %s\n",
608 GNUNET_i2s (target)); 585 GNUNET_i2s (target));
609 mh = GNUNET_new (struct CadetHandle); 586 mh = GNUNET_new (struct CadetHandle);
610 mh->reset_task = GNUNET_SCHEDULER_add_delayed (CLIENT_RETRY_TIMEOUT, 587 mh->reset_task =
611 &reset_cadet_task, 588 GNUNET_SCHEDULER_add_delayed (CLIENT_RETRY_TIMEOUT, &reset_cadet_task, mh);
612 mh);
613 mh->waiting_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES); 589 mh->waiting_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES);
614 mh->target = *target; 590 mh->target = *target;
615 GNUNET_assert (GNUNET_OK == 591 GNUNET_assert (GNUNET_OK ==
616 GNUNET_CONTAINER_multipeermap_put (cadet_map, 592 GNUNET_CONTAINER_multipeermap_put (
617 &mh->target, 593 cadet_map,
618 mh, 594 &mh->target,
619 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 595 mh,
596 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
620 { 597 {
621 struct GNUNET_MQ_MessageHandler handlers[] = { 598 struct GNUNET_MQ_MessageHandler handlers[] =
622 GNUNET_MQ_hd_var_size (reply, 599 {GNUNET_MQ_hd_var_size (reply,
623 GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, 600 GNUNET_MESSAGE_TYPE_FS_CADET_REPLY,
624 struct CadetReplyMessage, 601 struct CadetReplyMessage,
625 mh), 602 mh),
626 GNUNET_MQ_handler_end () 603 GNUNET_MQ_handler_end ()};
627 };
628 struct GNUNET_HashCode port; 604 struct GNUNET_HashCode port;
629 605
630 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, 606 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER,
@@ -634,7 +610,6 @@ get_cadet (const struct GNUNET_PeerIdentity *target)
634 mh, 610 mh,
635 &mh->target, 611 &mh->target,
636 &port, 612 &port,
637 GNUNET_CADET_OPTION_RELIABLE,
638 &window_change_cb, 613 &window_change_cb,
639 &disconnect_cb, 614 &disconnect_cb,
640 handlers); 615 handlers);
@@ -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_cadet_service.h b/src/include/gnunet_cadet_service.h
index a11c5f3cb..ba4d60eb8 100644
--- a/src/include/gnunet_cadet_service.h
+++ b/src/include/gnunet_cadet_service.h
@@ -93,49 +93,6 @@ struct GNUNET_CADET_ChannelTunnelNumber
93 uint32_t cn GNUNET_PACKED; 93 uint32_t cn GNUNET_PACKED;
94}; 94};
95 95
96
97/**
98 * Channel options. Second line indicates filed in the
99 * CadetChannelInfo union carrying the answer.
100 *
101 * @deprecated we should replace channel options with per-envelope
102 * options, and then re-use the options from `enum GNUNET_MQ_PriorityPreferences`.
103 */
104enum GNUNET_CADET_ChannelOption
105{
106 /**
107 * Default options: unreliable, default buffering, not out of order.
108 */
109 GNUNET_CADET_OPTION_DEFAULT = 0x0,
110
111 /**
112 * Disable buffering on intermediate nodes (for minimum latency).
113 * Yes/No.
114 */
115 GNUNET_CADET_OPTION_NOBUFFER = 0x1,
116
117 /**
118 * Enable channel reliability, lost messages will be retransmitted.
119 * Yes/No.
120 */
121 GNUNET_CADET_OPTION_RELIABLE = 0x2,
122
123 /**
124 * Enable out of order delivery of messages.
125 * Set bit for out-of-order delivery.
126 */
127 GNUNET_CADET_OPTION_OUT_OF_ORDER = 0x4,
128
129 /**
130 * Who is the peer at the other end of the channel.
131 * Only for use in @c GNUNET_CADET_channel_get_info
132 * struct GNUNET_PeerIdentity *peer
133 */
134 GNUNET_CADET_OPTION_PEER = 0x8
135
136};
137
138
139/** 96/**
140 * Method called whenever a peer connects to a port in MQ-based CADET. 97 * Method called whenever a peer connects to a port in MQ-based CADET.
141 * 98 *
@@ -259,7 +216,6 @@ GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p);
259 * - Each message type callback in @a handlers 216 * - Each message type callback in @a handlers
260 * @param destination Peer identity the channel should go to. 217 * @param destination Peer identity the channel should go to.
261 * @param port Identification of the destination port. 218 * @param port Identification of the destination port.
262 * @param options CadetOption flag field, with all desired option bits set to 1.
263 * @param window_changes Function called when the transmit window size changes. 219 * @param window_changes Function called when the transmit window size changes.
264 * Can be NULL if this data is of no interest. 220 * Can be NULL if this data is of no interest.
265 * TODO Not yet implemented. 221 * TODO Not yet implemented.
@@ -272,7 +228,6 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
272 void *channel_cls, 228 void *channel_cls,
273 const struct GNUNET_PeerIdentity *destination, 229 const struct GNUNET_PeerIdentity *destination,
274 const struct GNUNET_HashCode *port, 230 const struct GNUNET_HashCode *port,
275 enum GNUNET_CADET_ChannelOption options,
276 GNUNET_CADET_WindowSizeEventHandler window_changes, 231 GNUNET_CADET_WindowSizeEventHandler window_changes,
277 GNUNET_CADET_DisconnectEventHandler disconnects, 232 GNUNET_CADET_DisconnectEventHandler disconnects,
278 const struct GNUNET_MQ_MessageHandler *handlers); 233 const struct GNUNET_MQ_MessageHandler *handlers);
@@ -324,6 +279,16 @@ GNUNET_CADET_receive_done (struct GNUNET_CADET_Channel *channel);
324const struct GNUNET_HashCode * 279const struct GNUNET_HashCode *
325GC_u2h (uint32_t port); 280GC_u2h (uint32_t port);
326 281
282enum GNUNET_CADET_ChannelInfoOption
283{
284 /**
285 * Who is the peer at the other end of the channel.
286 * Only for use in @c GNUNET_CADET_channel_get_info
287 * struct GNUNET_PeerIdentity *peer
288 */
289 GNUNET_CADET_OPTION_PEER = 0x0
290
291};
327 292
328/** 293/**
329 * Union to retrieve info about a channel. 294 * Union to retrieve info about a channel.
@@ -347,13 +312,12 @@ union GNUNET_CADET_ChannelInfo
347 * Get information about a channel. 312 * Get information about a channel.
348 * 313 *
349 * @param channel Channel handle. 314 * @param channel Channel handle.
350 * @param option Query type GNUNET_CADET_OPTION_*
351 * @param ... dependant on option, currently not used 315 * @param ... dependant on option, currently not used
352 * @return Union with an answer to the query. 316 * @return Union with an answer to the query.
353 */ 317 */
354const union GNUNET_CADET_ChannelInfo * 318const union GNUNET_CADET_ChannelInfo *
355GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel, 319GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel,
356 enum GNUNET_CADET_ChannelOption option, 320 enum GNUNET_CADET_ChannelInfoOption option,
357 ...); 321 ...);
358 322
359 323
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index 81100d7d8..f3073d54b 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -296,7 +296,7 @@ enum GNUNET_MQ_PriorityPreferences
296 /** 296 /**
297 * Flag to indicate that out-of-order delivery is OK. 297 * Flag to indicate that out-of-order delivery is OK.
298 */ 298 */
299 GNUNET_MQ_PREF_OUT_OF_ORDER = 256 299 GNUNET_MQ_PREF_OUT_OF_ORDER = 256,
300 300
301}; 301};
302 302
@@ -386,6 +386,24 @@ typedef void (*GNUNET_MQ_ErrorHandler) (void *cls, enum GNUNET_MQ_Error error);
386 * @param[in|out] env element to insert at the tail 386 * @param[in|out] env element to insert at the tail
387 */ 387 */
388void 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
389GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head, 407GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
390 struct GNUNET_MQ_Envelope **env_tail, 408 struct GNUNET_MQ_Envelope **env_tail,
391 struct GNUNET_MQ_Envelope *env); 409 struct GNUNET_MQ_Envelope *env);
diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c
index cd17c2b7b..99cbfebf8 100644
--- a/src/pt/gnunet-daemon-pt.c
+++ b/src/pt/gnunet-daemon-pt.c
@@ -1088,7 +1088,6 @@ try_open_exit ()
1088 pos, 1088 pos,
1089 &pos->peer, 1089 &pos->peer,
1090 &port, 1090 &port,
1091 GNUNET_CADET_OPTION_DEFAULT,
1092 &channel_idle_notify_cb, 1091 &channel_idle_notify_cb,
1093 &cadet_channel_end_cb, 1092 &cadet_channel_end_cb,
1094 cadet_handlers); 1093 cadet_handlers);
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index c5530a1eb..bbfdba3ac 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -1015,7 +1015,6 @@ get_channel (struct PeerContext *peer_ctx)
1015 peer_ctx->send_channel_ctx, /* context */ 1015 peer_ctx->send_channel_ctx, /* context */
1016 &peer_ctx->peer_id, 1016 &peer_ctx->peer_id,
1017 &peer_ctx->sub->hash, 1017 &peer_ctx->sub->hash,
1018 GNUNET_CADET_OPTION_RELIABLE,
1019 NULL, /* WindowSize handler */ 1018 NULL, /* WindowSize handler */
1020 &cleanup_destroyed_channel, /* Disconnect handler */ 1019 &cleanup_destroyed_channel, /* Disconnect handler */
1021 cadet_handlers); 1020 cadet_handlers);
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
index 4b1a09e50..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,9 +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 *
614 sizeof (struct GNUNET_CRYPTO_EccPoint),
615 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA);
637 msg->contained_element_count = htonl (todo_count); 616 msg->contained_element_count = htonl (todo_count);
638 payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1]; 617 payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1];
639 r_ia = gcry_mpi_new (0); 618 r_ia = gcry_mpi_new (0);
@@ -645,33 +624,22 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
645 gcry_mpi_point_t h_i; 624 gcry_mpi_point_t h_i;
646 625
647 r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc); 626 r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc);
648 g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, 627 g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_i);
649 r_i);
650 /* r_ia = r_i * a */ 628 /* r_ia = r_i * a */
651 gcry_mpi_mul (r_ia, 629 gcry_mpi_mul (r_ia, r_i, my_privkey);
652 r_i,
653 my_privkey);
654 gcry_mpi_release (r_i); 630 gcry_mpi_release (r_i);
655 /* r_ia_ai = r_ia + a_i */ 631 /* r_ia_ai = r_ia + a_i */
656 gcry_mpi_add (r_ia_ai, 632 gcry_mpi_add (r_ia_ai, r_ia, s->sorted_elements[i].value);
657 r_ia, 633 h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_ia_ai);
658 s->sorted_elements[i].value); 634 GNUNET_CRYPTO_ecc_point_to_bin (edc, g_i, &payload[(i - off) * 2]);
659 h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, 635 GNUNET_CRYPTO_ecc_point_to_bin (edc, h_i, &payload[(i - off) * 2 + 1]);
660 r_ia_ai);
661 GNUNET_CRYPTO_ecc_point_to_bin (edc,
662 g_i,
663 &payload[(i - off) * 2]);
664 GNUNET_CRYPTO_ecc_point_to_bin (edc,
665 h_i,
666 &payload[(i - off) * 2 + 1]);
667 gcry_mpi_point_release (g_i); 636 gcry_mpi_point_release (g_i);
668 gcry_mpi_point_release (h_i); 637 gcry_mpi_point_release (h_i);
669 } 638 }
670 gcry_mpi_release (r_ia); 639 gcry_mpi_release (r_ia);
671 gcry_mpi_release (r_ia_ai); 640 gcry_mpi_release (r_ia_ai);
672 off += todo_count; 641 off += todo_count;
673 GNUNET_MQ_send (s->cadet_mq, 642 GNUNET_MQ_send (s->cadet_mq, e);
674 e);
675 } 643 }
676} 644}
677 645
@@ -706,10 +674,11 @@ cb_intersection_element_removed (void *cls,
706 "Intersection removed element with key %s and value %lld\n", 674 "Intersection removed element with key %s and value %lld\n",
707 GNUNET_h2s (&se->key), 675 GNUNET_h2s (&se->key),
708 (long long) GNUNET_ntohll (se->value)); 676 (long long) GNUNET_ntohll (se->value));
709 GNUNET_assert (GNUNET_YES == 677 GNUNET_assert (
710 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, 678 GNUNET_YES ==
711 element->data, 679 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
712 se)); 680 element->data,
681 se));
713 GNUNET_free (se); 682 GNUNET_free (se);
714 return; 683 return;
715 case GNUNET_SET_STATUS_DONE: 684 case GNUNET_SET_STATUS_DONE:
@@ -727,8 +696,7 @@ cb_intersection_element_removed (void *cls,
727 return; 696 return;
728 case GNUNET_SET_STATUS_FAILURE: 697 case GNUNET_SET_STATUS_FAILURE:
729 /* unhandled status code */ 698 /* unhandled status code */
730 LOG (GNUNET_ERROR_TYPE_DEBUG, 699 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
731 "Set intersection failed!\n");
732 if (NULL != s->intersection_listen) 700 if (NULL != s->intersection_listen)
733 { 701 {
734 GNUNET_SET_listen_cancel (s->intersection_listen); 702 GNUNET_SET_listen_cancel (s->intersection_listen);
@@ -776,18 +744,16 @@ cb_intersection_request_alice (void *cls,
776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
777 "Received intersection request from %s!\n", 745 "Received intersection request from %s!\n",
778 GNUNET_i2s (other_peer)); 746 GNUNET_i2s (other_peer));
779 if (0 != GNUNET_memcmp (other_peer, 747 if (0 != GNUNET_memcmp (other_peer, &s->peer))
780 &s->peer))
781 { 748 {
782 GNUNET_break_op (0); 749 GNUNET_break_op (0);
783 return; 750 return;
784 } 751 }
785 s->intersection_op 752 s->intersection_op = GNUNET_SET_accept (request,
786 = GNUNET_SET_accept (request, 753 GNUNET_SET_RESULT_REMOVED,
787 GNUNET_SET_RESULT_REMOVED, 754 (struct GNUNET_SET_Option[]){{0}},
788 (struct GNUNET_SET_Option[]) {{ 0 }}, 755 &cb_intersection_element_removed,
789 &cb_intersection_element_removed, 756 s);
790 s);
791 if (NULL == s->intersection_op) 757 if (NULL == s->intersection_op)
792 { 758 {
793 GNUNET_break (0); 759 GNUNET_break (0);
@@ -795,9 +761,7 @@ cb_intersection_request_alice (void *cls,
795 prepare_client_end_notification (s); 761 prepare_client_end_notification (s);
796 return; 762 return;
797 } 763 }
798 if (GNUNET_OK != 764 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set))
799 GNUNET_SET_commit (s->intersection_op,
800 s->intersection_set))
801 { 765 {
802 GNUNET_break (0); 766 GNUNET_break (0);
803 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 767 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -815,13 +779,12 @@ cb_intersection_request_alice (void *cls,
815static void 779static void
816client_request_complete_alice (struct AliceServiceSession *s) 780client_request_complete_alice (struct AliceServiceSession *s)
817{ 781{
818 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 782 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
819 GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message, 783 {GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message,
820 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, 784 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA,
821 struct EccBobCryptodataMessage, 785 struct EccBobCryptodataMessage,
822 s), 786 s),
823 GNUNET_MQ_handler_end () 787 GNUNET_MQ_handler_end ()};
824 };
825 struct EccServiceRequestMessage *msg; 788 struct EccServiceRequestMessage *msg;
826 struct GNUNET_MQ_Envelope *e; 789 struct GNUNET_MQ_Envelope *e;
827 struct GNUNET_HashCode set_sid; 790 struct GNUNET_HashCode set_sid;
@@ -832,15 +795,13 @@ client_request_complete_alice (struct AliceServiceSession *s)
832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
833 "Creating new channel for session with key %s.\n", 796 "Creating new channel for session with key %s.\n",
834 GNUNET_h2s (&s->session_id)); 797 GNUNET_h2s (&s->session_id));
835 s->channel 798 s->channel = GNUNET_CADET_channel_create (my_cadet,
836 = GNUNET_CADET_channel_create (my_cadet, 799 s,
837 s, 800 &s->peer,
838 &s->peer, 801 &s->session_id,
839 &s->session_id, 802 NULL,
840 GNUNET_CADET_OPTION_RELIABLE, 803 &cb_channel_destruction,
841 NULL, 804 cadet_handlers);
842 &cb_channel_destruction,
843 cadet_handlers);
844 if (NULL == s->channel) 805 if (NULL == s->channel)
845 { 806 {
846 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 807 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -848,12 +809,11 @@ client_request_complete_alice (struct AliceServiceSession *s)
848 return; 809 return;
849 } 810 }
850 s->cadet_mq = GNUNET_CADET_get_mq (s->channel); 811 s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
851 s->intersection_listen 812 s->intersection_listen = GNUNET_SET_listen (cfg,
852 = GNUNET_SET_listen (cfg, 813 GNUNET_SET_OPERATION_INTERSECTION,
853 GNUNET_SET_OPERATION_INTERSECTION, 814 &set_sid,
854 &set_sid, 815 &cb_intersection_request_alice,
855 &cb_intersection_request_alice, 816 s);
856 s);
857 if (NULL == s->intersection_listen) 817 if (NULL == s->intersection_listen)
858 { 818 {
859 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 819 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -863,11 +823,12 @@ client_request_complete_alice (struct AliceServiceSession *s)
863 return; 823 return;
864 } 824 }
865 825
866 e = GNUNET_MQ_msg (msg, 826 e =
867 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION); 827 GNUNET_MQ_msg (msg,
828 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION);
829 GNUNET_MQ_env_set_options (e, GNUNET_MQ_PRIO_CRITICAL_CONTROL);
868 msg->session_id = s->session_id; 830 msg->session_id = s->session_id;
869 GNUNET_MQ_send (s->cadet_mq, 831 GNUNET_MQ_send (s->cadet_mq, e);
870 e);
871} 832}
872 833
873 834
@@ -880,8 +841,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
880 * @return #GNUNET_OK if @a msg is well-formed 841 * @return #GNUNET_OK if @a msg is well-formed
881 */ 842 */
882static int 843static int
883check_alice_client_message_multipart (void *cls, 844check_alice_client_message_multipart (
884 const struct ComputationBobCryptodataMultipartMessage *msg) 845 void *cls,
846 const struct ComputationBobCryptodataMultipartMessage *msg)
885{ 847{
886 struct AliceServiceSession *s = cls; 848 struct AliceServiceSession *s = cls;
887 uint32_t contained_count; 849 uint32_t contained_count;
@@ -889,11 +851,12 @@ check_alice_client_message_multipart (void *cls,
889 851
890 msize = ntohs (msg->header.size); 852 msize = ntohs (msg->header.size);
891 contained_count = ntohl (msg->element_count_contained); 853 contained_count = ntohl (msg->element_count_contained);
892 if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + 854 if ((msize !=
893 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || 855 (sizeof (struct ComputationBobCryptodataMultipartMessage) +
894 (0 == contained_count) || 856 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
895 (s->total == s->client_received_element_count) || 857 (0 == contained_count) ||
896 (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))
897 { 860 {
898 GNUNET_break_op (0); 861 GNUNET_break_op (0);
899 return GNUNET_SYSERR; 862 return GNUNET_SYSERR;
@@ -910,8 +873,9 @@ check_alice_client_message_multipart (void *cls,
910 * @param msg the actual message 873 * @param msg the actual message
911 */ 874 */
912static void 875static void
913handle_alice_client_message_multipart (void *cls, 876handle_alice_client_message_multipart (
914 const struct ComputationBobCryptodataMultipartMessage *msg) 877 void *cls,
878 const struct ComputationBobCryptodataMultipartMessage *msg)
915{ 879{
916 struct AliceServiceSession *s = cls; 880 struct AliceServiceSession *s = cls;
917 uint32_t contained_count; 881 uint32_t contained_count;
@@ -926,13 +890,13 @@ handle_alice_client_message_multipart (void *cls,
926 { 890 {
927 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 891 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
928 GNUNET_memcpy (elem, 892 GNUNET_memcpy (elem,
929 &elements[i], 893 &elements[i],
930 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 894 sizeof (struct GNUNET_SCALARPRODUCT_Element));
931 if (GNUNET_SYSERR == 895 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
932 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 896 s->intersected_elements,
933 &elem->key, 897 &elem->key,
934 elem, 898 elem,
935 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 899 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
936 { 900 {
937 GNUNET_break (0); 901 GNUNET_break (0);
938 GNUNET_free (elem); 902 GNUNET_free (elem);
@@ -941,9 +905,7 @@ handle_alice_client_message_multipart (void *cls,
941 set_elem.data = &elem->key; 905 set_elem.data = &elem->key;
942 set_elem.size = sizeof (elem->key); 906 set_elem.size = sizeof (elem->key);
943 set_elem.element_type = 0; 907 set_elem.element_type = 0;
944 GNUNET_SET_add_element (s->intersection_set, 908 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
945 &set_elem,
946 NULL, NULL);
947 s->used_element_count++; 909 s->used_element_count++;
948 } 910 }
949 GNUNET_SERVICE_client_continue (s->client); 911 GNUNET_SERVICE_client_continue (s->client);
@@ -954,8 +916,7 @@ handle_alice_client_message_multipart (void *cls,
954 "Received client multipart data, waiting for more!\n"); 916 "Received client multipart data, waiting for more!\n");
955 return; 917 return;
956 } 918 }
957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n");
958 "Launching computation\n");
959 client_request_complete_alice (s); 920 client_request_complete_alice (s);
960} 921}
961 922
@@ -970,7 +931,7 @@ handle_alice_client_message_multipart (void *cls,
970 */ 931 */
971static int 932static int
972check_alice_client_message (void *cls, 933check_alice_client_message (void *cls,
973 const struct AliceComputationMessage *msg) 934 const struct AliceComputationMessage *msg)
974{ 935{
975 struct AliceServiceSession *s = cls; 936 struct AliceServiceSession *s = cls;
976 uint16_t msize; 937 uint16_t msize;
@@ -987,10 +948,10 @@ check_alice_client_message (void *cls,
987 msize = ntohs (msg->header.size); 948 msize = ntohs (msg->header.size);
988 total_count = ntohl (msg->element_count_total); 949 total_count = ntohl (msg->element_count_total);
989 contained_count = ntohl (msg->element_count_contained); 950 contained_count = ntohl (msg->element_count_contained);
990 if ( (0 == total_count) || 951 if ((0 == total_count) || (0 == contained_count) ||
991 (0 == contained_count) || 952 (msize !=
992 (msize != (sizeof (struct AliceComputationMessage) + 953 (sizeof (struct AliceComputationMessage) +
993 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) 954 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))))
994 { 955 {
995 GNUNET_break_op (0); 956 GNUNET_break_op (0);
996 return GNUNET_SYSERR; 957 return GNUNET_SYSERR;
@@ -1008,7 +969,7 @@ check_alice_client_message (void *cls,
1008 */ 969 */
1009static void 970static void
1010handle_alice_client_message (void *cls, 971handle_alice_client_message (void *cls,
1011 const struct AliceComputationMessage *msg) 972 const struct AliceComputationMessage *msg)
1012{ 973{
1013 struct AliceServiceSession *s = cls; 974 struct AliceServiceSession *s = cls;
1014 uint32_t contained_count; 975 uint32_t contained_count;
@@ -1025,23 +986,23 @@ handle_alice_client_message (void *cls,
1025 s->client_received_element_count = contained_count; 986 s->client_received_element_count = contained_count;
1026 s->session_id = msg->session_key; 987 s->session_id = msg->session_key;
1027 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 988 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
1028 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, 989 s->intersected_elements =
1029 GNUNET_YES); 990 GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES);
1030 s->intersection_set = GNUNET_SET_create (cfg, 991 s->intersection_set =
1031 GNUNET_SET_OPERATION_INTERSECTION); 992 GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
1032 for (uint32_t i = 0; i < contained_count; i++) 993 for (uint32_t i = 0; i < contained_count; i++)
1033 { 994 {
1034 if (0 == GNUNET_ntohll (elements[i].value)) 995 if (0 == GNUNET_ntohll (elements[i].value))
1035 continue; 996 continue;
1036 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 997 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1037 GNUNET_memcpy (elem, 998 GNUNET_memcpy (elem,
1038 &elements[i], 999 &elements[i],
1039 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1000 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1040 if (GNUNET_SYSERR == 1001 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1041 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1002 s->intersected_elements,
1042 &elem->key, 1003 &elem->key,
1043 elem, 1004 elem,
1044 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1005 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1045 { 1006 {
1046 /* element with same key encountered twice! */ 1007 /* element with same key encountered twice! */
1047 GNUNET_break (0); 1008 GNUNET_break (0);
@@ -1051,9 +1012,7 @@ handle_alice_client_message (void *cls,
1051 set_elem.data = &elem->key; 1012 set_elem.data = &elem->key;
1052 set_elem.size = sizeof (elem->key); 1013 set_elem.size = sizeof (elem->key);
1053 set_elem.element_type = 0; 1014 set_elem.element_type = 0;
1054 GNUNET_SET_add_element (s->intersection_set, 1015 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1055 &set_elem,
1056 NULL, NULL);
1057 s->used_element_count++; 1016 s->used_element_count++;
1058 } 1017 }
1059 GNUNET_SERVICE_client_continue (s->client); 1018 GNUNET_SERVICE_client_continue (s->client);
@@ -1064,8 +1023,7 @@ handle_alice_client_message (void *cls,
1064 "Received partial client request, waiting for more!\n"); 1023 "Received partial client request, waiting for more!\n");
1065 return; 1024 return;
1066 } 1025 }
1067 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n");
1068 "Launching computation\n");
1069 client_request_complete_alice (s); 1027 client_request_complete_alice (s);
1070} 1028}
1071 1029
@@ -1079,8 +1037,7 @@ handle_alice_client_message (void *cls,
1079static void 1037static void
1080shutdown_task (void *cls) 1038shutdown_task (void *cls)
1081{ 1039{
1082 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n");
1083 "Shutting down, initiating cleanup.\n");
1084 // FIXME: we have to cut our connections to CADET first! 1041 // FIXME: we have to cut our connections to CADET first!
1085 if (NULL != my_cadet) 1042 if (NULL != my_cadet)
1086 { 1043 {
@@ -1107,8 +1064,8 @@ shutdown_task (void *cls)
1107 */ 1064 */
1108static void * 1065static void *
1109client_connect_cb (void *cls, 1066client_connect_cb (void *cls,
1110 struct GNUNET_SERVICE_Client *client, 1067 struct GNUNET_SERVICE_Client *client,
1111 struct GNUNET_MQ_Handle *mq) 1068 struct GNUNET_MQ_Handle *mq)
1112{ 1069{
1113 struct AliceServiceSession *s; 1070 struct AliceServiceSession *s;
1114 1071
@@ -1131,8 +1088,8 @@ client_connect_cb (void *cls,
1131 */ 1088 */
1132static void 1089static void
1133client_disconnect_cb (void *cls, 1090client_disconnect_cb (void *cls,
1134 struct GNUNET_SERVICE_Client *client, 1091 struct GNUNET_SERVICE_Client *client,
1135 void *app_cls) 1092 void *app_cls)
1136{ 1093{
1137 struct AliceServiceSession *s = app_cls; 1094 struct AliceServiceSession *s = app_cls;
1138 1095
@@ -1158,45 +1115,40 @@ run (void *cls,
1158 struct GNUNET_SERVICE_Handle *service) 1115 struct GNUNET_SERVICE_Handle *service)
1159{ 1116{
1160 cfg = c; 1117 cfg = c;
1161 edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, 1118 edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, MAX_RAM);
1162 MAX_RAM);
1163 /* Select a random 'a' value for Alice */ 1119 /* Select a random 'a' value for Alice */
1164 GNUNET_CRYPTO_ecc_rnd_mpi (edc, 1120 GNUNET_CRYPTO_ecc_rnd_mpi (edc, &my_privkey, &my_privkey_inv);
1165 &my_privkey,
1166 &my_privkey_inv);
1167 my_cadet = GNUNET_CADET_connect (cfg); 1121 my_cadet = GNUNET_CADET_connect (cfg);
1168 if (NULL == my_cadet) 1122 if (NULL == my_cadet)
1169 { 1123 {
1170 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n"));
1171 _("Connect to CADET failed\n"));
1172 GNUNET_SCHEDULER_shutdown (); 1125 GNUNET_SCHEDULER_shutdown ();
1173 return; 1126 return;
1174 } 1127 }
1175 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1128 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1176 NULL);
1177
1178} 1129}
1179 1130
1180 1131
1181/** 1132/**
1182 * Define "main" method using service macro. 1133 * Define "main" method using service macro.
1183 */ 1134 */
1184GNUNET_SERVICE_MAIN 1135GNUNET_SERVICE_MAIN (
1185("scalarproduct-alice", 1136 "scalarproduct-alice",
1186 GNUNET_SERVICE_OPTION_NONE, 1137 GNUNET_SERVICE_OPTION_NONE,
1187 &run, 1138 &run,
1188 &client_connect_cb, 1139 &client_connect_cb,
1189 &client_disconnect_cb, 1140 &client_disconnect_cb,
1190 NULL, 1141 NULL,
1191 GNUNET_MQ_hd_var_size (alice_client_message, 1142 GNUNET_MQ_hd_var_size (alice_client_message,
1192 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, 1143 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
1193 struct AliceComputationMessage, 1144 struct AliceComputationMessage,
1194 NULL), 1145 NULL),
1195 GNUNET_MQ_hd_var_size (alice_client_message_multipart, 1146 GNUNET_MQ_hd_var_size (
1196 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, 1147 alice_client_message_multipart,
1197 struct ComputationBobCryptodataMultipartMessage, 1148 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
1198 NULL), 1149 struct ComputationBobCryptodataMultipartMessage,
1199 GNUNET_MQ_handler_end ()); 1150 NULL),
1151 GNUNET_MQ_handler_end ());
1200 1152
1201 1153
1202/* 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 393a1951b..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,27 +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 *
872 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext),
873 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA);
896 msg->contained_element_count = htonl (todo_count); 874 msg->contained_element_count = htonl (todo_count);
897 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 875 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
898 a = gcry_mpi_new (0); 876 a = gcry_mpi_new (0);
899 for (i = off; i < off + todo_count; i++) 877 for (i = off; i < off + todo_count; i++)
900 { 878 {
901 gcry_mpi_add (a, 879 gcry_mpi_add (a, s->sorted_elements[i].value, my_offset);
902 s->sorted_elements[i].value, 880 GNUNET_assert (
903 my_offset); 881 3 ==
904 GNUNET_assert (3 == 882 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - off]));
905 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey,
906 a,
907 3,
908 &payload[i - off]));
909 } 883 }
910 gcry_mpi_release (a); 884 gcry_mpi_release (a);
911 off += todo_count; 885 off += todo_count;
912 GNUNET_MQ_send (s->cadet_mq, 886 GNUNET_MQ_send (s->cadet_mq, e);
913 e);
914 } 887 }
915} 888}
916 889
@@ -945,10 +918,11 @@ cb_intersection_element_removed (void *cls,
945 "Intersection removed element with key %s and value %lld\n", 918 "Intersection removed element with key %s and value %lld\n",
946 GNUNET_h2s (&se->key), 919 GNUNET_h2s (&se->key),
947 (long long) GNUNET_ntohll (se->value)); 920 (long long) GNUNET_ntohll (se->value));
948 GNUNET_assert (GNUNET_YES == 921 GNUNET_assert (
949 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, 922 GNUNET_YES ==
950 element->data, 923 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
951 se)); 924 element->data,
925 se));
952 GNUNET_free (se); 926 GNUNET_free (se);
953 return; 927 return;
954 case GNUNET_SET_STATUS_DONE: 928 case GNUNET_SET_STATUS_DONE:
@@ -966,8 +940,7 @@ cb_intersection_element_removed (void *cls,
966 return; 940 return;
967 case GNUNET_SET_STATUS_FAILURE: 941 case GNUNET_SET_STATUS_FAILURE:
968 /* unhandled status code */ 942 /* unhandled status code */
969 LOG (GNUNET_ERROR_TYPE_DEBUG, 943 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
970 "Set intersection failed!\n");
971 if (NULL != s->intersection_listen) 944 if (NULL != s->intersection_listen)
972 { 945 {
973 GNUNET_SET_listen_cancel (s->intersection_listen); 946 GNUNET_SET_listen_cancel (s->intersection_listen);
@@ -1012,18 +985,16 @@ cb_intersection_request_alice (void *cls,
1012{ 985{
1013 struct AliceServiceSession *s = cls; 986 struct AliceServiceSession *s = cls;
1014 987
1015 if (0 != GNUNET_memcmp (other_peer, 988 if (0 != GNUNET_memcmp (other_peer, &s->peer))
1016 &s->peer))
1017 { 989 {
1018 GNUNET_break_op (0); 990 GNUNET_break_op (0);
1019 return; 991 return;
1020 } 992 }
1021 s->intersection_op 993 s->intersection_op = GNUNET_SET_accept (request,
1022 = GNUNET_SET_accept (request, 994 GNUNET_SET_RESULT_REMOVED,
1023 GNUNET_SET_RESULT_REMOVED, 995 (struct GNUNET_SET_Option[]){{0}},
1024 (struct GNUNET_SET_Option[]) {{ 0 }}, 996 &cb_intersection_element_removed,
1025 &cb_intersection_element_removed, 997 s);
1026 s);
1027 if (NULL == s->intersection_op) 998 if (NULL == s->intersection_op)
1028 { 999 {
1029 GNUNET_break (0); 1000 GNUNET_break (0);
@@ -1031,9 +1002,7 @@ cb_intersection_request_alice (void *cls,
1031 prepare_client_end_notification (s); 1002 prepare_client_end_notification (s);
1032 return; 1003 return;
1033 } 1004 }
1034 if (GNUNET_OK != 1005 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set))
1035 GNUNET_SET_commit (s->intersection_op,
1036 s->intersection_set))
1037 { 1006 {
1038 GNUNET_break (0); 1007 GNUNET_break (0);
1039 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1008 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1051,32 +1020,30 @@ cb_intersection_request_alice (void *cls,
1051static void 1020static void
1052client_request_complete_alice (struct AliceServiceSession *s) 1021client_request_complete_alice (struct AliceServiceSession *s)
1053{ 1022{
1054 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1023 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1055 GNUNET_MQ_hd_var_size (bobs_cryptodata_message, 1024 {GNUNET_MQ_hd_var_size (bobs_cryptodata_message,
1056 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, 1025 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
1057 struct BobCryptodataMessage, 1026 struct BobCryptodataMessage,
1058 s), 1027 s),
1059 GNUNET_MQ_hd_var_size (bobs_cryptodata_multipart, 1028 GNUNET_MQ_hd_var_size (
1060 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, 1029 bobs_cryptodata_multipart,
1061 struct BobCryptodataMultipartMessage, 1030 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
1062 s), 1031 struct BobCryptodataMultipartMessage,
1063 GNUNET_MQ_handler_end () 1032 s),
1064 }; 1033 GNUNET_MQ_handler_end ()};
1065 struct ServiceRequestMessage *msg; 1034 struct ServiceRequestMessage *msg;
1066 struct GNUNET_MQ_Envelope *e; 1035 struct GNUNET_MQ_Envelope *e;
1067 1036
1068 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1069 "Creating new channel for session with key %s.\n", 1038 "Creating new channel for session with key %s.\n",
1070 GNUNET_h2s (&s->session_id)); 1039 GNUNET_h2s (&s->session_id));
1071 s->channel 1040 s->channel = GNUNET_CADET_channel_create (my_cadet,
1072 = GNUNET_CADET_channel_create (my_cadet, 1041 s,
1073 s, 1042 &s->peer,
1074 &s->peer, 1043 &s->session_id,
1075 &s->session_id, 1044 NULL,
1076 GNUNET_CADET_OPTION_RELIABLE, 1045 &cb_channel_destruction,
1077 NULL, 1046 cadet_handlers);
1078 &cb_channel_destruction,
1079 cadet_handlers);
1080 if (NULL == s->channel) 1047 if (NULL == s->channel)
1081 { 1048 {
1082 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1049 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1084,12 +1051,11 @@ client_request_complete_alice (struct AliceServiceSession *s)
1084 return; 1051 return;
1085 } 1052 }
1086 s->cadet_mq = GNUNET_CADET_get_mq (s->channel); 1053 s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
1087 s->intersection_listen 1054 s->intersection_listen = GNUNET_SET_listen (cfg,
1088 = GNUNET_SET_listen (cfg, 1055 GNUNET_SET_OPERATION_INTERSECTION,
1089 GNUNET_SET_OPERATION_INTERSECTION, 1056 &s->session_id,
1090 &s->session_id, 1057 &cb_intersection_request_alice,
1091 &cb_intersection_request_alice, 1058 s);
1092 s);
1093 if (NULL == s->intersection_listen) 1059 if (NULL == s->intersection_listen)
1094 { 1060 {
1095 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1061 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1103,8 +1069,7 @@ client_request_complete_alice (struct AliceServiceSession *s)
1103 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION); 1069 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION);
1104 msg->session_id = s->session_id; 1070 msg->session_id = s->session_id;
1105 msg->public_key = my_pubkey; 1071 msg->public_key = my_pubkey;
1106 GNUNET_MQ_send (s->cadet_mq, 1072 GNUNET_MQ_send (s->cadet_mq, e);
1107 e);
1108} 1073}
1109 1074
1110 1075
@@ -1117,8 +1082,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
1117 * @return #GNUNET_OK if @a msg is well-formed 1082 * @return #GNUNET_OK if @a msg is well-formed
1118 */ 1083 */
1119static int 1084static int
1120check_alice_client_message_multipart (void *cls, 1085check_alice_client_message_multipart (
1121 const struct ComputationBobCryptodataMultipartMessage *msg) 1086 void *cls,
1087 const struct ComputationBobCryptodataMultipartMessage *msg)
1122{ 1088{
1123 struct AliceServiceSession *s = cls; 1089 struct AliceServiceSession *s = cls;
1124 uint32_t contained_count; 1090 uint32_t contained_count;
@@ -1126,11 +1092,12 @@ check_alice_client_message_multipart (void *cls,
1126 1092
1127 msize = ntohs (msg->header.size); 1093 msize = ntohs (msg->header.size);
1128 contained_count = ntohl (msg->element_count_contained); 1094 contained_count = ntohl (msg->element_count_contained);
1129 if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + 1095 if ((msize !=
1130 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || 1096 (sizeof (struct ComputationBobCryptodataMultipartMessage) +
1131 (0 == contained_count) || 1097 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
1132 (s->total == s->client_received_element_count) || 1098 (0 == contained_count) ||
1133 (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))
1134 { 1101 {
1135 GNUNET_break_op (0); 1102 GNUNET_break_op (0);
1136 return GNUNET_SYSERR; 1103 return GNUNET_SYSERR;
@@ -1147,8 +1114,9 @@ check_alice_client_message_multipart (void *cls,
1147 * @param msg the actual message 1114 * @param msg the actual message
1148 */ 1115 */
1149static void 1116static void
1150handle_alice_client_message_multipart (void *cls, 1117handle_alice_client_message_multipart (
1151 const struct ComputationBobCryptodataMultipartMessage *msg) 1118 void *cls,
1119 const struct ComputationBobCryptodataMultipartMessage *msg)
1152{ 1120{
1153 struct AliceServiceSession *s = cls; 1121 struct AliceServiceSession *s = cls;
1154 uint32_t contained_count; 1122 uint32_t contained_count;
@@ -1163,13 +1131,13 @@ handle_alice_client_message_multipart (void *cls,
1163 { 1131 {
1164 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 1132 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1165 GNUNET_memcpy (elem, 1133 GNUNET_memcpy (elem,
1166 &elements[i], 1134 &elements[i],
1167 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1135 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1168 if (GNUNET_SYSERR == 1136 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1169 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1137 s->intersected_elements,
1170 &elem->key, 1138 &elem->key,
1171 elem, 1139 elem,
1172 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1140 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1173 { 1141 {
1174 GNUNET_break (0); 1142 GNUNET_break (0);
1175 GNUNET_free (elem); 1143 GNUNET_free (elem);
@@ -1178,9 +1146,7 @@ handle_alice_client_message_multipart (void *cls,
1178 set_elem.data = &elem->key; 1146 set_elem.data = &elem->key;
1179 set_elem.size = sizeof (elem->key); 1147 set_elem.size = sizeof (elem->key);
1180 set_elem.element_type = 0; 1148 set_elem.element_type = 0;
1181 GNUNET_SET_add_element (s->intersection_set, 1149 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1182 &set_elem,
1183 NULL, NULL);
1184 s->used_element_count++; 1150 s->used_element_count++;
1185 } 1151 }
1186 GNUNET_SERVICE_client_continue (s->client); 1152 GNUNET_SERVICE_client_continue (s->client);
@@ -1203,7 +1169,7 @@ handle_alice_client_message_multipart (void *cls,
1203 */ 1169 */
1204static int 1170static int
1205check_alice_client_message (void *cls, 1171check_alice_client_message (void *cls,
1206 const struct AliceComputationMessage *msg) 1172 const struct AliceComputationMessage *msg)
1207{ 1173{
1208 struct AliceServiceSession *s = cls; 1174 struct AliceServiceSession *s = cls;
1209 uint16_t msize; 1175 uint16_t msize;
@@ -1220,10 +1186,10 @@ check_alice_client_message (void *cls,
1220 msize = ntohs (msg->header.size); 1186 msize = ntohs (msg->header.size);
1221 total_count = ntohl (msg->element_count_total); 1187 total_count = ntohl (msg->element_count_total);
1222 contained_count = ntohl (msg->element_count_contained); 1188 contained_count = ntohl (msg->element_count_contained);
1223 if ( (0 == total_count) || 1189 if ((0 == total_count) || (0 == contained_count) ||
1224 (0 == contained_count) || 1190 (msize !=
1225 (msize != (sizeof (struct AliceComputationMessage) + 1191 (sizeof (struct AliceComputationMessage) +
1226 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) 1192 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))))
1227 { 1193 {
1228 GNUNET_break_op (0); 1194 GNUNET_break_op (0);
1229 return GNUNET_SYSERR; 1195 return GNUNET_SYSERR;
@@ -1241,7 +1207,7 @@ check_alice_client_message (void *cls,
1241 */ 1207 */
1242static void 1208static void
1243handle_alice_client_message (void *cls, 1209handle_alice_client_message (void *cls,
1244 const struct AliceComputationMessage *msg) 1210 const struct AliceComputationMessage *msg)
1245{ 1211{
1246 struct AliceServiceSession *s = cls; 1212 struct AliceServiceSession *s = cls;
1247 uint32_t contained_count; 1213 uint32_t contained_count;
@@ -1258,10 +1224,10 @@ handle_alice_client_message (void *cls,
1258 s->client_received_element_count = contained_count; 1224 s->client_received_element_count = contained_count;
1259 s->session_id = msg->session_key; 1225 s->session_id = msg->session_key;
1260 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 1226 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
1261 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, 1227 s->intersected_elements =
1262 GNUNET_YES); 1228 GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES);
1263 s->intersection_set = GNUNET_SET_create (cfg, 1229 s->intersection_set =
1264 GNUNET_SET_OPERATION_INTERSECTION); 1230 GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
1265 1231
1266 for (uint32_t i = 0; i < contained_count; i++) 1232 for (uint32_t i = 0; i < contained_count; i++)
1267 { 1233 {
@@ -1269,13 +1235,13 @@ handle_alice_client_message (void *cls,
1269 continue; 1235 continue;
1270 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 1236 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1271 GNUNET_memcpy (elem, 1237 GNUNET_memcpy (elem,
1272 &elements[i], 1238 &elements[i],
1273 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1239 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1274 if (GNUNET_SYSERR == 1240 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1275 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1241 s->intersected_elements,
1276 &elem->key, 1242 &elem->key,
1277 elem, 1243 elem,
1278 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1244 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1279 { 1245 {
1280 /* element with same key encountered twice! */ 1246 /* element with same key encountered twice! */
1281 GNUNET_break (0); 1247 GNUNET_break (0);
@@ -1285,9 +1251,7 @@ handle_alice_client_message (void *cls,
1285 set_elem.data = &elem->key; 1251 set_elem.data = &elem->key;
1286 set_elem.size = sizeof (elem->key); 1252 set_elem.size = sizeof (elem->key);
1287 set_elem.element_type = 0; 1253 set_elem.element_type = 0;
1288 GNUNET_SET_add_element (s->intersection_set, 1254 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1289 &set_elem,
1290 NULL, NULL);
1291 s->used_element_count++; 1255 s->used_element_count++;
1292 } 1256 }
1293 GNUNET_SERVICE_client_continue (s->client); 1257 GNUNET_SERVICE_client_continue (s->client);
@@ -1308,8 +1272,7 @@ handle_alice_client_message (void *cls,
1308static void 1272static void
1309shutdown_task (void *cls) 1273shutdown_task (void *cls)
1310{ 1274{
1311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n");
1312 "Shutting down, initiating cleanup.\n");
1313 // FIXME: we have to cut our connections to CADET first! 1276 // FIXME: we have to cut our connections to CADET first!
1314 if (NULL != my_cadet) 1277 if (NULL != my_cadet)
1315 { 1278 {
@@ -1331,8 +1294,8 @@ shutdown_task (void *cls)
1331 */ 1294 */
1332static void * 1295static void *
1333client_connect_cb (void *cls, 1296client_connect_cb (void *cls,
1334 struct GNUNET_SERVICE_Client *client, 1297 struct GNUNET_SERVICE_Client *client,
1335 struct GNUNET_MQ_Handle *mq) 1298 struct GNUNET_MQ_Handle *mq)
1336{ 1299{
1337 struct AliceServiceSession *s; 1300 struct AliceServiceSession *s;
1338 1301
@@ -1355,8 +1318,8 @@ client_connect_cb (void *cls,
1355 */ 1318 */
1356static void 1319static void
1357client_disconnect_cb (void *cls, 1320client_disconnect_cb (void *cls,
1358 struct GNUNET_SERVICE_Client *client, 1321 struct GNUNET_SERVICE_Client *client,
1359 void *app_cls) 1322 void *app_cls)
1360{ 1323{
1361 struct AliceServiceSession *s = app_cls; 1324 struct AliceServiceSession *s = app_cls;
1362 1325
@@ -1387,17 +1350,13 @@ run (void *cls,
1387 m1+m2 mod n == (S + a) + (S + b) mod n, 1350 m1+m2 mod n == (S + a) + (S + b) mod n,
1388 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 */
1389 my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); 1352 my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3);
1390 gcry_mpi_set_bit (my_offset, 1353 gcry_mpi_set_bit (my_offset, GNUNET_CRYPTO_PAILLIER_BITS / 3);
1391 GNUNET_CRYPTO_PAILLIER_BITS / 3); 1354 GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey);
1392 GNUNET_CRYPTO_paillier_create (&my_pubkey,
1393 &my_privkey);
1394 my_cadet = GNUNET_CADET_connect (cfg); 1355 my_cadet = GNUNET_CADET_connect (cfg);
1395 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1356 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1396 NULL);
1397 if (NULL == my_cadet) 1357 if (NULL == my_cadet)
1398 { 1358 {
1399 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n"));
1400 _("Connect to CADET failed\n"));
1401 GNUNET_SCHEDULER_shutdown (); 1360 GNUNET_SCHEDULER_shutdown ();
1402 return; 1361 return;
1403 } 1362 }
@@ -1407,22 +1366,23 @@ run (void *cls,
1407/** 1366/**
1408 * Define "main" method using service macro. 1367 * Define "main" method using service macro.
1409 */ 1368 */
1410GNUNET_SERVICE_MAIN 1369GNUNET_SERVICE_MAIN (
1411("scalarproduct-alice", 1370 "scalarproduct-alice",
1412 GNUNET_SERVICE_OPTION_NONE, 1371 GNUNET_SERVICE_OPTION_NONE,
1413 &run, 1372 &run,
1414 &client_connect_cb, 1373 &client_connect_cb,
1415 &client_disconnect_cb, 1374 &client_disconnect_cb,
1416 NULL, 1375 NULL,
1417 GNUNET_MQ_hd_var_size (alice_client_message, 1376 GNUNET_MQ_hd_var_size (alice_client_message,
1418 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, 1377 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
1419 struct AliceComputationMessage, 1378 struct AliceComputationMessage,
1420 NULL), 1379 NULL),
1421 GNUNET_MQ_hd_var_size (alice_client_message_multipart, 1380 GNUNET_MQ_hd_var_size (
1422 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, 1381 alice_client_message_multipart,
1423 struct ComputationBobCryptodataMultipartMessage, 1382 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
1424 NULL), 1383 struct ComputationBobCryptodataMultipartMessage,
1425 GNUNET_MQ_handler_end ()); 1384 NULL),
1385 GNUNET_MQ_handler_end ());
1426 1386
1427 1387
1428/* 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 71f74594f..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,15 +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_log (GNUNET_ERROR_TYPE_DEBUG, 716 GNUNET_log (
745 "Suggesting incoming request with accept id %u to listener %p of client %p\n", 717 GNUNET_ERROR_TYPE_DEBUG,
746 op->suggest_id, 718 "Suggesting incoming request with accept id %u to listener %p of client %p\n",
747 listener, 719 op->suggest_id,
748 listener->cs); 720 listener,
721 listener->cs);
749 cmsg->accept_id = htonl (op->suggest_id); 722 cmsg->accept_id = htonl (op->suggest_id);
750 cmsg->peer_id = op->peer; 723 cmsg->peer_id = op->peer;
751 GNUNET_MQ_send (listener->cs->mq, 724 GNUNET_MQ_send (listener->cs->mq, env);
752 env);
753 /* NOTE: GNUNET_CADET_receive_done() will be called in 725 /* NOTE: GNUNET_CADET_receive_done() will be called in
754 #handle_client_accept() */ 726 #handle_client_accept() */
755} 727}
@@ -762,8 +734,7 @@ handle_incoming_msg (void *cls,
762 * @param msg message specifying the change 734 * @param msg message specifying the change
763 */ 735 */
764static void 736static void
765execute_add (struct Set *set, 737execute_add (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
766 const struct GNUNET_SET_ElementMessage *msg)
767{ 738{
768 struct GNUNET_SET_Element el; 739 struct GNUNET_SET_Element el;
769 struct ElementEntry *ee; 740 struct ElementEntry *ee;
@@ -773,10 +744,8 @@ execute_add (struct Set *set,
773 el.size = ntohs (msg->header.size) - sizeof (*msg); 744 el.size = ntohs (msg->header.size) - sizeof (*msg);
774 el.data = &msg[1]; 745 el.data = &msg[1];
775 el.element_type = ntohs (msg->element_type); 746 el.element_type = ntohs (msg->element_type);
776 GNUNET_SET_element_hash (&el, 747 GNUNET_SET_element_hash (&el, &hash);
777 &hash); 748 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash);
778 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements,
779 &hash);
780 if (NULL == ee) 749 if (NULL == ee)
781 { 750 {
782 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -785,9 +754,7 @@ execute_add (struct Set *set,
785 el.size); 754 el.size);
786 ee = GNUNET_malloc (el.size + sizeof (*ee)); 755 ee = GNUNET_malloc (el.size + sizeof (*ee));
787 ee->element.size = el.size; 756 ee->element.size = el.size;
788 GNUNET_memcpy (&ee[1], 757 GNUNET_memcpy (&ee[1], el.data, el.size);
789 el.data,
790 el.size);
791 ee->element.data = &ee[1]; 758 ee->element.data = &ee[1];
792 ee->element.element_type = el.element_type; 759 ee->element.element_type = el.element_type;
793 ee->remote = GNUNET_NO; 760 ee->remote = GNUNET_NO;
@@ -795,10 +762,11 @@ execute_add (struct Set *set,
795 ee->mutations_size = 0; 762 ee->mutations_size = 0;
796 ee->element_hash = hash; 763 ee->element_hash = hash;
797 GNUNET_break (GNUNET_YES == 764 GNUNET_break (GNUNET_YES ==
798 GNUNET_CONTAINER_multihashmap_put (set->content->elements, 765 GNUNET_CONTAINER_multihashmap_put (
799 &ee->element_hash, 766 set->content->elements,
800 ee, 767 &ee->element_hash,
801 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 768 ee,
769 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
802 } 770 }
803 else if (GNUNET_YES == 771 else if (GNUNET_YES ==
804 is_element_of_generation (ee, 772 is_element_of_generation (ee,
@@ -816,16 +784,11 @@ execute_add (struct Set *set,
816 } 784 }
817 785
818 { 786 {
819 struct MutationEvent mut = { 787 struct MutationEvent mut = {.generation = set->current_generation,
820 .generation = set->current_generation, 788 .added = GNUNET_YES};
821 .added = GNUNET_YES 789 GNUNET_array_append (ee->mutations, ee->mutations_size, mut);
822 };
823 GNUNET_array_append (ee->mutations,
824 ee->mutations_size,
825 mut);
826 } 790 }
827 set->vt->add (set->state, 791 set->vt->add (set->state, ee);
828 ee);
829} 792}
830 793
831 794
@@ -836,8 +799,7 @@ execute_add (struct Set *set,
836 * @param msg message specifying the change 799 * @param msg message specifying the change
837 */ 800 */
838static void 801static void
839execute_remove (struct Set *set, 802execute_remove (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
840 const struct GNUNET_SET_ElementMessage *msg)
841{ 803{
842 struct GNUNET_SET_Element el; 804 struct GNUNET_SET_Element el;
843 struct ElementEntry *ee; 805 struct ElementEntry *ee;
@@ -848,8 +810,7 @@ execute_remove (struct Set *set,
848 el.data = &msg[1]; 810 el.data = &msg[1];
849 el.element_type = ntohs (msg->element_type); 811 el.element_type = ntohs (msg->element_type);
850 GNUNET_SET_element_hash (&el, &hash); 812 GNUNET_SET_element_hash (&el, &hash);
851 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, 813 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash);
852 &hash);
853 if (NULL == ee) 814 if (NULL == ee)
854 { 815 {
855 /* Client tried to remove non-existing element. */ 816 /* Client tried to remove non-existing element. */
@@ -858,11 +819,10 @@ execute_remove (struct Set *set,
858 el.size); 819 el.size);
859 return; 820 return;
860 } 821 }
861 if (GNUNET_NO == 822 if (GNUNET_NO == is_element_of_generation (ee,
862 is_element_of_generation (ee, 823 set->current_generation,
863 set->current_generation, 824 set->excluded_generations,
864 set->excluded_generations, 825 set->excluded_generations_size))
865 set->excluded_generations_size))
866 { 826 {
867 /* Client tried to remove element twice */ 827 /* Client tried to remove element twice */
868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 828 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -872,21 +832,16 @@ execute_remove (struct Set *set,
872 } 832 }
873 else 833 else
874 { 834 {
875 struct MutationEvent mut = { 835 struct MutationEvent mut = {.generation = set->current_generation,
876 .generation = set->current_generation, 836 .added = GNUNET_NO};
877 .added = GNUNET_NO
878 };
879 837
880 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
881 "Client removes element of size %u\n", 839 "Client removes element of size %u\n",
882 el.size); 840 el.size);
883 841
884 GNUNET_array_append (ee->mutations, 842 GNUNET_array_append (ee->mutations, ee->mutations_size, mut);
885 ee->mutations_size,
886 mut);
887 } 843 }
888 set->vt->remove (set->state, 844 set->vt->remove (set->state, ee);
889 ee);
890} 845}
891 846
892 847
@@ -897,19 +852,18 @@ execute_remove (struct Set *set,
897 * @param msg specification of what to change 852 * @param msg specification of what to change
898 */ 853 */
899static void 854static void
900execute_mutation (struct Set *set, 855execute_mutation (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
901 const struct GNUNET_SET_ElementMessage *msg)
902{ 856{
903 switch (ntohs (msg->header.type)) 857 switch (ntohs (msg->header.type))
904 { 858 {
905 case GNUNET_MESSAGE_TYPE_SET_ADD: 859 case GNUNET_MESSAGE_TYPE_SET_ADD:
906 execute_add (set, msg); 860 execute_add (set, msg);
907 break; 861 break;
908 case GNUNET_MESSAGE_TYPE_SET_REMOVE: 862 case GNUNET_MESSAGE_TYPE_SET_REMOVE:
909 execute_remove (set, msg); 863 execute_remove (set, msg);
910 break; 864 break;
911 default: 865 default:
912 GNUNET_break (0); 866 GNUNET_break (0);
913 } 867 }
914} 868}
915 869
@@ -935,8 +889,7 @@ execute_delayed_mutations (struct Set *set)
935 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
936 "Executing pending mutation on %p.\n", 890 "Executing pending mutation on %p.\n",
937 pm->set); 891 pm->set);
938 execute_mutation (pm->set, 892 execute_mutation (pm->set, pm->msg);
939 pm->msg);
940 GNUNET_free (pm->msg); 893 GNUNET_free (pm->msg);
941 GNUNET_free (pm); 894 GNUNET_free (pm);
942 } 895 }
@@ -965,15 +918,14 @@ send_client_element (struct Set *set)
965 struct GNUNET_SET_IterResponseMessage *msg; 918 struct GNUNET_SET_IterResponseMessage *msg;
966 919
967 GNUNET_assert (NULL != set->iter); 920 GNUNET_assert (NULL != set->iter);
968 do { 921 do
922 {
969 ret = GNUNET_CONTAINER_multihashmap_iterator_next (set->iter, 923 ret = GNUNET_CONTAINER_multihashmap_iterator_next (set->iter,
970 NULL, 924 NULL,
971 (const void **) &ee); 925 (const void **) &ee);
972 if (GNUNET_NO == ret) 926 if (GNUNET_NO == ret)
973 { 927 {
974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration on %p done.\n", set);
975 "Iteration on %p done.\n",
976 set);
977 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE); 929 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE);
978 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); 930 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
979 set->iter = NULL; 931 set->iter = NULL;
@@ -981,8 +933,7 @@ send_client_element (struct Set *set)
981 GNUNET_assert (set->content->iterator_count > 0); 933 GNUNET_assert (set->content->iterator_count > 0);
982 set->content->iterator_count--; 934 set->content->iterator_count--;
983 execute_delayed_mutations (set); 935 execute_delayed_mutations (set);
984 GNUNET_MQ_send (set->cs->mq, 936 GNUNET_MQ_send (set->cs->mq, ev);
985 ev);
986 return; 937 return;
987 } 938 }
988 GNUNET_assert (NULL != ee); 939 GNUNET_assert (NULL != ee);
@@ -997,13 +948,10 @@ send_client_element (struct Set *set)
997 ev = GNUNET_MQ_msg_extra (msg, 948 ev = GNUNET_MQ_msg_extra (msg,
998 ee->element.size, 949 ee->element.size,
999 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT); 950 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT);
1000 GNUNET_memcpy (&msg[1], 951 GNUNET_memcpy (&msg[1], ee->element.data, ee->element.size);
1001 ee->element.data,
1002 ee->element.size);
1003 msg->element_type = htons (ee->element.element_type); 952 msg->element_type = htons (ee->element.element_type);
1004 msg->iteration_id = htons (set->iteration_id); 953 msg->iteration_id = htons (set->iteration_id);
1005 GNUNET_MQ_send (set->cs->mq, 954 GNUNET_MQ_send (set->cs->mq, ev);
1006 ev);
1007} 955}
1008 956
1009 957
@@ -1017,8 +965,7 @@ send_client_element (struct Set *set)
1017 * @param m message sent by the client 965 * @param m message sent by the client
1018 */ 966 */
1019static void 967static void
1020handle_client_iterate (void *cls, 968handle_client_iterate (void *cls, const struct GNUNET_MessageHeader *m)
1021 const struct GNUNET_MessageHeader *m)
1022{ 969{
1023 struct ClientState *cs = cls; 970 struct ClientState *cs = cls;
1024 struct Set *set; 971 struct Set *set;
@@ -1044,7 +991,8 @@ handle_client_iterate (void *cls,
1044 GNUNET_CONTAINER_multihashmap_size (set->content->elements)); 991 GNUNET_CONTAINER_multihashmap_size (set->content->elements));
1045 GNUNET_SERVICE_client_continue (cs->client); 992 GNUNET_SERVICE_client_continue (cs->client);
1046 set->content->iterator_count++; 993 set->content->iterator_count++;
1047 set->iter = GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements); 994 set->iter =
995 GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements);
1048 set->iter_generation = set->current_generation; 996 set->iter_generation = set->current_generation;
1049 send_client_element (set); 997 send_client_element (set);
1050} 998}
@@ -1059,8 +1007,7 @@ handle_client_iterate (void *cls,
1059 * @param m message sent by the client 1007 * @param m message sent by the client
1060 */ 1008 */
1061static void 1009static void
1062handle_client_create_set (void *cls, 1010handle_client_create_set (void *cls, const struct GNUNET_SET_CreateMessage *msg)
1063 const struct GNUNET_SET_CreateMessage *msg)
1064{ 1011{
1065 struct ClientState *cs = cls; 1012 struct ClientState *cs = cls;
1066 struct Set *set; 1013 struct Set *set;
@@ -1101,8 +1048,7 @@ handle_client_create_set (void *cls,
1101 } 1048 }
1102 set->content = GNUNET_new (struct SetContent); 1049 set->content = GNUNET_new (struct SetContent);
1103 set->content->refcount = 1; 1050 set->content->refcount = 1;
1104 set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, 1051 set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
1105 GNUNET_YES);
1106 set->cs = cs; 1052 set->cs = cs;
1107 cs->set = set; 1053 cs->set = set;
1108 GNUNET_SERVICE_client_continue (cs->client); 1054 GNUNET_SERVICE_client_continue (cs->client);
@@ -1154,22 +1100,17 @@ channel_new_cb (void *cls,
1154 struct Listener *listener = cls; 1100 struct Listener *listener = cls;
1155 struct Operation *op; 1101 struct Operation *op;
1156 1102
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New incoming channel\n");
1158 "New incoming channel\n");
1159 op = GNUNET_new (struct Operation); 1104 op = GNUNET_new (struct Operation);
1160 op->listener = listener; 1105 op->listener = listener;
1161 op->peer = *source; 1106 op->peer = *source;
1162 op->channel = channel; 1107 op->channel = channel;
1163 op->mq = GNUNET_CADET_get_mq (op->channel); 1108 op->mq = GNUNET_CADET_get_mq (op->channel);
1164 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1109 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1165 UINT32_MAX); 1110 op->timeout_task = GNUNET_SCHEDULER_add_delayed (INCOMING_CHANNEL_TIMEOUT,
1166 op->timeout_task 1111 &incoming_timeout_cb,
1167 = GNUNET_SCHEDULER_add_delayed (INCOMING_CHANNEL_TIMEOUT, 1112 op);
1168 &incoming_timeout_cb, 1113 GNUNET_CONTAINER_DLL_insert (listener->op_head, listener->op_tail, op);
1169 op);
1170 GNUNET_CONTAINER_DLL_insert (listener->op_head,
1171 listener->op_tail,
1172 op);
1173 return op; 1114 return op;
1174} 1115}
1175 1116
@@ -1191,8 +1132,7 @@ channel_new_cb (void *cls,
1191 * @param channel connection to the other end (henceforth invalid) 1132 * @param channel connection to the other end (henceforth invalid)
1192 */ 1133 */
1193static void 1134static void
1194channel_end_cb (void *channel_ctx, 1135channel_end_cb (void *channel_ctx, const struct GNUNET_CADET_Channel *channel)
1195 const struct GNUNET_CADET_Channel *channel)
1196{ 1136{
1197 struct Operation *op = channel_ctx; 1137 struct Operation *op = channel_ctx;
1198 1138
@@ -1211,8 +1151,7 @@ _GSS_operation_destroy2 (struct Operation *op)
1211{ 1151{
1212 struct GNUNET_CADET_Channel *channel; 1152 struct GNUNET_CADET_Channel *channel;
1213 1153
1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n");
1215 "channel_end_cb called\n");
1216 if (NULL != (channel = op->channel)) 1155 if (NULL != (channel = op->channel))
1217 { 1156 {
1218 /* This will free op; called conditionally as this helper function 1157 /* This will free op; called conditionally as this helper function
@@ -1228,8 +1167,7 @@ _GSS_operation_destroy2 (struct Operation *op)
1228 if (NULL != op->set) 1167 if (NULL != op->set)
1229 op->set->vt->channel_death (op); 1168 op->set->vt->channel_death (op);
1230 else 1169 else
1231 _GSS_operation_destroy (op, 1170 _GSS_operation_destroy (op, GNUNET_YES);
1232 GNUNET_YES);
1233 GNUNET_free (op); 1171 GNUNET_free (op);
1234} 1172}
1235 1173
@@ -1264,77 +1202,75 @@ channel_window_cb (void *cls,
1264 * @param msg message sent by the client 1202 * @param msg message sent by the client
1265 */ 1203 */
1266static void 1204static void
1267handle_client_listen (void *cls, 1205handle_client_listen (void *cls, const struct GNUNET_SET_ListenMessage *msg)
1268 const struct GNUNET_SET_ListenMessage *msg)
1269{ 1206{
1270 struct ClientState *cs = cls; 1207 struct ClientState *cs = cls;
1271 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1208 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1272 GNUNET_MQ_hd_var_size (incoming_msg, 1209 {GNUNET_MQ_hd_var_size (incoming_msg,
1273 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 1210 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
1274 struct OperationRequestMessage, 1211 struct OperationRequestMessage,
1275 NULL), 1212 NULL),
1276 GNUNET_MQ_hd_var_size (union_p2p_ibf, 1213 GNUNET_MQ_hd_var_size (union_p2p_ibf,
1277 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 1214 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF,
1278 struct IBFMessage, 1215 struct IBFMessage,
1279 NULL), 1216 NULL),
1280 GNUNET_MQ_hd_var_size (union_p2p_elements, 1217 GNUNET_MQ_hd_var_size (union_p2p_elements,
1281 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 1218 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS,
1282 struct GNUNET_SET_ElementMessage, 1219 struct GNUNET_SET_ElementMessage,
1283 NULL), 1220 NULL),
1284 GNUNET_MQ_hd_var_size (union_p2p_offer, 1221 GNUNET_MQ_hd_var_size (union_p2p_offer,
1285 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, 1222 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER,
1286 struct GNUNET_MessageHeader, 1223 struct GNUNET_MessageHeader,
1287 NULL), 1224 NULL),
1288 GNUNET_MQ_hd_var_size (union_p2p_inquiry, 1225 GNUNET_MQ_hd_var_size (union_p2p_inquiry,
1289 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, 1226 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY,
1290 struct InquiryMessage, 1227 struct InquiryMessage,
1291 NULL), 1228 NULL),
1292 GNUNET_MQ_hd_var_size (union_p2p_demand, 1229 GNUNET_MQ_hd_var_size (union_p2p_demand,
1293 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, 1230 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND,
1294 struct GNUNET_MessageHeader, 1231 struct GNUNET_MessageHeader,
1295 NULL), 1232 NULL),
1296 GNUNET_MQ_hd_fixed_size (union_p2p_done, 1233 GNUNET_MQ_hd_fixed_size (union_p2p_done,
1297 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, 1234 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE,
1298 struct GNUNET_MessageHeader, 1235 struct GNUNET_MessageHeader,
1299 NULL), 1236 NULL),
1300 GNUNET_MQ_hd_fixed_size (union_p2p_over, 1237 GNUNET_MQ_hd_fixed_size (union_p2p_over,
1301 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, 1238 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER,
1302 struct GNUNET_MessageHeader, 1239 struct GNUNET_MessageHeader,
1303 NULL), 1240 NULL),
1304 GNUNET_MQ_hd_fixed_size (union_p2p_full_done, 1241 GNUNET_MQ_hd_fixed_size (union_p2p_full_done,
1305 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, 1242 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE,
1306 struct GNUNET_MessageHeader, 1243 struct GNUNET_MessageHeader,
1307 NULL), 1244 NULL),
1308 GNUNET_MQ_hd_fixed_size (union_p2p_request_full, 1245 GNUNET_MQ_hd_fixed_size (union_p2p_request_full,
1309 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, 1246 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1310 struct GNUNET_MessageHeader, 1247 struct GNUNET_MessageHeader,
1311 NULL), 1248 NULL),
1312 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, 1249 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1313 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, 1250 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE,
1314 struct StrataEstimatorMessage, 1251 struct StrataEstimatorMessage,
1315 NULL), 1252 NULL),
1316 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, 1253 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1317 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, 1254 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC,
1318 struct StrataEstimatorMessage, 1255 struct StrataEstimatorMessage,
1319 NULL), 1256 NULL),
1320 GNUNET_MQ_hd_var_size (union_p2p_full_element, 1257 GNUNET_MQ_hd_var_size (union_p2p_full_element,
1321 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, 1258 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT,
1322 struct GNUNET_SET_ElementMessage, 1259 struct GNUNET_SET_ElementMessage,
1323 NULL), 1260 NULL),
1324 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, 1261 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info,
1325 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, 1262 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO,
1326 struct IntersectionElementInfoMessage, 1263 struct IntersectionElementInfoMessage,
1327 NULL), 1264 NULL),
1328 GNUNET_MQ_hd_var_size (intersection_p2p_bf, 1265 GNUNET_MQ_hd_var_size (intersection_p2p_bf,
1329 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, 1266 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF,
1330 struct BFMessage, 1267 struct BFMessage,
1331 NULL), 1268 NULL),
1332 GNUNET_MQ_hd_fixed_size (intersection_p2p_done, 1269 GNUNET_MQ_hd_fixed_size (intersection_p2p_done,
1333 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, 1270 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE,
1334 struct IntersectionDoneMessage, 1271 struct IntersectionDoneMessage,
1335 NULL), 1272 NULL),
1336 GNUNET_MQ_handler_end () 1273 GNUNET_MQ_handler_end ()};
1337 };
1338 struct Listener *listener; 1274 struct Listener *listener;
1339 1275
1340 if (NULL != cs->listener) 1276 if (NULL != cs->listener)
@@ -1349,21 +1285,18 @@ handle_client_listen (void *cls,
1349 cs->listener = listener; 1285 cs->listener = listener;
1350 listener->app_id = msg->app_id; 1286 listener->app_id = msg->app_id;
1351 listener->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation); 1287 listener->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation);
1352 GNUNET_CONTAINER_DLL_insert (listener_head, 1288 GNUNET_CONTAINER_DLL_insert (listener_head, listener_tail, listener);
1353 listener_tail,
1354 listener);
1355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1356 "New listener created (op %u, port %s)\n", 1290 "New listener created (op %u, port %s)\n",
1357 listener->operation, 1291 listener->operation,
1358 GNUNET_h2s (&listener->app_id)); 1292 GNUNET_h2s (&listener->app_id));
1359 listener->open_port 1293 listener->open_port = GNUNET_CADET_open_port (cadet,
1360 = GNUNET_CADET_open_port (cadet, 1294 &msg->app_id,
1361 &msg->app_id, 1295 &channel_new_cb,
1362 &channel_new_cb, 1296 listener,
1363 listener, 1297 &channel_window_cb,
1364 &channel_window_cb, 1298 &channel_end_cb,
1365 &channel_end_cb, 1299 cadet_handlers);
1366 cadet_handlers);
1367 GNUNET_SERVICE_client_continue (cs->client); 1300 GNUNET_SERVICE_client_continue (cs->client);
1368} 1301}
1369 1302
@@ -1376,8 +1309,7 @@ handle_client_listen (void *cls,
1376 * @param msg message sent by the client 1309 * @param msg message sent by the client
1377 */ 1310 */
1378static void 1311static void
1379handle_client_reject (void *cls, 1312handle_client_reject (void *cls, const struct GNUNET_SET_RejectMessage *msg)
1380 const struct GNUNET_SET_RejectMessage *msg)
1381{ 1313{
1382 struct ClientState *cs = cls; 1314 struct ClientState *cs = cls;
1383 struct Operation *op; 1315 struct Operation *op;
@@ -1409,8 +1341,7 @@ handle_client_reject (void *cls,
1409 * @param msg message sent by the client 1341 * @param msg message sent by the client
1410 */ 1342 */
1411static int 1343static int
1412check_client_mutation (void *cls, 1344check_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg)
1413 const struct GNUNET_SET_ElementMessage *msg)
1414{ 1345{
1415 /* NOTE: Technically, we should probably check with the 1346 /* NOTE: Technically, we should probably check with the
1416 block library whether the element we are given is well-formed */ 1347 block library whether the element we are given is well-formed */
@@ -1425,8 +1356,7 @@ check_client_mutation (void *cls,
1425 * @param msg message sent by the client 1356 * @param msg message sent by the client
1426 */ 1357 */
1427static void 1358static void
1428handle_client_mutation (void *cls, 1359handle_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg)
1429 const struct GNUNET_SET_ElementMessage *msg)
1430{ 1360{
1431 struct ClientState *cs = cls; 1361 struct ClientState *cs = cls;
1432 struct Set *set; 1362 struct Set *set;
@@ -1444,20 +1374,18 @@ handle_client_mutation (void *cls,
1444 { 1374 {
1445 struct PendingMutation *pm; 1375 struct PendingMutation *pm;
1446 1376
1447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling mutation on set\n");
1448 "Scheduling mutation on set\n");
1449 pm = GNUNET_new (struct PendingMutation); 1378 pm = GNUNET_new (struct PendingMutation);
1450 pm->msg = (struct GNUNET_SET_ElementMessage *) GNUNET_copy_message (&msg->header); 1379 pm->msg =
1380 (struct GNUNET_SET_ElementMessage *) GNUNET_copy_message (&msg->header);
1451 pm->set = set; 1381 pm->set = set;
1452 GNUNET_CONTAINER_DLL_insert_tail (set->content->pending_mutations_head, 1382 GNUNET_CONTAINER_DLL_insert_tail (set->content->pending_mutations_head,
1453 set->content->pending_mutations_tail, 1383 set->content->pending_mutations_tail,
1454 pm); 1384 pm);
1455 return; 1385 return;
1456 } 1386 }
1457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing mutation on set\n");
1458 "Executing mutation on set\n"); 1388 execute_mutation (set, msg);
1459 execute_mutation (set,
1460 msg);
1461} 1389}
1462 1390
1463 1391
@@ -1501,8 +1429,7 @@ advance_generation (struct Set *set)
1501 * @return #GNUNET_OK if the message is well-formed 1429 * @return #GNUNET_OK if the message is well-formed
1502 */ 1430 */
1503static int 1431static int
1504check_client_evaluate (void *cls, 1432check_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1505 const struct GNUNET_SET_EvaluateMessage *msg)
1506{ 1433{
1507 /* FIXME: suboptimal, even if the context below could be NULL, 1434 /* FIXME: suboptimal, even if the context below could be NULL,
1508 there are malformed messages this does not check for... */ 1435 there are malformed messages this does not check for... */
@@ -1519,78 +1446,76 @@ check_client_evaluate (void *cls,
1519 * @param msg message sent by the client 1446 * @param msg message sent by the client
1520 */ 1447 */
1521static void 1448static void
1522handle_client_evaluate (void *cls, 1449handle_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1523 const struct GNUNET_SET_EvaluateMessage *msg)
1524{ 1450{
1525 struct ClientState *cs = cls; 1451 struct ClientState *cs = cls;
1526 struct Operation *op = GNUNET_new (struct Operation); 1452 struct Operation *op = GNUNET_new (struct Operation);
1527 const struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1453 const struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1528 GNUNET_MQ_hd_var_size (incoming_msg, 1454 {GNUNET_MQ_hd_var_size (incoming_msg,
1529 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 1455 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
1530 struct OperationRequestMessage, 1456 struct OperationRequestMessage,
1531 op), 1457 op),
1532 GNUNET_MQ_hd_var_size (union_p2p_ibf, 1458 GNUNET_MQ_hd_var_size (union_p2p_ibf,
1533 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 1459 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF,
1534 struct IBFMessage, 1460 struct IBFMessage,
1535 op), 1461 op),
1536 GNUNET_MQ_hd_var_size (union_p2p_elements, 1462 GNUNET_MQ_hd_var_size (union_p2p_elements,
1537 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 1463 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS,
1538 struct GNUNET_SET_ElementMessage, 1464 struct GNUNET_SET_ElementMessage,
1539 op), 1465 op),
1540 GNUNET_MQ_hd_var_size (union_p2p_offer, 1466 GNUNET_MQ_hd_var_size (union_p2p_offer,
1541 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, 1467 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER,
1542 struct GNUNET_MessageHeader, 1468 struct GNUNET_MessageHeader,
1543 op), 1469 op),
1544 GNUNET_MQ_hd_var_size (union_p2p_inquiry, 1470 GNUNET_MQ_hd_var_size (union_p2p_inquiry,
1545 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, 1471 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY,
1546 struct InquiryMessage, 1472 struct InquiryMessage,
1547 op), 1473 op),
1548 GNUNET_MQ_hd_var_size (union_p2p_demand, 1474 GNUNET_MQ_hd_var_size (union_p2p_demand,
1549 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, 1475 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND,
1550 struct GNUNET_MessageHeader, 1476 struct GNUNET_MessageHeader,
1551 op), 1477 op),
1552 GNUNET_MQ_hd_fixed_size (union_p2p_done, 1478 GNUNET_MQ_hd_fixed_size (union_p2p_done,
1553 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, 1479 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE,
1554 struct GNUNET_MessageHeader, 1480 struct GNUNET_MessageHeader,
1555 op), 1481 op),
1556 GNUNET_MQ_hd_fixed_size (union_p2p_over, 1482 GNUNET_MQ_hd_fixed_size (union_p2p_over,
1557 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, 1483 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER,
1558 struct GNUNET_MessageHeader, 1484 struct GNUNET_MessageHeader,
1559 op), 1485 op),
1560 GNUNET_MQ_hd_fixed_size (union_p2p_full_done, 1486 GNUNET_MQ_hd_fixed_size (union_p2p_full_done,
1561 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, 1487 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE,
1562 struct GNUNET_MessageHeader, 1488 struct GNUNET_MessageHeader,
1563 op), 1489 op),
1564 GNUNET_MQ_hd_fixed_size (union_p2p_request_full, 1490 GNUNET_MQ_hd_fixed_size (union_p2p_request_full,
1565 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, 1491 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1566 struct GNUNET_MessageHeader, 1492 struct GNUNET_MessageHeader,
1567 op), 1493 op),
1568 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, 1494 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1569 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, 1495 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE,
1570 struct StrataEstimatorMessage, 1496 struct StrataEstimatorMessage,
1571 op), 1497 op),
1572 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, 1498 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1573 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, 1499 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC,
1574 struct StrataEstimatorMessage, 1500 struct StrataEstimatorMessage,
1575 op), 1501 op),
1576 GNUNET_MQ_hd_var_size (union_p2p_full_element, 1502 GNUNET_MQ_hd_var_size (union_p2p_full_element,
1577 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, 1503 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT,
1578 struct GNUNET_SET_ElementMessage, 1504 struct GNUNET_SET_ElementMessage,
1579 op), 1505 op),
1580 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, 1506 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info,
1581 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, 1507 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO,
1582 struct IntersectionElementInfoMessage, 1508 struct IntersectionElementInfoMessage,
1583 op), 1509 op),
1584 GNUNET_MQ_hd_var_size (intersection_p2p_bf, 1510 GNUNET_MQ_hd_var_size (intersection_p2p_bf,
1585 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, 1511 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF,
1586 struct BFMessage, 1512 struct BFMessage,
1587 op), 1513 op),
1588 GNUNET_MQ_hd_fixed_size (intersection_p2p_done, 1514 GNUNET_MQ_hd_fixed_size (intersection_p2p_done,
1589 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, 1515 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE,
1590 struct IntersectionDoneMessage, 1516 struct IntersectionDoneMessage,
1591 op), 1517 op),
1592 GNUNET_MQ_handler_end () 1518 GNUNET_MQ_handler_end ()};
1593 };
1594 struct Set *set; 1519 struct Set *set;
1595 const struct GNUNET_MessageHeader *context; 1520 const struct GNUNET_MessageHeader *context;
1596 1521
@@ -1601,8 +1526,7 @@ handle_client_evaluate (void *cls,
1601 GNUNET_SERVICE_client_drop (cs->client); 1526 GNUNET_SERVICE_client_drop (cs->client);
1602 return; 1527 return;
1603 } 1528 }
1604 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1529 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1605 UINT32_MAX);
1606 op->peer = msg->target_peer; 1530 op->peer = msg->target_peer;
1607 op->result_mode = ntohl (msg->result_mode); 1531 op->result_mode = ntohl (msg->result_mode);
1608 op->client_request_id = ntohl (msg->request_id); 1532 op->client_request_id = ntohl (msg->request_id);
@@ -1617,9 +1541,7 @@ handle_client_evaluate (void *cls,
1617 op->set = set; 1541 op->set = set;
1618 op->generation_created = set->current_generation; 1542 op->generation_created = set->current_generation;
1619 advance_generation (set); 1543 advance_generation (set);
1620 GNUNET_CONTAINER_DLL_insert (set->ops_head, 1544 GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op);
1621 set->ops_tail,
1622 op);
1623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1624 "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",
1625 GNUNET_h2s (&msg->app_id), 1547 GNUNET_h2s (&msg->app_id),
@@ -1628,13 +1550,11 @@ handle_client_evaluate (void *cls,
1628 op, 1550 op,
1629 &msg->target_peer, 1551 &msg->target_peer,
1630 &msg->app_id, 1552 &msg->app_id,
1631 GNUNET_CADET_OPTION_RELIABLE,
1632 &channel_window_cb, 1553 &channel_window_cb,
1633 &channel_end_cb, 1554 &channel_end_cb,
1634 cadet_handlers); 1555 cadet_handlers);
1635 op->mq = GNUNET_CADET_get_mq (op->channel); 1556 op->mq = GNUNET_CADET_get_mq (op->channel);
1636 op->state = set->vt->evaluate (op, 1557 op->state = set->vt->evaluate (op, context);
1637 context);
1638 if (NULL == op->state) 1558 if (NULL == op->state)
1639 { 1559 {
1640 GNUNET_break (0); 1560 GNUNET_break (0);
@@ -1654,8 +1574,7 @@ handle_client_evaluate (void *cls,
1654 * @param ack the message 1574 * @param ack the message
1655 */ 1575 */
1656static void 1576static void
1657handle_client_iter_ack (void *cls, 1577handle_client_iter_ack (void *cls, const struct GNUNET_SET_IterAckMessage *ack)
1658 const struct GNUNET_SET_IterAckMessage *ack)
1659{ 1578{
1660 struct ClientState *cs = cls; 1579 struct ClientState *cs = cls;
1661 struct Set *set; 1580 struct Set *set;
@@ -1717,14 +1636,10 @@ handle_client_copy_lazy_prepare (void *cls,
1717 cr = GNUNET_new (struct LazyCopyRequest); 1636 cr = GNUNET_new (struct LazyCopyRequest);
1718 cr->cookie = ++lazy_copy_cookie; 1637 cr->cookie = ++lazy_copy_cookie;
1719 cr->source_set = set; 1638 cr->source_set = set;
1720 GNUNET_CONTAINER_DLL_insert (lazy_copy_head, 1639 GNUNET_CONTAINER_DLL_insert (lazy_copy_head, lazy_copy_tail, cr);
1721 lazy_copy_tail, 1640 ev = GNUNET_MQ_msg (resp_msg, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE);
1722 cr);
1723 ev = GNUNET_MQ_msg (resp_msg,
1724 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE);
1725 resp_msg->cookie = cr->cookie; 1641 resp_msg->cookie = cr->cookie;
1726 GNUNET_MQ_send (set->cs->mq, 1642 GNUNET_MQ_send (set->cs->mq, ev);
1727 ev);
1728 GNUNET_SERVICE_client_continue (cs->client); 1643 GNUNET_SERVICE_client_continue (cs->client);
1729} 1644}
1730 1645
@@ -1736,8 +1651,9 @@ handle_client_copy_lazy_prepare (void *cls,
1736 * @param msg the message 1651 * @param msg the message
1737 */ 1652 */
1738static void 1653static void
1739handle_client_copy_lazy_connect (void *cls, 1654handle_client_copy_lazy_connect (
1740 const struct GNUNET_SET_CopyLazyConnectMessage *msg) 1655 void *cls,
1656 const struct GNUNET_SET_CopyLazyConnectMessage *msg)
1741{ 1657{
1742 struct ClientState *cs = cls; 1658 struct ClientState *cs = cls;
1743 struct LazyCopyRequest *cr; 1659 struct LazyCopyRequest *cr;
@@ -1767,9 +1683,7 @@ handle_client_copy_lazy_connect (void *cls,
1767 GNUNET_SERVICE_client_drop (cs->client); 1683 GNUNET_SERVICE_client_drop (cs->client);
1768 return; 1684 return;
1769 } 1685 }
1770 GNUNET_CONTAINER_DLL_remove (lazy_copy_head, 1686 GNUNET_CONTAINER_DLL_remove (lazy_copy_head, lazy_copy_tail, cr);
1771 lazy_copy_tail,
1772 cr);
1773 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1774 "Client %p requested use of lazy copy\n", 1688 "Client %p requested use of lazy copy\n",
1775 cs); 1689 cs);
@@ -1804,9 +1718,10 @@ handle_client_copy_lazy_connect (void *cls,
1804 1718
1805 set->current_generation = cr->source_set->current_generation; 1719 set->current_generation = cr->source_set->current_generation;
1806 set->excluded_generations_size = cr->source_set->excluded_generations_size; 1720 set->excluded_generations_size = cr->source_set->excluded_generations_size;
1807 set->excluded_generations 1721 set->excluded_generations =
1808 = GNUNET_memdup (cr->source_set->excluded_generations, 1722 GNUNET_memdup (cr->source_set->excluded_generations,
1809 set->excluded_generations_size * sizeof (struct GenerationRange)); 1723 set->excluded_generations_size *
1724 sizeof (struct GenerationRange));
1810 1725
1811 /* 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
1812 of the cloned set and the source set are independent. */ 1727 of the cloned set and the source set are independent. */
@@ -1825,8 +1740,7 @@ handle_client_copy_lazy_connect (void *cls,
1825 * @param msg the message 1740 * @param msg the message
1826 */ 1741 */
1827static void 1742static void
1828handle_client_cancel (void *cls, 1743handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg)
1829 const struct GNUNET_SET_CancelMessage *msg)
1830{ 1744{
1831 struct ClientState *cs = cls; 1745 struct ClientState *cs = cls;
1832 struct Set *set; 1746 struct Set *set;
@@ -1865,8 +1779,7 @@ handle_client_cancel (void *cls,
1865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1866 "Client requested cancel for op %u\n", 1780 "Client requested cancel for op %u\n",
1867 (uint32_t) ntohl (msg->request_id)); 1781 (uint32_t) ntohl (msg->request_id));
1868 _GSS_operation_destroy (op, 1782 _GSS_operation_destroy (op, GNUNET_YES);
1869 GNUNET_YES);
1870 } 1783 }
1871 GNUNET_SERVICE_client_continue (cs->client); 1784 GNUNET_SERVICE_client_continue (cs->client);
1872} 1785}
@@ -1881,8 +1794,7 @@ handle_client_cancel (void *cls,
1881 * @param msg the message 1794 * @param msg the message
1882 */ 1795 */
1883static void 1796static void
1884handle_client_accept (void *cls, 1797handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg)
1885 const struct GNUNET_SET_AcceptMessage *msg)
1886{ 1798{
1887 struct ClientState *cs = cls; 1799 struct ClientState *cs = cls;
1888 struct Set *set; 1800 struct Set *set;
@@ -1903,17 +1815,16 @@ handle_client_accept (void *cls,
1903 { 1815 {
1904 /* 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
1905 * have been destroyed when the partner peer disconnected. */ 1817 * have been destroyed when the partner peer disconnected. */
1906 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1818 GNUNET_log (
1907 "Client %p accepted request %u of listener %p that is no longer active\n", 1819 GNUNET_ERROR_TYPE_INFO,
1908 cs, 1820 "Client %p accepted request %u of listener %p that is no longer active\n",
1909 ntohl (msg->accept_reject_id), 1821 cs,
1910 cs->listener); 1822 ntohl (msg->accept_reject_id),
1911 ev = GNUNET_MQ_msg (result_message, 1823 cs->listener);
1912 GNUNET_MESSAGE_TYPE_SET_RESULT); 1824 ev = GNUNET_MQ_msg (result_message, GNUNET_MESSAGE_TYPE_SET_RESULT);
1913 result_message->request_id = msg->request_id; 1825 result_message->request_id = msg->request_id;
1914 result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE); 1826 result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE);
1915 GNUNET_MQ_send (set->cs->mq, 1827 GNUNET_MQ_send (set->cs->mq, ev);
1916 ev);
1917 GNUNET_SERVICE_client_continue (cs->client); 1828 GNUNET_SERVICE_client_continue (cs->client);
1918 return; 1829 return;
1919 } 1830 }
@@ -1922,13 +1833,9 @@ handle_client_accept (void *cls,
1922 (uint32_t) ntohl (msg->accept_reject_id)); 1833 (uint32_t) ntohl (msg->accept_reject_id));
1923 listener = op->listener; 1834 listener = op->listener;
1924 op->listener = NULL; 1835 op->listener = NULL;
1925 GNUNET_CONTAINER_DLL_remove (listener->op_head, 1836 GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op);
1926 listener->op_tail,
1927 op);
1928 op->set = set; 1837 op->set = set;
1929 GNUNET_CONTAINER_DLL_insert (set->ops_head, 1838 GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op);
1930 set->ops_tail,
1931 op);
1932 op->client_request_id = ntohl (msg->request_id); 1839 op->client_request_id = ntohl (msg->request_id);
1933 op->result_mode = ntohl (msg->result_mode); 1840 op->result_mode = ntohl (msg->result_mode);
1934 op->byzantine = msg->byzantine; 1841 op->byzantine = msg->byzantine;
@@ -1974,10 +1881,8 @@ shutdown_task (void *cls)
1974 cadet = NULL; 1881 cadet = NULL;
1975 } 1882 }
1976 } 1883 }
1977 GNUNET_STATISTICS_destroy (_GSS_statistics, 1884 GNUNET_STATISTICS_destroy (_GSS_statistics, GNUNET_YES);
1978 GNUNET_YES); 1885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n");
1979 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1980 "handled shutdown request\n");
1981} 1886}
1982 1887
1983 1888
@@ -1997,15 +1902,13 @@ run (void *cls,
1997 /* FIXME: need to modify SERVICE (!) API to allow 1902 /* FIXME: need to modify SERVICE (!) API to allow
1998 us to run a shutdown task *after* clients were 1903 us to run a shutdown task *after* clients were
1999 forcefully disconnected! */ 1904 forcefully disconnected! */
2000 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1905 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
2001 NULL); 1906 _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg);
2002 _GSS_statistics = GNUNET_STATISTICS_create ("set",
2003 cfg);
2004 cadet = GNUNET_CADET_connect (cfg); 1907 cadet = GNUNET_CADET_connect (cfg);
2005 if (NULL == cadet) 1908 if (NULL == cadet)
2006 { 1909 {
2007 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1910 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2008 _("Could not connect to CADET service\n")); 1911 _ ("Could not connect to CADET service\n"));
2009 GNUNET_SCHEDULER_shutdown (); 1912 GNUNET_SCHEDULER_shutdown ();
2010 return; 1913 return;
2011 } 1914 }
@@ -2015,62 +1918,62 @@ run (void *cls,
2015/** 1918/**
2016 * Define "main" method using service macro. 1919 * Define "main" method using service macro.
2017 */ 1920 */
2018GNUNET_SERVICE_MAIN 1921GNUNET_SERVICE_MAIN (
2019("set", 1922 "set",
2020 GNUNET_SERVICE_OPTION_NONE, 1923 GNUNET_SERVICE_OPTION_NONE,
2021 &run, 1924 &run,
2022 &client_connect_cb, 1925 &client_connect_cb,
2023 &client_disconnect_cb, 1926 &client_disconnect_cb,
2024 NULL, 1927 NULL,
2025 GNUNET_MQ_hd_fixed_size (client_accept, 1928 GNUNET_MQ_hd_fixed_size (client_accept,
2026 GNUNET_MESSAGE_TYPE_SET_ACCEPT, 1929 GNUNET_MESSAGE_TYPE_SET_ACCEPT,
2027 struct GNUNET_SET_AcceptMessage, 1930 struct GNUNET_SET_AcceptMessage,
2028 NULL), 1931 NULL),
2029 GNUNET_MQ_hd_fixed_size (client_iter_ack, 1932 GNUNET_MQ_hd_fixed_size (client_iter_ack,
2030 GNUNET_MESSAGE_TYPE_SET_ITER_ACK, 1933 GNUNET_MESSAGE_TYPE_SET_ITER_ACK,
2031 struct GNUNET_SET_IterAckMessage, 1934 struct GNUNET_SET_IterAckMessage,
2032 NULL), 1935 NULL),
2033 GNUNET_MQ_hd_var_size (client_mutation, 1936 GNUNET_MQ_hd_var_size (client_mutation,
2034 GNUNET_MESSAGE_TYPE_SET_ADD, 1937 GNUNET_MESSAGE_TYPE_SET_ADD,
2035 struct GNUNET_SET_ElementMessage, 1938 struct GNUNET_SET_ElementMessage,
2036 NULL), 1939 NULL),
2037 GNUNET_MQ_hd_fixed_size (client_create_set, 1940 GNUNET_MQ_hd_fixed_size (client_create_set,
2038 GNUNET_MESSAGE_TYPE_SET_CREATE, 1941 GNUNET_MESSAGE_TYPE_SET_CREATE,
2039 struct GNUNET_SET_CreateMessage, 1942 struct GNUNET_SET_CreateMessage,
2040 NULL), 1943 NULL),
2041 GNUNET_MQ_hd_fixed_size (client_iterate, 1944 GNUNET_MQ_hd_fixed_size (client_iterate,
2042 GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST, 1945 GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST,
2043 struct GNUNET_MessageHeader, 1946 struct GNUNET_MessageHeader,
2044 NULL), 1947 NULL),
2045 GNUNET_MQ_hd_var_size (client_evaluate, 1948 GNUNET_MQ_hd_var_size (client_evaluate,
2046 GNUNET_MESSAGE_TYPE_SET_EVALUATE, 1949 GNUNET_MESSAGE_TYPE_SET_EVALUATE,
2047 struct GNUNET_SET_EvaluateMessage, 1950 struct GNUNET_SET_EvaluateMessage,
2048 NULL), 1951 NULL),
2049 GNUNET_MQ_hd_fixed_size (client_listen, 1952 GNUNET_MQ_hd_fixed_size (client_listen,
2050 GNUNET_MESSAGE_TYPE_SET_LISTEN, 1953 GNUNET_MESSAGE_TYPE_SET_LISTEN,
2051 struct GNUNET_SET_ListenMessage, 1954 struct GNUNET_SET_ListenMessage,
2052 NULL), 1955 NULL),
2053 GNUNET_MQ_hd_fixed_size (client_reject, 1956 GNUNET_MQ_hd_fixed_size (client_reject,
2054 GNUNET_MESSAGE_TYPE_SET_REJECT, 1957 GNUNET_MESSAGE_TYPE_SET_REJECT,
2055 struct GNUNET_SET_RejectMessage, 1958 struct GNUNET_SET_RejectMessage,
2056 NULL), 1959 NULL),
2057 GNUNET_MQ_hd_var_size (client_mutation, 1960 GNUNET_MQ_hd_var_size (client_mutation,
2058 GNUNET_MESSAGE_TYPE_SET_REMOVE, 1961 GNUNET_MESSAGE_TYPE_SET_REMOVE,
2059 struct GNUNET_SET_ElementMessage, 1962 struct GNUNET_SET_ElementMessage,
2060 NULL), 1963 NULL),
2061 GNUNET_MQ_hd_fixed_size (client_cancel, 1964 GNUNET_MQ_hd_fixed_size (client_cancel,
2062 GNUNET_MESSAGE_TYPE_SET_CANCEL, 1965 GNUNET_MESSAGE_TYPE_SET_CANCEL,
2063 struct GNUNET_SET_CancelMessage, 1966 struct GNUNET_SET_CancelMessage,
2064 NULL), 1967 NULL),
2065 GNUNET_MQ_hd_fixed_size (client_copy_lazy_prepare, 1968 GNUNET_MQ_hd_fixed_size (client_copy_lazy_prepare,
2066 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE, 1969 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE,
2067 struct GNUNET_MessageHeader, 1970 struct GNUNET_MessageHeader,
2068 NULL), 1971 NULL),
2069 GNUNET_MQ_hd_fixed_size (client_copy_lazy_connect, 1972 GNUNET_MQ_hd_fixed_size (client_copy_lazy_connect,
2070 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT, 1973 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT,
2071 struct GNUNET_SET_CopyLazyConnectMessage, 1974 struct GNUNET_SET_CopyLazyConnectMessage,
2072 NULL), 1975 NULL),
2073 GNUNET_MQ_handler_end ()); 1976 GNUNET_MQ_handler_end ());
2074 1977
2075 1978
2076/* 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 260bafc60..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,23 +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_send (mq, 576 GNUNET_MQ_env_set_options (env,
593 env); 577 GNUNET_MQ_PRIO_BEST_EFFORT |
578 GNUNET_MQ_PREF_OUT_OF_ORDER);
579 GNUNET_MQ_send (mq, env);
594 if (GNUNET_MQ_get_length (mq) > MAX_MESSAGE_QUEUE_SIZE) 580 if (GNUNET_MQ_get_length (mq) > MAX_MESSAGE_QUEUE_SIZE)
595 { 581 {
596 env = GNUNET_MQ_unsent_head (mq); 582 env = GNUNET_MQ_unsent_head (mq);
597 GNUNET_assert (NULL != env); 583 GNUNET_assert (NULL != env);
598 GNUNET_STATISTICS_update (stats, 584 GNUNET_STATISTICS_update (stats,
599 gettext_noop ("# Messages dropped in cadet queue (overflow)"), 585 gettext_noop (
600 1, 586 "# Messages dropped in cadet queue (overflow)"),
601 GNUNET_NO); 587 1,
588 GNUNET_NO);
602 GNUNET_MQ_discard (env); 589 GNUNET_MQ_discard (env);
603 } 590 }
604} 591}
@@ -621,7 +608,8 @@ print_channel_destination (const struct DestinationEntry *de)
621 sizeof (dest), 608 sizeof (dest),
622 "HS: %s-%s", 609 "HS: %s-%s",
623 GNUNET_i2s (&de->details.service_destination.target), 610 GNUNET_i2s (&de->details.service_destination.target),
624 GNUNET_h2s (&de->details.service_destination.service_descriptor)); 611 GNUNET_h2s (
612 &de->details.service_destination.service_descriptor));
625 } 613 }
626 else 614 else
627 { 615 {
@@ -642,14 +630,14 @@ print_channel_destination (const struct DestinationEntry *de)
642 * @param channel connection to the other end (henceforth invalid) 630 * @param channel connection to the other end (henceforth invalid)
643 */ 631 */
644static void 632static void
645channel_cleaner (void *cls, 633channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel)
646 const struct GNUNET_CADET_Channel *channel)
647{ 634{
648 struct ChannelState *ts = cls; 635 struct ChannelState *ts = cls;
649 636
650 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 */
651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
652 "CADET notified us about death of channel to `%s'\n", 640 "CADET notified us about death of channel to `%s'\n",
653 print_channel_destination (&ts->destination)); 641 print_channel_destination (&ts->destination));
654 free_channel_state (ts); 642 free_channel_state (ts);
655} 643}
@@ -666,14 +654,14 @@ channel_cleaner (void *cls,
666 */ 654 */
667static void 655static void
668make_up_icmpv4_payload (struct ChannelState *ts, 656make_up_icmpv4_payload (struct ChannelState *ts,
669 struct GNUNET_TUN_IPv4Header *ipp, 657 struct GNUNET_TUN_IPv4Header *ipp,
670 struct GNUNET_TUN_UdpHeader *udp) 658 struct GNUNET_TUN_UdpHeader *udp)
671{ 659{
672 GNUNET_TUN_initialize_ipv4_header (ipp, 660 GNUNET_TUN_initialize_ipv4_header (ipp,
673 ts->protocol, 661 ts->protocol,
674 sizeof (struct GNUNET_TUN_TcpHeader), 662 sizeof (struct GNUNET_TUN_TcpHeader),
675 &ts->source_ip.v4, 663 &ts->source_ip.v4,
676 &ts->destination_ip.v4); 664 &ts->destination_ip.v4);
677 udp->source_port = htons (ts->source_port); 665 udp->source_port = htons (ts->source_port);
678 udp->destination_port = htons (ts->destination_port); 666 udp->destination_port = htons (ts->destination_port);
679 udp->len = htons (0); 667 udp->len = htons (0);
@@ -692,14 +680,14 @@ make_up_icmpv4_payload (struct ChannelState *ts,
692 */ 680 */
693static void 681static void
694make_up_icmpv6_payload (struct ChannelState *ts, 682make_up_icmpv6_payload (struct ChannelState *ts,
695 struct GNUNET_TUN_IPv6Header *ipp, 683 struct GNUNET_TUN_IPv6Header *ipp,
696 struct GNUNET_TUN_UdpHeader *udp) 684 struct GNUNET_TUN_UdpHeader *udp)
697{ 685{
698 GNUNET_TUN_initialize_ipv6_header (ipp, 686 GNUNET_TUN_initialize_ipv6_header (ipp,
699 ts->protocol, 687 ts->protocol,
700 sizeof (struct GNUNET_TUN_TcpHeader), 688 sizeof (struct GNUNET_TUN_TcpHeader),
701 &ts->source_ip.v6, 689 &ts->source_ip.v6,
702 &ts->destination_ip.v6); 690 &ts->destination_ip.v6);
703 udp->source_port = htons (ts->source_port); 691 udp->source_port = htons (ts->source_port);
704 udp->destination_port = htons (ts->destination_port); 692 udp->destination_port = htons (ts->destination_port);
705 udp->len = htons (0); 693 udp->len = htons (0);
@@ -716,8 +704,7 @@ make_up_icmpv6_payload (struct ChannelState *ts,
716 * #GNUNET_SYSERR to close it (signal serious error) 704 * #GNUNET_SYSERR to close it (signal serious error)
717 */ 705 */
718static int 706static int
719check_icmp_back (void *cls, 707check_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
720 const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
721{ 708{
722 struct ChannelState *ts = cls; 709 struct ChannelState *ts = cls;
723 710
@@ -743,309 +730,323 @@ check_icmp_back (void *cls,
743 * @param message the actual message 730 * @param message the actual message
744 */ 731 */
745static void 732static void
746handle_icmp_back (void *cls, 733handle_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
747 const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
748{ 734{
749 struct ChannelState *ts = cls; 735 struct ChannelState *ts = cls;
750 size_t mlen; 736 size_t mlen;
751 737
752 GNUNET_STATISTICS_update (stats, 738 GNUNET_STATISTICS_update (stats,
753 gettext_noop ("# ICMP packets received from cadet"), 739 gettext_noop ("# ICMP packets received from cadet"),
754 1, 740 1,
755 GNUNET_NO); 741 GNUNET_NO);
756 mlen = ntohs (i2v->header.size) - sizeof (struct GNUNET_EXIT_IcmpToVPNMessage); 742 mlen =
743 ntohs (i2v->header.size) - sizeof (struct GNUNET_EXIT_IcmpToVPNMessage);
757 { 744 {
758 char sbuf[INET6_ADDRSTRLEN]; 745 char sbuf[INET6_ADDRSTRLEN];
759 char dbuf[INET6_ADDRSTRLEN]; 746 char dbuf[INET6_ADDRSTRLEN];
760 747
761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 748 GNUNET_log (
762 "Received ICMP packet from cadet, sending %u bytes from %s -> %s via TUN\n", 749 GNUNET_ERROR_TYPE_DEBUG,
763 (unsigned int) mlen, 750 "Received ICMP packet from cadet, sending %u bytes from %s -> %s via TUN\n",
764 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), 751 (unsigned int) mlen,
765 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)));
766 } 754 }
767 switch (ts->af) 755 switch (ts->af)
768 { 756 {
769 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;
770 { 762 {
771 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) 763 /* reserve some extra space in case we have an ICMP type here where
772 + sizeof (struct GNUNET_TUN_IcmpHeader)
773 + sizeof (struct GNUNET_MessageHeader) +
774 sizeof (struct GNUNET_TUN_Layer2PacketHeader) +
775 mlen;
776 {
777 /* reserve some extra space in case we have an ICMP type here where
778 we will need to make up the payload ourselves */ 764 we will need to make up the payload ourselves */
779 char buf[size + sizeof (struct GNUNET_TUN_IPv4Header) + 8] GNUNET_ALIGN; 765 char buf[size + sizeof (struct GNUNET_TUN_IPv4Header) + 8] GNUNET_ALIGN;
780 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 766 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
781 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 767 struct GNUNET_TUN_Layer2PacketHeader *tun =
782 struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; 768 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
783 struct GNUNET_TUN_IcmpHeader *icmp = (struct GNUNET_TUN_IcmpHeader *) &ipv4[1]; 769 struct GNUNET_TUN_IPv4Header *ipv4 =
784 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 770 (struct GNUNET_TUN_IPv4Header *) &tun[1];
785 tun->flags = htons (0); 771 struct GNUNET_TUN_IcmpHeader *icmp =
786 tun->proto = htons (ETH_P_IPV4); 772 (struct GNUNET_TUN_IcmpHeader *) &ipv4[1];
787 GNUNET_TUN_initialize_ipv4_header (ipv4, 773 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
788 IPPROTO_ICMP, 774 tun->flags = htons (0);
789 sizeof (struct GNUNET_TUN_IcmpHeader) + mlen, 775 tun->proto = htons (ETH_P_IPV4);
790 &ts->destination_ip.v4, 776 GNUNET_TUN_initialize_ipv4_header (ipv4,
791 &ts->source_ip.v4); 777 IPPROTO_ICMP,
792 *icmp = i2v->icmp_header; 778 sizeof (struct GNUNET_TUN_IcmpHeader) +
793 GNUNET_memcpy (&icmp[1], 779 mlen,
794 &i2v[1], 780 &ts->destination_ip.v4,
795 mlen); 781 &ts->source_ip.v4);
796 /* 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.
797 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
798 do ICMP PT (translate ICMP types) */ 786 do ICMP PT (translate ICMP types) */
799 switch (ntohl (i2v->af)) 787 switch (ntohl (i2v->af))
800 { 788 {
801 case AF_INET: 789 case AF_INET:
802 switch (icmp->type) 790 switch (icmp->type)
803 { 791 {
804 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 792 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
805 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 793 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
806 break; 794 break;
807 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 795 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
808 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 796 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
809 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 797 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: {
810 { 798 struct GNUNET_TUN_IPv4Header *ipp =
811 struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; 799 (struct GNUNET_TUN_IPv4Header *) &icmp[1];
812 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 800 struct GNUNET_TUN_UdpHeader *udp =
813 801 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
814 if (mlen != 0) 802
815 { 803 if (mlen != 0)
816 /* sender did not strip ICMP payload? */ 804 {
817 GNUNET_break_op (0); 805 /* sender did not strip ICMP payload? */
818 return; 806 GNUNET_break_op (0);
819 } 807 return;
820 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; 808 }
821 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 809 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8;
822 make_up_icmpv4_payload (ts, ipp, udp); 810 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
823 } 811 make_up_icmpv4_payload (ts, ipp, udp);
824 break; 812 }
825 default: 813 break;
826 GNUNET_break_op (0); 814 default:
827 GNUNET_STATISTICS_update (stats, 815 GNUNET_break_op (0);
828 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), 816 GNUNET_STATISTICS_update (
829 1, GNUNET_NO); 817 stats,
830 return; 818 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
831 } 819 1,
832 /* end AF_INET */ 820 GNUNET_NO);
833 break; 821 return;
834 case AF_INET6: 822 }
835 /* ICMP PT 6-to-4 and possibly making up payloads */ 823 /* end AF_INET */
836 switch (icmp->type) 824 break;
837 { 825 case AF_INET6:
838 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 826 /* ICMP PT 6-to-4 and possibly making up payloads */
839 icmp->type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; 827 switch (icmp->type)
840 { 828 {
841 struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; 829 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
842 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 830 icmp->type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE;
843 831 {
844 if (mlen != 0) 832 struct GNUNET_TUN_IPv4Header *ipp =
845 { 833 (struct GNUNET_TUN_IPv4Header *) &icmp[1];
846 /* sender did not strip ICMP payload? */ 834 struct GNUNET_TUN_UdpHeader *udp =
847 GNUNET_break_op (0); 835 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
848 return; 836
849 } 837 if (mlen != 0)
850 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; 838 {
851 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 839 /* sender did not strip ICMP payload? */
852 make_up_icmpv4_payload (ts, ipp, udp); 840 GNUNET_break_op (0);
853 } 841 return;
854 break; 842 }
855 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 843 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8;
856 icmp->type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; 844 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
857 { 845 make_up_icmpv4_payload (ts, ipp, udp);
858 struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; 846 }
859 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 847 break;
860 848 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
861 if (mlen != 0) 849 icmp->type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED;
862 { 850 {
863 /* sender did not strip ICMP payload? */ 851 struct GNUNET_TUN_IPv4Header *ipp =
864 GNUNET_break_op (0); 852 (struct GNUNET_TUN_IPv4Header *) &icmp[1];
865 return; 853 struct GNUNET_TUN_UdpHeader *udp =
866 } 854 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
867 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; 855
868 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 856 if (mlen != 0)
869 make_up_icmpv4_payload (ts, ipp, udp); 857 {
870 } 858 /* sender did not strip ICMP payload? */
871 break; 859 GNUNET_break_op (0);
872 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 860 return;
873 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 861 }
874 GNUNET_STATISTICS_update (stats, 862 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8;
875 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), 863 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
876 1, GNUNET_NO); 864 make_up_icmpv4_payload (ts, ipp, udp);
877 return; 865 }
878 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 866 break;
879 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; 867 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
880 break; 868 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
881 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: 869 GNUNET_STATISTICS_update (
882 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; 870 stats,
883 break; 871 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"),
884 default: 872 1,
885 GNUNET_break_op (0); 873 GNUNET_NO);
886 GNUNET_STATISTICS_update (stats, 874 return;
887 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), 875 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
888 1, GNUNET_NO); 876 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST;
889 return; 877 break;
890 } 878 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
891 /* end AF_INET6 */ 879 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY;
892 break; 880 break;
893 default: 881 default:
894 GNUNET_break_op (0); 882 GNUNET_break_op (0);
895 return; 883 GNUNET_STATISTICS_update (
896 } 884 stats,
897 msg->size = htons (size); 885 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"),
898 GNUNET_TUN_calculate_icmp_checksum (icmp, 886 1,
899 &i2v[1], 887 GNUNET_NO);
900 mlen); 888 return;
901 (void) GNUNET_HELPER_send (helper_handle, 889 }
902 msg, 890 /* end AF_INET6 */
903 GNUNET_YES, 891 break;
904 NULL, NULL); 892 default:
893 GNUNET_break_op (0);
894 return;
905 } 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);
906 } 899 }
907 break; 900 }
908 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;
909 { 907 {
910 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) 908 char buf[size + sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN;
911 + sizeof (struct GNUNET_TUN_IcmpHeader) 909 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
912 + sizeof (struct GNUNET_MessageHeader) + 910 struct GNUNET_TUN_Layer2PacketHeader *tun =
913 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 911 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
914 mlen; 912 struct GNUNET_TUN_IPv6Header *ipv6 =
915 { 913 (struct GNUNET_TUN_IPv6Header *) &tun[1];
916 char buf[size + sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; 914 struct GNUNET_TUN_IcmpHeader *icmp =
917 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 915 (struct GNUNET_TUN_IcmpHeader *) &ipv6[1];
918 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 916 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
919 struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; 917 tun->flags = htons (0);
920 struct GNUNET_TUN_IcmpHeader *icmp = (struct GNUNET_TUN_IcmpHeader *) &ipv6[1]; 918 tun->proto = htons (ETH_P_IPV6);
921 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 919 GNUNET_TUN_initialize_ipv6_header (ipv6,
922 tun->flags = htons (0); 920 IPPROTO_ICMPV6,
923 tun->proto = htons (ETH_P_IPV6); 921 sizeof (struct GNUNET_TUN_IcmpHeader) +
924 GNUNET_TUN_initialize_ipv6_header (ipv6, 922 mlen,
925 IPPROTO_ICMPV6, 923 &ts->destination_ip.v6,
926 sizeof (struct GNUNET_TUN_IcmpHeader) + mlen, 924 &ts->source_ip.v6);
927 &ts->destination_ip.v6, 925 *icmp = i2v->icmp_header;
928 &ts->source_ip.v6); 926 GNUNET_memcpy (&icmp[1], &i2v[1], mlen);
929 *icmp = i2v->icmp_header; 927
930 GNUNET_memcpy (&icmp[1], 928 /* For some ICMP types, we need to adjust (make up) the payload here.
931 &i2v[1],
932 mlen);
933
934 /* For some ICMP types, we need to adjust (make up) the payload here.
935 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
936 do ICMP PT (translate ICMP types) */ 930 do ICMP PT (translate ICMP types) */
937 switch (ntohl (i2v->af)) 931 switch (ntohl (i2v->af))
938 { 932 {
939 case AF_INET: 933 case AF_INET:
940 /* ICMP PT 4-to-6 and possibly making up payloads */ 934 /* ICMP PT 4-to-6 and possibly making up payloads */
941 switch (icmp->type) 935 switch (icmp->type)
942 { 936 {
943 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 937 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
944 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; 938 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY;
945 break; 939 break;
946 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 940 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
947 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; 941 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST;
948 break; 942 break;
949 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 943 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
950 icmp->type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; 944 icmp->type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE;
951 { 945 {
952 struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; 946 struct GNUNET_TUN_IPv6Header *ipp =
953 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 947 (struct GNUNET_TUN_IPv6Header *) &icmp[1];
954 948 struct GNUNET_TUN_UdpHeader *udp =
955 if (mlen != 0) 949 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
956 { 950
957 /* sender did not strip ICMP payload? */ 951 if (mlen != 0)
958 GNUNET_break_op (0); 952 {
959 return; 953 /* sender did not strip ICMP payload? */
960 } 954 GNUNET_break_op (0);
961 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; 955 return;
962 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 956 }
963 make_up_icmpv6_payload (ts, ipp, udp); 957 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8;
964 } 958 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
965 break; 959 make_up_icmpv6_payload (ts, ipp, udp);
966 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 960 }
967 icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; 961 break;
968 { 962 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
969 struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; 963 icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED;
970 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 964 {
971 965 struct GNUNET_TUN_IPv6Header *ipp =
972 if (mlen != 0) 966 (struct GNUNET_TUN_IPv6Header *) &icmp[1];
973 { 967 struct GNUNET_TUN_UdpHeader *udp =
974 /* sender did not strip ICMP payload? */ 968 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
975 GNUNET_break_op (0); 969
976 return; 970 if (mlen != 0)
977 } 971 {
978 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; 972 /* sender did not strip ICMP payload? */
979 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 973 GNUNET_break_op (0);
980 make_up_icmpv6_payload (ts, ipp, udp); 974 return;
981 } 975 }
982 break; 976 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8;
983 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 977 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
984 GNUNET_STATISTICS_update (stats, 978 make_up_icmpv6_payload (ts, ipp, udp);
985 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), 979 }
986 1, GNUNET_NO); 980 break;
987 return; 981 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
988 default: 982 GNUNET_STATISTICS_update (
989 GNUNET_break_op (0); 983 stats,
990 GNUNET_STATISTICS_update (stats, 984 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"),
991 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), 985 1,
992 1, GNUNET_NO); 986 GNUNET_NO);
993 return; 987 return;
994 } 988 default:
995 /* end AF_INET */ 989 GNUNET_break_op (0);
996 break; 990 GNUNET_STATISTICS_update (
997 case AF_INET6: 991 stats,
998 switch (icmp->type) 992 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
999 { 993 1,
1000 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 994 GNUNET_NO);
1001 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 995 return;
1002 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 996 }
1003 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 997 /* end AF_INET */
1004 { 998 break;
1005 struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; 999 case AF_INET6:
1006 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 1000 switch (icmp->type)
1007 1001 {
1008 if (mlen != 0) 1002 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
1009 { 1003 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
1010 /* sender did not strip ICMP payload? */ 1004 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
1011 GNUNET_break_op (0); 1005 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: {
1012 return; 1006 struct GNUNET_TUN_IPv6Header *ipp =
1013 } 1007 (struct GNUNET_TUN_IPv6Header *) &icmp[1];
1014 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; 1008 struct GNUNET_TUN_UdpHeader *udp =
1015 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 1009 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
1016 make_up_icmpv6_payload (ts, ipp, udp); 1010
1017 } 1011 if (mlen != 0)
1018 break; 1012 {
1019 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 1013 /* sender did not strip ICMP payload? */
1020 break; 1014 GNUNET_break_op (0);
1021 default: 1015 return;
1022 GNUNET_break_op (0); 1016 }
1023 GNUNET_STATISTICS_update (stats, 1017 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8;
1024 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), 1018 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
1025 1, GNUNET_NO); 1019 make_up_icmpv6_payload (ts, ipp, udp);
1026 return; 1020 }
1027 } 1021 break;
1028 /* end AF_INET6 */ 1022 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
1029 break; 1023 break;
1030 default: 1024 default:
1031 GNUNET_break_op (0); 1025 GNUNET_break_op (0);
1032 return; 1026 GNUNET_STATISTICS_update (
1033 } 1027 stats,
1034 msg->size = htons (size); 1028 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"),
1035 GNUNET_TUN_calculate_icmp_checksum (icmp, 1029 1,
1036 &i2v[1], mlen); 1030 GNUNET_NO);
1037 (void) GNUNET_HELPER_send (helper_handle, 1031 return;
1038 msg, 1032 }
1039 GNUNET_YES, 1033 /* end AF_INET6 */
1040 NULL, NULL); 1034 break;
1035 default:
1036 GNUNET_break_op (0);
1037 return;
1041 } 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);
1042 } 1042 }
1043 break; 1043 }
1044 break;
1044 default: 1045 default:
1045 GNUNET_assert (0); 1046 GNUNET_assert (0);
1046 } 1047 }
1047 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1048 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1048 GNUNET_TIME_absolute_get ().abs_value_us); 1049 GNUNET_TIME_absolute_get ().abs_value_us);
1049 GNUNET_CADET_receive_done (ts->channel); 1050 GNUNET_CADET_receive_done (ts->channel);
1050} 1051}
1051 1052
@@ -1059,8 +1060,7 @@ handle_icmp_back (void *cls,
1059 * #GNUNET_SYSERR to close it (signal serious error) 1060 * #GNUNET_SYSERR to close it (signal serious error)
1060 */ 1061 */
1061static int 1062static int
1062check_udp_back (void *cls, 1063check_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply)
1063 const struct GNUNET_EXIT_UdpReplyMessage *reply)
1064{ 1064{
1065 struct ChannelState *ts = cls; 1065 struct ChannelState *ts = cls;
1066 1066
@@ -1086,125 +1086,115 @@ check_udp_back (void *cls,
1086 * @param reply the actual message 1086 * @param reply the actual message
1087 */ 1087 */
1088static void 1088static void
1089handle_udp_back (void *cls, 1089handle_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply)
1090 const struct GNUNET_EXIT_UdpReplyMessage *reply)
1091{ 1090{
1092 struct ChannelState *ts = cls; 1091 struct ChannelState *ts = cls;
1093 size_t mlen; 1092 size_t mlen;
1094 1093
1095 GNUNET_STATISTICS_update (stats, 1094 GNUNET_STATISTICS_update (stats,
1096 gettext_noop ("# UDP packets received from cadet"), 1095 gettext_noop ("# UDP packets received from cadet"),
1097 1, 1096 1,
1098 GNUNET_NO); 1097 GNUNET_NO);
1099 mlen = ntohs (reply->header.size) - sizeof (struct GNUNET_EXIT_UdpReplyMessage); 1098 mlen =
1099 ntohs (reply->header.size) - sizeof (struct GNUNET_EXIT_UdpReplyMessage);
1100 { 1100 {
1101 char sbuf[INET6_ADDRSTRLEN]; 1101 char sbuf[INET6_ADDRSTRLEN];
1102 char dbuf[INET6_ADDRSTRLEN]; 1102 char dbuf[INET6_ADDRSTRLEN];
1103 1103
1104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1104 GNUNET_log (
1105 "Received UDP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", 1105 GNUNET_ERROR_TYPE_DEBUG,
1106 (unsigned int) mlen, 1106 "Received UDP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n",
1107 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), 1107 (unsigned int) mlen,
1108 ts->destination_port, 1108 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)),
1109 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)), 1109 ts->destination_port,
1110 ts->source_port); 1110 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)),
1111 ts->source_port);
1111 } 1112 }
1112 switch (ts->af) 1113 switch (ts->af)
1113 { 1114 {
1114 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;
1115 { 1120 {
1116 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) 1121 char buf[size] GNUNET_ALIGN;
1117 + sizeof (struct GNUNET_TUN_UdpHeader) 1122 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1118 + sizeof (struct GNUNET_MessageHeader) + 1123 struct GNUNET_TUN_Layer2PacketHeader *tun =
1119 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1124 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1120 mlen; 1125 struct GNUNET_TUN_IPv4Header *ipv4 =
1121 { 1126 (struct GNUNET_TUN_IPv4Header *) &tun[1];
1122 char buf[size] GNUNET_ALIGN; 1127 struct GNUNET_TUN_UdpHeader *udp =
1123 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1128 (struct GNUNET_TUN_UdpHeader *) &ipv4[1];
1124 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1129 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1125 struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; 1130 msg->size = htons (size);
1126 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipv4[1]; 1131 tun->flags = htons (0);
1127 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1132 tun->proto = htons (ETH_P_IPV4);
1128 msg->size = htons (size); 1133 GNUNET_TUN_initialize_ipv4_header (ipv4,
1129 tun->flags = htons (0); 1134 IPPROTO_UDP,
1130 tun->proto = htons (ETH_P_IPV4); 1135 sizeof (struct GNUNET_TUN_UdpHeader) +
1131 GNUNET_TUN_initialize_ipv4_header (ipv4, 1136 mlen,
1132 IPPROTO_UDP, 1137 &ts->destination_ip.v4,
1133 sizeof (struct GNUNET_TUN_UdpHeader) + mlen, 1138 &ts->source_ip.v4);
1134 &ts->destination_ip.v4, 1139 if (0 == ntohs (reply->source_port))
1135 &ts->source_ip.v4); 1140 udp->source_port = htons (ts->destination_port);
1136 if (0 == ntohs (reply->source_port)) 1141 else
1137 udp->source_port = htons (ts->destination_port); 1142 udp->source_port = reply->source_port;
1138 else 1143 if (0 == ntohs (reply->destination_port))
1139 udp->source_port = reply->source_port; 1144 udp->destination_port = htons (ts->source_port);
1140 if (0 == ntohs (reply->destination_port)) 1145 else
1141 udp->destination_port = htons (ts->source_port); 1146 udp->destination_port = reply->destination_port;
1142 else 1147 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader));
1143 udp->destination_port = reply->destination_port; 1148 GNUNET_TUN_calculate_udp4_checksum (ipv4, udp, &reply[1], mlen);
1144 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); 1149 GNUNET_memcpy (&udp[1], &reply[1], mlen);
1145 GNUNET_TUN_calculate_udp4_checksum (ipv4, 1150 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1146 udp,
1147 &reply[1],
1148 mlen);
1149 GNUNET_memcpy (&udp[1],
1150 &reply[1],
1151 mlen);
1152 (void) GNUNET_HELPER_send (helper_handle,
1153 msg,
1154 GNUNET_YES,
1155 NULL, NULL);
1156 }
1157 } 1151 }
1158 break; 1152 }
1159 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;
1160 { 1159 {
1161 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) 1160 char buf[size] GNUNET_ALIGN;
1162 + sizeof (struct GNUNET_TUN_UdpHeader) 1161 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1163 + sizeof (struct GNUNET_MessageHeader) + 1162 struct GNUNET_TUN_Layer2PacketHeader *tun =
1164 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1163 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1165 mlen; 1164 struct GNUNET_TUN_IPv6Header *ipv6 =
1166 { 1165 (struct GNUNET_TUN_IPv6Header *) &tun[1];
1167 char buf[size] GNUNET_ALIGN; 1166 struct GNUNET_TUN_UdpHeader *udp =
1168 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1167 (struct GNUNET_TUN_UdpHeader *) &ipv6[1];
1169 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1168 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1170 struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; 1169 msg->size = htons (size);
1171 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipv6[1]; 1170 tun->flags = htons (0);
1172 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1171 tun->proto = htons (ETH_P_IPV6);
1173 msg->size = htons (size); 1172 GNUNET_TUN_initialize_ipv6_header (ipv6,
1174 tun->flags = htons (0); 1173 IPPROTO_UDP,
1175 tun->proto = htons (ETH_P_IPV6); 1174 sizeof (struct GNUNET_TUN_UdpHeader) +
1176 GNUNET_TUN_initialize_ipv6_header (ipv6, 1175 mlen,
1177 IPPROTO_UDP, 1176 &ts->destination_ip.v6,
1178 sizeof (struct GNUNET_TUN_UdpHeader) + mlen, 1177 &ts->source_ip.v6);
1179 &ts->destination_ip.v6, 1178 if (0 == ntohs (reply->source_port))
1180 &ts->source_ip.v6); 1179 udp->source_port = htons (ts->destination_port);
1181 if (0 == ntohs (reply->source_port)) 1180 else
1182 udp->source_port = htons (ts->destination_port); 1181 udp->source_port = reply->source_port;
1183 else 1182 if (0 == ntohs (reply->destination_port))
1184 udp->source_port = reply->source_port; 1183 udp->destination_port = htons (ts->source_port);
1185 if (0 == ntohs (reply->destination_port)) 1184 else
1186 udp->destination_port = htons (ts->source_port); 1185 udp->destination_port = reply->destination_port;
1187 else 1186 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader));
1188 udp->destination_port = reply->destination_port; 1187 GNUNET_TUN_calculate_udp6_checksum (ipv6, udp, &reply[1], mlen);
1189 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); 1188 GNUNET_memcpy (&udp[1], &reply[1], mlen);
1190 GNUNET_TUN_calculate_udp6_checksum (ipv6, 1189 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1191 udp,
1192 &reply[1], mlen);
1193 GNUNET_memcpy (&udp[1],
1194 &reply[1],
1195 mlen);
1196 (void) GNUNET_HELPER_send (helper_handle,
1197 msg,
1198 GNUNET_YES,
1199 NULL, NULL);
1200 }
1201 } 1190 }
1202 break; 1191 }
1192 break;
1203 default: 1193 default:
1204 GNUNET_assert (0); 1194 GNUNET_assert (0);
1205 } 1195 }
1206 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1196 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1207 GNUNET_TIME_absolute_get ().abs_value_us); 1197 GNUNET_TIME_absolute_get ().abs_value_us);
1208 GNUNET_CADET_receive_done (ts->channel); 1198 GNUNET_CADET_receive_done (ts->channel);
1209} 1199}
1210 1200
@@ -1218,8 +1208,7 @@ handle_udp_back (void *cls,
1218 * #GNUNET_SYSERR to close it (signal serious error) 1208 * #GNUNET_SYSERR to close it (signal serious error)
1219 */ 1209 */
1220static int 1210static int
1221check_tcp_back (void *cls, 1211check_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data)
1222 const struct GNUNET_EXIT_TcpDataMessage *data)
1223{ 1212{
1224 struct ChannelState *ts = cls; 1213 struct ChannelState *ts = cls;
1225 1214
@@ -1245,112 +1234,100 @@ check_tcp_back (void *cls,
1245 * @param data the actual message 1234 * @param data the actual message
1246 */ 1235 */
1247static void 1236static void
1248handle_tcp_back (void *cls, 1237handle_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data)
1249 const struct GNUNET_EXIT_TcpDataMessage *data)
1250{ 1238{
1251 struct ChannelState *ts = cls; 1239 struct ChannelState *ts = cls;
1252 size_t mlen; 1240 size_t mlen;
1253 1241
1254 GNUNET_STATISTICS_update (stats, 1242 GNUNET_STATISTICS_update (stats,
1255 gettext_noop ("# TCP packets received from cadet"), 1243 gettext_noop ("# TCP packets received from cadet"),
1256 1, 1244 1,
1257 GNUNET_NO); 1245 GNUNET_NO);
1258 mlen = ntohs (data->header.size) - sizeof (struct GNUNET_EXIT_TcpDataMessage); 1246 mlen = ntohs (data->header.size) - sizeof (struct GNUNET_EXIT_TcpDataMessage);
1259 { 1247 {
1260 char sbuf[INET6_ADDRSTRLEN]; 1248 char sbuf[INET6_ADDRSTRLEN];
1261 char dbuf[INET6_ADDRSTRLEN]; 1249 char dbuf[INET6_ADDRSTRLEN];
1262 1250
1263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1251 GNUNET_log (
1264 "Received TCP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", 1252 GNUNET_ERROR_TYPE_DEBUG,
1265 (unsigned int) mlen, 1253 "Received TCP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n",
1266 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), 1254 (unsigned int) mlen,
1267 ts->destination_port, 1255 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)),
1268 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)), 1256 ts->destination_port,
1269 ts->source_port); 1257 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)),
1258 ts->source_port);
1270 } 1259 }
1271 switch (ts->af) 1260 switch (ts->af)
1272 { 1261 {
1273 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;
1274 { 1267 {
1275 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) 1268 char buf[size] GNUNET_ALIGN;
1276 + sizeof (struct GNUNET_TUN_TcpHeader) 1269 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1277 + sizeof (struct GNUNET_MessageHeader) + 1270 struct GNUNET_TUN_Layer2PacketHeader *tun =
1278 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1271 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1279 mlen; 1272 struct GNUNET_TUN_IPv4Header *ipv4 =
1280 { 1273 (struct GNUNET_TUN_IPv4Header *) &tun[1];
1281 char buf[size] GNUNET_ALIGN; 1274 struct GNUNET_TUN_TcpHeader *tcp =
1282 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1275 (struct GNUNET_TUN_TcpHeader *) &ipv4[1];
1283 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1276 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1284 struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; 1277 msg->size = htons (size);
1285 struct GNUNET_TUN_TcpHeader *tcp = (struct GNUNET_TUN_TcpHeader *) &ipv4[1]; 1278 tun->flags = htons (0);
1286 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1279 tun->proto = htons (ETH_P_IPV4);
1287 msg->size = htons (size); 1280 GNUNET_TUN_initialize_ipv4_header (ipv4,
1288 tun->flags = htons (0); 1281 IPPROTO_TCP,
1289 tun->proto = htons (ETH_P_IPV4); 1282 sizeof (struct GNUNET_TUN_TcpHeader) +
1290 GNUNET_TUN_initialize_ipv4_header (ipv4, 1283 mlen,
1291 IPPROTO_TCP, 1284 &ts->destination_ip.v4,
1292 sizeof (struct GNUNET_TUN_TcpHeader) + mlen, 1285 &ts->source_ip.v4);
1293 &ts->destination_ip.v4, 1286 *tcp = data->tcp_header;
1294 &ts->source_ip.v4); 1287 tcp->source_port = htons (ts->destination_port);
1295 *tcp = data->tcp_header; 1288 tcp->destination_port = htons (ts->source_port);
1296 tcp->source_port = htons (ts->destination_port); 1289 GNUNET_TUN_calculate_tcp4_checksum (ipv4, tcp, &data[1], mlen);
1297 tcp->destination_port = htons (ts->source_port); 1290 GNUNET_memcpy (&tcp[1], &data[1], mlen);
1298 GNUNET_TUN_calculate_tcp4_checksum (ipv4, 1291 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1299 tcp,
1300 &data[1],
1301 mlen);
1302 GNUNET_memcpy (&tcp[1],
1303 &data[1],
1304 mlen);
1305 (void) GNUNET_HELPER_send (helper_handle,
1306 msg,
1307 GNUNET_YES,
1308 NULL, NULL);
1309 }
1310 } 1292 }
1311 break; 1293 }
1312 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;
1313 { 1300 {
1314 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) 1301 char buf[size] GNUNET_ALIGN;
1315 + sizeof (struct GNUNET_TUN_TcpHeader) 1302 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1316 + sizeof (struct GNUNET_MessageHeader) + 1303 struct GNUNET_TUN_Layer2PacketHeader *tun =
1317 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1304 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1318 mlen; 1305 struct GNUNET_TUN_IPv6Header *ipv6 =
1319 { 1306 (struct GNUNET_TUN_IPv6Header *) &tun[1];
1320 char buf[size] GNUNET_ALIGN; 1307 struct GNUNET_TUN_TcpHeader *tcp =
1321 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1308 (struct GNUNET_TUN_TcpHeader *) &ipv6[1];
1322 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1309 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1323 struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; 1310 msg->size = htons (size);
1324 struct GNUNET_TUN_TcpHeader *tcp = (struct GNUNET_TUN_TcpHeader *) &ipv6[1]; 1311 tun->flags = htons (0);
1325 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1312 tun->proto = htons (ETH_P_IPV6);
1326 msg->size = htons (size); 1313 GNUNET_TUN_initialize_ipv6_header (ipv6,
1327 tun->flags = htons (0); 1314 IPPROTO_TCP,
1328 tun->proto = htons (ETH_P_IPV6); 1315 sizeof (struct GNUNET_TUN_TcpHeader) +
1329 GNUNET_TUN_initialize_ipv6_header (ipv6, 1316 mlen,
1330 IPPROTO_TCP, 1317 &ts->destination_ip.v6,
1331 sizeof (struct GNUNET_TUN_TcpHeader) + mlen, 1318 &ts->source_ip.v6);
1332 &ts->destination_ip.v6, 1319 *tcp = data->tcp_header;
1333 &ts->source_ip.v6); 1320 tcp->source_port = htons (ts->destination_port);
1334 *tcp = data->tcp_header; 1321 tcp->destination_port = htons (ts->source_port);
1335 tcp->source_port = htons (ts->destination_port); 1322 GNUNET_TUN_calculate_tcp6_checksum (ipv6, tcp, &data[1], mlen);
1336 tcp->destination_port = htons (ts->source_port); 1323 GNUNET_memcpy (&tcp[1], &data[1], mlen);
1337 GNUNET_TUN_calculate_tcp6_checksum (ipv6, 1324 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1338 tcp,
1339 &data[1],
1340 mlen);
1341 GNUNET_memcpy (&tcp[1],
1342 &data[1],
1343 mlen);
1344 (void) GNUNET_HELPER_send (helper_handle,
1345 msg,
1346 GNUNET_YES,
1347 NULL, NULL);
1348 }
1349 } 1325 }
1350 break; 1326 }
1327 break;
1351 } 1328 }
1352 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1329 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1353 GNUNET_TIME_absolute_get ().abs_value_us); 1330 GNUNET_TIME_absolute_get ().abs_value_us);
1354 GNUNET_CADET_receive_done (ts->channel); 1331 GNUNET_CADET_receive_done (ts->channel);
1355} 1332}
1356 1333
@@ -1368,27 +1345,25 @@ create_channel (struct ChannelState *ts,
1368 const struct GNUNET_PeerIdentity *target, 1345 const struct GNUNET_PeerIdentity *target,
1369 const struct GNUNET_HashCode *port) 1346 const struct GNUNET_HashCode *port)
1370{ 1347{
1371 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1348 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1372 GNUNET_MQ_hd_var_size (udp_back, 1349 {GNUNET_MQ_hd_var_size (udp_back,
1373 GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY, 1350 GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY,
1374 struct GNUNET_EXIT_UdpReplyMessage, 1351 struct GNUNET_EXIT_UdpReplyMessage,
1375 ts), 1352 ts),
1376 GNUNET_MQ_hd_var_size (tcp_back, 1353 GNUNET_MQ_hd_var_size (tcp_back,
1377 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN, 1354 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN,
1378 struct GNUNET_EXIT_TcpDataMessage, 1355 struct GNUNET_EXIT_TcpDataMessage,
1379 ts), 1356 ts),
1380 GNUNET_MQ_hd_var_size (icmp_back, 1357 GNUNET_MQ_hd_var_size (icmp_back,
1381 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN, 1358 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN,
1382 struct GNUNET_EXIT_IcmpToVPNMessage, 1359 struct GNUNET_EXIT_IcmpToVPNMessage,
1383 ts), 1360 ts),
1384 GNUNET_MQ_handler_end() 1361 GNUNET_MQ_handler_end ()};
1385 };
1386 1362
1387 return GNUNET_CADET_channel_create (cadet_handle, 1363 return GNUNET_CADET_channel_create (cadet_handle,
1388 ts, 1364 ts,
1389 target, 1365 target,
1390 port, 1366 port,
1391 GNUNET_CADET_OPTION_DEFAULT,
1392 NULL, 1367 NULL,
1393 &channel_cleaner, 1368 &channel_cleaner,
1394 cadet_handlers); 1369 cadet_handlers);
@@ -1407,11 +1382,11 @@ create_channel (struct ChannelState *ts,
1407 */ 1382 */
1408static void 1383static void
1409handle_regex_result (void *cls, 1384handle_regex_result (void *cls,
1410 const struct GNUNET_PeerIdentity *id, 1385 const struct GNUNET_PeerIdentity *id,
1411 const struct GNUNET_PeerIdentity *get_path, 1386 const struct GNUNET_PeerIdentity *get_path,
1412 unsigned int get_path_length, 1387 unsigned int get_path_length,
1413 const struct GNUNET_PeerIdentity *put_path, 1388 const struct GNUNET_PeerIdentity *put_path,
1414 unsigned int put_path_length) 1389 unsigned int put_path_length)
1415{ 1390{
1416 struct ChannelState *ts = cls; 1391 struct ChannelState *ts = cls;
1417 struct GNUNET_HashCode port; 1392 struct GNUNET_HashCode port;
@@ -1444,9 +1419,7 @@ handle_regex_result (void *cls,
1444 "Creating tunnel to %s for destination %s!\n", 1419 "Creating tunnel to %s for destination %s!\n",
1445 GNUNET_i2s (id), 1420 GNUNET_i2s (id),
1446 print_channel_destination (&ts->destination)); 1421 print_channel_destination (&ts->destination));
1447 ts->channel = create_channel (ts, 1422 ts->channel = create_channel (ts, id, &port);
1448 id,
1449 &port);
1450} 1423}
1451 1424
1452 1425
@@ -1458,14 +1431,13 @@ handle_regex_result (void *cls,
1458 * @return channel state of the channel that was created 1431 * @return channel state of the channel that was created
1459 */ 1432 */
1460static struct ChannelState * 1433static struct ChannelState *
1461create_channel_to_destination (struct DestinationChannel *dt, 1434create_channel_to_destination (struct DestinationChannel *dt, int client_af)
1462 int client_af)
1463{ 1435{
1464 struct ChannelState *ts; 1436 struct ChannelState *ts;
1465 1437
1466 GNUNET_STATISTICS_update (stats, 1438 GNUNET_STATISTICS_update (stats,
1467 gettext_noop ("# Cadet channels created"), 1439 gettext_noop ("# Cadet channels created"),
1468 1, 1440 1,
1469 GNUNET_NO); 1441 GNUNET_NO);
1470 ts = GNUNET_new (struct ChannelState); 1442 ts = GNUNET_new (struct ChannelState);
1471 ts->af = client_af; 1443 ts->af = client_af;
@@ -1476,12 +1448,15 @@ create_channel_to_destination (struct DestinationChannel *dt,
1476 { 1448 {
1477 struct GNUNET_HashCode cadet_port; 1449 struct GNUNET_HashCode cadet_port;
1478 1450
1479 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,
1480 ts->destination_port, 1454 ts->destination_port,
1481 &cadet_port); 1455 &cadet_port);
1482 ts->channel = create_channel (ts, 1456 ts->channel =
1483 &dt->destination->details.service_destination.target, 1457 create_channel (ts,
1484 &cadet_port); 1458 &dt->destination->details.service_destination.target,
1459 &cadet_port);
1485 1460
1486 if (NULL == ts->channel) 1461 if (NULL == ts->channel)
1487 { 1462 {
@@ -1490,9 +1465,11 @@ create_channel_to_destination (struct DestinationChannel *dt,
1490 return NULL; 1465 return NULL;
1491 } 1466 }
1492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1493 "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",
1494 GNUNET_i2s (&dt->destination->details.service_destination.target), 1469 GNUNET_i2s (
1495 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),
1496 (unsigned int) ts->destination_port); 1473 (unsigned int) ts->destination_port);
1497 } 1474 }
1498 else 1475 else
@@ -1501,25 +1478,25 @@ create_channel_to_destination (struct DestinationChannel *dt,
1501 1478
1502 switch (dt->destination->details.exit_destination.af) 1479 switch (dt->destination->details.exit_destination.af)
1503 { 1480 {
1504 case AF_INET: 1481 case AF_INET: {
1505 {
1506 char address[GNUNET_TUN_IPV4_REGEXLEN]; 1482 char address[GNUNET_TUN_IPV4_REGEXLEN];
1507 1483
1508 GNUNET_TUN_ipv4toregexsearch (&dt->destination->details.exit_destination.ip.v4, 1484 GNUNET_TUN_ipv4toregexsearch (&dt->destination->details.exit_destination
1509 dt->destination_port, 1485 .ip.v4,
1510 address); 1486 dt->destination_port,
1487 address);
1511 GNUNET_asprintf (&policy, 1488 GNUNET_asprintf (&policy,
1512 "%s%s", 1489 "%s%s",
1513 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, 1490 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
1514 address); 1491 address);
1515 break; 1492 break;
1516 } 1493 }
1517 case AF_INET6: 1494 case AF_INET6: {
1518 {
1519 char address[GNUNET_TUN_IPV6_REGEXLEN]; 1495 char address[GNUNET_TUN_IPV6_REGEXLEN];
1520 1496
1521 GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination.ip.v6, 1497 GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination
1522 dt->destination_port, 1498 .ip.v6,
1499 dt->destination_port,
1523 address); 1500 address);
1524 GNUNET_asprintf (&policy, 1501 GNUNET_asprintf (&policy,
1525 "%s%s", 1502 "%s%s",
@@ -1533,12 +1510,9 @@ create_channel_to_destination (struct DestinationChannel *dt,
1533 } 1510 }
1534 1511
1535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1536 "Requesting connect by string: %s\n", 1513 "Requesting connect by string: %s\n",
1537 policy); 1514 policy);
1538 ts->search = GNUNET_REGEX_search (cfg, 1515 ts->search = GNUNET_REGEX_search (cfg, policy, &handle_regex_result, ts);
1539 policy,
1540 &handle_regex_result,
1541 ts);
1542 GNUNET_free (policy); 1516 GNUNET_free (policy);
1543 } 1517 }
1544 return ts; 1518 return ts;
@@ -1579,12 +1553,12 @@ expire_channel (struct ChannelState *except)
1579 */ 1553 */
1580static void 1554static void
1581route_packet (struct DestinationEntry *destination, 1555route_packet (struct DestinationEntry *destination,
1582 int af, 1556 int af,
1583 uint8_t protocol, 1557 uint8_t protocol,
1584 const void *source_ip, 1558 const void *source_ip,
1585 const void *destination_ip, 1559 const void *destination_ip,
1586 const void *payload, 1560 const void *payload,
1587 size_t payload_length) 1561 size_t payload_length)
1588{ 1562{
1589 struct GNUNET_HashCode key; 1563 struct GNUNET_HashCode key;
1590 struct ChannelState *ts; 1564 struct ChannelState *ts;
@@ -1600,92 +1574,89 @@ route_packet (struct DestinationEntry *destination,
1600 1574
1601 switch (protocol) 1575 switch (protocol)
1602 { 1576 {
1603 case IPPROTO_UDP: 1577 case IPPROTO_UDP: {
1578 if (payload_length < sizeof (struct GNUNET_TUN_UdpHeader))
1604 { 1579 {
1605 if (payload_length < sizeof (struct GNUNET_TUN_UdpHeader)) 1580 /* blame kernel? */
1606 { 1581 GNUNET_break (0);
1607 /* blame kernel? */ 1582 return;
1608 GNUNET_break (0);
1609 return;
1610 }
1611 tcp = NULL; /* make compiler happy */
1612 icmp = NULL; /* make compiler happy */
1613 udp = payload;
1614 if (udp->len < sizeof (struct GNUNET_TUN_UdpHeader))
1615 {
1616 GNUNET_break_op (0);
1617 return;
1618 }
1619 source_port = ntohs (udp->source_port);
1620 destination_port = ntohs (udp->destination_port);
1621 get_channel_key_from_ips (af,
1622 IPPROTO_UDP,
1623 source_ip,
1624 source_port,
1625 destination_ip,
1626 destination_port,
1627 &key);
1628 } 1583 }
1629 break; 1584 tcp = NULL; /* make compiler happy */
1630 case IPPROTO_TCP: 1585 icmp = NULL; /* make compiler happy */
1586 udp = payload;
1587 if (udp->len < sizeof (struct GNUNET_TUN_UdpHeader))
1631 { 1588 {
1632 if (payload_length < sizeof (struct GNUNET_TUN_TcpHeader)) 1589 GNUNET_break_op (0);
1633 { 1590 return;
1634 /* blame kernel? */
1635 GNUNET_break (0);
1636 return;
1637 }
1638 udp = NULL; /* make compiler happy */
1639 icmp = NULL; /* make compiler happy */
1640 tcp = payload;
1641 if (tcp->off * 4 < sizeof (struct GNUNET_TUN_TcpHeader))
1642 {
1643 GNUNET_break_op (0);
1644 return;
1645 }
1646 source_port = ntohs (tcp->source_port);
1647 destination_port = ntohs (tcp->destination_port);
1648 get_channel_key_from_ips (af,
1649 IPPROTO_TCP,
1650 source_ip,
1651 source_port,
1652 destination_ip,
1653 destination_port,
1654 &key);
1655 } 1591 }
1656 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;
1657 case IPPROTO_ICMP: 1629 case IPPROTO_ICMP:
1658 case IPPROTO_ICMPV6: 1630 case IPPROTO_ICMPV6: {
1631 if ((AF_INET == af) ^ (protocol == IPPROTO_ICMP))
1659 { 1632 {
1660 if ( (AF_INET == af) ^ (protocol == IPPROTO_ICMP) ) 1633 GNUNET_break (0);
1661 { 1634 return;
1662 GNUNET_break (0);
1663 return;
1664 }
1665 if (payload_length < sizeof (struct GNUNET_TUN_IcmpHeader))
1666 {
1667 /* blame kernel? */
1668 GNUNET_break (0);
1669 return;
1670 }
1671 tcp = NULL; /* make compiler happy */
1672 udp = NULL; /* make compiler happy */
1673 icmp = payload;
1674 source_port = 0;
1675 destination_port = 0;
1676 get_channel_key_from_ips (af,
1677 protocol,
1678 source_ip,
1679 0,
1680 destination_ip,
1681 0,
1682 &key);
1683 } 1635 }
1684 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;
1685 default: 1656 default:
1686 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1657 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1687 _("Protocol %u not supported, dropping\n"), 1658 _ ("Protocol %u not supported, dropping\n"),
1688 (unsigned int) protocol); 1659 (unsigned int) protocol);
1689 return; 1660 return;
1690 } 1661 }
1691 alen = 0; 1662 alen = 0;
@@ -1695,7 +1666,7 @@ route_packet (struct DestinationEntry *destination,
1695 { 1666 {
1696 case AF_INET: 1667 case AF_INET:
1697 alen = sizeof (struct in_addr); 1668 alen = sizeof (struct in_addr);
1698 break; 1669 break;
1699 case AF_INET6: 1670 case AF_INET6:
1700 alen = sizeof (struct in6_addr); 1671 alen = sizeof (struct in6_addr);
1701 break; 1672 break;
@@ -1708,27 +1679,23 @@ route_packet (struct DestinationEntry *destination,
1708 char dbuf[INET6_ADDRSTRLEN]; 1679 char dbuf[INET6_ADDRSTRLEN];
1709 char xbuf[INET6_ADDRSTRLEN]; 1680 char xbuf[INET6_ADDRSTRLEN];
1710 1681
1711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1682 GNUNET_log (
1712 "Routing %s packet from [%s]:%u -> [%s]:%u to destination [%s]:%u\n", 1683 GNUNET_ERROR_TYPE_DEBUG,
1713 (protocol == IPPROTO_TCP) ? "TCP" : "UDP", 1684 "Routing %s packet from [%s]:%u -> [%s]:%u to destination [%s]:%u\n",
1714 inet_ntop (af, 1685 (protocol == IPPROTO_TCP) ? "TCP" : "UDP",
1715 source_ip, 1686 inet_ntop (af, source_ip, sbuf, sizeof (sbuf)),
1716 sbuf, 1687 source_port,
1717 sizeof (sbuf)), 1688 inet_ntop (af, destination_ip, dbuf, sizeof (dbuf)),
1718 source_port, 1689 destination_port,
1719 inet_ntop (af, 1690 inet_ntop (destination->details.exit_destination.af,
1720 destination_ip, 1691 &destination->details.exit_destination.ip,
1721 dbuf, 1692 xbuf,
1722 sizeof (dbuf)), 1693 sizeof (xbuf)),
1723 destination_port, 1694 destination_port);
1724 inet_ntop (destination->details.exit_destination.af,
1725 &destination->details.exit_destination.ip,
1726 xbuf, sizeof (xbuf)),
1727 destination_port);
1728 } 1695 }
1729 for (dt = destination->dt_head; NULL != dt; dt = dt->next) 1696 for (dt = destination->dt_head; NULL != dt; dt = dt->next)
1730 if (dt->destination_port == destination_port) 1697 if (dt->destination_port == destination_port)
1731 break; 1698 break;
1732 } 1699 }
1733 else 1700 else
1734 { 1701 {
@@ -1736,39 +1703,34 @@ route_packet (struct DestinationEntry *destination,
1736 char sbuf[INET6_ADDRSTRLEN]; 1703 char sbuf[INET6_ADDRSTRLEN];
1737 char dbuf[INET6_ADDRSTRLEN]; 1704 char dbuf[INET6_ADDRSTRLEN];
1738 1705
1739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1706 GNUNET_log (
1740 "Routing %s packet from [%s]:%u -> [%s]:%u to service %s at peer %s\n", 1707 GNUNET_ERROR_TYPE_DEBUG,
1741 (protocol == IPPROTO_TCP) ? "TCP" : "UDP", 1708 "Routing %s packet from [%s]:%u -> [%s]:%u to service %s at peer %s\n",
1742 inet_ntop (af, 1709 (protocol == IPPROTO_TCP) ? "TCP" : "UDP",
1743 source_ip, 1710 inet_ntop (af, source_ip, sbuf, sizeof (sbuf)),
1744 sbuf, 1711 source_port,
1745 sizeof (sbuf)), 1712 inet_ntop (af, destination_ip, dbuf, sizeof (dbuf)),
1746 source_port, 1713 destination_port,
1747 inet_ntop (af, 1714 GNUNET_h2s (
1748 destination_ip, 1715 &destination->details.service_destination.service_descriptor),
1749 dbuf, 1716 GNUNET_i2s (&destination->details.service_destination.target));
1750 sizeof (dbuf)),
1751 destination_port,
1752 GNUNET_h2s (&destination->details.service_destination.service_descriptor),
1753 GNUNET_i2s (&destination->details.service_destination.target));
1754 } 1717 }
1755 for (dt = destination->dt_head; NULL != dt; dt = dt->next) 1718 for (dt = destination->dt_head; NULL != dt; dt = dt->next)
1756 if (dt->destination_port == destination_port) 1719 if (dt->destination_port == destination_port)
1757 break; 1720 break;
1758 } 1721 }
1759 if (NULL == dt) 1722 if (NULL == dt)
1760 { 1723 {
1761 dt = GNUNET_new (struct DestinationChannel); 1724 dt = GNUNET_new (struct DestinationChannel);
1762 dt->destination = destination; 1725 dt->destination = destination;
1763 GNUNET_CONTAINER_DLL_insert (destination->dt_head, 1726 GNUNET_CONTAINER_DLL_insert (destination->dt_head,
1764 destination->dt_tail, 1727 destination->dt_tail,
1765 dt); 1728 dt);
1766 dt->destination_port = destination_port; 1729 dt->destination_port = destination_port;
1767 } 1730 }
1768 1731
1769 /* see if we have an existing channel for this destination */ 1732 /* see if we have an existing channel for this destination */
1770 ts = GNUNET_CONTAINER_multihashmap_get (channel_map, 1733 ts = GNUNET_CONTAINER_multihashmap_get (channel_map, &key);
1771 &key);
1772 if (NULL == ts) 1734 if (NULL == ts)
1773 { 1735 {
1774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1776,8 +1738,7 @@ route_packet (struct DestinationEntry *destination,
1776 GNUNET_h2s (&key)); 1738 GNUNET_h2s (&key));
1777 /* 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
1778 available) or create a fresh one */ 1740 available) or create a fresh one */
1779 ts = create_channel_to_destination (dt, 1741 ts = create_channel_to_destination (dt, af);
1780 af);
1781 if (NULL == ts) 1742 if (NULL == ts)
1782 return; 1743 return;
1783 /* now bind existing "unbound" channel to our IP/port tuple */ 1744 /* now bind existing "unbound" channel to our IP/port tuple */
@@ -1785,46 +1746,51 @@ route_packet (struct DestinationEntry *destination,
1785 ts->af = af; 1746 ts->af = af;
1786 if (AF_INET == af) 1747 if (AF_INET == af)
1787 { 1748 {
1788 ts->source_ip.v4 = * (const struct in_addr *) source_ip; 1749 ts->source_ip.v4 = *(const struct in_addr *) source_ip;
1789 ts->destination_ip.v4 = * (const struct in_addr *) destination_ip; 1750 ts->destination_ip.v4 = *(const struct in_addr *) destination_ip;
1790 } 1751 }
1791 else 1752 else
1792 { 1753 {
1793 ts->source_ip.v6 = * (const struct in6_addr *) source_ip; 1754 ts->source_ip.v6 = *(const struct in6_addr *) source_ip;
1794 ts->destination_ip.v6 = * (const struct in6_addr *) destination_ip; 1755 ts->destination_ip.v6 = *(const struct in6_addr *) destination_ip;
1795 } 1756 }
1796 ts->source_port = source_port; 1757 ts->source_port = source_port;
1797 ts->destination_port = destination_port; 1758 ts->destination_port = destination_port;
1798 ts->heap_node = GNUNET_CONTAINER_heap_insert (channel_heap, 1759 ts->heap_node =
1799 ts, 1760 GNUNET_CONTAINER_heap_insert (channel_heap,
1800 GNUNET_TIME_absolute_get ().abs_value_us); 1761 ts,
1762 GNUNET_TIME_absolute_get ().abs_value_us);
1801 GNUNET_assert (GNUNET_YES == 1763 GNUNET_assert (GNUNET_YES ==
1802 GNUNET_CONTAINER_multihashmap_put (channel_map, 1764 GNUNET_CONTAINER_multihashmap_put (
1803 &key, 1765 channel_map,
1804 ts, 1766 &key,
1805 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1767 ts,
1768 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1806 GNUNET_STATISTICS_update (stats, 1769 GNUNET_STATISTICS_update (stats,
1807 gettext_noop ("# Active channels"), 1770 gettext_noop ("# Active channels"),
1808 1, GNUNET_NO); 1771 1,
1809 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)
1810 expire_channel (ts); 1775 expire_channel (ts);
1811 } 1776 }
1812 else 1777 else
1813 { 1778 {
1814 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1779 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1815 GNUNET_TIME_absolute_get ().abs_value_us); 1780 GNUNET_TIME_absolute_get ()
1781 .abs_value_us);
1816 } 1782 }
1817 if (NULL == ts->channel) 1783 if (NULL == ts->channel)
1818 { 1784 {
1819 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1785 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1820 "Packet dropped, channel to %s not yet ready (%s)\n", 1786 "Packet dropped, channel to %s not yet ready (%s)\n",
1821 print_channel_destination (&ts->destination), 1787 print_channel_destination (&ts->destination),
1822 (NULL == ts->search) 1788 (NULL == ts->search) ? "EXIT search failed"
1823 ? "EXIT search failed" 1789 : "EXIT search active");
1824 : "EXIT search active");
1825 GNUNET_STATISTICS_update (stats, 1790 GNUNET_STATISTICS_update (stats,
1826 gettext_noop ("# Packets dropped (channel not yet online)"), 1791 gettext_noop (
1827 1, 1792 "# Packets dropped (channel not yet online)"),
1793 1,
1828 GNUNET_NO); 1794 GNUNET_NO);
1829 return; 1795 return;
1830 } 1796 }
@@ -1837,19 +1803,21 @@ route_packet (struct DestinationEntry *destination,
1837 { 1803 {
1838 struct GNUNET_EXIT_UdpServiceMessage *usm; 1804 struct GNUNET_EXIT_UdpServiceMessage *usm;
1839 1805
1840 mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) + 1806 mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) + payload_length -
1841 payload_length - sizeof (struct GNUNET_TUN_UdpHeader); 1807 sizeof (struct GNUNET_TUN_UdpHeader);
1842 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1808 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1843 { 1809 {
1844 GNUNET_break (0); 1810 GNUNET_break (0);
1845 return; 1811 return;
1846 } 1812 }
1847 env = GNUNET_MQ_msg_extra (usm, 1813 env = GNUNET_MQ_msg_extra (usm,
1848 payload_length - sizeof (struct GNUNET_TUN_UdpHeader), 1814 payload_length -
1815 sizeof (struct GNUNET_TUN_UdpHeader),
1849 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE); 1816 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE);
1850 /* 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
1851 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) */
1852 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;
1853 usm->destination_port = udp->destination_port; 1821 usm->destination_port = udp->destination_port;
1854 GNUNET_memcpy (&usm[1], 1822 GNUNET_memcpy (&usm[1],
1855 &udp[1], 1823 &udp[1],
@@ -1862,33 +1830,35 @@ route_packet (struct DestinationEntry *destination,
1862 struct in6_addr *ip6dst; 1830 struct in6_addr *ip6dst;
1863 void *payload; 1831 void *payload;
1864 1832
1865 mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + 1833 mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + alen +
1866 alen + payload_length - sizeof (struct GNUNET_TUN_UdpHeader); 1834 payload_length - sizeof (struct GNUNET_TUN_UdpHeader);
1867 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1835 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1868 { 1836 {
1869 GNUNET_break (0); 1837 GNUNET_break (0);
1870 return; 1838 return;
1871 } 1839 }
1872 env = GNUNET_MQ_msg_extra (uim, 1840 env = GNUNET_MQ_msg_extra (uim,
1873 payload_length + alen - sizeof (struct GNUNET_TUN_UdpHeader), 1841 payload_length + alen -
1842 sizeof (struct GNUNET_TUN_UdpHeader),
1874 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET); 1843 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET);
1875 uim->af = htonl (destination->details.exit_destination.af); 1844 uim->af = htonl (destination->details.exit_destination.af);
1876 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;
1877 uim->destination_port = udp->destination_port; 1847 uim->destination_port = udp->destination_port;
1878 switch (destination->details.exit_destination.af) 1848 switch (destination->details.exit_destination.af)
1879 { 1849 {
1880 case AF_INET: 1850 case AF_INET:
1881 ip4dst = (struct in_addr *) &uim[1]; 1851 ip4dst = (struct in_addr *) &uim[1];
1882 *ip4dst = destination->details.exit_destination.ip.v4; 1852 *ip4dst = destination->details.exit_destination.ip.v4;
1883 payload = &ip4dst[1]; 1853 payload = &ip4dst[1];
1884 break; 1854 break;
1885 case AF_INET6: 1855 case AF_INET6:
1886 ip6dst = (struct in6_addr *) &uim[1]; 1856 ip6dst = (struct in6_addr *) &uim[1];
1887 *ip6dst = destination->details.exit_destination.ip.v6; 1857 *ip6dst = destination->details.exit_destination.ip.v6;
1888 payload = &ip6dst[1]; 1858 payload = &ip6dst[1];
1889 break; 1859 break;
1890 default: 1860 default:
1891 GNUNET_assert (0); 1861 GNUNET_assert (0);
1892 } 1862 }
1893 GNUNET_memcpy (payload, 1863 GNUNET_memcpy (payload,
1894 &udp[1], 1864 &udp[1],
@@ -1900,59 +1870,63 @@ route_packet (struct DestinationEntry *destination,
1900 { 1870 {
1901 if (destination->is_service) 1871 if (destination->is_service)
1902 { 1872 {
1903 struct GNUNET_EXIT_TcpServiceStartMessage *tsm; 1873 struct GNUNET_EXIT_TcpServiceStartMessage *tsm;
1904 1874
1905 mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) + 1875 mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) +
1906 payload_length - sizeof (struct GNUNET_TUN_TcpHeader); 1876 payload_length - sizeof (struct GNUNET_TUN_TcpHeader);
1907 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1877 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1908 { 1878 {
1909 GNUNET_break (0); 1879 GNUNET_break (0);
1910 return; 1880 return;
1911 } 1881 }
1912 env = GNUNET_MQ_msg_extra (tsm, 1882 env =
1913 payload_length - sizeof (struct GNUNET_TUN_TcpHeader), 1883 GNUNET_MQ_msg_extra (tsm,
1914 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START); 1884 payload_length -
1915 tsm->reserved = htonl (0); 1885 sizeof (struct GNUNET_TUN_TcpHeader),
1916 tsm->tcp_header = *tcp; 1886 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START);
1917 GNUNET_memcpy (&tsm[1], 1887 tsm->reserved = htonl (0);
1888 tsm->tcp_header = *tcp;
1889 GNUNET_memcpy (&tsm[1],
1918 &tcp[1], 1890 &tcp[1],
1919 payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); 1891 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1920 } 1892 }
1921 else 1893 else
1922 { 1894 {
1923 struct GNUNET_EXIT_TcpInternetStartMessage *tim; 1895 struct GNUNET_EXIT_TcpInternetStartMessage *tim;
1924 struct in_addr *ip4dst; 1896 struct in_addr *ip4dst;
1925 struct in6_addr *ip6dst; 1897 struct in6_addr *ip6dst;
1926 void *payload; 1898 void *payload;
1927 1899
1928 mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + 1900 mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + alen +
1929 alen + payload_length - sizeof (struct GNUNET_TUN_TcpHeader); 1901 payload_length - sizeof (struct GNUNET_TUN_TcpHeader);
1930 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1902 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1931 { 1903 {
1932 GNUNET_break (0); 1904 GNUNET_break (0);
1933 return; 1905 return;
1934 } 1906 }
1935 env = GNUNET_MQ_msg_extra (tim, 1907 env =
1936 payload_length + alen - sizeof (struct GNUNET_TUN_TcpHeader), 1908 GNUNET_MQ_msg_extra (tim,
1937 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START); 1909 payload_length + alen -
1938 tim->af = htonl (destination->details.exit_destination.af); 1910 sizeof (struct GNUNET_TUN_TcpHeader),
1939 tim->tcp_header = *tcp; 1911 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START);
1940 switch (destination->details.exit_destination.af) 1912 tim->af = htonl (destination->details.exit_destination.af);
1941 { 1913 tim->tcp_header = *tcp;
1942 case AF_INET: 1914 switch (destination->details.exit_destination.af)
1943 ip4dst = (struct in_addr *) &tim[1]; 1915 {
1944 *ip4dst = destination->details.exit_destination.ip.v4; 1916 case AF_INET:
1945 payload = &ip4dst[1]; 1917 ip4dst = (struct in_addr *) &tim[1];
1946 break; 1918 *ip4dst = destination->details.exit_destination.ip.v4;
1947 case AF_INET6: 1919 payload = &ip4dst[1];
1948 ip6dst = (struct in6_addr *) &tim[1]; 1920 break;
1949 *ip6dst = destination->details.exit_destination.ip.v6; 1921 case AF_INET6:
1950 payload = &ip6dst[1]; 1922 ip6dst = (struct in6_addr *) &tim[1];
1951 break; 1923 *ip6dst = destination->details.exit_destination.ip.v6;
1952 default: 1924 payload = &ip6dst[1];
1953 GNUNET_assert (0); 1925 break;
1954 } 1926 default:
1955 GNUNET_memcpy (payload, 1927 GNUNET_assert (0);
1928 }
1929 GNUNET_memcpy (payload,
1956 &tcp[1], 1930 &tcp[1],
1957 payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); 1931 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1958 } 1932 }
@@ -1961,22 +1935,23 @@ route_packet (struct DestinationEntry *destination,
1961 { 1935 {
1962 struct GNUNET_EXIT_TcpDataMessage *tdm; 1936 struct GNUNET_EXIT_TcpDataMessage *tdm;
1963 1937
1964 mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + 1938 mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + payload_length -
1965 payload_length - sizeof (struct GNUNET_TUN_TcpHeader); 1939 sizeof (struct GNUNET_TUN_TcpHeader);
1966 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1940 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1967 { 1941 {
1968 GNUNET_break (0); 1942 GNUNET_break (0);
1969 return; 1943 return;
1970 } 1944 }
1971 env = GNUNET_MQ_msg_extra (tdm, 1945 env = GNUNET_MQ_msg_extra (tdm,
1972 payload_length - sizeof (struct GNUNET_TUN_TcpHeader), 1946 payload_length -
1947 sizeof (struct GNUNET_TUN_TcpHeader),
1973 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT); 1948 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT);
1974 tdm->reserved = htonl (0); 1949 tdm->reserved = htonl (0);
1975 tdm->tcp_header = *tcp; 1950 tdm->tcp_header = *tcp;
1976 GNUNET_memcpy (&tdm[1], 1951 GNUNET_memcpy (&tdm[1],
1977 &tcp[1], 1952 &tcp[1],
1978 payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); 1953 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1979 } 1954 }
1980 break; 1955 break;
1981 case IPPROTO_ICMP: 1956 case IPPROTO_ICMP:
1982 case IPPROTO_ICMPV6: 1957 case IPPROTO_ICMPV6:
@@ -1990,62 +1965,67 @@ route_packet (struct DestinationEntry *destination,
1990 switch (af) 1965 switch (af)
1991 { 1966 {
1992 case AF_INET: 1967 case AF_INET:
1993 switch (icmp->type) 1968 switch (icmp->type)
1994 { 1969 {
1995 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 1970 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
1996 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 1971 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
1997 break; 1972 break;
1998 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 1973 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
1999 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 1974 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
2000 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 1975 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
2001 /* 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 */
2002 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 1977 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2003 break; 1978 break;
2004 default: 1979 default:
2005 GNUNET_STATISTICS_update (stats, 1980 GNUNET_STATISTICS_update (stats,
2006 gettext_noop ("# ICMPv4 packets dropped (not allowed)"), 1981 gettext_noop (
2007 1, GNUNET_NO); 1982 "# ICMPv4 packets dropped (not allowed)"),
2008 return; 1983 1,
2009 } 1984 GNUNET_NO);
2010 /* end of AF_INET */ 1985 return;
2011 break; 1986 }
1987 /* end of AF_INET */
1988 break;
2012 case AF_INET6: 1989 case AF_INET6:
2013 switch (icmp->type) 1990 switch (icmp->type)
2014 { 1991 {
2015 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 1992 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
2016 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 1993 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
2017 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 1994 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
2018 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 1995 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
2019 /* 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 */
2020 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 1997 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2021 break; 1998 break;
2022 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 1999 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
2023 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: 2000 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
2024 break; 2001 break;
2025 default: 2002 default:
2026 GNUNET_STATISTICS_update (stats, 2003 GNUNET_STATISTICS_update (stats,
2027 gettext_noop ("# ICMPv6 packets dropped (not allowed)"), 2004 gettext_noop (
2028 1, GNUNET_NO); 2005 "# ICMPv6 packets dropped (not allowed)"),
2029 return; 2006 1,
2030 } 2007 GNUNET_NO);
2031 /* end of AF_INET6 */ 2008 return;
2032 break; 2009 }
2010 /* end of AF_INET6 */
2011 break;
2033 default: 2012 default:
2034 GNUNET_assert (0); 2013 GNUNET_assert (0);
2035 break; 2014 break;
2036 } 2015 }
2037 2016
2038 /* update length calculations, as payload_length may have changed */ 2017 /* update length calculations, as payload_length may have changed */
2039 mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + 2018 mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + alen +
2040 alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); 2019 payload_length - sizeof (struct GNUNET_TUN_IcmpHeader);
2041 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 2020 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
2042 { 2021 {
2043 GNUNET_break (0); 2022 GNUNET_break (0);
2044 return; 2023 return;
2045 } 2024 }
2046 2025
2047 env = GNUNET_MQ_msg_extra (ism, 2026 env = GNUNET_MQ_msg_extra (ism,
2048 payload_length - sizeof (struct GNUNET_TUN_IcmpHeader), 2027 payload_length -
2028 sizeof (struct GNUNET_TUN_IcmpHeader),
2049 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE); 2029 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE);
2050 ism->af = htonl (af); /* need to tell destination ICMP protocol family! */ 2030 ism->af = htonl (af); /* need to tell destination ICMP protocol family! */
2051 ism->icmp_header = *icmp; 2031 ism->icmp_header = *icmp;
@@ -2067,114 +2047,125 @@ route_packet (struct DestinationEntry *destination,
2067 switch (af) 2047 switch (af)
2068 { 2048 {
2069 case AF_INET: 2049 case AF_INET:
2070 switch (icmp->type) 2050 switch (icmp->type)
2071 { 2051 {
2072 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 2052 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
2073 if (destination->details.exit_destination.af == AF_INET6) 2053 if (destination->details.exit_destination.af == AF_INET6)
2074 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; 2054 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY;
2075 break; 2055 break;
2076 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 2056 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
2077 if (destination->details.exit_destination.af == AF_INET6) 2057 if (destination->details.exit_destination.af == AF_INET6)
2078 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; 2058 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST;
2079 break; 2059 break;
2080 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 2060 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
2081 if (destination->details.exit_destination.af == AF_INET6) 2061 if (destination->details.exit_destination.af == AF_INET6)
2082 new_type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; 2062 new_type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE;
2083 /* 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 */
2084 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2064 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2085 break; 2065 break;
2086 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 2066 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
2087 if (destination->details.exit_destination.af == AF_INET6) 2067 if (destination->details.exit_destination.af == AF_INET6)
2088 new_type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; 2068 new_type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED;
2089 /* 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 */
2090 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2070 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2091 break; 2071 break;
2092 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 2072 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
2093 if (destination->details.exit_destination.af == AF_INET6) 2073 if (destination->details.exit_destination.af == AF_INET6)
2094 { 2074 {
2095 GNUNET_STATISTICS_update (stats, 2075 GNUNET_STATISTICS_update (
2096 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), 2076 stats,
2097 1, GNUNET_NO); 2077 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"),
2098 return; 2078 1,
2099 } 2079 GNUNET_NO);
2100 /* throw away IP-payload, exit will have to make it up anyway */ 2080 return;
2101 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2081 }
2102 break; 2082 /* throw away IP-payload, exit will have to make it up anyway */
2103 default: 2083 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2104 GNUNET_STATISTICS_update (stats, 2084 break;
2105 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), 2085 default:
2106 1, GNUNET_NO); 2086 GNUNET_STATISTICS_update (
2107 return; 2087 stats,
2108 } 2088 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
2109 /* end of AF_INET */ 2089 1,
2110 break; 2090 GNUNET_NO);
2091 return;
2092 }
2093 /* end of AF_INET */
2094 break;
2111 case AF_INET6: 2095 case AF_INET6:
2112 switch (icmp->type) 2096 switch (icmp->type)
2113 { 2097 {
2114 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 2098 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
2115 if (destination->details.exit_destination.af == AF_INET) 2099 if (destination->details.exit_destination.af == AF_INET)
2116 new_type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; 2100 new_type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE;
2117 /* 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 */
2118 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2102 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2119 break; 2103 break;
2120 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 2104 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
2121 if (destination->details.exit_destination.af == AF_INET) 2105 if (destination->details.exit_destination.af == AF_INET)
2122 new_type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; 2106 new_type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED;
2123 /* 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 */
2124 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2108 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2125 break; 2109 break;
2126 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 2110 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
2127 if (destination->details.exit_destination.af == AF_INET) 2111 if (destination->details.exit_destination.af == AF_INET)
2128 { 2112 {
2129 GNUNET_STATISTICS_update (stats, 2113 GNUNET_STATISTICS_update (
2130 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), 2114 stats,
2131 1, GNUNET_NO); 2115 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"),
2132 return; 2116 1,
2133 } 2117 GNUNET_NO);
2134 /* throw away IP-payload, exit will have to make it up anyway */ 2118 return;
2135 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2119 }
2136 break; 2120 /* throw away IP-payload, exit will have to make it up anyway */
2137 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 2121 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2138 if (destination->details.exit_destination.af == AF_INET) 2122 break;
2139 { 2123 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
2140 GNUNET_STATISTICS_update (stats, 2124 if (destination->details.exit_destination.af == AF_INET)
2141 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), 2125 {
2142 1, GNUNET_NO); 2126 GNUNET_STATISTICS_update (
2143 return; 2127 stats,
2144 } 2128 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"),
2145 /* throw away IP-payload, exit will have to make it up anyway */ 2129 1,
2146 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2130 GNUNET_NO);
2147 break; 2131 return;
2148 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 2132 }
2149 if (destination->details.exit_destination.af == AF_INET) 2133 /* throw away IP-payload, exit will have to make it up anyway */
2150 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; 2134 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2151 break; 2135 break;
2152 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: 2136 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
2153 if (destination->details.exit_destination.af == AF_INET) 2137 if (destination->details.exit_destination.af == AF_INET)
2154 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; 2138 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST;
2155 break; 2139 break;
2156 default: 2140 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
2157 GNUNET_STATISTICS_update (stats, 2141 if (destination->details.exit_destination.af == AF_INET)
2158 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), 2142 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY;
2159 1, GNUNET_NO); 2143 break;
2160 return; 2144 default:
2161 } 2145 GNUNET_STATISTICS_update (
2162 /* end of AF_INET6 */ 2146 stats,
2163 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;
2164 default: 2154 default:
2165 GNUNET_assert (0); 2155 GNUNET_assert (0);
2166 } 2156 }
2167 2157
2168 /* update length calculations, as payload_length may have changed */ 2158 /* update length calculations, as payload_length may have changed */
2169 mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + 2159 mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + alen +
2170 alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); 2160 payload_length - sizeof (struct GNUNET_TUN_IcmpHeader);
2171 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 2161 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
2172 { 2162 {
2173 GNUNET_break (0); 2163 GNUNET_break (0);
2174 return; 2164 return;
2175 } 2165 }
2176 env = GNUNET_MQ_msg_extra (iim, 2166 env = GNUNET_MQ_msg_extra (iim,
2177 alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader), 2167 alen + payload_length -
2168 sizeof (struct GNUNET_TUN_IcmpHeader),
2178 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET); 2169 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET);
2179 iim->icmp_header = *icmp; 2170 iim->icmp_header = *icmp;
2180 iim->icmp_header.type = new_type; 2171 iim->icmp_header.type = new_type;
@@ -2182,17 +2173,17 @@ route_packet (struct DestinationEntry *destination,
2182 switch (destination->details.exit_destination.af) 2173 switch (destination->details.exit_destination.af)
2183 { 2174 {
2184 case AF_INET: 2175 case AF_INET:
2185 ip4dst = (struct in_addr *) &iim[1]; 2176 ip4dst = (struct in_addr *) &iim[1];
2186 *ip4dst = destination->details.exit_destination.ip.v4; 2177 *ip4dst = destination->details.exit_destination.ip.v4;
2187 payload = &ip4dst[1]; 2178 payload = &ip4dst[1];
2188 break; 2179 break;
2189 case AF_INET6: 2180 case AF_INET6:
2190 ip6dst = (struct in6_addr *) &iim[1]; 2181 ip6dst = (struct in6_addr *) &iim[1];
2191 *ip6dst = destination->details.exit_destination.ip.v6; 2182 *ip6dst = destination->details.exit_destination.ip.v6;
2192 payload = &ip6dst[1]; 2183 payload = &ip6dst[1];
2193 break; 2184 break;
2194 default: 2185 default:
2195 GNUNET_assert (0); 2186 GNUNET_assert (0);
2196 } 2187 }
2197 GNUNET_memcpy (payload, 2188 GNUNET_memcpy (payload,
2198 &icmp[1], 2189 &icmp[1],
@@ -2205,8 +2196,7 @@ route_packet (struct DestinationEntry *destination,
2205 break; 2196 break;
2206 } 2197 }
2207 ts->is_established = GNUNET_YES; 2198 ts->is_established = GNUNET_YES;
2208 send_to_channel (ts, 2199 send_to_channel (ts, env);
2209 env);
2210} 2200}
2211 2201
2212 2202
@@ -2223,8 +2213,7 @@ route_packet (struct DestinationEntry *destination,
2223 * #GNUNET_SYSERR to stop further processing with error 2213 * #GNUNET_SYSERR to stop further processing with error
2224 */ 2214 */
2225static int 2215static int
2226message_token (void *cls, 2216message_token (void *cls, const struct GNUNET_MessageHeader *message)
2227 const struct GNUNET_MessageHeader *message)
2228{ 2217{
2229 const struct GNUNET_TUN_Layer2PacketHeader *tun; 2218 const struct GNUNET_TUN_Layer2PacketHeader *tun;
2230 size_t mlen; 2219 size_t mlen;
@@ -2232,101 +2221,96 @@ message_token (void *cls,
2232 struct DestinationEntry *de; 2221 struct DestinationEntry *de;
2233 2222
2234 GNUNET_STATISTICS_update (stats, 2223 GNUNET_STATISTICS_update (stats,
2235 gettext_noop ("# Packets received from TUN interface"), 2224 gettext_noop (
2236 1, GNUNET_NO); 2225 "# Packets received from TUN interface"),
2226 1,
2227 GNUNET_NO);
2237 mlen = ntohs (message->size); 2228 mlen = ntohs (message->size);
2238 if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || 2229 if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) ||
2239 (mlen < sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader)) ) 2230 (mlen < sizeof (struct GNUNET_MessageHeader) +
2231 sizeof (struct GNUNET_TUN_Layer2PacketHeader)))
2240 { 2232 {
2241 GNUNET_break (0); 2233 GNUNET_break (0);
2242 return GNUNET_OK; 2234 return GNUNET_OK;
2243 } 2235 }
2244 tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1]; 2236 tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1];
2245 mlen -= (sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader)); 2237 mlen -= (sizeof (struct GNUNET_MessageHeader) +
2238 sizeof (struct GNUNET_TUN_Layer2PacketHeader));
2246 switch (ntohs (tun->proto)) 2239 switch (ntohs (tun->proto))
2247 { 2240 {
2248 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))
2249 { 2245 {
2250 const struct GNUNET_TUN_IPv6Header *pkt6; 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)
2254 {
2255 char buf[INET6_ADDRSTRLEN];
2251 2256
2252 if (mlen < sizeof (struct GNUNET_TUN_IPv6Header)) 2257 GNUNET_log (
2253 { 2258 GNUNET_ERROR_TYPE_INFO,
2254 /* blame kernel */ 2259 _ ("Packet received for unmapped destination `%s' (dropping it)\n"),
2255 GNUNET_break (0); 2260 inet_ntop (AF_INET6, &pkt6->destination_address, buf, sizeof (buf)));
2256 return GNUNET_OK; 2261 return GNUNET_OK;
2257 }
2258 pkt6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1];
2259 get_destination_key_from_ip (AF_INET6,
2260 &pkt6->destination_address,
2261 &key);
2262 de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key);
2263 if (NULL == de)
2264 {
2265 char buf[INET6_ADDRSTRLEN];
2266
2267 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2268 _("Packet received for unmapped destination `%s' (dropping it)\n"),
2269 inet_ntop (AF_INET6,
2270 &pkt6->destination_address,
2271 buf,
2272 sizeof (buf)));
2273 return GNUNET_OK;
2274 }
2275 route_packet (de,
2276 AF_INET6,
2277 pkt6->next_header,
2278 &pkt6->source_address,
2279 &pkt6->destination_address,
2280 &pkt6[1],
2281 mlen - sizeof (struct GNUNET_TUN_IPv6Header));
2282 } 2262 }
2283 break; 2263 route_packet (de,
2284 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))
2285 { 2276 {
2286 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];
2287 2287
2288 if (mlen < sizeof (struct GNUNET_TUN_IPv4Header)) 2288 GNUNET_log (
2289 { 2289 GNUNET_ERROR_TYPE_INFO,
2290 /* blame kernel */ 2290 _ ("Packet received for unmapped destination `%s' (dropping it)\n"),
2291 GNUNET_break (0); 2291 inet_ntop (AF_INET, &pkt4->destination_address, buf, sizeof (buf)));
2292 return GNUNET_OK; 2292 return GNUNET_OK;
2293 }
2294 pkt4 = (struct GNUNET_TUN_IPv4Header *) &tun[1];
2295 get_destination_key_from_ip (AF_INET,
2296 &pkt4->destination_address,
2297 &key);
2298 de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key);
2299 if (NULL == de)
2300 {
2301 char buf[INET_ADDRSTRLEN];
2302
2303 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2304 _("Packet received for unmapped destination `%s' (dropping it)\n"),
2305 inet_ntop (AF_INET,
2306 &pkt4->destination_address,
2307 buf,
2308 sizeof (buf)));
2309 return GNUNET_OK;
2310 }
2311 if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header))
2312 {
2313 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2314 _("Received IPv4 packet with options (dropping it)\n"));
2315 return GNUNET_OK;
2316 }
2317 route_packet (de,
2318 AF_INET,
2319 pkt4->protocol,
2320 &pkt4->source_address,
2321 &pkt4->destination_address,
2322 &pkt4[1],
2323 mlen - sizeof (struct GNUNET_TUN_IPv4Header));
2324 } 2293 }
2325 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;
2326 default: 2309 default:
2327 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2310 GNUNET_log (
2328 _("Received packet of unknown protocol %d from TUN (dropping it)\n"), 2311 GNUNET_ERROR_TYPE_INFO,
2329 (unsigned int) ntohs (tun->proto)); 2312 _ ("Received packet of unknown protocol %d from TUN (dropping it)\n"),
2313 (unsigned int) ntohs (tun->proto));
2330 break; 2314 break;
2331 } 2315 }
2332 return GNUNET_OK; 2316 return GNUNET_OK;
@@ -2359,27 +2343,23 @@ allocate_v4_address (struct in_addr *v4)
2359 mask.s_addr = addr.s_addr | ~mask.s_addr; 2343 mask.s_addr = addr.s_addr | ~mask.s_addr;
2360 tries = 0; 2344 tries = 0;
2361 do 2345 do
2346 {
2347 tries++;
2348 if (tries > 16)
2362 { 2349 {
2363 tries++; 2350 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2364 if (tries > 16) 2351 _ (
2365 { 2352 "Failed to find unallocated IPv4 address in VPN's range\n"));
2366 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2353 return GNUNET_SYSERR;
2367 _("Failed to find unallocated IPv4 address in VPN's range\n"));
2368 return GNUNET_SYSERR;
2369 }
2370 /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */
2371 rnd.s_addr = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2372 UINT32_MAX);
2373 v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr;
2374 get_destination_key_from_ip (AF_INET,
2375 v4,
2376 &key);
2377 } 2354 }
2378 while ( (GNUNET_YES == 2355 /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */
2379 GNUNET_CONTAINER_multihashmap_contains (destination_map, 2356 rnd.s_addr =
2380 &key)) || 2357 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
2381 (v4->s_addr == addr.s_addr) || 2358 v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr;
2382 (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));
2383 return GNUNET_OK; 2363 return GNUNET_OK;
2384} 2364}
2385 2365
@@ -2408,39 +2388,33 @@ allocate_v6_address (struct in6_addr *v6)
2408 /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF, 2388 /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF,
2409 thus: */ 2389 thus: */
2410 mask = addr; 2390 mask = addr;
2411 for (i=127;i>=ipv6prefix;i--) 2391 for (i = 127; i >= ipv6prefix; i--)
2412 mask.s6_addr[i / 8] |= (1 << (i % 8)); 2392 mask.s6_addr[i / 8] |= (1 << (i % 8));
2413 2393
2414 /* 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 */
2415 tries = 0; 2395 tries = 0;
2416 do 2396 do
2397 {
2398 tries++;
2399 if (tries > 16)
2400 {
2401 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2402 _ (
2403 "Failed to find unallocated IPv6 address in VPN's range\n"));
2404 return GNUNET_SYSERR;
2405 }
2406 for (i = 0; i < 16; i++)
2417 { 2407 {
2418 tries++; 2408 rnd.s6_addr[i] =
2419 if (tries > 16) 2409 (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2420 { 2410 256);
2421 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2411 v6->s6_addr[i] = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i];
2422 _("Failed to find unallocated IPv6 address in VPN's range\n"));
2423 return GNUNET_SYSERR;
2424
2425 }
2426 for (i=0;i<16;i++)
2427 {
2428 rnd.s6_addr[i] = (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2429 256);
2430 v6->s6_addr[i]
2431 = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i];
2432 }
2433 get_destination_key_from_ip (AF_INET6,
2434 v6,
2435 &key);
2436 } 2412 }
2437 while ( (GNUNET_YES == 2413 get_destination_key_from_ip (AF_INET6, v6, &key);
2438 GNUNET_CONTAINER_multihashmap_contains (destination_map, 2414 } while ((GNUNET_YES ==
2439 &key)) || 2415 GNUNET_CONTAINER_multihashmap_contains (destination_map, &key)) ||
2440 (0 == GNUNET_memcmp (v6, 2416 (0 == GNUNET_memcmp (v6, &addr)) ||
2441 &addr)) || 2417 (0 == GNUNET_memcmp (v6, &mask)));
2442 (0 == GNUNET_memcmp (v6,
2443 &mask)) );
2444 return GNUNET_OK; 2418 return GNUNET_OK;
2445} 2419}
2446 2420
@@ -2456,26 +2430,24 @@ free_destination_entry (struct DestinationEntry *de)
2456 struct DestinationChannel *dt; 2430 struct DestinationChannel *dt;
2457 2431
2458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2459 "Cleaning up destination entry `%s'\n", 2433 "Cleaning up destination entry `%s'\n",
2460 print_channel_destination (de)); 2434 print_channel_destination (de));
2461 GNUNET_STATISTICS_update (stats, 2435 GNUNET_STATISTICS_update (stats,
2462 gettext_noop ("# Active destinations"), 2436 gettext_noop ("# Active destinations"),
2463 -1, GNUNET_NO); 2437 -1,
2438 GNUNET_NO);
2464 while (NULL != (dt = de->dt_head)) 2439 while (NULL != (dt = de->dt_head))
2465 { 2440 {
2466 GNUNET_CONTAINER_DLL_remove (de->dt_head, 2441 GNUNET_CONTAINER_DLL_remove (de->dt_head, de->dt_tail, dt);
2467 de->dt_tail,
2468 dt);
2469 GNUNET_free (dt); 2442 GNUNET_free (dt);
2470 } 2443 }
2471 if (NULL != de->heap_node) 2444 if (NULL != de->heap_node)
2472 { 2445 {
2473 GNUNET_CONTAINER_heap_remove_node (de->heap_node); 2446 GNUNET_CONTAINER_heap_remove_node (de->heap_node);
2474 de->heap_node = NULL; 2447 de->heap_node = NULL;
2475 GNUNET_assert (GNUNET_YES == 2448 GNUNET_assert (
2476 GNUNET_CONTAINER_multihashmap_remove (destination_map, 2449 GNUNET_YES ==
2477 &de->key, 2450 GNUNET_CONTAINER_multihashmap_remove (destination_map, &de->key, de));
2478 de));
2479 } 2451 }
2480 GNUNET_free (de); 2452 GNUNET_free (de);
2481} 2453}
@@ -2515,36 +2487,32 @@ expire_destination (struct DestinationEntry *except)
2515 */ 2487 */
2516static int 2488static int
2517allocate_response_ip (int *result_af, 2489allocate_response_ip (int *result_af,
2518 void **addr, 2490 void **addr,
2519 struct in_addr *v4, 2491 struct in_addr *v4,
2520 struct in6_addr *v6) 2492 struct in6_addr *v6)
2521{ 2493{
2522 *addr = NULL; 2494 *addr = NULL;
2523 switch (*result_af) 2495 switch (*result_af)
2524 { 2496 {
2525 case AF_INET: 2497 case AF_INET:
2526 if (GNUNET_OK != 2498 if (GNUNET_OK != allocate_v4_address (v4))
2527 allocate_v4_address (v4))
2528 *result_af = AF_UNSPEC; 2499 *result_af = AF_UNSPEC;
2529 else 2500 else
2530 *addr = v4; 2501 *addr = v4;
2531 break; 2502 break;
2532 case AF_INET6: 2503 case AF_INET6:
2533 if (GNUNET_OK != 2504 if (GNUNET_OK != allocate_v6_address (v6))
2534 allocate_v6_address (v6))
2535 *result_af = AF_UNSPEC; 2505 *result_af = AF_UNSPEC;
2536 else 2506 else
2537 *addr = v6; 2507 *addr = v6;
2538 break; 2508 break;
2539 case AF_UNSPEC: 2509 case AF_UNSPEC:
2540 if (GNUNET_OK == 2510 if (GNUNET_OK == allocate_v4_address (v4))
2541 allocate_v4_address (v4))
2542 { 2511 {
2543 *addr = v4; 2512 *addr = v4;
2544 *result_af = AF_INET; 2513 *result_af = AF_INET;
2545 } 2514 }
2546 else if (GNUNET_OK == 2515 else if (GNUNET_OK == allocate_v6_address (v6))
2547 allocate_v6_address (v6))
2548 { 2516 {
2549 *addr = v6; 2517 *addr = v6;
2550 *result_af = AF_INET6; 2518 *result_af = AF_INET6;
@@ -2626,18 +2594,13 @@ handle_client_redirect_to_ip (void *cls,
2626 addr_af = (int) htonl (msg->addr_af); 2594 addr_af = (int) htonl (msg->addr_af);
2627 /* allocate response IP */ 2595 /* allocate response IP */
2628 result_af = (int) htonl (msg->result_af); 2596 result_af = (int) htonl (msg->result_af);
2629 if (GNUNET_OK != allocate_response_ip (&result_af, 2597 if (GNUNET_OK != allocate_response_ip (&result_af, &addr, &v4, &v6))
2630 &addr,
2631 &v4, &v6))
2632 { 2598 {
2633 GNUNET_SERVICE_client_drop (client); 2599 GNUNET_SERVICE_client_drop (client);
2634 return; 2600 return;
2635 } 2601 }
2636 /* send reply with our IP address */ 2602 /* send reply with our IP address */
2637 send_client_reply (client, 2603 send_client_reply (client, msg->request_id, result_af, addr);
2638 msg->request_id,
2639 result_af,
2640 addr);
2641 if (result_af == AF_UNSPEC) 2604 if (result_af == AF_UNSPEC)
2642 { 2605 {
2643 /* failure, we're done */ 2606 /* failure, we're done */
@@ -2650,40 +2613,34 @@ handle_client_redirect_to_ip (void *cls,
2650 char dbuf[INET6_ADDRSTRLEN]; 2613 char dbuf[INET6_ADDRSTRLEN];
2651 2614
2652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2653 "Allocated address %s for redirection via exit to %s\n", 2616 "Allocated address %s for redirection via exit to %s\n",
2654 inet_ntop (result_af, 2617 inet_ntop (result_af, addr, sbuf, sizeof (sbuf)),
2655 addr, 2618 inet_ntop (addr_af, &msg[1], dbuf, sizeof (dbuf)));
2656 sbuf,
2657 sizeof (sbuf)),
2658 inet_ntop (addr_af,
2659 &msg[1],
2660 dbuf,
2661 sizeof (dbuf)));
2662 } 2619 }
2663 2620
2664 /* setup destination record */ 2621 /* setup destination record */
2665 de = GNUNET_new (struct DestinationEntry); 2622 de = GNUNET_new (struct DestinationEntry);
2666 de->is_service = GNUNET_NO; 2623 de->is_service = GNUNET_NO;
2667 de->details.exit_destination.af = addr_af; 2624 de->details.exit_destination.af = addr_af;
2668 GNUNET_memcpy (&de->details.exit_destination.ip, 2625 GNUNET_memcpy (&de->details.exit_destination.ip, &msg[1], alen);
2669 &msg[1], 2626 get_destination_key_from_ip (result_af, addr, &key);
2670 alen);
2671 get_destination_key_from_ip (result_af,
2672 addr,
2673 &key);
2674 de->key = key; 2627 de->key = key;
2675 GNUNET_assert (GNUNET_OK == 2628 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
2676 GNUNET_CONTAINER_multihashmap_put (destination_map, 2629 destination_map,
2677 &key, 2630 &key,
2678 de, 2631 de,
2679 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 2632 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
2680 de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap, 2633 de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap,
2681 de, 2634 de,
2682 GNUNET_TIME_absolute_ntoh (msg->expiration_time).abs_value_us); 2635 GNUNET_TIME_absolute_ntoh (
2636 msg->expiration_time)
2637 .abs_value_us);
2683 GNUNET_STATISTICS_update (stats, 2638 GNUNET_STATISTICS_update (stats,
2684 gettext_noop ("# Active destinations"), 2639 gettext_noop ("# Active destinations"),
2685 1, GNUNET_NO); 2640 1,
2686 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)
2687 expire_destination (de); 2644 expire_destination (de);
2688 GNUNET_SERVICE_client_continue (client); 2645 GNUNET_SERVICE_client_continue (client);
2689} 2646}
@@ -2698,8 +2655,9 @@ handle_client_redirect_to_ip (void *cls,
2698 * @param msg redirection request 2655 * @param msg redirection request
2699 */ 2656 */
2700static void 2657static void
2701handle_client_redirect_to_service (void *cls, 2658handle_client_redirect_to_service (
2702 const struct RedirectToServiceRequestMessage *msg) 2659 void *cls,
2660 const struct RedirectToServiceRequestMessage *msg)
2703{ 2661{
2704 struct GNUNET_SERVICE_Client *client = cls; 2662 struct GNUNET_SERVICE_Client *client = cls;
2705 int result_af; 2663 int result_af;
@@ -2712,25 +2670,18 @@ handle_client_redirect_to_service (void *cls,
2712 2670
2713 /* allocate response IP */ 2671 /* allocate response IP */
2714 result_af = (int) htonl (msg->result_af); 2672 result_af = (int) htonl (msg->result_af);
2715 if (GNUNET_OK != 2673 if (GNUNET_OK != allocate_response_ip (&result_af, &addr, &v4, &v6))
2716 allocate_response_ip (&result_af,
2717 &addr,
2718 &v4,
2719 &v6))
2720 { 2674 {
2721 GNUNET_break (0); 2675 GNUNET_break (0);
2722 GNUNET_SERVICE_client_drop (client); 2676 GNUNET_SERVICE_client_drop (client);
2723 return; 2677 return;
2724 } 2678 }
2725 send_client_reply (client, 2679 send_client_reply (client, msg->request_id, result_af, addr);
2726 msg->request_id,
2727 result_af,
2728 addr);
2729 if (result_af == AF_UNSPEC) 2680 if (result_af == AF_UNSPEC)
2730 { 2681 {
2731 /* failure, we're done */ 2682 /* failure, we're done */
2732 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2683 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2733 _("Failed to allocate IP address for new destination\n")); 2684 _ ("Failed to allocate IP address for new destination\n"));
2734 GNUNET_SERVICE_client_continue (client); 2685 GNUNET_SERVICE_client_continue (client);
2735 return; 2686 return;
2736 } 2687 }
@@ -2739,13 +2690,10 @@ handle_client_redirect_to_service (void *cls,
2739 char sbuf[INET6_ADDRSTRLEN]; 2690 char sbuf[INET6_ADDRSTRLEN];
2740 2691
2741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2742 "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",
2743 inet_ntop (result_af, 2694 inet_ntop (result_af, addr, sbuf, sizeof (sbuf)),
2744 addr, 2695 GNUNET_h2s (&msg->service_descriptor),
2745 sbuf, 2696 GNUNET_i2s (&msg->target));
2746 sizeof (sbuf)),
2747 GNUNET_h2s (&msg->service_descriptor),
2748 GNUNET_i2s (&msg->target));
2749 } 2697 }
2750 2698
2751 /* setup destination record */ 2699 /* setup destination record */
@@ -2753,33 +2701,30 @@ handle_client_redirect_to_service (void *cls,
2753 de->is_service = GNUNET_YES; 2701 de->is_service = GNUNET_YES;
2754 de->details.service_destination.target = msg->target; 2702 de->details.service_destination.target = msg->target;
2755 de->details.service_destination.service_descriptor = msg->service_descriptor; 2703 de->details.service_destination.service_descriptor = msg->service_descriptor;
2756 get_destination_key_from_ip (result_af, 2704 get_destination_key_from_ip (result_af, addr, &key);
2757 addr,
2758 &key);
2759 de->key = key; 2705 de->key = key;
2760 GNUNET_assert (GNUNET_OK == 2706 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
2761 GNUNET_CONTAINER_multihashmap_put (destination_map, 2707 destination_map,
2762 &key, 2708 &key,
2763 de, 2709 de,
2764 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 2710 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
2765 de->heap_node 2711 de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap,
2766 = GNUNET_CONTAINER_heap_insert (destination_heap, 2712 de,
2767 de, 2713 GNUNET_TIME_absolute_ntoh (
2768 GNUNET_TIME_absolute_ntoh (msg->expiration_time).abs_value_us); 2714 msg->expiration_time)
2769 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)
2770 expire_destination (de); 2718 expire_destination (de);
2771 2719
2772 dt = GNUNET_new (struct DestinationChannel); 2720 dt = GNUNET_new (struct DestinationChannel);
2773 dt->destination = de; 2721 dt->destination = de;
2774 GNUNET_CONTAINER_DLL_insert (de->dt_head, 2722 GNUNET_CONTAINER_DLL_insert (de->dt_head, de->dt_tail, dt);
2775 de->dt_tail,
2776 dt);
2777 /* we're done */ 2723 /* we're done */
2778 GNUNET_SERVICE_client_continue (client); 2724 GNUNET_SERVICE_client_continue (client);
2779} 2725}
2780 2726
2781 2727
2782
2783/** 2728/**
2784 * Free memory occupied by an entry in the destination map. 2729 * Free memory occupied by an entry in the destination map.
2785 * 2730 *
@@ -2789,9 +2734,7 @@ handle_client_redirect_to_service (void *cls,
2789 * @return #GNUNET_OK (continue to iterate) 2734 * @return #GNUNET_OK (continue to iterate)
2790 */ 2735 */
2791static int 2736static int
2792cleanup_destination (void *cls, 2737cleanup_destination (void *cls, const struct GNUNET_HashCode *key, void *value)
2793 const struct GNUNET_HashCode *key,
2794 void *value)
2795{ 2738{
2796 struct DestinationEntry *de = value; 2739 struct DestinationEntry *de = value;
2797 2740
@@ -2809,14 +2752,12 @@ cleanup_destination (void *cls,
2809 * @return #GNUNET_OK (continue to iterate) 2752 * @return #GNUNET_OK (continue to iterate)
2810 */ 2753 */
2811static int 2754static int
2812cleanup_channel (void *cls, 2755cleanup_channel (void *cls, const struct GNUNET_HashCode *key, void *value)
2813 const struct GNUNET_HashCode *key,
2814 void *value)
2815{ 2756{
2816 struct ChannelState *ts = value; 2757 struct ChannelState *ts = value;
2817 2758
2818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2819 "Tearing down channel to `%s' during cleanup\n", 2760 "Tearing down channel to `%s' during cleanup\n",
2820 print_channel_destination (&ts->destination)); 2761 print_channel_destination (&ts->destination));
2821 free_channel_state (ts); 2762 free_channel_state (ts);
2822 return GNUNET_OK; 2763 return GNUNET_OK;
@@ -2833,13 +2774,12 @@ cleanup (void *cls)
2833{ 2774{
2834 unsigned int i; 2775 unsigned int i;
2835 2776
2836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "VPN is shutting down\n");
2837 "VPN is shutting down\n");
2838 if (NULL != destination_map) 2778 if (NULL != destination_map)
2839 { 2779 {
2840 GNUNET_CONTAINER_multihashmap_iterate (destination_map, 2780 GNUNET_CONTAINER_multihashmap_iterate (destination_map,
2841 &cleanup_destination, 2781 &cleanup_destination,
2842 NULL); 2782 NULL);
2843 GNUNET_CONTAINER_multihashmap_destroy (destination_map); 2783 GNUNET_CONTAINER_multihashmap_destroy (destination_map);
2844 destination_map = NULL; 2784 destination_map = NULL;
2845 } 2785 }
@@ -2850,9 +2790,7 @@ cleanup (void *cls)
2850 } 2790 }
2851 if (NULL != channel_map) 2791 if (NULL != channel_map)
2852 { 2792 {
2853 GNUNET_CONTAINER_multihashmap_iterate (channel_map, 2793 GNUNET_CONTAINER_multihashmap_iterate (channel_map, &cleanup_channel, NULL);
2854 &cleanup_channel,
2855 NULL);
2856 GNUNET_CONTAINER_multihashmap_destroy (channel_map); 2794 GNUNET_CONTAINER_multihashmap_destroy (channel_map);
2857 channel_map = NULL; 2795 channel_map = NULL;
2858 } 2796 }
@@ -2877,7 +2815,7 @@ cleanup (void *cls)
2877 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 2815 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
2878 stats = NULL; 2816 stats = NULL;
2879 } 2817 }
2880 for (i=0;i<5;i++) 2818 for (i = 0; i < 5; i++)
2881 GNUNET_free_non_null (vpn_argv[i]); 2819 GNUNET_free_non_null (vpn_argv[i]);
2882} 2820}
2883 2821
@@ -2892,8 +2830,8 @@ cleanup (void *cls)
2892 */ 2830 */
2893static void * 2831static void *
2894client_connect_cb (void *cls, 2832client_connect_cb (void *cls,
2895 struct GNUNET_SERVICE_Client *c, 2833 struct GNUNET_SERVICE_Client *c,
2896 struct GNUNET_MQ_Handle *mq) 2834 struct GNUNET_MQ_Handle *mq)
2897{ 2835{
2898 return c; 2836 return c;
2899} 2837}
@@ -2908,8 +2846,8 @@ client_connect_cb (void *cls,
2908 */ 2846 */
2909static void 2847static void
2910client_disconnect_cb (void *cls, 2848client_disconnect_cb (void *cls,
2911 struct GNUNET_SERVICE_Client *c, 2849 struct GNUNET_SERVICE_Client *c,
2912 void *internal_cls) 2850 void *internal_cls)
2913{ 2851{
2914 GNUNET_assert (c == internal_cls); 2852 GNUNET_assert (c == internal_cls);
2915} 2853}
@@ -2936,17 +2874,17 @@ run (void *cls,
2936 struct in6_addr v6; 2874 struct in6_addr v6;
2937 char *binary; 2875 char *binary;
2938 2876
2939 cfg = cfg_; 2877 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn");
2940 binary = GNUNET_OS_get_suid_binary_path (cfg, "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 or the path is invalid, refusing to run.\n", 2886 "`%s' is not SUID, refusing to run.\n",
2949 binary); 2887 "gnunet-helper-vpn");
2950 GNUNET_free (binary); 2888 GNUNET_free (binary);
2951 global_ret = 1; 2889 global_ret = 1;
2952 /* we won't "really" exit here, as the 'service' is still running; 2890 /* we won't "really" exit here, as the 'service' is still running;
@@ -2954,23 +2892,29 @@ run (void *cls,
2954 anything either */ 2892 anything either */
2955 return; 2893 return;
2956 } 2894 }
2895 GNUNET_free (binary);
2896 cfg = cfg_;
2957 stats = GNUNET_STATISTICS_create ("vpn", cfg); 2897 stats = GNUNET_STATISTICS_create ("vpn", cfg);
2958 if (GNUNET_OK != 2898 if (GNUNET_OK !=
2959 GNUNET_CONFIGURATION_get_value_number (cfg, 2899 GNUNET_CONFIGURATION_get_value_number (cfg,
2960 "VPN", 2900 "VPN",
2961 "MAX_MAPPING", 2901 "MAX_MAPPING",
2962 &max_destination_mappings)) 2902 &max_destination_mappings))
2963 max_destination_mappings = 200; 2903 max_destination_mappings = 200;
2964 if (GNUNET_OK != 2904 if (GNUNET_OK !=
2965 GNUNET_CONFIGURATION_get_value_number (cfg, 2905 GNUNET_CONFIGURATION_get_value_number (cfg,
2966 "VPN", 2906 "VPN",
2967 "MAX_TUNNELS", 2907 "MAX_TUNNELS",
2968 &max_channel_mappings)) 2908 &max_channel_mappings))
2969 max_channel_mappings = 200; 2909 max_channel_mappings = 200;
2970 2910
2971 destination_map = GNUNET_CONTAINER_multihashmap_create (max_destination_mappings * 2, GNUNET_NO); 2911 destination_map =
2972 destination_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 2912 GNUNET_CONTAINER_multihashmap_create (max_destination_mappings * 2,
2973 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);
2974 channel_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 2918 channel_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2975 2919
2976 2920
@@ -2979,7 +2923,6 @@ run (void *cls,
2979 GNUNET_CONFIGURATION_get_value_string (cfg, "VPN", "IFNAME", &ifname)) 2923 GNUNET_CONFIGURATION_get_value_string (cfg, "VPN", "IFNAME", &ifname))
2980 { 2924 {
2981 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "VPN", "IFNAME"); 2925 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "VPN", "IFNAME");
2982 GNUNET_free (binary);
2983 GNUNET_SCHEDULER_shutdown (); 2926 GNUNET_SCHEDULER_shutdown ();
2984 return; 2927 return;
2985 } 2928 }
@@ -2987,40 +2930,43 @@ run (void *cls,
2987 ipv6addr = NULL; 2930 ipv6addr = NULL;
2988 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6)) 2931 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6))
2989 { 2932 {
2990 if ( (GNUNET_SYSERR == 2933 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
2991 GNUNET_CONFIGURATION_get_value_string (cfg, "VPN", "IPV6ADDR", 2934 "VPN",
2992 &ipv6addr) || 2935 "IPV6ADDR",
2993 (1 != inet_pton (AF_INET6, ipv6addr, &v6))) ) 2936 &ipv6addr) ||
2937 (1 != inet_pton (AF_INET6, ipv6addr, &v6))))
2994 { 2938 {
2995 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6ADDR", 2939 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
2996 _("Must specify valid IPv6 address")); 2940 "VPN",
2997 GNUNET_free (binary); 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_free (binary);
3010 GNUNET_SCHEDULER_shutdown (); 2955 GNUNET_SCHEDULER_shutdown ();
3011 GNUNET_free_non_null (ipv6prefix_s); 2956 GNUNET_free_non_null (ipv6prefix_s);
3012 return; 2957 return;
3013 } 2958 }
3014 vpn_argv[3] = ipv6prefix_s; 2959 vpn_argv[3] = ipv6prefix_s;
3015 if ( (GNUNET_OK != 2960 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
3016 GNUNET_CONFIGURATION_get_value_number (cfg, "VPN", 2961 "VPN",
3017 "IPV6PREFIX", 2962 "IPV6PREFIX",
3018 &ipv6prefix)) || 2963 &ipv6prefix)) ||
3019 (ipv6prefix >= 127) ) 2964 (ipv6prefix >= 127))
3020 { 2965 {
3021 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4MASK", 2966 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3022 _("Must specify valid IPv6 mask")); 2967 "VPN",
3023 GNUNET_free (binary); 2968 "IPV4MASK",
2969 _ ("Must specify valid IPv6 mask"));
3024 GNUNET_SCHEDULER_shutdown (); 2970 GNUNET_SCHEDULER_shutdown ();
3025 return; 2971 return;
3026 } 2972 }
@@ -3028,35 +2974,40 @@ run (void *cls,
3028 else 2974 else
3029 { 2975 {
3030 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2976 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3031 _("IPv6 support disabled as this system does not support IPv6\n")); 2977 _ (
2978 "IPv6 support disabled as this system does not support IPv6\n"));
3032 vpn_argv[2] = GNUNET_strdup ("-"); 2979 vpn_argv[2] = GNUNET_strdup ("-");
3033 vpn_argv[3] = GNUNET_strdup ("-"); 2980 vpn_argv[3] = GNUNET_strdup ("-");
3034 } 2981 }
3035 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET)) 2982 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET))
3036 { 2983 {
3037 ipv4addr = NULL; 2984 ipv4addr = NULL;
3038 if ( (GNUNET_SYSERR == 2985 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
3039 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR", 2986 "vpn",
3040 &ipv4addr) || 2987 "IPV4ADDR",
3041 (1 != inet_pton (AF_INET, ipv4addr, &v4))) ) 2988 &ipv4addr) ||
2989 (1 != inet_pton (AF_INET, ipv4addr, &v4))))
3042 { 2990 {
3043 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4ADDR", 2991 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3044 _("Must specify valid IPv4 address")); 2992 "VPN",
3045 GNUNET_free (binary); 2993 "IPV4ADDR",
2994 _ ("Must specify valid IPv4 address"));
3046 GNUNET_SCHEDULER_shutdown (); 2995 GNUNET_SCHEDULER_shutdown ();
3047 GNUNET_free_non_null (ipv4addr); 2996 GNUNET_free_non_null (ipv4addr);
3048 return; 2997 return;
3049 } 2998 }
3050 vpn_argv[4] = ipv4addr; 2999 vpn_argv[4] = ipv4addr;
3051 ipv4mask = NULL; 3000 ipv4mask = NULL;
3052 if ( (GNUNET_SYSERR == 3001 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
3053 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4MASK", 3002 "vpn",
3054 &ipv4mask) || 3003 "IPV4MASK",
3055 (1 != inet_pton (AF_INET, ipv4mask, &v4))) ) 3004 &ipv4mask) ||
3005 (1 != inet_pton (AF_INET, ipv4mask, &v4))))
3056 { 3006 {
3057 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4MASK", 3007 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3058 _("Must specify valid IPv4 mask")); 3008 "VPN",
3059 GNUNET_free (binary); 3009 "IPV4MASK",
3010 _ ("Must specify valid IPv4 mask"));
3060 GNUNET_SCHEDULER_shutdown (); 3011 GNUNET_SCHEDULER_shutdown ();
3061 GNUNET_free_non_null (ipv4mask); 3012 GNUNET_free_non_null (ipv4mask);
3062 return; 3013 return;
@@ -3066,45 +3017,44 @@ run (void *cls,
3066 else 3017 else
3067 { 3018 {
3068 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3019 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3069 _("IPv4 support disabled as this system does not support IPv4\n")); 3020 _ (
3021 "IPv4 support disabled as this system does not support IPv4\n"));
3070 vpn_argv[4] = GNUNET_strdup ("-"); 3022 vpn_argv[4] = GNUNET_strdup ("-");
3071 vpn_argv[5] = GNUNET_strdup ("-"); 3023 vpn_argv[5] = GNUNET_strdup ("-");
3072 } 3024 }
3073 vpn_argv[6] = NULL; 3025 vpn_argv[6] = NULL;
3074 3026
3075 cadet_handle = GNUNET_CADET_connect (cfg_); 3027 cadet_handle = GNUNET_CADET_connect (cfg_);
3076 // FIXME never opens ports??? 3028 // FIXME never opens ports???
3077 helper_handle = GNUNET_HELPER_start (GNUNET_NO, 3029 helper_handle = GNUNET_HELPER_start (GNUNET_NO,
3078 binary, 3030 "gnunet-helper-vpn",
3079 vpn_argv, 3031 vpn_argv,
3080 &message_token, 3032 &message_token,
3081 NULL, 3033 NULL,
3082 NULL); 3034 NULL);
3083 GNUNET_free (binary); 3035 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
3084 GNUNET_SCHEDULER_add_shutdown (&cleanup,
3085 NULL);
3086} 3036}
3087 3037
3088 3038
3089/** 3039/**
3090 * Define "main" method using service macro. 3040 * Define "main" method using service macro.
3091 */ 3041 */
3092GNUNET_SERVICE_MAIN 3042GNUNET_SERVICE_MAIN (
3093("vpn", 3043 "vpn",
3094 GNUNET_SERVICE_OPTION_NONE, 3044 GNUNET_SERVICE_OPTION_NONE,
3095 &run, 3045 &run,
3096 &client_connect_cb, 3046 &client_connect_cb,
3097 &client_disconnect_cb, 3047 &client_disconnect_cb,
3098 NULL, 3048 NULL,
3099 GNUNET_MQ_hd_var_size (client_redirect_to_ip, 3049 GNUNET_MQ_hd_var_size (client_redirect_to_ip,
3100 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, 3050 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP,
3101 struct RedirectToIpRequestMessage, 3051 struct RedirectToIpRequestMessage,
3102 NULL), 3052 NULL),
3103 GNUNET_MQ_hd_fixed_size (client_redirect_to_service, 3053 GNUNET_MQ_hd_fixed_size (client_redirect_to_service,
3104 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE, 3054 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE,
3105 struct RedirectToServiceRequestMessage, 3055 struct RedirectToServiceRequestMessage,
3106 NULL), 3056 NULL),
3107 GNUNET_MQ_handler_end ()); 3057 GNUNET_MQ_handler_end ());
3108 3058
3109 3059
3110/* end of gnunet-service-vpn.c */ 3060/* end of gnunet-service-vpn.c */