aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
commit83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch)
treed0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/mesh
parent28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff)
downloadgnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz
gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip
curly wars / auto-indentation
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c905
-rw-r--r--src/mesh/mesh_api.c40
-rw-r--r--src/mesh/mesh_protocol.h2
-rw-r--r--src/mesh/mesh_tunnel_tree.c334
-rw-r--r--src/mesh/mesh_tunnel_tree.h49
-rw-r--r--src/mesh/test_mesh_api.c3
-rw-r--r--src/mesh/test_mesh_local_2.c7
-rw-r--r--src/mesh/test_mesh_small.c335
-rw-r--r--src/mesh/test_mesh_small_unicast_far.c111
-rw-r--r--src/mesh/test_mesh_tree_api.c142
10 files changed, 836 insertions, 1092 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index c0a7852e0..a5113e52b 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -342,7 +342,7 @@ struct MeshPathInfo
342 * Path itself 342 * Path itself
343 */ 343 */
344 struct MeshPeerPath *path; 344 struct MeshPeerPath *path;
345 345
346 /** 346 /**
347 * Position in peer's transmit queue 347 * Position in peer's transmit queue
348 */ 348 */
@@ -479,7 +479,7 @@ static struct GNUNET_PeerIdentity my_full_id;
479/** 479/**
480 * Own private key 480 * Own private key
481 */ 481 */
482static struct GNUNET_CRYPTO_RsaPrivateKey* my_private_key; 482static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
483 483
484/** 484/**
485 * Own public key. 485 * Own public key.
@@ -546,12 +546,9 @@ static int
546announce_application (void *cls, const GNUNET_HashCode * key, void *value) 546announce_application (void *cls, const GNUNET_HashCode * key, void *value)
547{ 547{
548 /* FIXME are hashes in multihash map equal on all aquitectures? */ 548 /* FIXME are hashes in multihash map equal on all aquitectures? */
549 GNUNET_DHT_put (dht_handle, 549 GNUNET_DHT_put (dht_handle, key, 10U,
550 key,
551 10U,
552 GNUNET_DHT_RO_RECORD_ROUTE | 550 GNUNET_DHT_RO_RECORD_ROUTE |
553 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 551 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_BLOCK_TYPE_TEST,
554 GNUNET_BLOCK_TYPE_TEST,
555 sizeof (struct GNUNET_PeerIdentity), 552 sizeof (struct GNUNET_PeerIdentity),
556 (const char *) &my_full_id, 553 (const char *) &my_full_id,
557#if MESH_DEBUG 554#if MESH_DEBUG
@@ -620,11 +617,10 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
620 GNUNET_DHT_put (dht_handle, /* DHT handle */ 617 GNUNET_DHT_put (dht_handle, /* DHT handle */
621 &my_full_id.hashPubKey, /* Key to use */ 618 &my_full_id.hashPubKey, /* Key to use */
622 10U, /* Replication level */ 619 10U, /* Replication level */
623 GNUNET_DHT_RO_RECORD_ROUTE | 620 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
624 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
625 GNUNET_BLOCK_TYPE_TEST, /* Block type */ 621 GNUNET_BLOCK_TYPE_TEST, /* Block type */
626 sizeof(my_full_id), /* Size of the data */ 622 sizeof (my_full_id), /* Size of the data */
627 (char *)&my_full_id, /* Data itself */ 623 (char *) &my_full_id, /* Data itself */
628 GNUNET_TIME_absolute_get_forever (), /* Data expiration */ 624 GNUNET_TIME_absolute_get_forever (), /* Data expiration */
629 GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ 625 GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */
630#if MESH_DEBUG_DHT 626#if MESH_DEBUG_DHT
@@ -656,8 +652,8 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
656 const struct GNUNET_PeerIdentity *get_path, 652 const struct GNUNET_PeerIdentity *get_path,
657 unsigned int get_path_length, 653 unsigned int get_path_length,
658 const struct GNUNET_PeerIdentity *put_path, 654 const struct GNUNET_PeerIdentity *put_path,
659 unsigned int put_path_length, 655 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
660 enum GNUNET_BLOCK_Type type, size_t size, const void *data); 656 size_t size, const void *data);
661 657
662 658
663/******************************************************************************/ 659/******************************************************************************/
@@ -711,12 +707,12 @@ client_is_subscribed (uint16_t message_type, struct MeshClient *c)
711 * Allow a client to send more data after transmitting a multicast message 707 * Allow a client to send more data after transmitting a multicast message
712 * which some neighbor has not yet accepted altough a reasonable time has 708 * which some neighbor has not yet accepted altough a reasonable time has
713 * passed. 709 * passed.
714 * 710 *
715 * @param cls Closure (DataDescriptor containing the task identifier) 711 * @param cls Closure (DataDescriptor containing the task identifier)
716 * @param tc Task Context 712 * @param tc Task Context
717 */ 713 */
718static void 714static void
719client_allow_send(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 715client_allow_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
720{ 716{
721 struct MeshDataDescriptor *info = cls; 717 struct MeshDataDescriptor *info = cls;
722 718
@@ -728,7 +724,7 @@ client_allow_send(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
728 *(info->copies)); 724 *(info->copies));
729#endif 725#endif
730 *(info->timeout_task) = GNUNET_SCHEDULER_NO_TASK; 726 *(info->timeout_task) = GNUNET_SCHEDULER_NO_TASK;
731 GNUNET_SERVER_receive_done(info->client, GNUNET_OK); 727 GNUNET_SERVER_receive_done (info->client, GNUNET_OK);
732} 728}
733 729
734 730
@@ -756,8 +752,7 @@ tunnel_get (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid);
756 * 0 if the tunnel remained unaffected. 752 * 0 if the tunnel remained unaffected.
757 */ 753 */
758static GNUNET_PEER_Id 754static GNUNET_PEER_Id
759tunnel_notify_connection_broken (struct MeshTunnel *t, 755tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1,
760 GNUNET_PEER_Id p1,
761 GNUNET_PEER_Id p2); 756 GNUNET_PEER_Id p2);
762 757
763 758
@@ -777,39 +772,39 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg,
777 MESH_TunnelNumber *tid; 772 MESH_TunnelNumber *tid;
778 unsigned int count; 773 unsigned int count;
779 uint16_t type; 774 uint16_t type;
780 char cbuf[htons(msg->size)]; 775 char cbuf[htons (msg->size)];
781 776
782 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Sending to clients...\n"); 777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Sending to clients...\n");
783 type = ntohs (payload->type); 778 type = ntohs (payload->type);
784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message of type %u\n", type); 779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message of type %u\n", type);
785 780
786 memcpy (cbuf, msg, sizeof(cbuf)); 781 memcpy (cbuf, msg, sizeof (cbuf));
787 switch (htons(msg->type)) 782 switch (htons (msg->type))
788 { 783 {
789 struct GNUNET_MESH_Unicast *uc; 784 struct GNUNET_MESH_Unicast *uc;
790 struct GNUNET_MESH_Multicast *mc; 785 struct GNUNET_MESH_Multicast *mc;
791 struct GNUNET_MESH_ToOrigin *to; 786 struct GNUNET_MESH_ToOrigin *to;
792 787
793 case GNUNET_MESSAGE_TYPE_MESH_UNICAST: 788 case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
794 uc = (struct GNUNET_MESH_Unicast *) cbuf; 789 uc = (struct GNUNET_MESH_Unicast *) cbuf;
795 tid = &uc->tid; 790 tid = &uc->tid;
796 oid = &uc->oid; 791 oid = &uc->oid;
797 break; 792 break;
798 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: 793 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
799 mc = (struct GNUNET_MESH_Multicast *) cbuf; 794 mc = (struct GNUNET_MESH_Multicast *) cbuf;
800 tid = &mc->tid; 795 tid = &mc->tid;
801 oid = &mc->oid; 796 oid = &mc->oid;
802 break; 797 break;
803 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: 798 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
804 to = (struct GNUNET_MESH_ToOrigin *) cbuf; 799 to = (struct GNUNET_MESH_ToOrigin *) cbuf;
805 tid = &to->tid; 800 tid = &to->tid;
806 oid = &to->oid; 801 oid = &to->oid;
807 break; 802 break;
808 default: 803 default:
809 GNUNET_break (0); 804 GNUNET_break (0);
810 return 0; 805 return 0;
811 } 806 }
812 t = tunnel_get (oid, ntohl(*tid)); 807 t = tunnel_get (oid, ntohl (*tid));
813 if (NULL == t) 808 if (NULL == t)
814 { 809 {
815 GNUNET_break (0); 810 GNUNET_break (0);
@@ -823,11 +818,9 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg,
823 { 818 {
824 count++; 819 count++;
825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending\n"); 820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending\n");
826 GNUNET_SERVER_notification_context_unicast ( 821 GNUNET_SERVER_notification_context_unicast (nc, c->handle,
827 nc, 822 (struct GNUNET_MessageHeader
828 c->handle, 823 *) cbuf, GNUNET_YES);
829 (struct GNUNET_MessageHeader *) cbuf,
830 GNUNET_YES);
831 } 824 }
832 } 825 }
833 return count; 826 return count;
@@ -837,7 +830,7 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg,
837/** 830/**
838 * Notify the client that owns the tunnel that a peer has connected to it 831 * Notify the client that owns the tunnel that a peer has connected to it
839 * (the requested path to it has been confirmed). 832 * (the requested path to it has been confirmed).
840 * 833 *
841 * @param t Tunnel whose owner to notify 834 * @param t Tunnel whose owner to notify
842 * @param id Short id of the peer that has connected 835 * @param id Short id of the peer that has connected
843 */ 836 */
@@ -850,26 +843,26 @@ send_client_peer_connected (const struct MeshTunnel *t, const GNUNET_PEER_Id id)
850 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 843 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
851 pc.tunnel_id = htonl (t->local_tid); 844 pc.tunnel_id = htonl (t->local_tid);
852 GNUNET_PEER_resolve (id, &pc.peer); 845 GNUNET_PEER_resolve (id, &pc.peer);
853 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, 846 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, &pc.header,
854 &pc.header, GNUNET_NO); 847 GNUNET_NO);
855} 848}
856 849
857 850
858/** 851/**
859 * Notify all clients (not depending on registration status) that the incoming 852 * Notify all clients (not depending on registration status) that the incoming
860 * tunnel is no longer valid. 853 * tunnel is no longer valid.
861 * 854 *
862 * @param t Tunnel that was destroyed. 855 * @param t Tunnel that was destroyed.
863 */ 856 */
864static void 857static void
865send_clients_tunnel_destroy (struct MeshTunnel *t) 858send_clients_tunnel_destroy (struct MeshTunnel *t)
866{ 859{
867 struct GNUNET_MESH_TunnelMessage msg; 860 struct GNUNET_MESH_TunnelMessage msg;
868 861
869 msg.header.size = htons (sizeof (msg)); 862 msg.header.size = htons (sizeof (msg));
870 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); 863 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
871 msg.tunnel_id = htonl (t->local_tid); 864 msg.tunnel_id = htonl (t->local_tid);
872 GNUNET_SERVER_notification_context_broadcast(nc, &msg.header, GNUNET_NO); 865 GNUNET_SERVER_notification_context_broadcast (nc, &msg.header, GNUNET_NO);
873} 866}
874 867
875 868
@@ -906,7 +899,7 @@ send_core_data_multicast (void *cls, size_t size, void *buf);
906 899
907/** 900/**
908 * Decrements the reference counter and frees all resources if needed 901 * Decrements the reference counter and frees all resources if needed
909 * 902 *
910 * @param dd Data Descriptor used in a multicast message 903 * @param dd Data Descriptor used in a multicast message
911 */ 904 */
912static void 905static void
@@ -922,7 +915,7 @@ data_descriptor_decrement_multicast (struct MeshDataDescriptor *dd)
922 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
923 "MESH: cancelling client timeout (%u)...\n", 916 "MESH: cancelling client timeout (%u)...\n",
924 *(dd->timeout_task)); 917 *(dd->timeout_task));
925 GNUNET_SCHEDULER_cancel(*(dd->timeout_task)); 918 GNUNET_SCHEDULER_cancel (*(dd->timeout_task));
926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client...\n"); 919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client...\n");
927 GNUNET_SERVER_receive_done (dd->client, GNUNET_OK); 920 GNUNET_SERVER_receive_done (dd->client, GNUNET_OK);
928 } 921 }
@@ -937,12 +930,12 @@ data_descriptor_decrement_multicast (struct MeshDataDescriptor *dd)
937/** 930/**
938 * Cancel a core transmission that was already requested and free all resources 931 * Cancel a core transmission that was already requested and free all resources
939 * associated to the request. 932 * associated to the request.
940 * 933 *
941 * @param peer PeeInfo of the peer whose transmission is cancelled. 934 * @param peer PeeInfo of the peer whose transmission is cancelled.
942 * @param i Position of the transmission to be cancelled. 935 * @param i Position of the transmission to be cancelled.
943 */ 936 */
944static void 937static void
945peer_info_cancel_transmission(struct MeshPeerInfo *peer, unsigned int i) 938peer_info_cancel_transmission (struct MeshPeerInfo *peer, unsigned int i)
946{ 939{
947 if (NULL != peer->core_transmit[i]) 940 if (NULL != peer->core_transmit[i])
948 { 941 {
@@ -956,36 +949,34 @@ peer_info_cancel_transmission(struct MeshPeerInfo *peer, unsigned int i)
956 GNUNET_PEER_resolve (peer->id, &id); 949 GNUNET_PEER_resolve (peer->id, &id);
957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
958 "MESH: Cancelling data transmission at %s [%u]\n", 951 "MESH: Cancelling data transmission at %s [%u]\n",
959 GNUNET_i2s (&id), 952 GNUNET_i2s (&id), i);
960 i); 953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message type %u\n",
961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
962 "MESH: message type %u\n",
963 peer->types[i]); 954 peer->types[i]);
964 } 955 }
965#endif 956#endif
966 /* TODO: notify that tranmission has failed */ 957 /* TODO: notify that tranmission has failed */
967 switch (peer->types[i]) 958 switch (peer->types[i])
968 { 959 {
969 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: 960 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
970 case GNUNET_MESSAGE_TYPE_MESH_UNICAST: 961 case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
971 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: 962 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type payload\n"); 963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type payload\n");
973 dd = peer->infos[i]; 964 dd = peer->infos[i];
974 data_descriptor_decrement_multicast (dd); 965 data_descriptor_decrement_multicast (dd);
975 break; 966 break;
976 case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE: 967 case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type create path\n"); 968 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type create path\n");
978 path_info = peer->infos[i]; 969 path_info = peer->infos[i];
979 path_destroy(path_info->path); 970 path_destroy (path_info->path);
980 break; 971 break;
981 default: 972 default:
982 GNUNET_break (0); 973 GNUNET_break (0);
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type unknown!\n"); 974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type unknown!\n");
984 } 975 }
985 GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit[i]); 976 GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit[i]);
986 peer->core_transmit[i] = NULL; 977 peer->core_transmit[i] = NULL;
987 GNUNET_free (peer->infos[i]); 978 GNUNET_free (peer->infos[i]);
988 } 979 }
989} 980}
990 981
991 982
@@ -1008,7 +999,7 @@ peer_info_transmit_slot (struct MeshPeerInfo *peer)
1008 { 999 {
1009 /* All positions are taken! Overwriting! */ 1000 /* All positions are taken! Overwriting! */
1010 GNUNET_break (0); 1001 GNUNET_break (0);
1011 peer_info_cancel_transmission(peer, 0); 1002 peer_info_cancel_transmission (peer, 0);
1012 return 0; 1003 return 0;
1013 } 1004 }
1014 } 1005 }
@@ -1056,8 +1047,8 @@ peer_info_get_short (const GNUNET_PEER_Id peer)
1056{ 1047{
1057 struct GNUNET_PeerIdentity id; 1048 struct GNUNET_PeerIdentity id;
1058 1049
1059 GNUNET_PEER_resolve(peer, &id); 1050 GNUNET_PEER_resolve (peer, &id);
1060 return peer_info_get(&id); 1051 return peer_info_get (&id);
1061} 1052}
1062 1053
1063 1054
@@ -1072,7 +1063,7 @@ peer_info_get_short (const GNUNET_PEER_Id peer)
1072 * @return always GNUNET_YES, to keep iterating 1063 * @return always GNUNET_YES, to keep iterating
1073 */ 1064 */
1074static int 1065static int
1075peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value) 1066peer_info_delete_tunnel (void *cls, const GNUNET_HashCode * key, void *value)
1076{ 1067{
1077 struct MeshTunnel *t = cls; 1068 struct MeshTunnel *t = cls;
1078 struct MeshPeerInfo *peer = value; 1069 struct MeshPeerInfo *peer = value;
@@ -1080,9 +1071,8 @@ peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value)
1080 1071
1081 for (i = 0; i < peer->ntunnels; i++) 1072 for (i = 0; i < peer->ntunnels; i++)
1082 { 1073 {
1083 if (0 == memcmp(&peer->tunnels[i]->id, 1074 if (0 ==
1084 &t->id, 1075 memcmp (&peer->tunnels[i]->id, &t->id, sizeof (struct MESH_TunnelID)))
1085 sizeof(struct MESH_TunnelID)))
1086 { 1076 {
1087 peer->ntunnels--; 1077 peer->ntunnels--;
1088 peer->tunnels[i] = peer->tunnels[peer->ntunnels]; 1078 peer->tunnels[i] = peer->tunnels[peer->ntunnels];
@@ -1095,12 +1085,12 @@ peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value)
1095 1085
1096 1086
1097/** 1087/**
1098 * Core callback to write a 1088 * Core callback to write a
1099 * 1089 *
1100 * @param cls Closure (MeshDataDescriptor with data in "data" member). 1090 * @param cls Closure (MeshDataDescriptor with data in "data" member).
1101 * @param size Number of bytes available in buf. 1091 * @param size Number of bytes available in buf.
1102 * @param buf Where the to write the message. 1092 * @param buf Where the to write the message.
1103 * 1093 *
1104 * @return number of bytes written to buf 1094 * @return number of bytes written to buf
1105 */ 1095 */
1106static size_t 1096static size_t
@@ -1121,15 +1111,10 @@ send_core_data_raw (void *cls, size_t size, void *buf)
1121 1111
1122 GNUNET_PEER_resolve (info->peer->id, &id); 1112 GNUNET_PEER_resolve (info->peer->id, &id);
1123 info->peer->core_transmit[info->handler_n] = 1113 info->peer->core_transmit[info->handler_n] =
1124 GNUNET_CORE_notify_transmit_ready(core_handle, 1114 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100,
1125 0, 1115 GNUNET_TIME_UNIT_FOREVER_REL, &id,
1126 100, 1116 size, &send_core_data_raw, info);
1127 GNUNET_TIME_UNIT_FOREVER_REL, 1117 return 0;
1128 &id,
1129 size,
1130 &send_core_data_raw,
1131 info);
1132 return 0;
1133 } 1118 }
1134 info->peer->core_transmit[info->handler_n] = NULL; 1119 info->peer->core_transmit[info->handler_n] = NULL;
1135 memcpy (buf, msg, total_size); 1120 memcpy (buf, msg, total_size);
@@ -1181,14 +1166,9 @@ send_message (const struct GNUNET_MessageHeader *message,
1181 neighbor->types[i] = GNUNET_MESSAGE_TYPE_MESH_UNICAST; 1166 neighbor->types[i] = GNUNET_MESSAGE_TYPE_MESH_UNICAST;
1182 neighbor->infos[i] = info; 1167 neighbor->infos[i] = info;
1183 neighbor->core_transmit[i] = 1168 neighbor->core_transmit[i] =
1184 GNUNET_CORE_notify_transmit_ready(core_handle, 1169 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100,
1185 0, 1170 GNUNET_TIME_UNIT_FOREVER_REL, peer,
1186 100, 1171 size, &send_core_data_raw, info);
1187 GNUNET_TIME_UNIT_FOREVER_REL,
1188 peer,
1189 size,
1190 &send_core_data_raw,
1191 info);
1192 1172
1193} 1173}
1194 1174
@@ -1196,14 +1176,13 @@ send_message (const struct GNUNET_MessageHeader *message,
1196/** 1176/**
1197 * Sends a CREATE PATH message for a path to a peer, properly registrating 1177 * Sends a CREATE PATH message for a path to a peer, properly registrating
1198 * all used resources. 1178 * all used resources.
1199 * 1179 *
1200 * @param peer PeerInfo of the final peer for whom this path is being created. 1180 * @param peer PeerInfo of the final peer for whom this path is being created.
1201 * @param p Path itself. 1181 * @param p Path itself.
1202 * @param t Tunnel for which the path is created. 1182 * @param t Tunnel for which the path is created.
1203 */ 1183 */
1204static void 1184static void
1205send_create_path (struct MeshPeerInfo *peer, 1185send_create_path (struct MeshPeerInfo *peer, struct MeshPeerPath *p,
1206 struct MeshPeerPath *p,
1207 struct MeshTunnel *t) 1186 struct MeshTunnel *t)
1208{ 1187{
1209 struct GNUNET_PeerIdentity id; 1188 struct GNUNET_PeerIdentity id;
@@ -1213,7 +1192,7 @@ send_create_path (struct MeshPeerInfo *peer,
1213 1192
1214 if (NULL == p) 1193 if (NULL == p)
1215 { 1194 {
1216 p = tree_get_path_to_peer(t->tree, peer->id); 1195 p = tree_get_path_to_peer (t->tree, peer->id);
1217 if (NULL == p) 1196 if (NULL == p)
1218 { 1197 {
1219 GNUNET_break (0); 1198 GNUNET_break (0);
@@ -1227,37 +1206,34 @@ send_create_path (struct MeshPeerInfo *peer,
1227 } 1206 }
1228 if (i >= p->length - 1) 1207 if (i >= p->length - 1)
1229 { 1208 {
1230 path_destroy(p); 1209 path_destroy (p);
1231 GNUNET_break (0); 1210 GNUNET_break (0);
1232 return; 1211 return;
1233 } 1212 }
1234 GNUNET_PEER_resolve(p->peers[i + 1], &id); 1213 GNUNET_PEER_resolve (p->peers[i + 1], &id);
1235 1214
1236 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); 1215 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
1237 path_info->path = p; 1216 path_info->path = p;
1238 path_info->t = t; 1217 path_info->t = t;
1239 neighbor = peer_info_get(&id); 1218 neighbor = peer_info_get (&id);
1240 path_info->peer = neighbor; 1219 path_info->peer = neighbor;
1241 path_info->pos = peer_info_transmit_slot(neighbor); 1220 path_info->pos = peer_info_transmit_slot (neighbor);
1242 neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE; 1221 neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE;
1243 neighbor->infos[path_info->pos] = path_info; 1222 neighbor->infos[path_info->pos] = path_info;
1244 neighbor->core_transmit[path_info->pos] = 1223 neighbor->core_transmit[path_info->pos] = GNUNET_CORE_notify_transmit_ready (core_handle, /* handle */
1245 GNUNET_CORE_notify_transmit_ready ( 1224 0, /* cork */
1246 core_handle, /* handle */ 1225 0, /* priority */
1247 0, /* cork */ 1226 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
1248 0, /* priority */ 1227 &id, /* target */
1249 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 1228 sizeof (struct GNUNET_MESH_ManipulatePath) + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */
1250 &id, /* target */ 1229 &send_core_create_path, /* callback */
1251 sizeof (struct GNUNET_MESH_ManipulatePath) 1230 path_info); /* cls */
1252 + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */
1253 &send_core_create_path, /* callback */
1254 path_info); /* cls */
1255} 1231}
1256 1232
1257 1233
1258/** 1234/**
1259 * Sends a DESTROY PATH message to free resources for a path in a tunnel 1235 * Sends a DESTROY PATH message to free resources for a path in a tunnel
1260 * 1236 *
1261 * @param t Tunnel whose path to destroy. 1237 * @param t Tunnel whose path to destroy.
1262 * @param destination Short ID of the peer to whom the path to destroy. 1238 * @param destination Short ID of the peer to whom the path to destroy.
1263 */ 1239 */
@@ -1267,7 +1243,7 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination)
1267 struct MeshPeerPath *p; 1243 struct MeshPeerPath *p;
1268 size_t size; 1244 size_t size;
1269 1245
1270 p = tree_get_path_to_peer(t->tree, destination); 1246 p = tree_get_path_to_peer (t->tree, destination);
1271 if (NULL == p) 1247 if (NULL == p)
1272 { 1248 {
1273 GNUNET_break (0); 1249 GNUNET_break (0);
@@ -1288,9 +1264,9 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination)
1288 pi = (struct GNUNET_PeerIdentity *) &msg[1]; 1264 pi = (struct GNUNET_PeerIdentity *) &msg[1];
1289 for (i = 0; i < p->length; i++) 1265 for (i = 0; i < p->length; i++)
1290 { 1266 {
1291 GNUNET_PEER_resolve(p->peers[i], &pi[i]); 1267 GNUNET_PEER_resolve (p->peers[i], &pi[i]);
1292 } 1268 }
1293 send_message (&msg->header, path_get_first_hop(t->tree, destination)); 1269 send_message (&msg->header, path_get_first_hop (t->tree, destination));
1294 } 1270 }
1295 path_destroy (p); 1271 path_destroy (p);
1296} 1272}
@@ -1299,7 +1275,7 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination)
1299/** 1275/**
1300 * Try to establish a new connection to this peer. 1276 * Try to establish a new connection to this peer.
1301 * Use the best path for the given tunnel. 1277 * Use the best path for the given tunnel.
1302 * If the peer doesn't have any path to it yet, try to get one. 1278 * If the peer doesn't have any path to it yet, try to get one.
1303 * If the peer already has some path, send a CREATE PATH towards it. 1279 * If the peer already has some path, send a CREATE PATH towards it.
1304 * 1280 *
1305 * @param peer PeerInfo of the peer. 1281 * @param peer PeerInfo of the peer.
@@ -1313,7 +1289,7 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t)
1313 1289
1314 if (NULL != peer->path_head) 1290 if (NULL != peer->path_head)
1315 { 1291 {
1316 p = tree_get_path_to_peer(t->tree, peer->id); 1292 p = tree_get_path_to_peer (t->tree, peer->id);
1317 if (NULL == p) 1293 if (NULL == p)
1318 { 1294 {
1319 GNUNET_break (0); 1295 GNUNET_break (0);
@@ -1322,38 +1298,33 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t)
1322 1298
1323 if (p->length > 1) 1299 if (p->length > 1)
1324 { 1300 {
1325 send_create_path(peer, p, t); 1301 send_create_path (peer, p, t);
1326 } 1302 }
1327 else 1303 else
1328 { 1304 {
1329 path_destroy(p); 1305 path_destroy (p);
1330 send_client_peer_connected(t, myid); 1306 send_client_peer_connected (t, myid);
1331 } 1307 }
1332 } 1308 }
1333 else if (NULL == peer->dhtget) 1309 else if (NULL == peer->dhtget)
1334 { 1310 {
1335 struct GNUNET_PeerIdentity id; 1311 struct GNUNET_PeerIdentity id;
1336 1312
1337 GNUNET_PEER_resolve(peer->id, &id); 1313 GNUNET_PEER_resolve (peer->id, &id);
1338 path_info = GNUNET_malloc(sizeof(struct MeshPathInfo)); 1314 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
1339 path_info->peer = peer; 1315 path_info->peer = peer;
1340 path_info->t = t; 1316 path_info->t = t;
1341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1342 "MESH: Starting DHT GET for peer %s\n", 1318 "MESH: Starting DHT GET for peer %s\n", GNUNET_i2s (&id));
1343 GNUNET_i2s (&id));
1344 peer->dhtgetcls = path_info; 1319 peer->dhtgetcls = path_info;
1345 peer->dhtget = 1320 peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */
1346 GNUNET_DHT_get_start(dht_handle, /* handle */ 1321 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
1347 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 1322 GNUNET_BLOCK_TYPE_TEST, /* type */
1348 GNUNET_BLOCK_TYPE_TEST, /* type */ 1323 &id.hashPubKey, /* key to search */
1349 &id.hashPubKey, /* key to search */ 1324 4, /* replication level */
1350 4, /* replication level */ 1325 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
1351 GNUNET_DHT_RO_RECORD_ROUTE | 1326 0, /* xquery bits */
1352 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 1327 &dht_get_id_handler, path_info);
1353 NULL, /* xquery */
1354 0, /* xquery bits */
1355 &dht_get_id_handler,
1356 path_info);
1357 } 1328 }
1358 /* Otherwise, there is no path but the DHT get is already started. */ 1329 /* Otherwise, there is no path but the DHT get is already started. */
1359} 1330}
@@ -1384,9 +1355,9 @@ peer_info_connect_task (void *cls,
1384 1355
1385/** 1356/**
1386 * Destroy the peer_info and free any allocated resources linked to it 1357 * Destroy the peer_info and free any allocated resources linked to it
1387 * 1358 *
1388 * @param pi The peer_info to destroy. 1359 * @param pi The peer_info to destroy.
1389 * 1360 *
1390 * @return GNUNET_OK on success 1361 * @return GNUNET_OK on success
1391 */ 1362 */
1392static int 1363static int
@@ -1401,21 +1372,20 @@ peer_info_destroy (struct MeshPeerInfo *pi)
1401 GNUNET_PEER_change_rc (pi->id, -1); 1372 GNUNET_PEER_change_rc (pi->id, -1);
1402 1373
1403 if (GNUNET_YES != 1374 if (GNUNET_YES !=
1404 GNUNET_CONTAINER_multihashmap_remove (peers,&id.hashPubKey, pi)) 1375 GNUNET_CONTAINER_multihashmap_remove (peers, &id.hashPubKey, pi))
1405 { 1376 {
1406 GNUNET_break (0); 1377 GNUNET_break (0);
1407 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1378 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1408 "MESH: removing peer %s, not in hashmap\n", 1379 "MESH: removing peer %s, not in hashmap\n", GNUNET_i2s (&id));
1409 GNUNET_i2s (&id));
1410 } 1380 }
1411 if (NULL != pi->dhtget) 1381 if (NULL != pi->dhtget)
1412 { 1382 {
1413 GNUNET_DHT_get_stop(pi->dhtget); 1383 GNUNET_DHT_get_stop (pi->dhtget);
1414 GNUNET_free (pi->dhtgetcls); 1384 GNUNET_free (pi->dhtgetcls);
1415 } 1385 }
1416 for (i = 0; i < CORE_QUEUE_SIZE; i++) 1386 for (i = 0; i < CORE_QUEUE_SIZE; i++)
1417 { 1387 {
1418 peer_info_cancel_transmission(pi, i); 1388 peer_info_cancel_transmission (pi, i);
1419 } 1389 }
1420 p = pi->path_head; 1390 p = pi->path_head;
1421 while (NULL != p) 1391 while (NULL != p)
@@ -1442,8 +1412,7 @@ peer_info_destroy (struct MeshPeerInfo *pi)
1442 * TODO: optimize (see below) 1412 * TODO: optimize (see below)
1443 */ 1413 */
1444static void 1414static void
1445peer_info_remove_path (struct MeshPeerInfo *peer, 1415peer_info_remove_path (struct MeshPeerInfo *peer, GNUNET_PEER_Id p1,
1446 GNUNET_PEER_Id p1,
1447 GNUNET_PEER_Id p2) 1416 GNUNET_PEER_Id p2)
1448{ 1417{
1449 struct MeshPeerPath *p; 1418 struct MeshPeerPath *p;
@@ -1486,16 +1455,16 @@ peer_info_remove_path (struct MeshPeerInfo *peer,
1486 * Some of them might already have a path to reach them that does not 1455 * Some of them might already have a path to reach them that does not
1487 * involve p1 and p2. Adding all anew might render in a better tree than 1456 * involve p1 and p2. Adding all anew might render in a better tree than
1488 * the trivial immediate fix. 1457 * the trivial immediate fix.
1489 * 1458 *
1490 * Trivial immiediate fix: try to reconnect to the disconnected node. All 1459 * Trivial immiediate fix: try to reconnect to the disconnected node. All
1491 * its children will be reachable trough him. 1460 * its children will be reachable trough him.
1492 */ 1461 */
1493 peer_d = peer_info_get_short(d); 1462 peer_d = peer_info_get_short (d);
1494 best = UINT_MAX; 1463 best = UINT_MAX;
1495 aux = NULL; 1464 aux = NULL;
1496 for (p = peer_d->path_head; NULL != p; p = p->next) 1465 for (p = peer_d->path_head; NULL != p; p = p->next)
1497 { 1466 {
1498 if ((cost = path_get_cost(peer->tunnels[i]->tree, p)) < best) 1467 if ((cost = path_get_cost (peer->tunnels[i]->tree, p)) < best)
1499 { 1468 {
1500 best = cost; 1469 best = cost;
1501 aux = p; 1470 aux = p;
@@ -1504,7 +1473,7 @@ peer_info_remove_path (struct MeshPeerInfo *peer,
1504 if (NULL != aux) 1473 if (NULL != aux)
1505 { 1474 {
1506 /* No callback, as peer will be already disconnected */ 1475 /* No callback, as peer will be already disconnected */
1507 tree_add_path(peer->tunnels[i]->tree, aux, NULL, NULL); 1476 tree_add_path (peer->tunnels[i]->tree, aux, NULL, NULL);
1508 } 1477 }
1509 else 1478 else
1510 { 1479 {
@@ -1524,8 +1493,7 @@ peer_info_remove_path (struct MeshPeerInfo *peer,
1524 * @param trusted Do we trust that this path is real? 1493 * @param trusted Do we trust that this path is real?
1525 */ 1494 */
1526void 1495void
1527peer_info_add_path (struct MeshPeerInfo *peer_info, 1496peer_info_add_path (struct MeshPeerInfo *peer_info, struct MeshPeerPath *path,
1528 struct MeshPeerPath *path,
1529 int trusted) 1497 int trusted)
1530{ 1498{
1531 struct MeshPeerPath *aux; 1499 struct MeshPeerPath *aux;
@@ -1549,28 +1517,24 @@ peer_info_add_path (struct MeshPeerInfo *peer_info,
1549 { 1517 {
1550 if (path->peers[l] == myid) 1518 if (path->peers[l] == myid)
1551 { 1519 {
1552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: shortening path by %u\n", l);
1553 "MESH: shortening path by %u\n", 1521 for (l2 = 0; l2 < path->length - l - 1; l2++)
1554 l);
1555 for (l2 = 0; l2 < path->length - l - 1 ; l2++)
1556 { 1522 {
1557 path->peers[l2] = path->peers[l + l2]; 1523 path->peers[l2] = path->peers[l + l2];
1558 } 1524 }
1559 path->length -= l; 1525 path->length -= l;
1560 l = 1; 1526 l = 1;
1561 path->peers = GNUNET_realloc (path->peers, 1527 path->peers =
1562 path->length * sizeof (GNUNET_PEER_Id)); 1528 GNUNET_realloc (path->peers, path->length * sizeof (GNUNET_PEER_Id));
1563 } 1529 }
1564 } 1530 }
1565#if MESH_DEBUG 1531#if MESH_DEBUG
1566 { 1532 {
1567 struct GNUNET_PeerIdentity id; 1533 struct GNUNET_PeerIdentity id;
1568 1534
1569 GNUNET_PEER_resolve (peer_info->id, &id); 1535 GNUNET_PEER_resolve (peer_info->id, &id);
1570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: adding path [%u] to peer %s\n",
1571 "MESH: adding path [%u] to peer %s\n", 1537 path->length, GNUNET_i2s (&id));
1572 path->length,
1573 GNUNET_i2s (&id));
1574 } 1538 }
1575#endif 1539#endif
1576 l = path_get_length (path); 1540 l = path_get_length (path);
@@ -1587,22 +1551,19 @@ peer_info_add_path (struct MeshPeerInfo *peer_info,
1587 if (l2 > l) 1551 if (l2 > l)
1588 { 1552 {
1589 GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head, 1553 GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head,
1590 peer_info->path_tail, 1554 peer_info->path_tail, aux, path);
1591 aux,
1592 path);
1593 return; 1555 return;
1594 } 1556 }
1595 else 1557 else
1596 { 1558 {
1597 if (l2 == l && memcmp(path->peers, aux->peers, l) == 0) 1559 if (l2 == l && memcmp (path->peers, aux->peers, l) == 0)
1598 { 1560 {
1599 path_destroy(path); 1561 path_destroy (path);
1600 return; 1562 return;
1601 } 1563 }
1602 } 1564 }
1603 } 1565 }
1604 GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, 1566 GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, peer_info->path_tail,
1605 peer_info->path_tail,
1606 path); 1567 path);
1607 return; 1568 return;
1608} 1569}
@@ -1620,10 +1581,9 @@ peer_info_add_path (struct MeshPeerInfo *peer_info,
1620 */ 1581 */
1621static void 1582static void
1622peer_info_add_path_to_origin (struct MeshPeerInfo *peer_info, 1583peer_info_add_path_to_origin (struct MeshPeerInfo *peer_info,
1623 struct MeshPeerPath *path, 1584 struct MeshPeerPath *path, int trusted)
1624 int trusted)
1625{ 1585{
1626 path_invert(path); 1586 path_invert (path);
1627 peer_info_add_path (peer_info, path, trusted); 1587 peer_info_add_path (peer_info, path, trusted);
1628} 1588}
1629 1589
@@ -1646,29 +1606,28 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
1646 1606
1647 p = path_new (1); 1607 p = path_new (1);
1648 p->peers[0] = myid; 1608 p->peers[0] = myid;
1649 GNUNET_PEER_change_rc(myid, 1); 1609 GNUNET_PEER_change_rc (myid, 1);
1650 i = get_path_length; 1610 i = get_path_length;
1651 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i); 1611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i);
1652 for (i--; i >= 0; i--) 1612 for (i--; i >= 0; i--)
1653 { 1613 {
1654 id = GNUNET_PEER_intern (&get_path[i]); 1614 id = GNUNET_PEER_intern (&get_path[i]);
1655 if (p->length > 0 && id == p->peers[p->length - 1]) 1615 if (p->length > 0 && id == p->peers[p->length - 1])
1656 { 1616 {
1657 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); 1617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n");
1658 GNUNET_PEER_change_rc(id, -1); 1618 GNUNET_PEER_change_rc (id, -1);
1659 } 1619 }
1660 else 1620 else
1661 { 1621 {
1662 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Adding from GET: %s.\n",
1663 "MESH: Adding from GET: %s.\n", 1623 GNUNET_i2s (&get_path[i]));
1664 GNUNET_i2s(&get_path[i]));
1665 p->length++; 1624 p->length++;
1666 p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); 1625 p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length);
1667 p->peers[p->length - 1] = id; 1626 p->peers[p->length - 1] = id;
1668 } 1627 }
1669 } 1628 }
1670 i = put_path_length; 1629 i = put_path_length;
1671 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: PUT has %d hops.\n", i); 1630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: PUT has %d hops.\n", i);
1672 for (i--; i >= 0; i--) 1631 for (i--; i >= 0; i--)
1673 { 1632 {
1674 id = GNUNET_PEER_intern (&put_path[i]); 1633 id = GNUNET_PEER_intern (&put_path[i]);
@@ -1682,14 +1641,13 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
1682 } 1641 }
1683 if (p->length > 0 && id == p->peers[p->length - 1]) 1642 if (p->length > 0 && id == p->peers[p->length - 1])
1684 { 1643 {
1685 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); 1644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n");
1686 GNUNET_PEER_change_rc(id, -1); 1645 GNUNET_PEER_change_rc (id, -1);
1687 } 1646 }
1688 else 1647 else
1689 { 1648 {
1690 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Adding from PUT: %s.\n",
1691 "MESH: Adding from PUT: %s.\n", 1650 GNUNET_i2s (&put_path[i]));
1692 GNUNET_i2s(&put_path[i]));
1693 p->length++; 1651 p->length++;
1694 p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); 1652 p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length);
1695 p->peers[p->length - 1] = id; 1653 p->peers[p->length - 1] = id;
@@ -1697,25 +1655,20 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
1697 } 1655 }
1698#if MESH_DEBUG 1656#if MESH_DEBUG
1699 if (get_path_length > 0) 1657 if (get_path_length > 0)
1700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of GET: %s)\n",
1701 "MESH: (first of GET: %s)\n", 1659 GNUNET_i2s (&get_path[0]));
1702 GNUNET_i2s(&get_path[0]));
1703 if (put_path_length > 0) 1660 if (put_path_length > 0)
1704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of PUT: %s)\n",
1705 "MESH: (first of PUT: %s)\n", 1662 GNUNET_i2s (&put_path[0]));
1706 GNUNET_i2s(&put_path[0])); 1663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: In total: %d hops\n",
1707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1708 "MESH: In total: %d hops\n",
1709 p->length); 1664 p->length);
1710 for (i = 0; i < p->length; i++) 1665 for (i = 0; i < p->length; i++)
1711 { 1666 {
1712 struct GNUNET_PeerIdentity peer_id; 1667 struct GNUNET_PeerIdentity peer_id;
1713 1668
1714 GNUNET_PEER_resolve(p->peers[i], &peer_id); 1669 GNUNET_PEER_resolve (p->peers[i], &peer_id);
1715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %u: %s\n", p->peers[i],
1716 "MESH: %u: %s\n", 1671 GNUNET_i2s (&peer_id));
1717 p->peers[i],
1718 GNUNET_i2s(&peer_id));
1719 } 1672 }
1720#endif 1673#endif
1721 return p; 1674 return p;
@@ -1831,6 +1784,7 @@ notify_peer_disconnected (void *cls, GNUNET_PEER_Id peer_id)
1831 if (NULL != t->client && NULL != nc) 1784 if (NULL != t->client && NULL != nc)
1832 { 1785 {
1833 struct GNUNET_MESH_PeerControl msg; 1786 struct GNUNET_MESH_PeerControl msg;
1787
1834 msg.header.size = htons (sizeof (msg)); 1788 msg.header.size = htons (sizeof (msg));
1835 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL); 1789 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
1836 msg.tunnel_id = htonl (t->local_tid); 1790 msg.tunnel_id = htonl (t->local_tid);
@@ -1838,11 +1792,11 @@ notify_peer_disconnected (void *cls, GNUNET_PEER_Id peer_id)
1838 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, 1792 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
1839 &msg.header, GNUNET_NO); 1793 &msg.header, GNUNET_NO);
1840 } 1794 }
1841 peer = peer_info_get_short(peer_id); 1795 peer = peer_info_get_short (peer_id);
1842 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); 1796 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
1843 path_info->peer = peer; 1797 path_info->peer = peer;
1844 path_info->t = t; 1798 path_info->t = t;
1845 GNUNET_SCHEDULER_add_now(&peer_info_connect_task, path_info); 1799 GNUNET_SCHEDULER_add_now (&peer_info_connect_task, path_info);
1846} 1800}
1847 1801
1848 1802
@@ -1864,23 +1818,22 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer)
1864 unsigned int best_cost; 1818 unsigned int best_cost;
1865 unsigned int cost; 1819 unsigned int cost;
1866 1820
1867 GNUNET_PEER_resolve(peer->id, &id); 1821 GNUNET_PEER_resolve (peer->id, &id);
1868 if (GNUNET_NO == 1822 if (GNUNET_NO ==
1869 GNUNET_CONTAINER_multihashmap_contains(t->peers, &id.hashPubKey)) 1823 GNUNET_CONTAINER_multihashmap_contains (t->peers, &id.hashPubKey))
1870 { 1824 {
1871 t->peers_total++; 1825 t->peers_total++;
1872 GNUNET_array_append (peer->tunnels, peer->ntunnels, t); 1826 GNUNET_array_append (peer->tunnels, peer->ntunnels, t);
1873 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( 1827 GNUNET_assert (GNUNET_OK ==
1874 t->peers, 1828 GNUNET_CONTAINER_multihashmap_put (t->peers, &id.hashPubKey,
1875 &id.hashPubKey, 1829 peer,
1876 peer, 1830 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
1877 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
1878 } 1831 }
1879 1832
1880 if (NULL != (p = peer->path_head)) 1833 if (NULL != (p = peer->path_head))
1881 { 1834 {
1882 best_p = p; 1835 best_p = p;
1883 best_cost = path_get_cost(t->tree, p); 1836 best_cost = path_get_cost (t->tree, p);
1884 while (NULL != p) 1837 while (NULL != p)
1885 { 1838 {
1886 if ((cost = path_get_cost (t->tree, p)) < best_cost) 1839 if ((cost = path_get_cost (t->tree, p)) < best_cost)
@@ -1898,7 +1851,7 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer)
1898 else 1851 else
1899 { 1852 {
1900 /* Start a DHT get if necessary */ 1853 /* Start a DHT get if necessary */
1901 peer_info_connect(peer, t); 1854 peer_info_connect (peer, t);
1902 } 1855 }
1903} 1856}
1904 1857
@@ -1913,22 +1866,19 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer)
1913 * 1866 *
1914 */ 1867 */
1915static void 1868static void
1916tunnel_add_path (struct MeshTunnel *t, 1869tunnel_add_path (struct MeshTunnel *t, struct MeshPeerPath *p,
1917 struct MeshPeerPath *p,
1918 unsigned int own_pos) 1870 unsigned int own_pos)
1919{ 1871{
1920 struct GNUNET_PeerIdentity id; 1872 struct GNUNET_PeerIdentity id;
1921 1873
1922 GNUNET_assert (0 != own_pos); 1874 GNUNET_assert (0 != own_pos);
1923 tree_add_path(t->tree, p, NULL, NULL); 1875 tree_add_path (t->tree, p, NULL, NULL);
1924 if (tree_get_me (t->tree) == 0) 1876 if (tree_get_me (t->tree) == 0)
1925 tree_set_me (t->tree, p->peers[own_pos]); 1877 tree_set_me (t->tree, p->peers[own_pos]);
1926 if (own_pos < p->length - 1) 1878 if (own_pos < p->length - 1)
1927 { 1879 {
1928 GNUNET_PEER_resolve (p->peers[own_pos + 1], &id); 1880 GNUNET_PEER_resolve (p->peers[own_pos + 1], &id);
1929 tree_update_first_hops(t->tree, 1881 tree_update_first_hops (t->tree, tree_get_me (t->tree), &id);
1930 tree_get_me (t->tree),
1931 &id);
1932 } 1882 }
1933} 1883}
1934 1884
@@ -1947,24 +1897,21 @@ tunnel_add_path (struct MeshTunnel *t,
1947 * 0 if the tunnel remained unaffected. 1897 * 0 if the tunnel remained unaffected.
1948 */ 1898 */
1949static GNUNET_PEER_Id 1899static GNUNET_PEER_Id
1950tunnel_notify_connection_broken (struct MeshTunnel *t, 1900tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1,
1951 GNUNET_PEER_Id p1,
1952 GNUNET_PEER_Id p2) 1901 GNUNET_PEER_Id p2)
1953{ 1902{
1954 GNUNET_PEER_Id pid; 1903 GNUNET_PEER_Id pid;
1955 1904
1956 pid = tree_notify_connection_broken (t->tree, 1905 pid =
1957 p1, 1906 tree_notify_connection_broken (t->tree, p1, p2, &notify_peer_disconnected,
1958 p2, 1907 t);
1959 &notify_peer_disconnected,
1960 t);
1961 if (myid != p1 && myid != p2) 1908 if (myid != p1 && myid != p2)
1962 { 1909 {
1963 return pid; 1910 return pid;
1964 } 1911 }
1965 if (pid != myid) 1912 if (pid != myid)
1966 { 1913 {
1967 if (tree_get_predecessor(t->tree) != 0) 1914 if (tree_get_predecessor (t->tree) != 0)
1968 { 1915 {
1969 /* We are the peer still connected, notify owner of the disconnection. */ 1916 /* We are the peer still connected, notify owner of the disconnection. */
1970 struct GNUNET_MESH_PathBroken msg; 1917 struct GNUNET_MESH_PathBroken msg;
@@ -2002,8 +1949,7 @@ struct MeshMulticastData
2002 * Send a multicast packet to a neighbor. 1949 * Send a multicast packet to a neighbor.
2003 */ 1950 */
2004static void 1951static void
2005tunnel_send_multicast_iterator (void *cls, 1952tunnel_send_multicast_iterator (void *cls, GNUNET_PEER_Id neighbor_id)
2006 GNUNET_PEER_Id neighbor_id)
2007{ 1953{
2008 struct MeshMulticastData *mdata = cls; 1954 struct MeshMulticastData *mdata = cls;
2009 struct MeshDataDescriptor *info; 1955 struct MeshDataDescriptor *info;
@@ -2025,24 +1971,20 @@ tunnel_send_multicast_iterator (void *cls,
2025 info->destination = neighbor_id; 1971 info->destination = neighbor_id;
2026 GNUNET_PEER_resolve (neighbor_id, &neighbor); 1972 GNUNET_PEER_resolve (neighbor_id, &neighbor);
2027#if MESH_DEBUG 1973#if MESH_DEBUG
2028 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending to %s...\n",
2029 "MESH: sending to %s...\n", 1975 GNUNET_i2s (&neighbor));
2030 GNUNET_i2s (&neighbor));
2031#endif 1976#endif
2032 info->peer = peer_info_get(&neighbor); 1977 info->peer = peer_info_get (&neighbor);
2033 GNUNET_assert (NULL != info->peer); 1978 GNUNET_assert (NULL != info->peer);
2034 i = peer_info_transmit_slot(info->peer); 1979 i = peer_info_transmit_slot (info->peer);
2035 info->handler_n = i; 1980 info->handler_n = i;
2036 info->peer->infos[i] = info; 1981 info->peer->infos[i] = info;
2037 info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST; 1982 info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST;
2038 info->peer->core_transmit[i] = 1983 info->peer->core_transmit[i] =
2039 GNUNET_CORE_notify_transmit_ready (core_handle, 1984 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2040 0, 1985 GNUNET_TIME_UNIT_FOREVER_REL,
2041 0, 1986 &neighbor, info->size,
2042 GNUNET_TIME_UNIT_FOREVER_REL, 1987 &send_core_data_multicast, info);
2043 &neighbor,
2044 info->size,
2045 &send_core_data_multicast, info);
2046} 1988}
2047 1989
2048/** 1990/**
@@ -2072,9 +2014,9 @@ tunnel_send_multicast (struct MeshTunnel *t,
2072 if (NULL != t->client) 2014 if (NULL != t->client)
2073 { 2015 {
2074 mdata->task = GNUNET_malloc (sizeof (GNUNET_SCHEDULER_TaskIdentifier)); 2016 mdata->task = GNUNET_malloc (sizeof (GNUNET_SCHEDULER_TaskIdentifier));
2075 *(mdata->task) = GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT, 2017 *(mdata->task) =
2076 &client_allow_send, 2018 GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT, &client_allow_send,
2077 t->client->handle); 2019 t->client->handle);
2078 } 2020 }
2079 2021
2080 tree_iterate_children (t->tree, &tunnel_send_multicast_iterator, mdata); 2022 tree_iterate_children (t->tree, &tunnel_send_multicast_iterator, mdata);
@@ -2140,11 +2082,9 @@ tunnel_destroy (struct MeshTunnel *t)
2140 { 2082 {
2141 struct GNUNET_PeerIdentity id; 2083 struct GNUNET_PeerIdentity id;
2142 2084
2143 GNUNET_PEER_resolve(t->id.oid, &id); 2085 GNUNET_PEER_resolve (t->id.oid, &id);
2144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: destroying tunnel %s [%x]\n",
2145 "MESH: destroying tunnel %s [%x]\n", 2087 GNUNET_i2s (&id), t->id.tid);
2146 GNUNET_i2s (&id),
2147 t->id.tid);
2148 if (NULL != c) 2088 if (NULL != c)
2149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: by client %u\n", c->id); 2089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: by client %u\n", c->id);
2150 } 2090 }
@@ -2166,12 +2106,13 @@ tunnel_destroy (struct MeshTunnel *t)
2166 { 2106 {
2167 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); 2107 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
2168 GNUNET_break (GNUNET_YES == 2108 GNUNET_break (GNUNET_YES ==
2169 GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash, t)); 2109 GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash,
2110 t));
2170 } 2111 }
2171 if (NULL != t->peers) 2112 if (NULL != t->peers)
2172 { 2113 {
2173 GNUNET_CONTAINER_multihashmap_iterate(t->peers, 2114 GNUNET_CONTAINER_multihashmap_iterate (t->peers, &peer_info_delete_tunnel,
2174 &peer_info_delete_tunnel, t); 2115 t);
2175 GNUNET_CONTAINER_multihashmap_destroy (t->peers); 2116 GNUNET_CONTAINER_multihashmap_destroy (t->peers);
2176 } 2117 }
2177 q = t->queue_head; 2118 q = t->queue_head;
@@ -2184,13 +2125,13 @@ tunnel_destroy (struct MeshTunnel *t)
2184 q = qn; 2125 q = qn;
2185 /* TODO cancel core transmit ready in case it was active */ 2126 /* TODO cancel core transmit ready in case it was active */
2186 } 2127 }
2187 tree_destroy(t->tree); 2128 tree_destroy (t->tree);
2188 if (NULL != t->dht_get_type) 2129 if (NULL != t->dht_get_type)
2189 GNUNET_DHT_get_stop(t->dht_get_type); 2130 GNUNET_DHT_get_stop (t->dht_get_type);
2190 if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task) 2131 if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task)
2191 GNUNET_SCHEDULER_cancel(t->timeout_task); 2132 GNUNET_SCHEDULER_cancel (t->timeout_task);
2192 if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task) 2133 if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task)
2193 GNUNET_SCHEDULER_cancel(t->path_refresh_task); 2134 GNUNET_SCHEDULER_cancel (t->path_refresh_task);
2194 GNUNET_free (t); 2135 GNUNET_free (t);
2195 return r; 2136 return r;
2196} 2137}
@@ -2205,8 +2146,7 @@ tunnel_destroy (struct MeshTunnel *t)
2205 * @param p Peer which should be removed. 2146 * @param p Peer which should be removed.
2206 */ 2147 */
2207static void 2148static void
2208tunnel_delete_peer (struct MeshTunnel *t, 2149tunnel_delete_peer (struct MeshTunnel *t, GNUNET_PEER_Id peer)
2209 GNUNET_PEER_Id peer)
2210{ 2150{
2211 if (GNUNET_NO == tree_del_peer (t->tree, peer, NULL, NULL)) 2151 if (GNUNET_NO == tree_del_peer (t->tree, peer, NULL, NULL))
2212 tunnel_destroy (t); 2152 tunnel_destroy (t);
@@ -2216,11 +2156,11 @@ tunnel_delete_peer (struct MeshTunnel *t,
2216/** 2156/**
2217 * tunnel_destroy_iterator: iterator for deleting each tunnel that belongs to a 2157 * tunnel_destroy_iterator: iterator for deleting each tunnel that belongs to a
2218 * client when the client disconnects. 2158 * client when the client disconnects.
2219 * 2159 *
2220 * @param cls closure (client that is disconnecting) 2160 * @param cls closure (client that is disconnecting)
2221 * @param key the hash of the local tunnel id (used to access the hashmap) 2161 * @param key the hash of the local tunnel id (used to access the hashmap)
2222 * @param value the value stored at the key (tunnel to destroy) 2162 * @param value the value stored at the key (tunnel to destroy)
2223 * 2163 *
2224 * @return GNUNET_OK on success 2164 * @return GNUNET_OK on success
2225 */ 2165 */
2226static int 2166static int
@@ -2261,10 +2201,9 @@ tunnel_reset_timeout (struct MeshTunnel *t)
2261{ 2201{
2262 if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task) 2202 if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task)
2263 GNUNET_SCHEDULER_cancel (t->timeout_task); 2203 GNUNET_SCHEDULER_cancel (t->timeout_task);
2264 t->timeout_task = GNUNET_SCHEDULER_add_delayed ( 2204 t->timeout_task =
2265 GNUNET_TIME_relative_multiply(REFRESH_PATH_TIME, 4), 2205 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2266 &tunnel_timeout, 2206 (REFRESH_PATH_TIME, 4), &tunnel_timeout, t);
2267 t);
2268} 2207}
2269 2208
2270 2209
@@ -2295,8 +2234,7 @@ send_core_create_path (void *cls, size_t size, void *buf)
2295 size_t size_needed; 2234 size_t size_needed;
2296 int i; 2235 int i;
2297 2236
2298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CREATE PATH sending...\n");
2299 "MESH: CREATE PATH sending...\n");
2300 size_needed = 2238 size_needed =
2301 sizeof (struct GNUNET_MESH_ManipulatePath) + 2239 sizeof (struct GNUNET_MESH_ManipulatePath) +
2302 p->length * sizeof (struct GNUNET_PeerIdentity); 2240 p->length * sizeof (struct GNUNET_PeerIdentity);
@@ -2305,15 +2243,15 @@ send_core_create_path (void *cls, size_t size, void *buf)
2305 { 2243 {
2306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: create path retransmit!\n"); 2244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: create path retransmit!\n");
2307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: buf: %p\n", buf); 2245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: buf: %p\n", buf);
2308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: size: (%u/%u)\n", 2246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: size: (%u/%u)\n", size,
2309 size, size_needed); 2247 size_needed);
2310 info->peer->core_transmit[info->pos] = 2248 info->peer->core_transmit[info->pos] =
2311 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, 2249 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2312 GNUNET_TIME_UNIT_FOREVER_REL, 2250 GNUNET_TIME_UNIT_FOREVER_REL,
2313 path_get_first_hop (t->tree, peer->id), 2251 path_get_first_hop (t->tree,
2314 size_needed, 2252 peer->id),
2315 &send_core_create_path, 2253 size_needed, &send_core_create_path,
2316 info); 2254 info);
2317 return 0; 2255 return 0;
2318 } 2256 }
2319 info->peer->core_transmit[info->pos] = NULL; 2257 info->peer->core_transmit[info->pos] = NULL;
@@ -2324,8 +2262,7 @@ send_core_create_path (void *cls, size_t size, void *buf)
2324 GNUNET_PEER_resolve (peer->id, &id); 2262 GNUNET_PEER_resolve (peer->id, &id);
2325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2326 "MESH: setting core_transmit %s [%u] to NULL\n", 2264 "MESH: setting core_transmit %s [%u] to NULL\n",
2327 GNUNET_i2s (&id), 2265 GNUNET_i2s (&id), info->pos);
2328 info->pos);
2329 } 2266 }
2330#endif 2267#endif
2331 msg = (struct GNUNET_MESH_ManipulatePath *) buf; 2268 msg = (struct GNUNET_MESH_ManipulatePath *) buf;
@@ -2343,8 +2280,7 @@ send_core_create_path (void *cls, size_t size, void *buf)
2343 GNUNET_free (info); 2280 GNUNET_free (info);
2344 2281
2345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2346 "MESH: CREATE PATH (%u bytes long) sent!\n", 2283 "MESH: CREATE PATH (%u bytes long) sent!\n", size_needed);
2347 size_needed);
2348 return size_needed; 2284 return size_needed;
2349} 2285}
2350 2286
@@ -2358,7 +2294,7 @@ send_core_create_path (void *cls, size_t size, void *buf)
2358 * @param cls closure (data itself) 2294 * @param cls closure (data itself)
2359 * @param size number of bytes available in buf 2295 * @param size number of bytes available in buf
2360 * @param buf where the callee should write the message 2296 * @param buf where the callee should write the message
2361 * 2297 *
2362 * @return number of bytes written to buf 2298 * @return number of bytes written to buf
2363 */ 2299 */
2364static size_t 2300static size_t
@@ -2379,18 +2315,14 @@ send_core_data_multicast (void *cls, size_t size, void *buf)
2379 struct GNUNET_PeerIdentity id; 2315 struct GNUNET_PeerIdentity id;
2380 2316
2381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2382 "MESH: Multicast: retransmitting... (%u/%u)\n", 2318 "MESH: Multicast: retransmitting... (%u/%u)\n", size,
2383 size, total_size); 2319 total_size);
2384 GNUNET_PEER_resolve(info->peer->id, &id); 2320 GNUNET_PEER_resolve (info->peer->id, &id);
2385 info->peer->core_transmit[info->handler_n] = 2321 info->peer->core_transmit[info->handler_n] =
2386 GNUNET_CORE_notify_transmit_ready (core_handle, 2322 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2387 0, 2323 GNUNET_TIME_UNIT_FOREVER_REL, &id,
2388 0, 2324 total_size,
2389 GNUNET_TIME_UNIT_FOREVER_REL, 2325 &send_core_data_multicast, info);
2390 &id,
2391 total_size,
2392 &send_core_data_multicast,
2393 info);
2394 return 0; 2326 return 0;
2395 } 2327 }
2396 info->peer->core_transmit[info->handler_n] = NULL; 2328 info->peer->core_transmit[info->handler_n] = NULL;
@@ -2408,16 +2340,13 @@ send_core_data_multicast (void *cls, size_t size, void *buf)
2408 mc = (struct GNUNET_MESH_Multicast *) mh; 2340 mc = (struct GNUNET_MESH_Multicast *) mh;
2409 mh = (struct GNUNET_MessageHeader *) &mc[1]; 2341 mh = (struct GNUNET_MessageHeader *) &mc[1];
2410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2411 "MESH: multicast, payload type %u\n", 2343 "MESH: multicast, payload type %u\n", ntohs (mh->type));
2412 ntohs (mh->type));
2413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2414 "MESH: multicast, payload size %u\n", 2345 "MESH: multicast, payload size %u\n", ntohs (mh->size));
2415 ntohs (mh->size));
2416 } 2346 }
2417 else 2347 else
2418 { 2348 {
2419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type %u\n",
2420 "MESH: type %u\n",
2421 ntohs (mh->type)); 2350 ntohs (mh->type));
2422 } 2351 }
2423 } 2352 }
@@ -2483,7 +2412,7 @@ send_core_path_ack (void *cls, size_t size, void *buf)
2483 * @param peer peer identity this notification is about 2412 * @param peer peer identity this notification is about
2484 * @param atsi performance data 2413 * @param atsi performance data
2485 * @param atsi_count number of records in 'atsi' 2414 * @param atsi_count number of records in 'atsi'
2486 * 2415 *
2487 * @return GNUNET_OK to keep the connection open, 2416 * @return GNUNET_OK to keep the connection open,
2488 * GNUNET_SYSERR to close it (signal serious error) 2417 * GNUNET_SYSERR to close it (signal serious error)
2489 */ 2418 */
@@ -2491,7 +2420,7 @@ static int
2491handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, 2420handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2492 const struct GNUNET_MessageHeader *message, 2421 const struct GNUNET_MessageHeader *message,
2493 const struct GNUNET_ATS_Information *atsi, 2422 const struct GNUNET_ATS_Information *atsi,
2494 unsigned int atsi_count) 2423 unsigned int atsi_count)
2495{ 2424{
2496 unsigned int own_pos; 2425 unsigned int own_pos;
2497 uint16_t size; 2426 uint16_t size;
@@ -2507,7 +2436,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2507 2436
2508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2509 "MESH: Received a path create msg [%s]\n", 2438 "MESH: Received a path create msg [%s]\n",
2510 GNUNET_i2s(&my_full_id)); 2439 GNUNET_i2s (&my_full_id));
2511 size = ntohs (message->size); 2440 size = ntohs (message->size);
2512 if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) 2441 if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
2513 { 2442 {
@@ -2527,18 +2456,14 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2527 GNUNET_break_op (0); 2456 GNUNET_break_op (0);
2528 return GNUNET_OK; 2457 return GNUNET_OK;
2529 } 2458 }
2530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: path has %u hops.\n", size);
2531 "MESH: path has %u hops.\n",
2532 size);
2533 msg = (struct GNUNET_MESH_ManipulatePath *) message; 2460 msg = (struct GNUNET_MESH_ManipulatePath *) message;
2534 2461
2535 tid = ntohl (msg->tid); 2462 tid = ntohl (msg->tid);
2536 pi = (struct GNUNET_PeerIdentity *) &msg[1]; 2463 pi = (struct GNUNET_PeerIdentity *) &msg[1];
2537 t = tunnel_get (pi, tid); 2464 t = tunnel_get (pi, tid);
2538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2539 "MESH: path is for tunnel %s [%X].\n", 2466 "MESH: path is for tunnel %s [%X].\n", GNUNET_i2s (pi), tid);
2540 GNUNET_i2s(pi),
2541 tid);
2542 if (NULL == t) 2467 if (NULL == t)
2543 { 2468 {
2544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating tunnel\n"); 2469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating tunnel\n");
@@ -2549,15 +2474,12 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2549 next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; 2474 next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
2550 t->local_tid = next_local_tid++; 2475 t->local_tid = next_local_tid++;
2551 next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; 2476 next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
2552 t->tree = tree_new(t->id.oid); 2477 t->tree = tree_new (t->id.oid);
2553 2478
2554 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); 2479 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
2555 if (GNUNET_OK != 2480 if (GNUNET_OK !=
2556 GNUNET_CONTAINER_multihashmap_put ( 2481 GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t,
2557 tunnels, 2482 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
2558 &hash,
2559 t,
2560 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
2561 { 2483 {
2562 tunnel_destroy (t); 2484 tunnel_destroy (t);
2563 GNUNET_break (0); 2485 GNUNET_break (0);
@@ -2566,11 +2488,8 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2566 tunnel_reset_timeout (t); 2488 tunnel_reset_timeout (t);
2567 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); 2489 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
2568 if (GNUNET_OK != 2490 if (GNUNET_OK !=
2569 GNUNET_CONTAINER_multihashmap_put ( 2491 GNUNET_CONTAINER_multihashmap_put (incoming_tunnels, &hash, t,
2570 incoming_tunnels, 2492 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
2571 &hash,
2572 t,
2573 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
2574 { 2493 {
2575 tunnel_destroy (t); 2494 tunnel_destroy (t);
2576 GNUNET_break (0); 2495 GNUNET_break (0);
@@ -2604,15 +2523,13 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2604 own_pos = 0; 2523 own_pos = 0;
2605 for (i = 0; i < size; i++) 2524 for (i = 0; i < size; i++)
2606 { 2525 {
2607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... adding %s\n",
2608 "MESH: ... adding %s\n", 2527 GNUNET_i2s (&pi[i]));
2609 GNUNET_i2s(&pi[i]));
2610 path->peers[i] = GNUNET_PEER_intern (&pi[i]); 2528 path->peers[i] = GNUNET_PEER_intern (&pi[i]);
2611 if (path->peers[i] == myid) 2529 if (path->peers[i] == myid)
2612 own_pos = i; 2530 own_pos = i;
2613 } 2531 }
2614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Own position: %u\n", own_pos);
2615 "MESH: Own position: %u\n", own_pos);
2616 if (own_pos == 0) 2533 if (own_pos == 0)
2617 { 2534 {
2618 /* cannot be self, must be 'not found' */ 2535 /* cannot be self, must be 'not found' */
@@ -2630,22 +2547,22 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2630 struct MeshDataDescriptor *info; 2547 struct MeshDataDescriptor *info;
2631 unsigned int j; 2548 unsigned int j;
2632 2549
2633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: It's for us!\n");
2634 "MESH: It's for us!\n");
2635 peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO); 2551 peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO);
2636 if (NULL == t->peers) 2552 if (NULL == t->peers)
2637 t->peers = GNUNET_CONTAINER_multihashmap_create(4); 2553 t->peers = GNUNET_CONTAINER_multihashmap_create (4);
2638 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( 2554 GNUNET_break (GNUNET_OK ==
2639 t->peers, 2555 GNUNET_CONTAINER_multihashmap_put (t->peers,
2640 &my_full_id.hashPubKey, 2556 &my_full_id.hashPubKey,
2641 peer_info_get(&my_full_id), 2557 peer_info_get
2642 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 2558 (&my_full_id),
2559 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
2643 /* FIXME use send_message */ 2560 /* FIXME use send_message */
2644 info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); 2561 info = GNUNET_malloc (sizeof (struct MeshDataDescriptor));
2645 info->origin = &t->id; 2562 info->origin = &t->id;
2646 info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); 2563 info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
2647 GNUNET_assert (NULL != info->peer); 2564 GNUNET_assert (NULL != info->peer);
2648 j = peer_info_transmit_slot(info->peer); 2565 j = peer_info_transmit_slot (info->peer);
2649 info->handler_n = j; 2566 info->handler_n = j;
2650 info->peer->types[j] = GNUNET_MESSAGE_TYPE_MESH_PATH_ACK; 2567 info->peer->types[j] = GNUNET_MESSAGE_TYPE_MESH_PATH_ACK;
2651 info->peer->infos[j] = info; 2568 info->peer->infos[j] = info;
@@ -2654,24 +2571,23 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2654 GNUNET_TIME_UNIT_FOREVER_REL, peer, 2571 GNUNET_TIME_UNIT_FOREVER_REL, peer,
2655 sizeof (struct GNUNET_MESH_PathACK), 2572 sizeof (struct GNUNET_MESH_PathACK),
2656 &send_core_path_ack, info); 2573 &send_core_path_ack, info);
2657 cmsg.header.size = htons(sizeof(cmsg)); 2574 cmsg.header.size = htons (sizeof (cmsg));
2658 cmsg.header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); 2575 cmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
2659 GNUNET_PEER_resolve(t->id.oid, &cmsg.peer); 2576 GNUNET_PEER_resolve (t->id.oid, &cmsg.peer);
2660 cmsg.tunnel_id = htonl(t->local_tid); 2577 cmsg.tunnel_id = htonl (t->local_tid);
2661 GNUNET_SERVER_notification_context_broadcast(nc, &cmsg.header, GNUNET_NO); 2578 GNUNET_SERVER_notification_context_broadcast (nc, &cmsg.header, GNUNET_NO);
2662 } 2579 }
2663 else 2580 else
2664 { 2581 {
2665 struct MeshPeerPath *path2; 2582 struct MeshPeerPath *path2;
2666 2583
2667 /* It's for somebody else! Retransmit. */ 2584 /* It's for somebody else! Retransmit. */
2668 path2 = path_duplicate(path); 2585 path2 = path_duplicate (path);
2669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Retransmitting.\n");
2670 "MESH: Retransmitting.\n"); 2587 peer_info_add_path (dest_peer_info, path2, GNUNET_NO);
2671 peer_info_add_path(dest_peer_info, path2, GNUNET_NO); 2588 path2 = path_duplicate (path);
2672 path2 = path_duplicate(path); 2589 peer_info_add_path_to_origin (orig_peer_info, path2, GNUNET_NO);
2673 peer_info_add_path_to_origin(orig_peer_info, path2, GNUNET_NO); 2590 send_create_path (dest_peer_info, path, t);
2674 send_create_path(dest_peer_info, path, t);
2675 } 2591 }
2676 return GNUNET_OK; 2592 return GNUNET_OK;
2677} 2593}
@@ -2693,7 +2609,7 @@ static int
2693handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, 2609handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2694 const struct GNUNET_MessageHeader *message, 2610 const struct GNUNET_MessageHeader *message,
2695 const struct GNUNET_ATS_Information *atsi, 2611 const struct GNUNET_ATS_Information *atsi,
2696 unsigned int atsi_count) 2612 unsigned int atsi_count)
2697{ 2613{
2698 struct GNUNET_MESH_ManipulatePath *msg; 2614 struct GNUNET_MESH_ManipulatePath *msg;
2699 struct GNUNET_PeerIdentity *pi; 2615 struct GNUNET_PeerIdentity *pi;
@@ -2704,8 +2620,7 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2704 size_t size; 2620 size_t size;
2705 2621
2706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2707 "MESH: Received a PATH DESTROY msg from %s\n", 2623 "MESH: Received a PATH DESTROY msg from %s\n", GNUNET_i2s (peer));
2708 GNUNET_i2s(peer));
2709 size = ntohs (message->size); 2624 size = ntohs (message->size);
2710 if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) 2625 if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
2711 { 2626 {
@@ -2725,15 +2640,12 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2725 GNUNET_break_op (0); 2640 GNUNET_break_op (0);
2726 return GNUNET_OK; 2641 return GNUNET_OK;
2727 } 2642 }
2728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: path has %u hops.\n", size);
2729 "MESH: path has %u hops.\n",
2730 size);
2731 2644
2732 msg = (struct GNUNET_MESH_ManipulatePath *) message; 2645 msg = (struct GNUNET_MESH_ManipulatePath *) message;
2733 pi = (struct GNUNET_PeerIdentity *) &msg[1]; 2646 pi = (struct GNUNET_PeerIdentity *) &msg[1];
2734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2735 "MESH: path is for tunnel %s [%X].\n", 2648 "MESH: path is for tunnel %s [%X].\n", GNUNET_i2s (pi),
2736 GNUNET_i2s(pi),
2737 msg->tid); 2649 msg->tid);
2738 t = tunnel_get (pi, ntohl (msg->tid)); 2650 t = tunnel_get (pi, ntohl (msg->tid));
2739 if (NULL == t) 2651 if (NULL == t)
@@ -2747,15 +2659,13 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2747 own_pos = 0; 2659 own_pos = 0;
2748 for (i = 0; i < size; i++) 2660 for (i = 0; i < size; i++)
2749 { 2661 {
2750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... adding %s\n",
2751 "MESH: ... adding %s\n", 2663 GNUNET_i2s (&pi[i]));
2752 GNUNET_i2s(&pi[i]));
2753 path->peers[i] = GNUNET_PEER_intern (&pi[i]); 2664 path->peers[i] = GNUNET_PEER_intern (&pi[i]);
2754 if (path->peers[i] == myid) 2665 if (path->peers[i] == myid)
2755 own_pos = i; 2666 own_pos = i;
2756 } 2667 }
2757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Own position: %u\n", own_pos);
2758 "MESH: Own position: %u\n", own_pos);
2759 if (own_pos < path->length - 1) 2669 if (own_pos < path->length - 1)
2760 send_message (message, &pi[own_pos + 1]); 2670 send_message (message, &pi[own_pos + 1]);
2761 tunnel_delete_peer (t, path->peers[path->length - 1]); 2671 tunnel_delete_peer (t, path->peers[path->length - 1]);
@@ -2778,32 +2688,28 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2778 */ 2688 */
2779static int 2689static int
2780handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer, 2690handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
2781 const struct GNUNET_MessageHeader *message, 2691 const struct GNUNET_MessageHeader *message,
2782 const struct GNUNET_ATS_Information *atsi, 2692 const struct GNUNET_ATS_Information *atsi,
2783 unsigned int atsi_count) 2693 unsigned int atsi_count)
2784{ 2694{
2785 struct GNUNET_MESH_PathBroken *msg; 2695 struct GNUNET_MESH_PathBroken *msg;
2786 struct MeshTunnel *t; 2696 struct MeshTunnel *t;
2787 2697
2788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2789 "MESH: Received a PATH BROKEN msg from %s\n", 2699 "MESH: Received a PATH BROKEN msg from %s\n", GNUNET_i2s (peer));
2790 GNUNET_i2s(peer));
2791 msg = (struct GNUNET_MESH_PathBroken *) message; 2700 msg = (struct GNUNET_MESH_PathBroken *) message;
2792 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: regarding %s\n",
2793 "MESH: regarding %s\n", 2702 GNUNET_i2s (&msg->peer1));
2794 GNUNET_i2s(&msg->peer1)); 2703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: regarding %s\n",
2795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2704 GNUNET_i2s (&msg->peer2));
2796 "MESH: regarding %s\n", 2705 t = tunnel_get (&msg->oid, ntohl (msg->tid));
2797 GNUNET_i2s(&msg->peer2));
2798 t = tunnel_get(&msg->oid, ntohl (msg->tid));
2799 if (NULL == t) 2706 if (NULL == t)
2800 { 2707 {
2801 GNUNET_break_op (0); 2708 GNUNET_break_op (0);
2802 return GNUNET_OK; 2709 return GNUNET_OK;
2803 } 2710 }
2804 tunnel_notify_connection_broken(t, 2711 tunnel_notify_connection_broken (t, GNUNET_PEER_search (&msg->peer1),
2805 GNUNET_PEER_search(&msg->peer1), 2712 GNUNET_PEER_search (&msg->peer2));
2806 GNUNET_PEER_search(&msg->peer2));
2807 return GNUNET_OK; 2713 return GNUNET_OK;
2808 2714
2809} 2715}
@@ -2825,19 +2731,16 @@ static int
2825handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, 2731handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2826 const struct GNUNET_MessageHeader *message, 2732 const struct GNUNET_MessageHeader *message,
2827 const struct GNUNET_ATS_Information *atsi, 2733 const struct GNUNET_ATS_Information *atsi,
2828 unsigned int atsi_count) 2734 unsigned int atsi_count)
2829{ 2735{
2830 struct GNUNET_MESH_TunnelDestroy *msg; 2736 struct GNUNET_MESH_TunnelDestroy *msg;
2831 struct MeshTunnel *t; 2737 struct MeshTunnel *t;
2832 2738
2833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2834 "MESH: Got a TUNNEL DESTROY packet from %s\n", 2740 "MESH: Got a TUNNEL DESTROY packet from %s\n", GNUNET_i2s (peer));
2835 GNUNET_i2s (peer));
2836 msg = (struct GNUNET_MESH_TunnelDestroy *) message; 2741 msg = (struct GNUNET_MESH_TunnelDestroy *) message;
2837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for tunnel %s [%u]\n",
2838 "MESH: for tunnel %s [%u]\n", 2743 GNUNET_i2s (&msg->oid), ntohl (msg->tid));
2839 GNUNET_i2s (&msg->oid),
2840 ntohl (msg->tid));
2841 t = tunnel_get (&msg->oid, ntohl (msg->tid)); 2744 t = tunnel_get (&msg->oid, ntohl (msg->tid));
2842 if (NULL == t) 2745 if (NULL == t)
2843 { 2746 {
@@ -2878,15 +2781,14 @@ static int
2878handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, 2781handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2879 const struct GNUNET_MessageHeader *message, 2782 const struct GNUNET_MessageHeader *message,
2880 const struct GNUNET_ATS_Information *atsi, 2783 const struct GNUNET_ATS_Information *atsi,
2881 unsigned int atsi_count) 2784 unsigned int atsi_count)
2882{ 2785{
2883 struct GNUNET_MESH_Unicast *msg; 2786 struct GNUNET_MESH_Unicast *msg;
2884 struct MeshTunnel *t; 2787 struct MeshTunnel *t;
2885 GNUNET_PEER_Id pid; 2788 GNUNET_PEER_Id pid;
2886 size_t size; 2789 size_t size;
2887 2790
2888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a unicast packet from %s\n",
2889 "MESH: got a unicast packet from %s\n",
2890 GNUNET_i2s (peer)); 2792 GNUNET_i2s (peer));
2891 size = ntohs (message->size); 2793 size = ntohs (message->size);
2892 if (size < 2794 if (size <
@@ -2897,8 +2799,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2897 return GNUNET_OK; 2799 return GNUNET_OK;
2898 } 2800 }
2899 msg = (struct GNUNET_MESH_Unicast *) message; 2801 msg = (struct GNUNET_MESH_Unicast *) message;
2900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: of type %u\n",
2901 "MESH: of type %u\n",
2902 ntohs (msg[1].header.type)); 2803 ntohs (msg[1].header.type));
2903 t = tunnel_get (&msg->oid, ntohl (msg->tid)); 2804 t = tunnel_get (&msg->oid, ntohl (msg->tid));
2904 if (NULL == t) 2805 if (NULL == t)
@@ -2908,7 +2809,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2908 return GNUNET_OK; 2809 return GNUNET_OK;
2909 } 2810 }
2910 tunnel_reset_timeout (t); 2811 tunnel_reset_timeout (t);
2911 pid = GNUNET_PEER_search(&msg->destination); 2812 pid = GNUNET_PEER_search (&msg->destination);
2912 if (pid == myid) 2813 if (pid == myid)
2913 { 2814 {
2914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2918,7 +2819,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2918 } 2819 }
2919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2920 "MESH: not for us, retransmitting...\n"); 2821 "MESH: not for us, retransmitting...\n");
2921 send_message (message, path_get_first_hop(t->tree, pid)); 2822 send_message (message, path_get_first_hop (t->tree, pid));
2922 return GNUNET_OK; 2823 return GNUNET_OK;
2923} 2824}
2924 2825
@@ -2940,14 +2841,13 @@ static int
2940handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, 2841handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2941 const struct GNUNET_MessageHeader *message, 2842 const struct GNUNET_MessageHeader *message,
2942 const struct GNUNET_ATS_Information *atsi, 2843 const struct GNUNET_ATS_Information *atsi,
2943 unsigned int atsi_count) 2844 unsigned int atsi_count)
2944{ 2845{
2945 struct GNUNET_MESH_Multicast *msg; 2846 struct GNUNET_MESH_Multicast *msg;
2946 struct MeshTunnel *t; 2847 struct MeshTunnel *t;
2947 size_t size; 2848 size_t size;
2948 2849
2949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a multicast packet from %s\n",
2950 "MESH: got a multicast packet from %s\n",
2951 GNUNET_i2s (peer)); 2851 GNUNET_i2s (peer));
2952 size = ntohs (message->size); 2852 size = ntohs (message->size);
2953 if (sizeof (struct GNUNET_MESH_Multicast) + 2853 if (sizeof (struct GNUNET_MESH_Multicast) +
@@ -2973,7 +2873,7 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2973 { 2873 {
2974 send_subscribed_clients (message, &msg[1].header); 2874 send_subscribed_clients (message, &msg[1].header);
2975 } 2875 }
2976 tunnel_send_multicast(t, message); 2876 tunnel_send_multicast (t, message);
2977 return GNUNET_OK; 2877 return GNUNET_OK;
2978} 2878}
2979 2879
@@ -2994,7 +2894,7 @@ static int
2994handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, 2894handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
2995 const struct GNUNET_MessageHeader *message, 2895 const struct GNUNET_MessageHeader *message,
2996 const struct GNUNET_ATS_Information *atsi, 2896 const struct GNUNET_ATS_Information *atsi,
2997 unsigned int atsi_count) 2897 unsigned int atsi_count)
2998{ 2898{
2999 struct GNUNET_MESH_ToOrigin *msg; 2899 struct GNUNET_MESH_ToOrigin *msg;
3000 struct GNUNET_PeerIdentity id; 2900 struct GNUNET_PeerIdentity id;
@@ -3002,8 +2902,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3002 struct MeshTunnel *t; 2902 struct MeshTunnel *t;
3003 size_t size; 2903 size_t size;
3004 2904
3005 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a ToOrigin packet from %s\n",
3006 "MESH: got a ToOrigin packet from %s\n",
3007 GNUNET_i2s (peer)); 2906 GNUNET_i2s (peer));
3008 size = ntohs (message->size); 2907 size = ntohs (message->size);
3009 if (size < sizeof (struct GNUNET_MESH_ToOrigin) + /* Payload must be */ 2908 if (size < sizeof (struct GNUNET_MESH_ToOrigin) + /* Payload must be */
@@ -3013,8 +2912,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3013 return GNUNET_OK; 2912 return GNUNET_OK;
3014 } 2913 }
3015 msg = (struct GNUNET_MESH_ToOrigin *) message; 2914 msg = (struct GNUNET_MESH_ToOrigin *) message;
3016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: of type %u\n",
3017 "MESH: of type %u\n",
3018 ntohs (msg[1].header.type)); 2916 ntohs (msg[1].header.type));
3019 t = tunnel_get (&msg->oid, ntohl (msg->tid)); 2917 t = tunnel_get (&msg->oid, ntohl (msg->tid));
3020 2918
@@ -3035,8 +2933,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3035 if (NULL == t->client) 2933 if (NULL == t->client)
3036 { 2934 {
3037 /* got data packet for ownerless tunnel */ 2935 /* got data packet for ownerless tunnel */
3038 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2936 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: no clients!\n");
3039 "MESH: no clients!\n");
3040 GNUNET_break_op (0); 2937 GNUNET_break_op (0);
3041 return GNUNET_OK; 2938 return GNUNET_OK;
3042 } 2939 }
@@ -3044,10 +2941,8 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3044 memcpy (cbuf, message, size); 2941 memcpy (cbuf, message, size);
3045 copy = (struct GNUNET_MESH_ToOrigin *) cbuf; 2942 copy = (struct GNUNET_MESH_ToOrigin *) cbuf;
3046 copy->tid = htonl (t->local_tid); 2943 copy->tid = htonl (t->local_tid);
3047 GNUNET_SERVER_notification_context_unicast (nc, 2944 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
3048 t->client->handle, 2945 &copy->header, GNUNET_YES);
3049 &copy->header,
3050 GNUNET_YES);
3051 return GNUNET_OK; 2946 return GNUNET_OK;
3052 } 2947 }
3053 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3060,7 +2955,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3060 GNUNET_break (0); 2955 GNUNET_break (0);
3061 return GNUNET_OK; 2956 return GNUNET_OK;
3062 } 2957 }
3063 GNUNET_PEER_resolve (tree_get_predecessor(t->tree), &id); 2958 GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
3064 send_message (message, &id); 2959 send_message (message, &id);
3065 2960
3066 return GNUNET_OK; 2961 return GNUNET_OK;
@@ -3083,16 +2978,15 @@ static int
3083handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, 2978handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
3084 const struct GNUNET_MessageHeader *message, 2979 const struct GNUNET_MessageHeader *message,
3085 const struct GNUNET_ATS_Information *atsi, 2980 const struct GNUNET_ATS_Information *atsi,
3086 unsigned int atsi_count) 2981 unsigned int atsi_count)
3087{ 2982{
3088 struct GNUNET_MESH_PathACK *msg; 2983 struct GNUNET_MESH_PathACK *msg;
3089 struct GNUNET_PeerIdentity id; 2984 struct GNUNET_PeerIdentity id;
3090 struct MeshPeerInfo *peer_info; 2985 struct MeshPeerInfo *peer_info;
3091 struct MeshTunnel *t; 2986 struct MeshTunnel *t;
3092 2987
3093 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Received a path ACK msg [%s]\n",
3094 "MESH: Received a path ACK msg [%s]\n", 2989 GNUNET_i2s (&my_full_id));
3095 GNUNET_i2s(&my_full_id));
3096 msg = (struct GNUNET_MESH_PathACK *) message; 2990 msg = (struct GNUNET_MESH_PathACK *) message;
3097 t = tunnel_get (&msg->oid, msg->tid); 2991 t = tunnel_get (&msg->oid, msg->tid);
3098 if (NULL == t) 2992 if (NULL == t)
@@ -3116,14 +3010,14 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
3116 t->dht_get_type = NULL; 3010 t->dht_get_type = NULL;
3117 } 3011 }
3118 peer_info = peer_info_get (&msg->peer_id); 3012 peer_info = peer_info_get (&msg->peer_id);
3119 tree_set_status(t->tree, peer_info->id, MESH_PEER_READY); 3013 tree_set_status (t->tree, peer_info->id, MESH_PEER_READY);
3120 send_client_peer_connected(t, peer_info->id); 3014 send_client_peer_connected (t, peer_info->id);
3121 return GNUNET_OK; 3015 return GNUNET_OK;
3122 } 3016 }
3123 3017
3124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3125 "MESH: not for us, retransmitting...\n"); 3019 "MESH: not for us, retransmitting...\n");
3126 GNUNET_PEER_resolve(tree_get_predecessor(t->tree), &id); 3020 GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
3127 peer_info = peer_info_get (&msg->oid); 3021 peer_info = peer_info_get (&msg->oid);
3128 if (NULL == peer_info) 3022 if (NULL == peer_info)
3129 { 3023 {
@@ -3143,13 +3037,13 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
3143 {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0}, 3037 {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0},
3144 {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0}, 3038 {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0},
3145 {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN, 3039 {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN,
3146 sizeof (struct GNUNET_MESH_PathBroken)}, 3040 sizeof (struct GNUNET_MESH_PathBroken)},
3147 {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 0}, 3041 {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 0},
3148 {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, 3042 {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
3149 {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, 3043 {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0},
3150 {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, 3044 {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0},
3151 {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, 3045 {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK,
3152 sizeof (struct GNUNET_MESH_PathACK)}, 3046 sizeof (struct GNUNET_MESH_PathACK)},
3153 {NULL, 0, 0} 3047 {NULL, 0, 0}
3154}; 3048};
3155 3049
@@ -3161,18 +3055,19 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
3161 3055
3162/** 3056/**
3163 * deregister_app: iterator for removing each application registered by a client 3057 * deregister_app: iterator for removing each application registered by a client
3164 * 3058 *
3165 * @param cls closure 3059 * @param cls closure
3166 * @param key the hash of the application id (used to access the hashmap) 3060 * @param key the hash of the application id (used to access the hashmap)
3167 * @param value the value stored at the key (client) 3061 * @param value the value stored at the key (client)
3168 * 3062 *
3169 * @return GNUNET_OK on success 3063 * @return GNUNET_OK on success
3170 */ 3064 */
3171static int 3065static int
3172deregister_app (void *cls, const GNUNET_HashCode * key, void *value) 3066deregister_app (void *cls, const GNUNET_HashCode * key, void *value)
3173{ 3067{
3174 GNUNET_break (GNUNET_YES == 3068 GNUNET_break (GNUNET_YES ==
3175 GNUNET_CONTAINER_multihashmap_remove (applications, key, value)); 3069 GNUNET_CONTAINER_multihashmap_remove (applications, key,
3070 value));
3176 return GNUNET_OK; 3071 return GNUNET_OK;
3177} 3072}
3178 3073
@@ -3230,8 +3125,9 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3230 struct MeshTunnel *t = cls; 3125 struct MeshTunnel *t = cls;
3231 struct GNUNET_MessageHeader *payload; 3126 struct GNUNET_MessageHeader *payload;
3232 struct GNUNET_MESH_Multicast *msg; 3127 struct GNUNET_MESH_Multicast *msg;
3233 size_t size = sizeof(struct GNUNET_MESH_Multicast) + 3128 size_t size =
3234 sizeof(struct GNUNET_MessageHeader); 3129 sizeof (struct GNUNET_MESH_Multicast) +
3130 sizeof (struct GNUNET_MessageHeader);
3235 char cbuf[size]; 3131 char cbuf[size];
3236 3132
3237 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 3133 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
@@ -3241,16 +3137,15 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3241 t->path_refresh_task = GNUNET_SCHEDULER_NO_TASK; 3137 t->path_refresh_task = GNUNET_SCHEDULER_NO_TASK;
3242 3138
3243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3244 "MESH: sending keepalive for tunnel %d\n", 3140 "MESH: sending keepalive for tunnel %d\n", t->id.tid);
3245 t->id.tid);
3246 3141
3247 msg = (struct GNUNET_MESH_Multicast *) cbuf; 3142 msg = (struct GNUNET_MESH_Multicast *) cbuf;
3248 msg->header.size = htons (size); 3143 msg->header.size = htons (size);
3249 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); 3144 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
3250 msg->oid = my_full_id; 3145 msg->oid = my_full_id;
3251 msg->tid = htonl(t->id.tid); 3146 msg->tid = htonl (t->id.tid);
3252 payload = (struct GNUNET_MessageHeader *) &msg[1]; 3147 payload = (struct GNUNET_MessageHeader *) &msg[1];
3253 payload->size = htons (sizeof(struct GNUNET_MessageHeader)); 3148 payload->size = htons (sizeof (struct GNUNET_MessageHeader));
3254 payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE); 3149 payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE);
3255 tunnel_send_multicast (t, &msg->header); 3150 tunnel_send_multicast (t, &msg->header);
3256 3151
@@ -3280,30 +3175,27 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
3280 const struct GNUNET_PeerIdentity *get_path, 3175 const struct GNUNET_PeerIdentity *get_path,
3281 unsigned int get_path_length, 3176 unsigned int get_path_length,
3282 const struct GNUNET_PeerIdentity *put_path, 3177 const struct GNUNET_PeerIdentity *put_path,
3283 unsigned int put_path_length, 3178 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
3284 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 3179 size_t size, const void *data)
3285{ 3180{
3286 struct MeshPathInfo *path_info = cls; 3181 struct MeshPathInfo *path_info = cls;
3287 struct MeshPeerPath *p; 3182 struct MeshPeerPath *p;
3288 struct GNUNET_PeerIdentity pi; 3183 struct GNUNET_PeerIdentity pi;
3289 int i; 3184 int i;
3290 3185
3291 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got results from DHT!\n");
3292 "MESH: Got results from DHT!\n");
3293 GNUNET_PEER_resolve (path_info->peer->id, &pi); 3187 GNUNET_PEER_resolve (path_info->peer->id, &pi);
3294 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", GNUNET_i2s (&pi));
3295 "MESH: for %s\n",
3296 GNUNET_i2s(&pi));
3297// GNUNET_DHT_get_stop(path_info->peer->dhtget); 3189// GNUNET_DHT_get_stop(path_info->peer->dhtget);
3298// path_info->peer->dhtget = NULL; 3190// path_info->peer->dhtget = NULL;
3299 3191
3300 p = path_build_from_dht (get_path, get_path_length, 3192 p = path_build_from_dht (get_path, get_path_length, put_path,
3301 put_path, put_path_length); 3193 put_path_length);
3302 peer_info_add_path (path_info->peer, p, GNUNET_NO); 3194 peer_info_add_path (path_info->peer, p, GNUNET_NO);
3303 for (i = 0; i < path_info->peer->ntunnels; i++) 3195 for (i = 0; i < path_info->peer->ntunnels; i++)
3304 { 3196 {
3305 tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer); 3197 tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer);
3306 peer_info_connect(path_info->peer, path_info->t); 3198 peer_info_connect (path_info->peer, path_info->t);
3307 } 3199 }
3308// GNUNET_free (path_info); 3200// GNUNET_free (path_info);
3309 3201
@@ -3327,11 +3219,10 @@ static void
3327dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, 3219dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
3328 const GNUNET_HashCode * key, 3220 const GNUNET_HashCode * key,
3329 const struct GNUNET_PeerIdentity *get_path, 3221 const struct GNUNET_PeerIdentity *get_path,
3330 unsigned int get_path_length, 3222 unsigned int get_path_length,
3331 const struct GNUNET_PeerIdentity *put_path, 3223 const struct GNUNET_PeerIdentity *put_path,
3332 unsigned int put_path_length, 3224 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
3333 enum GNUNET_BLOCK_Type type, size_t size, 3225 size_t size, const void *data)
3334 const void *data)
3335{ 3226{
3336 const struct GNUNET_PeerIdentity *pi = data; 3227 const struct GNUNET_PeerIdentity *pi = data;
3337 struct MeshTunnel *t = cls; 3228 struct MeshTunnel *t = cls;
@@ -3345,16 +3236,14 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
3345 } 3236 }
3346 GNUNET_assert (NULL != t->client); 3237 GNUNET_assert (NULL != t->client);
3347 peer_info = peer_info_get (pi); 3238 peer_info = peer_info_get (pi);
3348 (void) GNUNET_CONTAINER_multihashmap_put ( 3239 (void) GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey,
3349 t->peers, 3240 peer_info,
3350 &pi->hashPubKey, 3241 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
3351 peer_info, 3242
3352 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 3243 p = path_build_from_dht (get_path, get_path_length, put_path,
3353 3244 put_path_length);
3354 p = path_build_from_dht (get_path, get_path_length,
3355 put_path, put_path_length);
3356 peer_info_add_path (peer_info, p, GNUNET_NO); 3245 peer_info_add_path (peer_info, p, GNUNET_NO);
3357 tunnel_add_peer(t, peer_info); 3246 tunnel_add_peer (t, peer_info);
3358 peer_info_connect (peer_info, t); 3247 peer_info_connect (peer_info, t);
3359} 3248}
3360 3249
@@ -3397,8 +3286,7 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
3397 if (NULL != c->tunnels) 3286 if (NULL != c->tunnels)
3398 { 3287 {
3399 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, 3288 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels,
3400 &tunnel_destroy_iterator, 3289 &tunnel_destroy_iterator, c);
3401 c);
3402 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); 3290 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels);
3403 } 3291 }
3404 3292
@@ -3467,7 +3355,8 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
3467#if MESH_DEBUG 3355#if MESH_DEBUG
3468 c->id = next_client_id++; 3356 c->id = next_client_id++;
3469#endif 3357#endif
3470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CLIENT NEW %u at %p\n", c->id, c); 3358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CLIENT NEW %u at %p\n", c->id,
3359 c);
3471 c->handle = client; 3360 c->handle = client;
3472 GNUNET_SERVER_client_keep (client); 3361 GNUNET_SERVER_client_keep (client);
3473 a = (GNUNET_MESH_ApplicationType *) &cc_msg[1]; 3362 a = (GNUNET_MESH_ApplicationType *) &cc_msg[1];
@@ -3589,20 +3478,16 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
3589 t->id.oid = myid; 3478 t->id.oid = myid;
3590 t->local_tid = ntohl (t_msg->tunnel_id); 3479 t->local_tid = ntohl (t_msg->tunnel_id);
3591#if MESH_DEBUG 3480#if MESH_DEBUG
3592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CREATED TUNNEL %s [%x] (%x)\n",
3593 "MESH: CREATED TUNNEL %s [%x] (%x)\n", 3482 GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid);
3594 GNUNET_i2s (&my_full_id),
3595 t->id.tid,
3596 t->local_tid);
3597#endif 3483#endif
3598 t->client = c; 3484 t->client = c;
3599 t->peers = GNUNET_CONTAINER_multihashmap_create (32); 3485 t->peers = GNUNET_CONTAINER_multihashmap_create (32);
3600 3486
3601 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); 3487 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
3602 if (GNUNET_OK != 3488 if (GNUNET_OK !=
3603 GNUNET_CONTAINER_multihashmap_put ( 3489 GNUNET_CONTAINER_multihashmap_put (c->tunnels, &hash, t,
3604 c->tunnels, &hash, t, 3490 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
3605 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
3606 { 3491 {
3607 GNUNET_break (0); 3492 GNUNET_break (0);
3608 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3493 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -3611,16 +3496,15 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
3611 3496
3612 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); 3497 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
3613 if (GNUNET_OK != 3498 if (GNUNET_OK !=
3614 GNUNET_CONTAINER_multihashmap_put ( 3499 GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t,
3615 tunnels, &hash, t, 3500 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
3616 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
3617 { 3501 {
3618 GNUNET_break (0); 3502 GNUNET_break (0);
3619 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3503 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3620 return; 3504 return;
3621 } 3505 }
3622 t->tree = tree_new (myid); 3506 t->tree = tree_new (myid);
3623 tree_set_me(t->tree, myid); 3507 tree_set_me (t->tree, myid);
3624 3508
3625 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3509 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3626 return; 3510 return;
@@ -3673,11 +3557,11 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
3673 GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash); 3557 GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash);
3674 t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash); 3558 t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash);
3675 GNUNET_assert (GNUNET_YES == 3559 GNUNET_assert (GNUNET_YES ==
3676 GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t)); 3560 GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t));
3677 3561
3678 t->client = NULL; 3562 t->client = NULL;
3679 tunnel_send_destroy (t); 3563 tunnel_send_destroy (t);
3680 tunnel_destroy(t); 3564 tunnel_destroy (t);
3681 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3565 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3682 return; 3566 return;
3683} 3567}
@@ -3700,7 +3584,7 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client,
3700 struct MeshTunnel *t; 3584 struct MeshTunnel *t;
3701 MESH_TunnelNumber tid; 3585 MESH_TunnelNumber tid;
3702 3586
3703 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n"); 3587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n");
3704 /* Sanity check for client registration */ 3588 /* Sanity check for client registration */
3705 if (NULL == (c = client_get (client))) 3589 if (NULL == (c = client_get (client)))
3706 { 3590 {
@@ -3735,12 +3619,12 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client,
3735 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3619 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3736 return; 3620 return;
3737 } 3621 }
3738 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", 3622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n",
3739 GNUNET_i2s(&peer_msg->peer)); 3623 GNUNET_i2s (&peer_msg->peer));
3740 peer_info = peer_info_get (&peer_msg->peer); 3624 peer_info = peer_info_get (&peer_msg->peer);
3741 3625
3742 tunnel_add_peer(t, peer_info); 3626 tunnel_add_peer (t, peer_info);
3743 peer_info_connect(peer_info, t); 3627 peer_info_connect (peer_info, t);
3744 3628
3745 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3629 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3746 return; 3630 return;
@@ -3800,12 +3684,11 @@ handle_local_connect_del (void *cls, struct GNUNET_SERVER_Client *client,
3800 return; 3684 return;
3801 } 3685 }
3802 3686
3803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for peer %s\n",
3804 "MESH: for peer %s\n", 3688 GNUNET_i2s (&peer_msg->peer));
3805 GNUNET_i2s(&peer_msg->peer));
3806 /* Is the peer in the tunnel? */ 3689 /* Is the peer in the tunnel? */
3807 peer_info = GNUNET_CONTAINER_multihashmap_get(t->peers, 3690 peer_info =
3808 &peer_msg->peer.hashPubKey); 3691 GNUNET_CONTAINER_multihashmap_get (t->peers, &peer_msg->peer.hashPubKey);
3809 if (NULL == peer_info) 3692 if (NULL == peer_info)
3810 { 3693 {
3811 GNUNET_break (0); 3694 GNUNET_break (0);
@@ -3818,7 +3701,7 @@ handle_local_connect_del (void *cls, struct GNUNET_SERVER_Client *client,
3818 &peer_msg->peer.hashPubKey); 3701 &peer_msg->peer.hashPubKey);
3819 3702
3820 send_destroy_path (t, peer_info->id); 3703 send_destroy_path (t, peer_info->id);
3821 tunnel_delete_peer(t, peer_info->id); 3704 tunnel_delete_peer (t, peer_info->id);
3822 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3705 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3823 return; 3706 return;
3824} 3707}
@@ -3894,7 +3777,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
3894 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 3777 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
3895 3778
3896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client\n"); 3779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client\n");
3897 send_client_peer_connected(t, myid); 3780 send_client_peer_connected (t, myid);
3898 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Done\n"); 3781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Done\n");
3899 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3782 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3900 return; 3783 return;
@@ -3907,14 +3790,10 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
3907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n", 3790 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n",
3908 GNUNET_h2s (&hash)); 3791 GNUNET_h2s (&hash));
3909 t->dht_get_type = 3792 t->dht_get_type =
3910 GNUNET_DHT_get_start (dht_handle, 3793 GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
3911 GNUNET_TIME_UNIT_FOREVER_REL, 3794 GNUNET_BLOCK_TYPE_TEST, &hash, 10U,
3912 GNUNET_BLOCK_TYPE_TEST,
3913 &hash,
3914 10U,
3915 GNUNET_DHT_RO_RECORD_ROUTE | 3795 GNUNET_DHT_RO_RECORD_ROUTE |
3916 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 3796 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, 0,
3917 NULL, 0,
3918 &dht_get_type_handler, t); 3797 &dht_get_type_handler, t);
3919 3798
3920 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3799 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -3972,8 +3851,7 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client,
3972 } 3851 }
3973 3852
3974 /* Is it a local tunnel? Then, does client own the tunnel? */ 3853 /* Is it a local tunnel? Then, does client own the tunnel? */
3975 if (NULL != t->client && 3854 if (NULL != t->client && NULL != t->client->handle &&
3976 NULL != t->client->handle &&
3977 t->client->handle != client) 3855 t->client->handle != client)
3978 { 3856 {
3979 GNUNET_break (0); 3857 GNUNET_break (0);
@@ -4074,7 +3952,7 @@ handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client,
4074 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3952 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
4075 return; 3953 return;
4076 } 3954 }
4077 GNUNET_PEER_resolve(t->id.oid, &id); 3955 GNUNET_PEER_resolve (t->id.oid, &id);
4078 3956
4079 /* Ok, everything is correct, send the message 3957 /* Ok, everything is correct, send the message
4080 * (pretend we got it from a mesh peer) 3958 * (pretend we got it from a mesh peer)
@@ -4153,16 +4031,16 @@ handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client,
4153 } 4031 }
4154 4032
4155 { 4033 {
4156 char buf[ntohs(message->size)]; 4034 char buf[ntohs (message->size)];
4157 struct GNUNET_MESH_Multicast *copy; 4035 struct GNUNET_MESH_Multicast *copy;
4158 4036
4159 copy = (struct GNUNET_MESH_Multicast *)buf; 4037 copy = (struct GNUNET_MESH_Multicast *) buf;
4160 memcpy(buf, message, ntohs(message->size)); 4038 memcpy (buf, message, ntohs (message->size));
4161 copy->oid = my_full_id; 4039 copy->oid = my_full_id;
4162 copy->tid = htonl(t->id.tid); 4040 copy->tid = htonl (t->id.tid);
4163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4164 "MESH: calling generic handler...\n"); 4042 "MESH: calling generic handler...\n");
4165 handle_mesh_data_multicast(client, &my_full_id, &copy->header, NULL, 0); 4043 handle_mesh_data_multicast (client, &my_full_id, &copy->header, NULL, 0);
4166 } 4044 }
4167 4045
4168 /* receive done gets called when last copy is sent to a neighbor */ 4046 /* receive done gets called when last copy is sent to a neighbor */
@@ -4213,10 +4091,11 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
4213{ 4091{
4214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Core init\n"); 4092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Core init\n");
4215 core_handle = server; 4093 core_handle = server;
4216 if (0 != memcmp(identity, &my_full_id, sizeof(my_full_id)) || NULL == server) 4094 if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)) ||
4095 NULL == server)
4217 { 4096 {
4218 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("MESH: Wrong CORE service\n")); 4097 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("MESH: Wrong CORE service\n"));
4219 GNUNET_SCHEDULER_shutdown(); 4098 GNUNET_SCHEDULER_shutdown ();
4220 } 4099 }
4221 return; 4100 return;
4222} 4101}
@@ -4240,7 +4119,7 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
4240#if MESH_DEBUG_CONNECTION 4119#if MESH_DEBUG_CONNECTION
4241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n"); 4120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n");
4242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", 4121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n",
4243 GNUNET_i2s(&my_full_id)); 4122 GNUNET_i2s (&my_full_id));
4244#endif 4123#endif
4245 peer_info = peer_info_get (peer); 4124 peer_info = peer_info_get (peer);
4246 if (myid == peer_info->id) 4125 if (myid == peer_info->id)
@@ -4253,15 +4132,14 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
4253#if MESH_DEBUG_CONNECTION 4132#if MESH_DEBUG_CONNECTION
4254 else 4133 else
4255 { 4134 {
4256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", 4135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", GNUNET_i2s (peer));
4257 GNUNET_i2s(peer));
4258 } 4136 }
4259#endif 4137#endif
4260 path = path_new (2); 4138 path = path_new (2);
4261 path->peers[0] = myid; 4139 path->peers[0] = myid;
4262 path->peers[1] = peer_info->id; 4140 path->peers[1] = peer_info->id;
4263 GNUNET_PEER_change_rc(myid, 1); 4141 GNUNET_PEER_change_rc (myid, 1);
4264 GNUNET_PEER_change_rc(peer_info->id, 1); 4142 GNUNET_PEER_change_rc (peer_info->id, 1);
4265 peer_info_add_path (peer_info, path, GNUNET_YES); 4143 peer_info_add_path (peer_info, path, GNUNET_YES);
4266 return; 4144 return;
4267} 4145}
@@ -4290,7 +4168,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
4290 for (i = 0; i < CORE_QUEUE_SIZE; i++) 4168 for (i = 0; i < CORE_QUEUE_SIZE; i++)
4291 { 4169 {
4292 /* TODO: notify that the transmission failed */ 4170 /* TODO: notify that the transmission failed */
4293 peer_info_cancel_transmission(pi, i); 4171 peer_info_cancel_transmission (pi, i);
4294 } 4172 }
4295 peer_info_remove_path (pi, pi->id, myid); 4173 peer_info_remove_path (pi, pi->id, myid);
4296#if MESH_DEBUG_CONNECTION 4174#if MESH_DEBUG_CONNECTION
@@ -4320,7 +4198,8 @@ static int
4320shutdown_tunnel (void *cls, const GNUNET_HashCode * key, void *value) 4198shutdown_tunnel (void *cls, const GNUNET_HashCode * key, void *value)
4321{ 4199{
4322 struct MeshTunnel *t = value; 4200 struct MeshTunnel *t = value;
4323 tunnel_destroy(t); 4201
4202 tunnel_destroy (t);
4324 return GNUNET_YES; 4203 return GNUNET_YES;
4325} 4204}
4326 4205
@@ -4337,6 +4216,7 @@ static int
4337shutdown_peer (void *cls, const GNUNET_HashCode * key, void *value) 4216shutdown_peer (void *cls, const GNUNET_HashCode * key, void *value)
4338{ 4217{
4339 struct MeshPeerInfo *p = value; 4218 struct MeshPeerInfo *p = value;
4219
4340 peer_info_destroy (p); 4220 peer_info_destroy (p);
4341 return GNUNET_YES; 4221 return GNUNET_YES;
4342} 4222}
@@ -4357,8 +4237,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4357 GNUNET_CORE_disconnect (core_handle); 4237 GNUNET_CORE_disconnect (core_handle);
4358 core_handle = NULL; 4238 core_handle = NULL;
4359 } 4239 }
4360 GNUNET_CONTAINER_multihashmap_iterate(tunnels, &shutdown_tunnel, NULL); 4240 GNUNET_CONTAINER_multihashmap_iterate (tunnels, &shutdown_tunnel, NULL);
4361 GNUNET_CONTAINER_multihashmap_iterate(peers, &shutdown_peer, NULL); 4241 GNUNET_CONTAINER_multihashmap_iterate (peers, &shutdown_peer, NULL);
4362 if (dht_handle != NULL) 4242 if (dht_handle != NULL)
4363 { 4243 {
4364 GNUNET_DHT_disconnect (dht_handle); 4244 GNUNET_DHT_disconnect (dht_handle);
@@ -4414,8 +4294,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
4414 } 4294 }
4415 4295
4416 if (GNUNET_OK != 4296 if (GNUNET_OK !=
4417 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", 4297 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
4418 &keyfile)) 4298 &keyfile))
4419 { 4299 {
4420 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 4300 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
4421 _ 4301 _
@@ -4463,8 +4343,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
4463 nc = GNUNET_SERVER_notification_context_create (server_handle, 4343 nc = GNUNET_SERVER_notification_context_create (server_handle,
4464 LOCAL_QUEUE_SIZE); 4344 LOCAL_QUEUE_SIZE);
4465 GNUNET_SERVER_disconnect_notify (server_handle, 4345 GNUNET_SERVER_disconnect_notify (server_handle,
4466 &handle_local_client_disconnect, 4346 &handle_local_client_disconnect, NULL);
4467 NULL);
4468 4347
4469 4348
4470 clients = NULL; 4349 clients = NULL;
@@ -4477,11 +4356,11 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
4477 announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); 4356 announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls);
4478 4357
4479 /* Create a peer_info for the local peer */ 4358 /* Create a peer_info for the local peer */
4480 peer = peer_info_get(&my_full_id); 4359 peer = peer_info_get (&my_full_id);
4481 p = path_new (1); 4360 p = path_new (1);
4482 p->peers[0] = myid; 4361 p->peers[0] = myid;
4483 GNUNET_PEER_change_rc (myid, 1); 4362 GNUNET_PEER_change_rc (myid, 1);
4484 peer_info_add_path(peer, p, GNUNET_YES); 4363 peer_info_add_path (peer, p, GNUNET_YES);
4485 4364
4486 /* Scheduled the task to clean up when shutdown is called */ 4365 /* Scheduled the task to clean up when shutdown is called */
4487 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 4366 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 33cb41179..35bbab3a1 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -903,10 +903,8 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
903 t = retrieve_tunnel (h, ntohl (ucast->tid)); 903 t = retrieve_tunnel (h, ntohl (ucast->tid));
904 payload = (struct GNUNET_MessageHeader *) &ucast[1]; 904 payload = (struct GNUNET_MessageHeader *) &ucast[1];
905 peer = &ucast->oid; 905 peer = &ucast->oid;
906 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 906 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: on tunnel %s [%x]\n",
907 "mesh: on tunnel %s [%x]\n", 907 GNUNET_i2s (peer), ntohl (ucast->tid));
908 GNUNET_i2s (peer),
909 ntohl (ucast->tid));
910 break; 908 break;
911 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: 909 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
912 mcast = (struct GNUNET_MESH_Multicast *) message; 910 mcast = (struct GNUNET_MESH_Multicast *) message;
@@ -1053,11 +1051,9 @@ send_callback (void *cls, size_t size, void *buf)
1053 1051
1054 GNUNET_assert (size >= th->size); 1052 GNUNET_assert (size >= th->size);
1055 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)]; 1053 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)];
1056 psize = 1054 psize = th->notify (th->notify_cls, size - sizeof (to), mh);
1057 th->notify (th->notify_cls, size - sizeof (to), mh); 1055 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: to origin, type %u\n",
1058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1056 ntohs (mh->type));
1059 "mesh: to origin, type %u\n",
1060 ntohs (mh->type));
1061 if (psize > 0) 1057 if (psize > 0)
1062 { 1058 {
1063 psize += sizeof (to); 1059 psize += sizeof (to);
@@ -1078,10 +1074,8 @@ send_callback (void *cls, size_t size, void *buf)
1078 1074
1079 GNUNET_assert (size >= th->size); 1075 GNUNET_assert (size >= th->size);
1080 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)]; 1076 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)];
1081 psize = 1077 psize = th->notify (th->notify_cls, size - sizeof (mc), mh);
1082 th->notify (th->notify_cls, size - sizeof (mc), mh); 1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: multicast, type %u\n",
1083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1084 "mesh: multicast, type %u\n",
1085 ntohs (mh->type)); 1079 ntohs (mh->type));
1086 if (psize > 0) 1080 if (psize > 0)
1087 { 1081 {
@@ -1102,11 +1096,9 @@ send_callback (void *cls, size_t size, void *buf)
1102 1096
1103 GNUNET_assert (size >= th->size); 1097 GNUNET_assert (size >= th->size);
1104 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)]; 1098 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)];
1105 psize = 1099 psize = th->notify (th->notify_cls, size - sizeof (uc), mh);
1106 th->notify (th->notify_cls, size - sizeof (uc), mh); 1100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: unicast, type %u\n",
1107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1101 ntohs (mh->type));
1108 "mesh: unicast, type %u\n",
1109 ntohs (mh->type));
1110 if (psize > 0) 1102 if (psize > 0)
1111 { 1103 {
1112 psize += sizeof (uc); 1104 psize += sizeof (uc);
@@ -1482,12 +1474,10 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
1482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1483 "mesh: mesh notify transmit ready called\n"); 1475 "mesh: mesh notify transmit ready called\n");
1484 if (NULL != target) 1476 if (NULL != target)
1485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: target %s\n",
1486 "mesh: target %s\n",
1487 GNUNET_i2s (target)); 1478 GNUNET_i2s (target));
1488 else 1479 else
1489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: target multicast\n");
1490 "mesh: target multicast\n");
1491#endif 1481#endif
1492 GNUNET_assert (NULL != notify); 1482 GNUNET_assert (NULL != notify);
1493 if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && 1483 if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size &&
@@ -1541,11 +1531,9 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
1541 if (NULL != tunnel->mesh->th) 1531 if (NULL != tunnel->mesh->th)
1542 return th; 1532 return th;
1543 tunnel->mesh->th = 1533 tunnel->mesh->th =
1544 GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, 1534 GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, th->size,
1545 th->size,
1546 GNUNET_TIME_UNIT_FOREVER_REL, 1535 GNUNET_TIME_UNIT_FOREVER_REL,
1547 GNUNET_YES, 1536 GNUNET_YES, &send_callback,
1548 &send_callback,
1549 tunnel->mesh); 1537 tunnel->mesh);
1550 return th; 1538 return th;
1551} 1539}
diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h
index e16f32093..180ba453f 100644
--- a/src/mesh/mesh_protocol.h
+++ b/src/mesh/mesh_protocol.h
@@ -206,7 +206,7 @@ struct GNUNET_MESH_PathBroken
206 * ID of the endpoint 206 * ID of the endpoint
207 */ 207 */
208 struct GNUNET_PeerIdentity peer1; 208 struct GNUNET_PeerIdentity peer1;
209 209
210 /** 210 /**
211 * ID of the endpoint 211 * ID of the endpoint
212 */ 212 */
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c
index 332a022c1..cfe6a46a8 100644
--- a/src/mesh/mesh_tunnel_tree.c
+++ b/src/mesh/mesh_tunnel_tree.c
@@ -119,11 +119,11 @@ path_new (unsigned int length)
119{ 119{
120 struct MeshPeerPath *p; 120 struct MeshPeerPath *p;
121 121
122 p = GNUNET_malloc (sizeof(struct MeshPeerPath)); 122 p = GNUNET_malloc (sizeof (struct MeshPeerPath));
123 if (length > 0) 123 if (length > 0)
124 { 124 {
125 p->length = length; 125 p->length = length;
126 p->peers = GNUNET_malloc (length * sizeof(GNUNET_PEER_Id)); 126 p->peers = GNUNET_malloc (length * sizeof (GNUNET_PEER_Id));
127 } 127 }
128 return p; 128 return p;
129} 129}
@@ -160,10 +160,10 @@ path_duplicate (struct MeshPeerPath *path)
160 struct MeshPeerPath *aux; 160 struct MeshPeerPath *aux;
161 unsigned int i; 161 unsigned int i;
162 162
163 aux = path_new(path->length); 163 aux = path_new (path->length);
164 memcpy (aux->peers, path->peers, path->length * sizeof(GNUNET_PEER_Id)); 164 memcpy (aux->peers, path->peers, path->length * sizeof (GNUNET_PEER_Id));
165 for (i = 0; i < path->length; i++) 165 for (i = 0; i < path->length; i++)
166 GNUNET_PEER_change_rc(path->peers[i], 1); 166 GNUNET_PEER_change_rc (path->peers[i], 1);
167 return aux; 167 return aux;
168} 168}
169 169
@@ -202,18 +202,17 @@ path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
202 { 202 {
203 struct MeshTunnelTreeNode *n; 203 struct MeshTunnelTreeNode *n;
204 204
205 n = tree_find_peer(t, peer); 205 n = tree_find_peer (t, peer);
206 if (NULL != t->me && NULL != n) 206 if (NULL != t->me && NULL != n)
207 { 207 {
208 tree_node_update_first_hops(t, n, NULL); 208 tree_node_update_first_hops (t, n, NULL);
209 r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey); 209 r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
210 GNUNET_assert (NULL != r); 210 GNUNET_assert (NULL != r);
211 } 211 }
212 else 212 else
213 { 213 {
214 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 214 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
215 "Tree structure inconsistent! me: %p, n: %p", 215 "Tree structure inconsistent! me: %p, n: %p", t->me, n);
216 t->me, n);
217 GNUNET_break (0); 216 GNUNET_break (0);
218 } 217 }
219 } 218 }
@@ -287,18 +286,17 @@ path_destroy (struct MeshPeerPath *p)
287 * @return Newly allocated node 286 * @return Newly allocated node
288 */ 287 */
289static struct MeshTunnelTreeNode * 288static struct MeshTunnelTreeNode *
290tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer) 289tree_node_new (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer)
291{ 290{
292 struct MeshTunnelTreeNode *node; 291 struct MeshTunnelTreeNode *node;
293 292
294 node = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode)); 293 node = GNUNET_malloc (sizeof (struct MeshTunnelTreeNode));
295 node->peer = peer; 294 node->peer = peer;
296 GNUNET_PEER_change_rc(peer, 1); 295 GNUNET_PEER_change_rc (peer, 1);
297 node->parent = parent; 296 node->parent = parent;
298 if (NULL != parent) 297 if (NULL != parent)
299 GNUNET_CONTAINER_DLL_insert(parent->children_head, 298 GNUNET_CONTAINER_DLL_insert (parent->children_head, parent->children_tail,
300 parent->children_tail, 299 node);
301 node);
302 300
303 return node; 301 return node;
304} 302}
@@ -313,8 +311,7 @@ tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer)
313 * @return Pointer to the node of the peer. NULL if not found. 311 * @return Pointer to the node of the peer. NULL if not found.
314 */ 312 */
315static struct MeshTunnelTreeNode * 313static struct MeshTunnelTreeNode *
316tree_node_find_peer (struct MeshTunnelTreeNode *parent, 314tree_node_find_peer (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer_id)
317 GNUNET_PEER_Id peer_id)
318{ 315{
319 struct MeshTunnelTreeNode *n; 316 struct MeshTunnelTreeNode *n;
320 struct MeshTunnelTreeNode *r; 317 struct MeshTunnelTreeNode *r;
@@ -350,10 +347,9 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree,
350 struct MeshTunnelTreeNode *n; 347 struct MeshTunnelTreeNode *n;
351 348
352#if MESH_TREE_DEBUG 349#if MESH_TREE_DEBUG
353 GNUNET_PEER_resolve(parent->peer, &id); 350 GNUNET_PEER_resolve (parent->peer, &id);
354 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Finding first hop for %s.\n",
355 "tree: Finding first hop for %s.\n", 352 GNUNET_i2s (&id));
356 GNUNET_i2s (&id));
357#endif 353#endif
358 if (NULL == hop) 354 if (NULL == hop)
359 { 355 {
@@ -364,35 +360,31 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree,
364 while (aux != tree->me) 360 while (aux != tree->me)
365 { 361 {
366#if MESH_TREE_DEBUG 362#if MESH_TREE_DEBUG
367 GNUNET_PEER_resolve(old->peer, &id); 363 GNUNET_PEER_resolve (old->peer, &id);
368 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: ... its not %s.\n",
369 "tree: ... its not %s.\n", 365 GNUNET_i2s (&id));
370 GNUNET_i2s (&id));
371#endif 366#endif
372 old = aux; 367 old = aux;
373 aux = aux->parent; 368 aux = aux->parent;
374 GNUNET_assert(NULL != aux); 369 GNUNET_assert (NULL != aux);
375 } 370 }
376#if MESH_TREE_DEBUG 371#if MESH_TREE_DEBUG
377 GNUNET_PEER_resolve(old->peer, &id); 372 GNUNET_PEER_resolve (old->peer, &id);
378 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: It's %s!\n",
379 "tree: It's %s!\n", 374 GNUNET_i2s (&id));
380 GNUNET_i2s (&id));
381#endif 375#endif
382 hop = &pi; 376 hop = &pi;
383 GNUNET_PEER_resolve(old->peer, hop); 377 GNUNET_PEER_resolve (old->peer, hop);
384 } 378 }
385 GNUNET_PEER_resolve(parent->peer, &id); 379 GNUNET_PEER_resolve (parent->peer, &id);
386 copy = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey); 380 copy = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey);
387 if (NULL == copy) 381 if (NULL == copy)
388 copy = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 382 copy = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
389 *copy = *hop; 383 *copy = *hop;
390 384
391 (void) GNUNET_CONTAINER_multihashmap_put( 385 (void) GNUNET_CONTAINER_multihashmap_put (tree->first_hops, &id.hashPubKey,
392 tree->first_hops, 386 copy,
393 &id.hashPubKey, 387 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
394 copy,
395 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
396 388
397 for (n = parent->children_head; NULL != n; n = n->next) 389 for (n = parent->children_head; NULL != n; n = n->next)
398 { 390 {
@@ -402,34 +394,34 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree,
402 394
403 395
404static void 396static void
405tree_node_debug(struct MeshTunnelTreeNode *n, uint16_t level) 397tree_node_debug (struct MeshTunnelTreeNode *n, uint16_t level)
406{ 398{
407 struct MeshTunnelTreeNode *c; 399 struct MeshTunnelTreeNode *c;
408 struct GNUNET_PeerIdentity id;; 400 struct GNUNET_PeerIdentity id;;
409 uint16_t i; 401 uint16_t i;
410 402
411 for (i = 0; i < level; i++) 403 for (i = 0; i < level; i++)
412 fprintf(stderr, " "); 404 fprintf (stderr, " ");
413 if (n->status == MESH_PEER_READY) 405 if (n->status == MESH_PEER_READY)
414 fprintf(stderr, "#"); 406 fprintf (stderr, "#");
415 if (n->status == MESH_PEER_SEARCHING) 407 if (n->status == MESH_PEER_SEARCHING)
416 fprintf(stderr, "+"); 408 fprintf (stderr, "+");
417 if (n->status == MESH_PEER_RELAY) 409 if (n->status == MESH_PEER_RELAY)
418 fprintf(stderr, "-"); 410 fprintf (stderr, "-");
419 if (n->status == MESH_PEER_RECONNECTING) 411 if (n->status == MESH_PEER_RECONNECTING)
420 fprintf(stderr, "*"); 412 fprintf (stderr, "*");
421 413
422 GNUNET_PEER_resolve(n->peer, &id); 414 GNUNET_PEER_resolve (n->peer, &id);
423 fprintf(stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n); 415 fprintf (stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n);
424 if (NULL != n->parent) 416 if (NULL != n->parent)
425 { 417 {
426 GNUNET_PEER_resolve(n->parent->peer, &id); 418 GNUNET_PEER_resolve (n->parent->peer, &id);
427 fprintf(stderr, "(-> %s [%u])\n", GNUNET_i2s(&id), n->parent->peer); 419 fprintf (stderr, "(-> %s [%u])\n", GNUNET_i2s (&id), n->parent->peer);
428 } 420 }
429 else 421 else
430 fprintf(stderr, "(root)\n"); 422 fprintf (stderr, "(root)\n");
431 for (c = n->children_head; NULL != c; c = c->next) 423 for (c = n->children_head; NULL != c; c = c->next)
432 tree_node_debug(c, level + 1); 424 tree_node_debug (c, level + 1);
433} 425}
434 426
435 427
@@ -443,30 +435,27 @@ tree_node_destroy (struct MeshTunnelTreeNode *parent)
443{ 435{
444 struct MeshTunnelTreeNode *n; 436 struct MeshTunnelTreeNode *n;
445 struct MeshTunnelTreeNode *next; 437 struct MeshTunnelTreeNode *next;
438
446#if MESH_TREE_DEBUG 439#if MESH_TREE_DEBUG
447 struct GNUNET_PeerIdentity id; 440 struct GNUNET_PeerIdentity id;
448 441
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying node %u\n",
450 "tree: Destroying node %u\n",
451 parent->peer); 443 parent->peer);
452 GNUNET_PEER_resolve (parent->peer, &id); 444 GNUNET_PEER_resolve (parent->peer, &id);
453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: (%s)\n", GNUNET_i2s (&id));
454 "tree: (%s)\n",
455 GNUNET_i2s (&id));
456#endif 446#endif
457 n = parent->children_head; 447 n = parent->children_head;
458 while (NULL != n) 448 while (NULL != n)
459 { 449 {
460 next = n->next; 450 next = n->next;
461 tree_node_destroy(n); 451 tree_node_destroy (n);
462 n = next; 452 n = next;
463 } 453 }
464 GNUNET_PEER_change_rc(parent->peer, -1); 454 GNUNET_PEER_change_rc (parent->peer, -1);
465 if (NULL != parent->parent) 455 if (NULL != parent->parent)
466 GNUNET_CONTAINER_DLL_remove(parent->parent->children_head, 456 GNUNET_CONTAINER_DLL_remove (parent->parent->children_head,
467 parent->parent->children_tail, 457 parent->parent->children_tail, parent);
468 parent); 458 GNUNET_free (parent);
469 GNUNET_free(parent);
470} 459}
471 460
472 461
@@ -484,9 +473,9 @@ tree_new (GNUNET_PEER_Id peer)
484{ 473{
485 struct MeshTunnelTree *tree; 474 struct MeshTunnelTree *tree;
486 475
487 tree = GNUNET_malloc(sizeof (struct MeshTunnelTree)); 476 tree = GNUNET_malloc (sizeof (struct MeshTunnelTree));
488 tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32); 477 tree->first_hops = GNUNET_CONTAINER_multihashmap_create (32);
489 tree->root = tree_node_new(NULL, peer); 478 tree->root = tree_node_new (NULL, peer);
490 tree->root->status = MESH_PEER_ROOT; 479 tree->root->status = MESH_PEER_ROOT;
491 480
492 return tree; 481 return tree;
@@ -502,7 +491,7 @@ tree_new (GNUNET_PEER_Id peer)
502void 491void
503tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer) 492tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer)
504{ 493{
505 tree->me = tree_find_peer(tree, peer); 494 tree->me = tree_find_peer (tree, peer);
506} 495}
507 496
508 497
@@ -529,13 +518,12 @@ tree_get_me (struct MeshTunnelTree *tree)
529 * @param peer A short peer id of local peer. 518 * @param peer A short peer id of local peer.
530 */ 519 */
531void 520void
532tree_set_status (struct MeshTunnelTree *tree, 521tree_set_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer,
533 GNUNET_PEER_Id peer,
534 enum MeshPeerState status) 522 enum MeshPeerState status)
535{ 523{
536 struct MeshTunnelTreeNode *n; 524 struct MeshTunnelTreeNode *n;
537 525
538 n = tree_find_peer(tree, peer); 526 n = tree_find_peer (tree, peer);
539 if (NULL == n) 527 if (NULL == n)
540 return; 528 return;
541 n->status = status; 529 n->status = status;
@@ -554,7 +542,7 @@ tree_get_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer)
554{ 542{
555 struct MeshTunnelTreeNode *n; 543 struct MeshTunnelTreeNode *n;
556 544
557 n = tree_find_peer(tree, peer); 545 n = tree_find_peer (tree, peer);
558 if (NULL == n) 546 if (NULL == n)
559 return MESH_PEER_INVALID; 547 return MESH_PEER_INVALID;
560 return n->status; 548 return n->status;
@@ -589,7 +577,7 @@ tree_get_predecessor (struct MeshTunnelTree *tree)
589struct MeshTunnelTreeNode * 577struct MeshTunnelTreeNode *
590tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id) 578tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id)
591{ 579{
592 return tree_node_find_peer(tree->root, peer_id); 580 return tree_node_find_peer (tree->root, peer_id);
593} 581}
594 582
595 583
@@ -603,8 +591,7 @@ tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id)
603static void 591static void
604tree_mark_peers_disconnected (struct MeshTunnelTree *tree, 592tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
605 struct MeshTunnelTreeNode *parent, 593 struct MeshTunnelTreeNode *parent,
606 MeshTreeCallback cb, 594 MeshTreeCallback cb, void *cbcls)
607 void *cbcls)
608{ 595{
609 struct GNUNET_PeerIdentity *pi; 596 struct GNUNET_PeerIdentity *pi;
610 struct GNUNET_PeerIdentity id; 597 struct GNUNET_PeerIdentity id;
@@ -622,24 +609,23 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
622 } 609 }
623 610
624 /* Remove and free info about first hop */ 611 /* Remove and free info about first hop */
625 GNUNET_PEER_resolve(parent->peer, &id); 612 GNUNET_PEER_resolve (parent->peer, &id);
626 pi = GNUNET_CONTAINER_multihashmap_get(tree->first_hops, &id.hashPubKey); 613 pi = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey);
627 GNUNET_CONTAINER_multihashmap_remove_all(tree->first_hops, &id.hashPubKey); 614 GNUNET_CONTAINER_multihashmap_remove_all (tree->first_hops, &id.hashPubKey);
628 if (NULL != pi) 615 if (NULL != pi)
629 GNUNET_free(pi); 616 GNUNET_free (pi);
630} 617}
631 618
632 619
633/** 620/**
634 * Iterate over all children of the local node. 621 * Iterate over all children of the local node.
635 * 622 *
636 * @param tree Tree to use. Must have "me" set. 623 * @param tree Tree to use. Must have "me" set.
637 * @param cb Callback to call over each child. 624 * @param cb Callback to call over each child.
638 * @param cls Closure. 625 * @param cls Closure.
639 */ 626 */
640void 627void
641tree_iterate_children (struct MeshTunnelTree *tree, 628tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb,
642 MeshTreeCallback cb,
643 void *cls) 629 void *cls)
644{ 630{
645 struct MeshTunnelTreeNode *n; 631 struct MeshTunnelTreeNode *n;
@@ -665,13 +651,10 @@ tree_iterate_children (struct MeshTunnelTree *tree,
665 * If not known, NULL to find out and pass on children. 651 * If not known, NULL to find out and pass on children.
666 */ 652 */
667void 653void
668tree_update_first_hops (struct MeshTunnelTree *tree, 654tree_update_first_hops (struct MeshTunnelTree *tree, GNUNET_PEER_Id parent_id,
669 GNUNET_PEER_Id parent_id,
670 struct GNUNET_PeerIdentity *hop) 655 struct GNUNET_PeerIdentity *hop)
671{ 656{
672 tree_node_update_first_hops(tree, 657 tree_node_update_first_hops (tree, tree_find_peer (tree, parent_id), hop);
673 tree_find_peer(tree, parent_id),
674 hop);
675} 658}
676 659
677 660
@@ -689,10 +672,8 @@ tree_update_first_hops (struct MeshTunnelTree *tree,
689 * NULL when not found 672 * NULL when not found
690 */ 673 */
691struct MeshTunnelTreeNode * 674struct MeshTunnelTreeNode *
692tree_del_path (struct MeshTunnelTree *t, 675tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id,
693 GNUNET_PEER_Id peer_id, 676 MeshTreeCallback cb, void *cbcls)
694 MeshTreeCallback cb,
695 void *cbcls)
696{ 677{
697 struct MeshTunnelTreeNode *parent; 678 struct MeshTunnelTreeNode *parent;
698 struct MeshTunnelTreeNode *node; 679 struct MeshTunnelTreeNode *node;
@@ -700,10 +681,10 @@ tree_del_path (struct MeshTunnelTree *t,
700 681
701#if MESH_TREE_DEBUG 682#if MESH_TREE_DEBUG
702 struct GNUNET_PeerIdentity id; 683 struct GNUNET_PeerIdentity id;
703 GNUNET_PEER_resolve(peer_id, &id); 684
704 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 685 GNUNET_PEER_resolve (peer_id, &id);
705 "tree: Deleting path to %s.\n", 686 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting path to %s.\n",
706 GNUNET_i2s (&id)); 687 GNUNET_i2s (&id));
707#endif 688#endif
708 if (peer_id == t->root->peer) 689 if (peer_id == t->root->peer)
709 return NULL; 690 return NULL;
@@ -713,8 +694,7 @@ tree_del_path (struct MeshTunnelTree *t,
713 if (n->peer == peer_id) 694 if (n->peer == peer_id)
714 { 695 {
715 /* Was already pathless, waiting for reconnection */ 696 /* Was already pathless, waiting for reconnection */
716 GNUNET_CONTAINER_DLL_remove (t->disconnected_head, 697 GNUNET_CONTAINER_DLL_remove (t->disconnected_head, t->disconnected_tail,
717 t->disconnected_tail,
718 n); 698 n);
719 return n; 699 return n;
720 } 700 }
@@ -725,26 +705,24 @@ tree_del_path (struct MeshTunnelTree *t,
725 node = n; 705 node = n;
726 706
727 parent = n->parent; 707 parent = n->parent;
728 GNUNET_CONTAINER_DLL_remove(parent->children_head, parent->children_tail, n); 708 GNUNET_CONTAINER_DLL_remove (parent->children_head, parent->children_tail, n);
729 n->parent = NULL; 709 n->parent = NULL;
730 710
731 while (MESH_PEER_RELAY == parent->status && NULL == parent->children_head) 711 while (MESH_PEER_RELAY == parent->status && NULL == parent->children_head)
732 { 712 {
733#if MESH_TREE_DEBUG 713#if MESH_TREE_DEBUG
734 GNUNET_PEER_resolve(parent->peer, &id); 714 GNUNET_PEER_resolve (parent->peer, &id);
735 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting node %s.\n",
736 "tree: Deleting node %s.\n", 716 GNUNET_i2s (&id));
737 GNUNET_i2s (&id));
738#endif 717#endif
739 n = parent->parent; 718 n = parent->parent;
740 tree_node_destroy(parent); 719 tree_node_destroy (parent);
741 parent = n; 720 parent = n;
742 } 721 }
743#if MESH_TREE_DEBUG 722#if MESH_TREE_DEBUG
744 GNUNET_PEER_resolve(parent->peer, &id); 723 GNUNET_PEER_resolve (parent->peer, &id);
745 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Not deleted peer %s.\n",
746 "tree: Not deleted peer %s.\n", 725 GNUNET_i2s (&id));
747 GNUNET_i2s (&id));
748#endif 726#endif
749 727
750 tree_mark_peers_disconnected (t, node, cb, cbcls); 728 tree_mark_peers_disconnected (t, node, cb, cbcls);
@@ -764,30 +742,30 @@ tree_del_path (struct MeshTunnelTree *t,
764 * Path must be destroyed afterwards. 742 * Path must be destroyed afterwards.
765 */ 743 */
766struct MeshPeerPath * 744struct MeshPeerPath *
767tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer) 745tree_get_path_to_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
768{ 746{
769 struct MeshTunnelTreeNode *n; 747 struct MeshTunnelTreeNode *n;
770 struct MeshPeerPath *p; 748 struct MeshPeerPath *p;
771 GNUNET_PEER_Id myid = t->me->peer; 749 GNUNET_PEER_Id myid = t->me->peer;
772 750
773 n = tree_find_peer(t, peer); 751 n = tree_find_peer (t, peer);
774 if (NULL == n) 752 if (NULL == n)
775 return NULL; 753 return NULL;
776 p = path_new(0); 754 p = path_new (0);
777 755
778 /* Building the path (inverted!) */ 756 /* Building the path (inverted!) */
779 while (n->peer != myid) 757 while (n->peer != myid)
780 { 758 {
781 GNUNET_array_append(p->peers, p->length, n->peer); 759 GNUNET_array_append (p->peers, p->length, n->peer);
782 GNUNET_PEER_change_rc(n->peer, 1); 760 GNUNET_PEER_change_rc (n->peer, 1);
783 n = n->parent; 761 n = n->parent;
784 if (NULL == n) 762 if (NULL == n)
785 return NULL; 763 return NULL;
786 } 764 }
787 GNUNET_array_append(p->peers, p->length, myid); 765 GNUNET_array_append (p->peers, p->length, myid);
788 GNUNET_PEER_change_rc(myid, 1); 766 GNUNET_PEER_change_rc (myid, 1);
789 767
790 path_invert(p); 768 path_invert (p);
791 769
792 return p; 770 return p;
793} 771}
@@ -816,10 +794,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
816 * - do not disconnect peers until new path is created & connected 794 * - do not disconnect peers until new path is created & connected
817 */ 795 */
818int 796int
819tree_add_path (struct MeshTunnelTree *t, 797tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
820 const struct MeshPeerPath *p, 798 MeshTreeCallback cb, void *cbcls)
821 MeshTreeCallback cb,
822 void *cbcls)
823{ 799{
824 struct MeshTunnelTreeNode *parent; 800 struct MeshTunnelTreeNode *parent;
825 struct MeshTunnelTreeNode *oldnode; 801 struct MeshTunnelTreeNode *oldnode;
@@ -831,18 +807,17 @@ tree_add_path (struct MeshTunnelTree *t,
831 unsigned int i; 807 unsigned int i;
832 808
833#if MESH_TREE_DEBUG 809#if MESH_TREE_DEBUG
834 GNUNET_PEER_resolve(p->peers[p->length - 1], &id); 810 GNUNET_PEER_resolve (p->peers[p->length - 1], &id);
835 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
836 "tree: Adding path [%u] towards peer %s.\n", 812 "tree: Adding path [%u] towards peer %s.\n", p->length,
837 p->length, 813 GNUNET_i2s (&id));
838 GNUNET_i2s (&id));
839#endif 814#endif
840 815
841 if (NULL != t->me) 816 if (NULL != t->me)
842 myid = t->me->peer; 817 myid = t->me->peer;
843 else 818 else
844 myid = 0; 819 myid = 0;
845 GNUNET_assert(0 != p->length); 820 GNUNET_assert (0 != p->length);
846 parent = n = t->root; 821 parent = n = t->root;
847 if (n->peer != p->peers[0]) 822 if (n->peer != p->peers[0])
848 { 823 {
@@ -862,10 +837,9 @@ tree_add_path (struct MeshTunnelTree *t,
862 for (i = 1; i < p->length; i++) 837 for (i = 1; i < p->length; i++)
863 { 838 {
864#if MESH_TREE_DEBUG 839#if MESH_TREE_DEBUG
865 GNUNET_PEER_resolve(p->peers[i], &id); 840 GNUNET_PEER_resolve (p->peers[i], &id);
866 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 841 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Looking for peer %s.\n",
867 "tree: Looking for peer %s.\n", 842 GNUNET_i2s (&id));
868 GNUNET_i2s (&id));
869#endif 843#endif
870 parent = n; 844 parent = n;
871 if (p->peers[i] == myid) 845 if (p->peers[i] == myid)
@@ -875,10 +849,9 @@ tree_add_path (struct MeshTunnelTree *t,
875 if (c->peer == p->peers[i]) 849 if (c->peer == p->peers[i])
876 { 850 {
877#if MESH_TREE_DEBUG 851#if MESH_TREE_DEBUG
878 GNUNET_PEER_resolve(parent->peer, &id); 852 GNUNET_PEER_resolve (parent->peer, &id);
879 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
880 "tree: Found in children of %s.\n", 854 "tree: Found in children of %s.\n", GNUNET_i2s (&id));
881 GNUNET_i2s (&id));
882#endif 855#endif
883 n = c; 856 n = c;
884 break; 857 break;
@@ -890,45 +863,40 @@ tree_add_path (struct MeshTunnelTree *t,
890 break; 863 break;
891 } 864 }
892#if MESH_TREE_DEBUG 865#if MESH_TREE_DEBUG
893 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: All childen visited.\n");
894 "tree: All childen visited.\n");
895#endif 867#endif
896 /* Add the rest of the path as a branch from parent. */ 868 /* Add the rest of the path as a branch from parent. */
897 while (i < p->length) 869 while (i < p->length)
898 { 870 {
899#if MESH_TREE_DEBUG 871#if MESH_TREE_DEBUG
900 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 872 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Adding peer %u to %u.\n",
901 "tree: Adding peer %u to %u.\n", 873 p->peers[i], parent->peer);
902 p->peers[i], parent->peer); 874 GNUNET_PEER_resolve (p->peers[i], &id);
903 GNUNET_PEER_resolve(p->peers[i], &id); 875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Adding peer %s.\n",
904 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 876 GNUNET_i2s (&id));
905 "tree: Adding peer %s.\n", 877 GNUNET_PEER_resolve (parent->peer, &id);
906 GNUNET_i2s (&id)); 878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: to %s.\n",
907 GNUNET_PEER_resolve(parent->peer, &id); 879 GNUNET_i2s (&id));
908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
909 "tree: to %s.\n",
910 GNUNET_i2s (&id));
911#endif 880#endif
912 881
913 if (i == p->length - 1 && NULL != oldnode) 882 if (i == p->length - 1 && NULL != oldnode)
914 { 883 {
915#if MESH_TREE_DEBUG 884#if MESH_TREE_DEBUG
916 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
917 "tree: Putting old node into place.\n"); 886 "tree: Putting old node into place.\n");
918#endif 887#endif
919 oldnode->parent = parent; 888 oldnode->parent = parent;
920 GNUNET_CONTAINER_DLL_insert(parent->children_head, 889 GNUNET_CONTAINER_DLL_insert (parent->children_head, parent->children_tail,
921 parent->children_tail, 890 oldnode);
922 oldnode);
923 tree_node_update_first_hops (t, oldnode, NULL); 891 tree_node_update_first_hops (t, oldnode, NULL);
924 n = oldnode; 892 n = oldnode;
925 } 893 }
926 else 894 else
927 { 895 {
928#if MESH_TREE_DEBUG 896#if MESH_TREE_DEBUG
929 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n"); 897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n");
930#endif 898#endif
931 n = tree_node_new(parent, p->peers[i]); 899 n = tree_node_new (parent, p->peers[i]);
932 n->status = MESH_PEER_RELAY; 900 n->status = MESH_PEER_RELAY;
933 if (n->peer == myid) 901 if (n->peer == myid)
934 t->me = n; 902 t->me = n;
@@ -943,16 +911,14 @@ tree_add_path (struct MeshTunnelTree *t,
943 { 911 {
944#if MESH_TREE_DEBUG 912#if MESH_TREE_DEBUG
945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
946 "MESH: finding first hop (own pos %d/%u)\n", 914 "MESH: finding first hop (own pos %d/%u)\n", me,
947 me, p->length - 1); 915 p->length - 1);
948#endif 916#endif
949 GNUNET_PEER_resolve (p->peers[me + 1], &id); 917 GNUNET_PEER_resolve (p->peers[me + 1], &id);
950 tree_update_first_hops(t, 918 tree_update_first_hops (t, p->peers[p->length - 1], &id);
951 p->peers[p->length - 1],
952 &id);
953 } 919 }
954#if MESH_TREE_DEBUG 920#if MESH_TREE_DEBUG
955 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); 921 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n");
956#endif 922#endif
957 return GNUNET_OK; 923 return GNUNET_OK;
958} 924}
@@ -971,40 +937,32 @@ tree_add_path (struct MeshTunnelTree *t,
971 * @return Short ID of the first disconnected peer in the tree. 937 * @return Short ID of the first disconnected peer in the tree.
972 */ 938 */
973GNUNET_PEER_Id 939GNUNET_PEER_Id
974tree_notify_connection_broken (struct MeshTunnelTree *t, 940tree_notify_connection_broken (struct MeshTunnelTree *t, GNUNET_PEER_Id p1,
975 GNUNET_PEER_Id p1, 941 GNUNET_PEER_Id p2, MeshTreeCallback cb,
976 GNUNET_PEER_Id p2,
977 MeshTreeCallback cb,
978 void *cbcls) 942 void *cbcls)
979{ 943{
980 struct MeshTunnelTreeNode *n; 944 struct MeshTunnelTreeNode *n;
981 struct MeshTunnelTreeNode *c; 945 struct MeshTunnelTreeNode *c;
982 946
983 n = tree_find_peer(t, p1); 947 n = tree_find_peer (t, p1);
984 if (NULL == n) 948 if (NULL == n)
985 return 0; 949 return 0;
986 if (NULL != n->parent && n->parent->peer == p2) 950 if (NULL != n->parent && n->parent->peer == p2)
987 { 951 {
988 tree_mark_peers_disconnected(t, n, cb, cbcls); 952 tree_mark_peers_disconnected (t, n, cb, cbcls);
989 GNUNET_CONTAINER_DLL_remove(n->parent->children_head, 953 GNUNET_CONTAINER_DLL_remove (n->parent->children_head,
990 n->parent->children_tail, 954 n->parent->children_tail, n);
991 n); 955 GNUNET_CONTAINER_DLL_insert (t->disconnected_head, t->disconnected_tail, n);
992 GNUNET_CONTAINER_DLL_insert(t->disconnected_head,
993 t->disconnected_tail,
994 n);
995 return p1; 956 return p1;
996 } 957 }
997 for (c = n->children_head; NULL != c; c = c->next) 958 for (c = n->children_head; NULL != c; c = c->next)
998 { 959 {
999 if (c->peer == p2) 960 if (c->peer == p2)
1000 { 961 {
1001 tree_mark_peers_disconnected(t, c, cb, cbcls); 962 tree_mark_peers_disconnected (t, c, cb, cbcls);
1002 GNUNET_CONTAINER_DLL_remove(n->children_head, 963 GNUNET_CONTAINER_DLL_remove (n->children_head, n->children_tail, c);
1003 n->children_tail, 964 GNUNET_CONTAINER_DLL_insert (t->disconnected_head, t->disconnected_tail,
1004 c); 965 c);
1005 GNUNET_CONTAINER_DLL_insert(t->disconnected_head,
1006 t->disconnected_tail,
1007 c);
1008 return p2; 966 return p2;
1009 } 967 }
1010 } 968 }
@@ -1026,21 +984,19 @@ tree_notify_connection_broken (struct MeshTunnelTree *t,
1026 * @return GNUNET_OK or GNUNET_SYSERR 984 * @return GNUNET_OK or GNUNET_SYSERR
1027 */ 985 */
1028int 986int
1029tree_del_peer (struct MeshTunnelTree *t, 987tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
1030 GNUNET_PEER_Id peer, 988 MeshTreeCallback cb, void *cbcls)
1031 MeshTreeCallback cb,
1032 void *cbcls)
1033{ 989{
1034 struct MeshTunnelTreeNode *n; 990 struct MeshTunnelTreeNode *n;
1035 991
1036 n = tree_del_path(t, peer, cb, cbcls); 992 n = tree_del_path (t, peer, cb, cbcls);
1037 if (NULL == n) 993 if (NULL == n)
1038 { 994 {
1039 GNUNET_break (0); 995 GNUNET_break (0);
1040 return GNUNET_YES; 996 return GNUNET_YES;
1041 } 997 }
1042 GNUNET_break_op (NULL == n->children_head); 998 GNUNET_break_op (NULL == n->children_head);
1043 tree_node_destroy(n); 999 tree_node_destroy (n);
1044 if (NULL == t->root->children_head && t->me != t->root) 1000 if (NULL == t->root->children_head && t->me != t->root)
1045 { 1001 {
1046 tree_node_destroy (t->root); 1002 tree_node_destroy (t->root);
@@ -1057,9 +1013,9 @@ tree_del_peer (struct MeshTunnelTree *t,
1057 * @param t The tree 1013 * @param t The tree
1058 */ 1014 */
1059void 1015void
1060tree_debug(struct MeshTunnelTree *t) 1016tree_debug (struct MeshTunnelTree *t)
1061{ 1017{
1062 tree_node_debug(t->root, 0); 1018 tree_node_debug (t->root, 0);
1063} 1019}
1064 1020
1065 1021
@@ -1075,14 +1031,14 @@ tree_debug(struct MeshTunnelTree *t)
1075static int 1031static int
1076iterate_free (void *cls, const GNUNET_HashCode * key, void *value) 1032iterate_free (void *cls, const GNUNET_HashCode * key, void *value)
1077{ 1033{
1078 GNUNET_free(value); 1034 GNUNET_free (value);
1079 return GNUNET_YES; 1035 return GNUNET_YES;
1080} 1036}
1081 1037
1082 1038
1083/** 1039/**
1084 * Destroy the whole tree and free all used memory and Peer_Ids 1040 * Destroy the whole tree and free all used memory and Peer_Ids
1085 * 1041 *
1086 * @param t Tree to be destroyed 1042 * @param t Tree to be destroyed
1087 */ 1043 */
1088void 1044void
@@ -1091,8 +1047,8 @@ tree_destroy (struct MeshTunnelTree *t)
1091#if MESH_TREE_DEBUG 1047#if MESH_TREE_DEBUG
1092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying tree\n"); 1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying tree\n");
1093#endif 1049#endif
1094 tree_node_destroy(t->root); 1050 tree_node_destroy (t->root);
1095 GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL); 1051 GNUNET_CONTAINER_multihashmap_iterate (t->first_hops, &iterate_free, NULL);
1096 GNUNET_CONTAINER_multihashmap_destroy(t->first_hops); 1052 GNUNET_CONTAINER_multihashmap_destroy (t->first_hops);
1097 GNUNET_free(t); 1053 GNUNET_free (t);
1098} 1054}
diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h
index e946259da..094a617cb 100644
--- a/src/mesh/mesh_tunnel_tree.h
+++ b/src/mesh/mesh_tunnel_tree.h
@@ -110,8 +110,7 @@ path_duplicate (struct MeshPeerPath *path);
110 * NULL on error 110 * NULL on error
111 */ 111 */
112struct GNUNET_PeerIdentity * 112struct GNUNET_PeerIdentity *
113path_get_first_hop (struct MeshTunnelTree *t, 113path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer);
114 GNUNET_PEER_Id peer);
115 114
116 115
117/** 116/**
@@ -136,8 +135,7 @@ path_get_length (struct MeshPeerPath *p);
136 * in the path 135 * in the path
137 */ 136 */
138unsigned int 137unsigned int
139path_get_cost (struct MeshTunnelTree *t, 138path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path);
140 struct MeshPeerPath *path);
141 139
142 140
143/** 141/**
@@ -159,8 +157,7 @@ path_destroy (struct MeshPeerPath *p);
159 * @param cls Closure. 157 * @param cls Closure.
160 * @param peer_id short ID of peer that is no longer reachable. 158 * @param peer_id short ID of peer that is no longer reachable.
161 */ 159 */
162typedef void (*MeshTreeCallback) (void *cls, 160typedef void (*MeshTreeCallback) (void *cls, GNUNET_PEER_Id peer_id);
163 GNUNET_PEER_Id peer_id);
164 161
165 162
166/** 163/**
@@ -202,8 +199,7 @@ tree_get_me (struct MeshTunnelTree *tree);
202 * @param peer A short peer id of local peer. 199 * @param peer A short peer id of local peer.
203 */ 200 */
204void 201void
205tree_set_status (struct MeshTunnelTree *tree, 202tree_set_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer,
206 GNUNET_PEER_Id peer,
207 enum MeshPeerState status); 203 enum MeshPeerState status);
208 204
209 205
@@ -243,14 +239,13 @@ tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id);
243 239
244/** 240/**
245 * Iterate over all children of the local node. 241 * Iterate over all children of the local node.
246 * 242 *
247 * @param tree Tree to use. Must have "me" set. 243 * @param tree Tree to use. Must have "me" set.
248 * @param cb Callback to call over each child. 244 * @param cb Callback to call over each child.
249 * @param cls Closure. 245 * @param cls Closure.
250 */ 246 */
251void 247void
252tree_iterate_children (struct MeshTunnelTree *tree, 248tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb,
253 MeshTreeCallback cb,
254 void *cls); 249 void *cls);
255 250
256 251
@@ -263,8 +258,7 @@ tree_iterate_children (struct MeshTunnelTree *tree,
263 * If not known, NULL to find out and pass on children. 258 * If not known, NULL to find out and pass on children.
264 */ 259 */
265void 260void
266tree_update_first_hops (struct MeshTunnelTree *tree, 261tree_update_first_hops (struct MeshTunnelTree *tree, GNUNET_PEER_Id parent_id,
267 GNUNET_PEER_Id parent_id,
268 struct GNUNET_PeerIdentity *hop); 262 struct GNUNET_PeerIdentity *hop);
269 263
270/** 264/**
@@ -282,10 +276,8 @@ tree_update_first_hops (struct MeshTunnelTree *tree,
282 * NULL when not found 276 * NULL when not found
283 */ 277 */
284struct MeshTunnelTreeNode * 278struct MeshTunnelTreeNode *
285tree_del_path (struct MeshTunnelTree *t, 279tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
286 GNUNET_PEER_Id peer, 280 MeshTreeCallback cb, void *cbcls);
287 MeshTreeCallback cb,
288 void *cbcls);
289 281
290 282
291/** 283/**
@@ -299,8 +291,7 @@ tree_del_path (struct MeshTunnelTree *t,
299 * Path must be destroyed afterwards. 291 * Path must be destroyed afterwards.
300 */ 292 */
301struct MeshPeerPath * 293struct MeshPeerPath *
302tree_get_path_to_peer(struct MeshTunnelTree *t, 294tree_get_path_to_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer);
303 GNUNET_PEER_Id peer);
304 295
305 296
306/** 297/**
@@ -315,10 +306,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t,
315 * GNUNET_SYSERR in case of error. 306 * GNUNET_SYSERR in case of error.
316 */ 307 */
317int 308int
318tree_add_path (struct MeshTunnelTree *t, 309tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
319 const struct MeshPeerPath *p, 310 MeshTreeCallback cb, void *cbcls);
320 MeshTreeCallback cb,
321 void *cbcls);
322 311
323 312
324/** 313/**
@@ -334,10 +323,8 @@ tree_add_path (struct MeshTunnelTree *t,
334 * @return Short ID of the first disconnected peer in the tree. 323 * @return Short ID of the first disconnected peer in the tree.
335 */ 324 */
336GNUNET_PEER_Id 325GNUNET_PEER_Id
337tree_notify_connection_broken (struct MeshTunnelTree *t, 326tree_notify_connection_broken (struct MeshTunnelTree *t, GNUNET_PEER_Id p1,
338 GNUNET_PEER_Id p1, 327 GNUNET_PEER_Id p2, MeshTreeCallback cb,
339 GNUNET_PEER_Id p2,
340 MeshTreeCallback cb,
341 void *cbcls); 328 void *cbcls);
342 329
343 330
@@ -355,10 +342,8 @@ tree_notify_connection_broken (struct MeshTunnelTree *t,
355 * @return GNUNET_YES if the tunnel still has nodes 342 * @return GNUNET_YES if the tunnel still has nodes
356 */ 343 */
357int 344int
358tree_del_peer (struct MeshTunnelTree *t, 345tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
359 GNUNET_PEER_Id peer, 346 MeshTreeCallback cb, void *cbcls);
360 MeshTreeCallback cb,
361 void *cbcls);
362 347
363/** 348/**
364 * Print the tree on stderr 349 * Print the tree on stderr
@@ -366,7 +351,7 @@ tree_del_peer (struct MeshTunnelTree *t,
366 * @param t The tree 351 * @param t The tree
367 */ 352 */
368void 353void
369tree_debug(struct MeshTunnelTree *t); 354tree_debug (struct MeshTunnelTree *t);
370 355
371 356
372/** 357/**
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c
index 10e16bd42..6fcc8c7ff 100644
--- a/src/mesh/test_mesh_api.c
+++ b/src/mesh/test_mesh_api.c
@@ -122,7 +122,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
122 } 122 }
123 123
124 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 124 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
125 (GNUNET_TIME_UNIT_SECONDS, 5), &do_shutdown, NULL); 125 (GNUNET_TIME_UNIT_SECONDS, 5), &do_shutdown,
126 NULL);
126} 127}
127 128
128 129
diff --git a/src/mesh/test_mesh_local_2.c b/src/mesh/test_mesh_local_2.c
index a2f5dd759..c91548052 100644
--- a/src/mesh/test_mesh_local_2.c
+++ b/src/mesh/test_mesh_local_2.c
@@ -268,10 +268,9 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
268 &peer_disconnected, (void *) &two); 268 &peer_disconnected, (void *) &two);
269 GNUNET_MESH_peer_request_connect_by_type (t, 1); 269 GNUNET_MESH_peer_request_connect_by_type (t, 1);
270 test_task = 270 test_task =
271 GNUNET_SCHEDULER_add_delayed ( 271 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
272 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 272 (GNUNET_TIME_UNIT_SECONDS, 5),
273 &do_connect_peer_1, 273 &do_connect_peer_1, cfg);
274 cfg);
275} 274}
276 275
277 276
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c
index 68fc9cc24..42390e1a6 100644
--- a/src/mesh/test_mesh_small.c
+++ b/src/mesh/test_mesh_small.c
@@ -171,14 +171,16 @@ shutdown_callback (void *cls, const char *emsg)
171 if (emsg != NULL) 171 if (emsg != NULL)
172 { 172 {
173#if VERBOSE 173#if VERBOSE
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Shutdown of peers failed!\n"); 174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "***************** test: Shutdown of peers failed!\n");
175#endif 176#endif
176 ok--; 177 ok--;
177 } 178 }
178 else 179 else
179 { 180 {
180#if VERBOSE 181#if VERBOSE
181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: All peers successfully shut down!\n"); 182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
183 "***************** test: All peers successfully shut down!\n");
182#endif 184#endif
183 } 185 }
184} 186}
@@ -188,7 +190,8 @@ static void
188shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 190shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
189{ 191{
190#if VERBOSE 192#if VERBOSE
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Ending test.\n"); 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "***************** test: Ending test.\n");
192#endif 195#endif
193 196
194 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK) 197 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
@@ -210,14 +213,14 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
211 "***************** test: disconnecting mesh service of peers\n"); 214 "***************** test: disconnecting mesh service of peers\n");
212 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 215 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
213 GNUNET_MESH_disconnect(h1); 216 GNUNET_MESH_disconnect (h1);
214 GNUNET_MESH_disconnect(h2); 217 GNUNET_MESH_disconnect (h2);
215 if (test == MULTICAST) 218 if (test == MULTICAST)
216 GNUNET_MESH_disconnect(h3); 219 GNUNET_MESH_disconnect (h3);
217 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle) 220 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
218 { 221 {
219 GNUNET_SCHEDULER_cancel (shutdown_handle); 222 GNUNET_SCHEDULER_cancel (shutdown_handle);
220 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 223 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
221 } 224 }
222} 225}
223 226
@@ -230,12 +233,13 @@ tmt_rdy (void *cls, size_t size, void *buf)
230{ 233{
231 struct GNUNET_MessageHeader *msg = buf; 234 struct GNUNET_MessageHeader *msg = buf;
232 235
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: tmt_rdy called\n"); 236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
234 if (size < sizeof(struct GNUNET_MessageHeader) || NULL == buf) 237 "***************** test: tmt_rdy called\n");
238 if (size < sizeof (struct GNUNET_MessageHeader) || NULL == buf)
235 return 0; 239 return 0;
236 msg->size = htons (sizeof(struct GNUNET_MessageHeader)); 240 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
237 msg->type = htons ((long) cls); 241 msg->type = htons ((long) cls);
238 return sizeof(struct GNUNET_MessageHeader); 242 return sizeof (struct GNUNET_MessageHeader);
239} 243}
240 244
241 245
@@ -252,57 +256,51 @@ tmt_rdy (void *cls, size_t size, void *buf)
252 * GNUNET_SYSERR to close it (signal serious error) 256 * GNUNET_SYSERR to close it (signal serious error)
253 */ 257 */
254int 258int
255data_callback (void *cls, 259data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
256 struct GNUNET_MESH_Tunnel * tunnel, 260 const struct GNUNET_PeerIdentity *sender,
257 void **tunnel_ctx, 261 const struct GNUNET_MessageHeader *message,
258 const struct GNUNET_PeerIdentity *sender, 262 const struct GNUNET_ATS_Information *atsi)
259 const struct GNUNET_MessageHeader *message,
260 const struct GNUNET_ATS_Information *atsi)
261{ 263{
262 long client = (long) cls; 264 long client = (long) cls;
263 265
264 switch (client) 266 switch (client)
265 { 267 {
266 case 1L: 268 case 1L:
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
268 "***************** test: Origin client got a response!\n"); 270 "***************** test: Origin client got a response!\n");
269 ok++; 271 ok++;
270 peers_responded++; 272 peers_responded++;
271 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 273 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
272 { 274 {
273 GNUNET_SCHEDULER_cancel (disconnect_task); 275 GNUNET_SCHEDULER_cancel (disconnect_task);
274 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, 276 disconnect_task =
275 &disconnect_mesh_peers, 277 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
276 NULL); 278 NULL);
277 } 279 }
278 if (test == MULTICAST && peers_responded < 2) 280 if (test == MULTICAST && peers_responded < 2)
279 return GNUNET_OK; 281 return GNUNET_OK;
280 GNUNET_MESH_tunnel_destroy (tunnel); 282 GNUNET_MESH_tunnel_destroy (tunnel);
281 break; 283 break;
282 case 2L: 284 case 2L:
283 case 3L: 285 case 3L:
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
285 "***************** test: Destination client %u got a message.\n", 287 "***************** test: Destination client %u got a message.\n",
286 client); 288 client);
287 ok++; 289 ok++;
288 GNUNET_MESH_notify_transmit_ready(tunnel, 290 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 0,
289 GNUNET_NO, 291 GNUNET_TIME_UNIT_FOREVER_REL, sender,
290 0, 292 sizeof (struct GNUNET_MessageHeader),
291 GNUNET_TIME_UNIT_FOREVER_REL, 293 &tmt_rdy, (void *) 1L);
292 sender, 294 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
293 sizeof(struct GNUNET_MessageHeader), 295 {
294 &tmt_rdy, 296 GNUNET_SCHEDULER_cancel (disconnect_task);
295 (void *) 1L); 297 disconnect_task =
296 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 298 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
297 { 299 NULL);
298 GNUNET_SCHEDULER_cancel (disconnect_task); 300 }
299 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, 301 break;
300 &disconnect_mesh_peers, 302 default:
301 NULL); 303 break;
302 }
303 break;
304 default:
305 break;
306 } 304 }
307 return GNUNET_OK; 305 return GNUNET_OK;
308} 306}
@@ -312,7 +310,7 @@ data_callback (void *cls,
312 * Handlers, for diverse services 310 * Handlers, for diverse services
313 */ 311 */
314static struct GNUNET_MESH_MessageHandler handlers[] = { 312static struct GNUNET_MESH_MessageHandler handlers[] = {
315 {&data_callback, 1, sizeof(struct GNUNET_MessageHeader)}, 313 {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
316 {NULL, 0, 0} 314 {NULL, 0, 0}
317}; 315};
318 316
@@ -329,15 +327,13 @@ static struct GNUNET_MESH_MessageHandler handlers[] = {
329 * (can be NULL -- that's not an error) 327 * (can be NULL -- that's not an error)
330 */ 328 */
331static void * 329static void *
332incoming_tunnel (void *cls, 330incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
333 struct GNUNET_MESH_Tunnel * tunnel, 331 const struct GNUNET_PeerIdentity *initiator,
334 const struct GNUNET_PeerIdentity * initiator, 332 const struct GNUNET_ATS_Information *atsi)
335 const struct GNUNET_ATS_Information * atsi)
336{ 333{
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
338 "***************** test: Incoming tunnel from %s to peer %d\n", 335 "***************** test: Incoming tunnel from %s to peer %d\n",
339 GNUNET_i2s(initiator), 336 GNUNET_i2s (initiator), (long) cls);
340 (long) cls);
341 ok++; 337 ok++;
342 if ((long) cls == 1L) 338 if ((long) cls == 1L)
343 incoming_t = tunnel; 339 incoming_t = tunnel;
@@ -346,9 +342,8 @@ incoming_tunnel (void *cls,
346 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 342 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
347 { 343 {
348 GNUNET_SCHEDULER_cancel (disconnect_task); 344 GNUNET_SCHEDULER_cancel (disconnect_task);
349 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, 345 disconnect_task =
350 &disconnect_mesh_peers, 346 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
351 NULL);
352 } 347 }
353 return NULL; 348 return NULL;
354} 349}
@@ -377,8 +372,7 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
377 ok++; 372 ok++;
378 else 373 else
379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
380 "***************** test: Unknown peer! %d\n", 375 "***************** test: Unknown peer! %d\n", i);
381 i);
382 peers_in_tunnel--; 376 peers_in_tunnel--;
383 if (peers_in_tunnel > 0) 377 if (peers_in_tunnel > 0)
384 return; 378 return;
@@ -404,7 +398,7 @@ dh (void *cls, const struct GNUNET_PeerIdentity *peer)
404{ 398{
405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
406 "***************** test: peer %s disconnected\n", 400 "***************** test: peer %s disconnected\n",
407 GNUNET_i2s(peer)); 401 GNUNET_i2s (peer));
408 return; 402 return;
409} 403}
410 404
@@ -423,51 +417,46 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer,
423 struct GNUNET_PeerIdentity *dest; 417 struct GNUNET_PeerIdentity *dest;
424 418
425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
426 "***************** test: peer %s connected\n", 420 "***************** test: peer %s connected\n", GNUNET_i2s (peer));
427 GNUNET_i2s(peer));
428 421
429 if (0 == memcmp(&d2->id, peer, sizeof(d2->id)) && (long) cls == 1L) 422 if (0 == memcmp (&d2->id, peer, sizeof (d2->id)) && (long) cls == 1L)
430 ok++; 423 ok++;
431 if (test == MULTICAST && 424 if (test == MULTICAST && 0 == memcmp (&d3->id, peer, sizeof (d3->id)) &&
432 0 == memcmp(&d3->id, peer, sizeof(d3->id)) &&
433 (long) cls == 1L) 425 (long) cls == 1L)
434 ok++; 426 ok++;
435 switch (test) 427 switch (test)
436 { 428 {
437 case UNICAST: 429 case UNICAST:
438 dest = &d2->id; 430 dest = &d2->id;
439 break; 431 break;
440 case MULTICAST: 432 case MULTICAST:
441 peers_in_tunnel++; 433 peers_in_tunnel++;
442 if (peers_in_tunnel < 2) 434 if (peers_in_tunnel < 2)
443 return;
444 dest = NULL;
445 break;
446 default:
447 return; 435 return;
436 dest = NULL;
437 break;
438 default:
439 return;
448 } 440 }
449 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 441 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
450 { 442 {
451 GNUNET_SCHEDULER_cancel (disconnect_task); 443 GNUNET_SCHEDULER_cancel (disconnect_task);
452 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, 444 disconnect_task =
453 &disconnect_mesh_peers, 445 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
454 NULL);
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
456 "***************** test: Sending data...\n"); 447 "***************** test: Sending data...\n");
457 peers_responded = 0; 448 peers_responded = 0;
458 GNUNET_MESH_notify_transmit_ready(t, 449 GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO, 0,
459 GNUNET_NO, 450 GNUNET_TIME_UNIT_FOREVER_REL, dest,
460 0, 451 sizeof (struct GNUNET_MessageHeader),
461 GNUNET_TIME_UNIT_FOREVER_REL, 452 &tmt_rdy, (void *) 1L);
462 dest,
463 sizeof(struct GNUNET_MessageHeader),
464 &tmt_rdy,
465 (void *) 1L);
466 } 453 }
467 else 454 else
468 { 455 {
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Disconnect already run?\n"); 456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Aborting...\n"); 457 "***************** test: Disconnect already run?\n");
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
459 "***************** test: Aborting...\n");
471 } 460 }
472 return; 461 return;
473} 462}
@@ -481,20 +470,19 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
481 { 470 {
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
483 "***************** test: add peer 3\n"); 472 "***************** test: add peer 3\n");
484 GNUNET_MESH_peer_request_connect_add(t, &d3->id); 473 GNUNET_MESH_peer_request_connect_add (t, &d3->id);
485 } 474 }
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: add peer 2\n");
487 "***************** test: add peer 2\n"); 476 GNUNET_MESH_peer_request_connect_add (t, &d2->id);
488 GNUNET_MESH_peer_request_connect_add(t, &d2->id);
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "***************** test: schedule timeout in 30s\n"); 478 "***************** test: schedule timeout in 30s\n");
491 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 479 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
492 { 480 {
493 GNUNET_SCHEDULER_cancel (disconnect_task); 481 GNUNET_SCHEDULER_cancel (disconnect_task);
494 disconnect_task = GNUNET_SCHEDULER_add_delayed( 482 disconnect_task =
495 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), 483 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
496 &disconnect_mesh_peers, 484 (GNUNET_TIME_UNIT_SECONDS, 30),
497 NULL); 485 &disconnect_mesh_peers, NULL);
498 } 486 }
499} 487}
500 488
@@ -510,50 +498,46 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
510 * @param emsg error message (NULL on success) 498 * @param emsg error message (NULL on success)
511 */ 499 */
512void 500void
513topo_cb (void *cls, 501topo_cb (void *cls, const struct GNUNET_PeerIdentity *first,
514 const struct GNUNET_PeerIdentity* first, 502 const struct GNUNET_PeerIdentity *second, const char *emsg)
515 const struct GNUNET_PeerIdentity* second,
516 const char *emsg)
517{ 503{
518 GNUNET_PEER_Id p1; 504 GNUNET_PEER_Id p1;
519 GNUNET_PEER_Id p2; 505 GNUNET_PEER_Id p2;
520 struct GNUNET_PeerIdentity id; 506 struct GNUNET_PeerIdentity id;
521 507
522 GNUNET_PEER_resolve(1, &id); 508 GNUNET_PEER_resolve (1, &id);
523 p1 = GNUNET_PEER_search(first); 509 p1 = GNUNET_PEER_search (first);
524 if (p1 == pid1) 510 if (p1 == pid1)
525 { 511 {
526 p2 = GNUNET_PEER_search(second); 512 p2 = GNUNET_PEER_search (second);
527 if (p2 == 0 || p2 > num_peers) 513 if (p2 == 0 || p2 > num_peers)
528 { 514 {
529 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 515 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
530 "***************** test: %s is UNKNOWN!? (%u)\n", 516 "***************** test: %s is UNKNOWN!? (%u)\n",
531 GNUNET_i2s(second), 517 GNUNET_i2s (second), p2);
532 p2);
533 return; 518 return;
534 } 519 }
535 mesh_peers[p2]++; 520 mesh_peers[p2]++;
536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
537 "***************** test: %s IS a neighbor\n", 522 "***************** test: %s IS a neighbor\n",
538 GNUNET_i2s(second)); 523 GNUNET_i2s (second));
539 return; 524 return;
540 } 525 }
541 p1 = GNUNET_PEER_search(second); 526 p1 = GNUNET_PEER_search (second);
542 if (p1 == pid1) 527 if (p1 == pid1)
543 { 528 {
544 p2 = GNUNET_PEER_search(first); 529 p2 = GNUNET_PEER_search (first);
545 if (p2 == 0 || p2 > num_peers) 530 if (p2 == 0 || p2 > num_peers)
546 { 531 {
547 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 532 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
548 "***************** test: %s is UNKNOWN!? (%u)\n", 533 "***************** test: %s is UNKNOWN!? (%u)\n",
549 GNUNET_i2s(first), 534 GNUNET_i2s (first), p2);
550 p2);
551 return; 535 return;
552 } 536 }
553 mesh_peers[p2]++; 537 mesh_peers[p2]++;
554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
555 "***************** test: %s IS a neighbor\n", 539 "***************** test: %s IS a neighbor\n",
556 GNUNET_i2s(first)); 540 GNUNET_i2s (first));
557 return; 541 return;
558 } 542 }
559} 543}
@@ -569,15 +553,15 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
569 unsigned int i; 553 unsigned int i;
570 struct GNUNET_PeerIdentity id; 554 struct GNUNET_PeerIdentity id;
571 555
572 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: connect_mesh_service\n"); 556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
557 "***************** test: connect_mesh_service\n");
573 558
574 for (i = 1; i <= num_peers; i++) 559 for (i = 1; i <= num_peers; i++)
575 { 560 {
576 GNUNET_PEER_resolve(i, &id); 561 GNUNET_PEER_resolve (i, &id);
577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
578 "***************** test: peer %s has %u conns to d1\n", 563 "***************** test: peer %s has %u conns to d1\n",
579 GNUNET_i2s (&id), 564 GNUNET_i2s (&id), mesh_peers[i]);
580 mesh_peers[i]);
581 if (mesh_peers[i] == 0) 565 if (mesh_peers[i] == 0)
582 break; 566 break;
583 } 567 }
@@ -587,11 +571,10 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
587 { 571 {
588 for (i++; i <= num_peers; i++) 572 for (i++; i <= num_peers; i++)
589 { 573 {
590 GNUNET_PEER_resolve(i, &id); 574 GNUNET_PEER_resolve (i, &id);
591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
592 "***************** test: peer %s has %u conns to d1\n", 576 "***************** test: peer %s has %u conns to d1\n",
593 GNUNET_i2s (&id), 577 GNUNET_i2s (&id), mesh_peers[i]);
594 mesh_peers[i]);
595 if (mesh_peers[i] == 0) 578 if (mesh_peers[i] == 0)
596 break; 579 break;
597 } 580 }
@@ -603,50 +586,32 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
603#if VERBOSE 586#if VERBOSE
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
605 "***************** test: connecting to mesh service of peer %s (%u)\n", 588 "***************** test: connecting to mesh service of peer %s (%u)\n",
606 GNUNET_i2s (&d1->id), 589 GNUNET_i2s (&d1->id), mesh_peers[0]);
607 mesh_peers[0]);
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
609 "***************** test: connecting to mesh service of peer %s (%u)\n", 591 "***************** test: connecting to mesh service of peer %s (%u)\n",
610 GNUNET_i2s (&d2->id), 592 GNUNET_i2s (&d2->id), i);
611 i);
612 if (test == MULTICAST) 593 if (test == MULTICAST)
613 { 594 {
614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 595 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
615 "***************** test: connecting to mesh service of peer %s (%u)\n", 596 "***************** test: connecting to mesh service of peer %s (%u)\n",
616 GNUNET_i2s (&d3->id), 597 GNUNET_i2s (&d3->id), i);
617 i);
618 } 598 }
619#endif 599#endif
620 h1 = GNUNET_MESH_connect (d1->cfg, 600 h1 = GNUNET_MESH_connect (d1->cfg, 10, (void *) 1L, NULL, &tunnel_cleaner,
621 10, 601 handlers, &app);
622 (void *) 1L, 602 h2 = GNUNET_MESH_connect (d2->cfg, 10, (void *) 2L, &incoming_tunnel,
623 NULL, 603 &tunnel_cleaner, handlers, &app);
624 &tunnel_cleaner,
625 handlers,
626 &app);
627 h2 = GNUNET_MESH_connect (d2->cfg,
628 10,
629 (void *) 2L,
630 &incoming_tunnel,
631 &tunnel_cleaner,
632 handlers,
633 &app);
634 if (test == MULTICAST) 604 if (test == MULTICAST)
635 { 605 {
636 h3 = GNUNET_MESH_connect (d3->cfg, 606 h3 = GNUNET_MESH_connect (d3->cfg, 10, (void *) 3L, &incoming_tunnel,
637 10, 607 &tunnel_cleaner, handlers, &app);
638 (void *) 3L,
639 &incoming_tunnel,
640 &tunnel_cleaner,
641 handlers,
642 &app);
643 } 608 }
644 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L); 609 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L);
645 peers_in_tunnel = 0; 610 peers_in_tunnel = 0;
646 test_task = 611 test_task =
647 GNUNET_SCHEDULER_add_delayed( 612 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
648 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6), 613 (GNUNET_TIME_UNIT_SECONDS, 6), &do_test,
649 &do_test, NULL); 614 NULL);
650} 615}
651 616
652 617
@@ -697,25 +662,21 @@ peergroup_ready (void *cls, const char *emsg)
697 GNUNET_PEER_Id peer_id; 662 GNUNET_PEER_Id peer_id;
698 663
699 d1 = GNUNET_TESTING_daemon_get (pg, i); 664 d1 = GNUNET_TESTING_daemon_get (pg, i);
700 peer_id = GNUNET_PEER_intern(&d1->id); 665 peer_id = GNUNET_PEER_intern (&d1->id);
701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: %u: %s\n",
702 "***************** test: %u: %s\n", 667 peer_id, GNUNET_i2s (&d1->id));
703 peer_id,
704 GNUNET_i2s (&d1->id));
705 } 668 }
706 d1 = GNUNET_TESTING_daemon_get (pg, 0); 669 d1 = GNUNET_TESTING_daemon_get (pg, 0);
707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
708 "***************** test: Peer looking: %s\n", 671 "***************** test: Peer looking: %s\n",
709 GNUNET_i2s (&d1->id)); 672 GNUNET_i2s (&d1->id));
710 pid1 = GNUNET_PEER_intern(&d1->id); 673 pid1 = GNUNET_PEER_intern (&d1->id);
711 mesh_peers[pid1] = 100; 674 mesh_peers[pid1] = 100;
712 GNUNET_TESTING_get_topology(pg, &topo_cb, NULL); 675 GNUNET_TESTING_get_topology (pg, &topo_cb, NULL);
713 676
714 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( 677 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
715 GNUNET_TIME_UNIT_SECONDS, 678 (GNUNET_TIME_UNIT_SECONDS, 4),
716 4), 679 &connect_mesh_service, NULL);
717 &connect_mesh_service,
718 NULL);
719 disconnect_task = 680 disconnect_task =
720 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); 681 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
721 682
@@ -753,11 +714,9 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
754 "***************** test: Problem with new connection (%s)\n", 715 "***************** test: Problem with new connection (%s)\n",
755 emsg); 716 emsg);
756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: (%s)\n",
757 "***************** test: (%s)\n",
758 GNUNET_i2s (first)); 718 GNUNET_i2s (first));
759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: (%s)\n",
760 "***************** test: (%s)\n",
761 GNUNET_i2s (second)); 720 GNUNET_i2s (second));
762 } 721 }
763 722
@@ -792,7 +751,8 @@ run (void *cls, char *const *args, const char *cfgfile,
792 NULL); 751 NULL);
793 752
794#if VERBOSE 753#if VERBOSE
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Starting daemons.\n"); 754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
755 "***************** test: Starting daemons.\n");
796 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", 756 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
797 "use_progressbars", "YES"); 757 "use_progressbars", "YES");
798#endif 758#endif
@@ -806,7 +766,7 @@ run (void *cls, char *const *args, const char *cfgfile,
806 return; 766 return;
807 } 767 }
808 768
809 mesh_peers = GNUNET_malloc (sizeof(uint16_t) * (num_peers + 1)); 769 mesh_peers = GNUNET_malloc (sizeof (uint16_t) * (num_peers + 1));
810 770
811 if (GNUNET_OK != 771 if (GNUNET_OK !=
812 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", 772 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
@@ -833,15 +793,15 @@ run (void *cls, char *const *args, const char *cfgfile,
833 &data_filename)) 793 &data_filename))
834 { 794 {
835 data_file = 795 data_file =
836 GNUNET_DISK_file_open (data_filename, 796 GNUNET_DISK_file_open (data_filename,
837 GNUNET_DISK_OPEN_READWRITE | 797 GNUNET_DISK_OPEN_READWRITE |
838 GNUNET_DISK_OPEN_CREATE, 798 GNUNET_DISK_OPEN_CREATE,
839 GNUNET_DISK_PERM_USER_READ | 799 GNUNET_DISK_PERM_USER_READ |
840 GNUNET_DISK_PERM_USER_WRITE); 800 GNUNET_DISK_PERM_USER_WRITE);
841 if (data_file == NULL) 801 if (data_file == NULL)
842 { 802 {
843 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", 803 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
844 data_filename); 804 data_filename);
845 GNUNET_free (data_filename); 805 GNUNET_free (data_filename);
846 } 806 }
847 } 807 }
@@ -939,8 +899,8 @@ main (int argc, char *argv[])
939 899
940 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 900 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
941 "test_mesh_small", 901 "test_mesh_small",
942 gettext_noop ("Test mesh in a small network."), 902 gettext_noop ("Test mesh in a small network."), options,
943 options, &run, NULL); 903 &run, NULL);
944#if REMOVE_DIR 904#if REMOVE_DIR
945 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); 905 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
946#endif 906#endif
@@ -950,8 +910,7 @@ main (int argc, char *argv[])
950 "***************** test: FAILED! (%d/%d)\n", ok, ok_goal); 910 "***************** test: FAILED! (%d/%d)\n", ok, ok_goal);
951 return 1; 911 return 1;
952 } 912 }
953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: success\n");
954 "***************** test: success\n");
955 return 0; 914 return 0;
956} 915}
957 916
diff --git a/src/mesh/test_mesh_small_unicast_far.c b/src/mesh/test_mesh_small_unicast_far.c
index e35922929..cc9995b48 100644
--- a/src/mesh/test_mesh_small_unicast_far.c
+++ b/src/mesh/test_mesh_small_unicast_far.c
@@ -148,7 +148,8 @@ shutdown_callback (void *cls, const char *emsg)
148 else 148 else
149 { 149 {
150#if VERBOSE 150#if VERBOSE
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n"); 151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
152 "test: All peers successfully shut down!\n");
152#endif 153#endif
153 } 154 }
154} 155}
@@ -189,10 +190,10 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
190 "test: disconnecting mesh service of peers\n"); 191 "test: disconnecting mesh service of peers\n");
191 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 192 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
192 GNUNET_MESH_disconnect(h1); 193 GNUNET_MESH_disconnect (h1);
193 GNUNET_MESH_disconnect(h2); 194 GNUNET_MESH_disconnect (h2);
194 GNUNET_SCHEDULER_cancel (shutdown_handle); 195 GNUNET_SCHEDULER_cancel (shutdown_handle);
195 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 196 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
196} 197}
197 198
198 199
@@ -208,16 +209,14 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
208 * (can be NULL -- that's not an error) 209 * (can be NULL -- that's not an error)
209 */ 210 */
210static void * 211static void *
211incoming_tunnel (void *cls, 212incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
212 struct GNUNET_MESH_Tunnel * tunnel, 213 const struct GNUNET_PeerIdentity *initiator,
213 const struct GNUNET_PeerIdentity * initiator, 214 const struct GNUNET_ATS_Information *atsi)
214 const struct GNUNET_ATS_Information * atsi)
215{ 215{
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Incoming tunnel from %s\n",
217 "test: Incoming tunnel from %s\n", 217 GNUNET_i2s (initiator));
218 GNUNET_i2s(initiator));
219 GNUNET_SCHEDULER_cancel (disconnect_task); 218 GNUNET_SCHEDULER_cancel (disconnect_task);
220 disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_mesh_peers, NULL); 219 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
221 ok = 0; 220 ok = 0;
222 return NULL; 221 return NULL;
223} 222}
@@ -238,7 +237,7 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
238#if VERBOSE 237#if VERBOSE
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tunnel disconnected\n"); 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tunnel disconnected\n");
240#endif 239#endif
241 240
242 return; 241 return;
243} 242}
244 243
@@ -251,9 +250,8 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
251static void 250static void
252dh (void *cls, const struct GNUNET_PeerIdentity *peer) 251dh (void *cls, const struct GNUNET_PeerIdentity *peer)
253{ 252{
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s disconnected\n",
255 "test: peer %s disconnected\n", 254 GNUNET_i2s (peer));
256 GNUNET_i2s(peer));
257 return; 255 return;
258} 256}
259 257
@@ -269,9 +267,8 @@ static void
269ch (void *cls, const struct GNUNET_PeerIdentity *peer, 267ch (void *cls, const struct GNUNET_PeerIdentity *peer,
270 const struct GNUNET_ATS_Information *atsi) 268 const struct GNUNET_ATS_Information *atsi)
271{ 269{
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s connected\n",
273 "test: peer %s connected\n", 271 GNUNET_i2s (peer));
274 GNUNET_i2s(peer));
275 return; 272 return;
276} 273}
277 274
@@ -280,11 +277,12 @@ static void
280do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 277do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
281{ 278{
282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); 279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n");
283 GNUNET_MESH_peer_request_connect_add(t, &d2->id); 280 GNUNET_MESH_peer_request_connect_add (t, &d2->id);
284 GNUNET_SCHEDULER_cancel (disconnect_task); 281 GNUNET_SCHEDULER_cancel (disconnect_task);
285 disconnect_task = GNUNET_SCHEDULER_add_delayed( 282 disconnect_task =
286 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), 283 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
287 &disconnect_mesh_peers, NULL); 284 (GNUNET_TIME_UNIT_SECONDS, 30),
285 &disconnect_mesh_peers, NULL);
288} 286}
289 287
290 288
@@ -300,10 +298,9 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
300 298
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n"); 299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n");
302 300
303 GNUNET_PEER_resolve(11, &id); 301 GNUNET_PEER_resolve (11, &id);
304 d2 = GNUNET_TESTING_daemon_get_by_id (pg, &id); 302 d2 = GNUNET_TESTING_daemon_get_by_id (pg, &id);
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer searched: %s\n",
306 "test: Peer searched: %s\n",
307 GNUNET_i2s (&d2->id)); 304 GNUNET_i2s (&d2->id));
308 app = (GNUNET_MESH_ApplicationType) 0; 305 app = (GNUNET_MESH_ApplicationType) 0;
309 306
@@ -315,20 +312,10 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
315 "test: connecting to mesh service of peer %s\n", 312 "test: connecting to mesh service of peer %s\n",
316 GNUNET_i2s (&d2->id)); 313 GNUNET_i2s (&d2->id));
317#endif 314#endif
318 h1 = GNUNET_MESH_connect (d1->cfg, 315 h1 = GNUNET_MESH_connect (d1->cfg, 10, NULL, NULL, &tunnel_cleaner, handlers,
319 10,
320 NULL,
321 NULL,
322 &tunnel_cleaner,
323 handlers,
324 &app);
325 h2 = GNUNET_MESH_connect (d2->cfg,
326 10,
327 NULL,
328 &incoming_tunnel,
329 &tunnel_cleaner,
330 handlers,
331 &app); 316 &app);
317 h2 = GNUNET_MESH_connect (d2->cfg, 10, NULL, &incoming_tunnel,
318 &tunnel_cleaner, handlers, &app);
332#if VERBOSE 319#if VERBOSE
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 "test: connected to mesh service of peer %s\n", 321 "test: connected to mesh service of peer %s\n",
@@ -339,9 +326,9 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
339#endif 326#endif
340 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, NULL); 327 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, NULL);
341 test_task = 328 test_task =
342 GNUNET_SCHEDULER_add_delayed( 329 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
343 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6), 330 (GNUNET_TIME_UNIT_SECONDS, 6), &do_test,
344 &do_test, NULL); 331 NULL);
345} 332}
346 333
347 334
@@ -362,8 +349,8 @@ peergroup_ready (void *cls, const char *emsg)
362 { 349 {
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
364 "test: Peergroup callback called with error, aborting test!\n"); 351 "test: Peergroup callback called with error, aborting test!\n");
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n",
366 "test: Error from testing: `%s'\n", emsg); 353 emsg);
367 ok++; 354 ok++;
368 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 355 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
369 return; 356 return;
@@ -373,8 +360,7 @@ peergroup_ready (void *cls, const char *emsg)
373 "************************************************************\n"); 360 "************************************************************\n");
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "test: Peer Group started successfully!\n"); 362 "test: Peer Group started successfully!\n");
376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n",
377 "test: Have %u connections\n",
378 total_connections); 364 total_connections);
379#endif 365#endif
380 366
@@ -390,18 +376,14 @@ peergroup_ready (void *cls, const char *emsg)
390 for (i = 0; i < num_peers; i++) 376 for (i = 0; i < num_peers; i++)
391 { 377 {
392 d1 = GNUNET_TESTING_daemon_get (pg, i); 378 d1 = GNUNET_TESTING_daemon_get (pg, i);
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %u: %s\n",
394 "test: %u: %s\n", 380 GNUNET_PEER_intern (&d1->id), GNUNET_i2s (&d1->id));
395 GNUNET_PEER_intern(&d1->id),
396 GNUNET_i2s (&d1->id));
397 } 381 }
398 d1 = GNUNET_TESTING_daemon_get (pg, 0); 382 d1 = GNUNET_TESTING_daemon_get (pg, 0);
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer looking: %s\n",
400 "test: Peer looking: %s\n",
401 GNUNET_i2s (&d1->id)); 384 GNUNET_i2s (&d1->id));
402 385
403 GNUNET_SCHEDULER_add_now (&connect_mesh_service, 386 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
404 NULL);
405 disconnect_task = 387 disconnect_task =
406 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); 388 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
407 389
@@ -437,8 +419,7 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
437 else 419 else
438 { 420 {
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "test: Problem with new connection (%s)\n", 422 "test: Problem with new connection (%s)\n", emsg);
441 emsg);
442 } 423 }
443 424
444} 425}
@@ -495,7 +476,7 @@ run (void *cls, char *const *args, const char *cfgfile,
495 } 476 }
496 } 477 }
497 478
498 mesh_peers = GNUNET_malloc (sizeof(GNUNET_PEER_Id) * (num_peers + 1)); 479 mesh_peers = GNUNET_malloc (sizeof (GNUNET_PEER_Id) * (num_peers + 1));
499 480
500 if (GNUNET_OK != 481 if (GNUNET_OK !=
501 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", 482 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
@@ -522,15 +503,15 @@ run (void *cls, char *const *args, const char *cfgfile,
522 &data_filename)) 503 &data_filename))
523 { 504 {
524 data_file = 505 data_file =
525 GNUNET_DISK_file_open (data_filename, 506 GNUNET_DISK_file_open (data_filename,
526 GNUNET_DISK_OPEN_READWRITE | 507 GNUNET_DISK_OPEN_READWRITE |
527 GNUNET_DISK_OPEN_CREATE, 508 GNUNET_DISK_OPEN_CREATE,
528 GNUNET_DISK_PERM_USER_READ | 509 GNUNET_DISK_PERM_USER_READ |
529 GNUNET_DISK_PERM_USER_WRITE); 510 GNUNET_DISK_PERM_USER_WRITE);
530 if (data_file == NULL) 511 if (data_file == NULL)
531 { 512 {
532 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", 513 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
533 data_filename); 514 data_filename);
534 GNUNET_free (data_filename); 515 GNUNET_free (data_filename);
535 } 516 }
536 } 517 }
@@ -585,8 +566,8 @@ int
585main (int argc, char *argv[]) 566main (int argc, char *argv[])
586{ 567{
587 GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast", 568 GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast",
588 gettext_noop ("Test mesh unicast in a small network."), options, 569 gettext_noop ("Test mesh unicast in a small network."),
589 &run, NULL); 570 options, &run, NULL);
590#if REMOVE_DIR 571#if REMOVE_DIR
591 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast"); 572 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast");
592#endif 573#endif
diff --git a/src/mesh/test_mesh_tree_api.c b/src/mesh/test_mesh_tree_api.c
index 8df8fe19b..b1bdcd693 100644
--- a/src/mesh/test_mesh_tree_api.c
+++ b/src/mesh/test_mesh_tree_api.c
@@ -39,16 +39,16 @@
39 39
40int failed; 40int failed;
41int cb_call; 41int cb_call;
42struct GNUNET_PeerIdentity* pi[10]; 42struct GNUNET_PeerIdentity *pi[10];
43struct MeshTunnelTree *tree; 43struct MeshTunnelTree *tree;
44 44
45static void 45static void
46cb (void *cls, GNUNET_PEER_Id peer_id) 46cb (void *cls, GNUNET_PEER_Id peer_id)
47{ 47{
48 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id); 48 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id);
49 if(0 == cb_call) 49 if (0 == cb_call)
50 { 50 {
51 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n"); 51 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n");
52 failed++; 52 failed++;
53 } 53 }
54 cb_call--; 54 cb_call--;
@@ -64,10 +64,8 @@ cb (void *cls, GNUNET_PEER_Id peer_id)
64 * @param first_hop Short ID of the expected first hop towards the peer. 64 * @param first_hop Short ID of the expected first hop towards the peer.
65 */ 65 */
66static void 66static void
67test_assert (GNUNET_PEER_Id peer_id, 67test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status,
68 enum MeshPeerState status, 68 unsigned int children, GNUNET_PEER_Id first_hop)
69 unsigned int children,
70 GNUNET_PEER_Id first_hop)
71{ 69{
72 struct MeshTunnelTreeNode *n; 70 struct MeshTunnelTreeNode *n;
73 struct MeshTunnelTreeNode *c; 71 struct MeshTunnelTreeNode *c;
@@ -75,58 +73,57 @@ test_assert (GNUNET_PEER_Id peer_id,
75 int pre_failed; 73 int pre_failed;
76 74
77 pre_failed = failed; 75 pre_failed = failed;
78 n = tree_find_peer(tree, peer_id); 76 n = tree_find_peer (tree, peer_id);
79 if (n->peer != peer_id) 77 if (n->peer != peer_id)
80 { 78 {
81 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 79 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
82 "Retrieved peer has wrong ID! (%u, %u)\n", 80 "Retrieved peer has wrong ID! (%u, %u)\n", n->peer, peer_id);
83 n->peer, peer_id);
84 failed++; 81 failed++;
85 } 82 }
86 if (n->status != status) 83 if (n->status != status)
87 { 84 {
88 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 85 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
89 "Retrieved peer has wrong status! (%u, %u)\n", 86 "Retrieved peer has wrong status! (%u, %u)\n", n->status,
90 n->status, status); 87 status);
91 failed++; 88 failed++;
92 } 89 }
93 for (c = n->children_head, i = 0; NULL != c; c = c->next, i++); 90 for (c = n->children_head, i = 0; NULL != c; c = c->next, i++) ;
94 if (i != children) 91 if (i != children)
95 { 92 {
96 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 93 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
97 "Retrieved peer wrong has number of children! (%u, %u)\n", 94 "Retrieved peer wrong has number of children! (%u, %u)\n", i,
98 i, children); 95 children);
99 failed++; 96 failed++;
100 } 97 }
101 if (0 != first_hop && 98 if (0 != first_hop &&
102 GNUNET_PEER_search(path_get_first_hop(tree, peer_id)) != first_hop) 99 GNUNET_PEER_search (path_get_first_hop (tree, peer_id)) != first_hop)
103 { 100 {
104 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 101 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Wrong first hop! (%u, %u)\n",
105 "Wrong first hop! (%u, %u)\n", 102 GNUNET_PEER_search (path_get_first_hop (tree, peer_id)),
106 GNUNET_PEER_search(path_get_first_hop(tree, peer_id)), 103 first_hop);
107 first_hop);
108 failed++; 104 failed++;
109 } 105 }
110 if (pre_failed != failed) 106 if (pre_failed != failed)
111 { 107 {
112 struct GNUNET_PeerIdentity id; 108 struct GNUNET_PeerIdentity id;
109
113 GNUNET_PEER_resolve (peer_id, &id); 110 GNUNET_PEER_resolve (peer_id, &id);
114 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 111 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
115 "*** Peer %s (%u) has failed %d checks! (real, expected)\n", 112 "*** Peer %s (%u) has failed %d checks! (real, expected)\n",
116 GNUNET_i2s (&id), peer_id, failed - pre_failed); 113 GNUNET_i2s (&id), peer_id, failed - pre_failed);
117 } 114 }
118} 115}
119 116
120 117
121static void 118static void
122finish(void) 119finish (void)
123{ 120{
124 unsigned int i; 121 unsigned int i;
125 122
126 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n"); 123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n");
127 for (i = 0; i < 10; i++) 124 for (i = 0; i < 10; i++)
128 { 125 {
129 GNUNET_free(pi[i]); 126 GNUNET_free (pi[i]);
130 } 127 }
131} 128}
132 129
@@ -138,7 +135,7 @@ get_pi (uint32_t id)
138{ 135{
139 struct GNUNET_PeerIdentity *pi; 136 struct GNUNET_PeerIdentity *pi;
140 137
141 pi = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 138 pi = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
142 pi->hashPubKey.bits[0] = id + 1; 139 pi->hashPubKey.bits[0] = id + 1;
143 return pi; 140 return pi;
144} 141}
@@ -164,11 +161,10 @@ main (int argc, char *argv[])
164 NULL); 161 NULL);
165 for (i = 0; i < 10; i++) 162 for (i = 0; i < 10; i++)
166 { 163 {
167 pi[i] = get_pi(i); 164 pi[i] = get_pi (i);
168 GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i])); 165 GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i]));
169 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", 166 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", i + 1,
170 i + 1, 167 GNUNET_h2s (&pi[i]->hashPubKey));
171 GNUNET_h2s(&pi[i]->hashPubKey));
172 } 168 }
173 tree = tree_new (1); 169 tree = tree_new (1);
174 tree->me = tree->root; 170 tree->me = tree->root;
@@ -179,37 +175,37 @@ main (int argc, char *argv[])
179 path->peers[3] = 4; 175 path->peers[3] = 4;
180 path->length = 4; 176 path->length = 4;
181 177
182 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n"); 178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n");
183 tree_add_path(tree, path, &cb, NULL); 179 tree_add_path (tree, path, &cb, NULL);
184 tree_debug(tree); 180 tree_debug (tree);
185 path1 = tree_get_path_to_peer(tree, 4); 181 path1 = tree_get_path_to_peer (tree, 4);
186 if (path->length != path1->length || 182 if (path->length != path1->length ||
187 memcmp(path->peers, path1->peers, path->length) != 0) 183 memcmp (path->peers, path1->peers, path->length) != 0)
188 { 184 {
189 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n"); 185 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n");
190 failed++; 186 failed++;
191 } 187 }
192 path_destroy(path1); 188 path_destroy (path1);
193 test_assert (4, MESH_PEER_SEARCHING, 0, 2); 189 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
194 test_assert (3, MESH_PEER_RELAY, 1, 0); 190 test_assert (3, MESH_PEER_RELAY, 1, 0);
195 test_assert (2, MESH_PEER_RELAY, 1, 0); 191 test_assert (2, MESH_PEER_RELAY, 1, 0);
196 test_assert (1, MESH_PEER_ROOT, 1, 0); 192 test_assert (1, MESH_PEER_ROOT, 1, 0);
197 193
198 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n"); 194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n");
199 path->length--; 195 path->length--;
200 tree_add_path(tree, path, &cb, NULL); 196 tree_add_path (tree, path, &cb, NULL);
201 tree_debug(tree); 197 tree_debug (tree);
202 198
203 test_assert (4, MESH_PEER_SEARCHING, 0, 2); 199 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
204 test_assert (3, MESH_PEER_SEARCHING, 1, 2); 200 test_assert (3, MESH_PEER_SEARCHING, 1, 2);
205 test_assert (2, MESH_PEER_RELAY, 1, 0); 201 test_assert (2, MESH_PEER_RELAY, 1, 0);
206 test_assert (1, MESH_PEER_ROOT, 1, 0); 202 test_assert (1, MESH_PEER_ROOT, 1, 0);
207 203
208 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n"); 204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n");
209 path->length++; 205 path->length++;
210 path->peers[3] = 5; 206 path->peers[3] = 5;
211 tree_add_path(tree, path, &cb, NULL); 207 tree_add_path (tree, path, &cb, NULL);
212 tree_debug(tree); 208 tree_debug (tree);
213 209
214 test_assert (5, MESH_PEER_SEARCHING, 0, 2); 210 test_assert (5, MESH_PEER_SEARCHING, 0, 2);
215 test_assert (4, MESH_PEER_SEARCHING, 0, 2); 211 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
@@ -217,20 +213,20 @@ main (int argc, char *argv[])
217 test_assert (2, MESH_PEER_RELAY, 1, 0); 213 test_assert (2, MESH_PEER_RELAY, 1, 0);
218 test_assert (1, MESH_PEER_ROOT, 1, 0); 214 test_assert (1, MESH_PEER_ROOT, 1, 0);
219 215
220 node = tree_find_peer(tree, 5); 216 node = tree_find_peer (tree, 5);
221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n"); 217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n");
222 node->status = MESH_PEER_READY; 218 node->status = MESH_PEER_READY;
223 cb_call = 1; 219 cb_call = 1;
224 node2 = tree_del_path(tree, 5, &cb, NULL); 220 node2 = tree_del_path (tree, 5, &cb, NULL);
225 tree_debug(tree); 221 tree_debug (tree);
226 if (cb_call != 0) 222 if (cb_call != 0)
227 { 223 {
228 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); 224 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
229 failed++; 225 failed++;
230 } 226 }
231 if (node2->peer != 5) 227 if (node2->peer != 5)
232 { 228 {
233 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); 229 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
234 failed++; 230 failed++;
235 } 231 }
236 232
@@ -239,20 +235,20 @@ main (int argc, char *argv[])
239 test_assert (2, MESH_PEER_RELAY, 1, 0); 235 test_assert (2, MESH_PEER_RELAY, 1, 0);
240 test_assert (1, MESH_PEER_ROOT, 1, 0); 236 test_assert (1, MESH_PEER_ROOT, 1, 0);
241 237
242 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n"); 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n");
243 GNUNET_free (node2); 239 GNUNET_free (node2);
244 240
245 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
246 "test: Adding new shorter first path...\n"); 242 "test: Adding new shorter first path...\n");
247 path->length = 2; 243 path->length = 2;
248 path->peers[1] = 4; 244 path->peers[1] = 4;
249 cb_call = 1; 245 cb_call = 1;
250 tree_find_peer(tree, 4)->status = MESH_PEER_READY; 246 tree_find_peer (tree, 4)->status = MESH_PEER_READY;
251 tree_add_path(tree, path, &cb, NULL); 247 tree_add_path (tree, path, &cb, NULL);
252 tree_debug(tree); 248 tree_debug (tree);
253 if (cb_call != 0) 249 if (cb_call != 0)
254 { 250 {
255 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); 251 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
256 failed++; 252 failed++;
257 } 253 }
258 254
@@ -265,35 +261,35 @@ main (int argc, char *argv[])
265 GNUNET_free (path); 261 GNUNET_free (path);
266 tree_destroy (tree); 262 tree_destroy (tree);
267 263
268 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test:\n"); 264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test:\n");
269 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n"); 265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n");
270 for (i = 0; i < 10; i++) 266 for (i = 0; i < 10; i++)
271 { 267 {
272 GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i])); 268 GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i]));
273 } 269 }
274 tree = tree_new(1); 270 tree = tree_new (1);
275 path = path_new (3); 271 path = path_new (3);
276 path->peers[0] = 1; 272 path->peers[0] = 1;
277 path->peers[1] = 2; 273 path->peers[1] = 2;
278 path->peers[2] = 3; 274 path->peers[2] = 3;
279 path->length = 3; 275 path->length = 3;
280 276
281 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n"); 277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n");
282 tree_add_path(tree, path, &cb, NULL); 278 tree_add_path (tree, path, &cb, NULL);
283 tree_debug(tree); 279 tree_debug (tree);
284 tree_set_me (tree, 2); 280 tree_set_me (tree, 2);
285 281
286 test_assert (3, MESH_PEER_SEARCHING, 0, 3); 282 test_assert (3, MESH_PEER_SEARCHING, 0, 3);
287 test_assert (2, MESH_PEER_RELAY, 1, 0); 283 test_assert (2, MESH_PEER_RELAY, 1, 0);
288 test_assert (1, MESH_PEER_ROOT, 1, 0); 284 test_assert (1, MESH_PEER_ROOT, 1, 0);
289 285
290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n"); 286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n");
291 tree_add_path(tree, path, &cb, NULL); 287 tree_add_path (tree, path, &cb, NULL);
292 288
293 GNUNET_free (path->peers); 289 GNUNET_free (path->peers);
294 GNUNET_free (path); 290 GNUNET_free (path);
295 tree_destroy (tree); 291 tree_destroy (tree);
296 finish(); 292 finish ();
297 if (failed > 0) 293 if (failed > 0)
298 { 294 {
299 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed); 295 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed);