aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations')
-rw-r--r--Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs25
-rw-r--r--Emby.Server.Implementations/Emby.Server.Implementations.csproj16
-rw-r--r--Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs17
-rw-r--r--Emby.Server.Implementations/Networking/NetworkManager.cs16
-rw-r--r--Emby.Server.Implementations/Updates/InstallationManager.cs84
5 files changed, 92 insertions, 66 deletions
diff --git a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs
index 4832c19c4..7ec5252d0 100644
--- a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs
+++ b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs
@@ -35,7 +35,7 @@ namespace Emby.Server.Implementations.AppBase
/// <summary>
/// The _configuration sync lock.
/// </summary>
- private object _configurationSyncLock = new object();
+ private readonly object _configurationSyncLock = new object();
/// <summary>
/// The _configuration.
@@ -98,16 +98,31 @@ namespace Emby.Server.Implementations.AppBase
public IApplicationPaths CommonApplicationPaths { get; private set; }
/// <summary>
- /// Gets the system configuration
+ /// Gets the system configuration.
/// </summary>
/// <value>The configuration.</value>
public BaseApplicationConfiguration CommonConfiguration
{
get
{
- // Lazy load
- LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationLoaded, ref _configurationSyncLock, () => (BaseApplicationConfiguration)ConfigurationHelper.GetXmlConfiguration(ConfigurationType, CommonApplicationPaths.SystemConfigurationFilePath, XmlSerializer));
- return _configuration;
+ if (_configurationLoaded)
+ {
+ return _configuration;
+ }
+
+ lock (_configurationSyncLock)
+ {
+ if (_configurationLoaded)
+ {
+ return _configuration;
+ }
+
+ _configuration = (BaseApplicationConfiguration)ConfigurationHelper.GetXmlConfiguration(ConfigurationType, CommonApplicationPaths.SystemConfigurationFilePath, XmlSerializer);
+
+ _configurationLoaded = true;
+
+ return _configuration;
+ }
}
protected set
{
diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj
index ea4444268..d6ca19e3f 100644
--- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj
+++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Emby.Naming\Emby.Naming.csproj" />
@@ -29,9 +29,9 @@
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.1" />
- <PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
- <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
- <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />
+ <PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.0" />
+ <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
+ <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.0.0" />
<PackageReference Include="ServiceStack.Text.Core" Version="5.6.0" />
<PackageReference Include="sharpcompress" Version="0.24.0" />
<PackageReference Include="SQLitePCL.pretty.netstandard" Version="2.0.1" />
@@ -47,16 +47,12 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
- <PropertyGroup>
- <!-- We need at least C# 7.3 to compare tuples-->
- <LangVersion>latest</LangVersion>
- </PropertyGroup>
-
<!-- Code analysers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4" />
- <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" />
+ <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
+ <PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" />
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
diff --git a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
index f26a70586..d55dc2f18 100644
--- a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
+++ b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs
@@ -27,6 +27,11 @@ namespace Emby.Server.Implementations.EntryPoints
private NatManager _natManager;
+ private readonly object _createdRulesLock = new object();
+ private List<string> _createdRules = new List<string>();
+ private readonly object _usnsHandledLock = new object();
+ private List<string> _usnsHandled = new List<string>();
+
public ExternalPortForwarding(ILoggerFactory loggerFactory, IServerApplicationHost appHost, IServerConfigurationManager config, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient)
{
_logger = loggerFactory.CreateLogger("PortMapper");
@@ -127,12 +132,13 @@ namespace Emby.Server.Implementations.EntryPoints
return;
}
- lock (_usnsHandled)
+ lock (_usnsHandledLock)
{
if (_usnsHandled.Contains(identifier))
{
return;
}
+
_usnsHandled.Add(identifier);
}
@@ -186,11 +192,12 @@ namespace Emby.Server.Implementations.EntryPoints
private void ClearCreatedRules(object state)
{
- lock (_createdRules)
+ lock (_createdRulesLock)
{
_createdRules.Clear();
}
- lock (_usnsHandled)
+
+ lock (_usnsHandledLock)
{
_usnsHandled.Clear();
}
@@ -216,8 +223,6 @@ namespace Emby.Server.Implementations.EntryPoints
}
}
- private List<string> _createdRules = new List<string>();
- private List<string> _usnsHandled = new List<string>();
private async void CreateRules(INatDevice device)
{
if (_disposed)
@@ -231,7 +236,7 @@ namespace Emby.Server.Implementations.EntryPoints
var addressString = address.ToString();
- lock (_createdRules)
+ lock (_createdRulesLock)
{
if (!_createdRules.Contains(addressString))
{
diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs
index 7d85a0666..d948dad68 100644
--- a/Emby.Server.Implementations/Networking/NetworkManager.cs
+++ b/Emby.Server.Implementations/Networking/NetworkManager.cs
@@ -20,6 +20,9 @@ namespace Emby.Server.Implementations.Networking
private IPAddress[] _localIpAddresses;
private readonly object _localIpAddressSyncLock = new object();
+ private readonly object _subnetLookupLock = new object();
+ private Dictionary<string, List<string>> _subnetLookup = new Dictionary<string, List<string>>(StringComparer.Ordinal);
+
public NetworkManager(ILogger<NetworkManager> logger)
{
_logger = logger;
@@ -28,10 +31,10 @@ namespace Emby.Server.Implementations.Networking
NetworkChange.NetworkAvailabilityChanged += OnNetworkAvailabilityChanged;
}
- public Func<string[]> LocalSubnetsFn { get; set; }
-
public event EventHandler NetworkChanged;
+ public Func<string[]> LocalSubnetsFn { get; set; }
+
private void OnNetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
_logger.LogDebug("NetworkAvailabilityChanged");
@@ -179,10 +182,9 @@ namespace Emby.Server.Implementations.Networking
return false;
}
- private Dictionary<string, List<string>> _subnetLookup = new Dictionary<string, List<string>>(StringComparer.Ordinal);
private List<string> GetSubnets(string endpointFirstPart)
{
- lock (_subnetLookup)
+ lock (_subnetLookupLock)
{
if (_subnetLookup.TryGetValue(endpointFirstPart, out var subnets))
{
@@ -200,7 +202,11 @@ namespace Emby.Server.Implementations.Networking
int subnet_Test = 0;
foreach (string part in unicastIPAddressInformation.IPv4Mask.ToString().Split('.'))
{
- if (part.Equals("0")) break;
+ if (part.Equals("0", StringComparison.Ordinal))
+ {
+ break;
+ }
+
subnet_Test++;
}
diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs
index 0c0c77cda..a1e2f9079 100644
--- a/Emby.Server.Implementations/Updates/InstallationManager.cs
+++ b/Emby.Server.Implementations/Updates/InstallationManager.cs
@@ -28,43 +28,10 @@ namespace Emby.Server.Implementations.Updates
/// </summary>
public class InstallationManager : IInstallationManager
{
- public event EventHandler<InstallationEventArgs> PackageInstalling;
- public event EventHandler<InstallationEventArgs> PackageInstallationCompleted;
- public event EventHandler<InstallationFailedEventArgs> PackageInstallationFailed;
- public event EventHandler<InstallationEventArgs> PackageInstallationCancelled;
-
- /// <summary>
- /// The current installations
- /// </summary>
- private List<(InstallationInfo info, CancellationTokenSource token)> _currentInstallations { get; set; }
-
/// <summary>
- /// The completed installations
- /// </summary>
- private ConcurrentBag<InstallationInfo> _completedInstallationsInternal;
-
- public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal;
-
- /// <summary>
- /// Occurs when [plugin uninstalled].
- /// </summary>
- public event EventHandler<GenericEventArgs<IPlugin>> PluginUninstalled;
-
- /// <summary>
- /// Occurs when [plugin updated].
- /// </summary>
- public event EventHandler<GenericEventArgs<(IPlugin, PackageVersionInfo)>> PluginUpdated;
-
- /// <summary>
- /// Occurs when [plugin updated].
- /// </summary>
- public event EventHandler<GenericEventArgs<PackageVersionInfo>> PluginInstalled;
-
- /// <summary>
- /// The _logger
+ /// The _logger.
/// </summary>
private readonly ILogger _logger;
-
private readonly IApplicationPaths _appPaths;
private readonly IHttpClient _httpClient;
private readonly IJsonSerializer _jsonSerializer;
@@ -79,6 +46,18 @@ namespace Emby.Server.Implementations.Updates
private readonly IZipClient _zipClient;
+ private readonly object _currentInstallationsLock = new object();
+
+ /// <summary>
+ /// The current installations.
+ /// </summary>
+ private List<(InstallationInfo info, CancellationTokenSource token)> _currentInstallations;
+
+ /// <summary>
+ /// The completed installations.
+ /// </summary>
+ private ConcurrentBag<InstallationInfo> _completedInstallationsInternal;
+
public InstallationManager(
ILogger<InstallationManager> logger,
IApplicationHost appHost,
@@ -107,6 +86,31 @@ namespace Emby.Server.Implementations.Updates
_zipClient = zipClient;
}
+ public event EventHandler<InstallationEventArgs> PackageInstalling;
+
+ public event EventHandler<InstallationEventArgs> PackageInstallationCompleted;
+
+ public event EventHandler<InstallationFailedEventArgs> PackageInstallationFailed;
+
+ public event EventHandler<InstallationEventArgs> PackageInstallationCancelled;
+
+ /// <summary>
+ /// Occurs when a plugin is uninstalled.
+ /// </summary>
+ public event EventHandler<GenericEventArgs<IPlugin>> PluginUninstalled;
+
+ /// <summary>
+ /// Occurs when a plugin plugin is updated.
+ /// </summary>
+ public event EventHandler<GenericEventArgs<(IPlugin, PackageVersionInfo)>> PluginUpdated;
+
+ /// <summary>
+ /// Occurs when a plugin plugin is installed.
+ /// </summary>
+ public event EventHandler<GenericEventArgs<PackageVersionInfo>> PluginInstalled;
+
+ public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal;
+
/// <summary>
/// Gets all available packages.
/// </summary>
@@ -330,7 +334,7 @@ namespace Emby.Server.Implementations.Updates
var tuple = (installationInfo, innerCancellationTokenSource);
// Add it to the in-progress list
- lock (_currentInstallations)
+ lock (_currentInstallationsLock)
{
_currentInstallations.Add(tuple);
}
@@ -349,7 +353,7 @@ namespace Emby.Server.Implementations.Updates
{
await InstallPackageInternal(package, linkedToken).ConfigureAwait(false);
- lock (_currentInstallations)
+ lock (_currentInstallationsLock)
{
_currentInstallations.Remove(tuple);
}
@@ -360,7 +364,7 @@ namespace Emby.Server.Implementations.Updates
}
catch (OperationCanceledException)
{
- lock (_currentInstallations)
+ lock (_currentInstallationsLock)
{
_currentInstallations.Remove(tuple);
}
@@ -375,7 +379,7 @@ namespace Emby.Server.Implementations.Updates
{
_logger.LogError(ex, "Package installation failed");
- lock (_currentInstallations)
+ lock (_currentInstallationsLock)
{
_currentInstallations.Remove(tuple);
}
@@ -535,7 +539,7 @@ namespace Emby.Server.Implementations.Updates
/// <inheritdoc/>
public bool CancelInstallation(Guid id)
{
- lock (_currentInstallations)
+ lock (_currentInstallationsLock)
{
var install = _currentInstallations.Find(x => x.Item1.Id == id);
if (install == default((InstallationInfo, CancellationTokenSource)))
@@ -563,7 +567,7 @@ namespace Emby.Server.Implementations.Updates
{
if (dispose)
{
- lock (_currentInstallations)
+ lock (_currentInstallationsLock)
{
foreach (var tuple in _currentInstallations)
{