aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules
diff options
context:
space:
mode:
authordiva2009-04-01 23:35:48 +0000
committerdiva2009-04-01 23:35:48 +0000
commit86c753a6bdce8788c6a23bebaf9a6015d5af238a (patch)
tree1cf7297e6e62cbaefa9d3bfa66fb089300545916 /OpenSim/Region/CoreModules
parentOne more bit of refactoring, so this can be used outside region code. (diff)
downloadopensim-SC-86c753a6bdce8788c6a23bebaf9a6015d5af238a.zip
opensim-SC-86c753a6bdce8788c6a23bebaf9a6015d5af238a.tar.gz
opensim-SC-86c753a6bdce8788c6a23bebaf9a6015d5af238a.tar.bz2
opensim-SC-86c753a6bdce8788c6a23bebaf9a6015d5af238a.tar.xz
More refactoring. This time extracting the client-side of RESTInterregionComms into a RegionClient class.
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r--OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs584
1 files changed, 51 insertions, 533 deletions
diff --git a/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs b/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs
index 7d6a988..b507bdd 100644
--- a/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs
+++ b/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs
@@ -36,6 +36,7 @@ using OpenMetaverse;
36using OpenMetaverse.StructuredData; 36using OpenMetaverse.StructuredData;
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Framework.Communications; 38using OpenSim.Framework.Communications;
39using OpenSim.Framework.Communications.Clients;
39using OpenSim.Region.CoreModules.Communications.Local; 40using OpenSim.Region.CoreModules.Communications.Local;
40using OpenSim.Region.Framework.Interfaces; 41using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes; 42using OpenSim.Region.Framework.Scenes;
@@ -55,6 +56,8 @@ namespace OpenSim.Region.CoreModules.Communications.REST
55 56
56 protected CommunicationsManager m_commsManager; 57 protected CommunicationsManager m_commsManager;
57 58
59 protected RegionToRegionClient m_regionClient;
60
58 #region IRegionModule 61 #region IRegionModule
59 62
60 public virtual void Initialise(Scene scene, IConfigSource config) 63 public virtual void Initialise(Scene scene, IConfigSource config)
@@ -112,6 +115,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
112 m_localBackend = new LocalInterregionComms(); 115 m_localBackend = new LocalInterregionComms();
113 m_commsManager = scene.CommsManager; 116 m_commsManager = scene.CommsManager;
114 m_aScene = scene; 117 m_aScene = scene;
118 m_regionClient = new RegionToRegionClient(m_aScene);
115 } 119 }
116 120
117 protected virtual void AddHTTPHandlers() 121 protected virtual void AddHTTPHandlers()
@@ -141,9 +145,9 @@ namespace OpenSim.Region.CoreModules.Communications.REST
141 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); 145 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle);
142 if (regInfo != null) 146 if (regInfo != null)
143 { 147 {
144 SendUserInformation(regInfo, aCircuit); 148 m_regionClient.SendUserInformation(regInfo, aCircuit);
145 149
146 return DoCreateChildAgentCall(regInfo, aCircuit); 150 return m_regionClient.DoCreateChildAgentCall(regInfo, aCircuit);
147 } 151 }
148 //else 152 //else
149 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); 153 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
@@ -163,7 +167,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
163 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); 167 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle);
164 if (regInfo != null) 168 if (regInfo != null)
165 { 169 {
166 return DoChildAgentUpdateCall(regInfo, cAgentData); 170 return m_regionClient.DoChildAgentUpdateCall(regInfo, cAgentData);
167 } 171 }
168 //else 172 //else
169 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); 173 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
@@ -184,7 +188,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
184 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); 188 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle);
185 if (regInfo != null) 189 if (regInfo != null)
186 { 190 {
187 return DoChildAgentUpdateCall(regInfo, cAgentData); 191 return m_regionClient.DoChildAgentUpdateCall(regInfo, cAgentData);
188 } 192 }
189 //else 193 //else
190 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); 194 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
@@ -205,7 +209,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
205 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); 209 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle);
206 if (regInfo != null) 210 if (regInfo != null)
207 { 211 {
208 return DoRetrieveRootAgentCall(regInfo, id, out agent); 212 return m_regionClient.DoRetrieveRootAgentCall(regInfo, id, out agent);
209 } 213 }
210 //else 214 //else
211 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); 215 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
@@ -221,7 +225,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
221 return true; 225 return true;
222 226
223 // else do the remote thing 227 // else do the remote thing
224 return DoReleaseAgentCall(regionHandle, id, uri); 228 return m_regionClient.DoReleaseAgentCall(regionHandle, id, uri);
225 } 229 }
226 230
227 231
@@ -237,7 +241,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
237 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); 241 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle);
238 if (regInfo != null) 242 if (regInfo != null)
239 { 243 {
240 return DoCloseAgentCall(regInfo, id); 244 return m_regionClient.DoCloseAgentCall(regInfo, id);
241 } 245 }
242 //else 246 //else
243 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); 247 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
@@ -264,7 +268,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
264 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); 268 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle);
265 if (regInfo != null) 269 if (regInfo != null)
266 { 270 {
267 return DoCreateObjectCall(regInfo, sog); 271 return m_regionClient.DoCreateObjectCall(regInfo, sog, m_aScene.m_allowScriptCrossings);
268 } 272 }
269 //else 273 //else
270 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); 274 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
@@ -291,7 +295,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
291 // Don't remote-call this instance; that's a startup hickup 295 // Don't remote-call this instance; that's a startup hickup
292 !((regInfo.ExternalHostName == thisRegion.ExternalHostName) && (regInfo.HttpPort == thisRegion.HttpPort))) 296 !((regInfo.ExternalHostName == thisRegion.ExternalHostName) && (regInfo.HttpPort == thisRegion.HttpPort)))
293 { 297 {
294 return DoHelloNeighbourCall(regInfo, thisRegion); 298 return m_regionClient.DoHelloNeighbourCall(regInfo, thisRegion);
295 } 299 }
296 //else 300 //else
297 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); 301 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
@@ -300,472 +304,6 @@ namespace OpenSim.Region.CoreModules.Communications.REST
300 304
301 #endregion /* IInterregionComms */ 305 #endregion /* IInterregionComms */
302 306
303 #region DoWork functions for the above public interface
304
305 //-------------------------------------------------------------------
306 // Internal functions for the above public interface
307 //-------------------------------------------------------------------
308
309 public bool DoCreateChildAgentCall(RegionInfo region, AgentCircuitData aCircuit)
310 {
311 // Eventually, we want to use a caps url instead of the agentID
312 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + aCircuit.AgentID + "/";
313 //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri);
314
315 HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri);
316 AgentCreateRequest.Method = "POST";
317 AgentCreateRequest.ContentType = "application/json";
318 AgentCreateRequest.Timeout = 10000;
319 //AgentCreateRequest.KeepAlive = false;
320
321 // Fill it in
322 OSDMap args = null;
323 try
324 {
325 args = aCircuit.PackAgentCircuitData();
326 }
327 catch (Exception e)
328 {
329 m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
330 }
331 // Add the regionhandle of the destination region
332 ulong regionHandle = GetRegionHandle(region.RegionHandle);
333 args["destination_handle"] = OSD.FromString(regionHandle.ToString());
334
335 string strBuffer = "";
336 byte[] buffer = new byte[1];
337 try
338 {
339 strBuffer = OSDParser.SerializeJsonString(args);
340 UTF8Encoding str = new UTF8Encoding();
341 buffer = str.GetBytes(strBuffer);
342
343 }
344 catch (Exception e)
345 {
346 m_log.WarnFormat("[OSG2]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
347 // ignore. buffer will be empty, caller should check.
348 }
349
350 Stream os = null;
351 try
352 { // send the Post
353 AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
354 os = AgentCreateRequest.GetRequestStream();
355 os.Write(buffer, 0, strBuffer.Length); //Send it
356 os.Close();
357 //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
358 }
359 //catch (WebException ex)
360 catch
361 {
362 //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
363
364 return false;
365 }
366
367 // Let's wait for the response
368 //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
369
370 try
371 {
372 WebResponse webResponse = AgentCreateRequest.GetResponse();
373 if (webResponse == null)
374 {
375 m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
376 }
377
378 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
379 //reply = sr.ReadToEnd().Trim();
380 sr.ReadToEnd().Trim();
381 sr.Close();
382 //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply);
383
384 }
385 catch (WebException ex)
386 {
387 m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
388 // ignore, really
389 }
390
391 return true;
392
393 }
394
395 public bool DoChildAgentUpdateCall(RegionInfo region, IAgentData cAgentData)
396 {
397 // Eventually, we want to use a caps url instead of the agentID
398 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + cAgentData.AgentID + "/";
399 //Console.WriteLine(" >>> DoChildAgentUpdateCall <<< " + uri);
400
401 HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri);
402 ChildUpdateRequest.Method = "PUT";
403 ChildUpdateRequest.ContentType = "application/json";
404 ChildUpdateRequest.Timeout = 10000;
405 //ChildUpdateRequest.KeepAlive = false;
406
407 // Fill it in
408 OSDMap args = null;
409 try
410 {
411 args = cAgentData.Pack();
412 }
413 catch (Exception e)
414 {
415 m_log.Debug("[REST COMMS]: PackUpdateMessage failed with exception: " + e.Message);
416 }
417 // Add the regionhandle of the destination region
418 ulong regionHandle = GetRegionHandle(region.RegionHandle);
419 args["destination_handle"] = OSD.FromString(regionHandle.ToString());
420
421 string strBuffer = "";
422 byte[] buffer = new byte[1];
423 try
424 {
425 strBuffer = OSDParser.SerializeJsonString(args);
426 UTF8Encoding str = new UTF8Encoding();
427 buffer = str.GetBytes(strBuffer);
428
429 }
430 catch (Exception e)
431 {
432 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
433 // ignore. buffer will be empty, caller should check.
434 }
435
436 Stream os = null;
437 try
438 { // send the Post
439 ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send
440 os = ChildUpdateRequest.GetRequestStream();
441 os.Write(buffer, 0, strBuffer.Length); //Send it
442 os.Close();
443 //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
444 }
445 //catch (WebException ex)
446 catch
447 {
448 //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
449
450 return false;
451 }
452
453 // Let's wait for the response
454 //m_log.Info("[REST COMMS]: Waiting for a reply after ChildAgentUpdate");
455
456 try
457 {
458 WebResponse webResponse = ChildUpdateRequest.GetResponse();
459 if (webResponse == null)
460 {
461 m_log.Info("[REST COMMS]: Null reply on ChilAgentUpdate post");
462 }
463
464 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
465 //reply = sr.ReadToEnd().Trim();
466 sr.ReadToEnd().Trim();
467 sr.Close();
468 //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
469
470 }
471 catch (WebException ex)
472 {
473 m_log.InfoFormat("[REST COMMS]: exception on reply of ChilAgentUpdate {0}", ex.Message);
474 // ignore, really
475 }
476
477 return true;
478 }
479
480 public bool DoRetrieveRootAgentCall(RegionInfo region, UUID id, out IAgentData agent)
481 {
482 agent = null;
483 // Eventually, we want to use a caps url instead of the agentID
484 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + id + "/" + region.RegionHandle.ToString() + "/";
485 //Console.WriteLine(" >>> DoRetrieveRootAgentCall <<< " + uri);
486
487 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
488 request.Method = "GET";
489 request.Timeout = 10000;
490 //request.Headers.Add("authorization", ""); // coming soon
491
492 HttpWebResponse webResponse = null;
493 string reply = string.Empty;
494 try
495 {
496 webResponse = (HttpWebResponse)request.GetResponse();
497 if (webResponse == null)
498 {
499 m_log.Info("[REST COMMS]: Null reply on agent get ");
500 }
501
502 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
503 reply = sr.ReadToEnd().Trim();
504 sr.Close();
505
506 //Console.WriteLine("[REST COMMS]: ChilAgentUpdate reply was " + reply);
507
508 }
509 catch (WebException ex)
510 {
511 m_log.InfoFormat("[REST COMMS]: exception on reply of agent get {0}", ex.Message);
512 // ignore, really
513 return false;
514 }
515
516 if (webResponse.StatusCode == HttpStatusCode.OK)
517 {
518 // we know it's jason
519 OSDMap args = GetOSDMap(reply);
520 if (args == null)
521 {
522 //Console.WriteLine("[REST COMMS]: Error getting OSDMap from reply");
523 return false;
524 }
525
526 agent = new CompleteAgentData();
527 agent.Unpack(args);
528 return true;
529 }
530
531 //Console.WriteLine("[REST COMMS]: DoRetrieveRootAgentCall returned status " + webResponse.StatusCode);
532 return false;
533 }
534
535 public bool DoReleaseAgentCall(ulong regionHandle, UUID id, string uri)
536 {
537 //m_log.Debug(" >>> DoReleaseAgentCall <<< " + uri);
538
539 WebRequest request = WebRequest.Create(uri);
540 request.Method = "DELETE";
541 request.Timeout = 10000;
542
543 try
544 {
545 WebResponse webResponse = request.GetResponse();
546 if (webResponse == null)
547 {
548 m_log.Info("[REST COMMS]: Null reply on agent delete ");
549 }
550
551 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
552 //reply = sr.ReadToEnd().Trim();
553 sr.ReadToEnd().Trim();
554 sr.Close();
555 //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
556
557 }
558 catch (WebException ex)
559 {
560 m_log.InfoFormat("[REST COMMS]: exception on reply of agent delete {0}", ex.Message);
561 // ignore, really
562 }
563
564 return true;
565 }
566
567
568 public bool DoCloseAgentCall(RegionInfo region, UUID id)
569 {
570 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + id + "/" + region.RegionHandle.ToString() +"/";
571
572 //Console.WriteLine(" >>> DoCloseAgentCall <<< " + uri);
573
574 WebRequest request = WebRequest.Create(uri);
575 request.Method = "DELETE";
576 request.Timeout = 10000;
577
578 try
579 {
580 WebResponse webResponse = request.GetResponse();
581 if (webResponse == null)
582 {
583 m_log.Info("[REST COMMS]: Null reply on agent delete ");
584 }
585
586 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
587 //reply = sr.ReadToEnd().Trim();
588 sr.ReadToEnd().Trim();
589 sr.Close();
590 //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
591
592 }
593 catch (WebException ex)
594 {
595 m_log.InfoFormat("[REST COMMS]: exception on reply of agent delete {0}", ex.Message);
596 // ignore, really
597 }
598
599 return true;
600 }
601
602 public bool DoCreateObjectCall(RegionInfo region, ISceneObject sog)
603 {
604 ulong regionHandle = GetRegionHandle(region.RegionHandle);
605 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/object/" + sog.UUID + "/" + regionHandle.ToString() + "/";
606 //m_log.Debug(" >>> DoCreateChildAgentCall <<< " + uri);
607
608 WebRequest ObjectCreateRequest = WebRequest.Create(uri);
609 ObjectCreateRequest.Method = "POST";
610 ObjectCreateRequest.ContentType = "application/json";
611 ObjectCreateRequest.Timeout = 10000;
612
613 OSDMap args = new OSDMap(2);
614 args["sog"] = OSD.FromString(sog.ToXmlString2());
615 args["extra"] = OSD.FromString(sog.ExtraToXmlString());
616 if (m_aScene.m_allowScriptCrossings)
617 {
618 string state = sog.GetStateSnapshot();
619 if (state.Length > 0)
620 args["state"] = OSD.FromString(state);
621 }
622
623 string strBuffer = "";
624 byte[] buffer = new byte[1];
625 try
626 {
627 strBuffer = OSDParser.SerializeJsonString(args);
628 UTF8Encoding str = new UTF8Encoding();
629 buffer = str.GetBytes(strBuffer);
630
631 }
632 catch (Exception e)
633 {
634 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of CreateObject: {0}", e.Message);
635 // ignore. buffer will be empty, caller should check.
636 }
637
638 Stream os = null;
639 try
640 { // send the Post
641 ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send
642 os = ObjectCreateRequest.GetRequestStream();
643 os.Write(buffer, 0, strBuffer.Length); //Send it
644 os.Close();
645 m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
646 }
647 //catch (WebException ex)
648 catch
649 {
650 // m_log.InfoFormat("[REST COMMS]: Bad send on CreateObject {0}", ex.Message);
651
652 return false;
653 }
654
655 // Let's wait for the response
656 //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
657
658 try
659 {
660 WebResponse webResponse = ObjectCreateRequest.GetResponse();
661 if (webResponse == null)
662 {
663 m_log.Info("[REST COMMS]: Null reply on DoCreateObjectCall post");
664 }
665
666 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
667 //reply = sr.ReadToEnd().Trim();
668 sr.ReadToEnd().Trim();
669 sr.Close();
670 //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply);
671
672 }
673 catch (WebException ex)
674 {
675 m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateObjectCall {0}", ex.Message);
676 // ignore, really
677 }
678
679 return true;
680
681 }
682
683 public bool DoHelloNeighbourCall(RegionInfo region, RegionInfo thisRegion)
684 {
685 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/region/" + thisRegion.RegionID + "/";
686 //m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri);
687
688 WebRequest HelloNeighbourRequest = WebRequest.Create(uri);
689 HelloNeighbourRequest.Method = "POST";
690 HelloNeighbourRequest.ContentType = "application/json";
691 HelloNeighbourRequest.Timeout = 10000;
692
693 // Fill it in
694 OSDMap args = null;
695 try
696 {
697 args = thisRegion.PackRegionInfoData();
698 }
699 catch (Exception e)
700 {
701 m_log.Debug("[REST COMMS]: PackRegionInfoData failed with exception: " + e.Message);
702 }
703 // Add the regionhandle of the destination region
704 ulong regionHandle = GetRegionHandle(region.RegionHandle);
705 args["destination_handle"] = OSD.FromString(regionHandle.ToString());
706
707 string strBuffer = "";
708 byte[] buffer = new byte[1];
709 try
710 {
711 strBuffer = OSDParser.SerializeJsonString(args);
712 UTF8Encoding str = new UTF8Encoding();
713 buffer = str.GetBytes(strBuffer);
714
715 }
716 catch (Exception e)
717 {
718 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of HelloNeighbour: {0}", e.Message);
719 // ignore. buffer will be empty, caller should check.
720 }
721
722 Stream os = null;
723 try
724 { // send the Post
725 HelloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send
726 os = HelloNeighbourRequest.GetRequestStream();
727 os.Write(buffer, 0, strBuffer.Length); //Send it
728 os.Close();
729 //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri);
730 }
731 //catch (WebException ex)
732 catch
733 {
734 //m_log.InfoFormat("[REST COMMS]: Bad send on HelloNeighbour {0}", ex.Message);
735
736 return false;
737 }
738
739 // Let's wait for the response
740 //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall");
741
742 try
743 {
744 WebResponse webResponse = HelloNeighbourRequest.GetResponse();
745 if (webResponse == null)
746 {
747 m_log.Info("[REST COMMS]: Null reply on DoHelloNeighbourCall post");
748 }
749
750 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
751 //reply = sr.ReadToEnd().Trim();
752 sr.ReadToEnd().Trim();
753 sr.Close();
754 //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply);
755
756 }
757 catch (WebException ex)
758 {
759 m_log.InfoFormat("[REST COMMS]: exception on reply of DoHelloNeighbourCall {0}", ex.Message);
760 // ignore, really
761 }
762
763 return true;
764
765 }
766
767 #endregion /* Do Work */
768
769 #region Incoming calls from remote instances 307 #region Incoming calls from remote instances
770 308
771 /** 309 /**
@@ -833,7 +371,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
833 371
834 protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) 372 protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
835 { 373 {
836 OSDMap args = GetOSDMap((string)request["body"]); 374 OSDMap args = RegionClient.GetOSDMap((string)request["body"]);
837 if (args == null) 375 if (args == null)
838 { 376 {
839 responsedata["int_response_code"] = 400; 377 responsedata["int_response_code"] = 400;
@@ -858,7 +396,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
858 } 396 }
859 397
860 // This is the meaning of POST agent 398 // This is the meaning of POST agent
861 AdjustUserInformation(aCircuit); 399 m_regionClient.AdjustUserInformation(aCircuit);
862 bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit); 400 bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit);
863 401
864 responsedata["int_response_code"] = 200; 402 responsedata["int_response_code"] = 200;
@@ -867,7 +405,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
867 405
868 protected virtual void DoAgentPut(Hashtable request, Hashtable responsedata) 406 protected virtual void DoAgentPut(Hashtable request, Hashtable responsedata)
869 { 407 {
870 OSDMap args = GetOSDMap((string)request["body"]); 408 OSDMap args = RegionClient.GetOSDMap((string)request["body"]);
871 if (args == null) 409 if (args == null)
872 { 410 {
873 responsedata["int_response_code"] = 400; 411 responsedata["int_response_code"] = 400;
@@ -1042,7 +580,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
1042 580
1043 protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, ulong regionhandle) 581 protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, ulong regionhandle)
1044 { 582 {
1045 OSDMap args = GetOSDMap((string)request["body"]); 583 OSDMap args = RegionClient.GetOSDMap((string)request["body"]);
1046 if (args == null) 584 if (args == null)
1047 { 585 {
1048 responsedata["int_response_code"] = 400; 586 responsedata["int_response_code"] = 400;
@@ -1154,7 +692,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
1154 692
1155 protected virtual void DoRegionPost(Hashtable request, Hashtable responsedata, UUID id) 693 protected virtual void DoRegionPost(Hashtable request, Hashtable responsedata, UUID id)
1156 { 694 {
1157 OSDMap args = GetOSDMap((string)request["body"]); 695 OSDMap args = RegionClient.GetOSDMap((string)request["body"]);
1158 if (args == null) 696 if (args == null)
1159 { 697 {
1160 responsedata["int_response_code"] = 400; 698 responsedata["int_response_code"] = 400;
@@ -1190,32 +728,6 @@ namespace OpenSim.Region.CoreModules.Communications.REST
1190 728
1191 #region Misc 729 #region Misc
1192 730
1193 public static OSDMap GetOSDMap(string data)
1194 {
1195 OSDMap args = null;
1196 try
1197 {
1198 OSD buffer;
1199 // We should pay attention to the content-type, but let's assume we know it's Json
1200 buffer = OSDParser.DeserializeJson(data);
1201 if (buffer.Type == OSDType.Map)
1202 {
1203 args = (OSDMap)buffer;
1204 return args;
1205 }
1206 else
1207 {
1208 // uh?
1209 Console.WriteLine("[REST COMMS]: Got OSD of type " + buffer.Type.ToString());
1210 return null;
1211 }
1212 }
1213 catch (Exception ex)
1214 {
1215 Console.WriteLine("[REST COMMS]: exception on parse of REST message " + ex.Message);
1216 return null;
1217 }
1218 }
1219 731
1220 /// <summary> 732 /// <summary>
1221 /// Extract the param from an uri. 733 /// Extract the param from an uri.
@@ -1251,45 +763,51 @@ namespace OpenSim.Region.CoreModules.Communications.REST
1251 763
1252 #endregion Misc 764 #endregion Misc
1253 765
1254 #region Hyperlinks 766 protected class RegionToRegionClient : RegionClient
1255
1256 protected virtual ulong GetRegionHandle(ulong handle)
1257 { 767 {
1258 if (m_aScene.SceneGridService is HGSceneCommunicationService) 768 Scene m_aScene = null;
1259 return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.FindRegionHandle(handle);
1260 769
1261 return handle; 770 public RegionToRegionClient(Scene s)
1262 } 771 {
772 m_aScene = s;
773 }
1263 774
1264 protected virtual bool IsHyperlink(ulong handle) 775 public override ulong GetRegionHandle(ulong handle)
1265 { 776 {
1266 if (m_aScene.SceneGridService is HGSceneCommunicationService) 777 if (m_aScene.SceneGridService is HGSceneCommunicationService)
1267 return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.IsHyperlinkRegion(handle); 778 return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.FindRegionHandle(handle);
1268 779
1269 return false; 780 return handle;
1270 } 781 }
1271 782
1272 protected virtual void SendUserInformation(RegionInfo regInfo, AgentCircuitData aCircuit) 783 public override bool IsHyperlink(ulong handle)
1273 {
1274 try
1275 { 784 {
1276 //if (IsHyperlink(regInfo.RegionHandle))
1277 if (m_aScene.SceneGridService is HGSceneCommunicationService) 785 if (m_aScene.SceneGridService is HGSceneCommunicationService)
786 return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.IsHyperlinkRegion(handle);
787
788 return false;
789 }
790
791 public override void SendUserInformation(RegionInfo regInfo, AgentCircuitData aCircuit)
792 {
793 try
1278 { 794 {
1279 ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.SendUserInformation(regInfo, aCircuit); 795 if (m_aScene.SceneGridService is HGSceneCommunicationService)
796 {
797 ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.SendUserInformation(regInfo, aCircuit);
798 }
1280 } 799 }
1281 } 800 catch // Bad cast
1282 catch // Bad cast 801 { }
1283 { }
1284 802
1285 } 803 }
1286 804
1287 protected virtual void AdjustUserInformation(AgentCircuitData aCircuit) 805 public override void AdjustUserInformation(AgentCircuitData aCircuit)
1288 { 806 {
1289 if (m_aScene.SceneGridService is HGSceneCommunicationService) 807 if (m_aScene.SceneGridService is HGSceneCommunicationService)
1290 ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.AdjustUserInformation(aCircuit); 808 ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.AdjustUserInformation(aCircuit);
809 }
1291 } 810 }
1292 #endregion /* Hyperlinks */
1293 811
1294 } 812 }
1295} 813}