Update V2rayConfigUtils.cs TrojanController.cs: sni

This commit is contained in:
ChsBuffer
2021-06-06 17:38:57 +08:00
parent 8a48e321b5
commit 2d000f5f4f
2 changed files with 77 additions and 70 deletions

View File

@@ -29,7 +29,7 @@ namespace Netch.Servers.Trojan
{
local_addr = this.LocalAddress(),
local_port = this.Socks5LocalPort(),
remote_addr = server.Hostname,
remote_addr = server.AutoResolveHostname(),
remote_port = server.Port,
password = new List<string>
{
@@ -37,8 +37,11 @@ namespace Netch.Servers.Trojan
}
};
if (!string.IsNullOrWhiteSpace(server.Host))
trojanConfig.ssl.sni = server.Host;
else if (Global.Settings.ResolveServerHostname)
trojanConfig.ssl.sni = server.Hostname;
File.WriteAllBytes(Constants.TempConfig, JsonSerializer.SerializeToUtf8Bytes(trojanConfig, Global.NewDefaultJsonSerializerOptions));

View File

@@ -1,9 +1,9 @@
using Netch.Models;
using Netch.Servers.V2ray.Models;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Netch.Enums;
using Netch.Models;
using Netch.Servers.V2ray.Models;
using V2rayConfig = Netch.Servers.V2ray.Models.V2rayConfig;
namespace Netch.Servers.V2ray.Utils
@@ -115,8 +115,8 @@ namespace Netch.Servers.V2ray.Utils
switch (server)
{
case Socks5.Socks5 socks5:
{
outbound.settings.servers = new List<ServersItem>
{
outbound.settings.servers = new List<ServersItem>
{
new()
{
@@ -136,80 +136,80 @@ namespace Netch.Servers.V2ray.Utils
}
};
outbound.mux.enabled = false;
outbound.mux.concurrency = -1;
outbound.protocol = "socks";
break;
}
case VLESS.VLESS vless:
{
var vnextItem = new VnextItem
{
users = new List<UsersItem>(),
address = server.AutoResolveHostname(),
port = server.Port
};
outbound.settings.vnext = new List<VnextItem> { vnextItem };
var usersItem = new UsersItem
{
id = vless.UserID,
alterId = 0,
flow = string.Empty,
encryption = vless.EncryptMethod
};
vnextItem.users.Add(usersItem);
var streamSettings = outbound.streamSettings;
boundStreamSettings(vless, ref streamSettings);
if (vless.TLSSecureType == "xtls")
{
usersItem.flow = string.IsNullOrEmpty(vless.Flow) ? "xtls-rprx-origin" : vless.Flow;
outbound.mux.enabled = false;
outbound.mux.concurrency = -1;
outbound.protocol = "socks";
break;
}
case VLESS.VLESS vless:
else
{
var vnextItem = new VnextItem
{
users = new List<UsersItem>(),
address = server.AutoResolveHostname(),
port = server.Port
};
outbound.settings.vnext = new List<VnextItem> { vnextItem };
var usersItem = new UsersItem
{
id = vless.UserID,
alterId = 0,
flow = string.Empty,
encryption = vless.EncryptMethod
};
vnextItem.users.Add(usersItem);
var streamSettings = outbound.streamSettings;
boundStreamSettings(vless, ref streamSettings);
if (vless.TLSSecureType == "xtls")
{
usersItem.flow = string.IsNullOrEmpty(vless.Flow) ? "xtls-rprx-origin" : vless.Flow;
outbound.mux.enabled = false;
outbound.mux.concurrency = -1;
}
else
{
outbound.mux.enabled = vless.UseMux ?? Global.Settings.V2RayConfig.UseMux;
outbound.mux.concurrency = vless.UseMux ?? Global.Settings.V2RayConfig.UseMux ? 8 : -1;
}
outbound.protocol = "vless";
outbound.settings.servers = null;
break;
outbound.mux.enabled = vless.UseMux ?? Global.Settings.V2RayConfig.UseMux;
outbound.mux.concurrency = vless.UseMux ?? Global.Settings.V2RayConfig.UseMux ? 8 : -1;
}
outbound.protocol = "vless";
outbound.settings.servers = null;
break;
}
case VMess.VMess vmess:
{
var vnextItem = new VnextItem
{
var vnextItem = new VnextItem
{
users = new List<UsersItem>(),
address = server.AutoResolveHostname(),
port = server.Port
};
users = new List<UsersItem>(),
address = server.AutoResolveHostname(),
port = server.Port
};
outbound.settings.vnext = new List<VnextItem> { vnextItem };
outbound.settings.vnext = new List<VnextItem> { vnextItem };
var usersItem = new UsersItem
{
id = vmess.UserID,
alterId = vmess.AlterID,
security = vmess.EncryptMethod
};
var usersItem = new UsersItem
{
id = vmess.UserID,
alterId = vmess.AlterID,
security = vmess.EncryptMethod
};
vnextItem.users.Add(usersItem);
vnextItem.users.Add(usersItem);
var streamSettings = outbound.streamSettings;
boundStreamSettings(vmess, ref streamSettings);
var streamSettings = outbound.streamSettings;
boundStreamSettings(vmess, ref streamSettings);
outbound.mux.enabled = vmess.UseMux ?? Global.Settings.V2RayConfig.UseMux;
outbound.mux.concurrency = vmess.UseMux ?? Global.Settings.V2RayConfig.UseMux ? 8 : -1;
outbound.protocol = "vmess";
break;
}
outbound.mux.enabled = vmess.UseMux ?? Global.Settings.V2RayConfig.UseMux;
outbound.mux.concurrency = vmess.UseMux ?? Global.Settings.V2RayConfig.UseMux ? 8 : -1;
outbound.protocol = "vmess";
break;
}
}
v2rayConfig.outbounds.AddRange(new[]
@@ -241,10 +241,14 @@ namespace Netch.Servers.V2ray.Utils
{
var tlsSettings = new TlsSettings
{
allowInsecure = Global.Settings.V2RayConfig.AllowInsecure,
serverName = !string.IsNullOrWhiteSpace(server.Host) ? server.Host : null
allowInsecure = Global.Settings.V2RayConfig.AllowInsecure
};
if (!string.IsNullOrWhiteSpace(server.Host))
tlsSettings.serverName = server.Host;
else if (Global.Settings.ResolveServerHostname)
tlsSettings.serverName = server.Hostname;
switch (server.TLSSecureType)
{
case "tls":