aboutsummaryrefslogtreecommitdiff
path: root/src/setup/gnunet-setup-transport-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/setup/gnunet-setup-transport-test.c')
-rw-r--r--src/setup/gnunet-setup-transport-test.c65
1 files changed, 62 insertions, 3 deletions
diff --git a/src/setup/gnunet-setup-transport-test.c b/src/setup/gnunet-setup-transport-test.c
index f351ddf5..dd2f5674 100644
--- a/src/setup/gnunet-setup-transport-test.c
+++ b/src/setup/gnunet-setup-transport-test.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010, 2011, 2014 GNUnet e.V. 3 Copyright (C) 2010, 2011, 2014, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -30,9 +30,13 @@
30/** 30/**
31 * How long do we wait for the NAT test to report success? 31 * How long do we wait for the NAT test to report success?
32 */ 32 */
33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
34 34
35 35
36/**
37 * Data structure we keep for NAT tests that run asynchronously until
38 * #TIMEOUT or shutdown.
39 */
36struct TestContext 40struct TestContext
37{ 41{
38 42
@@ -42,6 +46,16 @@ struct TestContext
42 struct GNUNET_NAT_AUTO_Test *tst; 46 struct GNUNET_NAT_AUTO_Test *tst;
43 47
44 /** 48 /**
49 * Timeout task.
50 */
51 struct GNUNET_SCHEDULER_Task *tt;
52
53 /**
54 * Shutdown task.
55 */
56 struct GNUNET_SCHEDULER_Task *st;
57
58 /**
45 * Name of widget to show on success. 59 * Name of widget to show on success.
46 */ 60 */
47 const char *success_image; 61 const char *success_image;
@@ -61,7 +75,8 @@ struct TestContext
61 * @param result #GNUNET_YES on success 75 * @param result #GNUNET_YES on success
62 */ 76 */
63static void 77static void
64display_test_result (struct TestContext *tc, int result) 78display_test_result (struct TestContext *tc,
79 int result)
65{ 80{
66 GObject *w; 81 GObject *w;
67 82
@@ -93,6 +108,41 @@ display_test_result (struct TestContext *tc, int result)
93 108
94 109
95/** 110/**
111 * Task run on timeout.
112 *
113 * @param cls the `struct TestContext`
114 */
115static void
116timeout_task (void *cls)
117{
118 struct TestContext *tc = cls;
119
120 tc->tt = NULL;
121 GNUNET_SCHEDULER_cancel (tc->st);
122 tc->st = NULL;
123 display_test_result (tc,
124 GNUNET_SYSERR);
125}
126
127
128/**
129 * Task run on shutdown.
130 *
131 * @param cls the `struct TestContext`
132 */
133static void
134shutdown_task (void *cls)
135{
136 struct TestContext *tc = cls;
137
138 tc->st = NULL;
139 GNUNET_SCHEDULER_cancel (tc->tt);
140 GNUNET_NAT_AUTO_test_stop (tc->tst);
141 GNUNET_free (tc);
142}
143
144
145/**
96 * Function called by NAT on success. 146 * Function called by NAT on success.
97 * Clean up and update GUI (with success). 147 * Clean up and update GUI (with success).
98 * 148 *
@@ -105,6 +155,10 @@ result_callback (void *cls,
105{ 155{
106 struct TestContext *tc = cls; 156 struct TestContext *tc = cls;
107 157
158 GNUNET_SCHEDULER_cancel (tc->tt);
159 tc->tt = NULL;
160 GNUNET_SCHEDULER_cancel (tc->st);
161 tc->st = NULL;
108 display_test_result (tc, 162 display_test_result (tc,
109 (GNUNET_NAT_ERROR_SUCCESS == result) 163 (GNUNET_NAT_ERROR_SUCCESS == result)
110 ? GNUNET_OK 164 ? GNUNET_OK
@@ -137,6 +191,11 @@ GNUNET_setup_transport_test (const char *section_name,
137 gtk_widget_hide (w); 191 gtk_widget_hide (w);
138 GNUNET_assert (NULL != cfg); 192 GNUNET_assert (NULL != cfg);
139 GNUNET_RESOLVER_connect (cfg); 193 GNUNET_RESOLVER_connect (cfg);
194 tc->tt = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
195 &timeout_task,
196 tc);
197 tc->st = GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
198 tc);
140 tc->tst = GNUNET_NAT_AUTO_test_start (cfg, 199 tc->tst = GNUNET_NAT_AUTO_test_start (cfg,
141 proto, 200 proto,
142 section_name, 201 section_name,