aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet_tunnel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/gnunet-service-cadet_tunnel.c')
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.c255
1 files changed, 133 insertions, 122 deletions
diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c
index 5b07e42c0..65775ce66 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.c
+++ b/src/cadet/gnunet-service-cadet_tunnel.c
@@ -63,7 +63,7 @@ struct CadetTChannel
63 63
64 64
65/** 65/**
66 * Connection list and metadata. 66 * Entry in list of connections used by tunnel, with metadata.
67 */ 67 */
68struct CadetTConnection 68struct CadetTConnection
69{ 69{
@@ -243,6 +243,7 @@ struct CadetTunnelAxolotl
243 struct GNUNET_TIME_Absolute ratchet_expiration; 243 struct GNUNET_TIME_Absolute ratchet_expiration;
244}; 244};
245 245
246
246/** 247/**
247 * Struct containing all information regarding a tunnel to a peer. 248 * Struct containing all information regarding a tunnel to a peer.
248 */ 249 */
@@ -309,7 +310,7 @@ struct CadetTunnel
309 /** 310 /**
310 * Channel ID for the next created channel. 311 * Channel ID for the next created channel.
311 */ 312 */
312 CADET_ChannelNumber next_chid; 313 struct GNUNET_CADET_ChannelTunnelNumber next_chid;
313 314
314 /** 315 /**
315 * Destroy flag: if true, destroy on last message. 316 * Destroy flag: if true, destroy on last message.
@@ -648,7 +649,7 @@ new_ephemeral (struct CadetTunnel *t)
648static void 649static void
649t_hmac (const void *plaintext, size_t size, 650t_hmac (const void *plaintext, size_t size,
650 uint32_t iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, 651 uint32_t iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
651 struct GNUNET_CADET_Hash *hmac) 652 struct GNUNET_ShortHashCode *hmac)
652{ 653{
653 static const char ctx[] = "cadet authentication key"; 654 static const char ctx[] = "cadet authentication key";
654 struct GNUNET_CRYPTO_AuthKey auth_key; 655 struct GNUNET_CRYPTO_AuthKey auth_key;
@@ -842,7 +843,7 @@ t_ax_decrypt (struct CadetTunnel *t, void *dst, const void *src, size_t size)
842 * @param msg Message whose header to encrypt. 843 * @param msg Message whose header to encrypt.
843 */ 844 */
844static void 845static void
845t_h_encrypt (struct CadetTunnel *t, struct GNUNET_CADET_Encrypted *msg) 846t_h_encrypt (struct CadetTunnel *t, struct GNUNET_CADET_TunnelEncryptedMessage *msg)
846{ 847{
847 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 848 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
848 struct CadetTunnelAxolotl *ax; 849 struct CadetTunnelAxolotl *ax;
@@ -873,8 +874,8 @@ t_h_encrypt (struct CadetTunnel *t, struct GNUNET_CADET_Encrypted *msg)
873 * @param dst Where to decrypt header to. 874 * @param dst Where to decrypt header to.
874 */ 875 */
875static void 876static void
876t_h_decrypt (struct CadetTunnel *t, const struct GNUNET_CADET_Encrypted *src, 877t_h_decrypt (struct CadetTunnel *t, const struct GNUNET_CADET_TunnelEncryptedMessage *src,
877 struct GNUNET_CADET_Encrypted *dst) 878 struct GNUNET_CADET_TunnelEncryptedMessage *dst)
878{ 879{
879 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 880 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
880 struct CadetTunnelAxolotl *ax; 881 struct CadetTunnelAxolotl *ax;
@@ -912,12 +913,12 @@ t_h_decrypt (struct CadetTunnel *t, const struct GNUNET_CADET_Encrypted *src,
912 */ 913 */
913static int 914static int
914try_old_ax_keys (struct CadetTunnel *t, void *dst, 915try_old_ax_keys (struct CadetTunnel *t, void *dst,
915 const struct GNUNET_CADET_Encrypted *src, size_t size) 916 const struct GNUNET_CADET_TunnelEncryptedMessage *src, size_t size)
916{ 917{
917 struct CadetTunnelSkippedKey *key; 918 struct CadetTunnelSkippedKey *key;
918 struct GNUNET_CADET_Hash *hmac; 919 struct GNUNET_ShortHashCode *hmac;
919 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 920 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
920 struct GNUNET_CADET_Encrypted plaintext_header; 921 struct GNUNET_CADET_TunnelEncryptedMessage plaintext_header;
921 struct GNUNET_CRYPTO_SymmetricSessionKey *valid_HK; 922 struct GNUNET_CRYPTO_SymmetricSessionKey *valid_HK;
922 size_t esize; 923 size_t esize;
923 size_t res; 924 size_t res;
@@ -926,7 +927,7 @@ try_old_ax_keys (struct CadetTunnel *t, void *dst,
926 927
927 LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying old keys\n"); 928 LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying old keys\n");
928 hmac = &plaintext_header.hmac; 929 hmac = &plaintext_header.hmac;
929 esize = size - sizeof (struct GNUNET_CADET_Encrypted); 930 esize = size - sizeof (struct GNUNET_CADET_TunnelEncryptedMessage);
930 931
931 /* Find a correct Header Key */ 932 /* Find a correct Header Key */
932 for (key = t->ax->skipped_head; NULL != key; key = key->next) 933 for (key = t->ax->skipped_head; NULL != key; key = key->next)
@@ -947,8 +948,8 @@ try_old_ax_keys (struct CadetTunnel *t, void *dst,
947 return -1; 948 return -1;
948 949
949 /* Should've been checked in -cadet_connection.c handle_cadet_encrypted. */ 950 /* Should've been checked in -cadet_connection.c handle_cadet_encrypted. */
950 GNUNET_assert (size > sizeof (struct GNUNET_CADET_Encrypted)); 951 GNUNET_assert (size > sizeof (struct GNUNET_CADET_TunnelEncryptedMessage));
951 len = size - sizeof (struct GNUNET_CADET_Encrypted); 952 len = size - sizeof (struct GNUNET_CADET_TunnelEncryptedMessage);
952 GNUNET_assert (len >= sizeof (struct GNUNET_MessageHeader)); 953 GNUNET_assert (len >= sizeof (struct GNUNET_MessageHeader));
953 954
954 /* Decrypt header */ 955 /* Decrypt header */
@@ -1091,19 +1092,19 @@ store_ax_keys (struct CadetTunnel *t,
1091 */ 1092 */
1092static int 1093static int
1093t_ax_decrypt_and_validate (struct CadetTunnel *t, void *dst, 1094t_ax_decrypt_and_validate (struct CadetTunnel *t, void *dst,
1094 const struct GNUNET_CADET_Encrypted *src, 1095 const struct GNUNET_CADET_TunnelEncryptedMessage *src,
1095 size_t size) 1096 size_t size)
1096{ 1097{
1097 struct CadetTunnelAxolotl *ax; 1098 struct CadetTunnelAxolotl *ax;
1098 struct GNUNET_CADET_Hash msg_hmac; 1099 struct GNUNET_ShortHashCode msg_hmac;
1099 struct GNUNET_HashCode hmac; 1100 struct GNUNET_HashCode hmac;
1100 struct GNUNET_CADET_Encrypted plaintext_header; 1101 struct GNUNET_CADET_TunnelEncryptedMessage plaintext_header;
1101 uint32_t Np; 1102 uint32_t Np;
1102 uint32_t PNp; 1103 uint32_t PNp;
1103 size_t esize; /* Size of encryped payload */ 1104 size_t esize; /* Size of encryped payload */
1104 size_t osize; /* Size of output (decrypted payload) */ 1105 size_t osize; /* Size of output (decrypted payload) */
1105 1106
1106 esize = size - sizeof (struct GNUNET_CADET_Encrypted); 1107 esize = size - sizeof (struct GNUNET_CADET_TunnelEncryptedMessage);
1107 ax = t->ax; 1108 ax = t->ax;
1108 if (NULL == ax) 1109 if (NULL == ax)
1109 return -1; 1110 return -1;
@@ -1321,12 +1322,11 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1321 struct CadetTunnelQueue *existing_q) 1322 struct CadetTunnelQueue *existing_q)
1322{ 1323{
1323 struct GNUNET_MessageHeader *msg; 1324 struct GNUNET_MessageHeader *msg;
1324 struct GNUNET_CADET_Encrypted *ax_msg; 1325 struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg;
1325 struct CadetTunnelQueue *tq; 1326 struct CadetTunnelQueue *tq;
1326 size_t size = ntohs (message->size); 1327 size_t size = ntohs (message->size);
1327 char cbuf[sizeof (struct GNUNET_CADET_Encrypted) + size] GNUNET_ALIGN; 1328 char cbuf[sizeof (struct GNUNET_CADET_TunnelEncryptedMessage) + size] GNUNET_ALIGN;
1328 size_t esize; 1329 size_t esize;
1329 uint32_t mid;
1330 uint16_t type; 1330 uint16_t type;
1331 int fwd; 1331 int fwd;
1332 1332
@@ -1352,10 +1352,10 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1352 1352
1353 GNUNET_assert (GNUNET_NO == GCT_is_loopback (t)); 1353 GNUNET_assert (GNUNET_NO == GCT_is_loopback (t));
1354 1354
1355 ax_msg = (struct GNUNET_CADET_Encrypted *) cbuf; 1355 ax_msg = (struct GNUNET_CADET_TunnelEncryptedMessage *) cbuf;
1356 msg = &ax_msg->header; 1356 msg = &ax_msg->header;
1357 msg->size = htons (sizeof (struct GNUNET_CADET_Encrypted) + size); 1357 msg->size = htons (sizeof (struct GNUNET_CADET_TunnelEncryptedMessage) + size);
1358 msg->type = htons (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED); 1358 msg->type = htons (GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED);
1359 esize = t_ax_encrypt (t, &ax_msg[1], message, size); 1359 esize = t_ax_encrypt (t, &ax_msg[1], message, size);
1360 ax_msg->Ns = htonl (t->ax->Ns++); 1360 ax_msg->Ns = htonl (t->ax->Ns++);
1361 ax_msg->PNs = htonl (t->ax->PNs); 1361 ax_msg->PNs = htonl (t->ax->PNs);
@@ -1378,34 +1378,22 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1378 } 1378 }
1379 fwd = GCC_is_origin (c, GNUNET_YES); 1379 fwd = GCC_is_origin (c, GNUNET_YES);
1380 ax_msg->cid = *GCC_get_id (c); 1380 ax_msg->cid = *GCC_get_id (c);
1381 ax_msg->pid = htonl (GCC_get_pid (c, fwd)); 1381 ax_msg->cemi = GCC_get_pid (c, fwd);
1382 1382
1383 mid = 0; 1383 type = htons (message->type);
1384 type = ntohs (message->type); 1384 LOG (GNUNET_ERROR_TYPE_DEBUG,
1385 switch (type) 1385 "Sending message of type %s with CEMI %u and CID %s\n",
1386 { 1386 GC_m2s (type),
1387 case GNUNET_MESSAGE_TYPE_CADET_DATA: 1387 htonl (ax_msg->cemi.pid),
1388 case GNUNET_MESSAGE_TYPE_CADET_DATA_ACK: 1388 GNUNET_sh2s (&ax_msg->cid.connection_of_tunnel));
1389 if (GNUNET_MESSAGE_TYPE_CADET_DATA == type)
1390 mid = ntohl (((struct GNUNET_CADET_Data *) message)->mid);
1391 else
1392 mid = ntohl (((struct GNUNET_CADET_DataACK *) message)->mid);
1393 /* Fall thru */
1394 case GNUNET_MESSAGE_TYPE_CADET_KEEPALIVE:
1395 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE:
1396 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY:
1397 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK:
1398 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK:
1399 break;
1400 default:
1401 GNUNET_break (0);
1402 LOG (GNUNET_ERROR_TYPE_ERROR, "type %s not valid\n", GC_m2s (type));
1403 }
1404 LOG (GNUNET_ERROR_TYPE_DEBUG, "type %s\n", GC_m2s (type));
1405 1389
1406 if (NULL == cont) 1390 if (NULL == cont)
1407 { 1391 {
1408 (void) GCC_send_prebuilt_message (msg, type, mid, c, fwd, 1392 (void) GCC_send_prebuilt_message (msg,
1393 type,
1394 ax_msg->cemi,
1395 c,
1396 fwd,
1409 force, NULL, NULL); 1397 force, NULL, NULL);
1410 return NULL; 1398 return NULL;
1411 } 1399 }
@@ -1418,11 +1406,16 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1418 tq = existing_q; 1406 tq = existing_q;
1419 tq->tqd = NULL; 1407 tq->tqd = NULL;
1420 } 1408 }
1421 tq->cq = GCC_send_prebuilt_message (msg, type, mid, c, fwd, force,
1422 &tun_message_sent, tq);
1423 GNUNET_assert (NULL != tq->cq);
1424 tq->cont = cont; 1409 tq->cont = cont;
1425 tq->cont_cls = cont_cls; 1410 tq->cont_cls = cont_cls;
1411 tq->cq = GCC_send_prebuilt_message (msg,
1412 type,
1413 ax_msg->cemi,
1414 c,
1415 fwd,
1416 force,
1417 &tun_message_sent, tq);
1418 GNUNET_assert (NULL != tq->cq);
1426 1419
1427 return tq; 1420 return tq;
1428} 1421}
@@ -1562,17 +1555,19 @@ destroy_iterator (void *cls,
1562 * @param gid ID of the channel. 1555 * @param gid ID of the channel.
1563 */ 1556 */
1564static void 1557static void
1565send_channel_destroy (struct CadetTunnel *t, unsigned int gid) 1558send_channel_destroy (struct CadetTunnel *t,
1559 struct GNUNET_CADET_ChannelTunnelNumber gid)
1566{ 1560{
1567 struct GNUNET_CADET_ChannelManage msg; 1561 struct GNUNET_CADET_ChannelManageMessage msg;
1568 1562
1569 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); 1563 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
1570 msg.header.size = htons (sizeof (msg)); 1564 msg.header.size = htons (sizeof (msg));
1571 msg.chid = htonl (gid); 1565 msg.chid = gid;
1572 1566
1573 LOG (GNUNET_ERROR_TYPE_DEBUG, 1567 LOG (GNUNET_ERROR_TYPE_DEBUG,
1574 "WARNING destroying unknown channel %u on tunnel %s\n", 1568 "WARNING destroying unknown channel %u on tunnel %s\n",
1575 gid, GCT_2s (t)); 1569 ntohl (gid.cn),
1570 GCT_2s (t));
1576 send_prebuilt_message (&msg.header, t, NULL, GNUNET_YES, NULL, NULL, NULL); 1571 send_prebuilt_message (&msg.header, t, NULL, GNUNET_YES, NULL, NULL, NULL);
1577} 1572}
1578 1573
@@ -1589,7 +1584,7 @@ send_channel_destroy (struct CadetTunnel *t, unsigned int gid)
1589 */ 1584 */
1590static void 1585static void
1591handle_data (struct CadetTunnel *t, 1586handle_data (struct CadetTunnel *t,
1592 const struct GNUNET_CADET_Data *msg, 1587 const struct GNUNET_CADET_ChannelAppDataMessage *msg,
1593 int fwd) 1588 int fwd)
1594{ 1589{
1595 struct CadetChannel *ch; 1590 struct CadetChannel *ch;
@@ -1600,7 +1595,7 @@ handle_data (struct CadetTunnel *t,
1600 /* Check size */ 1595 /* Check size */
1601 size = ntohs (msg->header.size); 1596 size = ntohs (msg->header.size);
1602 if (size < 1597 if (size <
1603 sizeof (struct GNUNET_CADET_Data) + 1598 sizeof (struct GNUNET_CADET_ChannelAppDataMessage) +
1604 sizeof (struct GNUNET_MessageHeader)) 1599 sizeof (struct GNUNET_MessageHeader))
1605 { 1600 {
1606 GNUNET_break (0); 1601 GNUNET_break (0);
@@ -1613,13 +1608,17 @@ handle_data (struct CadetTunnel *t,
1613 1608
1614 1609
1615 /* Check channel */ 1610 /* Check channel */
1616 ch = GCT_get_channel (t, ntohl (msg->chid)); 1611 ch = GCT_get_channel (t, msg->chid);
1617 if (NULL == ch) 1612 if (NULL == ch)
1618 { 1613 {
1619 GNUNET_STATISTICS_update (stats, "# data on unknown channel", 1614 GNUNET_STATISTICS_update (stats,
1620 1, GNUNET_NO); 1615 "# data on unknown channel",
1621 LOG (GNUNET_ERROR_TYPE_DEBUG, "channel 0x%X unknown\n", ntohl (msg->chid)); 1616 1,
1622 send_channel_destroy (t, ntohl (msg->chid)); 1617 GNUNET_NO);
1618 LOG (GNUNET_ERROR_TYPE_DEBUG,
1619 "channel 0x%X unknown\n",
1620 ntohl (msg->chid.cn));
1621 send_channel_destroy (t, msg->chid);
1623 return; 1622 return;
1624 } 1623 }
1625 1624
@@ -1639,7 +1638,7 @@ handle_data (struct CadetTunnel *t,
1639 */ 1638 */
1640static void 1639static void
1641handle_data_ack (struct CadetTunnel *t, 1640handle_data_ack (struct CadetTunnel *t,
1642 const struct GNUNET_CADET_DataACK *msg, 1641 const struct GNUNET_CADET_ChannelDataAckMessage *msg,
1643 int fwd) 1642 int fwd)
1644{ 1643{
1645 struct CadetChannel *ch; 1644 struct CadetChannel *ch;
@@ -1647,20 +1646,20 @@ handle_data_ack (struct CadetTunnel *t,
1647 1646
1648 /* Check size */ 1647 /* Check size */
1649 size = ntohs (msg->header.size); 1648 size = ntohs (msg->header.size);
1650 if (size != sizeof (struct GNUNET_CADET_DataACK)) 1649 if (size != sizeof (struct GNUNET_CADET_ChannelDataAckMessage))
1651 { 1650 {
1652 GNUNET_break (0); 1651 GNUNET_break (0);
1653 return; 1652 return;
1654 } 1653 }
1655 1654
1656 /* Check channel */ 1655 /* Check channel */
1657 ch = GCT_get_channel (t, ntohl (msg->chid)); 1656 ch = GCT_get_channel (t, msg->chid);
1658 if (NULL == ch) 1657 if (NULL == ch)
1659 { 1658 {
1660 GNUNET_STATISTICS_update (stats, "# data ack on unknown channel", 1659 GNUNET_STATISTICS_update (stats, "# data ack on unknown channel",
1661 1, GNUNET_NO); 1660 1, GNUNET_NO);
1662 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", 1661 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n",
1663 ntohl (msg->chid)); 1662 ntohl (msg->chid.cn));
1664 return; 1663 return;
1665 } 1664 }
1666 1665
@@ -1676,21 +1675,21 @@ handle_data_ack (struct CadetTunnel *t,
1676 */ 1675 */
1677static void 1676static void
1678handle_ch_create (struct CadetTunnel *t, 1677handle_ch_create (struct CadetTunnel *t,
1679 const struct GNUNET_CADET_ChannelCreate *msg) 1678 const struct GNUNET_CADET_ChannelOpenMessage *msg)
1680{ 1679{
1681 struct CadetChannel *ch; 1680 struct CadetChannel *ch;
1682 size_t size; 1681 size_t size;
1683 1682
1684 /* Check size */ 1683 /* Check size */
1685 size = ntohs (msg->header.size); 1684 size = ntohs (msg->header.size);
1686 if (size != sizeof (struct GNUNET_CADET_ChannelCreate)) 1685 if (size != sizeof (struct GNUNET_CADET_ChannelOpenMessage))
1687 { 1686 {
1688 GNUNET_break_op (0); 1687 GNUNET_break_op (0);
1689 return; 1688 return;
1690 } 1689 }
1691 1690
1692 /* Check channel */ 1691 /* Check channel */
1693 ch = GCT_get_channel (t, ntohl (msg->chid)); 1692 ch = GCT_get_channel (t, msg->chid);
1694 if (NULL != ch && ! GCT_is_loopback (t)) 1693 if (NULL != ch && ! GCT_is_loopback (t))
1695 { 1694 {
1696 /* Probably a retransmission, safe to ignore */ 1695 /* Probably a retransmission, safe to ignore */
@@ -1711,27 +1710,28 @@ handle_ch_create (struct CadetTunnel *t,
1711 */ 1710 */
1712static void 1711static void
1713handle_ch_nack (struct CadetTunnel *t, 1712handle_ch_nack (struct CadetTunnel *t,
1714 const struct GNUNET_CADET_ChannelManage *msg) 1713 const struct GNUNET_CADET_ChannelManageMessage *msg)
1715{ 1714{
1716 struct CadetChannel *ch; 1715 struct CadetChannel *ch;
1717 size_t size; 1716 size_t size;
1718 1717
1719 /* Check size */ 1718 /* Check size */
1720 size = ntohs (msg->header.size); 1719 size = ntohs (msg->header.size);
1721 if (size != sizeof (struct GNUNET_CADET_ChannelManage)) 1720 if (size != sizeof (struct GNUNET_CADET_ChannelManageMessage))
1722 { 1721 {
1723 GNUNET_break (0); 1722 GNUNET_break (0);
1724 return; 1723 return;
1725 } 1724 }
1726 1725
1727 /* Check channel */ 1726 /* Check channel */
1728 ch = GCT_get_channel (t, ntohl (msg->chid)); 1727 ch = GCT_get_channel (t, msg->chid);
1729 if (NULL == ch) 1728 if (NULL == ch)
1730 { 1729 {
1731 GNUNET_STATISTICS_update (stats, "# channel NACK on unknown channel", 1730 GNUNET_STATISTICS_update (stats, "# channel NACK on unknown channel",
1732 1, GNUNET_NO); 1731 1, GNUNET_NO);
1733 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", 1732 LOG (GNUNET_ERROR_TYPE_DEBUG,
1734 ntohl (msg->chid)); 1733 "WARNING channel %u unknown\n",
1734 ntohl (msg->chid.cn));
1735 return; 1735 return;
1736 } 1736 }
1737 1737
@@ -1751,7 +1751,7 @@ handle_ch_nack (struct CadetTunnel *t,
1751 */ 1751 */
1752static void 1752static void
1753handle_ch_ack (struct CadetTunnel *t, 1753handle_ch_ack (struct CadetTunnel *t,
1754 const struct GNUNET_CADET_ChannelManage *msg, 1754 const struct GNUNET_CADET_ChannelManageMessage *msg,
1755 int fwd) 1755 int fwd)
1756{ 1756{
1757 struct CadetChannel *ch; 1757 struct CadetChannel *ch;
@@ -1759,20 +1759,23 @@ handle_ch_ack (struct CadetTunnel *t,
1759 1759
1760 /* Check size */ 1760 /* Check size */
1761 size = ntohs (msg->header.size); 1761 size = ntohs (msg->header.size);
1762 if (size != sizeof (struct GNUNET_CADET_ChannelManage)) 1762 if (size != sizeof (struct GNUNET_CADET_ChannelManageMessage))
1763 { 1763 {
1764 GNUNET_break (0); 1764 GNUNET_break (0);
1765 return; 1765 return;
1766 } 1766 }
1767 1767
1768 /* Check channel */ 1768 /* Check channel */
1769 ch = GCT_get_channel (t, ntohl (msg->chid)); 1769 ch = GCT_get_channel (t, msg->chid);
1770 if (NULL == ch) 1770 if (NULL == ch)
1771 { 1771 {
1772 GNUNET_STATISTICS_update (stats, "# channel ack on unknown channel", 1772 GNUNET_STATISTICS_update (stats,
1773 1, GNUNET_NO); 1773 "# channel ack on unknown channel",
1774 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", 1774 1,
1775 ntohl (msg->chid)); 1775 GNUNET_NO);
1776 LOG (GNUNET_ERROR_TYPE_DEBUG,
1777 "WARNING channel %u unknown\n",
1778 ntohl (msg->chid.cn));
1776 return; 1779 return;
1777 } 1780 }
1778 1781
@@ -1792,7 +1795,7 @@ handle_ch_ack (struct CadetTunnel *t,
1792 */ 1795 */
1793static void 1796static void
1794handle_ch_destroy (struct CadetTunnel *t, 1797handle_ch_destroy (struct CadetTunnel *t,
1795 const struct GNUNET_CADET_ChannelManage *msg, 1798 const struct GNUNET_CADET_ChannelManageMessage *msg,
1796 int fwd) 1799 int fwd)
1797{ 1800{
1798 struct CadetChannel *ch; 1801 struct CadetChannel *ch;
@@ -1800,14 +1803,14 @@ handle_ch_destroy (struct CadetTunnel *t,
1800 1803
1801 /* Check size */ 1804 /* Check size */
1802 size = ntohs (msg->header.size); 1805 size = ntohs (msg->header.size);
1803 if (size != sizeof (struct GNUNET_CADET_ChannelManage)) 1806 if (size != sizeof (struct GNUNET_CADET_ChannelManageMessage))
1804 { 1807 {
1805 GNUNET_break (0); 1808 GNUNET_break (0);
1806 return; 1809 return;
1807 } 1810 }
1808 1811
1809 /* Check channel */ 1812 /* Check channel */
1810 ch = GCT_get_channel (t, ntohl (msg->chid)); 1813 ch = GCT_get_channel (t, msg->chid);
1811 if (NULL == ch) 1814 if (NULL == ch)
1812 { 1815 {
1813 /* Probably a retransmission, safe to ignore */ 1816 /* Probably a retransmission, safe to ignore */
@@ -1877,34 +1880,34 @@ handle_decrypted (struct CadetTunnel *t,
1877 1880
1878 switch (type) 1881 switch (type)
1879 { 1882 {
1880 case GNUNET_MESSAGE_TYPE_CADET_KEEPALIVE: 1883 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE:
1881 /* Do nothing, connection aleady got updated. */ 1884 /* Do nothing, connection aleady got updated. */
1882 GNUNET_STATISTICS_update (stats, "# keepalives received", 1, GNUNET_NO); 1885 GNUNET_STATISTICS_update (stats, "# keepalives received", 1, GNUNET_NO);
1883 break; 1886 break;
1884 1887
1885 case GNUNET_MESSAGE_TYPE_CADET_DATA: 1888 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA:
1886 /* Don't send hop ACK, wait for client to ACK */ 1889 /* Don't send hop ACK, wait for client to ACK */
1887 handle_data (t, (struct GNUNET_CADET_Data *) msgh, fwd); 1890 handle_data (t, (struct GNUNET_CADET_ChannelAppDataMessage *) msgh, fwd);
1888 break; 1891 break;
1889 1892
1890 case GNUNET_MESSAGE_TYPE_CADET_DATA_ACK: 1893 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK:
1891 handle_data_ack (t, (struct GNUNET_CADET_DataACK *) msgh, fwd); 1894 handle_data_ack (t, (struct GNUNET_CADET_ChannelDataAckMessage *) msgh, fwd);
1892 break; 1895 break;
1893 1896
1894 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE: 1897 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN:
1895 handle_ch_create (t, (struct GNUNET_CADET_ChannelCreate *) msgh); 1898 handle_ch_create (t, (struct GNUNET_CADET_ChannelOpenMessage *) msgh);
1896 break; 1899 break;
1897 1900
1898 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK: 1901 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_NACK_DEPRECATED:
1899 handle_ch_nack (t, (struct GNUNET_CADET_ChannelManage *) msgh); 1902 handle_ch_nack (t, (struct GNUNET_CADET_ChannelManageMessage *) msgh);
1900 break; 1903 break;
1901 1904
1902 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK: 1905 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK:
1903 handle_ch_ack (t, (struct GNUNET_CADET_ChannelManage *) msgh, fwd); 1906 handle_ch_ack (t, (struct GNUNET_CADET_ChannelManageMessage *) msgh, fwd);
1904 break; 1907 break;
1905 1908
1906 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY: 1909 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY:
1907 handle_ch_destroy (t, (struct GNUNET_CADET_ChannelManage *) msgh, fwd); 1910 handle_ch_destroy (t, (struct GNUNET_CADET_ChannelManageMessage *) msgh, fwd);
1908 break; 1911 break;
1909 1912
1910 default: 1913 default:
@@ -1931,7 +1934,7 @@ handle_decrypted (struct CadetTunnel *t,
1931 */ 1934 */
1932void 1935void
1933GCT_handle_encrypted (struct CadetTunnel *t, 1936GCT_handle_encrypted (struct CadetTunnel *t,
1934 const struct GNUNET_CADET_Encrypted *msg) 1937 const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
1935{ 1938{
1936 uint16_t size = ntohs (msg->header.size); 1939 uint16_t size = ntohs (msg->header.size);
1937 char cbuf [size]; 1940 char cbuf [size];
@@ -1990,7 +1993,7 @@ GCT_handle_encrypted (struct CadetTunnel *t,
1990 */ 1993 */
1991void 1994void
1992GCT_handle_kx (struct CadetTunnel *t, 1995GCT_handle_kx (struct CadetTunnel *t,
1993 const struct GNUNET_CADET_KX *msg) 1996 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
1994{ 1997{
1995 struct CadetTunnelAxolotl *ax; 1998 struct CadetTunnelAxolotl *ax;
1996 struct GNUNET_HashCode key_material[3]; 1999 struct GNUNET_HashCode key_material[3];
@@ -2143,9 +2146,9 @@ GCT_init (const struct GNUNET_CONFIGURATION_Handle *c,
2143 LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n"); 2146 LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n");
2144 2147
2145 expected_overhead = 0; 2148 expected_overhead = 0;
2146 expected_overhead += sizeof (struct GNUNET_CADET_Encrypted); 2149 expected_overhead += sizeof (struct GNUNET_CADET_TunnelEncryptedMessage);
2147 expected_overhead += sizeof (struct GNUNET_CADET_Data); 2150 expected_overhead += sizeof (struct GNUNET_CADET_ChannelAppDataMessage);
2148 expected_overhead += sizeof (struct GNUNET_CADET_ACK); 2151 expected_overhead += sizeof (struct GNUNET_CADET_ConnectionEncryptedAckMessage);
2149 GNUNET_assert (GNUNET_CONSTANTS_CADET_P2P_OVERHEAD == expected_overhead); 2152 GNUNET_assert (GNUNET_CONSTANTS_CADET_P2P_OVERHEAD == expected_overhead);
2150 2153
2151 if (GNUNET_OK != 2154 if (GNUNET_OK !=
@@ -2200,7 +2203,7 @@ GCT_new (struct CadetPeer *destination)
2200 struct CadetTunnel *t; 2203 struct CadetTunnel *t;
2201 2204
2202 t = GNUNET_new (struct CadetTunnel); 2205 t = GNUNET_new (struct CadetTunnel);
2203 t->next_chid = 0; 2206 t->next_chid.cn = 0;
2204 t->peer = destination; 2207 t->peer = destination;
2205 2208
2206 if (GNUNET_OK != 2209 if (GNUNET_OK !=
@@ -2442,7 +2445,8 @@ GCT_remove_connection (struct CadetTunnel *t,
2442 * @param ch Channel. 2445 * @param ch Channel.
2443 */ 2446 */
2444void 2447void
2445GCT_add_channel (struct CadetTunnel *t, struct CadetChannel *ch) 2448GCT_add_channel (struct CadetTunnel *t,
2449 struct CadetChannel *ch)
2446{ 2450{
2447 struct CadetTChannel *aux; 2451 struct CadetTChannel *aux;
2448 2452
@@ -2510,7 +2514,8 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch)
2510 * @return channel handler, NULL if doesn't exist 2514 * @return channel handler, NULL if doesn't exist
2511 */ 2515 */
2512struct CadetChannel * 2516struct CadetChannel *
2513GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid) 2517GCT_get_channel (struct CadetTunnel *t,
2518 struct GNUNET_CADET_ChannelTunnelNumber chid)
2514{ 2519{
2515 struct CadetTChannel *iter; 2520 struct CadetTChannel *iter;
2516 2521
@@ -2519,7 +2524,7 @@ GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid)
2519 2524
2520 for (iter = t->channel_head; NULL != iter; iter = iter->next) 2525 for (iter = t->channel_head; NULL != iter; iter = iter->next)
2521 { 2526 {
2522 if (GCCH_get_id (iter->ch) == chid) 2527 if (GCCH_get_id (iter->ch).cn == chid.cn)
2523 break; 2528 break;
2524 } 2529 }
2525 2530
@@ -2659,7 +2664,7 @@ GCT_destroy (struct CadetTunnel *t)
2659 2664
2660 mh = (struct GNUNET_MessageHeader *) &t->tq_head[1]; 2665 mh = (struct GNUNET_MessageHeader *) &t->tq_head[1];
2661 type = ntohs (mh->type); 2666 type = ntohs (mh->type);
2662 if (0 == keepalives_queued && GNUNET_MESSAGE_TYPE_CADET_KEEPALIVE == type) 2667 if (0 == keepalives_queued && GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE == type)
2663 { 2668 {
2664 keepalives_queued = 1; 2669 keepalives_queued = 1;
2665 LOG (GNUNET_ERROR_TYPE_DEBUG, 2670 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2727,7 +2732,7 @@ struct CadetConnection *
2727GCT_use_path (struct CadetTunnel *t, struct CadetPeerPath *path) 2732GCT_use_path (struct CadetTunnel *t, struct CadetPeerPath *path)
2728{ 2733{
2729 struct CadetConnection *c; 2734 struct CadetConnection *c;
2730 struct GNUNET_CADET_Hash cid; 2735 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
2731 unsigned int own_pos; 2736 unsigned int own_pos;
2732 2737
2733 if (NULL == t || NULL == path) 2738 if (NULL == t || NULL == path)
@@ -2966,11 +2971,11 @@ GCT_get_destination (struct CadetTunnel *t)
2966 * 2971 *
2967 * @return GID of a channel free to use. 2972 * @return GID of a channel free to use.
2968 */ 2973 */
2969CADET_ChannelNumber 2974struct GNUNET_CADET_ChannelTunnelNumber
2970GCT_get_next_chid (struct CadetTunnel *t) 2975GCT_get_next_chid (struct CadetTunnel *t)
2971{ 2976{
2972 CADET_ChannelNumber chid; 2977 struct GNUNET_CADET_ChannelTunnelNumber chid;
2973 CADET_ChannelNumber mask; 2978 struct GNUNET_CADET_ChannelTunnelNumber mask;
2974 int result; 2979 int result;
2975 2980
2976 /* Set bit 30 depending on the ID relationship. Bit 31 is always 0 for GID. 2981 /* Set bit 30 depending on the ID relationship. Bit 31 is always 0 for GID.
@@ -2979,20 +2984,22 @@ GCT_get_next_chid (struct CadetTunnel *t)
2979 */ 2984 */
2980 result = GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, GCP_get_id (t->peer)); 2985 result = GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, GCP_get_id (t->peer));
2981 if (0 > result) 2986 if (0 > result)
2982 mask = 0x40000000; 2987 mask.cn = htonl (0x40000000);
2983 else 2988 else
2984 mask = 0x0; 2989 mask.cn = 0x0;
2985 t->next_chid |= mask; 2990 t->next_chid.cn |= mask.cn;
2986 2991
2987 while (NULL != GCT_get_channel (t, t->next_chid)) 2992 while (NULL != GCT_get_channel (t, t->next_chid))
2988 { 2993 {
2989 LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %u exists...\n", t->next_chid); 2994 LOG (GNUNET_ERROR_TYPE_DEBUG,
2990 t->next_chid = (t->next_chid + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 2995 "Channel %u exists...\n",
2991 t->next_chid |= mask; 2996 t->next_chid.cn);
2997 t->next_chid.cn = htonl ((ntohl (t->next_chid.cn) + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
2998 t->next_chid.cn |= mask.cn;
2992 } 2999 }
2993 chid = t->next_chid; 3000 chid = t->next_chid;
2994 t->next_chid = (t->next_chid + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 3001 t->next_chid.cn = (t->next_chid.cn + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI;
2995 t->next_chid |= mask; 3002 t->next_chid.cn |= mask.cn;
2996 3003
2997 return chid; 3004 return chid;
2998} 3005}
@@ -3185,7 +3192,8 @@ GCT_has_queued_traffic (struct CadetTunnel *t)
3185 */ 3192 */
3186struct CadetTunnelQueue * 3193struct CadetTunnelQueue *
3187GCT_send_prebuilt_message (const struct GNUNET_MessageHeader *message, 3194GCT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
3188 struct CadetTunnel *t, struct CadetConnection *c, 3195 struct CadetTunnel *t,
3196 struct CadetConnection *c,
3189 int force, GCT_sent cont, void *cont_cls) 3197 int force, GCT_sent cont, void *cont_cls)
3190{ 3198{
3191 return send_prebuilt_message (message, t, c, force, cont, cont_cls, NULL); 3199 return send_prebuilt_message (message, t, c, force, cont, cont_cls, NULL);
@@ -3201,8 +3209,9 @@ GCT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
3201void 3209void
3202GCT_send_kx (struct CadetTunnel *t, int force_reply) 3210GCT_send_kx (struct CadetTunnel *t, int force_reply)
3203{ 3211{
3212 static struct CadetEncryptedMessageIdentifier zero;
3204 struct CadetConnection *c; 3213 struct CadetConnection *c;
3205 struct GNUNET_CADET_KX msg; 3214 struct GNUNET_CADET_TunnelKeyExchangeMessage msg;
3206 enum GNUNET_CADET_KX_Flags flags; 3215 enum GNUNET_CADET_KX_Flags flags;
3207 3216
3208 LOG (GNUNET_ERROR_TYPE_INFO, "==> { KX} on %s\n", GCT_2s (t)); 3217 LOG (GNUNET_ERROR_TYPE_INFO, "==> { KX} on %s\n", GCT_2s (t));
@@ -3225,7 +3234,7 @@ GCT_send_kx (struct CadetTunnel *t, int force_reply)
3225 } 3234 }
3226 3235
3227 msg.header.size = htons (sizeof (msg)); 3236 msg.header.size = htons (sizeof (msg));
3228 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_KX); 3237 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX);
3229 flags = GNUNET_CADET_KX_FLAG_NONE; 3238 flags = GNUNET_CADET_KX_FLAG_NONE;
3230 if (GNUNET_YES == force_reply) 3239 if (GNUNET_YES == force_reply)
3231 flags |= GNUNET_CADET_KX_FLAG_FORCE_REPLY; 3240 flags |= GNUNET_CADET_KX_FLAG_FORCE_REPLY;
@@ -3234,8 +3243,11 @@ GCT_send_kx (struct CadetTunnel *t, int force_reply)
3234 GNUNET_CRYPTO_ecdhe_key_get_public (t->ax->kx_0, &msg.ephemeral_key); 3243 GNUNET_CRYPTO_ecdhe_key_get_public (t->ax->kx_0, &msg.ephemeral_key);
3235 GNUNET_CRYPTO_ecdhe_key_get_public (t->ax->DHRs, &msg.ratchet_key); 3244 GNUNET_CRYPTO_ecdhe_key_get_public (t->ax->DHRs, &msg.ratchet_key);
3236 3245
3237 t->ephm_h = GCC_send_prebuilt_message (&msg.header, UINT16_MAX, 0, 3246 t->ephm_h = GCC_send_prebuilt_message (&msg.header,
3238 c, GCC_is_origin (c, GNUNET_YES), 3247 UINT16_MAX,
3248 zero,
3249 c,
3250 GCC_is_origin (c, GNUNET_YES),
3239 GNUNET_YES, &ephm_sent, t); 3251 GNUNET_YES, &ephm_sent, t);
3240 if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) 3252 if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate)
3241 GCT_change_estate (t, CADET_TUNNEL_KEY_SENT); 3253 GCT_change_estate (t, CADET_TUNNEL_KEY_SENT);
@@ -3486,4 +3498,3 @@ GCT_iterate_channels (struct CadetTunnel *t, GCT_chan_iter iter, void *cls)
3486 for (cht = t->channel_head; NULL != cht; cht = cht->next) 3498 for (cht = t->channel_head; NULL != cht; cht = cht->next)
3487 iter (cls, cht->ch); 3499 iter (cls, cht->ch);
3488} 3500}
3489