示例#1
0
static int
create_children(mmd_t *mdp,
    di_prom_handle_t ph, md_node_t *md_parent, di_node_t di_parent)
{
	md_node_t	*md_node;
	md_node_t	*md_child;
	di_node_t	di_child;
	char		*path;
	int		rv;

	path = di_devfs_path(di_parent);
	if (path == NULL)
		return (EIO);

	md_node = link_device_node(mdp, ph, di_parent, md_parent, path);
	di_devfs_path_free(path);
	if (md_node == NULL) {
		return (ENOMEM);
	}

	while ((di_child = di_child_node(di_parent)) != DI_NODE_NIL) {
		path = di_devfs_path(di_child);
		if (path != NULL) {
			md_child = link_device_node(mdp,
			    ph, di_child, md_node, path);
			di_devfs_path_free(path);
			if (md_child == NULL) {
				return (ENOMEM);
			}
		}

		rv = create_peers(mdp, ph, md_node, di_child);
		if (rv != 0)
			return (rv);

		md_node = md_child;
		di_parent = di_child;
	}
	return (0);
}
示例#2
0
/**
 * Signature of the event handler function called by the
 * respective event controller.
 *
 * @param cls closure
 * @param event information about the event
 */
static void
event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
{
  struct GNUNET_TESTBED_RunHandle *rc = cls;
  struct RunContextOperation *rcop;

  if (RC_INIT == rc->state)
  {
    switch (event->type)
    {
    case GNUNET_TESTBED_ET_OPERATION_FINISHED:
      rcop = event->op_cls;
      if (NULL != event->details.operation_finished.emsg)
      {
        LOG (GNUNET_ERROR_TYPE_ERROR, _("Linking controllers failed. Exiting"));
        GNUNET_SCHEDULER_shutdown ();
      }
      else
        rc->reg_hosts++;
      GNUNET_assert (event->op == rcop->op);
      remove_rcop (rc, rcop);
      GNUNET_TESTBED_operation_done (rcop->op);
      GNUNET_free (rcop);
      if (rc->reg_hosts == rc->num_hosts)
      {
        rc->state = RC_LINKED;
        create_peers (rc);
      }
      return;
    default:
      GNUNET_break (0);
      GNUNET_SCHEDULER_shutdown ();
      return;
    }
  }
  if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type)
    goto call_cc;
  if (NULL == (rcop = search_rcop (rc, event->op)))
    goto call_cc;
  remove_rcop (rc, rcop);
  GNUNET_TESTBED_operation_done (rcop->op);
  GNUNET_free (rcop);
  if ( (GNUNET_NO == rc->shutdown)
       && (NULL != event->details.operation_finished.emsg) )
  {
    LOG (GNUNET_ERROR_TYPE_ERROR, "A operation has failed with error: %s\n",
         event->details.operation_finished.emsg);
    GNUNET_SCHEDULER_shutdown ();
    return;
  }
  GNUNET_assert (GNUNET_YES == rc->shutdown);
  switch (rc->state)
  {
  case RC_LINKED:
  case RC_PEERS_CREATED:
  case RC_READY:
    rc->state = RC_PEERS_SHUTDOWN;
    GNUNET_free_non_null (rc->peers);
    rc->peers = NULL;
    DEBUG ("Peers shut down in %s\n", prof_time (rc));
    GNUNET_SCHEDULER_shutdown ();
    break;
  default:
    GNUNET_assert (0);
  }
  return;

call_cc:
  if ((0 != (rc->event_mask & (1LL << event->type))) && (NULL != rc->cc))
    rc->cc (rc->cc_cls, event);
  if (GNUNET_TESTBED_ET_PEER_START != event->type)
    return;
  if (NULL == (rcop = search_rcop (rc, event->op))) /* Not our operation */
    return;
  remove_rcop (rc, rcop);
  GNUNET_TESTBED_operation_done (rcop->op);
  GNUNET_free (rcop);
  rc->peer_count++;
  if (rc->peer_count < rc->num_peers)
    return;
  DEBUG ("%u peers started in %s\n", rc->num_peers, prof_time (rc));
  if (GNUNET_TESTBED_TOPOLOGY_NONE != rc->topology)
  {
    switch (rc->topology)
    {
    case GNUNET_TESTBED_TOPOLOGY_NONE:
      GNUNET_assert (0);
    case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
    case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
    case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
      rc->topology_operation =
          GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
                                                     rc->peers, &rc->num_oc,
                                                     &topology_completion_callback,
                                                     rc,
                                                     rc->topology,
                                                     rc->random_links,
                                                     GNUNET_TESTBED_TOPOLOGY_OPTION_END);
      break;
    case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
      GNUNET_assert (NULL != rc->topo_file);
      rc->topology_operation =
          GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
                                                     rc->peers, &rc->num_oc,
                                                     &topology_completion_callback,
                                                     rc,
                                                     rc->topology,
                                                     rc->topo_file,
                                                     GNUNET_TESTBED_TOPOLOGY_OPTION_END);
      break;
    case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
      {
        unsigned long long number;
        unsigned int cap;
        GNUNET_assert (GNUNET_OK ==
                       GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION,
                                                              SCALE_FREE_CAP,
                                                              &number));
        cap = (unsigned int) number;
        GNUNET_assert (GNUNET_OK ==
                       GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION,
                                                              SCALE_FREE_M,
                                                              &number));
        rc->topology_operation =
            GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
                                                       rc->peers, &rc->num_oc,
                                                       &topology_completion_callback,
                                                       rc,
                                                       rc->topology,
                                                       cap,    /* uint16_t */
                                                       (unsigned int) number, /* uint8_t */
                                                       GNUNET_TESTBED_TOPOLOGY_OPTION_END);
      }
      break;
    default:
      rc->topology_operation =
          GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
                                                     rc->peers, &rc->num_oc,
                                                     &topology_completion_callback,
                                                     rc,
                                                     rc->topology,
                                                     GNUNET_TESTBED_TOPOLOGY_OPTION_END);
    }
    if (NULL == rc->topology_operation)
      LOG (GNUNET_ERROR_TYPE_WARNING,
           "Not generating a topology. Check number of peers\n");
    else
    {
      DEBUG ("Creating overlay topology\n");
      rc->pstart_time = GNUNET_TIME_absolute_get ();
      return;
    }
  }
  rc->state = RC_READY;
  call_master (rc);
}