ownCloud Logo

BitTorrent

Transmission takes care of downloading and seeding files in the BitTorrent file sharing 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.

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

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 web servers 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:

 1schedules:
 2  # Run all task once an hour
 3  - tasks: '*'
 4    interval:
 5      hours: 1
 6templates:
 7  torrent:
 8    transmission:
 9      username: transmission
10      password: ********
11      ratio: -1
12tasks:
13  Tails:
14    # Download new Tails releases
15    template: torrent
16    rss: https://tails.boum.org/torrents/rss/index.rss
17    accept_all: yes
18  Ubuntu:
19    # Download Ubuntu releases
20    template: torrent
21    html: 
22      url: http://www.ubuntu.com/download/alternative-downloads
23      title_from: url
24    regexp:
25      accept:
26      - iso$
27      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#!/bin/bash
 2# Flexget daemon autostart
 3
 4description "Flexget daemon"
 5author "roll.urown.net"
 6
 7#start on (filesystem and networking) or runlevel [2345]
 8start on started transmission-daemon
 9#stop on runlevel [016]
10stop on stopping transmission-daemon
11
12respawn
13respawn limit 5 30
14
15#
16# to find your local run the locale command an example local would be en_US.utf8
17env LANG="en_US.UTF-8"
18env UID="debian-transmission"
19env GID="debian-transmission"
20#
21# log levels none, critical,error, warning, info, verbose, debug, trace
22env LOGLVL="warning"
23env CFGDIR="/var/lib/transmission-daemon/flexget"
24export CFGFILE="${CFGDIR}/config.yml"
25
26exec start-stop-daemon -S -c $UID:$GID --chdir $CFGDIR -x \
27    /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 # bt.example.net BitTorrent Server
 3
 4 upstream transmission {
 5     server 127.0.0.1:9091;
 6     keepalive 4;
 7 }
 8
 9 # Unsecured HTTP Site - Redirect to HTTPS
10 server {
11
12     # IPv4 private address
13     # Port-forwarded connections from firewall-router
14     listen                  192.0.2.10:80;
15
16     # IPv4 private address
17     listen                  192.0.2.15:80;
18
19     # IPv6 global address
20     listen                  [2001:db8::15]:80;
21
22     server_name             bt.example.net;
23
24     # Redirect to HTTPS
25     return                  301 https://bt.example.net$request_uri;
26 }
27
28 # Secured HTTPS Site
29 server {
30
31     # IPv4 private address
32     # Port-forwarded connections from firewall-router
33     listen                  192.0.2.12:443 ssl spdy;
34
35     # IPv4 private address
36     listen                  192.0.2.15:443 ssl spdy;
37
38     # IPv6 global address
39     listen                  [2001:db8::15]:443 ssl spdy;
40
41     server_name bt.example.net;
42
43     # TLS - Transport Layer Security Configuration, Certificates and Keys
44     include                  /etc/nginx/tls.conf;
45     include                  /etc/nginx/ocsp-stapling.conf;
46     ssl_certificate_key      /etc/ssl/certs/example.net.chained.cert.pem;
47     ssl_certificate_key      /etc/ssl/private/example.net.key.pem;
48     ssl_trusted_certificate  /etc/ssl/certs/CAcert_Class_3_Root.OCSP-chain.pem;
49
50      # Default common website settings
51      include                 /etc/nginx/sites-defaults/*.conf;
52
53     # Public Documents Root
54     root                    /var/www/bt.example.net/public_html;
55
56     location /transmission/ {
57         proxy_http_version 1.1;
58         proxy_set_header Connection "";
59         proxy_pass_header X-Transmission-Session-Id;
60
61         location /transmission/rpc {
62             proxy_pass http://transmission;
63         }
64
65         location /transmission/web/ {
66             proxy_pass http://transmission;
67         }
68
69         location /transmission/upload {
70             proxy_pass http://transmission;
71         }
72
73         location /transmission/web/style/ {
74             alias /usr/share/transmission/web/style/;
75         }
76
77         location /transmission/web/javascript/ {
78             alias /usr/share/transmission/web/javascript/;
79         }
80
81         location /transmission/web/images/ {
82             alias /usr/share/transmission/web/images/;
83         }
84     }
85
86      # Logging Configuration
87      access_log              /var/www/bt.example.net/log/access.log;
88      error_log               /var/www/bt.example.net/log/error.log;
89
90 }

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