Ejemplo n.º 1
0
 public void peer_PieceFinished(bool isActive, Peer peer, int pieceId)
 {
     // check all peers we are interested in to see if we should turn off interest now we have a new piece.
     if (!DownloadStrategyHelp.DoesPeerHavePieceWeDont(mManager, peer))
     {
         peer.AmIInterested = false;
     }
 }
Ejemplo n.º 2
0
 public void peer_PieceSectionFinished(bool isActive, Peer peer, int pieceId, int begin, int length)
 {
     if (isActive)
     {
         mManager.SendPieceRequestToPeer(peer, pieceId, begin + length,
                                         DownloadStrategyHelp.CalculatePieceSectionLength(mManager, pieceId, begin + length));
     }
 }
Ejemplo n.º 3
0
 public void peer_BitfieldChange(bool isActive, Peer peer, int pieceId)
 {
     if (isActive)
     {
         DownloadStrategyHelp.SetInterestedOnPeerIfNecessary(mManager, peer, pieceId);
         SendCurrentSectionRequestToPeer(peer);
     }
 }
Ejemplo n.º 4
0
        public void peer_BitfieldChange(bool isActive, Peer peer, int pieceId)
        {
            if (isActive)
            {
                DownloadStrategyHelp.SetInterestedOnPeerIfNecessary(mManager, peer, pieceId);

                // if the peer has a piece we want now, see if we want to/can download it
                this.StartDownloadingNextPieceIfPossible(peer);
            }
        }
Ejemplo n.º 5
0
        private void UpdateRequestWithNextPiece()
        {
            // else get a new piece to find
            int pieceId = DownloadStrategyHelp.DecideNextPiece(mManager, null);

            if (pieceId >= 0)
            {
                int pieceSectionLength = DownloadStrategyHelp.CalculatePieceSectionLength(mManager, pieceId, 0);
                this.mEndGameRequest = new PieceRequest(null, pieceId, 0, pieceSectionLength);
            }
        }
Ejemplo n.º 6
0
 private void StartDownloadingNextPieceIfPossible(Peer peer)
 {
     // if the peer isn't choking, isn't currently downloading anything and the maximum number of downloads hasn't been reached
     // we can authorise a request to be sent
     if (!peer.HeIsChoking && peer.AmIInterested && !this.mManager.IsPeerDownloading(peer))                // && this.piecesDownloading.Count < Config.ActiveConfig.SimultaneousDownloadsLimit)
     {
         int pieceId = DownloadStrategyHelp.DecideNextPiece(mManager, peer);
         if (pieceId >= 0)
         {
             mManager.SendPieceRequestToPeer(peer, pieceId, 0, DownloadStrategyHelp.CalculatePieceSectionLength(mManager, pieceId, 0));
         }
     }
 }
Ejemplo n.º 7
0
        public void peer_PieceFinished(bool isActive, Peer peer, int pieceId)
        {
            if (isActive)
            {
                this.CheckForEndGame();
                this.StartDownloadingNextPieceIfPossible(peer);

                // check all peers we are interested in to see if we should turn off interest now we have a new piece.
                foreach (Peer ipeer in this.mManager.Torrent.Peers)
                {
                    if (!DownloadStrategyHelp.DoesPeerHavePieceWeDont(mManager, ipeer))
                    {
                        ipeer.AmIInterested = false;
                    }
                }
            }
        }
Ejemplo n.º 8
0
 private void UpdateEndGameRequest()
 {
     if (this.mEndGameRequest == null)
     {
         UpdateRequestWithNextPiece();
     }
     else
     {
         // continue the old piece if it hasnt finished
         int pieceLength = DownloadStrategyHelp.CalculatePieceSectionLength(mManager, this.mEndGameRequest.PieceId, this.mEndGameRequest.Begin + this.mEndGameRequest.Length);
         if (pieceLength <= 0)
         {
             UpdateRequestWithNextPiece();
         }
         else
         {
             this.mEndGameRequest.Begin += this.mEndGameRequest.Length;
             this.mEndGameRequest.Length = pieceLength;
         }
     }
 }