Skip to content

Commit

Permalink
Do not try to connect to ourselves as a peer.
Browse files Browse the repository at this point in the history
  • Loading branch information
samhocevar committed Nov 22, 2016
1 parent 3c201b9 commit f1480ff
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/MonoTorrent/MonoTorrent.Client/Managers/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using System.Diagnostics;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using MonoTorrent.Client.Messages;
using MonoTorrent.Client.Connections;
using MonoTorrent.Client.Messages.FastPeer;
Expand Down Expand Up @@ -641,7 +642,21 @@ bool TryConnect (TorrentManager manager)
// Remove the peer from the lists so we can start connecting to him
peer = manager.Peers.AvailablePeers[i];
manager.Peers.AvailablePeers.RemoveAt(i);


// Do not try to connect to ourselves
if (peer.ConnectionUri.Port == manager.Engine.Listener.Endpoint.Port)
{
if (manager.Engine.Listener.Endpoint.Address.ToString() == peer.ConnectionUri.Host)
return false;

if (manager.Engine.Listener.Endpoint.Address == IPAddress.Any)
foreach (var intf in NetworkInterface.GetAllNetworkInterfaces())
if (intf.OperationalStatus == OperationalStatus.Up)
foreach (var ip in intf.GetIPProperties().UnicastAddresses)
if (ip.Address.ToString() == peer.ConnectionUri.Host)
return false;
}

if (ShouldBanPeer(peer))
return false;

Expand Down

0 comments on commit f1480ff

Please sign in to comment.