diff options
-rwxr-xr-x | src/gns/test_gns_proxy | 228 | ||||
-rw-r--r-- | src/gns/test_gns_proxy.c | 447 | ||||
-rw-r--r-- | src/gns/test_gns_proxy.conf | 27 |
3 files changed, 474 insertions, 228 deletions
diff --git a/src/gns/test_gns_proxy b/src/gns/test_gns_proxy deleted file mode 100755 index 45ee8ff8b..000000000 --- a/src/gns/test_gns_proxy +++ /dev/null | |||
@@ -1,228 +0,0 @@ | |||
1 | #! /bin/sh | ||
2 | |||
3 | # test_gns_proxy - temporary wrapper script for .libs/test_gns_proxy | ||
4 | # Generated by libtool (GNU libtool) 2.4.2 | ||
5 | # | ||
6 | # The test_gns_proxy program cannot be directly executed until all the libtool | ||
7 | # libraries that it depends on are installed. | ||
8 | # | ||
9 | # This wrapper script should never be moved out of the build directory. | ||
10 | # If it is, it will not operate correctly. | ||
11 | |||
12 | # Sed substitution that helps us do robust quoting. It backslashifies | ||
13 | # metacharacters that are still active within double-quoted strings. | ||
14 | sed_quote_subst='s/\([`"$\\]\)/\\\1/g' | ||
15 | |||
16 | # Be Bourne compatible | ||
17 | if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then | ||
18 | emulate sh | ||
19 | NULLCMD=: | ||
20 | # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which | ||
21 | # is contrary to our usage. Disable this feature. | ||
22 | alias -g '${1+"$@"}'='"$@"' | ||
23 | setopt NO_GLOB_SUBST | ||
24 | else | ||
25 | case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac | ||
26 | fi | ||
27 | BIN_SH=xpg4; export BIN_SH # for Tru64 | ||
28 | DUALCASE=1; export DUALCASE # for MKS sh | ||
29 | |||
30 | # The HP-UX ksh and POSIX shell print the target directory to stdout | ||
31 | # if CDPATH is set. | ||
32 | (unset CDPATH) >/dev/null 2>&1 && unset CDPATH | ||
33 | |||
34 | relink_command="(cd /home/schanzen/Documents/thesis/gnunet/src/gns; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/home/schanzen/bin:/home/schanzen/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/schanzen/Documents/thesis/gnunet-install/bin:/home/schanzen/bin:/home/schanzen/Documents/thesis/gnunet-install/bin; export PATH; gcc -fno-strict-aliasing -Wall -g -O2 -o \$progdir/\$file test_gns_proxy.o -L/home/schanzen/Documents/thesis/gnunet-install/lib /home/schanzen/Documents/thesis/gnunet-install/lib/libmicrohttpd.so -lpthread /home/schanzen/Documents/thesis/gnunet-install/lib/libcurl.so -lrt -lgnutls ../../src/util/.libs/libgnunetutil.so ../../src/namestore/.libs/libgnunetnamestore.so ../../src/gns/.libs/libgnunetgns.so /home/schanzen/Documents/thesis/gnunet/src/namestore/.libs/libgnunetnamestore.so /home/schanzen/Documents/thesis/gnunet/src/statistics/.libs/libgnunetstatistics.so ../../src/testing/.libs/libgnunettesting.so /home/schanzen/Documents/thesis/gnunet/src/util/.libs/libgnunetutil.so -lgcrypt -lgpg-error -lltdl -lz -lunistring -lm -ldl -Wl,-rpath -Wl,/home/schanzen/Documents/thesis/gnunet-install/lib -Wl,-rpath -Wl,/home/schanzen/Documents/thesis/gnunet/src/util/.libs -Wl,-rpath -Wl,/home/schanzen/Documents/thesis/gnunet/src/namestore/.libs -Wl,-rpath -Wl,/home/schanzen/Documents/thesis/gnunet/src/gns/.libs -Wl,-rpath -Wl,/home/schanzen/Documents/thesis/gnunet/src/statistics/.libs -Wl,-rpath -Wl,/home/schanzen/Documents/thesis/gnunet/src/testing/.libs -Wl,-rpath -Wl,/home/schanzen/Documents/thesis/gnunet-install/lib)" | ||
35 | |||
36 | # This environment variable determines our operation mode. | ||
37 | if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then | ||
38 | # install mode needs the following variables: | ||
39 | generated_by_libtool_version='2.4.2' | ||
40 | notinst_deplibs=' ../../src/util/libgnunetutil.la ../../src/namestore/libgnunetnamestore.la ../../src/gns/libgnunetgns.la /home/schanzen/Documents/thesis/gnunet/src/namestore/libgnunetnamestore.la /home/schanzen/Documents/thesis/gnunet/src/statistics/libgnunetstatistics.la ../../src/testing/libgnunettesting.la /home/schanzen/Documents/thesis/gnunet/src/util/libgnunetutil.la' | ||
41 | else | ||
42 | # When we are sourced in execute mode, $file and $ECHO are already set. | ||
43 | if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then | ||
44 | file="$0" | ||
45 | |||
46 | # A function that is used when there is no print builtin or printf. | ||
47 | func_fallback_echo () | ||
48 | { | ||
49 | eval 'cat <<_LTECHO_EOF | ||
50 | $1 | ||
51 | _LTECHO_EOF' | ||
52 | } | ||
53 | ECHO="printf %s\\n" | ||
54 | fi | ||
55 | |||
56 | # Very basic option parsing. These options are (a) specific to | ||
57 | # the libtool wrapper, (b) are identical between the wrapper | ||
58 | # /script/ and the wrapper /executable/ which is used only on | ||
59 | # windows platforms, and (c) all begin with the string --lt- | ||
60 | # (application programs are unlikely to have options which match | ||
61 | # this pattern). | ||
62 | # | ||
63 | # There are only two supported options: --lt-debug and | ||
64 | # --lt-dump-script. There is, deliberately, no --lt-help. | ||
65 | # | ||
66 | # The first argument to this parsing function should be the | ||
67 | # script's ../../libtool value, followed by no. | ||
68 | lt_option_debug= | ||
69 | func_parse_lt_options () | ||
70 | { | ||
71 | lt_script_arg0=$0 | ||
72 | shift | ||
73 | for lt_opt | ||
74 | do | ||
75 | case "$lt_opt" in | ||
76 | --lt-debug) lt_option_debug=1 ;; | ||
77 | --lt-dump-script) | ||
78 | lt_dump_D=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%/[^/]*$%%'` | ||
79 | test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=. | ||
80 | lt_dump_F=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%^.*/%%'` | ||
81 | cat "$lt_dump_D/$lt_dump_F" | ||
82 | exit 0 | ||
83 | ;; | ||
84 | --lt-*) | ||
85 | $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2 | ||
86 | exit 1 | ||
87 | ;; | ||
88 | esac | ||
89 | done | ||
90 | |||
91 | # Print the debug banner immediately: | ||
92 | if test -n "$lt_option_debug"; then | ||
93 | echo "test_gns_proxy:test_gns_proxy:${LINENO}: libtool wrapper (GNU libtool) 2.4.2" 1>&2 | ||
94 | fi | ||
95 | } | ||
96 | |||
97 | # Used when --lt-debug. Prints its arguments to stdout | ||
98 | # (redirection is the responsibility of the caller) | ||
99 | func_lt_dump_args () | ||
100 | { | ||
101 | lt_dump_args_N=1; | ||
102 | for lt_arg | ||
103 | do | ||
104 | $ECHO "test_gns_proxy:test_gns_proxy:${LINENO}: newargv[$lt_dump_args_N]: $lt_arg" | ||
105 | lt_dump_args_N=`expr $lt_dump_args_N + 1` | ||
106 | done | ||
107 | } | ||
108 | |||
109 | # Core function for launching the target application | ||
110 | func_exec_program_core () | ||
111 | { | ||
112 | |||
113 | if test -n "$lt_option_debug"; then | ||
114 | $ECHO "test_gns_proxy:test_gns_proxy:${LINENO}: newargv[0]: $progdir/$program" 1>&2 | ||
115 | func_lt_dump_args ${1+"$@"} 1>&2 | ||
116 | fi | ||
117 | exec "$progdir/$program" ${1+"$@"} | ||
118 | |||
119 | $ECHO "$0: cannot exec $program $*" 1>&2 | ||
120 | exit 1 | ||
121 | } | ||
122 | |||
123 | # A function to encapsulate launching the target application | ||
124 | # Strips options in the --lt-* namespace from $@ and | ||
125 | # launches target application with the remaining arguments. | ||
126 | func_exec_program () | ||
127 | { | ||
128 | case " $* " in | ||
129 | *\ --lt-*) | ||
130 | for lt_wr_arg | ||
131 | do | ||
132 | case $lt_wr_arg in | ||
133 | --lt-*) ;; | ||
134 | *) set x "$@" "$lt_wr_arg"; shift;; | ||
135 | esac | ||
136 | shift | ||
137 | done ;; | ||
138 | esac | ||
139 | func_exec_program_core ${1+"$@"} | ||
140 | } | ||
141 | |||
142 | # Parse options | ||
143 | func_parse_lt_options "$0" ${1+"$@"} | ||
144 | |||
145 | # Find the directory that this script lives in. | ||
146 | thisdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` | ||
147 | test "x$thisdir" = "x$file" && thisdir=. | ||
148 | |||
149 | # Follow symbolic links until we get to the real thisdir. | ||
150 | file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'` | ||
151 | while test -n "$file"; do | ||
152 | destdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` | ||
153 | |||
154 | # If there was a directory component, then change thisdir. | ||
155 | if test "x$destdir" != "x$file"; then | ||
156 | case "$destdir" in | ||
157 | [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; | ||
158 | *) thisdir="$thisdir/$destdir" ;; | ||
159 | esac | ||
160 | fi | ||
161 | |||
162 | file=`$ECHO "$file" | /bin/sed 's%^.*/%%'` | ||
163 | file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'` | ||
164 | done | ||
165 | |||
166 | # Usually 'no', except on cygwin/mingw when embedded into | ||
167 | # the cwrapper. | ||
168 | WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no | ||
169 | if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then | ||
170 | # special case for '.' | ||
171 | if test "$thisdir" = "."; then | ||
172 | thisdir=`pwd` | ||
173 | fi | ||
174 | # remove .libs from thisdir | ||
175 | case "$thisdir" in | ||
176 | *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /bin/sed 's%[\\/][^\\/]*$%%'` ;; | ||
177 | .libs ) thisdir=. ;; | ||
178 | esac | ||
179 | fi | ||
180 | |||
181 | # Try to get the absolute directory name. | ||
182 | absdir=`cd "$thisdir" && pwd` | ||
183 | test -n "$absdir" && thisdir="$absdir" | ||
184 | |||
185 | program=lt-'test_gns_proxy' | ||
186 | progdir="$thisdir/.libs" | ||
187 | |||
188 | if test ! -f "$progdir/$program" || | ||
189 | { file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /bin/sed 1q`; \ | ||
190 | test "X$file" != "X$progdir/$program"; }; then | ||
191 | |||
192 | file="$$-$program" | ||
193 | |||
194 | if test ! -d "$progdir"; then | ||
195 | mkdir "$progdir" | ||
196 | else | ||
197 | rm -f "$progdir/$file" | ||
198 | fi | ||
199 | |||
200 | # relink executable if necessary | ||
201 | if test -n "$relink_command"; then | ||
202 | if relink_command_output=`eval $relink_command 2>&1`; then : | ||
203 | else | ||
204 | printf %s\n "$relink_command_output" >&2 | ||
205 | rm -f "$progdir/$file" | ||
206 | exit 1 | ||
207 | fi | ||
208 | fi | ||
209 | |||
210 | mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null || | ||
211 | { rm -f "$progdir/$program"; | ||
212 | mv -f "$progdir/$file" "$progdir/$program"; } | ||
213 | rm -f "$progdir/$file" | ||
214 | fi | ||
215 | |||
216 | if test -f "$progdir/$program"; then | ||
217 | if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then | ||
218 | # Run the actual program with our arguments. | ||
219 | func_exec_program ${1+"$@"} | ||
220 | fi | ||
221 | else | ||
222 | # The program doesn't exist. | ||
223 | $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 | ||
224 | $ECHO "This script is just a wrapper for $program." 1>&2 | ||
225 | $ECHO "See the libtool documentation for more information." 1>&2 | ||
226 | exit 1 | ||
227 | fi | ||
228 | fi | ||
diff --git a/src/gns/test_gns_proxy.c b/src/gns/test_gns_proxy.c new file mode 100644 index 000000000..916ea7392 --- /dev/null +++ b/src/gns/test_gns_proxy.c | |||
@@ -0,0 +1,447 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2007, 2009, 2011, 2012 Christian Grothoff | ||
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 test_gns_proxy.c | ||
23 | * @brief testcase for accessing SOCKS5 GNS proxy | ||
24 | * @author Martin Schanzenbach | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include <curl/curl.h> | ||
28 | #include <microhttpd.h> | ||
29 | #include "gnunet_namestore_service.h" | ||
30 | #include "gnunet_gns_service.h" | ||
31 | #include "gnunet_testing_lib-new.h" | ||
32 | #include "gnunet_os_lib.h" | ||
33 | |||
34 | #define PORT 8080 | ||
35 | #define TEST_DOMAIN "www.gnunet" | ||
36 | |||
37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) | ||
38 | |||
39 | /** | ||
40 | * Return value for 'main'. | ||
41 | */ | ||
42 | static int global_ret; | ||
43 | |||
44 | static struct GNUNET_NAMESTORE_Handle *namestore; | ||
45 | |||
46 | static struct MHD_Daemon *mhd; | ||
47 | |||
48 | static GNUNET_SCHEDULER_TaskIdentifier mhd_task_id; | ||
49 | |||
50 | static GNUNET_SCHEDULER_TaskIdentifier curl_task_id; | ||
51 | |||
52 | static CURL *curl; | ||
53 | |||
54 | static CURLM *multi; | ||
55 | |||
56 | static char *url; | ||
57 | |||
58 | static struct GNUNET_OS_Process *proxy_proc; | ||
59 | |||
60 | static char* tmp_cfgfile; | ||
61 | |||
62 | struct CBC | ||
63 | { | ||
64 | char buf[1024]; | ||
65 | size_t pos; | ||
66 | }; | ||
67 | |||
68 | static struct CBC cbc; | ||
69 | |||
70 | |||
71 | static size_t | ||
72 | copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) | ||
73 | { | ||
74 | struct CBC *cbc = ctx; | ||
75 | |||
76 | if (cbc->pos + size * nmemb > sizeof(cbc->buf)) | ||
77 | return 0; /* overflow */ | ||
78 | memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb); | ||
79 | cbc->pos += size * nmemb; | ||
80 | return size * nmemb; | ||
81 | } | ||
82 | |||
83 | |||
84 | static int | ||
85 | mhd_ahc (void *cls, | ||
86 | struct MHD_Connection *connection, | ||
87 | const char *url, | ||
88 | const char *method, | ||
89 | const char *version, | ||
90 | const char *upload_data, size_t *upload_data_size, | ||
91 | void **unused) | ||
92 | { | ||
93 | static int ptr; | ||
94 | struct MHD_Response *response; | ||
95 | int ret; | ||
96 | |||
97 | if (0 != strcmp ("GET", method)) | ||
98 | return MHD_NO; /* unexpected method */ | ||
99 | if (&ptr != *unused) | ||
100 | { | ||
101 | *unused = &ptr; | ||
102 | return MHD_YES; | ||
103 | } | ||
104 | *unused = NULL; | ||
105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to URL `%s'\n", url); | ||
106 | response = MHD_create_response_from_buffer (strlen (url), | ||
107 | (void *) url, | ||
108 | MHD_RESPMEM_MUST_COPY); | ||
109 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | ||
110 | MHD_destroy_response (response); | ||
111 | if (ret == MHD_NO) | ||
112 | abort (); | ||
113 | return ret; | ||
114 | } | ||
115 | |||
116 | |||
117 | static void | ||
118 | do_shutdown () | ||
119 | { | ||
120 | if (mhd_task_id != GNUNET_SCHEDULER_NO_TASK) | ||
121 | { | ||
122 | GNUNET_SCHEDULER_cancel (mhd_task_id); | ||
123 | mhd_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
124 | } | ||
125 | if (curl_task_id != GNUNET_SCHEDULER_NO_TASK) | ||
126 | { | ||
127 | GNUNET_SCHEDULER_cancel (curl_task_id); | ||
128 | curl_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
129 | } | ||
130 | if (NULL != mhd) | ||
131 | { | ||
132 | MHD_stop_daemon (mhd); | ||
133 | mhd = NULL; | ||
134 | } | ||
135 | GNUNET_free_non_null (url); | ||
136 | |||
137 | if (NULL != tmp_cfgfile) | ||
138 | remove (tmp_cfgfile); | ||
139 | |||
140 | if (NULL != proxy_proc) | ||
141 | GNUNET_OS_process_kill (proxy_proc, 9); | ||
142 | url = NULL; | ||
143 | } | ||
144 | |||
145 | |||
146 | /** | ||
147 | * Function to run the HTTP client. | ||
148 | */ | ||
149 | static void | ||
150 | curl_main (void); | ||
151 | |||
152 | |||
153 | static void | ||
154 | curl_task (void *cls, | ||
155 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
156 | { | ||
157 | curl_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
158 | curl_main (); | ||
159 | } | ||
160 | |||
161 | |||
162 | static void | ||
163 | curl_main () | ||
164 | { | ||
165 | fd_set rs; | ||
166 | fd_set ws; | ||
167 | fd_set es; | ||
168 | int max; | ||
169 | struct GNUNET_NETWORK_FDSet nrs; | ||
170 | struct GNUNET_NETWORK_FDSet nws; | ||
171 | struct GNUNET_TIME_Relative delay; | ||
172 | long timeout; | ||
173 | int running; | ||
174 | struct CURLMsg *msg; | ||
175 | |||
176 | max = 0; | ||
177 | FD_ZERO (&rs); | ||
178 | FD_ZERO (&ws); | ||
179 | FD_ZERO (&es); | ||
180 | curl_multi_perform (multi, &running); | ||
181 | if (running == 0) | ||
182 | { | ||
183 | GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running))); | ||
184 | if (msg->msg == CURLMSG_DONE) | ||
185 | { | ||
186 | if (msg->data.result != CURLE_OK) | ||
187 | { | ||
188 | fprintf (stderr, | ||
189 | "%s failed at %s:%d: `%s'\n", | ||
190 | "curl_multi_perform", | ||
191 | __FILE__, | ||
192 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
193 | global_ret = 1; | ||
194 | } | ||
195 | } | ||
196 | curl_multi_remove_handle (multi, curl); | ||
197 | curl_multi_cleanup (multi); | ||
198 | curl_easy_cleanup (curl); | ||
199 | curl = NULL; | ||
200 | multi = NULL; | ||
201 | if (cbc.pos != strlen ("/hello_world")) | ||
202 | { | ||
203 | GNUNET_break (0); | ||
204 | global_ret = 2; | ||
205 | } | ||
206 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
207 | { | ||
208 | GNUNET_break (0); | ||
209 | global_ret = 3; | ||
210 | } | ||
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); | ||
212 | do_shutdown (); | ||
213 | return; | ||
214 | } | ||
215 | GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)); | ||
216 | if ( (CURLM_OK != curl_multi_timeout (multi, &timeout)) || | ||
217 | (-1 == timeout) ) | ||
218 | delay = GNUNET_TIME_UNIT_SECONDS; | ||
219 | else | ||
220 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int) timeout); | ||
221 | GNUNET_NETWORK_fdset_copy_native (&nrs, | ||
222 | &rs, | ||
223 | max + 1); | ||
224 | GNUNET_NETWORK_fdset_copy_native (&nws, | ||
225 | &ws, | ||
226 | max + 1); | ||
227 | curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
228 | delay, | ||
229 | &nrs, | ||
230 | &nws, | ||
231 | &curl_task, | ||
232 | NULL); | ||
233 | } | ||
234 | |||
235 | static void | ||
236 | start_curl (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
237 | { | ||
238 | GNUNET_asprintf (&url, | ||
239 | "http://%s:%d/hello_world", | ||
240 | TEST_DOMAIN, PORT); | ||
241 | curl = curl_easy_init (); | ||
242 | curl_easy_setopt (curl, CURLOPT_URL, url); | ||
243 | curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ©_buffer); | ||
244 | curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); | ||
245 | curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); | ||
246 | curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); | ||
247 | curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L); | ||
248 | curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); | ||
249 | curl_easy_setopt (curl, CURLOPT_PROXY, "socks5h://127.0.0.1:7777"); | ||
250 | |||
251 | multi = curl_multi_init (); | ||
252 | GNUNET_assert (multi != NULL); | ||
253 | GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); | ||
254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Beginning HTTP download from `%s'\n", url); | ||
255 | curl_main (); | ||
256 | } | ||
257 | |||
258 | static void | ||
259 | disco_ns (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
260 | { | ||
261 | GNUNET_NAMESTORE_disconnect (namestore); | ||
262 | } | ||
263 | |||
264 | /** | ||
265 | * Callback invoked from the namestore service once record is | ||
266 | * created. | ||
267 | * | ||
268 | * @param cls closure | ||
269 | * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error; | ||
270 | * will match 'result_af' from the request | ||
271 | * @param address IP address (struct in_addr or struct in_addr6, depending on 'af') | ||
272 | * that the VPN allocated for the redirection; | ||
273 | * traffic to this IP will now be redirected to the | ||
274 | * specified target peer; NULL on error | ||
275 | */ | ||
276 | static void | ||
277 | commence_testing (void *cls, int32_t success, const char *emsg) | ||
278 | { | ||
279 | GNUNET_SCHEDULER_add_now (&disco_ns, NULL); | ||
280 | |||
281 | if ((emsg != NULL) && (GNUNET_YES != success)) | ||
282 | { | ||
283 | fprintf (stderr, | ||
284 | "NS failed to create record %s\n", emsg); | ||
285 | GNUNET_SCHEDULER_shutdown (); | ||
286 | return; | ||
287 | } | ||
288 | |||
289 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), start_curl, NULL); | ||
290 | |||
291 | } | ||
292 | |||
293 | |||
294 | |||
295 | |||
296 | /** | ||
297 | * Function to keep the HTTP server running. | ||
298 | */ | ||
299 | static void | ||
300 | mhd_main (void); | ||
301 | |||
302 | |||
303 | static void | ||
304 | mhd_task (void *cls, | ||
305 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
306 | { | ||
307 | mhd_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
308 | MHD_run (mhd); | ||
309 | mhd_main (); | ||
310 | } | ||
311 | |||
312 | |||
313 | static void | ||
314 | mhd_main () | ||
315 | { | ||
316 | struct GNUNET_NETWORK_FDSet nrs; | ||
317 | struct GNUNET_NETWORK_FDSet nws; | ||
318 | fd_set rs; | ||
319 | fd_set ws; | ||
320 | fd_set es; | ||
321 | int max_fd; | ||
322 | unsigned MHD_LONG_LONG timeout; | ||
323 | struct GNUNET_TIME_Relative delay; | ||
324 | |||
325 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == mhd_task_id); | ||
326 | FD_ZERO (&rs); | ||
327 | FD_ZERO (&ws); | ||
328 | FD_ZERO (&es); | ||
329 | max_fd = -1; | ||
330 | GNUNET_assert (MHD_YES == | ||
331 | MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd)); | ||
332 | if (MHD_YES == MHD_get_timeout (mhd, &timeout)) | ||
333 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | ||
334 | (unsigned int) timeout); | ||
335 | else | ||
336 | delay = GNUNET_TIME_UNIT_FOREVER_REL; | ||
337 | GNUNET_NETWORK_fdset_copy_native (&nrs, | ||
338 | &rs, | ||
339 | max_fd + 1); | ||
340 | GNUNET_NETWORK_fdset_copy_native (&nws, | ||
341 | &ws, | ||
342 | max_fd + 1); | ||
343 | mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
344 | delay, | ||
345 | &nrs, | ||
346 | &nws, | ||
347 | &mhd_task, | ||
348 | NULL); | ||
349 | } | ||
350 | |||
351 | static void | ||
352 | run (void *cls, | ||
353 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
354 | struct GNUNET_TESTING_Peer *peer) | ||
355 | { | ||
356 | enum MHD_FLAG flags; | ||
357 | struct GNUNET_CRYPTO_RsaPrivateKey *host_key; | ||
358 | struct GNUNET_NAMESTORE_RecordData rd; | ||
359 | char *zone_keyfile; | ||
360 | |||
361 | namestore = GNUNET_NAMESTORE_connect (cfg); | ||
362 | GNUNET_assert (NULL != namestore); | ||
363 | flags = MHD_USE_DEBUG; | ||
364 | mhd = MHD_start_daemon (flags, | ||
365 | PORT, | ||
366 | NULL, NULL, | ||
367 | &mhd_ahc, NULL, | ||
368 | MHD_OPTION_END); | ||
369 | GNUNET_assert (NULL != mhd); | ||
370 | mhd_main (); | ||
371 | |||
372 | tmp_cfgfile = GNUNET_DISK_mktemp ("test_gns_proxy_tmp.conf"); | ||
373 | if (NULL == tmp_cfgfile) | ||
374 | { | ||
375 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
376 | "Failed to create tmp cfg!\n"); | ||
377 | do_shutdown (); | ||
378 | return; | ||
379 | } | ||
380 | |||
381 | if (GNUNET_OK != GNUNET_CONFIGURATION_write ((struct GNUNET_CONFIGURATION_Handle *)cfg, | ||
382 | tmp_cfgfile)) | ||
383 | { | ||
384 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
385 | "Failed to write tmp cfg\n"); | ||
386 | return; | ||
387 | } | ||
388 | |||
389 | proxy_proc = GNUNET_OS_start_process (GNUNET_NO, | ||
390 | GNUNET_OS_INHERIT_STD_ALL, | ||
391 | NULL, | ||
392 | NULL, | ||
393 | "gnunet-gns-proxy", | ||
394 | "gnunet-gns-proxy", | ||
395 | "-c", tmp_cfgfile, NULL); | ||
396 | |||
397 | GNUNET_assert (NULL != proxy_proc); | ||
398 | |||
399 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
400 | "ZONEKEY", | ||
401 | &zone_keyfile)) | ||
402 | { | ||
403 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); | ||
404 | return; | ||
405 | } | ||
406 | |||
407 | host_key = GNUNET_CRYPTO_rsa_key_create_from_file (zone_keyfile); | ||
408 | rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value; | ||
409 | GNUNET_assert (GNUNET_OK == GNUNET_NAMESTORE_string_to_value (GNUNET_GNS_RECORD_A, | ||
410 | "127.0.0.1", | ||
411 | (void**)&rd.data, | ||
412 | &rd.data_size)); | ||
413 | rd.record_type = GNUNET_GNS_RECORD_A; | ||
414 | |||
415 | GNUNET_NAMESTORE_record_create (namestore, | ||
416 | host_key, | ||
417 | "www", | ||
418 | &rd, | ||
419 | &commence_testing, | ||
420 | NULL); | ||
421 | |||
422 | GNUNET_free ((void**)rd.data); | ||
423 | GNUNET_free (zone_keyfile); | ||
424 | GNUNET_CRYPTO_rsa_key_free (host_key); | ||
425 | } | ||
426 | |||
427 | int | ||
428 | main (int argc, char *const *argv) | ||
429 | { | ||
430 | |||
431 | GNUNET_CRYPTO_setup_hostkey ("test_gns_proxy.conf"); | ||
432 | |||
433 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | ||
434 | { | ||
435 | fprintf (stderr, "failed to initialize curl\n"); | ||
436 | return 2; | ||
437 | } | ||
438 | if (0 != GNUNET_TESTING_peer_run ("test-gnunet-gns-proxy", | ||
439 | "test_gns_proxy.conf", | ||
440 | &run, NULL)) | ||
441 | return 1; | ||
442 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-gns-proxy"); | ||
443 | return global_ret; | ||
444 | } | ||
445 | |||
446 | /* end of test_gns_vpn.c */ | ||
447 | |||
diff --git a/src/gns/test_gns_proxy.conf b/src/gns/test_gns_proxy.conf new file mode 100644 index 000000000..9dd4a472b --- /dev/null +++ b/src/gns/test_gns_proxy.conf | |||
@@ -0,0 +1,27 @@ | |||
1 | [PATHS] | ||
2 | SERVICEHOME = /tmp/gnunet-test-gns-proxy/ | ||
3 | DEFAULTCONFIG = test_gns_proxy.conf | ||
4 | |||
5 | [transport] | ||
6 | PLUGINS = tcp | ||
7 | |||
8 | [arm] | ||
9 | DEFAULTSERVICES = statistics dns namestore gns | ||
10 | PORT = 0 | ||
11 | ALLOW_SHUTDOWN = YES | ||
12 | |||
13 | [testing] | ||
14 | WEAKRANDOM = YES | ||
15 | HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat | ||
16 | |||
17 | [gns] | ||
18 | AUTOSTART = YES | ||
19 | ZONEKEY = $SERVICEHOME/hostkey | ||
20 | HIJACK_DNS = YES | ||
21 | |||
22 | [gns-proxy] | ||
23 | PROXY_CACERT = proxy/test_cert.pem | ||
24 | PROXY_UNIXPATH = /tmp/gnunet-gns-proxy.sock | ||
25 | |||
26 | [namestore] | ||
27 | AUTOSTART = YES | ||