Torrantula is a BitTorrent client for Mac OS X and Windows written entirely in REALBasic. It is capable of downloading and seeding single and multifile torrents, and has an advanced user interface for monitoring download progress.It also has a web interface (currently under development) which allows torrents to be started remotely andviewed once they have downloaded.

Download with Source

Why REALBasic?I spent most of the summer working on a BitTorrent tracker. I read hundreds of pages of research about BitTorrent,and it sparked my curiosity. I wanted a client that I could play with: one that I could easily change and use to experimentwith different piece selection algorithms and endgame modes, etc…

For that purpose, REALBasic seemed the obvious choice. I searched the web for existing implementations and didn’t find any, soI designed and wrote the entire client from scratch. I wanted to get my hands dirty and learn about BitTorrent, and it worked.Like most REALBasic applications, Torrantula chews up memory and processor cycles like crazy – but it gets the job done, and it only took me a week and a half.

Capability
I wouldn’t recommend using this as your primary BitTorrent client. It’s slow and heavy. However, if you’re looking to implementBitTorrent in your REALBasic application, this will do everything you need. For those BitTorrent junkies, here’s a more complete list of features:

  • Torrents: Torrantula reads standard bencoded torrent files. You can open torrent files directly or specify a torrent url and let it download them. Single and multifile torrents are fine. It also checks for existing data if the file(s) already exist.
  • Tracker Communication: Torrantula sends standard announce requests and can read compact and non-compact responses from a tracker.It does not send scrape requests and does not use any secondary trackers listed in the torrent file. It obeys the interval property returnedby the tracker.
  • NAT-PMP, STUNT: Torrantula doesn’t implement any NAT traversal. In other words, it can’t get through your router unless you manuallyconfigure port forwarding/DMZ. I don’t think it is possible to do in REALBasic. At leastnot easily.
  • Peer Search: Torrantula doesn’t implement PEX or DHT. All peers must be returned by the tracker or injected manually.
  • Peer Communication: Torrantula sends all the standard messages associated with the BitTorrent protocol as defined here: http://wiki.theory.org/BitTorrentSpecification. It maintains a copy of eachpeer’s bitfield and can display it as an image. It keeps track of “debt” to each peer as pieces are recieved, so it could be setup tomore accurately determine which peers it should send data too. It logs data very aggressively and will display requests sent out and piecesrecieved.
  • Statistics Collection: I was interested in collecting block transfer statistics. Torrantula logs the throughput ofevery peer on a block-by-block basis. It does not calculate overall transfer rate, though.
  • Piece Selection: The client was designed to be easy to modify. Piece selection is pretty straightforward and this versionsupports two methods: In spread mode, pieces are sorted according to their rarity and then blocks are chosen from the rarest. Any piece which is partiallycomplete will be completed as quickly as possible. In streaming mode, earlier pieces are chosen first. I am working on a killer implementation of this whichuses a sliding “target” region and sends duplicate requests for late pieces, but it isn’t finished yet.

    In both modes, endgame begins when all pieces have been requested. Duplicate requests will be forced in order to keep all peers busy and get the dataas quickly as possible.

Known Issues
Torrantula crashes occasionally when you start multiple downloads. At the moment, I am not sure why. REALBasic gives no reason, and the application quits withoutany notice. I’m not sure when it started happening. I believe there is a socket double-disconnect problem that is causing it.

Block requests are not “stacked” on peers. One request is sent, data is recieved, another request is sent, etc.. When I wrote the client I did not realize that most clients keep a request queue on the remote peer to improve performance.

Dependencies
Torrantula requires the Monkey Bread Software plugin to compute SHA1 hashes of piece data. The GUI also uses Einhugur’s IconLib to displayOS-native file icons. I don’t actually own the MBS plugin, so the downloadable beta version display’s reminder messages occasionally.

Future Development
This is more or less the end of the road for Torrantula. I have learned an incredible amount about BitTorrent, and I feel this is a goodbasic implementation. However, I don’t think REALBasic is powerful enough to create a beautiful and highquality client like Transmission or Azureus. I use a lot of other programming languages, and I think C++ or Objective C would be a muchbetter choice if I were to develop a production quality client. I wrote this to learn about BitTorrent, and I think it could be a great resource for anyone looking to do the same. If you’re interested in writing a BitTorrent app in REALBasic, or perhaps building BitTorrent capability into a game, etc…, this will take care of almost all the dirty work.

 

Copyright 2007 – J. Benjamin Gotow. You may reproduce this work however you want.