aboutsummaryrefslogtreecommitdiff
path: root/src/setup/gnunet-setup-transport-udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/setup/gnunet-setup-transport-udp.c')
-rw-r--r--src/setup/gnunet-setup-transport-udp.c181
1 files changed, 181 insertions, 0 deletions
diff --git a/src/setup/gnunet-setup-transport-udp.c b/src/setup/gnunet-setup-transport-udp.c
new file mode 100644
index 00000000..28aec749
--- /dev/null
+++ b/src/setup/gnunet-setup-transport-udp.c
@@ -0,0 +1,181 @@
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/gnunet-setup-transport-udp.c
23 * @brief support for UDP configuration
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/**
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
66
67/**
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
136 * UDP configuration.
137 */
138void
139GNUNET_setup_transport_udp_test_button_clicked_cb ()
140{
141 GtkWidget *w;
142 int ok;
143 struct GNUNET_OS_Process *resolver;
144
145 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tsk);
146 GNUNET_assert (NULL == tst);
147 w = GTK_WIDGET (gtk_builder_get_object (builder,
148 "GNUNET_setup_transport_udp_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 (gtk_builder_get_object (builder,
163 "GNUNET_setup_transport_udp_test_fail_image"));
164 gtk_widget_show (w);
165 w = GTK_WIDGET (gtk_builder_get_object (builder,
166 "GNUNET_setup_transport_udp_test_success_image"));
167 gtk_widget_hide (w);
168 }
169 else
170 {
171 w = GTK_WIDGET (gtk_builder_get_object (builder,
172 "GNUNET_setup_transport_udp_test_fail_image"));
173 gtk_widget_hide (w);
174 w = GTK_WIDGET (gtk_builder_get_object (builder,
175 "GNUNET_setup_transport_udp_test_success_image"));
176 gtk_widget_show (w);
177 }
178}
179
180
181/* end of gnunet-setup-transport-udp.c */