Example #1
0
        public static ServiceData Decode(byte[] data)
        {
            G2Header root = new G2Header(data);

            G2Protocol.ReadPacket(root);

            if (root.Name != LocationPacket.Data)
            {
                return(null);
            }

            ServiceData packet = new ServiceData();
            G2Header    child  = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Date:
                    packet.Date = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                    break;

                case Packet_Tag:
                    packet.Tags.Add(PatchTag.FromBytes(child.Data, child.PayloadPos, child.PayloadSize));
                    break;
                }
            }

            return(packet);
        }
Example #2
0
        public void UpdateLocal()
        {
            ServiceData data = new ServiceData();

            data.Date = Core.TimeNow.ToUniversalTime();

            foreach (uint service in GetTag.HandlerMap.Keys)
            {
                foreach (uint datatype in GetTag.HandlerMap[service].Keys)
                {
                    PatchTag tag = new PatchTag();

                    tag.Service  = service;
                    tag.DataType = datatype;
                    tag.Tag      = GetTag[service, datatype].Invoke();

                    if (tag.Tag != null)
                    {
                        Debug.Assert(tag.Tag.Length < 8);

                        if (tag.Tag.Length < 8)
                        {
                            data.Tags.Add(tag);
                        }
                    }
                }
            }

            Cache.UpdateLocal("", null, data.Encode(Network.Protocol));
        }
Example #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);
        }
Example #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)));
            }
        }
Example #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)));
        }
Example #6
0
        public void UpdateLocal()
        {
            ServiceData data = new ServiceData();
            data.Date = Core.TimeNow.ToUniversalTime();

            foreach (uint service in GetTag.HandlerMap.Keys)
                foreach (uint datatype in GetTag.HandlerMap[service].Keys)
                {
                    PatchTag tag = new PatchTag();

                    tag.Service = service;
                    tag.DataType = datatype;
                    tag.Tag = GetTag[service, datatype].Invoke();

                    if (tag.Tag != null)
                    {
                        Debug.Assert(tag.Tag.Length < 8);

                        if (tag.Tag.Length < 8)
                            data.Tags.Add(tag);
                    }
                }

            Cache.UpdateLocal("", null, data.Encode(Network.Protocol));
        }