LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Listen Print Discuss Subscribe to Linux Subscribe to Newsletters

Distributing Content with BitTorrent
Pages: 1, 2, 3

Installing the torrent onto the web server

You need to make a minor addition to the web server's configuration settings to include the .torrent file extension as a new MIME type. Otherwise, the browser may attempt to read the torrent as a text file. If you're using Apache httpd, add the following to your httpd.conf file (and don't forget to restart the web server!):



AddType application/x-bittorrent .torrent

Upload the torrent to your web server. You can install a link on any of your web pages referring the torrent much in the same manner as you would for an ordinary HTML page:

<HTML>
<TITLE>Torrent Example</TITLE>
<BODY>
This is the <A
HREF="./pg_live1.3.3-SRA.iso.torrent">torrent</A>.
</BODY>
</HTML>

Setting up the tracker

Think of the tracker as the middleman to a financial transaction; he doesn't add anything to the product itself, but he makes it possible for both seller and the buyer to meet and carry out the transaction.

The Debian wrapper for the Python program bttrack.py is bttrack. This invocation puts the tracker on port 8090, recording all download activity in the file mydownloadlogfile.txt:

$ bttrack --dfile mydownloadlogfile.txt --port 8090

The switches control the logging information describing how to track the shared information. For further information, please refer to the source code or, in my case, the man pages, which the Debian distribution always includes.

Setting up the seed

The last piece of the puzzle is running the client itself. As I mentioned earlier, you need to run a client yourself if you are preparing to share a file for the first time; otherwise there will be no sharing. There are two kinds of command-line utilities that handle file sharing: single (btdownloadheadless.py) and multiple (btlaunchmany.py) file downloads. I will concentrate on the former.

The Debian command-line invocation is:

$ btdownloadheadless [ option ... ] torrent

The torrent can be either the URL or a file path. This invocation, used on my test platform, calls the torrent file directly from the web server. The --url switch refers to the torrent file, while the --saveas switch indicates the file path of the existing file I want to share with the world:

$ btdownloadheadless --url \
	http://localhost/pg_live.1.3.3-SRA.iso.torrent --saveas \
	./pg_live.1.3.3-SRA.iso

The client now connects with the tracker, informing it that it is ready to share a copy of pg_live.1.3.3-SRA.iso.

Here's another client invocation that I could have used. This looks for the torrent file on the client's own machine located in the current directory:

$ btdownloadheadless --saveas ./pg_live.1.3.3-SRA.iso \
	pg_live.1.3.3-SRA.iso.torrent

The client connects to the tracker, where it will synchronize its data. The larger the file, the longer it takes. My test machine took about two minutes before the sync completed. Here's a sample of the messages:

saving:         pg_live.1.3.3-SRAA.iso (382.6 MB)
percent done:   100
time left:      Download Succeeded!
download to:    /home/robert/tmp/pg_live.1.3.3-SRAA.iso
upload rate:    0.00 kB/s
upload total:   0.0 MiB

Optimizing BitTorrent

BitTorrent has an amazing amount of flexibility. You can control upload and download bandwidths, the ports you use for socket connections, the number of connecting clients, and the refresh rate reflecting changed or new torrents that become available on the tracker. You can even configure the system to take into account clients who are behind firewalls.

This next section covers only some of the neat tricks that you can use with BitTorrent. Refer to the BitTorrent documentation for a complete listing of what you can do.

Stats reporting from the tracker

Getting tracker statistics from my tracker is easy. I just direct my browser to the tracker's port, http://localhost:8099. The resulting HTML page returns data similar to:

BitTorrent download info

* tracker version: 3.4.2
* server time: 2005-03-29 13:50 UTC

               info hash                 complete downloading downloaded
4e98ea442573f5b8868537e970fd3ce6321e9e81        1           0          0
                                   0 files      1/1         0/0        0/0
                                                           
* info hash: SHA1 hash of the "info" section of the metainfo (*.torrent)
* complete: number of connected clients with the complete file 
  (total: unique IPs/total connections)
* downloading: number of connected clients still downloading 
  (total: unique IPs/total connections)
* downloaded: reported complete downloads (total: current/all)
* transferred: torrent size * total downloaded 
  (does not include partial transfers)

Pages: 1, 2, 3

Next Pagearrow




Tagged Articles

Post to del.icio.us

This article has been tagged:

linux

Articles that share the tag linux:

Managing Disk Space with LVM (74 tags)

Use Your Digital Camera with Linux (60 tags)

mdadm: A New Tool For Linux Software RAID Management (59 tags)

Asterisk: A Bare-Bones VoIP Example (43 tags)

View All

p2p

Articles that share the tag p2p:

Piracy is Progressive Taxation, and Other Thoughts on the Evolution of Online Distribution (23 tags)

Next-Generation File Sharing with Social Networks (18 tags)

Remixing Culture: An Interview with Lawrence Lessig (13 tags)

Swarm Intelligence: An Interview with Eric Bonabeau (12 tags)

Anonymous, Open Source P2P with MUTE (11 tags)

View All

bittorrent

Articles that share the tag bittorrent:

Distributing Content with BitTorrent (6 tags)

It Doesn't Pay to be Popular (4 tags)

BitTorrent Style (2 tags)

View All

sharing

Articles that share the tag sharing:

Inside Samba: Windows Sharing for the Mac (18 tags)

Anonymous, Open Source P2P with MUTE (3 tags)

Distributing Content with BitTorrent (3 tags)

Windows XP File Sharing Mysteries: Part 1 (3 tags)

Next-Generation File Sharing with Social Networks (2 tags)

View All

toread

Articles that share the tag toread:

What Is Web 2.0 (283 tags)

Ajax on Rails (36 tags)

Very Dynamic Web Interfaces (32 tags)

Rolling with Ruby on Rails (29 tags)

Calculating the True Price of Software (22 tags)

View All

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com