private static void boundStreamSettings(VMess server, ref StreamSettings streamSettings) { try { streamSettings.network = server.TransferProtocol; var host = server.Host; if (server.TLSSecure) { streamSettings.security = "tls"; var tlsSettings = new TlsSettings { allowInsecure = Global.Settings.V2RayConfig.AllowInsecure }; if (!string.IsNullOrWhiteSpace(host)) { tlsSettings.serverName = host; } streamSettings.tlsSettings = tlsSettings; } else { streamSettings.security = ""; } switch (server.TransferProtocol) { case "kcp": var kcpSettings = new KcpSettings { mtu = Global.Settings.V2RayConfig.KcpConfig.mtu, tti = Global.Settings.V2RayConfig.KcpConfig.tti, uplinkCapacity = Global.Settings.V2RayConfig.KcpConfig.uplinkCapacity, downlinkCapacity = Global.Settings.V2RayConfig.KcpConfig.downlinkCapacity, congestion = Global.Settings.V2RayConfig.KcpConfig.congestion, readBufferSize = Global.Settings.V2RayConfig.KcpConfig.readBufferSize, writeBufferSize = Global.Settings.V2RayConfig.KcpConfig.writeBufferSize, header = new Header { type = server.FakeType }, seed = !string.IsNullOrWhiteSpace(server.Path) ? server.Path : null }; streamSettings.kcpSettings = kcpSettings; break; case "ws": var path = server.Path; var wsSettings = new WsSettings { connectionReuse = true, headers = !string.IsNullOrWhiteSpace(host) ? new Headers { Host = host } : null, path = !string.IsNullOrWhiteSpace(path) ? path : null }; streamSettings.wsSettings = wsSettings; break; case "h2": var httpSettings = new HttpSettings { host = new List <string> { string.IsNullOrWhiteSpace(server.Host) ? server.Hostname : server.Host }, path = server.Path }; streamSettings.httpSettings = httpSettings; break; case "quic": var quicSettings = new QuicSettings { security = host, key = server.Path, header = new Header { type = server.FakeType } }; if (server.TLSSecure) { streamSettings.tlsSettings.serverName = server.Hostname; } streamSettings.quicSettings = quicSettings; break; case "xtls": streamSettings.security = server.TransferProtocol; var xtlsSettings = new TlsSettings { allowInsecure = Global.Settings.V2RayConfig.AllowInsecure }; if (!string.IsNullOrWhiteSpace(host)) { xtlsSettings.serverName = host; } streamSettings.xtlsSettings = xtlsSettings; break; default: if (server.FakeType == "http") { var tcpSettings = new TcpSettings { connectionReuse = true, header = new Header { type = server.FakeType, request = new TCPRequest { path = string.IsNullOrWhiteSpace(server.Path) ? "/" : server.Path, headers = new TCPRequestHeaders { Host = string.IsNullOrWhiteSpace(server.Host) ? server.Hostname : server.Host } } } }; streamSettings.tcpSettings = tcpSettings; } break; } } catch { // ignored } }
/// <summary> /// vmess协议远程服务器底层传输配置 /// </summary> /// <param name="config"></param> /// <param name="iobound"></param> /// <param name="streamSettings"></param> /// <returns></returns> private static int boundStreamSettings(Config config, string iobound, ref StreamSettings streamSettings) { try { //远程服务器底层传输配置 streamSettings.network = config.network(); streamSettings.security = config.streamSecurity(); //streamSettings switch (config.network()) { //kcp基本配置暂时是默认值,用户能自己设置伪装类型 case "kcp": KcpSettings kcpSettings = new KcpSettings(); kcpSettings.mtu = config.kcpItem.mtu; kcpSettings.tti = config.kcpItem.tti; if (iobound.Equals("out")) { kcpSettings.uplinkCapacity = config.kcpItem.uplinkCapacity; kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity; } else if (iobound.Equals("in")) { kcpSettings.uplinkCapacity = config.kcpItem.downlinkCapacity;; kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity; } else { kcpSettings.uplinkCapacity = config.kcpItem.uplinkCapacity; kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity; } kcpSettings.congestion = config.kcpItem.congestion; kcpSettings.readBufferSize = config.kcpItem.readBufferSize; kcpSettings.writeBufferSize = config.kcpItem.writeBufferSize; kcpSettings.header = new Header(); kcpSettings.header.type = config.headerType(); streamSettings.kcpSettings = kcpSettings; break; //ws case "ws": WsSettings wsSettings = new WsSettings(); wsSettings.connectionReuse = true; string host2 = config.requestHost().Replace(" ", ""); string path = config.path().Replace(" ", ""); if (!string.IsNullOrWhiteSpace(host2)) { wsSettings.headers = new Headers(); wsSettings.headers.Host = host2; } if (!string.IsNullOrWhiteSpace(path)) { wsSettings.path = path; } streamSettings.wsSettings = wsSettings; TlsSettings tlsSettings = new TlsSettings(); tlsSettings.allowInsecure = config.allowInsecure(); streamSettings.tlsSettings = tlsSettings; break; //h2 case "h2": HttpSettings httpSettings = new HttpSettings(); string host3 = config.requestHost().Replace(" ", ""); if (!string.IsNullOrWhiteSpace(host3)) { httpSettings.host = Utils.String2List(host3); } httpSettings.path = config.path().Replace(" ", ""); streamSettings.httpSettings = httpSettings; TlsSettings tlsSettings2 = new TlsSettings(); tlsSettings2.allowInsecure = config.allowInsecure(); streamSettings.tlsSettings = tlsSettings2; break; default: //tcp带http伪装 if (config.headerType().Equals(Global.TcpHeaderHttp)) { TcpSettings tcpSettings = new TcpSettings(); tcpSettings.connectionReuse = true; tcpSettings.header = new Header(); tcpSettings.header.type = config.headerType(); //request填入自定义Host string request = Utils.GetEmbedText(Global.v2raySampleHttprequestFileName); string[] arrHost = config.requestHost().Replace(" ", "").Split(','); string host = string.Join("\",\"", arrHost); request = request.Replace("$requestHost$", string.Format("\"{0}\"", host)); //request = request.Replace("$requestHost$", string.Format("\"{0}\"", config.requestHost())); string response = Utils.GetEmbedText(Global.v2raySampleHttpresponseFileName); tcpSettings.header.request = Utils.FromJson <object>(request); tcpSettings.header.response = Utils.FromJson <object>(response); streamSettings.tcpSettings = tcpSettings; } break; } } catch { } return(0); }
/// <summary> /// vmess协议远程服务器底层传输配置 /// </summary> /// <param name="config"></param> /// <param name="iobound"></param> /// <param name="streamSettings"></param> /// <returns></returns> private static int boundStreamSettings(Config config, string iobound, ref StreamSettings streamSettings) { try { //远程服务器底层传输配置 streamSettings.network = config.network(); streamSettings.security = config.streamSecurity(); //streamSettings switch (config.network()) { //kcp基本配置暂时是默认值,用户能自己设置伪装类型 case "kcp": KcpSettings kcpSettings = new KcpSettings(); kcpSettings.mtu = 1350; kcpSettings.tti = 50; if (iobound.Equals("out")) { kcpSettings.uplinkCapacity = 12; kcpSettings.downlinkCapacity = 100; } else if (iobound.Equals("in")) { kcpSettings.uplinkCapacity = 100; kcpSettings.downlinkCapacity = 100; } else { kcpSettings.uplinkCapacity = 12; kcpSettings.downlinkCapacity = 100; } kcpSettings.congestion = false; kcpSettings.readBufferSize = 2; kcpSettings.writeBufferSize = 2; kcpSettings.header = new Header(); kcpSettings.header.type = config.headerType(); streamSettings.kcpSettings = kcpSettings; break; //ws case "ws": WsSettings wsSettings = new WsSettings(); wsSettings.connectionReuse = true; wsSettings.path = config.requestHost(); streamSettings.wsSettings = wsSettings; break; default: //tcp带http伪装 if (config.headerType().Equals(Global.TcpHeaderHttp)) { TcpSettings tcpSettings = new TcpSettings(); tcpSettings.connectionReuse = true; tcpSettings.header = new Header(); tcpSettings.header.type = config.headerType(); //request填入自定义Host string request = Utils.GetEmbedText(Global.v2raySampleHttprequestFileName); string[] arrHost = config.requestHost().Split(','); string host = string.Join("\",\"", arrHost); request = request.Replace("$requestHost$", string.Format("\"{0}\"", host)); //request = request.Replace("$requestHost$", string.Format("\"{0}\"", config.requestHost())); string response = Utils.GetEmbedText(Global.v2raySampleHttpresponseFileName); tcpSettings.header.request = Utils.FromJson <object>(request); tcpSettings.header.response = Utils.FromJson <object>(response); streamSettings.tcpSettings = tcpSettings; } break; } } catch { } return(0); }