diff options
Diffstat (limited to 'src/mesh/gnunet-service-mesh_tunnel.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh_tunnel.c | 126 |
1 files changed, 73 insertions, 53 deletions
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index 62545b35c..8a240f4a8 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c | |||
@@ -290,58 +290,6 @@ tunnel_get_connection (struct MeshTunnel3 *t, int fwd) | |||
290 | 290 | ||
291 | 291 | ||
292 | /** | 292 | /** |
293 | * Get the total buffer space for a tunnel. | ||
294 | * | ||
295 | * @param t Tunnel. | ||
296 | * @param fwd Is this for FWD traffic? | ||
297 | * | ||
298 | * @return Buffer space offered by all connections in the tunnel. | ||
299 | */ | ||
300 | static unsigned int | ||
301 | tunnel_get_buffer (struct MeshTunnel3 *t, int fwd) | ||
302 | { | ||
303 | struct MeshTConnection *iter; | ||
304 | unsigned int buffer; | ||
305 | |||
306 | iter = t->connection_head; | ||
307 | buffer = 0; | ||
308 | |||
309 | /* If terminal, return biggest channel buffer */ | ||
310 | if (NULL == iter || GMC_is_terminal (iter->c, fwd)) | ||
311 | { | ||
312 | struct MeshTChannel *iter_ch; | ||
313 | unsigned int ch_buf; | ||
314 | |||
315 | if (NULL == t->channel_head) | ||
316 | return 64; | ||
317 | |||
318 | for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = iter_ch->next) | ||
319 | { | ||
320 | ch_buf = GMCH_get_buffer (iter_ch->ch, fwd); | ||
321 | if (ch_buf > buffer) | ||
322 | buffer = ch_buf; | ||
323 | } | ||
324 | return buffer; | ||
325 | } | ||
326 | |||
327 | /* If not terminal, return sum of connection buffers */ | ||
328 | while (NULL != iter) | ||
329 | { | ||
330 | if (GMC_get_state (iter->c) != MESH_CONNECTION_READY) | ||
331 | { | ||
332 | iter = iter->next; | ||
333 | continue; | ||
334 | } | ||
335 | |||
336 | buffer += GMC_get_buffer (iter->c, fwd); | ||
337 | iter = iter->next; | ||
338 | } | ||
339 | |||
340 | return buffer; | ||
341 | } | ||
342 | |||
343 | |||
344 | /** | ||
345 | * Send all cached messages that we can, tunnel is online. | 293 | * Send all cached messages that we can, tunnel is online. |
346 | * | 294 | * |
347 | * @param t Tunnel that holds the messages. | 295 | * @param t Tunnel that holds the messages. |
@@ -357,7 +305,7 @@ tunnel_send_queued_data (struct MeshTunnel3 *t, int fwd) | |||
357 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 305 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
358 | "tunnel_send_queued_data on tunnel %s\n", | 306 | "tunnel_send_queued_data on tunnel %s\n", |
359 | GMP_2s (t->peer)); | 307 | GMP_2s (t->peer)); |
360 | room = tunnel_get_buffer (t, fwd); | 308 | room = GMT_get_buffer (t, fwd); |
361 | LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer space: %u\n", room); | 309 | LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer space: %u\n", room); |
362 | for (tq = t->tq_head; NULL != tq && room > 0; tq = next) | 310 | for (tq = t->tq_head; NULL != tq && room > 0; tq = next) |
363 | { | 311 | { |
@@ -741,6 +689,27 @@ GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c) | |||
741 | 689 | ||
742 | 690 | ||
743 | /** | 691 | /** |
692 | * Remove a connection from a tunnel. | ||
693 | * | ||
694 | * @param t Tunnel. | ||
695 | * @param c Connection. | ||
696 | */ | ||
697 | void | ||
698 | GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c) | ||
699 | { | ||
700 | struct MeshTConnection *aux; | ||
701 | |||
702 | for (aux = t->connection_head; aux != NULL; aux = aux->next) | ||
703 | if (aux->c == c) | ||
704 | { | ||
705 | GNUNET_CONTAINER_DLL_remove (t->connection_head, t->connection_tail, aux); | ||
706 | GNUNET_free (aux); | ||
707 | return; | ||
708 | } | ||
709 | } | ||
710 | |||
711 | |||
712 | /** | ||
744 | * Tunnel is empty: destroy it. | 713 | * Tunnel is empty: destroy it. |
745 | * | 714 | * |
746 | * Notifies all connections about the destruction. | 715 | * Notifies all connections about the destruction. |
@@ -983,6 +952,57 @@ GMT_count_channels (struct MeshTunnel3 *t) | |||
983 | 952 | ||
984 | 953 | ||
985 | /** | 954 | /** |
955 | * Get the total buffer space for a tunnel. | ||
956 | * | ||
957 | * @param t Tunnel. | ||
958 | * @param fwd Is this for FWD traffic? | ||
959 | * | ||
960 | * @return Buffer space offered by all connections in the tunnel. | ||
961 | */ | ||
962 | unsigned int | ||
963 | GMT_get_buffer (struct MeshTunnel3 *t, int fwd) | ||
964 | { | ||
965 | struct MeshTConnection *iter; | ||
966 | unsigned int buffer; | ||
967 | |||
968 | iter = t->connection_head; | ||
969 | buffer = 0; | ||
970 | |||
971 | /* If terminal, return biggest channel buffer */ | ||
972 | if (NULL == iter || GMC_is_terminal (iter->c, fwd)) | ||
973 | { | ||
974 | struct MeshTChannel *iter_ch; | ||
975 | unsigned int ch_buf; | ||
976 | |||
977 | if (NULL == t->channel_head) | ||
978 | return 64; | ||
979 | |||
980 | for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = iter_ch->next) | ||
981 | { | ||
982 | ch_buf = GMCH_get_buffer (iter_ch->ch, fwd); | ||
983 | if (ch_buf > buffer) | ||
984 | buffer = ch_buf; | ||
985 | } | ||
986 | return buffer; | ||
987 | } | ||
988 | |||
989 | /* If not terminal, return sum of connection buffers */ | ||
990 | while (NULL != iter) | ||
991 | { | ||
992 | if (GMC_get_state (iter->c) != MESH_CONNECTION_READY) | ||
993 | { | ||
994 | iter = iter->next; | ||
995 | continue; | ||
996 | } | ||
997 | |||
998 | buffer += GMC_get_buffer (iter->c, fwd); | ||
999 | iter = iter->next; | ||
1000 | } | ||
1001 | |||
1002 | return buffer; | ||
1003 | } | ||
1004 | |||
1005 | /** | ||
986 | * Sends an already built message on a tunnel, choosing the best connection. | 1006 | * Sends an already built message on a tunnel, choosing the best connection. |
987 | * | 1007 | * |
988 | * @param message Message to send. Function modifies it. | 1008 | * @param message Message to send. Function modifies it. |