コード例 #1
0
        public Tracker(string addr, ActiveTorrent torrent)
        {
            string[] t0 = addr.Split(':');
            this.addr = addr;

            if (addr.StartsWith("udp"))
            {
                string tempPort = "";
                if (t0.Length == 2)
                {
                    this.addr = t0[0];
                    tempPort  = t0[1];
                }
                else if (t0.Length == 3)
                {
                    this.addr = t0[0] + ":" + t0[1];
                    tempPort  = t0[2];
                }
                if (tempPort.Contains('/'))
                {
                    string[] t1 = tempPort.Split("/".ToArray(), 2);
                    this.port  = Convert.ToInt32(t1[0]);
                    this.addr += "/" + t1[1];
                }
                else
                {
                    this.port = Convert.ToInt32(tempPort);
                }
            }

            this.isHandshaken = false;
            this.torrent      = torrent;
        }
コード例 #2
0
        public async void Download(SearchResponse sr, long chatId)
        {
            System.Console.WriteLine($"downloading {sr.Title}...");


            //services
            var transmission = _scope.CreateScope().ServiceProvider.GetRequiredService <TransmissionService>().Client;
            var database     = _scope.CreateScope().ServiceProvider.GetRequiredService <DatabaseContext>();

            System.Console.WriteLine(Directory.GetCurrentDirectory());

            var torrentSettings = new TorrentSettings();

            NewTorrent torrent;

            System.Console.WriteLine("trying with magnet");
            var metadata = await _engine.DownloadMetadataAsync(MagnetLink.Parse(sr.MagnetUrl), CancellationToken.None);

            System.Console.WriteLine("downloaded metadata");

            torrent = new NewTorrent()
            {
                Metainfo = Convert.ToBase64String(metadata)
            };


            var torrentInfo = transmission.TorrentAdd(torrent);

            if (database.ActiveTorrents.Any(at => at.TorrentId == torrentInfo.ID))
            {
                return;
            }

            var activeTorrent = new ActiveTorrent()
            {
                ChatId     = chatId,
                TorrentId  = torrentInfo.ID,
                IsFinished = false,
            };

            database.ActiveTorrents.Add(activeTorrent);
            database.SaveChanges();
        }
コード例 #3
0
ファイル: UdpTracker.cs プロジェクト: CMatri/TorrentClientCLI
 public UdpTracker(string addr, ActiveTorrent torrent) : base(addr, torrent)
 {
 }
コード例 #4
0
 public TrackerManager(ActiveTorrent torrent)
 {
     this.torrent  = torrent;
     this.trackers = new List <Tracker>();
 }