diff options
author | Philipp Tölke <toelke@in.tum.de> | 2010-07-20 22:22:03 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2010-07-20 22:22:03 +0000 |
commit | f2b9b53569e26dbbd5aab101c0e58e4cc31654fe (patch) | |
tree | 7f8dd46673f151c270d51108d355a2624d97aeab /src/vpn/gnunet-daemon-vpn.c | |
parent | f015c4a688d52ca75fe83817ffe60a246a73cc0a (diff) | |
download | gnunet-f2b9b53569e26dbbd5aab101c0e58e4cc31654fe.tar.gz gnunet-f2b9b53569e26dbbd5aab101c0e58e4cc31654fe.zip |
Use the mst to read packets
Diffstat (limited to 'src/vpn/gnunet-daemon-vpn.c')
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 2977b4098..2c38e6363 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "gnunet-vpn-pretty-print.h" | 32 | #include "gnunet-vpn-pretty-print.h" |
33 | #include "gnunet_common.h" | 33 | #include "gnunet_common.h" |
34 | #include "gnunet_protocols.h" | 34 | #include "gnunet_protocols.h" |
35 | #include "gnunet_server_lib.h" | ||
35 | /* #include "gnunet_template_service.h" */ | 36 | /* #include "gnunet_template_service.h" */ |
36 | 37 | ||
37 | /** | 38 | /** |
@@ -44,6 +45,8 @@ struct vpn_cls { | |||
44 | struct GNUNET_DISK_PipeHandle* helper_out; // To the helper | 45 | struct GNUNET_DISK_PipeHandle* helper_out; // To the helper |
45 | const struct GNUNET_DISK_FileHandle* fh_from_helper; | 46 | const struct GNUNET_DISK_FileHandle* fh_from_helper; |
46 | 47 | ||
48 | struct GNUNET_SERVER_MessageStreamTokenizer* mst; | ||
49 | |||
47 | struct GNUNET_SCHEDULER_Handle *sched; | 50 | struct GNUNET_SCHEDULER_Handle *sched; |
48 | 51 | ||
49 | pid_t helper_pid; | 52 | pid_t helper_pid; |
@@ -88,38 +91,27 @@ static void restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext* | |||
88 | 91 | ||
89 | static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) { | 92 | static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) { |
90 | struct vpn_cls* mycls = (struct vpn_cls*) cls; | 93 | struct vpn_cls* mycls = (struct vpn_cls*) cls; |
91 | struct GNUNET_MessageHeader hdr = { .size = 0, .type = 0 }; | 94 | char buf[65535]; |
92 | |||
93 | int r = 0; | ||
94 | 95 | ||
95 | if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) | 96 | if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) |
96 | return; | 97 | return; |
97 | 98 | ||
98 | while (r < sizeof(struct GNUNET_MessageHeader)) { | 99 | int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &buf, 65535); |
99 | int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &hdr, sizeof(struct GNUNET_MessageHeader)); | 100 | if (t<=0) { |
100 | if (t<=0) { | 101 | fprintf(stderr, "Read error for header: %m\n"); |
101 | fprintf(stderr, "Read error for header: %m\n"); | 102 | GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, cls); |
102 | GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, cls); | 103 | return; |
103 | return; | ||
104 | } | ||
105 | r += t; | ||
106 | } | 104 | } |
107 | 105 | ||
108 | struct suid_packet *pkt = (struct suid_packet*) GNUNET_malloc(ntohs(hdr.size)); | 106 | /* FIXME */ GNUNET_SERVER_mst_receive(mycls->mst, NULL, buf, t, 0, 0); |
109 | 107 | ||
110 | memcpy(pkt, &hdr, sizeof(struct GNUNET_MessageHeader)); | 108 | GNUNET_SCHEDULER_add_read_file (mycls->sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls->fh_from_helper, &helper_read, mycls); |
109 | } | ||
111 | 110 | ||
112 | while (r < ntohs(pkt->hdr.size)) { | 111 | static void message_token(void *cls, void *client, const struct GNUNET_MessageHeader *message) { |
113 | int t = GNUNET_DISK_file_read(mycls->fh_from_helper, (unsigned char*)pkt + r, ntohs(pkt->hdr.size) - r); | 112 | if (ntohs(message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) return; |
114 | if (t<=0) { | ||
115 | fprintf(stderr, "Read error for data: %m\n"); | ||
116 | GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, cls); | ||
117 | return; | ||
118 | } | ||
119 | r += t; | ||
120 | } | ||
121 | 113 | ||
122 | struct ip6_pkt *pkt6 = (struct ip6_pkt*) pkt; | 114 | struct ip6_pkt *pkt6 = (struct ip6_pkt*) message; |
123 | struct ip6_tcp *pkt6_tcp; | 115 | struct ip6_tcp *pkt6_tcp; |
124 | struct ip6_udp *pkt6_udp; | 116 | struct ip6_udp *pkt6_udp; |
125 | 117 | ||
@@ -138,9 +130,6 @@ static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* ts | |||
138 | break; | 130 | break; |
139 | } | 131 | } |
140 | 132 | ||
141 | GNUNET_free(pkt); | ||
142 | |||
143 | GNUNET_SCHEDULER_add_read_file (mycls->sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls->fh_from_helper, &helper_read, mycls); | ||
144 | } | 133 | } |
145 | 134 | ||
146 | /** | 135 | /** |
@@ -163,6 +152,8 @@ run (void *cls, | |||
163 | 152 | ||
164 | mycls->sched = sched; | 153 | mycls->sched = sched; |
165 | 154 | ||
155 | mycls->mst = GNUNET_SERVER_mst_create(&message_token, mycls); | ||
156 | |||
166 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); | 157 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); |
167 | 158 | ||
168 | start_helper_and_schedule(mycls); | 159 | start_helper_and_schedule(mycls); |