From 94517c8d5c63f9e8a1ea9a83b04db956f27aa25d Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 15 Jun 2012 02:51:52 +0100 Subject: [PATCH] Make the "debug http" command available for robust as well as the simulator. This allows one to see incoming requests as they happen. This required making everything use the common MainServer class for registering and retrieving http servers, rather than duplicate structures. --- .../Servers/HttpServer/BaseHttpServer.cs | 3 + OpenSim/Framework/Servers/MainServer.cs | 60 +++++++++++++- OpenSim/Region/Application/OpenSim.cs | 34 +------- OpenSim/Server/Base/HttpServerBase.cs | 78 +++++-------------- OpenSim/Server/ServerMain.cs | 26 +++---- prebuild.xml | 1 + 6 files changed, 92 insertions(+), 110 deletions(-) diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 0db1329ad2..3de7f9ca72 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1557,6 +1557,9 @@ namespace OpenSim.Framework.Servers.HttpServer private void StartHTTP() { + m_log.InfoFormat( + "[BASE HTTP SERVER]: Starting {0} server on port {1}", UseSSL ? "HTTPS" : "HTTP", Port); + try { //m_httpListener = new HttpListener(); diff --git a/OpenSim/Framework/Servers/MainServer.cs b/OpenSim/Framework/Servers/MainServer.cs index becbbc21b8..07ff60c326 100644 --- a/OpenSim/Framework/Servers/MainServer.cs +++ b/OpenSim/Framework/Servers/MainServer.cs @@ -30,13 +30,15 @@ using System.Collections.Generic; using System.Reflection; using System.Net; using log4net; +using OpenSim.Framework; +using OpenSim.Framework.Console; using OpenSim.Framework.Servers.HttpServer; namespace OpenSim.Framework.Servers { public class MainServer { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static BaseHttpServer instance = null; private static Dictionary m_Servers = new Dictionary(); @@ -87,6 +89,57 @@ namespace OpenSim.Framework.Servers } } + /// + /// Get all the registered servers. + /// + /// + /// Returns a copy of the dictionary so this can be iterated through without locking. + /// + /// + public static Dictionary Servers + { + get { return new Dictionary(m_Servers); } + } + + + public static void RegisterHttpConsoleCommands(ICommandConsole console) + { + console.Commands.AddCommand( + "Comms", false, "debug http", "debug http []", + "Turn on inbound non-poll http request debugging.", + "If level <= 0, then no extra logging is done.\n" + + "If level >= 1, then short warnings are logged when receiving bad input data.\n" + + "If level >= 2, then long warnings are logged when receiving bad input data.\n" + + "If level >= 3, then short notices about all incoming non-poll HTTP requests are logged.\n" + + "If no level is specified then the current level is returned.", + HandleDebugHttpCommand); + } + + /// + /// Turn on some debugging values for OpenSim. + /// + /// + private static void HandleDebugHttpCommand(string module, string[] args) + { + if (args.Length == 3) + { + int newDebug; + if (int.TryParse(args[2], out newDebug)) + { + MainServer.DebugLevel = newDebug; + MainConsole.Instance.OutputFormat("Debug http level set to {0}", newDebug); + } + } + else if (args.Length == 2) + { + MainConsole.Instance.OutputFormat("Current debug http level is {0}", MainServer.DebugLevel); + } + else + { + MainConsole.Instance.Output("Usage: debug http 0..3"); + } + } + /// /// Register an already started HTTP server to the collection of known servers. /// @@ -171,11 +224,10 @@ namespace OpenSim.Framework.Servers if (ipaddr != null) m_Servers[port].ListenIPAddress = ipaddr; - m_log.InfoFormat("[MAIN HTTP SERVER]: Starting main http server on port {0}", port); m_Servers[port].Start(); - } - return m_Servers[port]; + return m_Servers[port]; + } } } } \ No newline at end of file diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index abb30a9117..faa9e096ec 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -231,6 +231,8 @@ namespace OpenSim /// private void RegisterConsoleCommands() { + MainServer.RegisterHttpConsoleCommands(m_console); + m_console.Commands.AddCommand("Objects", false, "force update", "force update", "Force the update of all objects on clients", @@ -248,16 +250,6 @@ namespace OpenSim + "If an avatar name is given then only packets from that avatar are logged", Debug); - m_console.Commands.AddCommand("Comms", false, "debug http", - "debug http []", - "Turn on inbound non-poll http request debugging for everything except the event queue (see debug eq).", - "If level <= 0, then no extra logging is done.\n" - + "If level >= 1, then short warnings are logged when receiving bad input data.\n" - + "If level >= 2, then long warnings are logged when receiving bad input data.\n" - + "If level >= 3, then short notices about all incoming non-poll HTTP requests are logged.\n" - + "If no level is specified then the current level is returned.", - Debug); - m_console.Commands.AddCommand("Comms", false, "debug teleport", "debug teleport", "Toggle teleport route debugging", Debug); m_console.Commands.AddCommand("Regions", false, "debug scene", @@ -916,28 +908,6 @@ namespace OpenSim break; - case "http": - if (args.Length == 3) - { - int newDebug; - if (int.TryParse(args[2], out newDebug)) - { - MainServer.DebugLevel = newDebug; - MainConsole.Instance.OutputFormat("Debug http level set to {0}", newDebug); - break; - } - } - else if (args.Length == 2) - { - MainConsole.Instance.OutputFormat("Current debug http level is {0}", MainServer.DebugLevel); - } - else - { - MainConsole.Instance.Output("Usage: debug http 0..3"); - } - - break; - case "scene": if (args.Length == 4) { diff --git a/OpenSim/Server/Base/HttpServerBase.cs b/OpenSim/Server/Base/HttpServerBase.cs index 7014303203..7ba0ca8053 100644 --- a/OpenSim/Server/Base/HttpServerBase.cs +++ b/OpenSim/Server/Base/HttpServerBase.cs @@ -42,42 +42,9 @@ namespace OpenSim.Server.Base { // Logger // - private static readonly ILog m_Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - // The http server instance - // - protected BaseHttpServer m_HttpServer = null; - protected uint m_Port = 0; - protected Dictionary m_Servers = - new Dictionary(); - protected uint m_consolePort = 0; - - public IHttpServer HttpServer - { - get { return m_HttpServer; } - } - - public uint DefaultPort - { - get { return m_Port; } - } - - public IHttpServer GetHttpServer(uint port) - { - m_Log.InfoFormat("[SERVER]: Requested port {0}", port); - if (port == m_Port) - return HttpServer; - - if (m_Servers.ContainsKey(port)) - return m_Servers[port]; - - m_Servers[port] = new BaseHttpServer(port); - - m_Log.InfoFormat("[SERVER]: Starting new HTTP server on port {0}", port); - m_Servers[port].Start(); - - return m_Servers[port]; - } + private uint m_consolePort; // Handle all the automagical stuff // @@ -94,19 +61,21 @@ namespace OpenSim.Server.Base System.Console.WriteLine("Section 'Network' not found, server can't start"); Thread.CurrentThread.Abort(); } + uint port = (uint)networkConfig.GetInt("port", 0); if (port == 0) { - Thread.CurrentThread.Abort(); } - // + bool ssl_main = networkConfig.GetBoolean("https_main",false); bool ssl_listener = networkConfig.GetBoolean("https_listener",false); m_consolePort = (uint)networkConfig.GetInt("ConsolePort", 0); - m_Port = port; + + BaseHttpServer httpServer = null; + // // This is where to make the servers: // @@ -118,8 +87,7 @@ namespace OpenSim.Server.Base // if ( !ssl_main ) { - m_HttpServer = new BaseHttpServer(port); - + httpServer = new BaseHttpServer(port); } else { @@ -135,11 +103,12 @@ namespace OpenSim.Server.Base System.Console.WriteLine("Password for X509 certificate is missing, server can't start."); Thread.CurrentThread.Abort(); } - m_HttpServer = new BaseHttpServer(port, ssl_main, cert_path, cert_pass); + + httpServer = new BaseHttpServer(port, ssl_main, cert_path, cert_pass); } - MainServer.AddHttpServer(m_HttpServer); - MainServer.Instance = m_HttpServer; + MainServer.AddHttpServer(httpServer); + MainServer.Instance = httpServer; // If https_listener = true, then add an ssl listener on the https_port... if ( ssl_listener == true ) { @@ -159,34 +128,23 @@ namespace OpenSim.Server.Base Thread.CurrentThread.Abort(); } - m_Servers.Add(https_port, new BaseHttpServer(https_port, ssl_listener, cert_path, cert_pass)); + MainServer.AddHttpServer(new BaseHttpServer(https_port, ssl_listener, cert_path, cert_pass)); } } protected override void Initialise() { - m_Log.InfoFormat("[SERVER]: Starting HTTP server on port {0}", m_HttpServer.Port); - m_HttpServer.Start(); + foreach (BaseHttpServer s in MainServer.Servers.Values) + s.Start(); - if (m_Servers.Count > 0) - { - foreach (BaseHttpServer s in m_Servers.Values) - { - if (!s.UseSSL) - m_Log.InfoFormat("[SERVER]: Starting HTTP server on port {0}", s.Port); - else - m_Log.InfoFormat("[SERVER]: Starting HTTPS server on port {0}", s.Port); - - s.Start(); - } - } + MainServer.RegisterHttpConsoleCommands(MainConsole.Instance); if (MainConsole.Instance is RemoteConsole) { if (m_consolePort == 0) - ((RemoteConsole)MainConsole.Instance).SetServer(m_HttpServer); + ((RemoteConsole)MainConsole.Instance).SetServer(MainServer.Instance); else - ((RemoteConsole)MainConsole.Instance).SetServer(GetHttpServer(m_consolePort)); + ((RemoteConsole)MainConsole.Instance).SetServer(MainServer.GetHttpServer(m_consolePort)); } } } diff --git a/OpenSim/Server/ServerMain.cs b/OpenSim/Server/ServerMain.cs index 9503c4cff6..21fb6785c3 100644 --- a/OpenSim/Server/ServerMain.cs +++ b/OpenSim/Server/ServerMain.cs @@ -30,6 +30,7 @@ using log4net; using System.Reflection; using System; using System.Collections.Generic; +using OpenSim.Framework.Servers; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Server.Base; using OpenSim.Server.Handlers.Base; @@ -92,27 +93,24 @@ namespace OpenSim.Server if (parts.Length > 1) friendlyName = parts[1]; - IHttpServer server = m_Server.HttpServer; - if (port != 0) - server = m_Server.GetHttpServer(port); + IHttpServer server; - if (port != m_Server.DefaultPort && port != 0) - m_log.InfoFormat("[SERVER]: Loading {0} on port {1}", friendlyName, port); + if (port != 0) + server = MainServer.GetHttpServer(port); else - m_log.InfoFormat("[SERVER]: Loading {0}", friendlyName); + server = MainServer.Instance; + + m_log.InfoFormat("[SERVER]: Loading {0} on port {1}", friendlyName, server.Port); IServiceConnector connector = null; - Object[] modargs = new Object[] { m_Server.Config, server, - configName }; - connector = ServerUtils.LoadPlugin(conn, - modargs); + Object[] modargs = new Object[] { m_Server.Config, server, configName }; + connector = ServerUtils.LoadPlugin(conn, modargs); + if (connector == null) { modargs = new Object[] { m_Server.Config, server }; - connector = - ServerUtils.LoadPlugin(conn, - modargs); + connector = ServerUtils.LoadPlugin(conn, modargs); } if (connector != null) @@ -132,4 +130,4 @@ namespace OpenSim.Server return 0; } } -} +} \ No newline at end of file diff --git a/prebuild.xml b/prebuild.xml index d02f2b939f..45f58c7e7c 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1385,6 +1385,7 @@ +