public void Test1() { Logger.Console.Verbose = VerboseLevel.All; var netStream = new NetworkStreamSimulator(); var dbcfg = new HistorianServerDatabaseConfig("DB", @"C:\Archive", true); var server = new HistorianServer(dbcfg); var auth = new SecureStreamServer<SocketUserPermissions>(); auth.SetDefaultUser(true, new SocketUserPermissions() { CanRead = true, CanWrite = true, IsAdmin = true }); var netServer = new SnapStreamingServer(auth, netStream.ServerStream, server.Host); ThreadPool.QueueUserWorkItem(ProcessClient, netServer); var client = new SnapStreamingClient(netStream.ClientStream, new SecureStreamClientDefault(), true); var db = client.GetDatabase("DB"); client.Dispose(); server.Dispose(); }
public void Test2() { Logger.Console.Verbose = VerboseLevel.All; var netStream = new NetworkStreamSimulator(); var dbcfg = new HistorianServerDatabaseConfig("DB", @"C:\Archive", true); var server = new HistorianServer(dbcfg); var auth = new SecureStreamServer <SocketUserPermissions>(); auth.SetDefaultUser(true, new SocketUserPermissions() { CanRead = true, CanWrite = true, IsAdmin = true }); var netServer = new SnapStreamingServer(auth, netStream.ServerStream, server.Host); ThreadPool.QueueUserWorkItem(ProcessClient, netServer); var client = new SnapStreamingClient(netStream.ClientStream, new SecureStreamClientDefault(), true); var db = client.GetDatabase <HistorianKey, HistorianValue>("DB"); long len = db.Read().Count(); System.Console.WriteLine(len); client.Dispose(); server.Dispose(); }
public void Test1() { Logger.Console.Verbose = VerboseLevel.All; NetworkStreamSimulator netStream = new NetworkStreamSimulator(); HistorianServerDatabaseConfig dbcfg = new HistorianServerDatabaseConfig("DB", @"C:\Archive", true); HistorianServer server = new HistorianServer(dbcfg); SecureStreamServer <SocketUserPermissions> auth = new SecureStreamServer <SocketUserPermissions>(); auth.SetDefaultUser(true, new SocketUserPermissions() { CanRead = true, CanWrite = true, IsAdmin = true }); SnapStreamingServer netServer = new SnapStreamingServer(auth, netStream.ServerStream, server.Host); ThreadPool.QueueUserWorkItem(ProcessClient, netServer); SnapStreamingClient client = new SnapStreamingClient(netStream.ClientStream, new SecureStreamClientDefault(), true); ClientDatabaseBase db = client.GetDatabase("DB"); client.Dispose(); server.Dispose(); }
/// <summary> /// Creates a <see cref="SnapSocketListener"/> /// </summary> /// <param name="settings"></param> /// <param name="server"></param> /// <param name="parent"></param> public SnapSocketListener(SnapSocketListenerSettings settings, SnapServer server) : base(MessageClass.Framework) { if ((object)server == null) { throw new ArgumentNullException("server"); } if ((object)settings == null) { throw new ArgumentNullException("settings"); } m_server = server; m_settings = settings.CloneReadonly(); m_settings.Validate(); m_authenticator = new SecureStreamServer <SocketUserPermissions>(); if (settings.DefaultUserCanRead || settings.DefaultUserCanWrite || settings.DefaultUserIsAdmin) { m_authenticator.SetDefaultUser(true, new SocketUserPermissions() { CanRead = settings.DefaultUserCanRead, CanWrite = settings.DefaultUserCanWrite, IsAdmin = settings.DefaultUserIsAdmin }); } foreach (var user in settings.Users) { m_authenticator.AddUserIntegratedSecurity(user, new SocketUserPermissions() { CanRead = true, CanWrite = true, IsAdmin = true }); } // TODO: Shouldn't we use GSF.Communications async library here for scalability? If not, why not? // TODO: I think async communication classes could pass NetworkBinaryStream to a handler like ProcessClient... // TODO: Communications library may need a simple modification... Check with S. Wills for thoughts here... m_isRunning = true; m_listener = new TcpListener(m_settings.LocalEndPoint); //m_listener.Server.DualMode = true; m_listener.Start(); //var socket = m_listener.AcceptSocketAsync(); //socket.ContinueWith(ProcessDataRequests); //socket.Start(); Log.Publish(MessageLevel.Info, "Constructor Called", "Listening on " + m_settings.LocalEndPoint.ToString()); Thread th = new Thread(ProcessDataRequests); th.IsBackground = true; th.Start(); }
/// <summary> /// Creates a <see cref="SnapSocketListener"/> /// </summary> /// <param name="settings"></param> /// <param name="server"></param> /// <param name="parent"></param> public SnapSocketListener(SnapSocketListenerSettings settings, SnapServer server) : base(MessageClass.Framework) { if ((object)server == null) { throw new ArgumentNullException(nameof(server)); } if ((object)settings == null) { throw new ArgumentNullException(nameof(settings)); } m_server = server; m_settings = settings.CloneReadonly(); m_settings.Validate(); m_authenticator = new SecureStreamServer <SocketUserPermissions>(); if (settings.DefaultUserCanRead || settings.DefaultUserCanWrite || settings.DefaultUserIsAdmin) { m_authenticator.SetDefaultUser(true, new SocketUserPermissions { CanRead = settings.DefaultUserCanRead, CanWrite = settings.DefaultUserCanWrite, IsAdmin = settings.DefaultUserIsAdmin }); } foreach (string user in settings.Users) { m_authenticator.AddUserIntegratedSecurity(user, new SocketUserPermissions { CanRead = true, CanWrite = true, IsAdmin = true }); } m_isRunning = true; m_listener = new TcpListener(m_settings.LocalEndPoint); m_listener.Server.DualMode = m_settings.LocalEndPoint.AddressFamily == AddressFamily.InterNetworkV6; m_listener.Start(); Log.Publish(MessageLevel.Info, "Constructor Called", $"Listening on {m_settings.LocalEndPoint}"); new Thread(ProcessDataRequests) { IsBackground = true }.Start(); }
/// <summary> /// Creates a <see cref="SnapSocketListener"/> /// </summary> /// <param name="settings"></param> /// <param name="server"></param> /// <param name="parent"></param> public SnapSocketListener(SnapSocketListenerSettings settings, SnapServer server) : base(MessageClass.Framework) { if ((object)server == null) throw new ArgumentNullException("server"); if ((object)settings == null) throw new ArgumentNullException("settings"); m_server = server; m_settings = settings.CloneReadonly(); m_settings.Validate(); m_authenticator = new SecureStreamServer<SocketUserPermissions>(); if (settings.DefaultUserCanRead || settings.DefaultUserCanWrite || settings.DefaultUserIsAdmin) { m_authenticator.SetDefaultUser(true, new SocketUserPermissions() { CanRead = settings.DefaultUserCanRead, CanWrite = settings.DefaultUserCanWrite, IsAdmin = settings.DefaultUserIsAdmin }); } foreach (var user in settings.Users) { m_authenticator.AddUserIntegratedSecurity(user, new SocketUserPermissions() { CanRead = true, CanWrite = true, IsAdmin = true }); } // TODO: Shouldn't we use GSF.Communications async library here for scalability? If not, why not? // TODO: I think async communication classes could pass NetworkBinaryStream to a handler like ProcessClient... // TODO: Communications library may need a simple modification... Check with S. Wills for thoughts here... m_isRunning = true; m_listener = new TcpListener(m_settings.LocalEndPoint); //m_listener.Server.DualMode = true; m_listener.Start(); //var socket = m_listener.AcceptSocketAsync(); //socket.ContinueWith(ProcessDataRequests); //socket.Start(); Log.Publish(MessageLevel.Info, "Constructor Called", "Listening on " + m_settings.LocalEndPoint.ToString()); Thread th = new Thread(ProcessDataRequests); th.IsBackground = true; th.Start(); }
public void TestWriteServer() { HistorianKey key = new HistorianKey(); HistorianValue value = new HistorianValue(); Logger.Console.Verbose = VerboseLevel.All; Logger.FileWriter.SetPath(@"C:\Temp\", VerboseLevel.All); var netStream = new NetworkStreamSimulator(); var dbcfg = new HistorianServerDatabaseConfig("DB", @"C:\Temp\Scada", true); var server = new HistorianServer(dbcfg); var auth = new SecureStreamServer <SocketUserPermissions>(); auth.SetDefaultUser(true, new SocketUserPermissions() { CanRead = true, CanWrite = true, IsAdmin = true }); var netServer = new SnapStreamingServer(auth, netStream.ServerStream, server.Host); ThreadPool.QueueUserWorkItem(ProcessClient, netServer); var client = new SnapStreamingClient(netStream.ClientStream, new SecureStreamClientDefault(), false); var db = client.GetDatabase <HistorianKey, HistorianValue>("DB"); for (uint x = 0; x < 1000; x++) { key.Timestamp = x; db.Write(key, value); break; } client.Dispose(); server.Dispose(); }
public void TestDefault() { Logger.Console.Verbose = VerboseLevel.All; m_sw.Reset(); var net = new NetworkStreamSimulator(); var sa = new SecureStreamServer<NullToken>(); sa.SetDefaultUser(true, new NullToken()); ThreadPool.QueueUserWorkItem(ClientDefault, net.ClientStream); Stream stream; if (!sa.TryAuthenticateAsServer(net.ServerStream, true, out stream, out T)) { throw new Exception(); } stream.Write("Message"); stream.Flush(); if (stream.ReadString() != "Response") throw new Exception(); stream.Dispose(); Thread.Sleep(100); }
public void TestWriteServer() { HistorianKey key = new HistorianKey(); HistorianValue value = new HistorianValue(); Logger.Console.Verbose = VerboseLevel.All; Logger.FileWriter.SetPath(@"C:\Temp\", VerboseLevel.All); var netStream = new NetworkStreamSimulator(); var dbcfg = new HistorianServerDatabaseConfig("DB", @"C:\Temp\Scada", true); var server = new HistorianServer(dbcfg); var auth = new SecureStreamServer<SocketUserPermissions>(); auth.SetDefaultUser(true, new SocketUserPermissions() { CanRead = true, CanWrite = true, IsAdmin = true }); var netServer = new SnapStreamingServer(auth, netStream.ServerStream, server.Host); ThreadPool.QueueUserWorkItem(ProcessClient, netServer); var client = new SnapStreamingClient(netStream.ClientStream, new SecureStreamClientDefault(), false); var db = client.GetDatabase<HistorianKey, HistorianValue>("DB"); for (uint x = 0; x < 1000; x++) { key.Timestamp = x; db.Write(key, value); break; } client.Dispose(); server.Dispose(); }
public void TestBenchmarkDefault() { Logger.Console.Verbose = VerboseLevel.All; m_sw.Reset(); var net = new NetworkStreamSimulator(); var sa = new SecureStreamServer<NullToken>(); sa.SetDefaultUser(true, new NullToken()); ThreadPool.QueueUserWorkItem(ClientBenchmarkDefault, net.ClientStream); Stream stream; sa.TryAuthenticateAsServer(net.ServerStream, false, out stream, out T); sa.TryAuthenticateAsServer(net.ServerStream, true, out stream, out T); sa.TryAuthenticateAsServer(net.ServerStream, false, out stream, out T); sa.TryAuthenticateAsServer(net.ServerStream, true, out stream, out T); sa.TryAuthenticateAsServer(net.ServerStream, false, out stream, out T); Thread.Sleep(100); }