#include "gnunet_transport_service.h"
#include "gauger.h"
#include "transport.h"
+#include "transport-testing.h"
#define VERBOSE GNUNET_NO
* 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
* messages may be dropped even for a reliable transport.
*/
-#define TOTAL_MSGS (80000 * 3) /* Total messages should be divisible by 8, so we can make a nice bitmap */
+#define TOTAL_MSGS (1024 * 3) /* Total messages should be divisible by 8, so we can make a nice bitmap */
/**
* How long until we give up on transmitting the message?
#define MTYPE 12345
-struct PeerContext
-{
- struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_TRANSPORT_Handle *th;
- struct GNUNET_PeerIdentity id;
-#if START_ARM
- struct GNUNET_OS_Process *arm_proc;
-#endif
-};
-
static struct PeerContext p1;
static struct PeerContext p2;
static GNUNET_SCHEDULER_TaskIdentifier tct;
+struct GNUNET_TRANSPORT_TransmitHandle * th_p2;
+
static char *key_file_p1;
static char *cert_file_p1;
static int msg_recv_expected;
static int msg_recv;
+static int p1_hello_canceled;
+static int p2_hello_canceled;
+
+static int test_failed;
+
/**
* Sets a bit active in the bitmap.
*
}
}
- GNUNET_SCHEDULER_cancel (die_task);
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_NO_TASK;
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
#endif
+ if (th_p2 != NULL)
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
+ th_p2 = NULL;
+
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
#if VERBOSE
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
#endif
+ if (th_p2 != NULL)
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
+
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
#if VERBOSE
}
+
+static void
+exchange_hello_last (void *cls,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct PeerContext *me = 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 (p1.th, message, NULL, NULL);
+}
+
+
+
+static void
+exchange_hello (void *cls,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct PeerContext *me = cls;
+
+ 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 (p2.th, message, NULL, NULL);
+}
+
+
+
static void
end_badly (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reliability failed: Last message sent %u Next message scheduled %u Last message received %u Message expected %u\n",
- msg_sent,
- msg_scheduled,
- msg_recv,
- msg_recv_expected);
+ if (test_failed == GNUNET_NO)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Testcase timeout\n");
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n",
+ msg_sent,
+ msg_scheduled,
+ msg_recv,
+ msg_recv_expected);
+
GNUNET_break (0);
+ if (th_p2 != NULL)
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
+ th_p2 = NULL;
+ }
+ if (p2_hello_canceled == GNUNET_NO)
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
+ p2_hello_canceled = GNUNET_YES;
+ }
+ if (p1_hello_canceled == GNUNET_NO)
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
+ p1_hello_canceled = GNUNET_YES;
+ }
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
-
if (GNUNET_SCHEDULER_NO_TASK != tct)
{
GNUNET_SCHEDULER_cancel (tct);
}
+
struct TestMessage
{
struct GNUNET_MessageHeader header;
{
unsigned int ret;
- if (iter < 60000)
- return iter + sizeof (struct TestMessage);
ret = (iter * iter * iter);
return sizeof (struct TestMessage) + (ret % 60000);
}
ntohl(hdr->num), s,
ntohs (message->size),
ntohl (hdr->num));
- GNUNET_SCHEDULER_cancel (die_task);
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
+ test_failed = GNUNET_YES;
die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Expected message %u with bits %u, but body did not match\n",
ntohl(hdr->num), (unsigned char) n);
- GNUNET_SCHEDULER_cancel (die_task);
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
+ test_failed = GNUNET_YES;
die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
return;
}
#endif
n++;
set_bit(ntohl(hdr->num));
- if (0 == (n % (5000)))
+ if (0 == (n % (TOTAL_MSGS / 100)))
{
fprintf (stderr, ".");
- GNUNET_SCHEDULER_cancel (die_task);
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
+ test_failed = GNUNET_YES;
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&end_badly,
NULL);
unsigned int s;
unsigned int ret;
+ th_p2 = NULL;
+
if (buf == NULL)
{
GNUNET_break (0);
while (size - ret >= s);
if (n < TOTAL_MSGS)
{
- GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
+ th_p2 = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
&p1.id,
s, 0, TIMEOUT,
¬ify_ready,
else
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent!!\n");
- GNUNET_SCHEDULER_cancel(die_task);
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel(die_task);
die_task = GNUNET_SCHEDULER_add_delayed (UNRELIABLE_TIMEOUT, &end_unreliably, NULL);
}
if (n % 5000 == 0)
"Peer `%4s' disconnected (%p)!\n",
GNUNET_i2s (peer), cls);
#endif
+ if (th_p2 != NULL)
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
+ th_p2 = NULL;
+ }
}
-static void
-exchange_hello_last (void *cls,
- const struct GNUNET_MessageHeader *message)
-{
- struct PeerContext *me = cls;
-
- 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 (message != NULL);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
- message, &me->id));
- GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
-}
-
-
-
-static void
-exchange_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
-{
- struct PeerContext *me = cls;
-
- 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 (p2.th, message, NULL, NULL);
-}
-
-
static void
notify_connect (void *cls,
const struct GNUNET_PeerIdentity *peer,
}
if (2 == connected)
{
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_cancel (tct);
- tct = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
- GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ }
+ if (GNUNET_SCHEDULER_NO_TASK != tct)
+ {
+ GNUNET_SCHEDULER_cancel (tct);
+ tct = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (p2_hello_canceled == GNUNET_NO)
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
+ p2_hello_canceled = GNUNET_YES;
+ }
+ if (p1_hello_canceled == GNUNET_NO)
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
+ p1_hello_canceled = GNUNET_YES;
+ }
+
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&end_badly, NULL);
GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
static void
setup_peer (struct PeerContext *p, const char *cfgname)
{
+ memset (p, 0, sizeof (*p));
p->cfg = GNUNET_CONFIGURATION_create ();
+
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+ if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (p->cfg,
+ "PATHS", "SERVICEHOME",
+ &p->servicehome));
+ GNUNET_DISK_directory_remove (p->servicehome);
+ }
+
+
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
"gnunet-service-arm",
#endif
"-c", cfgname, NULL);
#endif
- GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
-
- if (is_https)
- {
- struct stat sbuf;
- if (p==&p1)
- {
- if (GNUNET_CONFIGURATION_have_value (p->cfg,
- "transport-https", "KEY_FILE"))
- GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p1);
- if (key_file_p1 == NULL)
- GNUNET_asprintf(&key_file_p1,"https_p1.key");
- if (0 == stat (key_file_p1, &sbuf ))
- {
- if (0 == remove(key_file_p1))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing private key file `%s'\n",key_file_p1);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove private key file `%s'\n",key_file_p1);
- }
- if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
- GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p1);
- if (cert_file_p1 == NULL)
- GNUNET_asprintf(&cert_file_p1,"https_p1.cert");
- if (0 == stat (cert_file_p1, &sbuf ))
- {
- if (0 == remove(cert_file_p1))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing certificate file `%s'\n",cert_file_p1);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove existing certificate file `%s'\n",cert_file_p1);
- }
- }
- else if (p==&p2)
- {
- if (GNUNET_CONFIGURATION_have_value (p->cfg,
- "transport-https", "KEY_FILE"))
- GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p2);
- if (key_file_p2 == NULL)
- GNUNET_asprintf(&key_file_p2,"https_p2.key");
- if (0 == stat (key_file_p2, &sbuf ))
- {
- if (0 == remove(key_file_p2))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing private key file `%s'\n",key_file_p2);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove private key file `%s'\n",key_file_p2);
- }
- if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
- GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p2);
- if (cert_file_p2 == NULL)
- GNUNET_asprintf(&cert_file_p2,"https_p2.cert");
- if (0 == stat (cert_file_p2, &sbuf ))
- {
- if (0 == remove(cert_file_p2))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing certificate file `%s'\n",cert_file_p2);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove existing certificate file `%s'\n",cert_file_p2);
- }
- }
- }
p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
p,
GNUNET_assert(p1.th != NULL);
GNUNET_assert(p2.th != NULL);
GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
+ p1_hello_canceled = GNUNET_NO;
GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
+ p2_hello_canceled = GNUNET_NO;
tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL);
}
static int
check ()
{
- char *const argv[] = { "test-transport-api-reliability",
+ char *const argv[] = { "test-transport-api-unreliability",
"-c",
"test_transport_api_data.conf",
#if VERBOSE
}
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-transport-api-reliability", "nohelp",
+ argv, "test-transport-api-unreliability", "nohelp",
options, &run, &ok);
stop_arm (&p1);
stop_arm (&p2);
GNUNET_free(cert_file_p2);
}
+ if (p1.servicehome != NULL)
+ {
+ GNUNET_DISK_directory_remove (p1.servicehome);
+ GNUNET_free(p1.servicehome);
+ }
+ if (p2.servicehome != NULL)
+ {
+ GNUNET_DISK_directory_remove (p2.servicehome);
+ GNUNET_free(p2.servicehome);
+ }
return ok;
}
main (int argc, char *argv[])
{
int ret;
-#ifdef MINGW
- return GNUNET_SYSERR;
-#endif
+
+ test_failed = GNUNET_NO;
GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
{
is_wlan = GNUNET_YES;
}
- GNUNET_log_setup ("test-transport-api-reliability",
+ GNUNET_log_setup ("test-transport-api-unreliability",
#if VERBOSE
"DEBUG",
#else
#endif
NULL);
ret = check ();
- GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
+
GNUNET_free_non_null(test_name);
return ret;
}
-/* end of test_transport_api_reliability.c */
+/* end of test_transport_api_unreliability.c */