Exemplo n.º 1
0
        // Mark this Peer as a bad peer.
        // This is threadsafe
        internal void RemovePeer(string ipAddress)
        {
            // We never remove bad peers from the list if we're using the configfile
            if (GameConfig.UseConfigForDiscovery)
            {
                return;
            }

            // Lock so we can test for contains, and then remove safely
            lock (KnownPeers.SyncRoot)
            {
                if (KnownPeers.ContainsKey(ipAddress))
                {
                    if (!_knownBadPeers.ContainsKey(ipAddress))
                    {
                        var badPeer = new Peer(ipAddress, ((Peer) KnownPeers[ipAddress]).LeaseTimeout.AddHours(1));
                        _knownBadPeers.Add(ipAddress, badPeer);
                    }

                    KnownPeers.Remove(ipAddress);
                }
            }
        }
Exemplo n.º 2
0
        // Keeps the bad peer list down to a reasonable size
        internal void TruncateBadPeerList()
        {
            // We always lock _knownPeers even though we are changing
            // bad peers so we don't deadlock
            lock (KnownPeers.SyncRoot)
            {
                if (_knownBadPeers.Count <= MaxKnownBadPeers) return;

                // Remove the peers with the oldest leases
                var peers = new Peer[_knownBadPeers.Count];
                _knownBadPeers.Values.CopyTo(peers, 0);
                Array.Sort(peers, new LeaseComparer());
                for (var index = 0; index < _knownBadPeers.Count - MaxKnownBadPeers; index++)
                {
                    _knownBadPeers.Remove(peers[index].IPAddress);
                }
            }
        }
Exemplo n.º 3
0
 // Keeps the bad peer list down to a reasonable size
 internal void TruncateBadPeerList()
 {
     // We always lock knownPeers even though we are changing
     // bad peers so we don't deadlock
     lock (knownPeers.SyncRoot)
     {
         if (knownBadPeers.Count > maxKnownBadPeers)
         {
             // Remove the peers with the oldest leases
             Peer [] peers = new Peer[knownBadPeers.Count];
             knownBadPeers.Values.CopyTo(peers, 0);
             Array.Sort(peers, new LeaseComparer());
             for (int index = 0; index < knownBadPeers.Count - maxKnownBadPeers; index++)
             {
                 knownBadPeers.Remove(peers[index].IPAddress);
             }
         }
     }
 }