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.
1 2 3
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.
1 2 3 4 5 6 7 8 9 10 11 12 13
Good news, it works! After you killed the server you will find some files around that it has generated for you.
1 2 3 4 5 6
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.
1 2 3
This is definitely better. Let’s move on and let the tracker start at boot.
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Now the final touch, enable it. This will write a file, S99tracker to
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
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 but it’s not avaiable on the current release of the piratebox custom OpenWrt so you have to use another pc.
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.
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.