Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When I started answering your question, I didn't realize you were asking how the magnet scheme works. Just thought you wanted to know how the parts relevant to the bittorrent protocol were generated.</p> <hr> <p>The hash listed in the magnet uri is the torrent's info hash encoded in base32. The info hash is the sha1 hash of the bencoded info block of the torrent.</p> <p>This <a href="http://osdir.com/ml/network.bit-torrent.general/2002-11/msg00023.html" rel="nofollow">python code</a> demonstrates how it can be calculated.</p> <p>I wrote a (very naive) C# implementation to test this out since I didn't have a bencoder on hand and it matches what is expected from the client.</p> <pre class="lang-c# prettyprint-override"><code>static string CalculateInfoHash(string path) { // assumes info block is last entry in dictionary var infokey = "e4:info"; var offset = File.ReadAllText(path).IndexOf(infokey) + infokey.Length; byte[] fileHash = File.ReadAllBytes(path).Skip(offset).ToArray(); byte[] bytes; using (SHA1 sha1 = SHA1.Create()) bytes = sha1.ComputeHash(fileHash, 0, fileHash.Length - 1); // need to remove last 'e' to compensate for bencoding return String.Join("", bytes.Select(b =&gt; b.ToString("X2"))); } </code></pre> <p>As I understand it, this hash does not include any information on how to locate the tracker, the client needs to find this out through other means (the announce url provided). This is just what distinguishes one torrent from another on the tracker.</p> <p><em>Everything</em> related to the bittorrent protocol still revolves around the tracker. It is still the primary means of communication among the swarm. The magnet uri scheme was not designed specifically for use by bittorrent. It's used by any P2P protocols as an alternative form of communicating. Bittorrent clients adapted to accept magnet links as another way to identify torrents that way you don't need to download .torrent files anymore. The magnet uri still needs to specify the <code>tr</code>acker in order to locate it so the client may participate. It can contain information about other protocols but is irrelevant to the bittorrent protocol. The bittorrent protocol ultimately will not work without the trackers.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload