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_channel.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_channel.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_channel.c | 81 |
1 files changed, 46 insertions, 35 deletions
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index d2d176e83..6bc3dc590 100644 --- a/src/cadet/gnunet-service-cadet_channel.c +++ b/src/cadet/gnunet-service-cadet_channel.c | |||
@@ -58,7 +58,7 @@ enum CadetChannelState | |||
58 | /** | 58 | /** |
59 | * Connection confirmed, ready to carry traffic. | 59 | * Connection confirmed, ready to carry traffic. |
60 | */ | 60 | */ |
61 | CADET_CHANNEL_READY, | 61 | CADET_CHANNEL_READY |
62 | }; | 62 | }; |
63 | 63 | ||
64 | 64 | ||
@@ -216,19 +216,19 @@ struct CadetChannel | |||
216 | /** | 216 | /** |
217 | * Global channel number ( < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) | 217 | * Global channel number ( < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) |
218 | */ | 218 | */ |
219 | CADET_ChannelNumber gid; | 219 | struct GNUNET_CADET_ChannelNumber gid; |
220 | 220 | ||
221 | /** | 221 | /** |
222 | * Local tunnel number for root (owner) client. | 222 | * Local tunnel number for root (owner) client. |
223 | * ( >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI or 0 ) | 223 | * ( >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI or 0 ) |
224 | */ | 224 | */ |
225 | CADET_ChannelNumber lid_root; | 225 | struct GNUNET_CADET_ClientChannelNumber lid_root; |
226 | 226 | ||
227 | /** | 227 | /** |
228 | * Local tunnel number for local destination clients (incoming number) | 228 | * Local tunnel number for local destination clients (incoming number) |
229 | * ( >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV or 0). | 229 | * ( >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV or 0). |
230 | */ | 230 | */ |
231 | CADET_ChannelNumber lid_dest; | 231 | struct GNUNET_CADET_ClientChannelNumber lid_dest; |
232 | 232 | ||
233 | /** | 233 | /** |
234 | * Channel state. | 234 | * Channel state. |
@@ -517,7 +517,7 @@ send_destroy (struct CadetChannel *ch, int local_only) | |||
517 | 517 | ||
518 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); | 518 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); |
519 | msg.header.size = htons (sizeof (msg)); | 519 | msg.header.size = htons (sizeof (msg)); |
520 | msg.chid = htonl (ch->gid); | 520 | msg.chid = ch->gid; |
521 | 521 | ||
522 | /* If root is not NULL, notify. | 522 | /* If root is not NULL, notify. |
523 | * If it's NULL, check lid_root. When a local destroy comes in, root | 523 | * If it's NULL, check lid_root. When a local destroy comes in, root |
@@ -526,12 +526,12 @@ send_destroy (struct CadetChannel *ch, int local_only) | |||
526 | */ | 526 | */ |
527 | if (NULL != ch->root) | 527 | if (NULL != ch->root) |
528 | GML_send_channel_destroy (ch->root, ch->lid_root); | 528 | GML_send_channel_destroy (ch->root, ch->lid_root); |
529 | else if (0 == ch->lid_root && GNUNET_NO == local_only) | 529 | else if (0 == ch->lid_root.channel_of_client && GNUNET_NO == local_only) |
530 | GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO, NULL); | 530 | GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO, NULL); |
531 | 531 | ||
532 | if (NULL != ch->dest) | 532 | if (NULL != ch->dest) |
533 | GML_send_channel_destroy (ch->dest, ch->lid_dest); | 533 | GML_send_channel_destroy (ch->dest, ch->lid_dest); |
534 | else if (0 == ch->lid_dest && GNUNET_NO == local_only) | 534 | else if (0 == ch->lid_dest.channel_of_client && GNUNET_NO == local_only) |
535 | GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_YES, NULL); | 535 | GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_YES, NULL); |
536 | } | 536 | } |
537 | 537 | ||
@@ -552,7 +552,10 @@ send_client_create (struct CadetChannel *ch) | |||
552 | opt = 0; | 552 | opt = 0; |
553 | opt |= GNUNET_YES == ch->reliable ? GNUNET_CADET_OPTION_RELIABLE : 0; | 553 | opt |= GNUNET_YES == ch->reliable ? GNUNET_CADET_OPTION_RELIABLE : 0; |
554 | opt |= GNUNET_YES == ch->nobuffer ? GNUNET_CADET_OPTION_NOBUFFER : 0; | 554 | opt |= GNUNET_YES == ch->nobuffer ? GNUNET_CADET_OPTION_NOBUFFER : 0; |
555 | GML_send_channel_create (ch->dest, ch->lid_dest, &ch->port, opt, | 555 | GML_send_channel_create (ch->dest, |
556 | ch->lid_dest, | ||
557 | &ch->port, | ||
558 | opt, | ||
556 | GCT_get_destination (ch->t)); | 559 | GCT_get_destination (ch->t)); |
557 | 560 | ||
558 | } | 561 | } |
@@ -883,7 +886,7 @@ send_create (struct CadetChannel *ch) | |||
883 | 886 | ||
884 | msgcc.header.size = htons (sizeof (msgcc)); | 887 | msgcc.header.size = htons (sizeof (msgcc)); |
885 | msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE); | 888 | msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE); |
886 | msgcc.chid = htonl (ch->gid); | 889 | msgcc.chid = ch->gid; |
887 | msgcc.port = ch->port; | 890 | msgcc.port = ch->port; |
888 | msgcc.opt = htonl (channel_get_options (ch)); | 891 | msgcc.opt = htonl (channel_get_options (ch)); |
889 | 892 | ||
@@ -904,10 +907,11 @@ send_ack (struct CadetChannel *ch, int fwd) | |||
904 | 907 | ||
905 | msg.header.size = htons (sizeof (msg)); | 908 | msg.header.size = htons (sizeof (msg)); |
906 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK); | 909 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK); |
907 | LOG (GNUNET_ERROR_TYPE_DEBUG, " sending channel %s ack for channel %s\n", | 910 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
911 | " sending channel %s ack for channel %s\n", | ||
908 | GC_f2s (fwd), GCCH_2s (ch)); | 912 | GC_f2s (fwd), GCCH_2s (ch)); |
909 | 913 | ||
910 | msg.chid = htonl (ch->gid); | 914 | msg.chid =ch->gid; |
911 | GCCH_send_prebuilt_message (&msg.header, ch, !fwd, NULL); | 915 | GCCH_send_prebuilt_message (&msg.header, ch, !fwd, NULL); |
912 | } | 916 | } |
913 | 917 | ||
@@ -925,8 +929,9 @@ fire_and_forget (const struct GNUNET_MessageHeader *msg, | |||
925 | struct CadetChannel *ch, | 929 | struct CadetChannel *ch, |
926 | int force) | 930 | int force) |
927 | { | 931 | { |
928 | GNUNET_break (NULL == GCT_send_prebuilt_message (msg, ch->t, NULL, | 932 | GNUNET_break (NULL == |
929 | force, NULL, NULL)); | 933 | GCT_send_prebuilt_message (msg, ch->t, NULL, |
934 | force, NULL, NULL)); | ||
930 | } | 935 | } |
931 | 936 | ||
932 | 937 | ||
@@ -946,7 +951,7 @@ send_nack (struct CadetChannel *ch) | |||
946 | " sending channel NACK for channel %s\n", | 951 | " sending channel NACK for channel %s\n", |
947 | GCCH_2s (ch)); | 952 | GCCH_2s (ch)); |
948 | 953 | ||
949 | msg.chid = htonl (ch->gid); | 954 | msg.chid = ch->gid; |
950 | GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO, NULL); | 955 | GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO, NULL); |
951 | } | 956 | } |
952 | 957 | ||
@@ -1252,7 +1257,7 @@ channel_save_copy (struct CadetChannel *ch, | |||
1252 | static struct CadetChannel * | 1257 | static struct CadetChannel * |
1253 | channel_new (struct CadetTunnel *t, | 1258 | channel_new (struct CadetTunnel *t, |
1254 | struct CadetClient *owner, | 1259 | struct CadetClient *owner, |
1255 | CADET_ChannelNumber lid_root) | 1260 | struct GNUNET_CADET_ClientChannelNumber lid_root) |
1256 | { | 1261 | { |
1257 | struct CadetChannel *ch; | 1262 | struct CadetChannel *ch; |
1258 | 1263 | ||
@@ -1393,7 +1398,7 @@ GCCH_destroy (struct CadetChannel *ch) | |||
1393 | * | 1398 | * |
1394 | * @return ID used to identify the channel with the remote peer. | 1399 | * @return ID used to identify the channel with the remote peer. |
1395 | */ | 1400 | */ |
1396 | CADET_ChannelNumber | 1401 | struct GNUNET_CADET_ChannelNumber |
1397 | GCCH_get_id (const struct CadetChannel *ch) | 1402 | GCCH_get_id (const struct CadetChannel *ch) |
1398 | { | 1403 | { |
1399 | return ch->gid; | 1404 | return ch->gid; |
@@ -1533,7 +1538,7 @@ GCCH_send_data_ack (struct CadetChannel *ch, int fwd) | |||
1533 | 1538 | ||
1534 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_DATA_ACK); | 1539 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_DATA_ACK); |
1535 | msg.header.size = htons (sizeof (msg)); | 1540 | msg.header.size = htons (sizeof (msg)); |
1536 | msg.chid = htonl (ch->gid); | 1541 | msg.chid = ch->gid; |
1537 | msg.mid = htonl (ack); | 1542 | msg.mid = htonl (ack); |
1538 | 1543 | ||
1539 | msg.futures = 0LL; | 1544 | msg.futures = 0LL; |
@@ -1657,7 +1662,7 @@ GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level) | |||
1657 | { | 1662 | { |
1658 | LOG2 (level, "CHN cli %s\n", GML_2s (ch->root)); | 1663 | LOG2 (level, "CHN cli %s\n", GML_2s (ch->root)); |
1659 | LOG2 (level, "CHN ready %s\n", ch->root_rel->client_ready ? "YES" : "NO"); | 1664 | LOG2 (level, "CHN ready %s\n", ch->root_rel->client_ready ? "YES" : "NO"); |
1660 | LOG2 (level, "CHN id %X\n", ch->lid_root); | 1665 | LOG2 (level, "CHN id %X\n", ch->lid_root.channel_of_client); |
1661 | LOG2 (level, "CHN recv %d\n", ch->root_rel->n_recv); | 1666 | LOG2 (level, "CHN recv %d\n", ch->root_rel->n_recv); |
1662 | LOG2 (level, "CHN MID r: %d, s: %d\n", | 1667 | LOG2 (level, "CHN MID r: %d, s: %d\n", |
1663 | ch->root_rel->mid_recv, ch->root_rel->mid_send); | 1668 | ch->root_rel->mid_recv, ch->root_rel->mid_send); |
@@ -1733,11 +1738,12 @@ GCCH_handle_local_ack (struct CadetChannel *ch, int fwd) | |||
1733 | * @param message Data message. | 1738 | * @param message Data message. |
1734 | * @param size Size of data. | 1739 | * @param size Size of data. |
1735 | * | 1740 | * |
1736 | * @return GNUNET_OK if everything goes well, GNUNET_SYSERR in case of en error. | 1741 | * @return #GNUNET_OK if everything goes well, #GNUNET_SYSERR in case of en error. |
1737 | */ | 1742 | */ |
1738 | int | 1743 | int |
1739 | GCCH_handle_local_data (struct CadetChannel *ch, | 1744 | GCCH_handle_local_data (struct CadetChannel *ch, |
1740 | struct CadetClient *c, int fwd, | 1745 | struct CadetClient *c, |
1746 | int fwd, | ||
1741 | const struct GNUNET_MessageHeader *message, | 1747 | const struct GNUNET_MessageHeader *message, |
1742 | size_t size) | 1748 | size_t size) |
1743 | { | 1749 | { |
@@ -1775,7 +1781,7 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1775 | GNUNET_memcpy (&payload[1], message, size); | 1781 | GNUNET_memcpy (&payload[1], message, size); |
1776 | payload->header.size = htons (p2p_size); | 1782 | payload->header.size = htons (p2p_size); |
1777 | payload->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_DATA); | 1783 | payload->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_DATA); |
1778 | payload->chid = htonl (ch->gid); | 1784 | payload->chid = ch->gid; |
1779 | LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n"); | 1785 | LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n"); |
1780 | GCCH_send_prebuilt_message (&payload->header, ch, fwd, NULL); | 1786 | GCCH_send_prebuilt_message (&payload->header, ch, fwd, NULL); |
1781 | 1787 | ||
@@ -1845,11 +1851,11 @@ GCCH_handle_local_create (struct CadetClient *c, | |||
1845 | struct CadetChannel *ch; | 1851 | struct CadetChannel *ch; |
1846 | struct CadetTunnel *t; | 1852 | struct CadetTunnel *t; |
1847 | struct CadetPeer *peer; | 1853 | struct CadetPeer *peer; |
1848 | CADET_ChannelNumber chid; | 1854 | struct GNUNET_CADET_ClientChannelNumber chid; |
1849 | 1855 | ||
1850 | LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n", | 1856 | LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n", |
1851 | GNUNET_i2s (&msg->peer), GNUNET_h2s (&msg->port)); | 1857 | GNUNET_i2s (&msg->peer), GNUNET_h2s (&msg->port)); |
1852 | chid = ntohl (msg->channel_id); | 1858 | chid = msg->channel_id; |
1853 | 1859 | ||
1854 | /* Sanity check for duplicate channel IDs */ | 1860 | /* Sanity check for duplicate channel IDs */ |
1855 | if (NULL != GML_channel_get (c, chid)) | 1861 | if (NULL != GML_channel_get (c, chid)) |
@@ -2147,20 +2153,21 @@ struct CadetChannel * | |||
2147 | GCCH_handle_create (struct CadetTunnel *t, | 2153 | GCCH_handle_create (struct CadetTunnel *t, |
2148 | const struct GNUNET_CADET_ChannelCreate *msg) | 2154 | const struct GNUNET_CADET_ChannelCreate *msg) |
2149 | { | 2155 | { |
2150 | CADET_ChannelNumber chid; | 2156 | struct GNUNET_CADET_ClientChannelNumber chid; |
2157 | struct GNUNET_CADET_ChannelNumber gid; | ||
2151 | struct CadetChannel *ch; | 2158 | struct CadetChannel *ch; |
2152 | struct CadetClient *c; | 2159 | struct CadetClient *c; |
2153 | int new_channel; | 2160 | int new_channel; |
2154 | const struct GNUNET_HashCode *port; | 2161 | const struct GNUNET_HashCode *port; |
2155 | 2162 | ||
2156 | chid = ntohl (msg->chid); | 2163 | gid = msg->chid; |
2157 | 2164 | ch = GCT_get_channel (t, gid); | |
2158 | ch = GCT_get_channel (t, chid); | ||
2159 | if (NULL == ch) | 2165 | if (NULL == ch) |
2160 | { | 2166 | { |
2161 | /* Create channel */ | 2167 | /* Create channel */ |
2162 | ch = channel_new (t, NULL, 0); | 2168 | chid.channel_of_client = htonl (0); |
2163 | ch->gid = chid; | 2169 | ch = channel_new (t, NULL, chid); |
2170 | ch->gid = gid; | ||
2164 | channel_set_options (ch, ntohl (msg->opt)); | 2171 | channel_set_options (ch, ntohl (msg->opt)); |
2165 | new_channel = GNUNET_YES; | 2172 | new_channel = GNUNET_YES; |
2166 | } | 2173 | } |
@@ -2403,7 +2410,7 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
2403 | { | 2410 | { |
2404 | struct GNUNET_CADET_ChannelCreate *cc_msg; | 2411 | struct GNUNET_CADET_ChannelCreate *cc_msg; |
2405 | cc_msg = (struct GNUNET_CADET_ChannelCreate *) message; | 2412 | cc_msg = (struct GNUNET_CADET_ChannelCreate *) message; |
2406 | SPRINTF (info, " 0x%08X", ntohl (cc_msg->chid)); | 2413 | SPRINTF (info, " 0x%08X", ntohl (cc_msg->chid.cn)); |
2407 | break; | 2414 | break; |
2408 | } | 2415 | } |
2409 | case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK: | 2416 | case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK: |
@@ -2412,7 +2419,7 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
2412 | { | 2419 | { |
2413 | struct GNUNET_CADET_ChannelManage *m_msg; | 2420 | struct GNUNET_CADET_ChannelManage *m_msg; |
2414 | m_msg = (struct GNUNET_CADET_ChannelManage *) message; | 2421 | m_msg = (struct GNUNET_CADET_ChannelManage *) message; |
2415 | SPRINTF (info, " 0x%08X", ntohl (m_msg->chid)); | 2422 | SPRINTF (info, " 0x%08X", ntohl (m_msg->chid.cn)); |
2416 | break; | 2423 | break; |
2417 | } | 2424 | } |
2418 | default: | 2425 | default: |
@@ -2542,9 +2549,13 @@ GCCH_2s (const struct CadetChannel *ch) | |||
2542 | if (NULL == ch) | 2549 | if (NULL == ch) |
2543 | return "(NULL Channel)"; | 2550 | return "(NULL Channel)"; |
2544 | 2551 | ||
2545 | SPRINTF (buf, "%s:%s gid:%X (%X / %X)", | 2552 | SPRINTF (buf, |
2546 | GCT_2s (ch->t), GNUNET_h2s (&ch->port), | 2553 | "%s:%s gid:%X (%X / %X)", |
2547 | ch->gid, ch->lid_root, ch->lid_dest); | 2554 | GCT_2s (ch->t), |
2555 | GNUNET_h2s (&ch->port), | ||
2556 | ntohl (ch->gid.cn), | ||
2557 | ntohl (ch->lid_root.channel_of_client), | ||
2558 | ntohl (ch->lid_dest.channel_of_client)); | ||
2548 | 2559 | ||
2549 | return buf; | 2560 | return buf; |
2550 | } | 2561 | } |