Example #1
0
        void TestOneInboundTunnel()
        {
            InboundTunnel intunnel;

            lock ( InboundTunnels )
            {
                if (InboundTunnels.Count == 0)
                {
                    return;
                }
                intunnel = InboundTunnels.First.Value;
                InboundTunnels.RemoveFirst();

                if (intunnel.NeedsRecreation)
                {
                    return;
                }
                InboundTunnels.AddLast(intunnel);
            }

            var run = OutstandingTests.Get(intunnel);

            if (run != null)
            {
                // Run has finished?
                if (run.TestedPartners.Count >= RunsPerTest)
                {
                    if (run.LastRun.DeltaToNow < TimeBetweenTests)
                    {
                        return;
                    }
                    run.OutstandingProbes.Clear();
                    run.SuccessPartners.Clear();
                    run.TestedPartners.Clear();
                }
            }
            else
            {
                run = new TestRun2(intunnel);
                OutstandingTests[intunnel] = run;
            }

            var test = TestResults.Get(intunnel, () => new TunnelTestResult(intunnel));

            var outtunnels = TunnelProvider.Inst.GetOutboundTunnels().Shuffle().Take(RunsPerTest).ToArray();;

            if (!outtunnels.Any())
            {
                //DebugUtils.LogDebug( "TunnelTester: Failed to get a established outbound tunnel." );
                return;
            }

            run.LastRun.SetNow();

            string tunneldbginfo = "";

            foreach (var outtunnel in outtunnels)
            {
                if (run.FailurePartners.Contains(outtunnel) ||
                    run.SuccessPartners.Contains(outtunnel) ||
                    run.TestedPartners.Contains(outtunnel))
                {
                    continue;
                }

                run.TestedPartners.Add(outtunnel);
                var probe = new ProbesSent()
                {
                    Tunnel    = intunnel,
                    Partner   = outtunnel,
                    MessageId = I2NPHeader.GenerateMessageId(),
                    TotalHops = outtunnel.Config.Info.Hops.Count + intunnel.Config.Info.Hops.Count
                };

                tunneldbginfo += $"({outtunnel.TunnelDebugTrace}:{probe.MessageId})";

                run.OutstandingProbes.Add(probe);
                OutstandingProbeIds[probe.MessageId] = probe;
                outtunnel.Send(new TunnelMessageTunnel((new DeliveryStatusMessage(probe.MessageId)).Header16, intunnel));
            }

            if (tunneldbginfo.Length > 0)
            {
                DebugUtils.LogDebug(
                    $"TunnelTester: Starting inbound tunnel {intunnel.TunnelDebugTrace} test with tunnels: {tunneldbginfo}");
            }
        }
Example #2
0
        void TestOneInboundTunnel()
        {
            if (InboundTunnels.IsEmpty)
            {
                return;
            }

            if (!InboundTunnels.TryDequeue(out var intunnel))
            {
                return;
            }
            if (!intunnel.Active || intunnel.Metrics.PassedTunnelTest)
            {
                return;
            }

            InboundTunnels.Enqueue(intunnel);

            var run = OutstandingTests.Get(intunnel);

            if (run != null)
            {
                // Run has finished?
                if (run.TestedPartners.Count >= RunsPerTest)
                {
                    if (run.LastRun.DeltaToNow < TimeBetweenTests)
                    {
                        return;
                    }
                    run.OutstandingProbes.Clear();
                    run.SuccessPartners.Clear();
                    run.TestedPartners.Clear();
                }
            }
            else
            {
                run = new TestRun2(intunnel);
                OutstandingTests[intunnel] = run;
            }

            var test = TestResults.Get(intunnel, () => new TunnelTestResult(intunnel));

            var outtunnels = TunnelProvider.Inst.GetOutboundTunnels()
                             .Where(t => t.Active)
                             .Shuffle()
                             .Take(RunsPerTest)
                             .ToArray();;

            if (!outtunnels.Any())
            {
                //Logging.LogDebug( "TunnelTester: Failed to get a established outbound tunnel." );
                return;
            }

            run.LastRun.SetNow();

            string tunneldbginfo = "";

            foreach (var outtunnel in outtunnels)
            {
                if (run.FailurePartners.Contains(outtunnel) ||
                    run.SuccessPartners.Contains(outtunnel) ||
                    run.TestedPartners.Contains(outtunnel))
                {
                    continue;
                }

                run.TestedPartners.Add(outtunnel);
                var probe = new ProbesSent()
                {
                    Tunnel    = intunnel,
                    Partner   = outtunnel,
                    MessageId = I2NPMessage.GenerateMessageId(),
                    TotalHops = outtunnel.Config.Info.Hops.Count + intunnel.Config.Info.Hops.Count
                };

                tunneldbginfo += $"({outtunnel.TunnelDebugTrace}:{probe.MessageId})";

                run.OutstandingProbes.Add(probe);
                OutstandingProbeIds[probe.MessageId] = probe;
                outtunnel.Send(new TunnelMessageTunnel(new DeliveryStatusMessage(probe.MessageId), intunnel));
            }

            if (tunneldbginfo.Length > 0)
            {
                Logging.LogDebug(
                    $"TunnelTester: Starting inbound tunnel {intunnel.TunnelDebugTrace} test with tunnels: {tunneldbginfo}");
            }
        }