aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/EntryPoints
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Server.Implementations/EntryPoints')
-rw-r--r--MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs3
-rw-r--r--MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs58
-rw-r--r--MediaBrowser.Server.Implementations/EntryPoints/LoadRegistrations.cs2
3 files changed, 31 insertions, 32 deletions
diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs b/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs
index 6e4451d96..de0719a62 100644
--- a/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs
+++ b/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs
@@ -4,11 +4,9 @@ using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Common.Updates;
using MediaBrowser.Controller;
-using MediaBrowser.Controller.Activity;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session;
using MediaBrowser.Controller.Subtitles;
@@ -21,6 +19,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using MediaBrowser.Model.Globalization;
namespace MediaBrowser.Server.Implementations.EntryPoints
{
diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
index fb5bdb790..9db49f97a 100644
--- a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
+++ b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
@@ -8,8 +8,9 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
-using MediaBrowser.Controller.Threading;
+using MediaBrowser.Common.Net;
using MediaBrowser.Model.Events;
+using MediaBrowser.Server.Implementations.Threading;
namespace MediaBrowser.Server.Implementations.EntryPoints
{
@@ -17,18 +18,20 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
{
private readonly IServerApplicationHost _appHost;
private readonly ILogger _logger;
+ private readonly IHttpClient _httpClient;
private readonly IServerConfigurationManager _config;
private readonly IDeviceDiscovery _deviceDiscovery;
private PeriodicTimer _timer;
private bool _isStarted;
- public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config, IDeviceDiscovery deviceDiscovery)
+ public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient)
{
_logger = logmanager.GetLogger("PortMapper");
_appHost = appHost;
_config = config;
_deviceDiscovery = deviceDiscovery;
+ _httpClient = httpClient;
}
private string _lastConfigIdentifier;
@@ -63,6 +66,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
public void Run()
{
NatUtility.Logger = _logger;
+ NatUtility.HttpClient = _httpClient;
if (_config.Configuration.EnableUPnP)
{
@@ -87,9 +91,6 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
NatUtility.DeviceLost += NatUtility_DeviceLost;
- // it is hard to say what one should do when an unhandled exception is raised
- // because there isn't anything one can do about it. Probably save a log or ignored it.
- NatUtility.UnhandledException += NatUtility_UnhandledException;
NatUtility.StartDiscovery();
_timer = new PeriodicTimer(ClearCreatedRules, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
@@ -136,7 +137,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_usnsHandled.Add(identifier);
}
- _logger.Debug("Calling Nat.Handle on " + identifier);
+ _logger.Debug("Found NAT device: " + identifier);
IPAddress address;
if (IPAddress.TryParse(info.Location.Host, out address))
@@ -150,16 +151,23 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
{
var localAddressString = await _appHost.GetLocalApiUrl().ConfigureAwait(false);
- if (!IPAddress.TryParse(localAddressString, out localAddress))
+ Uri uri;
+ if (Uri.TryCreate(localAddressString, UriKind.Absolute, out uri))
{
- return;
+ localAddressString = uri.Host;
+
+ if (!IPAddress.TryParse(localAddressString, out localAddress))
+ {
+ return;
+ }
}
}
- catch
+ catch (Exception ex)
{
return;
}
+ _logger.Debug("Calling Nat.Handle on " + identifier);
NatUtility.Handle(localAddress, info, endpoint, NatProtocol.Upnp);
}
}
@@ -173,21 +181,6 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
}
}
- void NatUtility_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- var ex = e.ExceptionObject as Exception;
-
- if (ex == null)
- {
- //_logger.Error("Unidentified error reported by Mono.Nat");
- }
- else
- {
- // Seeing some blank exceptions coming through here
- //_logger.ErrorException("Error reported by Mono.Nat: ", ex);
- }
- }
-
void NatUtility_DeviceFound(object sender, DeviceEventArgs e)
{
try
@@ -229,13 +222,21 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
}
}
- private void CreatePortMap(INatDevice device, int privatePort, int publicPort)
+ private async void CreatePortMap(INatDevice device, int privatePort, int publicPort)
{
_logger.Debug("Creating port map on port {0}", privatePort);
- device.CreatePortMap(new Mapping(Protocol.Tcp, privatePort, publicPort)
+
+ try
+ {
+ await device.CreatePortMap(new Mapping(Protocol.Tcp, privatePort, publicPort)
+ {
+ Description = _appHost.Name
+ }).ConfigureAwait(false);
+ }
+ catch (Exception ex)
{
- Description = _appHost.Name
- });
+ _logger.ErrorException("Error creating port map", ex);
+ }
}
// As I said before, this method will be never invoked. You can remove it.
@@ -268,7 +269,6 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
NatUtility.StopDiscovery();
NatUtility.DeviceFound -= NatUtility_DeviceFound;
NatUtility.DeviceLost -= NatUtility_DeviceLost;
- NatUtility.UnhandledException -= NatUtility_UnhandledException;
}
// Statements in try-block will no fail because StopDiscovery is a one-line
// method that was no chances to fail.
diff --git a/MediaBrowser.Server.Implementations/EntryPoints/LoadRegistrations.cs b/MediaBrowser.Server.Implementations/EntryPoints/LoadRegistrations.cs
index 38bf89c62..47f22cae6 100644
--- a/MediaBrowser.Server.Implementations/EntryPoints/LoadRegistrations.cs
+++ b/MediaBrowser.Server.Implementations/EntryPoints/LoadRegistrations.cs
@@ -3,7 +3,7 @@ using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Logging;
using System;
using System.Threading.Tasks;
-using MediaBrowser.Controller.Threading;
+using MediaBrowser.Server.Implementations.Threading;
namespace MediaBrowser.Server.Implementations.EntryPoints
{