3 Angajamente 00c0816275 ... 54114a23f5

Autor SHA1 Permisiunea de a trimite mesaje. Dacă este dezactivată, utilizatorul nu va putea trimite nici un fel de mesaj Data
  UbitUmarov 54114a23f5 cosmetics 2 luni în urmă
  UbitUmarov 4eb8fa29f4 oops fix typo 2 luni în urmă
  UbitUmarov a9be42a304 a few changes to EstateDataRemoteConnector, LoadEstateSettings can not be fatal so work around it 2 luni în urmă

+ 1 - 2
OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs

@@ -878,7 +878,6 @@ namespace OpenSim.ApplicationPlugins.RemoteController
                     int estateID = estateIDs[0];
 
                     region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(region.RegionID, false);
-
                     if (region.EstateSettings.EstateID != estateID)
                     {
                         // The region is already part of an estate, but not the one we want.
@@ -2114,7 +2113,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
             m_log.Info("[RADMIN]: Received Estate Reload Request");
 
             Hashtable responseData = (Hashtable)response.Value;
-//            Hashtable requestData = (Hashtable)request.Params[0];
+            //Hashtable requestData = (Hashtable)request.Params[0];
 
             m_application.SceneManager.ForEachScene(s =>
                 s.RegionInfo.EstateSettings = m_application.EstateDataService.LoadEstateSettings(s.RegionInfo.RegionID, false)

+ 50 - 18
OpenSim/Framework/Util.cs

@@ -1485,6 +1485,9 @@ namespace OpenSim.Framework
             return streamReader.ReadToEnd();
         }
 
+        private static readonly string pathSSLRsaPriv = Path.Combine("SSL","src");
+        private static readonly string pathSSLcerts = Path.Combine("SSL","ssl");
+
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public static void CreateOrUpdateSelfsignedCert(string certFileName, string certHostName, string certHostIp, string certPassword)
         {
@@ -1513,12 +1516,10 @@ namespace OpenSim.Framework
 
                 // (Optional)...
                 request.CertificateExtensions.Add(
-                new X509KeyUsageExtension(X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature , false));
+                    new X509KeyUsageExtension(X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature , false));
 
                 // (Optional) SSL Server Authentication...
-                request.CertificateExtensions.Add(
-                new X509EnhancedKeyUsageExtension(
-                    new OidCollection { new Oid("1.3.6.1.5.5.7.3.1") }, false));
+                request.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension([new Oid("1.3.6.1.5.5.7.3.1")], false));
 
                 request.CertificateExtensions.Add(san.Build());
 
@@ -1527,26 +1528,25 @@ namespace OpenSim.Framework
                 string privateKey = Convert.ToBase64String(rsa.ExportRSAPrivateKey(), Base64FormattingOptions.InsertLineBreaks);
 
                 // Create the SSL folder and sub folders if not exists.
-                if (!Directory.Exists("SSL\\src\\"))
-                    Directory.CreateDirectory("SSL\\src\\");
-
-                if (!Directory.Exists("SSL\\ssl\\"))
-                    Directory.CreateDirectory("SSL\\ssl\\");
+                if (!Directory.Exists(pathSSLRsaPriv))
+                    Directory.CreateDirectory(pathSSLRsaPriv);
+                if (!Directory.Exists(pathSSLcerts))
+                    Directory.CreateDirectory(pathSSLcerts);
 
                 // Store the RSA key in SSL\src\
-                File.WriteAllText($"SSL\\src\\{certFileName}.txt", privateKey);
-
+                File.WriteAllText(Path.Combine(pathSSLRsaPriv, certFileName) + ".txt", privateKey);
                 // Export and store the .pfx and .p12 certificates in SSL\ssl\.
                 // Note: Pfx is a Pkcs12 certificate and both files work for OpenSim.
+                string sslFileNames = Path.Combine(pathSSLcerts, certFileName);
                 byte[] pfxCertBytes = string.IsNullOrEmpty(certPassword) 
                                     ? certificate.Export(X509ContentType.Pfx) 
                                     : certificate.Export(X509ContentType.Pfx, certPassword);
-                File.WriteAllBytes($"SSL\\ssl\\{certFileName}.pfx", pfxCertBytes);
+                File.WriteAllBytes(sslFileNames + ".pfx", pfxCertBytes);
 
                 byte[] p12CertBytes = string.IsNullOrEmpty(certPassword) 
                                     ? certificate.Export(X509ContentType.Pkcs12) 
                                     : certificate.Export(X509ContentType.Pkcs12, certPassword);
-                File.WriteAllBytes($"SSL\\ssl\\{certFileName}.p12", p12CertBytes);
+                File.WriteAllBytes(sslFileNames + ".p12", p12CertBytes);
             }
         }
 
@@ -1591,19 +1591,20 @@ namespace OpenSim.Framework
             }
 
             // Create the SSL folder and ssl sub folder if not exists.
-            if (!Directory.Exists("SSL\\ssl\\"))
-                Directory.CreateDirectory("SSL\\ssl\\");
+            if (!Directory.Exists(pathSSLcerts))
+                Directory.CreateDirectory(pathSSLcerts);
 
+            string sslFileNames = System.IO.Path.Combine(pathSSLcerts, certFileName);
             // Export and store the .pfx and .p12 certificates in SSL\ssl\.
             byte[] pfxCertBytes = string.IsNullOrEmpty(outputPassword)
                                 ? certificate.Export(X509ContentType.Pfx)
                                 : certificate.Export(X509ContentType.Pfx, outputPassword);
-            File.WriteAllBytes($"SSL\\ssl\\{certFileName}.pfx", pfxCertBytes);
+            File.WriteAllBytes(sslFileNames + ".pfx", pfxCertBytes);
 
             byte[] p12CertBytes = string.IsNullOrEmpty(outputPassword) 
                                 ? certificate.Export(X509ContentType.Pkcs12) 
                                 : certificate.Export(X509ContentType.Pkcs12, outputPassword);
-            File.WriteAllBytes($"SSL\\ssl\\{certFileName}.p12", p12CertBytes);
+            File.WriteAllBytes(sslFileNames + ".p12", p12CertBytes);
             
         }
 
@@ -3186,7 +3187,7 @@ namespace OpenSim.Framework
         {
             if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
             {
-                timeEndPeriod(1);
+                timeBeginPeriod(1);
                 Thread.Sleep(period);
                 timeEndPeriod(1);
             }
@@ -3194,6 +3195,37 @@ namespace OpenSim.Framework
                 Thread.Sleep(period);
         }
 
+        [DllImport("kernel32.dll", SetLastError = true)]
+        public static extern bool SetProcessInformation(IntPtr hProcess, int ProcessInformationClass,
+                    IntPtr ProcessInformation, UInt32 ProcessInformationSize);
+
+        [StructLayout(LayoutKind.Sequential)]
+        private struct PROCESS_POWER_THROTTLING_STATE
+        {
+            public uint Version;
+            public uint ControlMask;
+            public uint StateMask;
+        }
+
+        public static void DisableTimerThrottling()
+        {
+            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            {
+                int sz = Marshal.SizeOf(typeof(PROCESS_POWER_THROTTLING_STATE));
+                PROCESS_POWER_THROTTLING_STATE PwrInfo = new()
+                {
+                    Version = 1,
+                    ControlMask = 4,
+                    StateMask = 0
+                };  // disable that flag explicitly
+                nint PwrInfoPtr = Marshal.AllocHGlobal(sz);
+                Marshal.StructureToPtr(PwrInfo, PwrInfoPtr, false);
+                IntPtr handle = Process.GetCurrentProcess().Handle;
+                bool r = SetProcessInformation(handle, 4, PwrInfoPtr, (uint)sz);
+                Marshal.FreeHGlobal(PwrInfoPtr);
+            }
+        }
+
         /// <summary>
         /// Used to trigger an early library load on Windows systems.
         /// </summary>

+ 1 - 1
OpenSim/Region/Application/OpenSimBase.cs

@@ -1059,7 +1059,7 @@ namespace OpenSim
             m_log.WarnFormat("[ESTATE] Region {0} is not part of an estate.", regInfo.RegionName);
 
             List<EstateSettings> estates = EstateDataService.LoadEstateSettingsAll();
-            Dictionary<string, EstateSettings> estatesByName = new Dictionary<string, EstateSettings>();
+            Dictionary<string, EstateSettings> estatesByName = [];
 
             foreach (EstateSettings estate in estates)
                 estatesByName[estate.EstateName] = estate;

+ 10 - 2
OpenSim/Region/Framework/Scenes/Scene.cs

@@ -874,7 +874,12 @@ namespace OpenSim.Region.Framework.Scenes
             RegionInfo.RegionSettings = rs;
 
             if (estateDataService is not null)
-                RegionInfo.EstateSettings = estateDataService.LoadEstateSettings(RegionInfo.RegionID, false);
+            {
+                EstateSettings es = estateDataService.LoadEstateSettings(RegionInfo.RegionID, false);
+                if (es == null)
+                    m_log.Error($"[SCENE]: Region {Name} failed to load estate settings. Using defaults");
+                RegionInfo.EstateSettings = es;
+            }
 
             SceneGridInfo = new GridInfo(config, RegionInfo.ServerURI);
 
@@ -5815,7 +5820,10 @@ Environment.Exit(1);
             if (estateDataService is not null)
             {
                 bool parcelEnvOvr = RegionInfo.EstateSettings.AllowEnvironmentOverride;
-                RegionInfo.EstateSettings = estateDataService.LoadEstateSettings(RegionInfo.RegionID, false);
+                EstateSettings es = estateDataService.LoadEstateSettings(RegionInfo.RegionID, false);
+                if (es == null)
+                    m_log.Error($"[SCENE]: Region {RegionInfo.RegionName} failed to reload estate settings. Using defaults");
+                RegionInfo.EstateSettings = es;
                 if(parcelEnvOvr && !RegionInfo.EstateSettings.AllowEnvironmentOverride)
                     ClearAllParcelEnvironments();
             }

+ 3 - 6
OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs

@@ -194,19 +194,16 @@ namespace OpenSim.Server.Handlers
 
             if (!string.IsNullOrEmpty(region))
             {
-                UUID regionID = UUID.Zero;
-                if (UUID.TryParse(region, out regionID))
+                if (UUID.TryParse(region, out UUID regionID))
                 {
                     string create = (string)httpRequest.Query["create"];
-                    bool createYN = false;
-                    Boolean.TryParse(create, out createYN);
+                    bool.TryParse(create, out bool createYN);
                     estate = m_EstateService.LoadEstateSettings(regionID, createYN);
                 }
             }
             else if (!string.IsNullOrEmpty(eid))
             {
-                int id = 0;
-                if (Int32.TryParse(eid, out id))
+                if (int.TryParse(eid, out  int id))
                     estate = m_EstateService.LoadEstateSettings(id);
             }
 

+ 50 - 75
OpenSim/Services/Connectors/Estate/EstateDataConnector.cs

@@ -35,8 +35,6 @@ using OpenMetaverse;
 using Nini.Config;
 
 using OpenSim.Framework;
-using OpenSim.Framework.ServiceAuth;
-using OpenSim.Services.Connectors;
 using OpenSim.Services.Interfaces;
 using OpenSim.Server.Base;
 using System.Net.Http;
@@ -45,9 +43,7 @@ namespace OpenSim.Services.Connectors
 {
     public class EstateDataRemoteConnector : BaseServiceConnector, IEstateDataService
     {
-        private static readonly ILog m_log =
-                LogManager.GetLogger(
-                MethodBase.GetCurrentMethod().DeclaringType);
+        private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
         private string m_ServerURI = String.Empty;
         private ExpiringCache<string, List<EstateSettings>> m_EstateCache = new ExpiringCache<string, List<EstateSettings>>();
@@ -61,15 +57,13 @@ namespace OpenSim.Services.Connectors
         public virtual void Initialise(IConfigSource source)
         {
             IConfig gridConfig = source.Configs["EstateService"];
-            if (gridConfig == null)
+            if (gridConfig is null)
             {
                 m_log.Error("[ESTATE CONNECTOR]: EstateService missing from OpenSim.ini");
                 throw new Exception("Estate connector init error");
             }
 
-            string serviceURI = gridConfig.GetString("EstateServerURI",
-                    String.Empty);
-
+            string serviceURI = gridConfig.GetString("EstateServerURI", string.Empty);
             if (serviceURI.Length == 0)
             {
                 m_log.Error("[ESTATE CONNECTOR]: No Server URI named in section EstateService");
@@ -84,45 +78,41 @@ namespace OpenSim.Services.Connectors
 
         public List<EstateSettings> LoadEstateSettingsAll()
         {
-            string reply = string.Empty;
             string uri = m_ServerURI + "/estates";
-
-            reply = MakeRequest("GET", uri, string.Empty);
+            string reply = MakeRequest("GET", uri, string.Empty);
             if (String.IsNullOrEmpty(reply))
-                return new List<EstateSettings>();
+                return [];
 
             Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
-
-            List<EstateSettings> estates = new List<EstateSettings>();
             if (replyData != null && replyData.Count > 0)
             {
-                m_log.DebugFormat("[ESTATE CONNECTOR]: LoadEstateSettingsAll returned {0} elements", replyData.Count);
+                m_log.Debug($"[ESTATE CONNECTOR]: LoadEstateSettingsAll returned {replyData.Count} elements");
                 Dictionary<string, object>.ValueCollection estateData = replyData.Values;
+                List<EstateSettings> estates = [];
                 foreach (object r in estateData)
                 {
-                    if (r is Dictionary<string, object>)
+                    if (r is Dictionary<string, object> dr )
                     {
-                        EstateSettings es = new EstateSettings((Dictionary<string, object>)r);
+                        EstateSettings es = new EstateSettings(dr);
                         estates.Add(es);
                     }
                 }
                 m_EstateCache.AddOrUpdate("estates", estates, EXPIRATION);
+                return estates;
             }
             else
-                m_log.DebugFormat("[ESTATE CONNECTOR]: LoadEstateSettingsAll from {0} received null or zero response", uri);
-
-            return estates;
+                m_log.Debug($"[ESTATE CONNECTOR]: LoadEstateSettingsAll from {uri} received empty response");
 
+            return [];
         }
 
         public List<int> GetEstatesAll()
         {
-            List<int> eids = new List<int>();
             // If we don't have them, load them from the server
-            List<EstateSettings> estates = null;
-            if (!m_EstateCache.TryGetValue("estates", out estates))
+            if (!m_EstateCache.TryGetValue("estates", out List<EstateSettings> estates))
                 estates = LoadEstateSettingsAll();
 
+            List<int> eids = [];
             foreach (EstateSettings es in estates)
                 eids.Add((int)es.EstateID);
 
@@ -132,11 +122,10 @@ namespace OpenSim.Services.Connectors
         public List<int> GetEstates(string search)
         {
             // If we don't have them, load them from the server
-            List<EstateSettings> estates = null;
-            if (!m_EstateCache.TryGetValue("estates", out estates))
+            if (!m_EstateCache.TryGetValue("estates", out List<EstateSettings> estates))
                 estates = LoadEstateSettingsAll();
 
-            List<int> eids = new List<int>();
+            List<int> eids = [];
             foreach (EstateSettings es in estates)
                 if (es.EstateName == search)
                     eids.Add((int)es.EstateID);
@@ -147,13 +136,12 @@ namespace OpenSim.Services.Connectors
         public List<int> GetEstatesByOwner(UUID ownerID)
         {
             // If we don't have them, load them from the server
-            List<EstateSettings> estates = null;
-            if (!m_EstateCache.TryGetValue("estates", out estates))
+            if (!m_EstateCache.TryGetValue("estates", out List<EstateSettings> estates))
                 estates = LoadEstateSettingsAll();
 
-            List<int> eids = new List<int>();
+            List<int> eids = [];
             foreach (EstateSettings es in estates)
-                if (es.EstateOwner == ownerID)
+                if (es.EstateOwner.Equals(ownerID))
                     eids.Add((int)es.EstateID);
 
             return eids;
@@ -161,49 +149,36 @@ namespace OpenSim.Services.Connectors
 
         public List<UUID> GetRegions(int estateID)
         {
-            string reply = string.Empty;
             // /estates/regions/?eid=int
             string uri = m_ServerURI + "/estates/regions/?eid=" + estateID.ToString();
 
-            reply = MakeRequest("GET", uri, string.Empty);
+            string reply = MakeRequest("GET", uri, string.Empty);
             if (String.IsNullOrEmpty(reply))
-                return new List<UUID>();
+                return [];
 
             Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
-
-            List<UUID> regions = new List<UUID>();
             if (replyData != null && replyData.Count > 0)
             {
-                m_log.DebugFormat("[ESTATE CONNECTOR]: GetRegions for estate {0} returned {1} elements", estateID, replyData.Count);
+                m_log.Debug($"[ESTATE CONNECTOR]: GetRegions for estate {estateID} returned {replyData.Count} elements");
+                List<UUID> regions = [];
                 Dictionary<string, object>.ValueCollection data = replyData.Values;
                 foreach (object r in data)
                 {
-                    UUID uuid = UUID.Zero;
-                    if (UUID.TryParse(r.ToString(), out uuid))
+                    if (UUID.TryParse(r.ToString(), out UUID uuid))
                         regions.Add(uuid);
                 }
+                return regions;
             }
             else
-                m_log.DebugFormat("[ESTATE CONNECTOR]: GetRegions from {0} received null or zero response", uri);
-
-            return regions;
+                m_log.Debug($"[ESTATE CONNECTOR]: GetRegions from {uri} received null or zero response");
+            return [];
         }
 
         public EstateSettings LoadEstateSettings(UUID regionID, bool create)
         {
-            string reply = string.Empty;
             // /estates/estate/?region=uuid&create=[t|f]
-            string uri = m_ServerURI + string.Format("/estates/estate/?region={0}&create={1}", regionID, create);
-
-            reply = MakeRequest("GET", uri, string.Empty);
-            if(reply == null)
-            {
-                // this is a fatal error
-                m_log.DebugFormat("[ESTATE CONNECTOR] connection to remote estates service failed");
-                m_log.DebugFormat("[ESTATE CONNECTOR] simulator needs to terminate");
-                Environment.Exit(-1);
-            }
-
+            string uri = m_ServerURI + $"/estates/estate/?region={regionID}&create={create}";
+            string reply = MakeRequest("GET", uri, string.Empty);
             if (String.IsNullOrEmpty(reply))
                 return null;
 
@@ -223,11 +198,10 @@ namespace OpenSim.Services.Connectors
 
         public EstateSettings LoadEstateSettings(int estateID)
         {
-            string reply = string.Empty;
             // /estates/estate/?eid=int
-            string uri = m_ServerURI + string.Format("/estates/estate/?eid={0}", estateID);
+            string uri = m_ServerURI + $"/estates/estate/?eid={estateID}";
 
-            reply = MakeRequest("GET", uri, string.Empty);
+            string reply = MakeRequest("GET", uri, string.Empty);
             if (String.IsNullOrEmpty(reply))
                 return null;
 
@@ -235,7 +209,7 @@ namespace OpenSim.Services.Connectors
 
             if (replyData != null && replyData.Count > 0)
             {
-                m_log.DebugFormat("[ESTATE CONNECTOR]: LoadEstateSettings({0}) returned {1} elements", estateID, replyData.Count);
+                m_log.Debug($"[ESTATE CONNECTOR]: LoadEstateSettings({estateID}) returned {replyData.Count} elements");
                 EstateSettings es = new EstateSettings(replyData);
                 return es;
             }
@@ -258,7 +232,7 @@ namespace OpenSim.Services.Connectors
         public void StoreEstateSettings(EstateSettings es)
         {
             // /estates/estate/
-            string uri = m_ServerURI + ("/estates/estate");
+            string uri = m_ServerURI + "/estates/estate";
 
             Dictionary<string, object> formdata = es.ToMap();
             formdata["OP"] = "STORE";
@@ -269,10 +243,12 @@ namespace OpenSim.Services.Connectors
         public bool LinkRegion(UUID regionID, int estateID)
         {
             // /estates/estate/?eid=int&region=uuid
-            string uri = m_ServerURI + String.Format("/estates/estate/?eid={0}&region={1}", estateID, regionID);
+            string uri = m_ServerURI + $"/estates/estate/?eid={estateID}&region={regionID}";
 
-            Dictionary<string, object> formdata = new Dictionary<string, object>();
-            formdata["OP"] = "LINK";
+            Dictionary<string, object> formdata = new()
+            {
+                ["OP"] = "LINK"
+            };
             return PostRequest(uri, formdata);
         }
 
@@ -285,20 +261,21 @@ namespace OpenSim.Services.Connectors
                 return false;
 
             Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
-
-            bool result = false;
             if (replyData != null && replyData.Count > 0)
             {
-                if (replyData.ContainsKey("Result"))
+                if (replyData.TryGetValue("Result", out object ortmp) && ortmp is string srtmp)
                 {
-                    if (Boolean.TryParse(replyData["Result"].ToString(), out result))
-                        m_log.DebugFormat("[ESTATE CONNECTOR]: PostRequest {0} returned {1}", uri, result);
+                    if (bool.TryParse(srtmp, out  bool result))
+                    {
+                        m_log.Debug($"[ESTATE CONNECTOR]: PostRequest {uri} returned {result}");
+                        return result;
+                    }
                 }
             }
             else
-                m_log.DebugFormat("[ESTATE CONNECTOR]: PostRequest {0} received null or zero response", uri);
+                m_log.Debug($"[ESTATE CONNECTOR]: PostRequest {uri} received empty response");
 
-            return result;
+            return false;
         }
 
         /// <summary>
@@ -326,22 +303,20 @@ namespace OpenSim.Services.Connectors
                 {
                     if (status == HttpStatusCode.Unauthorized)
                     {
-                        m_log.Error(string.Format("[ESTATE CONNECTOR]: Web request {0} requires authentication ", uri));
+                        m_log.Error($"[ESTATE CONNECTOR]: Web request {uri} requires authentication ");
                     }
                     else if (status != HttpStatusCode.NotFound)
                     {
-                        m_log.Error(string.Format("[ESTATE CONNECTOR]: Resource {0} not found ", uri));
+                        m_log.Error($"[ESTATE CONNECTOR]: Resource {uri} not found ");
                         return reply;
                     }
                 }
                 else
-                    m_log.Error(string.Format(
-                        "[ESTATE CONNECTOR]: WebException for {0} {1} {2} {3}",
-                        verb, uri, formdata, e.Message));
+                    m_log.Error($"[ESTATE CONNECTOR]: WebException for {verb} {uri} {formdata} {e.Message}");
             }
             catch (Exception e)
             {
-                m_log.DebugFormat("[ESTATE CONNECTOR]: Exception when contacting estate server at {0}: {1}", uri, e.Message);
+                m_log.DebugFormat($"[ESTATE CONNECTOR]: Exception when contacting estate server at {uri}: {e.Message}");
             }
 
             return null;