rakshasa / rtorrent

rTorrent BitTorrent client
https://github.com/rakshasa/rtorrent/wiki
GNU General Public License v2.0
4.05k stars 412 forks source link

Can't bootstrap DHT/documentation is wrong #1155

Open ihategithubsomuch opened 2 years ago

ihategithubsomuch commented 2 years ago

So for the life of me I cant figure out how to get DHT working in rtorrent. The documentation for this is so bad and makes so many assumptions regarding the users familiarity with the software, that it is damned near worthless. For example it says

https://github.com/rakshasa/rtorrent/wiki/Using-DHT "1. Adding torrents which have a list of DHT nodes in the .torrent file...

  1. Downloading a torrent with peers who advertise that they support DHT..."

Wow thats great, what torrent file though? I've tried adding a few from an Ubuntu image to some Simpsons torrents which all completed and the DHT database is still only 55 bytes. Is it so hard to just give a link to a torrent file which will do this, or would that be too much to ask?

Well what about "3. Manually entering a host name and port number of a DHT node". Oh yeah I tried adding "dht.add_node = dht.transmissionbt.com" as the documentation suggests and that doesnt work either, it just gives the error "rtorrent: Error in option file: ~/.rtorrent.rc:47: DHT not enabled." even though "dht.mode.set = auto" is set.

I've tried googleing around and saw people mention needing to "schedule2" the dht.add_node, but this doesnt seem to work either. My DHT database is still 55 bytes. The documentation also mentions checking logs, which have fuck all in them:

root@photon [ ~/log ]# cat rtorrent-1646014785.log 1646014785 N rtorrent main: Starting thread. 1646014785 N rtorrent scgi: Starting thread. 1646016231 N rtorrent scgi: Shutting down thread. 1646016252 N rtorrent main: Shutting down thread. 1646016252 N rtorrent disk: Shutting down thread.

So what exactly has to be done to get DHT to work? For reference here is my config

network.scgi.open_local = /root/rtorrent.socket
execute.nothrow = chmod,770,/root/rtorrent.socket
schedule2 = dht_node_1, 5, 0, "dht.add_node=router.utorrent.com:6881"
schedule2 = dht_node_2, 5, 0, "dht.add_node=dht.transmissionbt.com:6881"
schedule2 = dht_node_3, 5, 0, "dht.add_node=router.bitcomet.com:6881"
schedule2 = dht_node_4, 5, 0, "dht.add_node=dht.aelitis.com:6881"

method.insert = cfg.basedir,  private|const|string, (cat,"/root/")
method.insert = cfg.download, private|const|string, (cat,"/mnt/File Server/Downloads")
method.insert = cfg.logs,     private|const|string, (cat,(cfg.basedir),"log/")
method.insert = cfg.logfile,  private|const|string, (cat,(cfg.logs),"rtorrent-",(system.time),".log")
method.insert = cfg.session,  private|const|string, (cat,(cfg.basedir),".session/")

execute.throw = sh, -c, (cat,\
    "mkdir -p ",\
    "\"",(cfg.logs),"\" ",\
    "\"",(cfg.session),"\" ")

network.port_range.set = 50000-50000
network.port_random.set = no

dht.mode.set = auto
protocol.pex.set = yes
trackers.use_udp.set = yes

protocol.encryption.set = allow_incoming,try_outgoing,enable_retry

session.path.set = (cat, (cfg.session))
directory.default.set = (cat, (cfg.download))
log.execute = (cat, (cfg.logs), "execute.log")
execute.nothrow = sh, -c, (cat, "echo >",\
    (session.path), "rtorrent.pid", " ",(system.pid))

method.insert = system.startup_time, value|const, (system.time)
method.insert = d.data_path, simple,\
    "if=(d.is_multi_file),\
        (cat, (d.directory), /),\
        (cat, (d.directory), /, (d.name))"
method.insert = d.session_file, simple, "cat=(session.path), (d.hash), .torrent"

print = (cat, "Logging to ", (cfg.logfile))
log.open_file = "log", (cfg.logfile)
log.add_output = "info", "log"

I'm running libtorrent-0.13.8/rtorrent-0.9.8, built from source because VMware Photon has next to nothing in its repositories.

kannibalox commented 2 years ago

If you haven't added a torrent that requires DHT, and since the mode is set to auto instead of on, it's most likely simply not getting activated. There are log messages in the dht_debug, dht_router, dht_manager, and dht_debug outputs if you want to see the gory details.

I don't have a working DHT-only torrent for you, but the documentation is user-editable, so if you find one that contains legally available content then feel free to update the page with it. You should at least be able to activate DHT by grabbing any magnet link and stripping all the trackers from the URL before adding it.

AndrewSav commented 1 year ago

My log looks like this:

1662250115 dht_manager: cache file read (path:/media/sdr1/user1/private/rtorrent/work/rtorrent.dht_cache)
1662250115 dht_manager: initializing (bind_address:unspec)
1662250115 0000000000000000000000000000000000000000->dht_node: created (address:unspec)
1662250115 09D61EC265A456385A68257E18F751D54FC9D166->dht_router: creating (address:unspec)
1662250115 09D61EC265A456385A68257E18F751D54FC9D166->dht_router: adding nodes (size:0)
1662250116 dht_manager: starting (port:6881)
1662250116 09D61EC265A456385A68257E18F751D54FC9D166->dht_router: starting (port:6881)
1662250116 dht_server: starting (address:::)
1662250116 dht_manager: server start skipped, already active
1662250116 dht_manager: server start skipped, already active
1662250116 dht_manager: server start skipped, already active
1662250116 dht_manager: server start skipped, already active
1662250116 dht_manager: server start skipped, already active
1662250116 dht_manager: server start skipped, already active
1662250116 dht_manager: server start skipped, already active
1662250116 dht_manager: server start skipped, already active
1662250116 dht_manager: server start skipped, already active
1662250116 dht_manager: server start skipped, already active
1662250116 dht_manager: server start skipped, already active
1662250116 dht_manager: server start skipped, already active
1662250121 dht_manager: server start skipped, already active

This does not tell me much. And I'm getting No DHT nodes available for peer search. I wonder how to troubleshoot it deeper.

kannibalox commented 1 year ago

Do you have dht.add_node commands in your config like in the OP's? adding nodes (size:0) makes it seem otherwise.

AndrewSav commented 1 year ago

Do you have dht.add_node commands in your config like in the OP's? adding nodes (size:0) makes it seem otherwise.

Yes.

schedule2 = dht_node, 10, 0, "dht.add_node=dht.libtorrent.org:25401"
schedule2 = dht_node, 10, 0, "dht.add_node=dht.transmissionbt.com"
schedule2 = dht_node, 10, 0, "dht.add_node=router.utorrent.com"
aki-k commented 1 year ago

I got rtorrent working with dht (test torrent archlinux-2023.04.01-x86_64.iso.torrent):

It looks like the UDP port is not even needed. I have a Linux VM in Azure and its inbound security rules don't have any UDP ports allowed.

Here's the .rtorrent.rc that I have in that VM:

download_rate = 4000
max_peers = 10
max_peers_seed = 10
max_uploads = 10
min_peers = 10
min_peers_seed = 10
pieces.hash.on_completion = 1
pieces.sync.always_safe.set = 1
port_random = no
port_range = 1234-1234
schedule = low_diskspace,5,60,close_low_diskspace=1M
session = ~/.rtorrent-session-dir
upload_rate = 400
dht.mode.set = on
dht.port.set = 1235
log.open_file = "rtorrent", ~/.rtorrent.logs/rtorrent.log
log.open_file = "tracker", ~/.rtorrent.logs/tracker.log
log.open_file = "storage", ~/.rtorrent.logs/storage.log
log.add_output = "info", "rtorrent"
log.add_output = "critical", "rtorrent"
log.add_output = "error", "rtorrent"
log.add_output = "warn", "rtorrent"
log.add_output = "notice", "rtorrent"
log.add_output = "debug", "rtorrent"
log.add_output = "dht_debug", "tracker"
log.add_output = "tracker_debug", "tracker"
log.add_output = "storage_debug", "storage"
schedule = dht_node, 15, 0, dht.add_node=10.0.0.5:1234
protocol.pex.set = yes

10.0.0.5 is the IP address for eth0 interface of the VM (some NAT:ing going on)

nobrowser commented 2 months ago

I got rtorrent working with dht (test torrent archlinux-2023.04.01-x86_64.iso.torrent):

schedule = dht_node, 15, 0, dht.add_node=10.0.0.5:1234

10.0.0.5 is the IP address for eth0 interface of the VM (some NAT:ing going on)

What does the schedule line do? Like the OP says, it's impossible to figure out from the doc (and I'm reading the wiki which I believe is the official doc). I'm actually trying to enable DHT on the fly, by executing ^X commands in a running instance because I'm not ready to start fiddling with a rcfile. Is there a reason why it would work from a rcfile but not with ^X ?

-- Ian

kannibalox commented 1 month ago

What does the schedule line do?

dht_node is the name of the schedule, 15 is the number of seconds before the first run, 0 is the number of seconds between each next run ("0" is a special value that prevents it from repeating at all), and dht.add_node=10.0.0.5:1234 is the command that gets run on the scheduled times. So, 15 seconds after rtorrent starts, it adds the node 10.0.0.5:1234 to the DHT bootstrap pool. See the wiki or here for more details on scheduling.

I'm actually trying to enable DHT on the fly, by executing ^X commands in a running instance because I'm not ready to start fiddling with a rcfile. Is there a reason why it would work from a rcfile but not with ^X?

Most commands work the same regardless of whether they happen at startup or runtime, and the few that do care will throw explicit errors. I'd still recommend using an rtorrent.rc even just for the sake of convenience while troubleshooting.

You could also try enabling the DHT debug logs, but I don't know exactly how helpful those are:

log.open_file  = "dht", (cat,/tmp/rtorrent-dht.log)
log.add_output = "dht_debug", "dht"

See https://kannibalox.github.io/rtorrent-docs/cmd-ref.html#log-commands for an explanation of the logging commands.

nobrowser commented 1 month ago

Is your personal site recommended over the wiki?

kannibalox commented 1 month ago

You're asking a very biased source, but currently my fork of rtorrent-docs is the most complete reference for the individual commands that I'm aware of, while for pretty much anything else I'd recommend the wiki (if there's something missing from the wiki, feel free to add it, it's publicly editable!).