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

Allow stopping/pausing torrents #155

Open
ecdsa521 opened this issue May 13, 2017 · 19 comments
Open

Allow stopping/pausing torrents #155

ecdsa521 opened this issue May 13, 2017 · 19 comments

Comments

@ecdsa521
Copy link

ecdsa521 commented May 13, 2017

When writing my poor and dirty client I encountered a serious problem: your library by default is not able to stop/pause torrents, only remove them with Drop() method. I was able to overcome this by exporting close method and adding additional bit of code and calling it before DownloadAll(), and while it seems to work, I am certain this could be done better, and some torrents sometimes do not want to start again - are stuck at 0 peers/seeds.

So, let it be feature request: Please let us stop torrents in a sane, supported way.

Thanks for the great lib btw.

@anacrolix
Copy link
Owner

What would you want pause and stop to do? In particular, what impact should they have on network activity, downloading/uploading, fetching of info if it's not present, DHT activity, torrent Reader reading, scraping/tracking etc?

@ecdsa521
Copy link
Author

Should completely stop all network activity and close file descriptors if any. Basically everything Drop() does except for removing the torrent.

There is also a matter of exporting some more information and methods - when adding features I also encountered some other missing stuff (or stuff I failed to do otherwise?). I added all this but it's very bad, wonky code that doesn't always work properly and I still didn't find out why.

  • extra functions to re-announce, restart after Close() etc
  • exporting some inside data/stats such as wantPeers(), wantConns(), needData() etc
  • extra column for arbitrary status changes (.SetStatus("Downloading"), .SetStatus("Error") and then .Status )
  • exporting some other handy functions like AddTrackers()

For starters pause/stop function is the most important. I even noticed some of the torrent clients linked from your README also had this problem #

@anacrolix
Copy link
Owner

What's the difference between pause and stop? When would you use them? Do you have anything to add @axet and @arranlomas?

@ecdsa521
Copy link
Author

I was thinking of them being the same, just different wording, but now I have idea how they could be different: stop would stop all network activity, close files etc, pause could keep the peers/seeds data and keep pinging trackers/dht (but not upload/download anything). Restarting from pause would be faster then. But this is just something extra and nothing critical. Either is fine, but I think one of them is pretty critical functionality.

@axet
Copy link
Contributor

axet commented May 17, 2017

@anacrolix I think, here will be more and more people asking what is already done in https://gitlab.com/axet/libtorrent.

In my library I decide to remove and re add torrents, to keep runtime sane. Pause a torrent may need additionals notify calls or so...

@anacrolix maybe if you rework your original code and add more torrent state control, here will be more peace at the end :)

@anacrolix
Copy link
Owner

There definitely seems to be some desire for it, but I want to be sure what is gained, other than peace of mind for some users and some minor interface changes. @jpillora ?

@jpillora
Copy link
Contributor

Hey Matt, this feature would indeed be nice. I currently do the same as @axet, internally start and stop is implemented by adding and removing torrents. Having pause and/or stop built into anacrolix/torrent would be awesome 👍

@anacrolix
Copy link
Owner

Still chasing though, what is it that you need from pause/stop? Ceasing network activity? Killing all connections?

@jpillora
Copy link
Contributor

It's mostly about not having to track, remove, re-add torrents. However, for me, I think killing all connections of a torrent (stop) is more useful than ceasing network activity, which I assume to mean: don't send/receive to/from current connections (pause).

@arranlomas
Copy link

arranlomas commented May 20, 2017

I think an important part of this is to know how expensive it is to re-add torrents that are stopped, is keeping peers worth it if it's stopped (paused) for more than a couple of seconds?

With regards to tracking the state of a torrent isn't it the same whether it's stopped or paused? Would you want stop to do some kind of cleaning up? Or do you mean the client holds on to the torrent and you call pause and it doesn't drop the torrent?

Could an example be like a download from chrome. Pause stops the download and maintains peers. Stop would effectively cancel? Cleanup the torrent file and any related data?

However, as far as I'm aware and can tell other clients don't differentiate between pause and stop both effectively do the same a drop?

@ecdsa521
Copy link
Author

One problem with removing/readding torrent is, from what I saw, is that added torrent is not stopped but in a weird state where it doesn't download (before DownloadAll()) but it does seed the data it already has. So we can't stop torrent that way to move data elsewhere, for example.

Other clients do differentiate: utorrent and rtorrent stop torrent completely and notify tracker, but in paused state it retains idle connections with peers and still scrapes the tracker. It would be luxury to have both.

@anacrolix
Copy link
Owner

Could you describe that more? Do you mean after you Drop a Torrent, it continues to function in some way?

@anacrolix
Copy link
Owner

I might take some inspiration from recent criticisms of arbitrary labelling of things, like levelled logging, and add very specific methods like {Cease,Pause,Resume}Networking. That seems to be the main one this issue covers. If you also want forced reannounces, submit another issue for that and I'll add something like Torrent.AnnounceNow.

@ecdsa521
Copy link
Author

ecdsa521 commented May 29, 2017

Will it send announces when you ResumeNetworking? Also, does it send announces periodically? Can it be configured?

Thank you very much for looking into it. For now I'll be very happy with the networking options

When I drop the torrent it disappears, as it should. But when I add torrent that has some data downloaded, and not call DownloadAll it will still start - but only for seeding. It will not download but will still upload.

@anacrolix
Copy link
Owner

Well currently the Torrent currently announces periodically. The spec seems to suggest that the started event be sent when downloading begins, and stopped when it ceases, so I guess it's appropriate to send those when networking is paused/resumed.

@elgatito
Copy link
Contributor

I have been thinking of this issue after time passed.

I'd have these methods in Torrent: Start/Stop (or maybe name something like Halt), Unpause/Pause, Add/Drop (we do have the last ones).

So in this case:

  • Pause: Should stop download/upload of Data, but should continue to communicate with trackers and connect to peers.
  • Stop: Should stop all the network activities, but stay in the Client.

Why Pause is better - allows faster speed gain when unpaused.

Maybe we can make a simple if in the mail read/write loop to skip specific activities but leave the torrent working? Or some kind of a channel, waiting for Start/Unpause. Not sure about the place in the code to add that.

@anacrolix
Copy link
Owner

I'm intending to progress on this to fix #377. Specifically in that issue, downloading of data needs to cease until the disk situation is fixed, so I'll start there. I'm thinking of Torrent.{Disable,Pause}DownloadingData, Torrent.{Enable,Resume}DownloadingData, and Torrent.OnDownloadError or things to that effect. Clearly there may be more states in the future, and it may make sense to merge some of these common themes. I'm open to suggestions, cheers.

@axet
Copy link
Contributor

axet commented Feb 22, 2020

Most of my changes to 'torrent' is about start / stop feature. Is it not much code, you can see it on a top rebased commit. Just ignore changes on 't.go' most of them - additional peeks and methods:

Yet, some code lost because scrappers no longer has 'stop' method and nobody stopping dht servers. If you write your own code, I will rebase my changes. Also, to better understanding what is alive and what is dead I nil vars, it helps debug half open connection better.

@anacrolix
Copy link
Owner

See #377 (comment).

@anacrolix anacrolix removed this from the v1.15 milestone May 19, 2020
@anacrolix anacrolix removed their assignment May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants