Пример #1
0
		public UploadManager(MetainfoFile infofile, DownloadFile downloadFile)
		{
			this.infofile = infofile;
			this.downloadFile = downloadFile;

			this.chokeTimer = new System.Threading.Timer(new System.Threading.TimerCallback(OnChokeTimer), null, Config.ChokeInterval, Config.ChokeInterval);
		}
Пример #2
0
		public Peer(MetainfoFile infofile, DownloadFile downloadFile,
			Sockets.Socket socket, Sockets.NetworkStream netStream, PeerInformation peerInformation)
		{
			this.infofile = infofile;
			this.downloadFile = downloadFile;
			this.socket = socket;
			this.netStream = netStream;
			this.peerInformation = peerInformation;

			this.piecesDownloaded = new BitField(this.infofile.PieceCount);
			this.peerProtocol.UpThrottle.Start();
			this.peerProtocol.DownThrottle.Start();
		}
Пример #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;
		}
Пример #4
0
		public static void SendBitfieldMessage(IO.Stream stream, DownloadFile downloadFile)
		{
			int bitfieldLength = downloadFile.Bitfield.Count/8 + ((downloadFile.Bitfield.Count % 8) > 0 ? 1 : 0);
			byte[] bitfield = new byte[bitfieldLength];
			downloadFile.Bitfield.CopyTo(bitfield, 0);
			SendMessageHeader(stream, PeerMessage.Bitfield, bitfieldLength);
			stream.Write(bitfield, 0, bitfield.Length);
		}
Пример #5
0
		private void OnIntegrityCallback(DownloadFile file, int pieceId, bool good, float percentDone)
		{
			if (this.CheckIntegrity != null)
				this.CheckIntegrity(this, pieceId, good, percentDone);
		}
Пример #6
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);
		}
Пример #7
0
		/// <summary>
		/// Constructs a TrackerProtocol
		/// </summary>
		public TrackerProtocol(Torrent torrent, MetainfoFile infofile, DownloadFile file)
		{
			this.torrent = torrent;
			this.infofile = infofile;
			this.file = file;
		}
Пример #8
0
 /// <summary>
 /// Constructs a TrackerProtocol
 /// </summary>
 public TrackerProtocol(Torrent torrent, MetainfoFile infofile, DownloadFile file)
 {
     this.torrent  = torrent;
     this.infofile = infofile;
     this.file     = file;
 }
Пример #9
0
 private void torrent_PercentChanged(BitTorrent.DownloadFile file, float percent)
 {
     this.ListView.BeginInvoke(new UpdateSubItemTextDelegate(UpdateSubItemText), new object[] { 2, percent.ToString("0.0") });
 }