ownCloud Logo

BitTorrent

Transmission takes care of downloading and seeding files in the BitTorrent filesharing network.

Installed on a server as long.running service has substantial benefits from running it directly on a personal device.

  • No need to keep a system online or running until download completes.
  • Seed files forever, not only while online.
  • File transfers with residential high-speed connection, while on the road.
  • Tranasfers form multiple users don’t get in the way of each other.
  • Completed downloads are available immediately to all users who have access to the server.
  • Web-Interface for access without client software.

On the client side, nothing changes. You use the same client software the same way. While there is no noticable difference, behind the scenes all transfers take place on the server instead of the users desktop system.

Preparations

IP Address

Add IPv4 and IPV6 network adresses for the keyserver:

$ sudo ip addr add 192.0.2.36/24 dev eth0
$ sudo ip addr add 2001:db8::36/64 dev eth0

Also add them to the file /etc/network/interfaces to make them persistent across system restarts:

# bt.example.net - BitTorrent Server
iface eth0 inet static
    address 192.0.2.36/24
iface eth0 inet6 static
    address 2001:db8::36/64

DNS Records

Name Type Content Priority TTL
bt A 198.51.100.240   300
bt AAAA 2001:db8:1::36    
_443._tcp.bt TLSA 3 0 1 f8df4b2e……….76a2a0e5    

Check the “Add also reverse record” when adding the IPv6 entry.

Firewall Rules

IPv4 NAT port forwarding:

Protocol Port No. Forward To Description
UDP 51413 192.0.2.36 BitTorrent NAT UDP Port forwarding
TCP 51413 192.0.2.36 BitTorrent NAT TCP Port forwarding

Allowed IPv6 connections:

Protocol Port No. Destination Description
UDP 51413 2001:db8:1::36 Allow BitTorrent UDP
TCP 51413 2001:db8:1::36 Allow BitTorrent TCP
TCP 80 2001:db8:1::36 Allow HTTP to Transmission Web-UI
TCP 443 2001:db8:1::36 Allow HTTPS to Transmission Web-UI

Installation

Transmission is in the Ubuntu software repository. We install the server only.

$ sudo apt-get install transmission-daemon
After the installation there is
  • A new user and group debian-transmission.
  • The users home directory is /home/debian-transmission, but it doesn’t exist.
  • A directory /var/lib/transmission-daemon for the downloads, state-data and configuration.
  • A configuration file /etc/transmission-daemon/settings.json.
  • A service configuration file /etc/default/transmission-daemon.
  • A Ubuntu Upstart service /etc/init/transmission-daemon which will already be running.
  • The daemon is listening on all interfaces on TCP port 9091 and TCP and UDP ports 51413.

Directory for Incomplete Downloads

$ sudo mkdir -p /var/lib/transmission-daemon/downloads/.incomplete
$ sudo chown -R debian-transmission:debian-transmission \
    /var/lib/transmission-daemon/downloads/.incomplete

Configuration

The configuration file cannot be changed while the daemon is running.

$ sudo stop transmission-daemon

Then open /etc/transmission-daemon/settings.json and change the following lines:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{
    "alt-speed-down": 50, 
    "alt-speed-enabled": false, 
    "alt-speed-time-begin": 540, 
    "alt-speed-time-day": 127, 
    "alt-speed-time-enabled": false, 
    "alt-speed-time-end": 1020, 
    "alt-speed-up": 50, 
    "bind-address-ipv4": "192.0.2.36", 
    "bind-address-ipv6": "2001:db8::36", 
    "blocklist-enabled": false, 
    "blocklist-url": "", 
    "cache-size-mb": 4, 
    "dht-enabled": true, 
    "download-dir": "/var/lib/transmission-daemon/downloads", 
    "download-limit": 100, 
    "download-limit-enabled": 0, 
    "download-queue-enabled": false, 
    "download-queue-size": 8, 
    "encryption": 1, 
    "idle-seeding-limit": 30, 
    "idle-seeding-limit-enabled": false, 
    "incomplete-dir": "/var/lib/transmission-daemon/incomplete", 
    "incomplete-dir-enabled": true, 
    "lpd-enabled": true, 
    "max-peers-global": 200, 
    "message-level": 2, 
    "peer-congestion-algorithm": "", 
    "peer-id-ttl-hours": 6, 
    "peer-limit-global": 1200, 
    "peer-limit-per-torrent": 288, 
    "peer-port": 51413, 
    "peer-port-random-high": 65535, 
    "peer-port-random-low": 49152, 
    "peer-port-random-on-start": false, 
    "peer-socket-tos": "default", 
    "pex-enabled": true, 
    "port-forwarding-enabled": true, 
    "preallocation": 1, 
    "prefetch-enabled": 1, 
    "queue-stalled-enabled": true, 
    "queue-stalled-minutes": 30, 
    "ratio-limit": 4, 
    "ratio-limit-enabled": true, 
    "rename-partial-files": true, 
    "rpc-authentication-required": true, 
    "rpc-bind-address": "127.0.0.1", 
    "rpc-enabled": true, 
    "rpc-password": "********", 
    "rpc-port": 9091, 
    "rpc-url": "/transmission/", 
    "rpc-username": "transmission", 
    "rpc-whitelist": "127.0.0.1", 
    "rpc-whitelist-enabled": false, 
    "scrape-paused-torrents-enabled": true, 
    "script-torrent-done-enabled": false, 
    "script-torrent-done-filename": "", 
    "seed-queue-enabled": false, 
    "seed-queue-size": 10, 
    "speed-limit-down": 100, 
    "speed-limit-down-enabled": false, 
    "speed-limit-up": 1000, 
    "speed-limit-up-enabled": false, 
    "start-added-torrents": true, 
    "trash-original-torrent-files": false, 
    "umask": 18, 
    "upload-limit": 100, 
    "upload-limit-enabled": 0, 
    "upload-slots-per-torrent": 14, 
    "utp-enabled": true
}

Download Automation

With the help of the FlexGet add-on, Transmission can start downloading new files as soon as they are available.

FlexGet monitors RSS feeds, websites and similar sources and passes newly discovered Torrents who meet the configurable selection criteria to Transmission for downloading.

FlexGet Installation

FlexGet is a Python script and installed via the Python package installation program pip:

$ sudo apt-get install python-pip

If you already installed Python packages with pip before, make sure everything is up-to- date, as they are not managed by Ubuntu software updates:

$ sudo -H pip list --outdated | sed 's/(.*//g' | xargs sudo -H pip install -U

Install the FlexGet package:

$ sudo -H pip install --upgrade flexget

For fetching feeds from webservers which use TLS:

$ sudo -H pip install requests[security]

To work with Transmission FlexGet uses an additional Python package:

$ sudo -H pip install --upgrade transmissionrpc

FlexGet Configuration

Configuration is saved in the users home directory in a YAML file. In our case its the Transmission daemon home directory: /var/lib/transmission/daemon:

$ sudo mkdir -p /var/lib/transmission-daemon/flexget/
$ touch /var/lib/transmission-daemon/flexget/config.yml
$ sudo chown -R debian-transmission:debian-transmission \
    /var/lib/transmission-daemon/flexget

Note

The configuration file is in YAML format, which means, indentation is not just for the looks, has to be two spaces and not tabs.

The configuration file format and options are described in the FlexGet Wiki

/var/lib/transmission-daemon/flexget/config.yml:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
schedules:
  # Run all task once an hour
  - tasks: '*'
    interval:
      hours: 1
templates:
  torrent:
    transmission:
      username: transmission
      password: ********
      ratio: -1
tasks:
  Tails:
    # Download new Tails releases
    template: torrent
    rss: https://tails.boum.org/torrents/rss/index.rss
    accept_all: yes
  Ubuntu:
    # Download Ubuntu releases
    template: torrent
    html: 
      url: http://www.ubuntu.com/download/alternative-downloads
      title_from: url
    regexp:
      accept:
      - iso$
      rest: reject

In the example above we let FlexGet check for new downloads every hour, using the schedule plug-in.

The task itself consists of checking the RSS release feed of the Tails project by the RSS plugin and submit new Torrents found there to the Transmission daemon using the Transmission plugin.

To let FlexGet check the configuration file for errors:

$ sudo -Hu debian-transmission flexget check

To do a test run of the tasks:

$ sudo -Hu debian-transmission flexget --test --debug-warnings execute

System Service (Ubuntu Upstart)

/etc/init/flexget.conf:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
# Flexget daemon autostart

description "Flexget daemon"
author "roll.urown.net"

#start on (filesystem and networking) or runlevel [2345]
start on started transmission-daemon
#stop on runlevel [016]
stop on stopping transmission-daemon

respawn
respawn limit 5 30

#
# to find your local run the locale command an example local would be en_US.utf8
env LANG="en_US.UTF-8"
env UID="debian-transmission"
env GID="debian-transmission"
#
# log levels none, critical,error, warning, info, verbose, debug, trace
env LOGLVL="warning"
env CFGDIR="/var/lib/transmission-daemon/flexget"
export CFGFILE="${CFGDIR}/config.yml"

exec start-stop-daemon -S -c $UID:$GID --chdir $CFGDIR -x \
    /usr/local/bin/flexget -- --loglevel $LOGLVL daemon start
$ sudo init-checkconf /etc/init/flexget.conf
File /etc/init/flexget.conf: syntax ok
$ sudo initctl reload-configuration
$ sudo start flexget

Web Interface

Nginx Configuration

/etc/nginx/sites-available/bt.example.net.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 #
 # bt.example.net BitTorrent Server

 upstream transmission {
     server 127.0.0.1:9091;
     keepalive 4;
 }

 # Unsecured HTTP Site - Redirect to HTTPS
 server {

     # IPv4 private address
     # Port-forwarded connections from firewall-router
     listen                  192.0.2.10:80;

     # IPv4 private address
     listen                  192.0.2.15:80;

     # IPv6 global address
     listen                  [2001:db8::15]:80;

     server_name             bt.example.net;

     # Redirect to HTTPS
     return                  301 https://bt.example.net$request_uri;
 }

 # Secured HTTPS Site
 server {

     # IPv4 private address
     # Port-forwarded connections from firewall-router
     listen                  192.0.2.12:443 ssl spdy;

     # IPv4 private address
     listen                  192.0.2.15:443 ssl spdy;

     # IPv6 global address
     listen                  [2001:db8::15]:443 ssl spdy;

     server_name bt.example.net;

     # TLS - Transport Layer Security Configuration, Certificates and Keys
     include                  /etc/nginx/tls.conf;
     include                  /etc/nginx/ocsp-stapling.conf;
     ssl_certificate_key      /etc/ssl/certs/example.net.chained.cert.pem;
     ssl_certificate_key      /etc/ssl/private/example.net.key.pem;
     ssl_trusted_certificate  /etc/ssl/certs/CAcert_Class_3_Root.OCSP-chain.pem;

      # Default common website settings
      include                 /etc/nginx/sites-defaults/*.conf;

     # Public Documents Root
     root                    /var/www/bt.example.net/public_html;

     location /transmission/ {
         proxy_http_version 1.1;
         proxy_set_header Connection "";
         proxy_pass_header X-Transmission-Session-Id;

         location /transmission/rpc {
             proxy_pass http://transmission;
         }

         location /transmission/web/ {
             proxy_pass http://transmission;
         }

         location /transmission/upload {
             proxy_pass http://transmission;
         }

         location /transmission/web/style/ {
             alias /usr/share/transmission/web/style/;
         }

         location /transmission/web/javascript/ {
             alias /usr/share/transmission/web/javascript/;
         }

         location /transmission/web/images/ {
             alias /usr/share/transmission/web/images/;
         }
     }

      # Logging Configuration
      access_log              /var/www/bt.example.net/log/access.log;
      error_log               /var/www/bt.example.net/log/error.log;

 }

Tuning TCP/IP

Receive Buffer

UDP Failed to set receive buffer: requested 4194304, got 425984 (tr-udp.c:78)
UDP Please add the line "net.core.rmem_max = 4194304" to /etc/sysctl.conf (tr-udp.c:83)

Requested: 4,194,304

Got: 425,984

Send Buffer

UDP Failed to set send buffer: requested 1048576, got 425984 (tr-udp.c:89)
UDP Please add the line "net.core.wmem_max = 1048576" to /etc/sysctl.conf (tr-udp.c:94)

Requested: 1,048,576

Got: 425,984

Solution

$ sudo -s
$ echo "net.core.rmem_max = 4194304" >> /etc/sysctl.d/60-transmission-daemon.conf
$ echo "net.core.wmem_max = 1048576" >> /etc/sysctl.d/60-transmission-daemon.conf
$ service procps start
$ exit

Tracker

opentracker is a open and free bittorrent tracker project. It aims for minimal resource usage and is intended to run at your wlan router. Currently it is deployed as an open and free tracker instance. Read our free and open tracker blog and announce your torrents there (but do not hesitate to setup your own free trackers!).

Installation

opentracker is currently not in the Ubuntu software packages repository.

To install from source:

Get needed software libraries and stuff to be able to build your own software packages on Ubuntu:

$ sudo apt-get install libowfat-dev build-essential devscripts git autoconf

Get the source code:

$ cd /usr/local/src
$ git clone git://erdgeist.org/opentracker

Build:

$ cd opentracker
$ ./configure
$ make