aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh_tunnel.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-18 02:23:43 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-18 02:23:43 +0000
commit28653a4922fd5a2d8fb7f72d799c9e79a2400abe (patch)
tree6512c6305a85783ff40fef1b4a405084a44cc98a /src/mesh/gnunet-service-mesh_tunnel.c
parentb77d61f1ee16dca21c147e09623abe9c121667b7 (diff)
downloadgnunet-28653a4922fd5a2d8fb7f72d799c9e79a2400abe.tar.gz
gnunet-28653a4922fd5a2d8fb7f72d799c9e79a2400abe.zip
- flow control changes and fixes
Diffstat (limited to 'src/mesh/gnunet-service-mesh_tunnel.c')
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.c71
1 files changed, 65 insertions, 6 deletions
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c
index 89c9a9db1..5b0573d0a 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.c
+++ b/src/mesh/gnunet-service-mesh_tunnel.c
@@ -984,7 +984,7 @@ GMT_count_channels (struct MeshTunnel3 *t)
984 984
985 for (count = 0, iter = t->channel_head; 985 for (count = 0, iter = t->channel_head;
986 NULL != iter; 986 NULL != iter;
987 iter = iter->next, count++); 987 iter = iter->next, count++) /* skip */;
988 988
989 return count; 989 return count;
990} 990}
@@ -1008,10 +1008,13 @@ GMT_get_state (struct MeshTunnel3 *t)
1008/** 1008/**
1009 * Get the total buffer space for a tunnel. 1009 * Get the total buffer space for a tunnel.
1010 * 1010 *
1011 * If terminal, use the biggest channel buffer (or 64) if no channel exists.
1012 * If not terminal, use the sum of all connection buffers.
1013 *
1011 * @param t Tunnel. 1014 * @param t Tunnel.
1012 * @param fwd Is this for FWD traffic? 1015 * @param fwd Is this for FWD traffic?
1013 * 1016 *
1014 * @return Buffer space offered by all connections in the tunnel. 1017 * @return Buffer space offered by all entities (c/ch) in the tunnel.
1015 */ 1018 */
1016unsigned int 1019unsigned int
1017GMT_get_buffer (struct MeshTunnel3 *t, int fwd) 1020GMT_get_buffer (struct MeshTunnel3 *t, int fwd)
@@ -1030,7 +1033,7 @@ GMT_get_buffer (struct MeshTunnel3 *t, int fwd)
1030 1033
1031 if (NULL == t->channel_head) 1034 if (NULL == t->channel_head)
1032 { 1035 {
1033 /* Probably getting buffer for a channel create. */ 1036 /* Probably getting buffer for a channel create/handshake. */
1034 return 64; 1037 return 64;
1035 } 1038 }
1036 1039
@@ -1099,24 +1102,78 @@ GMT_get_next_chid (struct MeshTunnel3 *t)
1099 1102
1100 1103
1101/** 1104/**
1105 * Send ACK on one or more channels due to buffer in connections..
1106 *
1107 * @param t Channel which has some free buffer space.
1108 * @param fwd Is this for FWD traffic? (ACK goes to root)
1109 */
1110void
1111GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd)
1112{
1113 struct MeshTChannel *iter;
1114 unsigned int buffer;
1115 unsigned int channels = GMT_count_channels (t);
1116 unsigned int choked_n;
1117 struct MeshChannel *choked[channels];
1118
1119 LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT_unchoke_channels on %s\n", GMT_2s (t));
1120
1121 if (NULL == t)
1122 {
1123 GNUNET_break (0);
1124 return;
1125 }
1126
1127 /* Get buffer space */
1128 buffer = GMT_get_buffer (t, fwd);
1129 if (0 == buffer)
1130 {
1131 return;
1132 }
1133
1134 /* Count and remember choked channels */
1135 choked_n = 0;
1136 for (iter = t->channel_head; NULL != iter; iter = iter->next)
1137 {
1138 if (GNUNET_NO == GMCH_get_allowed (iter->ch, fwd))
1139 {
1140 choked[choked_n++] = iter->ch;
1141 }
1142 }
1143
1144 /* Unchoke random channels */
1145 while (0 < buffer && 0 < choked_n)
1146 {
1147 unsigned int r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1148 choked_n);
1149 GMCH_allow_client (choked[r], fwd);
1150 choked_n--;
1151 buffer--;
1152 choked[r] = choked[choked_n];
1153 }
1154}
1155
1156
1157/**
1102 * Send ACK on one or more connections due to buffer space to the client. 1158 * Send ACK on one or more connections due to buffer space to the client.
1103 * 1159 *
1104 * Iterates all connections of the tunnel and sends ACKs appropriately. 1160 * Iterates all connections of the tunnel and sends ACKs appropriately.
1105 * 1161 *
1106 * @param ch Channel which has some free buffer space. 1162 * @param t Tunnel.
1107 * @param fwd Is this in for FWD traffic? (ACK goes dest->root) 1163 * @param fwd Is this in for FWD traffic? (ACK goes dest->root)
1108 */ 1164 */
1109void 1165void
1110GMT_send_acks (struct MeshTunnel3 *t, unsigned int buffer, int fwd) 1166GMT_send_acks (struct MeshTunnel3 *t, int fwd)
1111{ 1167{
1112 struct MeshTConnection *iter; 1168 struct MeshTConnection *iter;
1113 uint32_t allowed; 1169 uint32_t allowed;
1114 uint32_t to_allow; 1170 uint32_t to_allow;
1115 uint32_t allow_per_connection; 1171 uint32_t allow_per_connection;
1116 unsigned int cs; 1172 unsigned int cs;
1173 unsigned int buffer;
1117 1174
1118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1119 "Tunnel send acks on %s:%X\n", 1176 "Tunnel send %s ACKs on %s\n",
1120 fwd ? "FWD" : "BCK", GMT_2s (t)); 1177 fwd ? "FWD" : "BCK", GMT_2s (t));
1121 1178
1122 if (NULL == t) 1179 if (NULL == t)
@@ -1131,6 +1188,8 @@ GMT_send_acks (struct MeshTunnel3 *t, unsigned int buffer, int fwd)
1131 return; 1188 return;
1132 } 1189 }
1133 1190
1191 buffer = GMT_get_buffer (t, fwd);
1192
1134 /* Count connections, how many messages are already allowed */ 1193 /* Count connections, how many messages are already allowed */
1135 cs = GMT_count_connections (t); 1194 cs = GMT_count_connections (t);
1136 for (allowed = 0, iter = t->connection_head; NULL != iter; iter = iter->next) 1195 for (allowed = 0, iter = t->connection_head; NULL != iter; iter = iter->next)