aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-20 18:56:17 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-20 18:56:17 +0100
commit6a828bdf078d44531cc8e7de70a88e9b6f438da9 (patch)
treeea7f15f8bc70c911d97a1d7de9f3601fdf2c2ad0 /src
parent6b25953f27639c7b87c98a6cb55fd173c9dc5016 (diff)
downloadgnunet-6a828bdf078d44531cc8e7de70a88e9b6f438da9.tar.gz
gnunet-6a828bdf078d44531cc8e7de70a88e9b6f438da9.zip
more work on new tunnel logic
Diffstat (limited to 'src')
-rw-r--r--src/cadet/cadet_protocol.h16
-rw-r--r--src/cadet/gnunet-service-cadet-new.c4
-rw-r--r--src/cadet/gnunet-service-cadet-new_channel.c4
-rw-r--r--src/cadet/gnunet-service-cadet-new_tunnels.c391
-rw-r--r--src/cadet/gnunet-service-cadet-new_tunnels.h64
-rw-r--r--src/cadet/gnunet-service-cadet_channel.h2
6 files changed, 258 insertions, 223 deletions
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index 070be3e28..0c325fc5a 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -253,10 +253,17 @@ struct GNUNET_CADET_TunnelEncryptedMessage
253 */ 253 */
254 struct GNUNET_MessageHeader header; 254 struct GNUNET_MessageHeader header;
255 255
256#if NEW_CADET
256 /** 257 /**
257 * ID of the packet (hop by hop). 258 * Reserved, for alignment.
259 */
260 uint32_t reserved GNUNET_PACKED;
261#else
262 /**
263 * Maximum packet ID authorized.
258 */ 264 */
259 struct CadetEncryptedMessageIdentifier cemi; 265 struct CadetEncryptedMessageIdentifier cemi;
266#endif
260 267
261 /** 268 /**
262 * ID of the connection. 269 * ID of the connection.
@@ -295,6 +302,8 @@ struct GNUNET_CADET_TunnelEncryptedMessage
295}; 302};
296 303
297 304
305#ifndef NEW_CADET
306
298/** 307/**
299 * Message to query a peer about its Flow Control status regarding a tunnel. 308 * Message to query a peer about its Flow Control status regarding a tunnel.
300 * 309 *
@@ -345,6 +354,8 @@ struct GNUNET_CADET_ConnectionEncryptedAckMessage
345 struct GNUNET_CADET_ConnectionTunnelIdentifier cid; 354 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
346}; 355};
347 356
357#endif
358
348 359
349/******************************************************************************/ 360/******************************************************************************/
350/******************************* CHANNEL ***********************************/ 361/******************************* CHANNEL ***********************************/
@@ -483,8 +494,7 @@ struct ChannelMessageIdentifier
483struct GNUNET_CADET_ChannelAppDataMessage 494struct GNUNET_CADET_ChannelAppDataMessage
484{ 495{
485 /** 496 /**
486 * Type: #GNUNET_MESSAGE_TYPE_CADET_UNICAST, 497 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
487 * #GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
488 */ 498 */
489 struct GNUNET_MessageHeader header; 499 struct GNUNET_MessageHeader header;
490 500
diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c
index 2f6cc7b11..7b4a0e95b 100644
--- a/src/cadet/gnunet-service-cadet-new.c
+++ b/src/cadet/gnunet-service-cadet-new.c
@@ -855,7 +855,7 @@ get_all_tunnels_iterator (void *cls,
855 msg->destination = *peer; 855 msg->destination = *peer;
856 msg->channels = htonl (GCT_count_channels (t)); 856 msg->channels = htonl (GCT_count_channels (t));
857 msg->connections = htonl (GCT_count_any_connections (t)); 857 msg->connections = htonl (GCT_count_any_connections (t));
858 msg->cstate = htons ((uint16_t) GCT_get_cstate (t)); 858 msg->cstate = htons (0);
859 msg->estate = htons ((uint16_t) GCT_get_estate (t)); 859 msg->estate = htons ((uint16_t) GCT_get_estate (t));
860 GNUNET_MQ_send (c->mq, 860 GNUNET_MQ_send (c->mq,
861 env); 861 env);
@@ -975,7 +975,7 @@ handle_show_tunnel (void *cls,
975 resp); 975 resp);
976 resp->connections = htonl (resp->connections); 976 resp->connections = htonl (resp->connections);
977 resp->channels = htonl (resp->channels); 977 resp->channels = htonl (resp->channels);
978 resp->cstate = htons (GCT_get_cstate (t)); 978 resp->cstate = htons (0);
979 resp->estate = htons (GCT_get_estate (t)); 979 resp->estate = htons (GCT_get_estate (t));
980 GNUNET_MQ_send (c->mq, 980 GNUNET_MQ_send (c->mq,
981 env); 981 env);
diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c
index c6adc351b..5d2eba618 100644
--- a/src/cadet/gnunet-service-cadet-new_channel.c
+++ b/src/cadet/gnunet-service-cadet-new_channel.c
@@ -25,6 +25,10 @@
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 * 26 *
27 * TODO: 27 * TODO:
28 * - handle CREATE_ACK
29 * - handle plaintext data
30 * - handle plaintext ACK
31 * - handle destroy
28 * - estimate max bandwidth using bursts and use to for CONGESTION CONTROL! 32 * - estimate max bandwidth using bursts and use to for CONGESTION CONTROL!
29 * - check that '0xFFULL' really is sufficient for flow control! 33 * - check that '0xFFULL' really is sufficient for flow control!
30 * - what about the 'no buffer' option? 34 * - what about the 'no buffer' option?
diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c
index 9b359ed58..8f1a19d5b 100644
--- a/src/cadet/gnunet-service-cadet-new_tunnels.c
+++ b/src/cadet/gnunet-service-cadet-new_tunnels.c
@@ -24,9 +24,10 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * 25 *
26 * FIXME: 26 * FIXME:
27 * - clean up KX logic! 27 * - check KX estate machine -- make sure it is never stuck!
28 * - implement sending and receiving KX messages 28 * - clean up KX logic, including adding sender authentication
29 * - implement processing of incoming decrypted plaintext messages 29 * - implement connection management (evaluate, kill old ones,
30 * search for new ones)
30 * - when managing connections, distinguish those that 31 * - when managing connections, distinguish those that
31 * have (recently) had traffic from those that were 32 * have (recently) had traffic from those that were
32 * never ready (or not recently) 33 * never ready (or not recently)
@@ -298,19 +299,19 @@ struct CadetTunnel
298 struct CadetTunnelAxolotl ax; 299 struct CadetTunnelAxolotl ax;
299 300
300 /** 301 /**
301 * State of the tunnel connectivity. 302 * Task scheduled if there are no more channels using the tunnel.
302 */ 303 */
303 enum CadetTunnelCState cstate; 304 struct GNUNET_SCHEDULER_Task *destroy_task;
304 305
305 /** 306 /**
306 * State of the tunnel encryption. 307 * Task to trim connections if too many are present.
307 */ 308 */
308 enum CadetTunnelEState estate; 309 struct GNUNET_SCHEDULER_Task *maintain_connections_task;
309 310
310 /** 311 /**
311 * Task to start the rekey process. 312 * Task to trigger KX.
312 */ 313 */
313 struct GNUNET_SCHEDULER_Task *rekey_task; 314 struct GNUNET_SCHEDULER_Task *kx_task;
314 315
315 /** 316 /**
316 * Tokenizer for decrypted messages. 317 * Tokenizer for decrypted messages.
@@ -353,25 +354,26 @@ struct CadetTunnel
353 */ 354 */
354 struct CadetTunnelQueueEntry *tq_tail; 355 struct CadetTunnelQueueEntry *tq_tail;
355 356
357
356 /** 358 /**
357 * Task scheduled if there are no more channels using the tunnel. 359 * Ephemeral message in the queue (to avoid queueing more than one).
358 */ 360 */
359 struct GNUNET_SCHEDULER_Task *destroy_task; 361 struct CadetConnectionQueue *ephm_hKILL;
360 362
361 /** 363 /**
362 * Task to trim connections if too many are present. 364 * Pong message in the queue.
363 */ 365 */
364 struct GNUNET_SCHEDULER_Task *maintain_connections_task; 366 struct CadetConnectionQueue *pong_hKILL;
365 367
366 /** 368 /**
367 * Ephemeral message in the queue (to avoid queueing more than one). 369 * How long do we wait until we retry the KX?
368 */ 370 */
369 struct CadetConnectionQueue *ephm_hKILL; 371 struct GNUNET_TIME_Relative kx_retry_delay;
370 372
371 /** 373 /**
372 * Pong message in the queue. 374 * When do we try the next KX?
373 */ 375 */
374 struct CadetConnectionQueue *pong_hKILL; 376 struct GNUNET_TIME_Absolute next_kx_attempt;
375 377
376 /** 378 /**
377 * Number of connections in the @e connection_head DLL. 379 * Number of connections in the @e connection_head DLL.
@@ -382,6 +384,12 @@ struct CadetTunnel
382 * Number of entries in the @e tq_head DLL. 384 * Number of entries in the @e tq_head DLL.
383 */ 385 */
384 unsigned int tq_len; 386 unsigned int tq_len;
387
388 /**
389 * State of the tunnel encryption.
390 */
391 enum CadetTunnelEState estate;
392
385}; 393};
386 394
387 395
@@ -466,16 +474,34 @@ GCT_count_any_connections (struct CadetTunnel *t)
466 474
467 475
468/** 476/**
469 * Get the connectivity state of a tunnel. 477 * Find first connection that is ready in the list of
478 * our connections. Picks ready connections round-robin.
470 * 479 *
471 * @param t Tunnel. 480 * @param t tunnel to search
472 * 481 * @return NULL if we have no connection that is ready
473 * @return Tunnel's connectivity state.
474 */ 482 */
475enum CadetTunnelCState 483static struct CadetTConnection *
476GCT_get_cstate (struct CadetTunnel *t) 484get_ready_connection (struct CadetTunnel *t)
477{ 485{
478 return t->cstate; 486 for (struct CadetTConnection *pos = t->connection_head;
487 NULL != pos;
488 pos = pos->next)
489 if (GNUNET_YES == pos->is_ready)
490 {
491 if (pos != t->connection_tail)
492 {
493 /* move 'pos' to the end, so we try other ready connections
494 first next time (round-robin, modulo availability) */
495 GNUNET_CONTAINER_DLL_remove (t->connection_head,
496 t->connection_tail,
497 pos);
498 GNUNET_CONTAINER_DLL_insert_tail (t->connection_head,
499 t->connection_tail,
500 pos);
501 }
502 return pos;
503 }
504 return NULL;
479} 505}
480 506
481 507
@@ -506,6 +532,19 @@ new_ephemeral (struct CadetTunnel *t)
506} 532}
507 533
508 534
535
536/**
537 * Called when either we have a new connection, or a new message in the
538 * queue, or some existing connection has transmission capacity. Looks
539 * at our message queue and if there is a message, picks a connection
540 * to send it on.
541 *
542 * @param t tunnel to process messages on
543 */
544static void
545trigger_transmissions (struct CadetTunnel *t);
546
547
509/* ************************************** start core crypto ***************************** */ 548/* ************************************** start core crypto ***************************** */
510 549
511 550
@@ -1104,6 +1143,39 @@ t_ax_decrypt_and_validate (struct CadetTunnel *t,
1104 1143
1105 1144
1106/** 1145/**
1146 * Change the tunnel encryption state.
1147 * If the encryption state changes to OK, stop the rekey task.
1148 *
1149 * @param t Tunnel whose encryption state to change, or NULL.
1150 * @param state New encryption state.
1151 */
1152void
1153GCT_change_estate (struct CadetTunnel *t,
1154 enum CadetTunnelEState state)
1155{
1156 enum CadetTunnelEState old = t->estate;
1157
1158 t->estate = state;
1159 LOG (GNUNET_ERROR_TYPE_DEBUG,
1160 "Tunnel %s estate changed from %d to %d\n",
1161 GCT_2s (t),
1162 old,
1163 state);
1164
1165 if ( (CADET_TUNNEL_KEY_OK != old) &&
1166 (CADET_TUNNEL_KEY_OK == t->estate) )
1167 {
1168 if (NULL != t->kx_task)
1169 {
1170 GNUNET_SCHEDULER_cancel (t->kx_task);
1171 t->kx_task = NULL;
1172 }
1173 /* FIXME: schedule rekey task! */
1174 }
1175}
1176
1177
1178/**
1107 * Send a KX message. 1179 * Send a KX message.
1108 * 1180 *
1109 * FIXME: does not take care of sender-authentication yet! 1181 * FIXME: does not take care of sender-authentication yet!
@@ -1116,20 +1188,16 @@ send_kx (struct CadetTunnel *t,
1116 int force_reply) 1188 int force_reply)
1117{ 1189{
1118 struct CadetTunnelAxolotl *ax = &t->ax; 1190 struct CadetTunnelAxolotl *ax = &t->ax;
1119 struct CadetConnection *c; 1191 struct CadetTConnection *ct;
1192 struct CadetConnection *cc;
1120 struct GNUNET_MQ_Envelope *env; 1193 struct GNUNET_MQ_Envelope *env;
1121 struct GNUNET_CADET_TunnelKeyExchangeMessage *msg; 1194 struct GNUNET_CADET_TunnelKeyExchangeMessage *msg;
1122 enum GNUNET_CADET_KX_Flags flags; 1195 enum GNUNET_CADET_KX_Flags flags;
1123 1196
1124#if FIXME 1197 ct = get_ready_connection (t);
1125 if (NULL != t->ephm_h) 1198 if (NULL == ct)
1126 {
1127 LOG (GNUNET_ERROR_TYPE_INFO,
1128 " already queued, nop\n");
1129 return; 1199 return;
1130 } 1200 cc = ct->cc;
1131#endif
1132 c = NULL; // FIXME: figure out where to transmit...
1133 1201
1134 // GNUNET_assert (GNUNET_NO == GCT_is_loopback (t)); 1202 // GNUNET_assert (GNUNET_NO == GCT_is_loopback (t));
1135 env = GNUNET_MQ_msg (msg, 1203 env = GNUNET_MQ_msg (msg,
@@ -1138,23 +1206,18 @@ send_kx (struct CadetTunnel *t,
1138 if (GNUNET_YES == force_reply) 1206 if (GNUNET_YES == force_reply)
1139 flags |= GNUNET_CADET_KX_FLAG_FORCE_REPLY; 1207 flags |= GNUNET_CADET_KX_FLAG_FORCE_REPLY;
1140 msg->flags = htonl (flags); 1208 msg->flags = htonl (flags);
1141 msg->cid = *GCC_get_id (c); 1209 msg->cid = *GCC_get_id (cc);
1142 GNUNET_CRYPTO_ecdhe_key_get_public (ax->kx_0, 1210 GNUNET_CRYPTO_ecdhe_key_get_public (ax->kx_0,
1143 &msg->ephemeral_key); 1211 &msg->ephemeral_key);
1144 GNUNET_CRYPTO_ecdhe_key_get_public (ax->DHRs, 1212 GNUNET_CRYPTO_ecdhe_key_get_public (ax->DHRs,
1145 &msg->ratchet_key); 1213 &msg->ratchet_key);
1146 1214 GCC_transmit (cc,
1147 // FIXME: send 'env'. 1215 env);
1148#if FIXME 1216 t->kx_retry_delay = GNUNET_TIME_STD_BACKOFF (t->kx_retry_delay);
1149 t->ephm_h = GCC_send_prebuilt_message (&msg.header, 1217 t->next_kx_attempt = GNUNET_TIME_relative_to_absolute (t->kx_retry_delay);
1150 UINT16_MAX,
1151 zero,
1152 c,
1153 GCC_is_origin (c, GNUNET_YES),
1154 GNUNET_YES, &ephm_sent, t);
1155 if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) 1218 if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate)
1156 GCT_change_estate (t, CADET_TUNNEL_KEY_SENT); 1219 GCT_change_estate (t,
1157#endif 1220 CADET_TUNNEL_KEY_SENT);
1158} 1221}
1159 1222
1160 1223
@@ -1193,10 +1256,10 @@ GCT_handle_kx (struct CadetTConnection *ct,
1193 1256
1194 if (0 != (GNUNET_CADET_KX_FLAG_FORCE_REPLY & ntohl (msg->flags))) 1257 if (0 != (GNUNET_CADET_KX_FLAG_FORCE_REPLY & ntohl (msg->flags)))
1195 { 1258 {
1196 if (NULL != t->rekey_task) 1259 if (NULL != t->kx_task)
1197 { 1260 {
1198 GNUNET_SCHEDULER_cancel (t->rekey_task); 1261 GNUNET_SCHEDULER_cancel (t->kx_task);
1199 t->rekey_task = NULL; 1262 t->kx_task = NULL;
1200 } 1263 }
1201 send_kx (t, 1264 send_kx (t,
1202 GNUNET_NO); 1265 GNUNET_NO);
@@ -1206,7 +1269,7 @@ GCT_handle_kx (struct CadetTConnection *ct,
1206 &msg->ratchet_key, 1269 &msg->ratchet_key,
1207 sizeof (msg->ratchet_key))) 1270 sizeof (msg->ratchet_key)))
1208 { 1271 {
1209 LOG (GNUNET_ERROR_TYPE_INFO, 1272 LOG (GNUNET_ERROR_TYPE_DEBUG,
1210 " known ratchet key, exit\n"); 1273 " known ratchet key, exit\n");
1211 return; 1274 return;
1212 } 1275 }
@@ -1290,12 +1353,29 @@ GCT_handle_kx (struct CadetTConnection *ct,
1290 ax->Nr = 0; 1353 ax->Nr = 0;
1291 ax->Ns = 0; 1354 ax->Ns = 0;
1292 1355
1293#if FIXME 1356 switch (t->estate)
1294 /* After KX is done, update state machine and begin transmissions... */ 1357 {
1295 GCT_change_estate (t, 1358 case CADET_TUNNEL_KEY_UNINITIALIZED:
1296 CADET_TUNNEL_KEY_PING); 1359 GCT_change_estate (t,
1297 send_queued_data (t); 1360 CADET_TUNNEL_KEY_PING);
1298#endif 1361 break;
1362 case CADET_TUNNEL_KEY_SENT:
1363 /* Got a response to us sending our key; now
1364 we can start transmitting! */
1365 GCT_change_estate (t,
1366 CADET_TUNNEL_KEY_OK);
1367 trigger_transmissions (t);
1368 break;
1369 case CADET_TUNNEL_KEY_PING:
1370 /* Got a key yet again; need encrypted payload to advance */
1371 break;
1372 case CADET_TUNNEL_KEY_OK:
1373 /* Did not expect a key, but so what. */
1374 break;
1375 case CADET_TUNNEL_KEY_REKEY:
1376 /* Got a key yet again; need encrypted payload to advance */
1377 break;
1378 }
1299} 1379}
1300 1380
1301 1381
@@ -1398,6 +1478,25 @@ destroy_tunnel (void *cls)
1398 1478
1399 1479
1400/** 1480/**
1481 * It's been a while, we should try to redo the KX, if we can.
1482 *
1483 * @param cls the `struct CadetTunnel` to do KX for.
1484 */
1485static void
1486retry_kx (void *cls)
1487{
1488 struct CadetTunnel *t = cls;
1489
1490 t->kx_task = NULL;
1491 send_kx (t,
1492 ( (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) ||
1493 (CADET_TUNNEL_KEY_SENT == t->estate) )
1494 ? GNUNET_YES
1495 : GNUNET_NO);
1496}
1497
1498
1499/**
1401 * A connection is @a is_ready for transmission. Looks at our message 1500 * A connection is @a is_ready for transmission. Looks at our message
1402 * queue and if there is a message, sends it out via the connection. 1501 * queue and if there is a message, sends it out via the connection.
1403 * 1502 *
@@ -1419,22 +1518,47 @@ connection_ready_cb (void *cls,
1419 return; 1518 return;
1420 } 1519 }
1421 ct->is_ready = GNUNET_YES; 1520 ct->is_ready = GNUNET_YES;
1422 if (NULL == tq) 1521 switch (t->estate)
1423 return; /* no messages pending right now */ 1522 {
1424 1523 case CADET_TUNNEL_KEY_UNINITIALIZED:
1425 /* ready to send message 'tq' on tunnel 'ct' */ 1524 send_kx (t,
1426 GNUNET_assert (t == tq->t); 1525 GNUNET_YES);
1427 GNUNET_CONTAINER_DLL_remove (t->tq_head, 1526 break;
1428 t->tq_tail, 1527 case CADET_TUNNEL_KEY_SENT:
1429 tq); 1528 case CADET_TUNNEL_KEY_PING:
1430 if (NULL != tq->cid) 1529 /* opportunity to #retry_kx() starts now, schedule job */
1431 *tq->cid = *GCC_get_id (ct->cc); 1530 if (NULL == t->kx_task)
1432 ct->is_ready = GNUNET_NO; 1531 {
1433 GCC_transmit (ct->cc, 1532 t->kx_task
1434 tq->env); 1533 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (t->next_kx_attempt),
1435 if (NULL != tq->cont) 1534 &retry_kx,
1436 tq->cont (tq->cont_cls); 1535 t);
1437 GNUNET_free (tq); 1536 }
1537 break;
1538 case CADET_TUNNEL_KEY_OK:
1539 /* send normal payload */
1540 if (NULL == tq)
1541 return; /* no messages pending right now */
1542 /* ready to send message 'tq' on tunnel 'ct' */
1543 GNUNET_assert (t == tq->t);
1544 GNUNET_CONTAINER_DLL_remove (t->tq_head,
1545 t->tq_tail,
1546 tq);
1547 if (NULL != tq->cid)
1548 *tq->cid = *GCC_get_id (ct->cc);
1549 ct->is_ready = GNUNET_NO;
1550 GCC_transmit (ct->cc,
1551 tq->env);
1552 if (NULL != tq->cont)
1553 tq->cont (tq->cont_cls);
1554 GNUNET_free (tq);
1555 break;
1556 case CADET_TUNNEL_KEY_REKEY:
1557 send_kx (t,
1558 GNUNET_NO);
1559 t->estate = CADET_TUNNEL_KEY_OK;
1560 break;
1561 }
1438} 1562}
1439 1563
1440 1564
@@ -1444,8 +1568,6 @@ connection_ready_cb (void *cls,
1444 * at our message queue and if there is a message, picks a connection 1568 * at our message queue and if there is a message, picks a connection
1445 * to send it on. 1569 * to send it on.
1446 * 1570 *
1447 * FIXME: yuck... Need better selection logic!
1448 *
1449 * @param t tunnel to process messages on 1571 * @param t tunnel to process messages on
1450 */ 1572 */
1451static void 1573static void
@@ -1455,11 +1577,7 @@ trigger_transmissions (struct CadetTunnel *t)
1455 1577
1456 if (NULL == t->tq_head) 1578 if (NULL == t->tq_head)
1457 return; /* no messages pending right now */ 1579 return; /* no messages pending right now */
1458 for (ct = t->connection_head; 1580 ct = get_ready_connection (t);
1459 NULL != ct;
1460 ct = ct->next)
1461 if (GNUNET_YES == ct->is_ready)
1462 break;
1463 if (NULL == ct) 1581 if (NULL == ct)
1464 return; /* no connections ready */ 1582 return; /* no connections ready */
1465 1583
@@ -1906,43 +2024,6 @@ GCT_remove_channel (struct CadetTunnel *t,
1906 2024
1907 2025
1908/** 2026/**
1909 * Change the tunnel encryption state.
1910 * If the encryption state changes to OK, stop the rekey task.
1911 *
1912 * @param t Tunnel whose encryption state to change, or NULL.
1913 * @param state New encryption state.
1914 */
1915void
1916GCT_change_estate (struct CadetTunnel *t,
1917 enum CadetTunnelEState state)
1918{
1919 enum CadetTunnelEState old = t->estate;
1920
1921 t->estate = state;
1922 LOG (GNUNET_ERROR_TYPE_DEBUG,
1923 "Tunnel %s estate changed from %d to %d\n",
1924 GCT_2s (t),
1925 old,
1926 state);
1927
1928 if ( (CADET_TUNNEL_KEY_OK != old) &&
1929 (CADET_TUNNEL_KEY_OK == t->estate) )
1930 {
1931 if (NULL != t->rekey_task)
1932 {
1933 GNUNET_SCHEDULER_cancel (t->rekey_task);
1934 t->rekey_task = NULL;
1935 }
1936#if FIXME
1937 /* Send queued data if tunnel is not loopback */
1938 if (myid != GCP_get_short_id (t->peer))
1939 send_queued_data (t);
1940#endif
1941 }
1942}
1943
1944
1945/**
1946 * Add a @a connection to the @a tunnel. 2027 * Add a @a connection to the @a tunnel.
1947 * 2028 *
1948 * @param t a tunnel 2029 * @param t a tunnel
@@ -1954,7 +2035,6 @@ GCT_add_inbound_connection (struct CadetTunnel *t,
1954 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 2035 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
1955 struct CadetPeerPath *path) 2036 struct CadetPeerPath *path)
1956{ 2037{
1957 struct CadetConnection *cc;
1958 struct CadetTConnection *ct; 2038 struct CadetTConnection *ct;
1959 2039
1960 ct = GNUNET_new (struct CadetTConnection); 2040 ct = GNUNET_new (struct CadetTConnection);
@@ -1992,11 +2072,36 @@ GCT_handle_encrypted (struct CadetTConnection *ct,
1992 char cbuf [size] GNUNET_ALIGN; 2072 char cbuf [size] GNUNET_ALIGN;
1993 ssize_t decrypted_size; 2073 ssize_t decrypted_size;
1994 2074
2075 switch (t->estate)
2076 {
2077 case CADET_TUNNEL_KEY_UNINITIALIZED:
2078 /* We did not even SEND our KX, how can the other peer
2079 send us encrypted data? */
2080 GNUNET_break_op (0);
2081 return;
2082 case CADET_TUNNEL_KEY_SENT:
2083 /* We did not get the KX of the other peer, but that
2084 might have been lost. Ask for KX again. */
2085 GNUNET_STATISTICS_update (stats,
2086 "# received encrypted without KX",
2087 1,
2088 GNUNET_NO);
2089 if (NULL != t->kx_task)
2090 GNUNET_SCHEDULER_cancel (t->kx_task);
2091 t->kx_task = GNUNET_SCHEDULER_add_now (&retry_kx,
2092 t);
2093 return;
2094 case CADET_TUNNEL_KEY_PING:
2095 /* Great, first payload, we might graduate to OK */
2096 case CADET_TUNNEL_KEY_OK:
2097 case CADET_TUNNEL_KEY_REKEY:
2098 break;
2099 }
2100
1995 GNUNET_STATISTICS_update (stats, 2101 GNUNET_STATISTICS_update (stats,
1996 "# received encrypted", 2102 "# received encrypted",
1997 1, 2103 1,
1998 GNUNET_NO); 2104 GNUNET_NO);
1999
2000 decrypted_size = t_ax_decrypt_and_validate (t, 2105 decrypted_size = t_ax_decrypt_and_validate (t,
2001 cbuf, 2106 cbuf,
2002 msg, 2107 msg,
@@ -2012,16 +2117,17 @@ GCT_handle_encrypted (struct CadetTConnection *ct,
2012 { 2117 {
2013 GNUNET_break_op (0); 2118 GNUNET_break_op (0);
2014 LOG (GNUNET_ERROR_TYPE_WARNING, 2119 LOG (GNUNET_ERROR_TYPE_WARNING,
2015 "Wrong crypto, tunnel %s\n", 2120 "Failed to decrypt message on tunnel %s\n",
2016 GCT_2s (t)); 2121 GCT_2s (t));
2017 GCT_debug (t,
2018 GNUNET_ERROR_TYPE_WARNING);
2019 } 2122 }
2020 return; 2123 return;
2021 } 2124 }
2022 2125 if (CADET_TUNNEL_KEY_PING == t->estate)
2023 GCT_change_estate (t, 2126 {
2024 CADET_TUNNEL_KEY_OK); 2127 GCT_change_estate (t,
2128 CADET_TUNNEL_KEY_OK);
2129 trigger_transmissions (t);
2130 }
2025 /* The MST will ultimately call #handle_decrypted() on each message. */ 2131 /* The MST will ultimately call #handle_decrypted() on each message. */
2026 GNUNET_break_op (GNUNET_OK == 2132 GNUNET_break_op (GNUNET_OK ==
2027 GNUNET_MST_from_buffer (t->mst, 2133 GNUNET_MST_from_buffer (t->mst,
@@ -2053,8 +2159,6 @@ GCT_send (struct CadetTunnel *t,
2053 struct GNUNET_MQ_Envelope *env; 2159 struct GNUNET_MQ_Envelope *env;
2054 struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg; 2160 struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg;
2055 2161
2056 /* FIXME: what about KX not yet being ready? (see "is_ready()" check in old code!) */
2057
2058 payload_size = ntohs (message->size); 2162 payload_size = ntohs (message->size);
2059 env = GNUNET_MQ_msg_extra (ax_msg, 2163 env = GNUNET_MQ_msg_extra (ax_msg,
2060 payload_size, 2164 payload_size,
@@ -2074,12 +2178,11 @@ GCT_send (struct CadetTunnel *t,
2074 0, 2178 0,
2075 &t->ax.HKs, 2179 &t->ax.HKs,
2076 &ax_msg->hmac); 2180 &ax_msg->hmac);
2077 // ax_msg->pid = htonl (GCC_get_pid (c, fwd)); // FIXME: connection flow-control not (re)implemented yet!
2078 2181
2079 tq = GNUNET_malloc (sizeof (*tq)); 2182 tq = GNUNET_malloc (sizeof (*tq));
2080 tq->t = t; 2183 tq->t = t;
2081 tq->env = env; 2184 tq->env = env;
2082 tq->cid = &ax_msg->cid; 2185 tq->cid = &ax_msg->cid; /* will initialize 'ax_msg->cid' once we know the connection */
2083 tq->cont = cont; 2186 tq->cont = cont;
2084 tq->cont_cls = cont_cls; 2187 tq->cont_cls = cont_cls;
2085 GNUNET_CONTAINER_DLL_insert_tail (t->tq_head, 2188 GNUNET_CONTAINER_DLL_insert_tail (t->tq_head,
@@ -2215,37 +2318,6 @@ debug_channel (void *cls,
2215 2318
2216 2319
2217/** 2320/**
2218 * Get string description for tunnel connectivity state.
2219 *
2220 * @param cs Tunnel state.
2221 *
2222 * @return String representation.
2223 */
2224static const char *
2225cstate2s (enum CadetTunnelCState cs)
2226{
2227 static char buf[32];
2228
2229 switch (cs)
2230 {
2231 case CADET_TUNNEL_NEW:
2232 return "CADET_TUNNEL_NEW";
2233 case CADET_TUNNEL_SEARCHING:
2234 return "CADET_TUNNEL_SEARCHING";
2235 case CADET_TUNNEL_WAITING:
2236 return "CADET_TUNNEL_WAITING";
2237 case CADET_TUNNEL_READY:
2238 return "CADET_TUNNEL_READY";
2239 case CADET_TUNNEL_SHUTDOWN:
2240 return "CADET_TUNNEL_SHUTDOWN";
2241 default:
2242 SPRINTF (buf, "%u (UNKNOWN STATE)", cs);
2243 return buf;
2244 }
2245}
2246
2247
2248/**
2249 * Get string description for tunnel encryption state. 2321 * Get string description for tunnel encryption state.
2250 * 2322 *
2251 * @param es Tunnel state. 2323 * @param es Tunnel state.
@@ -2299,9 +2371,8 @@ GCT_debug (const struct CadetTunnel *t,
2299 return; 2371 return;
2300 2372
2301 LOG2 (level, 2373 LOG2 (level,
2302 "TTT TUNNEL TOWARDS %s in cstate %s, estate %s tq_len: %u #cons: %u\n", 2374 "TTT TUNNEL TOWARDS %s in estate %s tq_len: %u #cons: %u\n",
2303 GCT_2s (t), 2375 GCT_2s (t),
2304 cstate2s (t->cstate),
2305 estate2s (t->estate), 2376 estate2s (t->estate),
2306 t->tq_len, 2377 t->tq_len,
2307 t->num_connections); 2378 t->num_connections);
diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.h b/src/cadet/gnunet-service-cadet-new_tunnels.h
index cd96a50bc..78c3cb6bb 100644
--- a/src/cadet/gnunet-service-cadet-new_tunnels.h
+++ b/src/cadet/gnunet-service-cadet-new_tunnels.h
@@ -39,45 +39,13 @@
39 39
40 40
41/** 41/**
42 * All the connectivity states a tunnel can be in.
43 */
44enum CadetTunnelCState
45{
46 /**
47 * Uninitialized status, should never appear in operation.
48 */
49 CADET_TUNNEL_NEW,
50
51 /**
52 * No path to the peer known yet.
53 */
54 CADET_TUNNEL_SEARCHING,
55
56 /**
57 * Request sent, not yet answered.
58 */
59 CADET_TUNNEL_WAITING,
60
61 /**
62 * Peer connected and ready to accept data.
63 */
64 CADET_TUNNEL_READY,
65
66 /**
67 * Tunnel being shut down, don't try to keep it alive.
68 */
69 CADET_TUNNEL_SHUTDOWN
70};
71
72
73
74/**
75 * All the encryption states a tunnel can be in. 42 * All the encryption states a tunnel can be in.
76 */ 43 */
77enum CadetTunnelEState 44enum CadetTunnelEState
78{ 45{
79 /** 46 /**
80 * Uninitialized status, should never appear in operation. 47 * Uninitialized status, we need to send KX. We will stay
48 * in this state until the first connection is up.
81 */ 49 */
82 CADET_TUNNEL_KEY_UNINITIALIZED, 50 CADET_TUNNEL_KEY_UNINITIALIZED,
83 51
@@ -87,19 +55,10 @@ enum CadetTunnelEState
87 CADET_TUNNEL_KEY_SENT, 55 CADET_TUNNEL_KEY_SENT,
88 56
89 /** 57 /**
90 * In OTR: New ephemeral key and ping sent, waiting for pong. 58 * Key received and we sent ours back, but we got no traffic yet.
91 * 59 * We will not yet send traffic, as this might have been a replay.
92 * This means that we DO have the peer's ephemeral key, otherwise the 60 * The other (initiating) peer should send a CHANNEL_OPEN next
93 * state would be KEY_SENT. We DO NOT have a valid session key (either no 61 * anyway.
94 * previous key or previous key expired).
95 *
96 *
97 * In Axolotl: Key sent and received but no deciphered traffic yet.
98 *
99 * This means that we can send traffic (otherwise we would never complete
100 * the handshake), but we don't have complete confirmation. Since the first
101 * traffic MUST be a complete channel creation 3-way handshake, no payload
102 * will be sent before confirmation.
103 */ 62 */
104 CADET_TUNNEL_KEY_PING, 63 CADET_TUNNEL_KEY_PING,
105 64
@@ -311,17 +270,6 @@ GCT_iterate_channels (struct CadetTunnel *t,
311 270
312 271
313/** 272/**
314 * Get the connectivity state of a tunnel.
315 *
316 * @param t Tunnel.
317 *
318 * @return Tunnel's connectivity state.
319 */
320enum CadetTunnelCState
321GCT_get_cstate (struct CadetTunnel *t);
322
323
324/**
325 * Get the encryption state of a tunnel. 273 * Get the encryption state of a tunnel.
326 * 274 *
327 * @param t Tunnel. 275 * @param t Tunnel.
diff --git a/src/cadet/gnunet-service-cadet_channel.h b/src/cadet/gnunet-service-cadet_channel.h
index 1eeebf34b..855d85b6c 100644
--- a/src/cadet/gnunet-service-cadet_channel.h
+++ b/src/cadet/gnunet-service-cadet_channel.h
@@ -72,6 +72,7 @@ GCCH_destroy (struct CadetChannel *ch);
72struct GNUNET_CADET_ChannelTunnelNumber 72struct GNUNET_CADET_ChannelTunnelNumber
73GCCH_get_id (const struct CadetChannel *ch); 73GCCH_get_id (const struct CadetChannel *ch);
74 74
75
75/** 76/**
76 * Get the channel tunnel. 77 * Get the channel tunnel.
77 * 78 *
@@ -82,6 +83,7 @@ GCCH_get_id (const struct CadetChannel *ch);
82struct CadetTunnel * 83struct CadetTunnel *
83GCCH_get_tunnel (const struct CadetChannel *ch); 84GCCH_get_tunnel (const struct CadetChannel *ch);
84 85
86
85/** 87/**
86 * Get free buffer space towards the client on a specific channel. 88 * Get free buffer space towards the client on a specific channel.
87 * 89 *