diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_local.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_local.c | 207 |
1 files changed, 110 insertions, 97 deletions
diff --git a/src/cadet/gnunet-service-cadet_local.c b/src/cadet/gnunet-service-cadet_local.c index 9be1224c1..e1f6ac4c3 100644 --- a/src/cadet/gnunet-service-cadet_local.c +++ b/src/cadet/gnunet-service-cadet_local.c | |||
@@ -61,7 +61,7 @@ struct CadetClient | |||
61 | * Tunnels that belong to this client, indexed by local id | 61 | * Tunnels that belong to this client, indexed by local id |
62 | */ | 62 | */ |
63 | struct GNUNET_CONTAINER_MultiHashMap32 *own_channels; | 63 | struct GNUNET_CONTAINER_MultiHashMap32 *own_channels; |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Tunnels this client has accepted, indexed by incoming local id | 66 | * Tunnels this client has accepted, indexed by incoming local id |
67 | */ | 67 | */ |
@@ -70,7 +70,7 @@ struct CadetClient | |||
70 | /** | 70 | /** |
71 | * Channel ID for the next incoming channel. | 71 | * Channel ID for the next incoming channel. |
72 | */ | 72 | */ |
73 | CADET_ChannelNumber next_chid; | 73 | struct GNUNET_CADET_ClientChannelNumber next_chid; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Handle to communicate with the client | 76 | * Handle to communicate with the client |
@@ -188,7 +188,9 @@ channel_destroy_iterator (void *cls, | |||
188 | " Channel %s destroy, due to client %s shutdown.\n", | 188 | " Channel %s destroy, due to client %s shutdown.\n", |
189 | GCCH_2s (ch), GML_2s (c)); | 189 | GCCH_2s (ch), GML_2s (c)); |
190 | 190 | ||
191 | GCCH_handle_local_destroy (ch, c, key < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV); | 191 | GCCH_handle_local_destroy (ch, |
192 | c, | ||
193 | key < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); | ||
192 | return GNUNET_OK; | 194 | return GNUNET_OK; |
193 | } | 195 | } |
194 | 196 | ||
@@ -247,7 +249,6 @@ client_new (struct GNUNET_SERVER_Client *client) | |||
247 | c = GNUNET_new (struct CadetClient); | 249 | c = GNUNET_new (struct CadetClient); |
248 | c->handle = client; | 250 | c->handle = client; |
249 | c->id = next_client_id++; /* overflow not important: just for debug */ | 251 | c->id = next_client_id++; /* overflow not important: just for debug */ |
250 | c->next_chid = GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; | ||
251 | 252 | ||
252 | c->own_channels = GNUNET_CONTAINER_multihashmap32_create (32); | 253 | c->own_channels = GNUNET_CONTAINER_multihashmap32_create (32); |
253 | c->incoming_channels = GNUNET_CONTAINER_multihashmap32_create (32); | 254 | c->incoming_channels = GNUNET_CONTAINER_multihashmap32_create (32); |
@@ -439,7 +440,7 @@ handle_channel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
439 | LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); | 440 | LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); |
440 | 441 | ||
441 | /* Message size sanity check */ | 442 | /* Message size sanity check */ |
442 | if (sizeof (struct GNUNET_CADET_ChannelCreateMessage) | 443 | if (sizeof (struct GNUNET_CADET_ChannelOpenMessageMessage) |
443 | != ntohs (message->size)) | 444 | != ntohs (message->size)) |
444 | { | 445 | { |
445 | GNUNET_break (0); | 446 | GNUNET_break (0); |
@@ -449,7 +450,7 @@ handle_channel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
449 | 450 | ||
450 | if (GNUNET_OK != | 451 | if (GNUNET_OK != |
451 | GCCH_handle_local_create (c, | 452 | GCCH_handle_local_create (c, |
452 | (struct GNUNET_CADET_ChannelCreateMessage *) | 453 | (struct GNUNET_CADET_ChannelOpenMessageMessage *) |
453 | message)) | 454 | message)) |
454 | { | 455 | { |
455 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 456 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
@@ -474,7 +475,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client, | |||
474 | struct GNUNET_CADET_ChannelDestroyMessage *msg; | 475 | struct GNUNET_CADET_ChannelDestroyMessage *msg; |
475 | struct CadetClient *c; | 476 | struct CadetClient *c; |
476 | struct CadetChannel *ch; | 477 | struct CadetChannel *ch; |
477 | CADET_ChannelNumber chid; | 478 | struct GNUNET_CADET_ClientChannelNumber chid; |
478 | 479 | ||
479 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a DESTROY CHANNEL from client!\n"); | 480 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a DESTROY CHANNEL from client!\n"); |
480 | 481 | ||
@@ -499,7 +500,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client, | |||
499 | msg = (struct GNUNET_CADET_ChannelDestroyMessage *) message; | 500 | msg = (struct GNUNET_CADET_ChannelDestroyMessage *) message; |
500 | 501 | ||
501 | /* Retrieve tunnel */ | 502 | /* Retrieve tunnel */ |
502 | chid = ntohl (msg->channel_id); | 503 | chid = msg->channel_id; |
503 | ch = GML_channel_get (c, chid); | 504 | ch = GML_channel_get (c, chid); |
504 | 505 | ||
505 | LOG (GNUNET_ERROR_TYPE_INFO, "Client %u is destroying channel %X\n", | 506 | LOG (GNUNET_ERROR_TYPE_INFO, "Client %u is destroying channel %X\n", |
@@ -515,7 +516,9 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client, | |||
515 | return; | 516 | return; |
516 | } | 517 | } |
517 | 518 | ||
518 | GCCH_handle_local_destroy (ch, c, chid < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV); | 519 | GCCH_handle_local_destroy (ch, |
520 | c, | ||
521 | ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); | ||
519 | 522 | ||
520 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 523 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
521 | return; | 524 | return; |
@@ -537,7 +540,7 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
537 | struct GNUNET_CADET_LocalData *msg; | 540 | struct GNUNET_CADET_LocalData *msg; |
538 | struct CadetClient *c; | 541 | struct CadetClient *c; |
539 | struct CadetChannel *ch; | 542 | struct CadetChannel *ch; |
540 | CADET_ChannelNumber chid; | 543 | struct GNUNET_CADET_ClientChannelNumber chid; |
541 | size_t message_size; | 544 | size_t message_size; |
542 | size_t payload_size; | 545 | size_t payload_size; |
543 | size_t payload_claimed_size; | 546 | size_t payload_claimed_size; |
@@ -583,12 +586,12 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
583 | return; | 586 | return; |
584 | } | 587 | } |
585 | 588 | ||
586 | chid = ntohl (msg->id); | 589 | chid = msg->id; |
587 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %u bytes (%u payload) by client %u\n", | 590 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %u bytes (%u payload) by client %u\n", |
588 | payload_size, payload_claimed_size, c->id); | 591 | payload_size, payload_claimed_size, c->id); |
589 | 592 | ||
590 | /* Channel exists? */ | 593 | /* Channel exists? */ |
591 | fwd = chid < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; | 594 | fwd = ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; |
592 | ch = GML_channel_get (c, chid); | 595 | ch = GML_channel_get (c, chid); |
593 | if (NULL == ch) | 596 | if (NULL == ch) |
594 | { | 597 | { |
@@ -626,7 +629,7 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client, | |||
626 | struct GNUNET_CADET_LocalAck *msg; | 629 | struct GNUNET_CADET_LocalAck *msg; |
627 | struct CadetChannel *ch; | 630 | struct CadetChannel *ch; |
628 | struct CadetClient *c; | 631 | struct CadetClient *c; |
629 | CADET_ChannelNumber chid; | 632 | struct GNUNET_CADET_ClientChannelNumber chid; |
630 | int fwd; | 633 | int fwd; |
631 | 634 | ||
632 | LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); | 635 | LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); |
@@ -644,13 +647,16 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client, | |||
644 | msg = (struct GNUNET_CADET_LocalAck *) message; | 647 | msg = (struct GNUNET_CADET_LocalAck *) message; |
645 | 648 | ||
646 | /* Channel exists? */ | 649 | /* Channel exists? */ |
647 | chid = ntohl (msg->channel_id); | 650 | chid = msg->channel_id; |
648 | LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", chid); | 651 | LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", |
652 | ntohl (chid.channel_of_client)); | ||
649 | ch = GML_channel_get (c, chid); | 653 | ch = GML_channel_get (c, chid); |
650 | LOG (GNUNET_ERROR_TYPE_DEBUG, " -- ch %p\n", ch); | 654 | LOG (GNUNET_ERROR_TYPE_DEBUG, " -- ch %p\n", ch); |
651 | if (NULL == ch) | 655 | if (NULL == ch) |
652 | { | 656 | { |
653 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %X unknown.\n", chid); | 657 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
658 | "Channel %X unknown.\n", | ||
659 | ntohl (chid.channel_of_client)); | ||
654 | LOG (GNUNET_ERROR_TYPE_DEBUG, " for client %u.\n", c->id); | 660 | LOG (GNUNET_ERROR_TYPE_DEBUG, " for client %u.\n", c->id); |
655 | GNUNET_STATISTICS_update (stats, | 661 | GNUNET_STATISTICS_update (stats, |
656 | "# client ack messages on unknown channel", | 662 | "# client ack messages on unknown channel", |
@@ -661,12 +667,10 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client, | |||
661 | 667 | ||
662 | /* If client is root, the ACK is going FWD, therefore this is "BCK ACK". */ | 668 | /* If client is root, the ACK is going FWD, therefore this is "BCK ACK". */ |
663 | /* If client is dest, the ACK is going BCK, therefore this is "FWD ACK" */ | 669 | /* If client is dest, the ACK is going BCK, therefore this is "FWD ACK" */ |
664 | fwd = chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; | 670 | fwd = ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; |
665 | 671 | ||
666 | GCCH_handle_local_ack (ch, fwd); | 672 | GCCH_handle_local_ack (ch, fwd); |
667 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 673 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
668 | |||
669 | return; | ||
670 | } | 674 | } |
671 | 675 | ||
672 | 676 | ||
@@ -961,8 +965,9 @@ static void | |||
961 | iter_connection (void *cls, struct CadetConnection *c) | 965 | iter_connection (void *cls, struct CadetConnection *c) |
962 | { | 966 | { |
963 | struct GNUNET_CADET_LocalInfoTunnel *msg = cls; | 967 | struct GNUNET_CADET_LocalInfoTunnel *msg = cls; |
964 | struct GNUNET_CADET_Hash *h = (struct GNUNET_CADET_Hash *) &msg[1]; | 968 | struct GNUNET_CADET_ConnectionTunnelIdentifier *h; |
965 | 969 | ||
970 | h = (struct GNUNET_CADET_ConnectionTunnelIdentifier *) &msg[1]; | ||
966 | h[msg->connections] = *(GCC_get_id (c)); | 971 | h[msg->connections] = *(GCC_get_id (c)); |
967 | msg->connections++; | 972 | msg->connections++; |
968 | } | 973 | } |
@@ -971,10 +976,10 @@ static void | |||
971 | iter_channel (void *cls, struct CadetChannel *ch) | 976 | iter_channel (void *cls, struct CadetChannel *ch) |
972 | { | 977 | { |
973 | struct GNUNET_CADET_LocalInfoTunnel *msg = cls; | 978 | struct GNUNET_CADET_LocalInfoTunnel *msg = cls; |
974 | struct GNUNET_CADET_Hash *h = (struct GNUNET_CADET_Hash *) &msg[1]; | 979 | struct GNUNET_CADET_ConnectionTunnelIdentifier *h = (struct GNUNET_CADET_ConnectionTunnelIdentifier *) &msg[1]; |
975 | CADET_ChannelNumber *chn = (CADET_ChannelNumber *) &h[msg->connections]; | 980 | struct GNUNET_CADET_ChannelTunnelNumber *chn = (struct GNUNET_CADET_ChannelTunnelNumber *) &h[msg->connections]; |
976 | 981 | ||
977 | chn[msg->channels] = htonl (GCCH_get_id (ch)); | 982 | chn[msg->channels] = GCCH_get_id (ch); |
978 | msg->channels++; | 983 | msg->channels++; |
979 | } | 984 | } |
980 | 985 | ||
@@ -1039,8 +1044,8 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client, | |||
1039 | c_n = GCT_count_any_connections (t); | 1044 | c_n = GCT_count_any_connections (t); |
1040 | 1045 | ||
1041 | size = sizeof (struct GNUNET_CADET_LocalInfoTunnel); | 1046 | size = sizeof (struct GNUNET_CADET_LocalInfoTunnel); |
1042 | size += c_n * sizeof (struct GNUNET_CADET_Hash); | 1047 | size += c_n * sizeof (struct GNUNET_CADET_ConnectionTunnelIdentifier); |
1043 | size += ch_n * sizeof (CADET_ChannelNumber); | 1048 | size += ch_n * sizeof (struct GNUNET_CADET_ChannelTunnelNumber); |
1044 | 1049 | ||
1045 | resp = GNUNET_malloc (size); | 1050 | resp = GNUNET_malloc (size); |
1046 | resp->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL); | 1051 | resp->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL); |
@@ -1123,8 +1128,8 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = { | |||
1123 | sizeof (struct GNUNET_CADET_PortMessage)}, | 1128 | sizeof (struct GNUNET_CADET_PortMessage)}, |
1124 | {&handle_port_close, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE, | 1129 | {&handle_port_close, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE, |
1125 | sizeof (struct GNUNET_CADET_PortMessage)}, | 1130 | sizeof (struct GNUNET_CADET_PortMessage)}, |
1126 | {&handle_channel_create, NULL, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE, | 1131 | {&handle_channel_create, NULL, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN, |
1127 | sizeof (struct GNUNET_CADET_ChannelCreateMessage)}, | 1132 | sizeof (struct GNUNET_CADET_ChannelOpenMessageMessage)}, |
1128 | {&handle_channel_destroy, NULL, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY, | 1133 | {&handle_channel_destroy, NULL, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY, |
1129 | sizeof (struct GNUNET_CADET_ChannelDestroyMessage)}, | 1134 | sizeof (struct GNUNET_CADET_ChannelDestroyMessage)}, |
1130 | {&handle_data, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, 0}, | 1135 | {&handle_data, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, 0}, |
@@ -1214,26 +1219,16 @@ GML_shutdown (void) | |||
1214 | * @return non-NULL if channel exists in the clients lists | 1219 | * @return non-NULL if channel exists in the clients lists |
1215 | */ | 1220 | */ |
1216 | struct CadetChannel * | 1221 | struct CadetChannel * |
1217 | GML_channel_get (struct CadetClient *c, CADET_ChannelNumber chid) | 1222 | GML_channel_get (struct CadetClient *c, |
1223 | struct GNUNET_CADET_ClientChannelNumber chid) | ||
1218 | { | 1224 | { |
1219 | struct GNUNET_CONTAINER_MultiHashMap32 *map; | 1225 | struct GNUNET_CONTAINER_MultiHashMap32 *map; |
1220 | 1226 | ||
1221 | if (0 == (chid & GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)) | 1227 | if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) |
1222 | { | ||
1223 | GNUNET_break_op (0); | ||
1224 | LOG (GNUNET_ERROR_TYPE_DEBUG, "CHID %X not a local chid\n", chid); | ||
1225 | return NULL; | ||
1226 | } | ||
1227 | |||
1228 | if (chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV) | ||
1229 | map = c->incoming_channels; | ||
1230 | else if (chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) | ||
1231 | map = c->own_channels; | 1228 | map = c->own_channels; |
1232 | else | 1229 | else |
1233 | { | 1230 | map = c->incoming_channels; |
1234 | GNUNET_break (0); | 1231 | |
1235 | map = NULL; | ||
1236 | } | ||
1237 | if (NULL == map) | 1232 | if (NULL == map) |
1238 | { | 1233 | { |
1239 | GNUNET_break (0); | 1234 | GNUNET_break (0); |
@@ -1242,7 +1237,8 @@ GML_channel_get (struct CadetClient *c, CADET_ChannelNumber chid) | |||
1242 | GML_2s (c), chid); | 1237 | GML_2s (c), chid); |
1243 | return NULL; | 1238 | return NULL; |
1244 | } | 1239 | } |
1245 | return GNUNET_CONTAINER_multihashmap32_get (map, chid); | 1240 | return GNUNET_CONTAINER_multihashmap32_get (map, |
1241 | chid.channel_of_client); | ||
1246 | } | 1242 | } |
1247 | 1243 | ||
1248 | 1244 | ||
@@ -1255,17 +1251,19 @@ GML_channel_get (struct CadetClient *c, CADET_ChannelNumber chid) | |||
1255 | */ | 1251 | */ |
1256 | void | 1252 | void |
1257 | GML_channel_add (struct CadetClient *client, | 1253 | GML_channel_add (struct CadetClient *client, |
1258 | uint32_t chid, | 1254 | struct GNUNET_CADET_ClientChannelNumber chid, |
1259 | struct CadetChannel *ch) | 1255 | struct CadetChannel *ch) |
1260 | { | 1256 | { |
1261 | if (chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV) | 1257 | if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) |
1262 | GNUNET_CONTAINER_multihashmap32_put (client->incoming_channels, chid, ch, | 1258 | GNUNET_CONTAINER_multihashmap32_put (client->own_channels, |
1263 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1259 | chid.channel_of_client, |
1264 | else if (chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) | 1260 | ch, |
1265 | GNUNET_CONTAINER_multihashmap32_put (client->own_channels, chid, ch, | ||
1266 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1261 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
1267 | else | 1262 | else |
1268 | GNUNET_break (0); | 1263 | GNUNET_CONTAINER_multihashmap32_put (client->incoming_channels, |
1264 | chid.channel_of_client, | ||
1265 | ch, | ||
1266 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
1269 | } | 1267 | } |
1270 | 1268 | ||
1271 | 1269 | ||
@@ -1278,19 +1276,17 @@ GML_channel_add (struct CadetClient *client, | |||
1278 | */ | 1276 | */ |
1279 | void | 1277 | void |
1280 | GML_channel_remove (struct CadetClient *client, | 1278 | GML_channel_remove (struct CadetClient *client, |
1281 | uint32_t chid, | 1279 | struct GNUNET_CADET_ClientChannelNumber chid, |
1282 | struct CadetChannel *ch) | 1280 | struct CadetChannel *ch) |
1283 | { | 1281 | { |
1284 | if (GNUNET_CADET_LOCAL_CHANNEL_ID_SERV <= chid) | 1282 | if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) |
1285 | GNUNET_break (GNUNET_YES == | 1283 | GNUNET_CONTAINER_multihashmap32_remove (client->own_channels, |
1286 | GNUNET_CONTAINER_multihashmap32_remove (client->incoming_channels, | 1284 | chid.channel_of_client, |
1287 | chid, ch)); | 1285 | ch); |
1288 | else if (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI <= chid) | ||
1289 | GNUNET_break (GNUNET_YES == | ||
1290 | GNUNET_CONTAINER_multihashmap32_remove (client->own_channels, | ||
1291 | chid, ch)); | ||
1292 | else | 1286 | else |
1293 | GNUNET_break (0); | 1287 | GNUNET_CONTAINER_multihashmap32_remove (client->incoming_channels, |
1288 | chid.channel_of_client, | ||
1289 | ch); | ||
1294 | } | 1290 | } |
1295 | 1291 | ||
1296 | 1292 | ||
@@ -1301,18 +1297,26 @@ GML_channel_remove (struct CadetClient *client, | |||
1301 | * | 1297 | * |
1302 | * @return LID of a channel free to use. | 1298 | * @return LID of a channel free to use. |
1303 | */ | 1299 | */ |
1304 | CADET_ChannelNumber | 1300 | struct GNUNET_CADET_ClientChannelNumber |
1305 | GML_get_next_chid (struct CadetClient *c) | 1301 | GML_get_next_chid (struct CadetClient *c) |
1306 | { | 1302 | { |
1307 | CADET_ChannelNumber chid; | 1303 | struct GNUNET_CADET_ClientChannelNumber chid; |
1308 | 1304 | ||
1309 | while (NULL != GML_channel_get (c, c->next_chid)) | 1305 | while (NULL != GML_channel_get (c, |
1306 | c->next_chid)) | ||
1310 | { | 1307 | { |
1311 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %u exists...\n", c->next_chid); | 1308 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1312 | c->next_chid = (c->next_chid + 1) | GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; | 1309 | "Channel %u exists...\n", |
1310 | c->next_chid); | ||
1311 | c->next_chid.channel_of_client | ||
1312 | = htonl (1 + (ntohl (c->next_chid.channel_of_client))); | ||
1313 | if (ntohl (c->next_chid.channel_of_client) >= | ||
1314 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) | ||
1315 | c->next_chid.channel_of_client = htonl (0); | ||
1313 | } | 1316 | } |
1314 | chid = c->next_chid; | 1317 | chid = c->next_chid; |
1315 | c->next_chid = (c->next_chid + 1) | GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; | 1318 | c->next_chid.channel_of_client |
1319 | = htonl (1 + (ntohl (c->next_chid.channel_of_client))); | ||
1316 | 1320 | ||
1317 | return chid; | 1321 | return chid; |
1318 | } | 1322 | } |
@@ -1330,9 +1334,11 @@ GML_client_get (struct GNUNET_SERVER_Client *client) | |||
1330 | { | 1334 | { |
1331 | if (NULL == client) | 1335 | if (NULL == client) |
1332 | return NULL; | 1336 | return NULL; |
1333 | return GNUNET_SERVER_client_get_user_context (client, struct CadetClient); | 1337 | return GNUNET_SERVER_client_get_user_context (client, |
1338 | struct CadetClient); | ||
1334 | } | 1339 | } |
1335 | 1340 | ||
1341 | |||
1336 | /** | 1342 | /** |
1337 | * Find a client that has opened a port | 1343 | * Find a client that has opened a port |
1338 | * | 1344 | * |
@@ -1357,27 +1363,25 @@ GML_client_get_by_port (const struct GNUNET_HashCode *port) | |||
1357 | void | 1363 | void |
1358 | GML_client_delete_channel (struct CadetClient *c, | 1364 | GML_client_delete_channel (struct CadetClient *c, |
1359 | struct CadetChannel *ch, | 1365 | struct CadetChannel *ch, |
1360 | CADET_ChannelNumber id) | 1366 | struct GNUNET_CADET_ClientChannelNumber id) |
1361 | { | 1367 | { |
1362 | int res; | 1368 | int res; |
1363 | 1369 | ||
1364 | if (GNUNET_CADET_LOCAL_CHANNEL_ID_SERV <= id) | 1370 | if (ntohl (id.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) |
1365 | { | ||
1366 | res = GNUNET_CONTAINER_multihashmap32_remove (c->incoming_channels, | ||
1367 | id, ch); | ||
1368 | if (GNUNET_YES != res) | ||
1369 | LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_channel dest KO\n"); | ||
1370 | } | ||
1371 | else if (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI <= id) | ||
1372 | { | 1371 | { |
1373 | res = GNUNET_CONTAINER_multihashmap32_remove (c->own_channels, | 1372 | res = GNUNET_CONTAINER_multihashmap32_remove (c->own_channels, |
1374 | id, ch); | 1373 | id.channel_of_client, |
1374 | ch); | ||
1375 | if (GNUNET_YES != res) | 1375 | if (GNUNET_YES != res) |
1376 | LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_tunnel root KO\n"); | 1376 | LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_tunnel root KO\n"); |
1377 | } | 1377 | } |
1378 | else | 1378 | else |
1379 | { | 1379 | { |
1380 | GNUNET_break (0); | 1380 | res = GNUNET_CONTAINER_multihashmap32_remove (c->incoming_channels, |
1381 | id.channel_of_client, | ||
1382 | ch); | ||
1383 | if (GNUNET_YES != res) | ||
1384 | LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_channel dest KO\n"); | ||
1381 | } | 1385 | } |
1382 | } | 1386 | } |
1383 | 1387 | ||
@@ -1390,17 +1394,21 @@ GML_client_delete_channel (struct CadetClient *c, | |||
1390 | * @param id Channel ID to use | 1394 | * @param id Channel ID to use |
1391 | */ | 1395 | */ |
1392 | void | 1396 | void |
1393 | GML_send_ack (struct CadetClient *c, CADET_ChannelNumber id) | 1397 | GML_send_ack (struct CadetClient *c, |
1398 | struct GNUNET_CADET_ClientChannelNumber id) | ||
1394 | { | 1399 | { |
1395 | struct GNUNET_CADET_LocalAck msg; | 1400 | struct GNUNET_CADET_LocalAck msg; |
1396 | 1401 | ||
1397 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1402 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1398 | "send local %s ack on %X towards %p\n", | 1403 | "send local %s ack on %X towards %p\n", |
1399 | id < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV ? "FWD" : "BCK", id, c); | 1404 | ntohl (id.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI |
1405 | ? "FWD" : "BCK", | ||
1406 | ntohl (id.channel_of_client), | ||
1407 | c); | ||
1400 | 1408 | ||
1401 | msg.header.size = htons (sizeof (msg)); | 1409 | msg.header.size = htons (sizeof (msg)); |
1402 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); | 1410 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); |
1403 | msg.channel_id = htonl (id); | 1411 | msg.channel_id = id; |
1404 | GNUNET_SERVER_notification_context_unicast (nc, | 1412 | GNUNET_SERVER_notification_context_unicast (nc, |
1405 | c->handle, | 1413 | c->handle, |
1406 | &msg.header, | 1414 | &msg.header, |
@@ -1421,14 +1429,16 @@ GML_send_ack (struct CadetClient *c, CADET_ChannelNumber id) | |||
1421 | */ | 1429 | */ |
1422 | void | 1430 | void |
1423 | GML_send_channel_create (struct CadetClient *c, | 1431 | GML_send_channel_create (struct CadetClient *c, |
1424 | uint32_t id, struct GNUNET_HashCode *port, | 1432 | struct GNUNET_CADET_ClientChannelNumber id, |
1425 | uint32_t opt, const struct GNUNET_PeerIdentity *peer) | 1433 | const struct GNUNET_HashCode *port, |
1434 | uint32_t opt, | ||
1435 | const struct GNUNET_PeerIdentity *peer) | ||
1426 | { | 1436 | { |
1427 | struct GNUNET_CADET_ChannelCreateMessage msg; | 1437 | struct GNUNET_CADET_ChannelOpenMessageMessage msg; |
1428 | 1438 | ||
1429 | msg.header.size = htons (sizeof (msg)); | 1439 | msg.header.size = htons (sizeof (msg)); |
1430 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE); | 1440 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); |
1431 | msg.channel_id = htonl (id); | 1441 | msg.channel_id = id; |
1432 | msg.port = *port; | 1442 | msg.port = *port; |
1433 | msg.opt = htonl (opt); | 1443 | msg.opt = htonl (opt); |
1434 | msg.peer = *peer; | 1444 | msg.peer = *peer; |
@@ -1444,17 +1454,19 @@ GML_send_channel_create (struct CadetClient *c, | |||
1444 | * @param id Channel ID to use | 1454 | * @param id Channel ID to use |
1445 | */ | 1455 | */ |
1446 | void | 1456 | void |
1447 | GML_send_channel_nack (struct CadetClient *c, CADET_ChannelNumber id) | 1457 | GML_send_channel_nack (struct CadetClient *c, |
1458 | struct GNUNET_CADET_ClientChannelNumber id) | ||
1448 | { | 1459 | { |
1449 | struct GNUNET_CADET_LocalAck msg; | 1460 | struct GNUNET_CADET_LocalAck msg; |
1450 | 1461 | ||
1451 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1462 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1452 | "send local nack on %X towards %p\n", | 1463 | "send local nack on %X towards %p\n", |
1453 | id, c); | 1464 | ntohl (id.channel_of_client), |
1465 | c); | ||
1454 | 1466 | ||
1455 | msg.header.size = htons (sizeof (msg)); | 1467 | msg.header.size = htons (sizeof (msg)); |
1456 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK); | 1468 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_NACK_DEPRECATED); |
1457 | msg.channel_id = htonl (id); | 1469 | msg.channel_id = id; |
1458 | GNUNET_SERVER_notification_context_unicast (nc, | 1470 | GNUNET_SERVER_notification_context_unicast (nc, |
1459 | c->handle, | 1471 | c->handle, |
1460 | &msg.header, | 1472 | &msg.header, |
@@ -1469,7 +1481,8 @@ GML_send_channel_nack (struct CadetClient *c, CADET_ChannelNumber id) | |||
1469 | * @param id ID of the channel that is destroyed. | 1481 | * @param id ID of the channel that is destroyed. |
1470 | */ | 1482 | */ |
1471 | void | 1483 | void |
1472 | GML_send_channel_destroy (struct CadetClient *c, uint32_t id) | 1484 | GML_send_channel_destroy (struct CadetClient *c, |
1485 | struct GNUNET_CADET_ClientChannelNumber id) | ||
1473 | { | 1486 | { |
1474 | struct GNUNET_CADET_ChannelDestroyMessage msg; | 1487 | struct GNUNET_CADET_ChannelDestroyMessage msg; |
1475 | 1488 | ||
@@ -1482,7 +1495,7 @@ GML_send_channel_destroy (struct CadetClient *c, uint32_t id) | |||
1482 | return; | 1495 | return; |
1483 | msg.header.size = htons (sizeof (msg)); | 1496 | msg.header.size = htons (sizeof (msg)); |
1484 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); | 1497 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); |
1485 | msg.channel_id = htonl (id); | 1498 | msg.channel_id = id; |
1486 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, | 1499 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, |
1487 | &msg.header, GNUNET_NO); | 1500 | &msg.header, GNUNET_NO); |
1488 | } | 1501 | } |
@@ -1497,11 +1510,11 @@ GML_send_channel_destroy (struct CadetClient *c, uint32_t id) | |||
1497 | */ | 1510 | */ |
1498 | void | 1511 | void |
1499 | GML_send_data (struct CadetClient *c, | 1512 | GML_send_data (struct CadetClient *c, |
1500 | const struct GNUNET_CADET_Data *msg, | 1513 | const struct GNUNET_CADET_ChannelAppDataMessage *msg, |
1501 | CADET_ChannelNumber id) | 1514 | struct GNUNET_CADET_ClientChannelNumber id) |
1502 | { | 1515 | { |
1503 | struct GNUNET_CADET_LocalData *copy; | 1516 | struct GNUNET_CADET_LocalData *copy; |
1504 | uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_CADET_Data); | 1517 | uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_CADET_ChannelAppDataMessage); |
1505 | char cbuf[size + sizeof (struct GNUNET_CADET_LocalData)]; | 1518 | char cbuf[size + sizeof (struct GNUNET_CADET_LocalData)]; |
1506 | 1519 | ||
1507 | if (size < sizeof (struct GNUNET_MessageHeader)) | 1520 | if (size < sizeof (struct GNUNET_MessageHeader)) |
@@ -1518,7 +1531,7 @@ GML_send_data (struct CadetClient *c, | |||
1518 | GNUNET_memcpy (©[1], &msg[1], size); | 1531 | GNUNET_memcpy (©[1], &msg[1], size); |
1519 | copy->header.size = htons (sizeof (struct GNUNET_CADET_LocalData) + size); | 1532 | copy->header.size = htons (sizeof (struct GNUNET_CADET_LocalData) + size); |
1520 | copy->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); | 1533 | copy->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); |
1521 | copy->id = htonl (id); | 1534 | copy->id = id; |
1522 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, | 1535 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, |
1523 | ©->header, GNUNET_NO); | 1536 | ©->header, GNUNET_NO); |
1524 | } | 1537 | } |