Ejemplo n.º 1
0
        /// <summary>Contructs a torrent using the metainfo filename</summary>
        /// <param name="metafilename">Filename of the metainfo file</param>
        internal Torrent(Session session, string metafilename)
        {
            this.mSession          = session;
            this.infofile          = new MetainfoFile(metafilename);
            this.downloadFile      = new DownloadFile(infofile);
            this.peerManager       = new PeerManager();
            this.mDownloadStrategy = new DownloadStrategyManager(this);
            this.uploadManager     = new UploadManager(infofile, downloadFile);
            this.tp = new TrackerProtocol(this, infofile, downloadFile);

            //		this.downloadManager.PieceFinished += new PieceFinishedCallback(downloadManager_PieceFinished);
            this.uploadManager.PieceSectionFinished += new PieceSectionFinishedCallback(uploadManager_PieceSectionFinished);

            this.tp.TrackerUpdate += new TrackerUpdateCallback(tp_TrackerUpdate);
        }
Ejemplo n.º 2
0
        /// <summary>Starts the torrent</summary>
        public void Start()
        {
            this.status = TorrentStatus.Working;
            if (this.StatusChanged != null)
            {
                this.StatusChanged(this, this.status);
            }

            // scrape the tracker to find out info
            TrackerProtocol.Scrape(this.infofile, out this.seedCount, out this.leecherCount, out this.finishedCount);

            DefaultDownloadStrategy defaultStrategy = new DefaultDownloadStrategy(this.mDownloadStrategy);

            this.mDownloadStrategy.AddNewStrategy(defaultStrategy);
            this.mDownloadStrategy.SetActiveStrategy(defaultStrategy);

            // then tell the tracker we are starting/resuming a download
            this.tp.Initiate();
        }
Ejemplo n.º 3
0
        /// <summary>Disposes the torrent</summary>
        public void Dispose()
        {
            // send shut down message to tracker
            if (this.tp != null)
            {
                this.tp.Stop();
            }

            this.peerManager.Stop();

            if (this.downloadFile != null)
            {
                this.downloadFile.Dispose();
            }
            this.downloadFile = null;

            lock (this.mPeers)
            {
                // disconnect each peer
                foreach (Peer peer in this.mPeers)
                {
                    peer.Disconnected -= new PeerDisconnectedCallback(peer_Disconnected);
                    peer.Disconnect();
                    if (this.PeerConnected != null)
                    {
                        this.PeerConnected(this, peer, false);
                    }
                }
            }

            this.mPeers.Clear();

            if (this.tp != null)
            {
                this.tp.Dispose();
            }
            this.tp = null;
        }
Ejemplo n.º 4
0
		/// <summary>Disposes the torrent</summary>
		public void Dispose()
		{
			// send shut down message to tracker
			if (this.tp != null)
				this.tp.Stop();

			this.peerManager.Stop();

			if (this.downloadFile != null)
				this.downloadFile.Dispose();
			this.downloadFile = null;

			lock ( this.mPeers )
			{
				// disconnect each peer
				foreach ( Peer peer in this.mPeers )
				{
					peer.Disconnected -= new PeerDisconnectedCallback(peer_Disconnected);
					peer.Disconnect();
					if (this.PeerConnected != null)
						this.PeerConnected(this, peer, false);
				}
			}

			this.mPeers.Clear();

			if (this.tp != null)
				this.tp.Dispose();
			this.tp = null;
		}
Ejemplo n.º 5
0
		/// <summary>Contructs a torrent using the metainfo filename</summary>
		/// <param name="metafilename">Filename of the metainfo file</param>
		internal Torrent( Session session, string metafilename )
		{
			this.mSession = session;
			this.infofile = new MetainfoFile(metafilename);
			this.downloadFile = new DownloadFile(infofile);
			this.peerManager = new PeerManager();
			this.mDownloadStrategy = new DownloadStrategyManager( this );
			this.uploadManager = new UploadManager(infofile, downloadFile);
			this.tp = new TrackerProtocol(this, infofile, downloadFile);

	//		this.downloadManager.PieceFinished += new PieceFinishedCallback(downloadManager_PieceFinished);
			this.uploadManager.PieceSectionFinished += new PieceSectionFinishedCallback(uploadManager_PieceSectionFinished);

			this.tp.TrackerUpdate += new TrackerUpdateCallback(tp_TrackerUpdate);
		}