|
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
|
|
using MediaBrowser.Common.Net;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using MediaBrowser.Model.Net;
|
|
|
+using MediaBrowser.Controller.Configuration;
|
|
|
|
|
|
namespace Rssdp.Infrastructure
|
|
|
{
|
|
@@ -45,6 +46,7 @@ namespace Rssdp.Infrastructure
|
|
|
private readonly ILogger _logger;
|
|
|
private ISocketFactory _SocketFactory;
|
|
|
private readonly INetworkManager _networkManager;
|
|
|
+ private readonly IServerConfigurationManager _config;
|
|
|
|
|
|
private int _LocalPort;
|
|
|
private int _MulticastTtl;
|
|
@@ -74,9 +76,11 @@ namespace Rssdp.Infrastructure
|
|
|
/// Minimum constructor.
|
|
|
/// </summary>
|
|
|
/// <exception cref="ArgumentNullException">The <paramref name="socketFactory"/> argument is null.</exception>
|
|
|
- public SsdpCommunicationsServer(ISocketFactory socketFactory, INetworkManager networkManager, ILogger logger, bool enableMultiSocketBinding)
|
|
|
+ public SsdpCommunicationsServer(IServerConfigurationManager config, ISocketFactory socketFactory,
|
|
|
+ INetworkManager networkManager, ILogger logger, bool enableMultiSocketBinding)
|
|
|
: this(socketFactory, 0, SsdpConstants.SsdpDefaultMulticastTimeToLive, networkManager, logger, enableMultiSocketBinding)
|
|
|
{
|
|
|
+ _config = config;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -236,15 +240,15 @@ namespace Rssdp.Infrastructure
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public Task SendMulticastMessage(string message, CancellationToken cancellationToken)
|
|
|
+ public Task SendMulticastMessage(string message, IpAddressInfo fromLocalIpAddress, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- return SendMulticastMessage(message, SsdpConstants.UdpResendCount, cancellationToken);
|
|
|
+ return SendMulticastMessage(message, SsdpConstants.UdpResendCount, fromLocalIpAddress, cancellationToken);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Sends a message to the SSDP multicast address and port.
|
|
|
/// </summary>
|
|
|
- public async Task SendMulticastMessage(string message, int sendCount, CancellationToken cancellationToken)
|
|
|
+ public async Task SendMulticastMessage(string message, int sendCount, IpAddressInfo fromLocalIpAddress, CancellationToken cancellationToken)
|
|
|
{
|
|
|
if (message == null) throw new ArgumentNullException(nameof(message));
|
|
|
|
|
@@ -264,7 +268,7 @@ namespace Rssdp.Infrastructure
|
|
|
IpAddress = new IpAddressInfo(SsdpConstants.MulticastLocalAdminAddress, IpAddressFamily.InterNetwork),
|
|
|
Port = SsdpConstants.MulticastPort
|
|
|
|
|
|
- }, cancellationToken).ConfigureAwait(false);
|
|
|
+ }, fromLocalIpAddress, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
|
|
|
}
|
|
@@ -332,14 +336,15 @@ namespace Rssdp.Infrastructure
|
|
|
|
|
|
#region Private Methods
|
|
|
|
|
|
- private Task SendMessageIfSocketNotDisposed(byte[] messageData, IpEndPointInfo destination, CancellationToken cancellationToken)
|
|
|
+ private Task SendMessageIfSocketNotDisposed(byte[] messageData, IpEndPointInfo destination, IpAddressInfo fromLocalIpAddress, CancellationToken cancellationToken)
|
|
|
{
|
|
|
var sockets = _sendSockets;
|
|
|
if (sockets != null)
|
|
|
{
|
|
|
sockets = sockets.ToList();
|
|
|
|
|
|
- var tasks = sockets.Select(s => SendFromSocket(s, messageData, destination, cancellationToken));
|
|
|
+ var tasks = sockets.Where(s => (fromLocalIpAddress == null || fromLocalIpAddress.Equals(s.LocalIPAddress)))
|
|
|
+ .Select(s => SendFromSocket(s, messageData, destination, cancellationToken));
|
|
|
return Task.WhenAll(tasks);
|
|
|
}
|
|
|
|
|
@@ -363,11 +368,11 @@ namespace Rssdp.Infrastructure
|
|
|
|
|
|
if (_enableMultiSocketBinding)
|
|
|
{
|
|
|
- foreach (var address in _networkManager.GetLocalIpAddresses())
|
|
|
+ foreach (var address in _networkManager.GetLocalIpAddresses(_config.Configuration.IgnoreVirtualInterfaces))
|
|
|
{
|
|
|
if (address.AddressFamily == IpAddressFamily.InterNetworkV6)
|
|
|
{
|
|
|
- // Not supported ?
|
|
|
+ // Not support IPv6 right now
|
|
|
continue;
|
|
|
}
|
|
|
|