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

Troubles with torrent seeding #671

Open
Kaidoz opened this issue Aug 9, 2024 · 9 comments
Open

Troubles with torrent seeding #671

Kaidoz opened this issue Aug 9, 2024 · 9 comments

Comments

@Kaidoz
Copy link

Kaidoz commented Aug 9, 2024

There's a problem with the client seeding.
I am using home pc.

I tried to seeding torrent in every possible way, but attempts were unsuccessful.
I take a torrent file, start its "StartAsync", after checking the hash, the seeding starts, but it is not actually there.

If I take the torrent file and start it in qBitTorrent - seeding goes.

I tried to switch off the firewall, also changed ports and various parameters.

Code: `

public class ManageTorrentSeedService
{
private ClientEngine _engine;

    public ManageTorrentSeedService()
    {
        const int httpListeningPort = 55125;

        var settingBuilder = new EngineSettingsBuilder
        {
            AllowPortForwarding = true,
            AutoSaveLoadDhtCache = true,
            AutoSaveLoadFastResume = true,

            AutoSaveLoadMagnetLinkMetadata = true,

            ListenEndPoints = new Dictionary<string, IPEndPoint> {
                { "ipv4", new IPEndPoint (IPAddress.Any, 55123) },
                { "ipv6", new IPEndPoint (IPAddress.IPv6Any, 55123) }
            },

            DhtEndPoint = new IPEndPoint(IPAddress.Any, 55123),

            HttpStreamingPrefix = $"http://0.0.0.0:{httpListeningPort}/"
        }.ToSettings();

        _engine = new ClientEngine(settingBuilder);
    }
    
    private async Task SeedClientAsync(string path, string torrentFileOrMagnetLink, CancellationToken cancellationToken)
    {
        try
        {
            var torrentSettings = new TorrentSettingsBuilder()
            {
                CreateContainingDirectory = false,
                AllowPeerExchange = true,
                AllowInitialSeeding = true,
                
            }.ToSettings();

            //torrentSettings.Ann
            var torrent = await Torrent.LoadAsync(torrentFileOrMagnetLink);
            var manager = await _engine.AddAsync(torrent, path, torrentSettings);

            string[] files = Directory.GetFiles(path);
            manager.TorrentStateChanged += Manager_TorrentStateChanged;
            manager.PeerConnected += Manager_PeerConnected;
            await manager.StartAsync();

            while (cancellationToken.IsCancellationRequested == false)
            {
                await Task.Delay(1000, cancellationToken);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }

}`

@Kaidoz
Copy link
Author

Kaidoz commented Aug 9, 2024

Trouble solved. Added code before "StartAsync":

                foreach (var trackerUrl in await GetTrackers())
                {
                    var uri = new Uri(trackerUrl);
                    await manager.TrackerManager.AddTrackerAsync(uri);
                }

@alanmcgovern
Copy link
Owner

Trouble solved. Added code before "StartAsync":

                foreach (var trackerUrl in await GetTrackers())
                {
                    var uri = new Uri(trackerUrl);
                    await manager.TrackerManager.AddTrackerAsync(uri);
                }

It'd probably be easier if the appropriate trackers are included in the .torrent file when creating it. Failing that, DHT should make this work too, though the initial peer discovery could be slow if there are only one or two actual peers accessing the torrent :)

That said, is there anything I need to do on the library side or was this simply a setup issue for the torrents you're working with?

@Kaidoz
Copy link
Author

Kaidoz commented Aug 10, 2024

Trouble solved. Added code before "StartAsync":

                foreach (var trackerUrl in await GetTrackers())
                {
                    var uri = new Uri(trackerUrl);
                    await manager.TrackerManager.AddTrackerAsync(uri);
                }

It'd probably be easier if the appropriate trackers are included in the .torrent file when creating it. Failing that, DHT should make this work too, though the initial peer discovery could be slow if there are only one or two actual peers accessing the torrent :)

That said, is there anything I need to do on the library side or was this simply a setup issue for the torrents you're working with?

Trackers have been added to torrent file. If upload a torrent file to qBitTorrent it works fine.

@alanmcgovern
Copy link
Owner

alanmcgovern commented Aug 10, 2024

Hrm, then what exactly do you mean by the previous code snippet where you said "adding this to StartAsync fixed the issue"?

Where exactly did you add that tracker code? I thought this was in your own app/library, which made me think you were adding extra trackers beyond what was contained in the .torrent file itself.

@Kaidoz
Copy link
Author

Kaidoz commented Aug 12, 2024

Hrm, then what exactly do you mean by the previous code snippet where you said "adding this to StartAsync fixed the issue"?

Where exactly did you add that tracker code? I thought this was in your own app/library, which made me think you were adding extra trackers beyond what was contained in the .torrent file itself.

When creating a torrent, I create it as follows:

         internal async Task<Torrent> CreateTorrent(string folderPath, string game)
        {
            var creator = new TorrentCreator();
            var files = new TorrentFileSource(folderPath);

            creator.Announces.Add(await GetTrackers());

            string path = GetTorrentFile(game);

            await using var stream = new FileStream(path, FileMode.Create);


            await creator.CreateAsync(files, stream);

            return await Torrent.LoadAsync(path);
        }

When I load a torrent file, I dont get a seeding due to lack of trackers. It worked only when I added them manually

@alanmcgovern
Copy link
Owner

alanmcgovern commented Aug 12, 2024

Can you share an example of one of those torrents where the trackers don't show up correctly?

I wonder if you're accidentally adding all of the trackers in 1 tier when you create the torrent , versus adding each tracker as a separate tier when you do it manually.

However the way that operates should be the same in all spec compliant torrent clients so it's surprising that one client would work better than another

@Kaidoz
Copy link
Author

Kaidoz commented Aug 13, 2024

Can you share an example of one of those torrents where the trackers don't show up correctly?

I wonder if you're accidentally adding all of the trackers in 1 tier when you create the torrent , versus adding each tracker as a separate tier when you do it manually.

However the way that operates should be the same in all spec compliant torrent clients so it's surprising that one client would work better than another
Rust.zip

Code GetTrackers:

        private static async Task<List<string>> GetTrackers()
        {
            try
            {
                string text = await new HttpClient().GetStringAsync("https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt");

                List<string> trackers = new List<string>();

                string[] lines = text.Split("\n");

                foreach (var line in lines)
                {
                    if (string.IsNullOrWhiteSpace(line) == false)
                    {
                        trackers.Add(line.Trim());
                    }
                }

                SaveCacheTrackers(trackers);

                return trackers;
            }
            catch
            {
                return GetLocalTrackers();
            }
        }

@keraf
Copy link

keraf commented Aug 15, 2024

Having the same issue here (on 3.0.2). My torrents have the trackers added to them but they won't start sending data unless I manually add the tracker. The state of the torrent says "seeding" but no bytes are leaving. Using the same torrent with the same tracker with two different clients (qBittorrent and Transmission) works right away.

It's a bit problematic for private torrents as the API doesn't allow manually adding trackers to them.

@alanmcgovern
Copy link
Owner

Could both of you try the new alpha release - 3.0.3-alpha.unstable.rev0003 ? It has definitely not been tested as thoroughly as I'd like, but it does contain some fixes for the kind of issue you're describing.

In addition, can you attach a logger for both the leecher client and seeder client and share the logs with me? It may have some private data (IP addresses of peers, filepaths for your torrent etc) so please review before sharing. Trim/redact anything you want redacted. It might help me figure out what the issue is if the new release doesn't help!

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