From 78c035a8492a5d57e0b16d6b784adbca2e817a96 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 22 Dec 2010 14:29:46 +0000 Subject: wlan changes --- src/transport/Makefile.am | 11 ++ src/transport/gnunet-transport-wlan-helper.c | 205 ++++++++++++++++++++++- src/transport/plugin_transport_wlan.c | 78 +++++---- src/transport/test_plugin_transport_wlan_dummy.c | 6 +- src/transport/test_transport_api.c | 14 +- src/transport/test_transport_api_wlan_peer1.conf | 105 ++++++++++++ src/transport/test_transport_api_wlan_peer2.conf | 105 ++++++++++++ 7 files changed, 484 insertions(+), 40 deletions(-) create mode 100644 src/transport/test_transport_api_wlan_peer1.conf create mode 100644 src/transport/test_transport_api_wlan_peer2.conf (limited to 'src/transport') diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index f1f72b689..5d766b7a9 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -81,6 +81,7 @@ gnunet_nat_server_SOURCES = \ gnunet_transport_wlan_helper_SOURCES = \ gnunet-transport-wlan-helper.c gnunet_transport_wlan_helper_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ -lpcap test_plugin_transport_wlan_SOURCES = \ @@ -208,6 +209,7 @@ check_PROGRAMS = \ $(HTTP_API_TEST) \ $(HTTPS_PLUGIN_TEST) \ $(HTTPS_API_TEST) \ + test_transport_api_wlan \ test_transport_api_multi \ test_transport_api_reliability_tcp \ test_transport_api_reliability_tcp_nat \ @@ -233,6 +235,7 @@ TESTS = \ $(HTTP_API_TEST) \ $(HTTPS_PLUGIN_TEST) \ $(HTTPS_API_TEST) \ + test_transport_api_wlan \ test_transport_api_multi \ test_transport_api_reliability_tcp \ test_transport_api_reliability_tcp_nat \ @@ -328,6 +331,12 @@ test_transport_api_reliability_https_LDADD = \ $(top_builddir)/src/transport/libgnunettransport.la \ $(top_builddir)/src/util/libgnunetutil.la +test_transport_api_wlan_SOURCES = \ + test_transport_api.c +test_transport_api_wlan_LDADD = \ + $(top_builddir)/src/transport/libgnunettransport.la \ + $(top_builddir)/src/util/libgnunetutil.la + test_quota_compliance_tcp_SOURCES = \ test_quota_compliance.c test_quota_compliance_tcp_LDADD = \ @@ -422,6 +431,8 @@ EXTRA_DIST = \ test_transport_api_http_peer2.conf \ test_transport_api_https_peer1.conf \ test_transport_api_https_peer2.conf \ + test_transport_api_wlan_peer1.conf \ + test_transport_api_wlan_peer2.conf \ test_transport_api_multi_peer1.conf \ test_transport_api_multi_peer2.conf \ test_transport_api_rel_http_peer1.conf \ diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index 87c140825..4332e9a0d 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c @@ -27,11 +27,23 @@ * This program serves as the mediator between the wlan interface and * gnunet */ -#include "gnunet-transport-wlan-helper.h" + + +#include "platform.h" +#include "gnunet_constants.h" +#include "gnunet_os_lib.h" +#include "gnunet_transport_plugin.h" +#include "transport.h" #include "plugin_transport_wlan.h" +#include "gnunet_common.h" +#include "gnunet-transport-wlan-helper.h" #include "ieee80211_radiotap.h" - #include +#include +#include +#include + + @@ -380,11 +392,200 @@ int ieee80211_radiotap_iterator_next( return -ENOENT; } +#define FIFO_FILE1 "MYFIFOin" +#define FIFO_FILE2 "MYFIFOout" +#define MAXLINE 5000 + +int closeprog = 0; + +void sigfunc(int sig) +{ + + if(sig != SIGINT || sig != SIGTERM || sig != SIGKILL) + return; + else + { + closeprog = 1; + } +} + + + +int +testmode(int argc, char *argv[]) +{ + struct stat st; + int erg; + int first; + FILE *fpin; + FILE *fpout; + pid_t pid; + + signal(SIGINT,sigfunc); + signal(SIGTERM,sigfunc); + signal(SIGKILL,sigfunc); + + //make the fifos if needed + if (stat(FIFO_FILE1, &st) != 0) + { + if (stat(FIFO_FILE2, &st) != 0) + { + perror("FIFO 2 exists, but FIFO 1 not"); + exit(1); + } + first = 1; + umask(0); + erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0); + erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0); + + if ((fpin = fopen(FIFO_FILE1, "r")) == NULL) + { + perror("fopen"); + exit(1); + } + if ((fpout = fopen(FIFO_FILE2, "w")) == NULL) + { + perror("fopen"); + exit(1); + } + } + else + { + first = 0; + if (stat(FIFO_FILE2, &st) == 0) + { + perror("FIFO 1 exists, but FIFO 2 not"); + exit(1); + } + if ((fpout = fopen(FIFO_FILE1, "w")) == NULL) + { + perror("fopen"); + exit(1); + } + if ((fpin = fopen(FIFO_FILE2, "r")) == NULL) + { + perror("fopen"); + exit(1); + } + + } + + // fork + + if ((pid = fork()) < 0) + { + perror("FORK ERROR"); + + //clean up + if (first == 1) + { + unlink(FIFO_FILE1); + unlink(FIFO_FILE2); + } + fclose(fpin); + fclose(fpout); + return -3; + } + else if (pid == 0) // CHILD PROCESS + { + int rv = 0; + int readc = 0; + int pos = 0; + char line[MAXLINE]; + + while (closeprog == 0) + { + readc = 0; + + while (readc < sizeof( struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader)){ + if ((rv = read(STDIN_FILENO, line, MAXLINE)) < 0) + { + perror("READ ERROR FROM STDIN"); + } + readc += rv; + } + + pos = 0; + + fwrite(&line[pos], 1, sizeof(struct GNUNET_MessageHeader), fpout); + + pos += sizeof(struct GNUNET_MessageHeader); + + //do not send radiotap header + pos += sizeof( struct RadiotapHeader); + + while (pos < readc) + { + pos += fwrite(&line[pos], 1, readc - pos, fpout); + } + } + + + //clean up + fclose(fpout); + } + else // PARENT PROCESS + { + int rv = 0; + ssize_t pos = 0; + char line[MAXLINE]; + struct Wlan_Helper_Control_Message macmsg; + + + //Send random mac address + macmsg.mac.mac[0] = 0x13; + macmsg.mac.mac[1] = 0x22; + macmsg.mac.mac[2] = 0x33; + macmsg.mac.mac[3] = 0x44; + macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); + macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); + macmsg.hdr.size = sizeof(struct Wlan_Helper_Control_Message); + + pos = 0; + while (pos < sizeof(struct Wlan_Helper_Control_Message)) + { + pos += write(STDOUT_FILENO, &macmsg + pos, sizeof(struct Wlan_Helper_Control_Message) - pos); + } + + while (closeprog == 0) + { + if ((rv = fread(line, 1, MAXLINE, fpin)) < 0) + { + perror("READ ERROR FROM fpin"); + } + + pos = 0; + while (pos < rv) + { + pos += write(STDOUT_FILENO, &line[pos], rv - pos); + } + } + + + //clean up + fclose(fpin); + + if (first == 1) + { + unlink(FIFO_FILE1); + unlink(FIFO_FILE2); + } + } + + // Write the input to the output + + return (0); +} int main(int argc, char *argv[]) { + if ((argc==3) && (strstr(argv[2],"1"))) + { + return testmode(argc, argv); + } + u8 u8aSendBuffer[500]; char szErrbuf[PCAP_ERRBUF_SIZE]; int nCaptureHeaderLength = 0, n80211HeaderLength = 0, nLinkEncap = 0; diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 8a4201863..d3c7d2150 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -1992,7 +1992,7 @@ wlan_plugin_helper_read (void *cls, * @return GNUNET_YES if process was started, GNUNET_SYSERR on error */ static int -wlan_transport_start_wlan_helper(struct Plugin *plugin) +wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode) { plugin->server_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_NO, GNUNET_YES); @@ -2010,7 +2010,7 @@ wlan_transport_start_wlan_helper(struct Plugin *plugin) /* Start the server process */ plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, plugin->server_stdout, "gnunet-transport-wlan-helper", - "gnunet-transport-wlan-helper", plugin->interface, NULL); + plugin->interface, testmode, NULL); if (plugin->server_proc == NULL) { #if DEBUG_wlan @@ -2038,6 +2038,27 @@ wlan_transport_start_wlan_helper(struct Plugin *plugin) } +/** + * Exit point from the plugin. + */ +//TODO doxigen +//FIXME cleanup +void * +libgnunet_plugin_transport_wlan_done (void *cls) +{ + struct GNUNET_TRANSPORT_PluginFunctions *api = cls; + struct Plugin *plugin = api->cls; + + GNUNET_assert(cls !=NULL); + + if (plugin->consoltoken != NULL) + GNUNET_SERVER_mst_destroy(plugin->consoltoken); + + GNUNET_free_non_null(plugin->interface); + GNUNET_free (plugin); + GNUNET_free (api); + return NULL; +} /** * Entry point for the plugin. @@ -2048,21 +2069,15 @@ wlan_transport_start_wlan_helper(struct Plugin *plugin) void * libgnunet_plugin_transport_wlan_init (void *cls) { - struct GNUNET_SERVICE_Context *service; + //struct GNUNET_SERVICE_Context *service; struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; struct GNUNET_TRANSPORT_PluginFunctions *api; struct Plugin *plugin; + int testmode; GNUNET_assert(cls !=NULL); - service = GNUNET_SERVICE_start ("transport-wlan", env->cfg); - if (service == NULL){ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to start service for `%s' transport plugin.\n"), - "wlan"); - return NULL; - } - + fprintf(stderr,"HERE"); plugin = GNUNET_malloc (sizeof (struct Plugin)); plugin->env = env; plugin->pendingsessions = 0; @@ -2071,7 +2086,25 @@ libgnunet_plugin_transport_wlan_init (void *cls) plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; - wlan_transport_start_wlan_helper(plugin); + testmode = GNUNET_NO; + if (GNUNET_CONFIGURATION_have_value (env->cfg, + "transport-wlan", "TESTMODE")) + { + testmode = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, + "transport-wlan","TESTMODE"); + } + + if (GNUNET_CONFIGURATION_have_value (env->cfg, + "transport-wlan", "INTERFACE")) + { + if (GNUNET_CONFIGURATION_get_value_string (env->cfg, + "transport-wlan","INTERFACE", &(plugin->interface)) != GNUNET_YES){ + libgnunet_plugin_transport_wlan_done(plugin); + return NULL; + } + } + + wlan_transport_start_wlan_helper(plugin, testmode); plugin->consoltoken = GNUNET_SERVER_mst_create(&wlan_process_helper,plugin); //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); @@ -2091,25 +2124,4 @@ libgnunet_plugin_transport_wlan_init (void *cls) return api; } - -/** - * Exit point from the plugin. - */ -//TODO doxigen -//FIXME cleanup -void * -libgnunet_plugin_transport_wlan_done (void *cls) -{ - struct GNUNET_TRANSPORT_PluginFunctions *api = cls; - struct Plugin *plugin = api->cls; - - GNUNET_assert(cls !=NULL); - - GNUNET_SERVER_mst_destroy(plugin->consoltoken); - - GNUNET_free (plugin); - GNUNET_free (api); - return NULL; -} - /* end of plugin_transport_wlan.c */ diff --git a/src/transport/test_plugin_transport_wlan_dummy.c b/src/transport/test_plugin_transport_wlan_dummy.c index b4fd46610..53b957eca 100644 --- a/src/transport/test_plugin_transport_wlan_dummy.c +++ b/src/transport/test_plugin_transport_wlan_dummy.c @@ -58,7 +58,7 @@ void sigfunc(int sig) int main(int argc, char *argv[]) { - struct stat st; + struct stat st,st2; int erg; int first; FILE *fpin; @@ -72,7 +72,7 @@ main(int argc, char *argv[]) //make the fifos if needed if (stat(FIFO_FILE1, &st) != 0) { - if (stat(FIFO_FILE2, &st) != 0) + if (stat(FIFO_FILE2, &st2) != 0) { perror("FIFO 2 exists, but FIFO 1 not"); exit(1); @@ -96,7 +96,7 @@ main(int argc, char *argv[]) else { first = 0; - if (stat(FIFO_FILE2, &st) == 0) + if (stat(FIFO_FILE2, &st2) == 0) { perror("FIFO 1 exists, but FIFO 2 not"); exit(1); diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index c115d1e5d..2d0b42008 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c @@ -36,7 +36,7 @@ #include "gnunet_transport_service.h" #include "transport.h" -#define VERBOSE GNUNET_NO +#define VERBOSE GNUNET_YES #define VERBOSE_ARM GNUNET_NO @@ -84,6 +84,8 @@ static int is_https; static int is_multi_protocol; +static int is_wlan; + static GNUNET_SCHEDULER_TaskIdentifier die_task; static char * key_file_p1; @@ -397,6 +399,11 @@ run (void *cls, setup_peer (&p1, "test_transport_api_https_peer1.conf"); setup_peer (&p2, "test_transport_api_https_peer2.conf"); } + else if (is_wlan) + { + setup_peer (&p1, "test_transport_api_wlan_peer1.conf"); + setup_peer (&p2, "test_transport_api_wlan_peer2.conf"); + } GNUNET_assert(p1.th != NULL); GNUNET_assert(p2.th != NULL); @@ -635,12 +642,15 @@ main (int argc, char *argv[]) { is_http = GNUNET_YES; } + else if (strstr(argv[0], "wlan") != NULL) + { + is_wlan = GNUNET_YES; + } else if (strstr(argv[0], "multi") != NULL) { is_multi_protocol = GNUNET_YES; } - ret = check (); if (is_multi_protocol) { diff --git a/src/transport/test_transport_api_wlan_peer1.conf b/src/transport/test_transport_api_wlan_peer1.conf new file mode 100644 index 000000000..c273d9482 --- /dev/null +++ b/src/transport/test_transport_api_wlan_peer1.conf @@ -0,0 +1,105 @@ +[fs] +AUTOSTART = NO + +[datastore] +AUTOSTART = NO + +[core] +AUTOSTART = NO + +[transport-wlan] +INTERFACE = wlan0 +TESTMODE = YES + +[hostlist] +HTTP-PROXY = +SERVERS = http://gnunet.org:8080/ +OPTIONS = -b +BINARY = gnunet-daemon-hostlist +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +HTTPPORT = 8080 + +[topology] +BINARY = gnunet-daemon-topology +CONFIG = $DEFAULTCONFIG +FRIENDS = $SERVICEHOME/friends +TARGET-CONNECTION-COUNT = 16 +AUTOCONNECT = YES +FRIENDS-ONLY = NO +MINIMUM-FRIENDS = 0 + +[transport] +PLUGINS = wlan +DEBUG = YES +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +NEIGHBOUR_LIMIT = 50 +BINARY = gnunet-service-transport +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 12365 +UNIXPATH = /tmp/gnunet-p1-service-transport.sock +#PREFIX = xterm -T transport2 -e gdb --command=cmd --args +#PREFIX = valgrind --leak-check=full +#PREFIX = valgrind --tool=massif + +[peerinfo] +TRUST = $SERVICEHOME/data/credit/ +HOSTS = $SERVICEHOME/data/hosts/ +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +BINARY = gnunet-service-peerinfo +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 12369 +UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock + +[resolver] +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +BINARY = gnunet-service-resolver +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 12364 +UNIXPATH = /tmp/gnunet-p1-service-resolver.sock + +[statistics] +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +BINARY = gnunet-service-statistics +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 12367 +UNIXPATH = /tmp/gnunet-p1-service-statistics.sock + +[arm] +DEFAULTSERVICES = +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +BINARY = gnunet-service-arm +#CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 12366 +UNIXPATH = /tmp/gnunet-p1-service-arm.sock + +[TESTING] +WEAKRANDOM = YES + +[gnunetd] +HOSTKEY = $SERVICEHOME/.hostkey + +[PATHS] +SERVICEHOME = /tmp/test-gnunetd-transport-peer-1/ + + +[dht] +AUTOSTART = NO + + diff --git a/src/transport/test_transport_api_wlan_peer2.conf b/src/transport/test_transport_api_wlan_peer2.conf new file mode 100644 index 000000000..7ed039f79 --- /dev/null +++ b/src/transport/test_transport_api_wlan_peer2.conf @@ -0,0 +1,105 @@ +[fs] +AUTOSTART = NO + +[datastore] +AUTOSTART = NO + +[core] +AUTOSTART = NO + +[transport-wlan] +INTERFACE = wlan1 +TESTMODE = YES + +[hostlist] +HTTP-PROXY = +SERVERS = http://gnunet.org:8080/ +OPTIONS = -b +BINARY = gnunet-daemon-hostlist +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +HTTPPORT = 8080 + +[topology] +BINARY = gnunet-daemon-topology +CONFIG = $DEFAULTCONFIG +FRIENDS = $SERVICEHOME/friends +TARGET-CONNECTION-COUNT = 16 +AUTOCONNECT = YES +FRIENDS-ONLY = NO +MINIMUM-FRIENDS = 0 + +[transport] +PLUGINS = wlan +DEBUG = YES +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +NEIGHBOUR_LIMIT = 50 +BINARY = gnunet-service-transport +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 22365 +UNIXPATH = /tmp/gnunet-p2-service-transport.sock +#PREFIX = xterm -T transport1 -e gdb --command=cmd --args +#PREFIX = valgrind --leak-check=full +#PREFIX = valgrind --tool=massif + +[peerinfo] +TRUST = $SERVICEHOME/data/credit/ +HOSTS = $SERVICEHOME/data/hosts/ +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +BINARY = gnunet-service-peerinfo +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 22369 +UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock + +[resolver] +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +BINARY = gnunet-service-resolver +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 22364 +UNIXPATH = /tmp/gnunet-p2-service-resolver.sock + +[statistics] +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +BINARY = gnunet-service-statistics +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 22367 +UNIXPATH = /tmp/gnunet-p2-service-statistics.sock + +[arm] +DEFAULTSERVICES = +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +BINARY = gnunet-service-arm +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 22366 +UNIXPATH = /tmp/gnunet-p2-service-arm.sock + +[TESTING] +WEAKRANDOM = YES + +[gnunetd] +HOSTKEY = $SERVICEHOME/.hostkey + +[PATHS] +SERVICEHOME = /tmp/test-gnunetd-transport-peer-2/ + + +[dht] +AUTOSTART = NO + + -- cgit v1.2.3