diff options
author | diva | 2009-05-25 20:30:24 +0000 |
---|---|---|
committer | diva | 2009-05-25 20:30:24 +0000 |
commit | cb704ecde19c512bfa4fc0b317d37fec63e76713 (patch) | |
tree | 1960e54ce2312b95f030009c335b5211322ef60d /OpenSim | |
parent | * reseparate inventory item creator id and creator uuid (diff) | |
download | opensim-SC_OLD-cb704ecde19c512bfa4fc0b317d37fec63e76713.zip opensim-SC_OLD-cb704ecde19c512bfa4fc0b317d37fec63e76713.tar.gz opensim-SC_OLD-cb704ecde19c512bfa4fc0b317d37fec63e76713.tar.bz2 opensim-SC_OLD-cb704ecde19c512bfa4fc0b317d37fec63e76713.tar.xz |
Beginning of refactoring RESTComms/LocalComms in the new style of services and connectors. This commit has the beginning of the In connector, not the Out. Nothing of this is finished yet, and it doesn't run. But it should compile ok.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | 182 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs | 53 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/Utils.cs | 70 | ||||
-rw-r--r-- | OpenSim/Services/Interfaces/IAuthenticationService.cs | 14 | ||||
-rw-r--r-- | OpenSim/Services/Interfaces/ISimulationService.cs | 81 | ||||
-rw-r--r-- | OpenSim/SimulatorServices/SimulationService.cs | 85 |
6 files changed, 485 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs new file mode 100644 index 0000000..1d455c6 --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | |||
@@ -0,0 +1,182 @@ | |||
1 | using System; | ||
2 | using System.IO; | ||
3 | using System.Reflection; | ||
4 | using System.Net; | ||
5 | using System.Text; | ||
6 | |||
7 | using OpenSim.Server.Base; | ||
8 | using OpenSim.Services.Interfaces; | ||
9 | using OpenSim.Framework; | ||
10 | using OpenSim.Framework.Servers.HttpServer; | ||
11 | |||
12 | using OpenMetaverse; | ||
13 | using OpenMetaverse.StructuredData; | ||
14 | using Nini.Config; | ||
15 | using log4net; | ||
16 | |||
17 | |||
18 | namespace OpenSim.Server.Handlers.Simulation | ||
19 | { | ||
20 | public class AgentGetHandler : BaseStreamHandler | ||
21 | { | ||
22 | private ISimulationService m_SimulationService; | ||
23 | private IAuthenticationService m_AuthenticationService; | ||
24 | |||
25 | public AgentGetHandler(ISimulationService service, IAuthenticationService authentication) : | ||
26 | base("GET", "/agent") | ||
27 | { | ||
28 | m_SimulationService = service; | ||
29 | m_AuthenticationService = authentication; | ||
30 | } | ||
31 | |||
32 | public override byte[] Handle(string path, Stream request, | ||
33 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
34 | { | ||
35 | // Not implemented yet | ||
36 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
37 | return new byte[] { }; | ||
38 | } | ||
39 | } | ||
40 | |||
41 | public class AgentPostHandler : BaseStreamHandler | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | private ISimulationService m_SimulationService; | ||
45 | private IAuthenticationService m_AuthenticationService; | ||
46 | private bool m_AllowForeignGuests; | ||
47 | |||
48 | public AgentPostHandler(ISimulationService service, IAuthenticationService authentication, bool foreignGuests) : | ||
49 | base("POST", "/agent") | ||
50 | { | ||
51 | m_SimulationService = service; | ||
52 | m_AuthenticationService = authentication; | ||
53 | m_AllowForeignGuests = foreignGuests; | ||
54 | } | ||
55 | |||
56 | public override byte[] Handle(string path, Stream request, | ||
57 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
58 | { | ||
59 | byte[] result = new byte[0]; | ||
60 | |||
61 | UUID agentID; | ||
62 | string action; | ||
63 | ulong regionHandle; | ||
64 | if (!Utils.GetParams(path, out agentID, out regionHandle, out action)) | ||
65 | { | ||
66 | m_log.InfoFormat("[AgentPostHandler]: Invalid parameters for agent message {0}", path); | ||
67 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
68 | httpResponse.StatusDescription = "Invalid parameters for agent message " + path; | ||
69 | |||
70 | return result; | ||
71 | } | ||
72 | |||
73 | if (m_AuthenticationService != null) | ||
74 | { | ||
75 | // Authentication | ||
76 | string authority = string.Empty; | ||
77 | string authToken = string.Empty; | ||
78 | if (!Utils.GetAuthentication(httpRequest, out authority, out authToken)) | ||
79 | { | ||
80 | m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path); | ||
81 | httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized; | ||
82 | return result; | ||
83 | } | ||
84 | if (!m_AuthenticationService.VerifyKey(agentID, authToken)) | ||
85 | { | ||
86 | m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path); | ||
87 | httpResponse.StatusCode = (int)HttpStatusCode.Forbidden; | ||
88 | return result; | ||
89 | } | ||
90 | m_log.DebugFormat("[AgentPostHandler]: Authentication succeeded for {0}", agentID); | ||
91 | } | ||
92 | |||
93 | OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength); | ||
94 | if (args == null) | ||
95 | { | ||
96 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
97 | httpResponse.StatusDescription = "Unable to retrieve data"; | ||
98 | m_log.DebugFormat("[AgentPostHandler]: Unable to retrieve data for post {0}", path); | ||
99 | return result; | ||
100 | } | ||
101 | |||
102 | // retrieve the regionhandle | ||
103 | ulong regionhandle = 0; | ||
104 | if (args["destination_handle"] != null) | ||
105 | UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); | ||
106 | |||
107 | AgentCircuitData aCircuit = new AgentCircuitData(); | ||
108 | try | ||
109 | { | ||
110 | aCircuit.UnpackAgentCircuitData(args); | ||
111 | } | ||
112 | catch (Exception ex) | ||
113 | { | ||
114 | m_log.InfoFormat("[AgentPostHandler]: exception on unpacking CreateAgent message {0}", ex.Message); | ||
115 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
116 | httpResponse.StatusDescription = "Problems with data deserialization"; | ||
117 | return result; | ||
118 | } | ||
119 | |||
120 | string reason = string.Empty; | ||
121 | |||
122 | // We need to clean up a few things in the user service before I can do this | ||
123 | //if (m_AllowForeignGuests) | ||
124 | // m_regionClient.AdjustUserInformation(aCircuit); | ||
125 | |||
126 | // Finally! | ||
127 | bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, out reason); | ||
128 | |||
129 | OSDMap resp = new OSDMap(1); | ||
130 | |||
131 | resp["success"] = OSD.FromBoolean(success); | ||
132 | |||
133 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
134 | |||
135 | return Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(resp)); | ||
136 | |||
137 | } | ||
138 | } | ||
139 | |||
140 | public class AgentPutHandler : BaseStreamHandler | ||
141 | { | ||
142 | private ISimulationService m_SimulationService; | ||
143 | private IAuthenticationService m_AuthenticationService; | ||
144 | |||
145 | public AgentPutHandler(ISimulationService service, IAuthenticationService authentication) : | ||
146 | base("PUT", "/agent") | ||
147 | { | ||
148 | m_SimulationService = service; | ||
149 | m_AuthenticationService = authentication; | ||
150 | } | ||
151 | |||
152 | public override byte[] Handle(string path, Stream request, | ||
153 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
154 | { | ||
155 | // Not implemented yet | ||
156 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
157 | return new byte[] { }; | ||
158 | } | ||
159 | } | ||
160 | |||
161 | public class AgentDeleteHandler : BaseStreamHandler | ||
162 | { | ||
163 | private ISimulationService m_SimulationService; | ||
164 | private IAuthenticationService m_AuthenticationService; | ||
165 | |||
166 | public AgentDeleteHandler(ISimulationService service, IAuthenticationService authentication) : | ||
167 | base("DELETE", "/agent") | ||
168 | { | ||
169 | m_SimulationService = service; | ||
170 | m_AuthenticationService = authentication; | ||
171 | } | ||
172 | |||
173 | public override byte[] Handle(string path, Stream request, | ||
174 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
175 | { | ||
176 | // Not implemented yet | ||
177 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
178 | return new byte[] { }; | ||
179 | } | ||
180 | } | ||
181 | |||
182 | } | ||
diff --git a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs new file mode 100644 index 0000000..80b22b0 --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs | |||
@@ -0,0 +1,53 @@ | |||
1 | using System; | ||
2 | using Nini.Config; | ||
3 | using OpenSim.Server.Base; | ||
4 | using OpenSim.Services.Interfaces; | ||
5 | using OpenSim.Framework; | ||
6 | using OpenSim.Framework.Servers.HttpServer; | ||
7 | using OpenSim.Server.Handlers.Base; | ||
8 | |||
9 | namespace OpenSim.Server.Handlers.Simulation | ||
10 | { | ||
11 | public class SimulationServiceInConnector : ServiceConnector | ||
12 | { | ||
13 | private ISimulationService m_SimulationService; | ||
14 | private IAuthenticationService m_AuthenticationService; | ||
15 | |||
16 | public SimulationServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) : | ||
17 | base(config, server) | ||
18 | { | ||
19 | IConfig serverConfig = config.Configs["SimulationService"]; | ||
20 | if (serverConfig == null) | ||
21 | throw new Exception("No section 'SimulationService' in config file"); | ||
22 | |||
23 | bool authentication = serverConfig.GetBoolean("RequireAuthentication", false); | ||
24 | |||
25 | if (authentication) | ||
26 | m_AuthenticationService = scene.RequestModuleInterface<IAuthenticationService>(); | ||
27 | |||
28 | bool foreignGuests = serverConfig.GetBoolean("AllowForeignGuests", false); | ||
29 | |||
30 | //string simService = serverConfig.GetString("LocalServiceModule", | ||
31 | // String.Empty); | ||
32 | |||
33 | //if (simService == String.Empty) | ||
34 | // throw new Exception("No SimulationService in config file"); | ||
35 | |||
36 | //Object[] args = new Object[] { config }; | ||
37 | m_SimulationService = scene.RequestModuleInterface<ISimulationService>(); | ||
38 | //ServerUtils.LoadPlugin<ISimulationService>(simService, args); | ||
39 | if (m_SimulationService == null) | ||
40 | throw new Exception("No Local ISimulationService Module"); | ||
41 | |||
42 | |||
43 | |||
44 | //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no")); | ||
45 | server.AddStreamHandler(new AgentGetHandler(m_SimulationService, m_AuthenticationService)); | ||
46 | server.AddStreamHandler(new AgentPostHandler(m_SimulationService, m_AuthenticationService, foreignGuests)); | ||
47 | server.AddStreamHandler(new AgentPutHandler(m_SimulationService, m_AuthenticationService)); | ||
48 | server.AddStreamHandler(new AgentDeleteHandler(m_SimulationService, m_AuthenticationService)); | ||
49 | //server.AddStreamHandler(new ObjectPostHandler(m_SimulationService, authentication)); | ||
50 | //server.AddStreamHandler(new NeighborPostHandler(m_SimulationService, authentication)); | ||
51 | } | ||
52 | } | ||
53 | } | ||
diff --git a/OpenSim/Server/Handlers/Simulation/Utils.cs b/OpenSim/Server/Handlers/Simulation/Utils.cs new file mode 100644 index 0000000..581622c --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/Utils.cs | |||
@@ -0,0 +1,70 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Net; | ||
4 | |||
5 | using OpenSim.Framework; | ||
6 | using OpenSim.Framework.Servers.HttpServer; | ||
7 | using OpenSim.Services.Interfaces; | ||
8 | using OpenMetaverse; | ||
9 | |||
10 | namespace OpenSim.Server.Handlers.Simulation | ||
11 | { | ||
12 | public class Utils | ||
13 | { | ||
14 | /// <summary> | ||
15 | /// Extract the param from an uri. | ||
16 | /// </summary> | ||
17 | /// <param name="uri">Something like this: /uuid/ or /uuid/handle/release</param> | ||
18 | /// <param name="uri">uuid on uuid field</param> | ||
19 | /// <param name="action">optional action</param> | ||
20 | public static bool GetParams(string path, out UUID uuid, out ulong regionHandle, out string action) | ||
21 | { | ||
22 | uuid = UUID.Zero; | ||
23 | action = ""; | ||
24 | regionHandle = 0; | ||
25 | |||
26 | path = path.Trim(new char[] { '/' }); | ||
27 | string[] parts = path.Split('/'); | ||
28 | if (parts.Length <= 1) | ||
29 | { | ||
30 | return false; | ||
31 | } | ||
32 | else | ||
33 | { | ||
34 | if (!UUID.TryParse(parts[0], out uuid)) | ||
35 | return false; | ||
36 | |||
37 | if (parts.Length >= 2) | ||
38 | UInt64.TryParse(parts[1], out regionHandle); | ||
39 | if (parts.Length >= 3) | ||
40 | action = parts[2]; | ||
41 | |||
42 | return true; | ||
43 | } | ||
44 | } | ||
45 | |||
46 | public static bool GetAuthentication(OSHttpRequest httpRequest, out string authority, out string authKey) | ||
47 | { | ||
48 | authority = string.Empty; | ||
49 | authKey = string.Empty; | ||
50 | |||
51 | Uri authUri; | ||
52 | |||
53 | string auth = httpRequest.Headers["authentication"]; | ||
54 | // Authentication keys look like this: | ||
55 | // http://orgrid.org:8002/<uuid> | ||
56 | if ((auth != null) && (!string.Empty.Equals(auth)) && auth != "None") | ||
57 | { | ||
58 | if (Uri.TryCreate(auth, UriKind.Absolute, out authUri)) | ||
59 | { | ||
60 | authority = authUri.Authority; | ||
61 | authKey = authUri.PathAndQuery.Trim('/'); | ||
62 | return true; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | return false; | ||
67 | } | ||
68 | |||
69 | } | ||
70 | } | ||
diff --git a/OpenSim/Services/Interfaces/IAuthenticationService.cs b/OpenSim/Services/Interfaces/IAuthenticationService.cs new file mode 100644 index 0000000..25ceaa6 --- /dev/null +++ b/OpenSim/Services/Interfaces/IAuthenticationService.cs | |||
@@ -0,0 +1,14 @@ | |||
1 | using System; | ||
2 | using OpenMetaverse; | ||
3 | |||
4 | namespace OpenSim.Services.Interfaces | ||
5 | { | ||
6 | public interface IAuthenticationService | ||
7 | { | ||
8 | string GetNewKey(UUID userID, UUID authToken); | ||
9 | |||
10 | bool VerifyKey(UUID userID, string key); | ||
11 | |||
12 | bool VerifySession(UUID iserID, UUID sessionID); | ||
13 | } | ||
14 | } | ||
diff --git a/OpenSim/Services/Interfaces/ISimulationService.cs b/OpenSim/Services/Interfaces/ISimulationService.cs new file mode 100644 index 0000000..da5410b --- /dev/null +++ b/OpenSim/Services/Interfaces/ISimulationService.cs | |||
@@ -0,0 +1,81 @@ | |||
1 | using System; | ||
2 | using OpenSim.Framework; | ||
3 | using OpenMetaverse; | ||
4 | |||
5 | namespace OpenSim.Services.Interfaces | ||
6 | { | ||
7 | public interface ISimulationService | ||
8 | { | ||
9 | #region Agents | ||
10 | |||
11 | bool CreateAgent(ulong regionHandle, AgentCircuitData aCircuit, out string reason); | ||
12 | |||
13 | /// <summary> | ||
14 | /// Full child agent update. | ||
15 | /// </summary> | ||
16 | /// <param name="regionHandle"></param> | ||
17 | /// <param name="data"></param> | ||
18 | /// <returns></returns> | ||
19 | bool UpdateAgent(ulong regionHandle, AgentData data); | ||
20 | |||
21 | /// <summary> | ||
22 | /// Short child agent update, mostly for position. | ||
23 | /// </summary> | ||
24 | /// <param name="regionHandle"></param> | ||
25 | /// <param name="data"></param> | ||
26 | /// <returns></returns> | ||
27 | bool UpdateAgent(ulong regionHandle, AgentPosition data); | ||
28 | |||
29 | bool RetrieveAgent(ulong regionHandle, UUID id, out IAgentData agent); | ||
30 | |||
31 | /// <summary> | ||
32 | /// Message from receiving region to departing region, telling it got contacted by the client. | ||
33 | /// When sent over REST, it invokes the opaque uri. | ||
34 | /// </summary> | ||
35 | /// <param name="regionHandle"></param> | ||
36 | /// <param name="id"></param> | ||
37 | /// <param name="uri"></param> | ||
38 | /// <returns></returns> | ||
39 | bool ReleaseAgent(ulong regionHandle, UUID id, string uri); | ||
40 | |||
41 | /// <summary> | ||
42 | /// Close agent. | ||
43 | /// </summary> | ||
44 | /// <param name="regionHandle"></param> | ||
45 | /// <param name="id"></param> | ||
46 | /// <returns></returns> | ||
47 | bool CloseAgent(ulong regionHandle, UUID id); | ||
48 | |||
49 | #endregion Agents | ||
50 | |||
51 | #region Objects | ||
52 | |||
53 | /// <summary> | ||
54 | /// Create an object in the destination region. This message is used primarily for prim crossing. | ||
55 | /// </summary> | ||
56 | /// <param name="regionHandle"></param> | ||
57 | /// <param name="sog"></param> | ||
58 | /// <param name="isLocalCall"></param> | ||
59 | /// <returns></returns> | ||
60 | bool CreateObject(ulong regionHandle, ISceneObject sog, bool isLocalCall); | ||
61 | |||
62 | /// <summary> | ||
63 | /// Create an object from the user's inventory in the destination region. | ||
64 | /// This message is used primarily by clients. | ||
65 | /// </summary> | ||
66 | /// <param name="regionHandle"></param> | ||
67 | /// <param name="userID"></param> | ||
68 | /// <param name="itemID"></param> | ||
69 | /// <returns></returns> | ||
70 | bool CreateObject(ulong regionHandle, UUID userID, UUID itemID); | ||
71 | |||
72 | #endregion Objects | ||
73 | |||
74 | #region Regions | ||
75 | |||
76 | bool HelloNeighbour(ulong regionHandle, RegionInfo thisRegion); | ||
77 | |||
78 | #endregion Regions | ||
79 | |||
80 | } | ||
81 | } | ||
diff --git a/OpenSim/SimulatorServices/SimulationService.cs b/OpenSim/SimulatorServices/SimulationService.cs new file mode 100644 index 0000000..8f01436 --- /dev/null +++ b/OpenSim/SimulatorServices/SimulationService.cs | |||
@@ -0,0 +1,85 @@ | |||
1 | using System; | ||
2 | using System.Reflection; | ||
3 | using System.Collections.Generic; | ||
4 | using log4net; | ||
5 | using Nini.Config; | ||
6 | using OpenSim.Framework; | ||
7 | using OpenSim.Framework.Servers.HttpServer; | ||
8 | using OpenSim.Region.Framework.Scenes; | ||
9 | using OpenSim.Region.Framework.Interfaces; | ||
10 | using OpenSim.Server.Base; | ||
11 | using OpenSim.Server.Handlers.Base; | ||
12 | |||
13 | |||
14 | namespace OpenSim.SimulatorServices | ||
15 | { | ||
16 | public class SimulationService : ISharedRegionModule | ||
17 | { | ||
18 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
19 | private static bool m_Enabled = false; | ||
20 | |||
21 | private IConfigSource m_Config; | ||
22 | bool m_Registered = false; | ||
23 | |||
24 | #region IRegionModule interface | ||
25 | |||
26 | public void Initialise(IConfigSource config) | ||
27 | { | ||
28 | m_Config = config; | ||
29 | |||
30 | IConfig moduleConfig = config.Configs["Modules"]; | ||
31 | if (moduleConfig != null) | ||
32 | { | ||
33 | string name = moduleConfig.GetString("AssetServices", ""); | ||
34 | if (name == Name) | ||
35 | { | ||
36 | m_Enabled = true; | ||
37 | m_log.Info("[SIM SERVICE]: SimulationService enabled"); | ||
38 | |||
39 | } | ||
40 | } | ||
41 | |||
42 | } | ||
43 | |||
44 | public void PostInitialise() | ||
45 | { | ||
46 | } | ||
47 | |||
48 | public void Close() | ||
49 | { | ||
50 | } | ||
51 | |||
52 | public string Name | ||
53 | { | ||
54 | get { return "SimulationService"; } | ||
55 | } | ||
56 | |||
57 | public void AddRegion(Scene scene) | ||
58 | { | ||
59 | if (!m_Enabled) | ||
60 | return; | ||
61 | |||
62 | if (!m_Registered) | ||
63 | { | ||
64 | m_Registered = true; | ||
65 | |||
66 | m_log.Info("[SIM SERVICE]: Starting..."); | ||
67 | |||
68 | Object[] args = new Object[] { m_Config, scene.CommsManager.HttpServer, scene }; | ||
69 | |||
70 | ServerUtils.LoadPlugin<IServiceConnector>("OpenSim.Server.Handlers.dll:SimulationServiceInConnector", args); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | public void RemoveRegion(Scene scene) | ||
75 | { | ||
76 | } | ||
77 | |||
78 | public void RegionLoaded(Scene scene) | ||
79 | { | ||
80 | } | ||
81 | |||
82 | #endregion | ||
83 | |||
84 | } | ||
85 | } | ||