aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Communications
diff options
context:
space:
mode:
authordiva2009-02-14 16:37:55 +0000
committerdiva2009-02-14 16:37:55 +0000
commit217ffee8cb50e0a7ddfc0d4c4e4bb6a68de909d8 (patch)
tree3131df695140a7846fcd86b689c9a9afe5ee880f /OpenSim/Region/CoreModules/Communications
parentThank you, patnad, for a patch that removes the "Subdivision of" text (diff)
downloadopensim-SC_OLD-217ffee8cb50e0a7ddfc0d4c4e4bb6a68de909d8.zip
opensim-SC_OLD-217ffee8cb50e0a7ddfc0d4c4e4bb6a68de909d8.tar.gz
opensim-SC_OLD-217ffee8cb50e0a7ddfc0d4c4e4bb6a68de909d8.tar.bz2
opensim-SC_OLD-217ffee8cb50e0a7ddfc0d4c4e4bb6a68de909d8.tar.xz
Moved RegionUp to REST/LocalComms. The original functionality has been entirely maintained, although it will have to be revisited soon, because it's buggy.
Diffstat (limited to 'OpenSim/Region/CoreModules/Communications')
-rw-r--r--OpenSim/Region/CoreModules/Communications/Local/LocalInterregionComms.cs17
-rw-r--r--OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs268
2 files changed, 254 insertions, 31 deletions
diff --git a/OpenSim/Region/CoreModules/Communications/Local/LocalInterregionComms.cs b/OpenSim/Region/CoreModules/Communications/Local/LocalInterregionComms.cs
index 6e813f4..29bc4f7 100644
--- a/OpenSim/Region/CoreModules/Communications/Local/LocalInterregionComms.cs
+++ b/OpenSim/Region/CoreModules/Communications/Local/LocalInterregionComms.cs
@@ -227,6 +227,23 @@ namespace OpenSim.Region.CoreModules.Communications.Local
227 return false; 227 return false;
228 } 228 }
229 229
230 /**
231 * Region-related communications
232 */
233
234 public bool SendHelloNeighbour(ulong regionHandle, RegionInfo thisRegion)
235 {
236 foreach (Scene s in m_sceneList)
237 {
238 if (s.RegionInfo.RegionHandle == regionHandle)
239 {
240 //m_log.Debug("[LOCAL COMMS]: Found region to SendHelloNeighbour");
241 return s.IncomingHelloNeighbour(thisRegion);
242 }
243 }
244 return false;
245 }
246
230 #endregion /* IInterregionComms */ 247 #endregion /* IInterregionComms */
231 248
232 #region Misc 249 #region Misc
diff --git a/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs b/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs
index fcb3f5b..bc98337 100644
--- a/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs
+++ b/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs
@@ -45,7 +45,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
45{ 45{
46 public class RESTInterregionComms : IRegionModule, IInterregionCommsOut 46 public class RESTInterregionComms : IRegionModule, IInterregionCommsOut
47 { 47 {
48 private bool initialized = false; 48 private static bool initialized = false;
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 50
51 protected bool m_enabled = false; 51 protected bool m_enabled = false;
@@ -78,6 +78,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
78 return; 78 return;
79 79
80 InitEach(scene); 80 InitEach(scene);
81
81 } 82 }
82 83
83 public virtual void PostInitialise() 84 public virtual void PostInitialise()
@@ -115,8 +116,9 @@ namespace OpenSim.Region.CoreModules.Communications.REST
115 116
116 protected virtual void AddHTTPHandlers() 117 protected virtual void AddHTTPHandlers()
117 { 118 {
118 m_aScene.CommsManager.HttpServer.AddHTTPHandler("/agent/", AgentHandler); 119 m_aScene.CommsManager.HttpServer.AddHTTPHandler("/agent/", AgentHandler);
119 m_aScene.CommsManager.HttpServer.AddHTTPHandler("/object/", ObjectHandler); 120 m_aScene.CommsManager.HttpServer.AddHTTPHandler("/object/", ObjectHandler);
121 m_aScene.CommsManager.HttpServer.AddHTTPHandler("/region/", RegionHandler);
120 } 122 }
121 123
122 #endregion /* IRegionModule */ 124 #endregion /* IRegionModule */
@@ -161,6 +163,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
161 //else 163 //else
162 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); 164 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
163 return false; 165 return false;
166
164 } 167 }
165 168
166 public bool SendChildAgentUpdate(ulong regionHandle, AgentPosition cAgentData) 169 public bool SendChildAgentUpdate(ulong regionHandle, AgentPosition cAgentData)
@@ -178,6 +181,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
178 //else 181 //else
179 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); 182 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
180 return false; 183 return false;
184
181 } 185 }
182 186
183 public bool SendReleaseAgent(ulong regionHandle, UUID id, string uri) 187 public bool SendReleaseAgent(ulong regionHandle, UUID id, string uri)
@@ -231,6 +235,32 @@ namespace OpenSim.Region.CoreModules.Communications.REST
231 return false; 235 return false;
232 } 236 }
233 237
238 /**
239 * Region-related communications
240 */
241
242 public bool SendHelloNeighbour(ulong regionHandle, RegionInfo thisRegion)
243 {
244 // Try local first
245 if (m_localBackend.SendHelloNeighbour(regionHandle, thisRegion))
246 {
247 //m_log.Debug("[REST COMMS]: LocalBackEnd SendHelloNeighbour succeeded");
248 return true;
249 }
250
251 // else do the remote thing
252 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle);
253 if ((regInfo != null) &&
254 // Don't remote-call this instance; that's a startup hickup
255 !((regInfo.ExternalHostName == thisRegion.ExternalHostName) && (regInfo.HttpPort == thisRegion.HttpPort)))
256 {
257 return DoHelloNeighbourCall(regInfo, thisRegion);
258 }
259 //else
260 // m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
261 return false;
262 }
263
234 #endregion /* IInterregionComms */ 264 #endregion /* IInterregionComms */
235 265
236 #region DoWork functions for the above public interface 266 #region DoWork functions for the above public interface
@@ -482,7 +512,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST
482 512
483 WebRequest ObjectCreateRequest = WebRequest.Create(uri); 513 WebRequest ObjectCreateRequest = WebRequest.Create(uri);
484 ObjectCreateRequest.Method = "POST"; 514 ObjectCreateRequest.Method = "POST";
485 ObjectCreateRequest.ContentType = "text/xml"; 515 ObjectCreateRequest.ContentType = "application/json";
486 ObjectCreateRequest.Timeout = 10000; 516 ObjectCreateRequest.Timeout = 10000;
487 517
488 OSDMap args = new OSDMap(2); 518 OSDMap args = new OSDMap(2);
@@ -555,6 +585,90 @@ namespace OpenSim.Region.CoreModules.Communications.REST
555 585
556 } 586 }
557 587
588 protected bool DoHelloNeighbourCall(RegionInfo region, RegionInfo thisRegion)
589 {
590 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/region/" + thisRegion.RegionID + "/";
591 //Console.WriteLine(" >>> DoHelloNeighbourCall <<< " + uri);
592
593 WebRequest HelloNeighbourRequest = WebRequest.Create(uri);
594 HelloNeighbourRequest.Method = "POST";
595 HelloNeighbourRequest.ContentType = "application/json";
596 HelloNeighbourRequest.Timeout = 10000;
597
598 // Fill it in
599 OSDMap args = null;
600 try
601 {
602 args = thisRegion.PackRegionInfoData();
603 }
604 catch (Exception e)
605 {
606 m_log.Debug("[REST COMMS]: PackRegionInfoData failed with exception: " + e.Message);
607 }
608 // Add the regionhandle of the destination region
609 ulong regionHandle = GetRegionHandle(region.RegionHandle);
610 args["destination_handle"] = OSD.FromString(regionHandle.ToString());
611
612 string strBuffer = "";
613 byte[] buffer = new byte[1];
614 try
615 {
616 strBuffer = OSDParser.SerializeJsonString(args);
617 UTF8Encoding str = new UTF8Encoding();
618 buffer = str.GetBytes(strBuffer);
619
620 }
621 catch (Exception e)
622 {
623 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of HelloNeighbour: {0}", e.Message);
624 // ignore. buffer will be empty, caller should check.
625 }
626
627 Stream os = null;
628 try
629 { // send the Post
630 HelloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send
631 os = HelloNeighbourRequest.GetRequestStream();
632 os.Write(buffer, 0, strBuffer.Length); //Send it
633 os.Close();
634 //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri);
635 }
636 //catch (WebException ex)
637 catch
638 {
639 //m_log.InfoFormat("[REST COMMS]: Bad send on HelloNeighbour {0}", ex.Message);
640
641 return false;
642 }
643
644 // Let's wait for the response
645 //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall");
646
647 try
648 {
649 WebResponse webResponse = HelloNeighbourRequest.GetResponse();
650 if (webResponse == null)
651 {
652 m_log.Info("[REST COMMS]: Null reply on DoHelloNeighbourCall post");
653 }
654
655 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
656 //reply = sr.ReadToEnd().Trim();
657 sr.ReadToEnd().Trim();
658 sr.Close();
659 //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply);
660
661 }
662 catch (WebException ex)
663 {
664 m_log.InfoFormat("[REST COMMS]: exception on reply of DoHelloNeighbourCall {0}", ex.Message);
665 // ignore, really
666 }
667
668 return true;
669
670 }
671
558 #endregion /* Do Work */ 672 #endregion /* Do Work */
559 673
560 #region Incoming calls from remote instances 674 #region Incoming calls from remote instances
@@ -617,33 +731,6 @@ namespace OpenSim.Region.CoreModules.Communications.REST
617 731
618 } 732 }
619 733
620 protected OSDMap GetOSDMap(Hashtable request)
621 {
622 OSDMap args = null;
623 try
624 {
625 OSD buffer;
626 // We should pay attention to the content-type, but let's assume we know it's Json
627 buffer = OSDParser.DeserializeJson((string)request["body"]);
628 if (buffer.Type == OSDType.Map)
629 {
630 args = (OSDMap)buffer;
631 return args;
632 }
633 else
634 {
635 // uh?
636 m_log.Debug("[REST COMMS]: Got OSD of type " + buffer.Type.ToString());
637 return null;
638 }
639 }
640 catch (Exception ex)
641 {
642 m_log.InfoFormat("[REST COMMS]: exception on parse of REST message {0}", ex.Message);
643 return null;
644 }
645 }
646
647 protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) 734 protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
648 { 735 {
649 OSDMap args = GetOSDMap(request); 736 OSDMap args = GetOSDMap(request);
@@ -868,10 +955,129 @@ namespace OpenSim.Region.CoreModules.Communications.REST
868 responsedata["str_response_string"] = result.ToString(); 955 responsedata["str_response_string"] = result.ToString();
869 } 956 }
870 957
958 /*
959 * Region-related incoming calls
960 *
961 */
962
963 public Hashtable RegionHandler(Hashtable request)
964 {
965 //m_log.Debug("[CONNECTION DEBUGGING]: RegionHandler Called");
966
967 //Console.WriteLine("---------------------------");
968 //Console.WriteLine(" >> uri=" + request["uri"]);
969 //Console.WriteLine(" >> content-type=" + request["content-type"]);
970 //Console.WriteLine(" >> http-method=" + request["http-method"]);
971 //Console.WriteLine("---------------------------\n");
972
973 Hashtable responsedata = new Hashtable();
974 responsedata["content_type"] = "text/html";
975
976 UUID regionID;
977 string action;
978 ulong regionHandle;
979 if (!GetParams((string)request["uri"], out regionID, out regionHandle, out action))
980 {
981 m_log.InfoFormat("[REST COMMS]: Invalid parameters for object message {0}", request["uri"]);
982 responsedata["int_response_code"] = 404;
983 responsedata["str_response_string"] = "false";
984
985 return responsedata;
986 }
987
988 // Next, let's parse the verb
989 string method = (string)request["http-method"];
990 if (method.Equals("POST"))
991 {
992 DoRegionPost(request, responsedata, regionID);
993 return responsedata;
994 }
995 //else if (method.Equals("PUT"))
996 //{
997 // DoRegionPut(request, responsedata, regionID);
998 // return responsedata;
999 //}
1000 //else if (method.Equals("DELETE"))
1001 //{
1002 // DoRegionDelete(request, responsedata, regiontID);
1003 // return responsedata;
1004 //}
1005 else
1006 {
1007 m_log.InfoFormat("[REST COMMS]: method {0} not supported in region message", method);
1008 responsedata["int_response_code"] = 404;
1009 responsedata["str_response_string"] = "false";
1010
1011 return responsedata;
1012 }
1013
1014 }
1015
1016 protected virtual void DoRegionPost(Hashtable request, Hashtable responsedata, UUID id)
1017 {
1018 OSDMap args = GetOSDMap(request);
1019 if (args == null)
1020 {
1021 responsedata["int_response_code"] = 400;
1022 responsedata["str_response_string"] = "false";
1023 return;
1024 }
1025
1026 // retrieve the regionhandle
1027 ulong regionhandle = 0;
1028 if (args["destination_handle"] != null)
1029 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
1030
1031 RegionInfo aRegion = new RegionInfo();
1032 try
1033 {
1034 aRegion.UnpackRegionInfoData(args);
1035 }
1036 catch (Exception ex)
1037 {
1038 m_log.InfoFormat("[REST COMMS]: exception on unpacking HelloNeighbour message {0}", ex.Message);
1039 return;
1040 }
1041
1042 // This is the meaning of POST region
1043 bool result = m_localBackend.SendHelloNeighbour(regionhandle, aRegion);
1044
1045 responsedata["int_response_code"] = 200;
1046 responsedata["str_response_string"] = result.ToString();
1047 }
1048
1049
871 #endregion 1050 #endregion
872 1051
873 #region Misc 1052 #region Misc
874 1053
1054 protected OSDMap GetOSDMap(Hashtable request)
1055 {
1056 OSDMap args = null;
1057 try
1058 {
1059 OSD buffer;
1060 // We should pay attention to the content-type, but let's assume we know it's Json
1061 buffer = OSDParser.DeserializeJson((string)request["body"]);
1062 if (buffer.Type == OSDType.Map)
1063 {
1064 args = (OSDMap)buffer;
1065 return args;
1066 }
1067 else
1068 {
1069 // uh?
1070 m_log.Debug("[REST COMMS]: Got OSD of type " + buffer.Type.ToString());
1071 return null;
1072 }
1073 }
1074 catch (Exception ex)
1075 {
1076 m_log.InfoFormat("[REST COMMS]: exception on parse of REST message {0}", ex.Message);
1077 return null;
1078 }
1079 }
1080
875 /// <summary> 1081 /// <summary>
876 /// Extract the param from an uri. 1082 /// Extract the param from an uri.
877 /// </summary> 1083 /// </summary>