aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2020-06-05 16:37:10 +0200
committert3sserakt <t3ss@posteo.de>2020-06-05 16:37:10 +0200
commitd22eacb13eb676b5c096b47c72a3fdbdb332d5a5 (patch)
tree9be948a80a6be2c56080be8826cba747de9dce57
parent59f616a3c5d8a6873de0090d0db1413c8b9c411d (diff)
downloadgnunet-d22eacb13eb676b5c096b47c72a3fdbdb332d5a5.tar.gz
gnunet-d22eacb13eb676b5c096b47c72a3fdbdb332d5a5.zip
Fixed bug #5822 by adding a monotonic time to the connection create message of a peer that want to start a KX, and the corresponding test #5823. Credits to dvn, lurchi and xrs for helpful discussions and coding.
-rw-r--r--src/cadet/Makefile.am5
-rw-r--r--src/cadet/cadet.h87
-rw-r--r--src/cadet/cadet_api.c66
-rw-r--r--src/cadet/cadet_protocol.h18
-rw-r--r--src/cadet/gnunet-service-cadet.c112
-rw-r--r--src/cadet/gnunet-service-cadet.h1
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c46
-rw-r--r--src/cadet/gnunet-service-cadet_channel.h17
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c47
-rw-r--r--src/cadet/gnunet-service-cadet_connection.h22
-rw-r--r--src/cadet/gnunet-service-cadet_core.c15
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c63
-rw-r--r--src/cadet/gnunet-service-cadet_peer.h9
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.c43
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.h21
-rw-r--r--src/cadet/test_cadet.c365
-rw-r--r--src/cadet/test_cadet.conf7
-rw-r--r--src/include/gnunet_protocols.h10
-rw-r--r--src/include/gnunet_signatures.h4
19 files changed, 780 insertions, 178 deletions
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am
index d8d81bf20..2289a2d96 100644
--- a/src/cadet/Makefile.am
+++ b/src/cadet/Makefile.am
@@ -30,6 +30,7 @@ lib_LTLIBRARIES = \
30 30
31libgnunetcadet_la_SOURCES = \ 31libgnunetcadet_la_SOURCES = \
32 cadet_api.c \ 32 cadet_api.c \
33 cadet_api_drop_message.c \
33 cadet_api_get_channel.c \ 34 cadet_api_get_channel.c \
34 cadet_api_get_path.c \ 35 cadet_api_get_path.c \
35 cadet_api_list_peers.c \ 36 cadet_api_list_peers.c \
@@ -95,6 +96,7 @@ check_PROGRAMS = \
95 test_cadet_2_speed_reliable \ 96 test_cadet_2_speed_reliable \
96 test_cadet_2_speed_reliable_backwards \ 97 test_cadet_2_speed_reliable_backwards \
97 test_cadet_2_reopen \ 98 test_cadet_2_reopen \
99 test_cadet_2_destroy \
98 test_cadet_5_forward \ 100 test_cadet_5_forward \
99 test_cadet_5_signal \ 101 test_cadet_5_signal \
100 test_cadet_5_keepalive \ 102 test_cadet_5_keepalive \
@@ -211,6 +213,9 @@ test_cadet_5_reopen_SOURCES = \
211 test_cadet.c 213 test_cadet.c
212test_cadet_5_reopen_LDADD = $(ld_cadet_test_lib) 214test_cadet_5_reopen_LDADD = $(ld_cadet_test_lib)
213 215
216test_cadet_2_destroy_SOURCES = \
217 test_cadet.c
218test_cadet_2_destroy_LDADD = $(ld_cadet_test_lib)
214 219
215if ENABLE_TEST_RUN 220if ENABLE_TEST_RUN
216AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 221AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h
index 29400e39f..d17eab1d6 100644
--- a/src/cadet/cadet.h
+++ b/src/cadet/cadet.h
@@ -95,7 +95,6 @@ extern "C" {
95 95
96GNUNET_NETWORK_STRUCT_BEGIN 96GNUNET_NETWORK_STRUCT_BEGIN
97 97
98
99/** 98/**
100 * Number uniquely identifying a channel of a client. 99 * Number uniquely identifying a channel of a client.
101 */ 100 */
@@ -111,6 +110,70 @@ struct GNUNET_CADET_ClientChannelNumber
111 uint32_t channel_of_client GNUNET_PACKED; 110 uint32_t channel_of_client GNUNET_PACKED;
112}; 111};
113 112
113/**
114 * Opaque handle to a channel.
115 */
116struct GNUNET_CADET_Channel
117{
118
119 /**
120 * Other end of the channel.
121 */
122 struct GNUNET_PeerIdentity peer;
123
124 /**
125 * Handle to the cadet this channel belongs to
126 */
127 struct GNUNET_CADET_Handle *cadet;
128
129 /**
130 * Channel's port, if incoming.
131 */
132 struct GNUNET_CADET_Port *incoming_port;
133
134 /**
135 * Any data the caller wants to put in here, used for the
136 * various callbacks (@e disconnects, @e window_changes, handlers).
137 */
138 void *ctx;
139
140 /**
141 * Message Queue for the channel (which we are implementing).
142 */
143 struct GNUNET_MQ_Handle *mq;
144
145 /**
146 * Task to allow mq to send more traffic.
147 */
148 struct GNUNET_SCHEDULER_Task *mq_cont;
149
150 /**
151 * Pending envelope with a message to be transmitted to the
152 * service as soon as we are allowed to. Should only be
153 * non-NULL if @e allow_send is 0.
154 */
155 struct GNUNET_MQ_Envelope *pending_env;
156
157 /**
158 * Window change handler.
159 */
160 GNUNET_CADET_WindowSizeEventHandler window_changes;
161
162 /**
163 * Disconnect handler.
164 */
165 GNUNET_CADET_DisconnectEventHandler disconnects;
166
167 /**
168 * Local ID of the channel, #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
169 */
170 struct GNUNET_CADET_ClientChannelNumber ccn;
171
172 /**
173 * How many messages are we allowed to send to the service right now?
174 */
175 unsigned int allow_send;
176};
114 177
115/** 178/**
116 * Message for a client to create and destroy channels. 179 * Message for a client to create and destroy channels.
@@ -252,7 +315,29 @@ struct GNUNET_CADET_LocalInfo
252 struct GNUNET_PeerIdentity peer; 315 struct GNUNET_PeerIdentity peer;
253}; 316};
254 317
318/**
319 * Message to drop another message of specific type. Used in test context
320 */
321struct GNUNET_CADET_RequestDropCadetMessage
322{
255 323
324 /**
325 * Type: #GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE
326 */
327 struct GNUNET_MessageHeader header;
328
329 /**
330 * Type of the message this handler covers, in host byte order.
331 */
332 uint16_t type;
333
334 /**
335 * ID of the channel we want to drop a message for.
336 */
337 struct GNUNET_CADET_ClientChannelNumber ccn;
338
339};
340
256/** 341/**
257 * Message to inform the client about channels in the service. 342 * Message to inform the client about channels in the service.
258 */ 343 */
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 3a75266b7..45cb66c1d 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -73,72 +73,6 @@ struct GNUNET_CADET_Handle
73 struct GNUNET_TIME_Relative reconnect_time; 73 struct GNUNET_TIME_Relative reconnect_time;
74}; 74};
75 75
76
77/**
78 * Opaque handle to a channel.
79 */
80struct GNUNET_CADET_Channel
81{
82 /**
83 * Other end of the channel.
84 */
85 struct GNUNET_PeerIdentity peer;
86
87 /**
88 * Handle to the cadet this channel belongs to
89 */
90 struct GNUNET_CADET_Handle *cadet;
91
92 /**
93 * Channel's port, if incoming.
94 */
95 struct GNUNET_CADET_Port *incoming_port;
96
97 /**
98 * Any data the caller wants to put in here, used for the
99 * various callbacks (@e disconnects, @e window_changes, handlers).
100 */
101 void *ctx;
102
103 /**
104 * Message Queue for the channel (which we are implementing).
105 */
106 struct GNUNET_MQ_Handle *mq;
107
108 /**
109 * Task to allow mq to send more traffic.
110 */
111 struct GNUNET_SCHEDULER_Task *mq_cont;
112
113 /**
114 * Pending envelope with a message to be transmitted to the
115 * service as soon as we are allowed to. Should only be
116 * non-NULL if @e allow_send is 0.
117 */
118 struct GNUNET_MQ_Envelope *pending_env;
119
120 /**
121 * Window change handler.
122 */
123 GNUNET_CADET_WindowSizeEventHandler window_changes;
124
125 /**
126 * Disconnect handler.
127 */
128 GNUNET_CADET_DisconnectEventHandler disconnects;
129
130 /**
131 * Local ID of the channel, #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
132 */
133 struct GNUNET_CADET_ClientChannelNumber ccn;
134
135 /**
136 * How many messages are we allowed to send to the service right now?
137 */
138 unsigned int allow_send;
139};
140
141
142/** 76/**
143 * Opaque handle to a port. 77 * Opaque handle to a port.
144 */ 78 */
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index e3417f8c4..08298e224 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -85,6 +85,24 @@ struct GNUNET_CADET_ConnectionCreateMessage
85 uint32_t options GNUNET_PACKED; 85 uint32_t options GNUNET_PACKED;
86 86
87 /** 87 /**
88 * This flag indicates the peer sending the connection create
89 * meassage likes to trigger a KX handshake.
90 */
91 int has_monotime;
92
93 /**
94 * This monotonic time is set, if a peer likes to trigger a KX, but is not
95 * the peer that should start the KX. (xrs,t3ss)
96 */
97 struct GNUNET_TIME_AbsoluteNBO monotime;
98
99 /**
100 * We sign the monotime. The receiving peer can check the signature, to verify
101 * the sending peer.
102 */
103 struct GNUNET_CRYPTO_EddsaSignature monotime_sig;
104
105 /**
88 * ID of the connection 106 * ID of the connection
89 */ 107 */
90 struct GNUNET_CADET_ConnectionTunnelIdentifier cid; 108 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c
index ba83fe0fc..03af3d5c0 100644
--- a/src/cadet/gnunet-service-cadet.c
+++ b/src/cadet/gnunet-service-cadet.c
@@ -580,6 +580,7 @@ handle_channel_create (void *cls,
580 if (ntohl (tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 580 if (ntohl (tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
581 { 581 {
582 /* Channel ID not in allowed range. */ 582 /* Channel ID not in allowed range. */
583 LOG (GNUNET_ERROR_TYPE_DEBUG,"Channel ID not in allowed range.");
583 GNUNET_break (0); 584 GNUNET_break (0);
584 GNUNET_SERVICE_client_drop (c->client); 585 GNUNET_SERVICE_client_drop (c->client);
585 return; 586 return;
@@ -589,6 +590,7 @@ handle_channel_create (void *cls,
589 if (NULL != ch) 590 if (NULL != ch)
590 { 591 {
591 /* Channel ID already in use. Not allowed. */ 592 /* Channel ID already in use. Not allowed. */
593 LOG (GNUNET_ERROR_TYPE_DEBUG,"Channel ID already in use. Not allowed.");
592 GNUNET_break (0); 594 GNUNET_break (0);
593 GNUNET_SERVICE_client_drop (c->client); 595 GNUNET_SERVICE_client_drop (c->client);
594 return; 596 return;
@@ -1008,6 +1010,26 @@ handle_info_tunnels (void *cls,
1008 GNUNET_SERVICE_client_continue (c->client); 1010 GNUNET_SERVICE_client_continue (c->client);
1009} 1011}
1010 1012
1013/**
1014 * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE request.
1015 *
1016 * @param cls client Identification of the client.
1017 * @param message The actual message.
1018 */
1019static void
1020handle_drop_message (void *cls,
1021 const struct GNUNET_CADET_RequestDropCadetMessage *message)
1022{
1023 struct CadetClient *c = cls;
1024 struct CadetChannel *ch;
1025
1026 ch = lookup_channel (c,
1027 message->ccn);
1028
1029 GCCH_assign_type_to_drop(ch, message);
1030
1031 GNUNET_SERVICE_client_continue (c->client);
1032}
1011 1033
1012/** 1034/**
1013 * Callback called when a client connects to the service. 1035 * Callback called when a client connects to the service.
@@ -1305,48 +1327,52 @@ run (void *cls,
1305 * Define "main" method using service macro. 1327 * Define "main" method using service macro.
1306 */ 1328 */
1307GNUNET_SERVICE_MAIN 1329GNUNET_SERVICE_MAIN
1308 ("cadet", 1330("cadet",
1309 GNUNET_SERVICE_OPTION_NONE, 1331 GNUNET_SERVICE_OPTION_NONE,
1310 &run, 1332 &run,
1311 &client_connect_cb, 1333 &client_connect_cb,
1312 &client_disconnect_cb, 1334 &client_disconnect_cb,
1313 NULL, 1335 NULL,
1314 GNUNET_MQ_hd_fixed_size (port_open, 1336 GNUNET_MQ_hd_fixed_size (port_open,
1315 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN, 1337 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN,
1316 struct GNUNET_CADET_PortMessage, 1338 struct GNUNET_CADET_PortMessage,
1317 NULL), 1339 NULL),
1318 GNUNET_MQ_hd_fixed_size (port_close, 1340 GNUNET_MQ_hd_fixed_size (port_close,
1319 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE, 1341 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE,
1320 struct GNUNET_CADET_PortMessage, 1342 struct GNUNET_CADET_PortMessage,
1321 NULL), 1343 NULL),
1322 GNUNET_MQ_hd_fixed_size (channel_create, 1344 GNUNET_MQ_hd_fixed_size (channel_create,
1323 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, 1345 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE,
1324 struct GNUNET_CADET_LocalChannelCreateMessage, 1346 struct GNUNET_CADET_LocalChannelCreateMessage,
1325 NULL), 1347 NULL),
1326 GNUNET_MQ_hd_fixed_size (channel_destroy, 1348 GNUNET_MQ_hd_fixed_size (channel_destroy,
1327 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, 1349 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY,
1328 struct GNUNET_CADET_LocalChannelDestroyMessage, 1350 struct GNUNET_CADET_LocalChannelDestroyMessage,
1329 NULL), 1351 NULL),
1330 GNUNET_MQ_hd_var_size (local_data, 1352 GNUNET_MQ_hd_var_size (local_data,
1331 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, 1353 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
1332 struct GNUNET_CADET_LocalData, 1354 struct GNUNET_CADET_LocalData,
1333 NULL), 1355 NULL),
1334 GNUNET_MQ_hd_fixed_size (local_ack, 1356 GNUNET_MQ_hd_fixed_size (local_ack,
1335 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, 1357 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK,
1336 struct GNUNET_CADET_LocalAck, 1358 struct GNUNET_CADET_LocalAck,
1337 NULL), 1359 NULL),
1338 GNUNET_MQ_hd_fixed_size (get_peers, 1360 GNUNET_MQ_hd_fixed_size (get_peers,
1339 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS, 1361 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS,
1340 struct GNUNET_MessageHeader, 1362 struct GNUNET_MessageHeader,
1341 NULL), 1363 NULL),
1342 GNUNET_MQ_hd_fixed_size (show_path, 1364 GNUNET_MQ_hd_fixed_size (show_path,
1343 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH, 1365 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH,
1344 struct GNUNET_CADET_RequestPathInfoMessage, 1366 struct GNUNET_CADET_RequestPathInfoMessage,
1345 NULL), 1367 NULL),
1346 GNUNET_MQ_hd_fixed_size (info_tunnels, 1368 GNUNET_MQ_hd_fixed_size (info_tunnels,
1347 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS, 1369 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS,
1348 struct GNUNET_MessageHeader, 1370 struct GNUNET_MessageHeader,
1349 NULL), 1371 NULL),
1350 GNUNET_MQ_handler_end ()); 1372 GNUNET_MQ_hd_fixed_size (drop_message,
1373 GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE,
1374 struct GNUNET_CADET_RequestDropCadetMessage,
1375 NULL),
1376 GNUNET_MQ_handler_end ());
1351 1377
1352/* end of gnunet-service-cadet-new.c */ 1378/* end of gnunet-service-cadet-new.c */
diff --git a/src/cadet/gnunet-service-cadet.h b/src/cadet/gnunet-service-cadet.h
index 6da0950f1..ff216f8c3 100644
--- a/src/cadet/gnunet-service-cadet.h
+++ b/src/cadet/gnunet-service-cadet.h
@@ -325,4 +325,5 @@ const char *
325GSC_2s (struct CadetClient *c); 325GSC_2s (struct CadetClient *c);
326 326
327 327
328
328#endif 329#endif
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index 5c8103c5e..e6fce562f 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -380,8 +380,44 @@ struct CadetChannel
380 * empty. 380 * empty.
381 */ 381 */
382 int destroy; 382 int destroy;
383
384 /**
385 * Type of message to be droped. See GCT_send.
386 */
387 uint16_t type GNUNET_PACKED;
388
383}; 389};
384 390
391/**
392 * Assign type of message to drop.
393 * @param ch CadetChannel to assign type to drop.
394 * @param message GNUNET_CADET_RequestDropCadetMessage to get the type from.
395 */
396void
397GCCH_assign_type_to_drop(struct CadetChannel *ch, const struct GNUNET_CADET_RequestDropCadetMessage *message)
398{
399
400 ch->type = message->type;
401
402}
403
404/**
405 * Check if type of message is the one to drop.
406 * @param ch CadetChannel to check for message type to drop.
407 * @param message GNUNET_MessageHeader to compare the type with.
408 */
409int
410GCCH_is_type_to_drop(struct CadetChannel *ch, const struct GNUNET_MessageHeader *message)
411{
412
413 if (ch->type == message->type)
414 {
415 ch->type = 0;
416 return GNUNET_YES;
417 }
418 else
419 return GNUNET_NO;
420}
385 421
386/** 422/**
387 * Get the static string for identification of the channel. 423 * Get the static string for identification of the channel.
@@ -594,7 +630,7 @@ send_channel_open (void *cls)
594 if (NULL != ch->last_control_qe) 630 if (NULL != ch->last_control_qe)
595 GCT_send_cancel (ch->last_control_qe); 631 GCT_send_cancel (ch->last_control_qe);
596 ch->last_control_qe = 632 ch->last_control_qe =
597 GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch); 633 GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch, &msgcc.ctn);
598 GNUNET_assert (NULL == ch->retry_control_task); 634 GNUNET_assert (NULL == ch->retry_control_task);
599} 635}
600 636
@@ -818,7 +854,7 @@ send_channel_data_ack (struct CadetChannel *ch)
818 GCCH_2s (ch)); 854 GCCH_2s (ch));
819 if (NULL != ch->last_control_qe) 855 if (NULL != ch->last_control_qe)
820 GCT_send_cancel (ch->last_control_qe); 856 GCT_send_cancel (ch->last_control_qe);
821 ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); 857 ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch, &msg.ctn);
822} 858}
823 859
824 860
@@ -845,7 +881,7 @@ send_open_ack (void *cls)
845 msg.port = ch->port; 881 msg.port = ch->port;
846 if (NULL != ch->last_control_qe) 882 if (NULL != ch->last_control_qe)
847 GCT_send_cancel (ch->last_control_qe); 883 GCT_send_cancel (ch->last_control_qe);
848 ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); 884 ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch, &msg.ctn);
849} 885}
850 886
851 887
@@ -1477,7 +1513,7 @@ retry_transmission (void *cls)
1477 "Retrying transmission on %s of message %u\n", 1513 "Retrying transmission on %s of message %u\n",
1478 GCCH_2s (ch), 1514 GCCH_2s (ch),
1479 (unsigned int) ntohl (crm->data_message->mid.mid)); 1515 (unsigned int) ntohl (crm->data_message->mid.mid));
1480 crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); 1516 crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm, &crm->data_message->ctn);
1481 GNUNET_assert (NULL == ch->retry_data_task); 1517 GNUNET_assert (NULL == ch->retry_data_task);
1482} 1518}
1483 1519
@@ -1865,7 +1901,7 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1865 GNUNET_SCHEDULER_cancel (ch->retry_data_task); 1901 GNUNET_SCHEDULER_cancel (ch->retry_data_task);
1866 ch->retry_data_task = NULL; 1902 ch->retry_data_task = NULL;
1867 } 1903 }
1868 crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); 1904 crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm, &crm->data_message->ctn);
1869 GNUNET_assert (NULL == ch->retry_data_task); 1905 GNUNET_assert (NULL == ch->retry_data_task);
1870 return GNUNET_OK; 1906 return GNUNET_OK;
1871} 1907}
diff --git a/src/cadet/gnunet-service-cadet_channel.h b/src/cadet/gnunet-service-cadet_channel.h
index 0a6c97329..7a072f128 100644
--- a/src/cadet/gnunet-service-cadet_channel.h
+++ b/src/cadet/gnunet-service-cadet_channel.h
@@ -57,6 +57,23 @@ GCCH_hash_port (struct GNUNET_HashCode *h_port,
57 const struct GNUNET_HashCode *port, 57 const struct GNUNET_HashCode *port,
58 const struct GNUNET_PeerIdentity *listener); 58 const struct GNUNET_PeerIdentity *listener);
59 59
60/**
61 * Check if type of message is the one to drop.
62 * @param ch CadetChannel to check for message type to drop.
63 * @param message GNUNET_MessageHeader to compare the type with.
64 */
65int
66GCCH_is_type_to_drop (struct CadetChannel *ch, const struct
67 GNUNET_MessageHeader *message);
68
69/**
70 * Check if type of message is the one to drop.
71 * @param ch CadetChannel to assign type to drop.
72 * @param message GNUNET_CADET_RequestDropCadetMessage to get the type from.
73 */
74void
75GCCH_assign_type_to_drop (struct CadetChannel *ch, const struct
76 GNUNET_CADET_RequestDropCadetMessage *message);
60 77
61/** 78/**
62 * Get the static string for identification of the channel. 79 * Get the static string for identification of the channel.
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index c07339ebc..1dac9eb1e 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -26,6 +26,7 @@
26 * @author Christian Grothoff 26 * @author Christian Grothoff
27 */ 27 */
28#include "platform.h" 28#include "platform.h"
29#include "gnunet_signatures.h"
29#include "gnunet-service-cadet_connection.h" 30#include "gnunet-service-cadet_connection.h"
30#include "gnunet-service-cadet_channel.h" 31#include "gnunet-service-cadet_channel.h"
31#include "gnunet-service-cadet_paths.h" 32#include "gnunet-service-cadet_paths.h"
@@ -78,7 +79,6 @@ enum CadetConnectionState
78 CADET_CONNECTION_READY 79 CADET_CONNECTION_READY
79}; 80};
80 81
81
82/** 82/**
83 * Low-level connection to a destination. 83 * Low-level connection to a destination.
84 */ 84 */
@@ -206,6 +206,14 @@ update_state (struct CadetConnection *cc,
206 int old_ready; 206 int old_ready;
207 int new_ready; 207 int new_ready;
208 208
209 LOG (GNUNET_ERROR_TYPE_DEBUG,
210 "Trying to update connection state for %s having old state %d to new %d and mqm_ready old %d to mqm_ready new %d\n",
211 GCT_2s (cc->ct->t),
212 cc->state,
213 new_state,
214 cc->mqm_ready,
215 new_mqm_ready);
216
209 if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready)) 217 if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready))
210 return; /* no change, nothing to do */ 218 return; /* no change, nothing to do */
211 old_ready = 219 old_ready =
@@ -214,6 +222,13 @@ update_state (struct CadetConnection *cc,
214 ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready)); 222 ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready));
215 cc->state = new_state; 223 cc->state = new_state;
216 cc->mqm_ready = new_mqm_ready; 224 cc->mqm_ready = new_mqm_ready;
225
226 LOG (GNUNET_ERROR_TYPE_DEBUG,
227 "Updating connection state for %s having old_ready %d and new_rady %d\n",
228 GCT_2s (cc->ct->t),
229 old_ready,
230 new_ready);
231
217 if (old_ready != new_ready) 232 if (old_ready != new_ready)
218 cc->ready_cb (cc->ready_cb_cls, new_ready); 233 cc->ready_cb (cc->ready_cb_cls, new_ready);
219} 234}
@@ -392,7 +407,7 @@ send_keepalive (void *cls)
392 msg.size = htons (sizeof(msg)); 407 msg.size = htons (sizeof(msg));
393 msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); 408 msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE);
394 409
395 cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc); 410 cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc, NULL);
396} 411}
397 412
398 413
@@ -580,6 +595,20 @@ GCC_handle_encrypted (struct CadetConnection *cc,
580} 595}
581 596
582 597
598void
599set_monotime_sig (struct GNUNET_CADET_ConnectionCreateMessage *msg)
600{
601
602 struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl (
603 GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR),
604 .purpose.size = htonl (sizeof(cp)),
605 .monotonic_time = msg->monotime};
606
607 GNUNET_CRYPTO_eddsa_sign (my_private_key, &cp,
608 &msg->monotime_sig);
609
610}
611
583/** 612/**
584 * Send a #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the 613 * Send a #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the
585 * first hop. 614 * first hop.
@@ -593,6 +622,7 @@ send_create (void *cls)
593 struct GNUNET_CADET_ConnectionCreateMessage *create_msg; 622 struct GNUNET_CADET_ConnectionCreateMessage *create_msg;
594 struct GNUNET_PeerIdentity *pids; 623 struct GNUNET_PeerIdentity *pids;
595 struct GNUNET_MQ_Envelope *env; 624 struct GNUNET_MQ_Envelope *env;
625 struct CadetTunnel *t;
596 626
597 cc->task = NULL; 627 cc->task = NULL;
598 GNUNET_assert (GNUNET_YES == cc->mqm_ready); 628 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
@@ -603,6 +633,18 @@ send_create (void *cls)
603 // 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. 633 // 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.
604 create_msg->options = 2; 634 create_msg->options = 2;
605 create_msg->cid = cc->cid; 635 create_msg->cid = cc->cid;
636
637 // check for tunnel state and set signed monotime (xrs,t3ss)
638 t = GCP_get_tunnel (cc->destination, GNUNET_YES);
639 if ((NULL != t)&& (GCT_get_estate (t) == CADET_TUNNEL_KEY_UNINITIALIZED) &&
640 (GCT_alice_or_betty (GCP_get_id (cc->destination)) == GNUNET_NO))
641 {
642 create_msg->has_monotime = GNUNET_YES;
643 create_msg->monotime = GNUNET_TIME_absolute_hton (
644 GNUNET_TIME_absolute_get_monotonic (cfg));
645 set_monotime_sig (create_msg);
646 }
647
606 pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; 648 pids = (struct GNUNET_PeerIdentity *) &create_msg[1];
607 pids[0] = my_full_id; 649 pids[0] = my_full_id;
608 for (unsigned int i = 0; i <= cc->off; i++) 650 for (unsigned int i = 0; i <= cc->off; i++)
@@ -792,6 +834,7 @@ connection_create (struct CadetPeer *destination,
792 cc = GNUNET_new (struct CadetConnection); 834 cc = GNUNET_new (struct CadetConnection);
793 cc->state = init_state; 835 cc->state = init_state;
794 cc->ct = ct; 836 cc->ct = ct;
837 cc->destination = destination; /* xrs,t3ss,lurchi*/
795 cc->cid = *cid; 838 cc->cid = *cid;
796 cc->retry_delay = 839 cc->retry_delay =
797 GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off); 840 GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off);
diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h
index b05c3b72c..a9ebef567 100644
--- a/src/cadet/gnunet-service-cadet_connection.h
+++ b/src/cadet/gnunet-service-cadet_connection.h
@@ -182,7 +182,29 @@ void
182GCC_handle_kx_auth (struct CadetConnection *cc, 182GCC_handle_kx_auth (struct CadetConnection *cc,
183 const struct 183 const struct
184 GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg); 184 GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
185struct CadetConnectionCreatePS
186{
187
188 /**
189 * Purpose is #GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR
190 */
191 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
185 192
193 /**
194 * Time at the initiator when generating the signature.
195 *
196 * Note that the receiver MUST IGNORE the absolute time, and only interpret
197 * the value as a mononic time and reject "older" values than the last one
198 * observed. This is necessary as we do not want to require synchronized
199 * clocks and may not have a bidirectional communication channel.
200 *
201 * Even with this, there is no real guarantee against replay achieved here,
202 * unless the latest timestamp is persisted. Persistence should be
203 * provided via PEERSTORE if possible.
204 */
205 struct GNUNET_TIME_AbsoluteNBO monotonic_time;
206
207};
186 208
187/** 209/**
188 * Performance metrics for a connection. 210 * Performance metrics for a connection.
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c
index d54022896..04847f906 100644
--- a/src/cadet/gnunet-service-cadet_core.c
+++ b/src/cadet/gnunet-service-cadet_core.c
@@ -227,7 +227,6 @@ static unsigned long long cur_buffers;
227 */ 227 */
228static struct GNUNET_SCHEDULER_Task *timeout_task; 228static struct GNUNET_SCHEDULER_Task *timeout_task;
229 229
230
231/** 230/**
232 * Get the route corresponding to a hash. 231 * Get the route corresponding to a hash.
233 * 232 *
@@ -724,6 +723,7 @@ handle_connection_create (
724 uint16_t size = ntohs (msg->header.size) - sizeof(*msg); 723 uint16_t size = ntohs (msg->header.size) - sizeof(*msg);
725 unsigned int path_length; 724 unsigned int path_length;
726 unsigned int off; 725 unsigned int off;
726 struct CadetTunnel *t;
727 727
728 path_length = size / sizeof(struct GNUNET_PeerIdentity); 728 path_length = size / sizeof(struct GNUNET_PeerIdentity);
729 if (0 == path_length) 729 if (0 == path_length)
@@ -822,8 +822,19 @@ handle_connection_create (
822 GCP_2s (origin), 822 GCP_2s (origin),
823 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 823 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
824 path = GCPP_get_path_from_route (path_length - 1, pids); 824 path = GCPP_get_path_from_route (path_length - 1, pids);
825 t = GCP_get_tunnel (sender, GNUNET_YES);
826
827 // Check for CADET state in case the other side has lost the tunnel (xrs,t3ss)
828 if ((GNUNET_YES == msg->has_monotime) &&
829 (GNUNET_YES == GCP_check_and_update_monotime(origin, msg->monotime)) &&
830 ( GNUNET_OK == GCP_check_monotime_sig(origin, msg)) &&
831 (CADET_TUNNEL_KEY_OK == GCT_get_estate(t)))
832 {
833 GCT_change_estate (t, CADET_TUNNEL_KEY_UNINITIALIZED);
834 }
835
825 if (GNUNET_OK != 836 if (GNUNET_OK !=
826 GCT_add_inbound_connection (GCP_get_tunnel (origin, GNUNET_YES), 837 GCT_add_inbound_connection (t,
827 &msg->cid, 838 &msg->cid,
828 path)) 839 path))
829 { 840 {
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 8258881d0..0ff4d1fb8 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -31,6 +31,7 @@
31 * to take a break if we have some connections and have searched a lot (?)) 31 * to take a break if we have some connections and have searched a lot (?))
32 */ 32 */
33#include "platform.h" 33#include "platform.h"
34#include "gnunet_time_lib.h"
34#include "gnunet_util_lib.h" 35#include "gnunet_util_lib.h"
35#include "gnunet_hello_lib.h" 36#include "gnunet_hello_lib.h"
36#include "gnunet_signatures.h" 37#include "gnunet_signatures.h"
@@ -38,10 +39,10 @@
38#include "gnunet_ats_service.h" 39#include "gnunet_ats_service.h"
39#include "gnunet_core_service.h" 40#include "gnunet_core_service.h"
40#include "gnunet_statistics_service.h" 41#include "gnunet_statistics_service.h"
41#include "cadet_protocol.h" 42#include "gnunet-service-cadet_peer.h"
43#include "gnunet-service-cadet.h"
42#include "gnunet-service-cadet_connection.h" 44#include "gnunet-service-cadet_connection.h"
43#include "gnunet-service-cadet_dht.h" 45#include "gnunet-service-cadet_dht.h"
44#include "gnunet-service-cadet_peer.h"
45#include "gnunet-service-cadet_paths.h" 46#include "gnunet-service-cadet_paths.h"
46#include "gnunet-service-cadet_tunnels.h" 47#include "gnunet-service-cadet_tunnels.h"
47 48
@@ -66,7 +67,6 @@
66 */ 67 */
67#define MAX_OOO_QUEUE_SIZE 100 68#define MAX_OOO_QUEUE_SIZE 100
68 69
69
70/** 70/**
71 * Data structure used to track whom we have to notify about changes 71 * Data structure used to track whom we have to notify about changes
72 * to our message queue. 72 * to our message queue.
@@ -118,7 +118,7 @@ struct CadetPeer
118 /** 118 /**
119 * Last time we heard from this peer (currently not used!) 119 * Last time we heard from this peer (currently not used!)
120 */ 120 */
121 struct GNUNET_TIME_Absolute last_contactXXX; 121 struct GNUNET_TIME_Absolute last_connection_create;
122 122
123 /** 123 /**
124 * Array of DLLs of paths traversing the peer, organized by the 124 * Array of DLLs of paths traversing the peer, organized by the
@@ -1552,5 +1552,60 @@ GCP_send_ooo (struct CadetPeer *cp,
1552 env); 1552 env);
1553} 1553}
1554 1554
1555/*
1556 * FIXME: comment
1557 */
1558void
1559GCP_update_monotime (struct CadetPeer *peer)
1560{
1561 peer->last_connection_create = GNUNET_TIME_absolute_get_monotonic (cfg);
1562}
1563
1564/*
1565 * FIXME: comment
1566 */
1567int
1568GCP_check_and_update_monotime (struct CadetPeer *peer,
1569 struct GNUNET_TIME_AbsoluteNBO monotime)
1570{
1571
1572 struct GNUNET_TIME_Absolute mt = GNUNET_TIME_absolute_ntoh (monotime);
1573
1574 if (mt.abs_value_us > *(&peer->last_connection_create.abs_value_us))
1575 {
1576 peer->last_connection_create = mt;
1577 return GNUNET_YES;
1578 }
1579 return GNUNET_NO;
1580}
1581
1582/*
1583 * FIXME: documentation here
1584 */
1585int
1586GCP_check_monotime_sig (struct CadetPeer *peer, const struct
1587 GNUNET_CADET_ConnectionCreateMessage *msg)
1588{
1589 // struct CadetPeer *peer;
1590 // const struct GNUNET_CADET_ConnectionCreateMessage *msg;
1591
1592 struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl (
1593 GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR),
1594 .purpose.size = htonl (sizeof(cp)),
1595 .monotonic_time = msg->monotime};
1596
1597 if (GNUNET_OK !=
1598 GNUNET_CRYPTO_eddsa_verify (
1599 GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR,
1600 &cp,
1601 &msg->monotime_sig,
1602 &peer->pid.public_key))
1603 {
1604 GNUNET_break_op (0);
1605 return GNUNET_SYSERR;
1606 }
1607 return GNUNET_OK;
1608}
1609
1555 1610
1556/* end of gnunet-service-cadet-new_peer.c */ 1611/* end of gnunet-service-cadet-new_peer.c */
diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h
index bec0606a0..31bd23121 100644
--- a/src/cadet/gnunet-service-cadet_peer.h
+++ b/src/cadet/gnunet-service-cadet_peer.h
@@ -402,5 +402,14 @@ void
402GCP_set_mq (struct CadetPeer *cp, 402GCP_set_mq (struct CadetPeer *cp,
403 struct GNUNET_MQ_Handle *mq); 403 struct GNUNET_MQ_Handle *mq);
404 404
405int
406GCP_check_monotime_sig (struct CadetPeer *peer, const struct GNUNET_CADET_ConnectionCreateMessage *msg);
407
408void
409GCP_update_monotime (struct CadetPeer *cp);
410
411int
412GCP_check_and_update_monotime (struct CadetPeer *peer,
413 struct GNUNET_TIME_AbsoluteNBO monotime);
405 414
406#endif 415#endif
diff --git a/src/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c
index f1f2ec81f..66e7d5b1e 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.c
+++ b/src/cadet/gnunet-service-cadet_tunnels.c
@@ -464,8 +464,8 @@ struct CadetTunnel
464 * @param other the other peer 464 * @param other the other peer
465 * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself 465 * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself
466 */ 466 */
467static int 467int
468alice_or_betty (const struct GNUNET_PeerIdentity *other) 468GCT_alice_or_betty (const struct GNUNET_PeerIdentity *other)
469{ 469{
470 if (0 > GNUNET_memcmp (&my_full_id, 470 if (0 > GNUNET_memcmp (&my_full_id,
471 other)) 471 other))
@@ -1345,7 +1345,7 @@ send_kx (struct CadetTunnel *t,
1345 struct GNUNET_CADET_TunnelKeyExchangeMessage *msg; 1345 struct GNUNET_CADET_TunnelKeyExchangeMessage *msg;
1346 enum GNUNET_CADET_KX_Flags flags; 1346 enum GNUNET_CADET_KX_Flags flags;
1347 1347
1348 if (GNUNET_YES != alice_or_betty (GCP_get_id (t->destination))) 1348 if (GNUNET_YES != GCT_alice_or_betty (GCP_get_id (t->destination)))
1349 return; /* only Alice may send KX */ 1349 return; /* only Alice may send KX */
1350 if ((NULL == ct) || 1350 if ((NULL == ct) ||
1351 (GNUNET_NO == ct->is_ready)) 1351 (GNUNET_NO == ct->is_ready))
@@ -1521,7 +1521,7 @@ update_ax_by_kx (struct CadetTunnelAxolotl *ax,
1521 const char salt[] = "CADET Axolotl salt"; 1521 const char salt[] = "CADET Axolotl salt";
1522 int am_I_alice; 1522 int am_I_alice;
1523 1523
1524 if (GNUNET_SYSERR == (am_I_alice = alice_or_betty (pid))) 1524 if (GNUNET_SYSERR == (am_I_alice = GCT_alice_or_betty (pid)))
1525 { 1525 {
1526 GNUNET_break_op (0); 1526 GNUNET_break_op (0);
1527 return GNUNET_SYSERR; 1527 return GNUNET_SYSERR;
@@ -1726,7 +1726,7 @@ GCT_handle_kx (struct CadetTConnection *ct,
1726 1, 1726 1,
1727 GNUNET_NO); 1727 GNUNET_NO);
1728 if (GNUNET_YES == 1728 if (GNUNET_YES ==
1729 alice_or_betty (GCP_get_id (t->destination))) 1729 GCT_alice_or_betty (GCP_get_id (t->destination)))
1730 { 1730 {
1731 /* Betty/Bob is not allowed to send KX! */ 1731 /* Betty/Bob is not allowed to send KX! */
1732 GNUNET_break_op (0); 1732 GNUNET_break_op (0);
@@ -2123,9 +2123,10 @@ GCT_add_channel (struct CadetTunnel *t,
2123 ch, 2123 ch,
2124 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2124 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2125 LOG (GNUNET_ERROR_TYPE_DEBUG, 2125 LOG (GNUNET_ERROR_TYPE_DEBUG,
2126 "Adding %s to %s\n", 2126 "Adding %s to %s with state %d\n",
2127 GCCH_2s (ch), 2127 GCCH_2s (ch),
2128 GCT_2s (t)); 2128 GCT_2s (t),
2129 t->estate);
2129 switch (t->estate) 2130 switch (t->estate)
2130 { 2131 {
2131 case CADET_TUNNEL_KEY_UNINITIALIZED: 2132 case CADET_TUNNEL_KEY_UNINITIALIZED:
@@ -2429,12 +2430,21 @@ connection_ready_cb (void *cls,
2429 switch (t->estate) 2430 switch (t->estate)
2430 { 2431 {
2431 case CADET_TUNNEL_KEY_UNINITIALIZED: 2432 case CADET_TUNNEL_KEY_UNINITIALIZED:
2433 LOG (GNUNET_ERROR_TYPE_DEBUG,
2434 "Do not begin KX for %s if WE have no channels waiting. Retrying after %d\n",
2435 GCT_2s (t),
2436 GNUNET_TIME_absolute_get_remaining (t->next_kx_attempt).rel_value_us);
2432 /* Do not begin KX if WE have no channels waiting! */ 2437 /* Do not begin KX if WE have no channels waiting! */
2433 if (0 != GNUNET_TIME_absolute_get_remaining ( 2438 if (0 != GNUNET_TIME_absolute_get_remaining (
2434 t->next_kx_attempt).rel_value_us) 2439 t->next_kx_attempt).rel_value_us)
2435 return; /* wait for timeout before retrying */ 2440 return; /* wait for timeout before retrying */
2436 /* We are uninitialized, just transmit immediately, 2441 /* We are uninitialized, just transmit immediately,
2437 without undue delay. */ 2442 without undue delay. */
2443
2444 LOG (GNUNET_ERROR_TYPE_DEBUG,
2445 "Why for %s \n",
2446 GCT_2s (t));
2447
2438 if (NULL != t->kx_task) 2448 if (NULL != t->kx_task)
2439 { 2449 {
2440 GNUNET_SCHEDULER_cancel (t->kx_task); 2450 GNUNET_SCHEDULER_cancel (t->kx_task);
@@ -3028,7 +3038,8 @@ GCT_send_channel_destroy (struct CadetTunnel *t,
3028 GCT_send (t, 3038 GCT_send (t,
3029 &msg.header, 3039 &msg.header,
3030 NULL, 3040 NULL,
3031 NULL); 3041 NULL,
3042 &ctn);
3032} 3043}
3033 3044
3034 3045
@@ -3445,18 +3456,32 @@ GCT_handle_encrypted (struct CadetTConnection *ct,
3445 * @param t Tunnel on which this message is transmitted. 3456 * @param t Tunnel on which this message is transmitted.
3446 * @param cont Continuation to call once message is really sent. 3457 * @param cont Continuation to call once message is really sent.
3447 * @param cont_cls Closure for @c cont. 3458 * @param cont_cls Closure for @c cont.
3459 * @param The ID of the channel we are using for sending.
3448 * @return Handle to cancel message 3460 * @return Handle to cancel message
3449 */ 3461 */
3450struct CadetTunnelQueueEntry * 3462struct CadetTunnelQueueEntry *
3451GCT_send (struct CadetTunnel *t, 3463GCT_send (struct CadetTunnel *t,
3452 const struct GNUNET_MessageHeader *message, 3464 const struct GNUNET_MessageHeader *message,
3453 GCT_SendContinuation cont, 3465 GCT_SendContinuation cont,
3454 void *cont_cls) 3466 void *cont_cls,
3467 struct GNUNET_CADET_ChannelTunnelNumber *ctn)
3455{ 3468{
3456 struct CadetTunnelQueueEntry *tq; 3469 struct CadetTunnelQueueEntry *tq;
3457 uint16_t payload_size; 3470 uint16_t payload_size;
3458 struct GNUNET_MQ_Envelope *env; 3471 struct GNUNET_MQ_Envelope *env;
3459 struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg; 3472 struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg;
3473 struct CadetChannel *ch;
3474
3475 if (NULL != ctn)
3476 {
3477 ch = lookup_channel (t,
3478 *ctn);
3479 if ((NULL != ch)&& GCCH_is_type_to_drop (ch, message))
3480 {
3481 GNUNET_break (0);
3482 return NULL;
3483 }
3484 }
3460 3485
3461 if (CADET_TUNNEL_KEY_OK != t->estate) 3486 if (CADET_TUNNEL_KEY_OK != t->estate)
3462 { 3487 {
diff --git a/src/cadet/gnunet-service-cadet_tunnels.h b/src/cadet/gnunet-service-cadet_tunnels.h
index ef07badea..147f2e56f 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.h
+++ b/src/cadet/gnunet-service-cadet_tunnels.h
@@ -80,6 +80,14 @@ enum CadetTunnelEState
80 CADET_TUNNEL_KEY_OK 80 CADET_TUNNEL_KEY_OK
81}; 81};
82 82
83/**
84 * Am I Alice or Betty (some call her Bob), or talking to myself?
85 *
86 * @param other the other peer
87 * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself
88 */
89int
90GCT_alice_or_betty (const struct GNUNET_PeerIdentity *other);
83 91
84/** 92/**
85 * Get the static string for the peer this tunnel is directed. 93 * Get the static string for the peer this tunnel is directed.
@@ -226,7 +234,8 @@ struct CadetTunnelQueueEntry *
226GCT_send (struct CadetTunnel *t, 234GCT_send (struct CadetTunnel *t,
227 const struct GNUNET_MessageHeader *message, 235 const struct GNUNET_MessageHeader *message,
228 GCT_SendContinuation cont, 236 GCT_SendContinuation cont,
229 void *cont_cls); 237 void *cont_cls,
238 struct GNUNET_CADET_ChannelTunnelNumber *ctn);
230 239
231 240
232/** 241/**
@@ -320,6 +329,16 @@ GCT_iterate_channels (struct CadetTunnel *t,
320enum CadetTunnelEState 329enum CadetTunnelEState
321GCT_get_estate (struct CadetTunnel *t); 330GCT_get_estate (struct CadetTunnel *t);
322 331
332/**
333 * Change the tunnel encryption state.
334 * If the encryption state changes to OK, stop the rekey task.
335 *
336 * @param t Tunnel whose encryption state to change, or NULL.
337 * @param state New encryption state.
338 */
339void
340GCT_change_estate (struct CadetTunnel *t,
341 enum CadetTunnelEState state);
323 342
324/** 343/**
325 * Handle KX message. 344 * Handle KX message.
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index 25713709c..779d3bc9f 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -25,6 +25,7 @@
25 */ 25 */
26#include <stdio.h> 26#include <stdio.h>
27#include "platform.h" 27#include "platform.h"
28#include "cadet.h"
28#include "cadet_test_lib.h" 29#include "cadet_test_lib.h"
29#include "gnunet_cadet_service.h" 30#include "gnunet_cadet_service.h"
30#include "gnunet_statistics_service.h" 31#include "gnunet_statistics_service.h"
@@ -74,6 +75,17 @@ struct CadetTestChannelWrapper
74#define SPEED_REL 8 75#define SPEED_REL 8
75#define P2P_SIGNAL 10 76#define P2P_SIGNAL 10
76#define REOPEN 11 77#define REOPEN 11
78#define DESTROY 12
79
80/**
81 * Active peer listing operation.
82 */
83static struct GNUNET_CADET_PeersLister *plo;
84
85/*
86 * Task called to check for existing tunnel and depending on that reopen channel
87 */
88static struct GNUNET_SCHEDULER_Task *get_peers_task;
77 89
78/** 90/**
79 * Which test are we running? 91 * Which test are we running?
@@ -123,7 +135,12 @@ static struct GNUNET_TESTBED_Operation *t_op[2];
123/** 135/**
124 * Peer ids. 136 * Peer ids.
125 */ 137 */
126static struct GNUNET_PeerIdentity *p_id[2]; 138static struct GNUNET_PeerIdentity *testpeer_id[2];
139
140/**
141 * Peer ids.
142 */
143static struct GNUNET_CONFIGURATION_Handle *p_cfg[2];
127 144
128/** 145/**
129 * Port ID 146 * Port ID
@@ -133,7 +150,7 @@ static struct GNUNET_HashCode port;
133/** 150/**
134 * Peer ids counter. 151 * Peer ids counter.
135 */ 152 */
136static unsigned int p_ids; 153static unsigned int peerinfo_task_cnt;
137 154
138/** 155/**
139 * Is the setup initialized? 156 * Is the setup initialized?
@@ -196,16 +213,6 @@ static struct GNUNET_SCHEDULER_Task *test_task;
196static struct GNUNET_SCHEDULER_Task *send_next_msg_task; 213static struct GNUNET_SCHEDULER_Task *send_next_msg_task;
197 214
198/** 215/**
199 * Cadet handle for the root peer
200 */
201static struct GNUNET_CADET_Handle *h1;
202
203/**
204 * Cadet handle for the first leaf peer
205 */
206static struct GNUNET_CADET_Handle *h2;
207
208/**
209 * Channel handle for the root peer 216 * Channel handle for the root peer
210 */ 217 */
211static struct GNUNET_CADET_Channel *outgoing_ch; 218static struct GNUNET_CADET_Channel *outgoing_ch;
@@ -226,6 +233,9 @@ static struct GNUNET_TIME_Absolute start_time;
226 */ 233 */
227static struct GNUNET_TESTBED_Peer **testbed_peers; 234static struct GNUNET_TESTBED_Peer **testbed_peers;
228 235
236
237struct GNUNET_CADET_Handle **cadets_running;
238
229/** 239/**
230 * Statistics operation handle. 240 * Statistics operation handle.
231 */ 241 */
@@ -246,6 +256,17 @@ static unsigned int ka_received;
246 */ 256 */
247static unsigned int msg_dropped; 257static unsigned int msg_dropped;
248 258
259/**
260 * Drop the next cadet message of a given type..
261 *
262 * @param mq message queue
263 * @param ccn client channel number.
264 * @param type of cadet message to be dropped.
265 */
266void
267GNUNET_CADET_drop_message (struct GNUNET_MQ_Handle *mq,
268 struct GNUNET_CADET_ClientChannelNumber ccn,
269 uint16_t type);
249 270
250/******************************************************************************/ 271/******************************************************************************/
251 272
@@ -516,6 +537,49 @@ static void
516disconnect_handler (void *cls, 537disconnect_handler (void *cls,
517 const struct GNUNET_CADET_Channel *channel); 538 const struct GNUNET_CADET_Channel *channel);
518 539
540static struct GNUNET_PeerIdentity *
541get_from_p_ids ()
542{
543 if (0 < GNUNET_memcmp (testpeer_id[0], testpeer_id[1]))
544 {
545 return testpeer_id[1];
546 }
547 else
548 {
549 return testpeer_id[0];
550 }
551}
552
553static struct GNUNET_CADET_Handle *
554get_from_cadets ()
555{
556
557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "1\n");
558 if (0 < GNUNET_memcmp (testpeer_id[0], testpeer_id[1]))
559 {
560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "standard peer\n");
561 return cadets_running[0];
562 }
563 else
564 {
565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "the other peer\n");
566 return cadets_running[peers_running - 1];
567 }
568
569}
570
571static unsigned int
572get_peer_nr (int outgoing)
573{
574 if (0 < GNUNET_memcmp (testpeer_id[0], testpeer_id[1]))
575 {
576 return GNUNET_YES == outgoing ? 0 : peers_running - 1;
577 }
578 else
579 {
580 return GNUNET_YES == outgoing ? peers_running - 1 : 0;
581 }
582}
519 583
520/** 584/**
521 * Task to reconnect to other peer. 585 * Task to reconnect to other peer.
@@ -534,6 +598,8 @@ reconnect_op (void *cls)
534 }; 598 };
535 long l = (long) cls; 599 long l = (long) cls;
536 struct CadetTestChannelWrapper *ch; 600 struct CadetTestChannelWrapper *ch;
601 static struct GNUNET_PeerIdentity *p_id;
602 static struct GNUNET_CADET_Handle *h1;
537 603
538 reconnect_task = NULL; 604 reconnect_task = NULL;
539 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 605 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -545,17 +611,127 @@ reconnect_op (void *cls)
545 outgoing_ch = NULL; 611 outgoing_ch = NULL;
546 } 612 }
547 ch = GNUNET_new (struct CadetTestChannelWrapper); 613 ch = GNUNET_new (struct CadetTestChannelWrapper);
614
615 p_id = get_from_p_ids ();
616 h1 = get_from_cadets ();
617
618 outgoing_ch = GNUNET_CADET_channel_create (h1,
619 ch,
620 p_id,
621 &port,
622 NULL,
623 &disconnect_handler,
624 handlers);
625 ch->ch = outgoing_ch;
626 send_test_message (outgoing_ch);
627}
628
629void
630reopen_channel ()
631{
632 struct CadetTestChannelWrapper *ch;
633 static struct GNUNET_CADET_Handle *h1;
634 static struct GNUNET_PeerIdentity *p_id;
635 struct GNUNET_MQ_MessageHandler handlers[] = {
636 GNUNET_MQ_hd_var_size (data,
637 GNUNET_MESSAGE_TYPE_DUMMY,
638 struct GNUNET_MessageHeader,
639 NULL),
640 GNUNET_MQ_handler_end ()
641 };
642
643 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "creating channel again\n");
644 p_id = get_from_p_ids ();
645 h1 = get_from_cadets ();
646
647 ch = GNUNET_new (struct CadetTestChannelWrapper);
548 outgoing_ch = GNUNET_CADET_channel_create (h1, 648 outgoing_ch = GNUNET_CADET_channel_create (h1,
549 ch, 649 ch,
550 p_id[1], 650 p_id,
551 &port, 651 &port,
552 NULL, 652 NULL,
553 &disconnect_handler, 653 &disconnect_handler,
554 handlers); 654 handlers);
555 ch->ch = outgoing_ch; 655 ch->ch = outgoing_ch;
656 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
657 "Sending second test data (after destroying the channel) on channel %p...\n",
658 outgoing_ch);
556 send_test_message (outgoing_ch); 659 send_test_message (outgoing_ch);
557} 660}
558 661
662static void
663peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple);
664
665/**
666 * We ask the monitoring api for all the peers.
667 */
668static void
669get_peers (void *cls)
670{
671
672 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
673 "requesting peers info!\n");
674 plo = GNUNET_CADET_list_peers (p_cfg[get_peer_nr (GNUNET_YES)],
675 &peers_callback, NULL);
676
677}
678
679/**
680 * Method called to retrieve information about all peers in CADET, called
681 * once per peer.
682 *
683 * After last peer has been reported, an additional call with NULL is done.
684 *
685 * We check the peer we are interested in, if we have a tunnel. If not, we
686 * reopen the channel
687 *
688 * @param cls Closure.
689 * @param ple information about peer, or NULL on "EOF".
690 */
691static void
692peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
693{
694
695 const struct GNUNET_PeerIdentity *p_id;
696 const struct GNUNET_PeerIdentity *peer;
697
698
699 peer = &ple->peer;
700
701 if (NULL == ple)
702 {
703 plo = NULL;
704 return;
705 }
706 p_id = get_from_p_ids ();
707
708 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
709 "ple->peer %s\n",
710 GNUNET_i2s_full (&ple->peer));
711 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
712 "p_id %s\n",
713 GNUNET_i2s_full (p_id));
714
715 if ((0 == GNUNET_memcmp (&ple->peer, p_id))&& ple->have_tunnel)
716 {
717
718 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
719 "schedule get_peers again?\n");
720 get_peers_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
721 &get_peers,
722 NULL);
723
724 }
725 else if (0 == GNUNET_memcmp (&ple->peer, p_id) )
726 {
727
728 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
729 "reopen channel\n");
730
731 reopen_channel ();
732
733 }
734}
559 735
560/** 736/**
561 * Function called whenever an MQ-channel is destroyed, unless the destruction 737 * Function called whenever an MQ-channel is destroyed, unless the destruction
@@ -575,9 +751,22 @@ disconnect_handler (void *cls,
575 struct CadetTestChannelWrapper *ch_w = cls; 751 struct CadetTestChannelWrapper *ch_w = cls;
576 752
577 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 753 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
578 "Channel disconnected at %d\n", 754 "Channel disconnected at ok=%d\n",
579 ok); 755 ok);
580 GNUNET_assert (ch_w->ch == channel); 756 GNUNET_assert (ch_w->ch == channel);
757
758 if ((DESTROY == test) && (3 == ok))
759 {
760 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
761 "Reopen channel task!\n");
762 if (NULL == get_peers_task)
763 {
764 get_peers_task = GNUNET_SCHEDULER_add_now (&get_peers,
765 NULL);
766 }
767 return;
768 }
769
581 if (channel == incoming_ch) 770 if (channel == incoming_ch)
582 { 771 {
583 ok++; 772 ok++;
@@ -651,8 +840,8 @@ send_test_message (struct GNUNET_CADET_Channel *channel)
651 int size; 840 int size;
652 841
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 842 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
654 "Sending test message on channel %p\n", 843 "Sending test message on channel %u\n",
655 channel); 844 channel->ccn.channel_of_client);
656 size = size_payload; 845 size = size_payload;
657 if (GNUNET_NO == initialized) 846 if (GNUNET_NO == initialized)
658 { 847 {
@@ -699,6 +888,10 @@ send_test_message (struct GNUNET_CADET_Channel *channel)
699 "Sending DATA %u [%d bytes]\n", 888 "Sending DATA %u [%d bytes]\n",
700 data_sent, size); 889 data_sent, size);
701 } 890 }
891 else if (DESTROY == test)
892 {
893 payload = data_sent;
894 }
702 else 895 else
703 { 896 {
704 GNUNET_assert (0); 897 GNUNET_assert (0);
@@ -826,7 +1019,7 @@ handle_data (void *cls,
826 } 1019 }
827 1020
828 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1021 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
829 " ok: (%d/%d)\n", 1022 "handle_data ok: (%d/%d)\n",
830 ok, 1023 ok,
831 ok_goal); 1024 ok_goal);
832 data = (uint32_t *) &message[1]; 1025 data = (uint32_t *) &message[1];
@@ -844,6 +1037,49 @@ handle_data (void *cls,
844 payload, *counter); 1037 payload, *counter);
845 } 1038 }
846 1039
1040 if (DESTROY == test)
1041 {
1042 if (2 == ok)
1043 {
1044 ok++;
1045 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1046 "dropping message ok: (%d/%d)\n",
1047 ok,
1048 ok_goal);
1049 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1050 "TEST ID 0: %s\n",
1051 GNUNET_i2s (testpeer_id[0]));
1052 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1053 "TEST ID 1: %s\n",
1054 GNUNET_i2s (testpeer_id[1]));
1055
1056 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "dropping message\n");
1057 GNUNET_CADET_drop_message (GNUNET_CADET_get_mq (outgoing_ch),
1058 outgoing_ch->ccn,
1059 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
1060 if (NULL != outgoing_ch)
1061 {
1062 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1063 "Destroying channel %p...\n",
1064 outgoing_ch);
1065 GNUNET_CADET_channel_destroy (outgoing_ch);
1066 outgoing_ch = NULL;
1067 }
1068 }
1069 else if (5 == ok)
1070 {
1071 ok++;
1072 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1073 "destroy test finished ok: (%d/%d)\n",
1074 ok,
1075 ok_goal);
1076 disconnect_task =
1077 GNUNET_SCHEDULER_add_now (&gather_stats_and_exit,
1078 (void *) __LINE__);
1079 // End of DESTROY test.
1080 }
1081 }
1082
847 if (GNUNET_NO == initialized) 1083 if (GNUNET_NO == initialized)
848 { 1084 {
849 initialized = GNUNET_YES; 1085 initialized = GNUNET_YES;
@@ -861,7 +1097,7 @@ handle_data (void *cls,
861 if (get_target_channel () == channel) /* Got "data" */ 1097 if (get_target_channel () == channel) /* Got "data" */
862 { 1098 {
863 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received); 1099 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received);
864 if ((SPEED != test) || ( (ok_goal - 2) == ok) ) 1100 if ((DESTROY != test) && ((SPEED != test) || ( (ok_goal - 2) == ok)) )
865 { 1101 {
866 /* Send ACK */ 1102 /* Send ACK */
867 send_test_message (channel); 1103 send_test_message (channel);
@@ -927,11 +1163,13 @@ connect_handler (void *cls,
927 channel); 1163 channel);
928 ok++; 1164 ok++;
929 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1165 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
930 " ok: %d\n", 1166 "connect_handler ok: (%d/%d)\n",
931 ok); 1167 ok,
932 if (peer == peers_requested - 1) 1168 ok_goal);
1169
1170 if (peer == get_peer_nr (GNUNET_NO))
933 { 1171 {
934 if (NULL != incoming_ch) 1172 if ((DESTROY != test)&&(NULL != incoming_ch))
935 { 1173 {
936 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1174 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
937 "Duplicate incoming channel for client %lu\n", 1175 "Duplicate incoming channel for client %lu\n",
@@ -947,7 +1185,7 @@ connect_handler (void *cls,
947 (long) cls); 1185 (long) cls);
948 GNUNET_assert (0); 1186 GNUNET_assert (0);
949 } 1187 }
950 if ((NULL != disconnect_task) && (REOPEN != test)) 1188 if ((NULL != disconnect_task) && (REOPEN != test) && (DESTROY != test))
951 { 1189 {
952 GNUNET_SCHEDULER_cancel (disconnect_task); 1190 GNUNET_SCHEDULER_cancel (disconnect_task);
953 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, 1191 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
@@ -971,6 +1209,7 @@ connect_handler (void *cls,
971 (void *) __LINE__); 1209 (void *) __LINE__);
972 } 1210 }
973 1211
1212
974 /* TODO: cannot return channel as-is, in order to unify the data handlers */ 1213 /* TODO: cannot return channel as-is, in order to unify the data handlers */
975 ch = GNUNET_new (struct CadetTestChannelWrapper); 1214 ch = GNUNET_new (struct CadetTestChannelWrapper);
976 ch->ch = channel; 1215 ch->ch = channel;
@@ -998,6 +1237,8 @@ start_test (void *cls)
998 GNUNET_MQ_handler_end () 1237 GNUNET_MQ_handler_end ()
999 }; 1238 };
1000 struct CadetTestChannelWrapper *ch; 1239 struct CadetTestChannelWrapper *ch;
1240 static struct GNUNET_CADET_Handle *h1;
1241 static struct GNUNET_PeerIdentity *p_id;
1001 1242
1002 test_task = NULL; 1243 test_task = NULL;
1003 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name); 1244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name);
@@ -1012,20 +1253,25 @@ start_test (void *cls)
1012 test = SPEED; 1253 test = SPEED;
1013 } 1254 }
1014 1255
1256 p_id = get_from_p_ids ();
1257 h1 = get_from_cadets ();
1258
1015 ch = GNUNET_new (struct CadetTestChannelWrapper); 1259 ch = GNUNET_new (struct CadetTestChannelWrapper);
1016 outgoing_ch = GNUNET_CADET_channel_create (h1, 1260 outgoing_ch = GNUNET_CADET_channel_create (h1,
1017 ch, 1261 ch,
1018 p_id[1], 1262 p_id,
1019 &port, 1263 &port,
1020 NULL, 1264 NULL,
1021 &disconnect_handler, 1265 &disconnect_handler,
1022 handlers); 1266 handlers);
1267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel created\n");
1023 1268
1024 ch->ch = outgoing_ch; 1269 ch->ch = outgoing_ch;
1025 1270
1026 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, 1271 if (DESTROY != test)
1027 &gather_stats_and_exit, 1272 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1028 (void *) __LINE__); 1273 &gather_stats_and_exit,
1274 (void *) __LINE__);
1029 if (KEEPALIVE == test) 1275 if (KEEPALIVE == test)
1030 return; /* Don't send any data. */ 1276 return; /* Don't send any data. */
1031 1277
@@ -1054,7 +1300,7 @@ start_test (void *cls)
1054/** 1300/**
1055 * Callback to be called when the requested peer information is available 1301 * Callback to be called when the requested peer information is available
1056 * 1302 *
1057 * @param cls the closure from GNUNET_TESTBED_peer_get_information() 1303 * @param cls the closure from GNUNET_TESTBED_peer_getinformation()
1058 * @param op the operation this callback corresponds to 1304 * @param op the operation this callback corresponds to
1059 * @param pinfo the result; will be NULL if the operation has failed 1305 * @param pinfo the result; will be NULL if the operation has failed
1060 * @param emsg error message if the operation has failed; 1306 * @param emsg error message if the operation has failed;
@@ -1068,9 +1314,6 @@ pi_cb (void *cls,
1068{ 1314{
1069 long i = (long) cls; 1315 long i = (long) cls;
1070 1316
1071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1072 "ID callback for %ld\n",
1073 i);
1074 if ((NULL == pinfo) || 1317 if ((NULL == pinfo) ||
1075 (NULL != emsg)) 1318 (NULL != emsg))
1076 { 1319 {
@@ -1080,15 +1323,40 @@ pi_cb (void *cls,
1080 abort_test (__LINE__); 1323 abort_test (__LINE__);
1081 return; 1324 return;
1082 } 1325 }
1083 p_id[i] = pinfo->result.id; 1326
1084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1327 if (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit)
1085 "id: %s\n", 1328 {
1086 GNUNET_i2s (p_id[i])); 1329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1087 p_ids++; 1330 "ID callback for %ld\n",
1088 if (p_ids < 2) 1331 i);
1332 testpeer_id[i] = pinfo->result.id;
1333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1334 "id: %s\n",
1335 GNUNET_i2s (testpeer_id[i]));
1336 }
1337 else if (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit)
1338 {
1339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1340 "CFG callback for %ld\n",
1341 i);
1342 p_cfg[i] = pinfo->result.cfg;
1343 }
1344 else
1345 {
1346 GNUNET_break (0);
1347 }
1348
1349 peerinfo_task_cnt++;
1350 if (peerinfo_task_cnt < 4)
1089 return; 1351 return;
1090 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1091 "Got all IDs, starting test\n"); 1353 "Got all peer information, starting test\n");
1354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1355 "TEST ID 0: %s\n",
1356 GNUNET_i2s (testpeer_id[0]));
1357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1358 "TEST ID 1: %s\n",
1359 GNUNET_i2s (testpeer_id[1]));
1092 test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL); 1360 test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL);
1093} 1361}
1094 1362
@@ -1115,8 +1383,8 @@ tmain (void *cls,
1115 peers_running = num_peers; 1383 peers_running = num_peers;
1116 GNUNET_assert (peers_running == peers_requested); 1384 GNUNET_assert (peers_running == peers_requested);
1117 testbed_peers = peers; 1385 testbed_peers = peers;
1118 h1 = cadets[0]; 1386 cadets_running = cadets;
1119 h2 = cadets[num_peers - 1]; 1387
1120 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, 1388 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1121 &disconnect_cadet_peers, 1389 &disconnect_cadet_peers,
1122 (void *) __LINE__); 1390 (void *) __LINE__);
@@ -1130,6 +1398,14 @@ tmain (void *cls,
1130 GNUNET_TESTBED_PIT_IDENTITY, 1398 GNUNET_TESTBED_PIT_IDENTITY,
1131 &pi_cb, 1399 &pi_cb,
1132 (void *) 1L); 1400 (void *) 1L);
1401 t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
1402 GNUNET_TESTBED_PIT_CONFIGURATION,
1403 &pi_cb,
1404 (void *) 0L);
1405 t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1],
1406 GNUNET_TESTBED_PIT_CONFIGURATION,
1407 &pi_cb,
1408 (void *) 1L);
1133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n"); 1409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n");
1134} 1410}
1135 1411
@@ -1272,6 +1548,13 @@ main (int argc, char *argv[])
1272 // */ 1548 // */
1273 ok_goal = 6; 1549 ok_goal = 6;
1274 } 1550 }
1551 else if (strstr (argv[0], "_destroy") != NULL)
1552 {
1553 test = DESTROY;
1554 test_name = "destroy";
1555 ok_goal = 6;
1556 short_time = GNUNET_TIME_relative_multiply (short_time, 5);
1557 }
1275 else 1558 else
1276 { 1559 {
1277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n"); 1560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
@@ -1286,7 +1569,7 @@ main (int argc, char *argv[])
1286 GNUNET_asprintf (&test_name, "backwards %s", test_name); 1569 GNUNET_asprintf (&test_name, "backwards %s", test_name);
1287 } 1570 }
1288 1571
1289 p_ids = 0; 1572 peerinfo_task_cnt = 0;
1290 ports[0] = &port; 1573 ports[0] = &port;
1291 ports[1] = NULL; 1574 ports[1] = NULL;
1292 GNUNET_CADET_TEST_ruN ("test_cadet_small", 1575 GNUNET_CADET_TEST_ruN ("test_cadet_small",
diff --git a/src/cadet/test_cadet.conf b/src/cadet/test_cadet.conf
index 30e496aff..067dd5fb4 100644
--- a/src/cadet/test_cadet.conf
+++ b/src/cadet/test_cadet.conf
@@ -27,7 +27,8 @@ QUOTA = 1 MB
27DATABASE = heap 27DATABASE = heap
28 28
29[transport] 29[transport]
30PLUGINS = udp 30#PLUGINS = udp
31PLUGINS = tcp
31NEIGHBOUR_LIMIT = 50 32NEIGHBOUR_LIMIT = 50
32#MANIPULATE_DELAY_IN = 10 ms 33#MANIPULATE_DELAY_IN = 10 ms
33#MANIPULATE_DELAY_OUT = 10 ms 34#MANIPULATE_DELAY_OUT = 10 ms
@@ -102,3 +103,7 @@ START_ON_DEMAND = NO
102[rps] 103[rps]
103IMMEDIATE_START = NO 104IMMEDIATE_START = NO
104START_ON_DEMAND = NO 105START_ON_DEMAND = NO
106
107[rest]
108IMMEDIATE_START = NO
109START_ON_DEMAND = NO
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index a9cd7466a..0db6150aa 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -2734,9 +2734,8 @@ extern "C" {
2734 * 1000-1009 Connection-level Messages 2734 * 1000-1009 Connection-level Messages
2735 * 1010-1019 Channel-level Messages 2735 * 1010-1019 Channel-level Messages
2736 * 1020-1029 Local Client-Service 2736 * 1020-1029 Local Client-Service
2737 * 1030-1039 Local Service Monitoring 2737 * 1030-1049 Local Service Monitoring
2738 * 1040-1049 Application Data 2738 * 1050-1059 Application Data
2739 * 1050-1059 Reserved
2740 */ 2739 */
2741 2740
2742/******************************** Connection ********************************/ 2741/******************************** Connection ********************************/
@@ -2932,6 +2931,11 @@ extern "C" {
2932 */ 2931 */
2933#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END 1041 2932#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END 1041
2934 2933
2934/**
2935 * Request to drop a message of type X to peer y.
2936 */
2937#define GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE 1042
2938
2935 2939
2936/******************************** Application *******************************/ 2940/******************************** Application *******************************/
2937 2941
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
index a00e0372d..503113770 100644
--- a/src/include/gnunet_signatures.h
+++ b/src/include/gnunet_signatures.h
@@ -241,6 +241,10 @@ extern "C"
241 */ 241 */
242#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 37 242#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 37
243 243
244/**
245 * Signature by a peer that like to create a connection.
246 */
247#define GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR 38
244 248
245#if 0 /* keep Emacsens' auto-indent happy */ 249#if 0 /* keep Emacsens' auto-indent happy */
246{ 250{