private static void ParsePing(BinaryReader reader) { UdpContact c = ReadContact(reader); long tokenId = IPAddress.NetworkToHostOrder(reader.ReadInt64()); localTable.DeliverPing(c); var callback = localTable.GetConsumer <Callback>(Callback.CONSUMER_ID); callback.SendResponse(localTable.LocalContact, c, tokenId, new byte[] { 1, 3, 3, 7 }); }
private Action<IAsyncResult> CreateEatPacket(DistributedRoutingTable routingTable) { return a => { try { IPEndPoint ep = new IPEndPoint(IPAddress.Any, ListenPort); var m = new MemoryStream(udpClient.EndReceive(a, ref ep)); ProxyContact source = Serializer.DeserializeWithLengthPrefix<ProxyContact>(m, PrefixStyle.Base128); if (m.ReadByte() == 0) { routingTable.DeliverPing(source); BinaryReader r = new BinaryReader(m); callback.SendResponse(routingTable.LocalContact, source, r.ReadInt64(), new byte[] { 1 }); } else { try { BinaryReader r = new BinaryReader(m); Guid consumer = new Guid(r.ReadBytes(16)); byte[] buffer = new byte[BitConverter.ToInt32(r.ReadBytes(4), 0)]; m.Read(buffer, 0, buffer.Length); ThreadPool.QueueUserWorkItem(_ => routingTable.Deliver(source, consumer, buffer)); } catch (Exception e) { Console.WriteLine(e); } } } catch (SocketException e) { Console.WriteLine(e); } }; }