diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-08-01 18:27:36 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-08-01 18:27:36 +0000 |
commit | 61faae19d6cc81ac2ad9177c3dc8a07706632afc (patch) | |
tree | f15cd736ae6d40652549a5580b88c05ccbfb25c9 /src | |
parent | 1a5f8627f57db2ce715154499a5a9648aa35d6b4 (diff) | |
download | gnunet-61faae19d6cc81ac2ad9177c3dc8a07706632afc.tar.gz gnunet-61faae19d6cc81ac2ad9177c3dc8a07706632afc.zip |
- more channel modifications
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 220 | ||||
-rw-r--r-- | src/mesh/mesh_enc.h | 4 | ||||
-rw-r--r-- | src/mesh/mesh_protocol_enc.h | 2 |
3 files changed, 139 insertions, 87 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index e0df91498..53032b5c8 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -1569,15 +1569,15 @@ send_connection_ack (struct MeshConnection *connection) | |||
1569 | * @param ack Value of the ACK. | 1569 | * @param ack Value of the ACK. |
1570 | */ | 1570 | */ |
1571 | static void | 1571 | static void |
1572 | send_ack (GNUNET_PEER_Id peer, uint32_t ack) | 1572 | send_ack (struct MeshPeer *peer, uint32_t ack) |
1573 | { | 1573 | { |
1574 | struct GNUNET_MESH_ACK msg; | 1574 | struct GNUNET_MESH_ACK msg; |
1575 | 1575 | ||
1576 | msg.header.size = htons (sizeof (msg)); | 1576 | msg.header.size = htons (sizeof (msg)); |
1577 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_ACK); | 1577 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_ACK); |
1578 | msg.pid = htonl (ack); | 1578 | msg.ack = htonl (ack); |
1579 | 1579 | ||
1580 | send_prebuilt_message_peer (&msg.header, peer_get_short (peer)); | 1580 | send_prebuilt_message_peer (&msg.header, peer); |
1581 | } | 1581 | } |
1582 | 1582 | ||
1583 | 1583 | ||
@@ -2646,71 +2646,35 @@ channel_send_data_ack (struct MeshChannel *ch, int fwd) | |||
2646 | 2646 | ||
2647 | /** | 2647 | /** |
2648 | * Send an ACK informing the predecessor about the available buffer space. | 2648 | * Send an ACK informing the predecessor about the available buffer space. |
2649 | * In case there is no predecessor, inform the owning client. | ||
2650 | * | 2649 | * |
2651 | * Note that although the name is fwd_ack, the FWD mean forward *traffic*, | 2650 | * Note that although the name is fwd_ack, the FWD mean forward *traffic*, |
2652 | * the ACK itself goes "back" (towards root). | 2651 | * the ACK itself goes "back" (towards root). |
2653 | * | 2652 | * |
2654 | * @param ch Channel on which to send the ACK. | ||
2655 | * @param c Connection on which to send the ACK. | 2653 | * @param c Connection on which to send the ACK. |
2656 | * @param type Type of message that triggered the ACK transmission. | ||
2657 | * @param fwd Is this FWD ACK? (Going dest->owner) | 2654 | * @param fwd Is this FWD ACK? (Going dest->owner) |
2658 | */ | 2655 | */ |
2659 | static void | 2656 | static void |
2660 | channel_send_ack (struct MeshChannel *ch, struct MeshConnection *c, | 2657 | connection_send_ack (struct MeshConnection *c, int fwd) |
2661 | uint16_t type, int fwd) | ||
2662 | { | 2658 | { |
2663 | struct MeshChannelReliability *rel; | ||
2664 | struct MeshFlowControl *next_fc; | 2659 | struct MeshFlowControl *next_fc; |
2665 | struct MeshFlowControl *prev_fc; | 2660 | struct MeshFlowControl *prev_fc; |
2666 | struct MeshClient *c; | 2661 | struct MeshPeer *next; |
2667 | struct MeshClient *o; | 2662 | struct MeshPeer *prev; |
2668 | GNUNET_PEER_Id hop; | 2663 | GNUNET_PEER_Id id; |
2669 | uint32_t delta_mid; | ||
2670 | uint32_t ack; | 2664 | uint32_t ack; |
2671 | int delta; | 2665 | int delta; |
2672 | 2666 | ||
2673 | rel = fwd ? ch->fwd_rel : ch->bck_rel; | 2667 | id = fwd ? connection_get_next_hop (c) : connection_get_prev_hop (c); |
2674 | c = fwd ? ch->client : ch->owner; | 2668 | next = peer_get_short (id); |
2675 | o = fwd ? ch->owner : ch->client; | 2669 | id = fwd ? connection_get_prev_hop (c) : connection_get_next_hop (c); |
2676 | hop = fwd ? connection_get_prev_hop (c) : connection_get_next_hop (c); | 2670 | prev = peer_get_short (id); |
2677 | next_fc = fwd ? &t->next_fc : &t->prev_fc; | 2671 | next_fc = next->fc; |
2678 | prev_fc = fwd ? &t->prev_fc : &t->next_fc; | 2672 | prev_fc = prev->fc; |
2679 | |||
2680 | switch (type) | ||
2681 | { | ||
2682 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
2683 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
2684 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2685 | "ACK due to %s\n", | ||
2686 | GNUNET_MESH_DEBUG_M2S (type)); | ||
2687 | if (GNUNET_YES == t->nobuffer && (GNUNET_NO == t->reliable || NULL == c)) | ||
2688 | { | ||
2689 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, nobuffer\n"); | ||
2690 | return; | ||
2691 | } | ||
2692 | if (GNUNET_YES == t->reliable && NULL != c) | ||
2693 | tunnel_send_data_ack (t, fwd); | ||
2694 | break; | ||
2695 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK: | ||
2696 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK: | ||
2697 | case GNUNET_MESSAGE_TYPE_MESH_ACK: | ||
2698 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK: | ||
2699 | break; | ||
2700 | case GNUNET_MESSAGE_TYPE_MESH_POLL: | ||
2701 | case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK: | ||
2702 | t->force_ack = GNUNET_YES; | ||
2703 | break; | ||
2704 | default: | ||
2705 | GNUNET_break (0); | ||
2706 | } | ||
2707 | 2673 | ||
2708 | /* Check if we need to transmit the ACK */ | 2674 | /* Check if we need to transmit the ACK */ |
2709 | if (NULL == o && | 2675 | if (prev_fc->last_ack_sent - prev_fc->last_pid_recv > 3) |
2710 | prev_fc->last_ack_sent - prev_fc->last_pid_recv > 3 && | ||
2711 | GNUNET_NO == t->force_ack) | ||
2712 | { | 2676 | { |
2713 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer free\n"); | 2677 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer > 3\n"); |
2714 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2678 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2715 | " last pid recv: %u, last ack sent: %u\n", | 2679 | " last pid recv: %u, last ack sent: %u\n", |
2716 | prev_fc->last_pid_recv, prev_fc->last_ack_sent); | 2680 | prev_fc->last_pid_recv, prev_fc->last_ack_sent); |
@@ -2718,52 +2682,140 @@ channel_send_ack (struct MeshChannel *ch, struct MeshConnection *c, | |||
2718 | } | 2682 | } |
2719 | 2683 | ||
2720 | /* Ok, ACK might be necessary, what PID to ACK? */ | 2684 | /* Ok, ACK might be necessary, what PID to ACK? */ |
2721 | delta = t->queue_max - next_fc->queue_n; | 2685 | delta = next_fc->queue_max - next_fc->queue_n; |
2722 | if (NULL != o && GNUNET_YES == t->reliable && NULL != rel->head_sent) | ||
2723 | delta_mid = rel->mid_sent - rel->head_sent->mid; | ||
2724 | else | ||
2725 | delta_mid = 0; | ||
2726 | if (0 > delta || (GNUNET_YES == t->reliable && | ||
2727 | NULL != o && | ||
2728 | (10 < rel->n_sent || 64 <= delta_mid))) | ||
2729 | delta = 0; | ||
2730 | if (NULL != o && delta > 1) | ||
2731 | delta = 1; | ||
2732 | ack = prev_fc->last_pid_recv + delta; | 2686 | ack = prev_fc->last_pid_recv + delta; |
2733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack); | 2687 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack); |
2734 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2688 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2735 | " last pid %u, last ack %u, qmax %u, q %u\n", | 2689 | " last pid %u, last ack %u, qmax %u, q %u\n", |
2736 | prev_fc->last_pid_recv, prev_fc->last_ack_sent, | 2690 | prev_fc->last_pid_recv, prev_fc->last_ack_sent, |
2737 | t->queue_max, next_fc->queue_n); | 2691 | next_fc->queue_max, next_fc->queue_n); |
2738 | if (ack == prev_fc->last_ack_sent && GNUNET_NO == t->force_ack) | 2692 | if (ack == prev_fc->last_ack_sent) |
2739 | { | 2693 | { |
2740 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, not needed\n"); | 2694 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, not needed\n"); |
2741 | return; | 2695 | return; |
2742 | } | 2696 | } |
2743 | 2697 | ||
2744 | prev_fc->last_ack_sent = ack; | 2698 | prev_fc->last_ack_sent = ack; |
2745 | if (NULL != o) | 2699 | send_ack (prev, ack); |
2746 | send_local_ack (t, o, fwd); | ||
2747 | else if (0 != hop) | ||
2748 | send_ack (t, hop, ack); | ||
2749 | else | ||
2750 | GNUNET_break (GNUNET_YES == t->destroy); | ||
2751 | t->force_ack = GNUNET_NO; | ||
2752 | } | 2700 | } |
2753 | 2701 | ||
2754 | 2702 | ||
2755 | /** | 2703 | /** |
2704 | * Send an ACK informing the client about available buffer space. | ||
2705 | * | ||
2706 | * Note that although the name is fwd_ack, the FWD mean forward *traffic*, | ||
2707 | * the ACK itself goes "back" (towards root). | ||
2708 | * | ||
2709 | * @param ch Channel on which to send the ACK, NULL if unknown. | ||
2710 | * @param fwd Is this FWD ACK? (Going dest->owner) | ||
2711 | */ | ||
2712 | // static void | ||
2713 | // channel_send_ack (struct MeshChannel *ch, uint16_t type, int fwd) | ||
2714 | // { | ||
2715 | // struct MeshChannelReliability *rel; | ||
2716 | // struct MeshFlowControl *next_fc; | ||
2717 | // struct MeshFlowControl *prev_fc; | ||
2718 | // struct MeshClient *c; | ||
2719 | // struct MeshClient *o; | ||
2720 | // GNUNET_PEER_Id hop; | ||
2721 | // uint32_t delta_mid; | ||
2722 | // uint32_t ack; | ||
2723 | // int delta; | ||
2724 | // | ||
2725 | // rel = fwd ? ch->fwd_rel : ch->bck_rel; | ||
2726 | // c = fwd ? ch->client : ch->owner; | ||
2727 | // o = fwd ? ch->owner : ch->client; | ||
2728 | // hop = fwd ? connection_get_prev_hop (cn) : connection_get_next_hop (cn); | ||
2729 | // next_fc = fwd ? &t->next_fc : &t->prev_fc; | ||
2730 | // prev_fc = fwd ? &t->prev_fc : &t->next_fc; | ||
2731 | // | ||
2732 | // switch (type) | ||
2733 | // { | ||
2734 | // case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
2735 | // case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
2736 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2737 | // "ACK due to %s\n", | ||
2738 | // GNUNET_MESH_DEBUG_M2S (type)); | ||
2739 | // if (GNUNET_YES == t->nobuffer && (GNUNET_NO == t->reliable || NULL == c)) | ||
2740 | // { | ||
2741 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, nobuffer\n"); | ||
2742 | // return; | ||
2743 | // } | ||
2744 | // if (GNUNET_YES == t->reliable && NULL != c) | ||
2745 | // tunnel_send_data_ack (t, fwd); | ||
2746 | // break; | ||
2747 | // case GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK: | ||
2748 | // case GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK: | ||
2749 | // case GNUNET_MESSAGE_TYPE_MESH_ACK: | ||
2750 | // case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK: | ||
2751 | // break; | ||
2752 | // case GNUNET_MESSAGE_TYPE_MESH_POLL: | ||
2753 | // case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK: | ||
2754 | // t->force_ack = GNUNET_YES; | ||
2755 | // break; | ||
2756 | // default: | ||
2757 | // GNUNET_break (0); | ||
2758 | // } | ||
2759 | // | ||
2760 | // /* Check if we need to transmit the ACK */ | ||
2761 | // if (NULL == o && | ||
2762 | // prev_fc->last_ack_sent - prev_fc->last_pid_recv > 3 && | ||
2763 | // GNUNET_NO == t->force_ack) | ||
2764 | // { | ||
2765 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer free\n"); | ||
2766 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2767 | // " last pid recv: %u, last ack sent: %u\n", | ||
2768 | // prev_fc->last_pid_recv, prev_fc->last_ack_sent); | ||
2769 | // return; | ||
2770 | // } | ||
2771 | // | ||
2772 | // /* Ok, ACK might be necessary, what PID to ACK? */ | ||
2773 | // delta = t->queue_max - next_fc->queue_n; | ||
2774 | // if (NULL != o && GNUNET_YES == t->reliable && NULL != rel->head_sent) | ||
2775 | // delta_mid = rel->mid_sent - rel->head_sent->mid; | ||
2776 | // else | ||
2777 | // delta_mid = 0; | ||
2778 | // if (0 > delta || (GNUNET_YES == t->reliable && | ||
2779 | // NULL != o && | ||
2780 | // (10 < rel->n_sent || 64 <= delta_mid))) | ||
2781 | // delta = 0; | ||
2782 | // if (NULL != o && delta > 1) | ||
2783 | // delta = 1; | ||
2784 | // ack = prev_fc->last_pid_recv + delta; | ||
2785 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack); | ||
2786 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2787 | // " last pid %u, last ack %u, qmax %u, q %u\n", | ||
2788 | // prev_fc->last_pid_recv, prev_fc->last_ack_sent, | ||
2789 | // t->queue_max, next_fc->queue_n); | ||
2790 | // if (ack == prev_fc->last_ack_sent && GNUNET_NO == t->force_ack) | ||
2791 | // { | ||
2792 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, not needed\n"); | ||
2793 | // return; | ||
2794 | // } | ||
2795 | // | ||
2796 | // prev_fc->last_ack_sent = ack; | ||
2797 | // if (NULL != o) | ||
2798 | // send_local_ack (t, o, fwd); | ||
2799 | // else if (0 != hop) | ||
2800 | // send_ack (t, hop, ack); | ||
2801 | // else | ||
2802 | // GNUNET_break (GNUNET_YES == t->destroy); | ||
2803 | // t->force_ack = GNUNET_NO; | ||
2804 | // } | ||
2805 | |||
2806 | |||
2807 | /** | ||
2756 | * Modify the mesh message TID from global to local and send to client. | 2808 | * Modify the mesh message TID from global to local and send to client. |
2757 | * | 2809 | * |
2758 | * @param t Tunnel on which to send the message. | 2810 | * @param ch Channel on which to send the message. |
2759 | * @param msg Message to modify and send. | 2811 | * @param msg Message to modify and send. |
2760 | * @param c Client to send to. | 2812 | * @param c Client to send to. |
2761 | * @param tid Tunnel ID to use (c can be both owner and client). | 2813 | * @param tid Tunnel ID to use (c can be both owner and client). |
2762 | */ | 2814 | */ |
2763 | static void | 2815 | static void |
2764 | tunnel_send_client_to_tid (struct MeshTunnel *t, | 2816 | channel_send_client_to_tid (struct MeshChannel *ch, |
2765 | const struct GNUNET_MESH_Data *msg, | 2817 | const struct GNUNET_MESH_Data *msg, |
2766 | struct MeshClient *c, MESH_ChannelNumber tid) | 2818 | struct MeshClient *c, MESH_ChannelNumber id) |
2767 | { | 2819 | { |
2768 | struct GNUNET_MESH_LocalData *copy; | 2820 | struct GNUNET_MESH_LocalData *copy; |
2769 | uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_MESH_Data); | 2821 | uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_MESH_Data); |
@@ -2783,27 +2835,27 @@ tunnel_send_client_to_tid (struct MeshTunnel *t, | |||
2783 | memcpy (©[1], &msg[1], size); | 2835 | memcpy (©[1], &msg[1], size); |
2784 | copy->header.size = htons (sizeof (struct GNUNET_MESH_LocalData) + size); | 2836 | copy->header.size = htons (sizeof (struct GNUNET_MESH_LocalData) + size); |
2785 | copy->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA); | 2837 | copy->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA); |
2786 | copy->tid = htonl (tid); | 2838 | copy->id = htonl (id); |
2787 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, | 2839 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, |
2788 | ©->header, GNUNET_NO); | 2840 | ©->header, GNUNET_NO); |
2789 | } | 2841 | } |
2790 | 2842 | ||
2791 | /** | 2843 | /** |
2792 | * Modify the unicast message TID from global to local and send to client. | 2844 | * Modify the data message ID from global to local and send to client. |
2793 | * | 2845 | * |
2794 | * @param t Tunnel on which to send the message. | 2846 | * @param ch Channel on which to send the message. |
2795 | * @param msg Message to modify and send. | 2847 | * @param msg Message to modify and send. |
2796 | * @param fwd Forward? | 2848 | * @param fwd Forward? |
2797 | */ | 2849 | */ |
2798 | static void | 2850 | static void |
2799 | tunnel_send_client_data (struct MeshTunnel *t, | 2851 | channel_send_client_data (struct MeshChannel *ch, |
2800 | const struct GNUNET_MESH_Data *msg, | 2852 | const struct GNUNET_MESH_Data *msg, |
2801 | int fwd) | 2853 | int fwd) |
2802 | { | 2854 | { |
2803 | if (fwd) | 2855 | if (fwd) |
2804 | tunnel_send_client_to_tid (t, msg, t->client, t->local_tid_dest); | 2856 | channel_send_client_to_tid (ch, msg, ch->client, ch->id_dest); |
2805 | else | 2857 | else |
2806 | tunnel_send_client_to_tid (t, msg, t->owner, t->local_tid); | 2858 | channel_send_client_to_tid (ch, msg, ch->owner, ch->id); |
2807 | } | 2859 | } |
2808 | 2860 | ||
2809 | 2861 | ||
diff --git a/src/mesh/mesh_enc.h b/src/mesh/mesh_enc.h index f8db74c7e..42cd22890 100644 --- a/src/mesh/mesh_enc.h +++ b/src/mesh/mesh_enc.h | |||
@@ -135,9 +135,9 @@ struct GNUNET_MESH_LocalData | |||
135 | struct GNUNET_MessageHeader header; | 135 | struct GNUNET_MessageHeader header; |
136 | 136 | ||
137 | /** | 137 | /** |
138 | * TID of the channel | 138 | * ID of the channel |
139 | */ | 139 | */ |
140 | uint32_t tid GNUNET_PACKED; | 140 | uint32_t id GNUNET_PACKED; |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * Payload follows | 143 | * Payload follows |
diff --git a/src/mesh/mesh_protocol_enc.h b/src/mesh/mesh_protocol_enc.h index cb3f6e719..547ae89fc 100644 --- a/src/mesh/mesh_protocol_enc.h +++ b/src/mesh/mesh_protocol_enc.h | |||
@@ -175,7 +175,7 @@ struct GNUNET_MESH_ACK | |||
175 | /** | 175 | /** |
176 | * Maximum packet ID authorized. | 176 | * Maximum packet ID authorized. |
177 | */ | 177 | */ |
178 | uint32_t pid GNUNET_PACKED; | 178 | uint32_t ack GNUNET_PACKED; |
179 | 179 | ||
180 | /** | 180 | /** |
181 | * OID of the tunnel | 181 | * OID of the tunnel |