Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 12, 2025

The downloader must use the latest MonoTorrent while avoiding OS firewall warnings by preventing listener/DHT sockets.

  • Dependency: Bumped MonoTorrent to 3.0.2 to stay current with upstream API and security fixes.
  • Networking defaults: Explicitly disable port forwarding, local peer discovery, DHT, and clear listen endpoints to prevent opening inbound sockets.
  • API alignment: Switched to the new monitor fields (DataBytesReceived, DownloadRate) and reduced duplicate reads via a local variable.

Example:

var settingsBuilder = new EngineSettingsBuilder {
    AllowLocalPeerDiscovery = false,
    AllowPortForwarding = false,
    CacheDirectory = cacheFolder,
    DhtEndPoint = null,
};
settingsBuilder.ListenEndPoints.Clear();

var monitor = torrentManager.Monitor;
var received = monitor.DataBytesReceived;
viewModel.SetDownloadedSize(received, torrent.Size);
viewModel.SetDownloadSpeed(monitor.DownloadRate);
Original prompt

升级到最新版MonoTorrent库,修改对应代码,确保不触发防火墙警告


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 12, 2025 16:44
Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com>
Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com>
Copilot AI changed the title [WIP] Upgrade to latest MonoTorrent library and update code Upgrade MonoTorrent and harden networking defaults to avoid firewall prompts Dec 12, 2025
Copilot AI requested a review from mrbbbaixue December 12, 2025 16:48
@mrbbbaixue mrbbbaixue marked this pull request as ready for review December 12, 2025 17:02
Copilot AI review requested due to automatic review settings December 12, 2025 17:02
@mrbbbaixue mrbbbaixue merged commit 3e9d2dd into main Dec 12, 2025
3 checks passed
@mrbbbaixue mrbbbaixue deleted the copilot/update-monotorrent-library branch December 12, 2025 17:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR upgrades MonoTorrent from version 2.0.7 to 3.0.2 and hardens the networking configuration to prevent Windows firewall prompts during torrent downloads.

  • Updates MonoTorrent dependency to version 3.0.2 for latest security fixes and API improvements
  • Explicitly disables all inbound networking features (local peer discovery, port forwarding, DHT, and listener endpoints) to avoid firewall warnings
  • Migrates to MonoTorrent 3.x API by switching from deprecated properties (DataBytesDownloaded, DownloadSpeed) to current equivalents (DataBytesReceived, DownloadRate)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Ra3.BattleNet.Downloader/Ra3.BattleNet.Downloader.csproj Upgrades MonoTorrent package reference from 2.0.7 to 3.0.2
Ra3.BattleNet.Downloader/Download.cs Updates networking configuration to disable all inbound sockets (preventing firewall prompts) and migrates to MonoTorrent 3.x API with updated property names and local variable optimization
Comments suppressed due to low confidence (8)

Ra3.BattleNet.Downloader/Download.cs:35

        foreach (var path in new List<string> { tempFolder, cacheFolder, DownloadFolder})
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }

Ra3.BattleNet.Downloader/Download.cs:173

  • Replace this call with a call to managed code if possible.
            IntPtr pidlList = ILCreateFromPathW(filePath);

Ra3.BattleNet.Downloader/Download.cs:178

  • Replace this call with a call to managed code if possible.
                    Marshal.ThrowExceptionForHR(SHOpenFolderAndSelectItems(pidlList, 0, IntPtr.Zero, 0));

Ra3.BattleNet.Downloader/Download.cs:182

  • Replace this call with a call to managed code if possible.
                    ILFree(pidlList);

Ra3.BattleNet.Downloader/Download.cs:152

  • Minimise the use of unmanaged code.
    private static extern void ILFree(IntPtr pidlList);

Ra3.BattleNet.Downloader/Download.cs:155

  • Minimise the use of unmanaged code.
    private static extern IntPtr ILCreateFromPathW(string pszPath);

Ra3.BattleNet.Downloader/Download.cs:158

  • Minimise the use of unmanaged code.
    private static extern int SHOpenFolderAndSelectItems(IntPtr pidlList, uint cild, IntPtr children, uint dwFlags);

Ra3.BattleNet.Downloader/Download.cs:79

  • This assignment to downloadedFile is useless, since its value is never read.
        var downloadedFile = await taskSource.Task;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

DhtEndPoint = null,
};
settingsBuilder.ListenEndPoints.Clear();
var engine = new ClientEngine(settingsBuilder.ToSettings());
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disposable 'ClientEngine' is created but not disposed.

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

2 participants