示例#1
0
文件: node.cpp 项目: itroot/elliptics
node::node(const logger &l, const std::string &config_path) : m_data(new node_data)
{
	m_data->log = l;

	struct dnet_config cfg;
	memset(&cfg, 0, sizeof(struct dnet_config));

	cfg.log = m_data->log.get_native();

	std::list<address> remotes;
	std::vector<int> groups;

	parse_config(config_path, cfg, remotes, groups, cfg.log->log_level);

	m_data->node_ptr = dnet_node_create(&cfg);
	if (!m_data->node_ptr) {
		throw std::bad_alloc();
	}

	for (std::list<address>::iterator it = remotes.begin(); it != remotes.end(); ++it) {
		try {
			add_remote(it->host.c_str(), it->port, it->family);
		} catch (...) {
			continue;
		}
	}
}
示例#2
0
struct remote *acquire_remote(struct set *ss, char *name)
{
  struct remote *rs;

  rs = find_remote(ss, name);
  if(rs){
    return rs;
  }

  return add_remote(ss, name);
}
示例#3
0
void node::add_remote(const char *addr)
{
	add_remote(std::string(addr));
}
示例#4
0
static int
add_remote_mdns_data(const char *id, int family, const char *address, int port, char *name, char *paircode)
{
  struct remote_info *ri;
  char *check_addr;
  int ret;

  for (ri = remote_list; ri; ri = ri->next)
    {
      if (!ri->pi.remote_id)
	continue;

      if (strcmp(ri->pi.remote_id, id) == 0)
	break;
    }

  if (!ri)
    {
      DPRINTF(E_DBG, L_REMOTE, "Remote id %s not known, adding\n", id);

      ri = add_remote();
      if (!ri)
	return -1;

      ret = 0;
    }
  else
    {
      DPRINTF(E_DBG, L_REMOTE, "Remote id %s found\n", id);

      free_pi(&ri->pi, 1);

      switch (family)
	{
	  case AF_INET:
	    if (ri->v4_address)
	      free(ri->v4_address);
	    break;

	  case AF_INET6:
	    if (ri->v6_address)
	      free(ri->v6_address);
	    break;
	}

      if (ri->paircode)
	free(ri->paircode);

      ret = 1;
    }

  ri->pi.remote_id = strdup(id);

  switch (family)
    {
      case AF_INET:
	ri->v4_address = strdup(address);
	ri->v4_port = port;

	check_addr = ri->v4_address;
	break;

      case AF_INET6:
	ri->v6_address = strdup(address);
	ri->v6_port = port;

	check_addr = ri->v6_address;
	break;

      default:
	DPRINTF(E_LOG, L_REMOTE, "Unknown address family %d\n", family);

	check_addr = NULL;
	break;
    }

  if (!ri->pi.remote_id || !check_addr)
    {
      DPRINTF(E_LOG, L_REMOTE, "Out of memory for remote pairing data\n");

      remove_remote(ri);
      return -1;
    }

  ri->pi.name = name;
  ri->paircode = paircode;

  return ret;
}
示例#5
0
void node::add_remote(const std::string &addr, const int port, const int family)
{
	add_remote(addr.c_str(), port, family);
}