Пример #1
0
 public void SetStreamSettingsTcp(ref StreamSettings item, bool bConnectionReuse, string sHeaderType, object oHeaderRequest, object oHeaderResponse)
 {
     item.tcpSettings.connectionReuse = bConnectionReuse;
     item.tcpSettings.header.type     = sHeaderType;
     item.tcpSettings.header.request  = oHeaderRequest;
     item.tcpSettings.header.response = oHeaderResponse;
 }
Пример #2
0
        /// <summary>Checks the stream identifier against the specified stream type and sets defaults.</summary>
        public MDBStreamSetting GetStreamSettings(long streamID)
        {
            MDBStreamSetting result = StreamSettings.TryGetStruct(streamID);
            bool             update = false;

            if (result.StreamID != streamID)
            {
                result.StreamID = streamID;
                if (result.Volume == 0)
                {
                    result.Volume = 1;
                }
                update = true;
            }
            switch (result.StreamType)
            {
            case MDBStreamType.Silence: break;

            case MDBStreamType.JukeBob: if (result.MinimumTitleCount < 1)
                {
                    update = true; result.MinimumTitleCount = 5;
                }
                break;

            default: throw new NotImplementedException();
            }
            if (update)
            {
                StreamSettings.Replace(result);
            }
            return(result);
        }
Пример #3
0
        public Twitch(StreamSettings settings)
            : base(settings)
        {
            ApiName = "Twitch";
            ApiInfo = new StreamApiInfo()
            {
                isFontLogo = false,
                logo       = "Twitch",
                color      = new SolidColorBrush(Color.FromRgb(0x69, 0x3D, 0xA5))
            };

            if (settings is TwitchSettings)
            {
                _settings = settings as TwitchSettings;
                if (!string.IsNullOrEmpty(_settings.OAuthToken))
                {
                    SetAuthorizationKey(_settings.OAuthToken);
                }
            }

            _headers.Add("Client-ID", "ca48u330owoiyhvnmmwl7rkai3i6vqs");
            _headers.Add("Accept", "application/vnd.twitchtv.v5+json");

            _baseUrl = "https://api.twitch.tv/kraken/";

            _allowedActions[StreamCapabilities.UpdateChannel] = true;
            _allowedActions[StreamCapabilities.DisplayChat]   = true;
        }
Пример #4
0
 /// <summary>
 /// 底层传输基本配置
 /// </summary>
 /// <param name="item"></param>
 /// <param name="sNetWork"></param>
 /// <param name="sSecurity"></param>
 /// <param name="bTlsAllowInsecure"></param>
 /// <param name="sTlsServerName"></param>
 public void SetStreamSettingsBase(ref StreamSettings item, string sNetWork, string sSecurity, bool bTlsAllowInsecure = false, string sTlsServerName = null)
 {
     item.network  = sNetWork;
     item.security = sSecurity;
     item.tlsSettings.allowInsecure = bTlsAllowInsecure;
     item.tlsSettings.serverName    = sTlsServerName;
 }
 public void OnPost(StreamSettings settings)
 {
     if (settings != null)
     {
         _manager.Remove(settings.ListeningPort);
     }
 }
Пример #6
0
        public void TestSetup()
        {
            state = Substitute.For <IStreamState>();
            state.Name.Returns(StreamName);
            state.BufferPool.Returns(pool   = Substitute.For <IBufferPool>());
            state.Statistics.Returns(stats  = Substitute.For <IStatisticsCollector>());
            state.Settings.Returns(settings = new StreamSettings());

            batcher          = new BufferSnapshotBatcher(1);
            contentFactory   = new RequestContentFactory(new BufferPool());
            responseAnalyzer = new ResponseAnalyzer(ResponseAnalysisContext.Stream);
            statusAnalyzer   = new StatusAnalyzer();

            requestSender = Substitute.For <IGateRequestSender>();

            sender = new StreamSender(
                () => GlobalApiKey,
                state,
                batcher,
                contentFactory,
                requestSender,
                responseAnalyzer,
                statusAnalyzer,
                new SynchronousConsoleLog());

            cancellation = new CancellationTokenSource();

            SetupBuffers(50, 100, 150);
            SetupResponses(HerculesStatus.Success);
        }
Пример #7
0
        /// <summary>
        /// vmess协议服务器配置
        /// </summary>
        /// <param name="config"></param>
        /// <param name="v2rayConfig"></param>
        /// <returns></returns>
        private static int ServerInbound(Config config, ref V2rayConfig v2rayConfig)
        {
            try
            {
                UsersItem usersItem;
                if (v2rayConfig.inbound.settings.clients.Count <= 0)
                {
                    usersItem = new UsersItem();
                    v2rayConfig.inbound.settings.clients.Add(usersItem);
                }
                else
                {
                    usersItem = v2rayConfig.inbound.settings.clients[0];
                }
                //远程服务器端口
                v2rayConfig.inbound.port = config.port();

                //远程服务器用户ID
                usersItem.id      = config.id();
                usersItem.alterId = config.alterId();
                usersItem.email   = Global.userEMail;

                //远程服务器底层传输配置
                StreamSettings streamSettings = v2rayConfig.inbound.streamSettings;
                boundStreamSettings(config, "in", ref streamSettings);
            }
            catch
            {
            }
            return(0);
        }
Пример #8
0
 public void SetStreamSettingsQuic(ref StreamSettings item, string security, string key, string sHeaderType, object oHeaderRequest, object oHeaderResponse)
 {
     item.quicSettings.security        = security;
     item.quicSettings.key             = key;
     item.quicSettings.header.type     = sHeaderType;
     item.quicSettings.header.request  = oHeaderRequest;
     item.quicSettings.header.response = oHeaderResponse;
 }
Пример #9
0
 IEnumerable <NewsEntryInfo> GetNewsEntries(ModuleInfo module, StreamSettings settings)
 {
     return(NewsRepository.Instance.GetNewsEntries_FirstPage(PortalSettings.PortalId,
                                                             settings.FeedMaxEntries ?? NewsConfig.Instance.Feed.DefaultMaxEntries,
                                                             HttpContext.Current.Timestamp,
                                                             new WeightRange(settings.MinThematicWeight, settings.MaxThematicWeight),
                                                             new WeightRange(settings.MinStructuralWeight, settings.MaxStructuralWeight),
                                                             settings.ShowAllNews, settings.IncludeTerms, out int newsEntriesCount));
 }
Пример #10
0
 protected IEnumerable <INewsEntry> GetNewsEntries(int portalId, StreamSettings settings)
 {
     return(NewsRepository.Instance.GetNewsEntries_FirstPage(
                portalId, settings.PageSize, DateTime.Now,
                new WeightRange(settings.MinThematicWeight, settings.MaxThematicWeight),
                new WeightRange(settings.MinStructuralWeight, settings.MaxStructuralWeight),
                settings.ShowAllNews, settings.IncludeTerms, out int newsEntriesCount
                ));
 }
Пример #11
0
        public StartCommand()
        {
            Type = CommandType.Start;
            Key  = "start";

            Settings = new StreamSettings
            {
                ListeningPort = 9999
            };
        }
Пример #12
0
 protected IEnumerable <INewsEntry> GetNewsEntries(StreamSettings settings, int newsCount, int portalId)
 {
     // TODO: Cache the result?
     return(NewsRepository.Instance.GetNewsEntries_FirstPage(
                portalId, newsCount, DateTime.Now,
                new WeightRange(settings.MinThematicWeight, settings.MaxThematicWeight),
                new WeightRange(settings.MinStructuralWeight, settings.MaxStructuralWeight),
                settings.ShowAllNews, settings.IncludeTerms, out int newsEntriesCount
                ));
 }
        public PageResult OnGet(int?port)
        {
            if (port.HasValue)
            {
                var streamSimulator = _manager.Get(port.Value);
                StreamSettings = streamSimulator?.Settings;
            }

            return(Page());
        }
Пример #14
0
        public void OnPost(StreamSettings settings)
        {
            if (settings != null)
            {
                var stream = _manager.Add(settings);
                stream.Start();
            }

            Redirect("/Index");
        }
Пример #15
0
        public StreamModuleViewModel(ModuleInfo module, StreamSettings settings, ViewModelContext context, int newsEntryThematicWeight, int newsEntryStructuralWeight,
                                     IList <Term> newsEntryTerms)
        {
            Module   = module;
            Settings = settings;
            Context  = context;

            NewsEntry_ThematicWeight   = newsEntryThematicWeight;
            NewsEntry_StructuralWeight = newsEntryStructuralWeight;
            NewsEntry_Terms            = newsEntryTerms;
        }
Пример #16
0
 public static bool IsNewsEntryWillBePassedByModule(
     StreamSettings settings,
     int thematicWeight,
     int structuralWeight,
     IList <Term> terms)
 {
     return((settings.ShowAllNews || ModelHelper.IsTermsOverlaps(terms, settings.IncludeTerms)) &&
            ModelHelper.IsVisible(thematicWeight, structuralWeight,
                                  settings.MinThematicWeight, settings.MaxThematicWeight,
                                  settings.MinStructuralWeight, settings.MaxStructuralWeight
                                  ));
 }
Пример #17
0
 public void SetStreamSettingsKcp(ref StreamSettings item, int mtu, int tti, int uplinkCapacity, int downlinkCapacity, bool congestion, int readBufferSize, int writeBufferSize, string sHeaderType, object oHeaderRequest, object oHeaderResponse)
 {
     item.kcpSettings.mtu              = mtu;
     item.kcpSettings.tti              = tti;
     item.kcpSettings.uplinkCapacity   = uplinkCapacity;
     item.kcpSettings.downlinkCapacity = downlinkCapacity;
     item.kcpSettings.congestion       = congestion;
     item.kcpSettings.readBufferSize   = readBufferSize;
     item.kcpSettings.writeBufferSize  = writeBufferSize;
     item.kcpSettings.header.type      = sHeaderType;
     item.kcpSettings.header.request   = oHeaderRequest;
     item.kcpSettings.header.response  = oHeaderResponse;
 }
Пример #18
0
        public ActionResult <string> Get(int id)
        {
            var settings = new StreamSettings
            {
                ListeningPort       = 9999,
                AllowSubscribe      = true,
                HeartbeatIntervalMs = 5000,
                SendReplyCommands   = true,
            };

            _manager.Add(settings);

            return("Ok");
        }
Пример #19
0
        private async Task InitializeAfterFirstPatchAsync()
        {
            _resourceService.Start();
            Targets.Start();
            Sources.Start();
            SceneEditing.Start();
            StreamSettings.Start();
            await Vpn.StartAsync();

            Streamer.Start();
            Settings.Start();
            About.Start();
            _stateLoggerService.Start();
            Audio.Start();
        }
Пример #20
0
 private void InitializeBracketApiList()
 {
     Type[] apis = Assembly.GetExecutingAssembly().GetTypes().Where((t) => t.IsSubclassOf(typeof(StreamApi))).ToArray();
     ApiList = new ObservableCollection <string>();
     foreach (var type in apis)
     {
         StreamSettings s = new StreamSettings();
         StreamApi      a = Activator.CreateInstance(type, s) as StreamApi;
         ApiList.Add(a.ApiName);
         if (type == Configuration.Instance.Stream?.GetType())
         {
             SelectedApi = ApiList.Count - 1;
         }
     }
 }
Пример #21
0
        private void streamWindow(object sender, EventArgs e)
        {
            var settings = new StreamSettings();

            feeble = new Feeble.Feeble();
            settings.ffmpegLocation      = ffmpegLocation.Text;
            settings.recordingRegionType = RecordingRegionType.window;
            settings.windowTitle         = swWindowTitle.Text;
            settings.twitchBroadcastURL  = swBroadcastUrl.Text;
            settings.twitchStreamKey     = swStreamKey.Text;
            settings.videoBitrate        = 500;
            settings.audioDevice         = swAudioDevice.SelectedValue.ToString();
            settings.drawMouse           = swDrawMouse.Checked;

            var temp = Task.Run(() => feeble.Stream(settings));
        }
Пример #22
0
        /// <summary>
        /// vmess协议服务器配置
        /// </summary>
        /// <param name="config"></param>
        /// <param name="v2rayConfig"></param>
        /// <returns></returns>
        private static int outbound(Config config, ref V2rayConfig v2rayConfig)
        {
            try
            {
                VnextItem vnextItem;
                if (v2rayConfig.outbound.settings.vnext.Count <= 0)
                {
                    vnextItem = new VnextItem();
                    v2rayConfig.outbound.settings.vnext.Add(vnextItem);
                }
                else
                {
                    vnextItem = v2rayConfig.outbound.settings.vnext[0];
                }
                //远程服务器地址和端口
                vnextItem.address = config.address();
                vnextItem.port    = config.port();

                UsersItem usersItem;
                if (vnextItem.users.Count <= 0)
                {
                    usersItem = new UsersItem();
                    vnextItem.users.Add(usersItem);
                }
                else
                {
                    usersItem = vnextItem.users[0];
                }
                //远程服务器用户ID
                usersItem.id       = config.id();
                usersItem.alterId  = config.alterId();
                usersItem.security = config.security();

                //Mux
                v2rayConfig.outbound.mux.enabled = config.muxEnabled;

                //远程服务器底层传输配置
                StreamSettings streamSettings = v2rayConfig.outbound.streamSettings;
                boundStreamSettings(config, "out", ref streamSettings);
            }
            catch
            {
            }
            return(0);
        }
Пример #23
0
        public Twitch(StreamSettings settings)
            : base(settings)
        {
            ApiName = "Twitch";
            // Logo =
            // ControlColor = new Color()
            if (settings is TwitchSettings)
            {
                _settings = settings as TwitchSettings;
                if (!string.IsNullOrEmpty(_settings.OAuthToken))
                {
                    SetAuthorizationKey(_settings.OAuthToken);
                }
            }

            _headers.Add("Client-ID", "ca48u330owoiyhvnmmwl7rkai3i6vqs");
            _headers.Add("Accept", "application/vnd.twitchtv.v5+json");

            _baseUrl = "https://api.twitch.tv/kraken/";

            _allowedActions[StreamCapabilities.UpdateChannel] = true;
            _allowedActions[StreamCapabilities.DisplayChat]   = true;
        }
Пример #24
0
        private void streamDesktop(object sender, EventArgs e)
        {
            var settings = new StreamSettings();

            feeble = new Feeble.Feeble();
            settings.ffmpegLocation      = ffmpegLocation.Text;
            settings.recordingRegionType = RecordingRegionType.desktop;
            settings.twitchBroadcastURL  = sdBroadcastUrl.Text;
            settings.twitchStreamKey     = sdStreamKey.Text;
            settings.videoBitrate        = 500;
            settings.audioDevice         = sdAudioDevice.SelectedValue.ToString();
            settings.drawCaptureRegion   = sdDrawRegion.Checked;
            settings.drawMouse           = sdDrawMouse.Checked;

            if (sdVerRes.Text != "")
            {
                settings.verticalResolution = int.Parse(sdVerRes.Text);
            }

            if (sdHozRes.Text != "")
            {
                settings.horizontalResolution = int.Parse(sdHozRes.Text);
            }

            if (sdXOffSet.Text != "")
            {
                settings.offSetX = int.Parse(sdXOffSet.Text);
            }

            if (sdYOffset.Text != "")
            {
                settings.offSetY = int.Parse(sdYOffset.Text);
            }

            var temp = Task.Run(() => feeble.Stream(settings));
        }
Пример #25
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 = 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);
        }
Пример #26
0
        /// <summary>
        /// vmess协议服务器配置
        /// </summary>
        /// <param name="config"></param>
        /// <param name="v2rayConfig"></param>
        /// <returns></returns>
        private static int outbound(Config config, ref V2rayConfig v2rayConfig)
        {
            try
            {
                if (config.configType() == (int)EConfigType.Vmess)
                {
                    VnextItem vnextItem;
                    if (v2rayConfig.outbound.settings.vnext.Count <= 0)
                    {
                        vnextItem = new VnextItem();
                        v2rayConfig.outbound.settings.vnext.Add(vnextItem);
                    }
                    else
                    {
                        vnextItem = v2rayConfig.outbound.settings.vnext[0];
                    }
                    //远程服务器地址和端口
                    vnextItem.address = config.address();
                    vnextItem.port    = config.port();

                    UsersItem usersItem;
                    if (vnextItem.users.Count <= 0)
                    {
                        usersItem = new UsersItem();
                        vnextItem.users.Add(usersItem);
                    }
                    else
                    {
                        usersItem = vnextItem.users[0];
                    }
                    //远程服务器用户ID
                    usersItem.id       = config.id();
                    usersItem.alterId  = config.alterId();
                    usersItem.email    = Global.userEMail;
                    usersItem.security = config.security();

                    //Mux
                    v2rayConfig.outbound.mux.enabled = config.muxEnabled;

                    //远程服务器底层传输配置
                    StreamSettings streamSettings = v2rayConfig.outbound.streamSettings;
                    boundStreamSettings(config, "out", ref streamSettings);

                    v2rayConfig.outbound.protocol         = "vmess";
                    v2rayConfig.outbound.settings.servers = null;
                }
                else if (config.configType() == (int)EConfigType.Shadowsocks)
                {
                    ServersItem serversItem;
                    if (v2rayConfig.outbound.settings.servers.Count <= 0)
                    {
                        serversItem = new ServersItem();
                        v2rayConfig.outbound.settings.servers.Add(serversItem);
                    }
                    else
                    {
                        serversItem = v2rayConfig.outbound.settings.servers[0];
                    }
                    //远程服务器地址和端口
                    serversItem.address  = config.address();
                    serversItem.port     = config.port();
                    serversItem.password = config.id();
                    serversItem.method   = config.security();

                    serversItem.ota   = false;
                    serversItem.level = 1;

                    v2rayConfig.outbound.mux.enabled = false;

                    v2rayConfig.outbound.protocol       = "shadowsocks";
                    v2rayConfig.outbound.settings.vnext = null;
                }
            }
            catch
            {
            }
            return(0);
        }
 /// <inheritdoc />
 public void ConfigureStream(string stream, StreamSettings settings)
 {
 }
Пример #28
0
        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
            }
        }
Пример #29
0
    private static StreamSettings boundStreamSettings(VMessServer server)
    {
        // https://xtls.github.io/config/transports

        var streamSettings = new StreamSettings
        {
            network  = server.TransferProtocol,
            security = server.TLSSecureType
        };

        if (server.TLSSecureType != "none")
        {
            var tlsSettings = new TlsSettings
            {
                allowInsecure = Global.Settings.V2RayConfig.AllowInsecure,
                serverName    = server.ServerName.ValueOrDefault() ?? server.Host.SplitOrDefault()?[0]
            };

            switch (server.TLSSecureType)
            {
            case "tls":
                streamSettings.tlsSettings = tlsSettings;
                break;

            case "xtls":
                streamSettings.xtlsSettings = tlsSettings;
                break;
            }
        }

        switch (server.TransferProtocol)
        {
        case "tcp":

            streamSettings.tcpSettings = new TcpSettings
            {
                header = new
                {
                    type    = server.FakeType,
                    request = server.FakeType switch
                    {
                        "none" => null,
                        "http" => new
                        {
                            path    = server.Path.SplitOrDefault(),
                            headers = new
                            {
                                Host = server.Host.SplitOrDefault()
                            }
                        },
                        _ => throw new MessageException($"Invalid tcp type {server.FakeType}")
                    }
                }
            };

            break;

        case "ws":

            streamSettings.wsSettings = new WsSettings
            {
                path    = server.Path.ValueOrDefault(),
                headers = new
                {
                    Host = server.Host.ValueOrDefault()
                }
            };

            break;

        case "kcp":

            streamSettings.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
                {
                    type = server.FakeType
                },
                seed = server.Path.ValueOrDefault()
            };

            break;

        case "h2":

            streamSettings.httpSettings = new HttpSettings
            {
                host = server.Host.SplitOrDefault(),
                path = server.Path.ValueOrDefault()
            };

            break;

        case "quic":

            streamSettings.quicSettings = new QuicSettings
            {
                security = server.QUICSecure,
                key      = server.QUICSecret,
                header   = new
                {
                    type = server.FakeType
                }
            };

            break;

        case "grpc":

            streamSettings.grpcSettings = new GrpcSettings
            {
                serviceName = server.Path,
                multiMode   = server.FakeType == "multi"
            };

            break;

        default:
            throw new MessageException($"transfer protocol \"{server.TransferProtocol}\" not implemented yet");
        }

        return(streamSettings);
    }
Пример #30
0
 /// <inheritdoc />
 public void ConfigureStream(string stream, StreamSettings streamSettings)
 => ObtainStream(stream).Settings = streamSettings ?? throw new ArgumentNullException(nameof(streamSettings));