mirror of
https://github.com/2dust/v2rayN.git
synced 2026-02-28 05:03:02 +00:00
Centralize active network info retrieval
This commit is contained in:
parent
b53507f486
commit
7931058342
8 changed files with 32 additions and 32 deletions
|
|
@ -629,12 +629,7 @@ public class Utils
|
|||
{
|
||||
try
|
||||
{
|
||||
List<IPEndPoint> lstIpEndPoints = new();
|
||||
List<TcpConnectionInformation> lstTcpConns = new();
|
||||
|
||||
lstIpEndPoints.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners());
|
||||
lstIpEndPoints.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners());
|
||||
lstTcpConns.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections());
|
||||
var (lstIpEndPoints, lstTcpConns) = GetActiveNetworkInfo();
|
||||
|
||||
if (lstIpEndPoints?.FindIndex(it => it.Port == port) >= 0)
|
||||
{
|
||||
|
|
@ -676,6 +671,27 @@ public class Utils
|
|||
return 59090;
|
||||
}
|
||||
|
||||
public static (List<IPEndPoint> endpoints, List<TcpConnectionInformation> connections) GetActiveNetworkInfo()
|
||||
{
|
||||
var endpoints = new List<IPEndPoint>();
|
||||
var connections = new List<TcpConnectionInformation>();
|
||||
|
||||
try
|
||||
{
|
||||
var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
|
||||
|
||||
endpoints.AddRange(ipGlobalProperties.GetActiveTcpListeners());
|
||||
endpoints.AddRange(ipGlobalProperties.GetActiveUdpListeners());
|
||||
connections.AddRange(ipGlobalProperties.GetActiveTcpConnections());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
|
||||
return (endpoints, connections);
|
||||
}
|
||||
|
||||
#endregion Speed Test
|
||||
|
||||
#region Miscellaneous
|
||||
|
|
|
|||
|
|
@ -72,7 +72,8 @@ public class CoreManager
|
|||
{
|
||||
context = context with
|
||||
{
|
||||
TunProtectSsPort = preContext.TunProtectSsPort, ProxyRelaySsPort = preContext.ProxyRelaySsPort,
|
||||
TunProtectSsPort = preContext.TunProtectSsPort,
|
||||
ProxyRelaySsPort = preContext.ProxyRelaySsPort,
|
||||
};
|
||||
}
|
||||
var result = await CoreConfigHandler.GenerateClientConfig(context, fileName);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public record CoreConfigContext
|
|||
// TUN Compatibility
|
||||
public bool IsTunEnabled { get; init; } = false;
|
||||
public HashSet<string> ProtectDomainList { get; init; } = new();
|
||||
// -> tun inbound --(if routing proxy)--> relay outbound
|
||||
// -> tun inbound --(if routing proxy)--> relay outbound
|
||||
// -> proxy core (relay inbound --> proxy outbound --(dialerProxy)--> protect outbound)
|
||||
// -> protect inbound -> direct proxy outbound data -> internet
|
||||
public int TunProtectSsPort { get; init; } = 0;
|
||||
|
|
|
|||
|
|
@ -257,6 +257,7 @@ public class Server4Sbox : BaseServer4Sbox
|
|||
|
||||
// Deprecated in sing-box 1.12.0 , kept for backward compatibility
|
||||
public string? address { get; set; }
|
||||
|
||||
public string? address_resolver { get; set; }
|
||||
public string? address_strategy { get; set; }
|
||||
public string? strategy { get; set; }
|
||||
|
|
|
|||
|
|
@ -137,18 +137,8 @@ public partial class CoreConfigSingboxService(CoreConfigContext context)
|
|||
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
||||
return ret;
|
||||
}
|
||||
List<IPEndPoint> lstIpEndPoints = new();
|
||||
List<TcpConnectionInformation> lstTcpConns = new();
|
||||
try
|
||||
{
|
||||
lstIpEndPoints.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners());
|
||||
lstIpEndPoints.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners());
|
||||
lstTcpConns.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
|
||||
var (lstIpEndPoints, lstTcpConns) = Utils.GetActiveNetworkInfo();
|
||||
|
||||
GenLog();
|
||||
GenMinimizedDns();
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ public partial class CoreConfigSingboxService
|
|||
case EConfigType.PolicyGroup:
|
||||
proxyOutboundList = BuildOutboundsList(baseTagName);
|
||||
break;
|
||||
|
||||
case EConfigType.ProxyChain:
|
||||
proxyOutboundList = BuildChainOutboundsList(baseTagName);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -94,18 +94,8 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
|
|||
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
||||
return ret;
|
||||
}
|
||||
List<IPEndPoint> lstIpEndPoints = new();
|
||||
List<TcpConnectionInformation> lstTcpConns = new();
|
||||
try
|
||||
{
|
||||
lstIpEndPoints.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners());
|
||||
lstIpEndPoints.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners());
|
||||
lstTcpConns.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
|
||||
var (lstIpEndPoints, lstTcpConns) = Utils.GetActiveNetworkInfo();
|
||||
|
||||
GenLog();
|
||||
_coreConfig.inbounds.Clear();
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ public partial class CoreConfigV2rayService
|
|||
case EConfigType.PolicyGroup:
|
||||
proxyOutboundList.AddRange(BuildOutboundsList(baseTagName));
|
||||
break;
|
||||
|
||||
case EConfigType.ProxyChain:
|
||||
proxyOutboundList.AddRange(BuildChainOutboundsList(baseTagName));
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in a new issue