Fix the presence info caching used in llRequestAgentData(), which was completely inoperative.

This means the presence info may be out of date by up to 20 seconds, but this avoids scripts potentially triggering constants requests to user accout and presence info services.
Relates to http://opensimulator.org/mantis/view.php?id=7088 though I fixed in a different way.
Adds regression test for this case.
0.8.0.3
Justin Clark-Casey (justincc) 2014-04-11 00:20:05 +01:00
parent 562a3cb338
commit 530c86335d
3 changed files with 96 additions and 63 deletions

View File

@ -40,7 +40,7 @@ namespace OpenSim.Data.Null
{ {
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static NullPresenceData Instance; public static NullPresenceData Instance;
Dictionary<UUID, PresenceData> m_presenceData = new Dictionary<UUID, PresenceData>(); Dictionary<UUID, PresenceData> m_presenceData = new Dictionary<UUID, PresenceData>();

View File

@ -87,6 +87,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public int LlRequestAgentDataCacheTimeoutMs { get; set; }
protected IScriptEngine m_ScriptEngine; protected IScriptEngine m_ScriptEngine;
protected SceneObjectPart m_host; protected SceneObjectPart m_host;
@ -160,30 +162,44 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
/// </summary> /// </summary>
private void LoadConfig() private void LoadConfig()
{ {
m_ScriptDelayFactor = LlRequestAgentDataCacheTimeoutMs = 20000;
m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
m_ScriptDistanceFactor = IConfig seConfig = m_ScriptEngine.Config;
m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
m_MinTimerInterval = if (seConfig != null)
m_ScriptEngine.Config.GetFloat("MinTimerInterval", 0.5f); {
m_automaticLinkPermission = m_ScriptDelayFactor =
m_ScriptEngine.Config.GetBoolean("AutomaticLinkPermission", false); seConfig.GetFloat("ScriptDelayFactor", m_ScriptDelayFactor);
m_notecardLineReadCharsMax = m_ScriptDistanceFactor =
m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255); seConfig.GetFloat("ScriptDistanceLimitFactor", m_ScriptDistanceFactor);
m_MinTimerInterval =
seConfig.GetFloat("MinTimerInterval", m_MinTimerInterval);
m_automaticLinkPermission =
seConfig.GetBoolean("AutomaticLinkPermission", m_automaticLinkPermission);
m_notecardLineReadCharsMax =
seConfig.GetInt("NotecardLineReadCharsMax", m_notecardLineReadCharsMax);
// Rezzing an object with a velocity can create recoil. This feature seems to have been
// removed from recent versions of SL. The code computes recoil (vel*mass) and scales
// it by this factor. May be zero to turn off recoil all together.
m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor);
}
if (m_notecardLineReadCharsMax > 65535) if (m_notecardLineReadCharsMax > 65535)
m_notecardLineReadCharsMax = 65535; m_notecardLineReadCharsMax = 65535;
// load limits for particular subsystems. // load limits for particular subsystems.
IConfig SMTPConfig; IConfigSource seConfigSource = m_ScriptEngine.ConfigSource;
if ((SMTPConfig = m_ScriptEngine.ConfigSource.Configs["SMTP"]) != null) {
// there's an smtp config, so load in the snooze time.
EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
}
// Rezzing an object with a velocity can create recoil. This feature seems to have been if (seConfigSource != null)
// removed from recent versions of SL. The code computes recoil (vel*mass) and scales {
// it by this factor. May be zero to turn off recoil all together. IConfig smtpConfig = seConfigSource.Configs["SMTP"];
m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor); if (smtpConfig != null)
{
// there's an smtp config, so load in the snooze time.
EMAIL_PAUSE_TIME = smtpConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
}
}
} }
public override Object InitializeLifetimeService() public override Object InitializeLifetimeService()
@ -4196,60 +4212,71 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
UserAccount account; UserAccount account;
UserInfoCacheEntry ce; UserInfoCacheEntry ce;
if (!m_userInfoCache.TryGetValue(uuid, out ce))
lock (m_userInfoCache)
{ {
account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); if (!m_userInfoCache.TryGetValue(uuid, out ce))
if (account == null)
{ {
m_userInfoCache[uuid] = null; // Cache negative account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
return UUID.Zero.ToString(); if (account == null)
}
PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
if (pinfos != null && pinfos.Length > 0)
{
foreach (PresenceInfo p in pinfos)
{ {
if (p.RegionID != UUID.Zero) m_userInfoCache[uuid] = null; // Cache negative
return UUID.Zero.ToString();
}
PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
if (pinfos != null && pinfos.Length > 0)
{
foreach (PresenceInfo p in pinfos)
{ {
pinfo = p; if (p.RegionID != UUID.Zero)
{
pinfo = p;
}
} }
} }
}
ce = new UserInfoCacheEntry(); ce = new UserInfoCacheEntry();
ce.time = Util.EnvironmentTickCount(); ce.time = Util.EnvironmentTickCount();
ce.account = account; ce.account = account;
ce.pinfo = pinfo; ce.pinfo = pinfo;
}
else
{
if (ce == null)
return UUID.Zero.ToString();
account = ce.account; m_userInfoCache[uuid] = ce;
pinfo = ce.pinfo;
}
if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000)
{
PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
if (pinfos != null && pinfos.Length > 0)
{
foreach (PresenceInfo p in pinfos)
{
if (p.RegionID != UUID.Zero)
{
pinfo = p;
}
}
} }
else else
pinfo = null; {
if (ce == null)
return UUID.Zero.ToString();
ce.time = Util.EnvironmentTickCount(); account = ce.account;
ce.pinfo = pinfo;
if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time)
>= LlRequestAgentDataCacheTimeoutMs)
{
PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
if (pinfos != null && pinfos.Length > 0)
{
foreach (PresenceInfo p in pinfos)
{
if (p.RegionID != UUID.Zero)
{
pinfo = p;
}
}
}
else
{
pinfo = null;
}
ce.time = Util.EnvironmentTickCount();
ce.pinfo = pinfo;
}
else
{
pinfo = ce.pinfo;
}
}
} }
string reply = String.Empty; string reply = String.Empty;

View File

@ -30,6 +30,7 @@ using System.Net;
using System.Collections.Generic; using System.Collections.Generic;
using Nini.Config; using Nini.Config;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Data.Null;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Communications; using OpenSim.Framework.Communications;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
@ -301,6 +302,11 @@ namespace OpenSim.Tests.Common
/// <param name="testScene"></param> /// <param name="testScene"></param>
private static LocalPresenceServicesConnector StartPresenceService() private static LocalPresenceServicesConnector StartPresenceService()
{ {
// Unfortunately, some services share data via statics, so we need to null every time to stop interference
// between tests.
// This is a massive non-obvious pita.
NullPresenceData.Instance = null;
IConfigSource config = new IniConfigSource(); IConfigSource config = new IniConfigSource();
config.AddConfig("Modules"); config.AddConfig("Modules");
config.AddConfig("PresenceService"); config.AddConfig("PresenceService");