MaDestro
@MaDestro
C#, PHP, html

Как правильно работать с MonoTorrent?

У меня возникла достаточно большая проблема при работе с MonoTorrent.
Проблема в том что самая последняя версия библиотеки (1.0.2) находит только 2-3 сиди и как предполагаю эти люди с каким-то особенным торрент трекером.
Если пытаюсь создать свой торрент с помощью uTorrent 3.5.5 и скормить проге то он просто напросто не находит не одного сида.
Немного потыкавши я увидел что у торрента там очень много параметров и возможно один из за это отвечает.
Документации на данную библиотеку осталось не так много, а с заменой под названием. + половина функционала сильно отличается от старого.
BitSharp разобраться не могу.

Вот код программы:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Threading;
using MonoTorrent.BEncoding;
using MonoTorrent.Client.Encryption;
using MonoTorrent.Client.Tracker;
using MonoTorrent.Client;
using MonoTorrent;

namespace TEST
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        static string _programPath;
        static string _downloadPath;
        static string _fastResumeFile;
        static string _torrentPath;
        static ClientEngine _engine;
        static TorrentManager _manager;

        private void Button1_Click(object sender, EventArgs e)
        {
            _programPath = Environment.CurrentDirectory;
            OpenFileDialog OPF = new OpenFileDialog();
            OPF.Filter = "Torrent|*.torrent";
            if (OPF.ShowDialog() == DialogResult.OK)
            {
                _torrentPath = OPF.FileName;
            }
            FolderBrowserDialog OPF1 = new FolderBrowserDialog();
            if (OPF1.ShowDialog() == DialogResult.OK)
            {
                _downloadPath = OPF1.SelectedPath;
            }
            _fastResumeFile = _programPath + "\temp.data";

            Thread Download = new Thread(new ThreadStart(DoDownload));
            Download.Start();
        }

        private void DoDownload()
        {
            //int _port;
            //_port = 31337;

            Torrent _torrent;
            EngineSettings _engineSettings = new EngineSettings();
            TorrentSettings _torrentDef = new TorrentSettings();

            _engineSettings.SavePath = _downloadPath;
            //_engineSettings.ListenPort = _port;

            _engine = new ClientEngine(_engineSettings);

            BEncodedDictionary _fastResume;

            try
            {
                _fastResume = BEncodedValue.Decode<BEncodedDictionary>(File.ReadAllBytes(_fastResumeFile));
            }
            catch
            {
                _fastResume = new BEncodedDictionary();
            }

            try
            {
                _torrent = Torrent.Load(_torrentPath);
            }
            catch
            {
                label1.Text += "Decoding error\n";
                _engine.Dispose();
                return;
            }

            Invoke((Action)(() =>
            {
                //Инвормация о торренте
                label1.Text = "";
                label1.Text += "Created by: " + _torrent.CreatedBy + "\n";
                label1.Text += "Creation date: " + _torrent.CreationDate + "\n";
                label1.Text += "Comment: " + _torrent.Comment + "\n";
                label1.Text += "Publish URL: " + _torrent.PublisherUrl + "\n";
                label1.Text += "Size: " + _torrent.Size / 1049600 + "\n";
            }));

            //if (_fastResume.ContainsKey(_torrent.InfoHash))
            //    _manager = new TorrentManager(_torrent, _downloadPath, _torrentDef, new FastResume((BEncodedDictionary)_fastResume[_torrent.InfoHash]));
            //else
            //{
            //string Test = Convert.ToString(_torrent.SHA1);
            _manager = new TorrentManager(_torrent, _downloadPath, _torrentDef);
            //}

            _engine.Register(_manager);
            _manager.StartAsync();

            Thread SpeedTest = new Thread(new ThreadStart(Speed));
            SpeedTest.Start();


            /*
            ClientEngine engine;
            string savePath;
            // Create a basic ClientEngine without changing any settings
            engine = new ClientEngine(new EngineSettings());
            savePath = _downloadPath;
            // Open the .torrent file
            Torrent torrent* = Torrent.Load("C:\\123.torrent");
            

            // Create the manager which will download the torrent to savePath
            // using the default settings.
            TorrentManager manager = new TorrentManager(torrent, savePath, new TorrentSettings());

            // Register the manager with the engine
            engine.Register(manager);

            // Begin the download. It is not necessary to call HashCheck on the manager
            // before starting the download. If a hash check has not been performed, the
            // manager will enter the Hashing state and perform a hash check before it
            // begins downloading.

            // If the torrent is fully downloaded already, calling 'Start' will place
            // the manager in the Seeding state.
            manager.Start();
            */
        }

        private void Speed()
        {
            int i = 0;
            bool _running = true;

            while (_running)
            {
                if ((i++) % 10 == 0)
                {
                    if (_manager.State == TorrentState.Stopped)
                    {
                        _running = false;
                    }

                    for (Int32 b = 1; b != 0; b++)
                    {
                        Invoke((Action)(() =>
                        {
                            label2.Text = "";
                            label2.Text += "Total Download Rate:   " + _engine.TotalDownloadSpeed / 1024.0 + " " + "kB/sec" + "\n";
                            label2.Text += "Total Upload Rate:   " + _engine.TotalUploadSpeed / 1024.0 + " " + "kB/sec" + "\n";
                            label2.Text += "Open Connections:   " + _engine.ConnectionManager.OpenConnections + "\n" + "\n";

                            label2.Text += "Name:   " + _manager.Torrent.Name + "\n";
                            label2.Text += "Progress:   " + _manager.Progress + "\n";
                            label2.Text += "Download Speed:   " + _manager.Monitor.DownloadSpeed / 1024.0 + " " + "kB/s" + "\n";
                            label2.Text += "Upload Speed:   " + _manager.Monitor.UploadSpeed / 1024.0 + " " + "kB/s" + "\n";
                            label2.Text += "Total Downloaded:   " + _manager.Monitor.DataBytesDownloaded / (1024.0 * 1024.0) + " " + "MB" + "\n";
                            label2.Text += "Total Uploaded:   " + _manager.Monitor.DataBytesUploaded / (1024.0 * 1024.0) + " " + "MB" + "\n";
                            //label2.Text += "Tracker Status:   " + _manager.TrackerManager.CurrentTracker.State + "\n";
                            //label2.Text += "Warning Message:   " + _manager.TrackerManager.CurrentTracker.WarningMessage + "\n";
                            //label2.Text += "Failure Message:   " + _manager.TrackerManager.CurrentTracker.FailureMessage + "\n";
                        }));

                        System.Threading.Thread.Sleep(2000);
                    }
                }
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            
        }
    }
}
  • Вопрос задан
  • 739 просмотров
Пригласить эксперта
Ответы на вопрос 1
tsklab
@tsklab
Здесь отвечаю на вопросы.
Начните с простого: 1024*1024=1048576
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы