summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-25 00:30:00 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-25 00:30:00 +0000
commitd0701eb6315fc3f5aca74415bbf0ff7418409f87 (patch)
treefcacb97bbcca542ce9493001c825fd265cb8a801
parent9bfb8bff3fd253407530c76c7590b33bacf033f1 (diff)
switching transport tests to new MQ-based transport API
-rw-r--r--src/include/Makefile.am5
-rw-r--r--src/include/gnunet_transport_core_service.h5
-rw-r--r--src/include/gnunet_transport_manipulation_service.h113
-rw-r--r--src/transport/Makefile.am1
-rw-r--r--src/transport/gnunet-service-transport_clients.c6
-rw-r--r--src/transport/plugin_transport_wlan.c5
-rw-r--r--src/transport/test_quota_compliance.c10
-rw-r--r--src/transport/test_transport_address_switch.c9
-rw-r--r--src/transport/test_transport_api.c10
-rw-r--r--src/transport/test_transport_api_blacklisting.c2
-rw-r--r--src/transport/test_transport_api_disconnect.c12
-rw-r--r--src/transport/test_transport_api_limited_sockets.c8
-rw-r--r--src/transport/test_transport_api_manipulation_cfg.c14
-rw-r--r--src/transport/test_transport_api_manipulation_recv_tcp.c20
-rw-r--r--src/transport/test_transport_api_manipulation_send_tcp.c20
-rw-r--r--src/transport/test_transport_api_monitor_peers.c6
-rw-r--r--src/transport/test_transport_api_reliability.c32
-rw-r--r--src/transport/test_transport_api_restart_reconnect.c16
-rw-r--r--src/transport/test_transport_api_timeout.c4
-rw-r--r--src/transport/test_transport_testing_restart.c6
-rw-r--r--src/transport/test_transport_testing_startstop.c3
-rw-r--r--src/transport/transport-testing-main.c123
-rw-r--r--src/transport/transport-testing-send.c98
-rw-r--r--src/transport/transport-testing.c146
-rw-r--r--src/transport/transport-testing.h153
-rw-r--r--src/transport/transport_api_core.c57
-rw-r--r--src/transport/transport_api_get_hello.c2
-rw-r--r--src/transport/transport_api_manipulation.c244
-rw-r--r--src/util/mq.c15
29 files changed, 754 insertions, 391 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 0faec4cfc..0ba6f8c74 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -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 \
diff --git a/src/include/gnunet_transport_core_service.h b/src/include/gnunet_transport_core_service.h
index 6dada4f54..941ef27e4 100644
--- a/src/include/gnunet_transport_core_service.h
+++ b/src/include/gnunet_transport_core_service.h
@@ -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
index 000000000..8c1789636
--- /dev/null
+++ b/src/include/gnunet_transport_manipulation_service.h
@@ -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 */
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index b201ab24a..1579602da 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -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
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index 71c8c0054..02d2428d3 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -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");
}
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 76fb1ce5a..376065d24 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -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;
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index 5bd3f0237..73b773b88 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.c
@@ -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);
}
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c
index 3998854da..9217d8f90 100644
--- a/src/transport/test_transport_address_switch.c
+++ b/src/transport/test_transport_address_switch.c
@@ -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);
}
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index d4ae1cf53..2f55631c3 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -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 ();
diff --git a/src/transport/test_transport_api_blacklisting.c b/src/transport/test_transport_api_blacklisting.c
index c3675bb9a..76780a48a 100644
--- a/src/transport/test_transport_api_blacklisting.c
+++ b/src/transport/test_transport_api_blacklisting.c
@@ -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");
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c
index c8cf89d7e..870d9e4c2 100644
--- a/src/transport/test_transport_api_disconnect.c
+++ b/src/transport/test_transport_api_disconnect.c
@@ -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);
diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c
index 1b82ade70..e487748aa 100644
--- a/src/transport/test_transport_api_limited_sockets.c
+++ b/src/transport/test_transport_api_limited_sockets.c
@@ -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;
}
diff --git a/src/transport/test_transport_api_manipulation_cfg.c b/src/transport/test_transport_api_manipulation_cfg.c
index 84824ad8b..a2312a872 100644
--- a/src/transport/test_transport_api_manipulation_cfg.c
+++ b/src/transport/test_transport_api_manipulation_cfg.c
@@ -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)
diff --git a/src/transport/test_transport_api_manipulation_recv_tcp.c b/src/transport/test_transport_api_manipulation_recv_tcp.c
index e902aed62..3014715b1 100644
--- a/src/transport/test_transport_api_manipulation_recv_tcp.c
+++ b/src/transport/test_transport_api_manipulation_recv_tcp.c
@@ -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;
diff --git a/src/transport/test_transport_api_manipulation_send_tcp.c b/src/transport/test_transport_api_manipulation_send_tcp.c
index 95a6b5140..fbb7ccbdb 100644
--- a/src/transport/test_transport_api_manipulation_send_tcp.c
+++ b/src/transport/test_transport_api_manipulation_send_tcp.c
@@ -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;
diff --git a/src/transport/test_transport_api_monitor_peers.c b/src/transport/test_transport_api_monitor_peers.c
index 1f0eb184c..37f50c4fc 100644
--- a/src/transport/test_transport_api_monitor_peers.c
+++ b/src/transport/test_transport_api_monitor_peers.c
@@ -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);
}
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index 24ad4b81e..d6702cc25 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -50,6 +50,11 @@
*/
#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 = {
diff --git a/src/transport/test_transport_api_restart_reconnect.c b/src/transport/test_transport_api_restart_reconnect.c
index 6fd969918..477b8b54d 100644
--- a/src/transport/test_transport_api_restart_reconnect.c
+++ b/src/transport/test_transport_api_restart_reconnect.c
@@ -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)
{
diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c
index 05fb01d1d..042cbebed 100644
--- a/src/transport/test_transport_api_timeout.c
+++ b/src/transport/test_transport_api_timeout.c
@@ -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));
}
diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c
index 4d5433713..595177e03 100644
--- a/src/transport/test_transport_testing_restart.c
+++ b/src/transport/test_transport_testing_restart.c
@@ -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",
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c
index 0846357e6..6ac0250cc 100644
--- a/src/transport/test_transport_testing_startstop.c
+++ b/src/transport/test_transport_testing_startstop.c
@@ -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",
diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c
index 79f6a0152..bba37eee8 100644
--- a/src/transport/transport-testing-main.c
+++ b/src/transport/transport-testing-main.c
@@ -145,6 +145,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],
diff --git a/src/transport/transport-testing-send.c b/src/transport/transport-testing-send.c
index 92d5833b0..24858353e 100644
--- a/src/transport/transport-testing-send.c
+++ b/src/transport/transport-testing-send.c
@@ -30,63 +30,6 @@
#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;
}
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 899ef7851..defafbbc6 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -86,6 +86,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,
@@ -322,22 +331,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)
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 806b8c5f9..87e647c2f 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -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"
@@ -47,19 +49,6 @@ 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
*/
struct GNUNET_TRANSPORT_TESTING_PeerContext
@@ -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.
*/
@@ -225,65 +224,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.
*/
struct GNUNET_TRANSPORT_TESTING_Handle
@@ -304,16 +244,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
*/
struct GNUNET_TRANSPORT_TESTING_PeerContext *p_head;
@@ -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
/**
diff --git a/src/transport/transport_api_core.c b/src/transport/transport_api_core.c
index 499aa96f6..4ca62d797 100644
--- a/src/transport/transport_api_core.c
+++ b/src/transport/transport_api_core.c
@@ -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,
diff --git a/src/transport/transport_api_get_hello.c b/src/transport/transport_api_get_hello.c
index 5a9efcd14..28f6c9d7b 100644
--- a/src/transport/transport_api_get_hello.c
+++ b/src/transport/transport_api_get_hello.c
@@ -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
index 000000000..6325354cb
--- /dev/null
+++ b/src/transport/transport_api_manipulation.c
@@ -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 */
diff --git a/src/util/mq.c b/src/util/mq.c
index 8a46414d2..1638d7e0c 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -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);
}