mpetazzoni / ttorrent

BitTorrent Java library with tracker and download client
http://mpetazzoni.github.com/ttorrent/
Apache License 2.0
1.38k stars 502 forks source link

Client.run() masks exception using finally { return } #78

Open shevek opened 10 years ago

shevek commented 10 years ago

Client.run() calls SharedTorrent.init()

If SharedTorrent.init() throws an exception, then the finally {} block enters the !isInitialized() condition.

However, since this block returns, any exception thrown is swallowed silently.

This causes download() to return silently, with ClientState == ERROR, but no indication as to why.

The return needs to be outside the finally{} to permit the normal exception handling to proceed.

shevek commented 10 years ago

Most likely all the close/cleanup routines should just be in one huge finally block at the end of run(), and nobody should ever call 'return'. The setState(ERROR) should be in the catch() blocks, which means that Client.run() EITHER sets state to error OR (in the case of an unforseen exception, such as I got) throws an exception.

shevek commented 10 years ago

https://github.com/shevek/ttorrent/commit/f59c33a45f23498f5155ab995e619a9f79412a0c

Please excuse lack of PRs, they won't come out clean as all my commits are stacked now.

shabin-slr commented 10 years ago

Dear sir, I've used your package, ttorrent in my final year project, which is an algorithm to ensure fairness in BitTorrent networks , called Fair Torrent. I need to get the download and upload speeds of the client. But getDLRate and getULRate methods return the Rates of the peers connected to the clients only and not of the client itself. Is there any method to get the download and upload rates of the client?

mpetazzoni commented 10 years ago

You can do so by summing the rates of each connected peer, which is what the info() method does, for example.

shabin-slr commented 10 years ago

thanks :)