Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't create a torrent and see it seeding #646

Closed
salaroglio opened this issue Oct 15, 2023 · 2 comments
Closed

I can't create a torrent and see it seeding #646

salaroglio opened this issue Oct 15, 2023 · 2 comments

Comments

@salaroglio
Copy link

Ok, this is not a bug, but a help request:

  1. I try to create a new torrent using monotorrent library:

ClientEngine engine = new ClientEngine(new EngineSettings());

var filePath = @"C:\Users\Carlo\Downloads\hello.pdf";
var fileInfo = new FileInfo(filePath);

Source filesSource = new Source
{
    TorrentName = "My first generated torrent",
    Files = new[] {new FileMapping(
        filePath,
         @"hello.pdf", fileInfo.Length) }
};

TorrentCreator creator = new TorrentCreator();


creator.Announces.Add(new List<string>());
creator.Announces[0].Add("http://192.168.178.26:10000/announce");
creator.Comment = "My first generated torrent";
creator.Private = true;            
creator.Publisher = "www.mdexplorer.com";
creator.Create(filesSource, @"c:\hello.pdf.26.torrent"); 
  1. I copy the generated file torrent into "./Torrents" directory of the ClientSample

  2. It doesn't seeds, but it starts downloading.

I know i should get it on my own... and i tried... Maybe just point me in the right direction.
Thank you for your help.

@scorpionsFC
Copy link

    public async Task CreateAsync(CancellationToken token, string torrentsPath, string downloadsPath)
    {
        try
        {
            DAPLauncher.MainWindow targetWindow = System.Windows.Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is DAPLauncher.MainWindow) as DAPLauncher.MainWindow;
            targetWindow.file_local.Content = "1. Created Torrent File : " + torrentsPath;

            int CountF = 0;
            ViewModel._orders.Clear();
            DirectoryInfo dir = new(downloadsPath);
            Files = dir.GetFiles("*", SearchOption.AllDirectories);
            for (int fcount = 0; fcount < Files.Length; fcount++)
            {
                CountF++;
            }
            targetWindow.progressload.Maximum = CountF + 1;
            string pubIp = new WebClient().DownloadString("https://api.ipify.org");
            TorrentType torrentType = TorrentType.V1Only;
            if (bCheckV1Only)
            {
                 torrentType = TorrentType.V1Only;
            }
            if (bCheckV1OnlyWithPaddingFiles)
            {
                torrentType = TorrentType.V1OnlyWithPaddingFiles;
            }
            if (bCheckV2Only)
            {
                torrentType = TorrentType.V2Only;
            }
            if (bCheckV1V2Hybrid)
            {
                torrentType = TorrentType.V1V2Hybrid;
            }

            Factories factories = new()
            {
            };

            TorrentCreator torrentCreator = new(torrentType, factories);

            TorrentFileSource torrentFileSource = new(downloadsPath)
            {
                TorrentName = Path.GetFileName(torrentsPath).Replace(".torrent", string.Empty)
            };


            torrentCreator.Hashed += async delegate (object o, TorrentCreatorEventArgs e)
            {
                targetWindow.md5local.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                {
                    targetWindow.md5local.Content = e.CurrentFile + "[FileSize : " + TotalFile(e.FileSize) + "/ FileBytesHashed : " + TotalFile(e.FileBytesHashed) + "]FileCompletion : " + e.FileCompletion;
                    if (e.FileCompletion == 1.0)
                    {
                        targetWindow.progressload.Value++;
                        ViewModel._orders.Add(new TorrentFileEntity
                        {
                            Name = Path.GetFileName(e.CurrentFile),
                            Path = e.CurrentFile,
                            Size = TotalFile(e.FileSize),
                            PriorityText = "",
                            ProgressText = string.Format("{0:0.00}%", e.FileCompletion),
                            Progress = 100
                        });
                        targetWindow.DataGFileTorrent.ItemsSource = ViewModel._orders;
                    }
                }));
                StatusMessage?.Invoke(this, $"" + "DownloadAsync," + e.CurrentFile + "[FileSize : " + TotalFile(e.FileSize) + "/ FileBytesHashed : " + TotalFile(e.FileBytesHashed) + "]FileCompletion : " + e.FileCompletion);
                await Task.Delay(500, token);
            };
            StatusMessage?.Invoke(this, $"" + "Engine," + Path.GetFileName(torrentsPath).Replace(".torrent", string.Empty));
            torrentCreator.Announces.Add(new List<string>());
            try
            {
                torrentCreator.Announces[0].Add("http://" + pubIp + ":" + PortTrackerhttp + "/announce");
                torrentCreator.Announces[0].Add("udp://" + pubIp + ":" + PortTrackerudp + "/announce");
                for (int pBName = 0; pBName < ListTrackers.Count; pBName++)
                {
                    torrentCreator.Announces[0].Add(ListTrackers[pBName].Tracker);
                }
            }
            catch (Exception ex) { System.Windows.MessageBox.Show("ADD TRACKERS : " + ex.Message); }
            torrentCreator.Comment = "ServerManager[SM]";
            torrentCreator.Publisher = "https://discord.com/invite/ZTJTRpb9TF";
            await torrentCreator.CreateAsync(torrentFileSource, torrentsPath, token);
            await Task.Delay(1000, token);
            ViewModel._orders.Clear();
            targetWindow.DataGFileTorrent.ItemsSource = ViewModel._orders;
            targetWindow.RLogTorrent.Document.Blocks.Clear();
            targetWindow.RichLogFirst.Document.Blocks.Clear();
            TorrentCreatOrDownloading = false;
            Thread FileSearch = new(new ThreadStart(targetWindow.StartHeSH))
            {
                IsBackground = true
            };
            FileSearch.Start();
        }
        catch (Exception ex) { System.Windows.MessageBox.Show("CreateAsync : " + ex.Message); }
    }

@alanmcgovern
Copy link
Owner

If the issue is that you expect monotorrent to be seeding, but it starts leeching instead, the problem is likely this:

When you create the torrent you named it My first generated torrent. The torrent contains one file, hello.pdf. When the torrent is created and placed in the 'Torrents' directory, you'll need to place the hello.pdf file in the Downloads directory, inside a sub-directory called My first generated torrent.

i.e. you have this layout:

Torrents/My first generated torrent.torrent
Download/My first generated torrent/hello.pdf

I think that'd do it! Let me know if that doesn't work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants