TryConnect() private method

private TryConnect ( TorrentManager manager ) : bool
manager TorrentManager
return bool
        public async Task SortByLeastConnections()
        {
            var engine  = new ClientEngine(EngineSettingsBuilder.CreateForTests());
            var manager = new ConnectionManager("test", engine.Settings, engine.Factories, engine.DiskManager);

            var torrents = new[] {
                await engine.AddAsync(new MagnetLink (new InfoHash(Enumerable.Repeat((byte)0, 20).ToArray())), "tmp"),
                await engine.AddAsync(new MagnetLink (new InfoHash(Enumerable.Repeat((byte)1, 20).ToArray())), "tmp"),
                await engine.AddAsync(new MagnetLink (new InfoHash(Enumerable.Repeat((byte)2, 20).ToArray())), "tmp")
            };

            torrents[0].Peers.ConnectedPeers.Add(PeerId.CreateNull(1));
            torrents[0].Peers.ConnectedPeers.Add(PeerId.CreateNull(1));
            torrents[2].Peers.ConnectedPeers.Add(PeerId.CreateNull(1));

            foreach (var torrent in torrents)
            {
                manager.Add(torrent);
            }

            manager.TryConnect();

            Assert.AreEqual(torrents[1], manager.Torrents[0]);
            Assert.AreEqual(torrents[2], manager.Torrents[1]);
            Assert.AreEqual(torrents[0], manager.Torrents[2]);
        }
Ejemplo n.º 2
0
        private void LogicTick()
        {
            tickCount++;

            ConnectionManager.TryConnect();
            for (int i = 0; i < this.torrents.Count; i++)
            {
                this.torrents[i].Mode.Tick(tickCount);
            }

            RaiseStatsUpdate(new StatsUpdateEventArgs());
        }
Ejemplo n.º 3
0
        private void LogicTick()
        {
            tickCount++;

            if (tickCount % (1000 / TickLength) == 0)
            {
                diskManager.writeLimiter.UpdateChunks(settings.MaxWriteRate, diskManager.WriteRate);
                diskManager.readLimiter.UpdateChunks(settings.MaxReadRate, diskManager.ReadRate);
            }

            ConnectionManager.TryConnect();
            for (int i = 0; i < this.torrents.Count; i++)
            {
                this.torrents[i].Mode.Tick(tickCount);
            }

            RaiseStatsUpdate(new StatsUpdateEventArgs());
        }
Ejemplo n.º 4
0
        private void LogicTick()
        {
            tickCount++;

            if (tickCount % 2 == 0)
            {
                downloadLimiter.UpdateChunks(Settings.GlobalMaxDownloadSpeed, TotalDownloadSpeed);
                uploadLimiter.UpdateChunks(Settings.GlobalMaxUploadSpeed, TotalUploadSpeed);
            }

            ConnectionManager.CancelPendingConnects();

            ConnectionManager.TryConnect();
            for (int i = 0; i < this.torrents.Count; i++)
            {
                this.torrents[i].Mode.Tick(tickCount);
            }

            RaiseStatsUpdate(new StatsUpdateEventArgs());
        }