# Ktorrent/configure
## Chapter 4. Configuring KTorrent

So you have already read that KTorrent comes with plug-ins to enable or disable features. You can find the KTorrent preferences dialog by clicking Settings-> Configure KTorrent.

## Downloads
### Queue Manager

Looking at the Downloads tab, you will find the section Queue Manager. Effectively, this section allows you to put a limit on the maximum number of active downloads or uploads when torrents are driven by the Queue Manager. The idea behind the Queue Manager is that it provides you a way to configure which torrent should start downloading (or uploading) after another torrent switches its status. Switching from a status can mean:
* a torrent (automatically) switches from downloading to seeding
* a torrent (automatically) switches from seeding to seeding completed
* an active torrent driven by queue manager gets stopped manually by user interaction
* an active torrent driven by queue manager gets removed from the queue manually to a user-driven state by the user
The Queue Manager always takes the torrent highest in queue when it starts another torrent. The queue manager is a nice tool to automatically start queued torrents, and while doing so, it gives you a method to dedicate your bandwidth on a few torrents. If you do not want to make use of the queue manager, you are free to disable it by setting the max uploads and max downloads to 0.
The queue manager threads two different torrents— torrents in user-driven state and torrents in queue manager driven state.
Every torrent in a user-driven state will be excluded by the restrictions of the Queue Manager, until the torrent is put back in queue manager state by the user. The benefit of user-driven torrents is that it is an easy way to go over the limit of maximum running torrents if you want.
While loading a torrent in KTorrent, it will start in the queue manager and be set to the lowest priority of torrents which are already in the queue.
If you manually stop the torrent, the torrent will get changed from queue-driven to user-driven and will be excluded from the max downloads/uploads limitation.
There are three ways of changing the state of a torrent:
* open the Queue Manager, select the torrent to change, and select Controlled by Queue Manager or Controlled by User
* right click a torrent and choose Enqueue/Dequeue
* select a torrent and click the queue icon in the tool bar
There are also two possibilities to view whether a torrent is driven by Queue Manager or by the user:
* open the Queue Manager and look in the column, Controlled By
* clicking the icon Groups on the side panel to the left of the screen, and select the appropriate filter.

### Preferences

The preferences section is where you can configure the main preferences of KTorrent.

#### Maximum connections per torrent

With max connections per torrent, you can set how many peers KTorrent will allow you to connect to per torrent.
Having too many established connections can make the response time on your internet connection a lot slower. For this reason, it is wise to have a limit for connections.
Normally, 45 to 65 maximum connections per torrent is enough for running a single torrent, though some people who have a fast connection can configure this higher (together with a higher number of upload slots and a higher upload speed). Note it is possible to have good results with setting the per torrent limit to a 25-35 range (this really depends on the overall speed and health of a swarm you are in).
In practice, you should see what works best for you. Do *NOT* assume high settings will automatically improve your download speeds. Speed is more dependent on the health of the swarm and your own upload behavior than the number of connections.

#### Maximum connections global

Global Connection Limit is a setting you can configure for the maximum number of peers KTorrent should connect to over all running torrents combined.
The same rules apply here as with the maximum number of connections per torrent above. Keep in mind that this setting ideally should be high enough for the amount of torrents you want to run, while still trying to avoid losing responsiveness of your internet connection or even worse— capping your own bandwidth.

#### Maximum upload rate

With Maximum Upload Rate, you can configure the maximum speed KTorrent should upload at. Generally, it is safe to set this somewhere at 85-90% of your upload ability. Depending on the quality of your internet connection, you can set this a little high, but if you set this too high, it might compromise your download speed.
Do not be confused if your configured maximum upload speed is not always reached. This is normal practice; when downloading with peer to peer technologies, the uploads and downloads always depend on the "peer", or other user connected (e.g. Maybe the other peer is already downloading at full speed, there might not be any peers to upload to, or maybe there are "leechers" (those who already have all the files completed they requested).

#### Maximum download rate

With maximum download rate, you can configure KTorrent's maximum download speed. This can be useful if you want to use a web browser while running KTorrent, or maybe there are other users on your LAN who would like to claim some of the bandwidth too.
Just like with the upload speed, the download speed will depend on the other side and overall health in the swarm.

#### Port

You can configure which port KTorrent should use to listen for incoming connections from other peers in the swarm.
Normally, it is okay to leave the port number as it is. Some internet providers however, do not like traffic on known p2p ports, and have either blocked them or made the use of these ports less comfortable in other ways. Because of this, there are trackers that have banned known p2p ports and only allow you to use other ports. It is advisable to read the FAQ section of the tracker so you know whether you need to change the ports. Ports which are generally OK to use are numbers in the range 49152 to 65535. This range is also known as unregistered, dynamic, and/or private. There are no known programs registered to use these ports, so anyone should be able to use these ports freely without having to worry whether another program has already been assigned to it.
BitTorrent connections are established in one direction only. That is, peer A only tries to connect to peer B once, and if it fails in doing so, peer A must wait until peer B announces others may connect.
Because of this mechanism of connecting in BitTorrent (not a flaw of the protocol!), there are two reasons why one should be connectable:
* If two peers want to do business with each other, but both do not accept outside connections, they will find themselves not being able to share any data at all.
* If peer A is accepting connections, loads a torrent, and tries to connect to a firewalled peer B, he/she would have to wait until peer B announces a free connection. Before data would be able to transfer, there would be time wasted. Of course, in that time you could potentially have had a re-transmission of data between the two.
It is advisable to forward your ports so others can connect easily. It improves the speed and health of a swarm.

#### UDP tracker port

The UDP tracker port is a port for the communication with trackers that support the UDP transmission protocol. Communicating with a tracker on the UDP protocol is more efficient, although the amount of trackers which support UDP is not that high. The torrent file should include an URL which looks like udp://tracker-url.com:port/announce, instead of the normal variant http://tracker-url.com:port/announce (used with TCP). The port for UDP trackers is the only port which does not need to be forwarded if you are located behind a router or software firewall.

#### Number of upload slots

You can set KTorrent to how many peers per torrent it requires to give away an upload slot. It is essential to not set this option too high or too low because if you, do your download speed will regress. Use the following two rules as a guide:
A. If you really can not upload a lot because of a bandwidth limitation, then try to keep the upload limit at least 12kbit/s with at least 2kbit/s per peer. This is recommended because you have to try and maintain a number of upload slots for other peers. The 2kbit/s minimum is to lower the chance that another peer will choke you, and 12kbit/s is to keep 6 peers happy.
B. If you have a larger upload bandwidth on your connection, it is generally good and logical to assign more speed per peer. This can improve the efficiency of the data flow in swarm, and it stimulates the peers you are uploading to give something back (they will be more interested in you due to your higher upload speed).
In practice, example B would start with raising the maximum upload speed setting while keeping the amount of upload slots the same. Then if you think you are uploading too much per peer, you can raise this number a little (i.e. 5000kbit/s maximum upload speed for 6 upload slots in a large swarm would not stimulate the swarm to upload to you, whereas if you would have set it to 20 upload slots).

#### Max share ratio

Max share ratio is a setting which is automatically applied to each torrent file you open in KTorrent. It tells KTorrent to automatically stop a completed torrent when it has reached a certain configured share ratio. This setting is useful if you do not want to upload too much data for a particular reason. An example of this would include a data limitation on your internet connection or if you prefer to distribute your share ratio over all seeding torrents as quickly as possible.
You can also configure the share ratio of each torrent separately. This can be done from the status panel, to the right of where it says max ratio.

#### Keep seeding after download is finished

This setting is enabled by default. Normally, you would not want to disable this setting, since BitTorrent is a sharing protocol. It is important that peers who have completed all the data they have requested keep seeding to a certain level. This option can be changed and is useful if you have a very low data limit for your internet connection.

### Attention/forward port

You should forward your ports if your computer is located behind a router or firewall. Some users might not need to configure anything to ensure their port for BitTorrent is accepting connections. This is because some do not have a software firewall enabled or are not located behind any router.
How do I know whether my computer will accept BitTorrent connections?
Take a look at the log viewer panel and search for a message which says “Authentication(S) to 99.999.99.99 : ok”. If you can find one such message with the (S) behind authentication, peers are able to establish incoming connections. You can start downloading! If you can not find a single (S) in the log from the time you started the torrent and the first announce, you should forward your ports.
Port forwarding in a router can be done either by using NAT or the UPnP functionality inside the router. You can choose either, although UPnP might be easier if you are stationed in a LAN with dynamic IP address assignments. For the UPnP plug-in to work, you should first check your router documentation to check whether it is supported on your model. If it is supported, login to your router either by a web browser or by telnet and enable it before you load the UPnP plug-in of KTorrent. Check http://portforward.com and search for your router model if you do not know how to login to your router. This site tells you how to enable port forwarding from a router by using NAT as well, if you happen to choose the NAT method. Note that if you have chosen NAT and it is working correctly, you can disable the UPnP plug-in of KTorrent.
If you are unsure whether you are actually located behind a router, you can use the site http://whatismyip.com to find out and compare the IP address listed with your address from the output in the command ifconfig.