node::node(logger &l, const std::string &config_path) : m_node(NULL), m_log(NULL) { struct dnet_config cfg; memset(&cfg, 0, sizeof(struct dnet_config)); cfg.sock_type = SOCK_STREAM; cfg.proto = IPPROTO_TCP; m_log = reinterpret_cast<logger *>(l.clone()); cfg.log = m_log->get_dnet_log(); std::list<addr_tuple> remotes; std::vector<int> groups; parse_config(config_path, cfg, remotes, groups, cfg.log->log_level); m_node = dnet_node_create(&cfg); if (!m_node) { delete m_log; throw std::bad_alloc(); } add_groups(groups); for (std::list<addr_tuple>::iterator it = remotes.begin(); it != remotes.end(); ++it) { try { add_remote(it->host.c_str(), it->port, it->family); } catch (...) { continue; } } }
node::node(logger &l, struct dnet_config &cfg) : m_node(NULL), m_log(NULL) { cfg.sock_type = SOCK_STREAM; cfg.proto = IPPROTO_TCP; m_log = reinterpret_cast<logger *>(l.clone()); cfg.log = m_log->get_dnet_log(); snprintf(cfg.addr, sizeof(cfg.addr), "0.0.0.0"); snprintf(cfg.port, sizeof(cfg.port), "0"); m_node = dnet_node_create(&cfg); if (!m_node) { delete m_log; throw std::bad_alloc(); } }