OctoTorrent.Client.Peer.Decode C# (CSharp) Method

Decode() public static method

public static Decode ( BEncodedList peers ) : MonoTorrentCollection
peers BEncodedList
return MonoTorrentCollection
        public static MonoTorrentCollection<Peer> Decode(BEncodedList peers)
        {
            var list = new MonoTorrentCollection<Peer>(peers.Count);
            foreach (var value in peers)
            {
                try
                {
                    if (value is BEncodedDictionary)
                        list.Add(DecodeFromDict((BEncodedDictionary)value));
                    else if (value is BEncodedString)
                        list.AddRange(Decode((BEncodedString) value));
                }
                catch
                {
                    // If something is invalid and throws an exception, ignore it
                    // and continue decoding the rest of the peers
                }
            }
            return list;
        }

Same methods

Peer::Decode ( BEncodedString peers ) : MonoTorrentCollection

Usage Example

Esempio n. 1
0
        protected virtual void HandlePeerExchangeMessage(PeerId id, PeerExchangeMessage message)
        {
            // Ignore peer exchange messages on private torrents
            if (id.TorrentManager.Torrent.IsPrivate || !id.TorrentManager.Settings.EnablePeerExchange)
            {
                return;
            }

            // If we already have lots of peers, don't process the messages anymore.
            if ((Manager.Peers.AvailableCount + Manager.OpenConnections) >= _manager.Settings.MaxConnections)
            {
                return;
            }

            IList <Peer> peers = Peer.Decode(message.Added);
            var          count = id.TorrentManager.AddPeersCore(peers);

            id.TorrentManager.RaisePeersFound(new PeerExchangePeersAdded(id.TorrentManager, count, peers.Count, id));
        }