Skip to content

Commit

Permalink
tcp http path 设置 和 kcp 设置
Browse files Browse the repository at this point in the history
  • Loading branch information
yanue committed Jul 28, 2024
1 parent 90062d9 commit 45e9adf
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 104 deletions.
134 changes: 60 additions & 74 deletions V2rayU/Base.lproj/ConfigWindow.xib

Large diffs are not rendered by default.

28 changes: 22 additions & 6 deletions V2rayU/ConfigWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel
@IBOutlet weak var kcpTti: NSTextField!
@IBOutlet weak var kcpUplinkCapacity: NSTextField!
@IBOutlet weak var kcpDownlinkCapacity: NSTextField!
@IBOutlet weak var kcpReadBufferSize: NSTextField!
@IBOutlet weak var kcpWriteBufferSize: NSTextField!
@IBOutlet weak var kcpSeed: NSTextField!
@IBOutlet weak var kcpHeader: NSPopUpButton!
@IBOutlet weak var kcpCongestion: NSButton!

@IBOutlet weak var tcpHeaderType: NSPopUpButton!
@IBOutlet weak var tcpHost: NSTextField!
@IBOutlet weak var tcpPath: NSTextField!

@IBOutlet weak var wsHost: NSTextField!
@IBOutlet weak var wsPath: NSTextField!
Expand Down Expand Up @@ -371,6 +372,12 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel
if self.tcpHeaderType.indexOfSelectedItem >= 0 {
v2rayConfig.streamTcp.header.type = self.tcpHeaderType.titleOfSelectedItem!
}
if v2rayConfig.streamTcp.header.type == "http" {
var tcpRequest = TcpSettingHeaderRequest()
tcpRequest.path = [self.tcpPath.stringValue]
tcpRequest.headers.host = [self.tcpHost.stringValue]
v2rayConfig.streamTcp.header.request = tcpRequest
}

// kcp
if self.kcpHeader.indexOfSelectedItem >= 0 {
Expand All @@ -380,8 +387,7 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel
v2rayConfig.streamKcp.tti = Int(self.kcpTti.intValue)
v2rayConfig.streamKcp.uplinkCapacity = Int(self.kcpUplinkCapacity.intValue)
v2rayConfig.streamKcp.downlinkCapacity = Int(self.kcpDownlinkCapacity.intValue)
v2rayConfig.streamKcp.readBufferSize = Int(self.kcpReadBufferSize.intValue)
v2rayConfig.streamKcp.writeBufferSize = Int(self.kcpWriteBufferSize.intValue)
v2rayConfig.streamKcp.seed = self.kcpSeed.stringValue
v2rayConfig.streamKcp.congestion = self.kcpCongestion.state.rawValue > 0

// h2
Expand Down Expand Up @@ -499,15 +505,25 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel

// tcp
self.tcpHeaderType.selectItem(withTitle: v2rayConfig.streamTcp.header.type)
if let req = v2rayConfig.streamTcp.header.request {
if req.path.count>0 {
self.tcpPath.stringValue = req.path[0]
}
if req.headers.host.count>0{
self.tcpHost.stringValue = req.headers.host[0]
}
} else {
self.tcpPath.stringValue = ""
self.tcpHost.stringValue = ""
}

// kcp
self.kcpHeader.selectItem(withTitle: v2rayConfig.streamKcp.header.type)
self.kcpMtu.intValue = Int32(v2rayConfig.streamKcp.mtu)
self.kcpTti.intValue = Int32(v2rayConfig.streamKcp.tti)
self.kcpUplinkCapacity.intValue = Int32(v2rayConfig.streamKcp.uplinkCapacity)
self.kcpDownlinkCapacity.intValue = Int32(v2rayConfig.streamKcp.downlinkCapacity)
self.kcpReadBufferSize.intValue = Int32(v2rayConfig.streamKcp.readBufferSize)
self.kcpWriteBufferSize.intValue = Int32(v2rayConfig.streamKcp.writeBufferSize)
self.kcpSeed.stringValue = v2rayConfig.streamKcp.seed
self.kcpCongestion.intValue = v2rayConfig.streamKcp.congestion ? 1 : 0

// h2
Expand Down
20 changes: 11 additions & 9 deletions V2rayU/Import.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class ImportUri {
v2ray.serverVless = vmessItem

// stream
v2ray.streamNetwork = vmess.type
v2ray.streamNetwork = vmess.network
v2ray.streamSecurity = vmess.security
v2ray.securityTls.serverName = vmess.sni // default tls sni
v2ray.securityTls.fingerprint = vmess.fp
Expand All @@ -348,7 +348,7 @@ class ImportUri {
}

// kcp
v2ray.streamKcp.header.type = vmess.type
v2ray.streamKcp.header.type = vmess.headerType
v2ray.streamKcp.seed = vmess.kcpSeed

// h2
Expand All @@ -364,7 +364,7 @@ class ImportUri {
v2ray.streamGrpc.multiMode = vmess.grpcMode == "multi" // v2rayN

// tcp
v2ray.streamTcp.header.type = vmess.type
v2ray.streamTcp.header.type = vmess.headerType
if v2ray.streamNetwork == "tcp" && v2ray.streamTcp.header.type == "http" {
var tcpReq = TcpSettingHeaderRequest()
tcpReq.path = [vmess.path]
Expand All @@ -373,8 +373,10 @@ class ImportUri {
}

// quic
v2ray.streamQuic.header.type = vmess.type

v2ray.streamQuic.header.type = vmess.headerType

print("importVless-v2ray",v2ray.streamKcp,v2ray.streamKcp.seed)

// check is valid
v2ray.checkManualValid()
if v2ray.isValid {
Expand Down Expand Up @@ -516,7 +518,7 @@ func importByClash(clash: clashProxy) -> ImportUri? {
item.port = clash.port
item.id = clash.uuid ?? ""
item.security = clash.cipher ?? "none" // vless encryption
item.type = clash.network ?? "tcp"
item.network = clash.network ?? "tcp"
item.sni = clash.sni ?? clash.server
if clash.security == "reality" {
item.sni = clash.servername ?? clash.server
Expand All @@ -527,15 +529,15 @@ func importByClash(clash: clashProxy) -> ImportUri? {
}
}
// network ws
if item.type == "ws" {
if item.network == "ws" {
item.host = clash.servername ?? clash.server
item.path = "/"
if clash.wsOpts != nil {
item.path = clash.wsOpts?.path ?? "/"
}
}
// network h2
if item.type == "h2" {
if item.network == "h2" {
item.host = clash.servername ?? clash.server
item.path = "/"
if clash.h2Opts != nil {
Expand All @@ -547,7 +549,7 @@ func importByClash(clash: clashProxy) -> ImportUri? {
}
}
// network grpc
if item.type == "grpc" {
if item.network == "grpc" {
item.host = clash.servername ?? clash.server
if clash.grpcOpts != nil {
item.path = clash.grpcOpts?.grpcServiceName ?? "/"
Expand Down
74 changes: 66 additions & 8 deletions V2rayU/Share.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ struct VmessShare: Codable {
var ps: String = ""
var add: String = ""
var port: String = ""
var id: String = ""
var aid: String = ""
var net: String = ""
var type: String = "none"
var host: String = ""
var path: String = ""
var id: String = "" // UUID
var aid: String = "" // alterId
var net: String = "" // network type: (tcp\kcp\ws\h2\quic\ds\grpc)
var type: String = "none" // 伪装类型(none\http\srtp\utp\wechat-video) *tcp or kcp or QUIC
var host: String = "" // host: 1)http(tcp)->host中间逗号(,)隔开,2)ws->host,3)h2->host,4)QUIC->securty
var path: String = "" // path: 1)ws->path,2)h2->path,3)QUIC->key/Kcp->seed,4)grpc->serviceName
var tls: String = "tls"
var security: String = "auto"
var security: String = "auto" // 加密方式(security),没有时值默认auto
var scy: String = "auto" // 同security
var alpn: String = "" // h2,http/1.1
var sni: String = ""
var fp: String = ""
}
Expand Down Expand Up @@ -99,6 +101,34 @@ class ShareUri {
}
self.share.net = self.v2ray.streamNetwork

if self.v2ray.streamNetwork == "tcp" {
self.share.type = self.v2ray.streamTcp.header.type
if self.v2ray.streamTcp.header.type == "http" {
if let req = self.v2ray.streamTcp.header.request {
if req.path.count > 0 {
self.share.path = req.path[0]
}
if req.headers.host.count>0 {
self.share.host = req.headers.host[0]
}
}
}
}

if self.v2ray.streamNetwork == "kcp" {
self.share.type = self.v2ray.streamKcp.header.type
self.share.path = self.v2ray.streamKcp.seed
}

if self.v2ray.streamNetwork == "quic" {
self.share.type = self.v2ray.streamQuic.header.type
self.share.path = self.v2ray.streamQuic.key
}

if self.v2ray.streamNetwork == "domainsocket" {
self.share.path = self.v2ray.streamDs.path
}

if self.v2ray.streamNetwork == "h2" {
if self.v2ray.streamH2.host.count > 0 {
self.share.host = self.v2ray.streamH2.host[0]
Expand Down Expand Up @@ -183,8 +213,36 @@ class ShareUri {
ss.fp = self.v2ray.securityTls.fingerprint
}

ss.type = self.v2ray.streamNetwork
ss.network = self.v2ray.streamNetwork

if self.v2ray.streamNetwork == "tcp" {
ss.headerType = self.v2ray.streamTcp.header.type
if self.v2ray.streamTcp.header.type == "http" {
if let req = self.v2ray.streamTcp.header.request {
if req.path.count > 0 {
ss.path = req.path[0]
}
if req.headers.host.count>0 {
ss.host = req.headers.host[0]
}
}
}
}

if self.v2ray.streamNetwork == "kcp" {
ss.headerType = self.v2ray.streamKcp.header.type
ss.kcpSeed = self.v2ray.streamKcp.seed
}

if self.v2ray.streamNetwork == "quic" {
ss.headerType = self.v2ray.streamQuic.header.type
ss.kcpSeed = self.v2ray.streamQuic.key
}

if self.v2ray.streamNetwork == "domainsocket" {
ss.path = self.v2ray.streamDs.path
}

if self.v2ray.streamNetwork == "h2" {
if self.v2ray.streamH2.host.count > 0 {
ss.host = self.v2ray.streamH2.host[0]
Expand Down
14 changes: 8 additions & 6 deletions V2rayU/Uri.swift
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,11 @@ class VlessUri {
var level: Int = 0
var flow: String = ""

var encryption: String = "" // auto,aes-128-gcm,...
var encryption: String = "" // none,auto,aes-128-gcm,...
var security: String = "" // xtls,tls,reality

var type: String = "" // tcp,http

var network: String = "" // network type: tcp,http,kcp,h2,ws,quic,grpc,domainsocket
var headerType: String = "" // header type: tcp=["none","http"],quic,kcp=["none", "srtp", "utp", "wechat-video", "dtls", "wireguard"]
var host: String = ""
var sni: String = ""
var path: String = ""
Expand All @@ -544,14 +545,15 @@ class VlessUri {
URLQueryItem(name: "flow", value: self.flow),
URLQueryItem(name: "security", value: self.security),
URLQueryItem(name: "encryption", value: self.encryption),
URLQueryItem(name: "type", value: self.type),
URLQueryItem(name: "type", value: self.network), // 网络类型: tcp,http,kcp,h2,ws,quic,grpc,domainsocket
URLQueryItem(name: "host", value: self.host),
URLQueryItem(name: "path", value: self.path),
URLQueryItem(name: "sni", value: self.sni),
URLQueryItem(name: "fp", value: self.fp),
URLQueryItem(name: "pbk", value: self.pbk),
URLQueryItem(name: "sid", value: self.sid),
URLQueryItem(name: "serviceName", value: self.path),
URLQueryItem(name: "headerType", value: self.headerType),
URLQueryItem(name: "mode", value: self.grpcMode),
URLQueryItem(name: "seed", value: self.kcpSeed)
]
Expand Down Expand Up @@ -594,7 +596,7 @@ class VlessUri {
self.security = item.value as! String
break
case "type":
self.type = item.value as! String
self.network = item.value as! String
break
case "host":
self.host = item.value as! String
Expand All @@ -615,7 +617,7 @@ class VlessUri {
self.sid = item.value as! String
break
case "headerType":
self.type = item.value as! String
self.headerType = item.value as! String
break
case "seed":
self.kcpSeed = item.value as! String
Expand Down
2 changes: 2 additions & 0 deletions V2rayU/v2ray/V2rayConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ class V2rayConfig: NSObject {

if transport.kcpSettings != nil {
self.streamKcp = transport.kcpSettings!
print("self.streamKcp",self.streamKcp)
}

if transport.wsSettings != nil {
Expand Down Expand Up @@ -1100,6 +1101,7 @@ class V2rayConfig: NSObject {
kcpSettings.congestion = streamJson["kcpSettings"]["congestion"].boolValue
kcpSettings.readBufferSize = streamJson["kcpSettings"]["readBufferSize"].intValue
kcpSettings.writeBufferSize = streamJson["kcpSettings"]["writeBufferSize"].intValue
kcpSettings.seed = streamJson["kcpSettings"]["seed"].stringValue
// "none"
if KcpSettingsHeaderType.firstIndex(of: streamJson["kcpSettings"]["header"]["type"].stringValue) != nil {
kcpSettings.header.type = streamJson["kcpSettings"]["header"]["type"].stringValue
Expand Down
2 changes: 1 addition & 1 deletion V2rayU/v2ray/v2rayStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct TcpSettingHeader: Codable {
struct TcpSettingHeaderRequest: Codable {
var version: String = "1.1"
var method: String = "GET"
var path: [String] = []
var path: [String] = [""]
var headers: TcpSettingHeaderRequestHeaders = TcpSettingHeaderRequestHeaders()
}

Expand Down

0 comments on commit 45e9adf

Please sign in to comment.