summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xserver/server/config.cpp20
-rwxr-xr-xserver/server/config.h6
-rwxr-xr-xserver/server/main.cpp21
-rw-r--r--server/server/main.h8
4 files changed, 42 insertions, 13 deletions
diff --git a/server/server/config.cpp b/server/server/config.cpp
index 4f32c0a..bbbdf54 100755
--- a/server/server/config.cpp
+++ b/server/server/config.cpp
@@ -2,14 +2,15 @@
extern logtofile *logger;
-void reload_config_thread_func(config *cfg, boost::mutex *m)
+void reload_config_thread_func(config *cfg, boost::mutex *lists_mutex, boost::mutex *cfg_mutex)
{
while(!boost::this_thread::interruption_requested())
{
boost::this_thread::sleep(boost::posix_time::seconds(cfg->config_reload_interval()));
if(boost::this_thread::interruption_requested())
return;
- m->lock();
+ lists_mutex->lock();
+ cfg_mutex->lock();
cfg->load_vars();
cfg->load_cvars();
cfg->load_proxy_list();
@@ -18,19 +19,22 @@ void reload_config_thread_func(config *cfg, boost::mutex *m)
cfg->load_deleted_list();
cfg->load_upload_list();
cfg->load_servers_list();
- m->unlock();
+ 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 *m)
+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)
{
while(!boost::this_thread::interruption_requested())
{
- m->lock();
+ cfg_mutex->lock();
for(std::list<config::static_proxy_entry>::iterator i = static_proxy_list->begin(), end = static_proxy_list->end(); i != end; ++i)
{
+ lists_mutex->lock();
speedtest t(test_url);
size_t sp = t.test(&(*i));
+ lists_mutex->unlock();
if(cfg->log_speed())
{
char port[10];
@@ -51,7 +55,7 @@ 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;
- m->unlock();
+ cfg_mutex->unlock();
boost::this_thread::sleep(boost::posix_time::seconds(check_interval));
}
}
@@ -130,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));
- 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_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));
}
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 4afa63d..9b15208 100755
--- a/server/server/config.h
+++ b/server/server/config.h
@@ -144,6 +144,10 @@ public:
{
return lists_mutex;
}
+ boost::mutex &get_cfg_mutex()
+ {
+ return cfg_mutex;
+ }
private:
struct cfg_data
{
@@ -164,7 +168,7 @@ private:
std::list<upload_entry> upload_list;
std::list<conn_server> servers_list;
boost::thread *cfg_reload_thr, *speed_test_thr;
- boost::mutex lists_mutex;
+ boost::mutex lists_mutex, cfg_mutex;
};
#endif \ No newline at end of file
diff --git a/server/server/main.cpp b/server/server/main.cpp
index 38ee904..7682cde 100755
--- a/server/server/main.cpp
+++ b/server/server/main.cpp
@@ -8,7 +8,8 @@ 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(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_mutex(serv->get_cfg_mutex()), cfg(serv->get_config())
{
this_sid = get_random(8);
server_ = serv;
@@ -197,6 +198,7 @@ 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)
@@ -233,6 +235,7 @@ 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);
@@ -282,6 +285,7 @@ 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)
@@ -370,6 +374,7 @@ 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);
@@ -419,6 +424,7 @@ 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)
@@ -499,6 +505,7 @@ 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);
@@ -548,6 +555,7 @@ 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()))
@@ -555,6 +563,7 @@ 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);
@@ -604,6 +613,7 @@ 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()))
@@ -623,6 +633,7 @@ 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);
@@ -672,6 +683,7 @@ 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()))
@@ -679,6 +691,7 @@ 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);
@@ -867,6 +880,8 @@ 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())
{
@@ -878,6 +893,8 @@ 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);
if(file.is_open())
@@ -1042,7 +1059,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(c)
+context_(io_service, boost::asio::ssl::context::sslv3_server), lists_mutex(c->get_lists_mutex()), cfg_mutex(c->get_cfg_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 0ebd349..d2ad412 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;
+ boost::mutex critical_mutex, &lists_mutex, &cfg_mutex;
config *cfg;
};
struct conn_count
@@ -104,6 +104,10 @@ public:
{
return lists_mutex;
}
+ boost::mutex &get_cfg_mutex()
+ {
+ return cfg_mutex;
+ }
config *get_config()
{
return cfg;
@@ -115,7 +119,7 @@ private:
std::list<conn_count> conns;
std::list<std::string> blacklist;
boost::thread *flood_chek, *blacklist_clean;
- boost::mutex &lists_mutex;
+ boost::mutex &lists_mutex, &cfg_mutex;
config *cfg;
};