Exemple #1
0
        void DownloadLogic(int counter)
        {
            if (ClientEngine.SupportsWebSeed && (DateTime.Now - Manager.StartTime) > Manager.Settings.WebSeedDelay && Manager.Monitor.DownloadSpeed < Manager.Settings.WebSeedSpeedTrigger)
            {
                foreach (string seedUri in Manager.Torrent.HttpSeeds)
                {
                    BEncodedString peerId = HttpConnection.CreatePeerId();

                    var uri  = new Uri(seedUri);
                    var peer = new Peer(peerId, uri);

                    var connection = (HttpConnection)ConnectionFactory.Create(uri);
                    // Unsupported connection type.
                    if (connection == null)
                    {
                        continue;
                    }
                    connection.Manager = Manager;

                    var id = new PeerId(peer, connection, Manager.Bitfield.Clone().SetAll(true));
                    id.BitField.SetAll(true);
                    id.Encryptor = PlainTextEncryption.Instance;
                    id.Decryptor = PlainTextEncryption.Instance;
                    id.IsChoking = false;
                    id.ClientApp = new Software(id.PeerID);
                    Manager.Peers.ConnectedPeers.Add(id);
                    Interlocked.Increment(ref ConnectionManager.openConnections);
                    Manager.RaisePeerConnected(new PeerConnectedEventArgs(Manager, id));
                    ConnectionManager.ReceiveMessagesAsync(id.Connection, id.Decryptor, Manager.DownloadLimiters, id.Monitor, Manager, id);
                    if (!Manager.Complete)
                    {
                        SetAmInterestedStatus(id, true);
                        id.MessageQueue.SetReady();
                        ConnectionManager.TryProcessQueue(Manager, id);
                    }
                }

                // FIXME: In future, don't clear out this list. It may be useful to keep the list of HTTP seeds
                // Add a boolean or something so that we don't add them twice.
                Manager.Torrent.HttpSeeds.Clear();
            }

            // Remove inactive peers we haven't heard from if we're downloading
            if (Manager.State == TorrentState.Downloading && Manager.lastCalledInactivePeerManager + TimeSpan.FromSeconds(5) < DateTime.Now)
            {
                Manager.InactivePeerManager.TimePassed();
                Manager.lastCalledInactivePeerManager = DateTime.Now;
            }

            // Now choke/unchoke peers; first instantiate the choke/unchoke manager if we haven't done so already
            if (Manager.chokeUnchoker == null)
            {
                Manager.chokeUnchoker = new ChokeUnchokeManager(new TorrentManagerUnchokeable(Manager));
            }
            Manager.chokeUnchoker.UnchokeReview();
        }
Exemple #2
0
        public void CreatePeerIds()
        {
            var ids = new HashSet <BEncodedString> ();

            for (int i = 0; i < 20; i++)
            {
                var id = HttpConnection.CreatePeerId();
                Assert.AreEqual(20, id.TextBytes.Length, "#1");
                Assert.IsTrue(ids.Add(id), "#2");
            }
        }
Exemple #3
0
        void DownloadLogic(int counter)
        {
            if ((DateTime.Now - Manager.StartTime) > Manager.Settings.WebSeedDelay && Manager.Monitor.DownloadSpeed < Manager.Settings.WebSeedSpeedTrigger)
            {
                foreach (var seedUri in Manager.Torrent.GetRightHttpSeeds)
                {
                    var peerId = HttpConnection.CreatePeerId();

                    var uri  = new Uri(seedUri);
                    var peer = new Peer(peerId, uri);

                    var connection = (HttpConnection)ConnectionFactory.Create(uri);
                    connection.Manager = Manager;

                    var id = new PeerId(peer, connection, Manager.Bitfield.Clone().SetAll(true));
                    id.BitField.SetAll(true);
                    id.Encryptor    = PlainTextEncryption.Instance;
                    id.Decryptor    = PlainTextEncryption.Instance;
                    id.IsChoking    = false;
                    id.AmInterested = !Manager.Complete;
                    id.ClientApp    = new Software(id.PeerID);
                    Manager.Peers.ConnectedPeers.Add(id);
                    Manager.RaisePeerConnected(new PeerConnectedEventArgs(Manager, id));
                    ConnectionManager.ReceiveMessagesAsync(id.Connection, id.Decryptor, Manager.DownloadLimiters, id.Monitor, Manager, id);
                }

                // FIXME: In future, don't clear out this list. It may be useful to keep the list of HTTP seeds
                // Add a boolean or something so that we don't add them twice.
                Manager.Torrent.GetRightHttpSeeds.Clear();
            }

            // Remove inactive peers we haven't heard from if we're downloading
            if (Manager.State == TorrentState.Downloading && Manager.lastCalledInactivePeerManager + TimeSpan.FromSeconds(5) < DateTime.Now)
            {
                Manager.InactivePeerManager.TimePassed();
                Manager.lastCalledInactivePeerManager = DateTime.Now;
            }

            // Now choke/unchoke peers; first instantiate the choke/unchoke manager if we haven't done so already
            if (Manager.chokeUnchoker == null)
            {
                Manager.chokeUnchoker = new ChokeUnchokeManager(Manager, Manager.Settings.MinimumTimeBetweenReviews, Manager.Settings.PercentOfMaxRateToSkipReview);
            }
            Manager.chokeUnchoker.UnchokeReview();
        }