mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 17:44:43 +01:00
reduce dlna chatter
This commit is contained in:
@@ -1901,9 +1901,9 @@ namespace Emby.Server.Implementations
|
||||
/// Gets the system status.
|
||||
/// </summary>
|
||||
/// <returns>SystemInfo.</returns>
|
||||
public async Task<SystemInfo> GetSystemInfo()
|
||||
public async Task<SystemInfo> GetSystemInfo(CancellationToken cancellationToken)
|
||||
{
|
||||
var localAddress = await GetLocalApiUrl().ConfigureAwait(false);
|
||||
var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return new SystemInfo
|
||||
{
|
||||
@@ -1955,12 +1955,12 @@ namespace Emby.Server.Implementations
|
||||
get { return Certificate != null || ServerConfigurationManager.Configuration.IsBehindProxy; }
|
||||
}
|
||||
|
||||
public async Task<string> GetLocalApiUrl()
|
||||
public async Task<string> GetLocalApiUrl(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Return the first matched address, if found, or the first known local address
|
||||
var address = (await GetLocalIpAddresses().ConfigureAwait(false)).FirstOrDefault(i => !i.Equals(IpAddressInfo.Loopback) && !i.Equals(IpAddressInfo.IPv6Loopback));
|
||||
var address = (await GetLocalIpAddresses(cancellationToken).ConfigureAwait(false)).FirstOrDefault(i => !i.Equals(IpAddressInfo.Loopback) && !i.Equals(IpAddressInfo.IPv6Loopback));
|
||||
|
||||
if (address != null)
|
||||
{
|
||||
@@ -1994,7 +1994,7 @@ namespace Emby.Server.Implementations
|
||||
HttpPort.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
public async Task<List<IpAddressInfo>> GetLocalIpAddresses()
|
||||
public async Task<List<IpAddressInfo>> GetLocalIpAddresses(CancellationToken cancellationToken)
|
||||
{
|
||||
var addresses = ServerConfigurationManager
|
||||
.Configuration
|
||||
@@ -2011,7 +2011,7 @@ namespace Emby.Server.Implementations
|
||||
|
||||
foreach (var address in addresses)
|
||||
{
|
||||
var valid = await IsIpAddressValidAsync(address).ConfigureAwait(false);
|
||||
var valid = await IsIpAddressValidAsync(address, cancellationToken).ConfigureAwait(false);
|
||||
if (valid)
|
||||
{
|
||||
list.Add(address);
|
||||
@@ -2043,7 +2043,7 @@ namespace Emby.Server.Implementations
|
||||
|
||||
private readonly ConcurrentDictionary<string, bool> _validAddressResults = new ConcurrentDictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
|
||||
private DateTime _lastAddressCacheClear;
|
||||
private async Task<bool> IsIpAddressValidAsync(IpAddressInfo address)
|
||||
private async Task<bool> IsIpAddressValidAsync(IpAddressInfo address, CancellationToken cancellationToken)
|
||||
{
|
||||
if (address.Equals(IpAddressInfo.Loopback) ||
|
||||
address.Equals(IpAddressInfo.IPv6Loopback))
|
||||
@@ -2075,7 +2075,9 @@ namespace Emby.Server.Implementations
|
||||
LogErrors = false,
|
||||
LogRequest = false,
|
||||
TimeoutMs = 30000,
|
||||
BufferContent = false
|
||||
BufferContent = false,
|
||||
|
||||
CancellationToken = cancellationToken
|
||||
|
||||
}, "POST").ConfigureAwait(false))
|
||||
{
|
||||
@@ -2090,6 +2092,10 @@ namespace Emby.Server.Implementations
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Logger.Debug("Ping test result to {0}. Success: {1}", apiUrl, false);
|
||||
|
||||
@@ -13,6 +13,7 @@ using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Threading;
|
||||
using Mono.Nat;
|
||||
using MediaBrowser.Model.Extensions;
|
||||
using System.Threading;
|
||||
|
||||
namespace Emby.Server.Implementations.EntryPoints
|
||||
{
|
||||
@@ -158,7 +159,7 @@ namespace Emby.Server.Implementations.EntryPoints
|
||||
|
||||
try
|
||||
{
|
||||
var localAddressString = await _appHost.GetLocalApiUrl().ConfigureAwait(false);
|
||||
var localAddressString = await _appHost.GetLocalApiUrl(CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
Uri uri;
|
||||
if (Uri.TryCreate(localAddressString, UriKind.Absolute, out uri))
|
||||
|
||||
@@ -191,7 +191,8 @@ namespace Emby.Server.Implementations.Library
|
||||
{
|
||||
ItemFields.AirTime,
|
||||
ItemFields.DateCreated,
|
||||
ItemFields.ChannelInfo
|
||||
ItemFields.ChannelInfo,
|
||||
ItemFields.ParentId
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -815,7 +815,7 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
var text = new StringBuilder();
|
||||
|
||||
var localAddress = _appHost.GetLocalApiUrl().Result ?? string.Empty;
|
||||
var localAddress = _appHost.GetLocalApiUrl(CancellationToken.None).Result ?? string.Empty;
|
||||
|
||||
text.AppendLine("Use your web browser to visit:");
|
||||
text.AppendLine(string.Empty);
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
}
|
||||
|
||||
var list = sources.ToList();
|
||||
var serverUrl = await _appHost.GetLocalApiUrl().ConfigureAwait(false);
|
||||
var serverUrl = await _appHost.GetLocalApiUrl(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
foreach (var source in list)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ using MediaBrowser.Model.Extensions;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Net;
|
||||
using System.Threading;
|
||||
|
||||
namespace Emby.Server.Implementations.Networking
|
||||
{
|
||||
@@ -37,7 +38,7 @@ namespace Emby.Server.Implementations.Networking
|
||||
|
||||
if (_localIpAddresses == null || forceRefresh)
|
||||
{
|
||||
var addresses = GetLocalIpAddressesInternal().Select(ToIpAddressInfo).ToList();
|
||||
var addresses = GetLocalIpAddressesInternal().Result.Select(ToIpAddressInfo).ToList();
|
||||
|
||||
_localIpAddresses = addresses;
|
||||
_lastRefresh = DateTime.UtcNow;
|
||||
@@ -49,14 +50,14 @@ namespace Emby.Server.Implementations.Networking
|
||||
return _localIpAddresses;
|
||||
}
|
||||
|
||||
private IEnumerable<IPAddress> GetLocalIpAddressesInternal()
|
||||
private async Task<List<IPAddress>> GetLocalIpAddressesInternal()
|
||||
{
|
||||
var list = GetIPsDefault()
|
||||
.ToList();
|
||||
|
||||
if (list.Count == 0)
|
||||
{
|
||||
list.AddRange(GetLocalIpAddressesFallback().Result);
|
||||
list.AddRange(await GetLocalIpAddressesFallback().ConfigureAwait(false));
|
||||
}
|
||||
|
||||
var listClone = list.ToList();
|
||||
@@ -65,7 +66,8 @@ namespace Emby.Server.Implementations.Networking
|
||||
.OrderBy(i => i.AddressFamily == AddressFamily.InterNetwork ? 0 : 1)
|
||||
.ThenBy(i => listClone.IndexOf(i))
|
||||
.Where(FilterIpAddress)
|
||||
.DistinctBy(i => i.ToString());
|
||||
.DistinctBy(i => i.ToString())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private bool FilterIpAddress(IPAddress address)
|
||||
|
||||
@@ -1182,7 +1182,7 @@ namespace Emby.Server.Implementations.Session
|
||||
{
|
||||
var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null).ToList();
|
||||
|
||||
var info = await _appHost.GetSystemInfo().ConfigureAwait(false);
|
||||
var info = await _appHost.GetSystemInfo(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var tasks = sessions.Select(session => Task.Run(async () =>
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Social;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Emby.Server.Implementations.Social
|
||||
@@ -42,7 +43,7 @@ namespace Emby.Server.Implementations.Social
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
var externalUrl = (await _appHost.GetSystemInfo().ConfigureAwait(false)).WanAddress;
|
||||
var externalUrl = (await _appHost.GetSystemInfo(CancellationToken.None).ConfigureAwait(false)).WanAddress;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(externalUrl))
|
||||
{
|
||||
@@ -73,7 +74,7 @@ namespace Emby.Server.Implementations.Social
|
||||
{
|
||||
var info = _repository.GetShareInfo(id);
|
||||
|
||||
AddShareInfo(info, _appHost.GetSystemInfo().Result.WanAddress);
|
||||
AddShareInfo(info, _appHost.GetSystemInfo(CancellationToken.None).Result.WanAddress);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Emby.Server.Implementations.Udp
|
||||
|
||||
private bool _isDisposed;
|
||||
|
||||
private readonly List<Tuple<string, bool, Func<string, IpEndPointInfo, Encoding, Task>>> _responders = new List<Tuple<string, bool, Func<string, IpEndPointInfo, Encoding, Task>>>();
|
||||
private readonly List<Tuple<string, bool, Func<string, IpEndPointInfo, Encoding, CancellationToken, Task>>> _responders = new List<Tuple<string, bool, Func<string, IpEndPointInfo, Encoding, CancellationToken, Task>>>();
|
||||
|
||||
private readonly IServerApplicationHost _appHost;
|
||||
private readonly IJsonSerializer _json;
|
||||
@@ -44,9 +44,9 @@ namespace Emby.Server.Implementations.Udp
|
||||
AddMessageResponder("who is MediaBrowserServer_v2?", false, RespondToV2Message);
|
||||
}
|
||||
|
||||
private void AddMessageResponder(string message, bool isSubstring, Func<string, IpEndPointInfo, Encoding, Task> responder)
|
||||
private void AddMessageResponder(string message, bool isSubstring, Func<string, IpEndPointInfo, Encoding, CancellationToken, Task> responder)
|
||||
{
|
||||
_responders.Add(new Tuple<string, bool, Func<string, IpEndPointInfo, Encoding, Task>>(message, isSubstring, responder));
|
||||
_responders.Add(new Tuple<string, bool, Func<string, IpEndPointInfo, Encoding, CancellationToken, Task>>(message, isSubstring, responder));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,9 +67,15 @@ namespace Emby.Server.Implementations.Udp
|
||||
|
||||
if (responder != null)
|
||||
{
|
||||
var cancellationToken = CancellationToken.None;
|
||||
|
||||
try
|
||||
{
|
||||
await responder.Item2.Item3(responder.Item1, message.RemoteEndPoint, encoding).ConfigureAwait(false);
|
||||
await responder.Item2.Item3(responder.Item1, message.RemoteEndPoint, encoding, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -78,7 +84,7 @@ namespace Emby.Server.Implementations.Udp
|
||||
}
|
||||
}
|
||||
|
||||
private Tuple<string, Tuple<string, bool, Func<string, IpEndPointInfo, Encoding, Task>>> GetResponder(byte[] buffer, int bytesReceived, Encoding encoding)
|
||||
private Tuple<string, Tuple<string, bool, Func<string, IpEndPointInfo, Encoding, CancellationToken, Task>>> GetResponder(byte[] buffer, int bytesReceived, Encoding encoding)
|
||||
{
|
||||
var text = encoding.GetString(buffer, 0, bytesReceived);
|
||||
var responder = _responders.FirstOrDefault(i =>
|
||||
@@ -94,14 +100,14 @@ namespace Emby.Server.Implementations.Udp
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Tuple<string, Tuple<string, bool, Func<string, IpEndPointInfo, Encoding, Task>>>(text, responder);
|
||||
return new Tuple<string, Tuple<string, bool, Func<string, IpEndPointInfo, Encoding, CancellationToken, Task>>>(text, responder);
|
||||
}
|
||||
|
||||
private async Task RespondToV2Message(string messageText, IpEndPointInfo endpoint, Encoding encoding)
|
||||
private async Task RespondToV2Message(string messageText, IpEndPointInfo endpoint, Encoding encoding, CancellationToken cancellationToken)
|
||||
{
|
||||
var parts = messageText.Split('|');
|
||||
|
||||
var localUrl = await _appHost.GetLocalApiUrl().ConfigureAwait(false);
|
||||
var localUrl = await _appHost.GetLocalApiUrl(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (!string.IsNullOrEmpty(localUrl))
|
||||
{
|
||||
@@ -112,7 +118,7 @@ namespace Emby.Server.Implementations.Udp
|
||||
Name = _appHost.FriendlyName
|
||||
};
|
||||
|
||||
await SendAsync(encoding.GetBytes(_json.SerializeToString(response)), endpoint).ConfigureAwait(false);
|
||||
await SendAsync(encoding.GetBytes(_json.SerializeToString(response)), endpoint, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (parts.Length > 1)
|
||||
{
|
||||
@@ -248,7 +254,7 @@ namespace Emby.Server.Implementations.Udp
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SendAsync(byte[] bytes, IpEndPointInfo remoteEndPoint)
|
||||
public async Task SendAsync(byte[] bytes, IpEndPointInfo remoteEndPoint, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
@@ -267,7 +273,7 @@ namespace Emby.Server.Implementations.Udp
|
||||
|
||||
try
|
||||
{
|
||||
await _udpClient.SendToAsync(bytes, 0, bytes.Length, remoteEndPoint, CancellationToken.None).ConfigureAwait(false);
|
||||
await _udpClient.SendToAsync(bytes, 0, bytes.Length, remoteEndPoint, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
_logger.Info("Udp message sent to {0}", remoteEndPoint);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user