aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Communications/REST
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Communications/REST')
-rw-r--r--OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs173
1 files changed, 155 insertions, 18 deletions
diff --git a/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs b/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
index b7c9269..f48e474 100644
--- a/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
+++ b/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
@@ -146,6 +146,40 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
146 146
147 } 147 }
148 148
149 public bool SendReleaseAgent(ulong regionHandle, UUID id, string uri)
150 {
151 // Try local first
152 if (m_localBackend.SendReleaseAgent(regionHandle, id, uri))
153 return true;
154
155 // else do the remote thing
156 return DoReleaseAgentCall(regionHandle, id, uri);
157 }
158
159 public bool SendCloseAgent(ulong regionHandle, UUID id)
160 {
161 // Try local first
162 if (m_localBackend.SendCloseAgent(regionHandle, id))
163 return true;
164
165 // else do the remote thing
166 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle);
167 if (regInfo != null)
168 {
169 return DoCloseAgentCall(regInfo, id);
170 }
171 //else
172 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
173 return false;
174 }
175
176 #endregion /* IInterregionComms */
177
178 #region DoWork functions for the above public interface
179 //-------------------------------------------------------------------
180 // Internal functions for the above public interface
181 //-------------------------------------------------------------------
182
149 protected bool DoChildAgentUpdateCall(RegionInfo region, AgentData cAgentData) 183 protected bool DoChildAgentUpdateCall(RegionInfo region, AgentData cAgentData)
150 { 184 {
151 // Eventually, we want to use a caps url instead of the agentID 185 // Eventually, we want to use a caps url instead of the agentID
@@ -168,7 +202,7 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
168 m_log.Debug("[REST COMMS]: PackUpdateMessage failed with exception: " + e.Message); 202 m_log.Debug("[REST COMMS]: PackUpdateMessage failed with exception: " + e.Message);
169 } 203 }
170 // Add the regionhandle of the destination region 204 // Add the regionhandle of the destination region
171 ulong regionHandle = GetRegionHandle(region); 205 ulong regionHandle = GetRegionHandle(region.RegionHandle);
172 args["destination_handle"] = OSD.FromString(regionHandle.ToString()); 206 args["destination_handle"] = OSD.FromString(regionHandle.ToString());
173 207
174 string strBuffer = ""; 208 string strBuffer = "";
@@ -231,9 +265,77 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
231 265
232 } 266 }
233 267
234 #endregion /* IInterregionComms */ 268 protected bool DoReleaseAgentCall(ulong regionHandle, UUID id, string uri)
269 {
270 //Console.WriteLine(" >>> DoReleaseAgentCall <<< " + uri);
271
272 WebRequest request = WebRequest.Create(uri);
273 request.Method = "DELETE";
274 request.Timeout = 10000;
275
276 try
277 {
278 WebResponse webResponse = request.GetResponse();
279 if (webResponse == null)
280 {
281 m_log.Info("[REST COMMS]: Null reply on agent get ");
282 }
283
284 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
285 //reply = sr.ReadToEnd().Trim();
286 sr.ReadToEnd().Trim();
287 sr.Close();
288 //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
289
290 }
291 catch (WebException ex)
292 {
293 m_log.InfoFormat("[REST COMMS]: exception on reply of agent get {0}", ex.Message);
294 // ignore, really
295 }
296
297 return true;
298
299 }
300
301 protected bool DoCloseAgentCall(RegionInfo region, UUID id)
302 {
303 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + id + "/" + region.RegionHandle.ToString() +"/";
304
305 //Console.WriteLine(" >>> DoCloseAgentCall <<< " + uri);
235 306
236 #region Called from remote instances on this instance 307 WebRequest request = WebRequest.Create(uri);
308 request.Method = "DELETE";
309 request.Timeout = 10000;
310
311 try
312 {
313 WebResponse webResponse = request.GetResponse();
314 if (webResponse == null)
315 {
316 m_log.Info("[REST COMMS]: Null reply on agent get ");
317 }
318
319 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
320 //reply = sr.ReadToEnd().Trim();
321 sr.ReadToEnd().Trim();
322 sr.Close();
323 //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
324
325 }
326 catch (WebException ex)
327 {
328 m_log.InfoFormat("[REST COMMS]: exception on reply of agent get {0}", ex.Message);
329 // ignore, really
330 }
331
332 return true;
333
334 }
335
336 #endregion /* DoWork */
337
338 #region Incoming calls from remote instances
237 339
238 public Hashtable AgentHandler(Hashtable request) 340 public Hashtable AgentHandler(Hashtable request)
239 { 341 {
@@ -250,7 +352,8 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
250 352
251 UUID agentID; 353 UUID agentID;
252 string action; 354 string action;
253 if (!GetParams((string)request["uri"], out agentID, out action)) 355 ulong regionHandle;
356 if (!GetParams((string)request["uri"], out agentID, out regionHandle, out action))
254 { 357 {
255 m_log.InfoFormat("[REST COMMS]: Invalid parameters for agent message {0}", request["uri"]); 358 m_log.InfoFormat("[REST COMMS]: Invalid parameters for agent message {0}", request["uri"]);
256 responsedata["int_response_code"] = 404; 359 responsedata["int_response_code"] = 404;
@@ -274,11 +377,9 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
274 377
275 return responsedata; 378 return responsedata;
276 } 379 }
277 else if (method.Equals("GET")) 380 else if (method.Equals("DELETE"))
278 { 381 {
279 m_log.InfoFormat("[REST COMMS]: method {0} not implemented yet in agent message", method); 382 DoDelete(request, responsedata, agentID, action, regionHandle);
280 responsedata["int_response_code"] = 404;
281 responsedata["str_response_string"] = "false";
282 383
283 return responsedata; 384 return responsedata;
284 } 385 }
@@ -293,7 +394,7 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
293 394
294 } 395 }
295 396
296 protected virtual void DoPut(Hashtable request, Hashtable responsedata) 397 protected OSDMap GetOSDMap(Hashtable request)
297 { 398 {
298 OSDMap args = null; 399 OSDMap args = null;
299 try 400 try
@@ -302,20 +403,32 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
302 // We should pay attention to the content-type, but let's assume we know it's Json 403 // We should pay attention to the content-type, but let's assume we know it's Json
303 buffer = OSDParser.DeserializeJson((string)request["body"]); 404 buffer = OSDParser.DeserializeJson((string)request["body"]);
304 if (buffer.Type == OSDType.Map) 405 if (buffer.Type == OSDType.Map)
406 {
305 args = (OSDMap)buffer; 407 args = (OSDMap)buffer;
408 return args;
409 }
306 else 410 else
307 { 411 {
308 // uh? 412 // uh?
309 m_log.Debug("[REST COMMS]: Got OSD of type " + buffer.Type.ToString()); 413 m_log.Debug("[REST COMMS]: Got OSD of type " + buffer.Type.ToString());
414 return null;
310 } 415 }
311 } 416 }
312 catch (Exception ex) 417 catch (Exception ex)
313 { 418 {
314 m_log.InfoFormat("[REST COMMS]: exception on parse of ChildAgentUpdate message {0}", ex.Message); 419 m_log.InfoFormat("[REST COMMS]: exception on parse of ChildAgentUpdate message {0}", ex.Message);
420 return null;
421 }
422 }
423
424 protected virtual void DoPut(Hashtable request, Hashtable responsedata)
425 {
426 OSDMap args = GetOSDMap(request);
427 if (args == null)
428 {
315 responsedata["int_response_code"] = 400; 429 responsedata["int_response_code"] = 400;
316 responsedata["str_response_string"] = "false"; 430 responsedata["str_response_string"] = "false";
317 431 return;
318 return ;
319 } 432 }
320 433
321 // retrieve the regionhandle 434 // retrieve the regionhandle
@@ -343,19 +456,34 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
343 responsedata["str_response_string"] = result.ToString(); 456 responsedata["str_response_string"] = result.ToString();
344 } 457 }
345 458
459 protected virtual void DoDelete(Hashtable request, Hashtable responsedata, UUID id, string action, ulong regionHandle)
460 {
461 //Console.WriteLine(" >>> DoDelete action:" + action + "; regionHandle:" + regionHandle);
462 bool result = true;
463 if (action.Equals("release"))
464 {
465 result = m_localBackend.SendReleaseAgent(regionHandle, id, "");
466 }
467 else
468 result = m_localBackend.SendCloseAgent(regionHandle, id);
469
470 responsedata["int_response_code"] = 200;
471 responsedata["str_response_string"] = "OpenSim agent " + id.ToString();
472 }
346 #endregion 473 #endregion
347 474
348 #region Misc 475 #region Misc
349 /// <summary> 476 /// <summary>
350 /// Extract the param from an uri. 477 /// Extract the param from an uri.
351 /// </summary> 478 /// </summary>
352 /// <param name="uri">Something like this: /agent/uuid/ or /agent/uuid/release</param> 479 /// <param name="uri">Something like this: /agent/uuid/ or /agent/uuid/handle/release</param>
353 /// <param name="uri">uuid on uuid field</param> 480 /// <param name="uri">uuid on uuid field</param>
354 /// <param name="action">optional action</param> 481 /// <param name="action">optional action</param>
355 protected bool GetParams(string uri, out UUID uuid, out string action) 482 protected bool GetParams(string uri, out UUID uuid, out ulong regionHandle, out string action)
356 { 483 {
357 uuid = UUID.Zero; 484 uuid = UUID.Zero;
358 action = ""; 485 action = "";
486 regionHandle = 0;
359 487
360 uri = uri.Trim(new char[] { '/' }); 488 uri = uri.Trim(new char[] { '/' });
361 string[] parts = uri.Split('/'); 489 string[] parts = uri.Split('/');
@@ -369,20 +497,29 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
369 return false; 497 return false;
370 498
371 if (parts.Length >= 3) 499 if (parts.Length >= 3)
372 action = parts[2]; 500 UInt64.TryParse(parts[2], out regionHandle);
373 501 if (parts.Length >= 4)
502 action = parts[3];
503
374 return true; 504 return true;
375 } 505 }
376 } 506 }
377 507
378 protected virtual ulong GetRegionHandle(RegionInfo region) 508 protected virtual ulong GetRegionHandle(ulong handle)
379 { 509 {
380 if (m_aScene.SceneGridService is HGSceneCommunicationService) 510 if (m_aScene.SceneGridService is HGSceneCommunicationService)
381 return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.FindRegionHandle(region.RegionHandle); 511 return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.FindRegionHandle(handle);
382 512
383 return region.RegionHandle; 513 return handle;
384 } 514 }
385 515
516 protected virtual bool IsHyperlink(ulong handle)
517 {
518 if (m_aScene.SceneGridService is HGSceneCommunicationService)
519 return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.IsHyperlinkRegion(handle);
520
521 return false;
522 }
386 #endregion /* Misc */ 523 #endregion /* Misc */
387 524
388 } 525 }