BitMaster – Yet another Mac torrent client…

Over the last few years I’ve been teaching myself how to program. Little programs like ultrawar were my first complete programs, but I’ve read and learned a lot since then. I’ve been working on a BitTorrent client for the last few years, mostly as a learning exercise but also with the goal of a real client at the end. I know Mac OS X doesn’t really need another torrent client, since Transmission rules and even the mighty uTorrent has a Mac version now. But I wondered what a client that focused solely on Mac technologies would look like, whether it could be any better than those that strive to live across platforms. So I’ve created BitMaster. Eventually it will be open source from this site, but it’s still in a very prototype stage (I can only read and parse torrent files, hash downloads, and create torrent files), so I’ll be posting code excerpts for now. It’s my hope that having public eyes on the project will help me learn to code and to actually release something, rather than playing with it whenever I’m in the mood. So here’s my first bit of code for public scrutiny: my torrent file parsing code.

Obviously, when I first sat down to develop BitMaster I had to determine what functionality I needed first. I chose torrent file parsing, since it seemed like a simple and ubiquitous part of torrent client development. You can see my first attempt a this code in my previous entry “Learning through doing…” which is quite rough. After feedback from various people online, it now looks like this:

This code is much faster, cleaner, and accurate than the previous attempt. But it’s still inelegant in a lot of ways. For example, I store the torrent file data within both an NSData object (for the subdata* methods) and a char array (so I can access individual characters to iterate over). Surely there must be a better way, I just haven’t found it. For a few of my methods, there must be a better way of converting to an NSNumber object than getting a subdata, making it a string, and making the string a number. Seems quite obtuse compared to the conversions I’ve seen in other languages.

Well, that’s all for now. I’ll try to get this post out and around so I can get feed back, so feel free to leave comments.