Exemple #1
0
        /// <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 TestBenchmarkIntegrated()
        {
            return;
            Logger.Console.Verbose = VerboseLevel.All;
            m_sw.Reset();

            var net = new NetworkStreamSimulator();

            var sa = new SecureStreamServer<NullToken>();
            sa.AddUserIntegratedSecurity("Zthe\\steven", new NullToken());
            ThreadPool.QueueUserWorkItem(ClientBenchmarkIntegrated, net.ClientStream);

            Stream stream;
            sa.TryAuthenticateAsServer(net.ServerStream, true, out stream, out T);
            sa.TryAuthenticateAsServer(net.ServerStream, true, out stream, out T);
            sa.TryAuthenticateAsServer(net.ServerStream, true, out stream, out T);
            sa.TryAuthenticateAsServer(net.ServerStream, true, out stream, out T);
            sa.TryAuthenticateAsServer(net.ServerStream, true, out stream, out T);

            Thread.Sleep(100);
        }