public static void Identify(MooNetClient client) { var packet = new PacketIn(client, client.IncomingMooNetStream.GetPacketHeader()); if (packet.Header.ServiceId == ServiceReply) ProcessReply(client, packet); else ProcessMessage(client, packet); }
public static void Identify(IConnection connection, CodedInputStream stream) { var client = (MooNetClient) connection.Client; var packet = new PacketIn(client, stream); if (packet.Header.ServiceId == ServiceReply) ProcessReply(client, packet); else ProcessMessage(client, stream, packet); }
private static void ProcessReply(MooNetClient client, PacketIn packet) { if (client.RPCCallbacks.ContainsKey(packet.Header.Token)) { var callback = client.RPCCallbacks[packet.Header.Token]; Logger.Trace("RPCReply => {0}", callback.Action.Target); callback.Action(packet.ReadMessage(callback.Builder)); client.RPCCallbacks.Remove(packet.Header.Token); } else { Logger.Warn("RPC callback contains unexpected token: {0}", packet.Header.Token); client.Connection.Disconnect(); } }
private static void ProcessMessage (MooNetClient client, PacketIn packet) { var service = Service.GetByID (packet.Header.ServiceId); if (service == null) { Logger.Error ("No service exists with id: 0x{0}", packet.Header.ServiceId.ToString ("X2")); return; } var method = service.DescriptorForType.Methods.Single (m => GetMethodId (m) == packet.Header.MethodId); var proto = service.GetRequestPrototype (method); var builder = proto.WeakCreateBuilderForType (); var message = packet.ReadMessage (builder); Logger.LogIncomingPacket (message, packet.Header); try { lock (service) { // lock the service so that its in-context client does not get changed.. ((IServerService)service).Client = client; ((IServerService)service).LastCallHeader = packet.Header; ((IServerService)service).Status = 0; service.CallMethod ( method, null, message, (msg => SendRPCResponse (client.Connection, packet.Header.Token, msg, ((IServerService)service).Status)) ); } Logger.Trace ("Trololololololololo {0}, {1}", method, message); } catch (NotImplementedException) { Logger.Warn("Unimplemented service method: {0}.{1}", service.GetType().Name, method.Name); } catch (UninitializedMessageException e) { Logger.Debug("Failed to parse message: {0}", e.Message); } catch (Exception e) { Logger.DebugException(e, string.Empty); } }
public MooNetCallNode(PacketIn packet, CodedInputStream stream) { var service = Service.GetByID(packet.Header.ServiceId); var method = service.DescriptorForType.Methods.Single(m => MooNetRouter.GetMethodId(m) == packet.Header.MethodId); var proto = service.GetRequestPrototype(method); reply = service.GetResponsePrototype(method); var builder = proto.WeakCreateBuilderForType(); try { message = builder.WeakMergeFrom(CodedInputStream.CreateInstance(packet.GetPayload(stream))).WeakBuild(); Text = message.DescriptorForType.Name; } catch (Exception e) { message = builder.WeakBuildPartial(); Text = "Error parsing message {0}"; } }
private static void ProcessMessage(MooNetClient client, CodedInputStream stream, PacketIn packet) { var service = Service.GetByID(packet.Header.ServiceId); if (service == null) { Logger.Error("No service exists with id: 0x{0}", packet.Header.ServiceId.ToString("X2")); return; } var method = service.DescriptorForType.Methods.Single(m => GetMethodId(m) == packet.Header.MethodId); var proto = service.GetRequestPrototype(method); var builder = proto.WeakCreateBuilderForType(); var message = builder.WeakMergeFrom(CodedInputStream.CreateInstance(packet.GetPayload(stream))).WeakBuild(); //var message = packet.ReadMessage(proto.WeakToBuilder()); // this method doesn't seem to work with 7728. /raist. Logger.LogIncoming(message, packet.Header); try { lock (service) // lock the service so that its in-context client does not get changed.. { ((IServerService)service).Client = client; ((IServerService)service).LastCallHeader = packet.Header; service.CallMethod(method, null, message, (msg => SendRPCResponse(client.Connection, packet.Header.Token, msg))); } } catch (NotImplementedException) { Logger.Warn("Unimplemented service method: {0}.{1}", service.GetType().Name, method.Name); } catch (UninitializedMessageException e) { Logger.Debug("Failed to parse message: {0}", e.Message); } catch (Exception e) { Logger.DebugException(e, string.Empty); } }
private void BNetBufferAssembledCallback(byte[] buffer, Direction direction, string clientHash) { Dictionary<string, Color[]> colors = new Dictionary<string, Color[]>(); Color[][] trafficColors = new Color[][] { new Color[] { Color.LightCoral , Color.LightBlue }, new Color[] { Color.Tomato, Color.Blue }, new Color[] { Color.Red, Color.BlueViolet }, new Color[] { Color.PaleVioletRed, Color.CadetBlue } }; var stream = CodedInputStream.CreateInstance(buffer); while (!stream.IsAtEnd) { try { var packet = new PacketIn(null, stream); if (packet.Header.ServiceId == 0xFE /*ServiceReply*/) { //ProcessReply(client, packet); var callNode = RPCCallbacksIn[packet.Header.Token]; RPCCallbacksIn.Remove(packet.Header.Token); callNode.ReceiveReply(packet, true); } else { var service = Service.GetByID(packet.Header.ServiceId); if (service == null) { MooNetTree.Nodes.Add(String.Format("Service not found: {0}", service)); return; } var newNode = new MooNetCallNode(packet, stream); MooNetTree.Nodes.Add(newNode); RPCCallbacksIn.Add(packet.Header.Token, newNode); } } catch (Exception e) { var newNode = new TreeNode(String.Format("Error parsing {0}", e.Message)); MooNetTree.Nodes.Add(newNode); } } }
public TreeNode ReceiveReply(PacketIn packet, bool add) { var node = new MooNetReplyNode(packet, reply.WeakCreateBuilderForType()); this.Nodes.Add(node); return node; }
public MooNetReplyNode(PacketIn packet, IBuilder builder) { this.packet = packet; this.message = packet.ReadMessage(builder); this.Text = message.DescriptorForType.Name; }