Beispiel #1
0
        public void Should_return_a_pong_to_the_pinger()
        {
            var pinger = new Pinger();
            var ponger = new Ponger();

            pinger.Ping(ponger.PongChannel);

            ponger.Pinged.WaitUntilCompleted(1.Seconds()).ShouldBeTrue();
            pinger.Ponged.WaitUntilCompleted(1.Seconds()).ShouldBeTrue();
        }
Beispiel #2
0
        public void Should_return_a_pong_to_the_pinger()
        {
            var pinger = new Pinger();
            var ponger = new Ponger();

            pinger.Ping(ponger.PongChannel);

            ponger.Pinged.IsAvailable(1.Seconds()).ShouldBeTrue();
            pinger.Ponged.IsAvailable(1.Seconds()).ShouldBeTrue();
        }
Beispiel #3
0
        public void Should_return_a_pong_to_the_pinger()
        {
            var pinger = new Pinger();
            var ponger = new Ponger();

            pinger.Ping(ponger.PongChannel);

            ponger.Pinged.WaitUntilCompleted(1.Seconds()).ShouldBeTrue();
            pinger.Ponged.WaitUntilCompleted(1.Seconds()).ShouldBeTrue();
        }
Beispiel #4
0
        public async Task <Dictionary <string, bool> > CheckAllSystems()
        {
            var systemDescriptors = await _systemService.GetAll();

            var resultDictionary = new Dictionary <string, bool>();

            systemDescriptors.ForEach(d =>
            {
                resultDictionary.Add(d.SystemName, Pinger.Ping($"{d.Address}", d.Port));
            });
            return(resultDictionary);
        }
Beispiel #5
0
        private void PingPeer(Object stateInfo)
        {
            if (!_pinging)
            {
                _pinging = true;
                if (IsTunnelEstablished)
                {
                    try
                    {
#if (DEBUG)
                        Logger.Debug("Pinging peer " + _remoteEndpoint);
#endif
                        var ping = _pinger.Ping(_remoteEndpoint, 10000, _udpClient);
                        // Average out the last 10 pings
                        PeerLatency = ((PeerLatency * 9) + ping) / 10;
                        if (_pingFailCount > 0)
                        {
                            Logger.Info("Pinged successfully [" + ping + "ms (" + PeerLatency + "ms avg)], recovered from " + _pingFailCount + " ping failure(s).");
                        }
                        _pingFailCount = 0;
                    }
                    catch (Exception e)
                    {
                        _pingFailCount++;
                        Logger.Warn("Ping failed [failCount=" + _pingFailCount + ", max=" + AllowedPingFailCount + "] : " + e.Message);
                        if (_pingFailCount >= AllowedPingFailCount)
                        {
                            Logger.Error("Peer failed to respond after " + _pingFailCount + " attempts, shutting down link");
                            this.Close();
                        }
                    }
                }
                else
                {
                    _pingTimer.Dispose();
                }
                _pinging = false;
            }
        }
Beispiel #6
0
 public async Task <bool> CheckSpecificSystem(SystemDescriptor descriptor)
 {
     return(await Task.Factory.StartNew(() =>
                                        Pinger.Ping($"{descriptor.Address}", descriptor.Port)
                                        ));
 }
        /// <summary>
        /// Parse and execute command line
        /// </summary>
        /// <param name="commandLine">Falcon command line string</param>
        private void ExecuteCli(string commandLine)
        {
            // ignore empty command line
            if (commandLine == "")
            {
                PrintLinePrefix();
                return;
            }

            historyBuff.ResetNavigation();
            historyBuff.AddItem(commandLine);

            if (displayMode == DisplayMode.SSH)
            {
                ssh_.RunCommand(commandLine);
                if (commandLine == "exit")
                {
                    ssh_.Close();
                    PrintToScreen("ssh session terminated.", Color.White, true);
                    ssh_        = null;
                    displayMode = DisplayMode.NORMAL;
                }
                return;
            }

            Argument argumentObj  = null;
            string   reply        = "";
            string   parserAnswer = "";

            Command.Type cmdType = Command.Type.INVALID;
            bool         validCmd;

            validCmd = CommandParser.Parse(commandLine, ref parserAnswer, ref cmdType, ref argumentObj);

            if (validCmd)
            {
                switch (cmdType)
                {
                case Command.Type.PING:
                    string targetIp = ((PingArgument)argumentObj).GetIp();
                    int    timeout  = ((PingArgument)argumentObj).GetTimeout();

                    if (timeout != -1)     // use timeout
                    {
                        Pinger.Ping(targetIp, timeout, ref reply);
                    }
                    else     // disable timeout
                    {
                        Pinger.Ping(targetIp, 0, ref reply);
                    }

                    break;

                case Command.Type.SSH:
                    bool success = ConnectSsh(((SshArgument)argumentObj).GetHostAddress(),
                                              ((SshArgument)argumentObj).GetUserName(),
                                              ((SshArgument)argumentObj).GetPassword(),
                                              ref reply,
                                              ref ssh_);
                    if (success)
                    {
                        displayMode = DisplayMode.SSH;
                    }
                    break;

                case Command.Type.CLEAR:
                    cliDisplayTxtBx.Text = "";
                    break;

                case Command.Type.INVALID:
                    break;
                }
            }

            if (parserAnswer != "")
            {
                PrintToScreen(parserAnswer + "\n", Color.White, true);
            }
            if (reply != "")
            {
                PrintToScreen(reply + "\n", Color.White, true);
            }

            PrintLinePrefix();
        }
Beispiel #8
0
        public void Pinger_Success()
        {
            var pinger = new Pinger("8.8.8.8");

            Assert.IsTrue(pinger.Ping());
        }
Beispiel #9
0
        public void Pingger_Fail()
        {
            var pinger = new Pinger("0.0.0.0");

            Assert.IsFalse(pinger.Ping());
        }