Skip to content

Commit

Permalink
Using mixed local listening ports
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Dec 3, 2024
1 parent 5494d63 commit ccacda9
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 59 deletions.
3 changes: 1 addition & 2 deletions v2rayN/ServiceLib/Enums/EInboundProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
public enum EInboundProtocol
{
socks = 0,
http,
socks2,
http2,
pac,
api,
api2,
mixed,
speedtest = 21
}
}
2 changes: 1 addition & 1 deletion v2rayN/ServiceLib/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public class Global
public static readonly List<string> Languages = new() { "zh-Hans", "zh-Hant", "en", "fa-Ir", "ru" };
public static readonly List<string> Alpns = new() { "h3", "h2", "http/1.1", "h3,h2", "h2,http/1.1", "h3,h2,http/1.1", "" };
public static readonly List<string> LogLevels = new() { "debug", "info", "warning", "error", "none" };
public static readonly List<string> InboundTags = new() { "socks", "http", "socks2", "http2" };
public static readonly List<string> InboundTags = new() { "socks", "socks2" };
public static readonly List<string> RuleProtocols = new() { "http", "tls", "bittorrent" };
public static readonly List<string> RuleNetworks = new() { "", "tcp", "udp", "tcp,udp" };
public static readonly List<string> destOverrideProtocols = ["http", "tls", "quic", "fakedns", "fakedns+others"];
Expand Down
9 changes: 4 additions & 5 deletions v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public static async Task<bool> UpdateSysProxy(Config config, bool forceDisable)

try
{
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
var portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
if (port <= 0)
{
return false;
Expand All @@ -23,7 +22,7 @@ public static async Task<bool> UpdateSysProxy(Config config, bool forceDisable)
{
case ESysProxyType.ForcedChange when Utils.IsWindows():
{
GetWindowsProxyString(config, port, portSocks, out var strProxy, out var strExceptions);
GetWindowsProxyString(config, port, out var strProxy, out var strExceptions);
ProxySettingWindows.SetProxy(strProxy, strExceptions, 2);
break;
}
Expand Down Expand Up @@ -64,7 +63,7 @@ public static async Task<bool> UpdateSysProxy(Config config, bool forceDisable)
return true;
}

private static void GetWindowsProxyString(Config config, int port, int portSocks, out string strProxy, out string strExceptions)
private static void GetWindowsProxyString(Config config, int port, out string strProxy, out string strExceptions)
{
strExceptions = $"{config.ConstItem.DefIEProxyExceptions};{config.SystemProxyItem.SystemProxyExceptions}";
if (config.SystemProxyItem.NotProxyLocalAddress)
Expand All @@ -82,7 +81,7 @@ private static void GetWindowsProxyString(Config config, int port, int portSocks
strProxy = config.SystemProxyItem.SystemProxyAdvancedProtocol
.Replace("{ip}", Global.Loopback)
.Replace("{http_port}", port.ToString())
.Replace("{socks_port}", portSocks.ToString());
.Replace("{socks_port}", port.ToString());
}
}

Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@
<value>Turn on Sniffing</value>
</data>
<data name="TbSettingsSocksPort" xml:space="preserve">
<value>ساکس Port</value>
<value>Mixed Port</value>
</data>
<data name="TbSettingsStartBoot" xml:space="preserve">
<value>درهنگام راه ائدازی شروع شود</value>
Expand Down Expand Up @@ -1244,7 +1244,7 @@
<value>Copy the font TTF/TTC file to the directory guiFonts, restart the settings</value>
</data>
<data name="TbSettingsSocksPortTip" xml:space="preserve">
<value>http port = +1; Pac port = +4; *ray API port = +5; mihomo API port = +6;</value>
<value>Pac port = +2; Xray API port = +3; mihomo API port = +4;</value>
</data>
<data name="TbSettingsStartBootTip" xml:space="preserve">
<value>Set this with admin privileges, get admin privileges after startup</value>
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@
<value>Turn on Sniffing</value>
</data>
<data name="TbSettingsSocksPort" xml:space="preserve">
<value>SOCKS Port</value>
<value>Mixed Port</value>
</data>
<data name="TbSettingsStartBoot" xml:space="preserve">
<value>Start on boot</value>
Expand Down Expand Up @@ -992,7 +992,7 @@
<value>Copy the font TTF/TTC file to the directory guiFonts, restart the settings</value>
</data>
<data name="TbSettingsSocksPortTip" xml:space="preserve">
<value>http port = +1; Pac port = +4; *ray API port = +5; mihomo API port = +6;</value>
<value>Pac port = +2; Xray API port = +3; mihomo API port = +4;</value>
</data>
<data name="TbSettingsStartBootTip" xml:space="preserve">
<value>Set this with admin privileges, get admin privileges after startup</value>
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Resx/ResUI.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@
<value>Включить сниффинг</value>
</data>
<data name="TbSettingsSocksPort" xml:space="preserve">
<value>Порт Socks</value>
<value>Mixed Port</value>
</data>
<data name="TbSettingsStartBoot" xml:space="preserve">
<value>Автозапуск</value>
Expand Down Expand Up @@ -1310,7 +1310,7 @@
<value>Move up and down</value>
</data>
<data name="TbSettingsSocksPortTip" xml:space="preserve">
<value>http port = +1; Pac port = +4; *ray API port = +5; mihomo API port = +6;</value>
<value>Pac port = +2; Xray API port = +3; mihomo API port = +4;</value>
</data>
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
<value>Install the font to the system and restart the settings</value>
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@
<value>开启流量探测</value>
</data>
<data name="TbSettingsSocksPort" xml:space="preserve">
<value>本地socks监听端口</value>
<value>本地混合监听端口</value>
</data>
<data name="TbSettingsStartBoot" xml:space="preserve">
<value>开机启动(可能会不成功)</value>
Expand Down Expand Up @@ -992,7 +992,7 @@
<value>拷贝字体TTF/TTC文件到目录guiFonts,重启设置</value>
</data>
<data name="TbSettingsSocksPortTip" xml:space="preserve">
<value>http端口= +1;Pac端口= +4;*ray API端口= +5;mihomo API端口= +6;</value>
<value>Pac端口= +2;Xray API端口= +3;mihomo API端口= +4;</value>
</data>
<data name="TbSettingsStartBootTip" xml:space="preserve">
<value>以管理员权限设置此项,在启动后获得管理员权限</value>
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@
<value>開啟流量探測</value>
</data>
<data name="TbSettingsSocksPort" xml:space="preserve">
<value>本機SOCKS偵聽埠</value>
<value>本機混合偵聽埠</value>
</data>
<data name="TbSettingsStartBoot" xml:space="preserve">
<value>開機啟動(可能會不成功)</value>
Expand Down Expand Up @@ -992,7 +992,7 @@
<value>複製字型TTF/TTC檔案到目錄guiFonts,重啟設定</value>
</data>
<data name="TbSettingsSocksPortTip" xml:space="preserve">
<value>http連接埠= +1;Pac連接埠= +4;*ray API連接埠= +5;mihomo API連接埠= +6;</value>
<value>Pac連接埠= +2;Xray API連接埠= +3;mihomo API連接埠= +4;</value>
</data>
<data name="TbSettingsStartBootTip" xml:space="preserve">
<value>以管理員權限設定此項,在啟動後獲得管理員權限</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ public async Task<RetResult> GenerateClientCustomConfig(ProfileItem node, string
return ret;
}

//port
fileContent["port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
//socks-port
fileContent["socks-port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
//mixed-port
fileContent["mixed-port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
//log-level
fileContent["log-level"] = GetLogLevel(_config.CoreBasicItem.Loglevel);

Expand Down
16 changes: 3 additions & 13 deletions v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
{
listen = Global.Loopback,
listen_port = port,
type = EInboundProtocol.http.ToString(),
type = EInboundProtocol.mixed.ToString(),
};
inbound.tag = inbound.type + inbound.listen_port.ToString();
singboxConfig.inbounds.Add(inbound);
Expand Down Expand Up @@ -488,7 +488,7 @@ private async Task<int> GenInbounds(SingboxConfig singboxConfig)
{
var inbound = new Inbound4Sbox()
{
type = EInboundProtocol.socks.ToString(),
type = EInboundProtocol.mixed.ToString(),
tag = EInboundProtocol.socks.ToString(),
listen = Global.Loopback,
};
Expand All @@ -505,10 +505,6 @@ private async Task<int> GenInbounds(SingboxConfig singboxConfig)
inbound.domain_strategy = routing.DomainStrategy4Singbox;
}

//http
var inbound2 = GetInbound(inbound, EInboundProtocol.http, false);
singboxConfig.inbounds.Add(inbound2);

if (_config.Inbound.First().AllowLANConn)
{
if (_config.Inbound.First().NewPort4LAN)
Expand All @@ -517,21 +513,15 @@ private async Task<int> GenInbounds(SingboxConfig singboxConfig)
inbound3.listen = listen;
singboxConfig.inbounds.Add(inbound3);

var inbound4 = GetInbound(inbound, EInboundProtocol.http2, false);
inbound4.listen = listen;
singboxConfig.inbounds.Add(inbound4);

//auth
if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass))
{
inbound3.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } };
inbound4.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } };
}
}
else
{
inbound.listen = listen;
inbound2.listen = listen;
}
}
}
Expand Down Expand Up @@ -574,7 +564,7 @@ private Inbound4Sbox GetInbound(Inbound4Sbox inItem, EInboundProtocol protocol,
var inbound = JsonUtils.DeepCopy(inItem);
inbound.tag = protocol.ToString();
inbound.listen_port = inItem.listen_port + (int)protocol;
inbound.type = bSocks ? EInboundProtocol.socks.ToString() : EInboundProtocol.http.ToString();
inbound.type = EInboundProtocol.mixed.ToString();
return inbound;
}

Expand Down
18 changes: 3 additions & 15 deletions v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
{
listen = Global.Loopback,
port = port,
protocol = EInboundProtocol.http.ToString(),
protocol = EInboundProtocol.socks.ToString(),
};
inbound.tag = inbound.protocol + inbound.port.ToString();
v2rayConfig.inbounds.Add(inbound);
Expand Down Expand Up @@ -391,13 +391,9 @@ public async Task<int> GenInbounds(V2rayConfig v2rayConfig)
var listen = "0.0.0.0";
v2rayConfig.inbounds = [];

Inbounds4Ray? inbound = GetInbound(_config.Inbound.First(), EInboundProtocol.socks, true);
var inbound = GetInbound(_config.Inbound.First(), EInboundProtocol.socks, true);
v2rayConfig.inbounds.Add(inbound);

//http
Inbounds4Ray? inbound2 = GetInbound(_config.Inbound.First(), EInboundProtocol.http, false);
v2rayConfig.inbounds.Add(inbound2);

if (_config.Inbound.First().AllowLANConn)
{
if (_config.Inbound.First().NewPort4LAN)
Expand All @@ -406,24 +402,16 @@ public async Task<int> GenInbounds(V2rayConfig v2rayConfig)
inbound3.listen = listen;
v2rayConfig.inbounds.Add(inbound3);

var inbound4 = GetInbound(_config.Inbound.First(), EInboundProtocol.http2, false);
inbound4.listen = listen;
v2rayConfig.inbounds.Add(inbound4);

//auth
if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass))
{
inbound3.settings.auth = "password";
inbound3.settings.accounts = new List<AccountsItem4Ray> { new AccountsItem4Ray() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass } };

inbound4.settings.auth = "password";
inbound4.settings.accounts = new List<AccountsItem4Ray> { new AccountsItem4Ray() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass } };
}
}
else
{
inbound.listen = listen;
inbound2.listen = listen;
}
}
}
Expand All @@ -449,7 +437,7 @@ private Inbounds4Ray GetInbound(InItem inItem, EInboundProtocol protocol, bool b
}
inbound.tag = protocol.ToString();
inbound.port = inItem.LocalPort + (int)protocol;
inbound.protocol = bSocks ? EInboundProtocol.socks.ToString() : EInboundProtocol.http.ToString();
inbound.protocol = EInboundProtocol.socks.ToString();
inbound.settings.udp = inItem.UdpEnabled;
inbound.sniffing.enabled = inItem.SniffingEnabled;
inbound.sniffing.destOverride = inItem.DestOverride;
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/ServiceLib/Services/DownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public async Task<int> GetRealPingTime(string url, IWebProxy? webProxy, int down
{
return null;
}
var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
if (await SocketCheck(Global.Loopback, httpPort) == false)
{
return null;
Expand Down
8 changes: 2 additions & 6 deletions v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,15 @@ private bool AllowEnableTun()
public async Task InboundDisplayStatus()
{
StringBuilder sb = new();
sb.Append($"[{EInboundProtocol.socks}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks)}]");
sb.Append(" | ");
sb.Append($"[{EInboundProtocol.http}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.http)}]");
sb.Append($"[{EInboundProtocol.mixed}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks)}]");
InboundDisplay = $"{ResUI.LabLocal}:{sb}";

if (_config.Inbound.First().AllowLANConn)
{
if (_config.Inbound.First().NewPort4LAN)
{
StringBuilder sb2 = new();
sb2.Append($"[{EInboundProtocol.socks}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks2)}]");
sb2.Append(" | ");
sb2.Append($"[{EInboundProtocol.http}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.http2)}]");
sb2.Append($"[{EInboundProtocol.mixed}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks2)}]");
InboundLanDisplay = $"{ResUI.LabLAN}:{sb2}";
}
else
Expand Down

4 comments on commit ccacda9

@ssssssbbb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所以这版的改动是什么意思,从这版之后,mihomo就需要按设置里的说明把端口号+4,之前不用

@2dust
Copy link
Owner Author

@2dust 2dust commented on ccacda9 Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是你说的意思
把原来的socks和http 入口合并成一个了,这样就少开2个端口;你看到+4那个是API接口端口,用来做统计流量用,一般用不到

@ssssssbbb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但是从这版开始,我不那么设置连direct都访问不了

@2dust
Copy link
Owner Author

@2dust 2dust commented on ccacda9 Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你可以看代码,mihomo的修改就是使用了mixed入口,api端口变了(这个如果你不用其他面板是用不到的)
你可以提交issue,把详细的使用发出来

Please sign in to comment.