# Public and private connection profiles

> From the Guides page of the Rtorrent 16 panel, version 16.27-14G. Polish: https://www.qnaputilities.com/rtorrent16/docs/pl/tracker-kinds.md

Every torrent runs on the Public or the Private connection profile: how many peers it holds, how many it uploads to
and downloads from at once, and how many peers it asks each tracker for. The private flag in the `.torrent` file picks
the profile when the torrent is added, and a list of tracker hosts can pick the other one.

## Change how many peers a torrent holds

*Figure: The connection profiles in Settings*

1. Open **Settings → Connection profiles** and choose **Custom** to reveal the manual limits. Opening it preserves values; review and save your edits separately.
2. Set the peers per torrent of a profile, **min** and **max** in the row **Private profile: peers per torrent**
   or **Public profile: peers per torrent**: below the minimum rtorrent looks for more peers, and the maximum is the
   most connections one torrent holds. The row under it, **slots per torrent**, holds **upload** and **download**: the
   peers one torrent uploads to and downloads from at once.
3. Set how many peers each tracker is asked for, per announce. `-1` lets the tracker decide.
4. To put the torrents of a tracker on the other profile, add its host to the list of that profile, one host per
   line, such as `tracker.example.org`. A host on both lists gets Public.
5. Save. The numbers reach the running rtorrent at once: every torrent of the profile gets them, and so does every
   torrent added later. When rtorrent is stopped or refuses the change, the page shows a message, and the numbers
   apply at its next start.

A host list counts when a torrent is added: a torrent already in the list keeps the profile it has. The package
stores the profile with the torrent, so it survives a restart.

## See which profile a torrent has

*Figure: The profile's mark on Quick access rows*

1. On Quick access, find the mark beside the torrent's size: a shield with a check is the Private profile, a
   globe the Public one. Its tooltip names what the profile sets.
2. From the shell, read the stored profile and the peer maximum the torrent holds now:

```
/etc/init.d/rtorrent16.sh rpc d.custom <hash> rt16_kind
/etc/init.d/rtorrent16.sh rpc d.peers_max <hash>
```

![Tracker classification and torrent profiles](https://www.qnaputilities.com/rtorrent16/docs/img/tracker-kinds-en.svg)

## Disconnect very slow peers

1. Open **Settings → Connection** and turn on **Disconnect very slow peers**. It is off by default.
2. Set **Slow below (KiB/s)**, 2 by default.
3. Save.

Every five minutes the package checks the torrents that download, hold their peer maximum and have peers waiting. It
disconnects a peer that sends less than **Slow below (KiB/s)** on two checks in a row, but only while at least three
peers of the same torrent send ten times that or more. Each check disconnects at most a tenth of a torrent's peers: at
least one and at most five. A disconnected peer is
not banned and may come back. Each torrent that lost peers gets a line in `service.log` in
the logs folder. Compare the speeds of your own torrents before you leave it on.

## Details

### The defaults

| Value per torrent | Public | Private |
|---|---|---|
| Min / max peers | 40 / 200 | 20 / 100 |
| Upload / download slots | 30 / 30 | 15 / 100 |
| Peers each tracker is asked for | 100 | 50 |

These are limits and request sizes; they promise no number of peers and no speed. While a torrent downloads, its minimum
rises to the number of peers each tracker is asked for (to its maximum when the tracker decides), never above its
maximum: 100 for public and 50 for private with the defaults. When the download completes, or a check finds every piece
already there, the minimum from the profile applies again. The Dashboard's **Peers and their limits** card shows the values rtorrent runs with, and its
link profiles set them for a 1, 2.5 or 10 Gbps line (the Control Center guide).

### Peers that keep a download waiting

Once a downloading torrent holds its minimum of peers, rtorrent connects to no new peer by itself, and only peers that
connect to it can take the free places. So such a torrent disconnects the peers that keep it waiting: the torrent told
the peer it wants its pieces, and no piece went either way. Every two minutes it disconnects those that have kept it
waiting for five minutes. When it has received almost nothing for a minute (less than a tenth of its best 30 seconds
of the last ten minutes, or under 2 KiB/s), it looks every 30 seconds and disconnects those that have kept it waiting
for 90 seconds. A peer that lets the torrent download from it now and then starts the count again each time. A peer
that wants the torrent's pieces is not counted, and neither is one that is ready to send while all the torrent's
download slots are in use. A disconnected peer cannot connect again for 30 minutes. When the torrent is left with
fewer peers than its minimum, it connects to other peers it knows of. A torrent below its minimum and a complete
torrent disconnect nobody this way. **Peer rules** below sets these times, and can switch the rule off. With
**rtorrent log level** at notice (the default)
or more, `rtorrent.log` in the logs folder gets a line with `dropped … idle peers` each time. **Disconnect very slow
peers** above is separate: it deals with peers that send a little.

### Peers that drop a download

While a torrent downloads, it puts a peer back on its list of peers to connect to when the peer closes the connection,
when the connection breaks, or when the peer sends nothing for about four minutes. This holds for a peer the torrent
connected to itself, and for a peer that connected to the torrent and sent it pieces, when the torrent knows the port
that peer listens on. The same peer goes back on the list once in five minutes at most. The torrent connects to the
peers on that list every 30 seconds while it holds fewer peers than its minimum. A peer the torrent disconnected itself
stays off the list (one that kept the download waiting, above, or a very slow one), and so does a peer that sent bad
pieces or is banned. So when rtorrent stands still for several minutes, for example while it waits for a disk that does
not answer, and every peer disconnects the torrent, the torrent connects to the same peers again within about half a
minute of rtorrent answering again, without asking the tracker.

### Download slots

A torrent's download slots are how many peers it asks for pieces at the same time. They are not a speed limit, and
they are not its connections (those are its maximum of peers). A peer sends pieces only after it lets the torrent
download from it; such a peer takes one of the slots, or waits for one when all are in use. A private torrent has 100
download slots by default, as many as its maximum of peers, so it can ask every peer that lets it download. The link
profiles keep the two equal: 150 for 2.5 Gbps and 225 for 10 Gbps. Auto-tuning moves the slots with the maximum of peers in
your ratio, so equal numbers stay equal, up to **Global download slots**. When a torrent holds more peers than slots
(past that number, or with fewer slots than peers of your own choice), the rotation below shares them.

When all of a torrent's download slots are in use and more peers are ready to send, every 30 seconds the torrent takes
the slots of its slowest senders and gives them to peers that have waited: about one in eight of the slots (4 of 25,
10 of 100). A slot is never taken back within 25 seconds of being given, so each new sender is measured first. A
seedbox that comes after the slots are full gets its turn this way. A peer whose slot was taken back waits for another
turn; if it sent nothing while it had the slot, the rule above can still disconnect it. **Peer rules** below sets how
often and how many, and can switch the rotation off. With **rtorrent log level** at notice or more, `rtorrent.log` gets
a line with `rotated … download slots` each time.

An update from an earlier version changes **Private: download slots** from 15, 25 or 50, the link profiles' earlier
numbers, to 100, 150 or 225, and writes one line about it in the package's service log (Diagnostics, Logs), and in the
QNAP System Logs when they take every event, the default. Any other number stays as you set it. To take a profile's
numbers anyway, apply the link profile again on the Dashboard's **Peers and their limits** card.

### Peer rules

**Settings → Connection profiles → Peer rules** holds the numbers of the two rules above, for every torrent. A change
reaches rtorrent when you save, with no restart, and rtorrent uses it from its next 30-second round. A number under a
switch that is off has no effect.

| Setting | Default | What it does |
|---|---|---|
| Close peers that keep a download waiting | on | The rule in **Peers that keep a download waiting**. |
| Idle peers: close after | 300 seconds | How long a peer keeps the torrent waiting before it is disconnected. |
| Idle peers: check every | 120 seconds | How often the torrent looks for such peers. |
| Refuse a closed peer for | 1800 seconds | How long a disconnected peer cannot connect again. 0 lets it back at once. |
| Close idle peers sooner while a download is stuck | on | The faster pass while the torrent receives almost nothing. |
| While stuck: close after | 90 seconds | The shorter wait while the torrent is stuck. |
| While stuck: check every | 30 seconds | How often the torrent checks whether it is stuck. |
| Stuck below: % of its best | 10 | Stuck: two checks in a row under this share of its best check of the last ten minutes. 0 turns this test off. |
| Stuck below: KiB/s | 2 | Or two checks in a row under this speed. 0 turns this test off. |
| Rotate a full set of download slots | on | The rotation in **Download slots**. |
| Rotation: every | 30 seconds | How often a torrent with every download slot in use hands its slowest slots over. |
| Rotation: how many | Automatic | One slot in eight, one in ten from 31 slots; or one in 2, 3, 4, 5, 8, 10 or 20. |

### Advanced: tuning the peer rules in rtorrent.rc

Each setting in **Peer rules** is an rtorrent command, and each command has a `.set` form. A line in **Settings →
Advanced → Extra rtorrent.rc lines**, in `rtorrent.rc.local` or in a drop-in in `/usr/bin/rtorrent16/etc/rtorrent.rc.d/`
sets it at every start:

```
throttle.idle_peers.timeout.set = 600
throttle.download_slots.rotate_interval.set = 60
```

rtorrent reads the package's own lines first, then the drop-ins, `rtorrent.rc.local` and the extra lines, so a line of
yours wins at start. The field in **Peer rules** then shows `rtorrent runs 600: a line of your own in rtorrent.rc sets
it`. Changing that field and saving sets the running value until the next start, when your line wins again. To go
back to the panel's value, remove your line and restart rtorrent. Over XML-RPC
(`throttle.idle_peers.timeout.set "" 600`) a command acts from rtorrent's next 30-second round; a value out of its
range is refused with the range in the error, and the number stays as it was.

| Command | Default | Range |
|---|---|---|
| `throttle.idle_peers` | 1 | 0 off, 1 on |
| `throttle.idle_peers.timeout` | 300 | 30 to 86400 seconds |
| `throttle.idle_peers.pass_interval` | 120 | 30 to 3600 seconds, a multiple of 30 |
| `throttle.idle_peers.refuse_time` | 1800 | 0 to 86400 seconds; 0 refuses nobody |
| `throttle.idle_peers.starved` | 1 | 0 off, 1 on |
| `throttle.idle_peers.starved_timeout` | 90 | 30 to 3600 seconds |
| `throttle.idle_peers.starved_interval` | 30 | 30 to 600 seconds, a multiple of 30 |
| `throttle.idle_peers.starved_ratio` | 10 | 0 to 100 percent of the best check of the last ten minutes; 0 turns the test off |
| `throttle.idle_peers.starved_floor` | 2048 | bytes a second; 0 turns the test off |
| `throttle.download_slots.rotate` | 1 | 0 off, 1 on |
| `throttle.download_slots.rotate_interval` | 30 | 30 to 3600 seconds, a multiple of 30 |
| `throttle.download_slots.rotate_divisor` | 0 | 0 automatic (one in 8, one in 10 from 31 slots), or 2 to 100: one in that many |

The panel offers a choice of the intervals and divisors; the commands take any value in their range.

### What a profile does not change

A profile sets connection limits only. The private flag of the `.torrent` file still decides DHT and peer exchange:
a torrent with the private flag never uses them, whatever its profile. The package adds its public tracker list only
to a torrent whose flag is public (**Add public trackers to new public torrents**, `trackers_source`). Such a torrent
takes the first 16 addresses of the list and keeps them when rtorrent restarts; in the merged list, the default, these
are the most reliable ones. A Private
profile on a torrent whose flag is public therefore keeps DHT, peer exchange and the public trackers; a Public profile
on a private torrent does not gain them.

The profile also picks which seeding rule of **Seeding & Retention** a torrent follows, the public or the private
one. The targets and what happens when one is reached are set there; a profile alone stops no torrent.

### Speed limits

**Settings → Bandwidth & limits** holds the total limits: **Max download rate** and **Max upload rate** (0 is
unlimited) and turtle mode's two limits, which replace both while it is on. It also holds named throttle groups (one
per line: `name,down_kb,up_kb`) that you assign to torrents in ruTorrent under Throttle. A group works only while the
global rate is limited.

The same two limits change on the **Dashboard** and in **Quick access**: tap or click the figure on the **Download** or
**Upload** tile, type the limit in KiB/s (0 is unlimited) and leave the field. Leaving it saves the limit: Done on a
phone's keyboard, Enter, Tab, a tap elsewhere on the page or **Save limits** on the bar at the bottom. **Cancel** or
Escape keeps the old limit. An unchanged number or an empty field saves nothing. The limit stays after a restart.

![How transfer limits combine](https://www.qnaputilities.com/rtorrent16/docs/img/bandwidth-throttle-en.svg)
