diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-16 19:12:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-16 19:12:42 +0000 |
commit | 4d93b2e4ef9f1cbb0118f67cc0391dd849cfed46 (patch) | |
tree | 5ce81ad3258811c90399d733ccbbfbe8b4c8cc20 /src | |
parent | 924c8ef21aadf46e7c3f6280e482d8c66a6216b1 (diff) | |
download | gnunet-4d93b2e4ef9f1cbb0118f67cc0391dd849cfed46.tar.gz gnunet-4d93b2e4ef9f1cbb0118f67cc0391dd849cfed46.zip |
-skeleton for new PT daemon
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/pt/Makefile.am | 29 | ||||
-rwxr-xr-x | src/pt/gnunet-daemon-pt | 148 | ||||
-rw-r--r-- | src/pt/gnunet-daemon-pt.c | 196 | ||||
-rw-r--r-- | src/pt/pt.conf | 10 |
5 files changed, 384 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 4e1c338aa..12862af38 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -33,5 +33,6 @@ SUBDIRS = \ | |||
33 | dns \ | 33 | dns \ |
34 | exit \ | 34 | exit \ |
35 | vpn \ | 35 | vpn \ |
36 | pt \ | ||
36 | integration-tests \ | 37 | integration-tests \ |
37 | $(EXP_DIR) | 38 | $(EXP_DIR) |
diff --git a/src/pt/Makefile.am b/src/pt/Makefile.am new file mode 100644 index 000000000..c43787133 --- /dev/null +++ b/src/pt/Makefile.am | |||
@@ -0,0 +1,29 @@ | |||
1 | INCLUDES = -I$(top_srcdir)/src/include | ||
2 | |||
3 | if MINGW | ||
4 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols | ||
5 | endif | ||
6 | |||
7 | if USE_COVERAGE | ||
8 | AM_CFLAGS = --coverage -O0 | ||
9 | endif | ||
10 | |||
11 | pkgcfgdir= $(pkgdatadir)/config.d/ | ||
12 | |||
13 | plugindir = $(libdir)/gnunet | ||
14 | |||
15 | dist_pkgcfg_DATA = \ | ||
16 | pt.conf | ||
17 | |||
18 | bin_PROGRAMS = \ | ||
19 | gnunet-daemon-pt $(PTBIN) | ||
20 | |||
21 | gnunet_daemon_pt_SOURCES = \ | ||
22 | gnunet-daemon-pt.c | ||
23 | gnunet_daemon_pt_LDADD = \ | ||
24 | $(top_builddir)/src/vpn/libgnunetvpn.la \ | ||
25 | $(top_builddir)/src/dns/libgnunetdns.la \ | ||
26 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
27 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
28 | $(top_builddir)/src/mesh/libgnunetmesh.la \ | ||
29 | $(GN_LIBINTL) | ||
diff --git a/src/pt/gnunet-daemon-pt b/src/pt/gnunet-daemon-pt new file mode 100755 index 000000000..d729865e3 --- /dev/null +++ b/src/pt/gnunet-daemon-pt | |||
@@ -0,0 +1,148 @@ | |||
1 | #! /bin/bash | ||
2 | |||
3 | # gnunet-daemon-pt - temporary wrapper script for .libs/gnunet-daemon-pt | ||
4 | # Generated by ltmain.sh (GNU libtool) 2.2.6b Debian-2.2.6b-2 | ||
5 | # | ||
6 | # The gnunet-daemon-pt 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 | Xsed='/bin/sed -e 1s/^X//' | ||
15 | sed_quote_subst='s/\([`"$\\]\)/\\\1/g' | ||
16 | |||
17 | # Be Bourne compatible | ||
18 | if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then | ||
19 | emulate sh | ||
20 | NULLCMD=: | ||
21 | # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which | ||
22 | # is contrary to our usage. Disable this feature. | ||
23 | alias -g '${1+"$@"}'='"$@"' | ||
24 | setopt NO_GLOB_SUBST | ||
25 | else | ||
26 | case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac | ||
27 | fi | ||
28 | BIN_SH=xpg4; export BIN_SH # for Tru64 | ||
29 | DUALCASE=1; export DUALCASE # for MKS sh | ||
30 | |||
31 | # The HP-UX ksh and POSIX shell print the target directory to stdout | ||
32 | # if CDPATH is set. | ||
33 | (unset CDPATH) >/dev/null 2>&1 && unset CDPATH | ||
34 | |||
35 | relink_command="(cd /home/grothoff/svn/gnunet/src/pt; { 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; }; }; LD_LIBRARY_PATH=/usr/lib/debug:/home/grothoff/lib; export LD_LIBRARY_PATH; PATH=/opt/jdk1.6.0_22/bin:/usr/lib/jvm/java-6-sun//bin:.:/home/grothoff/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games; export PATH; gcc -fno-strict-aliasing -Wall -g -Wall -Werror -O0 -I/home/grothoff//include -o \$progdir/\$file gnunet-daemon-pt.o -L/home/grothoff//lib ../../src/vpn/.libs/libgnunetvpn.so ../../src/dns/.libs/libgnunetdns.so ../../src/statistics/.libs/libgnunetstatistics.so ../../src/util/.libs/libgnunetutil.so ../../src/mesh/.libs/libgnunetmesh.so -ldl -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/vpn/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/dns/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/statistics/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/util/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/mesh/.libs -Wl,-rpath -Wl,/home/grothoff/lib)" | ||
36 | |||
37 | # This environment variable determines our operation mode. | ||
38 | if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then | ||
39 | # install mode needs the following variables: | ||
40 | generated_by_libtool_version='2.2.6b' | ||
41 | notinst_deplibs=' ../../src/vpn/libgnunetvpn.la ../../src/dns/libgnunetdns.la ../../src/statistics/libgnunetstatistics.la ../../src/util/libgnunetutil.la ../../src/mesh/libgnunetmesh.la' | ||
42 | else | ||
43 | # When we are sourced in execute mode, $file and $ECHO are already set. | ||
44 | if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then | ||
45 | ECHO="echo" | ||
46 | file="$0" | ||
47 | # Make sure echo works. | ||
48 | if test "X$1" = X--no-reexec; then | ||
49 | # Discard the --no-reexec flag, and continue. | ||
50 | shift | ||
51 | elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then | ||
52 | # Yippee, $ECHO works! | ||
53 | : | ||
54 | else | ||
55 | # Restart under the correct shell, and then maybe $ECHO will work. | ||
56 | exec /bin/bash "$0" --no-reexec ${1+"$@"} | ||
57 | fi | ||
58 | fi | ||
59 | |||
60 | # Find the directory that this script lives in. | ||
61 | thisdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` | ||
62 | test "x$thisdir" = "x$file" && thisdir=. | ||
63 | |||
64 | # Follow symbolic links until we get to the real thisdir. | ||
65 | file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'` | ||
66 | while test -n "$file"; do | ||
67 | destdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` | ||
68 | |||
69 | # If there was a directory component, then change thisdir. | ||
70 | if test "x$destdir" != "x$file"; then | ||
71 | case "$destdir" in | ||
72 | [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; | ||
73 | *) thisdir="$thisdir/$destdir" ;; | ||
74 | esac | ||
75 | fi | ||
76 | |||
77 | file=`$ECHO "X$file" | $Xsed -e 's%^.*/%%'` | ||
78 | file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'` | ||
79 | done | ||
80 | |||
81 | |||
82 | # Usually 'no', except on cygwin/mingw when embedded into | ||
83 | # the cwrapper. | ||
84 | WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no | ||
85 | if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then | ||
86 | # special case for '.' | ||
87 | if test "$thisdir" = "."; then | ||
88 | thisdir=`pwd` | ||
89 | fi | ||
90 | # remove .libs from thisdir | ||
91 | case "$thisdir" in | ||
92 | *[\\/].libs ) thisdir=`$ECHO "X$thisdir" | $Xsed -e 's%[\\/][^\\/]*$%%'` ;; | ||
93 | .libs ) thisdir=. ;; | ||
94 | esac | ||
95 | fi | ||
96 | |||
97 | # Try to get the absolute directory name. | ||
98 | absdir=`cd "$thisdir" && pwd` | ||
99 | test -n "$absdir" && thisdir="$absdir" | ||
100 | |||
101 | program=lt-'gnunet-daemon-pt' | ||
102 | progdir="$thisdir/.libs" | ||
103 | |||
104 | if test ! -f "$progdir/$program" || | ||
105 | { file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /bin/sed 1q`; \ | ||
106 | test "X$file" != "X$progdir/$program"; }; then | ||
107 | |||
108 | file="$$-$program" | ||
109 | |||
110 | if test ! -d "$progdir"; then | ||
111 | mkdir "$progdir" | ||
112 | else | ||
113 | rm -f "$progdir/$file" | ||
114 | fi | ||
115 | |||
116 | # relink executable if necessary | ||
117 | if test -n "$relink_command"; then | ||
118 | if relink_command_output=`eval $relink_command 2>&1`; then : | ||
119 | else | ||
120 | echo "$relink_command_output" >&2 | ||
121 | rm -f "$progdir/$file" | ||
122 | exit 1 | ||
123 | fi | ||
124 | fi | ||
125 | |||
126 | mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null || | ||
127 | { rm -f "$progdir/$program"; | ||
128 | mv -f "$progdir/$file" "$progdir/$program"; } | ||
129 | rm -f "$progdir/$file" | ||
130 | fi | ||
131 | |||
132 | if test -f "$progdir/$program"; then | ||
133 | if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then | ||
134 | # Run the actual program with our arguments. | ||
135 | |||
136 | exec "$progdir/$program" ${1+"$@"} | ||
137 | |||
138 | $ECHO "$0: cannot exec $program $*" 1>&2 | ||
139 | exit 1 | ||
140 | fi | ||
141 | else | ||
142 | # The program doesn't exist. | ||
143 | $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 | ||
144 | $ECHO "This script is just a wrapper for $program." 1>&2 | ||
145 | echo "See the libtool documentation for more information." 1>&2 | ||
146 | exit 1 | ||
147 | fi | ||
148 | fi | ||
diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c new file mode 100644 index 000000000..f8d83237a --- /dev/null +++ b/src/pt/gnunet-daemon-pt.c | |||
@@ -0,0 +1,196 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010, 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 3, 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 pt/gnunet-daemon-pt.c | ||
23 | * @brief tool to manipulate DNS and VPN services to perform protocol translation (IPvX over GNUnet) | ||
24 | * @author Christian Grothoff | ||
25 | * | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_dns_service.h" | ||
30 | #include "gnunet_vpn_service.h" | ||
31 | #include "gnunet_statistics_service.h" | ||
32 | |||
33 | |||
34 | /** | ||
35 | * The handle to the configuration used throughout the process | ||
36 | */ | ||
37 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
38 | |||
39 | /** | ||
40 | * The handle to the VPN | ||
41 | */ | ||
42 | static struct GNUNET_VPN_Handle *vpn_handle; | ||
43 | |||
44 | /** | ||
45 | * Statistics. | ||
46 | */ | ||
47 | static struct GNUNET_STATISTICS_Handle *stats; | ||
48 | |||
49 | /** | ||
50 | * The handle to DNS | ||
51 | */ | ||
52 | static struct GNUNET_DNS_Handle *dns_handle; | ||
53 | |||
54 | /** | ||
55 | * Are we doing IPv4-pt? | ||
56 | */ | ||
57 | static int ipv4_pt; | ||
58 | |||
59 | /** | ||
60 | * Are we doing IPv6-pt? | ||
61 | */ | ||
62 | static int ipv6_pt; | ||
63 | |||
64 | |||
65 | |||
66 | /** | ||
67 | * Signature of a function that is called whenever the DNS service | ||
68 | * encounters a DNS request and needs to do something with it. The | ||
69 | * function has then the chance to generate or modify the response by | ||
70 | * calling one of the three "GNUNET_DNS_request_*" continuations. | ||
71 | * | ||
72 | * When a request is intercepted, this function is called first to | ||
73 | * give the client a chance to do the complete address resolution; | ||
74 | * "rdata" will be NULL for this first call for a DNS request, unless | ||
75 | * some other client has already filled in a response. | ||
76 | * | ||
77 | * If multiple clients exist, all of them are called before the global | ||
78 | * DNS. The global DNS is only called if all of the clients' | ||
79 | * functions call GNUNET_DNS_request_forward. Functions that call | ||
80 | * GNUNET_DNS_request_forward will be called again before a final | ||
81 | * response is returned to the application. If any of the clients' | ||
82 | * functions call GNUNET_DNS_request_drop, the response is dropped. | ||
83 | * | ||
84 | * @param cls closure | ||
85 | * @param rh request handle to user for reply | ||
86 | * @param request_length number of bytes in request | ||
87 | * @param request udp payload of the DNS request | ||
88 | */ | ||
89 | static void | ||
90 | dns_request_handler (void *cls, | ||
91 | struct GNUNET_DNS_RequestHandle *rh, | ||
92 | size_t request_length, | ||
93 | const char *request) | ||
94 | { | ||
95 | } | ||
96 | |||
97 | |||
98 | /** | ||
99 | * Function scheduled as very last function, cleans up after us | ||
100 | */ | ||
101 | static void | ||
102 | cleanup (void *cls GNUNET_UNUSED, | ||
103 | const struct GNUNET_SCHEDULER_TaskContext *tskctx) | ||
104 | { | ||
105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
106 | "Pt service is shutting down now\n"); | ||
107 | if (vpn_handle != NULL) | ||
108 | { | ||
109 | GNUNET_VPN_disconnect (vpn_handle); | ||
110 | vpn_handle = NULL; | ||
111 | } | ||
112 | if (dns_handle != NULL) | ||
113 | { | ||
114 | GNUNET_DNS_disconnect (dns_handle); | ||
115 | dns_handle = NULL; | ||
116 | } | ||
117 | if (stats != NULL) | ||
118 | { | ||
119 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); | ||
120 | stats = NULL; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | |||
125 | /** | ||
126 | * @brief Main function that will be run by the scheduler. | ||
127 | * | ||
128 | * @param cls closure | ||
129 | * @param args remaining command-line arguments | ||
130 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
131 | * @param cfg_ configuration | ||
132 | */ | ||
133 | static void | ||
134 | run (void *cls, char *const *args GNUNET_UNUSED, | ||
135 | const char *cfgfile GNUNET_UNUSED, | ||
136 | const struct GNUNET_CONFIGURATION_Handle *cfg_) | ||
137 | { | ||
138 | cfg = cfg_; | ||
139 | stats = GNUNET_STATISTICS_create ("pt", cfg); | ||
140 | ipv4_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, "pt", "TUNNEL_IPV4"); | ||
141 | ipv6_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, "pt", "TUNNEL_IPV6"); | ||
142 | if (! (ipv4_pt || ipv6_pt)) | ||
143 | { | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
145 | _("No useful service enabled. Exiting.\n")); | ||
146 | GNUNET_SCHEDULER_shutdown (); | ||
147 | return; | ||
148 | } | ||
149 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); | ||
150 | dns_handle | ||
151 | = GNUNET_DNS_connect (cfg, | ||
152 | GNUNET_DNS_FLAG_POST_RESOLUTION, | ||
153 | &dns_request_handler, NULL); | ||
154 | if (NULL == dns_handle) | ||
155 | { | ||
156 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
157 | _("Failed to connect to %s service. Exiting.\n"), | ||
158 | "DNS"); | ||
159 | GNUNET_SCHEDULER_shutdown (); | ||
160 | return; | ||
161 | } | ||
162 | vpn_handle = GNUNET_VPN_connect (cfg); | ||
163 | if (NULL == vpn_handle) | ||
164 | { | ||
165 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
166 | _("Failed to connect to %s service. Exiting.\n"), | ||
167 | "VPN"); | ||
168 | GNUNET_SCHEDULER_shutdown (); | ||
169 | return; | ||
170 | } | ||
171 | } | ||
172 | |||
173 | |||
174 | /** | ||
175 | * The main function | ||
176 | * | ||
177 | * @param argc number of arguments from the command line | ||
178 | * @param argv command line arguments | ||
179 | * @return 0 ok, 1 on error | ||
180 | */ | ||
181 | int | ||
182 | main (int argc, char *const *argv) | ||
183 | { | ||
184 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
185 | GNUNET_GETOPT_OPTION_END | ||
186 | }; | ||
187 | |||
188 | return (GNUNET_OK == | ||
189 | GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-pt", | ||
190 | gettext_noop | ||
191 | ("Daemon to run to perform IP protocol translation to GNUnet"), | ||
192 | options, &run, NULL)) ? 0 : 1; | ||
193 | } | ||
194 | |||
195 | |||
196 | /* end of gnunet-daemon-pt.c */ | ||
diff --git a/src/pt/pt.conf b/src/pt/pt.conf new file mode 100644 index 000000000..f5169f6ee --- /dev/null +++ b/src/pt/pt.conf | |||
@@ -0,0 +1,10 @@ | |||
1 | [pt] | ||
2 | CONFIG = $DEFAULTCONFIG | ||
3 | BINARY = gnunet-daemon-pt | ||
4 | |||
5 | # Set this to YES to tunnel IPv4 traffic over GNUnet | ||
6 | TUNNEL_IPV4 = NO | ||
7 | |||
8 | # Set this to YES to tunnel IPv6 traffic over GNUnet | ||
9 | TUNNEL_IPV6 = NO | ||
10 | |||