Beispiel #1
0
        public void Test10()
        {
            DummyConnecter    c  = new DummyConnecter();
            DummyRawServer    rs = new DummyRawServer();
            IEncrypter        e  = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, DummySchedule, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40);
            DummySingleSocket c1 = new DummySingleSocket();

            e.MakeExternalConnection(c1);
            Assert.AreEqual(0, c.log.Count);
            Assert.AreEqual(0, rs.connects.Count);
            Assert.AreEqual(false, c1.Closed);

            byte[] bytes = new byte[68];
            Globals.CopyBytes(handshakeMessage, 0, bytes);
            int i;

            for (i = 48; i < 68; i++)
            {
                bytes[i] = 2;
            }

            e.DataCameIn(c1, bytes);
            Assert.AreEqual(1, c.log.Count);
            c.log.Clear();
            Assert.AreEqual(false, c1.Closed);

            e.DataCameIn(c1, new byte[] { 0, 0, 0, 0 });
            Assert.AreEqual(0, c.log.Count);
            Assert.AreEqual(false, c1.Closed);
        }
Beispiel #2
0
        public void Test7()
        {
            DummyConnecter c  = new DummyConnecter();
            DummyRawServer rs = new DummyRawServer();
            IEncrypter     e  = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, DummySchedule, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40);

            e.StartConnect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 6969), new byte[] { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 });
            Debug.Assert(c.log.Count == 0);
            Debug.Assert(rs.connects.Count == 1);
            DummySingleSocket c1 = (DummySingleSocket)((object[])rs.connects[0])[1];

            rs.connects.Clear();
            c1.Pop();
            Assert.AreEqual(false, c1.Closed);

            byte[] bytes = new byte[68];
            bytes[0] = 19;
            Buffer.BlockCopy(Encoding.Default.GetBytes(protocolName), 0, bytes, 1, 19);

            int i;

            for (i = 0; i < 8; i++)
            {
                bytes[20 + i] = 0;
            }
            for (i = 0; i < 20; i++)
            {
                bytes[28 + i] = 1;
                bytes[48 + i] = 2;
            }
            e.DataCameIn(c1, bytes);
            Assert.AreEqual(0, c.log.Count);
            Assert.AreEqual(true, c1.Closed);
        }
Beispiel #3
0
        public void Test16()
        {
            DummyConnecter    c  = new DummyConnecter();
            DummyRawServer    rs = new DummyRawServer();
            IEncrypter        e  = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, DummySchedule, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40);
            DummySingleSocket c1 = new DummySingleSocket();

            e.StartConnect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 6969), new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
            Assert.AreEqual(0, c.log.Count);
            Assert.AreEqual(0, rs.connects.Count);
            Assert.AreEqual(false, c1.Closed);
        }
Beispiel #4
0
        public void Test3()
        {
            DummyConnecter    c  = new DummyConnecter();
            DummyRawServer    rs = new DummyRawServer();
            Encrypter         e  = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, DummySchedule, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40);
            DummySingleSocket c1 = new DummySingleSocket();

            e.MakeExternalConnection(c1);

            e.FlushConnection(c1);

            c1.Pop();

            byte[] bytes = new byte[48];
            bytes[0] = 19;
            Buffer.BlockCopy(Encoding.Default.GetBytes(protocolName), 0, bytes, 1, 19);

            int i;

            for (i = 0; i < 8; i++)
            {
                bytes[20 + i] = 0;
            }
            for (i = 0; i < 20; i++)
            {
                bytes[28 + i] = 1;
            }

            e.DataCameIn(c1, bytes);
            c1.Pop();

            bytes = new byte[20];
            for (i = 0; i < 20; i++)
            {
                bytes[i] = (byte)'b';
            }

            e.DataCameIn(c1, bytes);
            c1.Pop();

            EncryptedConnection ch = (EncryptedConnection)((object[])c.log[0])[1];

            c.log.Clear();
            Assert.AreEqual(0, rs.connects.Count);
            Assert.AreEqual(false, c1.Closed);
            Assert.AreEqual(true, ch.IsFlushed);

            e.FlushConnection(c1);
            c1.Pop();

            c1.SetFlushed(false);
            Assert.AreEqual(false, ch.IsFlushed);
        }
Beispiel #5
0
        public void Test9()
        {
            log = new ArrayList();

            DummyConnecter c  = new DummyConnecter();
            DummyRawServer rs = new DummyRawServer();
            IEncrypter     e  = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, ScheduleLog, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40);

            Assert.AreEqual(1, log.Count);
            Assert.AreEqual(30, (double)((object[])log[0])[1]);
            TaskDelegate kfunc = (TaskDelegate)((object[])log[0])[0];

            log.Clear();
            DummySingleSocket c1 = new DummySingleSocket();

            e.MakeExternalConnection(c1);
            c1.Pop();
            Assert.AreEqual(0, c.log.Count);
            Assert.AreEqual(false, c1.Closed);
            kfunc();
            Assert.AreEqual(new byte[0], c1.Pop());
            Assert.AreEqual(0, c.log.Count);
            Assert.AreEqual(false, c1.Closed);
            log.Clear();

            byte[] bytes = new byte[68];
            bytes[0] = 19;
            Buffer.BlockCopy(Encoding.Default.GetBytes(protocolName), 0, bytes, 1, 19);

            int i;

            for (i = 0; i < 8; i++)
            {
                bytes[20 + i] = 0;
            }
            for (i = 0; i < 20; i++)
            {
                bytes[28 + i] = 1;
                bytes[48 + i] = 2;
            }
            e.DataCameIn(c1, bytes);
            Assert.AreEqual(1, c.log.Count);
            c.log.Clear();
            c1.Pop();
            Assert.AreEqual(new byte[0], c1.Pop());
            Assert.AreEqual(false, c1.Closed);

            kfunc();
            Assert.AreEqual(0, c.log.Count);
            Assert.AreEqual(false, c1.Closed);
        }
Beispiel #6
0
        public void Test2()
        {
            DummyConnecter    c  = new DummyConnecter();
            DummyRawServer    rs = new DummyRawServer();
            IEncrypter        e  = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, DummySchedule, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40);
            DummySingleSocket c1 = new DummySingleSocket();

            e.MakeExternalConnection(c1);
            c1.Pop();

            byte[] bytes = new byte[48];
            bytes[0] = 19;
            Buffer.BlockCopy(Encoding.Default.GetBytes(protocolName), 0, bytes, 1, 19);

            int i;

            for (i = 0; i < 8; i++)
            {
                bytes[20 + i] = 0;
            }
            for (i = 0; i < 20; i++)
            {
                bytes[28 + i] = 1;
            }

            e.DataCameIn(c1, bytes);


            bytes = new byte[20];
            for (i = 0; i < 20; i++)
            {
                bytes[i] = (byte)'b';
            }
            e.DataCameIn(c1, bytes);
            c1.Pop();

            IEncryptedConnection ch = (EncryptedConnection)((object[])c.log[0])[1];

            c.log.Clear();
            Encoding.Default.GetBytes(ch.IP);

            ch.SendMessage(new byte[] { (byte)'a', (byte)'b', (byte)'c' });
            c1.Pop();

            bytes = new byte[] { 0, 0, 0, 3, (byte)'d', (byte)'e', (byte)'f' };
            e.DataCameIn(c1, bytes);
            c1.Pop();
        }
Beispiel #7
0
        public void Test14()
        {
            DummyConnecter    c  = new DummyConnecter();
            DummyRawServer    rs = new DummyRawServer();
            IEncrypter        e  = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, DummySchedule, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40);
            DummySingleSocket c1 = new DummySingleSocket();

            e.MakeExternalConnection(c1);
            Assert.AreEqual(0, c.log.Count);
            Assert.AreEqual(0, rs.connects.Count);
            Assert.AreEqual(false, c1.Closed);

            byte[] bytes = new byte[24];
            bytes[0] = 19;
            Buffer.BlockCopy(Encoding.Default.GetBytes(protocolName), 0, bytes, 1, 19);

            int i;

            for (i = 0; i < 4; i++)
            {
                bytes[20 + i] = 0;
            }
            e.DataCameIn(c1, bytes);
            bytes = new byte[34];
            for (i = 0; i < 4; i++)
            {
                bytes[i] = 0;
            }
            for (i = 0; i < 20; i++)
            {
                bytes[4 + i] = 1;
            }
            for (i = 0; i < 10; i++)
            {
                bytes[24 + i] = 2;
            }
            e.DataCameIn(c1, bytes);
            bytes = new byte[10];
            for (i = 0; i < 10; i++)
            {
                bytes[i] = 2;
            }
            e.DataCameIn(c1, bytes);
            Assert.AreEqual(1, c.log.Count);

            c.log.Clear();
            Assert.AreEqual(false, c1.Closed);
        }
Beispiel #8
0
        public void Test4()
        {
            DummyConnecter    c  = new DummyConnecter();
            DummyRawServer    rs = new DummyRawServer();
            IEncrypter        e  = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, DummySchedule, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40);
            DummySingleSocket c1 = new DummySingleSocket();

            e.MakeExternalConnection(c1);
            c1.Pop();
            byte[] bytes = new byte[68];
            Globals.CopyBytes(handshakeMessage, 0, bytes);
            bytes[0] = 5;
            e.DataCameIn(c1, bytes);
            Assert.AreEqual(0, c.log.Count);
            Assert.AreEqual(true, c1.Closed);
        }
Beispiel #9
0
        public void Test1()
        {
            DummyConnecter    c  = new DummyConnecter();
            DummyRawServer    rs = new DummyRawServer();
            IEncrypter        e  = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, DummySchedule, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40);
            DummySingleSocket c1 = new DummySingleSocket();

            e.MakeExternalConnection(c1);
            byte[] temp = c1.Pop();

            int i;

            for (i = 0; i < 68; i++)
            {
                Assert.AreEqual(handshakeMessage[i], temp[i]);
            }
        }
Beispiel #10
0
        public void Test12()
        {
            DummyConnecter    c  = new DummyConnecter();
            DummyRawServer    rs = new DummyRawServer();
            IEncrypter        e  = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, DummySchedule, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40);
            DummySingleSocket c1 = new DummySingleSocket();

            e.MakeExternalConnection(c1);
            Assert.AreEqual(0, c.log.Count);
            Assert.AreEqual(0, rs.connects.Count);
            Assert.AreEqual(false, c1.Closed);

            byte[] bytes = new byte[68];
            bytes[0] = 19;
            Buffer.BlockCopy(Encoding.Default.GetBytes(protocolName), 0, bytes, 1, 19);

            int i;

            for (i = 0; i < 8; i++)
            {
                bytes[20 + i] = 0;
            }
            for (i = 0; i < 20; i++)
            {
                bytes[28 + i] = 1;
                bytes[48 + i] = 2;
            }
            e.DataCameIn(c1, bytes);
            Assert.AreEqual(1, c.log.Count);

            c.log.Clear();
            Assert.AreEqual(false, c1.Closed);

            c.CloseNext = true;
            e.DataCameIn(c1, new byte[] { 0, 0, 0, 4, 1, 2, 3, 4 });
            Console.WriteLine(c1.Closed);
            Assert.AreEqual(true, c1.Closed);
        }