gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r24839 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r24839 - gnunet/src/transport
Date: Thu, 8 Nov 2012 14:07:53 +0100

Author: wachs
Date: 2012-11-08 14:07:53 +0100 (Thu, 08 Nov 2012)
New Revision: 24839

Modified:
   gnunet/src/transport/gnunet-transport.c
Log:
- working: -i -e -C , todo: -m -s -b


Modified: gnunet/src/transport/gnunet-transport.c
===================================================================
--- gnunet/src/transport/gnunet-transport.c     2012-11-08 13:03:19 UTC (rev 
24838)
+++ gnunet/src/transport/gnunet-transport.c     2012-11-08 13:07:53 UTC (rev 
24839)
@@ -41,6 +41,7 @@
  */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 #define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 10)
+#define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 
 /**
  * Which peer should we connect to?
@@ -143,6 +144,12 @@
  */
 static GNUNET_SCHEDULER_TaskIdentifier end;
 
+/**
+ * Task for operation timeout
+ */
+static GNUNET_SCHEDULER_TaskIdentifier op_timeout;
+
+
 static struct GNUNET_CONTAINER_MultiHashMap *peers;
 
 /**
@@ -205,6 +212,11 @@
 shutdown_task (void *cls,
                const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
+  {
+      GNUNET_SCHEDULER_cancel (op_timeout);
+      op_timeout = GNUNET_SCHEDULER_NO_TASK;
+  }
   if (NULL != pic)
   {
       GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic);
@@ -227,6 +239,26 @@
   }
 }
 
+
+
+static void
+operation_timeout (void *cls,
+               const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  op_timeout = GNUNET_SCHEDULER_NO_TASK;
+  if (try_connect)
+  {
+      FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_h2s_full 
(&pid.hashPubKey));
+      if (GNUNET_SCHEDULER_NO_TASK != end)
+        GNUNET_SCHEDULER_cancel (end);
+      end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+      ret = 1;
+      return;
+  }
+}
+
+
+
 /**
  * Display the result of the test.
  *
@@ -456,25 +488,26 @@
   if (try_connect)
   {
       /* all done, terminate instantly */
-      if (verbosity > 0)
-        FPRINTF (stdout, _("Successfully connected to %s\n"), GNUNET_i2s 
(peer));
-      GNUNET_SCHEDULER_cancel (end);
+      FPRINTF (stdout, _("Successfully connected to %s\n"), GNUNET_h2s_full 
(&peer->hashPubKey));
+      ret = 0;
+
+      if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
+        GNUNET_SCHEDULER_cancel (op_timeout);
+
+      if (GNUNET_SCHEDULER_NO_TASK != end)
+        GNUNET_SCHEDULER_cancel (end);
       end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
+      return;
   }
-  else if (benchmark_send)
+  if (benchmark_send)
   {
     start_time = GNUNET_TIME_absolute_get ();
     if (NULL == th)
       th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 32 * 1024, 0,
                                                  GNUNET_TIME_UNIT_FOREVER_REL,
                                                  &transmit_data, NULL);
+    return;
   }
-  else
-  {
-    /* all done, terminate instantly */
-    GNUNET_SCHEDULER_cancel (end);
-    end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
-  }
 }
 
 
@@ -606,6 +639,7 @@
     {
         if (GNUNET_SCHEDULER_NO_TASK != end)
           GNUNET_SCHEDULER_cancel (end);
+        ret = 0;
         end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
     }
   }
@@ -657,9 +691,8 @@
 {
   struct GNUNET_CONFIGURATION_Handle *cfg = cls;
   int counter = 0;
-  int try_connect = 0;
+  ret = 1;
 
-
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
   {
       FPRINTF (stderr, _("Service `%s' is not running\n"), "transport");
@@ -707,10 +740,12 @@
     if (NULL == handle)
     {
         FPRINTF (stderr, _("Failed to connect to transport service\n"));
+        ret = 1;
         return;
     }
-
     GNUNET_TRANSPORT_try_connect (handle, &pid);
+    op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
+                                               &operation_timeout, NULL);
 
   }
   else if (benchmark_send) /* Benchmark sending */
@@ -719,9 +754,9 @@
     {
       FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
                "-s", "-p");
+      ret = 1;
       return;
     }
-    ret = 1;
     handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL,
                                        &notify_receive,
                                        &notify_connect,
@@ -729,15 +764,14 @@
     if (NULL == handle)
     {
         FPRINTF (stderr, _("Failed to connect to transport service\n"));
+        ret = 1;
         return;
     }
     GNUNET_TRANSPORT_try_connect (handle, &pid);
-    /*
-    end = GNUNET_SCHEDULER_add_delayed (benchmark_send ?
-                                        GNUNET_TIME_UNIT_FOREVER_REL :
-                                        GNUNET_TIME_UNIT_SECONDS,
-                                        &do_disconnect,
-                                        NULL);*/
+
+    op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
+                                               &operation_timeout,
+                                               NULL);
   }
   else if (benchmark_receive) /* Benchmark receiving */
   {
@@ -747,6 +781,7 @@
     if (NULL == handle)
     {
         FPRINTF (stderr, _("Failed to connect to transport service\n"));
+        ret = 1;
         return;
     }
     GNUNET_TRANSPORT_try_connect (handle, &pid);
@@ -782,8 +817,10 @@
     if (NULL == handle)
     {
       FPRINTF (stderr, _("Failed to connect to transport service\n"));
+      ret = 1;
       return;
     }
+    ret = 0;
   }
   else
   {




reply via email to

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