Ejemplo n.º 1
0
        public static ProjectData Decode(G2Header root)
        {
            ProjectData project = new ProjectData();
            G2Header    child   = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_ID:
                    project.ID = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_Name:
                    project.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_UserName:
                    project.UserName = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(project);
        }
Ejemplo n.º 2
0
        public void Store_Local(DataReq store)
        {
            // getting published to - search results - patch

            SignedData signed = SignedData.Decode(store.Data);

            if (signed == null)
            {
                return;
            }

            G2Header embedded = new G2Header(signed.Data);

            // figure out data contained
            if (G2Protocol.ReadPacket(embedded))
            {
                if (embedded.Name == LocationPacket.Data)
                {
                    LocationData location = LocationData.Decode(signed.Data);

                    if (Utilities.CheckSignedData(location.Key, signed.Data, signed.Signature))
                    {
                        Process_LocationData(store, signed, location);
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void Session_Data(RudpSession session, byte[] data)
        {
            IMStatus status = OpenStatus(session.UserID);


            G2Header root = new G2Header(data);

            if (G2Protocol.ReadPacket(root))
            {
                if (root.Name == IMPacket.Message)
                {
                    MessageData message = MessageData.Decode(root);

                    if (message.TargetID != 0)
                    {
                        Debug.Assert(session.UserID == Core.UserID);
                        if (session.UserID != Core.UserID)
                        {
                            return;
                        }

                        status = OpenStatus(message.TargetID);
                    }

                    ProcessMessage(status, new InstantMessage(Core, session, message));
                }

                if (root.Name == IMPacket.Alive)
                {
                    status.SetTTL(session.ClientID, SessionTimeout * 2);
                }
            }
        }
Ejemplo n.º 4
0
        public static LinkData Decode(G2Header root)
        {
            LinkData link  = new LinkData();
            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Project:
                    link.Project = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_Target:
                    link.Target   = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    link.TargetID = Utilities.KeytoID(link.Target);
                    break;

                case Packet_Uplink:
                    link.Uplink = BitConverter.ToBoolean(child.Data, child.PayloadPos);
                    break;

                case Packet_Title:
                    link.Title = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(link);
        }
Ejemplo n.º 5
0
        public static AudioPacket Decode(G2Header root)
        {
            AudioPacket packet = new AudioPacket();

            if (G2Protocol.ReadPayload(root))
            {
                packet.Audio = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize);
            }

            G2Protocol.ResetPacket(root);

            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_FrameSize:
                    packet.FrameSize = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(packet);
        }
Ejemplo n.º 6
0
        public static ProfileField Decode(G2Header root)
        {
            ProfileField field = new ProfileField();
            G2Header     child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Type:
                    field.FieldType = (ProfileFieldType)child.Data[child.PayloadPos];
                    break;

                case Packet_Name:
                    field.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Value:
                    field.Value = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(field);
        }
Ejemplo n.º 7
0
        public static WebCache Decode(G2Header root)
        {
            WebCache cache = new WebCache();

            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Address:
                    cache.Address = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_AccessKey:
                    cache.AccessKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_LastSeen:
                    cache.LastSeen = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                    break;

                case Packet_LastTried:
                    cache.LastTried = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                    break;
                }
            }

            return(cache);
        }
Ejemplo n.º 8
0
        public static SignedData Decode(G2Header root)
        {
            SignedData signed = new SignedData();
            G2Header   child  = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Signature:
                    signed.Signature = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

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

            return(signed);
        }
Ejemplo n.º 9
0
        public static UserInfo Decode(G2Header root)
        {
            UserInfo user = new UserInfo();

            if (G2Protocol.ReadPayload(root))
            {
                user.Key = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize);
                user.ID  = Utilities.KeytoID(user.Key);
            }

            G2Protocol.ResetPacket(root);

            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Name:
                    user.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(user);
        }
Ejemplo n.º 10
0
        public static MailDestination Decode(G2Header root)
        {
            MailDestination dest  = new MailDestination();
            G2Header        child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Key:
                    dest.Key   = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    dest.KeyID = Utilities.KeytoID(dest.Key);
                    break;

                case Packet_CC:
                    dest.CC = BitConverter.ToBoolean(child.Data, child.PayloadPos);
                    break;
                }
            }

            return(dest);
        }
Ejemplo n.º 11
0
        public static PostInfo Decode(G2Header root)
        {
            PostInfo info  = new PostInfo();
            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Subject:
                    info.Subject = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Format:
                    info.Format = (TextFormat)CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Quip:
                    info.Quip = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Unique:
                    info.Unique = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;
                }
            }

            return(info);
        }
Ejemplo n.º 12
0
        public static CommData Decode(G2Header root)
        {
            CommData data = new CommData();

            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Service:
                    data.Service = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

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

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

            return(data);
        }
Ejemplo n.º 13
0
        public void ReadChildren(G2Header rootPacket, TreeNode rootNode, Type packetType)
        {
            G2Header child = new G2Header(rootPacket.Data);

            while (G2Protocol.ReadNextChild(rootPacket, child) == G2ReadResult.PACKET_GOOD)
            {
                string name = child.Name.ToString();

                if (packetType != null)
                {
                    name += " : " + GetVariableName(packetType, child.Name);
                }

                TreeNode childNode = rootNode.Nodes.Add(name);

                if (G2Protocol.ReadPayload(child))
                {
                    //childNode.Nodes.Add( "Payload Ascii: " + Utilities.BytestoAscii(childPacket.Data, childPacket.PayloadPos, childPacket.PayloadSize));
                    childNode.Nodes.Add(new DataNode(child.Data, child.PayloadPos, child.PayloadSize));
                }

                G2Protocol.ResetPacket(child);

                ReadChildren(child, childNode, null);
            }
        }
Ejemplo n.º 14
0
        public UpdateInfo ReadUpdateInfo()
        {
            if (!File.Exists(BootstrapPath))
            {
                return(null);
            }

            try
            {
                using (IVCryptoStream crypto = IVCryptoStream.Load(BootstrapPath, BootstrapKey))
                {
                    PacketStream stream = new PacketStream(crypto, new G2Protocol(), FileAccess.Read);

                    G2Header root = null;

                    while (stream.ReadPacket(ref root))
                    {
                        if (root.Name == IdentityPacket.Update)
                        {
                            return(UpdateInfo.Decode(root));
                        }
                    }
                }
            }
            catch { }

            return(null);
        }
Ejemplo n.º 15
0
        public static LargeDataPacket Decode(G2Header root)
        {
            LargeDataPacket packet = new LargeDataPacket(root.Name, 0, null);

            // size packet
            G2Header child = new G2Header(root.Data);

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

                if (child.Name == Packet_Size)
                {
                    packet.Size = BitConverter.ToInt32(child.Data, child.PayloadPos);
                }

                if (child.Name == Packet_Hash)
                {
                    packet.Hash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                }
            }

            return(packet);
        }
Ejemplo n.º 16
0
        public static InvitePackage OpenInvite(byte[] decrypted, G2Protocol protocol)
        {
            // if we get down here, opening invite was success

            MemoryStream mem    = new MemoryStream(decrypted);
            PacketStream stream = new PacketStream(mem, protocol, FileAccess.Read);

            InvitePackage package = new InvitePackage();

            G2Header root = null;

            while (stream.ReadPacket(ref root))
            {
                if (root.Name == InvitePacket.Info)
                {
                    package.Info = OneWayInvite.Decode(root);
                }

                if (root.Name == InvitePacket.Contact)
                {
                    package.Contacts.Add(DhtContact.ReadPacket(root));
                }

                if (root.Name == InvitePacket.WebCache)
                {
                    package.Caches.Add(WebCache.Decode(root));
                }
            }

            return(package);
        }
Ejemplo n.º 17
0
        public static OneWayInvite Decode(G2Header root)
        {
            OneWayInvite invite = new OneWayInvite();

            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_UserName:
                    invite.UserName = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_OpName:
                    invite.OpName = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_OpAccess:
                    invite.OpAccess = (AccessType)child.Data[child.PayloadPos];
                    break;

                case Packet_OpID:
                    invite.OpID = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(invite);
        }
Ejemplo n.º 18
0
        public static SubHashPacket Decode(G2Header root)
        {
            SubHashPacket subhash = new SubHashPacket();

            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_ChunkSize:
                    subhash.ChunkSize = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_TotalCount:
                    subhash.TotalCount = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_SubHashes:
                    subhash.SubHashes = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(subhash);
        }
Ejemplo n.º 19
0
        public static PostFile Decode(G2Header root)
        {
            PostFile file  = new PostFile();
            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Name:
                    file.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Size:
                    file.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(file);
        }
Ejemplo n.º 20
0
        public static CachedIP Decode(G2Header root)
        {
            CachedIP saved = new CachedIP();

            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Contact:
                    saved.Contact = DhtContact.ReadPacket(child);
                    break;

                case Packet_LastSeen:
                    saved.LastSeen = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                    break;

                case Packet_Bootstrap:
                    saved.Bootstrap = BitConverter.ToBoolean(child.Data, child.PayloadPos);
                    break;
                }
            }

            saved.Contact.LastSeen = saved.LastSeen;

            return(saved);
        }
Ejemplo n.º 21
0
        public static MessageData Decode(G2Header root)
        {
            MessageData msg = new MessageData();

            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_Text:
                    msg.Text = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Format:
                    msg.Format = (TextFormat)CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_TargetID:
                    msg.TargetID = BitConverter.ToUInt64(child.Data, child.PayloadPos);
                    break;
                }
            }

            return(msg);
        }
Ejemplo n.º 22
0
        public static KeyRequest Decode(G2ReceivedPacket packet)
        {
            KeyRequest kr = new KeyRequest();

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

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

                if (child.Name == Packet_Encryption)
                {
                    kr.Encryption = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                }

                else if (child.Name == Packet_Key)
                {
                    kr.Key = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                }

                else if (child.Name == Packet_IV)
                {
                    kr.IV = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                }
            }

            return(kr);
        }
Ejemplo n.º 23
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);
        }
Ejemplo n.º 24
0
        public static TempData Decode(ulong target, byte[] data)
        {
            G2Header root = new G2Header(data);

            G2Protocol.ReadPacket(root);

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

            TempData temp  = new TempData(target);
            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_TTL:
                    temp.TTL = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

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

            return(temp);
        }
Ejemplo n.º 25
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.º 26
0
        public static ShareCollection Decode(G2Header header, ulong user)
        {
            ShareCollection root  = new ShareCollection(user);
            G2Header        child = new G2Header(header.Data);

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

                switch (child.Name)
                {
                case Packet_Hash:
                    root.Hash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Size:
                    root.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Key:
                    root.Key = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(root);
        }
Ejemplo n.º 27
0
        public static ProxyReq Decode(G2ReceivedPacket packet)
        {
            ProxyReq pr = new ProxyReq();

            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))
                    {
                        pr.SenderID = BitConverter.ToUInt64(child.Data, child.PayloadPos);
                    }
                    break;

                case Packet_Blocked:
                    pr.Type = ProxyType.ClientBlocked;
                    break;

                case Packet_NAT:
                    pr.Type = ProxyType.ClientNAT;
                    break;
                }
            }

            return(pr);
        }
Ejemplo n.º 28
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.º 29
0
        public static DhtAddress ReadPacket(G2Header root)
        {
            // read payload
            DhtAddress address = new DhtAddress();

            address.UserID   = BitConverter.ToUInt64(root.Data, root.PayloadPos);
            address.ClientID = BitConverter.ToUInt16(root.Data, root.PayloadPos + 8);
            address.UdpPort  = BitConverter.ToUInt16(root.Data, root.PayloadPos + 10);

            // read packets
            G2Protocol.ResetPacket(root);

            G2Header child = new G2Header(root.Data);

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

                switch (child.Name)
                {
                case Packet_IP:
                    address.IP = new IPAddress(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize));
                    break;
                }
            }

            return(address);
        }
Ejemplo n.º 30
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.º 31
0
        internal static SharedFile Decode(G2Header header, ushort client)
        {
            SharedFile root = new SharedFile(client);
            G2Header child = new G2Header(header.Data);

            while (G2Protocol.ReadNextChild(header, child) == G2ReadResult.PACKET_GOOD)
            {
                if (child.Name == Packet_Public)
                    root.Public = true;

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

                switch (child.Name)
                {
                    case Packet_Name:
                        root.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Hash:
                        root.Hash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Size:
                        root.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_FileKey:
                        root.FileKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_SystemPath:
                        root.SystemPath = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;
                }
            }

            return root;
        }
Ejemplo n.º 32
0
        internal static ShareCollection Decode(G2Header header, ulong user)
        {
            ShareCollection root = new ShareCollection(user);
            G2Header child = new G2Header(header.Data);

            while (G2Protocol.ReadNextChild(header, child) == G2ReadResult.PACKET_GOOD)
            {

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

                switch (child.Name)
                {
                    case Packet_Hash:
                        root.Hash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Size:
                        root.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Key:
                        root.Key = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        break;
                }
            }

            return root;
        }
Ejemplo n.º 33
0
        void Session_Data(RudpSession session, byte[] data)
        {
            G2Header root = new G2Header(data);

            if (G2Protocol.ReadPacket(root))
            {
                switch (root.Name)
                {
                    case SharingPacket.File:
                        ReceiveFileRequest(session, SharedFile.Decode(root, Core.Network.Local.ClientID));
                        break;

                    case SharingPacket.PublicRequest:
                        ReceivePublicRequest(session);
                        break;

                    case SharingPacket.Collection:
                        ReceivePublicDetails(session, ShareCollection.Decode(root, session.UserID));
                        break;
                }
            }
        }
Ejemplo n.º 34
0
 internal static PublicShareRequest Decode(G2Header header)
 {
     return new PublicShareRequest();
 }