SOHO : Small Office Home Office
Freeware - Opensource software tips, tricks, tweaks & fixes for managing, securing, improving the performance of SOHO Desktop, Laptop, Networks
Showing posts with label Torrents. Show all posts
Showing posts with label Torrents. Show all posts

Thursday, April 5, 2012

rtorrent queue manager python script


The complete story...

*** RTorrent as a torrent download manager ***

RTorrent is a very powerful console based torrent client.
You can find pretty advanced documentation on http://libtorrent.rakshasa.no.
I wanted to use rtorrent as my only torrent download manager, for that I needed to able to:

1) configure the total number of concurrent active torrent downloads;
2) add a queue of torrents to be automatically downloaded as soon as possible, provided the total number of active downloads before;
3) move the downloaded files to another directory and delete any related torrent;
4) limit the total amount of upload and download bandwidth not to choke my adsl connection.

while rtorrent provides built-in capabilities to accomplish 3) and 4), it doesn't provide a direct method to accomplish the first two points.
Fortunately rtorrent is able to watch a directory for torrents, meaning that automatically downloads any torrent added to that directory and automatically cancels any download related to a torrent that has been deleted from that directory.
I used this capability together with a little external script to solve 1) and 2).

First of all I created the following directory structure under /path (substitute /path with whatever you want):

/path/completed/
/path/loading/
/path/session/
/path/temp/
/path/watch/

loading contains the queued torrents;
session contains all the torrents rtorrent is downloading, this directory is managed by rtorrent and rtorrent only;
temp contains the uncompleted downloads, again this directory is managed my rtorrent;
completed contains all the completed downloads.

Then I configured rtorrent as follows:

--- .rtorrent.rc ---

directory = /path/temp
session = /path/session

schedule = watch_directory,10,10,load_start=/path/watch/*.torrent
schedule = untied_directory,5,5,"remove_untied="
schedule = low_diskspace,60,60,"close_low_diskspace=500M"

on_finished = rm_torrent,"execute=rm,$d.get_tied_to_file="
on_finished = move_complete,"execute=mv,-u,$d.get_base_path=,/path/completed/ ;d.set_directory=/path/
completed/"

upload_rate = 15
download_rate = 50

port_range = 6881-6889


--- .rtorrent.rc ---

Save this as .rtorrent.rc in your home directory.
directory specifies the temporary downloads directory;
session specifies where to put the torrents related to the active downloads;
upload_rate is for limiting the upload bandwidth;
download_rate is for limiting the download bandwidth;
I also specified the port_range for compatibility with the other torrent clients.
The other options are more difficult to understand:
the first two schedule commands are to configure a watch directory as described above, the third is to stop any download when the disk is full.
The two on_finished commands are to move all the finished downloads to the completed directory and to delete their torrents from the watch directory too.

These configurations alone accomplish 3) and 4), but we are not finished yet with 1) and 2):
we need a script to move torrents from the loading directory to the watch directory, so that the total number of concurrent downloads is lower or equal to the specified value. As a consequence there must be no more than that number of torrents in the watch directory.
When a torrent download is completed, it is removed from the session and the watch directories; the script can recognise this event and move another torrent to the watch directory and so on.
I wrote this script in Python:

--- rtorrentqueuemanager.py ---

#!/usr/bin/env python

# Now you can dynamically change the maximum number of simultaneous
# downloads writing the new number to the file "max_downloads_file" and
# then sending a signal SIGHUP to the rtorrentqueuemanager process.

import glob
import stat
import os
import shutil
import time
import signal

watch = "/share/storage/rtorrent/watch"
session = "/share/storage/rtorrent/session"
queue = "/share/storage/rtorrent/loading"
max_downloads_file = "/share/storage/rtorrent/max_downloads"
max_downloads = 2

def handler_sighup(signum, frame):
    f = open(max_downloads_file, "r")
    max_downloads = int(f.readline())
    f.close()

#### START
signal.signal(signal.SIGHUP, handler_sighup)
while True:
    time.sleep(60)
    bz2files = glob.glob(queue + "/*.torrent.bz2")
    for i in bz2files :
        os.system('bzip2 -d ' + i)
    gzipfiles = glob.glob(queue + "/*.torrent.gz")
    for i in gzipfiles :
        os.system('gunzip ' + i)
    sfiles = glob.glob(session + "/*.torrent")
    oldesttime = 0
    oldestfile = ""
    if len(sfiles) < max_downloads :
        qfiles = glob.glob(queue + "/*.torrent")
        for i in qfiles :
            ftime = os.stat(i)[stat.ST_MTIME]
            if oldesttime == 0 or ftime < oldesttime :
                oldesttime = ftime
                oldestfile = i
        if oldestfile != "" :
            shutil.move(oldestfile, watch)

--- rtorrentqueuemanager.py ---

save it as rtorrentqueuemanager.py.
Now you can start rtorrent with the screen utility:

screen rtorrent

detach the screen pressing Ctrl-A-D.
Then start the script:

python rtorrentqueuemanager.py &

From now on you can copy any torrent you want to download to the loading directory and rtorrent plus this script will take care of the rest!


Thanks to Jari Sundell for this great peace of software and to Shaun Dennie for giving me the idea of the queue manager script.

Stefano Stabellini
stefano@stabellini.net

Credit & Source : http://www.stabellini.net/rtorrent-howto.txt
Continue Reading...

Saturday, March 24, 2012

Allow only encrypted connections for both incoming and outgoing with rtorrent

What does encryption Do?

The RC4 encryption obfuscates not only the header but the entire stream. This means that it’s very hard for your ISP to detect that the traffic you are generating comes from BitTorrent.

Note that RC4 uses more CPU time than the plain encryption or no encryption. It is however harder to identify for traffic shaping devices


This can be achieved by modifying the .rtorrent.rc file
  • Quit all rtorrent sessions
  • Add / modify this line in rtorrent config file ( .rtorrent.rc located in the users home folder)  
encryption = require,allow_incoming,require_RC4
  • Restart rtorrent.
  • Check for E flag to all connected peers
( Click on image to enlarge )
Continue Reading...

Tuesday, March 13, 2012

Torrent client configuration

In order to apply these tips you need to know your maximum up- and download speed. You can test your bandwidth over here (stop all download activity while testing). 

Note that there’s a difference between kb/s (kilobits/second) and kB/s (kilobytes/second). To be precise, kB/s = kb/s divided by 8. In this tutorial we use kB/s (like most torrent clients do). This means that you might need to calculate your max speed in kB/s yourself if the speedtest only gives you the results in kb\s (so divide by 8 then).

Settings 1-4 can be found in the options, settings or preference tab of most torrent clients.

1. Maximum upload speed
Probably the most important setting there is. Your connection is (sort of) like a pipeline, if you use your maximum upload speed there’s not enough space left for the files you are downloading. So you have to cap your upload speed.

Use the following formula to determine your optimal upload speed…

80% of your maximum upload speed

so if your maximum upload speed is 40 kB/s, the optimal upload rate is 32kB/s

2. Maximum download speed
Although setting your maximum download speed to unlimited may sound interesting, in reality it will only hurt your connection. If you still want to be able to browse properly, set your maximum download speed to:

95% of your maximum download speed

so if your maximum download speed is 400 kB/s, the optimal download speed is 380kB/s

3. Maximum connected peers per torrent
Yet another setting that you don’t want to max out. I experimented quite a lot with the max connected peers settings and came to the conclusion that both high and low number hurt the download speed of a torrent. The following setting worked best for me.

upload speed * 1.3

so if your maximum upload speed is 40 kB/s, the optimal amount of connected peers per torrent is  40 * 1.3 = 52 .  I didn’t noticed a difference for fast or slow connections here.

4. Maximum upload slots
1 + (upload speed / 6)

so if your maximum upload speed is 30 kB/s, the optimal number of upload slots is

1 + (30 / 6) = 6

5.Change the default port.
By default, BitTorrent uses a port 6881-6999. BitTorrent generates a lot traffic (1/3), so isp’s like to limit the connection offered on the these ports. So, you should change these to another range. Good clients allow you to do this, just choose anything you like. If you’re behind a router, make sure you have your ports forwarded (portforward.com) or UPnP enabled.

6.Turn on Encryption
Encrypting your torrents will prevent throttling ISP’s from limiting your BitTorrent traffic. Check out how to enable encryption in Azureus, uTorrent, and Bitcomet, the three most popular torrent clients.


7.Enable DHT
DHT stands for “Distributed Hash Table”. If a web based tracker goes down, the torrents stay alive because peers can act as “nodes” keeping the swarm intact, and the torrent alive. So you could say that the DHT layer serves as a peer-to-peer tracker. The DHT feature is available on Azureus, Bitcomet, uTorrent and several other BitTorrent clients.


To do on windows PC

1. Disable Windows Firewall
It sucks. Windows Firewall hates P2P and often leads a life of it’s own. So disable it and get yourself a decent (free) firewall, Kerio or Zone Alarm for example.

2.Optimize your internet connection
The TCP optimizer is a freeware utility that optimizes your internet connection. I found it very useful and it helped speeding up my connection for regular internet activity and for downloading torrents. Just download it, and move the slidebar to your maximum download rate (note that it’s in kb/s). Don’t try to set it higher because that will hurt your download speeds!
Continue Reading...

Friday, April 15, 2011

How To Speed Up Torrents with Low Seeders


Here’s a ridiculously easy tip to squeeze out as many users as you can on a dead or dying torrent. It’s particularly handy when a torrent stops near the end, and/or the seed count is listed as zero. Having said that, I’ve also noticed that it helps to increase download speeds from healthy torrents, as well.

NOTE: Do not attempt this trick with private torrents - it possibly might get you banned from the tracker. Use this tip with torrents you find at Isohunt, TPB, Vertor, KickAssTorrents, etc.

How it works:
Simple. Just copy/paste the list of public trackers into your torrent’s tracker list.




udp://tracker.publicbt.com:80/announce

udp://tracker.openbittorrent.com:80/announce

udp://tracker.ilibr.org:6969/announce
























Applying the trackers to uTorrent:

In particular, this is a ‘µTorrent-compatible’ list, so that’s where I’ll show the example.

Open µTorrent, and right-click on the suspiciously-slow torrent. Select "Properties…".




In the first window box, the "General" tab should be open, and there should already be a list of existing trackers (or perhaps just one). ‘Copy’ the list from above, and ‘paste’ them into the window.




You should now be left with what looks like this (see below) - be certain that there’s a blank space (line) between each tracker in the list. Click "OK" to save the changes. No need to restart uTorrent; if the torrent is already ’started’ (ie - active), it will automatically update and thus look for the new trackers.




If there are ANY public users on that torrent, you’ll be sure to find them.


TIPS:

• Publicly-accessible trackers come and go - some may appear down; others will time out, go temporarily offline, or outright disappear altogether. For these reasons there truly is no definitive list of working trackers at any given time. However, there are available resources you can refer to in order to stay updated, such as:

* - http://bitsnoop.com/trackers/ — Offers a current list of the top 500 most popular trackers. Note that many entries in the list are private and thus will not work in public torrents.

* - Check out the tracker list in popular new torrents — For example, at KickAssTorrents visitors can view the current list of online trackers in the torrents. To do this, simply ‘click into’ a torrent’s details page, then click the tab called ‘Locations’.

• When browsing torrents, try to use magnet links whenever possible (requires DHT=enabled). Most torrent indexers now support magnet links. After a torrent has been added, you may then manually add the list of trackers from above.

• In uTorrent, enable as many ‘connectability’ options as possible - such as DHT, UDP, Peer Exchange, Peer Discovery, Tracker Scrape and Encryption Enabled (refer to the screenshot of uTorrent 2.0.4 below).


Continue Reading...