From fbd5d3b8a2e16932fb758eec56009cc0b81c71cb Mon Sep 17 00:00:00 2001 From: Charlie Qiu Date: Thu, 12 Jan 2017 15:31:23 +0800 Subject: [PATCH] Support configure kcptun mtu. --- .../PreferencesWindowController.xib | 147 ++++++++++-------- ShadowsocksX-NG/KcptunProfile.swift | 13 ++ .../PreferencesWindowController.swift | 4 + 3 files changed, 103 insertions(+), 61 deletions(-) diff --git a/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib b/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib index 66fc53c..4529f20 100644 --- a/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib +++ b/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib @@ -12,11 +12,12 @@ - + + - + @@ -33,20 +34,20 @@ - + - + - + - + - + @@ -93,13 +94,13 @@ - + - + - + @@ -107,7 +108,7 @@ - + @@ -118,7 +119,7 @@ - + @@ -135,7 +136,7 @@ - + @@ -143,7 +144,7 @@ - + @@ -151,7 +152,7 @@ - + @@ -162,7 +163,7 @@ - + @@ -170,7 +171,7 @@ - + @@ -178,7 +179,7 @@ - + @@ -186,7 +187,7 @@ - + @@ -194,27 +195,27 @@ - + - + - + @@ -222,7 +223,7 @@ - + @@ -230,7 +231,7 @@ - + @@ -241,7 +242,7 @@ - + @@ -249,31 +250,23 @@ - - - - - - - - - - - + + + - - + + @@ -281,10 +274,10 @@ - + - + @@ -292,48 +285,74 @@ - + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - @@ -341,8 +360,6 @@ - - @@ -482,7 +499,7 @@ DQ - + @@ -500,6 +517,14 @@ DQ + + + + + + + + diff --git a/ShadowsocksX-NG/KcptunProfile.swift b/ShadowsocksX-NG/KcptunProfile.swift index 5e40996..30ef470 100644 --- a/ShadowsocksX-NG/KcptunProfile.swift +++ b/ShadowsocksX-NG/KcptunProfile.swift @@ -18,6 +18,7 @@ class KcptunProfile: NSObject { var nocomp: Bool = false var datashard: uint = 10 var parityshard: uint = 3 + var mtu: uint = 1350 public func copy(with zone: NSZone? = nil) -> Any { @@ -39,6 +40,7 @@ class KcptunProfile: NSObject { "nocomp": NSNumber(value: self.nocomp), "datashard": NSNumber(value: self.datashard), "parityshard": NSNumber(value: self.parityshard), + "mtu": NSNumber(value: self.mtu), ] return conf } @@ -51,6 +53,9 @@ class KcptunProfile: NSObject { profile.nocomp = (data["nocomp"] as! NSNumber).boolValue profile.datashard = uint((data["datashard"] as! NSNumber).uintValue) profile.parityshard = uint((data["parityshard"] as! NSNumber).uintValue) + if let v = data["mtu"] as? NSNumber { + profile.mtu = uint(v.uintValue) + } return profile } @@ -68,6 +73,7 @@ class KcptunProfile: NSObject { "nocomp": NSNumber(value: self.nocomp), "datashard": NSNumber(value: self.datashard), "parityshard": NSNumber(value: self.parityshard), + "mtu": NSNumber(value: self.mtu), ] return conf } @@ -80,6 +86,7 @@ class KcptunProfile: NSObject { URLQueryItem(name: "datashard", value: "\(datashard)"), URLQueryItem(name: "parityshard", value: "\(parityshard)"), URLQueryItem(name: "nocomp", value: nocomp.description), + URLQueryItem(name: "mtu", value: "\(mtu)"), ] } @@ -116,6 +123,12 @@ class KcptunProfile: NSObject { nocomp = vv } } + case "mtu": + if let v = item.value { + if let vv = uint(v) { + mtu = vv + } + } default: continue } diff --git a/ShadowsocksX-NG/PreferencesWindowController.swift b/ShadowsocksX-NG/PreferencesWindowController.swift index d916144..62ad829 100644 --- a/ShadowsocksX-NG/PreferencesWindowController.swift +++ b/ShadowsocksX-NG/PreferencesWindowController.swift @@ -32,6 +32,7 @@ class PreferencesWindowController: NSWindowController @IBOutlet weak var kcptunNocompCheckBoxBtn: NSButton! @IBOutlet weak var kcptunDatashardTextField: NSTextField! @IBOutlet weak var kcptunParityshardTextField: NSTextField! + @IBOutlet weak var kcptunMTUTextField: NSTextField! @IBOutlet weak var removeButton: NSButton! let tableViewDragType: String = "ss.server.profile.data" @@ -244,6 +245,9 @@ class PreferencesWindowController: NSWindowController kcptunParityshardTextField.bind("value", to: editingProfile, withKeyPath: "kcptunProfile.parityshard" , options: [NSContinuouslyUpdatesValueBindingOption: true]) + kcptunMTUTextField.bind("value", to: editingProfile, withKeyPath: "kcptunProfile.mtu" + , options: [NSContinuouslyUpdatesValueBindingOption: true]) + } else { editingProfile = nil hostTextField.unbind("value")