merged RC_1_1 into master
This commit is contained in:
commit
381defab05
|
@ -54,6 +54,8 @@
|
|||
* resume data no longer has timestamps of files
|
||||
* require C++11 to build libtorrent
|
||||
|
||||
* add function to get default settings
|
||||
* updating super seeding would include the torrent in state_update_alert
|
||||
* fix issue where num_seeds could be greater than num_peers in torrent_status
|
||||
* finished non-seed torrents can also be in super-seeding mode
|
||||
* fix issue related to unloading torrents
|
||||
|
|
|
@ -67,7 +67,7 @@ struct time_point_to_python
|
|||
time_t const tm = system_clock::to_time_t(system_clock::now()
|
||||
+ duration_cast<system_clock::duration>(pt - lt::clock_type::now()));
|
||||
|
||||
std::tm* date = std::gmtime(&tm);
|
||||
std::tm* date = std::localtime(&tm);
|
||||
object result = datetime_datetime(
|
||||
(int)1900 + date->tm_year
|
||||
// tm use 0-11 and we need 1-12
|
||||
|
|
|
@ -202,6 +202,11 @@ namespace
|
|||
return make_dict(ret);
|
||||
}
|
||||
|
||||
dict default_settings_wrapper()
|
||||
{
|
||||
return make_dict(default_settings());
|
||||
}
|
||||
|
||||
dict high_performance_seed_wrapper()
|
||||
{
|
||||
settings_pack ret = high_performance_seed();
|
||||
|
@ -935,6 +940,7 @@ void bind_session()
|
|||
|
||||
def("high_performance_seed", high_performance_seed_wrapper);
|
||||
def("min_memory_usage", min_memory_usage_wrapper);
|
||||
def("default_settings", default_settings_wrapper);
|
||||
def("read_resume_data", read_resume_data_wrapper);
|
||||
|
||||
class_<stats_metric>("stats_metric")
|
||||
|
|
|
@ -447,6 +447,11 @@ class test_example_client(unittest.TestCase):
|
|||
+ "some configuration does not output errors like missing module members,"
|
||||
+ "try to call it manually to get the error message\n")
|
||||
|
||||
def test_default_settings(self):
|
||||
|
||||
default = lt.default_settings()
|
||||
print(default)
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(lt.__version__)
|
||||
shutil.copy(os.path.join('..', '..', 'test', 'test_torrents',
|
||||
|
|
|
@ -63,9 +63,6 @@ namespace libtorrent { namespace aux {
|
|||
return this->base::operator[](std::size_t(static_cast<underlying_index>(idx)));
|
||||
}
|
||||
|
||||
#if !TORRENT_USE_ASSERTS
|
||||
constexpr
|
||||
#endif
|
||||
IndexType end_index() const
|
||||
{
|
||||
TORRENT_ASSERT(this->size() <= std::size_t(std::numeric_limits<underlying_index>::max()));
|
||||
|
|
|
@ -68,6 +68,9 @@ namespace libtorrent
|
|||
TORRENT_EXPORT int setting_by_name(std::string const& name);
|
||||
TORRENT_EXPORT char const* name_for_setting(int s);
|
||||
|
||||
// returns a settings_pack with every setting set to its default value
|
||||
TORRENT_EXPORT settings_pack default_settings();
|
||||
|
||||
// The ``settings_pack`` struct, contains the names of all settings as
|
||||
// enum values. These values are passed in to the ``set_str()``,
|
||||
// ``set_int()``, ``set_bool()`` functions, to specify the setting to
|
||||
|
|
|
@ -467,6 +467,107 @@ TORRENT_TEST(torrent_completed_alert)
|
|||
TEST_EQUAL(num_file_completed, 1);
|
||||
}
|
||||
|
||||
// template for testing running swarms with edge case settings
|
||||
template <typename SettingsFun>
|
||||
void test_settings(SettingsFun fun)
|
||||
{
|
||||
setup_swarm(2, swarm_test::download
|
||||
// add session
|
||||
, fun
|
||||
// add torrent
|
||||
, [](lt::add_torrent_params& params) {}
|
||||
// on alert
|
||||
, [](lt::alert const* a, lt::session& ses) {}
|
||||
// terminate
|
||||
, [](int ticks, lt::session& ses) -> bool
|
||||
{
|
||||
if (ticks > 80)
|
||||
{
|
||||
TEST_ERROR("timeout");
|
||||
return true;
|
||||
}
|
||||
if (!is_seed(ses)) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
TORRENT_TEST(unlimited_connections)
|
||||
{
|
||||
test_settings([](lt::settings_pack& pack) {
|
||||
pack.set_int(settings_pack::connections_limit, std::numeric_limits<int>::max()); }
|
||||
);
|
||||
}
|
||||
|
||||
TORRENT_TEST(default_connections_limit)
|
||||
{
|
||||
test_settings([](lt::settings_pack& pack) {
|
||||
pack.set_int(settings_pack::connections_limit, 0); }
|
||||
);
|
||||
}
|
||||
|
||||
TORRENT_TEST(redundant_have)
|
||||
{
|
||||
test_settings([](lt::settings_pack& pack) {
|
||||
pack.set_bool(settings_pack::send_redundant_have, false); }
|
||||
);
|
||||
}
|
||||
|
||||
TORRENT_TEST(lazy_bitfields)
|
||||
{
|
||||
test_settings([](lt::settings_pack& pack) {
|
||||
pack.set_bool(settings_pack::lazy_bitfields, true); }
|
||||
);
|
||||
}
|
||||
|
||||
TORRENT_TEST(prioritize_partial_pieces)
|
||||
{
|
||||
test_settings([](lt::settings_pack& pack) {
|
||||
pack.set_bool(settings_pack::prioritize_partial_pieces, true); }
|
||||
);
|
||||
}
|
||||
|
||||
TORRENT_TEST(active_downloads)
|
||||
{
|
||||
test_settings([](lt::settings_pack& pack) {
|
||||
pack.set_int(settings_pack::active_downloads, std::numeric_limits<int>::max()); }
|
||||
);
|
||||
}
|
||||
|
||||
TORRENT_TEST(active_seeds)
|
||||
{
|
||||
test_settings([](lt::settings_pack& pack) {
|
||||
pack.set_int(settings_pack::active_seeds, std::numeric_limits<int>::max()); }
|
||||
);
|
||||
}
|
||||
|
||||
TORRENT_TEST(active_limit)
|
||||
{
|
||||
test_settings([](lt::settings_pack& pack) {
|
||||
pack.set_int(settings_pack::active_limit, std::numeric_limits<int>::max()); }
|
||||
);
|
||||
}
|
||||
|
||||
TORRENT_TEST(upload_rate_limit)
|
||||
{
|
||||
test_settings([](lt::settings_pack& pack) {
|
||||
pack.set_int(settings_pack::upload_rate_limit, std::numeric_limits<int>::max()); }
|
||||
);
|
||||
}
|
||||
|
||||
TORRENT_TEST(download_rate_limit)
|
||||
{
|
||||
test_settings([](lt::settings_pack& pack) {
|
||||
pack.set_int(settings_pack::download_rate_limit, std::numeric_limits<int>::max()); }
|
||||
);
|
||||
}
|
||||
|
||||
TORRENT_TEST(unchoke_slots_limit)
|
||||
{
|
||||
test_settings([](lt::settings_pack& pack) {
|
||||
pack.set_int(settings_pack::unchoke_slots_limit, std::numeric_limits<int>::max()); }
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: add test that makes sure a torrent in graceful pause mode won't make
|
||||
// outgoing connections
|
||||
// TODO: add test that makes sure a torrent in graceful pause mode won't accept
|
||||
|
|
|
@ -60,9 +60,18 @@ namespace libtorrent
|
|||
void bandwidth_channel::update_quota(int dt_milliseconds)
|
||||
{
|
||||
if (m_limit == 0) return;
|
||||
m_quota_left += (m_limit * dt_milliseconds + 500) / 1000;
|
||||
if (m_quota_left > m_limit * 3) m_quota_left = m_limit * 3;
|
||||
distribute_quota = int((std::max)(m_quota_left, std::int64_t(0)));
|
||||
|
||||
// avoid integer overflow
|
||||
if (m_limit >= std::numeric_limits<int>::max() / dt_milliseconds)
|
||||
{
|
||||
m_quota_left = std::numeric_limits<int>::max();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_quota_left += (m_limit * dt_milliseconds + 500) / 1000;
|
||||
if (m_quota_left / 3 > m_limit) m_quota_left = m_limit * 3;
|
||||
}
|
||||
distribute_quota = int(std::max(m_quota_left, std::int64_t(0)));
|
||||
}
|
||||
|
||||
// this is used when connections disconnect with
|
||||
|
|
|
@ -2967,6 +2967,7 @@ namespace aux {
|
|||
peer_class* pc = m_classes.at(c);
|
||||
if (pc == nullptr) return;
|
||||
if (limit <= 0) limit = 0;
|
||||
else limit = std::min(limit, std::numeric_limits<int>::max() - 1);
|
||||
pc->channel[channel].throttle(limit);
|
||||
}
|
||||
|
||||
|
@ -4023,8 +4024,9 @@ namespace aux {
|
|||
// TODO: use a lower limit than m_settings.connections_limit
|
||||
// to allocate the to 10% or so of connection slots for incoming
|
||||
// connections
|
||||
int limit = m_settings.get_int(settings_pack::connections_limit)
|
||||
- num_connections();
|
||||
// cap this at max - 1, since we may add one below
|
||||
int const limit = std::min(m_settings.get_int(settings_pack::connections_limit)
|
||||
- num_connections(), std::numeric_limits<int>::max() - 1);
|
||||
|
||||
// this logic is here to smooth out the number of new connection
|
||||
// attempts over time, to prevent connecting a large number of
|
||||
|
|
|
@ -55,6 +55,11 @@ namespace {
|
|||
if (i != c.end() && i->first == v.first) i->second = std::move(v.second);
|
||||
else c.emplace(i, std::move(v));
|
||||
}
|
||||
|
||||
// return the string, unless it's null, in which case the empty string is
|
||||
// returned
|
||||
char const* ensure_string(char const* str)
|
||||
{ return str == nullptr ? "" : str; }
|
||||
}
|
||||
|
||||
namespace libtorrent
|
||||
|
@ -415,8 +420,7 @@ namespace libtorrent
|
|||
// loop over all settings that differ from default
|
||||
for (int i = 0; i < settings_pack::num_string_settings; ++i)
|
||||
{
|
||||
char const* cmp = str_settings[i].default_value == nullptr ? "" : str_settings[i].default_value;
|
||||
if (cmp == s.m_strings[std::size_t(i)]) continue;
|
||||
if (ensure_string(str_settings[i].default_value) == s.m_strings[std::size_t(i)]) continue;
|
||||
sett[str_settings[i].name] = s.m_strings[std::size_t(i)];
|
||||
}
|
||||
|
||||
|
@ -455,6 +459,28 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
settings_pack default_settings()
|
||||
{
|
||||
settings_pack ret;
|
||||
// TODO: it would be nice to reserve() these vectors up front
|
||||
for (int i = 0; i < settings_pack::num_string_settings; ++i)
|
||||
{
|
||||
if (str_settings[i].default_value == nullptr) continue;
|
||||
ret.set_str(settings_pack::string_type_base + i, str_settings[i].default_value);
|
||||
}
|
||||
|
||||
for (int i = 0; i < settings_pack::num_int_settings; ++i)
|
||||
{
|
||||
ret.set_int(settings_pack::int_type_base + i, int_settings[i].default_value);
|
||||
}
|
||||
|
||||
for (int i = 0; i < settings_pack::num_bool_settings; ++i)
|
||||
{
|
||||
ret.set_bool(settings_pack::bool_type_base + i, bool_settings[i].default_value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void apply_pack(settings_pack const* pack, aux::session_settings& sett
|
||||
, aux::session_impl* ses)
|
||||
{
|
||||
|
|
|
@ -4361,6 +4361,7 @@ namespace libtorrent
|
|||
|
||||
m_super_seeding = on;
|
||||
set_need_save_resume();
|
||||
state_updated();
|
||||
|
||||
if (m_super_seeding) return;
|
||||
|
||||
|
@ -7467,6 +7468,7 @@ namespace libtorrent
|
|||
{
|
||||
m_super_seeding = false;
|
||||
set_need_save_resume();
|
||||
state_updated();
|
||||
}
|
||||
|
||||
if (is_finished() && m_state != torrent_status::finished)
|
||||
|
|
|
@ -86,7 +86,7 @@ struct peer_connection: bandwidth_socket, std::enable_shared_from_this<peer_conn
|
|||
int m_priority;
|
||||
bool m_ignore_limits;
|
||||
std::string m_name;
|
||||
int m_quota;
|
||||
boost::int64_t m_quota;
|
||||
};
|
||||
|
||||
void peer_connection::assign_bandwidth(int channel, int amount)
|
||||
|
@ -157,7 +157,6 @@ void run_test(connections_t& v
|
|||
, std::bind(&peer_connection::start, _1));
|
||||
|
||||
libtorrent::aux::session_settings s;
|
||||
initialize_default_settings(s);
|
||||
int tick_interval = s.get_int(settings_pack::tick_interval);
|
||||
|
||||
for (int i = 0; i < int(sample_time * 1000 / tick_interval); ++i)
|
||||
|
@ -458,36 +457,36 @@ void test_no_starvation(int limit)
|
|||
|
||||
TORRENT_TEST(equal_connection)
|
||||
{
|
||||
test_equal_connections(2, 20);
|
||||
test_equal_connections(2, 2000);
|
||||
test_equal_connections(2, 20000);
|
||||
test_equal_connections(3, 20000);
|
||||
test_equal_connections(5, 20000);
|
||||
test_equal_connections(7, 20000);
|
||||
test_equal_connections(33, 60000);
|
||||
test_equal_connections(33, 500000);
|
||||
test_equal_connections(1, 100000000);
|
||||
test_equal_connections( 2, 20);
|
||||
test_equal_connections( 2, 2000);
|
||||
test_equal_connections( 2, 20000);
|
||||
test_equal_connections( 3, 20000);
|
||||
test_equal_connections( 5, 20000);
|
||||
test_equal_connections( 7, 20000);
|
||||
test_equal_connections(33, 60000);
|
||||
test_equal_connections(33, 500000);
|
||||
test_equal_connections( 1, 1000000);
|
||||
}
|
||||
|
||||
TORRENT_TEST(conn_var_rate)
|
||||
{
|
||||
test_connections_variable_rate(2, 20, 0);
|
||||
test_connections_variable_rate(5, 20000, 0);
|
||||
test_connections_variable_rate(3, 2000, 6000);
|
||||
test_connections_variable_rate(5, 2000, 30000);
|
||||
test_connections_variable_rate( 2, 20, 0);
|
||||
test_connections_variable_rate( 5, 20000, 0);
|
||||
test_connections_variable_rate( 3, 2000, 6000);
|
||||
test_connections_variable_rate( 5, 2000, 30000);
|
||||
test_connections_variable_rate(33, 500000, 0);
|
||||
}
|
||||
|
||||
TORRENT_TEST(torrents)
|
||||
{
|
||||
test_torrents(2, 400, 400, 0);
|
||||
test_torrents(2, 100, 500, 0);
|
||||
test_torrents(2, 3000, 3000, 6000);
|
||||
test_torrents(1, 40000, 40000, 0);
|
||||
test_torrents(24, 50000, 50000, 0);
|
||||
test_torrents(5, 6000, 6000, 3000);
|
||||
test_torrents(5, 6000, 5000, 4000);
|
||||
test_torrents(5, 20000, 20000, 30000);
|
||||
test_torrents( 2, 400, 400, 0);
|
||||
test_torrents( 2, 100, 500, 0);
|
||||
test_torrents( 2, 3000, 3000, 6000);
|
||||
test_torrents( 1, 40000, 40000, 0);
|
||||
test_torrents(24, 50000, 50000, 0);
|
||||
test_torrents( 5, 6000, 6000, 3000);
|
||||
test_torrents( 5, 6000, 5000, 4000);
|
||||
test_torrents( 5, 20000, 20000, 30000);
|
||||
}
|
||||
|
||||
TORRENT_TEST(torrent_var_rate)
|
||||
|
|
|
@ -44,7 +44,6 @@ using namespace libtorrent::aux;
|
|||
TORRENT_TEST(default_settings)
|
||||
{
|
||||
aux::session_settings sett;
|
||||
initialize_default_settings(sett);
|
||||
|
||||
entry e;
|
||||
save_settings_to_dict(sett, e.dict());
|
||||
|
@ -58,10 +57,34 @@ TORRENT_TEST(default_settings)
|
|||
#endif
|
||||
}
|
||||
|
||||
TORRENT_TEST(default_settings2)
|
||||
{
|
||||
aux::session_settings sett;
|
||||
|
||||
settings_pack def = default_settings();
|
||||
|
||||
for (int i = 0; i < settings_pack::num_string_settings; ++i)
|
||||
{
|
||||
TEST_EQUAL(sett.get_str(settings_pack::string_type_base + i)
|
||||
, def.get_str(settings_pack::string_type_base + i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < settings_pack::num_int_settings; ++i)
|
||||
{
|
||||
TEST_EQUAL(sett.get_int(settings_pack::int_type_base + i)
|
||||
, def.get_int(settings_pack::int_type_base + i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < settings_pack::num_bool_settings; ++i)
|
||||
{
|
||||
TEST_EQUAL(sett.get_bool(settings_pack::bool_type_base + i)
|
||||
, def.get_bool(settings_pack::bool_type_base + i));
|
||||
}
|
||||
}
|
||||
|
||||
TORRENT_TEST(apply_pack)
|
||||
{
|
||||
aux::session_settings sett;
|
||||
initialize_default_settings(sett);
|
||||
settings_pack sp;
|
||||
sp.set_int(settings_pack::max_out_request_queue, 1337);
|
||||
|
||||
|
|
Loading…
Reference in New Issue