merged RC_1_1 into master

This commit is contained in:
arvidn 2017-01-28 14:36:23 -05:00
commit 6b91adab6a
12 changed files with 130 additions and 61 deletions

View File

@ -53,6 +53,10 @@
* resume data no longer has timestamps of files
* require C++11 to build libtorrent
* fix issue related to unloading torrents
* fixed finished-time calculation
* add missing min_memory_usage() and high_performance_seed() settings presets to python
* fix stat cache issue that sometimes would produce incorrect resume data
* storage optimization to peer classes
* fix torrent name in alerts of builds with deprecated functions
* make torrent_info::is_valid() return false if torrent failed to load

View File

@ -148,6 +148,29 @@ namespace
}
}
dict make_dict(lt::settings_pack const& sett)
{
dict ret;
for (int i = settings_pack::string_type_base;
i < settings_pack::max_string_setting_internal; ++i)
{
ret[name_for_setting(i)] = sett.get_str(i);
}
for (int i = settings_pack::int_type_base;
i < settings_pack::max_int_setting_internal; ++i)
{
ret[name_for_setting(i)] = sett.get_int(i);
}
for (int i = settings_pack::bool_type_base;
i < settings_pack::max_bool_setting_internal; ++i)
{
ret[name_for_setting(i)] = sett.get_bool(i);
}
return ret;
}
std::shared_ptr<lt::session> make_session(boost::python::dict sett, int flags)
{
settings_pack p;
@ -170,25 +193,21 @@ namespace
allow_threading_guard guard;
sett = ses.get_settings();
}
dict ret;
for (int i = settings_pack::string_type_base;
i < settings_pack::max_string_setting_internal; ++i)
{
ret[name_for_setting(i)] = sett.get_str(i);
}
return make_dict(sett);
}
for (int i = settings_pack::int_type_base;
i < settings_pack::max_int_setting_internal; ++i)
{
ret[name_for_setting(i)] = sett.get_int(i);
}
dict min_memory_usage_wrapper()
{
settings_pack ret;
min_memory_usage(ret);
return make_dict(ret);
}
for (int i = settings_pack::bool_type_base;
i < settings_pack::max_bool_setting_internal; ++i)
{
ret[name_for_setting(i)] = sett.get_bool(i);
}
return ret;
dict high_performance_seed_wrapper()
{
settings_pack ret;
high_performance_seed(ret);
return make_dict(ret);
}
#ifndef BOOST_NO_EXCEPTIONS
@ -916,11 +935,8 @@ void bind_session()
;
#endif
typedef void (*mem_preset2)(settings_pack& s);
typedef void (*perf_preset2)(settings_pack& s);
def("high_performance_seed", (perf_preset2)high_performance_seed);
def("min_memory_usage", (mem_preset2)min_memory_usage);
def("high_performance_seed", high_performance_seed_wrapper);
def("min_memory_usage", min_memory_usage_wrapper);
def("read_resume_data", read_resume_data_wrapper);
class_<stats_metric>("stats_metric")

View File

@ -309,14 +309,6 @@ class test_sha1hash(unittest.TestCase):
class test_session(unittest.TestCase):
def test_post_session_stats(self):
s = lt.session({'alert_mask': lt.alert.category_t.stats_notification, 'enable_dht': False})
s.post_session_stats()
a = s.wait_for_alert(1000)
self.assertTrue(isinstance(a, lt.session_stats_alert))
self.assertTrue(isinstance(a.values, dict))
self.assertTrue(len(a.values) > 0)
def test_add_torrent(self):
s = lt.session({'alert_mask': lt.alert.category_t.stats_notification, 'enable_dht': False})
h = s.add_torrent({'ti': lt.torrent_info('base.torrent'),
@ -327,13 +319,6 @@ class test_session(unittest.TestCase):
'banned_peers': [('8.7.6.5', 6881)],
'file_priorities': [1,1,1,2,0]})
def test_unknown_settings(self):
try:
s = lt.session({'unexpected-key-name': 42})
self.assertFalse('should have thrown an exception')
except KeyError as e:
print(e)
def test_apply_settings(self):
s = lt.session({'enable_dht': False})
@ -341,7 +326,6 @@ class test_session(unittest.TestCase):
self.assertEqual(s.get_settings()['num_want'], 66)
self.assertEqual(s.get_settings()['user_agent'], 'test123')
def test_post_session_stats(self):
s = lt.session({'alert_mask': lt.alert.category_t.stats_notification,
'enable_dht': False})
@ -351,35 +335,33 @@ class test_session(unittest.TestCase):
self.assertTrue(isinstance(a.values, dict))
self.assertTrue(len(a.values) > 0)
def test_add_torrent(self):
s = lt.session({'alert_mask': lt.alert.category_t.stats_notification,
'enable_dht': False})
s.add_torrent({
'ti': lt.torrent_info('base.torrent'),
'save_path': '.',
'dht_nodes': [('1.2.3.4', 6881), ('4.3.2.1', 6881)],
'http_seeds': ['http://test.com/seed'],
'peers': [('5.6.7.8', 6881)],
'banned_peers': [('8.7.6.5', 6881)],
'file_priorities': [1, 1, 1, 2, 0]})
def test_unknown_settings(self):
try:
lt.session({'unexpected-key-name': 42})
s = lt.session({'unexpected-key-name': 42})
self.assertFalse('should have thrown an exception')
except KeyError as e:
print(e)
def test_apply_settings(self):
s = lt.session({'enable_dht': False})
s.apply_settings({'num_want': 66, 'user_agent': 'test123'})
self.assertEqual(s.get_settings()['num_want'], 66)
self.assertEqual(s.get_settings()['user_agent'], 'test123')
def test_fingerprint(self):
self.assertEqual(lt.generate_fingerprint('LT', 0, 1, 2, 3), '-LT0123-')
self.assertEqual(lt.generate_fingerprint('..', 10, 1, 2, 3), '-..A123-')
def test_min_memory_preset(self):
min_mem = lt.min_memory_usage()
print(min_mem)
self.assertTrue('connection_speed' in min_mem)
self.assertTrue('file_pool_size' in min_mem)
def test_seed_mode_preset(self):
seed_mode = lt.high_performance_seed()
print(seed_mode)
self.assertTrue('alert_queue_size' in seed_mode)
self.assertTrue('connection_speed' in seed_mode)
self.assertTrue('file_pool_size' in seed_mode)
class test_example_client(unittest.TestCase):
def test_execute_client(self):

View File

@ -295,6 +295,9 @@ namespace libtorrent
// On windows this path (and other paths) are interpreted as UNC
// paths. This means they must use backslashes as directory separators
// and may not contain the special directories "." or "..".
//
// Setting this to an absolute path is slightly more performant than a
// relative path.
std::string save_path;
// One of the values from storage_mode_t. For more information, see

View File

@ -42,9 +42,13 @@ POSSIBILITY OF SUCH DAMAGE.
// OVERVIEW
//
// You have some control over session configuration through the session::apply_settings()
// member function. To change one or more configuration options, create a settings_pack.
// member function. To change one or more configuration options, create a settings_pack
// object and fill it with the settings to be set and pass it in to session::apply_settings().
//
// The settings_pack object is a collection of settings updates that are applied
// to the session when passed to session::apply_settings(). It's empty when
// constructed.
//
// You have control over proxy and authorization settings and also the user-agent
// that will be sent to the tracker. The user-agent will also be used to identify the
// client with other peers.

View File

@ -77,6 +77,9 @@ namespace libtorrent
void throw_invalid_handle() TORRENT_NO_RETURN;
#endif
using std::shared_ptr;
using std::make_shared;
// holds the state of a block in a piece. Who we requested
// it from and how far along we are at downloading it.
struct TORRENT_EXPORT block_info
@ -887,7 +890,7 @@ namespace libtorrent
// without metadata only if it was started without a .torrent file, e.g.
// by using the libtorrent extension of just supplying a tracker and
// info-hash.
std::shared_ptr<const torrent_info> torrent_file() const;
shared_ptr<const torrent_info> torrent_file() const;
#ifndef TORRENT_NO_DEPRECATE

View File

@ -5017,7 +5017,7 @@ namespace libtorrent
// only add new piece-chunks if the send buffer is small enough
// otherwise there will be no end to how large it will be!
int buffer_size_watermark = int(m_uploaded_last_second
int buffer_size_watermark = int(boost::int64_t(m_uploaded_last_second)
* m_settings.get_int(settings_pack::send_buffer_watermark_factor) / 100);
if (buffer_size_watermark < m_settings.get_int(settings_pack::send_buffer_low_watermark))

View File

@ -346,6 +346,7 @@ namespace libtorrent
TORRENT_ASSERT_PRECOND(!params.save_path.empty());
add_torrent_params* p = new add_torrent_params(params);
p->save_path = complete(p->save_path);
#ifndef TORRENT_NO_DEPRECATE
handle_backwards_compatible_resume_data(*p);

View File

@ -4639,6 +4639,8 @@ namespace aux {
, *params, ec);
return;
}
TORRENT_ASSERT(params->ti->is_valid());
TORRENT_ASSERT(params->ti->num_files() > 0);
add_torrent(*params, ec);
params->url.clear();
}

View File

@ -559,6 +559,10 @@ namespace libtorrent
// make sure we don't have the files open
m_pool.release(storage_index());
// make sure we can pick up new files added to the download directory when
// we start the torrent again
m_stat_cache.clear();
}
void default_storage::delete_files(int const options, storage_error& ec)
@ -601,6 +605,10 @@ namespace libtorrent
status_t ret;
std::tie(ret, m_save_path) = aux::move_storage(files(), m_save_path, sp
, m_part_file.get(), flags, ec);
// clear the stat cache in case the new location has new files
m_stat_cache.clear();
return ret;
}

View File

@ -8252,7 +8252,7 @@ namespace libtorrent
}
m_became_seed = clamped_subtract_u16(m_became_seed, seconds);
if (m_finished_time < seconds && is_finished())
if (m_became_finished < seconds && is_finished())
{
int const lost_seconds = seconds - m_became_finished;
m_finished_time += lost_seconds;

View File

@ -198,6 +198,52 @@ TORRENT_TEST(paused_session)
TEST_CHECK(!h.status().paused);
}
TORRENT_TEST(get_cache_info)
{
lt::session s(settings());
lt::cache_status ret;
s.get_cache_info(&ret);
TEST_CHECK(ret.pieces.empty());
#ifndef TORRENT_NO_DEPRECATE
TEST_EQUAL(ret.blocks_written, 0);
TEST_EQUAL(ret.writes, 0);
TEST_EQUAL(ret.blocks_read, 0);
TEST_EQUAL(ret.blocks_read_hit, 0);
TEST_EQUAL(ret.reads, 0);
TEST_EQUAL(ret.queued_bytes, 0);
TEST_EQUAL(ret.cache_size, 0);
TEST_EQUAL(ret.write_cache_size, 0);
TEST_EQUAL(ret.read_cache_size, 0);
TEST_EQUAL(ret.pinned_blocks, 0);
TEST_EQUAL(ret.total_used_buffers, 0);
TEST_EQUAL(ret.average_read_time, 0);
TEST_EQUAL(ret.average_write_time, 0);
TEST_EQUAL(ret.average_hash_time, 0);
TEST_EQUAL(ret.average_job_time, 0);
TEST_EQUAL(ret.cumulative_job_time, 0);
TEST_EQUAL(ret.cumulative_read_time, 0);
TEST_EQUAL(ret.cumulative_write_time, 0);
TEST_EQUAL(ret.cumulative_hash_time, 0);
TEST_EQUAL(ret.total_read_back, 0);
TEST_EQUAL(ret.read_queue_size, 0);
TEST_EQUAL(ret.blocked_jobs, 0);
TEST_EQUAL(ret.queued_jobs, 0);
TEST_EQUAL(ret.peak_queued, 0);
TEST_EQUAL(ret.pending_jobs, 0);
TEST_EQUAL(ret.num_jobs, 0);
TEST_EQUAL(ret.num_read_jobs, 0);
TEST_EQUAL(ret.num_write_jobs, 0);
TEST_EQUAL(ret.arc_mru_size, 0);
TEST_EQUAL(ret.arc_mru_ghost_size, 0);
TEST_EQUAL(ret.arc_mfu_size, 0);
TEST_EQUAL(ret.arc_mfu_ghost_size, 0);
TEST_EQUAL(ret.arc_write_size, 0);
TEST_EQUAL(ret.arc_volatile_size, 0);
TEST_EQUAL(ret.num_writing_threads, 0);
#endif
}
template <typename Set, typename Save, typename Default, typename Load>
void test_save_restore(Set setup, Save s, Default d, Load l)
{