Ejemplo n.º 1
0
center::center(std::string filename, std::string key){
	isrun = true;

	boost::shared_ptr<config::config> _config = boost::make_shared<config::config>(filename);
	if (_config == nullptr){
		throw std::exception(("cannot find config file" + filename).c_str());
	}


	auto center_config = _config->get_value_dict("center");
	if (center_config == 0){
		throw std::exception("cannot find center config");
	} else{
		try{
			center_addr.first = center_config->get_value_string("ip");
			center_addr.second = (short)center_config->get_value_int("port");
		} catch(...){
			throw std::exception("center config field error");
		}
	}

	servernum = 0;

	_service = juggle::create_service();
	_process = boost::make_shared<juggle::process>();
	_channelservice = boost::make_shared<achieve::channelservice>();

	_svrsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);

	auto key_config = _config->get_value_dict("key");
	if (key_config == 0){
		throw std::exception("cannot find this config");
	} else{
		auto set = boost::make_shared<std::vector<std::pair<std::string, short> > >();
		auto dict = _config->get_value_dict("blacklist");
		for (size_t i = 0; i < dict->get_list_size(); i++){
			auto e = dict->get_list_dict(i);
			auto ip = e->get_value_string("ip");
			auto port = (short)e->get_value_int("port");
			set->push_back(std::make_pair(ip, port));
		}
		_writeacceptor = boost::make_shared<acceptor::writeacceptor>(key_config->get_value_string("ip"), key_config->get_value_int("port"), set, _channelservice, _svrsessioncontainer);
	}
	_timerservice = timer::timerservice::createinstance();

	_module = boost::make_shared<module::center>(_process);
	_module->sigregister_db.connect(boost::bind(&center::register_db, this, _1, _2));
	_module->sigregister_gate.connect(boost::bind(&center::register_gate, this, _1, _2));
	_module->sigregister_routing.connect(boost::bind(&center::register_routing, this, _1, _2));
	_module->sigregister_logic.connect(boost::bind(&center::register_logic, this, _1, _2));
}
Ejemplo n.º 2
0
writeacceptor::writeacceptor(boost::shared_ptr<config::config> _config, boost::shared_ptr<achieve::channelservice> _chservice, boost::shared_ptr<achieve::sessioncontainer> _sc){
	acp = boost::make_shared<achieve::acceptor>(_chservice, _sc);
	
	auto ip = _config->get_value_string("ip");
	auto port = (short)_config->get_value_int("port");
	
	acp->init((char*)ip.c_str(), port);

	auto set = boost::make_shared<std::vector<std::pair<std::string, short> > >();
	auto dict = _config->get_value_dict("writelist");
	for (size_t i = 0; i < dict->get_list_size(); i++){
		auto e = dict->get_list_dict(i);
		auto ip = e->get_list_string(0);
		auto port = (short)e->get_list_int(1);
		set->push_back(std::make_pair(ip, port));
	}

	epfitle = boost::make_shared<fitle::fitle<std::pair<std::string, short> > >();

	epfitle->setfitle(
		[set](std::pair<std::string, short> ep){
			for(auto e : *set){
				if (ep.first == e.first){
					if (e.second == 0){
						return false;
					}else if (e.second == ep.second){
						return false;
					}
				}else{
					return false;
				}
			}
			return true;
		}
	);

	acp->set_fitle(epfitle);
}
Ejemplo n.º 3
0
gate::gate(std::string filename, std::string key){
	isrun = true;

	boost::shared_ptr<config::config> _config = boost::make_shared<config::config>(filename);

	auto center_config = _config->get_value_dict("center");
	if (center_config == 0){
		throw std::exception("cannot find center config");
	} else{
		try{
			center_addr.first = center_config->get_value_string("ip");
			center_addr.second = (short)center_config->get_value_int("port");
		} catch(...){
			throw std::exception("center config field error");
		}
	}

	auto routing_config = _config->get_value_dict("routing");
	if (routing_config == 0){
		throw std::exception("cannot find routing config");
	} else{
		try{
			auto size = routing_config->get_list_size();
			routing_server.resize(size);
			for (uint32_t i = 0; i < size; i++){
				auto cfig = routing_config->get_list_dict(i);
				routing_server[cfig->get_value_int("serial ")].first.first = cfig->get_value_string("ip");
				routing_server[cfig->get_value_int("serial ")].first.second = cfig->get_value_int("port");
				routing_server[cfig->get_value_int("serial ")].second = nullptr;
			}
		} catch (...){
			throw std::exception("routing config field error");
		}
	}

	_service = juggle::create_service();
	
	_channelservice = boost::make_shared<achieve::channelservice>();
	_rpcproxy = boost::make_shared<rpcproxy>(boost::bind(&gate::get_channel, this, _1, _2));

	_usersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _rpcproxy);
	_usersessioncontainer->sigdisconn.connect(boost::bind(&gate::user_disconn, this, _1));
	
	_process = boost::make_shared<juggle::process>();

	_logicsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_logicsessioncontainer->sigconn.connect(boost::bind(&gate::on_logic_conn, this, _1));
	_logicsessioncontainer->sigdisconn.connect(boost::bind(&gate::logic_disconn, this, _1));

	auto gate_config = _config->get_value_dict("key");
	if (gate_config == 0){
		throw std::exception("cannot find this config");
	} else{
		auto set = boost::make_shared<std::vector<std::pair<std::string, short> > >();
		auto dict = _config->get_value_dict("blacklist");
		for (size_t i = 0; i < dict->get_list_size(); i++){
			auto e = dict->get_list_dict(i);
			auto ip = e->get_value_string("ip");
			auto port = (short)e->get_value_int("port");
			set->push_back(std::make_pair(ip, port));
		}
		_blackacceptor = boost::make_shared<acceptor::blackacceptor>(gate_config->get_value_string("ip"), gate_config->get_value_int("port"), set, _channelservice, _usersessioncontainer);
		
		auto writeset = boost::make_shared<std::vector<std::pair<std::string, short> > >();
		auto writedict = _config->get_value_dict("writelist");
		for (size_t i = 0; i < dict->get_list_size(); i++){
			auto e = writedict->get_list_dict(i);
			auto ip = e->get_value_string("ip");
			auto port = (short)e->get_value_int("port");
			writeset->push_back(std::make_pair(ip, port));
		}
		_writeacceptor = boost::make_shared<acceptor::writeacceptor>(gate_config->get_value_string("clusterip"), gate_config->get_value_int("clusterport"), writeset, _channelservice, _logicsessioncontainer);
	}

	_timerservice = timer::timerservice::createinstance();
	_module = boost::make_shared<module::gate>(_process);

	_routingsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_routingconnector = boost::make_shared<connector::connector>(_channelservice, _routingsessioncontainer);

	_centersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_centerconnector = boost::make_shared<connector::connector>(_channelservice, _centersessioncontainer);
}
Ejemplo n.º 4
0
gate::gate(std::string filename, std::string key){
	isrun = true;

	boost::shared_ptr<config::config> _config = boost::make_shared<config::config>(filename);

	auto center_config = _config->get_value_dict("center");
	if (center_config == 0){
		throw std::exception("cannot find center config");
	} else{
		try{
			center_addr.first = center_config->get_value_string("ip");
			center_addr.second = (short)center_config->get_value_int("port");
		} catch(...){
			throw std::exception("center config field error");
		}
	}

	auto routing_config = _config->get_value_dict("routing");
	if (routing_config == 0){
		throw std::exception("cannot find routing config");
	} else{
		try{
			auto size = routing_config->get_list_size();
			routing_server.resize(size);
			for (uint32_t i = 0; i < size; i++){
				auto cfig = routing_config->get_list_dict(i);
				routing_server[cfig->get_value_int("serial ")].first.first = cfig->get_value_string("ip");
				routing_server[cfig->get_value_int("serial ")].first.second = cfig->get_value_int("port");
				routing_server[cfig->get_value_int("serial ")].second = nullptr;
			}
		} catch (...){
			throw std::exception("routing config field error");
		}
	}

	_service = juggle::create_service();
	
	_channelservice = boost::make_shared<achieve::channelservice>();
	_rpcproxy = boost::make_shared<rpcproxy>(boost::bind(&gate::get_channel, this, _1, _2));
	_usersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _rpcproxy);
	
	_usersessioncontainer->sigdisconn.connect(boost::bind(&gate::user_disconn, this, _1));

	auto gate_config = _config->get_value_dict("key");
	if (gate_config == 0){
		throw std::exception("cannot find this config");
	} else{
		_blackacceptor = boost::make_shared<acceptor::blackacceptor>(gate_config, _channelservice, _usersessioncontainer);
	}

	_timerservice = timer::timerservice::createinstance();

	_process = boost::make_shared<juggle::process>();

	_module = boost::make_shared<module::gate>(_process);
	_module->sigregister_logic.connect(boost::bind(&gate::add_logic, this, _1, _2));

	_logicsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_logicconnector = boost::make_shared<connector::connector>(_channelservice, _logicsessioncontainer);

	_routingsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_routingconnector = boost::make_shared<connector::connector>(_channelservice, _routingsessioncontainer);

	_centersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process);
	_centerconnector = boost::make_shared<connector::connector>(_channelservice, _centersessioncontainer);
}