-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix to_req() to not request pad-space for v2-only torrents #8231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| 2.0.13 | ||
|
|
||
| * optimize v2 request sizes | ||
| * fix socks5 issues | ||
| * fix issue in loading v2 resume data merkle trees | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -505,6 +505,16 @@ TORRENT_VERSION_NAMESPACE_3 | |
| // except for the last piece, which may be shorter. | ||
| int piece_size(piece_index_t index) const { return m_files.piece_size(index); } | ||
|
|
||
| // returns the piece size appropriate for computing request lengths. | ||
| // for v2 torrents, pieces at the end of files may be shorter than | ||
| // the main piece size. This is the case for hybrid torrents as well. | ||
| int piece_size_for_req(piece_index_t index) const | ||
| { | ||
| return v2() | ||
| ? m_files.piece_size2(index) | ||
| : m_files.piece_size(index); | ||
| } | ||
|
Comment on lines
+508
to
+516
|
||
|
|
||
| // ``hash_for_piece()`` takes a piece-index and returns the 20-bytes | ||
| // sha1-hash for that piece and ``info_hash()`` returns the 20-bytes | ||
| // sha1-hash for the info-section of the torrent file. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -807,7 +807,7 @@ aux::vector<download_priority_t, piece_index_t> file_to_piece_prio( | |
| return; | ||
| } | ||
|
|
||
| const int piece_size = m_torrent_file->piece_size(piece); | ||
| const int piece_size = m_torrent_file->piece_size_for_req(piece); | ||
|
arvidn marked this conversation as resolved.
|
||
| const int blocks_in_piece = (piece_size + block_size() - 1) / block_size(); | ||
|
|
||
| TORRENT_ASSERT(blocks_in_piece > 0); | ||
|
|
@@ -1254,7 +1254,7 @@ aux::vector<download_priority_t, piece_index_t> file_to_piece_prio( | |
|
|
||
| if (rp->blocks_left == 0) | ||
| { | ||
| int size = m_torrent_file->piece_size(r.piece); | ||
| int size = m_torrent_file->piece_size_for_req(r.piece); | ||
| if (rp->fail) | ||
| { | ||
| m_ses.alerts().emplace_alert<read_piece_alert>( | ||
|
|
@@ -1376,10 +1376,13 @@ aux::vector<download_priority_t, piece_index_t> file_to_piece_prio( | |
| return; | ||
|
|
||
| // make sure the piece size is correct | ||
| if (data.size() != std::size_t(m_torrent_file->piece_size(piece))) | ||
| return; | ||
|
|
||
| add_piece(piece, data.data(), flags); | ||
| // we check against the v1 piece size as well, for backwards compatibility | ||
| if (data.size() == std::size_t(m_torrent_file->piece_size_for_req(piece)) | ||
| || data.size() == std::size_t(m_torrent_file->piece_size(piece))) | ||
| { | ||
| data.resize(std::size_t(m_torrent_file->piece_size_for_req(piece))); | ||
| add_piece(piece, data.data(), flags); | ||
| } | ||
| } | ||
|
|
||
| // TODO: 3 there's some duplication between this function and | ||
|
|
@@ -1393,7 +1396,7 @@ aux::vector<download_priority_t, piece_index_t> file_to_piece_prio( | |
| if (piece >= torrent_file().end_piece()) | ||
| return; | ||
|
|
||
| int const piece_size = m_torrent_file->piece_size(piece); | ||
| int const piece_size = m_torrent_file->piece_size_for_req(piece); | ||
| int const blocks_in_piece = (piece_size + block_size() - 1) / block_size(); | ||
|
|
||
| if (m_deleted) return; | ||
|
|
@@ -1519,8 +1522,8 @@ aux::vector<download_priority_t, piece_index_t> file_to_piece_prio( | |
| peer_request torrent::to_req(piece_block const& p) const | ||
| { | ||
| int const block_offset = p.block_index * block_size(); | ||
| int const block = std::min(torrent_file().piece_size( | ||
| p.piece_index) - block_offset, block_size()); | ||
| int const piece_sz = torrent_file().piece_size_for_req(p.piece_index); | ||
| int const block = std::min(piece_sz - block_offset, block_size()); | ||
| TORRENT_ASSERT(block > 0); | ||
|
Comment on lines
1522
to
1527
|
||
| TORRENT_ASSERT(block <= block_size()); | ||
|
|
||
|
|
@@ -7391,7 +7394,7 @@ namespace { | |
| TORRENT_ASSERT(counter * blocks_per_piece + pi.blocks_in_piece <= int(blk.size())); | ||
| block_info* blocks = &blk[std::size_t(counter * blocks_per_piece)]; | ||
| pi.blocks = blocks; | ||
| int const piece_size = ti.piece_size(i->index); | ||
| int const piece_size = ti.piece_size_for_req(i->index); | ||
| int idx = -1; | ||
| for (auto const& info : p.blocks_for_piece(*i)) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.