diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index cc0dc50b1..fb02fead0 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -121,7 +121,7 @@ namespace int sett = setting_by_name(key); if (sett < 0) { - PyErr_SetString(PyExc_ValueError, ("unknown name in settings_pack: " + key).c_str()); + PyErr_SetString(PyExc_KeyError, ("unknown name in settings_pack: " + key).c_str()); throw_error_already_set(); } diff --git a/bindings/python/test.py b/bindings/python/test.py index 43da34298..788e38dd8 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -195,7 +195,7 @@ class test_session(unittest.TestCase): try: s = lt.session({'unexpected-key-name': 42}) self.assertFalse('should have thrown an exception') - except Exception as e: + except KeyError as e: print(e) def test_apply_settings(self): diff --git a/include/libtorrent/block_cache.hpp b/include/libtorrent/block_cache.hpp index 7c81a8159..1a5e5a658 100644 --- a/include/libtorrent/block_cache.hpp +++ b/include/libtorrent/block_cache.hpp @@ -462,10 +462,6 @@ namespace libtorrent int pinned_blocks() const { return m_pinned_blocks; } int read_cache_size() const { return m_read_cache_size; } -#if TORRENT_USE_ASSERTS - void mark_deleted(file_storage const& fs); -#endif - private: // returns number of bytes read on success, -1 on cache miss @@ -530,10 +526,6 @@ namespace libtorrent // the number of blocks with a refcount > 0, i.e. // they may not be evicted int m_pinned_blocks; - -#if TORRENT_USE_ASSERTS - std::vector> m_deleted_storages; -#endif }; } diff --git a/simulation/setup_swarm.cpp b/simulation/setup_swarm.cpp index 85640da3a..3c6123ab9 100644 --- a/simulation/setup_swarm.cpp +++ b/simulation/setup_swarm.cpp @@ -123,6 +123,7 @@ lt::torrent_status get_status(lt::session& ses) { auto handles = ses.get_torrents(); TEST_EQUAL(handles.size(), 1); + if (handles.empty()) return lt::torrent_status(); auto h = handles[0]; return h.status(); } @@ -131,6 +132,7 @@ bool has_metadata(lt::session& ses) { auto handles = ses.get_torrents(); TEST_EQUAL(handles.size(), 1); + if (handles.empty()) return false; auto h = handles[0]; return h.status().has_metadata; } @@ -139,6 +141,7 @@ bool is_seed(lt::session& ses) { auto handles = ses.get_torrents(); TEST_EQUAL(handles.size(), 1); + if (handles.empty()) return false; auto h = handles[0]; return h.status().is_seeding; } @@ -147,6 +150,7 @@ int completed_pieces(lt::session& ses) { auto handles = ses.get_torrents(); TEST_EQUAL(handles.size(), 1); + if (handles.empty()) return 0; auto h = handles[0]; return h.status().num_pieces; } diff --git a/simulation/test_metadata_extension.cpp b/simulation/test_metadata_extension.cpp index d2d5f0dd1..6f7af1582 100644 --- a/simulation/test_metadata_extension.cpp +++ b/simulation/test_metadata_extension.cpp @@ -63,7 +63,10 @@ enum flags_t utp = 8, // upload-only mode - upload_only = 16 + upload_only = 16, + + // re-add the torrent after removing + readd = 32 }; void run_metadata_test(int flags) @@ -108,10 +111,21 @@ void run_metadata_test(int flags) { metadata_alerts += 1; + auto ti = std::make_shared( + *ses.get_torrents()[0].torrent_file()); + if (flags & disconnect) { ses.remove_torrent(ses.get_torrents()[0]); } + + if (flags & readd) + { + add_torrent_params p = default_add_torrent; + p.ti = ti; + p.save_path = "."; + ses.add_torrent(p); + } } } // terminate @@ -127,6 +141,10 @@ void run_metadata_test(int flags) TEST_ERROR("timeout"); return true; } + if ((flags & disconnect) && metadata_alerts > 0) + { + return true; + } if ((flags & upload_only) && has_metadata(ses)) { // the other peer is in upload mode and should not have sent any @@ -167,3 +185,18 @@ TORRENT_TEST(ut_metadata_upload_only) run_metadata_test(upload_only); } +TORRENT_TEST(ut_metadata_disconnect) +{ + run_metadata_test(disconnect); +} + +TORRENT_TEST(ut_metadata_disconnect_readd) +{ + run_metadata_test(disconnect | readd); +} + +TORRENT_TEST(ut_metadata_upload_only_disconnect_readd) +{ + run_metadata_test(upload_only | disconnect | readd); +} + diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 5634fa42c..74011e2ed 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -357,15 +357,6 @@ int block_cache::try_read(disk_io_job* j, bool expect_no_fail) TORRENT_ASSERT(j->buffer.disk_block == nullptr); -#if TORRENT_USE_ASSERTS - // we're not allowed to add dirty blocks - // for a deleted storage! - TORRENT_ASSERT(std::find(m_deleted_storages.begin(), m_deleted_storages.end() - , std::make_pair(j->storage->files()->name() - , reinterpret_cast(j->storage->files()))) - == m_deleted_storages.end()); -#endif - cached_piece_entry* p = find_piece(j); int ret = 0; @@ -714,16 +705,6 @@ cached_piece_entry* block_cache::allocate_piece(disk_io_job const* j, int const return p; } -#if TORRENT_USE_ASSERTS -void block_cache::mark_deleted(file_storage const& fs) -{ - m_deleted_storages.push_back(std::make_pair(fs.name() - , reinterpret_cast(&fs))); - if (m_deleted_storages.size() > 100) - m_deleted_storages.erase(m_deleted_storages.begin()); -} -#endif - cached_piece_entry* block_cache::add_dirty_block(disk_io_job* j) { #if !defined TORRENT_DISABLE_POOL_ALLOCATOR @@ -733,15 +714,6 @@ cached_piece_entry* block_cache::add_dirty_block(disk_io_job* j) INVARIANT_CHECK; #endif -#if TORRENT_USE_ASSERTS - // we're not allowed to add dirty blocks - // for a deleted storage! - TORRENT_ASSERT(std::find(m_deleted_storages.begin(), m_deleted_storages.end() - , std::make_pair(j->storage->files()->name() - , static_cast(j->storage->files()))) - == m_deleted_storages.end()); -#endif - TORRENT_ASSERT(j->buffer.disk_block); TORRENT_ASSERT(m_write_cache_size + m_read_cache_size + 1 <= in_use()); @@ -1297,14 +1269,6 @@ void block_cache::insert_blocks(cached_piece_entry* pe, int block, spanin_use); TORRENT_PIECE_ASSERT(iov.size() > 0, pe); -#if TORRENT_USE_ASSERTS - // we're not allowed to add dirty blocks - // for a deleted storage! - TORRENT_ASSERT(std::find(m_deleted_storages.begin(), m_deleted_storages.end() - , std::make_pair(j->storage->files()->name(), static_cast(j->storage->files()))) - == m_deleted_storages.end()); -#endif - cache_hit(pe, j->requester, (j->flags & disk_io_job::volatile_read) != 0); TORRENT_ASSERT(pe->in_use); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 36017d562..b08f8779c 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -2445,9 +2445,6 @@ namespace libtorrent TORRENT_ASSERT(j->storage->num_outstanding_jobs() == 1); std::unique_lock l(m_cache_mutex); -#if TORRENT_USE_ASSERTS - m_disk_cache.mark_deleted(*j->storage->files()); -#endif flush_cache(j->storage.get(), flush_delete_cache | flush_expect_clear , completed_jobs, l);