Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[PeerExchange] Ignore PeerExchange messages when we have enough peers

PeerExchange messages are pretty CPU heavy to process as we need to
ensure we don't have duplicate peers in the list. As such, ignore them
once we have enough peers.
  • Loading branch information...
commit ed4175ce48eabf03e733447568232db033180fb0 1 parent a2b47b5
@alanmcgovern alanmcgovern authored
Showing with 4 additions and 0 deletions.
  1. +4 −0 src/MonoTorrent/MonoTorrent.Client/Modes/Mode.cs
4 src/MonoTorrent/MonoTorrent.Client/Modes/Mode.cs
@@ -186,6 +186,10 @@ protected virtual void HandlePeerExchangeMessage(PeerId id, PeerExchangeMessage
if (id.TorrentManager.Torrent.IsPrivate || !id.TorrentManager.Settings.EnablePeerExchange)
+ // If we already have lots of peers, don't process the messages anymore.
+ if ((Manager.Peers.Available + Manager.OpenConnections) >= manager.Settings.MaxConnections)
+ return;
IList<Peer> peers = Peer.Decode((BEncodedString)message.Added);
int count = id.TorrentManager.AddPeersCore(peers);
id.TorrentManager.RaisePeersFound(new PeerExchangePeersAdded(id.TorrentManager, count, peers.Count, id));
Please sign in to comment.
Something went wrong with that request. Please try again.