1
0

OGS1GridServices.cs 57 KB

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