Author: alanmc
Date: 2007-06-24 00:45:12 -0400 (Sun, 24 Jun 2007)
New Revision: 80610

Modified:
   trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/StandardPicker.cs
Log:
cosmetic

Modified: trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/StandardPicker.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/StandardPicker.cs        
2007-06-24 04:40:32 UTC (rev 80609)
+++ trunk/bitsharp/src/MonoTorrent/Client/PiecePicking/StandardPicker.cs        
2007-06-24 04:45:12 UTC (rev 80610)
@@ -229,6 +229,97 @@
 
 
         /// <summary>
+        /// When picking a piece, request a new piece normally
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        private RequestMessage GetStandardRequest(PeerIdInternal id, 
PeerIdCollection otherPeers)
+        {
+            int bitfieldIndex = 0;
+            int checkIndex = 0;
+            RequestMessage message = null;
+            Priority highestPriorityFound = Priority.DoNotDownload;
+
+            Buffer.BlockCopy(this.myBitfield.Array, 0, bufferBitfield.Array, 
0, this.bufferBitfield.Array.Length * 4);
+            this.bufferBitfield.Not();
+
+            if (!id.Peer.IsSeeder)
+                this.bufferBitfield.AndFast(id.Peer.Connection.BitField);
+
+            Buffer.BlockCopy(this.bufferBitfield.Array, 0, 
this.previousBitfields[bitfieldIndex].Array, 0, 
this.bufferBitfield.Array.Length * 4);
+
+            // Out of the pieces the other peer has that we want, we look for 
the highest priority and store it here.
+            // We then keep NANDing the bitfield until we no longer have 
pieces with that priority. Then we can pick
+            // a piece from the "highest priority" available
+            highestPriorityFound = 
HighestPriorityAvailable(this.bufferBitfield);
+
+            // Nothing to download. This peer may still be interesting, but we 
may have set files to "DoNotDownload"
+            if (highestPriorityFound == Priority.DoNotDownload)
+                return null;
+            /*
+                        for (int i = 0; i < otherPeers.Count; i++)
+                        {
+                            lock (otherPeers[i])
+                            {
+                                if (otherPeers[i].Peer.Connection == null || 
otherPeers[i].Peer.IsSeeder)
+                                    continue;
+
+                                Buffer.BlockCopy(this.bufferBitfield.Array, 0, 
this.previousBitfield.Array, 0, this.bufferBitfield.Array.Length * 4);
+                                
this.bufferBitfield.AndFast(otherPeers[i].Peer.Connection.BitField);
+                                if (this.bufferBitfield.AllFalseSecure() || 
highestPriorityFound != HighestPriorityAvailable(this.bufferBitfield))
+                                    break;
+                            }
+                        }
+            */
+            // FIXME: The bitfield still contains pieces from files which are 
*not* the highest priority. Fix this.
+
+            // 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, this.myBitfield.Length);
+            int endIndex = this.myBitfield.Length;
+            checkIndex = midPoint;
+
+            // First we check all the places from midpoint -> end
+            // Then if we dont find anything we check from 0 -> midpoint
+            while ((checkIndex = 
this.previousBitfields[bitfieldIndex].FirstTrue(checkIndex, endIndex)) != -1)
+                if (AlreadyHaveOrRequested(checkIndex))
+                    checkIndex++;
+                else
+                    break;
+
+            if (checkIndex == -1)
+            {
+                checkIndex = 0;
+                while ((checkIndex = 
this.previousBitfields[bitfieldIndex].FirstTrue(checkIndex, midPoint)) != -1)
+                    if (AlreadyHaveOrRequested(checkIndex))
+                        checkIndex++;
+                    else
+                        break;
+            }
+
+            if (checkIndex == -1)
+                return null;
+
+            // Request the piece
+            else
+            {
+                message = this.GenerateRequest(id, checkIndex);
+                PieceCollection reqs = requests[id];
+                for (int i = 0; i < reqs.Count; i++)
+                {
+                    if (reqs[i].Index != checkIndex)
+                        continue;
+
+                    id.TorrentManager.PieceManager.RaiseBlockRequested(new 
BlockEventArgs(reqs[i].Blocks[0], reqs[i], id));
+                }
+
+                return message;
+            }
+        }
+
+
+        /// <summary>
         /// When picking a piece, attempt to request a piece that the peer has 
recommended that we download
         /// </summary>
         /// <param name="id"></param>
@@ -337,92 +428,7 @@
             }
         }
 
-        private RequestMessage GetStandardRequest(PeerIdInternal id, 
PeerIdCollection otherPeers)
-        {
-            int bitfieldIndex = 0;
-            int checkIndex = 0;
-            RequestMessage message = null;
-            Priority highestPriorityFound = Priority.DoNotDownload;
 
-            Buffer.BlockCopy(this.myBitfield.Array, 0, bufferBitfield.Array, 
0, this.bufferBitfield.Array.Length * 4);
-            this.bufferBitfield.Not();
-
-            if (!id.Peer.IsSeeder)
-                this.bufferBitfield.AndFast(id.Peer.Connection.BitField);
-
-            Buffer.BlockCopy(this.bufferBitfield.Array, 0, 
this.previousBitfields[bitfieldIndex].Array, 0, 
this.bufferBitfield.Array.Length * 4);
-
-            // Out of the pieces the other peer has that we want, we look for 
the highest priority and store it here.
-            // We then keep NANDing the bitfield until we no longer have 
pieces with that priority. Then we can pick
-            // a piece from the "highest priority" available
-            highestPriorityFound = 
HighestPriorityAvailable(this.bufferBitfield);
-
-            // Nothing to download. This peer may still be interesting, but we 
may have set files to "DoNotDownload"
-            if (highestPriorityFound == Priority.DoNotDownload)
-                return null;
-/*
-            for (int i = 0; i < otherPeers.Count; i++)
-            {
-                lock (otherPeers[i])
-                {
-                    if (otherPeers[i].Peer.Connection == null || 
otherPeers[i].Peer.IsSeeder)
-                        continue;
-
-                    Buffer.BlockCopy(this.bufferBitfield.Array, 0, 
this.previousBitfield.Array, 0, this.bufferBitfield.Array.Length * 4);
-                    
this.bufferBitfield.AndFast(otherPeers[i].Peer.Connection.BitField);
-                    if (this.bufferBitfield.AllFalseSecure() || 
highestPriorityFound != HighestPriorityAvailable(this.bufferBitfield))
-                        break;
-                }
-            }
-*/
-            // FIXME: The bitfield still contains pieces from files which are 
*not* the highest priority. Fix this.
-
-            // 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, this.myBitfield.Length);
-            int endIndex = this.myBitfield.Length;
-            checkIndex = midPoint;
-
-            // First we check all the places from midpoint -> end
-            // Then if we dont find anything we check from 0 -> midpoint
-            while ((checkIndex = 
this.previousBitfields[bitfieldIndex].FirstTrue(checkIndex, endIndex)) != -1)
-                if (AlreadyHaveOrRequested(checkIndex))
-                    checkIndex++;
-                else
-                    break;
-
-            if (checkIndex == -1)
-            {
-                checkIndex = 0;
-                while ((checkIndex = 
this.previousBitfields[bitfieldIndex].FirstTrue(checkIndex, midPoint)) != -1)
-                    if (AlreadyHaveOrRequested(checkIndex))
-                        checkIndex++;
-                    else
-                        break;
-            }
-
-            if (checkIndex == -1)
-                return null;
-
-            // Request the piece
-            else
-            {
-                message = this.GenerateRequest(id, checkIndex);
-                PieceCollection reqs = requests[id];
-                for (int i = 0; i < reqs.Count; i++)
-                {
-                    if (reqs[i].Index != checkIndex)
-                        continue;
-
-                    id.TorrentManager.PieceManager.RaiseBlockRequested(new 
BlockEventArgs(reqs[i].Blocks[0], reqs[i], id));
-                }
-
-                return message;
-            }
-        }
-
-
         /// <summary>
         /// Removes any outstanding requests from the supplied peer
         /// </summary>

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

Reply via email to