transition the test_pe_crypto system tests to be simulation
This commit is contained in:
@@ -43,104 +43,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
||||
|
||||
char const* pe_policy(boost::uint8_t policy)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
if (policy == settings_pack::pe_disabled) return "disabled";
|
||||
else if (policy == settings_pack::pe_enabled) return "enabled";
|
||||
else if (policy == settings_pack::pe_forced) return "forced";
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
void display_settings(libtorrent::settings_pack const& s)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
fprintf(stderr, "out_enc_policy - %s\tin_enc_policy - %s\n"
|
||||
, pe_policy(s.get_int(settings_pack::out_enc_policy))
|
||||
, pe_policy(s.get_int(settings_pack::in_enc_policy)));
|
||||
|
||||
fprintf(stderr, "enc_level - %s\t\tprefer_rc4 - %s\n"
|
||||
, s.get_int(settings_pack::allowed_enc_level) == settings_pack::pe_plaintext ? "plaintext"
|
||||
: s.get_int(settings_pack::allowed_enc_level) == settings_pack::pe_rc4 ? "rc4"
|
||||
: s.get_int(settings_pack::allowed_enc_level) == settings_pack::pe_both ? "both" : "unknown"
|
||||
, s.get_bool(settings_pack::prefer_rc4) ? "true": "false");
|
||||
}
|
||||
|
||||
void test_transfer(libtorrent::settings_pack::enc_policy policy
|
||||
, int timeout
|
||||
, libtorrent::settings_pack::enc_level level = libtorrent::settings_pack::pe_both
|
||||
, bool pref_rc4 = false)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
namespace lt = libtorrent;
|
||||
|
||||
// these are declared before the session objects
|
||||
// so that they are destructed last. This enables
|
||||
// the sessions to destruct in parallel
|
||||
session_proxy p1;
|
||||
session_proxy p2;
|
||||
|
||||
settings_pack s;
|
||||
|
||||
s.set_int(settings_pack::out_enc_policy, settings_pack::pe_enabled);
|
||||
s.set_int(settings_pack::in_enc_policy, settings_pack::pe_enabled);
|
||||
s.set_int(settings_pack::allowed_enc_level, settings_pack::pe_both);
|
||||
|
||||
s.set_str(settings_pack::listen_interfaces, "0.0.0.0:48800");
|
||||
|
||||
lt::session ses2(s, 0);
|
||||
|
||||
fprintf(stderr, " Session2 \n");
|
||||
display_settings(s);
|
||||
|
||||
s.set_int(settings_pack::out_enc_policy, policy);
|
||||
s.set_int(settings_pack::in_enc_policy, policy);
|
||||
s.set_int(settings_pack::allowed_enc_level, level);
|
||||
s.set_bool(settings_pack::prefer_rc4, pref_rc4);
|
||||
|
||||
s.set_str(settings_pack::listen_interfaces, "0.0.0.0:49800");
|
||||
|
||||
lt::session ses1(s, 0);
|
||||
|
||||
fprintf(stderr, " Session1 \n");
|
||||
display_settings(s);
|
||||
|
||||
torrent_handle tor1;
|
||||
torrent_handle tor2;
|
||||
|
||||
using boost::tuples::ignore;
|
||||
boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0, true, false, true
|
||||
, "_pe", 16 * 1024, 0, false, 0, true);
|
||||
|
||||
fprintf(stderr, "waiting for transfer to complete\n");
|
||||
|
||||
for (int i = 0; i < timeout * 10; ++i)
|
||||
{
|
||||
torrent_status s = tor2.status();
|
||||
print_alerts(ses1, "ses1");
|
||||
print_alerts(ses2, "ses2");
|
||||
|
||||
if (s.is_seeding) break;
|
||||
test_sleep(100);
|
||||
}
|
||||
|
||||
TEST_CHECK(tor2.status().is_seeding);
|
||||
if (tor2.status().is_seeding) fprintf(stderr, "done\n");
|
||||
ses1.remove_torrent(tor1);
|
||||
ses2.remove_torrent(tor2);
|
||||
|
||||
// this allows shutting down the sessions in parallel
|
||||
p1 = ses1.abort();
|
||||
p2 = ses2.abort();
|
||||
|
||||
error_code ec;
|
||||
remove_all("tmp1_pe", ec);
|
||||
remove_all("tmp2_pe", ec);
|
||||
remove_all("tmp3_pe", ec);
|
||||
}
|
||||
|
||||
void test_enc_handler(libtorrent::crypto_plugin* a, libtorrent::crypto_plugin* b)
|
||||
{
|
||||
#ifdef TORRENT_USE_VALGRIND
|
||||
@@ -255,65 +157,6 @@ TORRENT_TEST(rc4)
|
||||
test_enc_handler(&rc41, &rc42);
|
||||
}
|
||||
|
||||
#ifdef TORRENT_USE_VALGRIND
|
||||
const int timeout = 10;
|
||||
#else
|
||||
const int timeout = 5;
|
||||
#endif
|
||||
|
||||
TORRENT_TEST(pe_disabled)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
test_transfer(settings_pack::pe_disabled, timeout);
|
||||
}
|
||||
|
||||
TORRENT_TEST(forced_plaintext)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
test_transfer(settings_pack::pe_forced, timeout, settings_pack::pe_plaintext);
|
||||
}
|
||||
|
||||
TORRENT_TEST(forced_rc4)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
test_transfer(settings_pack::pe_forced, timeout, settings_pack::pe_rc4);
|
||||
}
|
||||
|
||||
TORRENT_TEST(forced_both)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
test_transfer(settings_pack::pe_forced, timeout, settings_pack::pe_both, false);
|
||||
}
|
||||
|
||||
TORRENT_TEST(forced_both_prefer_rc4)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
test_transfer(settings_pack::pe_forced, timeout, settings_pack::pe_both, true);
|
||||
}
|
||||
|
||||
TORRENT_TEST(enabled_plaintext)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
test_transfer(settings_pack::pe_enabled, timeout, settings_pack::pe_plaintext);
|
||||
}
|
||||
|
||||
TORRENT_TEST(enabled_rc4)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
test_transfer(settings_pack::pe_enabled, timeout, settings_pack::pe_rc4);
|
||||
}
|
||||
|
||||
TORRENT_TEST(enabled_both)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
test_transfer(settings_pack::pe_enabled, timeout, settings_pack::pe_both, false);
|
||||
}
|
||||
|
||||
TORRENT_TEST(enabled_both_prefer_rc4)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
test_transfer(settings_pack::pe_enabled, timeout, settings_pack::pe_both, true);
|
||||
}
|
||||
#else
|
||||
TORRENT_TEST(disabled)
|
||||
{
|
||||
|
Reference in New Issue
Block a user