#nullable enable
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using MediaBrowser.Model.Configuration;
using Microsoft.AspNetCore.Http;
using NetworkCollection;
namespace MediaBrowser.Common.Net
{
///
/// Interface for the NetworkManager class.
///
public interface INetworkManager
{
///
/// Event triggered on network changes.
///
event EventHandler NetworkChanged;
///
/// Gets the published server urls list.
///
Dictionary PublishedServerUrls { get; }
///
/// Gets a value indicating whether is all IPv6 interfaces are trusted as internal.
///
public bool TrustAllIP6Interfaces { get; }
///
/// Gets the remote address filter.
///
NetCollection RemoteAddressFilter { get; }
///
/// Calculates the list of interfaces to use for Kestrel.
///
/// A NetCollection object containing all the interfaces to bind.
/// If all the interfaces are specified, and none are excluded, it returns zero items
/// to represent any address.
NetCollection GetAllBindInterfaces();
///
/// Returns a collection containing the loopback interfaces.
///
/// Netcollection.
public NetCollection GetLoopbacks();
///
/// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo)
/// If no bind addresses are specified, an internal interface address is selected.
/// The priority of selection is as follows:-
///
/// The value contained in the startup parameter --published-server-url.
///
/// If the user specified custom subnet overrides, the correct subnet for the source address.
///
/// If the user specified bind interfaces to use:-
/// The bind interface that contains the source subnet.
/// The first bind interface specified that suits best first the source's endpoint. eg. external or internal.
///
/// If the source is from a public subnet address range and the user hasn't specified any bind addresses:-
/// The first public interface that isn't a loopback and contains the source subnet.
/// The first public interface that isn't a loopback. Priority is given to interfaces with gateways.
/// An internal interface if there are no public ip addresses.
///
/// If the source is from a private subnet address range and the user hasn't specified any bind addresses:-
/// The first private interface that contains the source subnet.
/// The first private interface that isn't a loopback. Priority is given to interfaces with gateways.
///
/// If no interfaces meet any of these criteria, then a loopback address is returned.
///
/// Interface that have been specifically excluded from binding are not used in any of the calculations.
///
/// Source of the request.
/// Optional port returned, if it's part of an override.
/// IP Address to use, or loopback address if all else fails.
string GetBindInterface(IPObject source, out int? port);
///
/// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo)
/// If no bind addresses are specified, an internal interface address is selected.
/// (See above).
///
/// Source of the request.
/// Optional port returned, if it's part of an override.
/// IP Address to use, or loopback address if all else fails.
string GetBindInterface(HttpRequest source, out int? port);
///
/// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo)
/// If no bind addresses are specified, an internal interface address is selected.
/// (See above).
///
/// IP address of the request.
/// Optional port returned, if it's part of an override.
/// IP Address to use, or loopback address if all else fails.
string GetBindInterface(IPAddress source, out int? port);
///
/// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo)
/// If no bind addresses are specified, an internal interface address is selected.
/// (See above).
///
/// Source of the request.
/// Optional port returned, if it's part of an override.
/// IP Address to use, or loopback address if all else fails.
string GetBindInterface(string source, out int? port);
///
/// Checks to see if the ip address is specifically excluded in LocalNetworkAddresses.
///
/// IP address to check.
/// True if it is.
bool IsExcludedInterface(IPAddress address);
///
/// Get a list of all the MAC addresses associated with active interfaces.
///
/// List of MAC addresses.
List GetMacAddresses();
///
/// Checks to see if the IP Address provided matches an interface that has a gateway.
///
/// IP to check. Can be an IPAddress or an IPObject.
/// Result of the check.
public bool IsGatewayInterface(object? addressObj);
///
/// Returns true if the address is a private address.
/// The config option TrustIP6Interfaces overrides this functions behaviour.
///
/// Address to check.
/// True or False.
bool IsPrivateAddressRange(IPObject address);
///
/// Returns true if the address is part of the user defined LAN.
/// The config option TrustIP6Interfaces overrides this functions behaviour.
///
/// IP to check.
/// True if endpoint is within the LAN range.
bool IsInLocalNetwork(string address);
///
/// Returns true if the address is part of the user defined LAN.
/// The config option TrustIP6Interfaces overrides this functions behaviour.
///
/// IP to check.
/// True if endpoint is within the LAN range.
bool IsInLocalNetwork(IPObject address);
///
/// Returns true if the address is part of the user defined LAN.
/// The config option TrustIP6Interfaces overrides this functions behaviour.
///
/// IP to check.
/// True if endpoint is within the LAN range.
bool IsInLocalNetwork(IPAddress address);
///
/// Attempts to convert the token to an IP address, permitting for interface descriptions and indexes.
/// eg. "eth1", or "TP-LINK Wireless USB Adapter".
///
/// Token to parse.
/// Resultant object if successful.
/// Success of the operation.
bool TryParseInterface(string token, out IPNetAddress result);
///
/// Parses an array of strings into a NetCollection.
///
/// Values to parse.
/// When true, only include values in []. When false, ignore bracketed values.
/// IPCollection object containing the value strings.
NetCollection CreateIPCollection(string[] values, bool bracketed = false);
///
/// Returns all the internal Bind interface addresses.
///
/// An internal list of interfaces addresses.
NetCollection GetInternalBindAddresses();
///
/// Checks to see if an IP address is still a valid interface address.
///
/// IP address to check.
/// True if it is.
bool IsValidInterfaceAddress(IPAddress address);
///
/// Returns true if the IP address is in the excluded list.
///
/// IP to check.
/// True if excluded.
bool IsExcluded(IPAddress ip);
///
/// Returns true if the IP address is in the excluded list.
///
/// IP to check.
/// True if excluded.
bool IsExcluded(EndPoint ip);
///
/// Gets the filtered LAN ip addresses.
///
/// Optional filter for the list.
/// Returns a filtered list of LAN addresses.
NetCollection GetFilteredLANSubnets(NetCollection? filter = null);
///
/// Reloads all settings and re-initialises the instance.
///
/// to use.
public void UpdateSettings(ServerConfiguration config);
}
}