Author: alanmc
Date: 2006-09-17 08:26:27 -0400 (Sun, 17 Sep 2006)
New Revision: 65534
Modified:
trunk/bitsharp/src/MonoTorrent.Client/AllowedFastAlgorithm.cs
trunk/bitsharp/src/MonoTorrent.Client/Tests/AllowedFastAlgorithmTest.cs
Log:
Removed hardcoded value that was accidently left in. Now passed in via parameter
Modified: trunk/bitsharp/src/MonoTorrent.Client/AllowedFastAlgorithm.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/AllowedFastAlgorithm.cs
2006-09-17 11:49:00 UTC (rev 65533)
+++ trunk/bitsharp/src/MonoTorrent.Client/AllowedFastAlgorithm.cs
2006-09-17 12:26:27 UTC (rev 65534)
@@ -15,7 +15,7 @@
public const int AllowedFastPieceCount = 10;
private static SHA1Managed hasher = new SHA1Managed();
- public static UInt32[] Calculate(byte[] addressBytes, byte[]
infohash, int numberOfResults)
+ public static UInt32[] Calculate(byte[] addressBytes, byte[]
infohash, int numberOfResults, UInt32 numberOfPieces)
{
byte[] hashBuffer = new byte[24]; // The hash buffer to be used
in hashing
uint[] results = new uint[numberOfResults]; // The results array
which will be returned
@@ -45,7 +45,7 @@
for (int i = 0; i < 20; i += 4)
{
UInt32 result =
(UInt32)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(hashBuffer, i));
- results[j++] = result % 1313;
+ results[j++] = result % numberOfPieces;
if (j == results.Length)
return results;
}
Modified:
trunk/bitsharp/src/MonoTorrent.Client/Tests/AllowedFastAlgorithmTest.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/Tests/AllowedFastAlgorithmTest.cs
2006-09-17 11:49:00 UTC (rev 65533)
+++ trunk/bitsharp/src/MonoTorrent.Client/Tests/AllowedFastAlgorithmTest.cs
2006-09-17 12:26:27 UTC (rev 65534)
@@ -19,7 +19,7 @@
for (int i = 0; i < infohash.Length; i++)
infohash[i] = (byte)170;
- UInt32[] results =
AllowedFastAlgorithm.Calculate(endpoint.Address.GetAddressBytes(), infohash, 9);
+ UInt32[] results =
AllowedFastAlgorithm.Calculate(endpoint.Address.GetAddressBytes(), infohash, 9,
(UInt32)1313);
Assert.AreEqual(1059, results[0]);
Assert.AreEqual(431, results[1]);
Assert.AreEqual(808, results[2]);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches