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); }
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); } } } }
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); } } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); } } } } }
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); }
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); }
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); }
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); }
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); }
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; }
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; }
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; } } }
internal static PublicShareRequest Decode(G2Header header) { return new PublicShareRequest(); }