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

UPnP support #7

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

carlosjdelgado
Copy link
Contributor

If feature is added in client configuration, automatically open port just when TCP transport start listening. It uses Open.Nat library for UPnP functionality.

@ffMathy
Copy link

ffMathy commented Dec 14, 2019

This is really cool. I hope this framework is not dead. CC @SamuelFisher.

Copy link
Owner

@SamuelFisher SamuelFisher left a comment

Choose a reason for hiding this comment

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

Hi, apologies for the very long delay with looking at this.

This is a great addition to have UPnP support, however I understand if you're not interest in progressing this any further due to the delay - if so, please ignore my comments!

Comment on lines +15 to +17
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
Copy link
Owner

Choose a reason for hiding this comment

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

This looks unnecessary, can you remove it?

@@ -25,6 +25,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Open.NAT.Core" Version="2.1.0" />
Copy link
Owner

Choose a reason for hiding this comment

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

This library looks to be based on Mono.Nat which seems to have more usage. Would it be better to use the Mono library instead of this fork?

var cts = new CancellationTokenSource(10000);

var device = await discoverer.DiscoverDeviceAsync(PortMapper.Upnp, cts);
await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, port, port, "TorrentCore"));
Copy link
Owner

Choose a reason for hiding this comment

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

This doesn't take into consideration which IP the application is listening on (TorrentClientSettings.AdapterAddress).

For context, AdapterAddress is used for situations such as forcing TorrentCore to run over a VPN connection. In this situation it could end up adding the mapping onto a network the user specifically doesn't want TorrentCore to be using.

}
catch
{
// Do nothing
Copy link
Owner

Choose a reason for hiding this comment

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

What type of exceptions does this throw? It could do with some logging to indicate something has gone wrong.

@@ -40,6 +41,7 @@ public TcpTransportProtocol(ILogger<TcpTransportProtocol> logger, IOptions<Local
_logger = logger;
_streams = new ConcurrentBag<TcpTransportStream>();
Port = options.Value.Port;
_uPnPClient = new TcpTransportUPnPClient(options.Value.UseUPnP);
Copy link
Owner

Choose a reason for hiding this comment

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

Could you register this in the DI container and inject it instead of creating it here? This will allow users more flexibility to change how UPnP is handled if required.

@carlosjdelgado
Copy link
Contributor Author

Hi, apologies for the very long delay with looking at this.

This is a great addition to have UPnP support, however I understand if you're not interest in progressing this any further due to the delay - if so, please ignore my comments!

Thank you for your comments. I'll take an eye when I come from my holidays because I am in my parent's house wich have not an upnp capable router for testing.

@carlosjdelgado
Copy link
Contributor Author

Hi @SamuelFisher, are you going to merge net6 version into master branch?

I was thinking about to continue developing this feature and I don't know if would be better to abandon this Pr and start over net6 branch or wait until net6 branch is merged into master.

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.

4 participants