Ejemplo n.º 1
0
        public void Connect(VpnEndpoint endpoint, VpnCredentials credentials, VpnConfig config)
        {
            _config      = config;
            _endpoint    = endpoint;
            _credentials = credentials;

            _connectAction.Run();
        }
 public void StartGravityTurn()
 {
     GravityTurnStart = VSL.Altitude.Absolute;
     ApoapsisReached  = false;
     GearAction.Run();
     CFG.VTOLAssistON    = false;
     CFG.StabilizeFlight = false;
     CFG.HF.Off();
 }
Ejemplo n.º 3
0
        private async Task <IDnsClient> GetDnsClient()
        {
            if (_addressChanged)
            {
                await _refreshDnsClient.Run();
            }

            return(_dnsClient);
        }
Ejemplo n.º 4
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken token)
        {
            if (!_appSettings.DoHEnabled || _guestHoleState.Active)
            {
                ResetBackendHost();
                return(await SendInternalAsync(request, token));
            }

            if (ProxyActivated())
            {
                try
                {
                    _activeBackendHost = _appSettings.ActiveAlternativeApiBaseUrl;
                    return(await SendInternalAsync(request, token));
                }
                catch (Exception e) when(e.IsPotentialBlocking())
                {
                    ResetBackendHost();
                    return(await SendAsync(request, token));
                }
            }

            try
            {
                return(await SendInternalAsync(request, token));
            }
            catch (Exception e) when(e.IsPotentialBlocking())
            {
                await _fetchProxies.Run();

                if (_appSettings.AlternativeApiBaseUrls.Count == 0)
                {
                    throw;
                }

                if (await IsApiReachable(request, token))
                {
                    try
                    {
                        return(await SendInternalAsync(request, token));
                    }
                    catch (Exception ex) when(ex.IsPotentialBlocking())
                    {
                        throw;
                    }
                }

                var alternativeResult = await TryAlternativeHosts(request, token);

                if (alternativeResult.Success)
                {
                    return(alternativeResult.Value);
                }

                throw;
            }
        }
Ejemplo n.º 5
0
        public void Connect(VpnEndpoint endpoint, VpnCredentials credentials, VpnConfig config)
        {
            if (endpoint.Server.X25519PublicKey == null)
            {
                InvokeStateChange(VpnStatus.Disconnected, VpnError.MissingServerPublicKey);
                return;
            }

            _credentials = credentials;
            _endpoint    = endpoint;
            _vpnConfig   = config;

            _connectAction.Run();
        }
Ejemplo n.º 6
0
 public bool Liftoff()
 {
     UpdateTargetPosition();
     VSL.Engines.ActivateEngines();
     if (VSL.VerticalSpeed.Absolute / VSL.Physics.G < MinClimbTime)
     {
         Status("Liftoff...");
         CFG.DisableVSC();
         CFG.VTOLAssistON = true;
         THR.Throttle     = 1;
         return(true);
     }
     GravityTurnStart = VSL.Altitude.Absolute;
     ApoapsisReached  = false;
     GearAction.Run();
     CFG.VTOLAssistON    = false;
     CFG.StabilizeFlight = false;
     CFG.HF.Off();
     return(false);
 }
Ejemplo n.º 7
0
 public Task Update()
 {
     return(_updateAction.Run());
 }
Ejemplo n.º 8
0
 public async Task Update()
 {
     await _updateAction.Run();
 }
Ejemplo n.º 9
0
        protected override void Update()
        {
            //update state
            if (was_landed && !VSL.LandedOrSplashed)
            {
                stage = Stage.JustTookoff; GearTimer.Reset(); StopAction.Reset();
            }
            else if (VSL.LandedOrSplashed && !was_landed)
            {
                stage = Stage.JustLanded1;
            }
            was_landed = VSL.LandedOrSplashed;
            switch (stage)
            {
            case Stage.JustLanded1:
                working();
                srf_normal = Vector3.zero;
                CFG.HF.OnIfNot(HFlight.Level);
                VSL.BrakesOn();
                LandedTimer.RunIf(() => stage = Stage.JustLanded2,
                                  VSL.HorizontalSpeed < C.MinHSpeed);
                break;

            case Stage.JustLanded2:
                if (ATC != null)
                {
                    if (srf_normal.IsZero())
                    {
                        RaycastHit hit;
                        if (Physics.Raycast(VSL.Physics.wCoM, -VSL.Physics.Up, out hit, VSL.Geometry.D, Radar.RadarMask))
                        {
                            if (hit.collider != null && !hit.normal.IsZero())
                            {
                                srf_normal = -hit.normal;
                                break;
                            }
                        }
                        stage = Stage.Landed;
                        break;
                    }
                    working();
                    CFG.HF.Off();
                    CFG.AT.OnIfNot(Attitude.Custom);
                    ATC.SetThrustDirW(srf_normal);
                    LandedTimer.RunIf(() => { stage = Stage.Landed; CFG.AT.Off(); },
                                      VSL.Physics.NoRotation || VSL.Controls.AttitudeError < 1);
                    break;
                }
                stage = Stage.Landed;
                break;

            case Stage.JustTookoff:
                working();
                StopAction.Run();
                GearTimer.RunIf(() =>
                {
                    VSL.BrakesOn(false);
                    VSL.GearOn(false);
                    stage = Stage.Flying;
                }, VSL.Altitude.Relative > 2 * VSL.Geometry.H);
                break;

            case Stage.Landed:
                if (CFG.VerticalCutoff <= 0)
                {
                    working(false);
                }
                else
                {
                    var avSqr = VSL.vessel.angularVelocity.sqrMagnitude;
                    if (VSL.HorizontalSpeed < C.MaxHSpeed &&
                        avSqr > C.MinAngularVelocity)
                    {
                        working();
                        CFG.HF.OnIfNot(HFlight.Level);
                        if (avSqr > C.GearOffAngularVelocity &&
                            VSL.OnPlanetParams.DTWR > C.MinDTWR)
                        {
                            VSL.GearOn(false);
                        }
                    }
                    else
                    {
                        working(false);
                    }
                }
                break;

            case Stage.Flying:
                working(false);
                if (!VSL.vessel.ActionGroups[KSPActionGroup.Gear])
                {
                    if (VSL.VerticalSpeed.Relative < 0 &&
                        VSL.HorizontalSpeed < C.GearOnMaxHSpeed &&
                        (!CFG.AT || !VSL.Altitude.AboveGround || VSL.Engines.Thrust.IsZero()) &&
                        VSL.Altitude.Relative +
                        VSL.VerticalSpeed.Relative * (VSL.OnPlanetParams.GearDeployTime + C.GearOnTime)
                        < C.GearOnAtH * VSL.Geometry.H)
                    {
                        VSL.GearOn();
                        VSL.BrakesOn();
                    }
                }
                else if (VSL.OnPlanetParams.GearDeploying)
                {
                    if (VSC != null)
                    {
                        VSC.SetpointOverride = Utils.ClampH((C.GearOnAtH * VSL.Geometry.H - VSL.Altitude.Relative) /
                                                            (VSL.OnPlanetParams.GearDeployTime + C.GearOnTime), 0);
                    }
                }
                else
                {
                    GearTimer.RunIf(() =>
                    {
                        VSL.GearOn(false);
                        VSL.BrakesOn(false);
                    },
                                    VSL.VerticalSpeed.Relative > 5 ||
                                    VSL.HorizontalSpeed > C.GearOnMaxHSpeed ||
                                    VSL.VerticalSpeed.Relative > 0 && VSL.Altitude.Relative > VSL.Geometry.H * 5);
                }
                break;
            }
        }
Ejemplo n.º 10
0
 public void Start()
 {
     _ringLogger.Start();
     _receiveLogsAction.Run();
 }
Ejemplo n.º 11
0
 public Task Validate()
 {
     return(_validateAction.Run());
 }
Ejemplo n.º 12
0
 public void Disconnect(VpnError error)
 {
     _disconnectError = error;
     _disconnectAction.Run();
 }
Ejemplo n.º 13
0
 protected override void Update()
 {
     if (!IsActive)
     {
         return;
     }
     //update state
     if (last_state && !VSL.LandedOrSplashed)
     {
         tookoff = true; landed = false; GearTimer.Reset(); StopAction.Reset();
     }
     else if (VSL.LandedOrSplashed && !last_state)
     {
         landed = true; tookoff = false;
     }
     last_state = VSL.LandedOrSplashed;
     //just landed
     if (landed)
     {
         working();
         CFG.HF.OnIfNot(HFlight.Level);
         VSL.BrakesOn();
         LandedTimer.RunIf(() => landed = false,
                           VSL.HorizontalSpeed < TLA.MinHSpeed);
     }
     //just took off
     else if (tookoff)
     {
         working();
         StopAction.Run();
         GearTimer.RunIf(() =>
         {
             VSL.BrakesOn(false);
             VSL.GearOn(false);
             tookoff = false;
         }, VSL.Altitude.Relative > TLA.GearOnAtH + VSL.Geometry.H);
     }
     //moving on the ground
     else if (VSL.LandedOrSplashed)
     {
         var avSqr = VSL.vessel.angularVelocity.sqrMagnitude;
         if (VSL.HorizontalSpeed < TLA.MaxHSpeed &&
             avSqr > TLA.MinAngularVelocity)
         {
             working();
             CFG.HF.OnIfNot(HFlight.Level);
             if (avSqr > TLA.GearOffAngularVelocity &&
                 VSL.OnPlanetParams.DTWR > TLA.MinDTWR)
             {
                 VSL.GearOn(false);
             }
         }
         else
         {
             working(false);
         }
     }
     //if flying, check if trying to land and deploy the gear
     else
     {
         working(false);
         //if the gear is on, nothing to do; and autopilot takes precedence
         if (!VSL.vessel.ActionGroups[KSPActionGroup.Gear])
         {
             //check boundary conditions
             GearTimer.RunIf(() =>
             {
                 VSL.GearOn();
                 VSL.BrakesOn();
             },
                             VSL.VerticalSpeed.Relative < 0 &&
                             VSL.HorizontalSpeed < TLA.GearOnMaxHSpeed &&
                             VSL.Altitude.Relative + VSL.VerticalSpeed.Relative * (TLA.GearOnTime + TLA.GearTimer) < TLA.GearOnAtH * VSL.Geometry.H);
         }
         else
         {
             GearTimer.RunIf(() =>
             {
                 VSL.GearOn(false);
                 VSL.BrakesOn(false);
             },
                             VSL.VerticalSpeed.Relative > 5 ||
                             VSL.HorizontalSpeed > TLA.GearOnMaxHSpeed ||
                             VSL.VerticalSpeed.Relative > 0 && VSL.Altitude.Relative > VSL.Geometry.H * 5);
         }
     }
 }
Ejemplo n.º 14
0
 public void Start()
 {
     _updateBytesTransferredAction.Run();
 }
Ejemplo n.º 15
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken token)
        {
            if (!_appSettings.DoHEnabled || _guestHoleState.Active)
            {
                ResetBackendHost();
                return(await SendInternalAsync(request, token));
            }

            if (ProxyActivated())
            {
                try
                {
                    _activeBackendHost = _appSettings.ActiveAlternativeApiBaseUrl;
                    _logger.Info($"[AlternativeHostHandler: sending request using {_activeBackendHost}");

                    return(await SendInternalAsync(request, token));
                }
                catch (Exception e) when(e.IsPotentialBlocking())
                {
                    _logger.Info($"[AlternativeHostHandler] request failed while DoH active. Host: {_activeBackendHost}");

                    ResetBackendHost();
                    return(await SendAsync(request, token));
                }
            }

            try
            {
                return(await SendInternalAsync(request, token));
            }
            catch (Exception e) when(_isDisconnected && e.IsPotentialBlocking())
            {
                _logger.Info("[AlternativeHostHandler] request failed due to potentially not reachable api.");

                await _fetchProxies.Run();

                if (_appSettings.AlternativeApiBaseUrls.Count == 0)
                {
                    throw;
                }

                if (await IsApiReachable(request, token))
                {
                    _logger.Info("[AlternativeHostHandler] ping success, retrying original request.");

                    try
                    {
                        return(await SendInternalAsync(request, token));
                    }
                    catch (Exception ex) when(ex.IsPotentialBlocking())
                    {
                        throw;
                    }
                }

                Result <HttpResponseMessage> alternativeResult = await TryAlternativeHosts(request, token);

                if (alternativeResult.Success)
                {
                    return(alternativeResult.Value);
                }

                throw;
            }
        }