Previous and next proxy 4 sing-box

pull/4567/head
2dust 2023-12-25 16:42:23 +08:00
parent 51576b54c3
commit b74188d904
6 changed files with 81 additions and 22 deletions

View File

@ -45,7 +45,9 @@ namespace v2rayN.Handler
GenInbounds(singboxConfig);
GenOutbound(node, singboxConfig);
GenOutbound(node, singboxConfig.outbounds[0]);
GenMoreOutbounds(node, singboxConfig);
GenRouting(singboxConfig);
@ -202,20 +204,10 @@ namespace v2rayN.Handler
#region outbound private
private int GenOutbound(ProfileItem node, SingboxConfig singboxConfig)
private int GenOutbound(ProfileItem node, Outbound4Sbox outbound)
{
try
{
if (_config.tunModeItem.enableTun)
{
singboxConfig.outbounds.Add(new()
{
type = "dns",
tag = "dns_out"
});
}
var outbound = singboxConfig.outbounds[0];
outbound.server = node.address;
outbound.server_port = node.port;
@ -442,6 +434,59 @@ namespace v2rayN.Handler
return 0;
}
private int GenMoreOutbounds(ProfileItem node, SingboxConfig singboxConfig)
{
if (node.subid.IsNullOrEmpty())
{
return 0;
}
try
{
var subItem = LazyConfig.Instance.GetSubItem(node.subid);
if (subItem is null)
{
return 0;
}
//current proxy
var outbound = singboxConfig.outbounds[0];
var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound);
//Previous proxy
var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile!);
if (prevNode is not null
&& prevNode.configType != EConfigType.Custom)
{
var prevOutbound = Utils.FromJson<Outbound4Sbox>(txtOutbound);
GenOutbound(prevNode, prevOutbound);
prevOutbound.tag = $"{Global.ProxyTag}2";
singboxConfig.outbounds.Add(prevOutbound);
outbound.detour = prevOutbound.tag;
}
//Next proxy
var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile!);
if (nextNode is not null
&& nextNode.configType != EConfigType.Custom)
{
var nextOutbound = Utils.FromJson<Outbound4Sbox>(txtOutbound);
GenOutbound(nextNode, nextOutbound);
nextOutbound.tag = Global.ProxyTag;
singboxConfig.outbounds.Insert(0, nextOutbound);
outbound.tag = $"{Global.ProxyTag}1";
nextOutbound.detour = outbound.tag;
}
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
return 0;
}
#endregion outbound private
#region routing rule private

View File

@ -838,12 +838,15 @@ namespace v2rayN.Handler
//current proxy
var outbound = v2rayConfig.outbounds[0];
var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound);
//Previous proxy
var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile!);
if (prevNode is not null)
if (prevNode is not null
&& prevNode.configType != EConfigType.Custom
&& prevNode.configType != EConfigType.Hysteria2
&& prevNode.configType != EConfigType.Tuic)
{
var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound);
var prevOutbound = Utils.FromJson<Outbounds4Ray>(txtOutbound);
GenOutbound(prevNode, prevOutbound);
prevOutbound.tag = $"{Global.ProxyTag}2";
@ -857,9 +860,11 @@ namespace v2rayN.Handler
//Next proxy
var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile!);
if (nextNode is not null)
if (nextNode is not null
&& nextNode.configType != EConfigType.Custom
&& nextNode.configType != EConfigType.Hysteria2
&& nextNode.configType != EConfigType.Tuic)
{
var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound);
var nextOutbound = Utils.FromJson<Outbounds4Ray>(txtOutbound);
GenOutbound(nextNode, nextOutbound);
nextOutbound.tag = Global.ProxyTag;

View File

@ -105,7 +105,7 @@
public int? recv_window_conn { get; set; }
public int? recv_window { get; set; }
public bool? disable_mtu_discovery { get; set; }
public string detour { get; set; }
public string? detour { get; set; }
public string method { get; set; }
public string username { get; set; }
public string password { get; set; }

View File

@ -25,9 +25,18 @@
{
"type": "block",
"tag": "block"
},
{
"tag": "dns_out",
"type": "dns"
}
],
"route": {
"rules": []
"rules": [
{
"protocol": [ "dns" ],
"outbound": "dns_out"
}
]
}
}

View File

@ -24,5 +24,9 @@
"geoip:private",
"geoip:cn"
]
},
{
"port": "0-65535",
"outboundTag": "proxy"
}
]

View File

@ -1,8 +1,4 @@
[
{
"inbound": [ "dns_in" ],
"outbound": "dns_out"
},
{
"protocol": [ "dns" ],
"outbound": "dns_out"