OGS1GridServices.cs 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using System.Net.Sockets;
  32. using System.Runtime.Remoting;
  33. using System.Runtime.Remoting.Channels;
  34. using System.Runtime.Remoting.Channels.Tcp;
  35. using System.Security.Authentication;
  36. using libsecondlife;
  37. using Nwc.XmlRpc;
  38. using OpenSim.Framework;
  39. using OpenSim.Framework.Communications;
  40. using OpenSim.Framework.Console;
  41. using OpenSim.Framework.Servers;
  42. using OpenSim.Region.Communications.Local;
  43. namespace OpenSim.Region.Communications.OGS1
  44. {
  45. public class OGS1GridServices : IGridServices, IInterRegionCommunications
  46. {
  47. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  48. private LocalBackEndServices m_localBackend = new LocalBackEndServices();
  49. private Dictionary<ulong, RegionInfo> m_remoteRegionInfoCache = new Dictionary<ulong, RegionInfo>();
  50. private List<SimpleRegionInfo> m_knownRegions = new List<SimpleRegionInfo>();
  51. private Dictionary<ulong, int> m_deadRegionCache = new Dictionary<ulong, int>();
  52. private Dictionary<string, string> m_queuedGridSettings = new Dictionary<string, string>();
  53. public BaseHttpServer httpListener;
  54. public NetworkServersInfo serversInfo;
  55. public BaseHttpServer httpServer;
  56. public string _gdebugRegionName = String.Empty;
  57. public string gdebugRegionName
  58. {
  59. get { return _gdebugRegionName; }
  60. set { _gdebugRegionName = value; }
  61. }
  62. public string _rdebugRegionName = String.Empty;
  63. public string rdebugRegionName
  64. {
  65. get { return _rdebugRegionName; }
  66. set { _rdebugRegionName = value; }
  67. }
  68. /// <summary>
  69. /// Contructor. Adds "expect_user" and "check" xmlrpc method handlers
  70. /// </summary>
  71. /// <param name="servers_info"></param>
  72. /// <param name="httpServe"></param>
  73. public OGS1GridServices(NetworkServersInfo servers_info, BaseHttpServer httpServe)
  74. {
  75. serversInfo = servers_info;
  76. httpServer = httpServe;
  77. //Respond to Grid Services requests
  78. httpServer.AddXmlRPCHandler("expect_user", ExpectUser);
  79. httpServer.AddXmlRPCHandler("check", PingCheckReply);
  80. StartRemoting();
  81. }
  82. // see IGridServices
  83. public RegionCommsListener RegisterRegion(RegionInfo regionInfo)
  84. {
  85. m_log.DebugFormat(
  86. "[OGS1 GRID SERVICES]: Attempting to register region {0} with grid at {1}",
  87. regionInfo.RegionName, serversInfo.GridURL);
  88. Hashtable GridParams = new Hashtable();
  89. // Login / Authentication
  90. GridParams["authkey"] = serversInfo.GridSendKey;
  91. GridParams["recvkey"] = serversInfo.GridRecvKey;
  92. GridParams["UUID"] = regionInfo.RegionID.ToString();
  93. GridParams["sim_ip"] = regionInfo.ExternalHostName;
  94. GridParams["sim_port"] = regionInfo.InternalEndPoint.Port.ToString();
  95. GridParams["region_locx"] = regionInfo.RegionLocX.ToString();
  96. GridParams["region_locy"] = regionInfo.RegionLocY.ToString();
  97. GridParams["sim_name"] = regionInfo.RegionName;
  98. GridParams["http_port"] = serversInfo.HttpListenerPort.ToString();
  99. GridParams["remoting_port"] = NetworkServersInfo.RemotingListenerPort.ToString();
  100. GridParams["map-image-id"] = regionInfo.EstateSettings.terrainImageID.ToString();
  101. GridParams["originUUID"] = regionInfo.originRegionID.ToString();
  102. GridParams["server_uri"] = regionInfo.ServerURI;
  103. // part of an initial brutish effort to provide accurate information (as per the xml region spec)
  104. // wrt the ownership of a given region
  105. // the (very bad) assumption is that this value is being read and handled inconsistently or
  106. // not at all. Current strategy is to put the code in place to support the validity of this information
  107. // and to roll forward debugging any issues from that point
  108. //
  109. // this particular section of the mod attempts to supply a value from the region's xml file to the grid
  110. // server for the UUID of the region's owner (master avatar)
  111. GridParams["master_avatar_uuid"] = regionInfo.MasterAvatarAssignedUUID.ToString();
  112. // Package into an XMLRPC Request
  113. ArrayList SendParams = new ArrayList();
  114. SendParams.Add(GridParams);
  115. // Send Request
  116. XmlRpcResponse GridResp;
  117. try
  118. {
  119. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_login", SendParams);
  120. GridResp = GridReq.Send(serversInfo.GridURL, 30000);
  121. }
  122. catch (Exception ex)
  123. {
  124. m_log.ErrorFormat(
  125. "[OGS1 GRID SERVICES]: Unable to connect to grid at {0}. Grid server not running? Exception {1}",
  126. serversInfo.GridURL, ex);
  127. throw(ex);
  128. }
  129. Hashtable GridRespData = (Hashtable)GridResp.Value;
  130. Hashtable griddatahash = GridRespData;
  131. // Process Response
  132. if (GridRespData.ContainsKey("error"))
  133. {
  134. string errorstring = (string) GridRespData["error"];
  135. m_log.ErrorFormat(
  136. "[OGS1 GRID SERVICES]: Unable to connect to grid at {0}: {1}",
  137. serversInfo.GridURL, errorstring);
  138. return null;
  139. }
  140. else
  141. {
  142. m_knownRegions = RequestNeighbours(regionInfo.RegionLocX, regionInfo.RegionLocY);
  143. if (GridRespData.ContainsKey("allow_forceful_banlines"))
  144. {
  145. if ((string) GridRespData["allow_forceful_banlines"] != "TRUE")
  146. {
  147. //m_localBackend.SetForcefulBanlistsDisallowed(regionInfo.RegionHandle);
  148. m_queuedGridSettings.Add("allow_forceful_banlines", "FALSE");
  149. }
  150. }
  151. m_log.InfoFormat(
  152. "[OGS1 GRID SERVICES]: Region {0} successfully registered with grid at {1}",
  153. regionInfo.RegionName, serversInfo.GridURL);
  154. }
  155. return m_localBackend.RegisterRegion(regionInfo);
  156. }
  157. public bool DeregisterRegion(RegionInfo regionInfo)
  158. {
  159. Hashtable GridParams = new Hashtable();
  160. GridParams["UUID"] = regionInfo.RegionID.ToString();
  161. // Package into an XMLRPC Request
  162. ArrayList SendParams = new ArrayList();
  163. SendParams.Add(GridParams);
  164. // Send Request
  165. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_after_region_moved", SendParams);
  166. XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 10000);
  167. Hashtable GridRespData = (Hashtable) GridResp.Value;
  168. Hashtable griddatahash = GridRespData;
  169. // Process Response
  170. if (GridRespData.ContainsKey("error"))
  171. {
  172. string errorstring = (string)GridRespData["error"];
  173. m_log.Error("Unable to connect to grid: " + errorstring);
  174. return false;
  175. }
  176. // What does DeregisterRegion() do?
  177. return m_localBackend.DeregisterRegion(regionInfo);
  178. }
  179. public virtual Dictionary<string, string> GetGridSettings()
  180. {
  181. Dictionary<string, string> returnGridSettings = new Dictionary<string, string>();
  182. lock (m_queuedGridSettings)
  183. {
  184. foreach (string Dictkey in m_queuedGridSettings.Keys)
  185. {
  186. returnGridSettings.Add(Dictkey, m_queuedGridSettings[Dictkey]);
  187. }
  188. m_queuedGridSettings.Clear();
  189. }
  190. return returnGridSettings;
  191. }
  192. // see IGridServices
  193. public List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
  194. {
  195. Hashtable respData = MapBlockQuery((int) x - 1, (int) y - 1, (int) x + 1, (int) y + 1);
  196. List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
  197. foreach (ArrayList neighboursList in respData.Values)
  198. {
  199. foreach (Hashtable neighbourData in neighboursList)
  200. {
  201. uint regX = Convert.ToUInt32(neighbourData["x"]);
  202. uint regY = Convert.ToUInt32(neighbourData["y"]);
  203. if ((x != regX) || (y != regY))
  204. {
  205. string simIp = (string) neighbourData["sim_ip"];
  206. uint port = Convert.ToUInt32(neighbourData["sim_port"]);
  207. string externalUri = (string) neighbourData["sim_uri"];
  208. string externalIpStr = String.Empty;
  209. try
  210. {
  211. externalIpStr = Util.GetHostFromDNS(simIp).ToString();
  212. }
  213. catch (SocketException e)
  214. {
  215. m_log.WarnFormat("RequestNeighbours(): Lookup of neighbour {0} failed! Not including in neighbours list. {1}", simIp, e);
  216. continue;
  217. }
  218. SimpleRegionInfo sri = new SimpleRegionInfo(regX, regY, simIp, port);
  219. sri.RemotingPort = Convert.ToUInt32(neighbourData["remoting_port"]);
  220. if (neighbourData.ContainsKey("http_port"))
  221. {
  222. sri.HttpPort = Convert.ToUInt32(neighbourData["http_port"]);
  223. }
  224. sri.RegionID = new LLUUID((string) neighbourData["uuid"]);
  225. neighbours.Add(sri);
  226. }
  227. }
  228. }
  229. return neighbours;
  230. }
  231. /// <summary>
  232. ///
  233. /// </summary>
  234. /// <param name="regionHandle"></param>
  235. /// <returns></returns>
  236. public RegionInfo RequestNeighbourInfo(LLUUID Region_UUID)
  237. {
  238. RegionInfo regionInfo;
  239. Hashtable requestData = new Hashtable();
  240. requestData["region_UUID"] = Region_UUID.ToString();
  241. requestData["authkey"] = serversInfo.GridSendKey;
  242. ArrayList SendParams = new ArrayList();
  243. SendParams.Add(requestData);
  244. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  245. XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000);
  246. Hashtable responseData = (Hashtable) GridResp.Value;
  247. if (responseData.ContainsKey("error"))
  248. {
  249. Console.WriteLine("error received from grid server" + responseData["error"]);
  250. return null;
  251. }
  252. uint regX = Convert.ToUInt32((string) responseData["region_locx"]);
  253. uint regY = Convert.ToUInt32((string) responseData["region_locy"]);
  254. string internalIpStr = (string) responseData["sim_ip"];
  255. uint port = Convert.ToUInt32(responseData["sim_port"]);
  256. string externalUri = (string) responseData["sim_uri"];
  257. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
  258. string neighbourExternalUri = externalUri;
  259. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
  260. regionInfo.RemotingPort = Convert.ToUInt32((string) responseData["remoting_port"]);
  261. regionInfo.RemotingAddress = internalIpStr;
  262. if (responseData.ContainsKey("http_port"))
  263. {
  264. regionInfo.HttpPort = Convert.ToUInt32((string) responseData["http_port"]);
  265. }
  266. regionInfo.RegionID = new LLUUID((string) responseData["region_UUID"]);
  267. regionInfo.RegionName = (string) responseData["region_name"];
  268. if (requestData.ContainsKey("regionHandle"))
  269. {
  270. m_remoteRegionInfoCache.Add(Convert.ToUInt64((string) requestData["regionHandle"]), regionInfo);
  271. }
  272. return regionInfo;
  273. }
  274. /// <summary>
  275. ///
  276. /// </summary>
  277. /// <param name="regionHandle"></param>
  278. /// <returns></returns>
  279. public RegionInfo RequestNeighbourInfo(ulong regionHandle)
  280. {
  281. RegionInfo regionInfo = m_localBackend.RequestNeighbourInfo(regionHandle);
  282. if (regionInfo != null)
  283. {
  284. return regionInfo;
  285. }
  286. if (!m_remoteRegionInfoCache.TryGetValue(regionHandle, out regionInfo))
  287. {
  288. try
  289. {
  290. Hashtable requestData = new Hashtable();
  291. requestData["region_handle"] = regionHandle.ToString();
  292. requestData["authkey"] = serversInfo.GridSendKey;
  293. ArrayList SendParams = new ArrayList();
  294. SendParams.Add(requestData);
  295. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  296. XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000);
  297. Hashtable responseData = (Hashtable) GridResp.Value;
  298. if (responseData.ContainsKey("error"))
  299. {
  300. m_log.Error("[OGS1 GRID SERVICES]: Error received from grid server" + responseData["error"]);
  301. return null;
  302. }
  303. uint regX = Convert.ToUInt32((string) responseData["region_locx"]);
  304. uint regY = Convert.ToUInt32((string) responseData["region_locy"]);
  305. string internalIpStr = (string) responseData["sim_ip"];
  306. uint port = Convert.ToUInt32(responseData["sim_port"]);
  307. string externalUri = (string) responseData["sim_uri"];
  308. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
  309. string neighbourExternalUri = externalUri;
  310. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
  311. regionInfo.RemotingPort = Convert.ToUInt32((string) responseData["remoting_port"]);
  312. regionInfo.RemotingAddress = internalIpStr;
  313. if (responseData.ContainsKey("http_port"))
  314. {
  315. regionInfo.HttpPort = Convert.ToUInt32((string) responseData["http_port"]);
  316. }
  317. regionInfo.RegionID = new LLUUID((string) responseData["region_UUID"]);
  318. regionInfo.RegionName = (string) responseData["region_name"];
  319. m_remoteRegionInfoCache.Add(regionHandle, regionInfo);
  320. }
  321. catch (WebException)
  322. {
  323. m_log.Error("[OGS1 GRID SERVICES]: " +
  324. "Region lookup failed for: " + regionHandle.ToString() +
  325. " - Is the GridServer down?");
  326. return null;
  327. }
  328. }
  329. return regionInfo;
  330. }
  331. public RegionInfo RequestClosestRegion(string regionName)
  332. {
  333. // Don't use this method. It's only for SLURLS and Logins
  334. RegionInfo regionInfo = null;
  335. try
  336. {
  337. Hashtable requestData = new Hashtable();
  338. requestData["region_name_search"] = regionName;
  339. requestData["authkey"] = serversInfo.GridSendKey;
  340. ArrayList SendParams = new ArrayList();
  341. SendParams.Add(requestData);
  342. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  343. XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000);
  344. Hashtable responseData = (Hashtable) GridResp.Value;
  345. if (responseData.ContainsKey("error"))
  346. {
  347. m_log.Error("[OGS1 GRID SERVICES]: Error received from grid server" + responseData["error"]);
  348. return null;
  349. }
  350. uint regX = Convert.ToUInt32((string) responseData["region_locx"]);
  351. uint regY = Convert.ToUInt32((string) responseData["region_locy"]);
  352. string internalIpStr = (string) responseData["sim_ip"];
  353. uint port = Convert.ToUInt32(responseData["sim_port"]);
  354. string externalUri = (string) responseData["sim_uri"];
  355. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
  356. string neighbourExternalUri = externalUri;
  357. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
  358. regionInfo.RemotingPort = Convert.ToUInt32((string) responseData["remoting_port"]);
  359. regionInfo.RemotingAddress = internalIpStr;
  360. if (responseData.ContainsKey("http_port"))
  361. {
  362. regionInfo.HttpPort = Convert.ToUInt32((string) responseData["http_port"]);
  363. }
  364. regionInfo.RegionID = new LLUUID((string) responseData["region_UUID"]);
  365. regionInfo.RegionName = (string) responseData["region_name"];
  366. m_remoteRegionInfoCache.Add(regionInfo.RegionHandle, regionInfo);
  367. }
  368. catch (WebException)
  369. {
  370. m_log.Error("[OGS1 GRID SERVICES]: " +
  371. "Region lookup failed for: " + regionName +
  372. " - Is the GridServer down?");
  373. }
  374. return regionInfo;
  375. }
  376. /// <summary>
  377. ///
  378. /// </summary>
  379. /// <param name="minX"></param>
  380. /// <param name="minY"></param>
  381. /// <param name="maxX"></param>
  382. /// <param name="maxY"></param>
  383. /// <returns></returns>
  384. public List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
  385. {
  386. int temp = 0;
  387. if (minX > maxX)
  388. {
  389. temp = minX;
  390. minX = maxX;
  391. maxX = temp;
  392. }
  393. if (minY > maxY)
  394. {
  395. temp = minY;
  396. minY = maxY;
  397. maxY = temp;
  398. }
  399. Hashtable respData = MapBlockQuery(minX, minY, maxX, maxY);
  400. List<MapBlockData> neighbours = new List<MapBlockData>();
  401. foreach (ArrayList a in respData.Values)
  402. {
  403. foreach (Hashtable n in a)
  404. {
  405. MapBlockData neighbour = new MapBlockData();
  406. neighbour.X = Convert.ToUInt16(n["x"]);
  407. neighbour.Y = Convert.ToUInt16(n["y"]);
  408. neighbour.Name = (string) n["name"];
  409. neighbour.Access = Convert.ToByte(n["access"]);
  410. neighbour.RegionFlags = Convert.ToUInt32(n["region-flags"]);
  411. neighbour.WaterHeight = Convert.ToByte(n["water-height"]);
  412. neighbour.MapImageId = new LLUUID((string) n["map-image-id"]);
  413. neighbours.Add(neighbour);
  414. }
  415. }
  416. return neighbours;
  417. }
  418. /// <summary>
  419. /// Performs a XML-RPC query against the grid server returning mapblock information in the specified coordinates
  420. /// </summary>
  421. /// <remarks>REDUNDANT - OGS1 is to be phased out in favour of OGS2</remarks>
  422. /// <param name="minX">Minimum X value</param>
  423. /// <param name="minY">Minimum Y value</param>
  424. /// <param name="maxX">Maximum X value</param>
  425. /// <param name="maxY">Maximum Y value</param>
  426. /// <returns>Hashtable of hashtables containing map data elements</returns>
  427. private Hashtable MapBlockQuery(int minX, int minY, int maxX, int maxY)
  428. {
  429. Hashtable param = new Hashtable();
  430. param["xmin"] = minX;
  431. param["ymin"] = minY;
  432. param["xmax"] = maxX;
  433. param["ymax"] = maxY;
  434. IList parameters = new ArrayList();
  435. parameters.Add(param);
  436. try
  437. {
  438. XmlRpcRequest req = new XmlRpcRequest("map_block", parameters);
  439. XmlRpcResponse resp = req.Send(serversInfo.GridURL, 10000);
  440. Hashtable respData = (Hashtable) resp.Value;
  441. return respData;
  442. }
  443. catch (Exception e)
  444. {
  445. m_log.Error("MapBlockQuery XMLRPC failure: " + e.ToString());
  446. return new Hashtable();
  447. }
  448. }
  449. /// <summary>
  450. /// A ping / version check
  451. /// </summary>
  452. /// <param name="request"></param>
  453. /// <returns></returns>
  454. public XmlRpcResponse PingCheckReply(XmlRpcRequest request)
  455. {
  456. XmlRpcResponse response = new XmlRpcResponse();
  457. Hashtable respData = new Hashtable();
  458. respData["online"] = "true";
  459. m_localBackend.PingCheckReply(respData);
  460. response.Value = respData;
  461. return response;
  462. }
  463. // Grid Request Processing
  464. /// <summary>
  465. /// Received from the user server when a user starts logging in. This call allows
  466. /// the region to prepare for direct communication from the client. Sends back an empty
  467. /// xmlrpc response on completion.
  468. /// </summary>
  469. /// <param name="request"></param>
  470. /// <returns></returns>
  471. public XmlRpcResponse ExpectUser(XmlRpcRequest request)
  472. {
  473. m_log.Debug("[CONNECTION DEBUGGING]: Expect User called, starting agent setup ... ");
  474. Hashtable requestData = (Hashtable) request.Params[0];
  475. AgentCircuitData agentData = new AgentCircuitData();
  476. agentData.SessionID = new LLUUID((string) requestData["session_id"]);
  477. agentData.SecureSessionID = new LLUUID((string) requestData["secure_session_id"]);
  478. agentData.firstname = (string) requestData["firstname"];
  479. agentData.lastname = (string) requestData["lastname"];
  480. agentData.AgentID = new LLUUID((string) requestData["agent_id"]);
  481. agentData.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
  482. agentData.CapsPath = (string) requestData["caps_path"];
  483. if (requestData.ContainsKey("child_agent") && requestData["child_agent"].Equals("1"))
  484. {
  485. m_log.Debug("[CONNECTION DEBUGGING]: Child agent detected");
  486. agentData.child = true;
  487. }
  488. else
  489. {
  490. m_log.Debug("[CONNECTION DEBUGGING]: Main agent detected");
  491. agentData.startpos =
  492. new LLVector3(Convert.ToUInt32(requestData["startpos_x"]),
  493. Convert.ToUInt32(requestData["startpos_y"]),
  494. Convert.ToUInt32(requestData["startpos_z"]));
  495. agentData.child = false;
  496. }
  497. ulong regionHandle = Convert.ToUInt64((string) requestData["regionhandle"]);
  498. m_log.Debug("[CONNECTION DEBUGGING]: Triggering welcome for " + agentData.AgentID.ToString() + " into " + regionHandle.ToString());
  499. m_localBackend.TriggerExpectUser(regionHandle, agentData);
  500. m_log.Info("[OGS1 GRID SERVICES]: Welcoming new user...");
  501. return new XmlRpcResponse();
  502. }
  503. #region m_interRegion Comms
  504. /// <summary>
  505. ///
  506. /// </summary>
  507. private void StartRemoting()
  508. {
  509. TcpChannel ch;
  510. try
  511. {
  512. ch = new TcpChannel((int)NetworkServersInfo.RemotingListenerPort);
  513. ChannelServices.RegisterChannel(ch, false); // Disabled security as Mono doesnt support this.
  514. }
  515. catch (Exception ex)
  516. {
  517. m_log.Error("[OGS1 GRID SERVICES]: Exception while attempting to listen on TCP port " + (int)NetworkServersInfo.RemotingListenerPort + ".");
  518. throw (ex);
  519. }
  520. WellKnownServiceTypeEntry wellType =
  521. new WellKnownServiceTypeEntry(typeof (OGS1InterRegionRemoting), "InterRegions",
  522. WellKnownObjectMode.Singleton);
  523. RemotingConfiguration.RegisterWellKnownServiceType(wellType);
  524. InterRegionSingleton.Instance.OnArrival += TriggerExpectAvatarCrossing;
  525. InterRegionSingleton.Instance.OnChildAgent += IncomingChildAgent;
  526. InterRegionSingleton.Instance.OnPrimGroupArrival += IncomingPrim;
  527. InterRegionSingleton.Instance.OnPrimGroupNear += TriggerExpectPrimCrossing;
  528. InterRegionSingleton.Instance.OnRegionUp += TriggerRegionUp;
  529. InterRegionSingleton.Instance.OnChildAgentUpdate += TriggerChildAgentUpdate;
  530. InterRegionSingleton.Instance.OnTellRegionToCloseChildConnection += TriggerTellRegionToCloseChildConnection;
  531. }
  532. #region Methods called by regions in this instance
  533. public bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
  534. {
  535. int failures = 0;
  536. lock (m_deadRegionCache)
  537. {
  538. if (m_deadRegionCache.ContainsKey(regionHandle))
  539. {
  540. failures = m_deadRegionCache[regionHandle];
  541. }
  542. }
  543. if (failures <= 3)
  544. {
  545. RegionInfo regInfo = null;
  546. try
  547. {
  548. if (m_localBackend.ChildAgentUpdate(regionHandle, cAgentData))
  549. {
  550. return true;
  551. }
  552. regInfo = RequestNeighbourInfo(regionHandle);
  553. if (regInfo != null)
  554. {
  555. //don't want to be creating a new link to the remote instance every time like we are here
  556. bool retValue = false;
  557. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
  558. typeof(OGS1InterRegionRemoting),
  559. "tcp://" + regInfo.RemotingAddress +
  560. ":" + regInfo.RemotingPort +
  561. "/InterRegions");
  562. if (remObject != null)
  563. {
  564. retValue = remObject.ChildAgentUpdate(regionHandle, cAgentData);
  565. }
  566. else
  567. {
  568. m_log.Warn("[OGS1 GRID SERVICES]: remoting object not found");
  569. }
  570. remObject = null;
  571. // m_log.Info("[INTER]: " +
  572. // gdebugRegionName +
  573. // ": OGS1 tried to Update Child Agent data on outside region and got " +
  574. // retValue.ToString());
  575. return retValue;
  576. }
  577. NoteDeadRegion(regionHandle);
  578. return false;
  579. }
  580. catch (RemotingException e)
  581. {
  582. NoteDeadRegion(regionHandle);
  583. m_log.WarnFormat(
  584. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  585. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  586. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  587. return false;
  588. }
  589. catch (SocketException e)
  590. {
  591. NoteDeadRegion(regionHandle);
  592. m_log.WarnFormat(
  593. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  594. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  595. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  596. return false;
  597. }
  598. catch (InvalidCredentialException e)
  599. {
  600. NoteDeadRegion(regionHandle);
  601. m_log.WarnFormat(
  602. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  603. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  604. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  605. return false;
  606. }
  607. catch (AuthenticationException e)
  608. {
  609. NoteDeadRegion(regionHandle);
  610. m_log.WarnFormat(
  611. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  612. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  613. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  614. return false;
  615. }
  616. catch (Exception e)
  617. {
  618. NoteDeadRegion(regionHandle);
  619. m_log.WarnFormat("[OGS1 GRID SERVICES]: Unable to connect to adjacent region: {0} {1},{2}",
  620. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  621. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  622. return false;
  623. }
  624. }
  625. else
  626. {
  627. //m_log.Info("[INTERREGION]: Skipped Sending Child Update to a region because it failed too many times:" + regionHandle.ToString());
  628. return false;
  629. }
  630. }
  631. /// <summary>
  632. ///
  633. /// </summary>
  634. /// <param name="regionHandle"></param>
  635. /// <param name="agentData"></param>
  636. /// <returns></returns>
  637. public bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
  638. {
  639. RegionInfo regInfo = null;
  640. try
  641. {
  642. if (m_localBackend.InformRegionOfChildAgent(regionHandle, agentData))
  643. {
  644. return true;
  645. }
  646. regInfo = RequestNeighbourInfo(regionHandle);
  647. if (regInfo != null)
  648. {
  649. //don't want to be creating a new link to the remote instance every time like we are here
  650. bool retValue = false;
  651. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
  652. typeof(OGS1InterRegionRemoting),
  653. "tcp://" + regInfo.RemotingAddress +
  654. ":" + regInfo.RemotingPort +
  655. "/InterRegions");
  656. if (remObject != null)
  657. {
  658. retValue = remObject.InformRegionOfChildAgent(regionHandle, new sAgentCircuitData(agentData));
  659. }
  660. else
  661. {
  662. m_log.Warn("[OGS1 GRID SERVICES]: remoting object not found");
  663. }
  664. remObject = null;
  665. m_log.Info("[OGS1 GRID SERVICES]: " +
  666. gdebugRegionName + ": OGS1 tried to InformRegionOfChildAgent for " +
  667. agentData.firstname + " " + agentData.lastname + " and got " +
  668. retValue.ToString());
  669. return retValue;
  670. }
  671. NoteDeadRegion(regionHandle);
  672. return false;
  673. }
  674. catch (RemotingException e)
  675. {
  676. NoteDeadRegion(regionHandle);
  677. m_log.WarnFormat(
  678. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  679. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  680. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  681. return false;
  682. }
  683. catch (SocketException e)
  684. {
  685. NoteDeadRegion(regionHandle);
  686. m_log.WarnFormat(
  687. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  688. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  689. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  690. return false;
  691. }
  692. catch (InvalidCredentialException e)
  693. {
  694. NoteDeadRegion(regionHandle);
  695. m_log.WarnFormat(
  696. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  697. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  698. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  699. return false;
  700. }
  701. catch (AuthenticationException e)
  702. {
  703. NoteDeadRegion(regionHandle);
  704. m_log.WarnFormat(
  705. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  706. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  707. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  708. return false;
  709. }
  710. catch (Exception e)
  711. {
  712. NoteDeadRegion(regionHandle);
  713. m_log.WarnFormat(
  714. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  715. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  716. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  717. return false;
  718. }
  719. }
  720. // UGLY!
  721. public bool RegionUp(SearializableRegionInfo region, ulong regionhandle)
  722. {
  723. SearializableRegionInfo regInfo = null;
  724. try
  725. {
  726. // You may ask why this is in here...
  727. // The region asking the grid services about itself..
  728. // And, surprisingly, the reason is.. it doesn't know
  729. // it's own remoting port! How special.
  730. RegionUpData regiondata = new RegionUpData(region.RegionLocX, region.RegionLocY, region.ExternalHostName, region.InternalEndPoint.Port);
  731. region = new SearializableRegionInfo(RequestNeighbourInfo(region.RegionHandle));
  732. region.RemotingAddress = region.ExternalHostName;
  733. region.RemotingPort = NetworkServersInfo.RemotingListenerPort;
  734. region.HttpPort = serversInfo.HttpListenerPort;
  735. if (m_localBackend.RegionUp(region, regionhandle))
  736. {
  737. return true;
  738. }
  739. regInfo = new SearializableRegionInfo(RequestNeighbourInfo(regionhandle));
  740. if (regInfo != null)
  741. {
  742. // If we're not trying to remote to ourselves.
  743. if (regInfo.RemotingAddress != region.RemotingAddress && region.RemotingAddress != null)
  744. {
  745. //don't want to be creating a new link to the remote instance every time like we are here
  746. bool retValue = false;
  747. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  748. typeof(OGS1InterRegionRemoting),
  749. "tcp://" +
  750. regInfo.RemotingAddress +
  751. ":" + regInfo.RemotingPort +
  752. "/InterRegions");
  753. if (remObject != null)
  754. {
  755. retValue = remObject.RegionUp(regiondata, regionhandle);
  756. }
  757. else
  758. {
  759. m_log.Warn("[OGS1 GRID SERVICES]: remoting object not found");
  760. }
  761. remObject = null;
  762. m_log.Info("[INTER]: " + gdebugRegionName + ": OGS1 tried to inform region I'm up");
  763. return retValue;
  764. }
  765. else
  766. {
  767. // We're trying to inform ourselves via remoting.
  768. // This is here because we're looping over the listeners before we get here.
  769. // Odd but it should work.
  770. return true;
  771. }
  772. }
  773. return false;
  774. }
  775. catch (RemotingException e)
  776. {
  777. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region using tcp://" +
  778. regInfo.RemotingAddress +
  779. ":" + regInfo.RemotingPort +
  780. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
  781. " - Is this neighbor up?");
  782. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  783. return false;
  784. }
  785. catch (SocketException e)
  786. {
  787. m_log.Warn("[OGS1 GRID SERVICES]: Socket Error: Unable to connect to adjacent region using tcp://" +
  788. regInfo.RemotingAddress +
  789. ":" + regInfo.RemotingPort +
  790. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
  791. " - Is this neighbor up?");
  792. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  793. return false;
  794. }
  795. catch (InvalidCredentialException e)
  796. {
  797. m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credentials: Unable to connect to adjacent region using tcp://" +
  798. regInfo.RemotingAddress +
  799. ":" + regInfo.RemotingPort +
  800. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  801. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  802. return false;
  803. }
  804. catch (AuthenticationException e)
  805. {
  806. m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region using tcp://" +
  807. regInfo.RemotingAddress +
  808. ":" + regInfo.RemotingPort +
  809. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  810. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  811. return false;
  812. }
  813. catch (Exception e)
  814. {
  815. // This line errors with a Null Reference Exception.. Why? @.@
  816. //m_log.Warn("Unknown exception: Unable to connect to adjacent region using tcp://" + regInfo.RemotingAddress +
  817. // ":" + regInfo.RemotingPort +
  818. //"/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY + " - This is likely caused by an incompatibility in the protocol between this sim and that one");
  819. m_log.Debug(e.ToString());
  820. return false;
  821. }
  822. }
  823. /// <summary>
  824. ///
  825. /// </summary>
  826. /// <param name="regionHandle"></param>
  827. /// <param name="agentData"></param>
  828. /// <returns></returns>
  829. public bool InformRegionOfPrimCrossing(ulong regionHandle, LLUUID primID, string objData, int XMLMethod)
  830. {
  831. int failures = 0;
  832. lock (m_deadRegionCache)
  833. {
  834. if (m_deadRegionCache.ContainsKey(regionHandle))
  835. {
  836. failures = m_deadRegionCache[regionHandle];
  837. }
  838. }
  839. if (failures <= 1)
  840. {
  841. RegionInfo regInfo = null;
  842. try
  843. {
  844. if (m_localBackend.InformRegionOfPrimCrossing(regionHandle, primID, objData, XMLMethod))
  845. {
  846. return true;
  847. }
  848. regInfo = RequestNeighbourInfo(regionHandle);
  849. if (regInfo != null)
  850. {
  851. //don't want to be creating a new link to the remote instance every time like we are here
  852. bool retValue = false;
  853. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
  854. typeof(OGS1InterRegionRemoting),
  855. "tcp://" + regInfo.RemotingAddress +
  856. ":" + regInfo.RemotingPort +
  857. "/InterRegions");
  858. if (remObject != null)
  859. {
  860. retValue = remObject.InformRegionOfPrimCrossing(regionHandle, primID.UUID, objData, XMLMethod);
  861. }
  862. else
  863. {
  864. m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
  865. }
  866. remObject = null;
  867. return retValue;
  868. }
  869. NoteDeadRegion(regionHandle);
  870. return false;
  871. }
  872. catch (RemotingException e)
  873. {
  874. NoteDeadRegion(regionHandle);
  875. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
  876. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  877. return false;
  878. }
  879. catch (SocketException e)
  880. {
  881. NoteDeadRegion(regionHandle);
  882. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
  883. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  884. return false;
  885. }
  886. catch (InvalidCredentialException e)
  887. {
  888. NoteDeadRegion(regionHandle);
  889. m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credential Exception: Invalid Credentials : " + regionHandle);
  890. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  891. return false;
  892. }
  893. catch (AuthenticationException e)
  894. {
  895. NoteDeadRegion(regionHandle);
  896. m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region: " + regionHandle);
  897. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  898. return false;
  899. }
  900. catch (Exception e)
  901. {
  902. NoteDeadRegion(regionHandle);
  903. m_log.Warn("[OGS1 GRID SERVICES]: Unknown exception: Unable to connect to adjacent region: " + regionHandle);
  904. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0}", e);
  905. return false;
  906. }
  907. }
  908. else
  909. {
  910. return false;
  911. }
  912. }
  913. /// <summary>
  914. ///
  915. /// </summary>
  916. /// <param name="regionHandle"></param>
  917. /// <param name="agentID"></param>
  918. /// <param name="position"></param>
  919. /// <returns></returns>
  920. public bool ExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying)
  921. {
  922. RegionInfo regInfo = null;
  923. try
  924. {
  925. if (m_localBackend.TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying))
  926. {
  927. return true;
  928. }
  929. regInfo = RequestNeighbourInfo(regionHandle);
  930. if (regInfo != null)
  931. {
  932. bool retValue = false;
  933. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  934. typeof (OGS1InterRegionRemoting),
  935. "tcp://" + regInfo.RemotingAddress +
  936. ":" + regInfo.RemotingPort +
  937. "/InterRegions");
  938. if (remObject != null)
  939. {
  940. retValue =
  941. remObject.ExpectAvatarCrossing(regionHandle, agentID.UUID, new sLLVector3(position),
  942. isFlying);
  943. }
  944. else
  945. {
  946. m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
  947. }
  948. remObject = null;
  949. return retValue;
  950. }
  951. //TODO need to see if we know about where this region is and use .net remoting
  952. // to inform it.
  953. NoteDeadRegion(regionHandle);
  954. return false;
  955. }
  956. catch (RemotingException e)
  957. {
  958. NoteDeadRegion(regionHandle);
  959. m_log.WarnFormat(
  960. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  961. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  962. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  963. return false;
  964. }
  965. catch
  966. {
  967. NoteDeadRegion(regionHandle);
  968. return false;
  969. }
  970. }
  971. public bool ExpectPrimCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isPhysical)
  972. {
  973. RegionInfo regInfo = null;
  974. try
  975. {
  976. if (m_localBackend.TriggerExpectPrimCrossing(regionHandle, agentID, position, isPhysical))
  977. {
  978. return true;
  979. }
  980. regInfo = RequestNeighbourInfo(regionHandle);
  981. if (regInfo != null)
  982. {
  983. bool retValue = false;
  984. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  985. typeof (OGS1InterRegionRemoting),
  986. "tcp://" + regInfo.RemotingAddress +
  987. ":" + regInfo.RemotingPort +
  988. "/InterRegions");
  989. if (remObject != null)
  990. {
  991. retValue =
  992. remObject.ExpectAvatarCrossing(regionHandle, agentID.UUID, new sLLVector3(position),
  993. isPhysical);
  994. }
  995. else
  996. {
  997. m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
  998. }
  999. remObject = null;
  1000. return retValue;
  1001. }
  1002. //TODO need to see if we know about where this region is and use .net remoting
  1003. // to inform it.
  1004. NoteDeadRegion(regionHandle);
  1005. return false;
  1006. }
  1007. catch (RemotingException e)
  1008. {
  1009. NoteDeadRegion(regionHandle);
  1010. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
  1011. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1012. return false;
  1013. }
  1014. catch (SocketException e)
  1015. {
  1016. NoteDeadRegion(regionHandle);
  1017. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
  1018. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1019. return false;
  1020. }
  1021. catch (InvalidCredentialException e)
  1022. {
  1023. NoteDeadRegion(regionHandle);
  1024. m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credential Exception: Invalid Credentials : " + regionHandle);
  1025. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1026. return false;
  1027. }
  1028. catch (AuthenticationException e)
  1029. {
  1030. NoteDeadRegion(regionHandle);
  1031. m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region: " + regionHandle);
  1032. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1033. return false;
  1034. }
  1035. catch (Exception e)
  1036. {
  1037. NoteDeadRegion(regionHandle);
  1038. m_log.Warn("[OGS1 GRID SERVICES]: Unknown exception: Unable to connect to adjacent region: " + regionHandle);
  1039. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0}", e);
  1040. return false;
  1041. }
  1042. }
  1043. public bool TellRegionToCloseChildConnection(ulong regionHandle, LLUUID agentID)
  1044. {
  1045. RegionInfo regInfo = null;
  1046. try
  1047. {
  1048. if (m_localBackend.TriggerTellRegionToCloseChildConnection(regionHandle, agentID))
  1049. {
  1050. return true;
  1051. }
  1052. regInfo = RequestNeighbourInfo(regionHandle);
  1053. if (regInfo != null)
  1054. {
  1055. bool retValue = false;
  1056. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
  1057. typeof(OGS1InterRegionRemoting),
  1058. "tcp://" + regInfo.RemotingAddress +
  1059. ":" + regInfo.RemotingPort +
  1060. "/InterRegions");
  1061. if (remObject != null)
  1062. {
  1063. retValue =
  1064. remObject.TellRegionToCloseChildConnection(regionHandle, agentID.UUID);
  1065. }
  1066. else
  1067. {
  1068. m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
  1069. }
  1070. remObject = null;
  1071. return true;
  1072. }
  1073. //TODO need to see if we know about where this region is and use .net remoting
  1074. // to inform it.
  1075. NoteDeadRegion(regionHandle);
  1076. return false;
  1077. }
  1078. catch (RemotingException)
  1079. {
  1080. NoteDeadRegion(regionHandle);
  1081. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region to tell it to close child agents: " + regInfo.RegionName +
  1082. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  1083. //m_log.Debug(e.ToString());
  1084. return false;
  1085. }
  1086. catch (SocketException e)
  1087. {
  1088. NoteDeadRegion(regionHandle);
  1089. m_log.Warn("[OGS1 GRID SERVICES]: Socket Error: Unable to connect to adjacent region using tcp://" +
  1090. regInfo.RemotingAddress +
  1091. ":" + regInfo.RemotingPort +
  1092. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
  1093. " - Is this neighbor up?");
  1094. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1095. return false;
  1096. }
  1097. catch (InvalidCredentialException e)
  1098. {
  1099. NoteDeadRegion(regionHandle);
  1100. m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credentials: Unable to connect to adjacent region using tcp://" +
  1101. regInfo.RemotingAddress +
  1102. ":" + regInfo.RemotingPort +
  1103. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  1104. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1105. return false;
  1106. }
  1107. catch (AuthenticationException e)
  1108. {
  1109. NoteDeadRegion(regionHandle);
  1110. m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region using tcp://" +
  1111. regInfo.RemotingAddress +
  1112. ":" + regInfo.RemotingPort +
  1113. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  1114. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1115. return false;
  1116. }
  1117. catch (WebException e)
  1118. {
  1119. NoteDeadRegion(regionHandle);
  1120. m_log.Warn("[OGS1 GRID SERVICES]: WebException exception: Unable to connect to adjacent region using tcp://" +
  1121. regInfo.RemotingAddress +
  1122. ":" + regInfo.RemotingPort +
  1123. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  1124. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1125. return false;
  1126. }
  1127. catch (Exception e)
  1128. {
  1129. NoteDeadRegion(regionHandle);
  1130. // This line errors with a Null Reference Exception.. Why? @.@
  1131. //m_log.Warn("Unknown exception: Unable to connect to adjacent region using tcp://" + regInfo.RemotingAddress +
  1132. // ":" + regInfo.RemotingPort +
  1133. //"/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY + " - This is likely caused by an incompatibility in the protocol between this sim and that one");
  1134. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0}", e);
  1135. return false;
  1136. }
  1137. }
  1138. public bool AcknowledgeAgentCrossed(ulong regionHandle, LLUUID agentId)
  1139. {
  1140. return m_localBackend.AcknowledgeAgentCrossed(regionHandle, agentId);
  1141. }
  1142. public bool AcknowledgePrimCrossed(ulong regionHandle, LLUUID primId)
  1143. {
  1144. return m_localBackend.AcknowledgePrimCrossed(regionHandle, primId);
  1145. }
  1146. #endregion
  1147. #region Methods triggered by calls from external instances
  1148. /// <summary>
  1149. ///
  1150. /// </summary>
  1151. /// <param name="regionHandle"></param>
  1152. /// <param name="agentData"></param>
  1153. /// <returns></returns>
  1154. public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
  1155. {
  1156. //m_log.Info("[INTER]: " + gdebugRegionName + ": Incoming OGS1 Agent " + agentData.firstname + " " + agentData.lastname);
  1157. try
  1158. {
  1159. return m_localBackend.IncomingChildAgent(regionHandle, agentData);
  1160. }
  1161. catch (RemotingException)
  1162. {
  1163. //m_log.Error("Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  1164. return false;
  1165. }
  1166. }
  1167. public bool TriggerRegionUp(RegionUpData regionData, ulong regionhandle)
  1168. {
  1169. m_log.Info("[OGS1 GRID SERVICES]: " +
  1170. gdebugRegionName + "Incoming OGS1 RegionUpReport: " + "(" + regionData.X +
  1171. "," + regionData.Y + "). Giving this region a fresh set of 'dead' tries");
  1172. RegionInfo nRegionInfo = new RegionInfo();
  1173. nRegionInfo.SetEndPoint("127.0.0.1", regionData.PORT);
  1174. nRegionInfo.ExternalHostName = regionData.IPADDR;
  1175. nRegionInfo.RegionLocX = regionData.X;
  1176. nRegionInfo.RegionLocY = regionData.Y;
  1177. try
  1178. {
  1179. lock (m_deadRegionCache)
  1180. {
  1181. if (m_deadRegionCache.ContainsKey(nRegionInfo.RegionHandle))
  1182. {
  1183. m_deadRegionCache.Remove(nRegionInfo.RegionHandle);
  1184. }
  1185. }
  1186. return m_localBackend.TriggerRegionUp(nRegionInfo, regionhandle);
  1187. }
  1188. catch (RemotingException e)
  1189. {
  1190. m_log.Error("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  1191. return false;
  1192. }
  1193. }
  1194. public bool TriggerChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
  1195. {
  1196. //m_log.Info("[INTER]: Incoming OGS1 Child Agent Data Update");
  1197. try
  1198. {
  1199. return m_localBackend.TriggerChildAgentUpdate(regionHandle, cAgentData);
  1200. }
  1201. catch (RemotingException e)
  1202. {
  1203. m_log.Error("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  1204. return false;
  1205. }
  1206. }
  1207. /// <summary>
  1208. ///
  1209. /// </summary>
  1210. /// <param name="regionHandle"></param>
  1211. /// <param name="agentData"></param>
  1212. /// <returns></returns>
  1213. public bool IncomingPrim(ulong regionHandle, LLUUID primID, string objData, int XMLMethod)
  1214. {
  1215. // Is this necessary?
  1216. try
  1217. {
  1218. m_localBackend.TriggerExpectPrim(regionHandle, primID, objData, XMLMethod);
  1219. return true;
  1220. //m_localBackend.
  1221. }
  1222. catch (RemotingException e)
  1223. {
  1224. m_log.Error("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  1225. return false;
  1226. }
  1227. }
  1228. /// <summary>
  1229. ///
  1230. /// </summary>
  1231. /// <param name="regionHandle"></param>
  1232. /// <param name="agentID"></param>
  1233. /// <param name="position"></param>
  1234. /// <returns></returns>
  1235. public bool TriggerExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying)
  1236. {
  1237. try
  1238. {
  1239. return m_localBackend.TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying);
  1240. }
  1241. catch (RemotingException e)
  1242. {
  1243. m_log.Error("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  1244. return false;
  1245. }
  1246. }
  1247. public bool TriggerExpectPrimCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isPhysical)
  1248. {
  1249. try
  1250. {
  1251. return m_localBackend.TriggerExpectPrimCrossing(regionHandle, agentID, position, isPhysical);
  1252. }
  1253. catch (RemotingException e)
  1254. {
  1255. m_log.Error("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  1256. return false;
  1257. }
  1258. }
  1259. public bool TriggerTellRegionToCloseChildConnection(ulong regionHandle, LLUUID agentID)
  1260. {
  1261. try
  1262. {
  1263. return m_localBackend.TriggerTellRegionToCloseChildConnection(regionHandle, agentID);
  1264. }
  1265. catch (RemotingException)
  1266. {
  1267. m_log.Info("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to neighbour to tell it to close a child connection");
  1268. return false;
  1269. }
  1270. }
  1271. #endregion
  1272. #endregion
  1273. // helper to see if remote region is up
  1274. bool m_bAvailable = false;
  1275. int timeOut = 10; //10 seconds
  1276. public void CheckRegion(string address, uint port)
  1277. {
  1278. m_bAvailable = false;
  1279. IPAddress ia = null;
  1280. IPAddress.TryParse(address, out ia);
  1281. IPEndPoint m_EndPoint = new IPEndPoint(ia, (int)port);
  1282. AsyncCallback ConnectedMethodCallback = new AsyncCallback(ConnectedMethod);
  1283. Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  1284. IAsyncResult ar = socket.BeginConnect(m_EndPoint, ConnectedMethodCallback, socket);
  1285. ar.AsyncWaitHandle.WaitOne(timeOut*1000, false);
  1286. }
  1287. public bool Available
  1288. {
  1289. get { return m_bAvailable; }
  1290. }
  1291. void ConnectedMethod(IAsyncResult ar)
  1292. {
  1293. Socket socket = (Socket)ar.AsyncState;
  1294. try
  1295. {
  1296. socket.EndConnect(ar);
  1297. m_bAvailable = true;
  1298. }
  1299. catch (Exception)
  1300. {
  1301. }
  1302. socket.Close();
  1303. }
  1304. public void NoteDeadRegion(ulong regionhandle)
  1305. {
  1306. lock (m_deadRegionCache)
  1307. {
  1308. if (m_deadRegionCache.ContainsKey(regionhandle))
  1309. {
  1310. m_deadRegionCache[regionhandle] = m_deadRegionCache[regionhandle] + 1;
  1311. }
  1312. else
  1313. {
  1314. m_deadRegionCache.Add(regionhandle, 1);
  1315. }
  1316. }
  1317. }
  1318. }
  1319. }