Compare commits

..

9 Commits

Author SHA1 Message Date
UbitUmarov
d829644650 reduce unnecessary saves of attachments a bit 2026-06-20 01:34:33 +01:00
UbitUmarov
effb5784c1 a few changes on assets store and exists return 2026-06-19 22:47:12 +01:00
UbitUmarov
7130e30483 increase asset store web timeout to 30s again 2026-06-19 21:39:58 +01:00
UbitUmarov
ecdcaca032 cosmetics 2026-06-19 01:41:02 +01:00
UbitUmarov
2720a1db36 change the rebakes throotle code 2026-06-16 21:56:11 +01:00
UbitUmarov
60a32d28e4 add AddOrUpdate to ExpiringKey 2026-06-16 21:41:15 +01:00
Ubit Umarov
8a95a4dfe0 Merge pull request #41 from holoneon/patch-3
Update AvatarFactoryModule.cs
2026-06-16 20:54:32 +01:00
UbitUmarov
282db7dd1e update libomv 2026-06-16 19:09:47 +01:00
Fiona Sweet
dae81f7bf5 Update AvatarFactoryModule.cs
in logs i have noticed thousands of 'rebake' requests happening extremely rapidly from a few hg visitors, (for example yesterday 2400 from one hg visitor in 3 minutes) a potential denial of service vector. this adds throttling limit 1 per 30 seconds.  please review
2026-06-15 12:53:52 -07:00
30 changed files with 120 additions and 106 deletions

View File

@@ -253,7 +253,7 @@ namespace OpenSim.Data.MySQL
public override bool[] AssetsExist(UUID[] uuids)
{
if (uuids.Length == 0)
return new bool[0];
return [];
HashSet<UUID> exist = new HashSet<UUID>();

View File

@@ -401,7 +401,7 @@ namespace OpenSim.Data.MySQL
public bool[] AssetsExist(UUID[] uuids)
{
if (uuids.Length == 0)
return new bool[0];
return [];
HashSet<UUID> exists = new HashSet<UUID>();

View File

@@ -239,7 +239,7 @@ namespace OpenSim.Data.PGSQL
public override bool[] AssetsExist(UUID[] uuids)
{
if (uuids.Length == 0)
return new bool[0];
return [];
HashSet<UUID> exist = new HashSet<UUID>();

View File

@@ -147,7 +147,8 @@ namespace OpenSim.Data.SQLite
}
//m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString());
if (AssetsExist(new[] { asset.FullID })[0])
bool[] assetsExist = AssetsExist([ asset.FullID ]);
if (assetsExist.Length > 0 && assetsExist[0])
{
//LogAssetLoad(asset);
@@ -218,7 +219,7 @@ namespace OpenSim.Data.SQLite
public override bool[] AssetsExist(UUID[] uuids)
{
if (uuids.Length == 0)
return new bool[0];
return [];
HashSet<UUID> exist = new HashSet<UUID>();

View File

@@ -916,18 +916,17 @@ namespace OpenSim.Framework
{
// Wearables
OSD tmpOSD8;
OSDArray wears8 = null;
int wears8Count = 0;
if (data.TryGetValue("wrbls8", out tmpOSD8) && (tmpOSD8 is OSDArray))
if (data.TryGetValue("wrbls8", out tmpOSD8) && (tmpOSD8 is OSDArray wears8))
{
wears8 = (OSDArray)tmpOSD8;
wears8Count = wears8.Count;
}
else
wears8 = null;
if (data.TryGetValue("wearables", out tmpOSD) && (tmpOSD is OSDArray))
if (data.TryGetValue("wearables", out tmpOSD) && (tmpOSD is OSDArray wears))
{
OSDArray wears = (OSDArray)tmpOSD;
if(wears.Count + wears8Count > 0)
{
m_wearables = new AvatarWearable[wears.Count + wears8Count];
@@ -948,9 +947,8 @@ namespace OpenSim.Framework
Primitive.TextureEntry te = new Primitive.TextureEntry(teb, 0, teb.Length);
m_texture = te;
}
else if (data.TryGetValue("textures", out tmpOSD) && (tmpOSD is OSDArray))
else if (data.TryGetValue("textures", out tmpOSD) && (tmpOSD is OSDArray textures))
{
OSDArray textures = (OSDArray)tmpOSD;
for (int i = 0; i < textures.Count && i < TEXTURE_COUNT_PV7; ++i)
{
tmpOSD = textures[i];
@@ -959,26 +957,12 @@ namespace OpenSim.Framework
}
}
if (data.TryGetValue("bakedcache", out tmpOSD) && (tmpOSD is OSDArray))
if (data.TryGetValue("bakedcache", out tmpOSD) && (tmpOSD is OSDArray bakedOSDArray))
{
OSDArray bakedOSDArray = (OSDArray)tmpOSD;
m_cacheitems = WearableCacheItem.GetDefaultCacheItem();
bakedOSDArray = (OSDArray)tmpOSD;
foreach (OSDMap item in bakedOSDArray)
foreach (OSD oitem in bakedOSDArray)
{
int idx = item["textureindex"].AsInteger();
if (idx < 0 || idx >= m_cacheitems.Length)
continue;
m_cacheitems[idx].CacheId = item["cacheid"].AsUUID();
m_cacheitems[idx].TextureID = item["textureid"].AsUUID();
m_cacheitems[idx].TextureAsset = null;
}
if (data.TryGetValue("bc8", out tmpOSD) && (tmpOSD is OSDArray))
{
bakedOSDArray = (OSDArray)tmpOSD;
foreach (OSDMap item in bakedOSDArray)
if(oitem is OSDMap item)
{
int idx = item["textureindex"].AsInteger();
if (idx < 0 || idx >= m_cacheitems.Length)
@@ -988,6 +972,22 @@ namespace OpenSim.Framework
m_cacheitems[idx].TextureAsset = null;
}
}
if (data.TryGetValue("bc8", out tmpOSD) && (tmpOSD is OSDArray))
{
foreach (OSD oitem in bakedOSDArray)
{
if(oitem is OSDMap item)
{
int idx = item["textureindex"].AsInteger();
if (idx < 0 || idx >= m_cacheitems.Length)
continue;
m_cacheitems[idx].CacheId = item["cacheid"].AsUUID();
m_cacheitems[idx].TextureID = item["textureid"].AsUUID();
m_cacheitems[idx].TextureAsset = null;
}
}
}
}
// Visual Parameters
@@ -1002,9 +1002,8 @@ namespace OpenSim.Framework
}
// Attachments
if (data.TryGetValue("attachments", out tmpOSD) && tmpOSD is OSDArray)
if (data.TryGetValue("attachments", out tmpOSD) && tmpOSD is OSDArray attachs)
{
OSDArray attachs = (OSDArray)tmpOSD;
for (int i = 0; i < attachs.Count; i++)
{
AvatarAttachment att = new AvatarAttachment((OSDMap)attachs[i]);

View File

@@ -28,6 +28,7 @@ using System;
using System.Threading;
using System.Collections.Generic;
using Timer = System.Threading.Timer ;
using System.Runtime.InteropServices;
namespace OpenSim.Framework
{
@@ -168,6 +169,28 @@ namespace OpenSim.Framework
finally { m_rwLock.ExitWriteLock(); }
}
public bool AddOrUpdate(Tkey1 key, int 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_rwLock.EnterWriteLock();
try
{
ref int entry = ref CollectionsMarshal.GetValueRefOrAddDefault(m_dictionary, key, out bool exists);
entry = now;
CheckTimer();
return exists;
}
finally { m_rwLock.ExitWriteLock(); }
}
public bool Remove(Tkey1 key)
{
m_rwLock.EnterWriteLock();

View File

@@ -81,8 +81,7 @@ namespace OpenSim.Framework
public Lazy(Func<T> valueFactory, LazyThreadSafetyMode mode)
{
if (valueFactory == null)
throw new ArgumentNullException("valueFactory");
ArgumentNullException.ThrowIfNull(valueFactory);
this.factory = valueFactory;
if (mode != LazyThreadSafetyMode.None)
monitor = new object();

View File

@@ -212,6 +212,7 @@ namespace OpenSim.Framework.Servers.HttpServer
{
set { m_certificateValidationCallback = value; }
}
private static readonly char[] LineSeparators = ['\n','\r'];
private void load_cert(string CPath, string CPass)
{
@@ -223,13 +224,13 @@ namespace OpenSim.Framework.Servers.HttpServer
{
AsnEncodedData asndata = new AsnEncodedData(ext.Oid, ext.RawData);
string datastr = asndata.Format(true);
string[] lines = datastr.Split(new char[] {'\n','\r'});
string[] lines = datastr.Split(LineSeparators);
foreach(string s in lines)
{
if(String.IsNullOrEmpty(s))
if(string.IsNullOrEmpty(s))
continue;
string[] parts = s.Split(new char[] {'='});
if(String.IsNullOrEmpty(parts[0]))
string[] parts = s.Split('=');
if(string.IsNullOrEmpty(parts[0]))
continue;
string entryName = parts[0].Replace(" ","");
if(entryName == "DNSName")
@@ -1015,8 +1016,7 @@ namespace OpenSim.Framework.Servers.HttpServer
}
finally
{
if (innerStream != null)
innerStream.Dispose();
innerStream?.Dispose();
inputStream.Dispose();
}
}

View File

@@ -22,7 +22,7 @@ namespace OSHttpServer
public RequestCookie(string id, string content)
{
if (string.IsNullOrEmpty(id)) throw new ArgumentNullException("id");
if (content == null) throw new ArgumentNullException("content");
ArgumentNullException.ThrowIfNull(content);
_name = id;
_value = content;

View File

@@ -79,8 +79,10 @@ namespace OpenSim.Framework.Servers.HttpServer
using (MemoryStream buffer = new MemoryStream())
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
XmlWriterSettings settings = new()
{
Encoding = Encoding.UTF8
};
using (XmlWriter writer = XmlWriter.Create(buffer, settings))
{
@@ -134,8 +136,7 @@ namespace OpenSim.Framework.Servers.HttpServer
using (MemoryStream buffer = new MemoryStream())
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
XmlWriterSettings settings = new() { Encoding = Encoding.UTF8 };
using (XmlWriter writer = XmlWriter.Create(buffer, settings))
{
@@ -169,8 +170,7 @@ namespace OpenSim.Framework.Servers.HttpServer
// m_log.DebugFormat("[REST OBJECT POSTER RESPONSE]: Received {0}", reader.ReadToEnd());
deserial = (TResponse)deserializer.Deserialize(stream);
if (stream != null)
stream.Close();
stream?.Close();
if (deserial != null && ResponseCallback != null)
{

View File

@@ -1009,8 +1009,7 @@ namespace OpenSim.Framework
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUrl);
if (auth != null)
auth.AddAuthorization(request.Headers);
auth?.AddAuthorization(request.Headers);
request.AllowWriteStreamBuffering = false;

View File

@@ -1535,10 +1535,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
catch (Exception ex)
{
m_log.Error($"Packet statistics gathering failed: {ex.Message}");
if (PacketLog.Log != null)
{
PacketLog.Log.Close();
}
PacketLog?.Log?.Close();
PacketLog = null;
}
}

View File

@@ -226,8 +226,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
}
// Pass the new values up to the parent
if (m_parent != null)
m_parent.RegisterRequest(this, Math.Min(RequestedDripRate, TotalDripRequest));
m_parent?.RegisterRequest(this, Math.Min(RequestedDripRate, TotalDripRequest));
}
/// <summary>
@@ -246,8 +245,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
}
// Pass the new values up to the parent
if (Parent != null)
Parent.RegisterRequest(this,Math.Min(RequestedDripRate, TotalDripRequest));
Parent?.RegisterRequest(this,Math.Min(RequestedDripRate, TotalDripRequest));
}
/// <summary>
@@ -351,8 +349,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{
m_dripRate = Math.Clamp(value, m_minimumFlow, MaxDripRate);
if (m_parent != null)
m_parent.RegisterRequest(this, m_dripRate);
m_parent?.RegisterRequest(this, m_dripRate);
}
}
@@ -371,8 +368,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_dripRate = m_maxDripRate * .5f;
else
m_dripRate = m_maxDripRate;
if (m_parent != null)
m_parent.RegisterRequest(this, m_dripRate);
m_parent?.RegisterRequest(this, m_dripRate);
}
/// <summary>
@@ -392,7 +388,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public void AcknowledgePackets(Int32 count)
{
if (m_enabled)
AdjustedDripRate = AdjustedDripRate + count;
AdjustedDripRate += count;
}
}
}

View File

@@ -1008,6 +1008,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
/// <param name="saveAllScripted"></param>
private void UpdateKnownItem(IScenePresence sp, SceneObjectGroup grp, string scriptedState)
{
if (sp.IsNPC)
return;
if (m_invAccessModule is null)
return;
if(!grp.HasGroupChanged)
{
if (DebugLevel > 0)
@@ -1020,20 +1026,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
grp.HasGroupChanged = false;
if (m_invAccessModule is null)
return;
if (grp.FromItemID.IsZero())
{
// We can't save temp attachments
return;
}
if (sp.IsNPC)
{
return;
}
m_log.Debug($"[ATTACHMENTS MODULE]: Updating asset for attachment {grp.UUID}, attachpoint {grp.AttachmentPoint}");
InventoryItemBase item = m_scene.InventoryService.GetItem(sp.UUID, grp.FromItemID);
@@ -1153,6 +1151,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
so.IsSelected = false; // fudge....
so.ScheduleGroupForUpdate(PrimUpdateFlags.FullUpdatewithAnimMatOvr);
so.HasGroupChanged = false;
}
// In case it is later dropped again, don't let

View File

@@ -67,6 +67,10 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
private object m_setAppearanceLock = new object();
// add throttle
private const int REBAKE_THROTTLE_SECONDS = 30;
readonly ExpiringKey<string> m_rebakeThrottle = new(500 * REBAKE_THROTTLE_SECONDS);
#region Region Module interface
public void Initialise(IConfigSource config)
@@ -451,10 +455,21 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
sp.Appearance.WearableCacheItems = wearableCache;
// throttle rebake requests
if (missing.Count > 0)
{
string spuuidstr = sp.UUID.ToString();
foreach (UUID id in missing)
{
string key = spuuidstr + id.ToString();
if(m_rebakeThrottle.AddOrUpdate(key, 1000 * REBAKE_THROTTLE_SECONDS))
continue;
m_log.Debug($"[AVFACTORY]: Missing baked texture {id} for {sp.Name}, requesting rebake");
sp.ControllingClient.SendRebakeAvatarTextures(id);
}
}
bool changed = false;

View File

@@ -314,8 +314,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
public string Store(AssetBase asset)
{
if (m_Cache != null)
m_Cache.Cache(asset);
m_Cache?.Cache(asset);
if (asset.Local)
{

View File

@@ -512,7 +512,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
return m_localConnector.AssetsExist(ids);
else if (m_HGConnector != null)
return m_HGConnector.AssetsExist(ids);
return null;
return [];
}
public string Store(AssetBase asset)
@@ -524,12 +524,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
return null;
id = StoreForeign(asset);
if (m_Cache != null)
{
if (!string.IsNullOrEmpty(id) && !id.Equals(UUID.ZeroString))
m_Cache.Cache(asset);
if (!string.IsNullOrEmpty(id) && !id.Equals(UUID.ZeroString))
{
m_Cache?.Cache(asset);
return id;
}
return id;
else
return string.Empty;
}
if (m_Cache != null)
@@ -541,10 +542,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
id = StoreLocal(asset);
if (string.IsNullOrEmpty(id))
return string.Empty;
return id;
return string.IsNullOrEmpty(id) || id.Equals(UUID.ZeroString) ? string.Empty : id;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]

View File

@@ -105,11 +105,9 @@ namespace OpenSim.Region.CoreModules
}
// Check for desired plugin
if (m_availableWindPlugins.ContainsKey(m_dWindPluginName))
if (m_availableWindPlugins.TryGetValue(m_dWindPluginName, out m_activeWindPlugin))
{
m_activeWindPlugin = m_availableWindPlugins[m_dWindPluginName];
m_log.InfoFormat("[WIND] {0} plugin found, initializing.", m_dWindPluginName);
m_log.InfoFormat("[WIND] {0} plugin found, initializing.", m_dWindPluginName);
if (m_windConfig != null)
{

View File

@@ -451,7 +451,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
assetStrings[k], existChecks[k] ? "yes" : "no");
sb.Append(cdt.ToString());
sb.Append("\n");
sb.Append('\n');
}
}
else

View File

@@ -123,8 +123,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
if (!m_Enabled)
return;
if(m_odeScene != null)
m_odeScene.RegionLoaded();
m_odeScene?.RegionLoaded();
}
#endregion

View File

@@ -1331,8 +1331,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
}
finally
{
if(stream != null)
stream.Dispose();
stream?.Dispose();
}
if (!ok && File.Exists(filename))

View File

@@ -61,8 +61,7 @@ namespace OpenSim.Services.AssetService
if (assetConfig == null)
throw new Exception("No " + m_ConfigName + " configuration");
string loaderArgs = assetConfig.GetString("AssetLoaderArgs",
String.Empty);
string loaderArgs = assetConfig.GetString("AssetLoaderArgs", string.Empty);
bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true);
@@ -92,11 +91,8 @@ namespace OpenSim.Services.AssetService
public virtual AssetBase Get(string id)
{
// m_log.DebugFormat("[ASSET SERVICE]: Get asset for {0}", id);
UUID assetID;
if (!UUID.TryParse(id, out assetID))
// m_log.DebugFormat("[ASSET SERVICE]: Get asset for {0}", id);
if (!UUID.TryParse(id, out UUID assetID))
{
m_log.WarnFormat("[ASSET SERVICE]: Could not parse requested asset id {0}", id);
return null;
@@ -172,15 +168,13 @@ namespace OpenSim.Services.AssetService
public virtual string Store(AssetBase asset)
{
bool exists = m_Database.AssetsExist(new[] { asset.FullID })[0];
if (!exists)
bool[] assetsexist = m_Database.AssetsExist([ asset.FullID ] );
if (assetsexist.Length == 0 || !assetsexist[0])
{
// m_log.DebugFormat(
// "[ASSET SERVICE]: Storing asset {0} {1}, bytes {2}", asset.Name, asset.FullID, asset.Data.Length);
if (!m_Database.StoreAsset(asset))
{
return UUID.Zero.ToString();
}
return UUID.Zero.ToString();
}
// else
// {

View File

@@ -187,9 +187,8 @@ namespace OpenSim.Services.AssetService
public virtual string Store(AssetBase asset)
{
bool exists = m_Database.AssetsExist(new[] { asset.FullID })[0];
if (!exists)
{
bool[] assetsexist = m_Database.AssetsExist([ asset.FullID ] );
if (assetsexist.Length == 0 || !assetsexist[0]) {
// m_log.DebugFormat(
// "[XASSET SERVICE]: Storing asset {0} {1}, bytes {2}", asset.Name, asset.FullID, asset.Data.Length);
m_Database.StoreAsset(asset);

View File

@@ -359,7 +359,7 @@ namespace OpenSim.Services.Connectors
string newID;
try
{
newID = SynchronousRestObjectRequester.MakeRequest<AssetBase, string>("POST", uri, asset, 10000, m_Auth);
newID = SynchronousRestObjectRequester.MakeRequest<AssetBase, string>("POST", uri, asset, 30000, m_Auth);
}
catch
{

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.