private void HandleStateStatusChange(object sender, StateStatusChangeEventArgs e) { Node N; MethodInvoker action = delegate { DrawProtocolStates(); switch (e.StateStatus) { case State.Statuses.Started: N = graph.FindNode(ProtocolProvider.GetStateDesplayName(e.CurrentState)); N.Attr.FillColor = Microsoft.Msagl.Drawing.Color.MediumSeaGreen; break; case State.Statuses.FatalError: N = graph.FindNode(ProtocolProvider.GetStateDesplayName(e.CurrentState)); N.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; break; case State.Statuses.RuntimeError: N = graph.FindNode(ProtocolProvider.GetStateDesplayName(e.CurrentState)); N.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Yellow; break; //TODO:Add all Statuses } ProtocolStatesViewer.Refresh(); }; ProtocolStatesViewer.BeginInvoke(action); string Title = string.Format("{0}:{1}\n{2}", ProtocolProvider.GetStateDesplayName(e.CurrentState), e.StateStatus, e.Message); Log.LogEntery(new LoggingEntery("OctoTipPlus Appilcation", "ProtocolUserControl", Title, LoggingEntery.EnteryTypes.Debug)); }
public ChatSession(PacChatServer server, IChannel channel, ProtocolProvider protocolProvider, IConnectionManager connectionManager) : base(channel, protocolProvider.HandShake) { Server = server; this.protocolProvider = protocolProvider; this.connectionManager = connectionManager; }
protected async Task StartListeningAsync(Endpoint EP) { var P = ProtocolProvider.GetProvider(EP.Provider); if (P is { } Provider&& Source?.Token is { } Token) { await Provider.StartListeningAsync(EP, Token, GetHandler) .DefaultAwait() ; } }
public override string ToString() { string FieldNames = string.Empty; // = "Name=" + Name +"\n"; FieldInfo[] ProtocolFields = ProtocolProvider.GetProtocolParametersFields(this); foreach (FieldInfo FI in ProtocolFields) { FieldNames += string.Format("{0}={1}\n", FI.Name, FI.GetValue(this).ToString()); } return(FieldNames); }
private void DrawProtocolStates() { graph = new Graph("graph"); foreach (Type t in ProtocolProvider.GetProtocolStates(UserControlProtocolType)) { string NodeFrom = ProtocolProvider.GetStateDesplayName(t); foreach (Type ts in ProtocolProvider.GetStateNextStates(t)) { UpdateEdgeNodesAttr(graph.AddEdge(NodeFrom, ProtocolProvider.GetStateDesplayName(ts))); } } //Node N = graph.FindNode("Grow 1"); //N.Label.FontSize = 50; foreach (Node N in graph.NodeMap.Values) { // N.Label.FontSize = 50; } graph.Attr.LayerDirection = LayerDirection.None; double AspectRatio = Convert.ToDouble(panel1.Width) / Convert.ToDouble(panel1.Height); graph.Attr.AspectRatio = AspectRatio; //graph.Attr.MinNodeHeight = 50; //graph.Attr.MinNodeWidth = 100; // aspect ratio is set graph.Attr.BackgroundColor = Microsoft.Msagl.Drawing.Color.White; //Microsoft.Msagl.GeometryGraph geomGraph = new Microsoft.Msagl.GeometryGraph(); // geomGraph.SimpleStretch=false; // geomGraph.AspectRatio = 1; // geomGraph.CalculateLayout(); //ProtocolStatesViewer.Graph = graph; // graph.GeometryGraph = geomGraph; //ProtocolStatesViewer.Graph = graph; // ProtocolStatesViewer.NeedToCalculateLayout = false; ProtocolStatesViewer.Graph = graph; }
public ChatSocketServer(PacChatServer server, ProtocolProvider protocolProvider, CountdownLatch latch) : base(server, protocolProvider, latch) { this.bossGroup = new MultithreadEventLoopGroup(1); this.workerGroup = new MultithreadEventLoopGroup(); this.bootstrap = new ServerBootstrap(); this.bootstrap .Group(bossGroup, workerGroup) //.Option(ChannelOption.SoBacklog, 100) //.Handler(new LoggingHandler("SRV-LSTN")) .Channel <TcpServerSocketChannel>() .ChildOption(ChannelOption.TcpNodelay, true) .ChildOption(ChannelOption.SoKeepalive, true); }
private void PingNode(SwimNode node) { // Ping node directly PingCorrelationId = Ulid.NewUlid(); Debug.WriteLine($"Pinging node {node.Endpoint}."); Logger.LogInformation($"Pinging node {node.Endpoint}."); ProtocolProvider.SendMessage(node, new PingMessage(PingCorrelationId.Value) { SourceNode = ProtocolProvider.Node }); PingTimer.Start(); }
private void AddAvailableProtocols() { // List <Assembly> UncompitbleTypes = ProtocolProvider.GetUncompitbleProtocolPlugIns(); if (UncompitbleTypes.Count > 0) { string Massege = string.Empty; foreach (Assembly A in UncompitbleTypes) { Massege += string.Format("The suplied dll {0} is not compatible with the current version, and was not loaded\n", A.GetName()); } MessageBox.Show(Massege, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); List <Type> ProtocolsData = ProtocolProvider.GetAvalbleProtocolPlugIns(); ToolStripItem[] ToolStripProtocols = new ToolStripItem[ProtocolsData.Count]; // remove all items but the first 3. (refresh btn etc..) int ProtocolsToolStripItemsCount = this.ProtocolsToolStrip.Items.Count; for (int i = ProtocolsToolStripItemsCount; i > 3; i--) { this.ProtocolsToolStrip.Items.RemoveAt(i - 1); } foreach (Type ProtocolData in ProtocolsData) { ToolStripButton BTN = new ToolStripButton( ((ProtocolAttribute)ProtocolData.GetCustomAttributes(typeof(ProtocolAttribute), true)[0]).ShortName, ((System.Drawing.Image)(resources.GetObject("Protocol1.Image")))); BTN.ImageTransparentColor = System.Drawing.Color.Magenta; BTN.Size = new System.Drawing.Size(88, 20); BTN.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; BTN.ToolTipText = ((ProtocolAttribute)ProtocolData.GetCustomAttributes(typeof(ProtocolAttribute), true)[0]).Description; BTN.Click += new System.EventHandler(this.AvailableProtocolClick); BTN.Tag = ProtocolData; this.ProtocolsToolStrip.Items.Add(BTN); } }
private ChatConnection(ProtocolProvider protocolProvider) { this.Host = "pacchat.hytalevn.com"; this.Port = 8080; this.WebHost = "pacchat.hytalevn.com"; this.WebPort = 22; this.protocolProvider = protocolProvider; this.bootstrap = new Bootstrap(); this.workerGroup = new MultithreadEventLoopGroup(); bootstrap .Group(workerGroup) .Channel <TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, true) .Handler(new ChannelInitializer(this)); }
public PacChatServer() { instance = this; new ServerSettings(); protocolProvider = new ProtocolProvider(); SessionRegistry = new SessionRegistry(); Mongo.StartService(); ProfileCache.StartService(); CommandManager.StartService(); RegisterCommand(); Sticker.StartService(); StartNetworkService(); }
private void InitUserControlProtocol() { ProtocolStatesViewer.LayoutAlgorithmSettingsButtonVisible = true; if (UserControlProtocol != null) { //remove the courent Protocol from the List; ((MainForm)this.ParentForm).RemoveProtocol(this.UserControlProtocol); this.UserControlProtocol = null; } UserControlProtocol = ProtocolProvider.GetProtocol(UserControlProtocolType, UserControlProtocolParameters); UserControlProtocol.StatusChanged += HandleProtocolStatusChanged; UserControlProtocol.DisplayedDataChange += HandleDisplayedDataChange; UserControlProtocol.StateStatusChange += HandleStateStatusChange; UserControlProtocol.StateDisplayedDataChange += HandleStateDisplayedDataChange; ((MainForm)this.ParentForm).AddProtocol(this.UserControlProtocol); ActivateUserControlProtocol(); }
public async Task <IOutOfProcessController> StartAsync(OutOfProcessServerOptions?ServerOptions = default, OutOfProcessClientOptions?ClientOptions = default) { ServerOptions = ServerOptions ?? DefaultServerOptions(); ServerOptions = ServerOptions.Clone(); ClientOptions = ClientOptions ?? DefaultClientOptions(); ClientOptions = ClientOptions.Clone(); if (ServerOptions.ParentProcess_ID == null) { ServerOptions.ParentProcess_ID = System.Diagnostics.Process.GetCurrentProcess().Id; } var Process = StartProcess(ServerOptions); var Provider = ProtocolProvider.GetProvider(ServerOptions.ListenOn_Provider); var ret = await Provider.ConnectAsync <IOutOfProcessController>(ServerOptions.ToEndpoint(), ClientOptions) .DefaultAwait() ; return(ret); }
void ProtocolStatesViewerSelectionChanged(object sender, EventArgs e) { object selectedObject = ProtocolStatesViewer.SelectedObject; if (selectedObject != null) { if (selectedObject is Edge) { Edge SelectedEdge = selectedObject as Edge; } else if (selectedObject is Node) { Node SelectedNode = selectedObject as Node; string DescriptionAttribute = ProtocolProvider.GetStateDescription(ProtocolProvider.GetStatePlugInByDesplayName(SelectedNode.Id, UserControlProtocolType)); ProtocolStatesViewer.SetToolTip(new ToolTip(), DescriptionAttribute); } } //here you can use e.Attr.Id to get back to your data //this.gViewer.SetToolTip(toolTip1, String.Format("node {0}", (selectedObject as Node).Attr.Id)); ProtocolStatesViewer.Invalidate(); }
public ProtocolParametersForm(ProtocolUserControl ParentProtocolUserControl, Type ProtocolData) : this(ParentProtocolUserControl, ProtocolProvider.GetProtocolParameters(ProtocolData)) { }
public ProtocolParametersForm(ProtocolUserControl ParentProtocolUserControl, ProtocolParameters ProtocolParameters) : this() { this.ParentProtocolUserControl = ParentProtocolUserControl; this.FormProtocolParameters = ProtocolParameters; ProtocolParametersFields = ProtocolProvider.GetProtocolParametersFields(FormProtocolParameters); }
public ProtocolManager() { protocolProvider = new ProtocolProvider(); }
public ChatNetworkServer(PacChatServer server, ProtocolProvider protocolProvider, CountdownLatch latch) { this.Server = server; this.protocolProvider = protocolProvider; this.latch = latch; }
public ChatServer(PacChatServer server, ProtocolProvider protocolProvider, CountdownLatch latch) : base(server, protocolProvider, latch) { this.bootstrap.ChildHandler(new ChannelInitializer(this)); }
private void PingTimer_Elapsed(object sender, ElapsedEventArgs e) { lock (_receivedAckLock) { if (!ReceivedAck && ActiveNode != null) { Debug.WriteLine($"No direct response from Node {ActiveNode.Endpoint}"); Logger.LogInformation($"No direct response from Node {ActiveNode.Endpoint}"); lock (_nodesLock) { if (Nodes.Count >= 1) { // Select k num of nodes. RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider(); // Get four random bytes. byte[] four_bytes = new byte[4]; provider.GetBytes(four_bytes); // Convert that into an uint. int num = BitConverter.ToInt32(four_bytes, 0); num = num < 0 ? num * -1 : num; int k = 1 + (num % Math.Min(Nodes.Count, 8)); // Create list of node candidates, remove active node. var candidates = Nodes.ToList(); candidates.Remove(ActiveNode); // Shuffle candidates candidates.Shuffle(); // Select k nodes var nodesToPingReq = candidates.Take(k); if (!nodesToPingReq.Any()) { Debug.WriteLine("No nodes to select from"); Logger.LogInformation("No nodes to select from"); } foreach (var node in nodesToPingReq) { Debug.WriteLine($"Sending pingreq for {ActiveNode.Endpoint} to {node.Endpoint}"); Logger.LogInformation($"Sending pingreq for {ActiveNode.Endpoint} to {node.Endpoint}"); ProtocolProvider.SendMessage(node, new PingReqMessage(PingCorrelationId.Value, ActiveNode, ProtocolProvider.Node)); } } } } else if (ReceivedAck && ActiveNode != null) { Debug.WriteLine($"Node {ActiveNode.Endpoint} responded with Ack, marking as alive"); Logger.LogInformation($"Node {ActiveNode.Endpoint} responded with Ack, marking as alive"); } } PingTimer.Stop(); }
public ClientSession(IChannel channel, ProtocolProvider protocolProvider) : base(channel, protocolProvider.Test) { this.protocolProvider = protocolProvider; }
private void HandleMessage(MessageBase message) { Debug.WriteLine($"Processing {message.MessageType} Message from {message.SourceNode?.Endpoint ?? "unidentified node"}"); Logger.LogInformation($"Processing {message.MessageType} Message from {message.SourceNode?.Endpoint ?? "unidentified node"}"); try { switch (message.MessageType) { case MessageType.Composite: { var cm = message as CompositeMessage; if (cm.Messages != null) { foreach (var em in cm.Messages) { HandleMessage(em); } } } break; case MessageType.Alive: { lock (_nodesLock) { if (!Nodes.Any(x => x == message.SourceNode)) { AddNode(message.SourceNode); } } AddBroadcastMessage(message); } break; case MessageType.Dead: { lock (_nodesLock) { if (Nodes.Any(x => x == message.SourceNode)) { RemoveNode(message.SourceNode); } } AddBroadcastMessage(message); } break; case MessageType.Ping: { lock (_nodesLock) { if (!Nodes.Any(x => x == message.SourceNode)) { AddNode(message.SourceNode); } } if (message.SourceNode != null && ProtocolProvider?.Node?.Endpoint != null) { ProtocolProvider.SendMessage(message.SourceNode, new AckMessage(message.CorrelationId, ProtocolProvider.Node)); } } break; case MessageType.Ack: { if (message.SourceNode == ActiveNode) { lock (_receivedAckLock) { ReceivedAck = true; } } if (message.CorrelationId.HasValue) { MessageBase ms = null; // Send message back to originating node. if (CorrelatedMessages.TryRemove(message.CorrelationId.Value, out ms)) { var cm = ms as PingReqMessage; ProtocolProvider.SendMessage(cm.SourceNode, message); } } } break; case MessageType.PingReq: { var m = message as PingReqMessage; if (m.CorrelationId.HasValue) { CorrelatedMessages.TryAdd(m.CorrelationId.Value, m); } ProtocolProvider.SendMessage(m.Endpoint, new PingMessage(m.CorrelationId.Value) { SourceNode = ProtocolProvider.Node }); } break; default: Debug.WriteLine($"Unknown message type {message.MessageType}, skipping..."); Logger.LogWarning($"Unknown message type {message.MessageType}, skipping..."); break; } } catch (Exception e) { Debug.WriteLine($"{e.ToString()}: {e.StackTrace}"); Logger.LogError(e, string.Empty); } }