Esempio n. 1
0
        /** Search address of the servent
         *  may be null
         **/
        private static NodeAddress getAddressFromQueryHit(G2PacketQH2 qh2)
        {
            G2Packet p = qh2.getFirstChildPacket(G2PacketType.NA);

            if (p == null)
            {
                return(null);
            }
            G2PacketNA na = p as G2PacketNA;

            return(na.node);
        }
Esempio n. 2
0
        public static G2PacketLNI SmartLNIPacket()
        {
            G2PacketLNI root = new G2PacketLNI();
            G2PacketGU  guid = new G2PacketGU(GUID.generateGuid());

            root.AddChild(guid);

            NodeAddress self = new NodeAddress(G2Network.Instance.SelfAddress, G2Network.Instance.SelfPort);
            G2PacketNA  na   = new G2PacketNA(self);

            root.AddChild(na);

            G2PacketV v = new G2PacketV("RAZA");

            root.AddChild(v);

            root.FinalizePacket();
            return(root);
        }
Esempio n. 3
0
        public void testLNI(G2Packet packTest)
        {
            G2PacketLNI rLNI = (G2PacketLNI)packTest;
            G2PacketGU  rGU  = (G2PacketGU)rLNI.getFirstChildPacket(G2PacketType.GU);
            G2PacketNA  rNA  = (G2PacketNA)rLNI.getFirstChildPacket(G2PacketType.NA);
            G2PacketV   rV   = (G2PacketV)rLNI.getFirstChildPacket(G2PacketType.V);

            G2Packet lni = new G2PacketLNI();

            lni.AddChild(new G2PacketNA(rNA.node));
            lni.AddChild(new G2PacketGU(rGU.nodeGuid));
            lni.AddChild(new G2PacketV(rV.Str));
            lni.FinalizePacket();
            G2Log.Write(lni.ToString());
            MemoryStream s1 = new MemoryStream((int)rLNI.getTotalPacketLength());
            MemoryStream s2 = new MemoryStream((int)lni.getTotalPacketLength());

            rLNI.Write(s1);
            lni.Write(s2);

            byte[] b1 = s1.ToArray();
            byte[] b2 = s2.ToArray();

            if (b1.Length != b2.Length)
            {
                G2Log.Write(" NOT EQUAL");
                return;
            }
            for (int i = 0; i < b1.Length; i++)
            {
                if (b1 [i] != b2 [i])
                {
                    G2Log.Write("NOT EQUAL");
                    return;
                }
            }
            G2Log.Write("EQUAL !!");
        }
Esempio n. 4
0
        public void testReader()
        {
            G2Network.Instance.SelfAddress = System.Net.IPAddress.Parse("127.0.0.1");
            G2Packet lni = Settings.SmartLNIPacket();
            G2Packet na  = new G2PacketNA(new NodeAddress(System.Net.IPAddress.Parse("127.0.0.1"), 6345));

            for (int i = 0; i < 300; i++)
            {
                lni.AddChild(na);
            }
            lni.FinalizePacket();
            G2Log.Write(lni.ToString());
            ByteBuffer     b      = lni.ToBuffer();
            G2PacketReader reader = new G2PacketReader(new NodePeer(System.Net.IPAddress.Parse("127.0.0.1"), 6346, 0, false));
            int            nb     = 3;

            byte[][] bytes = new byte[nb][];
            int      start = 0;
            int      div   = b.Length / nb;

            for (int i = 0; i < nb; i++)
            {
                if (i == nb - 1)
                {
                    div += b.Length % nb;
                }
                bytes [i] = new byte[div];
                Array.Copy(b.Bytes, start, bytes [i], 0, div);
                start += div;
            }


            for (int i = 0; i < nb; i++)
            {
                bool enough = reader.Read(bytes [i], bytes[i].Length);
                if (enough)
                {
                    G2Log.Write("PacketReader Test Success");
                    break;
                }
            }
            G2Packet   lni2 = Settings.SmartLNIPacket();
            ByteBuffer b2   = lni2.ToBuffer();
            bool       succ = reader.Read(b2.Bytes, b2.DataOffset);

            if (succ)
            {
                G2Log.Write("PacketReader Test Unit Packet Success");
            }
            else
            {
                G2Log.Write("PacketReader Test Unit Packet FAILED");
            }


            b.Append(b2);
            succ = reader.Read(b.Bytes, b.DataOffset);
            if (succ)
            {
                G2Log.Write("PacketReader Test Sequential Packet Success");
            }
            else
            {
                G2Log.Write("PacketReader TEst Sequential Packet FAILED");
            }
        }