aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-11-16 15:37:03 +0000
committerChristian Grothoff <christian@grothoff.org>2012-11-16 15:37:03 +0000
commitbfa39dc4777fef5d3c0ebf9fe54472daf4b8fd5a (patch)
treeafd19e9a99c1f7dfa258ac2e917956d5f4608edb
parent5f5b69feb3ca531788f2c3b102fbe17a02d5be38 (diff)
downloadgnunet-bfa39dc4777fef5d3c0ebf9fe54472daf4b8fd5a.tar.gz
gnunet-bfa39dc4777fef5d3c0ebf9fe54472daf4b8fd5a.zip
-receiver hack
-rw-r--r--src/transport/Makefile.am9
-rw-r--r--src/transport/gnunet-transport-wlan-receiver.c113
2 files changed, 121 insertions, 1 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index eaf81a611..43e023907 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -49,6 +49,7 @@ if LINUX
49 WLAN_BIN = gnunet-helper-transport-wlan 49 WLAN_BIN = gnunet-helper-transport-wlan
50 WLAN_BIN_DUMMY = gnunet-helper-transport-wlan-dummy 50 WLAN_BIN_DUMMY = gnunet-helper-transport-wlan-dummy
51 WLAN_BIN_SENDER = gnunet-transport-wlan-sender 51 WLAN_BIN_SENDER = gnunet-transport-wlan-sender
52 WLAN_BIN_RECEIVER = gnunet-transport-wlan-receiver
52 WLAN_PLUGIN_LA = libgnunet_plugin_transport_wlan.la 53 WLAN_PLUGIN_LA = libgnunet_plugin_transport_wlan.la
53 WLAN_PLUGIN_TEST = test_plugin_wlan 54 WLAN_PLUGIN_TEST = test_plugin_wlan
54 WLAN_API_TEST = test_transport_api_wlan 55 WLAN_API_TEST = test_transport_api_wlan
@@ -77,7 +78,8 @@ UNIX_QUOTA_TEST = test_quota_compliance_unix \
77endif 78endif
78 79
79noinst_PROGRAMS = \ 80noinst_PROGRAMS = \
80 $(WLAN_BIN_SENDER) 81 $(WLAN_BIN_SENDER) \
82 $(WLAN_BIN_RECEIVER)
81 83
82lib_LTLIBRARIES = \ 84lib_LTLIBRARIES = \
83 libgnunettransport.la \ 85 libgnunettransport.la \
@@ -139,6 +141,11 @@ gnunet_transport_wlan_sender_SOURCES = \
139gnunet_transport_wlan_sender_LDADD = \ 141gnunet_transport_wlan_sender_LDADD = \
140 $(top_builddir)/src/util/libgnunetutil.la 142 $(top_builddir)/src/util/libgnunetutil.la
141 143
144gnunet_transport_wlan_receiver_SOURCES = \
145 gnunet-transport-wlan-receiver.c
146gnunet_transport_wlan_receiver_LDADD = \
147 $(top_builddir)/src/util/libgnunetutil.la
148
142gnunet_transport_SOURCES = \ 149gnunet_transport_SOURCES = \
143 gnunet-transport.c 150 gnunet-transport.c
144gnunet_transport_LDADD = \ 151gnunet_transport_LDADD = \
diff --git a/src/transport/gnunet-transport-wlan-receiver.c b/src/transport/gnunet-transport-wlan-receiver.c
new file mode 100644
index 000000000..22ad2e20d
--- /dev/null
+++ b/src/transport/gnunet-transport-wlan-receiver.c
@@ -0,0 +1,113 @@
1/*
2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
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 transport/gnunet-transport-wlan-receiver.c
23 * @brief program to send via WLAN as much as possible (to test physical/theoretical throughput)
24 * @author David Brodski
25 */
26#include "platform.h"
27#include "gnunet_protocols.h"
28#include "plugin_transport_wlan.h"
29
30int
31main (int argc, char *argv[])
32{
33 char msg_buf[65536];
34 unsigned long long count;
35 double bytes_per_s;
36 time_t start;
37 time_t akt;
38 ssize_t ret;
39 pid_t pid;
40 int commpipe[2]; /* This holds the fd for the input & output of the pipe */
41
42 if (2 != argc)
43 {
44 fprintf (stderr,
45 "This program must be started with the interface name as argument.\n");
46 fprintf (stderr,
47 "Usage: %s interface-name\n"
48 "e.g. %s mon0\n",
49 argv[0], argv[0]);
50 return 1;
51 }
52
53 /* Setup communication pipeline first */
54 if (pipe (commpipe))
55 {
56 fprintf (stderr,
57 "Failed to create pipe: %s\n",
58 STRERROR (errno));
59 exit (1);
60 }
61
62 /* Attempt to fork and check for errors */
63 if ((pid = fork ()) == -1)
64 {
65 fprintf (stderr, "Failed to fork: %s\n",
66 STRERROR (errno));
67 exit (1);
68 }
69
70 if (pid)
71 {
72 /* A positive (non-negative) PID indicates the parent process */
73 if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */
74 fprintf (stderr,
75 "Failed to close fd: %s\n",
76 strerror (errno));
77 start = time (NULL);
78 count = 0;
79 while (1)
80 {
81 ret = read (commpipe[1], msg_buf, sizeof (msg_buf));
82 if (0 > ret)
83 break;
84 count += ret;
85 akt = time (NULL);
86 if (akt - start > 30)
87 {
88 bytes_per_s = count / (akt - start);
89 bytes_per_s /= 1024;
90 printf ("recv %f kb/s\n", bytes_per_s);
91 start = akt;
92 count = 0;
93 }
94 }
95 }
96 else
97 {
98 /* A zero PID indicates that this is the child process */
99 (void) close (1);
100 if (-1 == dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */
101 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
102 (void) close (commpipe[0]); /* Close unused side of pipe (in side) */
103 /* Replace the child fork with a new process */
104 if (execl
105 ("gnunet-helper-transport-wlan", "gnunet-helper-transport-wlan",
106 argv[1], NULL) == -1)
107 {
108 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!");
109 _exit (1);
110 }
111 }
112 return 0;
113}