Пример #1
0
        public DeliveryStatusMessage()
        {
            AllocateBuffer(12);
            var writer = new BufRefLen(Payload);

            Timestamp       = new I2PDate(DateTime.UtcNow);
            StatusMessageId = I2NPMessage.GenerateMessageId();
        }
Пример #2
0
        public void TestGarlicCreate()
        {
            var ls = new I2PDate(DateTime.Now + TimeSpan.FromMinutes(5));

            var origmessage = new DeliveryStatusMessage(I2NPMessage.GenerateMessageId());
            var bigmessage  = new DataMessage(new BufLen(BufUtils.RandomBytes(14 * 1024)));

            var garlic = new Garlic(
                new GarlicClove(
                    new GarlicCloveDeliveryLocal(origmessage),
                    ls),
                new GarlicClove(
                    new GarlicCloveDeliveryLocal(bigmessage),
                    ls)
                );

            var egmsg = Garlic.EGEncryptGarlic(
                garlic,
                Public,
                new I2PSessionKey(),
                null);

            var origegdata  = I2NPMessage.Clone(egmsg);
            var origegdata2 = I2NPMessage.Clone(egmsg);

            // Decrypt

            var(aesblock, sessionkey1) = Garlic.EGDecryptGarlic(origegdata, Private);

            var newgarlic = new Garlic((BufRefLen)aesblock.Payload);

            var g1 = new BufLen(garlic.ToByteArray());
            var g2 = new BufLen(newgarlic.ToByteArray());

            Assert.IsTrue(g1 == g2);

            // Retrieve

            var(aesblock2, sessionkey2) = Garlic.RetrieveAESBlock(origegdata2, Private, null);

            newgarlic = new Garlic((BufRefLen)aesblock2.Payload);

            g1 = new BufLen(garlic.ToByteArray());
            g2 = new BufLen(newgarlic.ToByteArray());

            Assert.IsTrue(g1 == g2);
            Assert.IsTrue(sessionkey1 == sessionkey2);
        }
Пример #3
0
        void TestOneOutboundTunnel()
        {
            if (OutboundTunnels.IsEmpty)
            {
                return;
            }

            if (!OutboundTunnels.TryDequeue(out var outtunnel))
            {
                return;
            }
            if (!outtunnel.Active || outtunnel.Metrics.PassedTunnelTest)
            {
                return;
            }
            OutboundTunnels.Enqueue(outtunnel);

            var run = OutstandingTests.Get(outtunnel);

            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(outtunnel);
                OutstandingTests[outtunnel] = run;
            }

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

            var intunnels = TunnelProvider.Inst.GetInboundTunnels()
                            .Where(t => t.Active)
                            .Shuffle()
                            .Take(RunsPerTest * 2)
                            .ToArray();

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

            run.LastRun.SetNow();

            string tunneldbginfo = "";

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

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

                tunneldbginfo += $"({intunnel.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 outbound tunnel {outtunnel.TunnelDebugTrace} test with tunnels: {tunneldbginfo}");
            }
        }