updated Mono.Nat

This commit is contained in:
Luke Pulverenti 2015-04-29 14:48:34 -04:00
parent a75ce4197d
commit 32320b329a
20 changed files with 122 additions and 92 deletions

View File

@ -48,9 +48,9 @@
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog, Version=3.2.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<Reference Include="NLog, Version=3.2.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NLog.3.2.0.0\lib\net45\NLog.dll</HintPath>
<HintPath>..\packages\NLog.3.2.1\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="SharpCompress, Version=0.10.2.0, Culture=neutral, PublicKeyToken=beaf6f427e128133, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="3.2.0.0" targetFramework="net45" />
<package id="NLog" version="3.2.1" targetFramework="net45" />
<package id="SimpleInjector" version="2.7.0" targetFramework="net45" />
</packages>

View File

@ -0,0 +1,9 @@
using System;
namespace MediaBrowser.Controller.Dlna
{
public interface ISsdpHandler
{
event EventHandler<SsdpMessageEventArgs> MessageReceived;
}
}

View File

@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Net;
namespace MediaBrowser.Dlna.Ssdp
namespace MediaBrowser.Controller.Dlna
{
public class SsdpMessageEventArgs
{
@ -13,6 +13,7 @@ namespace MediaBrowser.Dlna.Ssdp
public Dictionary<string, string> Headers { get; set; }
public IPAddress LocalIp { get; set; }
public byte[] Message { get; set; }
public SsdpMessageEventArgs()
{

View File

@ -116,7 +116,9 @@
<Compile Include="Dlna\IDlnaManager.cs" />
<Compile Include="Dlna\IEventManager.cs" />
<Compile Include="Dlna\IMediaReceiverRegistrar.cs" />
<Compile Include="Dlna\ISsdpHandler.cs" />
<Compile Include="Dlna\IUpnpService.cs" />
<Compile Include="Dlna\SsdpMessageEventArgs.cs" />
<Compile Include="Drawing\IImageProcessor.cs" />
<Compile Include="Drawing\ImageCollageOptions.cs" />
<Compile Include="Drawing\ImageProcessingOptions.cs" />

View File

@ -2,6 +2,7 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Dlna.ContentDirectory;
using MediaBrowser.Dlna.PlayTo;

View File

@ -37,13 +37,26 @@ namespace MediaBrowser.Dlna.Main
private readonly ILocalizationManager _localization;
private readonly IMediaSourceManager _mediaSourceManager;
private SsdpHandler _ssdpHandler;
private readonly SsdpHandler _ssdpHandler;
private DeviceDiscovery _deviceDiscovery;
private readonly List<string> _registeredServerIds = new List<string>();
private bool _dlnaServerStarted;
public DlnaEntryPoint(IServerConfigurationManager config, ILogManager logManager, IServerApplicationHost appHost, INetworkManager network, ISessionManager sessionManager, IHttpClient httpClient, ILibraryManager libraryManager, IUserManager userManager, IDlnaManager dlnaManager, IImageProcessor imageProcessor, IUserDataManager userDataManager, ILocalizationManager localization, IMediaSourceManager mediaSourceManager)
public DlnaEntryPoint(IServerConfigurationManager config,
ILogManager logManager,
IServerApplicationHost appHost,
INetworkManager network,
ISessionManager sessionManager,
IHttpClient httpClient,
ILibraryManager libraryManager,
IUserManager userManager,
IDlnaManager dlnaManager,
IImageProcessor imageProcessor,
IUserDataManager userDataManager,
ILocalizationManager localization,
IMediaSourceManager mediaSourceManager,
ISsdpHandler ssdpHandler)
{
_config = config;
_appHost = appHost;
@ -57,6 +70,7 @@ namespace MediaBrowser.Dlna.Main
_userDataManager = userDataManager;
_localization = localization;
_mediaSourceManager = mediaSourceManager;
_ssdpHandler = (SsdpHandler)ssdpHandler;
_logger = logManager.GetLogger("Dlna");
}
@ -109,8 +123,6 @@ namespace MediaBrowser.Dlna.Main
{
try
{
_ssdpHandler = new SsdpHandler(_logger, _config, GenerateServerSignature());
_ssdpHandler.Start();
_deviceDiscovery = new DeviceDiscovery(_logger, _config, _ssdpHandler, _appHost);
@ -123,7 +135,7 @@ namespace MediaBrowser.Dlna.Main
}
}
private void DisposeSsdpHandler()
private void DisposeDeviceDiscovery()
{
try
{
@ -133,15 +145,6 @@ namespace MediaBrowser.Dlna.Main
{
_logger.ErrorException("Error disposing device discovery", ex);
}
try
{
_ssdpHandler.Dispose();
}
catch (Exception ex)
{
_logger.ErrorException("Error disposing ssdp handler", ex);
}
}
public void StartDlnaServer()
@ -184,29 +187,6 @@ namespace MediaBrowser.Dlna.Main
}
}
private string GenerateServerSignature()
{
var os = Environment.OSVersion;
var pstring = os.Platform.ToString();
switch (os.Platform)
{
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
pstring = "WIN";
break;
}
return String.Format(
"{0}{1}/{2}.{3} UPnP/1.0 DLNADOC/1.5 MediaBrowser/{4}",
pstring,
IntPtr.Size * 8,
os.Version.Major,
os.Version.Minor,
_appHost.ApplicationVersion
);
}
private readonly object _syncLock = new object();
private void StartPlayToManager()
{
@ -260,7 +240,7 @@ namespace MediaBrowser.Dlna.Main
{
DisposeDlnaServer();
DisposePlayToManager();
DisposeSsdpHandler();
DisposeDeviceDiscovery();
}
public void DisposeDlnaServer()

View File

@ -135,7 +135,6 @@
<Compile Include="Server\Headers.cs" />
<Compile Include="Server\UpnpDevice.cs" />
<Compile Include="Ssdp\SsdpMessageBuilder.cs" />
<Compile Include="Ssdp\SsdpMessageEventArgs.cs" />
<Compile Include="Ssdp\SsdpHandler.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -2,6 +2,7 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
@ -183,7 +184,6 @@ namespace MediaBrowser.Dlna.Ssdp
}
}, _tokenSource.Token, TaskCreationOptions.LongRunning);
}
private Socket GetMulticastSocket(IPAddress localIpAddress, EndPoint localEndpoint)

View File

@ -1,6 +1,8 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Events;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Dlna.Server;
using MediaBrowser.Model.Logging;
using System;
@ -16,7 +18,7 @@ using System.Threading.Tasks;
namespace MediaBrowser.Dlna.Ssdp
{
public class SsdpHandler : IDisposable
public class SsdpHandler : IDisposable, ISsdpHandler
{
private Socket _socket;
@ -39,13 +41,39 @@ namespace MediaBrowser.Dlna.Ssdp
private bool _isDisposed;
private readonly ConcurrentDictionary<Guid, List<UpnpDevice>> _devices = new ConcurrentDictionary<Guid, List<UpnpDevice>>();
public SsdpHandler(ILogger logger, IServerConfigurationManager config, string serverSignature)
private readonly IApplicationHost _appHost;
public SsdpHandler(ILogger logger, IServerConfigurationManager config, IApplicationHost appHost)
{
_logger = logger;
_config = config;
_serverSignature = serverSignature;
_appHost = appHost;
_config.NamedConfigurationUpdated += _config_ConfigurationUpdated;
_serverSignature = GenerateServerSignature();
}
private string GenerateServerSignature()
{
var os = Environment.OSVersion;
var pstring = os.Platform.ToString();
switch (os.Platform)
{
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
pstring = "WIN";
break;
}
return String.Format(
"{0}{1}/{2}.{3} UPnP/1.0 DLNADOC/1.5 MediaBrowser/{4}",
pstring,
IntPtr.Size * 8,
os.Version.Major,
os.Version.Minor,
_appHost.ApplicationVersion
);
}
void _config_ConfigurationUpdated(object sender, ConfigurationUpdateEventArgs e)

View File

@ -1,4 +1,5 @@
using System;
using MediaBrowser.Controller.Dlna;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
@ -34,7 +35,8 @@ namespace MediaBrowser.Dlna.Ssdp
return new SsdpMessageEventArgs
{
Method = method,
Headers = headers
Headers = headers,
Message = data
};
}
}

View File

@ -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,10 +79,10 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
private void Start()
{
_logger.Debug("Starting NAT discovery");
//NatUtility.EnabledProtocols = new List<NatProtocol>
//{
// NatProtocol.Pmp
//};
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.
@ -93,11 +97,23 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_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;
@ -183,6 +199,8 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_timer = null;
}
_ssdp.MessageReceived -= _ssdp_MessageReceived;
try
{
// This is not a significant improvement

View File

@ -8,7 +8,6 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.FileOrganization;
using MediaBrowser.Model.Logging;
using MediaBrowser.Naming.IO;
using MediaBrowser.Server.Implementations.Library;
using MediaBrowser.Server.Implementations.Logging;
using System;
@ -60,7 +59,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
var namingOptions = ((LibraryManager) _libraryManager).GetNamingOptions();
var resolver = new Naming.TV.EpisodeResolver(namingOptions, new PatternsLogger());
var episodeInfo = resolver.Resolve(path, FileInfoType.File) ??
var episodeInfo = resolver.Resolve(path, false) ??
new Naming.TV.EpisodeInfo();
var seriesName = episodeInfo.SeriesName;

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Extensions;
using Interfaces.IO;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Progress;
using MediaBrowser.Common.ScheduledTasks;
@ -17,7 +18,6 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Naming.Audio;
using MediaBrowser.Naming.Common;
using MediaBrowser.Naming.IO;
using MediaBrowser.Naming.TV;
using MediaBrowser.Naming.Video;
using MediaBrowser.Server.Implementations.Library.Validators;
@ -1767,14 +1767,13 @@ namespace MediaBrowser.Server.Implementations.Library
var resolver = new EpisodeResolver(GetNamingOptions(),
new PatternsLogger());
var fileType = episode.VideoType == VideoType.BluRay || episode.VideoType == VideoType.Dvd || episode.VideoType == VideoType.HdDvd ?
FileInfoType.Directory :
FileInfoType.File;
var isFolder = episode.VideoType == VideoType.BluRay || episode.VideoType == VideoType.Dvd ||
episode.VideoType == VideoType.HdDvd;
var locationType = episode.LocationType;
var episodeInfo = locationType == LocationType.FileSystem || locationType == LocationType.Offline ?
resolver.Resolve(episode.Path, fileType) :
resolver.Resolve(episode.Path, isFolder) :
new Naming.TV.EpisodeInfo();
if (episodeInfo == null)
@ -1928,10 +1927,10 @@ namespace MediaBrowser.Server.Implementations.Library
var videoListResolver = new VideoListResolver(GetNamingOptions(), new PatternsLogger());
var videos = videoListResolver.Resolve(fileSystemChildren.Select(i => new PortableFileInfo
var videos = videoListResolver.Resolve(fileSystemChildren.Select(i => new FileMetadata
{
FullName = i.FullName,
Type = GetFileType(i)
Id = i.FullName,
IsFolder = ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
}).ToList());
@ -1962,16 +1961,6 @@ namespace MediaBrowser.Server.Implementations.Library
}).OrderBy(i => i.Path).ToList();
}
private FileInfoType GetFileType(FileSystemInfo info)
{
if ((info.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
{
return FileInfoType.Directory;
}
return FileInfoType.File;
}
public IEnumerable<Video> FindExtras(BaseItem owner, List<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService)
{
var files = fileSystemChildren.OfType<DirectoryInfo>()
@ -1981,10 +1970,10 @@ namespace MediaBrowser.Server.Implementations.Library
var videoListResolver = new VideoListResolver(GetNamingOptions(), new PatternsLogger());
var videos = videoListResolver.Resolve(fileSystemChildren.Select(i => new PortableFileInfo
var videos = videoListResolver.Resolve(fileSystemChildren.Select(i => new FileMetadata
{
FullName = i.FullName,
Type = GetFileType(i)
Id = i.FullName,
IsFolder = ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
}).ToList());

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Entities;
using Interfaces.IO;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
@ -6,7 +7,6 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Naming.IO;
using MediaBrowser.Naming.Video;
using MediaBrowser.Server.Implementations.Logging;
using System;
@ -118,10 +118,10 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
var namingOptions = ((LibraryManager)LibraryManager).GetNamingOptions();
var resolver = new VideoListResolver(namingOptions, new PatternsLogger());
var resolverResult = resolver.Resolve(files.Select(i => new PortableFileInfo
var resolverResult = resolver.Resolve(files.Select(i => new FileMetadata
{
FullName = i.FullName,
Type = FileInfoType.File
Id = i.FullName,
IsFolder = false
}).ToList(), suppportMultiEditions).ToList();

View File

@ -6,7 +6,6 @@ using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Naming.Common;
using MediaBrowser.Naming.IO;
using MediaBrowser.Naming.TV;
using MediaBrowser.Server.Implementations.Logging;
using System;
@ -153,7 +152,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
}
var episodeResolver = new Naming.TV.EpisodeResolver(namingOptions, new PatternsLogger());
var episodeInfo = episodeResolver.Resolve(fullName, FileInfoType.File, false);
var episodeInfo = episodeResolver.Resolve(fullName, false, false);
if (episodeInfo != null && episodeInfo.EpisodeNumber.HasValue)
{
return true;

View File

@ -50,11 +50,11 @@
</Reference>
<Reference Include="MediaBrowser.Naming, Version=1.0.5509.27636, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\MediaBrowser.Naming.1.0.0.32\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll</HintPath>
<HintPath>..\packages\MediaBrowser.Naming.1.0.0.34\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll</HintPath>
</Reference>
<Reference Include="Mono.Nat, Version=1.2.23.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Mono.Nat, Version=1.2.24.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Mono.Nat.1.2.23.0\lib\net40\Mono.Nat.dll</HintPath>
<HintPath>..\packages\Mono.Nat.1.2.24.0\lib\net40\Mono.Nat.dll</HintPath>
</Reference>
<Reference Include="MoreLinq, Version=1.1.17511.0, Culture=neutral, PublicKeyToken=384d532d7e88985d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Interfaces.IO" version="1.0.0.5" targetFramework="net45" />
<package id="MediaBrowser.Naming" version="1.0.0.32" targetFramework="net45" />
<package id="Mono.Nat" version="1.2.23.0" targetFramework="net45" />
<package id="MediaBrowser.Naming" version="1.0.0.34" targetFramework="net45" />
<package id="Mono.Nat" version="1.2.24.0" targetFramework="net45" />
<package id="morelinq" version="1.1.0" targetFramework="net45" />
<package id="Patterns.Logging" version="1.0.0.2" targetFramework="net45" />
<package id="SocketHttpListener" version="1.0.0.5" targetFramework="net45" />

View File

@ -48,6 +48,7 @@ using MediaBrowser.Dlna.ConnectionManager;
using MediaBrowser.Dlna.ContentDirectory;
using MediaBrowser.Dlna.Main;
using MediaBrowser.Dlna.MediaReceiverRegistrar;
using MediaBrowser.Dlna.Ssdp;
using MediaBrowser.LocalMetadata.Providers;
using MediaBrowser.MediaEncoding.BdInfo;
using MediaBrowser.MediaEncoding.Encoder;
@ -520,6 +521,8 @@ namespace MediaBrowser.Server.Startup.Common
MediaEncoder, ChapterManager);
RegisterSingleInstance(EncodingManager);
RegisterSingleInstance<ISsdpHandler>(new SsdpHandler(LogManager.GetLogger("SsdpHandler"), ServerConfigurationManager, this));
var activityLogRepo = await GetActivityLogRepository().ConfigureAwait(false);
RegisterSingleInstance(activityLogRepo);
RegisterSingleInstance<IActivityManager>(new ActivityManager(LogManager.GetLogger("ActivityManager"), activityLogRepo, UserManager));

View File

@ -13,7 +13,7 @@
<copyright>Copyright © Emby 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.622" />
<dependency id="NLog" version="3.2.0.0" />
<dependency id="NLog" version="3.2.1" />
<dependency id="SimpleInjector" version="2.7.0" />
</dependencies>
</metadata>