Thursday, September 20, 2007

BitTorrent Content for Apple TV, Pt. 1

In Apple TV: Getting Content I talked about how BitTorrent technology can be used to exchange Apple TV and other content with other Internet users. Now I'd like to extend those remarks in a series of posts about exactly how that is done.

In the earlier post I said BitTorrent is

a peer-to-peer file sharing (P2P) protocol for distributing large amounts of data widely across cyberspace in a decentralized way. The general idea is that every file — movie or otherwise — is divided up into many, many, many tiny pieces, every one of which can be redundantly stored in different computers on the Internet. The pieces can be downloaded all at a time, in no particular sequence, from any of these locations. The BitTorrent client software that you run on your computer finds a source computer for each piece, downloads all the pieces one by one, and assembles them in their proper order to make a single file on your hard drive which is exactly like the original file.

All that still goes, but I should note that a lot of people don't think of BitTorrent as P2P, since it does things so much differently than earlier P2P methodologies such as LimeWire and KaZaA. For one thing, those earlier technologies didn't break files into pieces to be obtained from multiple sources.

Also, BitTorrent as a protocol for sharing files needs to be distinguished from BitTorrent as one of several available software clients that you can download and use to do file sharing, via the BitTorrent protocol, on the Internet. (That particular client is sometimes referred to as "the Official BitTorrent Client," or OBTC. There are other clients which in my humble opinion are better, such as Azureus. I'll talk about Azureus and some of the others in later posts.)

Furthermore, there is the official BitTorrent website, where the Official BitTorrent Client can be obtained, along with many (legal) torrent files.

And another thing: when we talk about sharing a file as a "torrent," what we really mean is that we are sharing either one individual computer file or a folder/directory containing one or more individual files. Torrents can include multiple files.

For example, a particular torrent may contain, in a single folder: a movie file, in perhaps the .avi format; one or more subtitle files in various languages, which the user may optionally apply to the movie; and perhaps a .jpg file showing DVD cover art for the movie.

(Notice that I used an .avi file as an example of a typical movie torrent's content. That was because a large proportion of movies available in the BitTorrent universe use that file format ... which does not happen to work in iTunes or Apple TV. In Apple TV: Getting Content I talked about that problem, along with some ways to deal with it by converting the .avi files to an iTunes-compatible format. I'll talk more about that concern in future posts.)

That word, "torrent," is a bit ambiguous. It can refer to the data file (or folder of many files) which is the ultimate target of the BitTorrent client. It can refer to a special file called a "torrent file" which describes the target file or folder; this so-called torrent file, which is small, contains "metadata" about the "target file," which is typically big. Or the word "torrent" can simply refer to the whole package, the target data and the metadata.

In order to download a torrent data file, also known as the target file (or folder), you first have to obtain the torrent file — the small file with metadata in it. The way you usually do that is to go to either a torrent search site on the Web or a torrent "tracker site" — more later on what a "tracker" is — find a torrent for (let us say) a movie you want to download, and download that in the "ordinary" way: click on a "Download" hotlink/button in your browser, at which point your browser will do it's customary downloading thing.

Once a copy of the torrent file is present on your desktop (or wherever you put it when you downloaded it), you simply open it in your favorite BitTorrent client software.

When you open the torrent file, the client will probably ask you where on your hard drive you intend to put the downloaded torrent target file it is about to create. Alternatively, the client may have a fixed place into which it is set up to put all its downloads. Chances are, depending on the client, you can select which of those two behavior patterns you prefer. You do this in the client's Preferences/Options. If you select to download to a fixed automatic location, you can also choose the exact location you want while you are in the client's Preferences/Options.

If all goes well, the client will then at this point do some stuff behind the scenes. Then, after a brief delay, you will see the client give you some indication that downloading has successfully begun. (If that doesn't happen pretty quickly, something is wrong. I'll talk about what may be amiss in a later post. But for now, keep in mind that some torrents aren't very popular and for that reason download slowly. If the first torrent you try is balky, try some others.)

What has actually happened when you open a torrent file? Put simply, when you open the torrent file in a BitTorrent client, the client arranges for you to join the "swarm" of "peers" all trying to download the same torrent!

That is, all the peers — in file-sharing protocols, "peers" are treated as equals — are after the same target data file or folder. Each peer presumably has some but not all of the pieces of the target. When you open the torrent metadata file, your client reads it and announces your presence to a "tracker" whose URL is contained therein.

This tracker is software running on a Web server, somewhere on the Internet. When your client announces that you have opened the torrent file, the tracker sends back current information about the "swarm" of peers for that torrent. Specifically, it tells you client what other peers are in the swarm and what the IP (Internet Protocol) address of each is. It's then up to your client to connect to the client software running on the other peers' computers.

When a connection is made by your client with a certain peer, your client and the peer's client exchange information about which pieces of the torrent each already has. When you open a torrent file for the first time, obviously you have yet to possess any of the pieces, so the respective BitTorrent clients treat that as a special situation, in order that you can get started downloading the torrent.

More generally, each peer you connect to will expect you to have some of the pieces it wants and will expect itself to have some of the pieces you want. The two clients will negotiate an exchange.

Notice that once you have downloaded some of the pieces of the torrent, you can expect peers you have yet to initiate contact with to initiate contact with you — that is, with your BitTorrent client. It is simply the mirror image of the process just described, except that it is initiated by one or more remote peers rather than by your "local" client.

Very quickly, as you can see, what you began as a download turns into an upload as well. No matter whether the other peer — the second peer— initiated the connection or you did, torrent pieces you have obtained elsewhere (i.e., from yet other peers) typically will start flying up to that second peer — or, rather, to any number of remote peers.

In fact, the BitTorrent protocol is implemented in such a way that if for any reason your client is not uploading pieces at a decent clip, other clients will "choke" their download speeds to you. Mark that well. If you want decent download speeds, you need to insure decent upload speeds.

Assume you have just begun downloading a torrent. Now it's a matter of waiting for the download to complete. Depending on any number of factors, that can take as little as two or three hours, for a full-length movie, to as much as several days.

Naturally, you want your download to go as fast as possible. One of the things I want to cover in the next post in this series has to do with avoiding a common mistake that can limit download (and upload) speeds. Hint: it has to do with making sure your client is using an "open port."

Using an open port requires that you open a particular "port number" — one of your choosing — and to tell your client what it is. Opening a port number involves, first of all, telling your computer's firewall not to screen out incoming traffic on that network port.

If your computer is "behind" a router on a local area network in your home or office, you also have to "port forward" the chosen port number from the router to your computer.

If the router also has a firewall, you have to open the port number on the router.

More about opening ports next time ...

No comments: