From 95aa3db41543254e36931fd9ddfb11df58511e02 Mon Sep 17 00:00:00 2001 From: Hellojack <106379370+H1JK@users.noreply.github.com> Date: Thu, 16 Jun 2022 17:01:40 +0800 Subject: [PATCH] [Netch] Support TCP Fast Open --- Netch/Forms/SettingForm.Designer.cs | 13 +++++++ Netch/Forms/SettingForm.cs | 2 +- Netch/Models/Settings/V2rayConfig.cs | 2 + Netch/Resources/zh-CN | 1 + Netch/Servers/V2ray/V2rayConfig.cs | 7 ++++ Netch/Servers/V2ray/V2rayConfigUtils.cs | 50 +++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-) diff --git a/Netch/Forms/SettingForm.Designer.cs b/Netch/Forms/SettingForm.Designer.cs index 84049753..bcbda2ba 100644 --- a/Netch/Forms/SettingForm.Designer.cs +++ b/Netch/Forms/SettingForm.Designer.cs @@ -80,6 +80,7 @@ namespace Netch.Forms this.XrayConeCheckBox = new System.Windows.Forms.CheckBox(); this.TLSAllowInsecureCheckBox = new System.Windows.Forms.CheckBox(); this.UseMuxCheckBox = new System.Windows.Forms.CheckBox(); + this.TCPFastOpenBox = new System.Windows.Forms.CheckBox(); this.KCPGroupBox = new System.Windows.Forms.GroupBox(); this.mtuLabel = new System.Windows.Forms.Label(); this.mtuTextBox = new System.Windows.Forms.TextBox(); @@ -590,6 +591,7 @@ namespace Netch.Forms this.v2rayTabPage.Controls.Add(this.XrayConeCheckBox); this.v2rayTabPage.Controls.Add(this.TLSAllowInsecureCheckBox); this.v2rayTabPage.Controls.Add(this.UseMuxCheckBox); + this.v2rayTabPage.Controls.Add(this.TCPFastOpenBox); this.v2rayTabPage.Controls.Add(this.KCPGroupBox); this.v2rayTabPage.Location = new System.Drawing.Point(4, 29); this.v2rayTabPage.Name = "v2rayTabPage"; @@ -628,6 +630,16 @@ namespace Netch.Forms this.UseMuxCheckBox.Text = "Use Mux"; this.UseMuxCheckBox.UseVisualStyleBackColor = true; // + // TCPFastOpenBox + // + this.TCPFastOpenBox.AutoSize = true; + this.TCPFastOpenBox.Location = new System.Drawing.Point(300, 42); + this.TCPFastOpenBox.Name = "TCPFastOpenBox"; + this.TCPFastOpenBox.Size = new System.Drawing.Size(131, 21); + this.TCPFastOpenBox.TabIndex = 3; + this.TCPFastOpenBox.Text = "TCP FastOpen"; + this.TCPFastOpenBox.UseVisualStyleBackColor = true; + // // KCPGroupBox // this.KCPGroupBox.Controls.Add(this.mtuLabel); @@ -1063,6 +1075,7 @@ namespace Netch.Forms private System.Windows.Forms.GroupBox KCPGroupBox; private System.Windows.Forms.CheckBox congestionCheckBox; private System.Windows.Forms.CheckBox TLSAllowInsecureCheckBox; + private System.Windows.Forms.CheckBox TCPFastOpenBox; private System.Windows.Forms.Label mtuLabel; private System.Windows.Forms.TextBox mtuTextBox; private System.Windows.Forms.Label writeBufferSizeLabel; diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs index def49c8e..07550f64 100644 --- a/Netch/Forms/SettingForm.cs +++ b/Netch/Forms/SettingForm.cs @@ -120,11 +120,11 @@ public partial class SettingForm : BindingForm #endregion #region V2Ray - BindCheckBox(XrayConeCheckBox, b => Global.Settings.V2RayConfig.XrayCone = b, Global.Settings.V2RayConfig.XrayCone); BindCheckBox(TLSAllowInsecureCheckBox, b => Global.Settings.V2RayConfig.AllowInsecure = b, Global.Settings.V2RayConfig.AllowInsecure); BindCheckBox(UseMuxCheckBox, b => Global.Settings.V2RayConfig.UseMux = b, Global.Settings.V2RayConfig.UseMux); + BindCheckBox(TCPFastOpenBox, b => Global.Settings.V2RayConfig.TCPFastOpen = b, Global.Settings.V2RayConfig.TCPFastOpen); BindTextBox(mtuTextBox, i => true, i => Global.Settings.V2RayConfig.KcpConfig.mtu = i, Global.Settings.V2RayConfig.KcpConfig.mtu); BindTextBox(ttiTextBox, i => true, i => Global.Settings.V2RayConfig.KcpConfig.tti = i, Global.Settings.V2RayConfig.KcpConfig.tti); diff --git a/Netch/Models/Settings/V2rayConfig.cs b/Netch/Models/Settings/V2rayConfig.cs index 6ae13dba..97d2cb5f 100644 --- a/Netch/Models/Settings/V2rayConfig.cs +++ b/Netch/Models/Settings/V2rayConfig.cs @@ -11,4 +11,6 @@ public class V2rayConfig public bool V2rayNShareLink { get; set; } = true; public bool XrayCone { get; set; } = true; + + public bool TCPFastOpen { get; set; } = false; } \ No newline at end of file diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index f91760ab..74a8f552 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -183,6 +183,7 @@ "STUN Server": "STUN 服务器", "Language": "语言", "FullCone Support (Required Server Xray-core v1.3.0+)": "FullCone 支持(需服务端 Xray-core v1.3.0+)", + "TCP FastOpen": "TCP 快速打开", "Disable Support Warning": "停用支持警告", "Profile": "配置名", diff --git a/Netch/Servers/V2ray/V2rayConfig.cs b/Netch/Servers/V2ray/V2rayConfig.cs index d412bab1..2d26668e 100644 --- a/Netch/Servers/V2ray/V2rayConfig.cs +++ b/Netch/Servers/V2ray/V2rayConfig.cs @@ -117,6 +117,8 @@ public class StreamSettings public TlsSettings xtlsSettings { get; set; } public GrpcSettings grpcSettings { get; set; } + + public Sockopt sockopt { get; set; } } #region Transport @@ -184,4 +186,9 @@ public class GrpcSettings public bool multiMode { get; set; } } +public class Sockopt +{ + public bool tcpFastOpen { get; set; } +} + #endregion \ No newline at end of file diff --git a/Netch/Servers/V2ray/V2rayConfigUtils.cs b/Netch/Servers/V2ray/V2rayConfigUtils.cs index 10173ee5..57a81d7f 100644 --- a/Netch/Servers/V2ray/V2rayConfigUtils.cs +++ b/Netch/Servers/V2ray/V2rayConfigUtils.cs @@ -160,6 +160,17 @@ public static class V2rayConfigUtils plugin = ss.Plugin ?? "", pluginOpts = ss.PluginOption ?? "" }; + + if (Global.Settings.V2RayConfig.TCPFastOpen) + { + outbound.streamSettings = new StreamSettings + { + sockopt = new Sockopt + { + tcpFastOpen = true + } + }; + } break; case ShadowsocksRServer ssr: outbound.protocol = "shadowsocks"; @@ -184,6 +195,17 @@ public static class V2rayConfigUtils "--protocol-param=" + ssr.ProtocolParam ?? "" } }; + + if (Global.Settings.V2RayConfig.TCPFastOpen) + { + outbound.streamSettings = new StreamSettings + { + sockopt = new Sockopt + { + tcpFastOpen = true + } + }; + } break; case TrojanServer trojan: outbound.protocol = "trojan"; @@ -225,6 +247,15 @@ public static class V2rayConfigUtils break; } } + + if (Global.Settings.V2RayConfig.TCPFastOpen) + { + outbound.streamSettings.sockopt = new Sockopt + { + tcpFastOpen = true + } + }; + } break; case WireGuardServer wg: outbound.protocol = "wireguard"; @@ -238,6 +269,17 @@ public static class V2rayConfigUtils preSharedKey = wg.PreSharedKey, mtu = wg.MTU }; + + if (Global.Settings.V2RayConfig.TCPFastOpen) + { + outbound.streamSettings = new StreamSettings + { + sockopt = new Sockopt + { + tcpFastOpen = true + } + }; + } break; } @@ -366,6 +408,14 @@ public static class V2rayConfigUtils throw new MessageException($"transfer protocol \"{server.TransferProtocol}\" not implemented yet"); } + if (Global.Settings.V2RayConfig.TCPFastOpen) + { + streamSettings.sockopt = new Sockopt + { + tcpFastOpen = true + }; + } + return streamSettings; }