gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r5590 - GNUnet/src/transports


From: gnunet
Subject: [GNUnet-SVN] r5590 - GNUnet/src/transports
Date: Mon, 3 Sep 2007 23:01:18 -0600 (MDT)

Author: grothoff
Date: 2007-09-03 23:01:17 -0600 (Mon, 03 Sep 2007)
New Revision: 5590

Added:
   GNUnet/src/transports/test.c
Modified:
   GNUnet/src/transports/Makefile.am
   GNUnet/src/transports/http.c
   GNUnet/src/transports/nat.c
   GNUnet/src/transports/tcp.c
   GNUnet/src/transports/udp.c
Log:
drafting transport testcase:


Modified: GNUnet/src/transports/Makefile.am
===================================================================
--- GNUnet/src/transports/Makefile.am   2007-09-03 04:34:08 UTC (rev 5589)
+++ GNUnet/src/transports/Makefile.am   2007-09-04 05:01:17 UTC (rev 5590)
@@ -19,7 +19,7 @@
   httptransport = libgnunettransport_http.la
 endif
 
-SUBDIRS = $(build_upnp) .
+SUBDIRS = . $(build_upnp)
 
 noinst_LTLIBRARIES = \
   $(v6ip) 
@@ -27,7 +27,14 @@
 lib_LTLIBRARIES = \
   libgnunetip.la
 
+check_PROGRAMS = \
+  test_udp \
+  test_tcp \
+  test_http 
 
+TESTS = $(check_PROGRAMS)
+
+
 if !MINGW
 # smtptransport = libgnunettransport_smtp.la
 endif
@@ -99,3 +106,37 @@
 libgnunettransport_udp6_la_LDFLAGS = \
  -export-dynamic -avoid-version -module 
 
+
+
+
+
+test_udp_SOURCES = \
+ test.c 
+test_udp_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la \
+ $(top_builddir)/src/util/cron/libgnunetutil_cron.la \
+ $(top_builddir)/src/util/boot/libgnunetutil_boot.la \
+ $(top_builddir)/src/util/loggers/libgnunetutil_logging.la \
+ $(top_builddir)/src/util/config_impl/libgnunetutil_config.la
+
+test_tcp_SOURCES = \
+ test.c 
+test_tcp_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/util/loggers/libgnunetutil_logging.la \
+ $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la \
+ $(top_builddir)/src/util/cron/libgnunetutil_cron.la \
+ $(top_builddir)/src/util/boot/libgnunetutil_boot.la \
+ $(top_builddir)/src/util/config_impl/libgnunetutil_config.la
+
+test_http_SOURCES = \
+ test.c 
+test_http_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/util/loggers/libgnunetutil_logging.la \
+ $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la \
+ $(top_builddir)/src/util/cron/libgnunetutil_cron.la \
+ $(top_builddir)/src/util/boot/libgnunetutil_boot.la \
+ $(top_builddir)/src/util/config_impl/libgnunetutil_config.la
+

Modified: GNUnet/src/transports/http.c
===================================================================
--- GNUnet/src/transports/http.c        2007-09-03 04:34:08 UTC (rev 5589)
+++ GNUnet/src/transports/http.c        2007-09-04 05:01:17 UTC (rev 5590)
@@ -37,7 +37,7 @@
 #include "platform.h"
 #include "ip.h"
 
-#define DEBUG_HTTP NO
+#define DEBUG_HTTP YES
 
 /**
  * Disable GET (for debugging only!).  Must be YES
@@ -1953,8 +1953,10 @@
 donetransport_http ()
 {
   GC_detach_change_listener (coreAPI->cfg, &reloadConfiguration, NULL);
-  coreAPI->releaseService (stats);
-  stats = NULL;
+  if (stats != NULL) {
+    coreAPI->releaseService (stats);
+    stats = NULL;
+  }
   if (upnp != NULL)
     {
       coreAPI->releaseService (upnp);

Modified: GNUnet/src/transports/nat.c
===================================================================
--- GNUnet/src/transports/nat.c 2007-09-03 04:34:08 UTC (rev 5589)
+++ GNUnet/src/transports/nat.c 2007-09-04 05:01:17 UTC (rev 5590)
@@ -30,7 +30,7 @@
 #include "platform.h"
 #include "ip.h"
 
-#define DEBUG_NAT NO
+#define DEBUG_NAT YES
 
 /**
  * Host-Address in a NAT network.  Since the idea behind

Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2007-09-03 04:34:08 UTC (rev 5589)
+++ GNUnet/src/transports/tcp.c 2007-09-04 05:01:17 UTC (rev 5590)
@@ -32,7 +32,7 @@
 #include "platform.h"
 #include "ip.h"
 
-#define DEBUG_TCP NO
+#define DEBUG_TCP YES
 
 /**
  * after how much time of the core not being associated with a tcp

Added: GNUnet/src/transports/test.c
===================================================================
--- GNUnet/src/transports/test.c                                (rev 0)
+++ GNUnet/src/transports/test.c        2007-09-04 05:01:17 UTC (rev 5590)
@@ -0,0 +1,257 @@
+/*
+     This file is part of GNUnet.
+     (C) 2007 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file transports/test.c
+ * @brief Test for the transports.
+ * @author Christian Grothoff
+ *
+ * This utility can be used to test if a transport mechanism for
+ * GNUnet is properly configured.
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_util_boot.h"
+#include "gnunet_directories.h"
+#include "gnunet_protocols.h"
+#include "gnunet_transport.h"
+
+/**
+ * Name of the configuration file.
+ */
+static char *cfgFilename = DEFAULT_DAEMON_CONFIG_FILE;
+
+/**
+ * Transport being tested.
+ */
+static TransportAPI *transport;
+
+/**
+ * What response do we currently expect to receive?
+ */
+static char * expectedValue;
+
+/**
+ * What is the size of the expected response?
+ * (pick a value smaller than the minimum expected MTU)
+ */
+static unsigned long long expectedSize = 1200;
+
+/**
+ * Am I client (!= 0) or server (== 0)?
+ */
+static pid_t pid;
+
+/**
+ * How often did we fail so far?
+ */
+static unsigned int error_count;
+
+/**
+ * How many messages did we process?
+ */
+static unsigned int msg_count;
+
+/**
+ * No options.
+ */
+static struct CommandLineOption testOptions[] = {
+  COMMAND_LINE_OPTION_END,
+};
+
+static void * requestService(const char * name) {
+  /* we expect only "stats" to be requested... */
+  if (0 != strcmp(name, "stats")) 
+    fprintf(stderr,
+           "Rejecting request for service `%s'\n", name);
+  return NULL;
+}
+
+static int assertUnused(TSession * tsession) {
+  return OK;
+}
+
+/**
+ * We received a message.  The "client" should try to echo it back,
+ * the "server" should validate that it got the right reply.
+ */
+static void receive(P2P_PACKET * mp) {
+  unsigned int retries;
+
+  msg_count++;
+  if (pid == 0) {
+    /* server; do echo back */
+    retries = 0;
+    while (NO == transport->send(mp->tsession,
+                                mp->msg,
+                                mp->size,
+                                retries > 6 ? YES : NO)) {
+      if (retries > 10) {
+       fprintf(stderr,
+               "Failed to send reply!\n");
+       error_count++;
+       break;
+      }
+      retries++;
+    }
+  } else {
+    /* validate echo */
+    if ( (mp->size != expectedSize) ||
+        (0 != memcmp(mp->msg,
+                     expectedValue,
+                     mp->size)) )
+      error_count++;
+  }  
+  FREE(mp);
+}
+
+int
+main (int argc, char *const *argv)
+{
+  CoreAPIForTransport api;
+  struct PluginHandle * plugin;
+  TransportMainMethod init;
+  void (*done) ();
+  PeerIdentity me;
+  char * trans;
+  int res;
+  int pos;
+
+  pid = fork();
+  res = GNUNET_init (argc,
+                     argv,
+                     "transport-test",
+                     &cfgFilename, testOptions, &api.ectx, &api.cfg);
+  if (res == -1)
+    goto cleanup;
+  
+  expectedValue = MALLOC (expectedSize);
+  pos = expectedSize;
+  expectedValue[--pos] = '\0';
+  while (pos-- > 0)
+    expectedValue[pos] = 'A' + (pos % 26);
+  trans = strstr(argv[0], "_");
+  if (trans == NULL)
+    goto cleanup;
+  trans++;
+  trans = strdup(trans);
+  if (NULL != strstr(trans, "."))
+    strstr(trans, ".")[0] = '\0';
+  if (NULL != strstr(trans, "-"))
+    strstr(trans, ".")[0] = '\0';
+  /* disable blacklists (loopback is often blacklisted)... */
+  GC_set_configuration_value_string (api.cfg, api.ectx, "TCP", "BLACKLIST", 
"");
+  GC_set_configuration_value_string (api.cfg, api.ectx, "TCP", "UPNP", "NO");
+  GC_set_configuration_value_string (api.cfg, api.ectx, "TCP6", "BLACKLIST", 
"");
+  GC_set_configuration_value_string (api.cfg, api.ectx, "UDP", "BLACKLIST", 
"");
+  GC_set_configuration_value_string (api.cfg, api.ectx, "UDP6", "BLACKLIST", 
"");
+  GC_set_configuration_value_string (api.cfg, api.ectx, "HTTP", "BLACKLIST", 
"");
+  GC_set_configuration_value_string (api.cfg, api.ectx, "HTTP", "UPNP", "NO");
+
+  if (pid == 0)
+    pos = 10;
+  else
+    pos = 0;
+  GC_set_configuration_value_number (api.cfg, api.ectx, "TCP", "PORT", 
4444+pos);
+  GC_set_configuration_value_number (api.cfg, api.ectx, "TCP6", "PORT", 
4445+pos);
+  GC_set_configuration_value_number (api.cfg, api.ectx, "UDP", "PORT", 
4446+pos);
+  GC_set_configuration_value_number (api.cfg, api.ectx, "UDP6", "PORT", 
4447+pos);
+  GC_set_configuration_value_number (api.cfg, api.ectx, "HTTP", "PORT", 
4448+pos);
+  makeRandomId(&me.hashPubKey);
+  plugin = os_plugin_load(api.ectx,
+                         "libgnunettransport_",
+                         trans);
+  if (plugin == NULL) {
+    fprintf(stderr, "Error loading plugin...\n");
+    goto cleanup;
+  }
+  init = os_plugin_resolve_function(plugin,
+                                   "inittransport_",
+                                   YES);
+  if (init == NULL) {
+    fprintf(stderr, "Error resolving init method...\n");
+    os_plugin_unload(plugin);
+    goto cleanup;
+  }
+  api.cron = cron_create (api.ectx);
+  api.myIdentity = &me;
+  api.receive = &receive;
+  api.requestService = &requestService;
+  api.releaseService = NULL; /* not needed */
+  api.assertUnused = &assertUnused;
+  cron_start(api.cron); 
+  res = OK;
+  transport = init(&api);
+  if (transport == NULL) {
+    fprintf(stderr, "Error initializing plugin...\n");
+    os_plugin_unload(plugin);
+    goto cleanup;
+  }
+  transport->startTransportServer();
+  GE_ASSERT(NULL, (transport->mtu >= expectedSize) || (transport->mtu == 0));
+  if (pid == 0) {
+    /* server - wait for requests */
+    GNUNET_SHUTDOWN_WAITFOR();
+  } else {
+    /* client - initiate requests */
+    // FIXME!
+
+    
+
+  }  
+
+  transport->stopTransportServer();
+  done = os_plugin_resolve_function(plugin,
+                                   "donetransport_",
+                                   NO);
+  if (done != NULL)
+    done();
+  if (pid != 0) {
+    kill(pid, SIGTERM);
+    waitpid(pid, &res, 0);
+    if (WEXITSTATUS(res) == 0)
+      res = OK;
+    else
+      res = SYSERR;
+  }
+  os_plugin_unload(plugin);
+  cron_stop (api.cron);
+  cron_destroy (api.cron);
+  GNUNET_fini (api.ectx, api.cfg);
+  FREE(expectedValue);
+  if (error_count > 0)
+    res = SYSERR;
+  if (res != OK)
+    return 2;
+  return 0;
+
+cleanup:      
+  GNUNET_fini (api.ectx, api.cfg);
+  if (pid != 0) {
+    kill(pid, SIGTERM);
+    waitpid(pid, &res, 0);
+  }
+  FREE(expectedValue);
+  return 1;
+}
+
+
+/* end of gnunet-transport-check */


Property changes on: GNUnet/src/transports/test.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: GNUnet/src/transports/udp.c
===================================================================
--- GNUnet/src/transports/udp.c 2007-09-03 04:34:08 UTC (rev 5589)
+++ GNUnet/src/transports/udp.c 2007-09-04 05:01:17 UTC (rev 5590)
@@ -32,7 +32,7 @@
 #include "ip.h"
 #include "platform.h"
 
-#define DEBUG_UDP NO
+#define DEBUG_UDP YES
 
 static UPnP_ServiceAPI *upnp;
 





reply via email to

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