Пример #1
0
        public void Socks5_Test_01_FindProxy()
        {
            ManualResetEvent Done  = new ManualResetEvent(false);
            Socks5Proxy      Proxy = new Socks5Proxy(this.client1);

            Proxy.StartSearch((sender, e) =>
            {
                Done.Set();
            });

            Assert.IsTrue(Done.WaitOne(30000), "Search not complete.");
            Assert.IsTrue(Proxy.HasProxy, "No SOCKS5 proxy found.");

            Console.Out.WriteLine("JID: " + Proxy.JID);
            Console.Out.WriteLine("Port: " + Proxy.Port.ToString());
            Console.Out.WriteLine("Host: " + Proxy.Host);
        }
Пример #2
0
        public void Socks5_Test_05_InitiateSession()
        {
            this.ConnectClients();

            Console.Out.WriteLine();
            Console.Out.WriteLine("Searching for SOCKS5 proxy.");
            Console.Out.WriteLine();

            ManualResetEvent Done1  = new ManualResetEvent(false);
            Socks5Proxy      Proxy1 = new Socks5Proxy(this.client1);

            Proxy1.StartSearch((sender, e) =>
            {
                Done1.Set();
            });

            ManualResetEvent Done2  = new ManualResetEvent(false);
            Socks5Proxy      Proxy2 = new Socks5Proxy(this.client2);

            Proxy2.StartSearch((sender, e) =>
            {
                Done2.Set();
            });

            Assert.IsTrue(Done1.WaitOne(30000), "Search not complete.");
            Assert.IsTrue(Proxy1.HasProxy, "No SOCKS5 proxy found.");

            Assert.IsTrue(Done2.WaitOne(30000), "Search not complete.");
            Assert.IsTrue(Proxy2.HasProxy, "No SOCKS5 proxy found.");

            Done1.Reset();
            Done2.Reset();

            ManualResetEvent Error1  = new ManualResetEvent(false);
            ManualResetEvent Error2  = new ManualResetEvent(false);
            ManualResetEvent Closed1 = new ManualResetEvent(false);
            ManualResetEvent Closed2 = new ManualResetEvent(false);

            Console.Out.WriteLine();
            Console.Out.WriteLine("Start of session initiation.");
            Console.Out.WriteLine();

            Proxy2.OnOpen += (sender, e) =>
            {
                e.AcceptStream((sender2, e2) =>
                {
                    if (Encoding.ASCII.GetString(e2.Data) == "Hello1")
                    {
                        Done2.Set();
                        e2.Stream.Send(Encoding.ASCII.GetBytes("Hello2"));
                        e2.Stream.CloseWhenDone();
                    }
                    else
                    {
                        Error2.Set();
                    }
                }, (sender2, e2) =>
                {
                    Closed2.Set();
                }, null);
            };

            Proxy1.InitiateSession(this.client2.FullJID, (sender, e) =>
            {
                if (e.Ok)
                {
                    e.Stream.OnDataReceived += (sender2, e2) =>
                    {
                        if (Encoding.ASCII.GetString(e2.Data) == "Hello2")
                        {
                            Done1.Set();
                        }
                        else
                        {
                            Error1.Set();
                        }
                    };

                    e.Stream.OnStateChange += (sender2, e2) =>
                    {
                        if (e.Stream.State == Socks5State.Offline)
                        {
                            Closed1.Set();
                        }
                    };

                    e.Stream.Send(Encoding.ASCII.GetBytes("Hello1"));
                }
            }, null);

            Assert.AreEqual(0, WaitHandle.WaitAny(new WaitHandle[] { Done1, Error1 }, 10000), "Did not receive message 1.");
            Assert.AreEqual(0, WaitHandle.WaitAny(new WaitHandle[] { Done2, Error2 }, 10000), "Did not receive message 2.");
            Assert.IsTrue(Closed1.WaitOne(10000), "Client 1 did not close properly.");
            Assert.IsTrue(Closed2.WaitOne(10000), "Client 2 did not close properly.");
        }