Author: alanmc
Date: 2007-03-14 18:50:33 -0500 (Wed, 14 Mar 2007)
New Revision: 74314

Modified:
   trunk/bitsharp/src/MonoTorrent.Client/PeerMessages/HandshakeMessage.cs
Log:
Updated to add an extra check to make sure that the protocol string sent in the 
handshake is correct

Modified: trunk/bitsharp/src/MonoTorrent.Client/PeerMessages/HandshakeMessage.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/PeerMessages/HandshakeMessage.cs      
2007-03-14 23:31:29 UTC (rev 74313)
+++ trunk/bitsharp/src/MonoTorrent.Client/PeerMessages/HandshakeMessage.cs      
2007-03-14 23:50:33 UTC (rev 74314)
@@ -211,7 +211,14 @@
 
         internal void Handle(PeerConnectionID id)
         {
-            // If we got the peer as a "compact" peer, then the peerid will be 
empty
+            if (!this.protocolString.Equals(VersionInfo.ProtocolStringV100))
+            {
+                Logger.Log(id, "Invalid protocol string: " + 
this.protocolString);
+                throw new ProtocolException("Invalid protocol string");
+            }
+
+            // If we got the peer as a "compact" peer, then the peerid will be 
empty. In this case
+            // we just copy the one that is in the handshake. 
             if (string.IsNullOrEmpty(id.Peer.PeerId))
                 id.Peer.PeerId = this.peerId;
 
@@ -222,13 +229,14 @@
                 throw new TorrentException("Invalid infohash. Not tracking 
this torrent");
             }
 
-            // If the peer id's don't match, dump the connection
+            // If the peer id's don't match, dump the connection. This is due 
to peers faking usually
             if (id.Peer.PeerId != this.peerId)
             {
                 Logger.Log(id, "Invalid peerid");
                 throw new TorrentException("Supplied PeerID didn't match the 
one the tracker gave us");
             }
 
+            // Attempt to parse the application that the peer is using
             id.Peer.Connection.ClientApp = new PeerID(this.peerId);
             id.Peer.Connection.SupportsFastPeer = this.supportsFastPeer;
 

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

Reply via email to