aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules
diff options
context:
space:
mode:
authordiva2009-01-03 07:05:33 +0000
committerdiva2009-01-03 07:05:33 +0000
commit158de95bde7cdee09334c40baee5122fd8f196e2 (patch)
tree8a8b1f41db53475cca08633cbeec09d5425a8745 /OpenSim/Region/Environment/Modules
parentPlumbing for moving InformRegionOfChildAgent over to RESTComms: pack and unpa... (diff)
downloadopensim-SC_OLD-158de95bde7cdee09334c40baee5122fd8f196e2.zip
opensim-SC_OLD-158de95bde7cdee09334c40baee5122fd8f196e2.tar.gz
opensim-SC_OLD-158de95bde7cdee09334c40baee5122fd8f196e2.tar.bz2
opensim-SC_OLD-158de95bde7cdee09334c40baee5122fd8f196e2.tar.xz
Another interregion comms change that will not work well with previous versions. This commit moves InformRegionOfChildAgent from OGS1 to RESTComms, effectively having the complete child agent life cycle over REST: create=POST, update=PUT, close=DELETE.
Additional changes include more functions in the IHyperlink interface, and some refactorings in the HG code for better reuse in RESTComms.
Diffstat (limited to 'OpenSim/Region/Environment/Modules')
-rw-r--r--OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs15
-rw-r--r--OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs171
2 files changed, 180 insertions, 6 deletions
diff --git a/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs b/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs
index 135a05e..efc5c39 100644
--- a/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs
+++ b/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs
@@ -118,6 +118,21 @@ namespace OpenSim.Region.Environment.Modules.Communications.Local
118 118
119 #region IInterregionComms 119 #region IInterregionComms
120 120
121 public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit)
122 {
123 foreach (Scene s in m_sceneList)
124 {
125 if (s.RegionInfo.RegionHandle == regionHandle)
126 {
127 //m_log.Debug("[LOCAL COMMS]: Found region to send SendCreateChildAgent");
128 s.NewUserConnection(aCircuit);
129 return true;
130 }
131 }
132 //m_log.Debug("[LOCAL COMMS]: region not found for SendCreateChildAgent");
133 return false;
134 }
135
121 public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData) 136 public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData)
122 { 137 {
123 foreach (Scene s in m_sceneList) 138 foreach (Scene s in m_sceneList)
diff --git a/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs b/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
index bff8316..7eb5d30 100644
--- a/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
+++ b/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
@@ -128,6 +128,25 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
128 128
129 #region IInterregionComms 129 #region IInterregionComms
130 130
131 public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit)
132 {
133 // Try local first
134 if (m_localBackend.SendCreateChildAgent(regionHandle, aCircuit))
135 return true;
136
137 // else do the remote thing
138 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle);
139 if (regInfo != null)
140 {
141 SendUserInformation(regInfo, aCircuit);
142
143 return DoCreateChildAgentCall(regInfo, aCircuit);
144 }
145 //else
146 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
147 return false;
148 }
149
131 public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData) 150 public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData)
132 { 151 {
133 // Try local first 152 // Try local first
@@ -197,6 +216,91 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
197 // Internal functions for the above public interface 216 // Internal functions for the above public interface
198 //------------------------------------------------------------------- 217 //-------------------------------------------------------------------
199 218
219 protected bool DoCreateChildAgentCall(RegionInfo region, AgentCircuitData aCircuit)
220 {
221 // Eventually, we want to use a caps url instead of the agentID
222 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + aCircuit.AgentID + "/";
223 //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri);
224
225 WebRequest AgentCreateRequest = WebRequest.Create(uri);
226 AgentCreateRequest.Method = "POST";
227 AgentCreateRequest.ContentType = "application/json";
228 AgentCreateRequest.Timeout = 10000;
229
230 // Fill it in
231 OSDMap args = null;
232 try
233 {
234 args = aCircuit.PackAgentCircuitData();
235 }
236 catch (Exception e)
237 {
238 m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
239 }
240 // Add the regionhandle of the destination region
241 ulong regionHandle = GetRegionHandle(region.RegionHandle);
242 args["destination_handle"] = OSD.FromString(regionHandle.ToString());
243
244 string strBuffer = "";
245 byte[] buffer = new byte[1];
246 try
247 {
248 strBuffer = OSDParser.SerializeJsonString(args);
249 System.Text.UTF8Encoding str = new System.Text.UTF8Encoding();
250 buffer = str.GetBytes(strBuffer);
251
252 }
253 catch (Exception e)
254 {
255 m_log.WarnFormat("[OSG2]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
256 // ignore. buffer will be empty, caller should check.
257 }
258
259 Stream os = null;
260 try
261 { // send the Post
262 AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
263 os = AgentCreateRequest.GetRequestStream();
264 os.Write(buffer, 0, strBuffer.Length); //Send it
265 os.Close();
266 //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
267 }
268 //catch (WebException ex)
269 catch
270 {
271 //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
272
273 return false;
274 }
275
276 // Let's wait for the response
277 //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
278
279 try
280 {
281 WebResponse webResponse = AgentCreateRequest.GetResponse();
282 if (webResponse == null)
283 {
284 m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
285 }
286
287 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
288 //reply = sr.ReadToEnd().Trim();
289 sr.ReadToEnd().Trim();
290 sr.Close();
291 //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply);
292
293 }
294 catch (WebException ex)
295 {
296 m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
297 // ignore, really
298 }
299
300 return true;
301
302 }
303
200 protected bool DoChildAgentUpdateCall(RegionInfo region, IAgentData cAgentData) 304 protected bool DoChildAgentUpdateCall(RegionInfo region, IAgentData cAgentData)
201 { 305 {
202 // Eventually, we want to use a caps url instead of the agentID 306 // Eventually, we want to use a caps url instead of the agentID
@@ -233,7 +337,7 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
233 } 337 }
234 catch (Exception e) 338 catch (Exception e)
235 { 339 {
236 m_log.WarnFormat("[OSG2]: Exception thrown on serialization of ChildUpdate: {0}", e.Message); 340 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
237 // ignore. buffer will be empty, caller should check. 341 // ignore. buffer will be empty, caller should check.
238 } 342 }
239 343
@@ -388,10 +492,7 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
388 } 492 }
389 else if (method.Equals("POST")) 493 else if (method.Equals("POST"))
390 { 494 {
391 m_log.InfoFormat("[REST COMMS]: method {0} not implemented yet in agent message", method); 495 DoPost(request, responsedata, agentID);
392 responsedata["int_response_code"] = 404;
393 responsedata["str_response_string"] = "false";
394
395 return responsedata; 496 return responsedata;
396 } 497 }
397 else if (method.Equals("DELETE")) 498 else if (method.Equals("DELETE"))
@@ -438,6 +539,40 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
438 } 539 }
439 } 540 }
440 541
542 protected virtual void DoPost(Hashtable request, Hashtable responsedata, UUID id)
543 {
544 OSDMap args = GetOSDMap(request);
545 if (args == null)
546 {
547 responsedata["int_response_code"] = 400;
548 responsedata["str_response_string"] = "false";
549 return;
550 }
551
552 // retrieve the regionhandle
553 ulong regionhandle = 0;
554 if (args["destination_handle"] != null)
555 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
556
557 AgentCircuitData aCircuit = new AgentCircuitData();
558 try
559 {
560 aCircuit.UnpackAgentCircuitData(args);
561 }
562 catch (Exception ex)
563 {
564 m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildCreate message {0}", ex.Message);
565 return;
566 }
567
568 // This is the meaning of POST agent
569 AdjustUserInformation(aCircuit);
570 bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit);
571
572 responsedata["int_response_code"] = 200;
573 responsedata["str_response_string"] = result.ToString();
574 }
575
441 protected virtual void DoPut(Hashtable request, Hashtable responsedata) 576 protected virtual void DoPut(Hashtable request, Hashtable responsedata)
442 { 577 {
443 OSDMap args = GetOSDMap(request); 578 OSDMap args = GetOSDMap(request);
@@ -553,6 +688,10 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
553 } 688 }
554 } 689 }
555 690
691 #endregion Misc
692
693 #region Hyperlinks
694
556 protected virtual ulong GetRegionHandle(ulong handle) 695 protected virtual ulong GetRegionHandle(ulong handle)
557 { 696 {
558 if (m_aScene.SceneGridService is HGSceneCommunicationService) 697 if (m_aScene.SceneGridService is HGSceneCommunicationService)
@@ -568,7 +707,27 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
568 707
569 return false; 708 return false;
570 } 709 }
571 #endregion /* Misc */ 710
711 protected virtual void SendUserInformation(RegionInfo regInfo, AgentCircuitData aCircuit)
712 {
713 try
714 {
715 if (IsHyperlink(regInfo.RegionHandle))
716 {
717 ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.SendUserInformation(regInfo, aCircuit);
718 }
719 }
720 catch // Bad cast
721 { }
722
723 }
724
725 protected virtual void AdjustUserInformation(AgentCircuitData aCircuit)
726 {
727 if (m_aScene.SceneGridService is HGSceneCommunicationService)
728 ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.AdjustUserInformation(aCircuit);
729 }
730 #endregion /* Hyperlinks */
572 731
573 } 732 }
574} 733}