Author: alanmc
Date: 2007-11-20 19:09:34 -0500 (Tue, 20 Nov 2007)
New Revision: 90053

Modified:
   trunk/bitsharp/src/MonoTorrent/Client/Tracker.cs
Log:
Feature: Implemented the 'key' property. This is used in some trackers as a 
kind of password.

Modified: trunk/bitsharp/src/MonoTorrent/Client/Tracker.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Client/Tracker.cs    2007-11-21 00:03:37 UTC 
(rev 90052)
+++ trunk/bitsharp/src/MonoTorrent/Client/Tracker.cs    2007-11-21 00:09:34 UTC 
(rev 90053)
@@ -42,9 +42,12 @@
     /// </summary>
     public class Tracker
     {
+        private static Random random = new Random();
+
         #region Member Variables
         private AsyncCallback announceCallback;
         private AsyncCallback scrapeCallback;
+        private readonly string key;
 
 
         /// <summary>
@@ -208,6 +211,10 @@
             int indexOfAnnounce = announceUrl.LastIndexOf('/') + 1;
             this.warningMessage = string.Empty;
             this.failureMessage = string.Empty;
+            byte[] passwordKey = new byte[8];
+            lock (random)
+                random.NextBytes(passwordKey);
+            this.key = HttpUtility.UrlEncode(passwordKey);
 
             if ((indexOfAnnounce + 8) <= announceUrl.Length && 
announceUrl.Substring(indexOfAnnounce, 8) == "announce")
             {
@@ -273,6 +280,8 @@
             sb.Append("&compact=1");    // Always use compact response
             sb.Append("&numwant=");
             sb.Append(100);
+            sb.Append("&key=");  // The 'key' protocol, used as a kind of 
'password'. Must be the same between announces
+            sb.Append(key);
             if (ipaddress != null)
             {
                 sb.Append("&ip=");

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to