private void AddStates(NetGraphBuilder builder, SwitchNodeFactory outputSwitch, SwitchNodeFactory inputSwitch, BaseNodeFactory outputNode, BaseNodeFactory inputNode) { foreach (StateGraphEntry entry in _entries) { BaseNodeFactory currentInput = inputSwitch; BaseNodeFactory currentOutput = outputSwitch; NetGraphFactory graph = entry.Graph == null?NetGraphBuilder.CreateDefaultProxyGraph(entry.StateName) : entry.Graph.Factory; LayerSectionMasterNodeFactory masterNode = new LayerSectionMasterNodeFactory(String.Format("{0} {1}", entry.StateName, GetDirection(false)), Guid.NewGuid(), Guid.NewGuid()); masterNode.DefaultMode = LayerSectionNodeDefaultMode.PassFrame; masterNode.Direction = LayerSectionGraphDirection.ServerToClient; builder.AddNode(masterNode); builder.AddNode(masterNode.SlaveFactory); LayerSectionFilterFactory[] filters = new LayerSectionFilterFactory[1]; LayerSectionFilterFactory filter = new LayerSectionFilterFactory(); filter.GraphFactory = graph; filter.LayerFactories = entry.GetLayerFactories(); filter.SelectionPath = ""; filter.FilterFactory = DataFrameFilterFactory.CreateDummyFactory(); filter.IsolatedGraph = false; masterNode.LayerFactories = new LayerSectionFilterFactory[1] { filter }; masterNode.SlaveFactory.Hidden = true; builder.AddLine(outputSwitch, masterNode, entry.StateName); builder.AddLine(inputSwitch, masterNode.SlaveFactory, entry.StateName); if (entry.LogPackets) { currentOutput = AddLog(builder, entry, masterNode, false); currentInput = AddLog(builder, entry, masterNode.SlaveFactory, true); } else { currentOutput = masterNode; currentInput = masterNode.SlaveFactory; } builder.AddLine(currentOutput, outputNode, null); builder.AddLine(currentInput, inputNode, null); } }
private void AddStateFromEntry(NetGraphBuilder builder, StateGraphEntry entry, BaseNodeFactory inputNode, BaseNodeFactory outputNode, bool clientToServer) { BaseNodeFactory currentFactory; if (entry.Graph != null) { currentFactory = builder.AddNode(new NetGraphContainerNodeFactory(String.Format("{0} {1}", entry.StateName, GetDirection(clientToServer)), Guid.NewGuid(), entry.Graph.Factory, clientToServer ? NetGraphContainerNode.GraphDirection.ClientToServer : NetGraphContainerNode.GraphDirection.ServerToClient)); currentFactory.Hidden = true; builder.AddLine(inputNode, currentFactory, entry.StateName); } else { currentFactory = inputNode; } if (entry.LogPackets) { LogPacketNodeFactory log = builder.AddLog(String.Format("{0} Log {1}", entry.StateName, GetDirection(clientToServer)), Guid.NewGuid(), entry.Color, null, false); log.Hidden = true; builder.AddLine(currentFactory, log, null); currentFactory = log; } builder.AddLine(currentFactory, outputNode, null); }
private static NetGraph BuildGraph(ScriptContainer container, string classname, string selectionPath, out BasePipelineNode input, out ParseWithPipelineNode output) { DynamicNodeFactory factory = new DynamicNodeFactory("", Guid.NewGuid(), container, classname, null); ParseWithPipelineNodeFactory parseWithFactory = new ParseWithPipelineNodeFactory(); factory.SelectionPath = selectionPath; NetGraphBuilder builder = new NetGraphBuilder(); builder.AddNode(factory); builder.AddNode(parseWithFactory); builder.AddLine(factory, parseWithFactory, null); NetGraph graph = builder.Factory.Create(Logger.GetSystemLogger(), null, new MetaDictionary(), new MetaDictionary(), new PropertyBag("Connection")); input = graph.Nodes[factory.Id]; output = (ParseWithPipelineNode)graph.Nodes[parseWithFactory.Id]; return(graph); }
/// <summary> /// Constructor /// </summary> /// <param name="logger">The logger</param> /// <param name="config">Configuration for the server</param> public FullHttpProxyServer(HttpProxyServerConfig config, Logger logger) : base(logger) { _config = config; NetGraphBuilder builder = new NetGraphBuilder(); ClientEndpointFactory client = builder.AddClient("Client", Guid.NewGuid()); ServerEndpointFactory server = builder.AddServer("Server", Guid.NewGuid()); DirectNodeFactory nop = builder.AddNode(new DirectNodeFactory("NOP", Guid.NewGuid())); builder.AddLines(client, nop, server, client); _factory = builder.Factory; }
private SwitchNodeFactory CreateBaseGraph(NetGraphBuilder builder, BaseNodeFactory inputNode, BaseNodeFactory outputNode, bool clientToServer) { SwitchNodeFactory switchNode = builder.AddNode(new SwitchNodeFactory(String.Format("{0} Switch {1}", _metaName, GetDirection(clientToServer)), Guid.NewGuid(), false, CANAPE.Nodes.SwitchNodeSelectionMode.ExactMatch)); switchNode.Hidden = true; switchNode.SelectionPath = "#" + (String.IsNullOrWhiteSpace(_metaName) ? "Invalid" : _metaName.Trim()); builder.AddLine(inputNode, switchNode, null); LogPacketNodeFactory log = builder.AddLog(String.Format("Invalid Traffic {0}", GetDirection(clientToServer)), Guid.NewGuid(), new ColorValue(255, 0, 0), null, false); log.Hidden = true; builder.AddLine(switchNode, log, null); builder.AddLine(log, outputNode, null); return(switchNode); }
/// <summary> /// Create the test graph /// </summary> /// <param name="logger">The logger to use</param> /// <param name="globals">The global meta</param> /// <returns>The new test graph container</returns> /// <exception cref="ArgumentException">Throw if script invalid</exception> public override TestGraphContainer CreateTestGraph(Logger logger, MetaDictionary globals) { if (String.IsNullOrWhiteSpace(_config.ClassName)) { throw new ArgumentException(CANAPE.Documents.Properties.Resources.ScriptTestDocument_MustProvideClassname); } NetGraphBuilder builder = new NetGraphBuilder(); ServerEndpointFactory server = builder.AddServer("server", Guid.NewGuid()); DynamicNodeFactory node = builder.AddNode((DynamicNodeFactory)_config.CreateFactory()); LogPacketNodeFactory log = builder.AddLog("Test Network", Guid.NewGuid(), new ColorValue(0xFF, 0xFF, 0xFF, 0xFF), "Entry", false); ClientEndpointFactory client = builder.AddClient("client", Guid.NewGuid()); builder.AddLine(server, node, null); builder.AddLine(node, log, null); builder.AddLine(log, client, null); NetGraph graph = builder.Factory.Create(logger, null, globals, new MetaDictionary(), new PropertyBag("Connection")); return(new TestGraphContainer(graph, graph.Nodes[server.Id], graph.Nodes[client.Id])); }
private SwitchNodeFactory CreateBaseGraph(NetGraphBuilder builder, BaseNodeFactory inputNode, BaseNodeFactory outputNode, bool clientToServer) { SwitchNodeFactory switchNode = builder.AddNode(new SwitchNodeFactory(String.Format("{0} Switch {1}", _metaName, GetDirection(clientToServer)), Guid.NewGuid(), false, CANAPE.Nodes.SwitchNodeSelectionMode.ExactMatch)); switchNode.Hidden = true; switchNode.SelectionPath = "#" + (String.IsNullOrWhiteSpace(_metaName) ? "Invalid" : _metaName.Trim()); builder.AddLine(inputNode, switchNode, null); LogPacketNodeFactory log = builder.AddLog(String.Format("Invalid Traffic {0}", GetDirection(clientToServer)), Guid.NewGuid(), new ColorValue(255, 0, 0), null, false); log.Hidden = true; builder.AddLine(switchNode, log, null); builder.AddLine(log, outputNode, null); return switchNode; }
private void AddStates(NetGraphBuilder builder, SwitchNodeFactory outputSwitch, SwitchNodeFactory inputSwitch, BaseNodeFactory outputNode, BaseNodeFactory inputNode) { foreach (StateGraphEntry entry in _entries) { BaseNodeFactory currentInput = inputSwitch; BaseNodeFactory currentOutput = outputSwitch; NetGraphFactory graph = entry.Graph == null ? NetGraphBuilder.CreateDefaultProxyGraph(entry.StateName) : entry.Graph.Factory; LayerSectionMasterNodeFactory masterNode = new LayerSectionMasterNodeFactory(String.Format("{0} {1}", entry.StateName, GetDirection(false)), Guid.NewGuid(), Guid.NewGuid()); masterNode.DefaultMode = LayerSectionNodeDefaultMode.PassFrame; masterNode.Direction = LayerSectionGraphDirection.ServerToClient; builder.AddNode(masterNode); builder.AddNode(masterNode.SlaveFactory); LayerSectionFilterFactory[] filters = new LayerSectionFilterFactory[1]; LayerSectionFilterFactory filter = new LayerSectionFilterFactory(); filter.GraphFactory = graph; filter.LayerFactories = entry.GetLayerFactories(); filter.SelectionPath = ""; filter.FilterFactory = DataFrameFilterFactory.CreateDummyFactory(); filter.IsolatedGraph = false; masterNode.LayerFactories = new LayerSectionFilterFactory[1] { filter }; masterNode.SlaveFactory.Hidden = true; builder.AddLine(outputSwitch, masterNode, entry.StateName); builder.AddLine(inputSwitch, masterNode.SlaveFactory, entry.StateName); if (entry.LogPackets) { currentOutput = AddLog(builder, entry, masterNode, false); currentInput = AddLog(builder, entry, masterNode.SlaveFactory, true); } else { currentOutput = masterNode; currentInput = masterNode.SlaveFactory; } builder.AddLine(currentOutput, outputNode, null); builder.AddLine(currentInput, inputNode, null); } }
private void btnInject_Click(object sender, EventArgs e) { if (_injectGraph != null) { CancelInject(); } else { try { NetGraph selectedGraph = comboBoxConnection.SelectedItem as NetGraph; while ((selectedGraph == null) || (selectedGraph.CheckShutdown())) { PopulateConnections(); if (comboBoxConnection.Items.Count == 0) { selectedGraph = null; break; } comboBoxConnection.SelectedItem = comboBoxConnection.Items[0]; selectedGraph = comboBoxConnection.SelectedItem as NetGraph; } if (selectedGraph != null) { if (logPacketControl.Packets.Length > 0) { if (comboBoxNodes.SelectedItem != null) { int repeatCount = (int)numericRepeatCount.Value; BasePipelineNode node = (BasePipelineNode)comboBoxNodes.SelectedItem; LogPacket[] basePackets = checkBoxInjectSelected.Checked ? logPacketControl.SelectedPackets : logPacketControl.Packets; List <LogPacket> packets = new List <LogPacket>(); for (int i = 0; i < repeatCount; ++i) { packets.AddRange((LogPacket[])GeneralUtils.CloneObject(basePackets)); } NetGraphBuilder builder = new NetGraphBuilder(); ClientEndpointFactory client = builder.AddClient("client", Guid.NewGuid()); ServerEndpointFactory server = builder.AddServer("server", Guid.NewGuid()); DynamicNodeFactory dyn = null; BaseNodeFactory startNode = client; if (_config.EnablePacketDelay && (_config.PacketDelayMs > 0)) { DelayNodeFactory delay = builder.AddNode(new DelayNodeFactory("delay", Guid.NewGuid()) { PacketDelayMs = (int)_config.PacketDelayMs }); builder.AddLine(startNode, delay, null); startNode = delay; } if (_config.EnableScripting && _config.ScriptDocumentId != Guid.Empty && !String.IsNullOrWhiteSpace(_config.ScriptDocumentClass)) { ScriptDocument doc = CANAPEProject.CurrentProject.GetDocumentByUuid(_config.ScriptDocumentId) as ScriptDocument; if (doc != null) { dyn = new DynamicNodeFactory("dyn", Guid.NewGuid(), doc.Container, _config.ScriptDocumentClass, null); builder.AddNode(dyn); builder.AddLine(startNode, dyn, null); startNode = dyn; } } builder.AddLine(startNode, server, null); _injectGraph = builder.Factory.Create(selectedGraph.Logger, selectedGraph, selectedGraph.GlobalMeta, new MetaDictionary(), new PropertyBag("root")); QueuedDataAdapter inputAdapter = new QueuedDataAdapter(); foreach (LogPacket p in packets) { inputAdapter.Enqueue(p.Frame); } inputAdapter.StopEnqueue(); _injectGraph.BindEndpoint(client.Id, inputAdapter); _injectGraph.BindEndpoint(server.Id, new DelegateDataAdapter( () => this.CancelInject(), frame => node.Input(frame), null )); // Start injection (_injectGraph.Nodes[client.Id] as IPipelineEndpoint).Start(); // Check if the dynamic node was an endpoint (so a generator), start as well if ((dyn != null) && (_injectGraph.Nodes[dyn.Id] is PipelineEndpoint)) { (_injectGraph.Nodes[dyn.Id] as IPipelineEndpoint).Start(); } // Start cancel timer timerCancel.Start(); btnInject.Text = CANAPE.Properties.Resources.InjectPacketControl_CancelButtonText; } else { MessageBox.Show(this, CANAPE.Properties.Resources.InjectPacketForm_SelectNode, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show(this, CANAPE.Properties.Resources.InjectPacketForm_SelectGraph, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (NotSupportedException) { MessageBox.Show(this, CANAPE.Properties.Resources.InjectPacketForm_NotSupported, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (InvalidOperationException ex) { MessageBox.Show(this, ex.Message, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (NodeFactoryException ex) { MessageBox.Show(this, ex.Message, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private static NetGraph BuildGraph(ScriptContainer container, string classname, string selectionPath, out BasePipelineNode input, out ParseWithPipelineNode output) { DynamicNodeFactory factory = new DynamicNodeFactory("", Guid.NewGuid(), container, classname, null); ParseWithPipelineNodeFactory parseWithFactory = new ParseWithPipelineNodeFactory(); factory.SelectionPath = selectionPath; NetGraphBuilder builder = new NetGraphBuilder(); builder.AddNode(factory); builder.AddNode(parseWithFactory); builder.AddLine(factory, parseWithFactory, null); NetGraph graph = builder.Factory.Create(Logger.GetSystemLogger(), null, new MetaDictionary(), new MetaDictionary(), new PropertyBag("Connection")); input = graph.Nodes[factory.Id]; output = (ParseWithPipelineNode)graph.Nodes[parseWithFactory.Id]; return graph; }
private void btnInject_Click(object sender, EventArgs e) { if (_injectGraph != null) { CancelInject(); } else { try { NetGraph selectedGraph = comboBoxConnection.SelectedItem as NetGraph; while ((selectedGraph == null) || (selectedGraph.CheckShutdown())) { PopulateConnections(); if (comboBoxConnection.Items.Count == 0) { selectedGraph = null; break; } comboBoxConnection.SelectedItem = comboBoxConnection.Items[0]; selectedGraph = comboBoxConnection.SelectedItem as NetGraph; } if (selectedGraph != null) { if (logPacketControl.Packets.Length > 0) { if (comboBoxNodes.SelectedItem != null) { int repeatCount = (int)numericRepeatCount.Value; BasePipelineNode node = (BasePipelineNode)comboBoxNodes.SelectedItem; LogPacket[] basePackets = checkBoxInjectSelected.Checked ? logPacketControl.SelectedPackets : logPacketControl.Packets; List<LogPacket> packets = new List<LogPacket>(); for (int i = 0; i < repeatCount; ++i) { packets.AddRange((LogPacket[])GeneralUtils.CloneObject(basePackets)); } NetGraphBuilder builder = new NetGraphBuilder(); ClientEndpointFactory client = builder.AddClient("client", Guid.NewGuid()); ServerEndpointFactory server = builder.AddServer("server", Guid.NewGuid()); DynamicNodeFactory dyn = null; BaseNodeFactory startNode = client; if (_config.EnablePacketDelay && (_config.PacketDelayMs > 0)) { DelayNodeFactory delay = builder.AddNode(new DelayNodeFactory("delay", Guid.NewGuid()) { PacketDelayMs = (int)_config.PacketDelayMs }); builder.AddLine(startNode, delay, null); startNode = delay; } if (_config.EnableScripting && _config.ScriptDocumentId != Guid.Empty && !String.IsNullOrWhiteSpace(_config.ScriptDocumentClass)) { ScriptDocument doc = CANAPEProject.CurrentProject.GetDocumentByUuid(_config.ScriptDocumentId) as ScriptDocument; if (doc != null) { dyn = new DynamicNodeFactory("dyn", Guid.NewGuid(), doc.Container, _config.ScriptDocumentClass, null); builder.AddNode(dyn); builder.AddLine(startNode, dyn, null); startNode = dyn; } } builder.AddLine(startNode, server, null); _injectGraph = builder.Factory.Create(selectedGraph.Logger, selectedGraph, selectedGraph.GlobalMeta, new MetaDictionary(), new PropertyBag("root")); QueuedDataAdapter inputAdapter = new QueuedDataAdapter(); foreach (LogPacket p in packets) { inputAdapter.Enqueue(p.Frame); } inputAdapter.StopEnqueue(); _injectGraph.BindEndpoint(client.Id, inputAdapter); _injectGraph.BindEndpoint(server.Id, new DelegateDataAdapter( () => this.CancelInject(), frame => node.Input(frame), null )); // Start injection (_injectGraph.Nodes[client.Id] as IPipelineEndpoint).Start(); // Check if the dynamic node was an endpoint (so a generator), start as well if ((dyn != null) && (_injectGraph.Nodes[dyn.Id] is PipelineEndpoint)) { (_injectGraph.Nodes[dyn.Id] as IPipelineEndpoint).Start(); } // Start cancel timer timerCancel.Start(); btnInject.Text = CANAPE.Properties.Resources.InjectPacketControl_CancelButtonText; } else { MessageBox.Show(this, CANAPE.Properties.Resources.InjectPacketForm_SelectNode, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show(this, CANAPE.Properties.Resources.InjectPacketForm_SelectGraph, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (NotSupportedException) { MessageBox.Show(this, CANAPE.Properties.Resources.InjectPacketForm_NotSupported, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (InvalidOperationException ex) { MessageBox.Show(this, ex.Message, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (NodeFactoryException ex) { MessageBox.Show(this, ex.Message, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Create the test graph /// </summary> /// <param name="logger">The logger to use</param> /// <param name="globals">The global meta</param> /// <returns>The new test graph container</returns> /// <exception cref="ArgumentException">Throw if script invalid</exception> public override TestGraphContainer CreateTestGraph(Logger logger, MetaDictionary globals) { if (String.IsNullOrWhiteSpace(_config.ClassName)) { throw new ArgumentException(CANAPE.Documents.Properties.Resources.ScriptTestDocument_MustProvideClassname); } NetGraphBuilder builder = new NetGraphBuilder(); ServerEndpointFactory server = builder.AddServer("server", Guid.NewGuid()); DynamicNodeFactory node = builder.AddNode((DynamicNodeFactory)_config.CreateFactory()); LogPacketNodeFactory log = builder.AddLog("Test Network", Guid.NewGuid(), new ColorValue(0xFF, 0xFF, 0xFF, 0xFF), "Entry", false); ClientEndpointFactory client = builder.AddClient("client", Guid.NewGuid()); builder.AddLine(server, node, null); builder.AddLine(node, log, null); builder.AddLine(log, client, null); NetGraph graph = builder.Factory.Create(logger, null, globals, new MetaDictionary(), new PropertyBag("Connection")); return new TestGraphContainer(graph, graph.Nodes[server.Id], graph.Nodes[client.Id]); }