예제 #1
0
 public TorrentData(TorrentInfo ti)
 {
     foreach (string s in ti.Files)
         files.Add(new FileData(s));
     this.torrentName = ti.Name;
     this.torrentProgress = ti.Progress;
     this.downSpeed = ti.DownloadSpeed;
     this.upSpeed = ti.UploadSpeed;
     this.ETA = ti.ETA;
     this.peers = ti.Peers;
     this.seeds = ti.Seeds;
 }
예제 #2
0
 private void TorrentReceived(TorrentInfo ti)
 {
     TorrentData td = new TorrentData(ti);
     int i;
     lock (torrents)
     {
         for (i = 0; i < torrents.Count; i++)
         {
             if (torrents[i].EqualsTorrent(td))
             {
                 torrents[i].Update(td);
                 break;
             }
         }
         if (i == torrents.Count)
             AddTorrent(td);
     }
 }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        public void Listen()
        {
            while (true)
            {
                foreach (TorrentManager torrentManager in this.torrentClient.TorrentManagers.ToList())
                {
                    this.tcpClient = this.tcpListener.AcceptTcpClient();
                    // System.Console.WriteLine("Client connected");
                    try
                    {
                        TorrentInfo torrentInfo = new TorrentInfo()
                        {
                            Files = torrentManager.Torrent.Files.Select<TorrentFile, string>(torrentFile => torrentFile.Path).ToList(),
                            Name = torrentManager.Torrent.Name,
                            Peers = torrentManager.Peers.Leechs,
                            Seeds = torrentManager.Peers.Seeds,
                            UploadSpeed = torrentManager.Monitor.UploadSpeed / 1024,
                            DownloadSpeed = torrentManager.Monitor.DownloadSpeed / 1024,
                            Progress = torrentManager.Progress,
                            ETA = this.CalculateSpeed(torrentManager)
                        };

                        var tcpStream = this.tcpClient.GetStream();
                        string update = Serializer.Serialize(torrentInfo);
                        byte[] byteArray = Encoding.UTF8.GetBytes(update);
                        tcpStream.Write(byteArray, 0, byteArray.Length);
                        tcpClient.Close();

                        Thread.Sleep(1000);
                    }
                    catch
                    {
                        // return;
                    }
                }
            }
        }