aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-10 18:00:27 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-10 18:00:27 +0000
commit1295876120a61a26b35473a83162ed0e1e6aaf6c (patch)
tree81e4957a522f2e8cb3d6a3e8b8c6969bd7dfc11a /src/mesh
parentbcc10bd6c81aeeac68019bdc2b557b81fa31d369 (diff)
downloadgnunet-1295876120a61a26b35473a83162ed0e1e6aaf6c.tar.gz
gnunet-1295876120a61a26b35473a83162ed0e1e6aaf6c.zip
- fix queueing
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c35
-rw-r--r--src/mesh/gnunet-service-mesh_connection.h10
-rw-r--r--src/mesh/gnunet-service-mesh_peer.c305
-rw-r--r--src/mesh/gnunet-service-mesh_peer.h7
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.c21
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.h11
6 files changed, 207 insertions, 182 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c
index 63e4b8bd0..e9e16293a 100644
--- a/src/mesh/gnunet-service-mesh_connection.c
+++ b/src/mesh/gnunet-service-mesh_connection.c
@@ -401,6 +401,27 @@ message_sent (void *cls,
401 LOG (GNUNET_ERROR_TYPE_DEBUG, "! destroying connection!\n"); 401 LOG (GNUNET_ERROR_TYPE_DEBUG, "! destroying connection!\n");
402 GMC_destroy (c); 402 GMC_destroy (c);
403 } 403 }
404 /* Send ACK if needed, after accounting for sent ID in fc->queue_n */
405 switch (type)
406 {
407 case GNUNET_MESSAGE_TYPE_MESH_FWD:
408 case GNUNET_MESSAGE_TYPE_MESH_BCK:
409 fc->last_pid_sent++;
410 LOG (GNUNET_ERROR_TYPE_DEBUG, "! accounting pid %u\n", fc->last_pid_sent);
411// send_ack (c, ch, fwd);
412 break;
413 default:
414 break;
415 }
416// if (NULL != c->t)
417// {
418// c->t->pending_messages--;
419// if (GNUNET_YES == c->t->destroy && 0 == t->pending_messages)
420// {
421// LOG (GNUNET_ERROR_TYPE_DEBUG, "* destroying tunnel!\n");
422// GMT_destroy (c->t);
423// }
424// }
404} 425}
405 426
406 427
@@ -1776,6 +1797,20 @@ GMC_get_id (const struct MeshConnection *c)
1776 1797
1777 1798
1778/** 1799/**
1800 * Get the connection path.
1801 *
1802 * @param c Connection to get the path from.
1803 *
1804 * @return path used by the connection.
1805 */
1806const struct MeshPeerPath *
1807GMC_get_path (const struct MeshConnection *c)
1808{
1809 return c->path;
1810}
1811
1812
1813/**
1779 * Get the connection state. 1814 * Get the connection state.
1780 * 1815 *
1781 * @param c Connection to get the state from. 1816 * @param c Connection to get the state from.
diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h
index 131bd9dc2..b0ddeabd9 100644
--- a/src/mesh/gnunet-service-mesh_connection.h
+++ b/src/mesh/gnunet-service-mesh_connection.h
@@ -264,6 +264,16 @@ const struct GNUNET_HashCode *
264GMC_get_id (const struct MeshConnection *c); 264GMC_get_id (const struct MeshConnection *c);
265 265
266/** 266/**
267 * Get the connection path.
268 *
269 * @param c Connection to get the path from.
270 *
271 * @return path used by the connection.
272 */
273const struct MeshPeerPath *
274GMC_get_path (const struct MeshConnection *c);
275
276/**
267 * Get the connection state. 277 * Get the connection state.
268 * 278 *
269 * @param c Connection to get the state from. 279 * @param c Connection to get the state from.
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c
index f997cf838..2bba99319 100644
--- a/src/mesh/gnunet-service-mesh_peer.c
+++ b/src/mesh/gnunet-service-mesh_peer.c
@@ -699,7 +699,6 @@ peer_get_best_path (const struct MeshPeer *peer)
699{ 699{
700 struct MeshPeerPath *best_p; 700 struct MeshPeerPath *best_p;
701 struct MeshPeerPath *p; 701 struct MeshPeerPath *p;
702 struct MeshConnection *c;
703 unsigned int best_cost; 702 unsigned int best_cost;
704 unsigned int cost; 703 unsigned int cost;
705 704
@@ -707,19 +706,56 @@ peer_get_best_path (const struct MeshPeer *peer)
707 best_p = NULL; 706 best_p = NULL;
708 for (p = peer->path_head; NULL != p; p = p->next) 707 for (p = peer->path_head; NULL != p; p = p->next)
709 { 708 {
710 for (c = peer->tunnel->connection_head; NULL != c; c = c->next) 709 if (GNUNET_YES == GMT_is_path_used (peer->tunnel, p))
711 if (c->path == p) 710 continue; /* If path is already in use, skip it. */
712 break; 711
713 if (NULL != c) 712 if ((cost = peer_get_path_cost (peer, p)) < best_cost)
714 continue; /* If path is in use in a connection, skip it. */ 713 {
715 714 best_cost = cost;
716 if ((cost = peer_get_path_cost (peer, p)) < best_cost) 715 best_p = p;
717 { 716 }
718 best_cost = cost; 717 }
719 best_p = p; 718 return best_p;
720 } 719}
720
721
722static int
723queue_is_sendable (struct MeshPeerQueue *q)
724{
725 /* Is PID-independent? */
726 switch (q->type)
727 {
728 case GNUNET_MESSAGE_TYPE_MESH_ACK:
729 case GNUNET_MESSAGE_TYPE_MESH_POLL:
730 return GNUNET_YES;
721 } 731 }
722 return best_p; 732
733 if (GMC_is_sendable (q->c, q->fwd))
734 return GNUNET_YES;
735
736 return GNUNET_NO;
737}
738
739
740/**
741 * Get first sendable message.
742 *
743 * @param peer The destination peer.
744 *
745 * @return Best current known path towards the peer, if any.
746 */
747static struct MeshPeerQueue *
748peer_get_first_message (const struct MeshPeer *peer)
749{
750 struct MeshPeerQueue *q;
751
752 for (q = peer->queue_head; NULL != q; q = q->next)
753 {
754 if (queue_is_sendable (q))
755 return q;
756 }
757
758 return NULL;
723} 759}
724 760
725 761
@@ -737,16 +773,16 @@ search_handler (void *cls, const struct MeshPeerPath *path)
737 struct MeshPeer *peer = cls; 773 struct MeshPeer *peer = cls;
738 unsigned int connection_count; 774 unsigned int connection_count;
739 775
740 path_add_to_peers (path, GNUNET_NO); 776 GMP_add_path_to_all (path, GNUNET_NO);
741 777
742 /* Count connections */ 778 /* Count connections */
743 connection_count = GMC_count (peer->tunnel->connection_head); 779 connection_count = GMT_count_connections (peer->tunnel);
744 780
745 /* If we already have 3 (or more (?!)) connections, it's enough */ 781 /* If we already have 3 (or more (?!)) connections, it's enough */
746 if (3 <= connection_count) 782 if (3 <= connection_count)
747 return; 783 return;
748 784
749 if (peer->tunnel->state == MESH_TUNNEL3_SEARCHING) 785 if (MESH_TUNNEL3_SEARCHING == GMT_get_state (peer->tunnel))
750 { 786 {
751 LOG (GNUNET_ERROR_TYPE_DEBUG, " ... connect!\n"); 787 LOG (GNUNET_ERROR_TYPE_DEBUG, " ... connect!\n");
752 GMP_connect (peer); 788 GMP_connect (peer);
@@ -756,6 +792,68 @@ search_handler (void *cls, const struct MeshPeerPath *path)
756 792
757 793
758/** 794/**
795 * Free a transmission that was already queued with all resources
796 * associated to the request.
797 *
798 * @param queue Queue handler to cancel.
799 * @param clear_cls Is it necessary to free associated cls?
800 */
801static void
802queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
803{
804 struct MeshPeer *peer;
805
806 peer = queue->peer;
807 GNUNET_assert (NULL != queue->c);
808
809 if (GNUNET_YES == clear_cls)
810 {
811 LOG (GNUNET_ERROR_TYPE_DEBUG, "# queue destroy type %s\n",
812 GNUNET_MESH_DEBUG_M2S (queue->type));
813 switch (queue->type)
814 {
815 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
816 case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
817 LOG (GNUNET_ERROR_TYPE_INFO, "destroying a DESTROY message\n");
818 /* fall through */
819 case GNUNET_MESSAGE_TYPE_MESH_FWD:
820 case GNUNET_MESSAGE_TYPE_MESH_BCK:
821 case GNUNET_MESSAGE_TYPE_MESH_ACK:
822 case GNUNET_MESSAGE_TYPE_MESH_POLL:
823 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
824 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
825 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
826 LOG (GNUNET_ERROR_TYPE_DEBUG, "# prebuilt message\n");;
827 GNUNET_free_non_null (queue->cls);
828 break;
829
830 default:
831 GNUNET_break (0);
832 LOG (GNUNET_ERROR_TYPE_ERROR, "# type %s unknown!\n",
833 GNUNET_MESH_DEBUG_M2S (queue->type));
834 }
835 }
836 GNUNET_CONTAINER_DLL_remove (peer->queue_head, peer->queue_tail, queue);
837
838 if (queue->type != GNUNET_MESSAGE_TYPE_MESH_ACK &&
839 queue->type != GNUNET_MESSAGE_TYPE_MESH_POLL)
840 {
841 peer->queue_n--;
842 }
843
844 if (NULL != queue->callback)
845 {
846 LOG (GNUNET_ERROR_TYPE_DEBUG, "# Calling callback\n");
847 queue->callback (queue->callback_cls,
848 queue->c, queue->type,
849 queue->fwd, queue->size,
850 GNUNET_TIME_absolute_get_duration (queue->start_waiting));
851 }
852
853 GNUNET_free (queue);
854}
855
856/**
759 * Core callback to write a queued packet to core buffer 857 * Core callback to write a queued packet to core buffer
760 * 858 *
761 * @param cls Closure (peer info). 859 * @param cls Closure (peer info).
@@ -769,15 +867,9 @@ queue_send (void *cls, size_t size, void *buf)
769{ 867{
770 struct MeshPeer *peer = cls; 868 struct MeshPeer *peer = cls;
771 struct MeshConnection *c; 869 struct MeshConnection *c;
772 struct GNUNET_MessageHeader *msg;
773 struct MeshPeerQueue *queue; 870 struct MeshPeerQueue *queue;
774 struct MeshTunnel3 *t;
775 struct MeshChannel *ch;
776 const struct GNUNET_PeerIdentity *dst_id; 871 const struct GNUNET_PeerIdentity *dst_id;
777 size_t data_size; 872 size_t data_size;
778 uint32_t pid;
779 uint16_t type;
780 int fwd;
781 873
782 peer->core_transmit = NULL; 874 peer->core_transmit = NULL;
783 LOG (GNUNET_ERROR_TYPE_DEBUG, "* Queue send (max %u)\n", size); 875 LOG (GNUNET_ERROR_TYPE_DEBUG, "* Queue send (max %u)\n", size);
@@ -796,7 +888,6 @@ queue_send (void *cls, size_t size, void *buf)
796 return 0; 888 return 0;
797 } 889 }
798 c = queue->c; 890 c = queue->c;
799 fwd = queue->fwd;
800 891
801 dst_id = GNUNET_PEER_resolve2 (peer->id); 892 dst_id = GNUNET_PEER_resolve2 (peer->id);
802 LOG (GNUNET_ERROR_TYPE_DEBUG, "* towards %s\n", GNUNET_i2s (dst_id)); 893 LOG (GNUNET_ERROR_TYPE_DEBUG, "* towards %s\n", GNUNET_i2s (dst_id));
@@ -817,9 +908,6 @@ queue_send (void *cls, size_t size, void *buf)
817 } 908 }
818 LOG (GNUNET_ERROR_TYPE_DEBUG, "* size %u ok\n", queue->size); 909 LOG (GNUNET_ERROR_TYPE_DEBUG, "* size %u ok\n", queue->size);
819 910
820 t = (NULL != c) ? c->t : NULL;
821 type = 0;
822
823 /* Fill buf */ 911 /* Fill buf */
824 switch (queue->type) 912 switch (queue->type)
825 { 913 {
@@ -834,8 +922,6 @@ queue_send (void *cls, size_t size, void *buf)
834 "* raw: %s\n", 922 "* raw: %s\n",
835 GNUNET_MESH_DEBUG_M2S (queue->type)); 923 GNUNET_MESH_DEBUG_M2S (queue->type));
836 data_size = send_core_data_raw (queue->cls, size, buf); 924 data_size = send_core_data_raw (queue->cls, size, buf);
837 msg = (struct GNUNET_MessageHeader *) buf;
838 type = ntohs (msg->type);
839 break; 925 break;
840 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE: 926 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
841 LOG (GNUNET_ERROR_TYPE_DEBUG, "* path create\n"); 927 LOG (GNUNET_ERROR_TYPE_DEBUG, "* path create\n");
@@ -876,29 +962,15 @@ queue_send (void *cls, size_t size, void *buf)
876 } 962 }
877 963
878 /* Free queue, but cls was freed by send_core_* */ 964 /* Free queue, but cls was freed by send_core_* */
879 ch = queue->ch; 965 queue_destroy (queue, GNUNET_NO);
880 GMP_queue_destroy (queue, GNUNET_NO);
881
882 /* Send ACK if needed, after accounting for sent ID in fc->queue_n */
883 switch (type)
884 {
885 case GNUNET_MESSAGE_TYPE_MESH_FWD:
886 case GNUNET_MESSAGE_TYPE_MESH_BCK:
887 pid = ntohl ( ((struct GNUNET_MESH_Encrypted *) buf)->pid );
888 LOG (GNUNET_ERROR_TYPE_DEBUG, "* accounting pid %u\n", pid);
889 fc->last_pid_sent = pid;
890 send_ack (c, ch, fwd);
891 break;
892 default:
893 break;
894 }
895 966
896 /* If more data in queue, send next */ 967 /* If more data in queue, send next */
897 queue = peer_get_first_message (peer); 968 queue = peer_get_first_message (peer);
898 if (NULL != queue) 969 if (NULL != queue)
899 { 970 {
900 LOG (GNUNET_ERROR_TYPE_DEBUG, "* more data!\n"); 971 LOG (GNUNET_ERROR_TYPE_DEBUG, "* more data!\n");
901 if (NULL == peer->core_transmit) { 972 if (NULL == peer->core_transmit)
973 {
902 peer->core_transmit = 974 peer->core_transmit =
903 GNUNET_CORE_notify_transmit_ready(core_handle, 975 GNUNET_CORE_notify_transmit_ready(core_handle,
904 0, 976 0,
@@ -915,145 +987,22 @@ queue_send (void *cls, size_t size, void *buf)
915 LOG (GNUNET_ERROR_TYPE_DEBUG, 987 LOG (GNUNET_ERROR_TYPE_DEBUG,
916 "* tmt rdy called somewhere else\n"); 988 "* tmt rdy called somewhere else\n");
917 } 989 }
918 if (GNUNET_SCHEDULER_NO_TASK == fc->poll_task) 990// GMC_start_poll (); FIXME needed?
919 {
920 LOG (GNUNET_ERROR_TYPE_DEBUG, "* starting poll timeout\n");
921 fc->poll_task =
922 GNUNET_SCHEDULER_add_delayed (fc->poll_time, &connection_poll, fc);
923 }
924 } 991 }
925 else 992 else
926 { 993 {
927 if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task) 994// GMC_stop_poll(); FIXME needed?
928 {
929 GNUNET_SCHEDULER_cancel (fc->poll_task);
930 fc->poll_task = GNUNET_SCHEDULER_NO_TASK;
931 }
932 } 995 }
933 996
934 if (NULL != t)
935 {
936 t->pending_messages--;
937 if (GNUNET_YES == t->destroy && 0 == t->pending_messages)
938 {
939 LOG (GNUNET_ERROR_TYPE_DEBUG, "* destroying tunnel!\n");
940 GMT_destroy (t);
941 }
942 }
943 LOG (GNUNET_ERROR_TYPE_DEBUG, "* Return %d\n", data_size); 997 LOG (GNUNET_ERROR_TYPE_DEBUG, "* Return %d\n", data_size);
944 return data_size; 998 return data_size;
945} 999}
946 1000
947 1001
948static int
949queue_is_sendable (struct MeshPeerQueue *q)
950{
951 /* Is PID-independent? */
952 switch (q->type)
953 {
954 case GNUNET_MESSAGE_TYPE_MESH_ACK:
955 case GNUNET_MESSAGE_TYPE_MESH_POLL:
956 return GNUNET_YES;
957 }
958
959 if (GMC_is_sendable (q->c, q->fwd))
960 return GNUNET_YES;
961
962 return GNUNET_NO;
963}
964
965/**
966 * Get first sendable message.
967 *
968 * @param peer The destination peer.
969 *
970 * @return Best current known path towards the peer, if any.
971 */
972static struct MeshPeerQueue *
973peer_get_first_message (const struct MeshPeer *peer)
974{
975 struct MeshPeerQueue *q;
976
977 for (q = peer->queue_head; NULL != q; q = q->next)
978 {
979 if (queue_is_sendable (q))
980 return q;
981 }
982
983 return NULL;
984}
985
986
987
988
989/******************************************************************************/ 1002/******************************************************************************/
990/******************************** API ***********************************/ 1003/******************************** API ***********************************/
991/******************************************************************************/ 1004/******************************************************************************/
992 1005
993
994/**
995 * Free a transmission that was already queued with all resources
996 * associated to the request.
997 *
998 * @param queue Queue handler to cancel.
999 * @param clear_cls Is it necessary to free associated cls?
1000 */
1001void
1002GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
1003{
1004 struct MeshPeer *peer;
1005
1006 peer = queue->peer;
1007 GNUNET_assert (NULL != queue->c);
1008
1009 if (GNUNET_YES == clear_cls)
1010 {
1011 LOG (GNUNET_ERROR_TYPE_DEBUG, "# queue destroy type %s\n",
1012 GNUNET_MESH_DEBUG_M2S (queue->type));
1013 switch (queue->type)
1014 {
1015 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
1016 case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
1017 LOG (GNUNET_ERROR_TYPE_INFO, "destroying a DESTROY message\n");
1018 /* fall through */
1019 case GNUNET_MESSAGE_TYPE_MESH_FWD:
1020 case GNUNET_MESSAGE_TYPE_MESH_BCK:
1021 case GNUNET_MESSAGE_TYPE_MESH_ACK:
1022 case GNUNET_MESSAGE_TYPE_MESH_POLL:
1023 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
1024 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
1025 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
1026 LOG (GNUNET_ERROR_TYPE_DEBUG, "# prebuilt message\n");;
1027 GNUNET_free_non_null (queue->cls);
1028 break;
1029
1030 default:
1031 GNUNET_break (0);
1032 LOG (GNUNET_ERROR_TYPE_ERROR, "# type %s unknown!\n",
1033 GNUNET_MESH_DEBUG_M2S (queue->type));
1034 }
1035 }
1036 GNUNET_CONTAINER_DLL_remove (peer->queue_head, peer->queue_tail, queue);
1037
1038 if (queue->type != GNUNET_MESSAGE_TYPE_MESH_ACK &&
1039 queue->type != GNUNET_MESSAGE_TYPE_MESH_POLL)
1040 {
1041 peer->queue_n--;
1042 }
1043
1044 if (NULL != queue->callback)
1045 {
1046 LOG (GNUNET_ERROR_TYPE_DEBUG, "# Calling callback\n");
1047 queue->callback (queue->callback_cls,
1048 queue->c, queue->type,
1049 queue->fwd, queue->size,
1050 GNUNET_TIME_absolute_get_duration (queue->start_waiting));
1051 }
1052
1053 GNUNET_free (queue);
1054}
1055
1056
1057/** 1006/**
1058 * @brief Queue and pass message to core when possible. 1007 * @brief Queue and pass message to core when possible.
1059 * 1008 *
@@ -1121,7 +1070,7 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
1121 if (copy->type == type && copy->c == c && copy->fwd == fwd) 1070 if (copy->type == type && copy->c == c && copy->fwd == fwd)
1122 { 1071 {
1123 /* Example: also a FWD ACK for connection XYZ */ 1072 /* Example: also a FWD ACK for connection XYZ */
1124 GMP_queue_destroy (copy, GNUNET_YES); 1073 queue_destroy (copy, GNUNET_YES);
1125 } 1074 }
1126 } 1075 }
1127 GNUNET_CONTAINER_DLL_insert (peer->queue_head, peer->queue_tail, queue); 1076 GNUNET_CONTAINER_DLL_insert (peer->queue_head, peer->queue_tail, queue);
@@ -1136,7 +1085,7 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
1136 { 1085 {
1137 LOG (GNUNET_ERROR_TYPE_DEBUG, 1086 LOG (GNUNET_ERROR_TYPE_DEBUG,
1138 "calling core tmt rdy towards %s for %u bytes\n", 1087 "calling core tmt rdy towards %s for %u bytes\n",
1139 peer2s (peer), size); 1088 GMP_2s (peer), size);
1140 peer->core_transmit = 1089 peer->core_transmit =
1141 GNUNET_CORE_notify_transmit_ready (core_handle, 1090 GNUNET_CORE_notify_transmit_ready (core_handle,
1142 0, 1091 0,
@@ -1152,7 +1101,7 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
1152 { 1101 {
1153 LOG (GNUNET_ERROR_TYPE_DEBUG, 1102 LOG (GNUNET_ERROR_TYPE_DEBUG,
1154 "core tmt rdy towards %s already called\n", 1103 "core tmt rdy towards %s already called\n",
1155 peer2s (peer)); 1104 GMP_2s (peer));
1156 1105
1157 } 1106 }
1158} 1107}
@@ -1178,7 +1127,7 @@ GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c)
1178 LOG (GNUNET_ERROR_TYPE_DEBUG, 1127 LOG (GNUNET_ERROR_TYPE_DEBUG,
1179 "connection_cancel_queue %s\n", 1128 "connection_cancel_queue %s\n",
1180 GNUNET_MESH_DEBUG_M2S (q->type)); 1129 GNUNET_MESH_DEBUG_M2S (q->type));
1181 GMP_queue_destroy (q, GNUNET_YES); 1130 queue_destroy (q, GNUNET_YES);
1182 } 1131 }
1183 } 1132 }
1184 if (NULL == peer->queue_head) 1133 if (NULL == peer->queue_head)
@@ -1380,7 +1329,7 @@ GMP_connect (struct MeshPeer *peer)
1380 1329
1381 LOG (GNUNET_ERROR_TYPE_DEBUG, 1330 LOG (GNUNET_ERROR_TYPE_DEBUG,
1382 "peer_connect towards %s\n", 1331 "peer_connect towards %s\n",
1383 peer2s (peer)); 1332 GMP_2s (peer));
1384 t = peer->tunnel; 1333 t = peer->tunnel;
1385 c = NULL; 1334 c = NULL;
1386 rerun_search = GNUNET_NO; 1335 rerun_search = GNUNET_NO;
@@ -1433,7 +1382,7 @@ GMP_connect (struct MeshPeer *peer)
1433 1382
1434 id = GNUNET_PEER_resolve2 (peer->id); 1383 id = GNUNET_PEER_resolve2 (peer->id);
1435 LOG (GNUNET_ERROR_TYPE_DEBUG, 1384 LOG (GNUNET_ERROR_TYPE_DEBUG,
1436 " Starting DHT GET for peer %s\n", peer2s (peer)); 1385 " Starting DHT GET for peer %s\n", GMP_2s (peer));
1437 peer->search_h = GMD_search (id, &search_handler, peer); 1386 peer->search_h = GMD_search (id, &search_handler, peer);
1438 if (MESH_TUNNEL3_NEW == GMT_get_state (t)) 1387 if (MESH_TUNNEL3_NEW == GMT_get_state (t))
1439 GMT_change_state (t, MESH_TUNNEL3_SEARCHING); 1388 GMT_change_state (t, MESH_TUNNEL3_SEARCHING);
@@ -1576,7 +1525,7 @@ GMP_add_path (struct MeshPeer *peer_info, struct MeshPeerPath *path,
1576 } 1525 }
1577 1526
1578 LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u] to peer %s\n", 1527 LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u] to peer %s\n",
1579 path->length, peer2s (peer_info)); 1528 path->length, GMP_2s (peer_info));
1580 1529
1581 l = path_get_length (path); 1530 l = path_get_length (path);
1582 if (0 == l) 1531 if (0 == l)
@@ -1640,7 +1589,7 @@ GMP_add_path_to_origin (struct MeshPeer *peer,
1640 * @param confirmed Whether we know if the path works or not. 1589 * @param confirmed Whether we know if the path works or not.
1641 */ 1590 */
1642void 1591void
1643GMP_add_path_to_all (struct MeshPeerPath *p, int confirmed) 1592GMP_add_path_to_all (const struct MeshPeerPath *p, int confirmed)
1644{ 1593{
1645 unsigned int i; 1594 unsigned int i;
1646 1595
diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h
index c7265ce2f..57eb1c61d 100644
--- a/src/mesh/gnunet-service-mesh_peer.h
+++ b/src/mesh/gnunet-service-mesh_peer.h
@@ -45,6 +45,8 @@ extern "C"
45 */ 45 */
46struct MeshPeer; 46struct MeshPeer;
47 47
48#include "gnunet-service-mesh_connection.h"
49
48/** 50/**
49 * Callback called when a queued message is sent. 51 * Callback called when a queued message is sent.
50 * 52 *
@@ -60,9 +62,6 @@ typedef void (*GMP_sent) (void *cls,
60 int fwd, size_t size, 62 int fwd, size_t size,
61 struct GNUNET_TIME_Relative wait); 63 struct GNUNET_TIME_Relative wait);
62 64
63#include "gnunet-service-mesh_connection.h"
64
65
66/******************************************************************************/ 65/******************************************************************************/
67/******************************** API ***********************************/ 66/******************************** API ***********************************/
68/******************************************************************************/ 67/******************************************************************************/
@@ -225,7 +224,7 @@ GMP_add_path_to_origin (struct MeshPeer *peer_info,
225 * @param confirmed Whether we know if the path works or not. 224 * @param confirmed Whether we know if the path works or not.
226 */ 225 */
227void 226void
228GMP_add_path_to_all (struct MeshPeerPath *p, int confirmed); 227GMP_add_path_to_all (const struct MeshPeerPath *p, int confirmed);
229 228
230/** 229/**
231 * Remove a connection from a neighboring peer. 230 * Remove a connection from a neighboring peer.
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c
index c5ccc9f5c..9341e0eaf 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.c
+++ b/src/mesh/gnunet-service-mesh_tunnel.c
@@ -1170,6 +1170,27 @@ GMT_is_loopback (const struct MeshTunnel3 *t)
1170 1170
1171 1171
1172/** 1172/**
1173 * Is the tunnel using this path already?
1174 *
1175 * @param t Tunnel.
1176 * @param p Path.
1177 *
1178 * @return GNUNET_YES a connection uses this path.
1179 */
1180int
1181GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p)
1182{
1183 struct MeshTConnection *c;
1184
1185 for (c = t->connection_head; NULL != c; c = c->next)
1186 if (GMC_get_path (c) == p)
1187 return GNUNET_YES;
1188
1189 return GNUNET_NO;
1190}
1191
1192
1193/**
1173 * Get the static string for the peer this tunnel is directed. 1194 * Get the static string for the peer this tunnel is directed.
1174 * 1195 *
1175 * @param t Tunnel. 1196 * @param t Tunnel.
diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h
index c55e91fe2..89c8a1462 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.h
+++ b/src/mesh/gnunet-service-mesh_tunnel.h
@@ -321,6 +321,17 @@ int
321GMT_is_loopback (const struct MeshTunnel3 *t); 321GMT_is_loopback (const struct MeshTunnel3 *t);
322 322
323/** 323/**
324 * Is the tunnel using this path already?
325 *
326 * @param t Tunnel.
327 * @param p Path.
328 *
329 * @return GNUNET_YES a connection uses this path.
330 */
331int
332GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p);
333
334/**
324 * Get the static string for the peer this tunnel is directed. 335 * Get the static string for the peer this tunnel is directed.
325 * 336 *
326 * @param t Tunnel. 337 * @param t Tunnel.