aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMike Mazur2008-07-25 07:16:27 +0000
committerMike Mazur2008-07-25 07:16:27 +0000
commit84cc69573bb522122606c3bc29c8ab188d4ccf70 (patch)
treeab7f7880d35e847726ee6a5102794ea4d8242928 /OpenSim
parentPatch #9155 (Mantis #1793) (diff)
downloadopensim-SC_OLD-84cc69573bb522122606c3bc29c8ab188d4ccf70.zip
opensim-SC_OLD-84cc69573bb522122606c3bc29c8ab188d4ccf70.tar.gz
opensim-SC_OLD-84cc69573bb522122606c3bc29c8ab188d4ccf70.tar.bz2
opensim-SC_OLD-84cc69573bb522122606c3bc29c8ab188d4ccf70.tar.xz
Thanks, lulurun, for a patch that adds an authenticated session cache to reduce
"check_auth_session" requests from inventory server to user server.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Communications/Cache/AuthedSessionCache.cs107
-rw-r--r--OpenSim/Grid/InventoryServer/GridInventoryService.cs38
2 files changed, 134 insertions, 11 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AuthedSessionCache.cs b/OpenSim/Framework/Communications/Cache/AuthedSessionCache.cs
new file mode 100644
index 0000000..b989997
--- /dev/null
+++ b/OpenSim/Framework/Communications/Cache/AuthedSessionCache.cs
@@ -0,0 +1,107 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Framework.Communications.Cache
6{
7 public class AuthedSessionCache
8 {
9 public class CacheData
10 {
11 private static readonly DateTime UNIX_EPOCH = new DateTime(1970, 1, 1);
12 private string m_session_id;
13 private string m_agent_id;
14 private int m_expire;
15
16 private int get_current_unix_time()
17 {
18 return (int)(DateTime.UtcNow - UNIX_EPOCH).TotalSeconds;
19 }
20
21 public CacheData(string sid, string aid)
22 {
23 m_session_id = sid;
24 m_agent_id = aid;
25 m_expire = get_current_unix_time() + DEFAULT_LIFETIME;
26 }
27
28 public CacheData(string sid, string aid, int time_now)
29 {
30 m_session_id = sid;
31 m_agent_id = aid;
32 m_expire = time_now + DEFAULT_LIFETIME;
33 }
34
35 public string SessionID
36 {
37 get { return m_session_id; }
38 set { m_session_id = value; }
39 }
40
41 public string AgentID
42 {
43 get { return m_agent_id; }
44 set { m_agent_id = value; }
45 }
46
47 public bool isExpired
48 {
49 get { return m_expire < get_current_unix_time(); }
50 }
51
52 public void Renew()
53 {
54 m_expire = get_current_unix_time() + DEFAULT_LIFETIME;
55 }
56 }
57
58 private static readonly int DEFAULT_LIFETIME = 30;
59 private Dictionary<string, CacheData> m_authed_sessions = new Dictionary<string,CacheData>();
60 private int m_session_lifetime = DEFAULT_LIFETIME;
61
62 public AuthedSessionCache()
63 {
64 m_session_lifetime = DEFAULT_LIFETIME;
65 }
66
67 public AuthedSessionCache(int timeout)
68 {
69 m_session_lifetime = timeout;
70 }
71
72 public CacheData getCachedSession(string session_id, string agent_id)
73 {
74 CacheData ret = null;
75 lock (m_authed_sessions)
76 {
77 if (m_authed_sessions.ContainsKey(session_id))
78 {
79 CacheData cached_session = m_authed_sessions[session_id];
80 if (!cached_session.isExpired && cached_session.AgentID == agent_id)
81 {
82 ret = m_authed_sessions[session_id];
83 // auto renew
84 m_authed_sessions[session_id].Renew();
85 }
86 }
87 }
88 return ret;
89 }
90
91 public void Add(string session_id, string agent_id)
92 {
93 CacheData data = new CacheData(session_id, agent_id);
94 lock (m_authed_sessions)
95 {
96 if (m_authed_sessions.ContainsKey(session_id))
97 {
98 m_authed_sessions[session_id] = data;
99 }
100 else
101 {
102 m_authed_sessions.Add(session_id, data);
103 }
104 }
105 }
106 }
107}
diff --git a/OpenSim/Grid/InventoryServer/GridInventoryService.cs b/OpenSim/Grid/InventoryServer/GridInventoryService.cs
index b8a0436..63eeced 100644
--- a/OpenSim/Grid/InventoryServer/GridInventoryService.cs
+++ b/OpenSim/Grid/InventoryServer/GridInventoryService.cs
@@ -38,6 +38,7 @@ using Nwc.XmlRpc;
38 38
39using OpenSim.Framework; 39using OpenSim.Framework;
40using OpenSim.Framework.Communications; 40using OpenSim.Framework.Communications;
41using OpenSim.Framework.Communications.Cache;
41 42
42namespace OpenSim.Grid.InventoryServer 43namespace OpenSim.Grid.InventoryServer
43{ 44{
@@ -48,8 +49,10 @@ namespace OpenSim.Grid.InventoryServer
48 { 49 {
49 private static readonly ILog m_log 50 private static readonly ILog m_log
50 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private static readonly int INVENTORY_DEFAULT_SESSION_TIME = 30; // secs
51 53
52 private string m_userserver_url; 54 private string m_userserver_url;
55 private AuthedSessionCache m_session_cache = new AuthedSessionCache(INVENTORY_DEFAULT_SESSION_TIME);
53 56
54 public GridInventoryService(string userserver_url) 57 public GridInventoryService(string userserver_url)
55 { 58 {
@@ -72,20 +75,33 @@ namespace OpenSim.Grid.InventoryServer
72 public bool CheckAuthSession(string session_id, string avatar_id) 75 public bool CheckAuthSession(string session_id, string avatar_id)
73 { 76 {
74 m_log.InfoFormat("[GRID AGENT INVENTORY]: checking authed session {0} {1}", session_id, avatar_id); 77 m_log.InfoFormat("[GRID AGENT INVENTORY]: checking authed session {0} {1}", session_id, avatar_id);
75 Hashtable requestData = new Hashtable(); 78 if (m_session_cache.getCachedSession(session_id, avatar_id) == null)
76 requestData["avatar_uuid"] = avatar_id; 79 {
77 requestData["session_id"] = session_id; 80 // cache miss, ask userserver
78 ArrayList SendParams = new ArrayList(); 81 Hashtable requestData = new Hashtable();
79 SendParams.Add(requestData); 82 requestData["avatar_uuid"] = avatar_id;
80 XmlRpcRequest UserReq = new XmlRpcRequest("check_auth_session", SendParams); 83 requestData["session_id"] = session_id;
81 XmlRpcResponse UserResp = UserReq.Send(m_userserver_url, 3000); 84 ArrayList SendParams = new ArrayList();
82 85 SendParams.Add(requestData);
83 Hashtable responseData = (Hashtable)UserResp.Value; 86 XmlRpcRequest UserReq = new XmlRpcRequest("check_auth_session", SendParams);
84 87 XmlRpcResponse UserResp = UserReq.Send(m_userserver_url, 3000);
85 if (responseData.ContainsKey("auth_session") && responseData["auth_session"].ToString() == "TRUE") 88
89 Hashtable responseData = (Hashtable)UserResp.Value;
90 if (responseData.ContainsKey("auth_session") && responseData["auth_session"].ToString() == "TRUE")
91 {
92 m_log.Info("[GRID AGENT INVENTORY]: got authed session from userserver");
93 // add to cache; the session time will be automatically renewed
94 m_session_cache.Add(session_id, avatar_id);
95 return true;
96 }
97 }
98 else
86 { 99 {
100 // cache hits
101 m_log.Info("[GRID AGENT INVENTORY]: got authed session from cache");
87 return true; 102 return true;
88 } 103 }
104 m_log.Info("[GRID AGENT INVENTORY]: unknown session_id, request rejected");
89 return false; 105 return false;
90 } 106 }
91 107