Author: alanmc
Date: 2007-02-11 11:53:05 -0500 (Sun, 11 Feb 2007)
New Revision: 72622

Modified:
   trunk/bitsharp/src/MonoTorrent.Client/PiecePicking/StandardPicker.cs
Log:
Bugfix for RequestFastPiece. Now only requesting a fast piece if the peer 
actually has that piece.

Modified: trunk/bitsharp/src/MonoTorrent.Client/PiecePicking/StandardPicker.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/PiecePicking/StandardPicker.cs        
2007-02-11 16:33:03 UTC (rev 72621)
+++ trunk/bitsharp/src/MonoTorrent.Client/PiecePicking/StandardPicker.cs        
2007-02-11 16:53:05 UTC (rev 72622)
@@ -204,13 +204,18 @@
                     continue;
                 }
 
-                // If we have no suggested pieces left, break out
-                if (id.Peer.Connection.IsAllowedFastPieces.Count == 0)
-                    return null;
-
-                requestIndex = (int)id.Peer.Connection.IsAllowedFastPieces[0];
-                id.Peer.Connection.IsAllowedFastPieces.RemoveAt(0);
-                return this.GenerateRequest(id, requestIndex);
+                // For all the remaining fast pieces
+                for (int i = 0; i < 
id.Peer.Connection.IsAllowedFastPieces.Count; i++)
+                {
+                    // If the peer has this piece
+                    if 
(id.Peer.Connection.BitField[(int)id.Peer.Connection.IsAllowedFastPieces[i]])
+                    {
+                        // We request that piece and remove it from the list
+                        requestIndex = 
(int)id.Peer.Connection.IsAllowedFastPieces[i];
+                        id.Peer.Connection.IsAllowedFastPieces.RemoveAt(i);
+                        return this.GenerateRequest(id, requestIndex);
+                    }
+                }
             }
 
             return null;

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

Reply via email to