aboutsummaryrefslogtreecommitdiff
path: root/src/vpn/gnunet-daemon-vpn.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-11-05 18:21:50 +0000
committerNathan S. Evans <evans@in.tum.de>2010-11-05 18:21:50 +0000
commit75a33a1499cf60ea4364c9aa673816629a6c1413 (patch)
tree0620da4312bb04de4d7b65074fdd3b0c3dd6cc0e /src/vpn/gnunet-daemon-vpn.c
parent7217c601ad30760872823193d62307e7a335d226 (diff)
downloadgnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.tar.gz
gnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.zip
big scheduler refactoring, expect some issues
Diffstat (limited to 'src/vpn/gnunet-daemon-vpn.c')
-rw-r--r--src/vpn/gnunet-daemon-vpn.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c
index d4ff33b9c..f6a20f8a6 100644
--- a/src/vpn/gnunet-daemon-vpn.c
+++ b/src/vpn/gnunet-daemon-vpn.c
@@ -21,7 +21,7 @@
21/** 21/**
22 * @file vpn/gnunet-daemon-vpn.c 22 * @file vpn/gnunet-daemon-vpn.c
23 * @brief 23 * @brief
24 * @author Philipp Tรถlke 24 * @author Philipp Toelke
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_getopt_lib.h" 27#include "gnunet_getopt_lib.h"
@@ -44,11 +44,6 @@
44static int ret; 44static int ret;
45 45
46/** 46/**
47 * The scheduler to use throughout the daemon
48 */
49static struct GNUNET_SCHEDULER_Handle *sched;
50
51/**
52 * The configuration to use 47 * The configuration to use
53 */ 48 */
54static const struct GNUNET_CONFIGURATION_Handle *cfg; 49static const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -222,7 +217,7 @@ start_helper_and_schedule(void *cls,
222 restart_hijack = 1; 217 restart_hijack = 1;
223 GNUNET_CLIENT_notify_transmit_ready(dns_connection, sizeof(struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); 218 GNUNET_CLIENT_notify_transmit_ready(dns_connection, sizeof(struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL);
224 219
225 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, fh_from_helper, &helper_read, NULL); 220 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fh_from_helper, &helper_read, NULL);
226} 221}
227 222
228/** 223/**
@@ -240,7 +235,7 @@ restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) {
240 GNUNET_DISK_pipe_close(helper_out); 235 GNUNET_DISK_pipe_close(helper_out);
241 236
242 /* Restart the helper */ 237 /* Restart the helper */
243 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_UNIT_SECONDS, start_helper_and_schedule, NULL); 238 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, start_helper_and_schedule, NULL);
244} 239}
245 240
246/** 241/**
@@ -259,13 +254,13 @@ helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) {
259 /* On read-error, restart the helper */ 254 /* On read-error, restart the helper */
260 if (t<=0) { 255 if (t<=0) {
261 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read error for header from vpn-helper: %m\n"); 256 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read error for header from vpn-helper: %m\n");
262 GNUNET_SCHEDULER_add_now(sched, restart_helper, cls); 257 GNUNET_SCHEDULER_add_now(restart_helper, cls);
263 return; 258 return;
264 } 259 }
265 260
266 /* FIXME */ GNUNET_SERVER_mst_receive(mst, NULL, buf, t, 0, 0); 261 /* FIXME */ GNUNET_SERVER_mst_receive(mst, NULL, buf, t, 0, 0);
267 262
268 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, fh_from_helper, &helper_read, NULL); 263 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fh_from_helper, &helper_read, NULL);
269} 264}
270 265
271/** 266/**
@@ -343,8 +338,7 @@ helper_write(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) {
343 338
344 /* if more packets are available, reschedule */ 339 /* if more packets are available, reschedule */
345 if (answer_proc_head != NULL) 340 if (answer_proc_head != NULL)
346 GNUNET_SCHEDULER_add_write_file (sched, 341 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
347 GNUNET_TIME_UNIT_FOREVER_REL,
348 fh_to_helper, 342 fh_to_helper,
349 &helper_write, 343 &helper_write,
350 NULL); 344 NULL);
@@ -429,7 +423,7 @@ message_token(void *cls,
429 memcpy(pkt6_icmp, pkt6, ntohs(pkt6->shdr.size)); 423 memcpy(pkt6_icmp, pkt6, ntohs(pkt6->shdr.size));
430 /* If this packet is an icmp-echo-request and a mapping exists, answer */ 424 /* If this packet is an icmp-echo-request and a mapping exists, answer */
431 if (pkt6_icmp->icmp_hdr.type == 0x80 && address_mapping_exists(pkt6->ip6_hdr.sadr)) 425 if (pkt6_icmp->icmp_hdr.type == 0x80 && address_mapping_exists(pkt6->ip6_hdr.sadr))
432 GNUNET_SCHEDULER_add_now(sched, &send_icmp_response, pkt6_icmp); 426 GNUNET_SCHEDULER_add_now(&send_icmp_response, pkt6_icmp);
433 break; 427 break;
434 } 428 }
435 } 429 }
@@ -477,7 +471,7 @@ connect_to_service_dns (void *cls,
477 return; 471 return;
478 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting to service-dns\n"); 472 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting to service-dns\n");
479 GNUNET_assert (dns_connection == NULL); 473 GNUNET_assert (dns_connection == NULL);
480 dns_connection = GNUNET_CLIENT_connect (sched, "dns", cfg); 474 dns_connection = GNUNET_CLIENT_connect ("dns", cfg);
481 GNUNET_CLIENT_receive(dns_connection, &dns_answer_handler, NULL, GNUNET_TIME_UNIT_FOREVER_REL); 475 GNUNET_CLIENT_receive(dns_connection, &dns_answer_handler, NULL, GNUNET_TIME_UNIT_FOREVER_REL);
482 476
483 /* If a packet is already in the list, schedule to send it */ 477 /* If a packet is already in the list, schedule to send it */
@@ -565,7 +559,7 @@ process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) {
565 559
566 GNUNET_CONTAINER_DLL_insert_after(answer_proc_head, answer_proc_tail, answer_proc_tail, list); 560 GNUNET_CONTAINER_DLL_insert_after(answer_proc_head, answer_proc_tail, answer_proc_tail, list);
567 561
568 GNUNET_SCHEDULER_add_write_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, fh_to_helper, &helper_write, NULL); 562 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fh_to_helper, &helper_write, NULL);
569 563
570 return; 564 return;
571} 565}
@@ -581,8 +575,7 @@ dns_answer_handler(void* cls, const struct GNUNET_MessageHeader *msg) {
581 { 575 {
582 GNUNET_CLIENT_disconnect(dns_connection, GNUNET_NO); 576 GNUNET_CLIENT_disconnect(dns_connection, GNUNET_NO);
583 dns_connection = NULL; 577 dns_connection = NULL;
584 GNUNET_SCHEDULER_add_delayed (sched, 578 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
585 GNUNET_TIME_UNIT_SECONDS,
586 &connect_to_service_dns, 579 &connect_to_service_dns,
587 NULL); 580 NULL);
588 return; 581 return;
@@ -594,8 +587,7 @@ dns_answer_handler(void* cls, const struct GNUNET_MessageHeader *msg) {
594 GNUNET_break (0); 587 GNUNET_break (0);
595 GNUNET_CLIENT_disconnect(dns_connection, GNUNET_NO); 588 GNUNET_CLIENT_disconnect(dns_connection, GNUNET_NO);
596 dns_connection = NULL; 589 dns_connection = NULL;
597 GNUNET_SCHEDULER_add_now (sched, 590 GNUNET_SCHEDULER_add_now (&connect_to_service_dns,
598 &connect_to_service_dns,
599 NULL); 591 NULL);
600 return; 592 return;
601 } 593 }
@@ -603,7 +595,7 @@ dns_answer_handler(void* cls, const struct GNUNET_MessageHeader *msg) {
603 595
604 memcpy(pkt, msg, ntohs(msg->size)); 596 memcpy(pkt, msg, ntohs(msg->size));
605 597
606 GNUNET_SCHEDULER_add_now(sched, process_answer, pkt); 598 GNUNET_SCHEDULER_add_now(process_answer, pkt);
607 GNUNET_CLIENT_receive(dns_connection, &dns_answer_handler, NULL, GNUNET_TIME_UNIT_FOREVER_REL); 599 GNUNET_CLIENT_receive(dns_connection, &dns_answer_handler, NULL, GNUNET_TIME_UNIT_FOREVER_REL);
608} 600}
609 601
@@ -611,24 +603,21 @@ dns_answer_handler(void* cls, const struct GNUNET_MessageHeader *msg) {
611 * Main function that will be run by the scheduler. 603 * Main function that will be run by the scheduler.
612 * 604 *
613 * @param cls closure 605 * @param cls closure
614 * @param sched the scheduler to use
615 * @param args remaining command-line arguments 606 * @param args remaining command-line arguments
616 * @param cfgfile name of the configuration file used (for saving, can be NULL!) 607 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
617 * @param cfg configuration 608 * @param cfg configuration
618 */ 609 */
619static void 610static void
620run (void *cls, 611run (void *cls,
621 struct GNUNET_SCHEDULER_Handle *sched_,
622 char *const *args, 612 char *const *args,
623 const char *cfgfile, 613 const char *cfgfile,
624 const struct GNUNET_CONFIGURATION_Handle *cfg_) { 614 const struct GNUNET_CONFIGURATION_Handle *cfg_) {
625 sched = sched_;
626 mst = GNUNET_SERVER_mst_create(&message_token, NULL); 615 mst = GNUNET_SERVER_mst_create(&message_token, NULL);
627 cfg = cfg_; 616 cfg = cfg_;
628 restart_hijack = 0; 617 restart_hijack = 0;
629 GNUNET_SCHEDULER_add_now (sched, connect_to_service_dns, NULL); 618 GNUNET_SCHEDULER_add_now (connect_to_service_dns, NULL);
630 GNUNET_SCHEDULER_add_now (sched, start_helper_and_schedule, NULL); 619 GNUNET_SCHEDULER_add_now (start_helper_and_schedule, NULL);
631 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); 620 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
632} 621}
633 622
634/** 623/**