Ejemplo n.º 1
0
        private void Receive_Patch(DhtAddress source, byte[] data)
        {
            // invoke patch
            G2Header root = new G2Header(data);

            if (G2Protocol.ReadPacket(root))
            {
                if (root.Name == StorePacket.Patch)
                {
                    PatchPacket packet = PatchPacket.Decode(root);

                    if (packet == null)
                    {
                        return;
                    }

                    foreach (PatchTag patch in packet.PatchData)
                    {
                        if (PatchEvent.Contains(patch.Service, patch.DataType))
                        {
                            PatchEvent[patch.Service, patch.DataType].Invoke(source, patch.Tag);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static PatchPacket Decode(G2Header root)
        {
            PatchPacket patch = new PatchPacket();
            G2Header    child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (child.Name == Packet_Patch && G2Protocol.ReadPayload(child))
                {
                    patch.PatchData.Add((PatchTag)PatchTag.FromBytes(child.Data, child.PayloadPos, child.PayloadSize));
                }
            }

            return(patch);
        }
Ejemplo n.º 3
0
        public static PatchPacket Decode(G2Header root)
        {
            PatchPacket patch = new PatchPacket();
            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
                if (child.Name == Packet_Patch && G2Protocol.ReadPayload(child))
                    patch.PatchData.Add((PatchTag) PatchTag.FromBytes(child.Data, child.PayloadPos, child.PayloadSize));

            return patch;
        }
Ejemplo n.º 4
0
        public void Replicate(DhtContact contact)
        {
            // dont replicate to local region until we've established our position in the dht
            if (!Network.Established)
            {
                return;
            }


            // when new user comes into our cache area, we send them the data we have in our high/low/xor bounds

            // replicate is only for cached area
            // for remote user stuff that loads up with client, but now out of bounds, it is
            // republished by the uniqe modifier on data

            List <PatchTag> PatchList = new List <PatchTag>();

            // get data that needs to be replicated from components
            // structure as so
            //      contact
            //          service []
            //              datatype []
            //                  patch data []

            foreach (uint service in ReplicateEvent.HandlerMap.Keys)
            {
                foreach (uint datatype in ReplicateEvent.HandlerMap[service].Keys)
                {
                    List <byte[]> patches = ReplicateEvent.HandlerMap[service][datatype].Invoke(contact);

                    if (patches != null)
                    {
                        foreach (byte[] data in patches)
                        {
                            PatchTag patch = new PatchTag();
                            patch.Service  = service;
                            patch.DataType = datatype;
                            patch.Tag      = data;

                            PatchList.Add(patch);
                        }
                    }
                }
            }

            PatchPacket packet = new PatchPacket();

            int totalSize = 0;

            foreach (PatchTag patch in PatchList)
            {
                if (patch.Tag.Length + totalSize > 1000)
                {
                    if (packet.PatchData.Count > 0)
                    {
                        Send_StoreReq(contact, contact, new DataReq(null, contact.UserID, 0, 0, packet.Encode(Network.Protocol)));
                    }

                    packet.PatchData.Clear();
                    totalSize = 0;
                }

                packet.PatchData.Add(patch);
                totalSize += patch.Tag.Length;
            }

            if (packet.PatchData.Count > 0)
            {
                Send_StoreReq(contact, contact, new DataReq(null, contact.UserID, 0, 0, packet.Encode(Network.Protocol)));
            }
        }
Ejemplo n.º 5
0
        public void Replicate(DhtContact contact)
        {
            // dont replicate to local region until we've established our position in the dht
            if (!Network.Established)
                return;

            // when new user comes into our cache area, we send them the data we have in our high/low/xor bounds

            // replicate is only for cached area
            // for remote user stuff that loads up with client, but now out of bounds, it is
            // republished by the uniqe modifier on data

            List<PatchTag> PatchList = new List<PatchTag>();

            // get data that needs to be replicated from components
            // structure as so
            //      contact
            //          service []
            //              datatype []
            //                  patch data []

            foreach (uint service in ReplicateEvent.HandlerMap.Keys)
                foreach (uint datatype in ReplicateEvent.HandlerMap[service].Keys)
                {
                    List<byte[]> patches = ReplicateEvent.HandlerMap[service][datatype].Invoke(contact);

                    if(patches != null)
                        foreach (byte[] data in patches)
                        {
                            PatchTag patch = new PatchTag();
                            patch.Service = service;
                            patch.DataType = datatype;
                            patch.Tag = data;

                            PatchList.Add(patch);
                        }
                }

            PatchPacket packet = new PatchPacket();

            int totalSize = 0;

            foreach (PatchTag patch in PatchList)
            {
                if (patch.Tag.Length + totalSize > 1000)
                {
                    if (packet.PatchData.Count > 0)
                        Send_StoreReq(contact, contact, new DataReq(null, contact.UserID, 0, 0, packet.Encode(Network.Protocol)));

                    packet.PatchData.Clear();
                    totalSize = 0;
                }

                packet.PatchData.Add(patch);
                totalSize += patch.Tag.Length;
            }

            if (packet.PatchData.Count > 0)
                Send_StoreReq(contact, contact, new DataReq(null, contact.UserID, 0, 0, packet.Encode(Network.Protocol)));
        }