Author: alanmc
Date: 2007-08-22 23:49:28 -0400 (Wed, 22 Aug 2007)
New Revision: 84675

Modified:
   trunk/bitsharp/src/MonoTorrent/Client/Managers/PieceManager.cs
   trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/PiecePickerBase.cs
   trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/StandardPicker.cs
Log:
Now offering Linear piece picking as a runtime changeable option in 
PieceManager. useful for streaming

Modified: trunk/bitsharp/src/MonoTorrent/Client/Managers/PieceManager.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Client/Managers/PieceManager.cs      
2007-08-23 00:30:30 UTC (rev 84674)
+++ trunk/bitsharp/src/MonoTorrent/Client/Managers/PieceManager.cs      
2007-08-23 03:49:28 UTC (rev 84675)
@@ -62,15 +62,36 @@
 
 
         #region Member Variables
+
+        private bool linearPickingEnabled;
         private PiecePickerBase piecePicker;
+
         #endregion
 
 
+        #region Properties
+
+        /// <summary>
+        /// This option changes the picking algorithm from rarest first to 
linear. This should
+        /// only be enabled if the content being downloaded is streaming 
audio/video. It degrades
+        /// overall performance of the swarm.
+        /// </summary>
+        public bool LinearPickingEnabled
+        {
+            get { return piecePicker.LinearPickingEnabled; }
+            set { piecePicker.LinearPickingEnabled = value; }
+        }
+
+        #endregion Properties
+
+
         #region Constructors
+
         internal PieceManager(BitField bitfield, TorrentFile[] files)
         {
             this.piecePicker = new StandardPicker(bitfield, files);
         }
+
         #endregion
 
 

Modified: trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/PiecePickerBase.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/PiecePickerBase.cs       
2007-08-23 00:30:30 UTC (rev 84674)
+++ trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/PiecePickerBase.cs       
2007-08-23 03:49:28 UTC (rev 84675)
@@ -40,6 +40,7 @@
         #region Private Fields
 
         protected BitField myBitfield;
+        private bool linearPickingEnabled;
 
         #endregion Private Fields
 
@@ -53,6 +54,11 @@
             get { return this.myBitfield; }
         }
 
+        public bool LinearPickingEnabled
+        {
+            get { return linearPickingEnabled; }
+            set { linearPickingEnabled = value; }
+        }
         #endregion Properties
 
         #region Abstract Methods

Modified: trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/StandardPicker.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/StandardPicker.cs        
2007-08-23 00:30:30 UTC (rev 84674)
+++ trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/StandardPicker.cs        
2007-08-23 03:49:28 UTC (rev 84675)
@@ -59,6 +59,7 @@
 
         #endregion Member Variables
 
+
         #region Properties
 
         /// <summary>
@@ -271,8 +272,8 @@
 
                     // When picking the piece, we start at a random index and 
then scan forwards to select the first available piece.
                     // If none is found, we scan from the start up until that 
random index. If nothing is found, the peer is actually
-                    // uninteresting.
-                    int midPoint = random.Next(0, current.Length);
+                    // uninteresting. If we're doing linear searching, then 
the start index is 0.
+                    int midPoint = LinearPickingEnabled ? 0 : random.Next(0, 
current.Length);
                     int endIndex = current.Length;
                     checkIndex = midPoint;
 
@@ -353,6 +354,10 @@
                 // Store this bitfield as the first iteration of the Rarest 
First algorithm.
                 bitfields.Push(current);
 
+                // If we're doing linear picking, then we don't want to 
calculate the rarest pieces
+                if (base.LinearPickingEnabled)
+                    return bitfields;
+
                 // Get a cloned copy of the bitfield and begin iterating to 
find the rarest pieces
                 current = 
ClientEngine.BufferManager.GetClonedBitfield(current);
 

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

Reply via email to