diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2012-03-24 14:55:20 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2012-03-24 14:55:20 +0200 |
commit | 3b008fbbaacd5e88eda1ff023ed1876c0a8d5b3b (patch) | |
tree | 39c798f470a3529e4ea9699a63ba9b6b627fe090 | |
parent | c7475fb35f897e7c3876e3cd8ae54fe00f55c046 (diff) |
static_list duplication for separated independent test
operator== for proxy structures
-rwxr-xr-x | server/server/config.cpp | 20 | ||||
-rwxr-xr-x | server/server/config.h | 40 | ||||
-rwxr-xr-x | server/server/main.cpp | 19 | ||||
-rw-r--r-- | server/server/main.h | 8 |
4 files changed, 54 insertions, 33 deletions
diff --git a/server/server/config.cpp b/server/server/config.cpp index bbbdf54..3be45bd 100755 --- a/server/server/config.cpp +++ b/server/server/config.cpp @@ -2,7 +2,7 @@ extern logtofile *logger; -void reload_config_thread_func(config *cfg, boost::mutex *lists_mutex, boost::mutex *cfg_mutex) +void reload_config_thread_func(config *cfg, boost::mutex *lists_mutex) { while(!boost::this_thread::interruption_requested()) { @@ -10,7 +10,6 @@ void reload_config_thread_func(config *cfg, boost::mutex *lists_mutex, boost::mu if(boost::this_thread::interruption_requested()) return; lists_mutex->lock(); - cfg_mutex->lock(); cfg->load_vars(); cfg->load_cvars(); cfg->load_proxy_list(); @@ -19,21 +18,23 @@ void reload_config_thread_func(config *cfg, boost::mutex *lists_mutex, boost::mu cfg->load_deleted_list(); cfg->load_upload_list(); cfg->load_servers_list(); - cfg_mutex->unlock(); lists_mutex->unlock(); } } -void speed_test_thread_func(config *cfg, int check_interval, std::list<config::proxy_entry>* proxy_list, std::list<config::static_proxy_entry> *static_proxy_list, const std::string& test_url, boost::mutex *lists_mutex, boost::mutex *cfg_mutex) +void speed_test_thread_func(config *cfg, int check_interval, std::list<config::proxy_entry>* proxy_list, std::list<config::static_proxy_entry> *static_proxy_list, const std::string& test_url, boost::mutex *lists_mutex) { while(!boost::this_thread::interruption_requested()) { - cfg_mutex->lock(); - for(std::list<config::static_proxy_entry>::iterator i = static_proxy_list->begin(), end = static_proxy_list->end(); i != end; ++i) + std::list<config::static_proxy_entry> tmp_list = *static_proxy_list; + for(std::list<config::static_proxy_entry>::iterator i = tmp_list.begin(), end = tmp_list.end(); i != end; ++i) { - lists_mutex->lock(); speedtest t(test_url); size_t sp = t.test(&(*i)); + lists_mutex->lock(); + std::list<config::static_proxy_entry>::iterator it = std::find(static_proxy_list->begin(), static_proxy_list->end(), *i); + if(it != static_proxy_list->end()) + *it = *i; lists_mutex->unlock(); if(cfg->log_speed()) { @@ -55,7 +56,6 @@ void speed_test_thread_func(config *cfg, int check_interval, std::list<config::p boost::this_thread::sleep(boost::posix_time::seconds(1)); } */ // delete l; - cfg_mutex->unlock(); boost::this_thread::sleep(boost::posix_time::seconds(check_interval)); } } @@ -134,8 +134,8 @@ config::config(const char *pth): cfg_reload_thr(NULL), speed_test_thr(NULL) load_deleted_list(); load_upload_list(); load_servers_list(); - cfg_reload_thr = new boost::thread(boost::bind(reload_config_thread_func, this, &lists_mutex, &cfg_mutex)); - speed_test_thr = new boost::thread(boost::bind(speed_test_thread_func, this, vars.proxy_check_interval, &proxy_list, &static_proxy_list, vars.speed_test_file_url, &lists_mutex, &cfg_mutex)); + cfg_reload_thr = new boost::thread(boost::bind(reload_config_thread_func, this, &lists_mutex)); + speed_test_thr = new boost::thread(boost::bind(speed_test_thread_func, this, vars.proxy_check_interval, &proxy_list, &static_proxy_list, vars.speed_test_file_url, &lists_mutex)); } const int config::get_int(const std::string& data, const char* var, int default_) { diff --git a/server/server/config.h b/server/server/config.h index 9b15208..40f5985 100755 --- a/server/server/config.h +++ b/server/server/config.h @@ -18,6 +18,24 @@ public: proxy_type type; proxy_entry_base(): port(0), speed(0), type(UNKNOWN) {} + bool operator==(const proxy_entry_base& e) + { + if(host != e.host) + return false; + if(login != e.login) + return false; + if(password != e.password) + return false; + if(port != e.port) + return false; + if(type != e.type) + return false; + return true; + } + bool operator!=(const proxy_entry_base& e) + { + return !((*this) == e); + } }; struct proxy_entry : public proxy_entry_base { @@ -33,6 +51,18 @@ public: city = city_; type = t; } + bool operator==(const proxy_entry& e) + { + if((proxy_entry_base)(*this) != (proxy_entry_base)e) + return false; + if(country != e.country) + return false; + if(state != e.state) + return false; + if(city != e.city) + return false; + return true; + } }; struct static_proxy_entry : public proxy_entry_base @@ -51,6 +81,16 @@ public: position = position_; type = t; } + bool operator==(const static_proxy_entry& e) + { + if((proxy_entry_base)(*this) != (proxy_entry_base)e) + return false; + if(position != e.position) + return false; + if(label != e.label) + return false; + return true; + } }; struct s_i diff --git a/server/server/main.cpp b/server/server/main.cpp index 7682cde..fa97e32 100755 --- a/server/server/main.cpp +++ b/server/server/main.cpp @@ -8,8 +8,7 @@ logtofile *logger = NULL, *dos_logger = NULL; //session -session::session(boost::asio::io_service& io_service, boost::asio::ssl::context& context, server *serv) : socket_(io_service, context), io_service_(io_service), lists_mutex(serv->get_lists_mutex()), - cfg_mutex(serv->get_cfg_mutex()), cfg(serv->get_config()) +session::session(boost::asio::io_service& io_service, boost::asio::ssl::context& context, server *serv) : socket_(io_service, context), io_service_(io_service), lists_mutex(serv->get_lists_mutex()), cfg(serv->get_config()) { this_sid = get_random(8); server_ = serv; @@ -198,7 +197,6 @@ void session::proto_parser(std::vector<byte>& data) data.push_back(0x13); data.push_back(0x01); lists_mutex.lock(); - cfg_mutex.lock(); if(!cfg->get_server_list()->empty()) { for(std::list<config::conn_server>::iterator i = cfg->get_server_list()->begin(), end = cfg->get_server_list()->end(); i != end; ++i) @@ -235,7 +233,6 @@ void session::proto_parser(std::vector<byte>& data) data.push_back('\n'); } } - cfg_mutex.unlock(); lists_mutex.unlock(); data.push_back(0x14); data.push_back(0x14); @@ -285,7 +282,6 @@ void session::proto_parser(std::vector<byte>& data) data.push_back(0x13); data.push_back(0x02); lists_mutex.lock(); - cfg_mutex.lock(); for(std::list<config::proxy_entry>::iterator it = cfg->get_proxy_list()->begin(), end = cfg->get_proxy_list()->end(); it != end; ++it) { switch(it->type) @@ -374,7 +370,6 @@ void session::proto_parser(std::vector<byte>& data) data.push_back('"'); data.push_back(';'); } - cfg_mutex.unlock(); lists_mutex.unlock(); data.push_back(0x14); data.push_back(0x14); @@ -424,7 +419,6 @@ void session::proto_parser(std::vector<byte>& data) data.push_back(0x13); data.push_back(0x03); lists_mutex.lock(); - cfg_mutex.lock(); for(std::list<config::static_proxy_entry>::iterator it = cfg->get_static_proxy_list()->begin(), end = cfg->get_static_proxy_list()->end(); it != end; ++it) { switch(it->type) @@ -505,7 +499,6 @@ void session::proto_parser(std::vector<byte>& data) //data.push_back('0'); //add speed here data.push_back(';'); } - cfg_mutex.unlock(); lists_mutex.unlock(); data.push_back(0x14); data.push_back(0x14); @@ -555,7 +548,6 @@ void session::proto_parser(std::vector<byte>& data) data.push_back(0x13); data.push_back(0x04); lists_mutex.lock(); - cfg_mutex.lock(); for(std::list<std::string>::iterator it = cfg->get_firewall_list()->begin(), end = cfg->get_firewall_list()->end(); it != end; ++it) { if(!(it->empty())) @@ -563,7 +555,6 @@ void session::proto_parser(std::vector<byte>& data) data.push_back((*it)[i]); data.push_back(';'); } - cfg_mutex.unlock(); lists_mutex.unlock(); data.push_back(0x14); data.push_back(0x14); @@ -613,7 +604,6 @@ void session::proto_parser(std::vector<byte>& data) data.push_back(0x13); data.push_back(0x05); lists_mutex.lock(); - cfg_mutex.lock(); for(std::list<config::upload_entry>::iterator it = cfg->get_upload_list()->begin(), end = cfg->get_upload_list()->end(); it != end; ++it) { /*if(!(it->source.empty())) @@ -633,7 +623,6 @@ void session::proto_parser(std::vector<byte>& data) data.push_back('0'); data.push_back(';'); } - cfg_mutex.unlock(); lists_mutex.unlock(); data.push_back(0x14); data.push_back(0x14); @@ -683,7 +672,6 @@ void session::proto_parser(std::vector<byte>& data) data.push_back(0x13); data.push_back(0x06); lists_mutex.lock(); - cfg_mutex.lock(); for(std::list<std::string>::iterator it = cfg->get_deleted_list()->begin(), end = cfg->get_deleted_list()->end(); it != end; ++it) { if(!(it->empty())) @@ -691,7 +679,6 @@ void session::proto_parser(std::vector<byte>& data) data.push_back((*it)[i]); data.push_back(';'); } - cfg_mutex.unlock(); lists_mutex.unlock(); data.push_back(0x14); data.push_back(0x14); @@ -881,7 +868,6 @@ void session::proto_parser(std::vector<byte>& data) filename += (char)*it; } lists_mutex.lock(); - cfg_mutex.lock(); std::list<config::upload_entry>::iterator uit = std::find(cfg->get_upload_list()->begin(), cfg->get_upload_list()->end(), config::s_i(filename, 1)); if(uit == cfg->get_upload_list()->end()) { @@ -893,7 +879,6 @@ void session::proto_parser(std::vector<byte>& data) } break; } - cfg_mutex.unlock(); lists_mutex.unlock(); std::ifstream file; file.open(uit->source.c_str(), std::ios::binary | std::ios::in); @@ -1059,7 +1044,7 @@ void session::handle_read(const boost::system::error_code& error, size_t bytes_t //server server::server(boost::asio::io_service& io_service, unsigned short port, config *c) : io_service_(io_service), acceptor_(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::from_string(c->bind_ip()), port)), -context_(io_service, boost::asio::ssl::context::sslv3_server), lists_mutex(c->get_lists_mutex()), cfg_mutex(c->get_cfg_mutex()), cfg(c) +context_(io_service, boost::asio::ssl::context::sslv3_server), lists_mutex(c->get_lists_mutex()), cfg(c) { boost::system::error_code err; std::string b_path = boost::filesystem::initial_path().string(), tmp_path; diff --git a/server/server/main.h b/server/server/main.h index d2ad412..0ebd349 100644 --- a/server/server/main.h +++ b/server/server/main.h @@ -59,7 +59,7 @@ private: server *server_; bool blacklisted, canceled; boost::thread *killer; - boost::mutex critical_mutex, &lists_mutex, &cfg_mutex; + boost::mutex critical_mutex, &lists_mutex; config *cfg; }; struct conn_count @@ -104,10 +104,6 @@ public: { return lists_mutex; } - boost::mutex &get_cfg_mutex() - { - return cfg_mutex; - } config *get_config() { return cfg; @@ -119,7 +115,7 @@ private: std::list<conn_count> conns; std::list<std::string> blacklist; boost::thread *flood_chek, *blacklist_clean; - boost::mutex &lists_mutex, &cfg_mutex; + boost::mutex &lists_mutex; config *cfg; }; |