Tuesday, September 28, 2010

Automatically update Transmission's block list

My favourite BitTorrent client Transmission supports bluetack-formatted blocklists. In computing, a blacklist or block list is a basic access control mechanism that allows everyone access, except for the members of the black list (i.e. list of denied accesses). Transmission utilizes a blocklist of known anti-P2P IPs, to prevent them from connecting and possibly interfering with transfers.
When you press the "Update Blocklist" button in the Transmission GUI, a new copy of blocklist is downloaded from a Transmission mirror that's updated twice daily. Since transmission-daemon on my headless server does not have such button I have to download the blocklist by hand, uncompress it, and place the uncompressed file in the daemon's blocklists folder.
Here's how to do it manually:

First, make sure you have enabled blocklist support. Stop transmission-daemon, open file /etc/transmission-daemon/settings.json, set "blocklist-enabled" property to true and re-start the daemon.

Go to directory where transmission expects to find the blocklist, on my PPA install it's in /var/lib/transmission-daemon/info/blocklists/:

# cd /var/lib/transmission-daemon/info/blocklists/

Here, files ending in ".bin" are the binary representations of bluetack files that Transmission generates for faster lookups.

You should now have a plain text, bluetack-formatted blocklist file called level1.

Reload transmissions-daemon:

# /etc/init.d/transmission-daemon reload

Now you should see a smaller file appearing called level1.bin. This a binary representation that Transmission generated for faster lookups by parsing our blocklist file. On start-up, Transmission will try to parse any non-".bin" file and generate a new blocklist from it, so you can have multiple blocklists just by copying new bluetack files into this directory.

Now depending on how frequently you want to update your blocklist you can place it either in /etc/cron.daily, /etc/cron.weekly or /etc/cron.monthly directory. I felt that weekly update was frequent enough:

mv update-blocklist /etc/cron.weekly/

You're done, now cron will automatically download the latest blocklist for you and reload Transmission with it.