OGS1GridServices.cs 63 KB

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