Exemplo n.º 1
0
	public PeerListViewItem(BT.Peer peer)
	{
		this.peer = peer;

		this.Text = peer.ToString();

		this.SubItems.Add("Leech");
		this.SubItems.Add("0");
		this.SubItems.Add("0");
		this.SubItems.Add("Y");
		this.SubItems.Add("N");
		this.SubItems.Add("Y");
		this.SubItems.Add("N");
		this.SubItems.Add("0");
		this.SubItems.Add(peer.Information.ClientType.ToString());
		this.SubItems.Add(peer.Information.ID.ToString());

		peer.BitfieldChange += new BitTorrent.PeerBitfieldChangeCallback(peer_BitfieldChange);
		peer.HeIsChokingChange += new BitTorrent.PeerStatusChangeCallback(peer_HeIsChokingChange);
		peer.HeIsInterestedChange += new BitTorrent.PeerStatusChangeCallback(peer_HeIsInterestedChange);
		peer.IAmChokingChange += new BitTorrent.PeerStatusChangeCallback(peer_IAmChokingChange);
		peer.IAmInterestedChange += new BitTorrent.PeerStatusChangeCallback(peer_IAmInterestedChange);

		peer.DownThrottle.RateChange += new BitTorrent.RateChangeCallback(peer_DownloadRateChange);
		peer.UpThrottle.RateChange +=new BitTorrent.RateChangeCallback(peer_UploadRateChange);
	}
Exemplo n.º 2
0
    public PeerListViewItem(BT.Peer peer)
    {
        this.peer = peer;

        this.Text = peer.ToString();

        this.SubItems.Add("Leech");
        this.SubItems.Add("0");
        this.SubItems.Add("0");
        this.SubItems.Add("Y");
        this.SubItems.Add("N");
        this.SubItems.Add("Y");
        this.SubItems.Add("N");
        this.SubItems.Add("0");
        this.SubItems.Add(peer.Information.ClientType.ToString());
        this.SubItems.Add(peer.Information.ID.ToString());

        peer.BitfieldChange       += new BitTorrent.PeerBitfieldChangeCallback(peer_BitfieldChange);
        peer.HeIsChokingChange    += new BitTorrent.PeerStatusChangeCallback(peer_HeIsChokingChange);
        peer.HeIsInterestedChange += new BitTorrent.PeerStatusChangeCallback(peer_HeIsInterestedChange);
        peer.IAmChokingChange     += new BitTorrent.PeerStatusChangeCallback(peer_IAmChokingChange);
        peer.IAmInterestedChange  += new BitTorrent.PeerStatusChangeCallback(peer_IAmInterestedChange);

        peer.DownThrottle.RateChange += new BitTorrent.RateChangeCallback(peer_DownloadRateChange);
        peer.UpThrottle.RateChange   += new BitTorrent.RateChangeCallback(peer_UploadRateChange);
    }
Exemplo n.º 3
0
        // Called by the Session class for peers connecting through the server and in StartPeerConnectionThread() method for peers
        // connected to directly
        private void AddPeerPrivate(Sockets.Socket socket, Sockets.NetworkStream netStream, PeerInformation peerInformation)
        {
            try
            {
                if (Config.ActiveConfig.MaxPeersConnected < this.mPeers.Count)
                {
                    socket.Close();
                    return;
                }

                bool connect = true;

                if (Config.ActiveConfig.OnlyOneConnectionFromEachIP)
                {
                    foreach (Peer connectedPeer in this.mPeers)
                    {
                        if (connectedPeer.Information.IP.Equals(peerInformation.IP))
                        {
                            connect = false;
                            break;
                        }
                    }
                }

                if (!connect)
                {
                    socket.Close();
                    return;
                }

                if (!this.downloadFile.Bitfield.AllFalse)
                {
                    PeerProtocol.SendBitfieldMessage(netStream, this.downloadFile);
                }

                Peer peer = new Peer(this.infofile, this.downloadFile, socket, netStream, peerInformation);
                peer.Disconnected += new PeerDisconnectedCallback(peer_Disconnected);

                Config.LogDebugMessage("Connection accepted from: " + peer.ToString());

                // add to download and upload manager
                this.mDownloadStrategy.HookPeerEvents(peer);
                this.uploadManager.AddPeer(peer);
                this.peerManager.AddPeer(peer);

                if (this.PeerConnected != null)
                {
                    this.PeerConnected(this, peer, true);
                }

                this.mPeers.Add(peer);
            }
            catch (System.Exception e)
            {
                Config.LogException(e);
            }
        }
Exemplo n.º 4
0
	private void OnPeerConnected(BT.Torrent torrent, BT.Peer peer, bool connected)
	{
		if (connected)
		{
			this.peerListView.Invoke( new AddNewPeerDelegate( this.peerListView.Items.Add ), new object[] { new PeerListViewItem( peer ) } );
//			this.peerListView.Items.Add(new PeerListViewItem(peer));
		}
		else
		{
			LogDebugMessage( "Peer disconnected from mainform.cs: " + peer.ToString() );
			this.peerListView.Invoke( new RemovePeerDelegate( RemovePeer ), peer );
		}
	}
Exemplo n.º 5
0
        private void SendCurrentSectionRequestToPeer(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)
            {
                if (this.mEndGameRequest == null)
                {
                    this.UpdateRequestWithNextPiece();
                }

                if (this.mEndGameRequest != null)
                {
                    if (peer.BitField.Get(this.mEndGameRequest.PieceId))
                    {
                        mManager.SendPieceRequestToPeer(peer, this.mEndGameRequest.PieceId, this.mEndGameRequest.Begin, this.mEndGameRequest.Length);
                        this.mEndGamePeers.Add(peer);
                        Config.LogDebugMessage("Sent end game request to peer: " + peer.ToString());
                    }
                }
            }
        }
Exemplo n.º 6
0
		// Called by the Session class for peers connecting through the server and in StartPeerConnectionThread() method for peers
		// connected to directly
		private void AddPeerPrivate(Sockets.Socket socket, Sockets.NetworkStream netStream, PeerInformation peerInformation)
		{
			try
			{
				if ( Config.ActiveConfig.MaxPeersConnected < this.mPeers.Count )
				{
					socket.Close();
					return;
				}

				bool connect = true;

				if (Config.ActiveConfig.OnlyOneConnectionFromEachIP)
				{
					foreach ( Peer connectedPeer in this.mPeers )
					{
						if (connectedPeer.Information.IP.Equals(peerInformation.IP))
						{
							connect = false;
							break;
						}
					}
				}

				if (!connect)
				{
					socket.Close();
					return;
				}

				if (!this.downloadFile.Bitfield.AllFalse)
					PeerProtocol.SendBitfieldMessage(netStream, this.downloadFile);

				Peer peer = new Peer(this.infofile, this.downloadFile, socket, netStream, peerInformation);
				peer.Disconnected += new PeerDisconnectedCallback(peer_Disconnected);

				Config.LogDebugMessage("Connection accepted from: " + peer.ToString());

				// add to download and upload manager
				this.mDownloadStrategy.HookPeerEvents(peer);
				this.uploadManager.AddPeer(peer);
				this.peerManager.AddPeer(peer);

				if (this.PeerConnected != null)
					this.PeerConnected(this, peer, true);

				this.mPeers.Add( peer );
			}
			catch ( System.Exception e )
			{
				Config.LogException( e );
			}
		}
Exemplo n.º 7
0
        public void peer_PieceSectionFinished(bool isActive, Peer peer, int pieceId, int begin, int length)
        {
            if (this.mEndGameRequest != null &&
                pieceId == this.mEndGameRequest.PieceId && begin == this.mEndGameRequest.Begin && length == this.mEndGameRequest.Length)
            {
                Config.LogDebugMessage("End game piece section received from peer: " + peer.ToString());

                // if an end game piece just came in, cancel the rest of the peers
                foreach (Peer endGamePeer in this.mEndGamePeers)
                {
                    if (!endGamePeer.Equals(peer))
                    {
                        mManager.SendPieceCancelToPeer(endGamePeer, this.mEndGameRequest.PieceId, this.mEndGameRequest.Begin, this.mEndGameRequest.Length);
                        Config.LogDebugMessage("Sent cancel to peer: " + endGamePeer.ToString());
                    }
                }

                this.mEndGamePeers.Clear();

                // choose the next end game piece
                this.UpdateEndGameRequest();

                // send it to all available peers
                foreach (Peer availablePeer in this.mManager.PeersAvailableToDownload)
                {
                    SendCurrentSectionRequestToPeer(availablePeer);
                    Config.LogDebugMessage("Sent end game request to peer: " + availablePeer.ToString());
                }
            }
        }