aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
diff options
context:
space:
mode:
authorTavares André <tavares_and@hotmail.com>2015-04-30 18:20:10 +0200
committerTavares André <tavares_and@hotmail.com>2015-04-30 18:20:10 +0200
commitfcb2bc2c8e37e75ffbd324bf242eed5eb4372fb5 (patch)
treeb79635656f847f4920acdfa3c0910c2ce2c2c36c /MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
parentadc52db15a497a003cbea77cf11d907390390e96 (diff)
parenta4e28a60a4de902ef58ecfef54cb56250c23e5e7 (diff)
Merge branch 'dev' of https://github.com/MediaBrowser/MediaBrowser into dev
Diffstat (limited to 'MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs')
-rw-r--r--MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs49
1 files changed, 35 insertions, 14 deletions
diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
index 3fa0df760..b5b63181a 100644
--- a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
+++ b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
@@ -1,5 +1,6 @@
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Logging;
using Mono.Nat;
@@ -7,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
+using System.Net;
using System.Text;
using System.Threading;
@@ -17,15 +19,17 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
private readonly IServerApplicationHost _appHost;
private readonly ILogger _logger;
private readonly IServerConfigurationManager _config;
+ private readonly ISsdpHandler _ssdp;
private Timer _timer;
private bool _isStarted;
- public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config)
+ public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config, ISsdpHandler ssdp)
{
_logger = logmanager.GetLogger("PortMapper");
_appHost = appHost;
_config = config;
+ _ssdp = ssdp;
}
private string _lastConfigIdentifier;
@@ -75,7 +79,10 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
private void Start()
{
_logger.Debug("Starting NAT discovery");
-
+ NatUtility.EnabledProtocols = new List<NatProtocol>
+ {
+ NatProtocol.Pmp
+ };
NatUtility.DeviceFound += NatUtility_DeviceFound;
// Mono.Nat does never rise this event. The event is there however it is useless.
@@ -88,26 +95,38 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
NatUtility.UnhandledException += NatUtility_UnhandledException;
NatUtility.StartDiscovery();
- _timer = new Timer(s => _createdRules = new List<string>(), null, TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3));
+ _timer = new Timer(s => _createdRules = new List<string>(), null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
+
+ _ssdp.MessageReceived += _ssdp_MessageReceived;
_lastConfigIdentifier = GetConfigIdentifier();
_isStarted = true;
}
+ void _ssdp_MessageReceived(object sender, SsdpMessageEventArgs e)
+ {
+ var endpoint = e.EndPoint as IPEndPoint;
+
+ if (endpoint != null && e.LocalIp != null)
+ {
+ NatUtility.Handle(e.LocalIp, e.Message, endpoint, NatProtocol.Upnp);
+ }
+ }
+
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);
- //}
+ 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)
@@ -180,6 +199,8 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_timer = null;
}
+ _ssdp.MessageReceived -= _ssdp_MessageReceived;
+
try
{
// This is not a significant improvement