diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 174 |
1 files changed, 95 insertions, 79 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index ccb66f75f..75f788895 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -27,6 +27,7 @@ | |||
27 | * - when sending in-order buffered data, wait for client ACKs | 27 | * - when sending in-order buffered data, wait for client ACKs |
28 | * - add signatures | 28 | * - add signatures |
29 | * - add encryption | 29 | * - add encryption |
30 | * - set connection IDs independently from tunnel, tunnel has no ID | ||
30 | * | 31 | * |
31 | * TODO: | 32 | * TODO: |
32 | * - relay corking down to core | 33 | * - relay corking down to core |
@@ -377,6 +378,11 @@ struct MeshReliableMessage | |||
377 | struct MeshReliableMessage *prev; | 378 | struct MeshReliableMessage *prev; |
378 | 379 | ||
379 | /** | 380 | /** |
381 | * Type of message (payload, channel management). | ||
382 | */ | ||
383 | int16_t type; | ||
384 | |||
385 | /** | ||
380 | * Tunnel Reliability queue this message is in. | 386 | * Tunnel Reliability queue this message is in. |
381 | */ | 387 | */ |
382 | struct MeshChannelReliability *rel; | 388 | struct MeshChannelReliability *rel; |
@@ -3091,9 +3097,10 @@ channel_send_data_ack (struct MeshChannel *ch, int fwd) | |||
3091 | struct GNUNET_MESH_DataACK msg; | 3097 | struct GNUNET_MESH_DataACK msg; |
3092 | struct MeshChannelReliability *rel; | 3098 | struct MeshChannelReliability *rel; |
3093 | struct MeshReliableMessage *copy; | 3099 | struct MeshReliableMessage *copy; |
3100 | unsigned int delta; | ||
3094 | uint64_t mask; | 3101 | uint64_t mask; |
3095 | uint32_t *mid; | 3102 | uint32_t *mid; |
3096 | unsigned int delta; | 3103 | uint16_t type; |
3097 | 3104 | ||
3098 | if (GNUNET_NO == ch->reliable) | 3105 | if (GNUNET_NO == ch->reliable) |
3099 | { | 3106 | { |
@@ -3106,14 +3113,16 @@ channel_send_data_ack (struct MeshChannel *ch, int fwd) | |||
3106 | "send_data_ack for %u\n", | 3113 | "send_data_ack for %u\n", |
3107 | *mid - 1); | 3114 | *mid - 1); |
3108 | 3115 | ||
3109 | msg.header.type = htons (fwd ? GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK : | 3116 | type = GNUNET_MESSAGE_TYPE_MESH_DATA_ACK; |
3110 | GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK); | 3117 | msg.header.type = htons (type); |
3111 | msg.header.size = htons (sizeof (msg)); | 3118 | msg.header.size = htons (sizeof (msg)); |
3112 | msg.chid = htonl (ch->gid); | 3119 | msg.chid = htonl (ch->gid); |
3113 | msg.mid = htonl (*mid - 1); | 3120 | msg.mid = htonl (*mid - 1); |
3114 | msg.futures = 0; | 3121 | msg.futures = 0; |
3115 | for (copy = rel->head_recv; NULL != copy; copy = copy->next) | 3122 | for (copy = rel->head_recv; NULL != copy; copy = copy->next) |
3116 | { | 3123 | { |
3124 | if (copy->type != type) | ||
3125 | continue; | ||
3117 | delta = copy->mid - *mid; | 3126 | delta = copy->mid - *mid; |
3118 | if (63 < delta) | 3127 | if (63 < delta) |
3119 | break; | 3128 | break; |
@@ -3265,6 +3274,7 @@ channel_send_client_buffered_data (struct MeshChannel *ch, | |||
3265 | 3274 | ||
3266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data\n"); | 3275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data\n"); |
3267 | copy = rel->head_recv; | 3276 | copy = rel->head_recv; |
3277 | /* We never buffer channel management messages */ | ||
3268 | if (NULL != copy) | 3278 | if (NULL != copy) |
3269 | { | 3279 | { |
3270 | if (copy->mid == *mid || GNUNET_NO == ch->reliable) | 3280 | if (copy->mid == *mid || GNUNET_NO == ch->reliable) |
@@ -3298,7 +3308,7 @@ channel_send_client_buffered_data (struct MeshChannel *ch, | |||
3298 | * Buffer it until we receive an ACK from the client or the missing | 3308 | * Buffer it until we receive an ACK from the client or the missing |
3299 | * message from the channel. | 3309 | * message from the channel. |
3300 | * | 3310 | * |
3301 | * @param msg Message to buffer. | 3311 | * @param msg Message to buffer (MUST be of type MESH_DATA). |
3302 | * @param rel Reliability data to the corresponding direction. | 3312 | * @param rel Reliability data to the corresponding direction. |
3303 | */ | 3313 | */ |
3304 | static void | 3314 | static void |
@@ -3312,6 +3322,7 @@ channel_rel_add_buffered_data (const struct GNUNET_MESH_Data *msg, | |||
3312 | 3322 | ||
3313 | size = ntohs (msg->header.size); | 3323 | size = ntohs (msg->header.size); |
3314 | mid = ntohl (msg->mid); | 3324 | mid = ntohl (msg->mid); |
3325 | |||
3315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add_buffered_data %u\n", mid); | 3326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add_buffered_data %u\n", mid); |
3316 | 3327 | ||
3317 | copy = GNUNET_malloc (sizeof (*copy) + size); | 3328 | copy = GNUNET_malloc (sizeof (*copy) + size); |
@@ -3674,6 +3685,54 @@ channel_confirm (struct MeshChannel *ch, int fwd) | |||
3674 | 3685 | ||
3675 | 3686 | ||
3676 | /** | 3687 | /** |
3688 | * Save a copy to retransmit in case it gets lost. | ||
3689 | * | ||
3690 | * Initializes all needed callbacks and timers. | ||
3691 | * | ||
3692 | * @param ch Channel this message goes on. | ||
3693 | * @param msg Message to copy. | ||
3694 | * @param fwd Is this fwd traffic? | ||
3695 | */ | ||
3696 | static void | ||
3697 | channel_save_copy (struct MeshChannel *ch, | ||
3698 | const struct GNUNET_MessageHeader *msg, | ||
3699 | int fwd) | ||
3700 | { | ||
3701 | struct MeshChannelReliability *rel; | ||
3702 | struct MeshReliableMessage *copy; | ||
3703 | uint32_t mid; | ||
3704 | uint16_t type; | ||
3705 | uint16_t size; | ||
3706 | |||
3707 | rel = fwd ? ch->fwd_rel : ch->bck_rel; | ||
3708 | mid = fwd ? ch->mid_send_fwd : ch->mid_send_bck; | ||
3709 | type = ntohs (msg->type); | ||
3710 | size = ntohs (msg->size); | ||
3711 | |||
3712 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! SAVE %u\n", mid); | ||
3713 | copy = GNUNET_malloc (sizeof (struct MeshReliableMessage) + size); | ||
3714 | copy->mid = mid; | ||
3715 | copy->timestamp = GNUNET_TIME_absolute_get (); | ||
3716 | copy->rel = rel; | ||
3717 | copy->type = type; | ||
3718 | memcpy (©[1], msg, size); | ||
3719 | rel->n_sent++; | ||
3720 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " n_sent %u\n", rel->n_sent); | ||
3721 | GNUNET_CONTAINER_DLL_insert_tail (rel->head_sent, rel->tail_sent, copy); | ||
3722 | if (GNUNET_SCHEDULER_NO_TASK == rel->retry_task) | ||
3723 | { | ||
3724 | rel->retry_timer = | ||
3725 | GNUNET_TIME_relative_multiply (rel->expected_delay, | ||
3726 | MESH_RETRANSMIT_MARGIN); | ||
3727 | rel->retry_task = | ||
3728 | GNUNET_SCHEDULER_add_delayed (rel->retry_timer, | ||
3729 | &channel_retransmit_message, | ||
3730 | rel); | ||
3731 | } | ||
3732 | } | ||
3733 | |||
3734 | |||
3735 | /** | ||
3677 | * Send keepalive packets for a connection. | 3736 | * Send keepalive packets for a connection. |
3678 | * | 3737 | * |
3679 | * @param c Connection to keep alive.. | 3738 | * @param c Connection to keep alive.. |
@@ -4594,8 +4653,7 @@ queue_send (void *cls, size_t size, void *buf) | |||
4594 | else | 4653 | else |
4595 | data_size = send_core_data_raw (queue->cls, size, buf); | 4654 | data_size = send_core_data_raw (queue->cls, size, buf); |
4596 | break; | 4655 | break; |
4597 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | 4656 | case GNUNET_MESSAGE_TYPE_MESH_DATA: |
4598 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
4599 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE: | 4657 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE: |
4600 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: | 4658 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: |
4601 | /* This should be encapsulted */ | 4659 | /* This should be encapsulted */ |
@@ -5527,6 +5585,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer, | |||
5527 | size_t dsize = size - sizeof (struct GNUNET_MESH_Encrypted); | 5585 | size_t dsize = size - sizeof (struct GNUNET_MESH_Encrypted); |
5528 | char cbuf[dsize]; | 5586 | char cbuf[dsize]; |
5529 | struct GNUNET_MessageHeader *msgh; | 5587 | struct GNUNET_MessageHeader *msgh; |
5588 | int r; | ||
5530 | 5589 | ||
5531 | /* TODO signature verification */ | 5590 | /* TODO signature verification */ |
5532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " it's for us!\n"); | 5591 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " it's for us!\n"); |
@@ -5537,52 +5596,41 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer, | |||
5537 | msgh = (struct GNUNET_MessageHeader *) cbuf; | 5596 | msgh = (struct GNUNET_MessageHeader *) cbuf; |
5538 | switch (ntohs (msgh->type)) | 5597 | switch (ntohs (msgh->type)) |
5539 | { | 5598 | { |
5540 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK: | 5599 | case GNUNET_MESSAGE_TYPE_MESH_DATA_ACK: |
5541 | if (GNUNET_YES == fwd) | 5600 | r = handle_data_ack (t, (struct GNUNET_MESH_DataACK *) msgh, fwd); |
5542 | return handle_data_ack (t, (struct GNUNET_MESH_DataACK *) msgh, | ||
5543 | GNUNET_YES); | ||
5544 | GNUNET_break_op (0); | ||
5545 | break; | ||
5546 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK: | ||
5547 | if (GNUNET_NO == fwd) | ||
5548 | return handle_data_ack (t, (struct GNUNET_MESH_DataACK *) msgh, | ||
5549 | GNUNET_YES); | ||
5550 | GNUNET_break_op (0); | ||
5551 | break; | ||
5552 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
5553 | if (GNUNET_YES == fwd) | ||
5554 | handle_data (t, (struct GNUNET_MESH_Data *) msgh, GNUNET_YES); | ||
5555 | GNUNET_break_op (0); | ||
5556 | break; | 5601 | break; |
5557 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | 5602 | |
5558 | if (GNUNET_NO == fwd) | 5603 | case GNUNET_MESSAGE_TYPE_MESH_DATA: |
5559 | handle_data (t, (struct GNUNET_MESH_Data *) msgh, GNUNET_NO); | 5604 | r = handle_data (t, (struct GNUNET_MESH_Data *) msgh, fwd); |
5560 | GNUNET_break_op (0); | ||
5561 | break; | 5605 | break; |
5606 | |||
5562 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE: | 5607 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE: |
5563 | return handle_channel_create (t, | 5608 | r = handle_channel_create (t, |
5564 | (struct GNUNET_MESH_ChannelCreate *) msgh, | 5609 | (struct GNUNET_MESH_ChannelCreate *) msgh, |
5565 | fwd); | 5610 | fwd); |
5566 | break; | 5611 | break; |
5612 | |||
5567 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK: | 5613 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK: |
5568 | return handle_channel_ack (t, | 5614 | r = handle_channel_ack (t, |
5569 | (struct GNUNET_MESH_ChannelManage *) msgh, | 5615 | (struct GNUNET_MESH_ChannelManage *) msgh, |
5570 | fwd); | 5616 | fwd); |
5571 | break; | 5617 | break; |
5618 | |||
5572 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: | 5619 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: |
5573 | return handle_channel_destroy (t, | 5620 | r = handle_channel_destroy (t, |
5574 | (struct GNUNET_MESH_ChannelManage *) | 5621 | (struct GNUNET_MESH_ChannelManage *) msgh, |
5575 | msgh, | 5622 | fwd); |
5576 | fwd); | ||
5577 | break; | 5623 | break; |
5624 | |||
5578 | default: | 5625 | default: |
5579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5580 | "end-to-end message not known (%u)\n", | 5627 | "end-to-end message not known (%u)\n", |
5581 | ntohs (msgh->type)); | 5628 | ntohs (msgh->type)); |
5629 | r = GNUNET_OK; | ||
5582 | } | 5630 | } |
5583 | 5631 | ||
5584 | connection_send_ack (c, fwd); | 5632 | connection_send_ack (c, fwd); |
5585 | return GNUNET_OK; | 5633 | return r; |
5586 | } | 5634 | } |
5587 | 5635 | ||
5588 | /* Message not for us: forward to next hop */ | 5636 | /* Message not for us: forward to next hop */ |
@@ -6315,58 +6363,26 @@ handle_local_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
6315 | else | 6363 | else |
6316 | ch->blocked_bck = GNUNET_YES; | 6364 | ch->blocked_bck = GNUNET_YES; |
6317 | 6365 | ||
6318 | /* Ok, everything is correct, send the message | 6366 | /* Ok, everything is correct, send the message. */ |
6319 | * (pretend we got it from a mesh peer) | ||
6320 | */ | ||
6321 | { | 6367 | { |
6322 | struct GNUNET_MESH_Data *payload; | 6368 | struct GNUNET_MESH_Data *payload; |
6323 | char cbuf[sizeof(struct GNUNET_MESH_Data) + size]; | 6369 | uint16_t p2p_size = sizeof(struct GNUNET_MESH_Data) + size; |
6370 | unsigned char cbuf[p2p_size]; | ||
6324 | uint32_t *mid; | 6371 | uint32_t *mid; |
6325 | 6372 | ||
6326 | mid = fwd ? &ch->mid_send_fwd : &ch->mid_send_bck; | 6373 | mid = fwd ? &ch->mid_send_fwd : &ch->mid_send_bck; |
6327 | if (GNUNET_YES == ch->reliable) | 6374 | payload = (struct GNUNET_MESH_Data *) cbuf; |
6328 | { | ||
6329 | struct MeshChannelReliability *rel; | ||
6330 | struct MeshReliableMessage *copy; | ||
6331 | |||
6332 | rel = fwd ? ch->fwd_rel : ch->bck_rel; | ||
6333 | copy = GNUNET_malloc (sizeof (struct MeshReliableMessage) | ||
6334 | + sizeof(struct GNUNET_MESH_Data) | ||
6335 | + size); | ||
6336 | copy->mid = *mid; | ||
6337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! DATA %u\n", copy->mid); | ||
6338 | copy->timestamp = GNUNET_TIME_absolute_get (); | ||
6339 | copy->rel = rel; | ||
6340 | rel->n_sent++; | ||
6341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " n_sent %u\n", rel->n_sent); | ||
6342 | GNUNET_CONTAINER_DLL_insert_tail (rel->head_sent, rel->tail_sent, copy); | ||
6343 | if (GNUNET_SCHEDULER_NO_TASK == rel->retry_task) | ||
6344 | { | ||
6345 | rel->retry_timer = | ||
6346 | GNUNET_TIME_relative_multiply (rel->expected_delay, | ||
6347 | MESH_RETRANSMIT_MARGIN); | ||
6348 | rel->retry_task = | ||
6349 | GNUNET_SCHEDULER_add_delayed (rel->retry_timer, | ||
6350 | &channel_retransmit_message, | ||
6351 | rel); | ||
6352 | } | ||
6353 | payload = (struct GNUNET_MESH_Data *) ©[1]; | ||
6354 | } | ||
6355 | else | ||
6356 | { | ||
6357 | payload = (struct GNUNET_MESH_Data *) cbuf; | ||
6358 | } | ||
6359 | payload->mid = htonl (*mid); | 6375 | payload->mid = htonl (*mid); |
6360 | *mid = *mid + 1; | 6376 | *mid = *mid + 1; |
6361 | memcpy (&payload[1], &msg[1], size); | 6377 | memcpy (&payload[1], &msg[1], size); |
6362 | payload->header.size = htons (sizeof (struct GNUNET_MESH_Data) + size); | 6378 | payload->header.size = htons (p2p_size); |
6363 | payload->header.type = htons (chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV ? | 6379 | payload->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_DATA); |
6364 | GNUNET_MESSAGE_TYPE_MESH_UNICAST : | ||
6365 | GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN); | ||
6366 | payload->chid = htonl (ch->gid); | 6380 | payload->chid = htonl (ch->gid); |
6367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 6381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n"); |
6368 | " calling generic handler...\n"); | ||
6369 | send_prebuilt_message_channel (&payload->header, ch, fwd); | 6382 | send_prebuilt_message_channel (&payload->header, ch, fwd); |
6383 | |||
6384 | if (GNUNET_YES == ch->reliable) | ||
6385 | channel_save_copy (ch, &payload->header, fwd); | ||
6370 | } | 6386 | } |
6371 | if (tunnel_get_buffer (ch->t, fwd) > 0) | 6387 | if (tunnel_get_buffer (ch->t, fwd) > 0) |
6372 | send_local_ack (ch, c, fwd); | 6388 | send_local_ack (ch, c, fwd); |