Skip to content
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

Customize files fragments checking, when torrent is added #1553

Closed
BarushevEA opened this issue Nov 23, 2018 · 13 comments
Closed

Customize files fragments checking, when torrent is added #1553

BarushevEA opened this issue Nov 23, 2018 · 13 comments
Labels

Comments

@BarushevEA
Copy link

@BarushevEA BarushevEA commented Nov 23, 2018

Please help me solve a problem.

What version of WebTorrent? - 0.102.4
What operating system and Node.js version? - OS Win 10 64, Node.js - v10.11.0

What actually happened?
Situation by step:

  1. Add torrent "test" with many files
  2. Some files are 100% downloaded, some files are still downloading
  3. Stop and close the application
  4. Start application
  5. Add torrent "test" again
  6. Before torrent is ready, webtorrent checks fragments and this process takes a lot of time

What did you expect to happen?
How i can stop files check, if they are 100% downloaded?

@SilentBot1

This comment has been minimized.

Copy link
Member

@SilentBot1 SilentBot1 commented Nov 23, 2018

@BarushevEA

This comment has been minimized.

Copy link
Author

@BarushevEA BarushevEA commented Nov 23, 2018

Thanks, I will try to use it.

@SilentBot1 SilentBot1 added the question label Nov 23, 2018
@BarushevEA

This comment has been minimized.

Copy link
Author

@BarushevEA BarushevEA commented Nov 23, 2018

This works for the whole torrent.
But i need to disable scanning selectively, separately for each file.

@BarushevEA

This comment has been minimized.

Copy link
Author

@BarushevEA BarushevEA commented Nov 23, 2018

May be need to create new options/function similar to this:

  _markAllVerified () {
    for (let index = 0; index < this.pieces.length; index++) {
      this._markVerified(index)
    }
  }

But with options for example:

  _markAllSelected (start, stop) {
    // validation start
    // validation stop
    for (let index = start; index < stop; index++) {
      this._markVerified(index)
    }
  }
@SilentBot1

This comment has been minimized.

Copy link
Member

@SilentBot1 SilentBot1 commented Nov 23, 2018

Hey BarushevEA,

As it stands, like you've said, there is currently no way to do it selectively for each file, only per torrent.

Creating a selectiveVerify torrent option and additional if statement inside this else statement seems like the best way to implement something like this.

@BarushevEA

This comment has been minimized.

Copy link
Author

@BarushevEA BarushevEA commented Nov 23, 2018

Ok.
Thank you very much for your answers!
Are you planning to introduce the ability to selectively disable the scan?

@SilentBot1

This comment has been minimized.

Copy link
Member

@SilentBot1 SilentBot1 commented Nov 23, 2018

Something possibly like this, which uses parse-numeric-range to select the files to be marked as verified, similar to how I handled select only (BEP53) above.

if(this.selectiveVerify){
  const selectiveVerifyFiles = parseRange(this.selectiveVerify)
  this.files.forEach((v, i)=>{
    if(selectiveVerifyFiles.includes(i)){
      for(let index = v._startPiece; index <= v._endPiece; index++){
        this._markVerified(index)
      }
    }
  })
}
@BarushevEA

This comment has been minimized.

Copy link
Author

@BarushevEA BarushevEA commented Nov 23, 2018

Yes, it is very similar to what I need.

@SilentBot1

This comment has been minimized.

Copy link
Member

@SilentBot1 SilentBot1 commented Nov 23, 2018

@BarushevEA It could be implemented and I see no reason as to why it wouldn't be as it's quite useful in combination with select only.

I don't have the time at the moment to implement it properly myself, mainly writing the tests for it, but the code above should be functional.

Yourself or anybody else is more than welcome to create the PR to add this feature, sorry I'm not able to do it myself at the moment.

@BarushevEA

This comment has been minimized.

Copy link
Author

@BarushevEA BarushevEA commented Nov 23, 2018

I understand.
I starting this at next week.
I can implement this for my project and try to help you too.
If you do not mind.

@BarushevEA

This comment has been minimized.

Copy link
Author

@BarushevEA BarushevEA commented Nov 27, 2018

I am try to use new functionality, but found error flow.
Files really do not verify, but after this torrent never ready.

I am write code:
to class Torrent

constructor add
this.skipVerifyFiles = !this.skipVerify ? opts.skipVerifyFiles : null;

rewvrite _markAllVerified()

    _markAllVerified() {
        this._markVerifiedGroup(0, this.pieces.length - 1);
    }

    _markVerifiedGroup(start, end) {
        for (let i = start; i <= end; i++) {
            this._markVerified(i);
        }
    }

add function

    /**
     *  Pieces of file mark as verified
     *  verefiedFiles contained object with filenames.
     *  For example - {filename: "filename", filename1: "filename1"}
     */
    _markFileVerified(verefiedFiles) {
        this.files.forEach(file => {
            if (verefiedFiles[file.name]) {
                this._markVerifiedGroup(file._startPiece, file._endPiece);
            }
        });
    }

add to _onMetadata(metadata)

        if (this.skipVerifyFiles) {
            this._markFileVerified(this.skipVerifyFiles);
        }

Use options
{path: downloadPath, skipVerifyFiles: verifiedFiles}

@BarushevEA

This comment has been minimized.

Copy link
Author

@BarushevEA BarushevEA commented Nov 29, 2018

I guess I found a mistake.

Function - _verifyPieces()
File - torrent.js, strings 576 - 578:

                        if (!this.pieces[index]) return
                        this._debug('piece verified %s', index)
                        this._markVerified(index)

Fix:

                        if (this.pieces[index]) {
                            this._debug('piece verified %s', index);
                            this._markVerified(index);
                        }
@stale

This comment has been minimized.

Copy link

@stale stale bot commented Feb 27, 2019

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

@stale stale bot added the stale label Feb 27, 2019
@stale stale bot closed this Mar 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.