/// <summary> /// Runs the creation mutation /// </summary> /// <param name="connection">The connection</param> /// <param name="request">The request</param> /// <param name="field"> /// The connection field /// </param> /// <param name="context"> /// The context. /// </param> /// <param name="argumentsSerializer"> /// The arguments serializer. /// </param> /// <param name="onErrorCallback"> /// The on error callback. /// </param> /// <returns>The resolved data</returns> private async Task <JObject> MutationCreate( INodeConnection <T> connection, ApiRequest request, ApiField field, RequestContext context, JsonSerializer argumentsSerializer, Action <Exception> onErrorCallback) { var serializedData = ((JObject)request.Arguments)?.Property("newNode")?.Value as JObject; var newNode = serializedData?.ToObject <T>(); var result = await connection.Create(newNode); var mutationCreate = (JObject) await mutationResultResolver.ResolveQuery( result, request, field, context, argumentsSerializer, onErrorCallback); SetLog(request, field, context, EnConnectionAction.Create); return(mutationCreate); }
public void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { if (e.Session.Authentication != AuthenticationType.security && e.Message is Authentication) { Authentication authentication = (Authentication)e.Message; if (!authentication.Token.VerifyMd5Hash(authentication.NodeID + TokenKey)) { Loger.Process(LogType.ERROR, "[{0}] node from {1} authentication error", authentication.NodeID, e.Session.RemoteEndPoint); e.Session.Dispose(); } else { e.Session.Authentication = AuthenticationType.security; Loger.Process(LogType.INFO, "[{0}] node from {1} authentication success", authentication.NodeID, e.Session.RemoteEndPoint); mRemoteNodeSessions[authentication.NodeID] = e.Session; e.Session["NODEID"] = authentication.NodeID; INodeConnection connection = mRemoteNodeCenter.Get(authentication.NodeID); if (connection != null) { connection.SyncSubscriber(); } } return; } if (e.Session.Authentication != AuthenticationType.security) { Loger.Process(LogType.ERROR, "[{0}] session authentication error", e.Session.RemoteEndPoint); e.Session.Dispose(); } else { ProcessMessage(server, e.Session, e.Message); } }
private void OnDiscoverNode(object sender, NodeBroadcastListen.DiscoverEventArgs e) { Loger.Process(LogType.INFO, "discovery node [{0}] from {1}@{2}", e.NodeID, e.Address, e.Port); INodeConnection connecter = mRemoteNodeCenter.Register(this, e.NodeID, e.Address, e.Port); // new SmartRoute.NodeConnecter(this, e.NodeID, e.Address, e.Port); connecter.Receive = OnRemoteNodeReceive; connecter.Connect(); }
private void network_ReceivedCriticalError(INodeConnection ErrorFrom, MeshworkError error) { try { UpdateConnectionList(); } catch (Exception ex) { LoggingService.LogError(ex); Gui.ShowErrorDialog(ex.ToString(), Gui.MainWindow.Window); } }
private void network_ConnectionDown(INodeConnection c) { try { UpdateConnectionList(); } catch (Exception ex) { LoggingService.LogError(ex); Gui.ShowErrorDialog(ex.ToString(), Gui.MainWindow.Window); } }
public Message CreateAuthMessage(INodeConnection connection, TrustedNodeInfo messageTo) { Message p = new Message(network, MessageType.Auth); p.To = messageTo.NodeID; AuthInfo c = new AuthInfo(); c.ProtocolVersion = Core.ProtocolVersion; c.NetworkName = network.NetworkName; c.NickName = network.LocalNode.NickName; p.Content = c; return p; }
private void OnRemoteNodeReceive(INodeConnection connecter, object message) { if (message is GetSubscribersResponse) { GetSubscribersResponse response = (GetSubscribersResponse)message; RegisterRemoteSubscribers(response.NodeID, response.Subscribers); Loger.Process(LogType.INFO, "sync remote subscribers from [{0}]", response.NodeID); } else if (message is Message) { Publish((Message)message); } }
public Message CreateAuthMessage(INodeConnection connection, TrustedNodeInfo messageTo) { Message p = new Message(network, MessageType.Auth); p.To = messageTo.NodeID; AuthInfo c = new AuthInfo(); c.ProtocolVersion = Core.ProtocolVersion; c.NetworkName = network.NetworkName; c.NickName = network.LocalNode.NickName; p.Content = c; return(p); }
internal void ProcessConnectionDownMessage(Node messageFrom, ConnectionInfo info) { INodeConnection c = network.FindConnection(info.SourceNodeID, info.DestNodeID); if (c != null) { network.RemoveConnection(c); } else { Core.LoggingService.LogWarning("MessageProcessor: ConnectionDown received from {0} for a non-existant connection!", messageFrom); } network.Cleanup(); }
public bool TryConnect(IConnector connectorOne, IConnector connectorTwo, out INodeConnection connection) { if (connectorOne.ConnectorType is ConnectorType.Output && connectorTwo.ConnectorType is ConnectorType.Input) { return(TryMakeConnector(connectorOne, connectorTwo, out connection)); } if (connectorTwo.ConnectorType is ConnectorType.Input && connectorTwo.ConnectorType is ConnectorType.Output) { return(TryMakeConnector(connectorTwo, connectorOne, out connection)); } connection = default; return(false); }
private void RegisterRemoteSubscribers(string remoteNode, params string[] names) { if (names == null) { return; } foreach (string name in names) { if (mIsLinux) { ISession session = GetNodeSession(remoteNode); ISubscriber subscriber = null; if (session != null) { subscriber = new SessionSubscriber(this, name, session); mRemoteSubscriberCenter.Register(name, subscriber); Loger.Process(LogType.DEBUG, "remote {0} registed to SessionSubscriber", name); OnSubscriberRegisted(subscriber); } else { INodeConnection connection = mRemoteNodeCenter.Get(remoteNode); if (connection != null) { subscriber = new RemoteNodeSubscriber(name, this, connection); mRemoteSubscriberCenter.Register(name, subscriber); Loger.Process(LogType.DEBUG, "remote {0} registed to RemoteNodeSubscriber", name); OnSubscriberRegisted(subscriber); } } } else { ISubscriber subscriber = null; INodeConnection connection = mRemoteNodeCenter.Get(remoteNode); if (connection != null) { subscriber = new RemoteNodeSubscriber(name, this, connection); mRemoteSubscriberCenter.Register(name, subscriber); Loger.Process(LogType.DEBUG, "remote {0} registed to RemoteNodeSubscriber", name); OnSubscriberRegisted(subscriber); } } } }
public static int Main(string[] args) { // hook API logger Logger.SetLogSink(HandleLogEntry); try { // in most cases this would just be localhost, but I'm actually connecting to a remote node string hostname = "JoshVM-XP"; int port = 80; // we use INodeConnection here because this node does not have to be (and probably is not) the NC Console.WriteLine("Connecting to node..."); using (INodeConnection conn = CSAPI.Create().CreateNodeConnection(hostname, port)) { // pull the data local to this node (part of which are the node attributes) Console.Write("Retrieving node data..."); using (var result = conn.LocalData.ReadNodeData()) { if (result.IsSuccess) { Console.WriteLine("success, {0} node attributes found", result.Value.Attributes.Count); foreach (string attrName in result.Value.Attributes.Keys) { Console.WriteLine(" NodeAttribute {{ Name = \"{0}\", Value = \"{1}\" }}", attrName, result.Value.Attributes[attrName]); } } else { Console.WriteLine("failed: " + result.ToString()); return(-1); } } } return(0); } finally { // unhook API logger Logger.SetLogSink(null); } }
/// <summary> /// Runs the creation mutation /// </summary> /// <param name="connection">The connection</param> /// <param name="request">The request</param> /// <param name="field"> /// The connection field /// </param> /// <param name="context"> /// The context. /// </param> /// <param name="argumentsSerializer"> /// The arguments serializer. /// </param> /// <param name="onErrorCallback"> /// The on error callback. /// </param> /// <returns>The resolved data</returns> private async Task <JObject> MutationUpdate( INodeConnection <T> connection, ApiRequest request, ApiField field, RequestContext context, JsonSerializer argumentsSerializer, Action <Exception> onErrorCallback) { var serializedData = ((JObject)request.Arguments)?.Property("newNode")?.Value as JObject; var serializedId = ((JObject)request.Arguments)?.Property("id")?.Value; var id = serializedId?.ToObject(NodeMetaData.KeyProperty.PropertyType); if (id == null) { return(null); } var newNode = serializedData?.ToObject <T>(); var result = await connection.Update(id, newNode, request); var mutationUpdate = (JObject) await mutationResultResolver.ResolveQuery( result, request, field, context, argumentsSerializer, onErrorCallback); if (result.Result != null) { if (!id.Equals(GetIdValue(result.Result))) { mutationUpdate.Add("__deletedId", JToken.FromObject(id)); } } SetLog(request, field, context, EnConnectionAction.Update); return(mutationUpdate); }
private void RegisterRemoteSubscribers(string remoteNode, params string[] names) { foreach (string name in names) { if (mIsLinux) { ISession session = GetNodeSession(remoteNode); ISubscriber subscriber = null; if (session != null) { subscriber = new SessionSubscriber(this, name, session); mRemoteSubscriberCenter.Register(name, subscriber); OnSubscriberRegisted(subscriber); } else { INodeConnection connection = mRemoteNodeCenter.Get(remoteNode); if (connection != null) { subscriber = new RemoteNodeSubscriber(name, this, connection); mRemoteSubscriberCenter.Register(name, subscriber); OnSubscriberRegisted(subscriber); } } } else { ISubscriber subscriber = null; INodeConnection connection = mRemoteNodeCenter.Get(remoteNode); if (connection != null) { subscriber = new RemoteNodeSubscriber(name, this, connection); mRemoteSubscriberCenter.Register(name, subscriber); OnSubscriberRegisted(subscriber); } } } }
private void OnPingRemoteNode(object state) { ICollection <INodeConnection> onlines = mRemoteNodeCenter.GetOnlines(); foreach (INodeConnection item in onlines) { if (item.PingCount > 5) { INodeConnection result = mRemoteNodeCenter.UnRegister(item.RemoteNodeID); mBroadcastListen.Remove(item.RemoteNodeID); item.Dispose(); Loger.Process(LogType.INFO, "remove node [{0}]", item.RemoteNodeID); } else { item.Ping(); ISession session; if (this.mRemoteNodeSessions.TryGetValue(item.RemoteNodeID, out session)) { item.SyncSubscriber(); } } } }
public RemoteNodeSubscriber(string name, INode node, INodeConnection remoteConnection) { Node = node; Name = name; mConnection = remoteConnection; }
// XXX : Move this internal void SendAuthReply(INodeConnection connection, Node node) { this.SendRoutedMessage(this.MessageBuilder.CreateAuthReplyMessage(connection, this.TrustedNodes[node.NodeID])); }
internal void AddConnection(INodeConnection connection) { lock (connections) connections.Add(connection); if (connection is LocalNodeConnection) { var localConnection = (LocalNodeConnection)connection; if (localConnection.Incoming) { LoggingService.LogInfo("New incoming connection from {0}.", localConnection.RemoteAddress); if (NewIncomingConnection != null) NewIncomingConnection(this, localConnection); } else { LoggingService.LogInfo("New outgoing connection to {0}.", localConnection.RemoteAddress); if (ConnectingTo != null) ConnectingTo(this, localConnection); } } else if (connection is RemoteNodeConnection) { LoggingService.LogInfo("Added new connection between {0} and {1}.", connection.NodeLocal.NickName, connection.NodeRemote.NickName); if (ConnectionUp != null) ConnectionUp(connection); } }
private static bool TryMakeConnector(IConnector outputConnector, IConnector inputConnector, out INodeConnection successfulConnection) { if (outputConnector.CanConnectTo(inputConnector)) { INodeConnection connection = new NodeConnection(outputConnector, inputConnector); outputConnector.AddConnection(connection); inputConnector.AddConnection(connection); successfulConnection = connection; return(true); } successfulConnection = default; return(false); }
private void network_ConnectionUp(INodeConnection c) { try { UpdateConnectionList(); } catch (Exception ex) { LoggingService.LogError(ex); Gui.ShowErrorDialog (ex.ToString(), Gui.MainWindow.Window); } }
public static int Main(string[] args) { Logger.SetLogSink(HandleLogEntry); try { CSAPI api = CSAPI.Create(); // first create a node connection directly to the node whose local data store we want to modify using (INodeConnection tnConn = api.CreateNodeConnection(HOST, PORT)) { // we need a local session context to use the local data table apis Console.Write("Establishing local session with node..."); using (var result = tnConn.CreateLocalSession()) { if (result.IsSuccess) { Console.WriteLine("success"); } else { Console.WriteLine("failed: " + result.ToString()); return(1001); } } // we need to figure out if the table already exists in the local store or not, so we'll try to read it from there first bool isAlreadyInLocalStore; Console.Write("Reading table from local data store..."); using (var result = tnConn.LocalData.ReadLocalDataTable(TABLE_ID)) { if (result.IsSuccess) { Console.WriteLine("found it"); isAlreadyInLocalStore = true; } else if (result.ErrorType == CommandErrorType.ServerError && result.ServerErrorCode == ServerErrorType.ObjectNotFound) { Console.WriteLine("doesn't exist"); isAlreadyInLocalStore = false; } else { Console.WriteLine("failed: " + result.ToString()); return(1002); } } // this is the object which will contain all the changes we're going to make to the table IDataTableChangeSet changes = tnConn.LocalData.CreateDataTableChangeSet(); // if the table does not yet exist in the local store, then we must save the schema with the update; if it does already exist then we can just update rows if (!isAlreadyInLocalStore) { // what is the schema? we'll pull it from the network cached version of the table (the one downloaded from the parent node) // for this to work, the table would need to be associated with the node in some way. E.g. if it were bound to a content in the schedule of this node, or one if this node's descendants. Console.Write("Reading table from network cache..."); using (var result = tnConn.LocalData.ReadCachedDataTable(TABLE_ID)) { if (result.IsSuccess) { Console.WriteLine("found it"); IDataTable networkCopy = result.Value; // add the table & fields to our local store changes changes.UpdateTable(networkCopy); foreach (IDataTableField field in networkCopy.DataTableDesigns.Items.First().DataTableFields.Items) { changes.UpdateField(field); } } else if (result.ErrorType == CommandErrorType.ServerError && result.ServerErrorCode == ServerErrorType.ObjectNotFound) { Console.WriteLine("doesn't exist, aborting"); return(1003); } else { Console.WriteLine("failed: " + result.ToString()); return(1004); } } } // first delete all existing rows, you may not want to do this if you're appending a row changes.DeleteAllRows(); // now add the new row IDataRow row = tnConn.ModelFactory.CreateDataRow(); row.ActivationDate = new DateTime(1600, 1, 1); row.ExpirationDate = new DateTime(3000, 1, 1); row.SequenceNumber = 0; row.Values[FIELD_1] = "some value"; changes.UpdateRow(row); // save changes into local store Console.Write("Updating table in local store..."); using (var result = tnConn.LocalData.UpdateLocalDataTable(TABLE_ID, changes, false)) { if (result.IsSuccess) { Console.WriteLine("success"); } else { Console.WriteLine("failed: " + result.ToString()); return(1005); } } } } finally { Console.WriteLine("Press enter to exit"); Console.ReadLine(); Logger.SetLogSink(null); } return(0); }
private void network_ReceivedCriticalError(INodeConnection ErrorFrom, MeshworkError error) { try { UpdateConnectionList(); } catch (Exception ex) { LoggingService.LogError(ex); Gui.ShowErrorDialog (ex.ToString(), Gui.MainWindow.Window); } }
internal void RemoveConnection(INodeConnection connection) { lock (connections) connections.Remove(connection); if (connection is RemoteNodeConnection) { LoggingService.LogInfo("Removed connection between {0} and {1}.", connection.NodeLocal.NickName, connection.NodeRemote.NickName); if (ConnectionDown != null) ConnectionDown(connection); } }