src/transport/transport_api_address_to_string.c
src/transport/transport_api_blacklist.c
src/transport/transport_api.c
+src/transport/transport_api_core.c
+src/transport/transport_api_get_hello.c
src/transport/transport_api_monitor_peers.c
src/transport/transport_api_monitor_plugins.c
-src/transport/transport_api_monitor_validation.c
+src/transport/transport_api_offer_hello.c
src/transport/transport-testing.c
+src/transport/transport-testing-filenames.c
+src/transport/transport-testing-loggers.c
+src/transport/transport-testing-main.c
src/tun/regex.c
src/tun/tun.c
src/util/bandwidth.c
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received a store request (size: %lu).\n" " Sub system `%s'\n"
- " Peer `%s'\n" " Key `%s'\n" " Value size %lu\n"
- " Options: %d.\n", record->value_size, record->sub_system,
- GNUNET_i2s (record->peer), record->key, record->value_size,
+ "Received a store request (size: %u). Sub system `%s' Peer `%s Key `%s' Options: %d.\n",
+ (unsigned int) record->value_size,
+ record->sub_system,
+ GNUNET_i2s (record->peer),
+ record->key,
ntohl (srm->options));
record->client = client;
if (GNUNET_OK !=
TESTS = \
test_transport_testing_startstop \
test_transport_testing_restart \
- test_transport_testing \
test_plugin_tcp \
test_plugin_udp \
$(UNIX_TEST) \
test_transport_api_timeout_tcp_peer2.conf\
test_transport_api_multi_peer1.conf\
test_transport_api_multi_peer2.conf\
+test_transport_api_restart_1peer_peer1.conf\
+test_transport_api_restart_1peer_peer2.conf\
test_transport_api_reliability_http_peer1.conf\
test_transport_api_reliability_http_peer2.conf\
test_transport_api_reliability_https_peer1.conf\
test_transport_api_manipulation_recv_tcp_peer2.conf\
test_transport_api_manipulation_cfg_peer1.conf\
test_transport_api_manipulation_cfg_peer2.conf\
+test_transport_api_restart_1peer_peer1.conf\
+test_transport_api_restart_1peer_peer2.conf\
+test_transport_api_restart_2peers_peer1.conf\
+test_transport_api_restart_2peers_peer2.conf\
test_transport_api_tcp_nat_peer1.conf\
test_transport_api_tcp_nat_peer2.conf\
test_transport_api_tcp_peer1.conf\
{
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
.connect_continuation = &connected_cb,
- .config_file = "test_transport_startonly.conf",
+ .config_file = "test_transport_api.conf",
.rec = ¬ify_receive,
.nc = &GNUNET_TRANSPORT_TESTING_log_connect,
.nd = ¬ify_disconnect,
char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "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),
¬ify_receive,
¬ify_connect,
¬ify_disconnect,
+ NULL,
&start_cb,
NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
¬ify_receive,
¬ify_connect,
¬ify_disconnect,
+ NULL,
&start_cb,
NULL);
if ((p1 == NULL) || (p2 == NULL))
/*
This file is part of GNUnet.
- Copyright (C) 2009, 2010, 2015 GNUnet e.V.
+ Copyright (C) 2009, 2010, 2015, 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
/**
* How long until we give up on transmitting the message?
*/
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
#define MTYPE 12345
-static char *test_name;
-static int ok;
-
-static struct GNUNET_SCHEDULER_Task *die_task;
-
-static struct GNUNET_SCHEDULER_Task *send_task;
+static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
-
static int p1_connected;
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
-
static int p2_connected;
-static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
-
static struct GNUNET_TRANSPORT_TransmitHandle *th;
-static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
-
-static char *cfg_file_p1;
-
-static char *cfg_file_p2;
+static struct GNUNET_SCHEDULER_Task *send_task;
static int restarted;
static void
-end ()
+custom_shutdown (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping peers\n");
-
- if (NULL != send_task)
- {
- GNUNET_SCHEDULER_cancel (send_task);
- send_task = NULL;
- }
if (NULL != ats_sh)
{
GNUNET_ATS_connectivity_suggest_cancel (ats_sh);
ats_sh = NULL;
}
- if (NULL != die_task)
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = NULL;
- }
if (NULL != th)
{
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
}
- if (NULL != p1)
- {
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
- p1 = NULL;
- }
- if (NULL != p2)
- {
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
- p2 = NULL;
- }
-}
-
-
-static void
-end_badly (void *cls)
-{
- die_task = NULL;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Fail! Stopping peers\n");
-
- if (restarted == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Peer was restarted\n");
-
- if (restarted == GNUNET_NO)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Peer was NOT restarted\n");
- if (NULL != cc)
+ if (NULL != send_task)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Fail! Could not connect peers\n"));
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
- cc = NULL;
+ GNUNET_SCHEDULER_cancel (send_task);
+ send_task = NULL;
}
- end ();
- ok = GNUNET_SYSERR;
}
static void
-restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls)
+restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
+ void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Restarted peer %u (`%4s'), issuing reconnect\n",
+ "Restarted peer %u (`%s'), issuing reconnect\n",
p->no,
GNUNET_i2s (&p->id));
ats_sh = GNUNET_ATS_connectivity_suggest (p->ats,
- &p2->id,
+ &ccc->p[1]->id,
1);
}
restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Restarting peer %u (`%4s')\n",
+ "Restarting peer %u (`%s')\n",
p->no,
GNUNET_i2s (&p->id));
- GNUNET_TRANSPORT_TESTING_restart_peer (p,
- &restart_cb,
- p);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_TRANSPORT_TESTING_restart_peer (p,
+ &restart_cb,
+ p));
}
static void
notify_receive (void *cls,
- const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
+ const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
- struct GNUNET_TRANSPORT_TESTING_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;
- GNUNET_assert (t != NULL);
-
- char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "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));
- GNUNET_free (ps);
+ {
+ char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "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),
+ GNUNET_i2s (sender));
+ GNUNET_free (ps);
+ }
if ((MTYPE == ntohs (message->type)) &&
(sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
{
- if (restarted == GNUNET_NO)
+ if (GNUNET_NO == restarted)
{
restarted = GNUNET_YES;
- restart (p1);
+ restart (ccc->p[0]);
return;
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Restarted peers connected and message was sent, stopping test...\n");
- ok = 0;
- end ();
+ ccc->global_ret = GNUNET_OK;
+ GNUNET_SCHEDULER_shutdown ();
}
}
else
{
GNUNET_break (0);
- ok = 1;
- if (die_task != NULL)
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ ccc->global_ret = GNUNET_SYSERR;
+ GNUNET_SCHEDULER_shutdown ();
}
}
static size_t
-notify_ready (void *cls, size_t size, void *buf)
+notify_ready (void *cls,
+ size_t size,
+ void *buf)
{
struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
struct GNUNET_MessageHeader *hdr;
th = NULL;
-
if (NULL == buf)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Timeout occurred while waiting for transmit_ready\n");
- if (NULL != die_task)
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
- ok = 42;
+ GNUNET_SCHEDULER_shutdown ();
+ ccc->global_ret = 42;
return 0;
}
hdr->type = htons (MTYPE);
{
- char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
+ char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->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,
+ "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n",
+ ccc->p[1]->no,
ps,
ntohs (hdr->type),
ntohs (hdr->size),
sendtask (void *cls)
{
send_task = NULL;
- char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
- p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
- GNUNET_free (receiver_s);
-
- th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
- &p1->id,
+ {
+ char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
+ ccc->p[1]->no,
+ GNUNET_i2s (&ccc->p[1]->id),
+ ccc->p[0]->no,
+ receiver_s);
+ GNUNET_free (receiver_s);
+ }
+ th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
+ &ccc->p[0]->id,
256,
TIMEOUT_TRANSMIT,
¬ify_ready,
- p1);
+ ccc->p[0]);
}
static void
notify_connect (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+ struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
+ const struct GNUNET_PeerIdentity *other)
{
- static int c;
-
- c++;
- struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
- struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
-
- if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
- {
+ GNUNET_TRANSPORT_TESTING_log_connect (cls,
+ me,
+ other);
+ if (0 == memcmp (other,
+ &ccc->p[0]->id,
+ sizeof (struct GNUNET_PeerIdentity)))
p1_connected = GNUNET_YES;
- t = p1;
- }
- if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
- {
+ if (0 == memcmp (other,
+ &ccc->p[1]->id,
+ sizeof (struct GNUNET_PeerIdentity)))
p2_connected = GNUNET_YES;
- t = p2;
- }
- GNUNET_assert (t != NULL);
- char *ps = GNUNET_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);
-
- if ( (restarted == GNUNET_YES) &&
- (p1_connected == GNUNET_YES) &&
- (p2_connected == GNUNET_YES) )
+ if ( (GNUNET_YES == restarted) &&
+ (GNUNET_YES == p1_connected) &&
+ (GNUNET_YES == p2_connected) )
{
/* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */
- send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
+ send_task = GNUNET_SCHEDULER_add_now (&sendtask,
+ NULL);
}
}
static void
-notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_disconnect (void *cls,
+ struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
+ const struct GNUNET_PeerIdentity *other)
{
- struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-
- if ( (NULL != p1) &&
- (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))))
- {
+ GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
+ me,
+ other);
+ if (me == ccc->p[0])
p1_connected = GNUNET_NO;
- }
- if ( (NULL != p2) &&
- (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))))
- {
+ if (me == ccc->p[1])
p2_connected = GNUNET_NO;
- }
- char *ps = GNUNET_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));
- GNUNET_free (ps);
-
- if (th != NULL)
+ if (NULL != th)
+ {
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
- th = NULL;
+ th = NULL;
+ }
if (NULL != send_task)
- GNUNET_SCHEDULER_cancel (send_task);
- send_task = NULL;
-}
-
-
-static void
-testing_connect_cb (void *cls)
-{
- cc = NULL;
- char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peers connected: %u (%s) <-> %u (%s)\n",
- p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
- GNUNET_free (p1_c);
-
- send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
-}
-
-
-
-static void
-start_cb (struct GNUNET_TRANSPORT_TESTING_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 = GNUNET_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));
- GNUNET_free (sender_c);
-
- cc = GNUNET_TRANSPORT_TESTING_connect_peers (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_connected = GNUNET_NO;
- p2_connected = GNUNET_NO;
- p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
- cfg_file_p1,
- 1,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
- NULL);
-
- p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
- cfg_file_p2,
- 2,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
- NULL);
-
- if ((p1 == NULL) || (p2 == NULL))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Fail! Could not start peers!\n");
- if (die_task != NULL)
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly,
- NULL);
- return;
+ GNUNET_SCHEDULER_cancel (send_task);
+ send_task = NULL;
}
}
-static int
-check ()
-{
- static char *const argv[] = { "test-transport-api",
- "-c",
- "test_transport_api_data.conf",
- NULL
- };
- static struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
-
- send_task = NULL;
-
- ok = 1;
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name,
- "nohelp", options, &run, &ok);
-
- return ok;
-}
-
int
main (int argc, char *argv[])
{
- int ret;
-
- test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]);
- GNUNET_log_setup (test_name,
- "WARNING",
- NULL);
- tth = GNUNET_TRANSPORT_TESTING_init ();
- GNUNET_asprintf (&cfg_file_p1, "test_transport_api_tcp_peer1.conf");
- GNUNET_asprintf (&cfg_file_p2, "test_transport_api_tcp_peer2.conf");
- ret = check ();
- GNUNET_free (cfg_file_p1);
- GNUNET_free (cfg_file_p2);
- GNUNET_free (test_name);
- GNUNET_TRANSPORT_TESTING_done (tth);
- return ret;
+ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
+ .connect_continuation = &sendtask,
+ .config_file = "test_transport_api_data.conf",
+ .rec = ¬ify_receive,
+ .nc = ¬ify_connect,
+ .nd = ¬ify_disconnect,
+ .shutdown_task = &custom_shutdown,
+ .timeout = TIMEOUT
+ };
+
+ ccc = &my_ccc;
+ if (GNUNET_OK !=
+ GNUNET_TRANSPORT_TESTING_main (2,
+ &GNUNET_TRANSPORT_TESTING_connect_check,
+ ccc))
+ return 1;
+ return 0;
}
/* end of test_transport_api_restart_1peer.c */
--- /dev/null
+@INLINE@ template_cfg_peer1.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p1/
+
+[transport]
+PLUGINS = tcp
+
+#[transport]
+#PREFIX = valgrind
--- /dev/null
+@INLINE@ template_cfg_peer2.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p2/
+
+[transport]
+PLUGINS = tcp
+
+#[transport]
+#PREFIX = valgrind
/*
This file is part of GNUnet.
- Copyright (C) 2009, 2010, 2015 GNUnet e.V.
+ Copyright (C) 2009, 2010, 2015, 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
Boston, MA 02110-1301, USA.
*/
/**
- * @file transport/test_transport_api_restart_2peers.c
+ * @file transport/test_transport_api_restart_1peer.c
* @brief base test case for transport implementations
*
* This test case starts 2 peers, connects and exchanges a message
- * boths peer are restarted and tested if peers reconnect
+ * 1 peer is restarted and tested if peers reconnect
+ * C code apparently.
*/
#include "platform.h"
#include "gnunet_transport_service.h"
/**
* How long until we give up on transmitting the message?
*/
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
/**
* How long until we give up on transmitting the message?
*/
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
+#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
#define MTYPE 12345
-static char *test_name;
-static int ok;
-
-static struct GNUNET_SCHEDULER_Task *die_task;
-
-static struct GNUNET_SCHEDULER_Task *send_task;
+static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
-
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
+static int p1_connected;
-static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
+static int p2_connected;
static struct GNUNET_TRANSPORT_TransmitHandle *th;
-static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
-
-static char *cfg_file_p1;
-
-static char *cfg_file_p2;
+static struct GNUNET_SCHEDULER_Task *send_task;
static int restarted;
static void
-end ()
+custom_shutdown (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
- if (NULL != send_task)
- {
- GNUNET_SCHEDULER_cancel (send_task);
- send_task = NULL;
- }
if (NULL != ats_sh)
{
GNUNET_ATS_connectivity_suggest_cancel (ats_sh);
ats_sh = NULL;
}
- if (NULL != die_task)
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = NULL;
- }
if (NULL != th)
{
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
}
- if (NULL != p1)
- {
- GNUNET_TRANSPORT_TESTING_stop_peer (p1);
- p1 = NULL;
- }
- if (NULL != p2)
- {
- GNUNET_TRANSPORT_TESTING_stop_peer (p2);
- p2 = NULL;
- }
-}
-
-
-static void
-end_badly (void *cls)
-{
- die_task = NULL;
-
- if (restarted == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Peer was restarted, but communication did not resume\n");
-
- if (restarted == GNUNET_NO)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Peer was NOT (even) restarted\n");
- if (cc != NULL)
+ if (NULL != send_task)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Fail! Could not connect peers\n"));
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
- cc = NULL;
+ GNUNET_SCHEDULER_cancel (send_task);
+ send_task = NULL;
}
- end ();
- ok = GNUNET_SYSERR;
}
restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
void *cls)
{
- static int c;
+ static unsigned int c;
c++;
if (c != 2)
return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Restarted peer %u (`%4s'), issuing reconnect\n",
+ "Restarted peer %u (`%s'), issuing reconnect\n",
p->no,
GNUNET_i2s (&p->id));
- ats_sh = GNUNET_ATS_connectivity_suggest (p->ats,
- &p2->id,
+ ats_sh = GNUNET_ATS_connectivity_suggest (ccc->p[0]->ats,
+ &ccc->p[1]->id,
1);
}
static void
restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
{
- GNUNET_assert (NULL != p);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Restarting peer %u (`%4s')\n",
+ "Restarting peer %u (`%s')\n",
p->no,
GNUNET_i2s (&p->id));
- GNUNET_TRANSPORT_TESTING_restart_peer (p,
- &restart_cb,
- p);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_TRANSPORT_TESTING_restart_peer (p,
+ &restart_cb,
+ p));
}
static void
notify_receive (void *cls,
- const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
+ const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
- struct GNUNET_TRANSPORT_TESTING_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;
- GNUNET_assert (t != NULL);
-
{
- char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
+ 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 %u (`%4s')!\n",
- p->no,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "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),
- t->no,
- GNUNET_i2s (&t->id));
+ GNUNET_i2s (sender));
GNUNET_free (ps);
}
-
if ((MTYPE == ntohs (message->type)) &&
(sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
{
- if (restarted == GNUNET_NO)
+ if (GNUNET_NO == restarted)
{
restarted = GNUNET_YES;
- restart (p1);
- restart (p2);
+ restart (ccc->p[0]);
+ restart (ccc->p[1]);
return;
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Restarted peers connected, stopping test...\n");
- ok = 0;
- end ();
+ "Restarted peers connected and message was sent, stopping test...\n");
+ ccc->global_ret = GNUNET_OK;
+ GNUNET_SCHEDULER_shutdown ();
}
}
else
{
GNUNET_break (0);
- ok = 1;
- if (die_task != NULL)
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ ccc->global_ret = GNUNET_SYSERR;
+ GNUNET_SCHEDULER_shutdown ();
}
}
static size_t
notify_ready (void *cls,
- size_t size,
- void *buf)
+ size_t size,
+ void *buf)
{
struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
struct GNUNET_MessageHeader *hdr;
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Timeout occurred while waiting for transmit_ready\n");
- if (NULL != die_task)
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
- ok = 42;
+ GNUNET_SCHEDULER_shutdown ();
+ ccc->global_ret = 42;
return 0;
}
hdr->type = htons (MTYPE);
{
- char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
+ char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->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,
+ "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n",
+ ccc->p[1]->no,
ps,
ntohs (hdr->type),
ntohs (hdr->size),
GNUNET_i2s (&p->id));
GNUNET_free (ps);
}
-
return sizeof (struct GNUNET_MessageHeader);
}
{
send_task = NULL;
{
- char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
+ char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
- p2->no,
- GNUNET_i2s (&p2->id),
- p1->no,
- receiver_s);
+ "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
+ ccc->p[1]->no,
+ GNUNET_i2s (&ccc->p[1]->id),
+ ccc->p[0]->no,
+ receiver_s);
GNUNET_free (receiver_s);
}
-
- th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
- &p1->id,
+ th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
+ &ccc->p[0]->id,
256,
TIMEOUT_TRANSMIT,
¬ify_ready,
- p1);
+ ccc->p[0]);
}
static void
-notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_connect (void *cls,
+ struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
+ const struct GNUNET_PeerIdentity *other)
{
- static int c;
- struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
- struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
-
- c++;
- if (0 == memcmp (peer,
- &p1->id,
- sizeof (struct GNUNET_PeerIdentity)))
- t = p1;
- if (0 == memcmp (peer,
- &p2->id,
- sizeof (struct GNUNET_PeerIdentity)))
- t = p2;
- GNUNET_assert (t != NULL);
-
- {
- char *ps = GNUNET_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);
- }
-
- if ((restarted == GNUNET_YES) && (c == 4))
+ GNUNET_TRANSPORT_TESTING_log_connect (cls,
+ me,
+ other);
+ if (0 == memcmp (other,
+ &ccc->p[0]->id,
+ sizeof (struct GNUNET_PeerIdentity)))
+ p1_connected = GNUNET_YES;
+ if (0 == memcmp (other,
+ &ccc->p[1]->id,
+ sizeof (struct GNUNET_PeerIdentity)))
+ p2_connected = GNUNET_YES;
+
+ if ( (GNUNET_YES == restarted) &&
+ (GNUNET_YES == p1_connected) &&
+ (GNUNET_YES == p2_connected) )
{
+ /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */
send_task = GNUNET_SCHEDULER_add_now (&sendtask,
- NULL);
+ NULL);
}
}
static void
notify_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+ struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
+ const struct GNUNET_PeerIdentity *other)
{
- struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-
- {
- char *ps = GNUNET_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));
- GNUNET_free (ps);
- }
-
- if (th != NULL)
+ GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
+ me,
+ other);
+ if (me == ccc->p[0])
+ p1_connected = GNUNET_NO;
+ if (me == ccc->p[1])
+ p2_connected = GNUNET_NO;
+ if (NULL != th)
{
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
}
-static void
-testing_connect_cb (void *cls)
-{
- cc = NULL;
-
- {
- char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peers connected: %u (%s) <-> %u (%s)\n",
- p1->no,
- p1_c,
- p2->no,
- GNUNET_i2s (&p2->id));
- GNUNET_free (p1_c);
- }
- send_task = GNUNET_SCHEDULER_add_now (&sendtask,
- NULL);
-}
-
-
-static void
-start_cb (struct GNUNET_TRANSPORT_TESTING_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 = GNUNET_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));
- GNUNET_free (sender_c);
- }
-
- cc = GNUNET_TRANSPORT_TESTING_connect_peers (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,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
- NULL);
-
- p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
- cfg_file_p2,
- 2,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
- NULL);
-
- if ((p1 == NULL) || (p2 == NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
- if (die_task != NULL)
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
- return;
- }
-}
-
-
-static int
-check ()
-{
- static char *const argv[] = { "test-transport-api",
- "-c",
- "test_transport_api_data.conf",
- NULL
- };
- static struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
-
- send_task = NULL;
-
- ok = 1;
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name,
- "nohelp", options, &run, NULL);
-
- return ok;
-}
-
-
int
main (int argc, char *argv[])
{
- int ret;
-
- test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]);
- GNUNET_log_setup (test_name,
- "WARNING",
- NULL);
- tth = GNUNET_TRANSPORT_TESTING_init ();
- GNUNET_asprintf (&cfg_file_p1, "test_transport_api_tcp_peer1.conf");
- GNUNET_asprintf (&cfg_file_p2, "test_transport_api_tcp_peer2.conf");
- ret = check ();
- GNUNET_free (cfg_file_p1);
- GNUNET_free (cfg_file_p2);
- GNUNET_free (test_name);
- GNUNET_TRANSPORT_TESTING_done (tth);
- return ret;
+ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
+ .connect_continuation = &sendtask,
+ .config_file = "test_transport_api_data.conf",
+ .rec = ¬ify_receive,
+ .nc = ¬ify_connect,
+ .nd = ¬ify_disconnect,
+ .shutdown_task = &custom_shutdown,
+ .timeout = TIMEOUT
+ };
+
+ ccc = &my_ccc;
+ if (GNUNET_OK !=
+ GNUNET_TRANSPORT_TESTING_main (2,
+ &GNUNET_TRANSPORT_TESTING_connect_check,
+ ccc))
+ return 1;
+ return 0;
}
-/* end of test_transport_api_restart_2peers.c */
+/* end of test_transport_api_restart_1peer.c */
--- /dev/null
+@INLINE@ template_cfg_peer1.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p1/
+
+[transport]
+PLUGINS = tcp
+
+#[transport]
+#PREFIX = valgrind
--- /dev/null
+@INLINE@ template_cfg_peer2.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p2/
+
+[transport]
+PLUGINS = tcp
+
+#[transport]
+#PREFIX = valgrind
¬ify_receive,
¬ify_connect,
¬ify_disconnect,
+ NULL,
&start_cb,
NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
¬ify_receive,
¬ify_connect,
¬ify_disconnect,
+ NULL,
&start_cb,
NULL);
1,
NULL,
NULL,
+ NULL,
NULL,
&start_cb,
NULL);
2,
NULL,
NULL,
+ NULL,
NULL,
&start_cb,
NULL);
p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
cfg_p1,
1, NULL, NULL, NULL,
+ NULL,
&start_cb, NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
cfg_p2, 2,
NULL, NULL, NULL,
+ NULL,
&start_cb, NULL);
/* check if configuration contain correct blacklist entries */
cfg_p1,
1,
NULL,
+ NULL,
NULL,
NULL,
&start_cb,
cfg_p2, 2,
NULL,
NULL,
+ NULL,
NULL,
&start_cb,
NULL);
p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
cfg_p1, 1,
+ NULL,
NULL, NULL, NULL,
&start_cb, NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
cfg_p2, 2,
+ NULL,
NULL, NULL, NULL,
&start_cb, NULL);
p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
cfg_p1, 1,
+ NULL,
NULL, NULL, NULL,
&start_cb, NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
cfg_p2, 2,
+ NULL,
NULL, NULL,
NULL,
&start_cb, NULL);
p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
cfg_p1, 1,
+ NULL,
NULL, NULL, NULL,
&start_cb, NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
cfg_p2, 2,
+ NULL,
NULL, NULL, NULL,
&start_cb, NULL);
NULL, /* receive cb */
NULL, /* connect cb */
NULL, /* disconnect cb */
+ NULL, /* nc/nd closure */
start_cb, /* startup cb */
NULL); /* closure */
if (NULL == p)
&end_badly,
NULL);
- p = GNUNET_TRANSPORT_TESTING_start_peer(tth,
- cfgfile,
- 1,
- NULL, /* receive cb */
- NULL, /* connect cb */
- NULL, /* disconnect cb */
- &start_cb, /* startup cb */
- NULL); /* closure */
+ p = GNUNET_TRANSPORT_TESTING_start_peer (tth,
+ cfgfile,
+ 1,
+ NULL, /* receive cb */
+ NULL, /* connect cb */
+ NULL, /* disconnect cb */
+ NULL, /* nc/nd closure */
+ &start_cb, /* startup cb */
+ NULL); /* closure */
if (NULL == p)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n");
&my_rec,
&my_nc,
&my_nd,
+ &ccc->ip[i],
&start_cb,
&ccc->ip[i]);
if (NULL == ccc->p[i])
p->no,
GNUNET_i2s (&p->id));
p->start_cb (p,
- p->cb_cls);
+ p->start_cb_cls);
p->start_cb = NULL;
}
}
* @param rec receive callback
* @param nc connect callback
* @param nd disconnect callback
- * @param start_cb start callback
* @param cb_cls closure for callback
+ * @param start_cb start callback
+ * @param start_cb_cls closure for callback
* @return the peer context
*/
struct GNUNET_TRANSPORT_TESTING_PeerContext *
GNUNET_TRANSPORT_ReceiveCallback rec,
GNUNET_TRANSPORT_NotifyConnect nc,
GNUNET_TRANSPORT_NotifyDisconnect nd,
+ void *cb_cls,
GNUNET_TRANSPORT_TESTING_StartCallback start_cb,
- void *cb_cls)
+ void *start_cb_cls)
{
char *emsg = NULL;
struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
p->nc = nc;
p->nd = nd;
p->rec = rec;
- p->start_cb = start_cb;
- if (cb_cls != NULL)
+ if (NULL != cb_cls)
p->cb_cls = cb_cls;
else
p->cb_cls = p;
+ p->start_cb = start_cb;
+ p->start_cb_cls = start_cb_cls;
GNUNET_CONTAINER_DLL_insert (tth->p_head,
tth->p_tail,
p);
*
* @param p the peer
* @param restart_cb callback to call when restarted
- * @param cb_cls callback closure
+ * @param restart_cb_cls callback closure
* @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
*/
int
GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
GNUNET_TRANSPORT_TESTING_StartCallback restart_cb,
- void *cb_cls)
+ void *restart_cb_cls)
{
/* shutdown */
LOG (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_assert (NULL == p->start_cb);
p->start_cb = restart_cb;
- p->cb_cls = cb_cls;
+ p->start_cb_cls = restart_cb_cls;
p->th = GNUNET_TRANSPORT_connect (p->cfg,
NULL,
struct GNUNET_HELLO_Message *hello;
/**
- * Closure for the callbacks
+ * Closure for the @a nc and @a nd callbacks
*/
void *cb_cls;
+ /**
+ * Closure for @e start_cb.
+ */
+ void *start_cb_cls;
+
/**
* An unique number to identify the peer
*/
* @param rec receive callback
* @param nc connect callback
* @param nd disconnect callback
+ * @param cb_cls closure for @a nc and @a nd callback
* @param start_cb start callback
- * @param cb_cls closure for callback
+ * @param start_cb_cls closure for @a start_cb
* @return the peer context
*/
struct GNUNET_TRANSPORT_TESTING_PeerContext *
GNUNET_TRANSPORT_ReceiveCallback rec,
GNUNET_TRANSPORT_NotifyConnect nc,
GNUNET_TRANSPORT_NotifyDisconnect nd,
+ void *cb_cls,
GNUNET_TRANSPORT_TESTING_StartCallback start_cb,
- void *cb_cls);
+ void *start_cb_cls);
/**
*
* @param p the peer
* @param restart_cb restart callback
- * @param cb_cls callback closure
+ * @param restart_cb_cls callback closure
* @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
*/
int
GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
GNUNET_TRANSPORT_TESTING_StartCallback restart_cb,
- void *cb_cls);
+ void *restart_cb_cls);
GNUNET_MQ_discard (env);
continue;
}
+ obm->header.size = htons (mret + sizeof (*obm));
if (NULL != n->unready_warn_task)
n->unready_warn_task
= GNUNET_SCHEDULER_add_delayed (UNREADY_WARN_TIME,
want = ntohs (hdr->size);
if (want < sizeof (struct GNUNET_MessageHeader))
{
- GNUNET_break_op (0);
+ GNUNET_break_op (0);
mst->off = 0;
return GNUNET_SYSERR;
}