Esempio n. 1
0
        // \Client Context Section


        /// <summary>
        /// Creates the instance for a new TCP server client.
        /// </summary>
        /// <param name="Server">Role server that the client connected to.</param>
        /// <param name="TcpClient">TCP client class that holds the connection and allows communication with the client.</param>
        /// <param name="Id">Unique identifier of the client's connection.</param>
        /// <param name="UseTls">true if the client is connected to the TLS port, false otherwise.</param>
        /// <param name="KeepAliveIntervalMs">Number of seconds for the connection to this client to be without any message until the profile server can close it for inactivity.</param>
        /// <param name="LogPrefix">Prefix for log entries created by the client.</param>
        public IncomingClient(TcpRoleServer <IncomingClient> Server, TcpClient TcpClient, ulong Id, bool UseTls, int KeepAliveIntervalMs, string LogPrefix) :
            base(TcpClient, new PsMessageProcessor(Server, LogPrefix), Id, UseTls, KeepAliveIntervalMs, Server.IdBase, Server.ShutdownSignaling, LogPrefix)
        {
            this.Id = Id;
            log     = new Logger("ProfileServer.Network.IncomingClient", LogPrefix);

            log.Trace("(UseTls:{0},KeepAliveIntervalMs:{1})", UseTls, KeepAliveIntervalMs);

            messageBuilder = new PsMessageBuilder(Server.IdBase, new List <SemVer>()
            {
                SemVer.V100
            }, Config.Configuration.Keys);
            this.KeepAliveIntervalMs = KeepAliveIntervalMs;
            NextKeepAliveTime        = DateTime.UtcNow.AddMilliseconds(this.KeepAliveIntervalMs);

            ConversationStatus = ClientConversationStatus.NoConversation;

            ApplicationServices = new ApplicationServices(LogPrefix);

            log.Trace("(-)");
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the instance for a new TCP server client.
        /// </summary>
        /// <param name="Server">Role server that the client connected to.</param>
        /// <param name="TcpClient">TCP client class that holds the connection and allows communication with the client.</param>
        /// <param name="Id">Unique identifier of the client's connection.</param>
        /// <param name="UseTls">true if the client is connected to the TLS port, false otherwise.</param>
        /// <param name="KeepAliveIntervalSeconds">Number of seconds for the connection to this client to be without any message until the profile server can close it for inactivity.</param>
        public IncomingClient(TcpRoleServer Server, TcpClient TcpClient, ulong Id, bool UseTls, int KeepAliveIntervalSeconds) :
            base(TcpClient, UseTls, Server.IdBase)
        {
            this.Id = Id;
            server  = Server;
            string logPrefix = string.Format("[{0}<=>{1}|{2}] ", server.EndPoint, RemoteEndPoint, Id.ToHex());
            string logName   = "ProfileServer.Network.IncomingClient";

            log = new PrefixLogger(logName, logPrefix);

            log.Trace("(UseTls:{0},KeepAliveIntervalSeconds:{1})", UseTls, KeepAliveIntervalSeconds);

            messageProcessor = new MessageProcessor(server, logPrefix);

            this.KeepAliveIntervalSeconds = KeepAliveIntervalSeconds;
            NextKeepAliveTime             = DateTime.UtcNow.AddSeconds(this.KeepAliveIntervalSeconds);

            ConversationStatus   = ClientConversationStatus.NoConversation;
            IsOurCheckedInClient = false;

            ApplicationServices = new ApplicationServices(logPrefix);

            log.Trace("(-)");
        }
Esempio n. 3
0
        public override bool Init()
        {
            log.Info("()");

            bool res   = false;
            bool error = false;

            try
            {
                serverId   = ProfileServerCrypto.Crypto.Sha256(Base.Configuration.Keys.PublicKey);
                clientList = new IncomingClientList();

                foreach (RoleServerConfiguration roleServer in Base.Configuration.ServerRoles.RoleServers.Values)
                {
                    if (roleServer.IsTcpServer)
                    {
                        IPEndPoint    endPoint = new IPEndPoint(Base.Configuration.ServerInterface, roleServer.Port);
                        TcpRoleServer server   = new TcpRoleServer(endPoint, roleServer.Encrypted, roleServer.Roles);
                        tcpServers.Add(server.EndPoint.Port, server);
                    }
                    else
                    {
                        log.Fatal("UDP servers are not supported.");
                        error = true;
                        break;
                    }
                }


                foreach (TcpRoleServer server in tcpServers.Values)
                {
                    if (!server.Start())
                    {
                        log.Error("Unable to start TCP server {0}.", server.EndPoint);
                        error = true;
                        break;
                    }
                }

                if (!error)
                {
                    res         = true;
                    Initialized = true;
                }
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }

            if (!res)
            {
                ShutdownSignaling.SignalShutdown();

                foreach (TcpRoleServer server in tcpServers.Values)
                {
                    if (server.IsRunning)
                    {
                        server.Stop();
                    }
                }
                tcpServers.Clear();
            }

            log.Info("(-):{0}", res);
            return(res);
        }