gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r12303 - gnunet/src/vpn


From: gnunet
Subject: [GNUnet-SVN] r12303 - gnunet/src/vpn
Date: Wed, 21 Jul 2010 00:22:03 +0200

Author: toelke
Date: 2010-07-21 00:22:03 +0200 (Wed, 21 Jul 2010)
New Revision: 12303

Modified:
   gnunet/src/vpn/gnunet-daemon-vpn.c
Log:
Use the mst to read packets

Modified: gnunet/src/vpn/gnunet-daemon-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.c  2010-07-20 22:22:01 UTC (rev 12302)
+++ gnunet/src/vpn/gnunet-daemon-vpn.c  2010-07-20 22:22:03 UTC (rev 12303)
@@ -32,6 +32,7 @@
 #include "gnunet-vpn-pretty-print.h"
 #include "gnunet_common.h"
 #include "gnunet_protocols.h"
+#include "gnunet_server_lib.h"
 /* #include "gnunet_template_service.h" */
 
 /**
@@ -44,6 +45,8 @@
        struct GNUNET_DISK_PipeHandle* helper_out; // To the helper
        const struct GNUNET_DISK_FileHandle* fh_from_helper;
 
+       struct GNUNET_SERVER_MessageStreamTokenizer* mst;
+
        struct GNUNET_SCHEDULER_Handle *sched;
 
        pid_t helper_pid;
@@ -88,38 +91,27 @@
 
 static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* 
tsdkctx) {
        struct vpn_cls* mycls = (struct vpn_cls*) cls;
-       struct GNUNET_MessageHeader hdr = { .size = 0, .type = 0 };
+       char buf[65535];
 
-       int r = 0;
-
        if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)
                return;
 
-       while (r < sizeof(struct GNUNET_MessageHeader)) {
-               int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &hdr, 
sizeof(struct GNUNET_MessageHeader));
-               if (t<=0) {
-                       fprintf(stderr, "Read error for header: %m\n");
-                       GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, 
cls);
-                       return;
-               }
-               r += t;
+       int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &buf, 65535);
+       if (t<=0) {
+               fprintf(stderr, "Read error for header: %m\n");
+               GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, cls);
+               return;
        }
 
-       struct suid_packet *pkt = (struct suid_packet*) 
GNUNET_malloc(ntohs(hdr.size));
+       /* FIXME */ GNUNET_SERVER_mst_receive(mycls->mst, NULL, buf, t, 0, 0);
 
-       memcpy(pkt, &hdr, sizeof(struct GNUNET_MessageHeader));
+       GNUNET_SCHEDULER_add_read_file (mycls->sched, 
GNUNET_TIME_UNIT_FOREVER_REL, mycls->fh_from_helper, &helper_read, mycls);
+}
 
-       while (r < ntohs(pkt->hdr.size)) {
-               int t = GNUNET_DISK_file_read(mycls->fh_from_helper, (unsigned 
char*)pkt + r, ntohs(pkt->hdr.size) - r);
-               if (t<=0) {
-                       fprintf(stderr, "Read error for data: %m\n");
-                       GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, 
cls);
-                       return;
-               }
-               r += t;
-       }
+static void message_token(void *cls, void *client, const struct 
GNUNET_MessageHeader *message) {
+       if (ntohs(message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) return;
 
-       struct ip6_pkt *pkt6 = (struct ip6_pkt*) pkt;
+       struct ip6_pkt *pkt6 = (struct ip6_pkt*) message;
        struct ip6_tcp *pkt6_tcp;
        struct ip6_udp *pkt6_udp;
 
@@ -138,9 +130,6 @@
                        break;
        }
 
-       GNUNET_free(pkt);
-
-       GNUNET_SCHEDULER_add_read_file (mycls->sched, 
GNUNET_TIME_UNIT_FOREVER_REL, mycls->fh_from_helper, &helper_read, mycls);
 }
 
 /**
@@ -163,6 +152,8 @@
 
        mycls->sched = sched;
 
+       mycls->mst = GNUNET_SERVER_mst_create(&message_token, mycls);
+
        GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, 
&cleanup, cls);
 
        start_helper_and_schedule(mycls);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]