aboutsummaryrefslogtreecommitdiff
path: root/src/setup/gnunet-setup-transport-udp.c
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 /src/setup/gnunet-setup-transport-udp.c
parentc6cad778edf8963396850f6dedbb0a4c80a3af47 (diff)
downloadgnunet-gtk-3d9fda8a1eb0c21c58440d64f5e934d818a40eaf.tar.gz
gnunet-gtk-3d9fda8a1eb0c21c58440d64f5e934d818a40eaf.zip
eliminate SCHEDULER_run, simplify code
Diffstat (limited to 'src/setup/gnunet-setup-transport-udp.c')
-rw-r--r--src/setup/gnunet-setup-transport-udp.c142
1 files changed, 7 insertions, 135 deletions
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