Author: alanmc
Date: 2007-12-21 10:33:28 -0500 (Fri, 21 Dec 2007)
New Revision: 91766
Modified:
trunk/bitsharp/src/MonoTorrent/Tracker/SimpleTorrentManager.cs
Log:
Added IPAddress comparer for peers
Modified: trunk/bitsharp/src/MonoTorrent/Tracker/SimpleTorrentManager.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Tracker/SimpleTorrentManager.cs
2007-12-21 15:27:50 UTC (rev 91765)
+++ trunk/bitsharp/src/MonoTorrent/Tracker/SimpleTorrentManager.cs
2007-12-21 15:33:28 UTC (rev 91766)
@@ -39,6 +39,19 @@
namespace MonoTorrent.Tracker
{
+ public class IPAddressComparer : IEqualityComparer<Peer>
+ {
+ public bool Equals(Peer left, Peer right)
+ {
+ return left.ClientAddress.Equals(right.ClientAddress);
+ }
+
+ public int GetHashCode(Peer peer)
+ {
+ return peer.ClientAddress.GetHashCode();
+ }
+ }
+
///<summary>
///This class is a TorrentManager which uses .Net Generics datastructures,
such
///as Dictionary and List to manage Peers from a Torrent.
@@ -108,9 +121,15 @@
#region Constructors
public SimpleTorrentManager(ITrackable trackable)
+ : this(trackable, new IPAddressComparer())
{
+
+ }
+
+ public SimpleTorrentManager(ITrackable trackable,
IEqualityComparer<Peer> comparer)
+ {
this.trackable = trackable;
- peers = new Dictionary<IPAddress, Peer>();
+ peers = new Dictionary<IPAddress, Peer>(comparer);
random = new Random();
}
@@ -232,4 +251,3 @@
#endregion Methods
}
}
-
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches