diff options
author | Justin Clark-Casey (justincc) | 2012-03-28 23:40:25 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-03-28 23:40:25 +0100 |
commit | d9f7b8549b3cb9699eb8bd54242d31aac0f8241a (patch) | |
tree | d58aaac2914a63dd459931a31b17b16f1d0e34d9 | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC-d9f7b8549b3cb9699eb8bd54242d31aac0f8241a.zip opensim-SC-d9f7b8549b3cb9699eb8bd54242d31aac0f8241a.tar.gz opensim-SC-d9f7b8549b3cb9699eb8bd54242d31aac0f8241a.tar.bz2 opensim-SC-d9f7b8549b3cb9699eb8bd54242d31aac0f8241a.tar.xz |
Simplify friends caching by only doing this for root agents - no functions require caching for child agents.
This allows us to avoid unnecessary multiple calls to the friends service.
All friends functions originate from the root agent and only go to other root agents in existing code.
This also allows us to eliminate complex ref counting.
Diffstat (limited to '')
9 files changed, 31 insertions, 55 deletions
diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 3f560d0..1e36b06 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs | |||
@@ -710,7 +710,7 @@ namespace OpenSim.Framework | |||
710 | /// The scene agent for this client. This will only be set if the client has an agent in a scene (i.e. if it | 710 | /// The scene agent for this client. This will only be set if the client has an agent in a scene (i.e. if it |
711 | /// is connected). | 711 | /// is connected). |
712 | /// </summary> | 712 | /// </summary> |
713 | ISceneAgent SceneAgent { get; } | 713 | ISceneAgent SceneAgent { get; set; } |
714 | 714 | ||
715 | UUID SessionId { get; } | 715 | UUID SessionId { get; } |
716 | 716 | ||
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index cd81df5..9899669 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | |||
@@ -384,7 +384,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
384 | set { m_startpos = value; } | 384 | set { m_startpos = value; } |
385 | } | 385 | } |
386 | public UUID AgentId { get { return m_agentId; } } | 386 | public UUID AgentId { get { return m_agentId; } } |
387 | public ISceneAgent SceneAgent { get; private set; } | 387 | public ISceneAgent SceneAgent { get; set; } |
388 | public UUID ActiveGroupId { get { return m_activeGroupID; } } | 388 | public UUID ActiveGroupId { get { return m_activeGroupID; } } |
389 | public string ActiveGroupName { get { return m_activeGroupName; } } | 389 | public string ActiveGroupName { get { return m_activeGroupName; } } |
390 | public ulong ActiveGroupPowers { get { return m_activeGroupPowers; } } | 390 | public ulong ActiveGroupPowers { get { return m_activeGroupPowers; } } |
@@ -695,7 +695,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
695 | 695 | ||
696 | public virtual void Start() | 696 | public virtual void Start() |
697 | { | 697 | { |
698 | SceneAgent = m_scene.AddNewClient(this, PresenceType.User); | 698 | m_scene.AddNewClient(this, PresenceType.User); |
699 | 699 | ||
700 | RefreshGroupMembership(); | 700 | RefreshGroupMembership(); |
701 | } | 701 | } |
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index d1a1af0..f3982ea 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | |||
@@ -57,7 +57,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
57 | { | 57 | { |
58 | public UUID PrincipalID; | 58 | public UUID PrincipalID; |
59 | public FriendInfo[] Friends; | 59 | public FriendInfo[] Friends; |
60 | public int Refcount; | ||
61 | 60 | ||
62 | public bool IsFriend(string friend) | 61 | public bool IsFriend(string friend) |
63 | { | 62 | { |
@@ -255,6 +254,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
255 | 254 | ||
256 | private void OnNewClient(IClientAPI client) | 255 | private void OnNewClient(IClientAPI client) |
257 | { | 256 | { |
257 | if (client.SceneAgent.IsChildAgent) | ||
258 | return; | ||
259 | |||
258 | client.OnInstantMessage += OnInstantMessage; | 260 | client.OnInstantMessage += OnInstantMessage; |
259 | client.OnApproveFriendRequest += OnApproveFriendRequest; | 261 | client.OnApproveFriendRequest += OnApproveFriendRequest; |
260 | client.OnDenyFriendRequest += OnDenyFriendRequest; | 262 | client.OnDenyFriendRequest += OnDenyFriendRequest; |
@@ -281,23 +283,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
281 | UUID agentID = client.AgentId; | 283 | UUID agentID = client.AgentId; |
282 | lock (m_Friends) | 284 | lock (m_Friends) |
283 | { | 285 | { |
284 | UserFriendData friendsData; | 286 | UserFriendData friendsData = new UserFriendData(); |
285 | if (m_Friends.TryGetValue(agentID, out friendsData)) | 287 | friendsData.PrincipalID = agentID; |
286 | { | 288 | friendsData.Friends = GetFriendsFromService(client); |
287 | friendsData.Refcount++; | ||
288 | return false; | ||
289 | } | ||
290 | else | ||
291 | { | ||
292 | friendsData = new UserFriendData(); | ||
293 | friendsData.PrincipalID = agentID; | ||
294 | friendsData.Friends = GetFriendsFromService(client); | ||
295 | friendsData.Refcount = 1; | ||
296 | 289 | ||
297 | m_Friends[agentID] = friendsData; | 290 | m_Friends[agentID] = friendsData; |
298 | return true; | ||
299 | } | ||
300 | } | 291 | } |
292 | |||
293 | return true; | ||
301 | } | 294 | } |
302 | 295 | ||
303 | private void OnClientClosed(UUID agentID, Scene scene) | 296 | private void OnClientClosed(UUID agentID, Scene scene) |
@@ -307,23 +300,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
307 | { | 300 | { |
308 | // do this for root agents closing out | 301 | // do this for root agents closing out |
309 | StatusChange(agentID, false); | 302 | StatusChange(agentID, false); |
310 | } | ||
311 | 303 | ||
312 | lock (m_Friends) | 304 | lock (m_Friends) |
313 | { | 305 | m_Friends.Remove(agentID); |
314 | UserFriendData friendsData; | ||
315 | if (m_Friends.TryGetValue(agentID, out friendsData)) | ||
316 | { | ||
317 | friendsData.Refcount--; | ||
318 | if (friendsData.Refcount <= 0) | ||
319 | m_Friends.Remove(agentID); | ||
320 | } | ||
321 | } | 306 | } |
322 | } | 307 | } |
323 | 308 | ||
324 | private void OnMakeRootAgent(ScenePresence sp) | 309 | private void OnMakeRootAgent(ScenePresence sp) |
325 | { | 310 | { |
326 | RecacheFriends(sp.ControllingClient); | 311 | // FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event |
312 | // is on the critical path for transferring an avatar from one region to another. | ||
313 | CacheFriends(sp.ControllingClient); | ||
327 | } | 314 | } |
328 | 315 | ||
329 | private void OnClientLogin(IClientAPI client) | 316 | private void OnClientLogin(IClientAPI client) |
@@ -623,7 +610,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
623 | StoreFriendships(client.AgentId, friendID); | 610 | StoreFriendships(client.AgentId, friendID); |
624 | 611 | ||
625 | // Update the local cache. | 612 | // Update the local cache. |
626 | RecacheFriends(client); | 613 | CacheFriends(client); |
627 | 614 | ||
628 | // | 615 | // |
629 | // Notify the friend | 616 | // Notify the friend |
@@ -685,7 +672,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
685 | client.SendAlertMessage("Unable to terminate friendship on this sim."); | 672 | client.SendAlertMessage("Unable to terminate friendship on this sim."); |
686 | 673 | ||
687 | // Update local cache | 674 | // Update local cache |
688 | RecacheFriends(client); | 675 | CacheFriends(client); |
689 | 676 | ||
690 | client.SendTerminateFriend(exfriendID); | 677 | client.SendTerminateFriend(exfriendID); |
691 | 678 | ||
@@ -799,7 +786,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
799 | friendClient.SendInstantMessage(im); | 786 | friendClient.SendInstantMessage(im); |
800 | 787 | ||
801 | // Update the local cache | 788 | // Update the local cache |
802 | RecacheFriends(friendClient); | 789 | CacheFriends(friendClient); |
803 | 790 | ||
804 | // we're done | 791 | // we're done |
805 | return true; | 792 | return true; |
@@ -832,7 +819,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
832 | // the friend in this sim as root agent | 819 | // the friend in this sim as root agent |
833 | friendClient.SendTerminateFriend(exfriendID); | 820 | friendClient.SendTerminateFriend(exfriendID); |
834 | // update local cache | 821 | // update local cache |
835 | RecacheFriends(friendClient); | 822 | CacheFriends(friendClient); |
836 | // we're done | 823 | // we're done |
837 | return true; | 824 | return true; |
838 | } | 825 | } |
@@ -933,19 +920,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
933 | return FriendsService.GetFriends(client.AgentId); | 920 | return FriendsService.GetFriends(client.AgentId); |
934 | } | 921 | } |
935 | 922 | ||
936 | protected void RecacheFriends(IClientAPI client) | ||
937 | { | ||
938 | // FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event | ||
939 | // is on the critical path for transferring an avatar from one region to another. | ||
940 | UUID agentID = client.AgentId; | ||
941 | lock (m_Friends) | ||
942 | { | ||
943 | UserFriendData friendsData; | ||
944 | if (m_Friends.TryGetValue(agentID, out friendsData)) | ||
945 | friendsData.Friends = GetFriendsFromService(client); | ||
946 | } | ||
947 | } | ||
948 | |||
949 | /// <summary> | 923 | /// <summary> |
950 | /// Are friends cached on this simulator for a particular user? | 924 | /// Are friends cached on this simulator for a particular user? |
951 | /// </summary> | 925 | /// </summary> |
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs index e50a84a..7bc3018 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs | |||
@@ -121,7 +121,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
121 | { | 121 | { |
122 | UUID agentID = client.AgentId; | 122 | UUID agentID = client.AgentId; |
123 | // we do this only for the root agent | 123 | // we do this only for the root agent |
124 | if (m_Friends[agentID].Refcount == 1) | 124 | if (!client.SceneAgent.IsChildAgent) |
125 | { | 125 | { |
126 | // We need to preload the user management cache with the names | 126 | // We need to preload the user management cache with the names |
127 | // of foreign friends, just like we do with SOPs' creators | 127 | // of foreign friends, just like we do with SOPs' creators |
@@ -426,14 +426,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
426 | agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode); | 426 | agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode); |
427 | agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit); | 427 | agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit); |
428 | agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); | 428 | agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); |
429 | RecacheFriends(agentClient); | 429 | CacheFriends(agentClient); |
430 | } | 430 | } |
431 | if (friendClient != null) | 431 | if (friendClient != null) |
432 | { | 432 | { |
433 | friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode); | 433 | friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode); |
434 | friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit); | 434 | friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit); |
435 | friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); | 435 | friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); |
436 | RecacheFriends(friendClient); | 436 | CacheFriends(friendClient); |
437 | } | 437 | } |
438 | 438 | ||
439 | m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", | 439 | m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", |
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index 7993abe..fe3438e 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs | |||
@@ -71,6 +71,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
71 | /// Triggered when a new client is added to the scene. | 71 | /// Triggered when a new client is added to the scene. |
72 | /// </summary> | 72 | /// </summary> |
73 | /// <remarks> | 73 | /// <remarks> |
74 | /// This is triggered for both child and root agent client connections. | ||
74 | /// Triggered before OnClientLogin. | 75 | /// Triggered before OnClientLogin. |
75 | /// </remarks> | 76 | /// </remarks> |
76 | public event OnNewClientDelegate OnNewClient; | 77 | public event OnNewClientDelegate OnNewClient; |
@@ -191,7 +192,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
191 | public delegate void ClientClosed(UUID clientID, Scene scene); | 192 | public delegate void ClientClosed(UUID clientID, Scene scene); |
192 | 193 | ||
193 | /// <summary> | 194 | /// <summary> |
194 | /// Fired when a client is removed from a scene. | 195 | /// Fired when a client is removed from a scene whether it's a child or a root agent. |
195 | /// </summary> | 196 | /// </summary> |
196 | /// <remarks> | 197 | /// <remarks> |
197 | /// At the point of firing, the scene still contains the client's scene presence. | 198 | /// At the point of firing, the scene still contains the client's scene presence. |
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index c887b4e..60fe48f 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs | |||
@@ -2670,6 +2670,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2670 | sp.IsChildAgent ? "child" : "root", sp.Name, RegionInfo.RegionName); | 2670 | sp.IsChildAgent ? "child" : "root", sp.Name, RegionInfo.RegionName); |
2671 | } | 2671 | } |
2672 | 2672 | ||
2673 | client.SceneAgent = sp; | ||
2673 | m_LastLogin = Util.EnvironmentTickCount(); | 2674 | m_LastLogin = Util.EnvironmentTickCount(); |
2674 | 2675 | ||
2675 | // Cache the user's name | 2676 | // Cache the user's name |
diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs index 5cf478a..43548e6 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs | |||
@@ -55,7 +55,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server | |||
55 | 55 | ||
56 | private UUID m_agentID = UUID.Random(); | 56 | private UUID m_agentID = UUID.Random(); |
57 | 57 | ||
58 | public ISceneAgent SceneAgent { get; private set; } | 58 | public ISceneAgent SceneAgent { get; set; } |
59 | 59 | ||
60 | private string m_username; | 60 | private string m_username; |
61 | private string m_nick; | 61 | private string m_nick; |
@@ -895,7 +895,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server | |||
895 | 895 | ||
896 | public void Start() | 896 | public void Start() |
897 | { | 897 | { |
898 | SceneAgent = m_scene.AddNewClient(this, PresenceType.User); | 898 | m_scene.AddNewClient(this, PresenceType.User); |
899 | 899 | ||
900 | // Mimicking LLClientView which gets always set appearance from client. | 900 | // Mimicking LLClientView which gets always set appearance from client. |
901 | AvatarAppearance appearance; | 901 | AvatarAppearance appearance; |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 16ec34f..5ea5af7 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs | |||
@@ -72,7 +72,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
72 | get { return m_ownerID; } | 72 | get { return m_ownerID; } |
73 | } | 73 | } |
74 | 74 | ||
75 | public ISceneAgent SceneAgent { get { throw new NotImplementedException(); } } | 75 | public ISceneAgent SceneAgent { get; set; } |
76 | 76 | ||
77 | public void Say(string message) | 77 | public void Say(string message) |
78 | { | 78 | { |
diff --git a/OpenSim/Tests/Common/Mock/TestClient.cs b/OpenSim/Tests/Common/Mock/TestClient.cs index 455b51e..d6e7200 100644 --- a/OpenSim/Tests/Common/Mock/TestClient.cs +++ b/OpenSim/Tests/Common/Mock/TestClient.cs | |||
@@ -327,7 +327,7 @@ namespace OpenSim.Tests.Common.Mock | |||
327 | /// </value> | 327 | /// </value> |
328 | private UUID m_agentId; | 328 | private UUID m_agentId; |
329 | 329 | ||
330 | public ISceneAgent SceneAgent { get { throw new NotImplementedException(); } } | 330 | public ISceneAgent SceneAgent { get; set; } |
331 | 331 | ||
332 | /// <value> | 332 | /// <value> |
333 | /// The last caps seed url that this client was given. | 333 | /// The last caps seed url that this client was given. |