anacrolix / torrent

Full-featured BitTorrent client package and utilities
Mozilla Public License 2.0
5.39k stars 615 forks source link

Inferring reasons for stopped transfer? #862

Closed marcovidonis closed 5 months ago

marcovidonis commented 10 months ago

I'm looking for a way to understand and report why a downloading torrent stops before it's complete. I wonder whether there is some info available on what is being exchanged between leecher, seeder and tracker and how I could tap into that (and perhaps surface this info to outside the package) to infer what's happening. For example: Have all seeders disappeared? Has the leecher lost connection to the tracker? Etc.

I've gone through PeerConn, but I haven't been able to find anything holding the state of the connection (perhaps I missed something). I did notice an expVar.Map variable called torrent that keeps a count of several events, but I'm not sure whether it could be useful for this purpose.

Do you have any suggestions on how I could go about this?

anacrolix commented 10 months ago

I usually have a HTTP handler writing the torrent status somewhere. It's textual but you can usually work out problems from that and the goroutine trace. Here's an example: https://github.com/anacrolix/confluence/blob/10e015cde1c83daa33fcbe78f70d9b6fc749700f/confluence/handlers.go#L64-L66. You'll be able to see what the piece state is of the connected peers, and the amount of redundancy for each piece. You'll probably find some pieces are missing from the swarm.

marcovidonis commented 10 months ago

Thanks! That might just be what I need, I'll look into that!

anacrolix commented 5 months ago

Question answered.