diff options
author | Philipp Tölke <toelke@in.tum.de> | 2010-11-02 21:40:01 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2010-11-02 21:40:01 +0000 |
commit | 11c2830064ec60af2b84a9b7f885b2f9d31a1b0d (patch) | |
tree | b2a6542452d7ed9b0006f519fea239de4849176c | |
parent | f0d0be799be9acd5fee5e0b1f39ea196a8f253b6 (diff) | |
download | gnunet-11c2830064ec60af2b84a9b7f885b2f9d31a1b0d.tar.gz gnunet-11c2830064ec60af2b84a9b7f885b2f9d31a1b0d.zip |
get rid of the unneeded "closure"-struct
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 204 | ||||
-rw-r--r-- | src/vpn/gnunet-service-dns.c | 79 |
2 files changed, 165 insertions, 118 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index cc2474f32..e84600e4a 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c | |||
@@ -43,42 +43,92 @@ | |||
43 | */ | 43 | */ |
44 | static int ret; | 44 | static int ret; |
45 | 45 | ||
46 | struct vpn_cls { | 46 | /** |
47 | struct GNUNET_DISK_PipeHandle* helper_in; // From the helper | 47 | * The scheduler to use throughout the daemon |
48 | struct GNUNET_DISK_PipeHandle* helper_out; // To the helper | 48 | */ |
49 | const struct GNUNET_DISK_FileHandle* fh_from_helper; | 49 | static struct GNUNET_SCHEDULER_Handle *sched; |
50 | const struct GNUNET_DISK_FileHandle* fh_to_helper; | ||
51 | 50 | ||
52 | struct GNUNET_SERVER_MessageStreamTokenizer* mst; | 51 | /** |
52 | * The configuration to use | ||
53 | */ | ||
54 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
53 | 55 | ||
54 | struct GNUNET_SCHEDULER_Handle *sched; | 56 | /** |
57 | * PipeHandle to receive data from the helper | ||
58 | */ | ||
59 | static struct GNUNET_DISK_PipeHandle* helper_in; | ||
55 | 60 | ||
56 | struct GNUNET_CLIENT_Connection *dns_connection; | 61 | /** |
57 | unsigned char restart_hijack; | 62 | * PipeHandle to send data to the helper |
63 | */ | ||
64 | static struct GNUNET_DISK_PipeHandle* helper_out; | ||
58 | 65 | ||
59 | pid_t helper_pid; | 66 | /** |
67 | * FileHandle to receive data from the helper | ||
68 | */ | ||
69 | static const struct GNUNET_DISK_FileHandle* fh_from_helper; | ||
60 | 70 | ||
61 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 71 | /** |
72 | * FileHandle to send data to the helper | ||
73 | */ | ||
74 | static const struct GNUNET_DISK_FileHandle* fh_to_helper; | ||
62 | 75 | ||
63 | struct query_packet_list *head; | 76 | /** |
64 | struct query_packet_list *tail; | 77 | * The Message-Tokenizer that tokenizes the messages comming from the helper |
78 | */ | ||
79 | static struct GNUNET_SERVER_MessageStreamTokenizer* mst; | ||
65 | 80 | ||
66 | struct answer_packet_list *answer_proc_head; | 81 | /** |
67 | struct answer_packet_list *answer_proc_tail; | 82 | * The connection to the service-dns |
68 | }; | 83 | */ |
84 | static struct GNUNET_CLIENT_Connection *dns_connection; | ||
69 | 85 | ||
70 | static struct vpn_cls mycls; | 86 | /** |
87 | * A flag to show that the service-dns has to rehijack the outbound dns-packets | ||
88 | * | ||
89 | * This gets set when the helper restarts as the routing-tables are flushed when | ||
90 | * the interface vanishes. | ||
91 | */ | ||
92 | static unsigned char restart_hijack; | ||
93 | |||
94 | /** | ||
95 | * The process id of the helper | ||
96 | */ | ||
97 | static pid_t helper_pid; | ||
98 | |||
99 | /** | ||
100 | * a list of outgoing dns-query-packets | ||
101 | */ | ||
102 | static struct query_packet_list *head; | ||
103 | |||
104 | /** | ||
105 | * The last element of the list of outgoing dns-query-packets | ||
106 | */ | ||
107 | static struct query_packet_list *tail; | ||
108 | |||
109 | /** | ||
110 | * A list of processed dns-responses. | ||
111 | * | ||
112 | * "processed" means that the packet is complete and can be sent out via udp | ||
113 | * directly | ||
114 | */ | ||
115 | static struct answer_packet_list *answer_proc_head; | ||
116 | |||
117 | /** | ||
118 | * The last element of the list of processed dns-responses. | ||
119 | */ | ||
120 | static struct answer_packet_list *answer_proc_tail; | ||
71 | 121 | ||
72 | size_t send_query(void* cls, size_t size, void* buf); | 122 | size_t send_query(void* cls, size_t size, void* buf); |
73 | 123 | ||
74 | static void cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { | 124 | static void cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { |
75 | GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); | 125 | GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); |
76 | PLIBC_KILL(mycls.helper_pid, SIGTERM); | 126 | PLIBC_KILL(helper_pid, SIGTERM); |
77 | GNUNET_OS_process_wait(mycls.helper_pid); | 127 | GNUNET_OS_process_wait(helper_pid); |
78 | if (mycls.dns_connection != NULL) | 128 | if (dns_connection != NULL) |
79 | { | 129 | { |
80 | GNUNET_CLIENT_disconnect (mycls.dns_connection, GNUNET_NO); | 130 | GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO); |
81 | mycls.dns_connection = NULL; | 131 | dns_connection = NULL; |
82 | } | 132 | } |
83 | } | 133 | } |
84 | 134 | ||
@@ -90,39 +140,39 @@ static void start_helper_and_schedule(void *cls, | |||
90 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 140 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
91 | return; | 141 | return; |
92 | 142 | ||
93 | mycls.helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO); | 143 | helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO); |
94 | mycls.helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); | 144 | helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); |
95 | 145 | ||
96 | if (mycls.helper_in == NULL || mycls.helper_out == NULL) return; | 146 | if (helper_in == NULL || helper_out == NULL) return; |
97 | 147 | ||
98 | mycls.helper_pid = GNUNET_OS_start_process(mycls.helper_in, mycls.helper_out, "gnunet-helper-vpn", "gnunet-helper-vpn", NULL); | 148 | helper_pid = GNUNET_OS_start_process(helper_in, helper_out, "gnunet-helper-vpn", "gnunet-helper-vpn", NULL); |
99 | 149 | ||
100 | mycls.fh_from_helper = GNUNET_DISK_pipe_handle (mycls.helper_out, GNUNET_DISK_PIPE_END_READ); | 150 | fh_from_helper = GNUNET_DISK_pipe_handle (helper_out, GNUNET_DISK_PIPE_END_READ); |
101 | mycls.fh_to_helper = GNUNET_DISK_pipe_handle (mycls.helper_in, GNUNET_DISK_PIPE_END_WRITE); | 151 | fh_to_helper = GNUNET_DISK_pipe_handle (helper_in, GNUNET_DISK_PIPE_END_WRITE); |
102 | 152 | ||
103 | GNUNET_DISK_pipe_close_end(mycls.helper_out, GNUNET_DISK_PIPE_END_WRITE); | 153 | GNUNET_DISK_pipe_close_end(helper_out, GNUNET_DISK_PIPE_END_WRITE); |
104 | GNUNET_DISK_pipe_close_end(mycls.helper_in, GNUNET_DISK_PIPE_END_READ); | 154 | GNUNET_DISK_pipe_close_end(helper_in, GNUNET_DISK_PIPE_END_READ); |
105 | 155 | ||
106 | GNUNET_SCHEDULER_add_read_file (mycls.sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls.fh_from_helper, &helper_read, NULL); | 156 | GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, fh_from_helper, &helper_read, NULL); |
107 | } | 157 | } |
108 | 158 | ||
109 | 159 | ||
110 | static void restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { | 160 | static void restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { |
111 | // Kill the helper | 161 | // Kill the helper |
112 | PLIBC_KILL(mycls.helper_pid, SIGKILL); | 162 | PLIBC_KILL(helper_pid, SIGKILL); |
113 | GNUNET_OS_process_wait(mycls.helper_pid); | 163 | GNUNET_OS_process_wait(helper_pid); |
114 | 164 | ||
115 | /* Tell the dns-service to rehijack the dns-port | 165 | /* Tell the dns-service to rehijack the dns-port |
116 | * The routing-table gets flushed if an interface disappears. | 166 | * The routing-table gets flushed if an interface disappears. |
117 | */ | 167 | */ |
118 | mycls.restart_hijack = 1; | 168 | restart_hijack = 1; |
119 | GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, sizeof(struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); | 169 | GNUNET_CLIENT_notify_transmit_ready(dns_connection, sizeof(struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); |
120 | 170 | ||
121 | GNUNET_DISK_pipe_close(mycls.helper_in); | 171 | GNUNET_DISK_pipe_close(helper_in); |
122 | GNUNET_DISK_pipe_close(mycls.helper_out); | 172 | GNUNET_DISK_pipe_close(helper_out); |
123 | 173 | ||
124 | // Restart the helper | 174 | // Restart the helper |
125 | GNUNET_SCHEDULER_add_delayed (mycls.sched, GNUNET_TIME_UNIT_SECONDS, start_helper_and_schedule, NULL); | 175 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_UNIT_SECONDS, start_helper_and_schedule, NULL); |
126 | 176 | ||
127 | } | 177 | } |
128 | 178 | ||
@@ -132,16 +182,16 @@ static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* ts | |||
132 | if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) | 182 | if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) |
133 | return; | 183 | return; |
134 | 184 | ||
135 | int t = GNUNET_DISK_file_read(mycls.fh_from_helper, &buf, 65535); | 185 | int t = GNUNET_DISK_file_read(fh_from_helper, &buf, 65535); |
136 | if (t<=0) { | 186 | if (t<=0) { |
137 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read error for header from vpn-helper: %m\n"); | 187 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read error for header from vpn-helper: %m\n"); |
138 | GNUNET_SCHEDULER_add_now(mycls.sched, restart_helper, cls); | 188 | GNUNET_SCHEDULER_add_now(sched, restart_helper, cls); |
139 | return; | 189 | return; |
140 | } | 190 | } |
141 | 191 | ||
142 | /* FIXME */ GNUNET_SERVER_mst_receive(mycls.mst, NULL, buf, t, 0, 0); | 192 | /* FIXME */ GNUNET_SERVER_mst_receive(mst, NULL, buf, t, 0, 0); |
143 | 193 | ||
144 | GNUNET_SCHEDULER_add_read_file (mycls.sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls.fh_from_helper, &helper_read, NULL); | 194 | GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, fh_from_helper, &helper_read, NULL); |
145 | } | 195 | } |
146 | 196 | ||
147 | static uint16_t calculate_ip_checksum(uint16_t* hdr, short len) { | 197 | static uint16_t calculate_ip_checksum(uint16_t* hdr, short len) { |
@@ -159,7 +209,7 @@ static uint16_t calculate_ip_checksum(uint16_t* hdr, short len) { | |||
159 | static void helper_write(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) { | 209 | static void helper_write(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) { |
160 | if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) | 210 | if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) |
161 | return; | 211 | return; |
162 | struct answer_packet_list* ans = mycls.answer_proc_head; | 212 | struct answer_packet_list* ans = answer_proc_head; |
163 | size_t len = ntohs(ans->pkt.hdr.size); | 213 | size_t len = ntohs(ans->pkt.hdr.size); |
164 | 214 | ||
165 | GNUNET_assert(ans->pkt.subtype == GNUNET_DNS_ANSWER_TYPE_IP); | 215 | GNUNET_assert(ans->pkt.subtype == GNUNET_DNS_ANSWER_TYPE_IP); |
@@ -199,21 +249,21 @@ static void helper_write(void* cls, const struct GNUNET_SCHEDULER_TaskContext* t | |||
199 | 249 | ||
200 | memcpy(&pkt->udp_dns.data, ans->pkt.data, data_len); | 250 | memcpy(&pkt->udp_dns.data, ans->pkt.data, data_len); |
201 | 251 | ||
202 | GNUNET_CONTAINER_DLL_remove (mycls.answer_proc_head, mycls.answer_proc_tail, ans); | 252 | GNUNET_CONTAINER_DLL_remove (answer_proc_head, answer_proc_tail, ans); |
203 | GNUNET_free(ans); | 253 | GNUNET_free(ans); |
204 | 254 | ||
205 | /* FIXME */ GNUNET_DISK_file_write(mycls.fh_to_helper, pkt, pkt_len); | 255 | /* FIXME */ GNUNET_DISK_file_write(fh_to_helper, pkt, pkt_len); |
206 | 256 | ||
207 | if (mycls.answer_proc_head != NULL) | 257 | if (answer_proc_head != NULL) |
208 | GNUNET_SCHEDULER_add_write_file (mycls.sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls.fh_to_helper, &helper_write, NULL); | 258 | GNUNET_SCHEDULER_add_write_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, fh_to_helper, &helper_write, NULL); |
209 | } | 259 | } |
210 | 260 | ||
211 | size_t send_query(void* cls, size_t size, void* buf) | 261 | size_t send_query(void* cls, size_t size, void* buf) |
212 | { | 262 | { |
213 | size_t len; | 263 | size_t len; |
214 | if (mycls.restart_hijack == 1) | 264 | if (restart_hijack == 1) |
215 | { | 265 | { |
216 | mycls.restart_hijack = 0; | 266 | restart_hijack = 0; |
217 | GNUNET_assert(sizeof(struct GNUNET_MessageHeader) >= size); | 267 | GNUNET_assert(sizeof(struct GNUNET_MessageHeader) >= size); |
218 | struct GNUNET_MessageHeader* hdr = buf; | 268 | struct GNUNET_MessageHeader* hdr = buf; |
219 | len = sizeof(struct GNUNET_MessageHeader); | 269 | len = sizeof(struct GNUNET_MessageHeader); |
@@ -222,20 +272,20 @@ size_t send_query(void* cls, size_t size, void* buf) | |||
222 | } | 272 | } |
223 | else | 273 | else |
224 | { | 274 | { |
225 | struct query_packet_list* query = mycls.head; | 275 | struct query_packet_list* query = head; |
226 | len = ntohs(query->pkt.hdr.size); | 276 | len = ntohs(query->pkt.hdr.size); |
227 | 277 | ||
228 | GNUNET_assert(len <= size); | 278 | GNUNET_assert(len <= size); |
229 | 279 | ||
230 | memcpy(buf, &query->pkt.hdr, len); | 280 | memcpy(buf, &query->pkt.hdr, len); |
231 | 281 | ||
232 | GNUNET_CONTAINER_DLL_remove (mycls.head, mycls.tail, query); | 282 | GNUNET_CONTAINER_DLL_remove (head, tail, query); |
233 | 283 | ||
234 | GNUNET_free(query); | 284 | GNUNET_free(query); |
235 | } | 285 | } |
236 | 286 | ||
237 | if (mycls.head != NULL || mycls.restart_hijack == 1) { | 287 | if (head != NULL || restart_hijack == 1) { |
238 | GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, ntohs(mycls.head->pkt.hdr.size), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); | 288 | GNUNET_CLIENT_notify_transmit_ready(dns_connection, ntohs(head->pkt.hdr.size), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); |
239 | } | 289 | } |
240 | 290 | ||
241 | return len; | 291 | return len; |
@@ -279,10 +329,10 @@ static void message_token(void *cls, void *client, const struct GNUNET_MessageHe | |||
279 | query->pkt.src_port = udp->udp_hdr.spt; | 329 | query->pkt.src_port = udp->udp_hdr.spt; |
280 | memcpy(query->pkt.data, udp->data, ntohs(udp->udp_hdr.len) - 8); | 330 | memcpy(query->pkt.data, udp->data, ntohs(udp->udp_hdr.len) - 8); |
281 | 331 | ||
282 | GNUNET_CONTAINER_DLL_insert_after(mycls.head, mycls.tail, mycls.tail, query); | 332 | GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, query); |
283 | 333 | ||
284 | if (mycls.dns_connection != NULL) | 334 | if (dns_connection != NULL) |
285 | /* struct GNUNET_CLIENT_TransmitHandle* th = */ GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, len, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); | 335 | /* struct GNUNET_CLIENT_TransmitHandle* th = */ GNUNET_CLIENT_notify_transmit_ready(dns_connection, len, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); |
286 | } | 336 | } |
287 | } | 337 | } |
288 | 338 | ||
@@ -297,11 +347,11 @@ reconnect_to_service_dns (void *cls, | |||
297 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 347 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
298 | return; | 348 | return; |
299 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting\n"); | 349 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting\n"); |
300 | GNUNET_assert (mycls.dns_connection == NULL); | 350 | GNUNET_assert (dns_connection == NULL); |
301 | mycls.dns_connection = GNUNET_CLIENT_connect (mycls.sched, "dns", mycls.cfg); | 351 | dns_connection = GNUNET_CLIENT_connect (sched, "dns", cfg); |
302 | GNUNET_CLIENT_receive(mycls.dns_connection, &dns_answer_handler, NULL, GNUNET_TIME_UNIT_FOREVER_REL); | 352 | GNUNET_CLIENT_receive(dns_connection, &dns_answer_handler, NULL, GNUNET_TIME_UNIT_FOREVER_REL); |
303 | if (mycls.head != NULL) | 353 | if (head != NULL) |
304 | /* struct GNUNET_CLIENT_TransmitHandle* th = */ GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, ntohs(mycls.head->pkt.hdr.size), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); | 354 | /* struct GNUNET_CLIENT_TransmitHandle* th = */ GNUNET_CLIENT_notify_transmit_ready(dns_connection, ntohs(head->pkt.hdr.size), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); |
305 | } | 355 | } |
306 | 356 | ||
307 | static void | 357 | static void |
@@ -332,9 +382,9 @@ process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { | |||
332 | 382 | ||
333 | memcpy(&list->pkt, pkt, htons(pkt->hdr.size)); | 383 | memcpy(&list->pkt, pkt, htons(pkt->hdr.size)); |
334 | 384 | ||
335 | GNUNET_CONTAINER_DLL_insert_after(mycls.answer_proc_head, mycls.answer_proc_tail, mycls.answer_proc_tail, list); | 385 | GNUNET_CONTAINER_DLL_insert_after(answer_proc_head, answer_proc_tail, answer_proc_tail, list); |
336 | 386 | ||
337 | GNUNET_SCHEDULER_add_write_file (mycls.sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls.fh_to_helper, &helper_write, NULL); | 387 | GNUNET_SCHEDULER_add_write_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, fh_to_helper, &helper_write, NULL); |
338 | 388 | ||
339 | return; | 389 | return; |
340 | } | 390 | } |
@@ -344,9 +394,9 @@ dns_answer_handler(void* cls, const struct GNUNET_MessageHeader *msg) | |||
344 | { | 394 | { |
345 | if (msg == NULL) | 395 | if (msg == NULL) |
346 | { | 396 | { |
347 | GNUNET_CLIENT_disconnect(mycls.dns_connection, GNUNET_NO); | 397 | GNUNET_CLIENT_disconnect(dns_connection, GNUNET_NO); |
348 | mycls.dns_connection = NULL; | 398 | dns_connection = NULL; |
349 | GNUNET_SCHEDULER_add_delayed (mycls.sched, | 399 | GNUNET_SCHEDULER_add_delayed (sched, |
350 | GNUNET_TIME_UNIT_SECONDS, | 400 | GNUNET_TIME_UNIT_SECONDS, |
351 | &reconnect_to_service_dns, | 401 | &reconnect_to_service_dns, |
352 | NULL); | 402 | NULL); |
@@ -356,9 +406,9 @@ dns_answer_handler(void* cls, const struct GNUNET_MessageHeader *msg) | |||
356 | if (msg->type != htons(GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS)) | 406 | if (msg->type != htons(GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS)) |
357 | { | 407 | { |
358 | GNUNET_break (0); | 408 | GNUNET_break (0); |
359 | GNUNET_CLIENT_disconnect(mycls.dns_connection, GNUNET_NO); | 409 | GNUNET_CLIENT_disconnect(dns_connection, GNUNET_NO); |
360 | mycls.dns_connection = NULL; | 410 | dns_connection = NULL; |
361 | GNUNET_SCHEDULER_add_now (mycls.sched, | 411 | GNUNET_SCHEDULER_add_now (sched, |
362 | &reconnect_to_service_dns, | 412 | &reconnect_to_service_dns, |
363 | NULL); | 413 | NULL); |
364 | return; | 414 | return; |
@@ -367,8 +417,8 @@ dns_answer_handler(void* cls, const struct GNUNET_MessageHeader *msg) | |||
367 | 417 | ||
368 | memcpy(pkt, msg, ntohs(msg->size)); | 418 | memcpy(pkt, msg, ntohs(msg->size)); |
369 | 419 | ||
370 | GNUNET_SCHEDULER_add_now(mycls.sched, process_answer, pkt); | 420 | GNUNET_SCHEDULER_add_now(sched, process_answer, pkt); |
371 | GNUNET_CLIENT_receive(mycls.dns_connection, &dns_answer_handler, NULL, GNUNET_TIME_UNIT_FOREVER_REL); | 421 | GNUNET_CLIENT_receive(dns_connection, &dns_answer_handler, NULL, GNUNET_TIME_UNIT_FOREVER_REL); |
372 | } | 422 | } |
373 | 423 | ||
374 | /** | 424 | /** |
@@ -382,15 +432,15 @@ dns_answer_handler(void* cls, const struct GNUNET_MessageHeader *msg) | |||
382 | */ | 432 | */ |
383 | static void | 433 | static void |
384 | run (void *cls, | 434 | run (void *cls, |
385 | struct GNUNET_SCHEDULER_Handle *sched, | 435 | struct GNUNET_SCHEDULER_Handle *sched_, |
386 | char *const *args, | 436 | char *const *args, |
387 | const char *cfgfile, | 437 | const char *cfgfile, |
388 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 438 | const struct GNUNET_CONFIGURATION_Handle *cfg_) |
389 | { | 439 | { |
390 | mycls.sched = sched; | 440 | sched = sched_; |
391 | mycls.mst = GNUNET_SERVER_mst_create(&message_token, NULL); | 441 | mst = GNUNET_SERVER_mst_create(&message_token, NULL); |
392 | mycls.cfg = cfg; | 442 | cfg = cfg_; |
393 | mycls.restart_hijack = 0; | 443 | restart_hijack = 0; |
394 | GNUNET_SCHEDULER_add_now (sched, &reconnect_to_service_dns, NULL); | 444 | GNUNET_SCHEDULER_add_now (sched, &reconnect_to_service_dns, NULL); |
395 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); | 445 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); |
396 | GNUNET_SCHEDULER_add_now (sched, start_helper_and_schedule, NULL); | 446 | GNUNET_SCHEDULER_add_now (sched, start_helper_and_schedule, NULL); |
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 9732f90c4..c3d136406 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c | |||
@@ -39,21 +39,18 @@ | |||
39 | #include "gnunet_crypto_lib.h" | 39 | #include "gnunet_crypto_lib.h" |
40 | #include "gnunet_signatures.h" | 40 | #include "gnunet_signatures.h" |
41 | 41 | ||
42 | struct dns_cls { | 42 | static struct GNUNET_SCHEDULER_Handle *sched; |
43 | struct GNUNET_SCHEDULER_Handle *sched; | ||
44 | 43 | ||
45 | struct GNUNET_NETWORK_Handle *dnsout; | 44 | static struct GNUNET_NETWORK_Handle *dnsout; |
46 | 45 | ||
47 | struct GNUNET_DHT_Handle *dht; | 46 | static struct GNUNET_DHT_Handle *dht; |
48 | 47 | ||
49 | unsigned short dnsoutport; | 48 | static unsigned short dnsoutport; |
50 | 49 | ||
51 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 50 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
52 | 51 | ||
53 | struct answer_packet_list *head; | 52 | static struct answer_packet_list *head; |
54 | struct answer_packet_list *tail; | 53 | static struct answer_packet_list *tail; |
55 | }; | ||
56 | static struct dns_cls mycls; | ||
57 | 54 | ||
58 | struct dns_query_id_state { | 55 | struct dns_query_id_state { |
59 | unsigned valid:1; | 56 | unsigned valid:1; |
@@ -163,7 +160,7 @@ void receive_dht(void *cls, | |||
163 | 160 | ||
164 | answer->pkt.addroffset = htons((unsigned short)((unsigned long)(&drec_data->data)-(unsigned long)(&answer->pkt))); | 161 | answer->pkt.addroffset = htons((unsigned short)((unsigned long)(&drec_data->data)-(unsigned long)(&answer->pkt))); |
165 | 162 | ||
166 | GNUNET_CONTAINER_DLL_insert_after(mycls.head, mycls.tail, mycls.tail, answer); | 163 | GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, answer); |
167 | 164 | ||
168 | GNUNET_SERVER_notify_transmit_ready(query_states[id].client, | 165 | GNUNET_SERVER_notify_transmit_ready(query_states[id].client, |
169 | len, | 166 | len, |
@@ -178,8 +175,8 @@ void receive_dht(void *cls, | |||
178 | * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS | 175 | * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS |
179 | */ | 176 | */ |
180 | void rehijack(void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { | 177 | void rehijack(void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { |
181 | unhijack(mycls.dnsoutport); | 178 | unhijack(dnsoutport); |
182 | hijack(mycls.dnsoutport); | 179 | hijack(dnsoutport); |
183 | } | 180 | } |
184 | 181 | ||
185 | /** | 182 | /** |
@@ -212,7 +209,7 @@ void receive_query(void *cls, struct GNUNET_SERVER_Client *client, const struct | |||
212 | struct receive_dht_cls* cls = GNUNET_malloc(sizeof(struct receive_dht_cls)); | 209 | struct receive_dht_cls* cls = GNUNET_malloc(sizeof(struct receive_dht_cls)); |
213 | cls->id = dns->s.id; | 210 | cls->id = dns->s.id; |
214 | 211 | ||
215 | cls->handle = GNUNET_DHT_get_start(mycls.dht, | 212 | cls->handle = GNUNET_DHT_get_start(dht, |
216 | GNUNET_TIME_UNIT_MINUTES, | 213 | GNUNET_TIME_UNIT_MINUTES, |
217 | GNUNET_BLOCK_TYPE_DNS, | 214 | GNUNET_BLOCK_TYPE_DNS, |
218 | &key, | 215 | &key, |
@@ -235,26 +232,26 @@ void receive_query(void *cls, struct GNUNET_SERVER_Client *client, const struct | |||
235 | dest.sin_port = htons(53); | 232 | dest.sin_port = htons(53); |
236 | dest.sin_addr.s_addr = pkt->orig_to; | 233 | dest.sin_addr.s_addr = pkt->orig_to; |
237 | 234 | ||
238 | /* int r = */ GNUNET_NETWORK_socket_sendto(mycls.dnsout, dns, ntohs(pkt->hdr.size) - sizeof(struct query_packet) + 1, (struct sockaddr*) &dest, sizeof dest); | 235 | /* int r = */ GNUNET_NETWORK_socket_sendto(dnsout, dns, ntohs(pkt->hdr.size) - sizeof(struct query_packet) + 1, (struct sockaddr*) &dest, sizeof dest); |
239 | 236 | ||
240 | out: | 237 | out: |
241 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 238 | GNUNET_SERVER_receive_done(client, GNUNET_OK); |
242 | } | 239 | } |
243 | 240 | ||
244 | size_t send_answer(void* cls, size_t size, void* buf) { | 241 | size_t send_answer(void* cls, size_t size, void* buf) { |
245 | struct answer_packet_list* query = mycls.head; | 242 | struct answer_packet_list* query = head; |
246 | size_t len = ntohs(query->pkt.hdr.size); | 243 | size_t len = ntohs(query->pkt.hdr.size); |
247 | 244 | ||
248 | GNUNET_assert(len <= size); | 245 | GNUNET_assert(len <= size); |
249 | 246 | ||
250 | memcpy(buf, &query->pkt.hdr, len); | 247 | memcpy(buf, &query->pkt.hdr, len); |
251 | 248 | ||
252 | GNUNET_CONTAINER_DLL_remove (mycls.head, mycls.tail, query); | 249 | GNUNET_CONTAINER_DLL_remove (head, tail, query); |
253 | 250 | ||
254 | GNUNET_free(query); | 251 | GNUNET_free(query); |
255 | 252 | ||
256 | if (mycls.head != NULL) { | 253 | if (head != NULL) { |
257 | GNUNET_SERVER_notify_transmit_ready(cls, ntohs(mycls.head->pkt.hdr.size), GNUNET_TIME_UNIT_FOREVER_REL, &send_answer, cls); | 254 | GNUNET_SERVER_notify_transmit_ready(cls, ntohs(head->pkt.hdr.size), GNUNET_TIME_UNIT_FOREVER_REL, &send_answer, cls); |
258 | } | 255 | } |
259 | 256 | ||
260 | return len; | 257 | return len; |
@@ -272,7 +269,7 @@ static void read_response (void *cls, const struct GNUNET_SCHEDULER_TaskContext | |||
272 | unsigned int addrlen = sizeof addr; | 269 | unsigned int addrlen = sizeof addr; |
273 | 270 | ||
274 | int r; | 271 | int r; |
275 | r = GNUNET_NETWORK_socket_recvfrom(mycls.dnsout, buf, 65536, (struct sockaddr*)&addr, &addrlen); | 272 | r = GNUNET_NETWORK_socket_recvfrom(dnsout, buf, 65536, (struct sockaddr*)&addr, &addrlen); |
276 | 273 | ||
277 | /* if (r < 0) TODO */ | 274 | /* if (r < 0) TODO */ |
278 | 275 | ||
@@ -289,12 +286,12 @@ static void read_response (void *cls, const struct GNUNET_SCHEDULER_TaskContext | |||
289 | answer->pkt.dst_port = query_states[dns->s.id].local_port; | 286 | answer->pkt.dst_port = query_states[dns->s.id].local_port; |
290 | memcpy(answer->pkt.data, buf, r); | 287 | memcpy(answer->pkt.data, buf, r); |
291 | 288 | ||
292 | GNUNET_CONTAINER_DLL_insert_after(mycls.head, mycls.tail, mycls.tail, answer); | 289 | GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, answer); |
293 | 290 | ||
294 | /* struct GNUNET_CONNECTION_TransmitHandle* th = */ GNUNET_SERVER_notify_transmit_ready(query_states[dns->s.id].client, len, GNUNET_TIME_UNIT_FOREVER_REL, &send_answer, query_states[dns->s.id].client); | 291 | /* struct GNUNET_CONNECTION_TransmitHandle* th = */ GNUNET_SERVER_notify_transmit_ready(query_states[dns->s.id].client, len, GNUNET_TIME_UNIT_FOREVER_REL, &send_answer, query_states[dns->s.id].client); |
295 | } | 292 | } |
296 | 293 | ||
297 | GNUNET_SCHEDULER_add_read_net(mycls.sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls.dnsout, &read_response, NULL); | 294 | GNUNET_SCHEDULER_add_read_net(sched, GNUNET_TIME_UNIT_FOREVER_REL, dnsout, &read_response, NULL); |
298 | } | 295 | } |
299 | 296 | ||
300 | 297 | ||
@@ -308,8 +305,8 @@ static void | |||
308 | cleanup_task (void *cls, | 305 | cleanup_task (void *cls, |
309 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 306 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
310 | { | 307 | { |
311 | unhijack(mycls.dnsoutport); | 308 | unhijack(dnsoutport); |
312 | GNUNET_DHT_disconnect(mycls.dht); | 309 | GNUNET_DHT_disconnect(dht); |
313 | } | 310 | } |
314 | 311 | ||
315 | static void | 312 | static void |
@@ -330,7 +327,7 @@ publish_name (void *cls, | |||
330 | GNUNET_CRYPTO_hash(name, strlen(name)+1, &data.service_descriptor); | 327 | GNUNET_CRYPTO_hash(name, strlen(name)+1, &data.service_descriptor); |
331 | 328 | ||
332 | char* keyfile; | 329 | char* keyfile; |
333 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(mycls.cfg, "GNUNETD", | 330 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, "GNUNETD", |
334 | "HOSTKEY", &keyfile)) | 331 | "HOSTKEY", &keyfile)) |
335 | { | 332 | { |
336 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n"); | 333 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n"); |
@@ -359,7 +356,7 @@ publish_name (void *cls, | |||
359 | 356 | ||
360 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x\n", *((unsigned int*)&data.service_descriptor)); | 357 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x\n", *((unsigned int*)&data.service_descriptor)); |
361 | 358 | ||
362 | GNUNET_DHT_put(mycls.dht, | 359 | GNUNET_DHT_put(dht, |
363 | &data.service_descriptor, | 360 | &data.service_descriptor, |
364 | GNUNET_DHT_RO_NONE, | 361 | GNUNET_DHT_RO_NONE, |
365 | GNUNET_BLOCK_TYPE_DNS, | 362 | GNUNET_BLOCK_TYPE_DNS, |
@@ -370,7 +367,7 @@ publish_name (void *cls, | |||
370 | NULL, | 367 | NULL, |
371 | NULL); | 368 | NULL); |
372 | 369 | ||
373 | GNUNET_SCHEDULER_add_delayed (mycls.sched, GNUNET_TIME_UNIT_HOURS, publish_name, NULL); | 370 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_UNIT_HOURS, publish_name, NULL); |
374 | } | 371 | } |
375 | 372 | ||
376 | /** | 373 | /** |
@@ -381,9 +378,9 @@ publish_name (void *cls, | |||
381 | */ | 378 | */ |
382 | static void | 379 | static void |
383 | run (void *cls, | 380 | run (void *cls, |
384 | struct GNUNET_SCHEDULER_Handle *sched, | 381 | struct GNUNET_SCHEDULER_Handle *sched_, |
385 | struct GNUNET_SERVER_Handle *server, | 382 | struct GNUNET_SERVER_Handle *server, |
386 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 383 | const struct GNUNET_CONFIGURATION_Handle *cfg_) |
387 | { | 384 | { |
388 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 385 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
389 | /* callback, cls, type, size */ | 386 | /* callback, cls, type, size */ |
@@ -392,7 +389,8 @@ run (void *cls, | |||
392 | {NULL, NULL, 0, 0} | 389 | {NULL, NULL, 0, 0} |
393 | }; | 390 | }; |
394 | 391 | ||
395 | mycls.cfg = cfg; | 392 | cfg = cfg_; |
393 | sched = sched_; | ||
396 | 394 | ||
397 | { | 395 | { |
398 | int i; | 396 | int i; |
@@ -401,18 +399,17 @@ run (void *cls, | |||
401 | } | 399 | } |
402 | } | 400 | } |
403 | 401 | ||
404 | mycls.dht = GNUNET_DHT_connect(sched, cfg, 1024); | 402 | dht = GNUNET_DHT_connect(sched, cfg, 1024); |
405 | 403 | ||
406 | struct sockaddr_in addr; | 404 | struct sockaddr_in addr; |
407 | 405 | ||
408 | mycls.sched = sched; | 406 | dnsout = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0); |
409 | mycls.dnsout = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0); | 407 | if (dnsout == NULL) |
410 | if (mycls.dnsout == NULL) | ||
411 | return; | 408 | return; |
412 | memset(&addr, 0, sizeof(struct sockaddr_in)); | 409 | memset(&addr, 0, sizeof(struct sockaddr_in)); |
413 | 410 | ||
414 | int err = GNUNET_NETWORK_socket_bind (mycls.dnsout, | 411 | int err = GNUNET_NETWORK_socket_bind (dnsout, |
415 | (struct sockaddr*)&addr, | 412 | (struct sockaddr*)&addr, |
416 | sizeof(struct sockaddr_in)); | 413 | sizeof(struct sockaddr_in)); |
417 | 414 | ||
418 | if (err != GNUNET_YES) { | 415 | if (err != GNUNET_YES) { |
@@ -420,17 +417,17 @@ run (void *cls, | |||
420 | return; | 417 | return; |
421 | } | 418 | } |
422 | socklen_t addrlen = sizeof(struct sockaddr_in); | 419 | socklen_t addrlen = sizeof(struct sockaddr_in); |
423 | err = getsockname(GNUNET_NETWORK_get_fd(mycls.dnsout), | 420 | err = getsockname(GNUNET_NETWORK_get_fd(dnsout), |
424 | (struct sockaddr*) &addr, | 421 | (struct sockaddr*) &addr, |
425 | &addrlen); | 422 | &addrlen); |
426 | 423 | ||
427 | mycls.dnsoutport = htons(addr.sin_port); | 424 | dnsoutport = htons(addr.sin_port); |
428 | 425 | ||
429 | hijack(htons(addr.sin_port)); | 426 | hijack(htons(addr.sin_port)); |
430 | 427 | ||
431 | GNUNET_SCHEDULER_add_now (mycls.sched, publish_name, NULL); | 428 | GNUNET_SCHEDULER_add_now (sched, publish_name, NULL); |
432 | 429 | ||
433 | GNUNET_SCHEDULER_add_read_net(sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls.dnsout, &read_response, NULL); | 430 | GNUNET_SCHEDULER_add_read_net(sched, GNUNET_TIME_UNIT_FOREVER_REL, dnsout, &read_response, NULL); |
434 | 431 | ||
435 | GNUNET_SERVER_add_handlers (server, handlers); | 432 | GNUNET_SERVER_add_handlers (server, handlers); |
436 | GNUNET_SCHEDULER_add_delayed (sched, | 433 | GNUNET_SCHEDULER_add_delayed (sched, |