Example #1
0
/**
 * Enable a microphone.
 *
 * @param cls clsoure with our `struct Microphone`
 * @param rdc function to call with recorded data
 * @param rdc_cls closure for @a dc
 */
static int
enable (void *cls,
	GNUNET_MICROPHONE_RecordedDataCallback rdc,
	void *rdc_cls)
{
  struct Microphone *mic = cls;
  static char * const record_helper_argv[] =
  {
    "gnunet-helper-audio-record",
    NULL
  };

  mic->rdc = rdc;
  mic->rdc_cls = rdc_cls;
  mic->record_helper = GNUNET_HELPER_start (GNUNET_NO,
					    "gnunet-helper-audio-record",
					    record_helper_argv,
					    &process_record_messages,
					    NULL, mic);
  if (NULL == mic->record_helper)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
		_("Could not start record audio helper\n"));
    return GNUNET_SYSERR;
  }
  return GNUNET_OK;
}
Example #2
0
/**
 * Start a directory scanner thread.
 *
 * @param filename name of the directory to scan
 * @param disable_extractor GNUNET_YES to not to run libextractor on files (only build a tree)
 * @param ex if not NULL, must be a list of extra plugins for extractor
 * @param cb the callback to call when there are scanning progress messages
 * @param cb_cls closure for 'cb'
 * @return directory scanner object to be used for controlling the scanner
 */
struct GNUNET_FS_DirScanner *
GNUNET_FS_directory_scan_start (const char *filename,
				int disable_extractor, const char *ex,
				GNUNET_FS_DirScannerProgressCallback cb, 
				void *cb_cls)
{
  struct stat sbuf;
  char *filename_expanded;
  struct GNUNET_FS_DirScanner *ds;

  if (0 != STAT (filename, &sbuf))
    return NULL;
  filename_expanded = GNUNET_STRINGS_filename_expand (filename);
  if (NULL == filename_expanded)
    return NULL;
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
	      "Starting to scan directory `%s'\n",
	      filename_expanded);
  ds = GNUNET_malloc (sizeof (struct GNUNET_FS_DirScanner));
  ds->progress_callback = cb;
  ds->progress_callback_cls = cb_cls;
  ds->filename_expanded = filename_expanded;
  if (disable_extractor)  
    ds->ex_arg = GNUNET_strdup ("-");
  else 
    ds->ex_arg = (NULL != ex) ? GNUNET_strdup (ex) : NULL;
  ds->args[0] = "gnunet-helper-fs-publish";
  ds->args[1] = ds->filename_expanded;
  ds->args[2] = ds->ex_arg;
  ds->args[3] = NULL;
  ds->helper = GNUNET_HELPER_start (GNUNET_NO,
				    "gnunet-helper-fs-publish",
				    ds->args,
				    &process_helper_msgs,
				    &helper_died_cb, ds);
  if (NULL == ds->helper)
    {
    GNUNET_free (filename_expanded);
    GNUNET_free (ds);
    return NULL;
  }
  return ds;
}
Example #3
0
/**
 * Function that enables a speaker.
 *
 * @param cls closure with the `struct Speaker`
 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
 */
static int
enable (void *cls)
{
  struct Speaker *spe = cls;
  static char *playback_helper_argv[] =
  {
    "gnunet-helper-audio-playback",
    NULL
  };

  spe->playback_helper = GNUNET_HELPER_start (GNUNET_NO,
					      "gnunet-helper-audio-playback",
					      playback_helper_argv,
					      NULL,
					      NULL, spe);
  if (NULL == spe->playback_helper)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
		_("Could not start playback audio helper.\n"));
    return GNUNET_SYSERR;
  }
  return GNUNET_OK;
}
Example #4
0
/**
 * Starts a controller process at the given host.  The given host's configration
 * is used as a Template configuration to use for the remote controller; the
 * remote controller will be started with a slightly modified configuration
 * (port numbers, unix domain sockets and service home values are changed as per
 * TESTING library on the remote host).  The modified configuration replaces the
 * host's existing configuration before signalling success through the
 * GNUNET_TESTBED_ControllerStatusCallback()
 *
 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
 *          HOST(all connections form this ip are permitted by the testbed) when
 *          starting testbed controller at host. This can either be a single ip
 *          address or a network address in CIDR notation.
 * @param host the host where the controller has to be started.  CANNOT be NULL.
 * @param cb function called when the controller is successfully started or
 *          dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
 *          called if cb is called with GNUNET_SYSERR as status. Will never be
 *          called in the same task as 'GNUNET_TESTBED_controller_start'
 *          (synchronous errors will be signalled by returning NULL). This
 *          parameter cannot be NULL.
 * @param cls closure for above callbacks
 * @return the controller process handle, NULL on errors
 */
struct GNUNET_TESTBED_ControllerProc *
GNUNET_TESTBED_controller_start (const char *trusted_ip,
                                 struct GNUNET_TESTBED_Host *host,
                                 GNUNET_TESTBED_ControllerStatusCallback cb,
                                 void *cls)
{
  struct GNUNET_TESTBED_ControllerProc *cp;
  struct GNUNET_TESTBED_HelperInit *msg;
  const struct GNUNET_CONFIGURATION_Handle *cfg;
  const char *hostname;
  static char *const binary_argv[] = {
    HELPER_TESTBED_BINARY, NULL
  };

  GNUNET_assert (NULL != host);
  GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host)));
  hostname = NULL;
  API_VIOLATION (GNUNET_NO == host->locked,
                 "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()");
  host->locked = GNUNET_YES;
  API_VIOLATION (GNUNET_NO == host->controller_started,
                 "Attempting to start a controller on a host which is already started a controller");
  cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc);
  if (0 == GNUNET_TESTBED_host_get_id_ (host))
  {
    cp->helper =
        GNUNET_HELPER_start (GNUNET_YES, HELPER_TESTBED_BINARY, binary_argv,
                             &helper_mst, &helper_exp_cb, cp);
  }
  else
  {
    char *helper_binary_path_args[2];
    char **rsh_args;
    char **rsh_suffix_args;
    const char *username;
    char *port;
    char *argstr;
    char *aux;
    unsigned int cnt;

    username = host->username;
    hostname = host->hostname;
    GNUNET_asprintf (&port, "%u", host->port);
    LOG_DEBUG ("Starting remote connection to destination %s\n", hostname);
    if (GNUNET_OK !=
        GNUNET_CONFIGURATION_get_value_filename (cfg, "testbed",
                                               "HELPER_BINARY_PATH",
                                               &helper_binary_path_args[0]))
      helper_binary_path_args[0] =
          GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
    helper_binary_path_args[1] = NULL;
    rsh_args = gen_rsh_args (port, hostname, username);
    rsh_suffix_args = gen_rsh_suffix_args ((const char **) helper_binary_path_args);
    cp->helper_argv =
        join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
    free_argv (rsh_args);
    free_argv (rsh_suffix_args);
    GNUNET_free (port);
    argstr = GNUNET_strdup ("");
    for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++)
    {
      aux = argstr;
      GNUNET_assert (0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt]));
      GNUNET_free (aux);
    }
    LOG_DEBUG ("Helper cmd str: %s\n", argstr);
    GNUNET_free (argstr);
    cp->helper =
        GNUNET_HELPER_start (GNUNET_NO, cp->helper_argv[0], cp->helper_argv, &helper_mst,
                             &helper_exp_cb, cp);
    GNUNET_free (helper_binary_path_args[0]);
  }
  if (NULL == cp->helper)
  {
    if (NULL != cp->helper_argv)
      free_argv (cp->helper_argv);
    GNUNET_free (cp);
    return NULL;
  }
  cp->host = host;
  cp->cb = cb;
  cp->cls = cls;
  msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg);
  cp->msg = &msg->header;
  cp->shandle =
      GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp);
  if (NULL == cp->shandle)
  {
    GNUNET_free (msg);
    GNUNET_TESTBED_controller_stop (cp);
    return NULL;
  }
  return cp;
}