switching transport tests to new MQ-based transport API
authorChristian Grothoff <christian@grothoff.org>
Mon, 25 Jul 2016 00:30:00 +0000 (00:30 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 25 Jul 2016 00:30:00 +0000 (00:30 +0000)
29 files changed:
src/include/Makefile.am
src/include/gnunet_transport_core_service.h
src/include/gnunet_transport_manipulation_service.h [new file with mode: 0644]
src/transport/Makefile.am
src/transport/gnunet-service-transport_clients.c
src/transport/plugin_transport_wlan.c
src/transport/test_quota_compliance.c
src/transport/test_transport_address_switch.c
src/transport/test_transport_api.c
src/transport/test_transport_api_blacklisting.c
src/transport/test_transport_api_disconnect.c
src/transport/test_transport_api_limited_sockets.c
src/transport/test_transport_api_manipulation_cfg.c
src/transport/test_transport_api_manipulation_recv_tcp.c
src/transport/test_transport_api_manipulation_send_tcp.c
src/transport/test_transport_api_monitor_peers.c
src/transport/test_transport_api_reliability.c
src/transport/test_transport_api_restart_reconnect.c
src/transport/test_transport_api_timeout.c
src/transport/test_transport_testing_restart.c
src/transport/test_transport_testing_startstop.c
src/transport/transport-testing-main.c
src/transport/transport-testing-send.c
src/transport/transport-testing.c
src/transport/transport-testing.h
src/transport/transport_api_core.c
src/transport/transport_api_get_hello.c
src/transport/transport_api_manipulation.c [new file with mode: 0644]
src/util/mq.c

index 0faec4cfc3c607f4fe092e83da8de50e2c624f52..0ba6f8c744018101989b2da03c5b279f3f2bf608 100644 (file)
@@ -118,6 +118,11 @@ gnunetinclude_HEADERS = \
   gnunet_testing_lib.h \
   gnunet_time_lib.h \
   gnunet_transport_service.h \
+  gnunet_transport_communication_service.h \
+  gnunet_transport_core_service.h \
+  gnunet_transport_hello_service.h \
+  gnunet_transport_manipulation_service.h \
+  gnunet_transport_monitor_service.h \
   gnunet_transport_plugin.h \
   gnunet_tun_lib.h \
   gnunet_util_lib.h \
index 6dada4f54effe4aa3788fa6f6431f16374b02f50..941ef27e4d0172da851d831aa84c977f31d54ad2 100644 (file)
@@ -60,7 +60,10 @@ struct GNUNET_TRANSPORT_CoreHandle;
  * peer connected to us.
  *
  * @param cls closure
- * @param peer the peer that connected
+ * @param peer the identity of the peer that connected; this
+ *        pointer will remain valid until the disconnect, hence
+ *        applications do not necessarily have to make a copy 
+ *        of the value if they only need it until disconnect
  * @param mq message queue to use to transmit to @a peer
  * @return closure to use in MQ handlers
  */
diff --git a/src/include/gnunet_transport_manipulation_service.h b/src/include/gnunet_transport_manipulation_service.h
new file mode 100644 (file)
index 0000000..8c17896
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+     This file is part of GNUnet.
+     Copyright (C) 2009-2014, 2016 GNUnet e.V.
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @author Christian Grothoff
+ *
+ * @file
+ * Low-level P2P IO
+ *
+ * @defgroup transport  Transport service
+ * Low-level P2P IO
+ *
+ * @see [Documentation](https://gnunet.org/transport-service)
+ *
+ * @{
+ */
+
+#ifndef GNUNET_TRANSPORT_MANIPULATION_SERVICE_H
+#define GNUNET_TRANSPORT_MANIPULATION_SERVICE_H
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#if 0                           /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
+#include "gnunet_util_lib.h"
+#include "gnunet_ats_service.h"
+
+/**
+ * Version number of the transport API.
+ */
+#define GNUNET_TRANSPORT_MANIPULATION_VERSION 0x00000003
+
+/**
+ * Handle for transport manipulation.
+ */
+struct GNUNET_TRANSPORT_ManipulationHandle;
+
+
+/**
+ * Connect to the transport service.  Note that the connection may
+ * complete (or fail) asynchronously.
+ *
+ * @param cfg configuration to use
+ * @return NULL on error
+ */
+struct GNUNET_TRANSPORT_ManipulationHandle *
+GNUNET_TRANSPORT_manipulation_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
+
+
+/**
+ * Disconnect from the transport service.
+ *
+ * @param handle handle returned from connect
+ */
+void
+GNUNET_TRANSPORT_manipulation_disconnect (struct GNUNET_TRANSPORT_ManipulationHandle *handle);
+
+
+/**
+ * Set transport metrics for a peer and a direction
+ *
+ * @param handle transport handle
+ * @param peer the peer to set the metric for
+ * @param prop the performance metrics to set
+ * @param delay_in inbound delay to introduce
+ * @param delay_out outbound delay to introduce
+ *
+ * Note: Delay restrictions in receiving direction will be enforced
+ * with one message delay.
+ */
+void
+GNUNET_TRANSPORT_manipulation_set (struct GNUNET_TRANSPORT_ManipulationHandle *handle,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  const struct GNUNET_ATS_Properties *prop,
+                                  struct GNUNET_TIME_Relative delay_in,
+                                  struct GNUNET_TIME_Relative delay_out);
+
+
+#if 0                           /* keep Emacsens' auto-indent happy */
+{
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+/* ifndef GNUNET_TRANSPORT_MANIPULATION_SERVICE_H */
+#endif
+
+/** @} */  /* end of group */
+
+/* end of gnunet_transport_manipulation_service.h */
index b201ab24ade2f6095e0a2b472e142f9e98be97c0..1579602da156adbee98111ea9f4220c36913820e 100644 (file)
@@ -171,6 +171,7 @@ libgnunettransport_la_SOURCES = \
   transport_api_blacklist.c \
   transport_api_core.c \
   transport_api_get_hello.c \
+  transport_api_manipulation.c \
   transport_api_monitor_peers.c \
   transport_api_monitor_plugins.c \
   transport_api_offer_hello.c
index 71c8c005416fbdca2d1771b7ec4e557b19b768b7..02d2428d3249ab7a961084d2fd4bfbf79bbc05b4 100644 (file)
@@ -1366,18 +1366,24 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
                        int may_drop)
 {
   struct TransportClient *tc;
+  int done;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Asked to broadcast message of type %u with %u bytes\n",
               (unsigned int) ntohs (msg->type),
               (unsigned int) ntohs (msg->size));
+  done = GNUNET_NO;
   for (tc = clients_head; NULL != tc; tc = tc->next)
   {
     if ( (GNUNET_YES == may_drop) &&
          (GNUNET_YES != tc->send_payload) )
       continue; /* skip, this client does not care about payload */
     unicast (tc, msg, may_drop);
+    done = GNUNET_YES;
   }
+  if (GNUNET_NO == done)
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+               "Message not delivered, is CORE service up?\n");
 }
 
 
index 76fb1ce5ad823085dbe8e5dec8b29a326388b99f..376065d24cf9c5cb0fde48e8c85e9e73e13212c8 100644 (file)
@@ -1888,9 +1888,10 @@ handle_helper_message (void *cls, void *client,
     break;
   default:
     GNUNET_break (0);
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
+    LOG (GNUNET_ERROR_TYPE_ERROR,
         "Unexpected message of type %u (%u bytes)",
-        ntohs (hdr->type), ntohs (hdr->size));
+        ntohs (hdr->type),
+        ntohs (hdr->size));
     break;
   }
   return GNUNET_OK;
index 5bd3f0237b3906609942ffa7507f34252b745a83..73b773b881d09e7761b4a1610021b9a936a46b09 100644 (file)
@@ -127,14 +127,12 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr)
 {
-  const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr;
 
-  hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message;
-  if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type))
+  if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type))
     return;
-  total_bytes_recv += ntohs (message->size);
+  total_bytes_recv += ntohs (hdr->header.size);
 
   {
     char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
@@ -144,7 +142,7 @@ notify_receive (void *cls,
                 receiver->no,
                 ps,
                 ntohl (hdr->num),
-                ntohs (message->size),
+                ntohs (hdr->header.size),
                 GNUNET_i2s (sender));
     GNUNET_free (ps);
   }
index 3998854da4277aa53a1cc2ac4156716b9c6aa068..9217d8f902bdabbab0569fc3a9e796fc014869b7 100644 (file)
@@ -286,12 +286,9 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr)
 {
-  const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr;
-
-  hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message;
-  if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type))
+  if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type))
     return;
 
   {
@@ -302,7 +299,7 @@ notify_receive (void *cls,
                 receiver->no,
                 ps,
                 ntohl (hdr->num),
-                ntohs (message->size),
+                ntohs (hdr->header.size),
                 GNUNET_i2s (sender));
     GNUNET_free (ps);
   }
index d4ae1cf53b27f136680e0ffdceb02ced8fb2d5fb..2f55631c3749b7e95e941e9f15d01d525eb5a8f5 100644 (file)
@@ -43,7 +43,7 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 {
   {
     char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
@@ -52,14 +52,14 @@ notify_receive (void *cls,
                 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
                 receiver->no,
                 ps,
-                ntohs (message->type),
-                ntohs (message->size),
+                ntohs (message->header.type),
+                ntohs (message->header.size),
                 GNUNET_i2s (sender));
     GNUNET_free (ps);
   }
 
-  if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) &&
-      (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE == ntohs (message->size)))
+  if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) &&
+      (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE == ntohs (message->header.size)))
   {
     ccc->global_ret = GNUNET_OK;
     GNUNET_SCHEDULER_shutdown ();
index c3675bb9a668e43b8ef290d7aa0cf576159ffd85..76780a48a621186f37fccf1a5945cdd264d3781b 100644 (file)
@@ -94,7 +94,7 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
               "Unexpectedly even received the message despite blacklist\n");
index c8cf89d7e057731d6e3071f5fdc1e6bca5ab37f4..870d9e4c262d47d8d7241ba9f5b0a6099365f6a3 100644 (file)
@@ -77,22 +77,22 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 {
   {
     char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Peer %u (`%4s') received message of type %d and size %u size from peer %s!\n",
+                "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
                 receiver->no,
                 ps,
-                ntohs (message->type),
-                ntohs (message->size),
+                ntohs (message->header.type),
+                ntohs (message->header.size),
                 GNUNET_i2s (sender));
     GNUNET_free (ps);
   }
-  if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) &&
-      (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->size)))
+  if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) &&
+      (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->header.size)))
   {
     GNUNET_SCHEDULER_add_now (&stop_peer,
                               NULL);
index 1b82ade70945b1e1954d935f8fd0e984c3217e6b..e487748aa0ae8a702a2a18276a97d43e3efe6365 100644 (file)
@@ -47,16 +47,16 @@ static void
 notify_receive (void *cls, 
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received message of type %d from peer %s!\n",
-              ntohs (message->type),
+              ntohs (message->header.type),
              GNUNET_i2s (sender));
   if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE ==
-       ntohs (message->type)) &&
+       ntohs (message->header.type)) &&
        (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) ==
-       ntohs (message->size)) )
+       ntohs (message->header.size)) )
   {
     ccc->global_ret = GNUNET_OK;
   }
index 84824ad8b3e55de4404ef9851301aa98e8ee99ec..a2312a872317a3c95f3ac8e4b5b073500a7cc90d 100644 (file)
@@ -40,7 +40,7 @@
 
 #define TEST_MESSAGE_SIZE 2600
 
-#define TEST_RESPONSE_MESSAGE_TYPE 12346
+#define TEST_RESPONSE_MESSAGE_TYPE 
 
 /**
  * Test delay, in microseconds.
@@ -63,7 +63,7 @@ sendtask_response_task (void *cls)
   start_response = GNUNET_TIME_absolute_get();
   ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
                                       ccc->p[0],
-                                      TEST_RESPONSE_MESSAGE_TYPE,
+                                      GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
                                       TEST_MESSAGE_SIZE,
                                       1,
                                       NULL,
@@ -82,7 +82,7 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 {
   struct GNUNET_TIME_Relative duration;
 
@@ -93,13 +93,13 @@ notify_receive (void *cls,
                 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n",
                 receiver->no,
                 ps,
-                ntohs (message->type),
-                ntohs (message->size),
+                ntohs (message->header.type),
+                ntohs (message->header.size),
                 GNUNET_i2s (sender));
     GNUNET_free (ps);
   }
 
-  switch (ntohs (message->type)) {
+  switch (ntohs (message->header.type)) {
   case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE:
     duration = GNUNET_TIME_absolute_get_difference (start_request,
                                                    GNUNET_TIME_absolute_get());
@@ -123,7 +123,7 @@ notify_receive (void *cls,
     GNUNET_SCHEDULER_add_now (&sendtask_response_task,
                              NULL);
     return;
-  case TEST_RESPONSE_MESSAGE_TYPE:
+  case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2:
     duration = GNUNET_TIME_absolute_get_difference(start_response,
                                                    GNUNET_TIME_absolute_get());
     if (duration.rel_value_us >= TEST_DELAY)
index e902aed62d4ab9d5c93461398ac616826b69b906..3014715b1db139d94dd61fe28534f95aa83ca2c2 100644 (file)
@@ -79,11 +79,11 @@ sendtask (void *cls)
   {
     memset (&prop, 0, sizeof (prop));
     delay = GNUNET_TIME_UNIT_SECONDS;
-    GNUNET_TRANSPORT_set_traffic_metric (ccc->p[1]->th,
-                                         &ccc->p[0]->id,
-                                         &prop,
-                                         delay,
-                                         GNUNET_TIME_UNIT_ZERO);
+    GNUNET_TRANSPORT_manipulation_set (ccc->p[1]->tmh,
+                                      &ccc->p[0]->id,
+                                      &prop,
+                                      delay,
+                                      GNUNET_TIME_UNIT_ZERO);
     start_delayed = GNUNET_TIME_absolute_get();
   }
   GNUNET_TRANSPORT_TESTING_large_send (sc);
@@ -94,7 +94,7 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 {
   {
     char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
@@ -103,13 +103,13 @@ notify_receive (void *cls,
                 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n",
                 receiver->no,
                 ps,
-                ntohs (message->type),
-                ntohs (message->size),
+                ntohs (message->header.type),
+                ntohs (message->header.size),
                 GNUNET_i2s (sender));
     GNUNET_free (ps);
   }
-  if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type)) ||
-       (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->size)) )
+  if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->header.type)) ||
+       (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->header.size)) )
   {
     GNUNET_break (0);
     ccc->global_ret = GNUNET_SYSERR;
index 95a6b5140a7543849a45916e805e867d7cf3fb08..fbb7ccbdb1e2b57aabc98be49a08fcbcf5bd2b97 100644 (file)
@@ -78,11 +78,11 @@ sendtask (void *cls)
   {
     memset (&prop, 0, sizeof (prop));
     delay = GNUNET_TIME_UNIT_SECONDS;
-    GNUNET_TRANSPORT_set_traffic_metric (ccc->p[0]->th,
-                                         &ccc->p[1]->id,
-                                         &prop,
-                                         GNUNET_TIME_UNIT_ZERO,
-                                         delay);
+    GNUNET_TRANSPORT_manipulation_set (ccc->p[0]->tmh,
+                                      &ccc->p[1]->id,
+                                      &prop,
+                                      GNUNET_TIME_UNIT_ZERO,
+                                      delay);
     start_delayed = GNUNET_TIME_absolute_get();
   }
   GNUNET_TRANSPORT_TESTING_large_send (sc);
@@ -93,7 +93,7 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 {
   {
     char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
@@ -102,14 +102,14 @@ notify_receive (void *cls,
                 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n",
                 receiver->no,
                 ps,
-                ntohs (message->type),
-                ntohs (message->size),
+                ntohs (message->header.type),
+                ntohs (message->header.size),
                 GNUNET_i2s (sender));
     GNUNET_free (ps);
   }
 
-  if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type)) ||
-       (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->size)) )
+  if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->header.type)) ||
+       (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->header.size)) )
   {
     GNUNET_break (0);
     ccc->global_ret = GNUNET_SYSERR;
index 1f0eb184c9b211767ebe7d275cb82264dc8f7e74..37f50c4fcacb66f4412f91db872f6b2ece4b4116 100644 (file)
@@ -81,7 +81,7 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 {
   char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
 
@@ -89,8 +89,8 @@ notify_receive (void *cls,
               "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
               receiver->no,
               ps,
-              ntohs (message->type),
-              ntohs (message->size),
+              ntohs (message->header.type),
+              ntohs (message->header.size),
               GNUNET_i2s (sender));
   GNUNET_free (ps);
 }
index 24ad4b81e8f5f00f079a5516f2bf9600f75a57ee..d6702cc25b52d5299cfaf7a088e25bbc606718c2 100644 (file)
  */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 450 * FACTOR)
 
+/**
+ * If we are in an "xhdr" test, the factor by which we divide
+ * #TOTAL_MSGS for a more sane test duration.
+ */
+static unsigned int xhdr = 1;
 
 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
 
@@ -105,7 +110,7 @@ get_size (unsigned int iter)
 static size_t
 get_size_cnt (unsigned int cnt_down)
 {
-  size_t ret = get_size (TOTAL_MSGS - 1 - cnt_down);
+  size_t ret = get_size (TOTAL_MSGS / xhdr - 1 - cnt_down);
 
   total_bytes += ret;
   return ret;
@@ -189,7 +194,7 @@ custom_shutdown (void *cls)
   }
 
   ok = 0;
-  for (unsigned int i = 0; i < TOTAL_MSGS; i++)
+  for (unsigned int i = 0; i < TOTAL_MSGS / xhdr; i++)
   {
     if (get_bit (bitmap, i) == 0)
     {
@@ -208,27 +213,24 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr)
 {
   static int n;
   unsigned int s;
   char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
-  const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr;
-
-  hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message;
 
-  if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type))
+  if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type))
     return;
   msg_recv = ntohl (hdr->num);
   s = get_size (ntohl (hdr->num));
 
-  if (ntohs (message->size) != s)
+  if (ntohs (hdr->header.size) != s)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Expected message %u of size %u, got %u bytes of message %u\n",
                 ntohl (hdr->num),
                 s,
-                ntohs (message->size),
+                ntohs (hdr->header.size),
                 ntohl (hdr->num));
     ccc->global_ret = GNUNET_SYSERR;
     GNUNET_SCHEDULER_shutdown ();
@@ -257,7 +259,7 @@ notify_receive (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Got message %u of size %u\n",
                 ntohl (hdr->num),
-                ntohs (message->size));
+                ntohs (hdr->header.size));
   }
 #endif
   n++;
@@ -266,13 +268,13 @@ notify_receive (void *cls,
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Message id %u is bigger than maxmimum number of messages %u expected\n",
                   ntohl (hdr->num),
-                  TOTAL_MSGS);
+                  TOTAL_MSGS / xhdr);
   }
-  if (0 == (n % (TOTAL_MSGS / 100)))
+  if (0 == (n % (TOTAL_MSGS / xhdr / 100)))
   {
     FPRINTF (stderr, "%s",  ".");
   }
-  if (n == TOTAL_MSGS)
+  if (n == TOTAL_MSGS / xhdr)
   {
     /* end testcase with success */
     ccc->global_ret = GNUNET_OK;
@@ -284,8 +286,10 @@ notify_receive (void *cls,
 int
 main (int argc, char *argv[])
 {
+  if (0 == strstr (argv[0], "xhdr"))
+    xhdr = 30;
   struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
-    .num_messages = TOTAL_MSGS,
+    .num_messages = TOTAL_MSGS / xhdr,
     .get_size_cb = &get_size_cnt
   };
   struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
index 6fd96991825d193988713e5de34b475ab60aecbf..477b8b54d787ad0d38932cfe6ceb30c6b22becd5 100644 (file)
@@ -58,11 +58,11 @@ custom_shutdown (void *cls)
 
 
 static void
-restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
-           void *cls)
+restart_cb (void *cls)
 {
   static unsigned int c;
-
+  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
+  
   c++;
   if ( (2 != c) &&
        (NULL != strstr (ccc->test_name,
@@ -96,7 +96,7 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 {
   {
     char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
@@ -105,13 +105,13 @@ notify_receive (void *cls,
                 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
                 receiver->no,
                 ps,
-                ntohs (message->type),
-                ntohs (message->size),
+                ntohs (message->header.type),
+                ntohs (message->header.size),
                 GNUNET_i2s (sender));
     GNUNET_free (ps);
   }
-  if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) &&
-       (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->size)) )
+  if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) &&
+       (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->header.size)) )
   {
     if (GNUNET_NO == restarted)
     {
index 05fb01d1d663fbeae15965bb558e6e2f9c93b460..042cbebedd87f5c73867b9c3cf8208faebb198fb 100644 (file)
@@ -79,11 +79,11 @@ static void
 notify_receive (void *cls,
                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_MessageHeader *message)
+                const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received message of type %d from peer %s!\n",
-              ntohs (message->type),
+              ntohs (message->header.type),
              GNUNET_i2s (sender));
 }
 
index 4d54337131c9d9ade82f2fb526a46363bb481424..595177e036ac1bccdae232186d0f3d29af4eae82 100644 (file)
@@ -64,8 +64,7 @@ end_badly ()
 
 
 static void
-restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
-            void *cls)
+restart_cb (void *cls)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Peer %u (`%s') successfully restarted\n",
@@ -90,8 +89,7 @@ restart_task ()
 
 
 static void
-start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
-          void *cls)
+start_cb (void *cls)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Peer %u (`%s') successfully started\n",
index 0846357e66f9ef35c1c2c6e3d4e8c493e521e5b8..6ac0250cc0f68df0132a9e8512a4f994d5b88cf0 100644 (file)
@@ -64,8 +64,7 @@ end_badly ()
 
 
 static void
-start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
-          void *cls)
+start_cb (void *cls)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Peer %u (`%s') successfully started\n",
index 79f6a0152793f3963fa6f72e13ee3122581e1abd..bba37eee87f61fcf0eda1480436876f54cbb0fed 100644 (file)
@@ -144,6 +144,23 @@ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext
 };
 
 
+/**
+ * Information tracked per connected peer.
+ */ 
+struct ConnectPairInfo
+{
+  /**
+   * Peer this is about.
+   */
+  const struct GNUNET_PeerIdentity *sender;
+
+  /**
+   * Information about the receiving peer.
+   */
+  struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi;
+};
+
+
 /**
  * Function called when we connected two peers.  Once we have gotten
  * to the clique, launch test-specific logic.
@@ -207,61 +224,123 @@ GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheck
  *
  * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
  * @param peer peer we got connected to
+ * @param mq message queue for transmissions to @a peer
+ * @return closure for message handlers
  */
-static void
+static void *
 my_nc (void *cls,
-       const struct GNUNET_PeerIdentity *peer)
+       const struct GNUNET_PeerIdentity *peer,
+       struct GNUNET_MQ_Handle *mq)
 {
   struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
   struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
-
+  struct ConnectPairInfo *cpi;
+  
   if (NULL != ccc->nc)
     ccc->nc (ccc->cls,
              ccc->p[ipi->off],
              peer);
+  cpi = GNUNET_new (struct ConnectPairInfo);
+  cpi->ipi = ipi;
+  cpi->sender = peer; /* valid until disconnect */
+  return cpi;
 }
 
 
-
 /**
  * Wrapper around peers disconnecting.  Calls client's nd function.
  *
  * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
  * @param peer peer we got disconnected from
+ * @param custom_cls return value from @my_nc
  */
 static void
 my_nd (void *cls,
-       const struct GNUNET_PeerIdentity *peer)
+       const struct GNUNET_PeerIdentity *peer,
+       void *custom_cls)
 {
   struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
   struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
-
+  struct ConnectPairInfo *cpi = custom_cls;
+  
   if (NULL != ccc->nd)
     ccc->nd (ccc->cls,
              ccc->p[ipi->off],
              peer);
+  GNUNET_free (cpi);
 }
 
 
 /**
  * Wrapper around receiving data.  Calls client's rec function.
  *
- * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
- * @param peer peer we got a message from
+ * @param cls our `struct ConnectPairInfo *`
+ * @param message message we received
+ * @return #GNUNET_OK (all messages are fine)
+ */
+static int
+check_test (void *cls,
+           const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+  return GNUNET_OK;
+}
+
+
+/**
+ * Wrapper around receiving data.  Calls client's rec function.
+ *
+ * @param cls our `struct ConnectPairInfo *`
  * @param message message we received
  */
 static void
-my_rec (void *cls,
-        const struct GNUNET_PeerIdentity *peer,
-        const struct GNUNET_MessageHeader *message)
+handle_test (void *cls,
+            const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 {
-  struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
+  struct ConnectPairInfo *cpi = cls;
+  struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi;
+  struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
+
+  if (NULL != ccc->rec)
+    ccc->rec (ccc->cls,
+              ccc->p[ipi->off],
+              cpi->sender,
+              message);
+}
+
+
+/**
+ * Wrapper around receiving data.  Calls client's rec function.
+ *
+ * @param cls our `struct ConnectPairInfo *`
+ * @param message message we received
+ * @return #GNUNET_OK (all messages are fine)
+ */
+static int
+check_test2 (void *cls,
+            const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+  return GNUNET_OK;
+}
+
+
+/**
+ * Wrapper around receiving data.  Calls client's rec function.
+ *
+ * @param cls our `struct ConnectPairInfo *`
+ * @param message message we received
+ */
+static void
+handle_test2 (void *cls,
+             const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+  struct ConnectPairInfo *cpi = cls;
+  struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi;
   struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
 
   if (NULL != ccc->rec)
     ccc->rec (ccc->cls,
               ccc->p[ipi->off],
-              peer,
+              cpi->sender,
               message);
 }
 
@@ -315,15 +394,14 @@ do_connect (void *cls)
  * Once all peers have been launched, we connect all of them
  * in a clique.
  *
- * @param p peer that was launched (redundant, kill ASAP)
  * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
  */
 static void
-start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
-          void *cls)
+start_cb (void *cls)
 {
   struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
   struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
+  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = ccc->p[ipi->off];
 
   ccc->started++;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -364,6 +442,12 @@ connect_check_run (void *cls,
                    const char *cfgfile,
                    const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  GNUNET_MQ_hd_var_size (test,
+                        GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
+                        struct GNUNET_TRANSPORT_TESTING_TestMessage);
+  GNUNET_MQ_hd_var_size (test2,
+                        GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
+                        struct GNUNET_TRANSPORT_TESTING_TestMessage);
   struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
   int ok;
 
@@ -376,10 +460,15 @@ connect_check_run (void *cls,
   ok = GNUNET_OK;
   for (unsigned int i=0;i<ccc->num_peers;i++)
   {
+    struct GNUNET_MQ_MessageHandler handlers[] = {
+      make_test_handler (NULL),
+      make_test2_handler (NULL),
+      GNUNET_MQ_handler_end()
+    };
     ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer (ccc->tth,
                                                      ccc->cfg_files[i],
                                                      i + 1,
-                                                     &my_rec,
+                                                     handlers,
                                                      &my_nc,
                                                      &my_nd,
                                                     &ccc->ip[i],
index 92d5833b064892a0eb9f18e27035fe4f74f5ab1d..24858353ecbc4982338811459789ca99894d4fdf 100644 (file)
 #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 
 
-static size_t
-notify_ready (void *cls,
-              size_t size,
-              void *buf)
-{ 
-  struct TRANSPORT_TESTING_SendJob *sj = cls;
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *sender = sj->sender;
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver = sj->receiver;
-  struct GNUNET_TRANSPORT_TESTING_Handle *tth = sender->tth;
-  uint16_t msize = sj->msize;
-  struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
-
-  sj->th = NULL;
-  GNUNET_CONTAINER_DLL_remove (tth->sj_head,
-                              tth->sj_tail,
-                              sj);
-  if (NULL == buf)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Timeout occurred while waiting for transmit_ready\n");
-    GNUNET_SCHEDULER_shutdown ();
-    GNUNET_free (sj);
-    return 0;
-  }
-
-  GNUNET_assert (size >= msize);
-  if (NULL != buf)
-  {
-    memset (buf, sj->num, msize);
-    test = buf;
-    test->header.size = htons (msize);
-    test->header.type = htons (sj->mtype);
-    test->num = htonl (sj->num);
-  }
-
-  {
-    char *ps = GNUNET_strdup (GNUNET_i2s (&sender->id));
-
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Sending message %u from %u (%s) with type %u and size %u bytes to peer %u (%s)\n",
-               (unsigned int) sj->num,
-               sender->no,
-               ps,
-                sj->mtype,
-                msize,
-                receiver->no,
-                GNUNET_i2s (&receiver->id));
-    GNUNET_free (ps);
-  }
-  if (NULL != sj->cont)
-    GNUNET_SCHEDULER_add_now (sj->cont,
-                             sj->cont_cls);
-  GNUNET_free (sj);
-  return msize;
-}
-
-
 /**
  * Return @a cx in @a cls.
  */
@@ -127,10 +70,10 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send
                               GNUNET_SCHEDULER_TaskCallback cont,
                               void *cont_cls)
 {
-  struct GNUNET_TRANSPORT_TESTING_Handle *tth = sender->tth;
-  struct TRANSPORT_TESTING_SendJob *sj;
   struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr;
-
+  struct GNUNET_MQ_Envelope *env;
+  struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
+  
   if (msize < sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage))
   {
     GNUNET_break (0);
@@ -151,17 +94,11 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send
     GNUNET_break (0);
     return GNUNET_NO;
   }
-  sj = GNUNET_new (struct TRANSPORT_TESTING_SendJob);
-  sj->num = num;
-  sj->sender = sender;
-  sj->receiver = receiver;
-  sj->cont = cont;
-  sj->cont_cls = cont_cls;
-  sj->mtype = mtype;
-  sj->msize = msize;
-  GNUNET_CONTAINER_DLL_insert (tth->sj_head,
-                              tth->sj_tail,
-                              sj);
+  if (NULL == cr->mq) 
+  {
+    GNUNET_break (0);
+    return GNUNET_NO;
+  }
   {
     char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
 
@@ -173,13 +110,18 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send
                 receiver_s);
     GNUNET_free (receiver_s);
   }
-  sj->th = GNUNET_TRANSPORT_notify_transmit_ready (sender->th,
-                                                  &receiver->id,
-                                                  msize,
-                                                  TIMEOUT_TRANSMIT,
-                                                  &notify_ready,
-                                                  sj);
-  GNUNET_assert (NULL != sj->th);
+  env = GNUNET_MQ_msg_extra (test,
+                            msize - sizeof (*test),
+                            mtype);
+  test->num = htonl (num);
+  memset (&test[1],
+         num,
+         msize - sizeof (*test));
+  GNUNET_MQ_notify_sent (env,
+                        cont,
+                        cont_cls);
+  GNUNET_MQ_send (cr->mq,
+                 env);
   return GNUNET_OK;
 }
 
index 899ef7851465e5dfbe5196285cbfa8ea166d56d8..defafbbc6d22006b43e55ec60cd5c45f8905301c 100644 (file)
@@ -85,6 +85,16 @@ set_p1c (void *cls,
 }
 
 
+static void
+set_mq (void *cls,   
+       struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
+{
+  struct GNUNET_MQ_Handle *mq = cls;
+
+  cx->mq = mq;
+}
+
+
 static void
 set_p2c (void *cls,   
         struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
@@ -121,9 +131,10 @@ clear_p2c (void *cls,
 }
 
 
-static void
+static void *
 notify_connect (void *cls,
-                const struct GNUNET_PeerIdentity *peer)
+                const struct GNUNET_PeerIdentity *peer,
+               struct GNUNET_MQ_Handle *mq)
 {
   struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
   struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
@@ -132,12 +143,16 @@ notify_connect (void *cls,
   struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
   struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
   int found;
+  void *ret;
 
   p2 = find_peer_context (p->tth,
                           peer);
   if (NULL != p->nc)
-    p->nc (p->cb_cls,
-           peer);
+    ret = p->nc (p->cb_cls,
+                peer,
+                mq);
+  else
+    ret = NULL;
 
   if (p2 != NULL)
     GNUNET_asprintf (&p2_s,
@@ -185,6 +200,10 @@ notify_connect (void *cls,
                                 tth->cc_tail,
                                 cc);
   }
+  GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
+                                                   p2,
+                                                   &set_mq,
+                                                   mq);
   /* update set connected flag for all requests */
   for (cc = tth->cc_head; NULL != cc; cc = cc->next)
   {
@@ -223,6 +242,7 @@ notify_connect (void *cls,
       cc->cb = NULL; /* only notify once! */
     }
   }
+  return ret;
 }
 
 
@@ -237,7 +257,8 @@ offer_hello (void *cls);
 
 static void
 notify_disconnect (void *cls,
-                   const struct GNUNET_PeerIdentity *peer)
+                   const struct GNUNET_PeerIdentity *peer,
+                  void *handler_cls)
 {
   struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
   struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
@@ -245,8 +266,6 @@ notify_disconnect (void *cls,
   /* Find PeerContext */
   int no = 0;
   struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL;
-  struct TRANSPORT_TESTING_SendJob *sj;
-  struct TRANSPORT_TESTING_SendJob *sjn;
   struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
   
   p2 = find_peer_context (p->tth,
@@ -270,25 +289,15 @@ notify_disconnect (void *cls,
   /* notify about disconnect */
   if (NULL != p->nd)
     p->nd (p->cb_cls,
-           peer);
+           peer,
+          handler_cls);
   if (NULL == p2)
     return;
-  /* abort all transmissions this disconnected pair is involved in */
-  for (sj = tth->sj_head; NULL != sj; sj = sjn)
-  {
-    sjn = sj->next;
-    if ( ( (sj->sender == p2) &&
-          (sj->receiver == p) ) ||
-        ( (sj->receiver == p2) &&
-          (sj->sender == p) ) )
-    {
-      GNUNET_CONTAINER_DLL_remove (tth->sj_head,
-                                  tth->sj_tail,
-                                  sj);
-      GNUNET_TRANSPORT_notify_transmit_ready_cancel (sj->th);
-      GNUNET_free (sj);
-    }
-  }
+  /* clear MQ, it is now invalid */
+  GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
+                                                   p2,
+                                                   &set_mq,
+                                                   NULL);
   /* update set connected flags for all requests */
   GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
                                                    p2,
@@ -321,22 +330,6 @@ notify_disconnect (void *cls,
 }
 
 
-static void
-notify_receive (void *cls,
-                const struct GNUNET_PeerIdentity *peer,
-                const struct GNUNET_MessageHeader *message)
-{
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-
-  if (NULL == p)
-    return;
-  if (NULL != p->rec)
-    p->rec (p->cb_cls,
-            peer,
-            message);
-}
-
-
 static void
 get_hello (void *cb_cls,
            const struct GNUNET_MessageHeader *message)
@@ -359,8 +352,7 @@ get_hello (void *cb_cls,
          "Peer %u (`%s') successfully started\n",
          p->no,
          GNUNET_i2s (&p->id));
-    p->start_cb (p,
-                 p->start_cb_cls);
+    p->start_cb (p->start_cb_cls);
     p->start_cb = NULL;
   }
 }
@@ -371,7 +363,7 @@ get_hello (void *cb_cls,
  * @param tth the testing handle
  * @param cfgname configuration file
  * @param peer_id a unique number to identify the peer
- * @param rec receive callback
+ * @param handlers functions for receiving messages
  * @param nc connect callback
  * @param nd disconnect callback
  * @param cb_cls closure for callback
@@ -383,17 +375,18 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext *
 GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth,
                                      const char *cfgname,
                                      int peer_id,
-                                     GNUNET_TRANSPORT_ReceiveCallback rec,
-                                     GNUNET_TRANSPORT_NotifyConnect nc,
-                                     GNUNET_TRANSPORT_NotifyDisconnect nd,
+                                     const struct GNUNET_MQ_MessageHandler *handlers,
+                                     GNUNET_TRANSPORT_NotifyConnecT nc,
+                                     GNUNET_TRANSPORT_NotifyDisconnecT nd,
                                     void *cb_cls,
-                                     GNUNET_TRANSPORT_TESTING_StartCallback start_cb,
+                                     GNUNET_SCHEDULER_TaskCallback start_cb,
                                      void *start_cb_cls)
 {
   char *emsg = NULL;
   struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
   struct GNUNET_PeerIdentity *dummy;
-
+  unsigned int i;
+  
   if (GNUNET_NO == GNUNET_DISK_file_test (cfgname))
   {
     LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -406,7 +399,15 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
   p->tth = tth;
   p->nc = nc;
   p->nd = nd;
-  p->rec = rec;
+  if (NULL != handlers)
+  {
+    for (i=0;NULL != handlers[i].cb;i++) ;
+    p->handlers = GNUNET_new_array (i + 1,
+                                   struct GNUNET_MQ_MessageHandler);
+    GNUNET_memcpy (p->handlers,
+                  handlers,
+                  i * sizeof (struct GNUNET_MQ_MessageHandler));
+  }    
   if (NULL != cb_cls)
     p->cb_cls = cb_cls;
   else
@@ -479,14 +480,16 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
        "Peer %u configured with identity `%s'\n",
        p->no,
        GNUNET_i2s_full (&p->id));
-
-  p->th = GNUNET_TRANSPORT_connect (p->cfg,
-                                    NULL,
-                                    p,
-                                    &notify_receive,
-                                    &notify_connect,
-                                    &notify_disconnect);
-  if (NULL == p->th)
+  p->tmh = GNUNET_TRANSPORT_manipulation_connect (p->cfg);
+  p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
+                                        NULL,
+                                        handlers,
+                                        p,
+                                        &notify_connect,
+                                        &notify_disconnect,
+                                        NULL);
+  if ( (NULL == p->th) ||
+       (NULL == p->tmh) )
   {
     LOG (GNUNET_ERROR_TYPE_ERROR,
          "Failed to connect to transport service for peer `%s': `%s'\n",
@@ -523,7 +526,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
  */
 int
 GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
-                                       GNUNET_TRANSPORT_TESTING_StartCallback restart_cb,
+                                       GNUNET_SCHEDULER_TaskCallback restart_cb,
                                        void *restart_cb_cls)
 {
   struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
@@ -541,9 +544,14 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte
   }
   if (NULL != p->th)
   {
-    GNUNET_TRANSPORT_disconnect (p->th);
+    GNUNET_TRANSPORT_core_disconnect (p->th);
     p->th = NULL;
   }
+  if (NULL != p->tmh)
+  {
+    GNUNET_TRANSPORT_manipulation_disconnect (p->tmh);
+    p->tmh = NULL;
+  }
   for (cc = p->tth->cc_head; NULL != cc; cc = ccn)
   {
     ccn = cc->next;
@@ -586,12 +594,13 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte
   p->start_cb = restart_cb;
   p->start_cb_cls = restart_cb_cls;
 
-  p->th = GNUNET_TRANSPORT_connect (p->cfg,
-                                    NULL,
-                                    p,
-                                    &notify_receive,
-                                    &notify_connect,
-                                    &notify_disconnect);
+  p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
+                                        NULL,
+                                        p->handlers,
+                                        p,
+                                        &notify_connect,
+                                        &notify_disconnect,
+                                        NULL);
   GNUNET_assert (NULL != p->th);
   p->ats = GNUNET_ATS_connectivity_init (p->cfg);
   p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg,
@@ -626,9 +635,14 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext
     GNUNET_TRANSPORT_get_hello_cancel (p->ghh);
     p->ghh = NULL;
   }
+  if (NULL != p->tmh)
+  {
+    GNUNET_TRANSPORT_manipulation_disconnect (p->tmh);
+    p->tmh = NULL;
+  }
   if (NULL != p->th)
   {
-    GNUNET_TRANSPORT_disconnect (p->th);
+    GNUNET_TRANSPORT_core_disconnect (p->th);
     p->th = NULL;
   }
   if (NULL != p->peer)
index 806b8c5f94e8c58c59926615942bcfc7a6cb4c78..87e647c2f3789b89c668147f93a5027ae8796374 100644 (file)
@@ -30,6 +30,8 @@
 #include "gnunet_util_lib.h"
 #include "gnunet_hello_lib.h"
 #include "gnunet_transport_service.h"
+#include "gnunet_transport_core_service.h"
+#include "gnunet_transport_manipulation_service.h"
 #include "gnunet_testing_lib.h"
 
 
@@ -46,19 +48,6 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext;
 struct GNUNET_TRANSPORT_TESTING_Handle;
 
 
-/**
- * Callback when two peers are connected and both have called the connect callback
- * to notify clients about a new peer
- *
- * @param p FIXME: remove ASAP.
- * @param cls closure
- */
-typedef void
-(*GNUNET_TRANSPORT_TESTING_StartCallback) (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
-                                           void *cls);
-
-
-
 /**
  * Context for a single peer
  */
@@ -87,7 +76,12 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext
   /**
    * Peer's transport service handle
    */
-  struct GNUNET_TRANSPORT_Handle *th;
+  struct GNUNET_TRANSPORT_CoreHandle *th;
+
+  /**
+   * Peer's transport service manipulation handle
+   */
+  struct GNUNET_TRANSPORT_ManipulationHandle *tmh;
 
   /**
    * Peer's ATS handle.
@@ -117,22 +111,22 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext
   /**
    * Receive callback
    */
-  GNUNET_TRANSPORT_ReceiveCallback rec;
+  struct GNUNET_MQ_MessageHandler *handlers;
 
   /**
    * Notify connect callback
    */
-  GNUNET_TRANSPORT_NotifyConnect nc;
+  GNUNET_TRANSPORT_NotifyConnecT nc;
 
   /**
    * Notify disconnect callback
    */
-  GNUNET_TRANSPORT_NotifyDisconnect nd;
+  GNUNET_TRANSPORT_NotifyDisconnecT nd;
 
   /**
    * Startup completed callback
    */
-  GNUNET_TRANSPORT_TESTING_StartCallback start_cb;
+  GNUNET_SCHEDULER_TaskCallback start_cb;
 
   /**
    * Peers HELLO Message
@@ -207,6 +201,11 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest
    */
   void *cb_cls;
 
+  /**
+   * Message queue for sending from @a p1 to @a p2.
+   */
+  struct GNUNET_MQ_Handle *mq;
+
   /** 
    * Set if peer1 says the connection is up to peer2.
    */
@@ -224,65 +223,6 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest
 };
 
 
-/**
- * Information we keep for active transmission jobs.
- */
-struct TRANSPORT_TESTING_SendJob
-{
-
-  /**
-   * Kept in a DLL.
-   */ 
-  struct TRANSPORT_TESTING_SendJob *next;
-
-  /**
-   * Kept in a DLL.
-   */ 
-  struct TRANSPORT_TESTING_SendJob *prev;
-
-  /**
-   * Sender of the message.
-   */
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *sender;
-
-  /** 
-   * Receiver of the message.
-   */ 
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver;
-
-  /**
-   * Operation handle.
-   */
-  struct GNUNET_TRANSPORT_TransmitHandle *th;
-
-  /**
-   * Function to call upon completion.
-   */
-  GNUNET_SCHEDULER_TaskCallback cont;
-
-  /**
-   * Closure for @e cont.
-   */
-  void *cont_cls;
-  
-  /**
-   * Number of the message.
-   */ 
-  uint32_t num;
-  
-  /**
-   * Type of message to send.
-   */ 
-  uint16_t mtype;
-
-  /**
-   * Length of the message.
-   */
-  uint16_t msize;
-  
-};
-
-
 /**
  * Handle for a test run.
  */
@@ -303,16 +243,6 @@ struct GNUNET_TRANSPORT_TESTING_Handle
    */
   struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_tail;
 
-  /**
-   * Kept in a DLL.
-   */ 
-  struct TRANSPORT_TESTING_SendJob *sj_head;
-
-  /**
-   * Kept in a DLL.
-   */ 
-  struct TRANSPORT_TESTING_SendJob *sj_tail;
-  
   /**
    * head DLL of peers
    */
@@ -349,7 +279,7 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth);
  * @param tth the testing handle
  * @param cfgname configuration file
  * @param peer_id the peer_id
- * @param rec receive callback
+ * @param handlers functions for receiving messages
  * @param nc connect callback
  * @param nd disconnect callback
  * @param cb_cls closure for @a nc and @a nd callback
@@ -361,11 +291,11 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext *
 GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth,
                                      const char *cfgname,
                                      int peer_id,
-                                     GNUNET_TRANSPORT_ReceiveCallback rec,
-                                     GNUNET_TRANSPORT_NotifyConnect nc,
-                                     GNUNET_TRANSPORT_NotifyDisconnect nd,
+                                     const struct GNUNET_MQ_MessageHandler *handlers,
+                                     GNUNET_TRANSPORT_NotifyConnecT nc,
+                                     GNUNET_TRANSPORT_NotifyDisconnecT nd,
                                     void *cb_cls,
-                                     GNUNET_TRANSPORT_TESTING_StartCallback start_cb,
+                                     GNUNET_SCHEDULER_TaskCallback start_cb,
                                      void *start_cb_cls);
 
 
@@ -388,7 +318,7 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext
  */
 int
 GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
-                                       GNUNET_TRANSPORT_TESTING_StartCallback restart_cb,
+                                       GNUNET_SCHEDULER_TaskCallback restart_cb,
                                        void *restart_cb_cls);
 
 
@@ -476,6 +406,23 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequestList;
 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext;
 
 
+GNUNET_NETWORK_STRUCT_BEGIN
+struct GNUNET_TRANSPORT_TESTING_TestMessage
+{
+  /**
+   * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE.
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Monotonically increasing counter throughout the test.
+   */
+  uint32_t num GNUNET_PACKED;
+};
+GNUNET_NETWORK_STRUCT_END
+
+
+
 /**
  * Function called by the transport for each received message.
  *
@@ -488,7 +435,7 @@ typedef void
 (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (void *cls,
                                              struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
                                              const struct GNUNET_PeerIdentity *sender,
-                                             const struct GNUNET_MessageHeader *message);
+                                             const struct GNUNET_TRANSPORT_TESTING_TestMessage *message);
 
 
 /**
@@ -800,20 +747,10 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send
  */
 #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345
 
-GNUNET_NETWORK_STRUCT_BEGIN
-struct GNUNET_TRANSPORT_TESTING_TestMessage
-{
-  /**
-   * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE.
-   */
-  struct GNUNET_MessageHeader header;
-
-  /**
-   * Monotonically increasing counter throughout the test.
-   */
-  uint32_t num GNUNET_PACKED;
-};
-GNUNET_NETWORK_STRUCT_END
+/**
+ * Alternative message type for tests.
+ */
+#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346
 
 
 /**
index 499aa96f62e73e9f6ed311a6f73ceb6e6d9dfb11..4ca62d797497b30b52372d5c23926dc36a6f0d04 100644 (file)
@@ -266,12 +266,12 @@ neighbour_delete (void *cls,
     GNUNET_SCHEDULER_cancel (n->timeout_task);
     n->timeout_task = NULL;
   }
-  GNUNET_MQ_destroy (n->mq);
   if (NULL != n->env)
   {
     GNUNET_MQ_send_cancel (n->env);
     n->env = NULL;
   }
+  GNUNET_MQ_destroy (n->mq);
   GNUNET_assert (NULL == n->mq);
   GNUNET_assert (GNUNET_YES ==
                  GNUNET_CONTAINER_multipeermap_remove (handle->neighbours,
@@ -411,7 +411,7 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
                                     GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
                                     msg);
   obm->reserved = htonl (0);
-  obm->timeout = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); /* FIXME: to be removed */
+  obm->timeout = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */
   obm->peer = n->id;
   GNUNET_assert (NULL == n->timeout_task);
   n->is_ready = GNUNET_NO;
@@ -421,6 +421,9 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
                          n);
   GNUNET_MQ_send (h->mq,
                   n->env);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Queued message for neighbour `%s'.\n",
+       GNUNET_i2s (&n->id));
 }
 
 
@@ -655,15 +658,14 @@ check_recv (void *cls,
   const struct GNUNET_MessageHeader *imm;
   uint16_t size;
 
-  size = ntohs (im->header.size);
-  if (size <
-      sizeof (struct InboundMessage) + sizeof (struct GNUNET_MessageHeader))
+  size = ntohs (im->header.size) - sizeof (*im);
+  if (size < sizeof (struct GNUNET_MessageHeader))
   {
     GNUNET_break (0);
     return GNUNET_SYSERR;
   }
   imm = (const struct GNUNET_MessageHeader *) &im[1];
-  if (ntohs (imm->size) + sizeof (struct InboundMessage) != size)
+  if (ntohs (imm->size) != size)
   {
     GNUNET_break (0);
     return GNUNET_SYSERR;
@@ -808,15 +810,15 @@ static void
 disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h)
 {
   GNUNET_assert (NULL == h->reconnect_task);
+  /* Forget about all neighbours that we used to be connected to */
+  GNUNET_CONTAINER_multipeermap_iterate (h->neighbours,
+                                         &neighbour_delete,
+                                         h);
   if (NULL != h->mq)
   {
     GNUNET_MQ_destroy (h->mq);
     h->mq = NULL;
   }
-  /* Forget about all neighbours that we used to be connected to */
-  GNUNET_CONTAINER_multipeermap_iterate (h->neighbours,
-                                         &neighbour_delete,
-                                         h);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Scheduling task to reconnect to transport service in %s.\n",
        GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay,
@@ -865,13 +867,13 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
  * @return NULL on error
  */
 struct GNUNET_TRANSPORT_CoreHandle *
-GNUNET_TRANSPORT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                          const struct GNUNET_PeerIdentity *self,
-                          const struct GNUNET_MQ_MessageHandler *handlers,
-                          void *cls,
-                          GNUNET_TRANSPORT_NotifyConnecT nc,
-                          GNUNET_TRANSPORT_NotifyDisconnecT nd,
-                          GNUNET_TRANSPORT_NotifyExcessBandwidtH neb)
+GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                              const struct GNUNET_PeerIdentity *self,
+                              const struct GNUNET_MQ_MessageHandler *handlers,
+                              void *cls,
+                              GNUNET_TRANSPORT_NotifyConnecT nc,
+                              GNUNET_TRANSPORT_NotifyDisconnecT nd,
+                              GNUNET_TRANSPORT_NotifyExcessBandwidtH neb)
 {
   struct GNUNET_TRANSPORT_CoreHandle *h;
   unsigned int i;
@@ -888,22 +890,23 @@ GNUNET_TRANSPORT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg,
   h->nd_cb = nd;
   h->neb_cb = neb;
   h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Connecting to transport service.\n");
-  reconnect (h);
-  if (NULL == h->mq)
-  {
-    GNUNET_free (h);
-    return NULL;
-  }
   if (NULL != handlers)
   {
     for (i=0;NULL != handlers[i].cb; i++) ;
     h->handlers = GNUNET_new_array (i + 1,
                                     struct GNUNET_MQ_MessageHandler);
     GNUNET_memcpy (h->handlers,
-           handlers,
-           i * sizeof (struct GNUNET_MQ_MessageHandler));
+                  handlers,
+                  i * sizeof (struct GNUNET_MQ_MessageHandler));
+  }
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Connecting to transport service\n");
+  reconnect (h);
+  if (NULL == h->mq)
+  {
+    GNUNET_free_non_null (h->handlers);
+    GNUNET_free (h);
+    return NULL;
   }
   h->neighbours =
     GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE,
index 5a9efcd14fe093415935bf7eb96e17cb985fc690..28f6c9d7b77bd1c5fa9985bebe12f1e9bb8d6a51 100644 (file)
@@ -19,7 +19,7 @@
 */
 
 /**
- * @file transport/transport_api.c
+ * @file transport/transport_api_get_hello.c
  * @brief library to obtain our HELLO from our transport service
  * @author Christian Grothoff
  */
diff --git a/src/transport/transport_api_manipulation.c b/src/transport/transport_api_manipulation.c
new file mode 100644 (file)
index 0000000..6325354
--- /dev/null
@@ -0,0 +1,244 @@
+/*
+     This file is part of GNUnet.
+     Copyright (C) 2009-2013, 2016 GNUnet e.V.
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file transport/transport_api_manipulation.c
+ * @brief library to access the low-level P2P IO service
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_constants.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_hello_lib.h"
+#include "gnunet_protocols.h"
+#include "gnunet_transport_service.h"
+#include "transport.h"
+
+#define LOG(kind,...) GNUNET_log_from (kind, "transport-api",__VA_ARGS__)
+
+
+/**
+ * Handle for the transport service (includes all of the
+ * state for the transport service).
+ */
+struct GNUNET_TRANSPORT_ManipulationHandle
+{
+
+  /**
+   * My client connection to the transport service.
+   */
+  struct GNUNET_MQ_Handle *mq;
+
+  /**
+   * My configuration.
+   */
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+  /**
+   * ID of the task trying to reconnect to the service.
+   */
+  struct GNUNET_SCHEDULER_Task *reconnect_task;
+
+  /**
+   * Delay until we try to reconnect.
+   */
+  struct GNUNET_TIME_Relative reconnect_delay;
+
+  /**
+   * Reconnect in progress
+   */
+  int reconnecting;
+};
+
+
+/**
+ * Function that will schedule the job that will try
+ * to connect us again to the client.
+ *
+ * @param h transport service to reconnect
+ */
+static void
+disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_ManipulationHandle *h);
+
+
+/**
+ * Generic error handler, called with the appropriate
+ * error code and the same closure specified at the creation of
+ * the message queue.
+ * Not every message queue implementation supports an error handler.
+ *
+ * @param cls closure with the `struct GNUNET_TRANSPORT_ManipulationHandle *`
+ * @param error error code
+ */
+static void
+mq_error_handler (void *cls,
+                  enum GNUNET_MQ_Error error)
+{
+  struct GNUNET_TRANSPORT_ManipulationHandle *h = cls;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Error receiving from transport service, disconnecting temporarily.\n");
+  h->reconnecting = GNUNET_YES;
+  disconnect_and_schedule_reconnect (h);
+}
+
+
+/**
+ * Try again to connect to transport service.
+ *
+ * @param cls the handle to the transport service
+ */
+static void
+reconnect (void *cls)
+{
+  struct GNUNET_TRANSPORT_ManipulationHandle *h = cls;
+  struct GNUNET_MQ_MessageHandler handlers[] = {
+    GNUNET_MQ_handler_end ()
+  };
+  struct GNUNET_MQ_Envelope *env;
+  struct StartMessage *s;
+
+  h->reconnect_task = NULL;
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Connecting to transport service.\n");
+  GNUNET_assert (NULL == h->mq);
+  h->reconnecting = GNUNET_NO;
+  h->mq = GNUNET_CLIENT_connecT (h->cfg,
+                                 "transport",
+                                 handlers,
+                                 &mq_error_handler,
+                                 h);
+  if (NULL == h->mq)
+    return;
+  env = GNUNET_MQ_msg (s,
+                       GNUNET_MESSAGE_TYPE_TRANSPORT_START);
+  GNUNET_MQ_send (h->mq,
+                  env);
+}
+
+
+/**
+ * Function that will schedule the job that will try
+ * to connect us again to the client.
+ *
+ * @param h transport service to reconnect
+ */
+static void
+disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_ManipulationHandle *h)
+{
+  GNUNET_assert (NULL == h->reconnect_task);
+  if (NULL != h->mq)
+  {
+    GNUNET_MQ_destroy (h->mq);
+    h->mq = NULL;
+  }
+  h->reconnect_task =
+      GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
+                                    &reconnect,
+                                    h);
+  h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
+}
+
+
+/**
+ * Set transport metrics for a peer and a direction.
+ *
+ * @param handle transport handle
+ * @param peer the peer to set the metric for
+ * @param prop the performance metrics to set
+ * @param delay_in inbound delay to introduce
+ * @param delay_out outbound delay to introduce
+ *
+ * Note: Delay restrictions in receiving direction will be enforced
+ * with one message delay.
+ */
+void
+GNUNET_TRANSPORT_manipulation_set (struct GNUNET_TRANSPORT_ManipulationHandle *handle,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  const struct GNUNET_ATS_Properties *prop,
+                                  struct GNUNET_TIME_Relative delay_in,
+                                  struct GNUNET_TIME_Relative delay_out)
+{
+  struct GNUNET_MQ_Envelope *env;
+  struct TrafficMetricMessage *msg;
+
+  if (NULL == handle->mq)
+    return;
+  env = GNUNET_MQ_msg (msg,
+                       GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC);
+  msg->reserved = htonl (0);
+  msg->peer = *peer;
+  GNUNET_ATS_properties_hton (&msg->properties,
+                              prop);
+  msg->delay_in = GNUNET_TIME_relative_hton (delay_in);
+  msg->delay_out = GNUNET_TIME_relative_hton (delay_out);
+  GNUNET_MQ_send (handle->mq,
+                  env);
+}
+
+
+/**
+ * Connect to the transport service.  Note that the connection may
+ * complete (or fail) asynchronously.
+ *
+ * @param cfg configuration to use
+ * @return NULL on error
+ */
+struct GNUNET_TRANSPORT_ManipulationHandle *
+GNUNET_TRANSPORT_manipulation_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  struct GNUNET_TRANSPORT_ManipulationHandle *h;
+
+  h = GNUNET_new (struct GNUNET_TRANSPORT_ManipulationHandle);
+  h->cfg = cfg;
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Connecting to transport service.\n");
+  reconnect (h);
+  if (NULL == h->mq)
+  {
+    GNUNET_free (h);
+    return NULL;
+  }
+  return h;
+}
+
+
+/**
+ * Disconnect from the transport service.
+ *
+ * @param handle handle to the service as returned from #GNUNET_TRANSPORT_manipulation_connect()
+ */
+void
+GNUNET_TRANSPORT_manipulation_disconnect (struct GNUNET_TRANSPORT_ManipulationHandle *handle)
+{
+  if (NULL == handle->reconnect_task)
+    disconnect_and_schedule_reconnect (handle);
+  /* and now we stop trying to connect again... */
+  if (NULL != handle->reconnect_task)
+  {
+    GNUNET_SCHEDULER_cancel (handle->reconnect_task);
+    handle->reconnect_task = NULL;
+  }
+  GNUNET_free (handle);
+}
+
+
+/* end of transport_api_manipulation.c */
index 8a46414d2e3d287605da0dbcca6bff000a929705..1638d7e0c9db497a4f8846eed54de423bf24109f 100644 (file)
@@ -807,9 +807,18 @@ connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq,
 {
   struct ClientConnectionState *state = impl_state;
 
-  GNUNET_assert (NULL != state->th);
-  GNUNET_CLIENT_notify_transmit_ready_cancel (state->th);
-  state->th = NULL;
+  if (NULL != state->th)
+  {
+    GNUNET_CLIENT_notify_transmit_ready_cancel (state->th);
+    state->th = NULL;
+  }
+  else if (NULL != mq->continue_task)
+  {
+    GNUNET_SCHEDULER_cancel (mq->continue_task);
+    mq->continue_task = NULL;
+  }
+  else
+    GNUNET_assert (0);
 }