A decentralised tracker
Recently I received a wonderful gift, a Piratebox! Now I have my own Internet! With a forum, a chat and a file sharing server! So cool!
What is not cool is that my hardware is very limited and the platform is stable only when the custom part is kept at minimum.
Definitely the best part of the box is the shared file server, connect, upload/download and go, a single download can go as up as 1Mb/s (using scp) or 30Mb/s with wget but not everyone can use a terminal or have credentials to access the box, the easiest option is definitely the HTML interface.
Under the hood the piratebox is powered by lighttp, a very resource-light webserver that fits good in the great picture of the project but we are a little late with the updates. Piratebox ships whit v0.9 and lighttp is now at v1.4, maybe we can squeeze more from the hardware with asyncronous I/O or some modern witchcraft but that’s not the point.
Before diving into the development part of this article I would like to say a few word about Droopy. Droopy is the magic that runs the piratebox most loved feature, the file sharing. It provides a dead simple upload page that you can encapsulate inside an iframe and you can use python to make more magic happen during the upload process. What I don’t really like about this approach is that it’s good only if you have small files or you are really patient.
A better approach would be using a file-sharing protocol like bittorrent, the file is avaiable to the network, not uploaded to the piratebox storage and there is virtually no size limit to what you can share.
Enough with the tecno-blabbery, let’s run our PirateBay!
Everything has been made possible by the bnbt tracker project, I think it has been abandoned a long time ago (2006) but the docs is something good and I did most of the experimentation for you.
The package we are gonna install is cbtt and you can find it in the package list for the OpenWrt attitude adjustment release. We will also need the uclibcxx package, a C++ library on diet, required to run our tracker.
Move the packages to the piratebox either with scp or upload it to the shared folder.
As in every linux distro we have a package manager, opkg; here you can find more info about the usage.
This commmand will install both the library and the tracker software on a extended-root partition we have “mounted” as ext, se opkg.conf file for more info.
Link this new executable in /bin and you will be ready to go on.
Go on and give it a try, start the server with the command bnbt
, a lot of log lines will come out and you can see what happens.
Good news, it works! After you killed the server you will find some files around that it has generated for you.
You can open them and look around, bnbt.cfg is the configuration file, dstate.bnbt is the internal file to keep some stats as number of completed torrents and tags.bnbt is the internal file to keep track of the tags you can add to torrents.
But I don’t like it this way, these files are polluting my limited memory on the root filesystem and they can grow very large, let’s move them to somewhere else.
This is definitely better, now the files are on the external memory. Let’s move on and let the tracker start at boot.
init files
I don’t know if this is the best way to handle this but I found that init files are the simplest option so I will go that way.
Init files are all alike, so I will just post mine, just copy and paste it into the tracker file you created before.
Now the final touch, enable it. This will write a file, S99tracker to /etc/rc.d/
and it will start the tracker at boot.
To enable it
Reboot the piratebox and wait until it is back online, go to http://piratebox.lan:26213/users.html, here you can create a user with every permission, it will be your administrator. Do me a favor and don’t call it admin, administrator or root and give it a decent password. The email is required but you can put anything in there, so be creative.
The next page you will see is the tracker’s index page, there you can see what your tracker is doing with the torrent network you set up.
There won’t be a lot of info but this is good, we prefer anoninmity and no logging.
configuring your tracker
You can find a lot of info on the official documentation of the bnbt project, so I won’t cover (now) what these config means, just copy and paste it to your config file (which is now /mnt/ext/etc/config/bnbt/bnbt.cfg
).
I know working on the Piratebox is not that simple, so here it is the config file, upload it to the piratebox and mv it to the bnbt config folder.
Now you only need a torrent to upload and we will see if the tracker is really working.
make a torrent
I will be only covering how to do this with a command line but google is your friend.
We will use mktorrent because it’s dead simple, the problem is it’s not avaiable on the current release of the piratebox so you have to use another pc to create the torrent file.
let it run and we are done, upload the torrent file to the piratebox, download it from the Shared file folder and open it with your torrent client of choiche. When prompted where to save the file choose the current file location on your pc and Enable local peer discovery to share your file with the local net.
Web seeds
Okay but if I already have a file on the piratebox and I want it to stay there how can this help me achieving a better download speed?
Intrducing Web Seeds, just use the option --web-seed
with the file url like this.
Basically this will enable the piratebox to be a seed box, serving the files both on http and torrent.
Conclusion
I had fun with this project and it all went very well, it took maybe three days of thinkering and it’s now working quite well.
What I really like about this implementation is that if the configuration of the tracker on every box is the same then you can jump across networks with your files and you can keep sharing, there is the option to have the tracker display every torrent it is tracking and that would mean that we can add a page to the piratebox where avaiable torrents are listed for everyone to go and get it.