private void Log(ReceivedManagementMessage message)
 {
     if (!message.IsByteCount)
     {
         _logger.Info($"Management -> {message}");
     }
 }
Пример #2
0
        private async Task HandleStateMessage(ReceivedManagementMessage message)
        {
            var managementState = message.State();

            if (managementState.HasError)
            {
                await TrySend(_managementChannel.Messages.Disconnect());

                if (_lastError == VpnError.None)
                {
                    _lastError = managementState.Error;
                }
            }
            else
            {
                if (managementState.HasStatus)
                {
                    OnVpnStateChanged(new VpnState(managementState.Status, _lastError, managementState.LocalIpAddress, managementState.RemoteIpAddress));
                }
            }
        }
Пример #3
0
 private void HandleErrorMessage(ReceivedManagementMessage message)
 {
     _lastError = message.Error().VpnError();
 }
Пример #4
0
        private void HandleByteMessage(ReceivedManagementMessage message)
        {
            var bandwidth = message.Bandwidth();

            OnTransportStatsChanged(bandwidth);
        }
Пример #5
0
        private async void HandleMessage(ReceivedManagementMessage message)
        {
            var handled = false;

            if (message.IsState)
            {
                await HandleStateMessage(message);

                handled = true;
            }
            else if (message.IsByteCount)
            {
                HandleByteMessage(message);
                handled = true;
            }
            else if (message.IsError)
            {
                HandleErrorMessage(message);
                handled = true;
            }
            else if (message.IsDisconnectReceived)
            {
                OnVpnStateChanged(VpnStatus.Disconnecting);
                _disconnectAccepted = true;
                handled             = true;
            }
            else if (message.IsUsernameNeeded)
            {
                await TrySend(_managementChannel.Messages.Username(_credentials.Username));

                handled = true;
            }
            else if (message.IsPasswordNeeded)
            {
                await TrySend(_managementChannel.Messages.Password(_credentials.Password));

                handled = true;
            }

            if (handled)
            {
                return;
            }

            if (_disconnectRequested && !_disconnectAccepted)
            {
                await TrySend(_managementChannel.Messages.Disconnect());
            }
            else if (message.IsWaitingHoldRelease)
            {
                await TrySend(_managementChannel.Messages.EchoOn());
            }
            else if (message.IsEchoSet)
            {
                await TrySend(_managementChannel.Messages.StateOn());
            }
            else if (message.IsStateSet)
            {
                await TrySend(_managementChannel.Messages.Bytecount());
            }
            else if (message.IsByteCountSet)
            {
                await TrySend(_managementChannel.Messages.LogOn());
            }
            else if (message.IsLogSet)
            {
                await TrySend(_managementChannel.Messages.HoldRelease());
            }
        }