From 20695be8cd1c9386ea7da9772d0ca8e76195f1f0 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 12 Nov 2020 00:30:20 +0000 Subject: [PATCH] several changes to simulatorfeatures, special url ones. Centralize those on scene gridinfo. Do host and dns checks, etc. Grid can override local settings, but currently same old mess. Grid login and info fecth should happen before loading anything in scene, specially modules --- OpenSim/Framework/ExpiringCacheOS.cs | 35 +++- OpenSim/Framework/GridInfo.cs | 180 +++++++++++++++++- OpenSim/Region/Application/OpenSimBase.cs | 22 +-- .../Linden/Caps/SimulatorFeaturesModule.cs | 79 ++++---- OpenSim/Region/Framework/Scenes/Scene.cs | 63 ++++++ 5 files changed, 308 insertions(+), 71 deletions(-) diff --git a/OpenSim/Framework/ExpiringCacheOS.cs b/OpenSim/Framework/ExpiringCacheOS.cs index c246758a7c..4bf3d1b977 100644 --- a/OpenSim/Framework/ExpiringCacheOS.cs +++ b/OpenSim/Framework/ExpiringCacheOS.cs @@ -29,7 +29,7 @@ using System; using System.Threading; using System.Collections.Generic; -using Timer = System.Threading.Timer ; +using Timer = System.Threading.Timer; namespace OpenSim.Framework { @@ -125,7 +125,8 @@ namespace OpenSim.Framework List expired = new List(m_expireControl.Count); foreach(KeyValuePair kvp in m_expireControl) { - if(kvp.Value < now) + int expire = kvp.Value; + if(expire > 0 && expire < now) expired.Add(kvp.Key); } @@ -213,8 +214,14 @@ namespace OpenSim.Framework public void Add(TKey1 key, TValue1 val, int expireMS) { bool gotLock = false; - expireMS = (expireMS > m_expire) ? expireMS : m_expire; - int now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; + int now; + if (expireMS > 0) + { + expireMS = (expireMS > m_expire) ? expireMS : m_expire; + now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; + } + else + now = int.MinValue; try { @@ -345,8 +352,14 @@ namespace OpenSim.Framework m_rwLock.EnterWriteLock(); gotWriteLock = true; } - expireMS = (expireMS > m_expire) ? expireMS : m_expire; - int now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; + int now; + if(expireMS > 0) + { + expireMS = (expireMS > m_expire) ? expireMS : m_expire; + now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; + } + else + now = int.MinValue; m_expireControl[key] = now; return true; @@ -417,8 +430,14 @@ namespace OpenSim.Framework m_rwLock.EnterWriteLock(); gotWriteLock = true; } - expireMS = (expireMS > m_expire) ? expireMS : m_expire; - int now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; + int now; + if(expireMS > 0) + { + expireMS = (expireMS > m_expire) ? expireMS : m_expire; + now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; + } + else + now = int.MinValue; m_expireControl[key] = now; } diff --git a/OpenSim/Framework/GridInfo.cs b/OpenSim/Framework/GridInfo.cs index 5e0f80417a..555ec5df38 100644 --- a/OpenSim/Framework/GridInfo.cs +++ b/OpenSim/Framework/GridInfo.cs @@ -143,7 +143,7 @@ namespace OpenSim.Framework public string URIwEndSlash { - get { return Flags != OSHTTPURIFlags.None ? "" : URI + "/";} + get { return Flags == OSHTTPURIFlags.None ? "" : URI + "/";} } public int CompareTo(OSHTTPURI other) @@ -319,18 +319,18 @@ namespace OpenSim.Framework public int CompareTo(OSHHTPHost other) { - if (Port == other.Port && ((Flags & other.Flags) & OSHTTPURIFlags.ValidHost) != 0) + if (((Flags & other.Flags) & OSHTTPURIFlags.ValidHost) != 0) { - return Host.CompareTo(other.Host); + return URI.CompareTo(other.Host); } return -1; } public bool Equals(OSHHTPHost other) { - if (Port == other.Port && ((Flags & other.Flags) & OSHTTPURIFlags.ValidHost) != 0) + if (((Flags & other.Flags) & OSHTTPURIFlags.ValidHost) != 0) { - return Host.Equals(other.Host); + return URI.Equals(other.URI); } return false; } @@ -351,10 +351,17 @@ namespace OpenSim.Framework private OSHHTPHost m_homeURL; private HashSet m_homeURLAlias; + private string m_gridUrl = string.Empty; + private string[] m_gridUrlAlias = null; + private string m_GridName = string.Empty; + private string m_GridNick = string.Empty; + private string m_SearchURL = string.Empty; + private string m_DestinationGuideURL = string.Empty; + private string m_economyURL = string.Empty; public GridInfo (IConfigSource config, string defaultURI = "") { - string[] sections = new string[] { "Startup", "Hypergrid"}; + string[] sections = new string[] {"Const", "Startup", "Hypergrid"}; string gatekeeper = Util.GetConfigVarFromSections(config, "GatekeeperURI", sections, String.Empty); if (string.IsNullOrEmpty(gatekeeper)) @@ -387,6 +394,8 @@ namespace OpenSim.Framework throw new Exception("GatekeeperURI configuration error"); } + m_gridUrl = m_gateKeeperURL.URIwEndSlash; + string gatekeeperURIAlias = Util.GetConfigVarFromSections(config, "GatekeeperURIAlias", sections, String.Empty); if (!string.IsNullOrWhiteSpace(gatekeeperURIAlias)) @@ -404,6 +413,14 @@ namespace OpenSim.Framework } } + if (m_gateKeeperAlias != null && m_gateKeeperAlias.Count > 0) + { + m_gridUrlAlias = new string[m_gateKeeperAlias.Count]; + int i = 0; + foreach (OSHHTPHost a in m_gateKeeperAlias) + m_gridUrlAlias[i++] = a.URI; + } + string home = Util.GetConfigVarFromSections(config, "HomeURI", sections, string.Empty); if (string.IsNullOrEmpty(home)) @@ -437,6 +454,57 @@ namespace OpenSim.Framework } } } + + string[] namessections = new string[] { "Const", "GridInfo", "SimulatorFeatures" }; + m_GridName = Util.GetConfigVarFromSections(config, "GridName", namessections, string.Empty); + if (string.IsNullOrEmpty(m_GridName)) + m_GridName = Util.GetConfigVarFromSections(config, "gridname", namessections, string.Empty); + + m_GridNick = Util.GetConfigVarFromSections(config, "GridNick", namessections, string.Empty); + + if (m_GridName == string.Empty) + m_GridName = "Another bad configured grid"; + + OSHTTPURI tmpuri; + m_SearchURL = Util.GetConfigVarFromSections(config,"SearchServerURI", namessections, string.Empty); + if (!string.IsNullOrEmpty(m_SearchURL)) + { + tmpuri = new OSHTTPURI(m_SearchURL.Trim(), true); + if (!tmpuri.IsResolvedHost) + { + m_log.Error(tmpuri.IsValidHost ? "Could not resolve SearchServerURI" : "SearchServerURI is a invalid host"); + throw new Exception("SearchServerURI configuration error"); + } + m_SearchURL = tmpuri.URIwEndSlash; + } + + m_DestinationGuideURL = Util.GetConfigVarFromSections(config, "DestinationGuideURI",namessections, string.Empty); + + if (string.IsNullOrEmpty(m_DestinationGuideURL)) // Make this consistent with the variable in the LoginService config + m_DestinationGuideURL = Util.GetConfigVarFromSections(config, "DestinationGuide", namessections, string.Empty); + + if (!string.IsNullOrEmpty(m_DestinationGuideURL)) + { + tmpuri = new OSHTTPURI(m_DestinationGuideURL.Trim(), true); + if (!tmpuri.IsResolvedHost) + { + m_log.Error(tmpuri.IsValidHost ? "Could not resolve DestinationGuideURL" : "DestinationGuideURL is a invalid host"); + throw new Exception("DestinationGuideURL configuration error"); + } + m_DestinationGuideURL = tmpuri.URIwEndSlash; + } + + m_economyURL = Util.GetConfigVarFromSections(config, "economy", new string[] { "Economy", "GridInfo" }); + if (!string.IsNullOrEmpty(m_economyURL)) + { + tmpuri = new OSHTTPURI(m_economyURL.Trim(), true); + if (!tmpuri.IsResolvedHost) + { + m_log.Error(tmpuri.IsValidHost ? "Could not resolve economyURL" : "economyURL is a invalid host"); + throw new Exception("economyURL configuration error"); + } + m_economyURL = tmpuri.URIwEndSlash; + } } public bool HasHGConfig @@ -568,5 +636,105 @@ namespace OpenSim.Framework } return 0; } + + public string[] GridUrlAlias + { + get { return m_gridUrlAlias; } + set + { + if(value.Length > 0) + { + for (int i = 0; i < value.Length; ++i) + { + OSHHTPHost tmp = new OSHHTPHost(value[i].Trim(), false); + if (tmp.IsValidHost) + { + if (m_gateKeeperAlias == null) + m_gateKeeperAlias = new HashSet(); + m_gateKeeperAlias.Add(tmp); + } + } + if (m_gateKeeperAlias != null && m_gateKeeperAlias.Count > 0) + { + m_gridUrlAlias = new string[m_homeURLAlias.Count]; + int i = 0; + foreach (OSHHTPHost a in m_homeURLAlias) + m_gridUrlAlias[i++] = a.URI; + } + } + } + } + + public string GridName + { + get { return m_GridName; } + set + { + if (!string.IsNullOrEmpty(value)) + m_GridName = value; + } + } + + public string GridNick + { + get { return m_GridNick; } + set + { + if (!string.IsNullOrEmpty(value)) + m_GridNick = value; + } + } + + public string GridUrl + { + get { return m_gridUrl; } + set + { + OSHHTPHost tmp = new OSHHTPHost(value, true); + if (tmp.IsResolvedHost) + m_gridUrl = tmp.URI; + else + m_log.Error(tmp.IsValidHost ? "Could not resolve GridUrl" : "GridUrl is a invalid host"); + } + } + + public string SearchURL + { + get { return m_SearchURL; } + set + { + OSHTTPURI tmp = new OSHTTPURI(value, true); + if (tmp.IsResolvedHost) + m_SearchURL = tmp.URIwEndSlash; + else + m_log.Error(tmp.IsValidHost ? "Could not resolve SearchURL" : "SearchURL is a invalid host"); + } + } + + public string DestinationGuideURL + { + get { return m_DestinationGuideURL; } + set + { + OSHTTPURI tmp = new OSHTTPURI(value, true); + if (tmp.IsResolvedHost) + m_DestinationGuideURL = tmp.URIwEndSlash; + else + m_log.Error(tmp.IsValidHost ? "Could not resolve DestinationGuideURL" : "DestinationGuideURL is a invalid host"); + } + } + + public string EconomyURL + { + get { return m_economyURL; } + set + { + OSHTTPURI tmp = new OSHTTPURI(value, true); + if (tmp.IsResolvedHost) + m_economyURL = tmp.URIwEndSlash; + else + m_log.Error(tmp.IsValidHost ? "Could not resolve EconomyURL" : "EconomyURL is a invalid host"); + } + } } } diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 5b00a910cc..525f87a937 100755 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -406,6 +406,13 @@ namespace OpenSim /// public void CreateRegion(RegionInfo regionInfo, bool portadd_flag, bool do_post_init, out IScene mscene) { + IRegionModulesController controller; + if (!ApplicationRegistry.TryGet(out controller)) + { + m_log.Fatal("REGIONMODULES]: The new RegionModulesController is missing..."); + Environment.Exit(0); + } + int port = regionInfo.InternalEndPoint.Port; // set initial RegionID to originRegionID in RegionInfo. (it needs for loding prims) @@ -429,7 +436,6 @@ namespace OpenSim regionInfo.ServerURI = "http://" + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort.ToString() + "/"; - regionInfo.osSecret = m_osSecret; if ((proxyUrl.Length > 0) && (portadd_flag)) @@ -442,16 +448,9 @@ namespace OpenSim Scene scene = SetupScene(regionInfo, proxyOffset, Config); - m_log.Info("[MODULES]: Loading Region's modules (old style)"); - - // Use this in the future, the line above will be deprecated soon - m_log.Info("[REGIONMODULES]: Loading Region's modules (new style)"); - IRegionModulesController controller; - if (ApplicationRegistry.TryGet(out controller)) - { + m_log.Info("[REGIONMODULES]: Loading Region's modules"); + if (controller != null) controller.AddRegionToModules(scene); - } - else m_log.Error("[REGIONMODULES]: The new RegionModulesController is missing..."); if (m_securePermissionsLoading) { @@ -520,8 +519,7 @@ namespace OpenSim scene.SnmpService.BootInfo("Grid Registration done", scene); } - // We need to do this after we've initialized the - // scripting engines. + // We need to do this after we've initialized the scripting engines. scene.CreateScriptInstances(); if (scene.SnmpService != null) diff --git a/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs index e3ddd34777..4000257e9f 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs @@ -72,11 +72,7 @@ namespace OpenSim.Region.ClientStack.Linden /// private OSDMap m_features = new OSDMap(); - private string m_SearchURL = string.Empty; - private string m_DestinationGuideURL = string.Empty; private bool m_ExportSupported = false; - private string m_GridName = string.Empty; - private string m_GridURL = string.Empty; private bool m_doScriptSyntax; @@ -84,8 +80,6 @@ namespace OpenSim.Region.ClientStack.Linden static private UUID m_scriptSyntaxID = UUID.Zero; static private byte[] m_scriptSyntaxXML = null; - static private string m_economyURL = null; - #region ISharedRegionModule Members public void Initialise(IConfigSource source) @@ -94,34 +88,10 @@ namespace OpenSim.Region.ClientStack.Linden m_doScriptSyntax = true; if (config != null) { - // - // All this is obsolete since getting these features from the grid service!! - // Will be removed after the next release - // - m_SearchURL = config.GetString("SearchServerURI", m_SearchURL); - - m_DestinationGuideURL = config.GetString ("DestinationGuideURI", m_DestinationGuideURL); - - if (m_DestinationGuideURL == string.Empty) // Make this consistent with the variable in the LoginService config - m_DestinationGuideURL = config.GetString("DestinationGuide", m_DestinationGuideURL); - m_ExportSupported = config.GetBoolean("ExportSupported", m_ExportSupported); - - m_GridURL = Util.GetConfigVarFromSections( - source, "GatekeeperURI", new string[] { "Startup", "Hypergrid", "SimulatorFeatures" }, String.Empty); - - m_GridName = config.GetString("GridName", string.Empty); - if (m_GridName == string.Empty) - m_GridName = Util.GetConfigVarFromSections( - source, "GridName", new string[] { "GridInfo", "SimulatorFeatures" }, String.Empty); - if (m_GridName == string.Empty) - m_GridName = Util.GetConfigVarFromSections( - source, "gridname", new string[] { "GridInfo", "SimulatorFeatures" }, String.Empty); m_doScriptSyntax = config.GetBoolean("ScriptSyntax", m_doScriptSyntax); } - m_economyURL = Util.GetConfigVarFromSections(source, "economy", new string[] { "Economy", "GridInfo" }); - ReadScriptSyntax(); AddDefaultFeatures(); } @@ -208,19 +178,8 @@ namespace OpenSim.Region.ClientStack.Linden extrasMap["MinHeightmap"] = Constants.MinTerrainHeightmap; extrasMap["MaxHeightmap"] = Constants.MaxTerrainHeightmap; - // TODO: Take these out of here into their respective modules, like map-server-url - if (!string.IsNullOrWhiteSpace(m_SearchURL)) - extrasMap["search-server-url"] = m_SearchURL; - if (!string.IsNullOrEmpty(m_DestinationGuideURL)) - extrasMap["destination-guide-url"] = m_DestinationGuideURL; if (m_ExportSupported) extrasMap["ExportSupported"] = true; - if (!string.IsNullOrWhiteSpace(m_GridURL)) - extrasMap["GridURL"] = m_GridURL; - if (!string.IsNullOrWhiteSpace(m_GridName)) - extrasMap["GridName"] = m_GridName; - if(!string.IsNullOrWhiteSpace(m_economyURL)) - extrasMap["currency-base-uri"] = Util.AppendEndSlash(m_economyURL); if (extrasMap.Count > 0) m_features["OpenSimExtras"] = extrasMap; } @@ -363,6 +322,7 @@ namespace OpenSim.Region.ClientStack.Linden return; } + GridInfo ginfo = scene.SceneGridInfo; lock (m_features) { OSDMap extrasMap; @@ -375,12 +335,41 @@ namespace OpenSim.Region.ClientStack.Linden foreach (string key in extraFeatures.Keys) { - extrasMap[key] = (string)extraFeatures[key]; - - if (key == "ExportSupported") + string val = (string)extraFeatures[key]; + switch(key) { - bool.TryParse(extraFeatures[key].ToString(), out m_ExportSupported); + case "GridName": + ginfo.GridName = val; + break; + case "GridNick": + ginfo.GridNick = val; + break; + case "GridURL": + ginfo.GridUrl = val; + break; + case "GridURLAlias": + string[] vals = val.Split(','); + if(vals.Length > 0) + ginfo.GridUrlAlias = vals; + break; + case "search-server-url": + ginfo.SearchURL = val; + break; + case "destination-guide-url": + ginfo.DestinationGuideURL = val; + break; + case "currency-base-uri": + ginfo.EconomyURL = val; + break; + default: + extrasMap[key] = val; + if (key == "ExportSupported") + { + bool.TryParse(val, out m_ExportSupported); + } + break; } + } m_features["OpenSimExtras"] = extrasMap; } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 25ab66ca2f..5f0664df9c 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1268,6 +1268,69 @@ namespace OpenSim.Region.Framework.Scenes fm.AddOpenSimExtraFeature("MaxPrimScale", OSD.FromReal(m_maxNonphys)); fm.AddOpenSimExtraFeature("MinPhysPrimScale", OSD.FromReal(m_minPhys)); fm.AddOpenSimExtraFeature("MaxPhysPrimScale", OSD.FromReal(m_maxPhys)); + + if(SceneGridInfo != null) + { + OSD osdtmp; + string tmp; + if (!fm.TryGetOpenSimExtraFeature("GridName", out osdtmp)) + { + tmp = SceneGridInfo.GridName; + if (!string.IsNullOrEmpty(tmp)) + fm.AddOpenSimExtraFeature("GridName", tmp); + } + + if (!fm.TryGetOpenSimExtraFeature("GridNick", out osdtmp)) + { + tmp = SceneGridInfo.GridNick; + if (!string.IsNullOrEmpty(tmp)) + fm.AddOpenSimExtraFeature("GridNick", tmp); + } + + if (!fm.TryGetOpenSimExtraFeature("GridURL", out osdtmp)) + { + tmp = SceneGridInfo.GridUrl; + fm.AddOpenSimExtraFeature("GridURL", tmp); + } + + if (!fm.TryGetOpenSimExtraFeature("GridURLAlias", out osdtmp)) + { + string[] alias = SceneGridInfo.GridUrlAlias; + if(alias != null && alias.Length > 0) + { + StringBuilder sb = osStringBuilderCache.Acquire(); + int i = 0; + for(; i < alias.Length - 1; ++i) + { + sb.Append(alias[i]); + sb.Append(','); + } + sb.Append(alias[i]); + fm.AddOpenSimExtraFeature("GridURLAlias", osStringBuilderCache.GetStringAndRelease(sb)); + } + } + + if (!fm.TryGetOpenSimExtraFeature("search-server-url", out osdtmp)) + { + tmp = SceneGridInfo.SearchURL; + if (!string.IsNullOrEmpty(tmp)) + fm.AddOpenSimExtraFeature("search-server-url", tmp); + } + + if (!fm.TryGetOpenSimExtraFeature("destination-guide-url", out osdtmp)) + { + tmp = SceneGridInfo.DestinationGuideURL; + if (!string.IsNullOrEmpty(tmp)) + fm.AddOpenSimExtraFeature("destination-guide-url", tmp); + } + + if (!fm.TryGetOpenSimExtraFeature("currency-base-uri", out osdtmp)) + { + tmp = SceneGridInfo.EconomyURL; + if (!string.IsNullOrEmpty(tmp)) + fm.AddOpenSimExtraFeature("currency-base-uri", tmp); + } + } } }