RTorrent

From ArchWiki
Jump to navigation Jump to search

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

rTorrent is a very simple, elegant and ultra-light bittorent client. It is written in C++ and uses ncurses, so it is completely text based and runs entirely in a console. rTorrent is ideal for low-end systems and with the addition of GNU Screen and openssh it is convenient as a remote bittorrent client.

Installing

# pacman -S rtorrent

You can also install Template:Package AUR from the AUR.

Configuring

Before running rTorrent, copy the default configuration file, which is available at the rTorrent project page, and save it as .rtorrent.rc in your home directory.

Once the file has been saved, open it with your preferred text editor and make any necessary changes. Simply uncomment the options you wish to enable/utilize. For more detailed information on the options available, visit rTorrent Common Tasks

Recommended Configuration

These values in the following are subjective and dependent upon your own system and Internet connection speed. To find the optimal settings for you to use, visit the following website and follow the instructions: Optimize Your BitTorrent Download Speed

# Maximum and minimum number of peers to connect to per torrent.
#min_peers = 40
max_peers = 52

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
max_peers_seed = 52

# Maximum number of simultanious uploads per torrent.
max_uploads = 8

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 200
upload_rate = 28

The option below will determine where your torrent data will be saved. Change the default save directory to whatever is most convenient. Be sure to enter the absolute path; there is an odd bug with rTorrent sometimes does not respect relative paths (i.e. ~/torrents):

# Default directory to save the downloaded torrents.
directory = /home/[user]/torrents/

This option will allow rTorrent to save the progess of your torrents. Be sure to create a directory called .session (simply run as normal user:mkdir ~/.session):

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session = /home/[user]/.session/

The following option will have rTorrent "watch" a particular directory for new .torrent files. Be careful when using this option as rtorrent will move the torrent file to your session folder and rename it to it's hash value. Using your browser, when you find a .torrent file you would like to download, just save the file into this directory and rTorrent will automatically start the torrent. Be sure to create the directory that will be watched (simply run as normal user:mkdir ~/watch):

# Watch a directory for new torrents, and stop those that have been
# deleted.
#schedule = watch_directory,5,5,load_start=./watch/*.torrent
#schedule = untied_directory,5,5,stop_untied=
schedule = watch_directory,5,5,load_start=/home/[user]/watch/*.torrent
schedule = untied_directory,5,5,stop_untied=
schedule = tied_directory,5,5,start_tied=

The option below will stop rTorrent from downloading any further when disk space is low. This is particuarly useful with a Seedbox where disk space is quite limited. Change the value as you like:

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=100M

This option will set what port to use for listening. It is recommended to use a port that is higher than 49152. rTorrent allows the use of a single port rather than a range; a single port rather than an actual range is recommended.

# Port range to use for listening.
port_range = 49164-49164

The following option allow for a hash check whenever a torrent is complete or whenever rTorrent is restarted. This will make sure there are no errors with your acquired/seeding files.

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
check_hash = yes

The following option allows for the enabling of encryption. This is very important to enable, if not for yourself, but for others in the torrent swarm; people might need to obscure their bandwidth usage from their ISP. Does not hurt you to enable even if you do not need such protection. More information: Bittorrent Protocol Encryption

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext
encryption = allow_incoming,try_outgoing,enable_retry

The following is for DHT support. If you use public trackers, you'll want to enable DHT to acquire more peers. If you use only private trackers, do not enable DHT as this will reduce your speeds and can create a privacy risk. Some private trackers will even warn you if you use DHT.

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
# 
# dht = auto

# UDP port to use for DHT. 
# 
# dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
# peer_exchange = yes

Be sure to forward the proper port(s) with your router if you use one. A decent guide per router make/model can be found here.

Pre-allocation

One could recompile libtorrent from ABS with a new switch to configure pre-allocation:

 ./configure --prefix=/usr --disable-debug --with-posix-fallocate|| return 1

It will pre-allocate files before downloading the torrent but this has its pros and cons:

Pros

This limits/avoids fragmentation of the filesystem

Cons

This introduces a delay during the pre-allocation if the filesystem does not support natively the fallocate syscall.

So i recommend its use for users of xfs and ext4 and btrfs which have native fallocate syscall. They will see no delay during preallocation and no fragmented filesystem. Others filesystems will cause delay at pre-allocation time but no fragmented file.

Controls

rTorrent relies exclusively on keyboard shortcuts for user input. A complete guide is available on the main site: rTorrent User Guide

Here are the basics for quick reference:

  • Control-q : closes rTorrent, done twice makes the program shutdown without waiting to send stopping information to the trackers.
  • Left arrow : returns to the previous screen.
  • Right arrow : goes to the next screen.
  • a|s|d : increase global upload throttle about 1|5|50 KB/s
  • A|S|D : increase global download throttle about 1|5|50 KB/s
  • z|x|c : decrease global upload throttle about 1|5|50 KB/s
  • Z|X|C : decrease global download throttle about 1|5|50 KB/s
  • Control-S : starts download
  • Control-D : stops an active download, removes a stopped download.
  • + or - : changes the download priority of selected torrent.
  • Backspace : adds the specified .torrent. After pressing this button write full path or URL of .torrent file. You can use Tab and other tricks from bash.

Use rTorrent with Screen

Screen is a program that will allow CLI applications to be run in the background and without X running.

Install screen:

# pacman -S screen

and then copy screenrc to your home directory as normal user:

$ cp /etc/screenrc ~/.screenrc

To have rTorrent always start with screen, add the following to your .screenrc file:

$ screen -t rtorrent rtorrent 

To start screen + rTorrent, simply run screen from a terminal. Control-a followed by d will detach screen, and running screen -r will open screen again.

On a remote machine

Most setups of rTorrent on a remote machine involve using Screen. Supposing you have a detached Screen session with rtorrent on the remote machine (and the option to SSH into it), you can gain access to it using:

/usr/bin/ssh -t -p <ssh port on remote machine> <user>@<remote machine> screen -RD

If you want immediate access on startup, you will need to upload a key from your machine to remote host (so you will not be prompted for a password) and setup a terminal to run the command above. An inittab example using rungetty on virtual console 4:

sam:45:respawn:/sbin/rungetty tty4 -u <local user> -- /usr/bin/ssh -t -p <ssh port on remote machine> <remote user>@<remote machine> screen -RD

rtorrent Daemon with screen

I use this on my home server to run rtorrent w/ screen as a daemon. With the username rtorrent Just create an rtorrent file in your /etc/rc.d/ and add the following code.

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
  start)
    stat_busy "Starting rtorrent"
    su rtorrent -c 'screen -d -m rtorrent' &> /dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      add_daemon rtorrent
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping rtorrent"
    killall -w -s 2 /usr/bin/rtorrent &> /dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm_daemon rtorrent
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
esac
exit 0

On a remote computer I use the following script to connect to the server's daemon process:

ssh -t rtorrent@192.168.1.10 'screen -r'

Additional Tips

  • To use rTorrent with a tracker that uses https, do the following as root:
cd /etc/ssl/certs
wget --no-check-certificate https://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_Global_eBusiness_CA-1.cer
mv Equifax_Secure_Global_eBusiness_CA-1.cer Equifax_Secure_Global_eBusiness_CA-1.pem
c_rehash

And from now on run rTorrent with:

rtorrent -o http_capath=/etc/ssl/certs

Be sure to change .screenrc to reflect this change if you use screen:

screen -t rtorrent rtorrent -o http_capath=/etc/ssl/certs



Send Text Message Upon Torrent Completion Using GMail

Cell phone providers allow you to "email" your phone:

Verizon: 10digitphonenumber@vtext.com
AT&T: 10digitphonenumber@txt.att.net
Former AT&T customers: 10digitphonenumber@mmode.com
Sprint: 10digitphonenumber@messaging.sprintpcs.com
T-Mobile: 10digitphonenumber@tmomail.net
Nextel: 10digitphonenumber@messaging.nextel.com
Cingular: 10digitphonenumber@cingularme.com
Virgin Mobile: 10digitphonenumber@vmobl.com
Alltel: 10digitphonenumber@alltelmessage.com OR
10digitphonenumber@message.alltel.com
CellularOne: 10digitphonenumber@mobile.celloneusa.com
Omnipoint: 10digitphonenumber@omnipointpcs.com
Qwest: 10digitphonenumber@qwestmp.com

If you have Verizon, your cell phone's "email" is 5551234567@vtext.com

  • Install Heirloom's mailx program:
pacman -Sy mailx-heirloom
  • Clear the /etc/nail.rc file and enter:
set smtp=smtp.gmail.com:587
set smtp-use-starttls
set ssl-verify=ignore
set ssl-auth=login
set smtp-auth-user=USERNAME@gmail.com
set smtp-auth-password=PASSWORD

Now to send the text, we must pipe a message to the mailx program.

  • Make a bash script (/path/to/mail.sh):
echo "$@: Done" | mailx 5551234567@vtext.com

Where the $@ is a variable holding all the arguments passed to our script.

  • And finally, add the important ~/.rtorrent.rc line:
system.method.set_key = event.download.finished,notify_me,"execute=/path/to/mail.sh,$d.get_name="

Breaking it down:

notify_me is the command id, which may be used by other commands, it can be just about anything you like, so long as it is unique.

execute= is the rtorrent command, in this case to execute a shell command.

/path/to/mail.sh is the name of our script (or whatever command you want to execute) followed by a comma separated list of all the switches/arguments to be passed.

$d.get_name= 'd' is an alias to whatever download triggered the command, get_name is a function which returns the name of our download, and the '$' tells rtorrent to replace the command with its output before it calls execute.

The end result? When that torrent, 'All Live Nudibranches', that we started before leaving for work finishes, we'll be texted:

All Live Nudibranches: Done

See Also

Screen Tips

A Detailed Intro to Bittorrent including definition of terms terms

Web GUI Clients for RTorrent

  • WTorrent a web interface to rtorrent programmed in php using Smarty templates and XMLRPC for PHP library.
  • nTorrent A graphical user interface client to rtorrent (a cli torrent client) written in java.
  • rTWi a simple rTorrent web interface written in PHP.
  • rtGui a web based front end for rTorrent written in PHP and uses XML-RPC to communicate with the rTorrent client.