diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-15 21:49:06 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-15 21:49:06 +0100 |
commit | 71785fccb8584bd028ff48aa56f55e84324c569e (patch) | |
tree | df07376ac00f04484045be67f5743ff42449a2d2 /src/cadet/gnunet-service-cadet_tunnel.c | |
parent | 4270685ca41e6401f0836716a24e87dbab4d1145 (diff) | |
download | gnunet-71785fccb8584bd028ff48aa56f55e84324c569e.tar.gz gnunet-71785fccb8584bd028ff48aa56f55e84324c569e.zip |
cleaning up some CADET logic, improving types used
Diffstat (limited to 'src/cadet/gnunet-service-cadet_tunnel.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_tunnel.c | 96 |
1 files changed, 57 insertions, 39 deletions
diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c index 6ddcf6598..2e17774d4 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 | */ |
68 | struct CadetTConnection | 68 | struct 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_ChannelNumber next_chid; |
313 | 314 | ||
314 | /** | 315 | /** |
315 | * Destroy flag: if true, destroy on last message. | 316 | * Destroy flag: if true, destroy on last message. |
@@ -1401,7 +1402,11 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
1401 | GNUNET_break (0); | 1402 | GNUNET_break (0); |
1402 | LOG (GNUNET_ERROR_TYPE_ERROR, "type %s not valid\n", GC_m2s (type)); | 1403 | LOG (GNUNET_ERROR_TYPE_ERROR, "type %s not valid\n", GC_m2s (type)); |
1403 | } | 1404 | } |
1404 | LOG (GNUNET_ERROR_TYPE_DEBUG, "type %s\n", GC_m2s (type)); | 1405 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1406 | "Sending message of type %s with PID %u and CID %s\n", | ||
1407 | GC_m2s (type), | ||
1408 | htonl (ax_msg->pid), | ||
1409 | GC_h2s (&ax_msg->cid)); | ||
1405 | 1410 | ||
1406 | if (NULL == cont) | 1411 | if (NULL == cont) |
1407 | { | 1412 | { |
@@ -1562,17 +1567,19 @@ destroy_iterator (void *cls, | |||
1562 | * @param gid ID of the channel. | 1567 | * @param gid ID of the channel. |
1563 | */ | 1568 | */ |
1564 | static void | 1569 | static void |
1565 | send_channel_destroy (struct CadetTunnel *t, unsigned int gid) | 1570 | send_channel_destroy (struct CadetTunnel *t, |
1571 | struct GNUNET_CADET_ChannelNumber gid) | ||
1566 | { | 1572 | { |
1567 | struct GNUNET_CADET_ChannelManage msg; | 1573 | struct GNUNET_CADET_ChannelManage msg; |
1568 | 1574 | ||
1569 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); | 1575 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); |
1570 | msg.header.size = htons (sizeof (msg)); | 1576 | msg.header.size = htons (sizeof (msg)); |
1571 | msg.chid = htonl (gid); | 1577 | msg.chid = gid; |
1572 | 1578 | ||
1573 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1579 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1574 | "WARNING destroying unknown channel %u on tunnel %s\n", | 1580 | "WARNING destroying unknown channel %u on tunnel %s\n", |
1575 | gid, GCT_2s (t)); | 1581 | ntohl (gid.cn), |
1582 | GCT_2s (t)); | ||
1576 | send_prebuilt_message (&msg.header, t, NULL, GNUNET_YES, NULL, NULL, NULL); | 1583 | send_prebuilt_message (&msg.header, t, NULL, GNUNET_YES, NULL, NULL, NULL); |
1577 | } | 1584 | } |
1578 | 1585 | ||
@@ -1613,13 +1620,17 @@ handle_data (struct CadetTunnel *t, | |||
1613 | 1620 | ||
1614 | 1621 | ||
1615 | /* Check channel */ | 1622 | /* Check channel */ |
1616 | ch = GCT_get_channel (t, ntohl (msg->chid)); | 1623 | ch = GCT_get_channel (t, msg->chid); |
1617 | if (NULL == ch) | 1624 | if (NULL == ch) |
1618 | { | 1625 | { |
1619 | GNUNET_STATISTICS_update (stats, "# data on unknown channel", | 1626 | GNUNET_STATISTICS_update (stats, |
1620 | 1, GNUNET_NO); | 1627 | "# data on unknown channel", |
1621 | LOG (GNUNET_ERROR_TYPE_DEBUG, "channel 0x%X unknown\n", ntohl (msg->chid)); | 1628 | 1, |
1622 | send_channel_destroy (t, ntohl (msg->chid)); | 1629 | GNUNET_NO); |
1630 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1631 | "channel 0x%X unknown\n", | ||
1632 | ntohl (msg->chid.cn)); | ||
1633 | send_channel_destroy (t, msg->chid); | ||
1623 | return; | 1634 | return; |
1624 | } | 1635 | } |
1625 | 1636 | ||
@@ -1654,13 +1665,13 @@ handle_data_ack (struct CadetTunnel *t, | |||
1654 | } | 1665 | } |
1655 | 1666 | ||
1656 | /* Check channel */ | 1667 | /* Check channel */ |
1657 | ch = GCT_get_channel (t, ntohl (msg->chid)); | 1668 | ch = GCT_get_channel (t, msg->chid); |
1658 | if (NULL == ch) | 1669 | if (NULL == ch) |
1659 | { | 1670 | { |
1660 | GNUNET_STATISTICS_update (stats, "# data ack on unknown channel", | 1671 | GNUNET_STATISTICS_update (stats, "# data ack on unknown channel", |
1661 | 1, GNUNET_NO); | 1672 | 1, GNUNET_NO); |
1662 | LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", | 1673 | LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", |
1663 | ntohl (msg->chid)); | 1674 | ntohl (msg->chid.cn)); |
1664 | return; | 1675 | return; |
1665 | } | 1676 | } |
1666 | 1677 | ||
@@ -1690,7 +1701,7 @@ handle_ch_create (struct CadetTunnel *t, | |||
1690 | } | 1701 | } |
1691 | 1702 | ||
1692 | /* Check channel */ | 1703 | /* Check channel */ |
1693 | ch = GCT_get_channel (t, ntohl (msg->chid)); | 1704 | ch = GCT_get_channel (t, msg->chid); |
1694 | if (NULL != ch && ! GCT_is_loopback (t)) | 1705 | if (NULL != ch && ! GCT_is_loopback (t)) |
1695 | { | 1706 | { |
1696 | /* Probably a retransmission, safe to ignore */ | 1707 | /* Probably a retransmission, safe to ignore */ |
@@ -1725,13 +1736,14 @@ handle_ch_nack (struct CadetTunnel *t, | |||
1725 | } | 1736 | } |
1726 | 1737 | ||
1727 | /* Check channel */ | 1738 | /* Check channel */ |
1728 | ch = GCT_get_channel (t, ntohl (msg->chid)); | 1739 | ch = GCT_get_channel (t, msg->chid); |
1729 | if (NULL == ch) | 1740 | if (NULL == ch) |
1730 | { | 1741 | { |
1731 | GNUNET_STATISTICS_update (stats, "# channel NACK on unknown channel", | 1742 | GNUNET_STATISTICS_update (stats, "# channel NACK on unknown channel", |
1732 | 1, GNUNET_NO); | 1743 | 1, GNUNET_NO); |
1733 | LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", | 1744 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1734 | ntohl (msg->chid)); | 1745 | "WARNING channel %u unknown\n", |
1746 | ntohl (msg->chid.cn)); | ||
1735 | return; | 1747 | return; |
1736 | } | 1748 | } |
1737 | 1749 | ||
@@ -1766,13 +1778,16 @@ handle_ch_ack (struct CadetTunnel *t, | |||
1766 | } | 1778 | } |
1767 | 1779 | ||
1768 | /* Check channel */ | 1780 | /* Check channel */ |
1769 | ch = GCT_get_channel (t, ntohl (msg->chid)); | 1781 | ch = GCT_get_channel (t, msg->chid); |
1770 | if (NULL == ch) | 1782 | if (NULL == ch) |
1771 | { | 1783 | { |
1772 | GNUNET_STATISTICS_update (stats, "# channel ack on unknown channel", | 1784 | GNUNET_STATISTICS_update (stats, |
1773 | 1, GNUNET_NO); | 1785 | "# channel ack on unknown channel", |
1774 | LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", | 1786 | 1, |
1775 | ntohl (msg->chid)); | 1787 | GNUNET_NO); |
1788 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1789 | "WARNING channel %u unknown\n", | ||
1790 | ntohl (msg->chid.cn)); | ||
1776 | return; | 1791 | return; |
1777 | } | 1792 | } |
1778 | 1793 | ||
@@ -1807,7 +1822,7 @@ handle_ch_destroy (struct CadetTunnel *t, | |||
1807 | } | 1822 | } |
1808 | 1823 | ||
1809 | /* Check channel */ | 1824 | /* Check channel */ |
1810 | ch = GCT_get_channel (t, ntohl (msg->chid)); | 1825 | ch = GCT_get_channel (t, msg->chid); |
1811 | if (NULL == ch) | 1826 | if (NULL == ch) |
1812 | { | 1827 | { |
1813 | /* Probably a retransmission, safe to ignore */ | 1828 | /* Probably a retransmission, safe to ignore */ |
@@ -2200,7 +2215,7 @@ GCT_new (struct CadetPeer *destination) | |||
2200 | struct CadetTunnel *t; | 2215 | struct CadetTunnel *t; |
2201 | 2216 | ||
2202 | t = GNUNET_new (struct CadetTunnel); | 2217 | t = GNUNET_new (struct CadetTunnel); |
2203 | t->next_chid = 0; | 2218 | t->next_chid.cn = 0; |
2204 | t->peer = destination; | 2219 | t->peer = destination; |
2205 | 2220 | ||
2206 | if (GNUNET_OK != | 2221 | if (GNUNET_OK != |
@@ -2442,7 +2457,8 @@ GCT_remove_connection (struct CadetTunnel *t, | |||
2442 | * @param ch Channel. | 2457 | * @param ch Channel. |
2443 | */ | 2458 | */ |
2444 | void | 2459 | void |
2445 | GCT_add_channel (struct CadetTunnel *t, struct CadetChannel *ch) | 2460 | GCT_add_channel (struct CadetTunnel *t, |
2461 | struct CadetChannel *ch) | ||
2446 | { | 2462 | { |
2447 | struct CadetTChannel *aux; | 2463 | struct CadetTChannel *aux; |
2448 | 2464 | ||
@@ -2510,7 +2526,8 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch) | |||
2510 | * @return channel handler, NULL if doesn't exist | 2526 | * @return channel handler, NULL if doesn't exist |
2511 | */ | 2527 | */ |
2512 | struct CadetChannel * | 2528 | struct CadetChannel * |
2513 | GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid) | 2529 | GCT_get_channel (struct CadetTunnel *t, |
2530 | struct GNUNET_CADET_ChannelNumber chid) | ||
2514 | { | 2531 | { |
2515 | struct CadetTChannel *iter; | 2532 | struct CadetTChannel *iter; |
2516 | 2533 | ||
@@ -2519,7 +2536,7 @@ GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid) | |||
2519 | 2536 | ||
2520 | for (iter = t->channel_head; NULL != iter; iter = iter->next) | 2537 | for (iter = t->channel_head; NULL != iter; iter = iter->next) |
2521 | { | 2538 | { |
2522 | if (GCCH_get_id (iter->ch) == chid) | 2539 | if (GCCH_get_id (iter->ch).cn == chid.cn) |
2523 | break; | 2540 | break; |
2524 | } | 2541 | } |
2525 | 2542 | ||
@@ -2966,11 +2983,11 @@ GCT_get_destination (struct CadetTunnel *t) | |||
2966 | * | 2983 | * |
2967 | * @return GID of a channel free to use. | 2984 | * @return GID of a channel free to use. |
2968 | */ | 2985 | */ |
2969 | CADET_ChannelNumber | 2986 | struct GNUNET_CADET_ChannelNumber |
2970 | GCT_get_next_chid (struct CadetTunnel *t) | 2987 | GCT_get_next_chid (struct CadetTunnel *t) |
2971 | { | 2988 | { |
2972 | CADET_ChannelNumber chid; | 2989 | struct GNUNET_CADET_ChannelNumber chid; |
2973 | CADET_ChannelNumber mask; | 2990 | struct GNUNET_CADET_ChannelNumber mask; |
2974 | int result; | 2991 | int result; |
2975 | 2992 | ||
2976 | /* Set bit 30 depending on the ID relationship. Bit 31 is always 0 for GID. | 2993 | /* Set bit 30 depending on the ID relationship. Bit 31 is always 0 for GID. |
@@ -2979,20 +2996,22 @@ GCT_get_next_chid (struct CadetTunnel *t) | |||
2979 | */ | 2996 | */ |
2980 | result = GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, GCP_get_id (t->peer)); | 2997 | result = GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, GCP_get_id (t->peer)); |
2981 | if (0 > result) | 2998 | if (0 > result) |
2982 | mask = 0x40000000; | 2999 | mask.cn = htonl (0x40000000); |
2983 | else | 3000 | else |
2984 | mask = 0x0; | 3001 | mask.cn = 0x0; |
2985 | t->next_chid |= mask; | 3002 | t->next_chid.cn |= mask.cn; |
2986 | 3003 | ||
2987 | while (NULL != GCT_get_channel (t, t->next_chid)) | 3004 | while (NULL != GCT_get_channel (t, t->next_chid)) |
2988 | { | 3005 | { |
2989 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %u exists...\n", t->next_chid); | 3006 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2990 | t->next_chid = (t->next_chid + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; | 3007 | "Channel %u exists...\n", |
2991 | t->next_chid |= mask; | 3008 | t->next_chid.cn); |
3009 | t->next_chid.cn = htonl ((ntohl (t->next_chid.cn) + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); | ||
3010 | t->next_chid.cn |= mask.cn; | ||
2992 | } | 3011 | } |
2993 | chid = t->next_chid; | 3012 | chid = t->next_chid; |
2994 | t->next_chid = (t->next_chid + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; | 3013 | t->next_chid.cn = (t->next_chid.cn + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; |
2995 | t->next_chid |= mask; | 3014 | t->next_chid.cn |= mask.cn; |
2996 | 3015 | ||
2997 | return chid; | 3016 | return chid; |
2998 | } | 3017 | } |
@@ -3486,4 +3505,3 @@ GCT_iterate_channels (struct CadetTunnel *t, GCT_chan_iter iter, void *cls) | |||
3486 | for (cht = t->channel_head; NULL != cht; cht = cht->next) | 3505 | for (cht = t->channel_head; NULL != cht; cht = cht->next) |
3487 | iter (cls, cht->ch); | 3506 | iter (cls, cht->ch); |
3488 | } | 3507 | } |
3489 | |||