Skip to content


Subversion checkout URL

You can clone with
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...
1 parent a2b47b5 commit ed4175ce48eabf03e733447568232db033180fb0 @alanmcgovern alanmcgovern committed
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));

0 comments on commit ed4175c

Please sign in to comment.
Something went wrong with that request. Please try again.