diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-10-11 15:20:28 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-10-11 15:20:28 +0000 |
commit | a85261acba2c59241458bff597db815de85fa771 (patch) | |
tree | 5308aa2c244b8a62011cb7a0ef1f5f30a96aeb64 /src/mesh | |
parent | 03b222dc177798ed9448cdeca67ba4051c6397e3 (diff) | |
download | gnunet-a85261acba2c59241458bff597db815de85fa771.tar.gz gnunet-a85261acba2c59241458bff597db815de85fa771.zip |
- backport
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh_connection.c | 34 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_connection.h | 11 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_tunnel.c | 63 |
3 files changed, 103 insertions, 5 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index 910b5f1f3..94813adf2 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c | |||
@@ -520,8 +520,8 @@ connection_send_ack (struct MeshConnection *c, unsigned int buffer, int fwd) | |||
520 | { | 520 | { |
521 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer > 3\n"); | 521 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer > 3\n"); |
522 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 522 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
523 | " last pid recv: %u, last ack sent: %u\n", | 523 | " last pid recv: %u, last ack sent: %u\n", |
524 | prev_fc->last_pid_recv, prev_fc->last_ack_sent); | 524 | prev_fc->last_pid_recv, prev_fc->last_ack_sent); |
525 | return; | 525 | return; |
526 | } | 526 | } |
527 | 527 | ||
@@ -530,9 +530,9 @@ connection_send_ack (struct MeshConnection *c, unsigned int buffer, int fwd) | |||
530 | ack = prev_fc->last_pid_recv + delta; | 530 | ack = prev_fc->last_pid_recv + delta; |
531 | LOG (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack); | 531 | LOG (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack); |
532 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 532 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
533 | " last pid %u, last ack %u, qmax %u, q %u\n", | 533 | " last pid %u, last ack %u, qmax %u, q %u\n", |
534 | prev_fc->last_pid_recv, prev_fc->last_ack_sent, | 534 | prev_fc->last_pid_recv, prev_fc->last_ack_sent, |
535 | next_fc->queue_max, next_fc->queue_n); | 535 | next_fc->queue_max, next_fc->queue_n); |
536 | if (ack == prev_fc->last_ack_sent) | 536 | if (ack == prev_fc->last_ack_sent) |
537 | { | 537 | { |
538 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, not needed\n"); | 538 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, not needed\n"); |
@@ -1663,6 +1663,8 @@ GMC_send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd) | |||
1663 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1663 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1664 | "send ack %s on %p %p\n", | 1664 | "send ack %s on %p %p\n", |
1665 | fwd ? "FWD" : "BCK", c, ch); | 1665 | fwd ? "FWD" : "BCK", c, ch); |
1666 | |||
1667 | /* Get available bufffer space */ | ||
1666 | if (NULL == c || GMC_is_terminal (c, fwd)) | 1668 | if (NULL == c || GMC_is_terminal (c, fwd)) |
1667 | { | 1669 | { |
1668 | struct MeshTunnel3 *t; | 1670 | struct MeshTunnel3 *t; |
@@ -1677,6 +1679,7 @@ GMC_send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd) | |||
1677 | } | 1679 | } |
1678 | LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer available: %u\n", buffer); | 1680 | LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer available: %u\n", buffer); |
1679 | 1681 | ||
1682 | /* Send available buffer space */ | ||
1680 | if ( (NULL != ch && GMCH_is_origin (ch, fwd)) || | 1683 | if ( (NULL != ch && GMCH_is_origin (ch, fwd)) || |
1681 | (NULL != c && GMC_is_origin (c, fwd)) ) | 1684 | (NULL != c && GMC_is_origin (c, fwd)) ) |
1682 | { | 1685 | { |
@@ -1891,6 +1894,27 @@ GMC_get_buffer (struct MeshConnection *c, int fwd) | |||
1891 | } | 1894 | } |
1892 | 1895 | ||
1893 | /** | 1896 | /** |
1897 | * Get how many messages have we allowed to send to us from a direction.. | ||
1898 | * | ||
1899 | * @param c Connection. | ||
1900 | * @param fwd Are we asking about traffic from FWD (BCK messages)? | ||
1901 | * | ||
1902 | * @return last_ack_sent - last_pid_recv | ||
1903 | */ | ||
1904 | unsigned int | ||
1905 | GMC_get_allowed (struct MeshConnection *c, int fwd) | ||
1906 | { | ||
1907 | struct MeshFlowControl *fc; | ||
1908 | |||
1909 | fc = fwd ? &c->fwd_fc : &c->bck_fc; | ||
1910 | if (GMC_is_pid_bigger(fc->last_pid_recv, fc->last_ack_sent)) | ||
1911 | { | ||
1912 | return 0; | ||
1913 | } | ||
1914 | return (fc->last_ack_sent - fc->last_pid_recv); | ||
1915 | } | ||
1916 | |||
1917 | /** | ||
1894 | * Get messages queued in a connection. | 1918 | * Get messages queued in a connection. |
1895 | * | 1919 | * |
1896 | * @param c Connection. | 1920 | * @param c Connection. |
diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h index b55d55fe6..a617054ff 100644 --- a/src/mesh/gnunet-service-mesh_connection.h +++ b/src/mesh/gnunet-service-mesh_connection.h | |||
@@ -306,6 +306,17 @@ unsigned int | |||
306 | GMC_get_buffer (struct MeshConnection *c, int fwd); | 306 | GMC_get_buffer (struct MeshConnection *c, int fwd); |
307 | 307 | ||
308 | /** | 308 | /** |
309 | * Get how many messages have we allowed to send to us from a direction.. | ||
310 | * | ||
311 | * @param c Connection. | ||
312 | * @param fwd Are we asking about traffic from FWD (BCK messages)? | ||
313 | * | ||
314 | * @return last_ack_sent - last_pid_recv | ||
315 | */ | ||
316 | unsigned int | ||
317 | GMC_get_allowed (struct MeshConnection *c, int fwd); | ||
318 | |||
319 | /** | ||
309 | * Get messages queued in a connection. | 320 | * Get messages queued in a connection. |
310 | * | 321 | * |
311 | * @param c Connection. | 322 | * @param c Connection. |
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index 9a25db089..105317501 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c | |||
@@ -1018,7 +1018,10 @@ GMT_get_buffer (struct MeshTunnel3 *t, int fwd) | |||
1018 | unsigned int ch_buf; | 1018 | unsigned int ch_buf; |
1019 | 1019 | ||
1020 | if (NULL == t->channel_head) | 1020 | if (NULL == t->channel_head) |
1021 | { | ||
1022 | /* Probably getting buffer for a channel create. */ | ||
1021 | return 64; | 1023 | return 64; |
1024 | } | ||
1022 | 1025 | ||
1023 | for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = iter_ch->next) | 1026 | for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = iter_ch->next) |
1024 | { | 1027 | { |
@@ -1085,6 +1088,66 @@ GMT_get_next_chid (struct MeshTunnel3 *t) | |||
1085 | 1088 | ||
1086 | 1089 | ||
1087 | /** | 1090 | /** |
1091 | * Send ACK on one or more connections due to buffer space to the client. | ||
1092 | * | ||
1093 | * Iterates all connections of the tunnel and sends ACKs appropriately. | ||
1094 | * | ||
1095 | * @param ch Channel which has some free buffer space. | ||
1096 | * @param fwd Is this in for FWD traffic? (ACK goes dest->root) | ||
1097 | */ | ||
1098 | static void | ||
1099 | GMT_send_acks (struct MeshTunnel3 *t, | ||
1100 | unsigned int buffer, | ||
1101 | int fwd) | ||
1102 | { | ||
1103 | struct MeshTConnection *iter; | ||
1104 | uint32_t allowed; | ||
1105 | uint32_t to_allow; | ||
1106 | uint32_t allow_per_connection; | ||
1107 | unsigned int cs; | ||
1108 | |||
1109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1110 | "Tunnel send acks on %s:%X\n", | ||
1111 | fwd ? "FWD" : "BCK", peer2s (ch->t->peer), ch->gid); | ||
1112 | |||
1113 | /* Count connections, how many messages are already allowed */ | ||
1114 | cs = GMT_count_connections (t); | ||
1115 | for (allowed = 0, iter = t->connection_head; NULL != iter; iter = iter->next) | ||
1116 | { | ||
1117 | allowed += GMC_get_allowed (iter->c, fwd); | ||
1118 | } | ||
1119 | |||
1120 | /* Make sure there is no overflow */ | ||
1121 | if (allowed > buffer) | ||
1122 | { | ||
1123 | GNUNET_break (0); | ||
1124 | return; | ||
1125 | } | ||
1126 | |||
1127 | /* Authorize connections to send more data */ | ||
1128 | to_allow = buffer - allowed; | ||
1129 | |||
1130 | for (iter = t->connection_head; NULL != iter && to_allow > 0; iter = iter->next) | ||
1131 | { | ||
1132 | allow_per_connection = to_allow/cs; | ||
1133 | to_allow -= allow_per_connection; | ||
1134 | cs--; | ||
1135 | if (GMC_get_allowed (iter->c, fwd) > 64 / 3) | ||
1136 | { | ||
1137 | continue; | ||
1138 | } | ||
1139 | GMC_send_ack (iter->c, NULL, fwd); | ||
1140 | connection_send_ack (iter, allow_per_connection, fwd); | ||
1141 | } | ||
1142 | |||
1143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1144 | "Channel send connection %s ack on %s:%X\n", | ||
1145 | fwd ? "FWD" : "BCK", peer2s (ch->t->peer), ch->gid); | ||
1146 | GNUNET_break (to_allow == 0); | ||
1147 | } | ||
1148 | |||
1149 | |||
1150 | /** | ||
1088 | * Sends an already built message on a tunnel, GMT_encrypting it and | 1151 | * Sends an already built message on a tunnel, GMT_encrypting it and |
1089 | * choosing the best connection. | 1152 | * choosing the best connection. |
1090 | * | 1153 | * |