Exemplo n.º 1
0
        void PreLogicTick(int counter)
        {
            PeerId id;

            //Execute iniitial logic for individual peers
            if (counter % (1000 / ClientEngine.TickLength) == 0)
            {               // Call it every second... ish
                manager.Monitor.Tick();
                manager.UpdateLimiters();
            }

            if (manager.finishedPieces.Count > 0)
            {
                SendHaveMessagesToAll();
            }

            for (int i = 0; i < manager.Peers.ConnectedPeers.Count; i++)
            {
                id = manager.Peers.ConnectedPeers[i];
                if (id.Connection == null)
                {
                    continue;
                }

                int maxRequests = PieceManager.NormalRequestAmount + (int)(id.Monitor.DownloadSpeed / 1024.0 / PieceManager.BonusRequestPerKb);
                maxRequests           = Math.Min(id.AmRequestingPiecesCount + 2, maxRequests);
                maxRequests           = Math.Min(id.MaxSupportedPendingRequests, maxRequests);
                maxRequests           = Math.Max(2, maxRequests);
                id.MaxPendingRequests = maxRequests;

                id.Monitor.Tick();
            }
        }