static void
do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct GNUNET_TIME_Relative del;
  char *fancy;

  GNUNET_SCHEDULER_shutdown ();
  if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
  {
    del = GNUNET_TIME_absolute_get_duration (start_time);
    if (del.rel_value_us == 0)
      del.rel_value_us = 1;
    fancy =
        GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
                                        1000000LL / del.rel_value_us);
    FPRINTF (stdout, "Download speed was %s/s\n", fancy);
    GNUNET_free (fancy);
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
                (unsigned long long) FILESIZE);
  }
  else
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Timeout during download, shutting down with error\n");
    ok = 1;
  }
}
static void
do_report (void *cls)
{
  static int download_counter;
  const char *type = cls;
  struct GNUNET_TIME_Relative del;
  char *fancy;
  struct StatMaster *sm;

  if (0 ==
      GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
                                                                    TIMEOUT)).rel_value_us)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Timeout during download for type `%s', shutting down with error\n",
                type);
    ok = 1;
    cleanup ();
    return;
  }
  del = GNUNET_TIME_absolute_get_duration (start_time);
  if (del.rel_value_us == 0)
    del.rel_value_us = 1;
  fancy =
    GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
				    1000000LL / del.rel_value_us);
  FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
  GNUNET_free (fancy);
  if (NUM_DAEMONS != ++download_counter)
    return;                   /* more downloads to come */
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
	      "Finished all downloads, getting statistics\n");
  sm = GNUNET_new (struct StatMaster);
  sm->op =
    GNUNET_TESTBED_service_connect (NULL,
				    daemons[sm->daemon],
				    "statistics",
				    &stat_run, sm,
				    &statistics_connect_adapter,
				    &statistics_disconnect_adapter,
				    NULL);
}
예제 #3
0
static int
check ()
{
  char buf[128];
  char *r;
  char *b;
  struct GNUNET_TIME_Absolute at;
  const char *hdir;

  sprintf (buf, "4 %s", _( /* size unit */ "b"));
  b = GNUNET_STRINGS_byte_size_fancy (4);
  WANT (buf, b);
  sprintf (buf, "10 %s", _( /* size unit */ "KiB"));
  b = GNUNET_STRINGS_byte_size_fancy (10240);
  WANT (buf, b);
  sprintf (buf, "10 %s", _( /* size unit */ "TiB"));
  b = GNUNET_STRINGS_byte_size_fancy (10240LL * 1024LL * 1024LL * 1024LL);
  WANT (buf, b);
  sprintf (buf, "4 %s", _( /* time unit */ "ms"));
  b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
                                              (GNUNET_TIME_UNIT_MILLISECONDS,
                                               4));
  WANT (buf, b);
  sprintf (buf, "7 %s", _( /* time unit */ "s"));
  b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
                                              (GNUNET_TIME_UNIT_MILLISECONDS,
                                               7 * 1000));
  WANT (buf, b);
  sprintf (buf, "7 %s", _( /* time unit */ "h"));
  b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
                                              (GNUNET_TIME_UNIT_MILLISECONDS,
                                               7 * 60 * 60 * 1000));
  WANT (buf, b);
#ifndef MINGW
  hdir = getenv ("HOME");
#else
  hdir = getenv ("USERPROFILE");
#endif
  GNUNET_snprintf (buf, sizeof (buf), "%s%s", hdir, DIR_SEPARATOR_STR);
  b = GNUNET_STRINGS_filename_expand ("~");
  GNUNET_assert (b != NULL);
  WANT (buf, b);
  GNUNET_STRINGS_buffer_fill (buf, sizeof (buf), 3, "a", "btx", "c");
  WANTB ("a\0btx\0c", buf, 8);
  if (6 != GNUNET_STRINGS_buffer_tokenize (buf, sizeof (buf), 2, &r, &b))
    return 1;
  r = GNUNET_strdup (r);
  WANT ("a", r);
  b = GNUNET_strdup (b);
  WANT ("btx", b);
  if (0 != GNUNET_STRINGS_buffer_tokenize (buf, 2, 2, &r, &b))
    return 1;
  at.abs_value = 5000;
  r = GNUNET_STRINGS_absolute_time_to_string (at);
  /* r should be something like "Wed Dec 31 17:00:05 1969"
   * where the details of the day and hour depend on the timezone;
   * however, the "0:05 19" should always be there; hence: */
  if (NULL == strstr (r, "0:05 19"))
  {
    FPRINTF (stderr, "Got %s\n", r);
    GNUNET_break (0);
    GNUNET_free (r);
    return 1;
  }
  GNUNET_free (r);
  b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII");
  WANT ("TEST", b);
#if ENABLE_NLS && HAVE_ICONV
  GNUNET_log_skip (2, GNUNET_NO);
  b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "unknown");
  GNUNET_log_skip (0, GNUNET_YES);
  WANT ("TEST", b);
#endif
  return 0;
}
예제 #4
0
/**
 * Called by FS client to give information about the progress of an
 * operation.
 *
 * @param cls closure
 * @param info details about the event, specifying the event type
 *        and various bits about the event
 * @return client-context (for the next progress call
 *         for this operation; should be set to NULL for
 *         SUSPEND and STOPPED events).  The value returned
 *         will be passed to future callbacks in the respective
 *         field in the `struct GNUNET_FS_ProgressInfo`
 */
static void *
progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
{
  char *s;
  const char *s2;
  char *t;

  switch (info->status)
  {
  case GNUNET_FS_STATUS_DOWNLOAD_START:
    if (verbose > 1)
      FPRINTF (stderr, _("Starting download `%s'.\n"),
               info->value.download.filename);
    break;
  case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
    if (verbose)
    {
      s = GNUNET_strdup (GNUNET_STRINGS_relative_time_to_string (info->value.download.eta,
								 GNUNET_YES));
      if (info->value.download.specifics.progress.block_download_duration.rel_value_us
          == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
        s2 = _("<unknown time>");
      else
        s2 = GNUNET_STRINGS_relative_time_to_string (
						     info->value.download.specifics.progress.block_download_duration,
						     GNUNET_YES);
      t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed *
                                          1000LL /
                                          (info->value.download.
                                           duration.rel_value_us + 1));
      FPRINTF (stdout,
               _("Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"),
               info->value.download.filename,
               (unsigned long long) info->value.download.completed,
               (unsigned long long) info->value.download.size, s, t, s2);
      GNUNET_free (s);
      GNUNET_free (t);
    }
    else
    {
      display_bar (info->value.download.completed,
		   info->value.download.size,
		   60);
    }
    break;
  case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
#if !WINDOWS
    if (0 != isatty (1))
      fprintf (stdout, "\n");
#else
    if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
      fprintf (stdout, "\n");
#endif
    FPRINTF (stderr, _("Error downloading: %s.\n"),
             info->value.download.specifics.error.message);
    GNUNET_SCHEDULER_shutdown ();
    break;
  case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
    s = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 1000 /
                                        (info->value.download.
                                         duration.rel_value_us + 1));
#if !WINDOWS
    if (0 != isatty (1))
      fprintf (stdout, "\n");
#else
    if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
      fprintf (stdout, "\n");
#endif
    FPRINTF (stdout, _("Downloading `%s' done (%s/s).\n"),
             info->value.download.filename, s);
    GNUNET_free (s);
    if (info->value.download.dc == dc)
      GNUNET_SCHEDULER_shutdown ();
    break;
  case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
    if (info->value.download.dc == dc)
      GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
    break;
  case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
  case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
    break;
  default:
    FPRINTF (stderr, _("Unexpected status: %d\n"), info->status);
    break;
  }
  return NULL;
}