libtorrent icon indicating copy to clipboard operation
libtorrent copied to clipboard

[Feature request] Quick file check

Open master255 opened this issue 3 years ago • 5 comments

@arvidn It is necessary to add a new flag and algorithm to torrent_session to check files more quickly. Now the checking is done by calculating file hashes. The new flag will mean checking with three parameters:

  1. File path
  2. File size
  3. Date of file modification (if any)

If these three parameters match, consider the file verified.

master255 avatar Mar 31 '23 21:03 master255

Sounds like a bad idea.

  1. Date of (last) file modification can simply set by every Script/Program and it is only a local Information that has no value for a valid File Check here.
  2. File Size isn't an safe Information. I can produce the same File with the same size but all filled with 0 Zero Bytes.

The current Hash checks the hashes of every single Block in the File not the file itself as far as i know. This hashes are contained in the .torrent file.

Infos: https://en.wikipedia.org/wiki/Torrent_file#File_structure

Milbret avatar Jun 14 '23 11:06 Milbret

@Milbret You are talking to a professional who made his own torrent library, DHT library, torrent streaming via https protocol, fast torrent files update. Obviously your level is too low to understand what is written here :)

master255 avatar Jun 14 '23 11:06 master255

What kind of professional? Seams like you missed a lot of stuff here to understand how torrent hashing work.

If you have your own torrent library why should libtorrent add something that technical doesn't make any sense? This "Feature" wouldn't ensure that the torrent is valid in any way. If a single bit of one block is invalid, then the whole file is. With this Feature you would ignore invalid blocks as long as the path, file size and "maybe" the Date of last modification is identical. With that a malicious client or a user with broken files could send garbage and you would accept it as valid. Doesn't sound professional at all ;-) And i don't see who wants to use it but clearly you could provide a use case for this.

Milbret avatar Jun 14 '23 12:06 Milbret

This is an optional file check. Additional to the basic functionality. Libtorrent has a mechanism for detecting corrupted files during distribution. So there will be no problem with cheating other clients. Already all torrent clients have the ability to add an already downloaded torrent without checking the data at all, and this option will do a quick check. This will save users a lot of time.

master255 avatar Jun 14 '23 12:06 master255

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 17 '23 01:09 stale[bot]

@arvidn Still looking for a solution. It's an important problem.

master255 avatar Jul 28 '24 23:07 master255

@arvidn In the process of creating the program I realized - removing and adding torrentHandle in some process to change some property is IMPOSSIBLE! If you want your library to work (and torrents work), you need methods that will do it without removing torrentHandle. This is critically important!

master255 avatar Jul 29 '24 23:07 master255

Solved the problem: In the program in alertloop:

final StateChangedAlert stateChangedAlert = ((StateChangedAlert) Alerts.cast(a));
                                    if (downloadedTorrentHandle.getInfoHash().equals(stateChangedAlert.handle().infoHash().toHex()) && stateChangedAlert.getState().swig() == 1) {
                                        final torrent_status torrentStatus = downloadedTorrentHandle.swig().status();
                                        final String savePath = torrentStatus.getSave_path();
                                        final piece_index_bitfield pieceIndexBitfield = new piece_index_bitfield(torrentStatus.torrent_file_ptr().num_pieces());
                                        final file_storage fileStorage = torrentStatus.torrent_file_ptr().orig_files();
                                        final int fileStorageSize = fileStorage.num_files();
                                        final int pieceLength = fileStorage.piece_length();
                                        for (int u = 0; u < fileStorageSize; u++) {
                                            final String filePath = fileStorage.file_path(u);
                                            if (filePath.contains(Constants.TORRENTS_PAD_TAG))
                                                continue;
                                            final File file = new File(savePath + "/" + filePath);
                                            if (file.exists()) {
                                                final long fileSize = fileStorage.file_size(u);
                                                if (file.length() == fileSize) {
                                                    final long offset = fileStorage.file_offset(u);
                                                    final int startPiece = (int) (offset / pieceLength);
                                                    final int endPiece = (int) ((offset + fileSize) / pieceLength);
                                                    for (int y = startPiece; y <= endPiece; y++)
                                                        pieceIndexBitfield.set_bit(y);
                                                }
                                            }
                                        }
                                        downloadedTorrentHandle.swig().set_have_pieces(pieceIndexBitfield);
                                        downloadedTorrentHandle.swig().resume();
                                    }

in libtorrent in torrent.cpp:

    void torrent::set_have_pieces(typed_bitfield<piece_index_t> const& bits) {
        need_picker();
        for (piece_index_t i = piece_index_t(0); i < piece_index_t(bits.size()); ++i)
        {
            if (!bits[i]) continue;
            m_picker->we_have(i);
            inc_stats_counter(counters::num_piece_passed);
            update_gauge();
            we_have(i);
        }
        files_checked();
    }

Score Arvidn -10 Master +10

master255 avatar Jul 30 '24 21:07 master255