Exemplo n.º 1
0
Arquivo: Hub.cs Projeto: radtek/BackO
        internal void Run()
        {
            if (running)
            {
                throw new Exception("Already running");
            }
            int maxClientNodes = 300;

            int.TryParse(ConfigurationManager.AppSettings["Nodes.MaxConnectedClients"], out maxClientNodes);
            Utilities.Logger.Append("START", Severity.INFO, "######## Starting Hub as '" + Thread.CurrentPrincipal.Identity.Name + "'. Date: " + DateTime.Now.ToString() + ", Version: " + Utilities.PlatForm.Instance().NodeVersion
                                    + ", OS: " + Utilities.PlatForm.Instance().OS + ", Runtime: " + Utilities.PlatForm.Instance().Runtime
                                    + ", DB Provider: " + ConfigurationManager.AppSettings["Storage.DBHandle.Provider"]);
            running = true;
            Socket hub = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            connection = hub;

            string listenIp   = ConfigurationManager.AppSettings["Nodes.ListenIp"];
            int    listenPort = 52561;

            int.TryParse(ConfigurationManager.AppSettings["Nodes.ListenPort"], out listenPort);
            IPAddress  listenAddress = (listenIp == "*") ? IPAddress.Any : IPAddress.Parse(listenIp);
            IPEndPoint src           = new IPEndPoint(listenAddress, listenPort);

            hub.Bind(src);
            hub.Listen(100);
            hub.BeginAccept(new AsyncCallback(AcceptClient), hub);

            Utilities.Logger.Append("START", Severity.INFO, "Starting Scheduler...");
            TaskScheduler.Start();
            TaskScheduler.Instance().TaskEvent        += HandleTaskEvent;
            TaskScheduler.Instance().NodeWakeUpNeeded += WakeUpNode;
            TasksMonitor.Start();
            Utilities.Logger.Append("START", Severity.INFO, "Starting nodes watcher...");
            NodesMonitor.Instance.Start();
            NodesMonitor.Instance.NodeOffline += HandleOfflineNode;
            Utilities.Logger.Append("START", Severity.INFO, "Starting Remoting Server...");
            Remoting.RemotingServer.Instance.Start();
            Utilities.Logger.Append("START", Severity.INFO, "Hub started.");
            ReAuthenticateNodes();
        }
Exemplo n.º 2
0
Arquivo: Hub.cs Projeto: radtek/BackO
        /// <summary>
        /// Logs out all online users and stops the hub
        /// </summary>
        internal static void Shutdown(User user, bool cancelTasks)
        {
            PeerNode u;

            try{
                Utilities.Logger.Append("STOP", Severity.INFO, "Hub shutdown requested by '" + user.Name + "', stopping...");
                Utilities.Logger.Append("STOP", Severity.INFO, "Informing client nodes of shutdown...");
                if (!running)
                {
                    return;
                }
                Remoting.RemotingServer.Instance.Stop();
                running = false;
                Thread.MemoryBarrier();
                TaskScheduler.Instance().TaskEvent -= HandleTaskEvent;
                TaskScheduler.Stop();
                TasksMonitor.Stop();
                for (int i = 0; i < NodesList.Count; i++)
                {
                    u = (PeerNode)NodesList[i];
                    u.Disconnect();
                    i = i - 1;
                }
                if (connection != null)
                {
                    connection.Disconnect(true);
                    connection.Dispose();
                }
                Utilities.Logger.Append("STOP", Severity.INFO, "Hub stopped.");
                P2PBackupHub.IdManager.Instance.Stop();
                Environment.Exit(0);
            }
            catch (Exception ex) {
                Utilities.Logger.Append("STOP", Severity.ERROR, "Could not stop Hub : " + ex.Message);
                Environment.Exit(1);
            }
        }