Skip to content

Commit

Permalink
grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
yanue committed Jul 21, 2024
1 parent de04b2e commit c465324
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
37 changes: 24 additions & 13 deletions V2rayU/Import.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ class ImportUri {
}

func importVmess(vmess: VmessUri) {
if vmess.fp.isEmpty {
vmess.fp = "chrome"
}
if vmess.security.isEmpty {
vmess.security = "none"
}
if vmess.sni.count == 0 {
vmess.sni = vmess.address
}

let v2ray = V2rayConfig()

var vmessItem = V2rayOutboundVMessItem()
Expand Down Expand Up @@ -232,12 +242,10 @@ class ImportUri {
v2ray.streamKcp.header.type = vmess.type
v2ray.streamKcp.uplinkCapacity = vmess.uplinkCapacity
v2ray.streamKcp.downlinkCapacity = vmess.downlinkCapacity
v2ray.streamKcp.seed = vmess.kcpSeed

// h2
if v2ray.streamH2.host.count == 0 {
v2ray.streamH2.host = [""]
}
v2ray.streamH2.host[0] = vmess.netHost
v2ray.streamH2.host = [vmess.netHost]
v2ray.streamH2.path = vmess.netPath

// ws
Expand Down Expand Up @@ -311,6 +319,9 @@ class ImportUri {
if vmess.flow.isEmpty {
vmess.flow = "xtls-rprx-vision"
}
if vmess.sni.count == 0 {
vmess.sni = vmess.address
}

let v2ray = V2rayConfig()
v2ray.serverProtocol = V2rayProtocolOutbound.vless.rawValue
Expand All @@ -326,10 +337,6 @@ class ImportUri {
vmessItem.users = [user]
v2ray.serverVless = vmessItem

if vmess.sni.count == 0 {
vmess.sni = vmess.address
}

// stream
v2ray.streamNetwork = vmess.type
v2ray.streamSecurity = vmess.security
Expand All @@ -345,12 +352,10 @@ class ImportUri {

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

// h2
if v2ray.streamH2.host.count == 0 {
v2ray.streamH2.host = [""]
}
v2ray.streamH2.host[0] = vmess.host
v2ray.streamH2.host = [vmess.host]
v2ray.streamH2.path = vmess.path

// ws
Expand All @@ -363,7 +368,13 @@ class ImportUri {

// tcp
v2ray.streamTcp.header.type = vmess.type

if v2ray.streamNetwork == "tcp" && v2ray.streamTcp.header.type == "http" {
var tcpReq = TcpSettingHeaderRequest()
tcpReq.path = [vmess.path]
tcpReq.headers.host = [vmess.host]
v2ray.streamTcp.header.request = tcpReq
}

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

Expand Down
21 changes: 21 additions & 0 deletions V2rayU/Uri.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class VmessUri {
var alpn: String = ""
var sni: String = ""
var fp: String = ""
var grpcMode:String = ""
var kcpSeed:String = ""

/**
vmess://base64(security:uuid@host:port)?[urlencode(parameters)]
Expand Down Expand Up @@ -145,6 +147,13 @@ class VmessUri {
case "remark":
self.remark = param[1].urlDecoded()
break
case "serviceName":
self.netPath = param[1]
break
case "mode":
self.grpcMode = param[1]
case "seed":
self.kcpSeed = param[1]
default:
break
}
Expand Down Expand Up @@ -219,6 +228,8 @@ class VmessUri {
self.fp = json["fp"].stringValue
// type:伪装类型(none\http\srtp\utp\wechat-video)
self.type = json["type"].stringValue
self.kcpSeed = json["seed"].stringValue
self.grpcMode = json["mode"].stringValue
}
}

Expand Down Expand Up @@ -520,6 +531,7 @@ class VlessUri {
var pbk: String = "" // reality public key
var sid: String = "" // reality shortId
var grpcMode:String = ""
var kcpSeed:String = ""

// vless://[email protected]:443?flow=xtls-rprx-splite&encryption=none&security=xtls&sni=aaaaa&type=http&host=00.com&path=%2fvl#vless1
func encode() -> String {
Expand All @@ -539,6 +551,9 @@ class VlessUri {
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: "mode", value: self.grpcMode),
URLQueryItem(name: "seed", value: self.kcpSeed)
]

return (uri.url?.absoluteString ?? "") + "#" + self.remark
Expand Down Expand Up @@ -602,6 +617,12 @@ class VlessUri {
case "sid":
self.sid = item.value as! String
break
case "headerType":
self.type = item.value as! String
break
case "seed":
self.kcpSeed = item.value as! String
break
case "serviceName":
self.path = item.value as! String
break
Expand Down
1 change: 1 addition & 0 deletions V2rayU/v2ray/v2rayStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ struct KcpSettings: Codable {
var congestion: Bool = false
var readBufferSize: Int = 1
var writeBufferSize: Int = 1
var seed:String = ""
var header: KcpSettingsHeader = KcpSettingsHeader()
}

Expand Down

0 comments on commit c465324

Please sign in to comment.