aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 17:40:28 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 17:40:28 +0000
commit3d9fda8a1eb0c21c58440d64f5e934d818a40eaf (patch)
tree53923f70d96036e6041882f2a81801ee738dd737
parentc6cad778edf8963396850f6dedbb0a4c80a3af47 (diff)
downloadgnunet-gtk-3d9fda8a1eb0c21c58440d64f5e934d818a40eaf.tar.gz
gnunet-gtk-3d9fda8a1eb0c21c58440d64f5e934d818a40eaf.zip
eliminate SCHEDULER_run, simplify code
-rw-r--r--src/setup/Makefile.am1
-rw-r--r--src/setup/gnunet-setup-options.c2
-rw-r--r--src/setup/gnunet-setup-options.h2
-rw-r--r--src/setup/gnunet-setup-transport-http.c143
-rw-r--r--src/setup/gnunet-setup-transport-https.c143
-rw-r--r--src/setup/gnunet-setup-transport-tcp.c143
-rw-r--r--src/setup/gnunet-setup-transport-test.c199
-rw-r--r--src/setup/gnunet-setup-transport-test.h44
-rw-r--r--src/setup/gnunet-setup-transport-udp.c142
-rw-r--r--src/setup/gnunet-setup-transport.c7
-rw-r--r--src/setup/gnunet-setup.c21
11 files changed, 293 insertions, 554 deletions
diff --git a/src/setup/Makefile.am b/src/setup/Makefile.am
index a30485ed..b5934ad4 100644
--- a/src/setup/Makefile.am
+++ b/src/setup/Makefile.am
@@ -17,6 +17,7 @@ gnunet_setup_SOURCES = \
17 gnunet-setup.c gnunet-setup.h \ 17 gnunet-setup.c gnunet-setup.h \
18 gnunet-setup-options.c gnunet-setup-options.h \ 18 gnunet-setup-options.c gnunet-setup-options.h \
19 gnunet-setup-transport-plugins.c \ 19 gnunet-setup-transport-plugins.c \
20 gnunet-setup-transport-test.c gnunet-setup-transport-test.h \
20 gnunet-setup-transport-http.c \ 21 gnunet-setup-transport-http.c \
21 gnunet-setup-transport-https.c \ 22 gnunet-setup-transport-https.c \
22 gnunet-setup-transport-tcp.c \ 23 gnunet-setup-transport-tcp.c \
diff --git a/src/setup/gnunet-setup-options.c b/src/setup/gnunet-setup-options.c
index ee230c2b..fe896892 100644
--- a/src/setup/gnunet-setup-options.c
+++ b/src/setup/gnunet-setup-options.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file src/gnunet-setup-options.c 22 * @file src/setup/gnunet-setup-options.c
23 * @brief configuration details 23 * @brief configuration details
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
diff --git a/src/setup/gnunet-setup-options.h b/src/setup/gnunet-setup-options.h
index 25cd6507..1c1a3a03 100644
--- a/src/setup/gnunet-setup-options.h
+++ b/src/setup/gnunet-setup-options.h
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file src/gnunet-setup-options.h 22 * @file src/setup/gnunet-setup-options.h
23 * @brief configuration details 23 * @brief configuration details
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
diff --git a/src/setup/gnunet-setup-transport-http.c b/src/setup/gnunet-setup-transport-http.c
index 36447917..17c116c6 100644
--- a/src/setup/gnunet-setup-transport-http.c
+++ b/src/setup/gnunet-setup-transport-http.c
@@ -19,158 +19,27 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file src/gnunet-setup-transport-http.c 22 * @file src/setup/gnunet-setup-transport-http.c
23 * @brief support for HTTP configuration 23 * @brief support for HTTP configuration
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "gnunet-setup.h" 26#include "gnunet-setup.h"
27#include <gnunet/gnunet_resolver_service.h> 27#include <gnunet/gnunet_resolver_service.h>
28#include <gnunet/gnunet_nat_lib.h> 28#include <gnunet/gnunet_nat_lib.h>
29 29#include "gnunet-setup-transport-test.h"
30/**
31 * How long do we wait for the NAT test to report success?
32 */
33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
34
35/**
36 * Handle to the active NAT test.
37 */
38static struct GNUNET_NAT_Test *tst;
39
40/**
41 * Task identifier for the timeout.
42 */
43static GNUNET_SCHEDULER_TaskIdentifier tsk;
44
45
46/**
47 * Function called by NAT on success.
48 * Clean up and update GUI (with success).
49 *
50 * @param cls closure (unused)
51 * @param success currently always GNUNET_OK
52 */
53static void
54result_callback (void *cls,
55 int success)
56{
57 int *ok = cls;
58
59 *ok = success;
60 GNUNET_SCHEDULER_cancel (tsk);
61 tsk = GNUNET_SCHEDULER_NO_TASK;
62 GNUNET_NAT_test_stop (tst);
63 tst = NULL;
64}
65 30
66 31
67/** 32/**
68 * Function called if NAT failed to confirm success.
69 * Clean up and update GUI (with failure).
70 *
71 * @param cls closure (unused)
72 * @param tc scheduler callback
73 */
74static void
75fail_timeout (void *cls,
76 const struct GNUNET_SCHEDULER_TaskContext *tc)
77{
78 int *ok = cls;
79
80 GNUNET_assert (NULL != tst);
81 *ok = GNUNET_NO;
82 tsk = GNUNET_SCHEDULER_NO_TASK;
83 GNUNET_NAT_test_stop (tst);
84 tst = NULL;
85}
86
87
88/**
89 * Main function for the NAT test.
90 *
91 * @param cls the 'int*' for the result
92 * @param tc scheduler context
93 */
94static void
95test (void *cls,
96 const struct GNUNET_SCHEDULER_TaskContext *tc)
97{
98 int *ok = cls;
99 unsigned long long bnd_port;
100 unsigned long long adv_port;
101
102 GNUNET_assert (NULL != cfg);
103 GNUNET_RESOLVER_connect (cfg);
104 if (GNUNET_OK !=
105 GNUNET_CONFIGURATION_get_value_number (cfg,
106 "transport-http",
107 "PORT",
108 &bnd_port))
109 {
110 GNUNET_break (0);
111 return;
112 }
113 if (GNUNET_OK !=
114 GNUNET_CONFIGURATION_get_value_number (cfg,
115 "transport-http",
116 "ADVERTISED_PORT",
117 &adv_port))
118 adv_port = bnd_port;
119 tst = GNUNET_NAT_test_start (cfg,
120 GNUNET_YES,
121 (uint16_t) bnd_port,
122 (uint16_t) adv_port,
123 &result_callback,
124 ok);
125 if (NULL == tst)
126 {
127 *ok = GNUNET_SYSERR;
128 return;
129 }
130 tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
131 &fail_timeout,
132 ok);
133}
134
135/**
136 * Function called whenever the user wants to test the 33 * Function called whenever the user wants to test the
137 * HTTP configuration. 34 * HTTP configuration.
138 */ 35 */
139void 36void
140GNUNET_setup_transport_http_test_button_clicked_cb () 37GNUNET_setup_transport_http_test_button_clicked_cb ()
141{ 38{
142 GtkWidget *w; 39 GNUNET_setup_transport_test ("transport-http",
143 int ok; 40 GNUNET_YES,
144 struct GNUNET_OS_Process *resolver; 41 "GNUNET_setup_transport_http_test_success_image",
145 42 "GNUNET_setup_transport_http_test_fail_image");
146 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tsk);
147 GNUNET_assert (NULL == tst);
148 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_http_test_success_image"));
149 gtk_widget_hide (w);
150 resolver = GNUNET_OS_start_process (NULL, NULL,
151 "gnunet-service-resolver",
152 "gnunet-service-resolver", NULL);
153 ok = GNUNET_NO;
154 GNUNET_SCHEDULER_run (&test, &ok);
155 if (NULL != resolver)
156 {
157 GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
158 GNUNET_OS_process_close (resolver);
159 }
160 if (GNUNET_YES != ok)
161 {
162 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_http_test_fail_image"));
163 gtk_widget_show (w);
164 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_http_test_success_image"));
165 gtk_widget_hide (w);
166 }
167 else
168 {
169 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_http_test_fail_image"));
170 gtk_widget_hide (w);
171 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_http_test_success_image"));
172 gtk_widget_show (w);
173 }
174} 43}
175 44
176 45
diff --git a/src/setup/gnunet-setup-transport-https.c b/src/setup/gnunet-setup-transport-https.c
index c4ac462a..08554383 100644
--- a/src/setup/gnunet-setup-transport-https.c
+++ b/src/setup/gnunet-setup-transport-https.c
@@ -19,158 +19,27 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file src/gnunet-setup-transport-https.c 22 * @file src/setup/gnunet-setup-transport-https.c
23 * @brief support for HTTPS configuration 23 * @brief support for HTTPS configuration
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "gnunet-setup.h" 26#include "gnunet-setup.h"
27#include <gnunet/gnunet_resolver_service.h> 27#include <gnunet/gnunet_resolver_service.h>
28#include <gnunet/gnunet_nat_lib.h> 28#include <gnunet/gnunet_nat_lib.h>
29 29#include "gnunet-setup-transport-test.h"
30/**
31 * How long do we wait for the NAT test to report success?
32 */
33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
34
35/**
36 * Handle to the active NAT test.
37 */
38static struct GNUNET_NAT_Test *tst;
39
40/**
41 * Task identifier for the timeout.
42 */
43static GNUNET_SCHEDULER_TaskIdentifier tsk;
44
45
46/**
47 * Function called by NAT on success.
48 * Clean up and update GUI (with success).
49 *
50 * @param cls closure (unused)
51 * @param success currently always GNUNET_OK
52 */
53static void
54result_callback (void *cls,
55 int success)
56{
57 int *ok = cls;
58
59 *ok = success;
60 GNUNET_SCHEDULER_cancel (tsk);
61 tsk = GNUNET_SCHEDULER_NO_TASK;
62 GNUNET_NAT_test_stop (tst);
63 tst = NULL;
64}
65 30
66 31
67/** 32/**
68 * Function called if NAT failed to confirm success.
69 * Clean up and update GUI (with failure).
70 *
71 * @param cls closure (unused)
72 * @param tc scheduler callback
73 */
74static void
75fail_timeout (void *cls,
76 const struct GNUNET_SCHEDULER_TaskContext *tc)
77{
78 int *ok = cls;
79
80 GNUNET_assert (NULL != tst);
81 *ok = GNUNET_NO;
82 tsk = GNUNET_SCHEDULER_NO_TASK;
83 GNUNET_NAT_test_stop (tst);
84 tst = NULL;
85}
86
87
88/**
89 * Main function for the NAT test.
90 *
91 * @param cls the 'int*' for the result
92 * @param tc scheduler context
93 */
94static void
95test (void *cls,
96 const struct GNUNET_SCHEDULER_TaskContext *tc)
97{
98 int *ok = cls;
99 unsigned long long bnd_port;
100 unsigned long long adv_port;
101
102 GNUNET_assert (NULL != cfg);
103 GNUNET_RESOLVER_connect (cfg);
104 if (GNUNET_OK !=
105 GNUNET_CONFIGURATION_get_value_number (cfg,
106 "transport-https",
107 "PORT",
108 &bnd_port))
109 {
110 GNUNET_break (0);
111 return;
112 }
113 if (GNUNET_OK !=
114 GNUNET_CONFIGURATION_get_value_number (cfg,
115 "transport-https",
116 "ADVERTISED_PORT",
117 &adv_port))
118 adv_port = bnd_port;
119 tst = GNUNET_NAT_test_start (cfg,
120 GNUNET_YES,
121 (uint16_t) bnd_port,
122 (uint16_t) adv_port,
123 &result_callback,
124 ok);
125 if (NULL == tst)
126 {
127 *ok = GNUNET_SYSERR;
128 return;
129 }
130 tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
131 &fail_timeout,
132 ok);
133}
134
135/**
136 * Function called whenever the user wants to test the 33 * Function called whenever the user wants to test the
137 * HTTPS configuration. 34 * HTTPS configuration.
138 */ 35 */
139void 36void
140GNUNET_setup_transport_https_test_button_clicked_cb () 37GNUNET_setup_transport_https_test_button_clicked_cb ()
141{ 38{
142 GtkWidget *w; 39 GNUNET_setup_transport_test ("transport-https",
143 int ok; 40 GNUNET_YES,
144 struct GNUNET_OS_Process *resolver; 41 "GNUNET_setup_transport_https_test_success_image",
145 42 "GNUNET_setup_transport_https_test_fail_image");
146 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tsk);
147 GNUNET_assert (NULL == tst);
148 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_https_test_success_image"));
149 gtk_widget_hide (w);
150 resolver = GNUNET_OS_start_process (NULL, NULL,
151 "gnunet-service-resolver",
152 "gnunet-service-resolver", NULL);
153 ok = GNUNET_NO;
154 GNUNET_SCHEDULER_run (&test, &ok);
155 if (NULL != resolver)
156 {
157 GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
158 GNUNET_OS_process_close (resolver);
159 }
160 if (GNUNET_YES != ok)
161 {
162 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_https_test_fail_image"));
163 gtk_widget_show (w);
164 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_https_test_success_image"));
165 gtk_widget_hide (w);
166 }
167 else
168 {
169 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_https_test_fail_image"));
170 gtk_widget_hide (w);
171 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_https_test_success_image"));
172 gtk_widget_show (w);
173 }
174} 43}
175 44
176 45
diff --git a/src/setup/gnunet-setup-transport-tcp.c b/src/setup/gnunet-setup-transport-tcp.c
index 52312a4b..89d8085c 100644
--- a/src/setup/gnunet-setup-transport-tcp.c
+++ b/src/setup/gnunet-setup-transport-tcp.c
@@ -19,158 +19,27 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file src/gnunet-setup-transport-tcp.c 22 * @file src/setup/gnunet-setup-transport-tcp.c
23 * @brief support for TCP configuration 23 * @brief support for TCP configuration
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "gnunet-setup.h" 26#include "gnunet-setup.h"
27#include <gnunet/gnunet_resolver_service.h> 27#include <gnunet/gnunet_resolver_service.h>
28#include <gnunet/gnunet_nat_lib.h> 28#include <gnunet/gnunet_nat_lib.h>
29 29#include "gnunet-setup-transport-test.h"
30/**
31 * How long do we wait for the NAT test to report success?
32 */
33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
34
35/**
36 * Handle to the active NAT test.
37 */
38static struct GNUNET_NAT_Test *tst;
39
40/**
41 * Task identifier for the timeout.
42 */
43static GNUNET_SCHEDULER_TaskIdentifier tsk;
44
45
46/**
47 * Function called by NAT on success.
48 * Clean up and update GUI (with success).
49 *
50 * @param cls closure (unused)
51 * @param success currently always GNUNET_OK
52 */
53static void
54result_callback (void *cls,
55 int success)
56{
57 int *ok = cls;
58
59 *ok = success;
60 GNUNET_SCHEDULER_cancel (tsk);
61 tsk = GNUNET_SCHEDULER_NO_TASK;
62 GNUNET_NAT_test_stop (tst);
63 tst = NULL;
64}
65 30
66 31
67/** 32/**
68 * Function called if NAT failed to confirm success.
69 * Clean up and update GUI (with failure).
70 *
71 * @param cls closure (unused)
72 * @param tc scheduler callback
73 */
74static void
75fail_timeout (void *cls,
76 const struct GNUNET_SCHEDULER_TaskContext *tc)
77{
78 int *ok = cls;
79
80 GNUNET_assert (NULL != tst);
81 *ok = GNUNET_NO;
82 tsk = GNUNET_SCHEDULER_NO_TASK;
83 GNUNET_NAT_test_stop (tst);
84 tst = NULL;
85}
86
87
88/**
89 * Main function for the NAT test.
90 *
91 * @param cls the 'int*' for the result
92 * @param tc scheduler context
93 */
94static void
95test (void *cls,
96 const struct GNUNET_SCHEDULER_TaskContext *tc)
97{
98 int *ok = cls;
99 unsigned long long bnd_port;
100 unsigned long long adv_port;
101
102 GNUNET_assert (NULL != cfg);
103 GNUNET_RESOLVER_connect (cfg);
104 if (GNUNET_OK !=
105 GNUNET_CONFIGURATION_get_value_number (cfg,
106 "transport-tcp",
107 "PORT",
108 &bnd_port))
109 {
110 GNUNET_break (0);
111 return;
112 }
113 if (GNUNET_OK !=
114 GNUNET_CONFIGURATION_get_value_number (cfg,
115 "transport-tcp",
116 "ADVERTISED_PORT",
117 &adv_port))
118 adv_port = bnd_port;
119 tst = GNUNET_NAT_test_start (cfg,
120 GNUNET_YES,
121 (uint16_t) bnd_port,
122 (uint16_t) adv_port,
123 &result_callback,
124 ok);
125 if (NULL == tst)
126 {
127 *ok = GNUNET_SYSERR;
128 return;
129 }
130 tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
131 &fail_timeout,
132 ok);
133}
134
135/**
136 * Function called whenever the user wants to test the 33 * Function called whenever the user wants to test the
137 * TCP configuration. 34 * TCP configuration.
138 */ 35 */
139void 36void
140GNUNET_setup_transport_tcp_test_button_clicked_cb () 37GNUNET_setup_transport_tcp_test_button_clicked_cb ()
141{ 38{
142 GtkWidget *w; 39 GNUNET_setup_transport_test ("transport-tcp",
143 int ok; 40 GNUNET_YES,
144 struct GNUNET_OS_Process *resolver; 41 "GNUNET_setup_transport_tcp_test_success_image",
145 42 "GNUNET_setup_transport_tcp_test_fail_image");
146 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tsk);
147 GNUNET_assert (NULL == tst);
148 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_tcp_test_success_image"));
149 gtk_widget_hide (w);
150 resolver = GNUNET_OS_start_process (NULL, NULL,
151 "gnunet-service-resolver",
152 "gnunet-service-resolver", NULL);
153 ok = GNUNET_NO;
154 GNUNET_SCHEDULER_run (&test, &ok);
155 if (NULL != resolver)
156 {
157 GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
158 GNUNET_OS_process_close (resolver);
159 }
160 if (GNUNET_YES != ok)
161 {
162 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_tcp_test_fail_image"));
163 gtk_widget_show (w);
164 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_tcp_test_success_image"));
165 gtk_widget_hide (w);
166 }
167 else
168 {
169 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_tcp_test_fail_image"));
170 gtk_widget_hide (w);
171 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_tcp_test_success_image"));
172 gtk_widget_show (w);
173 }
174} 43}
175 44
176 45
diff --git a/src/setup/gnunet-setup-transport-test.c b/src/setup/gnunet-setup-transport-test.c
new file mode 100644
index 00000000..4bc9c26c
--- /dev/null
+++ b/src/setup/gnunet-setup-transport-test.c
@@ -0,0 +1,199 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010, 2011 Christian Grothoff (and other contributing authors)
4
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
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/setup/gnunet-setup-transport-test.c
23 * @brief support for testing transport configurations
24 * @author Christian Grothoff
25 */
26#include "gnunet-setup.h"
27#include <gnunet/gnunet_resolver_service.h>
28#include <gnunet/gnunet_nat_lib.h>
29
30/**
31 * How long do we wait for the NAT test to report success?
32 */
33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
34
35
36struct TestContext
37{
38
39 /**
40 * Handle to the active NAT test.
41 */
42 struct GNUNET_NAT_Test *tst;
43
44 /**
45 * Task identifier for the timeout.
46 */
47 GNUNET_SCHEDULER_TaskIdentifier tsk;
48
49 /**
50 * Name of widget to show on success.
51 */
52 const char *success_image;
53
54 /**
55 * Name of widget to show on failure.
56 */
57 const char *failure_image;
58
59};
60
61
62/**
63 * Display the result of the test.
64 *
65 * @param tc test context
66 * @param result GNUNET_YES on success
67 */
68static void
69display_test_result (struct TestContext *tc,
70 int result)
71{
72 GObject *w;
73
74 if (GNUNET_YES != result)
75 {
76 w = GNUNET_SETUP_get_object (tc->failure_image);
77 if (NULL != w)
78 gtk_widget_show (GTK_WIDGET (w));
79 w = GNUNET_SETUP_get_object (tc->success_image);
80 if (NULL != w)
81 gtk_widget_hide (GTK_WIDGET (w));
82 }
83 else
84 {
85 w = GNUNET_SETUP_get_object (tc->failure_image);
86 if (NULL != w)
87 gtk_widget_hide (GTK_WIDGET (w));
88 w = GNUNET_SETUP_get_object (tc->success_image);
89 if (NULL != w)
90 gtk_widget_show (GTK_WIDGET (w));
91 }
92 if (GNUNET_SCHEDULER_NO_TASK != tc->tsk)
93 {
94 GNUNET_SCHEDULER_cancel (tc->tsk);
95 tc->tsk = GNUNET_SCHEDULER_NO_TASK;
96 }
97 if (NULL != tc->tst)
98 {
99 GNUNET_NAT_test_stop (tc->tst);
100 tc->tst = NULL;
101 }
102 GNUNET_free (tc);
103}
104
105
106/**
107 * Function called by NAT on success.
108 * Clean up and update GUI (with success).
109 *
110 * @param cls test context
111 * @param success currently always GNUNET_OK
112 */
113static void
114result_callback (void *cls,
115 int success)
116{
117 struct TestContext *tc = cls;
118
119 display_test_result (tc, success);
120}
121
122
123/**
124 * Function called if NAT failed to confirm success.
125 * Clean up and update GUI (with failure).
126 *
127 * @param cls test context
128 * @param tc scheduler callback
129 */
130static void
131fail_timeout (void *cls,
132 const struct GNUNET_SCHEDULER_TaskContext *tc)
133{
134 struct TestContext *tstc = cls;
135
136 tstc->tsk = GNUNET_SCHEDULER_NO_TASK;
137 display_test_result (tstc, GNUNET_NO);
138}
139
140
141/**
142 * Function called whenever the user wants to test a
143 * transport configuration.
144 *
145 * @param section_name section with the port numbers
146 * @param is_tcp GNUNET_YES for TCP, GNUNET_NO for UDP
147 * @param success_image image to show on success
148 * @param failure_image image to show on failure
149 */
150void
151GNUNET_setup_transport_test (const char *section_name,
152 int is_tcp,
153 const char *success_image,
154 const char *failure_image)
155{
156 struct TestContext *tc;
157 unsigned long long bnd_port;
158 unsigned long long adv_port;
159 GtkWidget *w;
160
161 if (GNUNET_OK !=
162 GNUNET_CONFIGURATION_get_value_number (cfg,
163 section_name,
164 "PORT",
165 &bnd_port))
166 {
167 GNUNET_break (0);
168 return;
169 }
170 if (GNUNET_OK !=
171 GNUNET_CONFIGURATION_get_value_number (cfg,
172 section_name,
173 "ADVERTISED_PORT",
174 &adv_port))
175 adv_port = bnd_port;
176 tc = GNUNET_malloc (sizeof (struct TestContext));
177 tc->success_image = success_image;
178 tc->failure_image = failure_image;
179 w = GTK_WIDGET (GNUNET_SETUP_get_object (success_image));
180 gtk_widget_hide (w);
181 GNUNET_assert (NULL != cfg);
182 GNUNET_RESOLVER_connect (cfg);
183 tc->tst = GNUNET_NAT_test_start (cfg,
184 is_tcp,
185 (uint16_t) bnd_port,
186 (uint16_t) adv_port,
187 &result_callback,
188 tc);
189 if (NULL == tc->tst)
190 {
191 display_test_result (tc, GNUNET_SYSERR);
192 return;
193 }
194 tc->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
195 &fail_timeout,
196 tc);
197}
198
199/* end of gnunet-setup-transport-test.c */
diff --git a/src/setup/gnunet-setup-transport-test.h b/src/setup/gnunet-setup-transport-test.h
new file mode 100644
index 00000000..2867a612
--- /dev/null
+++ b/src/setup/gnunet-setup-transport-test.h
@@ -0,0 +1,44 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010, 2011 Christian Grothoff (and other contributing authors)
4
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
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/setup/gnunet-setup-transport-test.c
23 * @brief support for testing transport configurations
24 * @author Christian Grothoff
25 */
26#ifndef GNUNET_SETUP_TRANSPORT_TEST_H
27#define GNUNET_SETUP_TRANSPORT_TEST_H
28
29/**
30 * Function called whenever the user wants to test a
31 * transport configuration.
32 *
33 * @param section_name section with the port numbers
34 * @param is_tcp GNUNET_YES for TCP, GNUNET_NO for UDP
35 * @param success_image image to show on success
36 * @param failure_image image to show on failure
37 */
38void
39GNUNET_setup_transport_test (const char *section_name,
40 int is_tcp,
41 const char *success_image,
42 const char *failure_image);
43
44#endif
diff --git a/src/setup/gnunet-setup-transport-udp.c b/src/setup/gnunet-setup-transport-udp.c
index 989b5bf3..f758f8d0 100644
--- a/src/setup/gnunet-setup-transport-udp.c
+++ b/src/setup/gnunet-setup-transport-udp.c
@@ -19,157 +19,29 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file src/gnunet-setup-transport-udp.c 22 * @file src/setup/gnunet-setup-transport-udp.c
23 * @brief support for UDP configuration 23 * @brief support for UDP configuration
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "gnunet-setup.h" 26#include "gnunet-setup.h"
27#include <gnunet/gnunet_resolver_service.h> 27#include <gnunet/gnunet_resolver_service.h>
28#include <gnunet/gnunet_nat_lib.h> 28#include <gnunet/gnunet_nat_lib.h>
29 29#include "gnunet-setup-transport-test.h"
30/**
31 * How long do we wait for the NAT test to report success?
32 */
33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
34
35/**
36 * Handle to the active NAT test.
37 */
38static struct GNUNET_NAT_Test *tst;
39
40/**
41 * Task identifier for the timeout.
42 */
43static GNUNET_SCHEDULER_TaskIdentifier tsk;
44
45
46/**
47 * Function called by NAT on success.
48 * Clean up and update GUI (with success).
49 *
50 * @param cls closure (unused)
51 * @param success currently always GNUNET_OK
52 */
53static void
54result_callback (void *cls,
55 int success)
56{
57 int *ok = cls;
58
59 *ok = success;
60 GNUNET_SCHEDULER_cancel (tsk);
61 tsk = GNUNET_SCHEDULER_NO_TASK;
62 GNUNET_NAT_test_stop (tst);
63 tst = NULL;
64}
65 30
66 31
67/** 32/**
68 * Function called if NAT failed to confirm success.
69 * Clean up and update GUI (with failure).
70 *
71 * @param cls closure (unused)
72 * @param tc scheduler callback
73 */
74static void
75fail_timeout (void *cls,
76 const struct GNUNET_SCHEDULER_TaskContext *tc)
77{
78 int *ok = cls;
79
80 *ok = GNUNET_NO;
81 tsk = GNUNET_SCHEDULER_NO_TASK;
82 GNUNET_NAT_test_stop (tst);
83 tst = NULL;
84}
85
86
87/**
88 * Main function for the NAT test.
89 *
90 * @param cls the 'int*' for the result
91 * @param tc scheduler context
92 */
93static void
94test (void *cls,
95 const struct GNUNET_SCHEDULER_TaskContext *tc)
96{
97 int *ok = cls;
98 unsigned long long bnd_port;
99 unsigned long long adv_port;
100
101 GNUNET_assert (NULL != cfg);
102 GNUNET_RESOLVER_connect (cfg);
103 if (GNUNET_OK !=
104 GNUNET_CONFIGURATION_get_value_number (cfg,
105 "transport-udp",
106 "PORT",
107 &bnd_port))
108 {
109 GNUNET_break (0);
110 return;
111 }
112 if (GNUNET_OK !=
113 GNUNET_CONFIGURATION_get_value_number (cfg,
114 "transport-udp",
115 "ADVERTISED_PORT",
116 &adv_port))
117 adv_port = bnd_port;
118 tst = GNUNET_NAT_test_start (cfg,
119 GNUNET_NO,
120 (uint16_t) bnd_port,
121 (uint16_t) adv_port,
122 &result_callback,
123 ok);
124 if (NULL == tst)
125 {
126 *ok = GNUNET_SYSERR;
127 return;
128 }
129 tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
130 &fail_timeout,
131 ok);
132}
133
134/**
135 * Function called whenever the user wants to test the 33 * Function called whenever the user wants to test the
136 * UDP configuration. 34 * UDP configuration.
137 */ 35 */
138void 36void
139GNUNET_setup_transport_udp_test_button_clicked_cb () 37GNUNET_setup_transport_udp_test_button_clicked_cb ()
140{ 38{
141 GtkWidget *w;
142 int ok;
143 struct GNUNET_OS_Process *resolver;
144 39
145 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tsk); 40 GNUNET_setup_transport_test ("transport-udp",
146 GNUNET_assert (NULL == tst); 41 GNUNET_NO,
147 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_udp_test_success_image")); 42 "GNUNET_setup_transport_udp_test_success_image",
148 gtk_widget_hide (w); 43 "GNUNET_setup_transport_udp_test_fail_image");
149 resolver = GNUNET_OS_start_process (NULL, NULL, 44
150 "gnunet-service-resolver",
151 "gnunet-service-resolver", NULL);
152 ok = GNUNET_NO;
153 GNUNET_SCHEDULER_run (&test, &ok);
154 if (NULL != resolver)
155 {
156 GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
157 GNUNET_OS_process_close (resolver);
158 }
159 if (GNUNET_YES != ok)
160 {
161 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_udp_test_fail_image"));
162 gtk_widget_show (w);
163 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_udp_test_success_image"));
164 gtk_widget_hide (w);
165 }
166 else
167 {
168 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_udp_test_fail_image"));
169 gtk_widget_hide (w);
170 w = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_udp_test_success_image"));
171 gtk_widget_show (w);
172 }
173} 45}
174 46
175 47
diff --git a/src/setup/gnunet-setup-transport.c b/src/setup/gnunet-setup-transport.c
index 85792964..a88a7d65 100644
--- a/src/setup/gnunet-setup-transport.c
+++ b/src/setup/gnunet-setup-transport.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file src/gnunet-setup-transport.c 22 * @file src/setup/gnunet-setup-transport.c
23 * @brief support for transport (NAT) configuration 23 * @brief support for transport (NAT) configuration
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
@@ -67,7 +67,6 @@ update_icmp_server_enable_button (int on)
67} 67}
68 68
69 69
70
71/** 70/**
72 * Function called by NAT on success. 71 * Function called by NAT on success.
73 * Clean up and update GUI (with success). 72 * Clean up and update GUI (with success).
@@ -146,6 +145,8 @@ reversal_test (void *cls,
146static void 145static void
147test_connection_reversal () 146test_connection_reversal ()
148{ 147{
148 if (NULL != resolver)
149 return; /* test already active!? */
149 resolver = GNUNET_OS_start_process (NULL, NULL, 150 resolver = GNUNET_OS_start_process (NULL, NULL,
150 "gnunet-service-resolver", 151 "gnunet-service-resolver",
151 "gnunet-service-resolver", NULL); 152 "gnunet-service-resolver", NULL);
@@ -271,8 +272,6 @@ GNUNET_setup_transport_autoconfig_button_clicked_cb ()
271 if (hns) 272 if (hns)
272 test_connection_reversal (); 273 test_connection_reversal ();
273 274
274
275
276 /* test gnunet-helper-nat-client */ 275 /* test gnunet-helper-nat-client */
277 tmp = NULL; 276 tmp = NULL;
278 hnc = ( (GNUNET_OK == 277 hnc = ( (GNUNET_OK ==
diff --git a/src/setup/gnunet-setup.c b/src/setup/gnunet-setup.c
index 136eff23..6844a076 100644
--- a/src/setup/gnunet-setup.c
+++ b/src/setup/gnunet-setup.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file src/gnunet-setup.c 22 * @file src/setup/gnunet-setup.c
23 * @brief Main function of gnunet-setup 23 * @brief Main function of gnunet-setup
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
@@ -56,6 +56,12 @@ struct GNUNET_CONFIGURATION_Handle *cfg;
56static int gret; 56static int gret;
57 57
58/** 58/**
59 * Resolver process handle.
60 */
61struct GNUNET_OS_Process *resolver;
62
63
64/**
59 * Get an object from the main window. 65 * Get an object from the main window.
60 * 66 *
61 * @param name name of the object 67 * @param name name of the object
@@ -64,6 +70,8 @@ static int gret;
64GObject * 70GObject *
65GNUNET_SETUP_get_object (const char *name) 71GNUNET_SETUP_get_object (const char *name)
66{ 72{
73 if (NULL == ml)
74 return NULL;
67 return GNUNET_GTK_main_loop_get_object (ml, name); 75 return GNUNET_GTK_main_loop_get_object (ml, name);
68} 76}
69 77
@@ -305,6 +313,13 @@ GNUNET_SETUP_quit_cb (GtkObject *object,
305 gret = 1; 313 gret = 1;
306 GNUNET_CONFIGURATION_destroy (cfgDefault); 314 GNUNET_CONFIGURATION_destroy (cfgDefault);
307 GNUNET_CONFIGURATION_destroy (cfg); 315 GNUNET_CONFIGURATION_destroy (cfg);
316 cfg = NULL;
317 if (NULL != resolver)
318 {
319 GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
320 GNUNET_OS_process_close (resolver);
321 resolver = NULL;
322 }
308} 323}
309 324
310 325
@@ -324,7 +339,9 @@ run (void *cls,
324 cfg = GNUNET_CONFIGURATION_create (); 339 cfg = GNUNET_CONFIGURATION_create ();
325 (void) GNUNET_CONFIGURATION_load (cfg, cfgName); 340 (void) GNUNET_CONFIGURATION_load (cfg, cfgName);
326 main_window = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_dialog")); 341 main_window = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_dialog"));
327 342 resolver = GNUNET_OS_start_process (NULL, NULL,
343 "gnunet-service-resolver",
344 "gnunet-service-resolver", NULL);
328 load_options (); 345 load_options ();
329 gtk_widget_show (main_window); 346 gtk_widget_show (main_window);
330 gtk_window_present (GTK_WINDOW (main_window)); 347 gtk_window_present (GTK_WINDOW (main_window));