<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.simplicity &#187; Django</title>
	<atom:link href="http://www.dotsimplicity.net/tag/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotsimplicity.net</link>
	<description>Simple, reliable, simplicity. A software discussion blog</description>
	<lastBuildDate>Sun, 04 Jul 2010 09:44:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Experiment: Django Distributed BitTorrent Tracker (DDBTT)</title>
		<link>http://www.dotsimplicity.net/2009/03/experiment-django-distributed-bittorrent-tracker-ddbtt/</link>
		<comments>http://www.dotsimplicity.net/2009/03/experiment-django-distributed-bittorrent-tracker-ddbtt/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 15:25:13 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.dotsimplicity.net/?p=163</guid>
		<description><![CDATA[After publishing my previous post about Django I decided to try something more complex. The idea was to create a Django Distributed BitTorrent Tracker.
The BitTorrent protocol is a peer-to-peer file sharing protocol. The main advantage of the BitTorrent protocol over plain HTTP is that when a file is downloaded by multiple people, the downloaders will [...]]]></description>
			<content:encoded><![CDATA[<p>After publishing my <a href="http://www.dotsimplicity.net/?p=152">previous post</a> about Django I decided to try something more complex. The idea was to create a Django Distributed BitTorrent Tracker.</p>
<p>The BitTorrent protocol is a peer-to-peer file sharing protocol. The main advantage of the BitTorrent protocol over plain HTTP is that when a file is downloaded by multiple people, the downloaders will upload the data to each other. As a result hardware and bandwidth loads are significantly reduced. One of the main components of this protocol is the BitTorrent tracker. The tracker is responsible for coordinating the file distribution. To achieve this the tracker collects data of torrents and their seeders (uploaders) and leechers (downloaders). This data is then shared with BitTorrent clients that connect with the tracker. From there on the clients are on their own when it comes to making decisions.</p>
<p>One of the features of the BitTorrent tracker is the ability to add new torrents at any given time. But what if you want your tracker to keep track of only your torrents? What if you don&#8217;t want to become the next Pirate Bay? The answer is quite simple. You would have to disable the tracker&#8217;s ability to add external torrents. But by doing so, you too won&#8217;t be able to add torrents. This means that you would have to implement an interface to add torrents internally. If your tracker is database-driven this shouldn&#8217;t be very hard to do; you only have to add a new entry (assuming you&#8217;ve a table of torrents) to your database.</p>
<p>Okay, so your tracker only accepts internal torrents. Lets move on to the next problem. What if there aren&#8217;t any seeders available to distribute my file? Again, the answer is simple. You would have to implement HTTP seeding. HTTP seeding allows BitTorrent clients to download torrent pieces from an HTTP source in addition to the peers. Even though HTTP seeding is a client affair, I think the server can play a significant role. After all, the HTTP torrent pieces have to hosted somewhere.</p>
<p>If you combine these two ideas you get something along lines of this:</p>
<ul>
<li>Uploading:
<ul>
<li> File is uploaded to the webserver;</li>
</ul>
<ul>
<li> Torrent meta data file (.torrent) is generated;
<ul>
<li> Don&#8217;t forget to generate a 20 byte sha1 hash for the torrent.</li>
</ul>
</li>
</ul>
<ul>
<li> Torrent is exposed to the webserver;</li>
</ul>
</li>
<li>Downloading:
<ul>
<li> Peer downloads the torrent meta data file;</li>
</ul>
<ul>
<li> Peer&#8217;s BitTorrent client downloads data from peers and webserver;</li>
</ul>
</li>
</ul>
<p>As you can see the concept is fairly easy. The implementation should be too hard either. The BitTorrent protocol is largely based upon plain HTTP. Clients send data to the tracker with HTTP GET variables and trackers send data back by outputting data (bencoded). Having said that, I didn&#8217;t finish my implementation of the Django Distributed BitTorrent Tracker. The reason for this is that I came across some bugs. Normally I would take my time to get rid of them, but currently I&#8217;m a bit short on time. Not only am I involved in multiple projects, but I also have to practice for my final examinations.</p>
<p>Even though I didn&#8217;t finish the implementation of the concept I&#8217;m content with this project. I really enjoyed working on this project. I&#8217;ve learned a lot about peer-to-peer (P2P). I was really amazed by the simplicity of the BitTorrent protocol.</p>
<p>If you would like to implement your own BitTorrent tracker or if you just want to know more about it then check out these sites:<br />
<a href="http://en.wikipedia.org/wiki/BitTorrent_(protocol)">Wikipedia &#8211; BitTorrent (protocol)</a><br />
<a href="http://www.bittorrent.org/beps/bep_0003.html">Official BitTorrent specification</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotsimplicity.net/2009/03/experiment-django-distributed-bittorrent-tracker-ddbtt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django</title>
		<link>http://www.dotsimplicity.net/2009/03/django/</link>
		<comments>http://www.dotsimplicity.net/2009/03/django/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 18:54:48 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.dotsimplicity.net/?p=152</guid>
		<description><![CDATA[Lately I&#8217;ve been experimenting with Django. Django is a web framework written in the popular Python language. Python wasn&#8217;t exactly written with web development in mind as far as I know. As a result web development with Django is different than with something like PHP or ASP. That isn&#8217;t a bad thing, though. Lets say [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been experimenting with <a href="http://www.djangoproject.com/">Django</a>. Django is a web framework written in the popular <a href="http://www.python.org/">Python</a> language. Python wasn&#8217;t exactly written with web development in mind as far as I know. As a result web development with Django is different than with something like PHP or ASP. That isn&#8217;t a bad thing, though. Lets say that I&#8217;ve never developed web applications as fast as I&#8217;m doing now.</p>
<p>The main reason why web development with Django is so quick, is because Django takes care of some annoying jobs. It&#8217;s a case of the DRY (Don&#8217;t Repeat Yourself) principle:</p>
<p><em>Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.</em></p>
<p><span id="more-152"></span></p>
<p>A fine example of this is Django&#8217;s dynamic database-access API. The API is completely OOP-based. With Django you can define your SQL tables with Python classes. And as soon as you expose that class to Django an appropriate SQL table is created. Besides that Django also takes care of creating new table entries, editing table entries and querying tables. This can be all done through Django&#8217;s Python API. But what I really love about Django&#8217;s database-access API is the relative ease of defining relations between different tables and their entries. When I started with plain MySQL I was shocked to see that it wasn&#8217;t possible to have nested objects (table entries). Django doesn&#8217;t support this feature either, but it&#8217;s a whole lot easier to link tables. And raw SQL lovers don&#8217;t have to worry, because Django also provides ways to access the database data with raw SQL queries. But maybe it&#8217;s more interesting to show some Django code:</p>
<pre class="brush: python;">
from django.db import models
from django.contrib.auth.models import User

# Project class
class Project(models.Model):
   name = models.CharField(max_length=30)
   name_unix = models.CharField(max_length=30)

   description = models.TextField()
   tech_description = models.TextField()

   admins = models.ManyToManyField(User, related_name='admins')
   developers = models.ManyToManyField(User, related_name='developers')

   date_activity = models.DateField(auto_now=False, auto_now_add=False)
   data_registered = models.DateField(auto_now=False, auto_now_add=False)

# Project Subgrouping
# The following classes represent the sub-groups a project can be divided in.

# Genre class
class Genre(models.Model):
   # General genre fields.
   name = models.CharField(max_length=30)
   name_unix = models.CharField(max_length=30)
   description = models.TextField()

   # Projects that are part of the genre.
   projects = models.ManyToManyField(Project)

...

# Project Subgrouping - END
</pre>
<p>The above piece of code creates defines two classes: Project and Genre. In this situation a relation is created between the two with a so-called ManyToManyField. Thanks to this Project can access Genre objects and vice versa. This can be useful when a project wants to show to which genres it belongs. And the genres itself can keep track of the projects that are part of themselves.</p>
<p>Another thing I really like about Django is the emphasis on modularity. You build your site by creating the building blocks individually. So, if you change one block another shouldn&#8217;t be affected. Besides that code and data (output) is clearly separated. I really admire this choice as this makes it easier to manage large applications. And a lack of modularity can be a real killer.</p>
<p>Also, according to <a href="http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&amp;lang=python&amp;lang2=php&amp;box=1">this benchmark</a> Python is somewhat faster than PHP. So performance shouldn&#8217;t be a relative big problem.</p>
<p>But that&#8217;s all for now. So far Django is fulfilling its promise: to make it easier to build better web apps quickly and with less code. Anyway, I hope you enjoyed reading this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotsimplicity.net/2009/03/django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

