summaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-10-07 16:20:21 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-10-07 16:20:21 +0000
commit0663a057d7611270d5f41ae8b345125d737387f2 (patch)
tree39793c7c288dbef472c66cb1c8f12af48f6989b9 /src/transport
parent013cf64f56c0a529f0c11597e912b39e4a0a896c (diff)
transport-testing is not stateless anymore
-> fixed assertion failure transport_api.c:1348 - connecting peers is now unidirectional - added peer_startup callback
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am18
-rw-r--r--src/transport/gnunet-transport-connect-running-peers.c1
-rw-r--r--src/transport/plugin_transport_http.h2
-rw-r--r--src/transport/template_cfg_peer2.conf2
-rw-r--r--src/transport/test_transport_api.c190
-rw-r--r--src/transport/test_transport_api_http_peer1.conf2
-rw-r--r--src/transport/test_transport_api_limited_sockets.c44
-rw-r--r--src/transport/test_transport_api_reliability.c81
-rw-r--r--src/transport/test_transport_api_reliability_tcp_peer1.conf1
-rw-r--r--src/transport/test_transport_api_reliability_tcp_peer2.conf2
-rw-r--r--src/transport/test_transport_api_tcp_nat_peer2.conf3
-rw-r--r--src/transport/test_transport_api_tcp_peer1.conf2
-rw-r--r--src/transport/test_transport_api_timeout.c72
-rw-r--r--src/transport/test_transport_api_timeout_tcp_peer1.conf2
-rw-r--r--src/transport/test_transport_api_timeout_tcp_peer2.conf5
-rw-r--r--src/transport/test_transport_api_unreliability.c49
-rw-r--r--src/transport/test_transport_api_unreliability_constant.c48
-rw-r--r--src/transport/test_transport_startonly.c17
-rw-r--r--src/transport/test_transport_testing.c106
-rw-r--r--src/transport/transport-testing.c302
-rw-r--r--src/transport/transport-testing.h87
21 files changed, 725 insertions, 311 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index d8821e499..6ed3e918a 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -56,8 +56,8 @@ UNIX_QUOTA_TEST = test_quota_compliance_unix \
endif
noinst_PROGRAMS = \
- $(WLAN_BIN_DUMMY) \
- gnunet-transport-connect-running-peers
+ $(WLAN_BIN_DUMMY)
+# gnunet-transport-connect-running-peers
lib_LTLIBRARIES = \
libgnunettransport.la \
@@ -337,13 +337,13 @@ test_transport_testing_LDADD = \
$(top_builddir)/src/hello/libgnunethello.la \
$(top_builddir)/src/transport/libgnunettransporttesting.la
-gnunet_transport_connect_running_peers_SOURCES = \
- gnunet-transport-connect-running-peers.c
-gnunet_transport_connect_running_peers_LDADD = \
- $(top_builddir)/src/transport/libgnunettransport.la \
- $(top_builddir)/src/hello/libgnunethello.la \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/transport/libgnunettransporttesting.la
+#gnunet_transport_connect_running_peers_SOURCES = \
+# gnunet-transport-connect-running-peers.c
+#gnunet_transport_connect_running_peers_LDADD = \
+# $(top_builddir)/src/transport/libgnunettransport.la \
+# $(top_builddir)/src/hello/libgnunethello.la \
+# $(top_builddir)/src/util/libgnunetutil.la \
+# $(top_builddir)/src/transport/libgnunettransporttesting.la
test_transport_api_disconnect_SOURCES = \
test_transport_api_disconnect.c
diff --git a/src/transport/gnunet-transport-connect-running-peers.c b/src/transport/gnunet-transport-connect-running-peers.c
index 3542f8521..9b60ba176 100644
--- a/src/transport/gnunet-transport-connect-running-peers.c
+++ b/src/transport/gnunet-transport-connect-running-peers.c
@@ -324,6 +324,7 @@ run (void *cls, char *const *args, const char *cfgfile,
cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb,
NULL);
+
}
diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h
index d5fa4725e..16da05c32 100644
--- a/src/transport/plugin_transport_http.h
+++ b/src/transport/plugin_transport_http.h
@@ -42,7 +42,7 @@
#include <curl/curl.h>
-#define DEBUG_HTTP GNUNET_EXTRA_LOGGING
+#define DEBUG_HTTP GNUNET_YES
#define VERBOSE_SERVER GNUNET_EXTRA_LOGGING
#define VERBOSE_CLIENT GNUNET_EXTRA_LOGGING
#define VERBOSE_CURL GNUNET_NO
diff --git a/src/transport/template_cfg_peer2.conf b/src/transport/template_cfg_peer2.conf
index 2fb65b9c9..a086a2408 100644
--- a/src/transport/template_cfg_peer2.conf
+++ b/src/transport/template_cfg_peer2.conf
@@ -4,7 +4,7 @@ SERVICEHOME = /tmp/test-transport/api-tcp-p2/
DEFAULTCONFIG = template_cfg_peer2.conf
[transport-tcp]
-PORT = 0
+PORT = 12100
TIMEOUT = 5000
[arm]
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index c9068c47a..49e160ddb 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -75,6 +75,8 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
struct GNUNET_TRANSPORT_TransmitHandle *th;
+struct TransportTestingHandle * tth;
+
char *cfg_file_p1;
char *cfg_file_p2;
@@ -90,7 +92,55 @@ static void
end ()
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
+#if 0
+static void
+get_hello_p2 (void *cb_cls, const struct GNUNET_MessageHeader *message);
+
+static void
+get_hello_p1 (void *cb_cls, const struct GNUNET_MessageHeader *message);
+
+static void
+notify_connect_internal (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
+{
+ struct ConnectingContext *cc = cls;
+
+ GNUNET_assert (cc != NULL);
+
+ if (0 ==
+ memcmp (&(*peer).hashPubKey, &cc->p1->id.hashPubKey,
+ sizeof (GNUNET_HashCode)))
+ {
+ if (cc->p1_c == GNUNET_NO)
+ cc->p1_c = GNUNET_YES;
+ }
+ if (0 ==
+ memcmp (&(*peer).hashPubKey, &cc->p2->id.hashPubKey,
+ sizeof (GNUNET_HashCode)))
+ {
+ if (cc->p2_c == GNUNET_NO)
+ cc->p2_c = GNUNET_YES;
+ }
+ if ((cc->p2_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES))
+ {
+ /* clean up */
+ if (cc->tct != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (cc->tct);
+
+ cc->tct = GNUNET_SCHEDULER_NO_TASK;
+
+ GNUNET_TRANSPORT_disconnect (cc->th_p1);
+ GNUNET_TRANSPORT_disconnect (cc->th_p2);
+
+ if (cc->cb != NULL)
+ cc->cb (cc->p1, cc->p2, cc->cb_cls);
+
+ GNUNET_free (cc);
+ }
+}
+#endif
if (send_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (send_task);
@@ -101,8 +151,8 @@ end ()
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
}
static void
@@ -112,13 +162,14 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
+
if (send_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (send_task);
if (cc != NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n"));
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
}
if (th != NULL)
@@ -126,9 +177,11 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
th = NULL;
if (p1 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
if (p2 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+
+ GNUNET_TRANSPORT_TESTING_done (tth);
ok = GNUNET_SYSERR;
}
@@ -141,10 +194,18 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
uint32_t ats_count)
{
struct PeerContext * p = cls;
+ struct PeerContext *t = NULL;
+
+ if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
+ t = p1;
+ if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
+ t = p2;
+
+ char * ps = strdup (GNUNET_i2s(&p->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %d from peer %u (`%4s')!\n",
- ntohs (message->type), p->no, GNUNET_i2s (peer));
+ "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n",
+ p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id));
if ((MTYPE == ntohs (message->type)) &&
(sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
@@ -180,9 +241,6 @@ notify_ready (void *cls, size_t size, void *buf)
return 0;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting message with %u bytes to peer %u (%4s)\n",
- sizeof (struct GNUNET_MessageHeader), p->no, GNUNET_i2s (&p->id));
GNUNET_assert (size >= 256);
if (buf != NULL)
@@ -191,11 +249,17 @@ notify_ready (void *cls, size_t size, void *buf)
hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
hdr->type = htons (MTYPE);
}
+ char * ps = strdup (GNUNET_i2s(&p2->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n",
+ p2->no,
+ ps,
+ ntohs (hdr->type),
+ ntohs (hdr->size), p->no, GNUNET_i2s (&p->id));
+ GNUNET_free (ps);
return sizeof (struct GNUNET_MessageHeader);
}
-struct PeerContext * sender;
-struct PeerContext * receiver;
static void
sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -204,16 +268,16 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- char * receiver_s = strdup(GNUNET_i2s (&receiver->id));
+ char * receiver_s = strdup(GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
- sender->no,
- GNUNET_i2s (&sender->id), receiver->no, receiver_s);
+ p2->no,
+ GNUNET_i2s (&p2->id), p1->no, receiver_s);
GNUNET_free (receiver_s);
- th = GNUNET_TRANSPORT_notify_transmit_ready (sender->th, &receiver->id, 256, 0,
+ th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0,
TIMEOUT_TRANSMIT, &notify_ready,
- receiver);
+ p1);
}
@@ -225,10 +289,18 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
static int c;
c++;
struct PeerContext *p = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n",
- p->no, GNUNET_i2s (peer));
- if (c == 2)
- send_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
+ struct PeerContext *t = NULL;
+
+ if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
+ t = p1;
+ if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
+ t = p2;
+
+ char * ps = strdup (GNUNET_i2s(&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer %u (`%s') connected to me!\n",
+ p->no, ps,
+ t->no, GNUNET_i2s (peer));
+ GNUNET_free (ps);
}
@@ -236,14 +308,15 @@ static void
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *p = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n",
- p->no, GNUNET_i2s (peer));
+ char * ps = strdup (GNUNET_i2s(&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n",
+ p->no, ps, GNUNET_i2s (peer));
+
if (th != NULL)
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
}
-
static void
testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
@@ -254,6 +327,33 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
p1->no, p1_c,
p2->no, GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
+
+ send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
+}
+
+
+
+void start_cb (struct PeerContext * p,
+ void *cls)
+{
+ static int started;
+ started++;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
+ p->no,
+ GNUNET_i2s (&p->id));
+
+ if (started != 2)
+ return;
+
+ char *sender_c = strdup (GNUNET_i2s (&p1->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
+ p1->no, sender_c,
+ p2->no, GNUNET_i2s (&p2->id));
+
+ cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
+ NULL);
+
}
static void
@@ -262,14 +362,20 @@ run (void *cls, char *const *args, const char *cfgfile,
{
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
- p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, &notify_receive,
- &notify_connect, &notify_disconnect,
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
+ &notify_receive,
+ &notify_connect,
+ &notify_disconnect,
+ &start_cb,
+ NULL);
+
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
+ &notify_receive,
+ &notify_connect,
+ &notify_disconnect,
+ &start_cb,
NULL);
- p1->no = 1;
- p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, &notify_receive,
- &notify_connect, &notify_disconnect,
- NULL);
- p2->no = 2;
+
if ((p1 == NULL) || (p2 == NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
@@ -278,25 +384,6 @@ run (void *cls, char *const *args, const char *cfgfile,
die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
return;
}
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n",
- p1->no,
- GNUNET_i2s (&p1->id), cfg_file_p1);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n",
- p2->no,
- GNUNET_i2s (&p2->id), cfg_file_p2);
-
- sender = p2;
- receiver = p1;
-
- char *sender_c = strdup (GNUNET_i2s (&sender->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test triest to send from %u (%s) -> peer %u (%s)\n",
- sender->no, sender_c,
- receiver->no, GNUNET_i2s (&receiver->id));
-
-
- cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb,
- NULL);
}
@@ -333,6 +420,8 @@ main (int argc, char *argv[])
int ret;
int nat_res;
+ tth = GNUNET_TRANSPORT_TESTING_init ();
+
GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
&test_plugin);
@@ -376,6 +465,7 @@ main (int argc, char *argv[])
GNUNET_free (test_plugin);
GNUNET_free (test_name);
+ GNUNET_TRANSPORT_TESTING_done (tth);
return ret;
}
diff --git a/src/transport/test_transport_api_http_peer1.conf b/src/transport/test_transport_api_http_peer1.conf
index c322c36c1..91d0afe02 100644
--- a/src/transport/test_transport_api_http_peer1.conf
+++ b/src/transport/test_transport_api_http_peer1.conf
@@ -8,7 +8,7 @@ DISABLEV6 = NO
[transport-http]
PORT = 12080
-USE_IPv6 = YES
+#USE_IPv6 = NO
USE_IPv4 = YES
DISABLEV6 = NO
#BINDTO = 127.0.0.1
diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c
index 66816671c..7ceed03aa 100644
--- a/src/transport/test_transport_api_limited_sockets.c
+++ b/src/transport/test_transport_api_limited_sockets.c
@@ -77,6 +77,8 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
struct GNUNET_TRANSPORT_TransmitHandle *th;
+struct TransportTestingHandle * tth;
+
char *cfg_file_p1;
char *cfg_file_p2;
@@ -103,8 +105,8 @@ end ()
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
}
static void
@@ -118,16 +120,16 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_SCHEDULER_cancel (send_task);
if (cc != NULL)
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
if (th != NULL)
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
if (p1 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
if (p2 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
ok = GNUNET_SYSERR;
}
@@ -228,19 +230,42 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
}
+void start_cb (struct PeerContext * p,
+ void *cls)
+{
+ static int started;
+ started++;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
+ p->no,
+ GNUNET_i2s (&p->id));
+
+ if (started != 2)
+ return;
+
+ cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
+ NULL);
+
+}
+
static void
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
- p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, &notify_receive,
+ tth = GNUNET_TRANSPORT_TESTING_init ();
+
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
+ &notify_receive,
&notify_connect, &notify_disconnect,
+ &start_cb,
NULL);
- p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, &notify_receive,
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
+ &notify_receive,
&notify_connect, &notify_disconnect,
+ &start_cb,
NULL);
-
if ((p1 == NULL) || (p2 == NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
@@ -249,9 +274,6 @@ run (void *cls, char *const *args, const char *cfgfile,
die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
return;
}
-
- cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb,
- NULL);
}
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index e028c93fd..0719a9e47 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -79,6 +79,8 @@ char *cfg_file_p1;
char *cfg_file_p2;
+struct TransportTestingHandle * tth;
+
/*
* Testcase specific declarations
*/
@@ -145,8 +147,8 @@ end ()
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
}
static void
@@ -165,9 +167,11 @@ end_badly ()
th = NULL;
if (p1 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
if (p2 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+
+ GNUNET_TRANSPORT_TESTING_done (tth);
ok = GNUNET_SYSERR;
}
@@ -255,8 +259,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
if (n == TOTAL_MSGS)
{
ok = 0;
- fprintf (stderr, "\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages received\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\nAll messages received\n");
end ();
}
}
@@ -399,35 +402,22 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
p2->no, GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
- // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
+ GNUNET_SCHEDULER_add_now (&sendtask, NULL);
}
-static void
-run (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+void start_cb (struct PeerContext * p,
+ void *cls)
{
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
+ static int started;
+ started++;
- p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1,
- &notify_receive,
- &notify_connect, &notify_disconnect,
- NULL);
- p1->no = 1;
- p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2,
- &notify_receive,
- &notify_connect, &notify_disconnect,
- NULL);
- p2->no = 2;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
+ p->no,
+ GNUNET_i2s (&p->id));
- if ((p1 == NULL) || (p2 == NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
- if (die_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ if (started != 2)
return;
- }
+
test_connected = GNUNET_NO;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n",
@@ -445,7 +435,36 @@ run (void *cls, char *const *args, const char *cfgfile,
sender->no, sender_c,
receiver->no, GNUNET_i2s (&receiver->id));
- GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
+ GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL);
+
+}
+
+
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
+
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
+ &notify_receive,
+ &notify_connect, &notify_disconnect,
+ &start_cb,
+ NULL);
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
+ &notify_receive,
+ &notify_connect, &notify_disconnect,
+ &start_cb,
+ NULL);
+
+ if ((p1 == NULL) || (p2 == NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
+ if (die_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ return;
+ }
}
static int
@@ -479,6 +498,8 @@ main (int argc, char *argv[])
int ret;
int nat_res;
+ tth = GNUNET_TRANSPORT_TESTING_init ();
+
GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
&test_plugin);
diff --git a/src/transport/test_transport_api_reliability_tcp_peer1.conf b/src/transport/test_transport_api_reliability_tcp_peer1.conf
index 1c770dd4f..755ef1dd4 100644
--- a/src/transport/test_transport_api_reliability_tcp_peer1.conf
+++ b/src/transport/test_transport_api_reliability_tcp_peer1.conf
@@ -28,4 +28,3 @@ UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
PORT = 12001
UNIXPATH = /tmp/gnunet-p1-service-transport.sock
-
diff --git a/src/transport/test_transport_api_reliability_tcp_peer2.conf b/src/transport/test_transport_api_reliability_tcp_peer2.conf
index f849dcaaa..e443b5a9a 100644
--- a/src/transport/test_transport_api_reliability_tcp_peer2.conf
+++ b/src/transport/test_transport_api_reliability_tcp_peer2.conf
@@ -27,4 +27,4 @@ UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
[transport]
PORT = 12010
UNIXPATH = /tmp/gnunet-p2-service-transport.sock
-
+#DEBUG = YES
diff --git a/src/transport/test_transport_api_tcp_nat_peer2.conf b/src/transport/test_transport_api_tcp_nat_peer2.conf
index 1b5586c4f..9a068123e 100644
--- a/src/transport/test_transport_api_tcp_nat_peer2.conf
+++ b/src/transport/test_transport_api_tcp_nat_peer2.conf
@@ -31,5 +31,4 @@ UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
[transport]
PORT = 45923
UNIXPATH = /tmp/gnunet-p2-service-transport.sock
-
-
+#DEBUG = YES
diff --git a/src/transport/test_transport_api_tcp_peer1.conf b/src/transport/test_transport_api_tcp_peer1.conf
index 1c770dd4f..7424f5e6f 100644
--- a/src/transport/test_transport_api_tcp_peer1.conf
+++ b/src/transport/test_transport_api_tcp_peer1.conf
@@ -27,5 +27,5 @@ UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
[transport]
PORT = 12001
UNIXPATH = /tmp/gnunet-p1-service-transport.sock
-
+#DEBUG = YES
diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c
index 84a8316bd..bb8ede313 100644
--- a/src/transport/test_transport_api_timeout.c
+++ b/src/transport/test_transport_api_timeout.c
@@ -65,6 +65,8 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task;
static GNUNET_SCHEDULER_TaskIdentifier timer_task;
+struct TransportTestingHandle * tth;
+
struct PeerContext *p1;
struct PeerContext *p2;
@@ -113,8 +115,8 @@ end ()
th = NULL;
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
if (disconnects == 0)
ok = 0;
@@ -125,6 +127,8 @@ end ()
"Fail! Had %u disconnects while waiting %llu seconds \n",
disconnects, WAIT.rel_value);
}
+
+ GNUNET_TRANSPORT_TESTING_done (tth);
}
static void
@@ -139,21 +143,18 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_SCHEDULER_cancel (timer_task);
timer_task = GNUNET_SCHEDULER_NO_TASK;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "1\n");
if (cc != NULL)
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "2\n");
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
if (th != NULL)
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "3\n");
if (p1 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "4\n");
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
if (p2 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5\n");
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
ok = GNUNET_SYSERR;
+
+ GNUNET_TRANSPORT_TESTING_done (tth);
}
@@ -236,10 +237,30 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
shutdown_flag = GNUNET_NO;
- // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
- timer_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (WAIT, 10),
- &timer, NULL);
+ timer_task = GNUNET_SCHEDULER_add_now (&timer, NULL);
+}
+
+void start_cb (struct PeerContext * p,
+ void *cls)
+{
+ static int started;
+ started++;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
+ p->no,
+ GNUNET_i2s (&p->id));
+
+ if (started != 2)
+ return;
+
+ char *sender_c = strdup (GNUNET_i2s (&p1->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
+ p1->no, sender_c,
+ p2->no, GNUNET_i2s (&p2->id));
+
+ cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
+ NULL);
+
}
static void
@@ -248,11 +269,17 @@ run (void *cls, char *const *args, const char *cfgfile,
{
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
- p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, &notify_receive,
- &notify_connect, &notify_disconnect,
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
+ &notify_receive,
+ &notify_connect,
+ &notify_disconnect,
+ &start_cb,
NULL);
- p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, &notify_receive,
- &notify_connect, &notify_disconnect,
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
+ &notify_receive,
+ &notify_connect,
+ &notify_disconnect,
+ &start_cb,
NULL);
if ((p1 == NULL) || (p2 == NULL))
@@ -263,15 +290,12 @@ run (void *cls, char *const *args, const char *cfgfile,
die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
return;
}
-
- cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb,
- NULL);
}
static int
check ()
{
- static char *const argv[] = { "test-transport-api-multiaddress",
+ static char *const argv[] = { "test-transport-api-timeout",
"-c",
"test_transport_api_data.conf",
#if VERBOSE
@@ -290,7 +314,7 @@ check ()
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
- "test-transport-api-multiaddress", "nohelp", options,
+ "test-transport-api-timeout", "nohelp", options,
&run, &ok);
return ok;
@@ -302,6 +326,8 @@ main (int argc, char *argv[])
int ret;
int nat_res;
+ tth = GNUNET_TRANSPORT_TESTING_init ();
+
GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
&test_plugin);
diff --git a/src/transport/test_transport_api_timeout_tcp_peer1.conf b/src/transport/test_transport_api_timeout_tcp_peer1.conf
index 974481fde..d724a6e8b 100644
--- a/src/transport/test_transport_api_timeout_tcp_peer1.conf
+++ b/src/transport/test_transport_api_timeout_tcp_peer1.conf
@@ -6,7 +6,6 @@ DEFAULTCONFIG = template_cfg_peer1.conf
[transport-tcp]
PORT = 12000
TIMEOUT = 5000
-BINDTO = 127.0.0.1
[arm]
PORT = 12005
@@ -28,6 +27,5 @@ UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
[transport]
PORT = 12001
UNIXPATH = /tmp/gnunet-p1-service-transport.sock
-DEBUG = NO
diff --git a/src/transport/test_transport_api_timeout_tcp_peer2.conf b/src/transport/test_transport_api_timeout_tcp_peer2.conf
index 0d4869f77..87503f61c 100644
--- a/src/transport/test_transport_api_timeout_tcp_peer2.conf
+++ b/src/transport/test_transport_api_timeout_tcp_peer2.conf
@@ -7,9 +7,7 @@ DEFAULTCONFIG = template_cfg_peer2.conf
ALLOW_NAT = NO
[transport-tcp]
-PORT = 0
-TIMEOUT = 5000
-BINDTO = 127.0.0.1
+PORT = 12100
[arm]
PORT = 12014
@@ -31,6 +29,5 @@ UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
[transport]
PORT = 12010
UNIXPATH = /tmp/gnunet-p2-service-transport.sock
-DEBUG = NO
diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c
index a8c8d14e9..20b05a50f 100644
--- a/src/transport/test_transport_api_unreliability.c
+++ b/src/transport/test_transport_api_unreliability.c
@@ -78,6 +78,8 @@ char *cfg_file_p2;
uint32_t max_bps_p1;
uint32_t max_bps_p2;
+struct TransportTestingHandle * tth;
+
/*
* Testcase specific declarations
*/
@@ -150,8 +152,10 @@ end ()
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+
+ GNUNET_TRANSPORT_TESTING_done (tth);
ok = 0;
@@ -190,9 +194,11 @@ end_badly ()
th = NULL;
if (p1 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
if (p2 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+
+ GNUNET_TRANSPORT_TESTING_done (tth);
ok = GNUNET_SYSERR;
}
@@ -456,19 +462,44 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
}
+void start_cb (struct PeerContext * p,
+ void *cls)
+{
+ static int started;
+ started++;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
+ p->no,
+ GNUNET_i2s (&p->id));
+
+ if (started != 2)
+ return;
+
+ test_connected = GNUNET_NO;
+
+ test_connected = GNUNET_NO;
+ GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL);
+
+}
+
static void
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
- p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, &notify_receive,
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
+ &notify_receive,
&notify_connect, &notify_disconnect,
+ &start_cb,
NULL);
- p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, &notify_receive,
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
+ &notify_receive,
&notify_connect, &notify_disconnect,
+ &start_cb,
NULL);
+
if ((p1 == NULL) || (p2 == NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
@@ -478,8 +509,7 @@ run (void *cls, char *const *args, const char *cfgfile,
return;
}
- test_connected = GNUNET_NO;
- GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
+
}
static int
@@ -514,6 +544,8 @@ main (int argc, char *argv[])
int ret;
int nat_res;
+ tth = GNUNET_TRANSPORT_TESTING_init ();
+
GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
&test_plugin);
@@ -557,6 +589,7 @@ main (int argc, char *argv[])
GNUNET_free (test_plugin);
GNUNET_free (test_name);
+
return ret;
}
diff --git a/src/transport/test_transport_api_unreliability_constant.c b/src/transport/test_transport_api_unreliability_constant.c
index d7c70df83..670e34f7a 100644
--- a/src/transport/test_transport_api_unreliability_constant.c
+++ b/src/transport/test_transport_api_unreliability_constant.c
@@ -71,6 +71,8 @@ struct PeerContext *p2;
struct GNUNET_TRANSPORT_TransmitHandle *th;
+struct TransportTestingHandle * tth;
+
char *cfg_file_p1;
char *cfg_file_p2;
@@ -149,8 +151,10 @@ end ()
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+
+ GNUNET_TRANSPORT_TESTING_done (tth);
ok = 0;
if (test_failed == GNUNET_NO)
@@ -176,9 +180,11 @@ end_badly ()
th = NULL;
if (p1 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
if (p2 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+
+ GNUNET_TRANSPORT_TESTING_done (tth);
ok = GNUNET_SYSERR;
}
@@ -361,7 +367,7 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
uint32_t ats_count)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (GNUNET_TIME_UNIT_SECONDS%p)!\n",
GNUNET_i2s (peer), cls);
if (cls == p1)
@@ -409,8 +415,24 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
- // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
+ GNUNET_SCHEDULER_add_now (&sendtask, NULL);
+}
+
+void start_cb (struct PeerContext * p,
+ void *cls)
+{
+ static int started;
+ started++;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
+ p->no,
+ GNUNET_i2s (&p->id));
+
+ if (started != 2)
+ return;
+
+ GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL);
+
}
static void
@@ -419,11 +441,15 @@ run (void *cls, char *const *args, const char *cfgfile,
{
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
- p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, &notify_receive,
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
+ &notify_receive,
&notify_connect, &notify_disconnect,
+ &start_cb,
NULL);
- p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, &notify_receive,
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
+ &notify_receive,
&notify_connect, &notify_disconnect,
+ &start_cb,
NULL);
if ((p1 == NULL) || (p2 == NULL))
@@ -434,8 +460,6 @@ run (void *cls, char *const *args, const char *cfgfile,
die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
return;
}
-
- GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
}
static int
@@ -470,6 +494,8 @@ main (int argc, char *argv[])
int ret;
int nat_res;
+ tth = GNUNET_TRANSPORT_TESTING_init ();
+
GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
&test_plugin);
diff --git a/src/transport/test_transport_startonly.c b/src/transport/test_transport_startonly.c
index 89ada4c01..730d7946c 100644
--- a/src/transport/test_transport_startonly.c
+++ b/src/transport/test_transport_startonly.c
@@ -54,6 +54,8 @@ GNUNET_SCHEDULER_TaskIdentifier timeout_task;
static struct PeerContext *p1;
+struct TransportTestingHandle * tth;
+
static int connected = GNUNET_NO;
static int ret = 0;
@@ -83,7 +85,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
return;
if (p1 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
ret = GNUNET_SYSERR;
}
@@ -119,6 +121,8 @@ static void
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ tth = GNUNET_TRANSPORT_TESTING_init ();
+
timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
i = 1;
@@ -126,9 +130,9 @@ run (void *cls, char *const *args, const char *cfgfile,
while (i <= ITERATIONS)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
- p1 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_startonly.conf",
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_startonly.conf", 1,
&notify_receive, &notify_connect,
- &notify_disconnect, p1);
+ &notify_disconnect, NULL, p1);
if (p1 != NULL)
@@ -139,14 +143,15 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_assert (p1 != NULL);
GNUNET_assert (p1->th != NULL);
- //sleep (5);
-
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
i++;
if (i <= ITERATIONS)
fprintf (stderr, "..%i", i);
}
+
+ GNUNET_TRANSPORT_TESTING_init (tth);
+
fprintf (stderr, "\n");
end ();
}
diff --git a/src/transport/test_transport_testing.c b/src/transport/test_transport_testing.c
index db9f528d6..066e56d5b 100644
--- a/src/transport/test_transport_testing.c
+++ b/src/transport/test_transport_testing.c
@@ -53,6 +53,10 @@ GNUNET_SCHEDULER_TaskIdentifier timeout_task;
static struct PeerContext *p1;
static struct PeerContext *p2;
+static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
+
+struct TransportTestingHandle * tth;
+
static int connected = GNUNET_NO;
static int ret = 0;
@@ -65,8 +69,10 @@ end ()
if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (timeout_task);
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+
+ GNUNET_TRANSPORT_TESTING_done (tth);
}
static void
@@ -75,8 +81,12 @@ end_badly ()
timeout_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+ if (p1 != NULL)
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+ if (p2 != NULL)
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+
+ GNUNET_TRANSPORT_TESTING_done (tth);
ret = GNUNET_SYSERR;
}
@@ -84,12 +94,12 @@ end_badly ()
static void
testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
- char *p1_c = strdup (GNUNET_i2s (&p1->id));
-
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers connected: %s <-> %s\n", p1_c,
- GNUNET_i2s (&p2->id));
- GNUNET_free (p1_c);
- end ();
+ char * ps = strdup (GNUNET_i2s(&p1->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to peer %u (`%s')!\n",
+ p1->no, ps,
+ p2->no, GNUNET_i2s (&p2->id));
+ GNUNET_free (ps);
+ GNUNET_SCHEDULER_add_now (&end, NULL);
}
static void
@@ -118,42 +128,68 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n");
}
+void start_cb (struct PeerContext * p,
+ void *cls)
+{
+ static int started;
+ started++;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
+ p->no,
+ GNUNET_i2s (&p->id));
+
+ if (started != 2)
+ return;
+
+ char *sender_c = strdup (GNUNET_i2s (&p1->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
+ p1->no, sender_c,
+ p2->no, GNUNET_i2s (&p2->id));
+
+ cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
+ NULL);
+
+}
static void
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ tth = GNUNET_TRANSPORT_TESTING_init ();
+
timeout_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
- p1 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_api_tcp_peer1.conf",
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer1.conf",
+ 1,
&notify_receive, &notify_connect,
- &notify_disconnect, p1);
-
- p2 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_api_tcp_peer2.conf",
+ &notify_disconnect,
+ &start_cb,
+ p1);
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer2.conf",
+ 2,
&notify_receive, &notify_connect,
- &notify_disconnect, p2);
-
- if (p1 != NULL)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 was successfully started\n");
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer1 was not started successfully\n");
- GNUNET_assert (p1 != NULL);
- GNUNET_assert (p1->th != NULL);
-
- if (p2 != NULL)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 was successfully started\n");
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer2 was not started successfully\n");
- GNUNET_assert (p2 != NULL);
- GNUNET_assert (p2->th != NULL);
-
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peers\n");
- GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
+ &notify_disconnect,
+ &start_cb,
+ p2);
+
+ if (p1 == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 was not started successfully\n");
+ if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel(timeout_task);
+ timeout_task =
+ GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ }
+ if (p2 == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 was not started successfully\n");
+ if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel(timeout_task);
+ timeout_task =
+ GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ }
}
int
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 08bcd5c4e..036fff9e4 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -27,67 +27,58 @@
#include "transport-testing.h"
-struct ConnectingContext
-{
- struct PeerContext *p1;
- struct PeerContext *p2;
- GNUNET_SCHEDULER_TaskIdentifier tct;
- GNUNET_TRANSPORT_TESTING_connect_cb cb;
- void *cb_cls;
- struct GNUNET_TRANSPORT_Handle *th_p1;
- struct GNUNET_TRANSPORT_Handle *th_p2;
- int p1_c;
- int p2_c;
-};
+#define VERBOSE GNUNET_EXTRA_LOGGING
-static void
-exchange_hello_last (void *cb_cls, const struct GNUNET_MessageHeader *message);
-static void
-exchange_hello (void *cb_cls, const struct GNUNET_MessageHeader *message);
-
-static void
-notify_connect_internal (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+struct PeerContext *
+find_peer_context_by_pc ( struct TransportTestingHandle *tth,
+ struct PeerContext *p)
{
- struct ConnectingContext *cc = cls;
-
- GNUNET_assert (cc != NULL);
+ struct PeerContext * t = tth->p_head;
- if (0 ==
- memcmp (&(*peer).hashPubKey, &cc->p1->id.hashPubKey,
- sizeof (GNUNET_HashCode)))
- {
- if (cc->p1_c == GNUNET_NO)
- cc->p1_c = GNUNET_YES;
- }
- if (0 ==
- memcmp (&(*peer).hashPubKey, &cc->p2->id.hashPubKey,
- sizeof (GNUNET_HashCode)))
+ while (t != NULL)
{
- if (cc->p2_c == GNUNET_NO)
- cc->p2_c = GNUNET_YES;
+ if (p == t)
+ break;
+ t = t->next;
}
- if ((cc->p2_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES))
- {
- /* clean up */
- GNUNET_TRANSPORT_get_hello_cancel (cc->p1->ghh);
- GNUNET_TRANSPORT_get_hello_cancel (cc->p2->ghh);
+ return t;
+}
- if (cc->tct != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (cc->tct);
- cc->tct = GNUNET_SCHEDULER_NO_TASK;
+struct PeerContext *
+find_peer_context ( struct TransportTestingHandle *tth,
+ const struct GNUNET_PeerIdentity *peer)
+{
+ struct PeerContext * t = tth->p_head;
+
+ while (t != NULL)
+ {
+ if (0 == memcmp (&t->id, peer, sizeof (struct GNUNET_PeerIdentity)))
+ break;
+ t = t->next;
+ }
- GNUNET_TRANSPORT_disconnect (cc->th_p1);
- GNUNET_TRANSPORT_disconnect (cc->th_p2);
+ return t;
+}
- if (cc->cb != NULL)
- cc->cb (cc->p1, cc->p2, cc->cb_cls);
+struct ConnectingContext *
+find_connecting_context ( struct TransportTestingHandle *tth,
+ struct PeerContext *p1,
+ struct PeerContext * p2)
+{
+ struct ConnectingContext * cc = tth->cc_head;
- GNUNET_free (cc);
+ while (cc != NULL)
+ {
+ if ((cc->p1 == p1) && (cc->p2 == p2))
+ break;
+ if ((cc->p1 == p2) && (cc->p2 == p1))
+ break;
+ cc = cc->next;
}
+
+ return cc;
}
static void
@@ -96,17 +87,63 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
uint32_t ats_count)
{
struct PeerContext *p = cls;
+ /* Find PeerContext */
+ struct PeerContext * p2 = find_peer_context (p->tth, peer);
if (p == NULL)
return;
if (p->nc != NULL)
p->nc (p->cb_cls, peer, ats, ats_count);
+
+#if VERBOSE
+ char * p2_s;
+ if (p2 != NULL)
+ GNUNET_asprintf(&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id));
+ else
+ GNUNET_asprintf(&p2_s, "`%s'", GNUNET_i2s (peer));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
+ "Peers %s connected to peer %u (`%s')\n",
+ p2_s,
+ p->no, GNUNET_i2s (&p->id));
+ GNUNET_free (p2_s);
+#endif
+
+
+ /* Find ConnectingContext */
+ struct ConnectingContext * cc = find_connecting_context(p->tth, p, p2);
+ if (cc == NULL)
+ return;
+
+ if (p == cc->p1)
+ cc->p1_c = GNUNET_YES;
+
+ if (p == cc->p2)
+ cc->p2_c = GNUNET_YES;
+
+ if ((cc->p1_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES))
+ {
+ cc->cb (cc->p1, cc->p2, cc->cb_cls);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel(p->tth, cc);
+ }
}
static void
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *p = cls;
+ /* Find PeerContext */
+ struct PeerContext * p2 = find_peer_context (p->tth, peer);
+
+ char * p2_s;
+ if (p2 != NULL)
+ GNUNET_asprintf(&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id));
+ else
+ GNUNET_asprintf(&p2_s, "`%s'", GNUNET_i2s (peer));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
+ "Peers %s disconnected from peer %u (`%s')\n",
+ p2_s,
+ p->no, GNUNET_i2s (&p->id));
+ GNUNET_free (p2_s);
if (p == NULL)
return;
@@ -128,46 +165,38 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
p->rec (p->cb_cls, peer, message, ats, ats_count);
}
-
static void
-exchange_hello_last (void *cb_cls, const struct GNUNET_MessageHeader *message)
+get_hello (void *cb_cls, const struct GNUNET_MessageHeader *message)
{
- struct ConnectingContext *cc = cb_cls;
- struct PeerContext *me = cc->p2;
-
- //struct PeerContext *p1 = cc->p1;
+ struct PeerContext *p = cb_cls;
GNUNET_assert (message != NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d with peer (%s)!\n",
- (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
- message), GNUNET_i2s (&me->id));
GNUNET_assert (GNUNET_OK ==
GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
- message, &me->id));
- GNUNET_TRANSPORT_offer_hello (cc->th_p1, message, NULL, NULL);
-}
+ message, &p->id));
+ if (p->hello != NULL)
+ GNUNET_free (p->hello);
-static void
-exchange_hello (void *cb_cls, const struct GNUNET_MessageHeader *message)
-{
- struct ConnectingContext *cc = cb_cls;
- struct PeerContext *me = cc->p1;
-
- //struct PeerContext *p2 = cc->p2;
+ size_t size = GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *) message);
+ p->hello = GNUNET_malloc (size);
+ memcpy (p->hello,
+ (const struct GNUNET_HELLO_Message *) message,
+ size);
- GNUNET_assert (message != NULL);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
- message, &me->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d from peer %s!\n",
- (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
- message), GNUNET_i2s (&me->id));
- GNUNET_TRANSPORT_offer_hello (cc->th_p2, message, NULL, NULL);
+ if (p->start_cb != NULL)
+ {
+#if VERBOSE
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
+ "Peer %u (`%s') successfully started\n",
+ p->no, GNUNET_i2s (&p->id), size);
+#endif
+ p->start_cb(p, p->cb_cls);
+ p->start_cb = NULL;
+ }
}
+
static void
try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
@@ -179,10 +208,15 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
- /* FIXME: 'pX.id' may still be all-zeros here... */
+ char * p2_s = strdup(GNUNET_i2s (&p2->id));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
+ "Asking peers %u (`%s') to connect peer %u (`%s')\n",
+ p1->no, GNUNET_i2s (&p1->id), p2->no, p2_s);
+ GNUNET_free (p2_s);
+
+ GNUNET_TRANSPORT_offer_hello (cc->th_p1,
+ (const struct GNUNET_MessageHeader *) cc->p2->hello, NULL, NULL);
GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id);
- GNUNET_TRANSPORT_try_connect (cc->th_p2, &p1->id);
cc->tct =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, cc);
@@ -198,15 +232,19 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
* @return the peer context
*/
struct PeerContext *
-GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
+GNUNET_TRANSPORT_TESTING_start_peer (struct TransportTestingHandle * tth,
+ const char *cfgname,
+ int peer_id,
GNUNET_TRANSPORT_ReceiveCallback rec,
GNUNET_TRANSPORT_NotifyConnect nc,
GNUNET_TRANSPORT_NotifyDisconnect nd,
+ GNUNET_TRANSPORT_TESTING_start_cb start_cb,
void *cb_cls)
{
if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "File not found: `%s' \n", cfgname);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing",
+ "File not found: `%s' \n", cfgname);
return NULL;
}
@@ -229,9 +267,13 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
"-L", "ERROR",
#endif
NULL);
+
+ p->no = peer_id;
+ p->tth = tth;
p->nc = nc;
p->nd = nd;
p->rec = rec;
+ p->start_cb = start_cb;
if (cb_cls != NULL)
p->cb_cls = cb_cls;
else
@@ -241,6 +283,12 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
GNUNET_TRANSPORT_connect (p->cfg, NULL, p, &notify_receive,
&notify_connect, &notify_disconnect);
GNUNET_assert (p->th != NULL);
+
+ p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p);
+ GNUNET_assert (p->ghh != NULL);
+
+ GNUNET_CONTAINER_DLL_insert(tth->p_head, tth->p_tail, p);
+
return p;
}
@@ -249,9 +297,15 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
* @param p the peer
*/
void
-GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext *p)
+GNUNET_TRANSPORT_TESTING_stop_peer (struct TransportTestingHandle * tth,
+ struct PeerContext *p)
{
GNUNET_assert (p != NULL);
+
+ if (p->ghh != NULL)
+ GNUNET_TRANSPORT_get_hello_cancel (p->ghh);
+ p->ghh = NULL;
+
if (p->th != NULL)
GNUNET_TRANSPORT_disconnect (p->th);
@@ -263,22 +317,29 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext *p)
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
}
+
if (p->servicehome != NULL)
{
GNUNET_DISK_directory_remove (p->servicehome);
GNUNET_free (p->servicehome);
}
+ if (p->hello != NULL)
+ GNUNET_free (p->hello);
+
if (p->cfg != NULL)
GNUNET_CONFIGURATION_destroy (p->cfg);
+
+ GNUNET_CONTAINER_DLL_remove (tth->p_head, tth->p_tail, p);
+
GNUNET_free (p);
p = NULL;
}
/**
- * Connect the two given peers and call the callback when both peers report the
- * inbound connect. Remarks: start_peer's notify_connect callback can be called
- * before.
+ * Initiate peer p1 to connect to peer p2
+ * Get peer p2's HELLO and offer it to p1
+ * p1 then tries to connect to p2
* @param p1 peer 1
* @param p2 peer 2
* @param cb the callback to call
@@ -286,10 +347,12 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext *p)
* @return connect context
*/
GNUNET_TRANSPORT_TESTING_ConnectRequest
-GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
+GNUNET_TRANSPORT_TESTING_connect_peers (struct TransportTestingHandle * tth,
+ struct PeerContext *p1,
struct PeerContext *p2,
GNUNET_TRANSPORT_TESTING_connect_cb cb,
void *cb_cls)
+
{
struct ConnectingContext *cc =
GNUNET_malloc (sizeof (struct ConnectingContext));
@@ -303,22 +366,23 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
cc->cb = cb;
cc->cb_cls = cb_cls;
- cc->th_p1 =
- GNUNET_TRANSPORT_connect (cc->p1->cfg, NULL, cc, NULL,
- &notify_connect_internal, NULL);
+ cc->th_p1 = p1->th;
+ /* GNUNET_TRANSPORT_connect (cc->p1->cfg, NULL, cc, NULL,
+ &notify_connect_internal, NULL);*/
- cc->th_p2 =
- GNUNET_TRANSPORT_connect (cc->p2->cfg, NULL, cc, NULL,
- &notify_connect_internal, NULL);
+ cc->th_p2 = p2->th;
+ /* GNUNET_TRANSPORT_connect (cc->p2->cfg, NULL, cc, NULL,
+ &notify_connect_internal, NULL);*/
GNUNET_assert (cc->th_p1 != NULL);
GNUNET_assert (cc->th_p2 != NULL);
- p1->ghh = GNUNET_TRANSPORT_get_hello (cc->th_p1, &exchange_hello, cc);
- p2->ghh = GNUNET_TRANSPORT_get_hello (cc->th_p2, &exchange_hello_last, cc);
+ GNUNET_CONTAINER_DLL_insert (tth->cc_head, tth->cc_tail, cc);
cc->tct = GNUNET_SCHEDULER_add_now (&try_connect, cc);
return cc;
+
+
}
/**
@@ -327,25 +391,57 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
* @param cc a connect request handle
*/
void GNUNET_TRANSPORT_TESTING_connect_peers_cancel
- (GNUNET_TRANSPORT_TESTING_ConnectRequest ccr)
+ (struct TransportTestingHandle * tth,
+ GNUNET_TRANSPORT_TESTING_ConnectRequest ccr)
{
struct ConnectingContext *cc = ccr;
- /* clean up */
- GNUNET_TRANSPORT_get_hello_cancel (cc->p1->ghh);
- GNUNET_TRANSPORT_get_hello_cancel (cc->p2->ghh);
-
if (cc->tct != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (cc->tct);
cc->tct = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_TRANSPORT_disconnect (cc->th_p1);
- GNUNET_TRANSPORT_disconnect (cc->th_p2);
+ GNUNET_CONTAINER_DLL_remove (tth->cc_head, tth->cc_tail, cc);
GNUNET_free (cc);
}
+void
+GNUNET_TRANSPORT_TESTING_done (struct TransportTestingHandle * tth)
+{
+ struct ConnectingContext *cc = tth->cc_head;
+ struct ConnectingContext *ct = NULL;
+ struct PeerContext *p = tth->p_head;
+ struct PeerContext *t = NULL;
+ while (cc != NULL)
+ {
+ ct = cc->next;
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing",
+ "Developer forgot to cancel connect request!\n");
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
+ cc = ct;
+ }
+
+ while (p != NULL)
+ {
+ t = p->next;
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing",
+ "Developer forgot to stop peer!\n");
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p);
+ p = t;
+ }
+
+ GNUNET_free (tth);
+}
+
+struct TransportTestingHandle *
+GNUNET_TRANSPORT_TESTING_init ()
+{
+ struct TransportTestingHandle * tth = GNUNET_malloc (sizeof (struct TransportTestingHandle));
+
+ return tth;
+}
+
/*
* Some utility functions
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 75a568cf7..2aaff26b0 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -31,15 +31,45 @@
#include "gnunet_hello_lib.h"
#include "gnunet_os_lib.h"
#include "gnunet_program_lib.h"
+#include "gnunet_container_lib.h"
#include "gnunet_transport_service.h"
#define GNUNET_TRANSPORT_TESTING_ConnectRequest void *
+
+/**
+ * Context for a single peer
+ */
+struct PeerContext;
+
+/**
+ * Callback when two peers are connected and both have called the connect callback
+ * to notify clients about a new peer
+ */
+typedef void (*GNUNET_TRANSPORT_TESTING_start_cb) (struct PeerContext * p,
+ void *cls);
+
+/**
+ * Callback when two peers are connected and both have called the connect callback
+ * to notify clients about a new peer
+ */
+typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
+ struct PeerContext * p2,
+ void *cls);
+
+
+struct TransportTestingHandle;
+
/**
* Context for a single peer
*/
struct PeerContext
{
+ struct PeerContext * next;
+ struct PeerContext * prev;
+
+ struct TransportTestingHandle * tth;
+
struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_TRANSPORT_Handle *th;
@@ -56,6 +86,10 @@ struct PeerContext
GNUNET_TRANSPORT_NotifyDisconnect nd;
+ GNUNET_TRANSPORT_TESTING_start_cb start_cb;
+
+ struct GNUNET_HELLO_Message *hello;
+
void *cb_cls;
char *servicehome;
@@ -63,13 +97,31 @@ struct PeerContext
unsigned int no;
};
-/**
- * Callback when two peers are connected and both have called the connect callback
- * to notify clients about a new peer
- */
-typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
- struct PeerContext * p2,
- void *cls);
+
+struct ConnectingContext
+{
+ struct ConnectingContext * next;
+ struct ConnectingContext * prev;
+ struct PeerContext *p1;
+ struct PeerContext *p2;
+ GNUNET_SCHEDULER_TaskIdentifier tct;
+ GNUNET_TRANSPORT_TESTING_connect_cb cb;
+ void *cb_cls;
+ struct GNUNET_TRANSPORT_Handle *th_p1;
+ struct GNUNET_TRANSPORT_Handle *th_p2;
+ int p1_c;
+ int p2_c;
+};
+
+struct TransportTestingHandle
+{
+ struct ConnectingContext * cc_head;
+ struct ConnectingContext * cc_tail;
+
+ struct PeerContext * p_head;
+ struct PeerContext * p_tail;
+};
+
/**
@@ -82,10 +134,13 @@ typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
* @return the peer context
*/
struct PeerContext *
-GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
+GNUNET_TRANSPORT_TESTING_start_peer (struct TransportTestingHandle * tth,
+ const char *cfgname,
+ int peer_id,
GNUNET_TRANSPORT_ReceiveCallback rec,
GNUNET_TRANSPORT_NotifyConnect nc,
GNUNET_TRANSPORT_NotifyDisconnect nd,
+ GNUNET_TRANSPORT_TESTING_start_cb start_cb,
void *cb_cls);
@@ -95,7 +150,8 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
*/
void
-GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext *pc);
+GNUNET_TRANSPORT_TESTING_stop_peer (struct TransportTestingHandle * tth,
+ struct PeerContext *pc);
/**
@@ -109,7 +165,8 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext *pc);
* @return a connect request handle
*/
GNUNET_TRANSPORT_TESTING_ConnectRequest
-GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
+GNUNET_TRANSPORT_TESTING_connect_peers (struct TransportTestingHandle * tth,
+ struct PeerContext *p1,
struct PeerContext *p2,
GNUNET_TRANSPORT_TESTING_connect_cb cb,
void *cls);
@@ -120,7 +177,15 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
* @param cc a connect request handle
*/
void
-GNUNET_TRANSPORT_TESTING_connect_peers_cancel (void *cc);
+GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct TransportTestingHandle *,
+ void *cc);
+
+
+void
+GNUNET_TRANSPORT_TESTING_done (struct TransportTestingHandle * tth);
+
+struct TransportTestingHandle *
+GNUNET_TRANSPORT_TESTING_init ();
/*
* Some utility functions