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); }
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 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 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); }
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); }
public static Bye Decode(G2ReceivedPacket packet) { Bye bye = new Bye(); G2Header child = new G2Header(packet.Root.Data); while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { if (child.Name == Packet_Reconnect) { bye.Reconnect = true; } continue; } switch (child.Name) { case Packet_Source: bye.SenderID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_Contacts: bye.ContactList.Add(DhtContact.ReadPacket(child)); break; case Packet_Message: bye.Message = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(bye); }