Пример #1
0
static void
run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  char *fn;
  const struct GNUNET_DISK_FileHandle *stdout_read_handle;
  const struct GNUNET_DISK_FileHandle *wh;

#if !WINDOWS
  GNUNET_asprintf (&fn, "cat");
#else
  GNUNET_asprintf (&fn, "w32cat");
#endif

  hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
  hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);

  if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL))
  {
    GNUNET_break (0);
    ok = 1;
    GNUNET_free (fn);
    return;
  }

  proc =
      GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, hello_pipe_stdin, hello_pipe_stdout, fn,
                               "test_gnunet_echo_hello", "-", NULL);
  GNUNET_free (fn);

  /* Close the write end of the read pipe */
  GNUNET_DISK_pipe_close_end (hello_pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
  /* Close the read end of the write pipe */
  GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_READ);

  wh = GNUNET_DISK_pipe_handle (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE);

  /* Write the test_phrase to the cat process */
  if (GNUNET_DISK_file_write (wh, test_phrase, strlen (test_phrase) + 1) !=
      strlen (test_phrase) + 1)
  {
    GNUNET_break (0);
    ok = 1;
    return;
  }

  /* Close the write end to end the cycle! */
  GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE);

  stdout_read_handle =
      GNUNET_DISK_pipe_handle (hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ);

  die_task =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                    (GNUNET_TIME_UNIT_MINUTES, 1), &end_task,
                                    NULL);

  GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
                                  stdout_read_handle, &read_call,
                                  (void *) stdout_read_handle);
}
Пример #2
0
/**
 * Start the helper process.
 *
 * @param h handle to the helper process
 */
static void
start_helper (struct GNUNET_HELPER_Handle *h)
{
  h->helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
  h->helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
  if ( (h->helper_in == NULL) || (h->helper_out == NULL))
  {
    /* out of file descriptors? try again later... */
    stop_helper (h, GNUNET_NO);
    h->restart_task =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
								  h->retry_back_off),
				    &restart_task, h);
    return;
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
	      "Starting HELPER process `%s'\n",
	      h->binary_name);
  h->fh_from_helper =
      GNUNET_DISK_pipe_handle (h->helper_out, GNUNET_DISK_PIPE_END_READ);
  h->fh_to_helper =
      GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE);
  h->helper_proc =
    GNUNET_OS_start_process_vap (h->with_control_pipe, GNUNET_OS_INHERIT_STD_ERR,
				 h->helper_in, h->helper_out, NULL,
				 h->binary_name,
				 h->binary_argv);
  if (NULL == h->helper_proc)
  {
    /* failed to start process? try again later... */
    stop_helper (h, GNUNET_NO);
    h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
										  h->retry_back_off),
						    &restart_task, h);
    return;
  }
  GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE);
  GNUNET_DISK_pipe_close_end (h->helper_in, GNUNET_DISK_PIPE_END_READ);
  if (NULL != h->mst)
    h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
						   h->fh_from_helper,
						   &helper_read,
						   h);
}
static void
runone ()
{
  const struct GNUNET_DISK_FileHandle *stdout_read_handle;

  pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);

  if (pipe_stdout == NULL)
  {
    GNUNET_break (0);
    ok = 2;
    return;
  }

  putenv ("GNUNET_LOG=");
  putenv ("GNUNET_FORCE_LOG=");
  putenv ("GNUNET_FORCE_LOGFILE=");
  switch (phase)
  {
  case 0:
    putenv ("GNUNET_LOG=;;;;ERROR");
    break;
  case 1:
    putenv ("GNUNET_LOG=;;;;WARNING");
    break;
  case 2:
    putenv ("GNUNET_LOG=;;;;INFO");
    break;
  case 3:
    putenv ("GNUNET_LOG=;;;;DEBUG");
    break;
  case 4:
    putenv ("GNUNET_FORCE_LOG=;;;;ERROR");
    break;
  case 5:
    putenv ("GNUNET_FORCE_LOG=;;;;WARNING");
    break;
  case 6:
    putenv ("GNUNET_FORCE_LOG=;;;;INFO");
    break;
  case 7:
    putenv ("GNUNET_FORCE_LOG=;;;;DEBUG");
    break;
  case 8:
    putenv ("GNUNET_LOG=blah;;;;ERROR");
    break;
  case 9:
    putenv ("GNUNET_FORCE_LOG=blah;;;;ERROR");
    break;
  }

  proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
                                  NULL, pipe_stdout, NULL,
#if MINGW
                                  "test_common_logging_dummy",
#else
                                  "./test_common_logging_dummy",
#endif
                                  "test_common_logging_dummy", NULL);
  GNUNET_assert (NULL != proc);
  putenv ("GNUNET_FORCE_LOG=");
  putenv ("GNUNET_LOG=");

  /* Close the write end of the read pipe */
  GNUNET_DISK_pipe_close_end (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);

  stdout_read_handle =
      GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_READ);

  die_task =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                    (GNUNET_TIME_UNIT_SECONDS, 10), &end_task,
                                    NULL);

  bytes = 0;
  buf_ptr = buf;
  memset (&buf, 0, sizeof (buf));

  read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
					      stdout_read_handle, &read_call,
					      (void*) stdout_read_handle);
}
Пример #4
0
/**
 * Try to get the external IPv4 address of this peer.
 *
 * @param cb function to call with result
 * @param cb_cls closure for @a cb
 * @return handle for cancellation (can only be used until @a cb is called), never NULL
 */
struct GNUNET_NAT_ExternalHandle *
GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb,
				    void *cb_cls)
{
  struct GNUNET_NAT_ExternalHandle *eh;

  eh = GNUNET_new (struct GNUNET_NAT_ExternalHandle);
  eh->cb = cb;
  eh->cb_cls = cb_cls;
  eh->ret = GNUNET_NAT_ERROR_SUCCESS;
  if (GNUNET_SYSERR ==
      GNUNET_OS_check_helper_binary ("external-ip",
				     GNUNET_NO,
				     NULL))
  {
    LOG (GNUNET_ERROR_TYPE_INFO,
	 _("`external-ip' command not found\n"));
    eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND;
    eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
                                         eh);
    return eh;
  }
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Running `external-ip' to determine our external IP\n");
  eh->opipe = GNUNET_DISK_pipe (GNUNET_YES,
				GNUNET_YES,
				GNUNET_NO,
				GNUNET_YES);
  if (NULL == eh->opipe)
  {
    eh->ret = GNUNET_NAT_ERROR_IPC_FAILURE;
    eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
                                         eh);
    return eh;
  }
  eh->eip =
      GNUNET_OS_start_process (GNUNET_NO,
			       0,
			       NULL,
			       eh->opipe,
			       NULL,
                               "external-ip",
			       "external-ip",
                               NULL);
  if (NULL == eh->eip)
  {
    GNUNET_DISK_pipe_close (eh->opipe);
    eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED;
    eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
                                         eh);
    return eh;
  }
  GNUNET_DISK_pipe_close_end (eh->opipe,
			      GNUNET_DISK_PIPE_END_WRITE);
  eh->r = GNUNET_DISK_pipe_handle (eh->opipe,
				   GNUNET_DISK_PIPE_END_READ);
  eh->task 
    = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
                                      eh->r,
                                      &read_external_ipv4,
				      eh);
  return eh;
}