aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-02-08 15:23:34 +0000
committerBart Polot <bart@net.in.tum.de>2012-02-08 15:23:34 +0000
commitdef7109bb2daa04027c2de91883486f509f39849 (patch)
tree5e3d5693c1065b18dbf4ad9eb1399c8389d299ab /src/mesh
parenteb9946906b648956195b9de60bfbde047956810f (diff)
downloadgnunet-def7109bb2daa04027c2de91883486f509f39849.tar.gz
gnunet-def7109bb2daa04027c2de91883486f509f39849.zip
Attemp to fix ctrl-c crashes - disconnect from services before calling daemons_stop, since the cfg is free'd in the latter.
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c2
-rw-r--r--src/mesh/mesh_api.c108
-rw-r--r--src/mesh/test_mesh_small.c27
3 files changed, 96 insertions, 41 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 33643e2c7..ab5b5000b 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -1614,7 +1614,7 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t)
1614 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 1614 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
1615 GNUNET_BLOCK_TYPE_TEST, /* type */ 1615 GNUNET_BLOCK_TYPE_TEST, /* type */
1616 &id.hashPubKey, /* key to search */ 1616 &id.hashPubKey, /* key to search */
1617 4, /* replication level */ 1617 10U, /* replication level */
1618 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ 1618 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
1619 0, /* xquery bits */ 1619 0, /* xquery bits */
1620 &dht_get_id_handler, path_info); 1620 &dht_get_id_handler, path_info);
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index d4c2e8155..94b9f07de 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -207,6 +207,11 @@ struct GNUNET_MESH_Handle
207 * Time to the next reconnect in case one reconnect fails 207 * Time to the next reconnect in case one reconnect fails
208 */ 208 */
209 struct GNUNET_TIME_Relative reconnect_time; 209 struct GNUNET_TIME_Relative reconnect_time;
210
211 /**
212 * Task for trying to reconnect.
213 */
214 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
210}; 215};
211 216
212 217
@@ -629,7 +634,7 @@ send_connect (struct GNUNET_MESH_Handle *h)
629 for (napps = 0; napps < h->n_applications; napps++) 634 for (napps = 0; napps < h->n_applications; napps++)
630 { 635 {
631 apps[napps] = htonl (h->applications[napps]); 636 apps[napps] = htonl (h->applications[napps]);
632 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: app %u\n", h->applications[napps]); 637 LOG (GNUNET_ERROR_TYPE_DEBUG, " app %u\n", h->applications[napps]);
633 } 638 }
634 types = (uint16_t *) & apps[napps]; 639 types = (uint16_t *) & apps[napps];
635 for (ntypes = 0; ntypes < h->n_handlers; ntypes++) 640 for (ntypes = 0; ntypes < h->n_handlers; ntypes++)
@@ -637,7 +642,7 @@ send_connect (struct GNUNET_MESH_Handle *h)
637 msg->applications = htons (napps); 642 msg->applications = htons (napps);
638 msg->types = htons (ntypes); 643 msg->types = htons (ntypes);
639 LOG (GNUNET_ERROR_TYPE_DEBUG, 644 LOG (GNUNET_ERROR_TYPE_DEBUG,
640 "mesh: Sending %lu bytes long message %d types and %d apps\n", 645 "Sending %lu bytes long message %d types and %d apps\n",
641 ntohs (msg->header.size), ntypes, napps); 646 ntohs (msg->header.size), ntypes, napps);
642 send_packet (h, &msg->header, NULL); 647 send_packet (h, &msg->header, NULL);
643 } 648 }
@@ -653,14 +658,14 @@ send_connect (struct GNUNET_MESH_Handle *h)
653 * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...) 658 * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...)
654 */ 659 */
655static int 660static int
656reconnect (struct GNUNET_MESH_Handle *h) 661do_reconnect (struct GNUNET_MESH_Handle *h)
657{ 662{
658 struct GNUNET_MESH_Tunnel *t; 663 struct GNUNET_MESH_Tunnel *t;
659 unsigned int i; 664 unsigned int i;
660 665
661 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n"); 666 LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n");
662 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: ******* RECONNECT *******\n"); 667 LOG (GNUNET_ERROR_TYPE_DEBUG, "******* RECONNECT *******\n");
663 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n"); 668 LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n");
664 669
665 h->in_receive = GNUNET_NO; 670 h->in_receive = GNUNET_NO;
666 /* disconnect */ 671 /* disconnect */
@@ -678,12 +683,13 @@ reconnect (struct GNUNET_MESH_Handle *h)
678 h->client = GNUNET_CLIENT_connect ("mesh", h->cfg); 683 h->client = GNUNET_CLIENT_connect ("mesh", h->cfg);
679 if (h->client == NULL) 684 if (h->client == NULL)
680 { 685 {
681 GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h); 686 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time,
687 &reconnect_cbk, h);
682 h->reconnect_time = 688 h->reconnect_time =
683 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, 689 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
684 GNUNET_TIME_relative_multiply 690 GNUNET_TIME_relative_multiply
685 (h->reconnect_time, 2)); 691 (h->reconnect_time, 2));
686 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Next retry in %sms\n", 692 LOG (GNUNET_ERROR_TYPE_DEBUG, " Next retry in %sms\n",
687 GNUNET_TIME_relative_to_string (h->reconnect_time)); 693 GNUNET_TIME_relative_to_string (h->reconnect_time));
688 GNUNET_break (0); 694 GNUNET_break (0);
689 return GNUNET_NO; 695 return GNUNET_NO;
@@ -752,9 +758,26 @@ reconnect_cbk (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
752{ 758{
753 struct GNUNET_MESH_Handle *h = cls; 759 struct GNUNET_MESH_Handle *h = cls;
754 760
755 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 761 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
762 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
756 return; 763 return;
757 reconnect (h); 764 do_reconnect (h);
765}
766
767
768/**
769 * Reconnect to the service, retransmit all infomation to try to restore the
770 * original state.
771 *
772 * @param h handle to the mesh
773 *
774 * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...)
775 */
776static void
777reconnect (struct GNUNET_MESH_Handle *h)
778{
779 if (GNUNET_SCHEDULER_NO_TASK != h->reconnect_task)
780 GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h);
758} 781}
759 782
760 783
@@ -800,7 +823,7 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h,
800 atsi.value = 0; 823 atsi.value = 0;
801 t->ctx = h->new_tunnel (h->cls, t, &msg->peer, &atsi); 824 t->ctx = h->new_tunnel (h->cls, t, &msg->peer, &atsi);
802 } 825 }
803 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: new incoming tunnel %X\n", t->tid); 826 LOG (GNUNET_ERROR_TYPE_DEBUG, "new incoming tunnel %X\n", t->tid);
804 return; 827 return;
805} 828}
806 829
@@ -829,7 +852,7 @@ process_tunnel_destroy (struct GNUNET_MESH_Handle *h,
829 { 852 {
830 GNUNET_break (0); 853 GNUNET_break (0);
831 } 854 }
832 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: tunnel %u destroyed\n", t->tid); 855 LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %u destroyed\n", t->tid);
833 destroy_tunnel (t, GNUNET_YES); 856 destroy_tunnel (t, GNUNET_YES);
834 return; 857 return;
835} 858}
@@ -851,7 +874,7 @@ process_peer_event (struct GNUNET_MESH_Handle *h,
851 GNUNET_PEER_Id id; 874 GNUNET_PEER_Id id;
852 uint16_t size; 875 uint16_t size;
853 876
854 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: processig peer event\n"); 877 LOG (GNUNET_ERROR_TYPE_DEBUG, "processig peer event\n");
855 size = ntohs (msg->header.size); 878 size = ntohs (msg->header.size);
856 if (size != sizeof (struct GNUNET_MESH_PeerControl)) 879 if (size != sizeof (struct GNUNET_MESH_PeerControl))
857 { 880 {
@@ -869,7 +892,7 @@ process_peer_event (struct GNUNET_MESH_Handle *h,
869 p = add_peer_to_tunnel (t, &msg->peer); 892 p = add_peer_to_tunnel (t, &msg->peer);
870 if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD == ntohs (msg->header.type)) 893 if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD == ntohs (msg->header.type))
871 { 894 {
872 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: adding peer\n"); 895 LOG (GNUNET_ERROR_TYPE_DEBUG, "adding peer\n");
873 if (NULL != t->connect_handler) 896 if (NULL != t->connect_handler)
874 { 897 {
875 atsi.type = 0; 898 atsi.type = 0;
@@ -880,7 +903,7 @@ process_peer_event (struct GNUNET_MESH_Handle *h,
880 } 903 }
881 else 904 else
882 { 905 {
883 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: removing peer\n"); 906 LOG (GNUNET_ERROR_TYPE_DEBUG, "removing peer\n");
884 if (NULL != t->disconnect_handler && p->connected) 907 if (NULL != t->disconnect_handler && p->connected)
885 { 908 {
886 t->disconnect_handler (t->cls, &msg->peer); 909 t->disconnect_handler (t->cls, &msg->peer);
@@ -888,7 +911,7 @@ process_peer_event (struct GNUNET_MESH_Handle *h,
888 remove_peer_from_tunnel (p); 911 remove_peer_from_tunnel (p);
889 GNUNET_free (p); 912 GNUNET_free (p);
890 } 913 }
891 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: processing peer event END\n"); 914 LOG (GNUNET_ERROR_TYPE_DEBUG, "processing peer event END\n");
892} 915}
893 916
894 917
@@ -915,7 +938,7 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
915 unsigned int i; 938 unsigned int i;
916 uint16_t type; 939 uint16_t type;
917 940
918 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Got a data message!\n"); 941 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a data message!\n");
919 type = ntohs (message->type); 942 type = ntohs (message->type);
920 switch (type) 943 switch (type)
921 { 944 {
@@ -925,7 +948,7 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
925 t = retrieve_tunnel (h, ntohl (ucast->tid)); 948 t = retrieve_tunnel (h, ntohl (ucast->tid));
926 payload = (struct GNUNET_MessageHeader *) &ucast[1]; 949 payload = (struct GNUNET_MessageHeader *) &ucast[1];
927 peer = &ucast->oid; 950 peer = &ucast->oid;
928 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: ucast on tunnel %s [%x]\n", 951 LOG (GNUNET_ERROR_TYPE_DEBUG, " ucast on tunnel %s [%x]\n",
929 GNUNET_i2s (peer), ntohl (ucast->tid)); 952 GNUNET_i2s (peer), ntohl (ucast->tid));
930 break; 953 break;
931 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: 954 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
@@ -933,7 +956,7 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
933 t = retrieve_tunnel (h, ntohl (mcast->tid)); 956 t = retrieve_tunnel (h, ntohl (mcast->tid));
934 payload = (struct GNUNET_MessageHeader *) &mcast[1]; 957 payload = (struct GNUNET_MessageHeader *) &mcast[1];
935 peer = &mcast->oid; 958 peer = &mcast->oid;
936 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: mcast on tunnel %s [%x]\n", 959 LOG (GNUNET_ERROR_TYPE_DEBUG, " mcast on tunnel %s [%x]\n",
937 GNUNET_i2s (peer), ntohl (mcast->tid)); 960 GNUNET_i2s (peer), ntohl (mcast->tid));
938 break; 961 break;
939 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: 962 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
@@ -941,7 +964,7 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
941 t = retrieve_tunnel (h, ntohl (to_orig->tid)); 964 t = retrieve_tunnel (h, ntohl (to_orig->tid));
942 payload = (struct GNUNET_MessageHeader *) &to_orig[1]; 965 payload = (struct GNUNET_MessageHeader *) &to_orig[1];
943 peer = &to_orig->sender; 966 peer = &to_orig->sender;
944 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: torig on tunnel %s [%x]\n", 967 LOG (GNUNET_ERROR_TYPE_DEBUG, " torig on tunnel %s [%x]\n",
945 GNUNET_i2s (peer), ntohl (to_orig->tid)); 968 GNUNET_i2s (peer), ntohl (to_orig->tid));
946 break; 969 break;
947 default: 970 default:
@@ -995,10 +1018,11 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
995 1018
996 if (msg == NULL) 1019 if (msg == NULL)
997 { 1020 {
1021 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NULL msg\n");
998 reconnect (h); 1022 reconnect (h);
999 return; 1023 return;
1000 } 1024 }
1001 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: received a message type %hu from MESH\n", 1025 LOG (GNUNET_ERROR_TYPE_DEBUG, "received a message type %hu from MESH\n",
1002 ntohs (msg->type)); 1026 ntohs (msg->type));
1003 switch (ntohs (msg->type)) 1027 switch (ntohs (msg->type))
1004 { 1028 {
@@ -1028,7 +1052,7 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
1028 "MESH: unsolicited message form service (type %d)\n", 1052 "MESH: unsolicited message form service (type %d)\n",
1029 ntohs (msg->type)); 1053 ntohs (msg->type));
1030 } 1054 }
1031 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: message processed\n"); 1055 LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n");
1032 GNUNET_CLIENT_receive (h->client, &msg_received, h, 1056 GNUNET_CLIENT_receive (h->client, &msg_received, h,
1033 GNUNET_TIME_UNIT_FOREVER_REL); 1057 GNUNET_TIME_UNIT_FOREVER_REL);
1034} 1058}
@@ -1057,11 +1081,12 @@ send_callback (void *cls, size_t size, void *buf)
1057 size_t tsize; 1081 size_t tsize;
1058 size_t psize; 1082 size_t psize;
1059 1083
1060 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() Buffer %u\n", size); 1084 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send packet() Buffer %u\n", size);
1061 h->th = NULL; 1085 h->th = NULL;
1062 if ((0 == size) || (NULL == buf)) 1086 if ((0 == size) || (NULL == buf))
1063 { 1087 {
1064 reconnect (h); 1088 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NULL callback\n");
1089// reconnect (h); FIXME
1065 return 0; 1090 return 0;
1066 } 1091 }
1067 tsize = 0; 1092 tsize = 0;
@@ -1078,7 +1103,7 @@ send_callback (void *cls, size_t size, void *buf)
1078 GNUNET_assert (size >= th->size); 1103 GNUNET_assert (size >= th->size);
1079 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)]; 1104 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)];
1080 psize = th->notify (th->notify_cls, size - sizeof (to), mh); 1105 psize = th->notify (th->notify_cls, size - sizeof (to), mh);
1081 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: to origin, type %u\n", 1106 LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin, type %u\n",
1082 ntohs (mh->type)); 1107 ntohs (mh->type));
1083 if (psize > 0) 1108 if (psize > 0)
1084 { 1109 {
@@ -1101,7 +1126,7 @@ send_callback (void *cls, size_t size, void *buf)
1101 GNUNET_assert (size >= th->size); 1126 GNUNET_assert (size >= th->size);
1102 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)]; 1127 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)];
1103 psize = th->notify (th->notify_cls, size - sizeof (mc), mh); 1128 psize = th->notify (th->notify_cls, size - sizeof (mc), mh);
1104 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: multicast, type %u\n", 1129 LOG (GNUNET_ERROR_TYPE_DEBUG, " multicast, type %u\n",
1105 ntohs (mh->type)); 1130 ntohs (mh->type));
1106 if (psize > 0) 1131 if (psize > 0)
1107 { 1132 {
@@ -1125,7 +1150,7 @@ send_callback (void *cls, size_t size, void *buf)
1125 GNUNET_assert (size >= th->size); 1150 GNUNET_assert (size >= th->size);
1126 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)]; 1151 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)];
1127 psize = th->notify (th->notify_cls, size - sizeof (uc), mh); 1152 psize = th->notify (th->notify_cls, size - sizeof (uc), mh);
1128 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: unicast, type %u\n", 1153 LOG (GNUNET_ERROR_TYPE_DEBUG, " unicast, type %u\n",
1129 ntohs (mh->type)); 1154 ntohs (mh->type));
1130 if (psize > 0) 1155 if (psize > 0)
1131 { 1156 {
@@ -1158,17 +1183,17 @@ send_callback (void *cls, size_t size, void *buf)
1158 size -= psize; 1183 size -= psize;
1159 tsize += psize; 1184 tsize += psize;
1160 } 1185 }
1161 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: total size: %u\n", tsize); 1186 LOG (GNUNET_ERROR_TYPE_DEBUG, " total size: %u\n", tsize);
1162 if (NULL != (th = h->th_head)) 1187 if (NULL != (th = h->th_head))
1163 { 1188 {
1164 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: next size: %u\n", th->size); 1189 LOG (GNUNET_ERROR_TYPE_DEBUG, " next size: %u\n", th->size);
1165 if (NULL == h->th) 1190 if (NULL == h->th)
1166 h->th = 1191 h->th =
1167 GNUNET_CLIENT_notify_transmit_ready (h->client, th->size, 1192 GNUNET_CLIENT_notify_transmit_ready (h->client, th->size,
1168 GNUNET_TIME_UNIT_FOREVER_REL, 1193 GNUNET_TIME_UNIT_FOREVER_REL,
1169 GNUNET_YES, &send_callback, h); 1194 GNUNET_YES, &send_callback, h);
1170 } 1195 }
1171 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() END\n"); 1196 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send packet() END\n");
1172 if (GNUNET_NO == h->in_receive) 1197 if (GNUNET_NO == h->in_receive)
1173 { 1198 {
1174 h->in_receive = GNUNET_YES; 1199 h->in_receive = GNUNET_YES;
@@ -1248,7 +1273,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1248{ 1273{
1249 struct GNUNET_MESH_Handle *h; 1274 struct GNUNET_MESH_Handle *h;
1250 1275
1251 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n"); 1276 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect()\n");
1252 h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); 1277 h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
1253 h->cfg = cfg; 1278 h->cfg = cfg;
1254 h->max_queue_size = queue_size; 1279 h->max_queue_size = queue_size;
@@ -1272,7 +1297,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1272 for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ; 1297 for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ;
1273 for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ; 1298 for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ;
1274 send_connect (h); 1299 send_connect (h);
1275 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect() END\n"); 1300 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect() END\n");
1276 return h; 1301 return h;
1277} 1302}
1278 1303
@@ -1299,7 +1324,7 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1299 if (t->tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) 1324 if (t->tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
1300 { 1325 {
1301 GNUNET_break (0); 1326 GNUNET_break (0);
1302 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: tunnel %X not destroyed\n", t->tid); 1327 LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X not destroyed\n", t->tid);
1303 } 1328 }
1304 destroy_tunnel (t, GNUNET_YES); 1329 destroy_tunnel (t, GNUNET_YES);
1305 t = aux; 1330 t = aux;
@@ -1321,7 +1346,7 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1321 break; 1346 break;
1322 default: 1347 default:
1323 GNUNET_break (0); 1348 GNUNET_break (0);
1324 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: unexpected msg %u\n", 1349 LOG (GNUNET_ERROR_TYPE_DEBUG, "unexpected msg %u\n",
1325 ntohs(msg->type)); 1350 ntohs(msg->type));
1326 } 1351 }
1327 1352
@@ -1339,6 +1364,11 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1339 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); 1364 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
1340 handle->client = NULL; 1365 handle->client = NULL;
1341 } 1366 }
1367 if (GNUNET_SCHEDULER_NO_TASK != handle->reconnect_task)
1368 {
1369 GNUNET_SCHEDULER_cancel(handle->reconnect_task);
1370 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1371 }
1342 GNUNET_free (handle); 1372 GNUNET_free (handle);
1343} 1373}
1344 1374
@@ -1362,7 +1392,7 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx,
1362 struct GNUNET_MESH_Tunnel *t; 1392 struct GNUNET_MESH_Tunnel *t;
1363 struct GNUNET_MESH_TunnelMessage msg; 1393 struct GNUNET_MESH_TunnelMessage msg;
1364 1394
1365 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Creating new tunnel\n"); 1395 LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating new tunnel\n");
1366 t = create_tunnel (h, 0); 1396 t = create_tunnel (h, 0);
1367 t->connect_handler = connect_handler; 1397 t->connect_handler = connect_handler;
1368 t->disconnect_handler = disconnect_handler; 1398 t->disconnect_handler = disconnect_handler;
@@ -1389,7 +1419,7 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel)
1389 struct GNUNET_MESH_TunnelMessage msg; 1419 struct GNUNET_MESH_TunnelMessage msg;
1390 struct GNUNET_MESH_TransmitHandle *th; 1420 struct GNUNET_MESH_TransmitHandle *th;
1391 1421
1392 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); 1422 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying tunnel\n");
1393 h = tunnel->mesh; 1423 h = tunnel->mesh;
1394 1424
1395 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); 1425 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
@@ -1564,11 +1594,11 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
1564 size_t overhead; 1594 size_t overhead;
1565 1595
1566 GNUNET_assert (NULL != tunnel); 1596 GNUNET_assert (NULL != tunnel);
1567 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: mesh notify transmit ready called\n"); 1597 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh notify transmit ready called\n");
1568 if (NULL != target) 1598 if (NULL != target)
1569 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: target %s\n", GNUNET_i2s (target)); 1599 LOG (GNUNET_ERROR_TYPE_DEBUG, " target %s\n", GNUNET_i2s (target));
1570 else 1600 else
1571 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: target multicast\n"); 1601 LOG (GNUNET_ERROR_TYPE_DEBUG, " target multicast\n");
1572 GNUNET_assert (NULL != notify); 1602 GNUNET_assert (NULL != notify);
1573 if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && 1603 if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size &&
1574 tunnel->npackets > 0) 1604 tunnel->npackets > 0)
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c
index 1e0f2def2..4b3856e1d 100644
--- a/src/mesh/test_mesh_small.c
+++ b/src/mesh/test_mesh_small.c
@@ -26,6 +26,8 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_testing_lib.h" 27#include "gnunet_testing_lib.h"
28#include "gnunet_mesh_service.h" 28#include "gnunet_mesh_service.h"
29#include <gauger.h>
30
29 31
30#define VERBOSE GNUNET_YES 32#define VERBOSE GNUNET_YES
31#define REMOVE_DIR GNUNET_YES 33#define REMOVE_DIR GNUNET_YES
@@ -217,6 +219,22 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
217 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 219 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
218 } 220 }
219 221
222 if (NULL != h1)
223 {
224 GNUNET_MESH_disconnect (h1);
225 h1 = NULL;
226 }
227 if (NULL != h2)
228 {
229 GNUNET_MESH_disconnect (h2);
230 h2 = NULL;
231 }
232 if (test == MULTICAST && NULL != h3)
233 {
234 GNUNET_MESH_disconnect (h3);
235 h3 = NULL;
236 }
237
220 if (data_file != NULL) 238 if (data_file != NULL)
221 GNUNET_DISK_file_close (data_file); 239 GNUNET_DISK_file_close (data_file);
222 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 240 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
@@ -250,8 +268,12 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
250 } 268 }
251 GNUNET_MESH_disconnect (h1); 269 GNUNET_MESH_disconnect (h1);
252 GNUNET_MESH_disconnect (h2); 270 GNUNET_MESH_disconnect (h2);
271 h1 = h2 = NULL;
253 if (test == MULTICAST) 272 if (test == MULTICAST)
273 {
254 GNUNET_MESH_disconnect (h3); 274 GNUNET_MESH_disconnect (h3);
275 h3 = NULL;
276 }
255 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle) 277 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
256 { 278 {
257 GNUNET_SCHEDULER_cancel (shutdown_handle); 279 GNUNET_SCHEDULER_cancel (shutdown_handle);
@@ -376,11 +398,14 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
376 return GNUNET_OK; 398 return GNUNET_OK;
377 end_time = GNUNET_TIME_absolute_get(); 399 end_time = GNUNET_TIME_absolute_get();
378 total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time); 400 total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time);
379 FPRINTF (stderr, "\nTest time %llu ms\n", total_time.rel_value); 401 FPRINTF (stderr, "\nTest time %llu ms\n",
402 (unsigned long long) total_time.rel_value);
380 FPRINTF (stderr, "Test bandwidth: %f kb/s\n", 403 FPRINTF (stderr, "Test bandwidth: %f kb/s\n",
381 4000.0 / total_time.rel_value); 404 4000.0 / total_time.rel_value);
382 FPRINTF (stderr, "Test throughput: %f packets/s\n", 405 FPRINTF (stderr, "Test throughput: %f packets/s\n",
383 1000000.0 / total_time.rel_value); 406 1000000.0 / total_time.rel_value);
407 GAUGER ("MESH", "Tunnel 5 peers", 1000000.0 / total_time.rel_value,
408 "packets/s");
384 } 409 }
385 GNUNET_MESH_tunnel_destroy (tunnel); 410 GNUNET_MESH_tunnel_destroy (tunnel);
386 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 411 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)