added proxy test to test_web_seed
This commit is contained in:
parent
e1d46c6821
commit
e03ffb1d6b
|
@ -31,8 +31,16 @@ void test_sleep(int millisec)
|
|||
boost::thread::sleep(xt);
|
||||
}
|
||||
|
||||
void stop_web_server(int port)
|
||||
{
|
||||
std::stringstream cmd;
|
||||
cmd << "kill `cat ./lighty" << port << ".pid` >/dev/null";
|
||||
system(cmd.str().c_str());
|
||||
}
|
||||
|
||||
void start_web_server(int port)
|
||||
{
|
||||
stop_web_server(port);
|
||||
std::ofstream f("./lighty_config");
|
||||
f << "server.modules = (\"mod_access\")\n"
|
||||
"server.document-root = \"" << boost::filesystem::initial_path().string() << "\"\n"
|
||||
|
@ -45,10 +53,39 @@ void start_web_server(int port)
|
|||
test_sleep(1000);
|
||||
}
|
||||
|
||||
void stop_web_server(int port)
|
||||
void stop_proxy(int port)
|
||||
{
|
||||
std::stringstream cmd;
|
||||
cmd << "kill `cat ./lighty" << port << ".pid`";
|
||||
cmd << "delegated -P" << port << " -Fkill";
|
||||
system(cmd.str().c_str());
|
||||
}
|
||||
|
||||
void start_proxy(int port, int proxy_type)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
stop_proxy(port);
|
||||
std::stringstream cmd;
|
||||
// we need to echo n since dg will ask us to configure it
|
||||
cmd << "echo n | delegated -P" << port << " ADMIN=test@test.com";
|
||||
switch (proxy_type)
|
||||
{
|
||||
case proxy_settings::socks4:
|
||||
cmd << " SERVER=socks4";
|
||||
break;
|
||||
case proxy_settings::socks5:
|
||||
cmd << " SERVER=socks5";
|
||||
break;
|
||||
case proxy_settings::socks5_pw:
|
||||
cmd << " SERVER=socks5 AUTHORIZER=-list{testuser:testpass}";
|
||||
break;
|
||||
case proxy_settings::http:
|
||||
cmd << " SERVER=http";
|
||||
break;
|
||||
case proxy_settings::http_pw:
|
||||
cmd << " SERVER=http AUTHORIZER=-list{testuser:testpass}";
|
||||
break;
|
||||
}
|
||||
system(cmd.str().c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ setup_transfer(libtorrent::session* ses1, libtorrent::session* ses2
|
|||
|
||||
void start_web_server(int port);
|
||||
void stop_web_server(int port);
|
||||
void start_proxy(int port, int type);
|
||||
void stop_proxy(int port);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -33,10 +33,62 @@ void add_files(
|
|||
}
|
||||
}
|
||||
|
||||
void test_transfer()
|
||||
// proxy: 0=none, 1=socks4, 2=socks5, 3=socks5_pw 4=http 5=http_pw
|
||||
void test_transfer(torrent_info torrent_file, int proxy)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
session ses;
|
||||
ses.set_severity_level(alert::debug);
|
||||
ses.listen_on(std::make_pair(49000, 50000));
|
||||
remove_all("./tmp1");
|
||||
|
||||
char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};
|
||||
|
||||
std::cerr << " ==== TESTING " << test_name[proxy] << " proxy ====" << std::endl;
|
||||
|
||||
if (proxy)
|
||||
{
|
||||
start_proxy(8002, proxy);
|
||||
proxy_settings ps;
|
||||
ps.hostname = "127.0.0.1";
|
||||
ps.port = 8002;
|
||||
ps.username = "testuser";
|
||||
ps.password = "testpass";
|
||||
ps.type = (proxy_settings::proxy_type)proxy;
|
||||
ses.set_web_seed_proxy(ps);
|
||||
}
|
||||
|
||||
torrent_handle th = ses.add_torrent(torrent_file, "./tmp1");
|
||||
|
||||
std::vector<announce_entry> empty;
|
||||
th.replace_trackers(empty);
|
||||
|
||||
for (int i = 0; i < 30; ++i)
|
||||
{
|
||||
torrent_status s = th.status();
|
||||
std::cerr << s.progress << " " << (s.download_rate / 1000.f) << std::endl;
|
||||
std::auto_ptr<alert> a;
|
||||
a = ses.pop_alert();
|
||||
if (a.get())
|
||||
std::cerr << a->msg() << "\n";
|
||||
|
||||
if (th.is_seed()) break;
|
||||
test_sleep(1000);
|
||||
}
|
||||
|
||||
TEST_CHECK(th.is_seed());
|
||||
|
||||
if (proxy) stop_proxy(8002);
|
||||
|
||||
remove_all("./tmp1");
|
||||
}
|
||||
|
||||
int test_main()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
boost::intrusive_ptr<torrent_info> torrent_file(new torrent_info);
|
||||
torrent_file->add_url_seed("http://127.0.0.1:8000/");
|
||||
|
||||
|
@ -72,44 +124,14 @@ void test_transfer()
|
|||
// to calculate the info_hash
|
||||
entry te = torrent_file->create_torrent();
|
||||
|
||||
session ses;
|
||||
ses.set_severity_level(alert::debug);
|
||||
ses.listen_on(std::make_pair(49000, 50000));
|
||||
remove_all("./tmp1");
|
||||
torrent_handle th = ses.add_torrent(torrent_file, "./tmp1");
|
||||
|
||||
std::vector<announce_entry> empty;
|
||||
th.replace_trackers(empty);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
test_transfer(*torrent_file, i);
|
||||
|
||||
for (int i = 0; i < 30; ++i)
|
||||
{
|
||||
torrent_status s = th.status();
|
||||
std::cerr << s.progress << " " << (s.download_rate / 1000.f) << std::endl;
|
||||
std::auto_ptr<alert> a;
|
||||
a = ses.pop_alert();
|
||||
if (a.get())
|
||||
std::cerr << a->msg() << "\n";
|
||||
|
||||
if (th.is_seed()) break;
|
||||
test_sleep(1000);
|
||||
}
|
||||
|
||||
TEST_CHECK(th.is_seed());
|
||||
|
||||
remove_all("./test_torrent");
|
||||
|
||||
stop_web_server(8000);
|
||||
}
|
||||
|
||||
int test_main()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
test_transfer();
|
||||
|
||||
remove_all("./tmp1");
|
||||
remove_all("./tmp2");
|
||||
|
||||
remove_all("./test_torrent");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue