Learning Through Doing

In an effort to teach myself Objective-C and the Cocoa framework, I’ve decided to create a Cocoa BitTorrent client. So far I’m able to parse torrent files (most of the time), hash the file to be downloaded (if it’s already downloaded) and the info dictionary string (big hack), and both scrape and get torrent specific data from trackers. Once this program can actually download a file from a torrent I’ll release the source code under an open source license (likely the Apache license). In the meantime, I’m going to be using whatever resources I can find. That includes IRC channels frequented by various Mac projects (#webkit, #transmission, etc) on irc.freenode.net (which may be how you got here). From time to time I’m going to post some of my code on this blog so I can get feedback from various parties on fixing bugs or implementing features. That’s what this post in about.

Currently, I can parse .torrent files pretty successfully. By turning them into NSDictionary’s I can access their contents very easily. However, I’m not 100% successful yet. Strangely, some torrents, like this one, don’t parse successfully, breaking my later code. It seems as if the contents of the comment and name keys in the file aren’t decoding correctly as UTF8 strings, so the data put into those keys is incorrect. I can’t figure out why that is. I suspect it has something to do with the findBlockRangeAtIndex: method. Here’s the code:

I know it’s rough and fragile, but anything you can suggest will help. If you want more info on the BitTorrent specification this is the best resource I could find.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">