Ejemplo n.º 1
0
        public static Ping Decode(G2ReceivedPacket packet)
        {
            Ping pi = new Ping();

            if (G2Protocol.ReadPayload(packet.Root))
            {
                pi.Ident = BitConverter.ToUInt16(packet.Root.Data, packet.Root.PayloadPos);
            }

            G2Protocol.ResetPacket(packet.Root);

            G2Header child = new G2Header(packet.Root.Data);

            while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                switch (child.Name)
                {
                case Packet_Source:
                    pi.Source = DhtSource.ReadPacket(child);
                    break;

                case Packet_RemoteIP:
                    pi.RemoteIP = new IPAddress(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize));
                    break;
                }
            }

            return(pi);
        }
Ejemplo n.º 2
0
        public static ProxyAck Decode(G2ReceivedPacket packet)
        {
            ProxyAck pa = new ProxyAck();

            G2Header child = new G2Header(packet.Root.Data);

            while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD)
            {
                switch (child.Name)
                {
                case Packet_Source:
                    if (G2Protocol.ReadPayload(child))
                    {
                        pa.Source = DhtSource.ReadPacket(child);
                    }
                    break;

                case Packet_Accept:
                    pa.Accept = true;
                    break;

                case Packet_Contacts:
                    if (G2Protocol.ReadPayload(child))
                    {
                        pa.ContactList.Add(DhtContact.ReadPacket(child));
                    }
                    break;
                }
            }

            return(pa);
        }
Ejemplo n.º 3
0
        public static SearchReq Decode(G2ReceivedPacket packet)
        {
            SearchReq req = new SearchReq();

            G2Header child = new G2Header(packet.Root.Data);

            while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                switch (child.Name)
                {
                case Packet_Source:
                    req.Source = DhtSource.ReadPacket(child);
                    break;

                case Packet_SearchID:
                    req.SearchID = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_Target:
                    req.TargetID = BitConverter.ToUInt64(child.Data, child.PayloadPos);
                    break;

                case Packet_Service:
                    req.Service = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_DataType:
                    req.DataType = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Parameters:
                    req.Parameters = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Nodes:
                    req.Nodes = BitConverter.ToBoolean(child.Data, child.PayloadPos);
                    break;

                case Packet_EndSearch:
                    req.EndProxySearch = true;
                    break;
                }
            }

            return(req);
        }
Ejemplo n.º 4
0
        public static SearchAck Decode(G2ReceivedPacket packet)
        {
            SearchAck ack = new SearchAck();

            G2Header child = new G2Header(packet.Root.Data);

            while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (child.Name == Packet_Proxied)
                {
                    ack.Proxied = true;
                    continue;
                }

                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                switch (child.Name)
                {
                case Packet_Source:
                    ack.Source = DhtSource.ReadPacket(child);
                    break;

                case Packet_SearchID:
                    ack.SearchID = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_Contacts:
                    ack.ContactList.Add(DhtContact.ReadPacket(child));
                    break;

                case Packet_Service:
                    ack.Service = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Values:
                    ack.ValueList.Add(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize));
                    break;
                }
            }

            return(ack);
        }
Ejemplo n.º 5
0
        public static StoreReq Decode(G2ReceivedPacket packet)
        {
            StoreReq req = new StoreReq();

            G2Header child = new G2Header(packet.Root.Data);

            while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                switch (child.Name)
                {
                case Packet_Source:
                    req.Source = DhtSource.ReadPacket(child);
                    break;

                case Packet_Key:
                    req.Key = BitConverter.ToUInt64(child.Data, child.PayloadPos);
                    break;

                case Packet_Service:
                    req.Service = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_DataType:
                    req.DataType = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Data:
                    req.Data = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_TTL:
                    req.TTL = BitConverter.ToUInt16(child.Data, child.PayloadPos);
                    break;
                }
            }

            return(req);
        }
Ejemplo n.º 6
0
        public static CrawlAck Decode(G2ReceivedPacket packet)
        {
            CrawlAck ack = new CrawlAck();

            G2Header child = new G2Header(packet.Root.Data);

            while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                switch (child.Name)
                {
                case Packet_Source:
                    ack.Source = DhtSource.ReadPacket(child);
                    break;

                case Packet_Version:
                    ack.Version = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Uptime:
                    ack.Uptime = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_ProxyServers:
                    ack.ProxyServers.Add(DhtContact.ReadPacket(child));
                    break;

                case Packet_ProxyClients:
                    ack.ProxyClients.Add(DhtContact.ReadPacket(child));
                    break;
                }
            }

            return(ack);
        }
Ejemplo n.º 7
0
        public static Pong Decode(G2ReceivedPacket packet)
        {
            Pong po = new Pong();

            G2Header child = new G2Header(packet.Root.Data);

            while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                {
                    if (child.Name == Packet_Direct)
                    {
                        po.Direct = true;
                    }

                    continue;
                }

                switch (child.Name)
                {
                case Packet_Source:
                    po.Source = DhtSource.ReadPacket(child);
                    break;

                case Packet_RemoteIP:
                    po.RemoteIP = new IPAddress(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize));
                    break;

                case Packet_Version:
                    po.Version = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(po);
        }