summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-01-21 11:24:52 +0200
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-01-21 11:24:52 +0200
commit6f8e7cae703145cd6eb103c08681045ced28f5e5 (patch)
treecac209997cf72302677b714e51a9aac8b2052898
parent54005ef00542cef6317982cafe2d7b1aafe875aa (diff)
code cleanup
speedtest optimization
-rwxr-xr-xserver/server/config.cpp44
-rwxr-xr-xserver/server/config.h58
-rwxr-xr-xserver/server/headers.h7
-rwxr-xr-xserver/server/main.cpp6
-rwxr-xr-xserver/server/server.project10
-rw-r--r--server/server/speedtest.cpp73
-rw-r--r--server/server/speedtest.h3
7 files changed, 17 insertions, 184 deletions
diff --git a/server/server/config.cpp b/server/server/config.cpp
index cc972c6..d8a9cfa 100755
--- a/server/server/config.cpp
+++ b/server/server/config.cpp
@@ -64,7 +64,6 @@ void config::load_vars()
vars.bind_ip = get_string(cfg_str, "BindAddress=", "0.0.0.0");
vars.log_path = get_string(cfg_str, "LogPath=", "");
vars.dos_log_path = get_string(cfg_str, "DosLogPath=", "");
-// vars.proxifier_path = get_string(cfg_str, "ProxifierPath=", "c:/proxifier");
vars.ignore_ssl_errors = get_int(cfg_str, "IgnoreSslErrors=", 0);
vars.config_reload_interval = get_int(cfg_str, "ConfigReloadInterval=", 600);
vars.proxy_check_interval = get_int(cfg_str, "ProxyCheckInterval=", 6000);
@@ -473,45 +472,6 @@ void config::load_deleted_list(char* pth)
}
}
-/*std::list<config::p_proxy_entry> *config::make_p_proxy_list()
-{
- if(!p_proxy_list.empty())
- p_proxy_list.clear();
- if(!static_proxy_list.empty())
- {
- for(std::list<config::static_proxy_entry>::iterator i = static_proxy_list.begin(), end = static_proxy_list.end(); i != end; ++i)
- {
- p_proxy_entry e;
- e.enable_auth = (!i->login.empty())?true:false;
- e.host = i->host;
- e.id = !p_proxy_list.empty()?p_proxy_list.back().id+1:100;
- e.login = i->login;
- e.options = 0;
- e.password = i->password;
- e.port = i->port;
- e.type = i->type;
- p_proxy_list.push_back(e);
- }
- }
-
- if(!proxy_list.empty())
- {
- for(std::list<config::proxy_entry>::iterator i = proxy_list.begin(), end = proxy_list.end(); i != end; ++i)
- {
- p_proxy_entry e;
- e.enable_auth = (!i->login.empty())?true:false;
- e.host = i->host;
- e.id = !p_proxy_list.empty()?p_proxy_list.back().id+1:100;
- e.login = i->login;
- e.options = 0;
- e.password = i->password;
- e.port = i->port;
- e.type = i->type;
- p_proxy_list.push_back(e);
- }
- }
- return &p_proxy_list;
-}*/
const int config::ban_time()
{
@@ -549,10 +509,6 @@ const std::string& config::dos_log_path()
{
return vars.dos_log_path;
}
-/*const std::string& config::proxifier_path()
-{
- return vars.proxifier_path;
-}*/
std::list<config::proxy_entry> *config::get_proxy_list()
{
return &proxy_list;
diff --git a/server/server/config.h b/server/server/config.h
index 94d5df3..5f2ea40 100755
--- a/server/server/config.h
+++ b/server/server/config.h
@@ -9,15 +9,19 @@ class config
{
public:
enum proxy_type {UNKNOWN = -1, HTTP, HTTPS, SOCKS4, SOCKS5};
- struct proxy_entry
+ struct proxy_entry_base
{
- std::string host, login, password, country, state, city;
+ std::string host, login, password;
int port;
size_t speed;
std::list<size_t> speed_list;
proxy_type type;
- proxy_entry(): port(0), speed(0), type(UNKNOWN)
+ proxy_entry_base(): port(0), speed(0), type(UNKNOWN)
{}
+ };
+ struct proxy_entry : public proxy_entry_base
+ {
+ std::string country, state, city;
proxy_entry (std::string login_, std::string password_, std::string host_, int port_, std::string country_, std::string state_, std::string city_, proxy_type t)
{
login = login_;
@@ -30,51 +34,14 @@ public:
type = t;
}
};
-/* struct p_proxy_entry
- {
- std::string host, login, password;
- int port, id, options;
- bool enable_auth;
- proxy_type type;
- p_proxy_entry()
- {
- port = 3128;
- id = 100;
- options = 0;
- type = UNKNOWN;
- enable_auth = false;
- }
- };
-
- struct p_proxy_chain
- {
- std::string name;
- int id;
- struct chain_entry
- {
- int id;
- bool enabled;
- chain_entry()
- {
- id = 100;
- enabled = true;
- }
- };
- std::list<chain_entry> chain;
- p_proxy_chain()
- {
- id = 100;
- }
- };*/
- struct static_proxy_entry
+ struct static_proxy_entry : public proxy_entry_base
{
int port, position;
size_t speed;
std::list<size_t> speed_list;
- std::string host, login, password, label;
- proxy_type type;
- static_proxy_entry(): port(0), position(0), speed(0), type(UNKNOWN)
+ std::string label;
+ static_proxy_entry(): position(0)
{}
static_proxy_entry(std::string login_, std::string password_, std::string host_, int port_, std::string label_, int position_, proxy_type t)
{
@@ -180,13 +147,12 @@ public:
std::list<std::string> *get_deleted_list();
std::list<upload_entry> *get_upload_list();
std::list<conn_server> *get_server_list();
-// std::list<p_proxy_entry> *make_p_proxy_list();
private:
struct cfg_data
{
int ban_time, conn_count, check_interval, debug, dos_conn_count, conn_time, config_reload_interval, proxy_check_interval;
bool ignore_ssl_errors;
- std::string log_path, bind_ip, dos_log_path, /*proxifier_path, */speed_test_file_url;
+ std::string log_path, bind_ip, dos_log_path, speed_test_file_url;
cfg_data()
{
ignore_ssl_errors = false;
@@ -198,7 +164,6 @@ private:
debug = 0;
dos_conn_count = 200;
bind_ip = "0.0.0.0";
-// proxifier_path = "c:/proxifier";
speed_test_file_url = "http://localhost/speed.test";
}
};
@@ -224,7 +189,6 @@ private:
std::list<std::string> firewall_list, deleted_list;
std::list<upload_entry> upload_list;
std::list<conn_server> servers_list;
-// std::list<p_proxy_entry> p_proxy_list;
boost::thread *cfg_reload_thr, *speed_test_thr;
boost::mutex lists_mutex;
};
diff --git a/server/server/headers.h b/server/server/headers.h
index 54ac82c..a4d0114 100755
--- a/server/server/headers.h
+++ b/server/server/headers.h
@@ -22,21 +22,14 @@
#include <boost/nondet_random.hpp>
#include <boost/date_time.hpp>
-//#include <rapidxml.hpp>
-//#include <rapidxml_print.hpp>
-
#include <openssl/md5.h>
-//#include <Poco/Process.h>
-
#include <curl/curl.h>
#include "utilities.h"
#include "main.h"
#include "log.h"
#include "config.h"
-#include "p_process.h"
-#include "p_xml.h"
#include "speedtest.h"
#endif
diff --git a/server/server/main.cpp b/server/server/main.cpp
index c662e6b..ebeb898 100755
--- a/server/server/main.cpp
+++ b/server/server/main.cpp
@@ -1011,8 +1011,6 @@ server::server(boost::asio::io_service& io_service, unsigned short port) : io_se
*logger << time_str()<<": Openning server cert file: " << tmp_path << " " << err.message()<<"\n";
logger->unlock();
tmp_path.replace(tmp_path.length() - 3, 3, "key");
-// tmp_path = b_path;
-// tmp_path.append("/server.key");
context_.use_private_key_file(tmp_path, boost::asio::ssl::context::pem, err);
logger->lock();
*logger << time_str()<<": Openning server key file: " << tmp_path << " " << err.message()<<"\n";
@@ -1072,8 +1070,6 @@ void server::flood_check_thread(std::list<conn_count> *list, std::list<std::stri
boost::this_thread::sleep(boost::posix_time::seconds(cfg->check_interval()));
if(boost::this_thread::interruption_requested())
return;
-// if(boost::this_thread::interruption_requested())
-// break;
if(!list->empty())
{
std::list<conn_count>::iterator end = list->end();
@@ -1129,8 +1125,6 @@ void server::blacklist_clean_thread(std::list<std::string> *list)
boost::this_thread::sleep(boost::posix_time::minutes(cfg->ban_time()));
if(boost::this_thread::interruption_requested())
return;
-// if(boost::this_thread::interruption_requested())
-// break;
if(cfg->debug())
{
logger->lock();
diff --git a/server/server/server.project b/server/server/server.project
index 6b8c5f7..8ccd40e 100755
--- a/server/server/server.project
+++ b/server/server/server.project
@@ -17,10 +17,6 @@
<File Name="main.h"/>
<File Name="utilities.cpp"/>
<File Name="utilities.h"/>
- <File Name="p_process.cpp"/>
- <File Name="p_process.h"/>
- <File Name="p_xml.cpp"/>
- <File Name="p_xml.h"/>
<File Name="speedtest.cpp"/>
<File Name="speedtest.h"/>
</VirtualDirectory>
@@ -54,7 +50,8 @@
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
- <![CDATA[]]>
+ <![CDATA[
+ ]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="">
<PostConnectCommands/>
@@ -101,7 +98,8 @@
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
- <![CDATA[]]>
+ <![CDATA[
+ ]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="">
<PostConnectCommands/>
diff --git a/server/server/speedtest.cpp b/server/server/speedtest.cpp
index ff7d882..21fe21c 100644
--- a/server/server/speedtest.cpp
+++ b/server/server/speedtest.cpp
@@ -17,7 +17,7 @@ size_t speedtest::curl_data_callback(void *contents, size_t size, size_t nmemb,
}
-size_t speedtest::test(config::proxy_entry *p)
+size_t speedtest::test(config::proxy_entry_base *p)
{
curl = curl_easy_init();
if(!curl)
@@ -89,74 +89,3 @@ size_t speedtest::test(config::proxy_entry *p)
return speed;
}
-size_t speedtest::test(config::static_proxy_entry *p)
-{
- curl = curl_easy_init();
- if(!curl)
- return 0;
- memory_struct chunk;
- chunk.memory = (char*)malloc(1);
- chunk.size = 0;
- curl_easy_setopt(curl, CURLOPT_URL, test_url.c_str());
- curl_easy_setopt(curl, CURLOPT_PROXY, p->host.c_str());
- curl_easy_setopt(curl, CURLOPT_PROXYPORT, p->port);
- if(!p->password.empty() && !p->login.empty())
- curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, std::string(p->login + ":" + p->password).c_str());
- curl_proxytype type = CURLPROXY_HTTP;
- switch(p->type)
- {
- break;
- case config::HTTPS:
- type = CURLPROXY_HTTP; //is it correct ?
- curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L); //required for ssl
- curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY); //maybe required for https proxy ?
- break;
- case config::SOCKS4:
- type = CURLPROXY_SOCKS4;
- break;
- case config::SOCKS5:
- type = CURLPROXY_SOCKS5;
- break;
- }
- curl_easy_setopt(curl, CURLOPT_PROXYTYPE, type);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &speedtest::curl_data_callback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&chunk);
- curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-speedtest/0.1");
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
-
- time_t start = time(0);
-
- CURLcode error = curl_easy_perform(curl);
-
- double t = time(0) - start;
-
- curl_easy_cleanup(curl);
-
- free(chunk.memory);
- size_t speed = 0;
- if(!error)
- {
- if(chunk.size)
- {
- if(t)
- speed = (double)chunk.size/t;
- else
- speed = chunk.size;
- }
- p->speed_list.push_back(speed);
- }
- while(p->speed_list.size() > 10)
- p->speed_list.pop_front();
- if(!p->speed_list.empty())
- {
- if(speed)
- {
- size_t speed_sum = 0;
- for(std::list<size_t>::iterator i = p->speed_list.begin(), end = p->speed_list.end(); i != end; ++i)
- speed_sum += *i;
- speed = speed_sum/p->speed_list.size();
- }
- p->speed = speed;
- }
- return speed;
-}
diff --git a/server/server/speedtest.h b/server/server/speedtest.h
index 85579bc..95e9b89 100644
--- a/server/server/speedtest.h
+++ b/server/server/speedtest.h
@@ -6,8 +6,7 @@
class speedtest
{
public:
- size_t test(config::proxy_entry*);
- size_t test(config::static_proxy_entry*);
+ size_t test(config::proxy_entry_base*);
speedtest() : curl(NULL){}
speedtest(const std::string& url) : curl(NULL)
{