diff options
-rw-r--r-- | src/vpn/Makefile.am | 3 | ||||
-rw-r--r-- | src/vpn/gnunet-daemon-vpn-helper.c | 118 | ||||
-rw-r--r-- | src/vpn/gnunet-daemon-vpn-helper.h | 11 | ||||
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 11 | ||||
-rw-r--r-- | src/vpn/gnunet-helper-vpn-api.c | 136 | ||||
-rw-r--r-- | src/vpn/gnunet-helper-vpn-api.h | 116 |
6 files changed, 290 insertions, 105 deletions
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index f1b0e1df7..a36f56833 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am | |||
@@ -36,7 +36,8 @@ gnunet_daemon_vpn_SOURCES = \ | |||
36 | gnunet-vpn-pretty-print.c gnunet-vpn-pretty-print.h \ | 36 | gnunet-vpn-pretty-print.c gnunet-vpn-pretty-print.h \ |
37 | gnunet-dns-parser.c gnunet-dns-parser.h \ | 37 | gnunet-dns-parser.c gnunet-dns-parser.h \ |
38 | gnunet-daemon-vpn-helper.c gnunet-daemon-vpn-helper.h \ | 38 | gnunet-daemon-vpn-helper.c gnunet-daemon-vpn-helper.h \ |
39 | gnunet-daemon-vpn-dns.c gnunet-daemon-vpn-dns.h | 39 | gnunet-daemon-vpn-dns.c gnunet-daemon-vpn-dns.h \ |
40 | gnunet-helper-vpn-api.c gnunet-helper-vpn-api.h | ||
40 | gnunet_daemon_vpn_LDADD = \ | 41 | gnunet_daemon_vpn_LDADD = \ |
41 | $(top_builddir)/src/core/libgnunetcore.la \ | 42 | $(top_builddir)/src/core/libgnunetcore.la \ |
42 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 43 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c index d2815d4e5..ae6d18fd9 100644 --- a/src/vpn/gnunet-daemon-vpn-helper.c +++ b/src/vpn/gnunet-daemon-vpn-helper.c | |||
@@ -41,27 +41,10 @@ | |||
41 | #include "gnunet-vpn-packet.h" | 41 | #include "gnunet-vpn-packet.h" |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * PipeHandle to receive data from the helper | ||
45 | */ | ||
46 | static struct GNUNET_DISK_PipeHandle* helper_in; | ||
47 | |||
48 | /** | ||
49 | * PipeHandle to send data to the helper | ||
50 | */ | ||
51 | static struct GNUNET_DISK_PipeHandle* helper_out; | ||
52 | |||
53 | /** | ||
54 | * FileHandle to receive data from the helper | ||
55 | */ | ||
56 | static const struct GNUNET_DISK_FileHandle* fh_from_helper; | ||
57 | |||
58 | /** | ||
59 | * FileHandle to send data to the helper | ||
60 | */ | ||
61 | static const struct GNUNET_DISK_FileHandle* fh_to_helper; | ||
62 | |||
63 | /** | ||
64 | * Start the helper-process | 44 | * Start the helper-process |
45 | * | ||
46 | * If cls != NULL it is assumed that this function is called as a result of a dying | ||
47 | * helper. cls is then taken as handle to the old helper and is cleaned up. | ||
65 | * {{{ | 48 | * {{{ |
66 | */ | 49 | */ |
67 | void | 50 | void |
@@ -70,16 +53,22 @@ start_helper_and_schedule(void *cls, | |||
70 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 53 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
71 | return; | 54 | return; |
72 | 55 | ||
73 | helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO); | 56 | if (cls != NULL) |
74 | helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); | 57 | cleanup_helper(cls); |
75 | 58 | cls = NULL; | |
76 | if (helper_in == NULL || helper_out == NULL) return; | ||
77 | 59 | ||
60 | char* ifname; | ||
78 | char* ipv6addr; | 61 | char* ipv6addr; |
79 | char* ipv6prefix; | 62 | char* ipv6prefix; |
80 | char* ipv4addr; | 63 | char* ipv4addr; |
81 | char* ipv4mask; | 64 | char* ipv4mask; |
82 | 65 | ||
66 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IFNAME", &ifname)) | ||
67 | { | ||
68 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IFNAME' in configuration!\n"); | ||
69 | exit(1); | ||
70 | } | ||
71 | |||
83 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr)) | 72 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr)) |
84 | { | 73 | { |
85 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV6ADDR' in configuration!\n"); | 74 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV6ADDR' in configuration!\n"); |
@@ -104,75 +93,32 @@ start_helper_and_schedule(void *cls, | |||
104 | exit(1); | 93 | exit(1); |
105 | } | 94 | } |
106 | 95 | ||
107 | helper_proc = | 96 | /* Start the helper |
108 | GNUNET_OS_start_process (helper_in, helper_out, "gnunet-helper-vpn", | 97 | * Messages get passed to the function message_token |
109 | "gnunet-helper-vpn", ipv6addr, ipv6prefix, | 98 | * When the helper dies, this function will be called again with the |
110 | ipv4addr, ipv4mask, NULL); | 99 | * helper_handle as cls. |
100 | */ | ||
101 | helper_handle = start_helper(ifname, | ||
102 | ipv6addr, | ||
103 | ipv6prefix, | ||
104 | ipv4addr, | ||
105 | ipv4mask, | ||
106 | "vpn-gnunet", | ||
107 | start_helper_and_schedule, | ||
108 | message_token, | ||
109 | NULL, | ||
110 | NULL); | ||
111 | 111 | ||
112 | GNUNET_free(ipv6addr); | 112 | GNUNET_free(ipv6addr); |
113 | GNUNET_free(ipv6prefix); | 113 | GNUNET_free(ipv6prefix); |
114 | GNUNET_free(ipv4addr); | 114 | GNUNET_free(ipv4addr); |
115 | GNUNET_free(ipv4mask); | 115 | GNUNET_free(ipv4mask); |
116 | 116 | ||
117 | fh_from_helper = GNUNET_DISK_pipe_handle (helper_out, GNUNET_DISK_PIPE_END_READ); | ||
118 | fh_to_helper = GNUNET_DISK_pipe_handle (helper_in, GNUNET_DISK_PIPE_END_WRITE); | ||
119 | |||
120 | GNUNET_DISK_pipe_close_end(helper_out, GNUNET_DISK_PIPE_END_WRITE); | ||
121 | GNUNET_DISK_pipe_close_end(helper_in, GNUNET_DISK_PIPE_END_READ); | ||
122 | |||
123 | /* Tell the dns-service to rehijack the dns-port | 117 | /* Tell the dns-service to rehijack the dns-port |
124 | * The routing-table gets flushed if an interface disappears. | 118 | * The routing-table gets flushed if an interface disappears. |
125 | */ | 119 | */ |
126 | restart_hijack = 1; | 120 | restart_hijack = 1; |
127 | GNUNET_CLIENT_notify_transmit_ready(dns_connection, sizeof(struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); | 121 | GNUNET_CLIENT_notify_transmit_ready(dns_connection, sizeof(struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); |
128 | |||
129 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fh_from_helper, &helper_read, NULL); | ||
130 | } | ||
131 | /*}}}*/ | ||
132 | /** | ||
133 | * Restart the helper-process | ||
134 | * {{{ | ||
135 | */ | ||
136 | void | ||
137 | restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { | ||
138 | // Kill the helper | ||
139 | GNUNET_OS_process_kill (helper_proc, SIGKILL); | ||
140 | GNUNET_OS_process_wait (helper_proc); | ||
141 | GNUNET_OS_process_close (helper_proc); | ||
142 | helper_proc = NULL; | ||
143 | |||
144 | GNUNET_DISK_pipe_close(helper_in); | ||
145 | GNUNET_DISK_pipe_close(helper_out); | ||
146 | |||
147 | /* Restart the helper */ | ||
148 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, start_helper_and_schedule, NULL); | ||
149 | } | ||
150 | /*}}}*/ | ||
151 | |||
152 | /** | ||
153 | * Read from the helper-process | ||
154 | * {{{ | ||
155 | */ | ||
156 | void | ||
157 | helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) { | ||
158 | /* no message can be bigger then 64k */ | ||
159 | char buf[65535]; | ||
160 | |||
161 | if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) | ||
162 | return; | ||
163 | |||
164 | int t = GNUNET_DISK_file_read(fh_from_helper, &buf, 65535); | ||
165 | |||
166 | /* On read-error, restart the helper */ | ||
167 | if (t<=0) { | ||
168 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read error for header from vpn-helper: %m\n"); | ||
169 | GNUNET_SCHEDULER_add_now(restart_helper, cls); | ||
170 | return; | ||
171 | } | ||
172 | |||
173 | /* FIXME */ GNUNET_SERVER_mst_receive(mst, NULL, buf, t, 0, 0); | ||
174 | |||
175 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fh_from_helper, &helper_read, NULL); | ||
176 | } | 122 | } |
177 | /*}}}*/ | 123 | /*}}}*/ |
178 | 124 | ||
@@ -234,12 +180,12 @@ helper_write(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) { | |||
234 | GNUNET_CONTAINER_DLL_remove (answer_proc_head, answer_proc_tail, ans); | 180 | GNUNET_CONTAINER_DLL_remove (answer_proc_head, answer_proc_tail, ans); |
235 | GNUNET_free(ans); | 181 | GNUNET_free(ans); |
236 | 182 | ||
237 | /* FIXME */ GNUNET_DISK_file_write(fh_to_helper, pkt, pkt_len); | 183 | /* FIXME */ GNUNET_DISK_file_write(helper_handle->fh_to_helper, pkt, pkt_len); |
238 | 184 | ||
239 | /* if more packets are available, reschedule */ | 185 | /* if more packets are available, reschedule */ |
240 | if (answer_proc_head != NULL) | 186 | if (answer_proc_head != NULL) |
241 | GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | 187 | GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, |
242 | fh_to_helper, | 188 | helper_handle->fh_to_helper, |
243 | &helper_write, | 189 | &helper_write, |
244 | NULL); | 190 | NULL); |
245 | } | 191 | } |
@@ -361,10 +307,10 @@ message_token(void *cls, | |||
361 | 307 | ||
362 | void write_to_helper(void* buf, size_t len) | 308 | void write_to_helper(void* buf, size_t len) |
363 | { | 309 | { |
364 | (void)GNUNET_DISK_file_write(fh_to_helper, buf, len); | 310 | (void)GNUNET_DISK_file_write(helper_handle->fh_to_helper, buf, len); |
365 | } | 311 | } |
366 | 312 | ||
367 | void schedule_helper_write(struct GNUNET_TIME_Relative time, void* cls) | 313 | void schedule_helper_write(struct GNUNET_TIME_Relative time, void* cls) |
368 | { | 314 | { |
369 | GNUNET_SCHEDULER_add_write_file (time, fh_to_helper, &helper_write, cls); | 315 | GNUNET_SCHEDULER_add_write_file (time, helper_handle->fh_to_helper, &helper_write, cls); |
370 | } | 316 | } |
diff --git a/src/vpn/gnunet-daemon-vpn-helper.h b/src/vpn/gnunet-daemon-vpn-helper.h index c7234c092..17d775b86 100644 --- a/src/vpn/gnunet-daemon-vpn-helper.h +++ b/src/vpn/gnunet-daemon-vpn-helper.h | |||
@@ -26,15 +26,12 @@ | |||
26 | #ifndef GNUNET_DAEMON_VPN_HELPER_H | 26 | #ifndef GNUNET_DAEMON_VPN_HELPER_H |
27 | #define GNUNET_DAEMON_VPN_HELPER_H | 27 | #define GNUNET_DAEMON_VPN_HELPER_H |
28 | 28 | ||
29 | /** | 29 | #include "gnunet-helper-vpn-api.h" |
30 | * The process id of the helper | ||
31 | */ | ||
32 | struct GNUNET_OS_Process *helper_proc; | ||
33 | 30 | ||
34 | /** | 31 | /** |
35 | * The Message-Tokenizer that tokenizes the messages comming from the helper | 32 | * Handle to the helper. contains filedescriptors and such |
36 | */ | 33 | */ |
37 | struct GNUNET_SERVER_MessageStreamTokenizer* mst; | 34 | struct GNUNET_VPN_HELPER_Handle *helper_handle; |
38 | 35 | ||
39 | /** | 36 | /** |
40 | * Start the helper-process | 37 | * Start the helper-process |
@@ -65,9 +62,7 @@ void message_token(void *cls, | |||
65 | const struct GNUNET_MessageHeader *message); | 62 | const struct GNUNET_MessageHeader *message); |
66 | 63 | ||
67 | void write_to_helper(void* buf, size_t len); | 64 | void write_to_helper(void* buf, size_t len); |
68 | // GNUNET_DISK_file_write(fh_to_helper, response, ntohs(response->shdr.size)); | ||
69 | 65 | ||
70 | void schedule_helper_write(struct GNUNET_TIME_Relative, void* cls); | 66 | void schedule_helper_write(struct GNUNET_TIME_Relative, void* cls); |
71 | // GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fh_to_helper, &helper_write, NULL); | ||
72 | 67 | ||
73 | #endif /* end of include guard: GNUNET-DAEMON-VPN-HELPER_H */ | 68 | #endif /* end of include guard: GNUNET-DAEMON-VPN-HELPER_H */ |
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 1e0afea35..8424e9887 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include "gnunet-vpn-packet.h" | 29 | #include "gnunet-vpn-packet.h" |
30 | #include "gnunet-vpn-pretty-print.h" | 30 | #include "gnunet-vpn-pretty-print.h" |
31 | #include "gnunet_common.h" | 31 | #include "gnunet_common.h" |
32 | #include <gnunet_os_lib.h> | ||
33 | #include "gnunet_protocols.h" | 32 | #include "gnunet_protocols.h" |
34 | #include <gnunet_mesh_service.h> | 33 | #include <gnunet_mesh_service.h> |
35 | #include "gnunet_client_lib.h" | 34 | #include "gnunet_client_lib.h" |
@@ -61,14 +60,7 @@ cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { | |||
61 | GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); | 60 | GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); |
62 | 61 | ||
63 | /* stop the helper */ | 62 | /* stop the helper */ |
64 | if (helper_proc != NULL) | 63 | cleanup_helper(helper_handle); |
65 | { | ||
66 | if (0 != GNUNET_OS_process_kill (helper_proc, SIGTERM)) | ||
67 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
68 | GNUNET_OS_process_wait (helper_proc); | ||
69 | GNUNET_OS_process_close (helper_proc); | ||
70 | helper_proc = NULL; | ||
71 | } | ||
72 | 64 | ||
73 | /* close the connection to the service-dns */ | 65 | /* close the connection to the service-dns */ |
74 | if (dns_connection != NULL) | 66 | if (dns_connection != NULL) |
@@ -478,7 +470,6 @@ run (void *cls, | |||
478 | NULL, | 470 | NULL, |
479 | NULL, | 471 | NULL, |
480 | handlers); | 472 | handlers); |
481 | mst = GNUNET_SERVER_mst_create(&message_token, NULL); | ||
482 | cfg = cfg_; | 473 | cfg = cfg_; |
483 | restart_hijack = 0; | 474 | restart_hijack = 0; |
484 | hashmap = GNUNET_CONTAINER_multihashmap_create(65536); | 475 | hashmap = GNUNET_CONTAINER_multihashmap_create(65536); |
diff --git a/src/vpn/gnunet-helper-vpn-api.c b/src/vpn/gnunet-helper-vpn-api.c new file mode 100644 index 000000000..c2ab6081d --- /dev/null +++ b/src/vpn/gnunet-helper-vpn-api.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010 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 vpn/gnunet-helper-vpn-api.c | ||
23 | * @brief exposes the API (the convenience-functions) of dealing with the | ||
24 | * helper-vpn | ||
25 | * @author Philipp Toelke | ||
26 | */ | ||
27 | |||
28 | #include <platform.h> | ||
29 | #include <gnunet_common.h> | ||
30 | #include <gnunet_server_lib.h> | ||
31 | #include <gnunet_os_lib.h> | ||
32 | |||
33 | #include "gnunet-helper-vpn-api.h" | ||
34 | |||
35 | static void | ||
36 | stop_helper (struct GNUNET_VPN_HELPER_Handle *handle) | ||
37 | { | ||
38 | if (NULL == handle->helper_proc) | ||
39 | return; | ||
40 | GNUNET_OS_process_kill (handle->helper_proc, SIGKILL); | ||
41 | GNUNET_OS_process_wait (handle->helper_proc); | ||
42 | GNUNET_OS_process_close (handle->helper_proc); | ||
43 | handle->helper_proc = NULL; | ||
44 | |||
45 | GNUNET_DISK_pipe_close (handle->helper_in); | ||
46 | GNUNET_DISK_pipe_close (handle->helper_out); | ||
47 | } | ||
48 | |||
49 | /** | ||
50 | * Read from the helper-process | ||
51 | */ | ||
52 | static void | ||
53 | helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx) | ||
54 | { | ||
55 | struct GNUNET_VPN_HELPER_Handle *handle = cls; | ||
56 | /* no message can be bigger then 64k */ | ||
57 | char buf[65535]; | ||
58 | |||
59 | if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) | ||
60 | return; | ||
61 | |||
62 | int t = GNUNET_DISK_file_read (handle->fh_from_helper, &buf, 65535); | ||
63 | |||
64 | /* On read-error, restart the helper */ | ||
65 | if (t <= 0) | ||
66 | { | ||
67 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
68 | "Read error for header from vpn-helper: %m\n"); | ||
69 | stop_helper (handle); | ||
70 | |||
71 | /* Restart the helper */ | ||
72 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
73 | handle->restart_task, handle); | ||
74 | return; | ||
75 | } | ||
76 | |||
77 | /* FIXME */ GNUNET_SERVER_mst_receive (handle->mst, handle->client, buf, t, | ||
78 | 0, 0); | ||
79 | |||
80 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
81 | handle->fh_from_helper, &helper_read, | ||
82 | handle); | ||
83 | } | ||
84 | |||
85 | void | ||
86 | cleanup_helper (struct GNUNET_VPN_HELPER_Handle *handle) | ||
87 | { | ||
88 | stop_helper (handle); | ||
89 | GNUNET_free (handle); | ||
90 | } | ||
91 | |||
92 | struct GNUNET_VPN_HELPER_Handle * | ||
93 | start_helper (const char *ifname, | ||
94 | const char *ipv6addr, | ||
95 | const char *ipv6prefix, | ||
96 | const char *ipv4addr, | ||
97 | const char *ipv4mask, const char *process_name, | ||
98 | GNUNET_SCHEDULER_Task restart_task, | ||
99 | GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls, | ||
100 | void *client) | ||
101 | { | ||
102 | struct GNUNET_VPN_HELPER_Handle *handle = | ||
103 | GNUNET_malloc (sizeof (struct GNUNET_VPN_HELPER_Handle)); | ||
104 | |||
105 | handle->helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO); | ||
106 | handle->helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); | ||
107 | |||
108 | handle->restart_task = restart_task; | ||
109 | |||
110 | if (handle->helper_in == NULL || handle->helper_out == NULL) | ||
111 | { | ||
112 | GNUNET_free (handle); | ||
113 | return NULL; | ||
114 | } | ||
115 | |||
116 | handle->helper_proc = | ||
117 | GNUNET_OS_start_process (handle->helper_in, handle->helper_out, | ||
118 | "gnunet-helper-vpn", process_name, ifname, | ||
119 | ipv6addr, ipv6prefix, ipv4addr, ipv4mask, NULL); | ||
120 | |||
121 | handle->fh_from_helper = | ||
122 | GNUNET_DISK_pipe_handle (handle->helper_out, GNUNET_DISK_PIPE_END_READ); | ||
123 | handle->fh_to_helper = | ||
124 | GNUNET_DISK_pipe_handle (handle->helper_in, GNUNET_DISK_PIPE_END_WRITE); | ||
125 | |||
126 | GNUNET_DISK_pipe_close_end (handle->helper_out, GNUNET_DISK_PIPE_END_WRITE); | ||
127 | GNUNET_DISK_pipe_close_end (handle->helper_in, GNUNET_DISK_PIPE_END_READ); | ||
128 | |||
129 | handle->mst = GNUNET_SERVER_mst_create (cb, cb_cls); | ||
130 | |||
131 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
132 | handle->fh_from_helper, &helper_read, | ||
133 | handle); | ||
134 | |||
135 | return handle; | ||
136 | } | ||
diff --git a/src/vpn/gnunet-helper-vpn-api.h b/src/vpn/gnunet-helper-vpn-api.h new file mode 100644 index 000000000..00eb7db62 --- /dev/null +++ b/src/vpn/gnunet-helper-vpn-api.h | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010 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 vpn/gnunet-helper-vpn-api.h | ||
23 | * @brief exposes the API (the convenience-functions) of dealing with the | ||
24 | * helper-vpn | ||
25 | * @author Philipp Toelke | ||
26 | */ | ||
27 | #ifndef GNUNET_HELPER_VPN_API_H | ||
28 | #define GNUNET_HELPER_VPN_API_H | ||
29 | |||
30 | /** | ||
31 | * The handle to a helper. | ||
32 | * sometimes a few entries may be made opaque. | ||
33 | */ | ||
34 | struct GNUNET_VPN_HELPER_Handle | ||
35 | { | ||
36 | /** | ||
37 | * PipeHandle to receive data from the helper | ||
38 | */ | ||
39 | struct GNUNET_DISK_PipeHandle *helper_in; | ||
40 | |||
41 | /** | ||
42 | * PipeHandle to send data to the helper | ||
43 | */ | ||
44 | struct GNUNET_DISK_PipeHandle *helper_out; | ||
45 | |||
46 | /** | ||
47 | * FileHandle to receive data from the helper | ||
48 | */ | ||
49 | const struct GNUNET_DISK_FileHandle *fh_from_helper; | ||
50 | |||
51 | /** | ||
52 | * FileHandle to send data to the helper | ||
53 | */ | ||
54 | const struct GNUNET_DISK_FileHandle *fh_to_helper; | ||
55 | |||
56 | /** | ||
57 | * The process id of the helper | ||
58 | */ | ||
59 | struct GNUNET_OS_Process *helper_proc; | ||
60 | |||
61 | /** | ||
62 | * The Message-Tokenizer that tokenizes the messages comming from the helper | ||
63 | */ | ||
64 | struct GNUNET_SERVER_MessageStreamTokenizer *mst; | ||
65 | |||
66 | /** | ||
67 | * The client-identifier passed to the mst-callback | ||
68 | */ | ||
69 | void *client; | ||
70 | |||
71 | /** | ||
72 | * The name of the interface | ||
73 | */ | ||
74 | char *ifname; | ||
75 | |||
76 | /** | ||
77 | * The task called when the helper dies. | ||
78 | * Will be called with the handle as cls | ||
79 | */ | ||
80 | GNUNET_SCHEDULER_Task restart_task; | ||
81 | }; | ||
82 | |||
83 | /** | ||
84 | * @brief Starts a helper and begins reading from it | ||
85 | * | ||
86 | * @param ifname The name of the new interface | ||
87 | * @param ipv6addr The IPv6 address of the new interface | ||
88 | * @param ipv6prefix The IPv6 prefix length of the new IP | ||
89 | * @param ipv4addr The IPv4 address of the new interface | ||
90 | * @param ipv4mask The associated netmask | ||
91 | * @param process_name How the helper should appear in process-listings | ||
92 | * @param restart_task The task called when the helper dies. Will be called with the handle as cls | ||
93 | * @param cb A callback for messages from the helper | ||
94 | * @param cb_cls Closure for the callback | ||
95 | * @param client client_name for the callback | ||
96 | * | ||
97 | * @return A pointer to the new Handle, NULL on error | ||
98 | */ | ||
99 | struct GNUNET_VPN_HELPER_Handle *start_helper (const char *ifname, | ||
100 | const char *ipv6addr, | ||
101 | const char *ipv6prefix, | ||
102 | const char *ipv4addr, | ||
103 | const char *ipv4mask, | ||
104 | const char *process_name, | ||
105 | GNUNET_SCHEDULER_Task | ||
106 | restart_task, | ||
107 | GNUNET_SERVER_MessageTokenizerCallback | ||
108 | cb, void *cb_cls, | ||
109 | void *client); | ||
110 | |||
111 | /** | ||
112 | * @brief Kills the helper, closes the pipe and free()s the handle | ||
113 | */ | ||
114 | void cleanup_helper (struct GNUNET_VPN_HELPER_Handle *); | ||
115 | |||
116 | #endif /* end of include guard: GNUNET_HELPER_VPN_API_H */ | ||