Move main torrent running code to torrent library.

(This should make it somewhat easier to call from tests.)