fixing 1696
authorChristian Grothoff <christian@grothoff.org>
Fri, 17 Jun 2011 09:51:39 +0000 (09:51 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 17 Jun 2011 09:51:39 +0000 (09:51 +0000)
doc/man/gnunet-search.1
src/fs/gnunet-search.c

index 52609773307930fc42ed932588f1ae06382567f9..8f9789400020383b40fee5c9b538d9bff5828d55 100644 (file)
@@ -41,6 +41,10 @@ Writes a GNUnet directory containing all of the search results to FILENAME.
 \fB\-n\fR, \fB\-\-no-network\fR
 Only search locally, do not forward requests to other peers.
 
+.TP
+\fB\-t \fIVALUE\fR, \fB\-\-timeout=\fIVALUE\fR
+Automatically timeout search after VALUE ms.  Otherwise the search runs until gnunet\-search is aborted with CTRL\-C.
+
 .TP
 \fB\-v\fR, \fB\-\-version\fR
 print the version number
index cc3ef7c872c47409a69e4f2ee7ac14735c355213..f2414322dd37cc10c6b381c96abdf6e1e7ff85fc 100644 (file)
@@ -42,6 +42,8 @@ static struct GNUNET_FS_DirectoryBuilder *db;
 
 static unsigned int anonymity = 1;
 
+static unsigned long long timeout;
+
 static int verbose;
 
 static int local_only;
@@ -231,6 +233,7 @@ run (void *cls,
   struct GNUNET_FS_Uri *uri;
   unsigned int argc;
   enum GNUNET_FS_SearchOptions options;
+  struct GNUNET_TIME_Relative delay;
 
   argc = 0;
   while (NULL != args[argc])
@@ -242,7 +245,6 @@ run (void *cls,
       fprintf (stderr,
               _("Could not create keyword URI from arguments.\n"));
       ret = 1;
-      GNUNET_FS_uri_destroy (uri);
       return;
     }
   cfg = c;
@@ -280,9 +282,19 @@ run (void *cls,
       ret = 1;
       return;
     }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                               &shutdown_task,
-                               NULL);
+  if (timeout != 0)
+    {
+      delay.rel_value = timeout;
+      GNUNET_SCHEDULER_add_delayed (delay,
+                                   &shutdown_task,
+                                   NULL);  
+    }
+  else
+    {
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                                   &shutdown_task,
+                                   NULL);  
+    }
 }
 
 
@@ -307,11 +319,15 @@ main (int argc, char *const *argv)
      gettext_noop
      ("write search results to file starting with PREFIX"),
      1, &GNUNET_GETOPT_set_string, &output_filename}, 
+    {'t', "timeout", "VALUE",
+     gettext_noop 
+     ("automatically terminate search after VALUE ms"),
+     1, &GNUNET_GETOPT_set_ulong, &timeout},
     {'V', "verbose", NULL,
      gettext_noop ("be verbose (print progress information)"),
      0, &GNUNET_GETOPT_set_one, &verbose},
     GNUNET_GETOPT_OPTION_END
-  };
+  }; 
   return (GNUNET_OK ==
           GNUNET_PROGRAM_run (argc,
                               argv,