Exemple #1
0
 internal IntroducerInfo(string host, string port, string ikey, string tag)
 {
     Host     = IPAddress.Parse(host);
     Port     = int.Parse(port);
     IntroKey = new BufLen(FreenetBase64.Decode(ikey));
     IntroTag = uint.Parse(tag);
 }
Exemple #2
0
        // We are client
        public SSUSession(SSUHost owner, IPEndPoint remoteep, I2PRouterAddress remoteaddr, I2PKeysAndCert rri, IMTUProvider mtup, RouterContext rc)
        {
            Host              = owner;
            RemoteEP          = remoteep;
            RemoteAddr        = remoteaddr;
            RemoteRouter      = rri;
            MTUProvider       = mtup;
            MyRouterContext   = rc;
            TransportInstance = Interlocked.Increment(ref NTCPClient.TransportInstanceCounter);

#if LOG_ALL_TRANSPORT
            DebugUtils.LogDebug("SSUSession: " + DebugId + " Client instance created.");
#endif

            Fragmenter = new DataFragmenter();

            if (RemoteAddr == null)
            {
                throw new NullReferenceException("SSUSession needs an address");
            }

            IntroKey = new BufLen(FreenetBase64.Decode(RemoteAddr.Options["key"]));

            MTU = MTUProvider.GetMTU(remoteep);
        }
Exemple #3
0
        public I2PDestinationInfo(string base64)
        {
            var reader = new BufRefLen(FreenetBase64.Decode(base64));

            Certificate       = new I2PCertificate(reader);
            PrivateKey        = new I2PPrivateKey(reader, Certificate);
            PublicKey         = new I2PPublicKey(reader, Certificate);
            PrivateSigningKey = new I2PSigningPrivateKey(reader, Certificate);
            PublicSigningKey  = new I2PSigningPublicKey(reader, Certificate);
        }
Exemple #4
0
        public void TestGarlicCreateMessage()
        {
            var dsm1 = new DeliveryStatusMessage(0x425c)
            {
                MessageId = 2354
            };

            var dsm2 = new DeliveryStatusMessage(0x425c)
            {
                MessageId = 2354
            };

            dsm2.Timestamp  = dsm1.Timestamp;
            dsm2.Expiration = dsm1.Expiration;

            var dsm1h = dsm1.CreateHeader16;
            var dsm2h = dsm2.CreateHeader16;

            var dsm1hap = dsm1h.HeaderAndPayload;
            var dsm2hap = dsm2h.HeaderAndPayload;

            var st11 = FreenetBase64.Encode(dsm1hap);
            var st12 = FreenetBase64.Encode(dsm2hap);

            Assert.IsTrue(dsm1hap == dsm2hap);

            var gcd1 = new GarlicCloveDeliveryDestination(
                dsm1,
                Destination.IdentHash);

            var gcd2 = new GarlicCloveDeliveryDestination(
                dsm2,
                Destination.IdentHash);

            var gcd1ar = gcd1.ToByteArray();
            var gcd2ar = gcd2.ToByteArray();

            var st1 = FreenetBase64.Encode(new BufLen(gcd1ar));
            var st2 = FreenetBase64.Encode(new BufLen(gcd2ar));

            Assert.IsTrue(BufUtils.Equal(gcd1ar, gcd2ar));

            var msg1 = new GarlicClove(gcd1);
            var msg2 = new GarlicClove(gcd2);

            var g1 = new Garlic(msg1, msg2);
            var g2 = new Garlic(new BufRefLen(g1.ToByteArray()).Clone());

            Assert.IsTrue(BufUtils.Equal(g1.ToByteArray(), g2.ToByteArray()));
        }
Exemple #5
0
        internal void SetIntroducers(IEnumerable <IntroducerInfo> introducers)
        {
            var result = new List <KeyValuePair <string, string> >();
            var ix     = 0;

            foreach (var one in introducers)
            {
                result.Add(new KeyValuePair <string, string>($"ihost{ix}", one.Host.ToString()));
                result.Add(new KeyValuePair <string, string>($"iport{ix}", one.Port.ToString()));
                result.Add(new KeyValuePair <string, string>($"ikey{ix}", FreenetBase64.Encode(one.IntroKey)));
                result.Add(new KeyValuePair <string, string>($"itag{ix}", one.IntroTag.ToString()));
                ++ix;
            }

            SSUIntroducersInfo = result;
            MyRouterInfoCache  = null;
        }
Exemple #6
0
        public override string ToString()
        {
            string addr;

            if (IPAddressOk)
            {
                addr = (new IPAddress(AliceIPAddr.ToByteArray())).ToString();
            }
            else if (AliceIPAddr.Length == 0)
            {
                addr = "<empty>";
            }
            else
            {
                addr = AliceIPAddr.ToString();
            }
            return(string.Format("PeerTest: Test nonce: {0}, Alice IP#: {1}, Port: {2}, Intro key: {3}",
                                 TestNonce.PeekFlip32(0), addr, AlicePort.PeekFlip16(0),
                                 FreenetBase64.Encode(IntroKey)));
        }
Exemple #7
0
        public void TestEGCompatibilityDecode()
        {
            var priv = new I2PPrivateKey(
                new BufRefLen(FreenetBase64.Decode(PRIVATE_KEY)),
                new I2PCertificate());

            var pub = new I2PPublicKey(
                new BufRefLen(FreenetBase64.Decode(PUBLIC_KEY)),
                new I2PCertificate());

            for (int i = 0; i < ENCRYPTED.Length; ++i)
            {
                var decr = ElGamalCrypto.Decrypt(
                    new BufLen(FreenetBase64.Decode(ENCRYPTED[i])),
                    priv,
                    true);

                var clear = new BufLen(Encoding.UTF8.GetBytes(UNENCRYPTED[i]));
                Assert.IsTrue(decr == clear);
            }
        }
Exemple #8
0
        private void UpdateRouterContext()
        {
            var addr = new I2PRouterAddress(RouterContext.Inst.ExtAddress, RouterContext.Inst.UDPPort, 5, "SSU");

            var ssucaps = "";

            if (PeerTestSupported)
            {
                ssucaps += "B";
            }
            if (IntroductionSupported)
            {
                ssucaps += "C";
            }

            addr.Options["caps"] = ssucaps;
            addr.Options["key"]  = FreenetBase64.Encode(RouterContext.Inst.IntroKey);
            foreach (var intro in IntroducersInfo)
            {
                addr.Options[intro.Key] = intro.Value;
            }

            RouterContext.Inst.UpdateAddress(this, addr);
        }
Exemple #9
0
        internal void SetIntroducers(IEnumerable <IntroducerInfo> introducers)
        {
            if (!introducers.Any())
            {
                NoIntroducers();
                return;
            }

            var result = new List <KeyValuePair <string, string> >();
            var ix     = 0;

            foreach (var one in introducers)
            {
                result.Add(new KeyValuePair <string, string>($"ihost{ix}", one.Host.ToString()));
                result.Add(new KeyValuePair <string, string>($"iport{ix}", one.Port.ToString()));
                result.Add(new KeyValuePair <string, string>($"ikey{ix}", FreenetBase64.Encode(one.IntroKey)));
                result.Add(new KeyValuePair <string, string>($"itag{ix}", one.IntroTag.ToString()));
                ++ix;
            }

            IntroducersInfo = result;

            UpdateRouterContext();
        }
Exemple #10
0
 public override string ToString()
 {
     return("I2PSignature: " + FreenetBase64.Encode(Sig));
 }
Exemple #11
0
        public void TestEGDecrypt()
        {
            var mi =
                "niPls-Doz1DJ3ua4pQDwstMeqnmznBCU~qaxIidv" +
                "jTW~ohDDpq3BatYwTSM-fIr-eEy4Amdl-tWJTXRO" +
                "2UzftkuD1-t-Ix9EfED26KrUxnwx2fC74Haykj9L" +
                "oytqFTFbYj34kMCUDDbhAqv6Ep3EDY8Am7WYqSJL" +
                "stXXV4tUFZ~mteCm1qfNUbbl6itCUId7zcgkW6SX" +
                "rwdkno3Ul4H~WVDtmewlxdDbT-rYyOJTnp4Y39Mo" +
                "8B1ojtMuGCgtbk-LS4gJmlXeCJh~1kHiM-nLIB9W" +
                "rtq8O4weJ~-R36obERZofGOV3D3kSKSoawXVcq4V" +
                "BlQOHTn24LkTHYLh3O~0SZlT0KfU5WrqTZtu8jZ~" +
                "B0q-cvrfqqWcmCFCoKW3WSJ5D0qZi1e9sLMebM96" +
                "asSRFZvlOUp8xZm84Z-au~m3EmkAaF4QlAzufA~L" +
                "~1RFaepKpfng0eWfWG73H1daoL3c2e3Pt~5m07FR" +
                "ZMr6TZoj1IsuI7J-QXRGfvbuMjJqB-tMBQAEAAcA" +
                "ADJtDgiK2OMz6qSmopA~cLUMW~zQesBqsoYx9AEc" +
                "sOIkp4g8YgRK2jJhfY46h7aj76ftkV-5uF6xoDUG" +
                "kbIQGH3rjneTQ2wspOz2WRpQk0MW6Ugd0H~5vYK2" +
                "ekploxq2gOil0Ad1rz~uobpE2bBKYK9B-EEkRKEP" +
                "-GTX6DSyosFXxMC1I5cwLDWmXktdNVuzt56AxfcL" +
                "Nzh9gd1R4l903-aFRiY~VXFHg1NjWBPcjCCz6fpL" +
                "U0XIdg6hf~DNMnd5D4C27HYujxUi6tj42sikDCPu" +
                "P6CBGAH~j7vzqkDxW2wker91lwwp~6N8jN4xcvme" +
                "-EI27LPGnOICvpzxdVrKtpc0Ib4dOe8SFkvxSR4x" +
                "PDSGWFF-~vAELzyHTYiE07ahNw==";

            var myinfo = FreenetBase64.Decode(mi);

            var ed =
                "AAAOggAE3uf0930YRPZqauUGNYgj5Ix7aoMz0ZO8" +
                "OIYpRS9zFi6CHe-SXOCeZMgOSxdkp320s70lnAJ9" +
                "2Z0fjP9WbBeKuCPjZSyMa-MQ4Bq5Sv~iXK-5T~ui" +
                "m9WTMnwzWIltbt2Toncx-9aAGsIgoABUpzQ1yjsG" +
                "-DwSEazn1ZsGAxGXI74SqokXGBggerXCtAhpTOTJ" +
                "MsFteib29WhURmPxLXPxtoCqav8hEUjEyBy2pnPE" +
                "h-3fcZPhxfK5FI0h0vZO0ZATZx~0RDV9NyxwaAMy" +
                "llav8iG2nFmVd7hkvWSVdcaRp2gpZuDcM9aXb2yo" +
                "xIagerhVF8Dyfbib3YX8GP9tvOhBAGWSRlvNIW6i" +
                "ImwOHJPuCbD4f2Ombp2VENYfKH~Tc4JP53DOnLs0" +
                "1pMze3xLaK0LsoPwR2LgYfamxbGDINa8KNB0PXC7" +
                "l7zcO6vDuC~mlVgs6VkkC-kirW8QMpO9t7v49l3y" +
                "tqlHBLU~khJwBFYuQEoB78bt~RQANw6R6V12yRIE" +
                "oW8dGJh5P1eGAFgO24oHyfLdKB-vfm1SZQB5MVyU" +
                "Ec6Hv4AKDBsxFqzFbThSgURqWk~AL9v-LuMhz034" +
                "jq-fGZtUY3l~ogz12IxdJIJVsjvJ2jWE-8NyFzC5" +
                "NhCSYV8jgdbL56ISMNPT9PRuiIyMHJ1w1NfypZ3c" +
                "aHKEnIjBzpj6R-9~~8PjLvdNO9cVaur5OLOGf4Q3" +
                "ABbqj9rg5uMJYIrFgddB4uETzb97Iue8BJr8XTRh" +
                "mwihpOLabG9r1b4-X1Z1HpBZxp8ml3xlZ-Lw6zp3" +
                "rQj2O84fSr0pxQh04Q-gIPBq7d4fS74uHMhN6rMx" +
                "bydEq0QQe4cqHDlGO-WZuTmK0tN-vMkwgHRXlz18" +
                "AdFFTf4caSoYerKPCk07neOWn0Vop1ni3DTRL~Tv" +
                "k04ZxNLnuuuor8gBh~jVFS-S9EnKkLcWJtJFcVbY" +
                "y9ZK-4caSvFGz1-Qf0elJKA-cpx7-ivKIQLQEuhx" +
                "5U6FrnJvchbY4JaZq2QzXVRF8s7X04kYOWWmAPXt" +
                "C3xE58e9s4-5MJhLNjdsjXoJ0R9jBleMWF-RsVwy" +
                "QNlTtabQDtDUzVeEQNRAHu9nVc0mJ18NH04KFMbH" +
                "jTWpgY1wDFB9566C9OOKzK-gkTjzO5RlSwDn5sgN" +
                "iejCOqM0-4JzMlFQNCuhMvmYAglRG8dLDZ3WjYck" +
                "NiRqHP2iKMyGQThwIS~TCzc-i5WgNzjLKPnWhhKm" +
                "1uvsZiWdnVAn9IOsFuOYvuR5NBnRJb~lYWI~zlvT" +
                "8riNkMIrnCE4CF380NEPfulMM6~98XVtmuMTY-Im" +
                "Zut2O1kz0OCBvCiYClrFlSlVDVoYEbVmkyoBKjiq" +
                "dGdPtLC5FnX6eC2bcUNGFOOY32ozF3UUsaRWVMrC" +
                "Y824xhPxcCt2yiJ~rSXAEBN2qtVW90wYzamz9pw6" +
                "XiNUdhshjLrOb-qVAnC33Kak89wbPtMGh6uXljR4" +
                "YxZ3gW2Tl9LIu4~5QP~sS7plo19-bdRfL8uAZ63j" +
                "gy-fY71std81WBfthqlOTFJMf~c-EU8xj90O408z" +
                "qYfFty-wgBBfYeeHdyWAWrqbfwLCMlHGGN0M-dbV" +
                "SjzwgSeLTYbdPrX1Dr6NHxSnJ9br0sXfoFUao1xa" +
                "4FN556lbolHjV0ns~6IbOVWElDNNecsLxjTWKgdA" +
                "CrLdh2ZMFL9M56H2Xdz4Adsm5vY1K6kCcLPgbpgb" +
                "~~gl-Qq4AEc~-nV6fxpu7pmH3HfTXIm0aDtR1KG7" +
                "kEHv-MreoFvmWvnVCj6tqJr5LAOKCDTvm7cw5fYc" +
                "27gsskqG~SM~1TyPkF5sb5~xX1EkAYm9PC0pA9WG" +
                "1~M4640pRCzbVl7jWqf1B~RPc7FRs3wMZqHu6SJW" +
                "kDRfvupQeNU6TXTkVPwJZcfTElH9ajcu23ucNXP-" +
                "Glp-00AZZA2fwOzdJe8AlzBIReLRyWKza5hLqmAy" +
                "paI1e5wSFDgXH027-tXLCYw-l2rsHl2aDO-M0Psj" +
                "OOA4GhdBUlLZWdy6OAI1~vpssgFY9CUErqR6m7LA" +
                "mLa9NaBFtTt~ZUYgc0TyrYfXjecl-jxUcPnYEo3u" +
                "YiBx3kk73LQWI-jj4IqKxUf1Rjp6b~Vhw77NFQPr" +
                "vqe91ICRuo9XTMavCQP8R1Lg2R7CwljE2qLJ0qxM" +
                "UN34gUfOIdQzBi~ApnG~aLoRwwro2U2MA63RMKkZ" +
                "OoXpjAmPj1xGqsQ73bI3lpfpHFLbWm3Ax37t2aud" +
                "c7-nPoaKoNvNIC0~28jROr35UGCKNMSNmqrifhHB" +
                "wsIqqMrubLjjmts-ELHWZF~1AZEDKMGrF3j-zGVg" +
                "LAhaSCvG3CNjaHTiAkPXc5zRwFLi5XTof1QipptG" +
                "u~j6-0Kpcwb5aWUD4q0JFxJPd0pt5p8N8r8Y04RR" +
                "TSzzyQsC8iGUDsmQyAnsquvMBpMBoCd3pOsSwYu3" +
                "d0A7UAoEI0S3Cp4JPndz2waXB4RhJzmHQu3JYv3A" +
                "IzYNfKvLwkZVdky-e7MqHtrSJU6HErb7JE7CgtW1" +
                "Gv-WYaCGZZR5qt3x-43CCYN9qnLpSIOXL17yK6P1" +
                "wsc2lXnAj6IYzppaH6~CtP3WnrsiEzh6lznkQbDx" +
                "pFygHfhvQQBJbhfjLL6-0RWG52oVsurXnT4og0oW" +
                "0itSdrP2tFjKc3aFkG4toWyDpfEOS427cPxRRNv6" +
                "6uEq-giDYHxVuk5k4TQ9bBp4HaWSKS55vr-oz5FF" +
                "SjT~p3-7WViVeoSO4wbcO7x2djkaQ7rWm6eiggut" +
                "NKw3WVNTG-oEQWuauwWp7mHwbDmTC7i-j4dvxMfz" +
                "k4gRWFOZpOEXIuiVBp20Ljy53fqZaSmijYqJwpRi" +
                "l~g6h-gvc43GMdoC48ryj0ClTN209Ua20YN54lg~" +
                "izHnl6X-VnmgPr298LKe0COK0xlDLKj~tu2CIzi3" +
                "mNwe4eLWfsmKRGrcXMwfz7F2SfOfNpqXbpgAV9AZ" +
                "Qy-SPuqFxNTcmclIzWKudDECoUqADHu3-tLijV0m" +
                "uer990OtbKeSrW9ICCVpjrbh5aPezOLNXcDkfxGB" +
                "S~yLpUgLn1aCFQv6Bz1htwfEpeKfqQvwVfD17SoW" +
                "-8XBA2ORSqXGOL9x93tzmt1pspsfgehXTqEVerH9" +
                "H9qCAECvRtyHu7jh-DNxFtnA-w5PTg7sf0uKKMOf" +
                "qtvIrpJulVuPl~JX89aigeihJXAQoc-QD5aMBVYC" +
                "n55mgrYUEKfe4~yYYYdkJCG0zwD5mADMA-elcNUI" +
                "ojXYff~X4eJwm1upbS5LpVyH4D-F57JMJKBFOUA4" +
                "Z6i1qTjQInIDYeinHKRThB9hz3EIB18TvroAz5Yl" +
                "UdE-BmdrXsXHztucbfw4GQ5LamIGHeYrapJ4QkRm" +
                "s~a5kdy78FrTV4drRuqoGWlpB9MORKyUVKZbQJND" +
                "6ncPyrRLaVTXy4m~L2MZoi4mPifkH6JdCUtyHK4f" +
                "Z0Ch1CSjHBr~kN3FoQRW4fJ9SazZ7sreYJLHOBhf" +
                "IdJTlu6ZX~nVwDzBZSg-kDj0phD7iWSAy9tI-qjq" +
                "nLkoZZj7oDt~L1Z-M~pXgsZkfIYN2nfoC3JV~HFl" +
                "W7DB3HEphkpU2cCzr2-BBFGGftNup6O1rohh1OSD" +
                "1T9OOACf-VvRk~z1motf5Y9oboEljWgrsqXSgDWM" +
                "Nsmk7WBv0e8H8SaNiKwoRiT4Y6EVjIe5Ft5pw7r7" +
                "7s3RhsGA6EcmRT8POELuJz5Q7qK7rYbDw1Ooil9v" +
                "ebQ7Zo9m~FpTAGAnuIgcPvmFfcgdI9Y46SV1JK4f" +
                "N91F5dm~7BXZcstbE3cinOV7VEiUEUUPiZaW6dXv" +
                "7dEwrELbD0gFStVy5IGuy1gqsygVxCvQwXFZ2j0N" +
                "EpYr0NTIwEOWKol17u3UTBSY6zhhajSPxl1f0QeF" +
                "yybEcw41IHy1fDZ3RfihzHIislrcDYHQ3mr~kdYC" +
                "oUlK83CKpQL2NJPKtLXsx0ATPjSYOg9Q25rf9v8c" +
                "joNrHERzhbDgqeCIXmSF5nLEpys~yRKLYpl7RLPS" +
                "fptt5gLOVNLmp~Z4CAKjLN-aqMYNopmy92-u74fb" +
                "u-d7UftyaZHNgT2QNP7TDrwYfivNKRS6detKwTYH" +
                "fxVpGRDT2HIHXZE3xCfZa6YmfPCrl0kAKAt1NB4i" +
                "VBb~TJ0p43CuaMnT~Mu7vXkwGVKJtZ3bGQfUtEhJ" +
                "xh61nVfh3k1F3EuczB~f1ekAZDMa9qhkp-Rv67~S" +
                "97ASXgyz673QLIoksK2udHB0iHPL6H2pJlBpv4oH" +
                "4YnA0o4ejTUy5vLgret0ItpMao4waezWK8TMHAzD" +
                "STd76eOIacKbIYkuorpx2atQrHizDQ9vPSIvurH7" +
                "8gMHJ03JnYoh60zIvZIqDajTS9vrqIvvu5HaB2re" +
                "bqmfMx2XKEvjqEBA7hPdqXR6n9typIcj1tqdHK-h" +
                "9iOYkQ81u64y6SgYMxuXNd38AFTUUouh1OQp2jVv" +
                "pnLLR-vUT1-G-lO8Xw5wrlwx6G4BA3peKmaMIxBu" +
                "iJA0qLUc336-oFXvThUh2JwT9RshrKclS7vp-zc9" +
                "8dzAXxATuxKakXZaJGQ91xWyTkz8lFzuGnfWK5HF" +
                "CgNiOa2F8nbR5kzofCXyYHyRbp9pT8Ek1xAK0Ayp" +
                "FYwqfcVFZnhe0TXcup5UDgdFlroirzfJaDIbQKBz" +
                "O4cS68Kd4YV9HPgu2de84dz~PfIgredg-A-rKon8" +
                "1ZhGylOgaXCDNNag9mjdF7B5nFjddYytaOgFCTDR" +
                "G0ntFV8mMDIwxW9GZtt6MSJQSJqjdOM1ywFdPrdX" +
                "GDKnib~NO247LxGLa05wUZPMvg92~mPgg9SkD9v4" +
                "-g008LITmMajbpE8~0t-jijMKJkPCQxOaBsH5-fn" +
                "uToqxg-xm0d9wg48Xr5BmirS5UbC7pS-U9pKI1E8" +
                "vp~DWbxxRpulZYhgNq2-cR2w7ie01mDleoUv-tdk" +
                "T9L1erdyTAhHrw2YNe0SD8OmyvW4aPPsjAGMeg==";

            var egdata = FreenetBase64.Decode(ed);

            var di = new I2PDestinationInfo(new BufRefLen(myinfo));

            var decr = ElGamalCrypto.Decrypt(new BufLen(egdata, 4, 514), di.PrivateKey, true);
        }
Exemple #12
0
        public override string ToString()
        {
            var hc = HashCache != null?FreenetBase64.Encode(new BufLen( HashCache )) : "<null>";

            return($"I2PRoutingKey: HashCacheDay {HashCacheDay}, HashCache: {hc}.");
        }
Exemple #13
0
        // This test does not work
        //[Test]
        public void TestSSU()
        {
            //Logging.LogToFile( "TestSSU.log" );

            RouterContext testcontext = new RouterContext(new I2PCertificate(I2PSigningKey.SigningKeyTypes.DSA_SHA1));

            testcontext.DefaultTCPPort = 2048 + BufUtils.RandomInt(5000);
            testcontext.DefaultUDPPort = 2048 + BufUtils.RandomInt(5000);

            var host = new SSUHost(testcontext, new FixedMTU());

            host.AllowConnectToSelf = true;

            host.ConnectionCreated += host_ConnectionCreated;

            // Remote
            var dnsa = Dns.GetHostEntry(Dns.GetHostName()).AddressList.Where(a => a.AddressFamily == AddressFamily.InterNetwork).FirstOrDefault();
            var addr = new I2PRouterAddress(dnsa, testcontext.UDPPort, 6, "SSU");

            addr.Options["key"] = FreenetBase64.Encode(testcontext.IntroKey);

            RouterContext remotetestcontext = new RouterContext(new I2PCertificate(I2PSigningKey.SigningKeyTypes.DSA_SHA1));

            remotetestcontext.DefaultTCPPort = testcontext.DefaultTCPPort + 5;
            remotetestcontext.DefaultUDPPort = testcontext.DefaultUDPPort + 5;

            var remotehost = new SSUHost(remotetestcontext, new FixedMTU());

            remotehost.AllowConnectToSelf = true;
            var client = remotehost.AddSession(addr, testcontext.MyRouterIdentity);

            client.Connect();

            var data = new BufLen(BufUtils.RandomBytes(30000));

            var messagecount = 900; // If the out queue is larger than 1000 msgs we start discarding them

            for (int i = 0; i < messagecount; ++i)
            {
                client.Send(new DataMessage(data));
            }

            System.Threading.Thread.Sleep(10000);

            for (int i = 0; i < messagecount; ++i)
            {
                if (i % 10 == 0)
                {
                    System.Threading.Thread.Sleep(100);
                }
                client.Send(new DataMessage(data));
            }

            var start = new TickCounter();

            while (DataReceived.Count < 2 * messagecount)
            {
                if (start.DeltaToNow.ToMinutes >= 1)
                {
                    Assert.Fail("Failed to receive sent data due to a timeout");
                    break;
                }

                System.Threading.Thread.Sleep(500);
            }

            for (int i = 0; i < 100; ++i)
            {
                Assert.IsTrue(((DataMessage)DataReceived.Random().Message).DataMessagePayload ==
                              new BufLen(data));
            }

            System.Threading.Thread.Sleep(500);

            client.Terminate();

            System.Threading.Thread.Sleep(500);

            host.Terminate();

            System.Threading.Thread.Sleep(500);
        }
Exemple #14
0
 public string ToBase64()
 {
     return(FreenetBase64.Encode(new BufLen(ToByteArray())));
 }
Exemple #15
0
 public I2PDestinationInfo(string base64)
     : this(new BufRefLen(FreenetBase64.Decode(base64)))
 {
 }
Exemple #16
0
        public override string ToString()
        {
            var hc = HashCache != null?FreenetBase64.Encode(new BufLen( HashCache )) : "<null>";

            return(string.Format("I2PRoutingKey: HashCacheDay {0}, HashCache: {1}.", HashCacheDay, hc));
        }
Exemple #17
0
        private void SendLSDatabaseLookup(I2PIdentHash ident, IdentUpdateRequestInfo info)
        {
            var outtunnel   = TunnelProvider.Inst.GetEstablishedOutboundTunnel(true);
            var replytunnel = TunnelProvider.Inst.GetInboundTunnel(true);

            if (outtunnel is null || replytunnel is null)
            {
                Logging.LogDebug($"SendLSDatabaseLookup: " +
                                 $"outtunnel: {outtunnel}, replytunnel: {replytunnel}");
                return;
            }

            var getnext = DateTime.UtcNow.Hour >= 23;
            var ff      = NetDb.Inst.GetClosestFloodfill(
                ident,
                DatabaseLookupSelectFloodfillCount + 2 * info.Retries,
                info.AlreadyQueried,
                getnext)
                          .Select(r => new { Id = r, NetDb.Inst.Statistics[r].Score });

#if LOG_ALL_IDENT_LOOKUPS
            StringBuilder foundrouters     = new StringBuilder();
            StringBuilder foundrouterskeys = new StringBuilder();

            foreach (var router in ff)
            {
                foundrouters.AppendFormat("{0}{1}{2}", (foundrouters.Length != 0 ? ", " : ""),
                                          router.Id32Short,
                                          FreenetBase64.Encode(router.Hash));
                foundrouterskeys.AppendFormat("{0}{1}{2}", (foundrouterskeys.Length != 0 ? ", " : ""),
                                              router.Id32Short,
                                              FreenetBase64.Encode(router.RoutingKey.Hash));
            }
            var st  = foundrouters.ToString();
            var st2 = foundrouterskeys.ToString();
#endif

            if (!ff.Any())
            {
                Logging.Log($"IdentResolver failed to find a floodfill router to lookup ({ident}): ");
                return;
            }

            var minscore = ff.Min(r => r.Score);

            for (int i = 0; i < DatabaseLookupSelectFloodfillCount; ++i)
            {
                var oneff = ff
                            .RandomWeighted(r => r.Score - minscore + 0.1)
                            .Id;
                try
                {
                    var msg = new DatabaseLookupMessage(
                        ident,
                        replytunnel.Destination, replytunnel.GatewayTunnelId,
                        DatabaseLookupMessage.LookupTypes.LeaseSet, null);

                    outtunnel.Send(new TunnelMessageRouter(msg, oneff));

                    info.AlreadyQueried.Add(oneff);

#if !LOG_ALL_IDENT_LOOKUPS
                    Logging.Log($"IdentResolver: LeaseSet query {msg.Key.Id32Short} " +
                                $"sent to {oneff.Id32Short}. Dist: {oneff ^ msg.Key.RoutingKey}");
#endif
                }
                catch (Exception ex)
                {
                    Logging.Log("SendLSDatabaseLookup", ex);
                }
            }
        }
Exemple #18
0
        private void SendLSDatabaseLookup(I2PIdentHash ident, IdentUpdateRequestInfo info)
        {
            /*
             * var replytunnel = TunnelProvider.Inst.GetInboundTunnel();
             * if ( replytunnel == null ) return;
             */

            var ff = NetDb.Inst.GetClosestFloodfill(ident, DatabaseLookupSelectFloodfillCount * 2, info.AlreadyQueried, false).ToArray();

#if LOG_ALL_IDENT_LOOKUPS
            StringBuilder foundrouters     = new StringBuilder();
            StringBuilder foundrouterskeys = new StringBuilder();

            foreach (var router in ff)
            {
                foundrouters.AppendFormat("{0}{1}{2}", (foundrouters.Length != 0 ? ", " : ""),
                                          router.Id32Short,
                                          FreenetBase64.Encode(router.Hash));
                foundrouterskeys.AppendFormat("{0}{1}{2}", (foundrouterskeys.Length != 0 ? ", " : ""),
                                              router.Id32Short,
                                              FreenetBase64.Encode(router.RoutingKey.Hash));
            }
            var st  = foundrouters.ToString();
            var st2 = foundrouterskeys.ToString();
#endif

            if (ff == null || ff.Length == 0)
            {
                DebugUtils.Log("IdentResolver failed to find a floodfill router to lookup (" + ident.ToString() + "): ");
                return;
            }

            ff.Shuffle();
            ff = ff.Take(DatabaseLookupSelectFloodfillCount).ToArray();

            foreach (var oneff in ff)
            {
                try
                {
                    var msg = new DatabaseLookupMessage(
                        ident,
                        RouterContext.Inst.MyRouterIdentity.IdentHash,
                        DatabaseLookupMessage.LookupTypes.LeaseSet);

                    /*
                     * var msg = new DatabaseLookupMessage(
                     *          ident,
                     *          replytunnel.Destination, replytunnel.GatewayTunnelId,
                     *          DatabaseLookupMessage.LookupTypes.LeaseSet, null );
                     */

                    //TunnelProvider.Inst.SendEncrypted( oneff.Identity, false, msg );
                    TransportProvider.Send(oneff, msg);
#if LOG_ALL_IDENT_LOOKUPS
                    DebugUtils.Log(string.Format("IdentResolver: LeaseSet query {0} sent to {1}. Dist: {2}",
                                                 msg.Key.Id32Short,
                                                 oneff.Id32Short,
                                                 oneff ^ msg.Key.RoutingKey));
#endif
                }
                catch (Exception ex)
                {
                    DebugUtils.Log("SendLSDatabaseLookup", ex);
                }
            }

            lock (info.AlreadyQueried)
            {
                info.AlreadyQueried.AddRange(ff);
            }
        }