LLUDPServer.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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 OpenSimulator 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 log4net;
  34. using Nini.Config;
  35. using OpenMetaverse.Packets;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.Framework.Scenes;
  38. namespace OpenSim.Region.ClientStack.LindenUDP
  39. {
  40. /// <summary>
  41. /// This class handles the initial UDP circuit setup with a client and passes on subsequent packets to the LLPacketServer
  42. /// </summary>
  43. public class LLUDPServer : ILLClientStackNetworkHandler, IClientNetworkServer
  44. {
  45. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. /// <value>
  47. /// The client circuits established with this UDP server. If a client exists here we can also assume that
  48. /// it is populated in clientCircuits_reverse and proxyCircuits (if relevant)
  49. /// </value>
  50. protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>();
  51. public Hashtable clientCircuits_reverse = Hashtable.Synchronized(new Hashtable());
  52. protected Dictionary<uint, EndPoint> proxyCircuits = new Dictionary<uint, EndPoint>();
  53. private Socket m_socket;
  54. protected IPEndPoint ServerIncoming;
  55. protected byte[] RecvBuffer = new byte[4096];
  56. protected byte[] ZeroBuffer = new byte[8192];
  57. /// <value>
  58. /// This is an endpoint that is reused where we don't need to protect the information from potentially
  59. /// being stomped on by other threads.
  60. /// </value>
  61. protected EndPoint reusedEpSender = new IPEndPoint(IPAddress.Any, 0);
  62. protected int proxyPortOffset;
  63. protected AsyncCallback ReceivedData;
  64. protected LLPacketServer m_packetServer;
  65. protected Location m_location;
  66. protected uint listenPort;
  67. protected bool Allow_Alternate_Port;
  68. protected IPAddress listenIP = IPAddress.Parse("0.0.0.0");
  69. protected IScene m_localScene;
  70. protected IAssetCache m_assetCache;
  71. protected int m_clientSocketReceiveBuffer = 0;
  72. /// <value>
  73. /// Manages authentication for agent circuits
  74. /// </value>
  75. protected AgentCircuitManager m_circuitManager;
  76. public IScene LocalScene
  77. {
  78. set
  79. {
  80. m_localScene = value;
  81. m_packetServer.LocalScene = m_localScene;
  82. m_location = new Location(m_localScene.RegionInfo.RegionHandle);
  83. }
  84. }
  85. public ulong RegionHandle
  86. {
  87. get { return m_location.RegionHandle; }
  88. }
  89. Socket IClientNetworkServer.Server
  90. {
  91. get { return m_socket; }
  92. }
  93. public bool HandlesRegion(Location x)
  94. {
  95. //return x.RegionHandle == m_location.RegionHandle;
  96. return x == m_location;
  97. }
  98. public void AddScene(IScene x)
  99. {
  100. LocalScene = x;
  101. }
  102. public void Start()
  103. {
  104. ServerListener();
  105. }
  106. public void Stop()
  107. {
  108. m_socket.Close();
  109. }
  110. public LLUDPServer()
  111. {
  112. }
  113. public LLUDPServer(
  114. IPAddress _listenIP, ref uint port, int proxyPortOffset, bool allow_alternate_port, IConfigSource configSource,
  115. IAssetCache assetCache, AgentCircuitManager authenticateClass)
  116. {
  117. Initialise(_listenIP, ref port, proxyPortOffset, allow_alternate_port, configSource, authenticateClass);
  118. }
  119. /// <summary>
  120. /// Initialize the server
  121. /// </summary>
  122. /// <param name="_listenIP"></param>
  123. /// <param name="port"></param>
  124. /// <param name="proxyPortOffsetParm"></param>
  125. /// <param name="allow_alternate_port"></param>
  126. /// <param name="configSource"></param>
  127. /// <param name="assetCache"></param>
  128. /// <param name="circuitManager"></param>
  129. public void Initialise(
  130. IPAddress _listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource,
  131. AgentCircuitManager circuitManager)
  132. {
  133. ClientStackUserSettings userSettings = new ClientStackUserSettings();
  134. IConfig config = configSource.Configs["ClientStack.LindenUDP"];
  135. if (config != null)
  136. {
  137. if (config.Contains("client_throttle_multiplier"))
  138. userSettings.ClientThrottleMultipler = config.GetFloat("client_throttle_multiplier");
  139. if (config.Contains("client_socket_rcvbuf_size"))
  140. m_clientSocketReceiveBuffer = config.GetInt("client_socket_rcvbuf_size");
  141. }
  142. m_log.DebugFormat("[CLIENT]: client_throttle_multiplier = {0}", userSettings.ClientThrottleMultipler);
  143. m_log.DebugFormat("[CLIENT]: client_socket_rcvbuf_size = {0}", (m_clientSocketReceiveBuffer != 0 ?
  144. m_clientSocketReceiveBuffer.ToString() : "OS default"));
  145. proxyPortOffset = proxyPortOffsetParm;
  146. listenPort = (uint) (port + proxyPortOffsetParm);
  147. listenIP = _listenIP;
  148. Allow_Alternate_Port = allow_alternate_port;
  149. m_circuitManager = circuitManager;
  150. CreatePacketServer(userSettings);
  151. // Return new port
  152. // This because in Grid mode it is not really important what port the region listens to as long as it is correctly registered.
  153. // So the option allow_alternate_ports="true" was added to default.xml
  154. port = (uint)(listenPort - proxyPortOffsetParm);
  155. }
  156. protected virtual void CreatePacketServer(ClientStackUserSettings userSettings)
  157. {
  158. new LLPacketServer(this, userSettings);
  159. }
  160. /// <summary>
  161. /// This method is called every time that we receive new UDP data.
  162. /// </summary>
  163. /// <param name="result"></param>
  164. protected virtual void OnReceivedData(IAsyncResult result)
  165. {
  166. Packet packet = null;
  167. int numBytes = 1;
  168. EndPoint epSender = new IPEndPoint(IPAddress.Any, 0);
  169. EndPoint epProxy = null;
  170. try
  171. {
  172. if (EndReceive(out numBytes, result, ref epSender))
  173. {
  174. // Make sure we are getting zeroes when running off the
  175. // end of grab / degrab packets from old clients
  176. Array.Clear(RecvBuffer, numBytes, RecvBuffer.Length - numBytes);
  177. int packetEnd = numBytes - 1;
  178. if (proxyPortOffset != 0) packetEnd -= 6;
  179. try
  180. {
  181. packet = PacketPool.Instance.GetPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
  182. }
  183. catch (MalformedDataException e)
  184. {
  185. m_log.DebugFormat("[CLIENT]: Dropped Malformed Packet due to MalformedDataException: {0}", e.StackTrace);
  186. }
  187. catch (IndexOutOfRangeException e)
  188. {
  189. m_log.DebugFormat("[CLIENT]: Dropped Malformed Packet due to IndexOutOfRangeException: {0}", e.StackTrace);
  190. }
  191. catch (Exception e)
  192. {
  193. m_log.Debug("[CLIENT]: " + e);
  194. }
  195. }
  196. if (proxyPortOffset != 0)
  197. {
  198. // If we've received a use circuit packet, then we need to decode an endpoint proxy, if one exists,
  199. // before allowing the RecvBuffer to be overwritten by the next packet.
  200. if (packet != null && packet.Type == PacketType.UseCircuitCode)
  201. {
  202. epProxy = epSender;
  203. }
  204. // Now decode the message from the proxy server
  205. epSender = ProxyCodec.DecodeProxyMessage(RecvBuffer, ref numBytes);
  206. }
  207. }
  208. catch (Exception ex)
  209. {
  210. m_log.ErrorFormat("[CLIENT]: Exception thrown during EndReceive(): {0}", ex);
  211. }
  212. BeginRobustReceive();
  213. if (packet != null)
  214. {
  215. if (packet.Type == PacketType.UseCircuitCode)
  216. AddNewClient((UseCircuitCodePacket)packet, epSender, epProxy);
  217. else
  218. ProcessInPacket(packet, epSender);
  219. }
  220. }
  221. /// <summary>
  222. /// Process a successfully received packet.
  223. /// </summary>
  224. /// <param name="packet"></param>
  225. /// <param name="epSender"></param>
  226. protected virtual void ProcessInPacket(Packet packet, EndPoint epSender)
  227. {
  228. try
  229. {
  230. // do we already have a circuit for this endpoint
  231. uint circuit;
  232. bool ret;
  233. lock (clientCircuits)
  234. {
  235. ret = clientCircuits.TryGetValue(epSender, out circuit);
  236. }
  237. if (ret)
  238. {
  239. //if so then send packet to the packetserver
  240. //m_log.DebugFormat(
  241. // "[UDPSERVER]: For circuit {0} {1} got packet {2}", circuit, epSender, packet.Type);
  242. m_packetServer.InPacket(circuit, packet);
  243. }
  244. }
  245. catch (Exception e)
  246. {
  247. m_log.Error("[CLIENT]: Exception in processing packet - ignoring: ", e);
  248. }
  249. }
  250. /// <summary>
  251. /// Begin an asynchronous receive of the next bit of raw data
  252. /// </summary>
  253. protected virtual void BeginReceive()
  254. {
  255. m_socket.BeginReceiveFrom(
  256. RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref reusedEpSender, ReceivedData, null);
  257. }
  258. /// <summary>
  259. /// Begin a robust asynchronous receive of the next bit of raw data. Robust means that SocketExceptions are
  260. /// automatically dealt with until the next set of valid UDP data is received.
  261. /// </summary>
  262. private void BeginRobustReceive()
  263. {
  264. bool done = false;
  265. while (!done)
  266. {
  267. try
  268. {
  269. BeginReceive();
  270. done = true;
  271. }
  272. catch (SocketException e)
  273. {
  274. // ENDLESS LOOP ON PURPOSE!
  275. // Reset connection and get next UDP packet off the buffer
  276. // If the UDP packet is part of the same stream, this will happen several hundreds of times before
  277. // the next set of UDP data is for a valid client.
  278. try
  279. {
  280. CloseCircuit(e);
  281. }
  282. catch (Exception e2)
  283. {
  284. m_log.ErrorFormat(
  285. "[CLIENT]: Exception thrown when trying to close the circuit for {0} - {1}", reusedEpSender,
  286. e2);
  287. }
  288. }
  289. catch (ObjectDisposedException)
  290. {
  291. m_log.Info(
  292. "[UDPSERVER]: UDP Object disposed. No need to worry about this if you're restarting the simulator.");
  293. done = true;
  294. }
  295. catch (Exception ex)
  296. {
  297. m_log.ErrorFormat("[CLIENT]: Exception thrown during BeginReceive(): {0}", ex);
  298. }
  299. }
  300. }
  301. /// <summary>
  302. /// Close a client circuit. This is done in response to an exception on receive, and should not be called
  303. /// normally.
  304. /// </summary>
  305. /// <param name="e">The exception that caused the close. Can be null if there was no exception</param>
  306. private void CloseCircuit(Exception e)
  307. {
  308. uint circuit;
  309. lock (clientCircuits)
  310. {
  311. if (clientCircuits.TryGetValue(reusedEpSender, out circuit))
  312. {
  313. m_packetServer.CloseCircuit(circuit);
  314. if (e != null)
  315. m_log.ErrorFormat(
  316. "[CLIENT]: Closed circuit {0} {1} due to exception {2}", circuit, reusedEpSender, e);
  317. }
  318. }
  319. }
  320. /// <summary>
  321. /// Finish the process of asynchronously receiving the next bit of raw data
  322. /// </summary>
  323. /// <param name="numBytes">The number of bytes received. Will return 0 if no bytes were recieved
  324. /// <param name="result"></param>
  325. /// <param name="epSender">The sender of the data</param>
  326. /// <returns></returns>
  327. protected virtual bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender)
  328. {
  329. bool hasReceivedOkay = false;
  330. numBytes = 0;
  331. try
  332. {
  333. numBytes = m_socket.EndReceiveFrom(result, ref epSender);
  334. hasReceivedOkay = true;
  335. }
  336. catch (SocketException e)
  337. {
  338. // TODO : Actually only handle those states that we have control over, re-throw everything else,
  339. // TODO: implement cases as we encounter them.
  340. //m_log.Error("[CLIENT]: Connection Error! - " + e.ToString());
  341. switch (e.SocketErrorCode)
  342. {
  343. case SocketError.AlreadyInProgress:
  344. return hasReceivedOkay;
  345. case SocketError.NetworkReset:
  346. case SocketError.ConnectionReset:
  347. case SocketError.OperationAborted:
  348. break;
  349. default:
  350. throw;
  351. }
  352. }
  353. catch (ObjectDisposedException e)
  354. {
  355. m_log.DebugFormat("[CLIENT]: ObjectDisposedException: Object {0} disposed.", e.ObjectName);
  356. // Uhh, what object, and why? this needs better handling.
  357. }
  358. return hasReceivedOkay;
  359. }
  360. /// <summary>
  361. /// Add a new client circuit.
  362. /// </summary>
  363. /// <param name="packet"></param>
  364. /// <param name="epSender"></param>
  365. /// <param name="epProxy"></param>
  366. protected virtual void AddNewClient(UseCircuitCodePacket useCircuit, EndPoint epSender, EndPoint epProxy)
  367. {
  368. //Slave regions don't accept new clients
  369. if (m_localScene.RegionStatus != RegionStatus.SlaveScene)
  370. {
  371. AuthenticateResponse sessionInfo;
  372. bool isNewCircuit = false;
  373. if (!m_packetServer.IsClientAuthorized(useCircuit, m_circuitManager, out sessionInfo))
  374. {
  375. m_log.WarnFormat(
  376. "[CONNECTION FAILURE]: Connection request for client {0} connecting with unnotified circuit code {1} from {2}",
  377. useCircuit.CircuitCode.ID, useCircuit.CircuitCode.Code, epSender);
  378. return;
  379. }
  380. lock (clientCircuits)
  381. {
  382. if (!clientCircuits.ContainsKey(epSender))
  383. {
  384. clientCircuits.Add(epSender, useCircuit.CircuitCode.Code);
  385. isNewCircuit = true;
  386. }
  387. }
  388. if (isNewCircuit)
  389. {
  390. // This doesn't need locking as it's synchronized data
  391. clientCircuits_reverse[useCircuit.CircuitCode.Code] = epSender;
  392. lock (proxyCircuits)
  393. {
  394. proxyCircuits[useCircuit.CircuitCode.Code] = epProxy;
  395. }
  396. m_packetServer.AddNewClient(epSender, useCircuit, m_assetCache, sessionInfo, epProxy);
  397. //m_log.DebugFormat(
  398. // "[CONNECTION SUCCESS]: Incoming client {0} (circuit code {1}) received and authenticated for {2}",
  399. // useCircuit.CircuitCode.ID, useCircuit.CircuitCode.Code, m_localScene.RegionInfo.RegionName);
  400. }
  401. }
  402. // Ack the UseCircuitCode packet
  403. PacketAckPacket ack_it = (PacketAckPacket)PacketPool.Instance.GetPacket(PacketType.PacketAck);
  404. // TODO: don't create new blocks if recycling an old packet
  405. ack_it.Packets = new PacketAckPacket.PacketsBlock[1];
  406. ack_it.Packets[0] = new PacketAckPacket.PacketsBlock();
  407. ack_it.Packets[0].ID = useCircuit.Header.Sequence;
  408. // ((useCircuit.Header.Sequence < uint.MaxValue) ? useCircuit.Header.Sequence : 0) is just a failsafe to ensure that we don't overflow.
  409. ack_it.Header.Sequence = ((useCircuit.Header.Sequence < uint.MaxValue) ? useCircuit.Header.Sequence : 0) + 1;
  410. ack_it.Header.Reliable = false;
  411. byte[] ackmsg = ack_it.ToBytes();
  412. // Need some extra space in case we need to add proxy
  413. // information to the message later
  414. byte[] msg = new byte[4096];
  415. Buffer.BlockCopy(ackmsg, 0, msg, 0, ackmsg.Length);
  416. SendPacketTo(msg, ackmsg.Length, SocketFlags.None, useCircuit.CircuitCode.Code);
  417. PacketPool.Instance.ReturnPacket(useCircuit);
  418. }
  419. public void ServerListener()
  420. {
  421. uint newPort = listenPort;
  422. m_log.Info("[UDPSERVER]: Opening UDP socket on " + listenIP + " " + newPort + ".");
  423. ServerIncoming = new IPEndPoint(listenIP, (int)newPort);
  424. m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  425. if (0 != m_clientSocketReceiveBuffer)
  426. m_socket.ReceiveBufferSize = m_clientSocketReceiveBuffer;
  427. m_socket.Bind(ServerIncoming);
  428. // Add flags to the UDP socket to prevent "Socket forcibly closed by host"
  429. // uint IOC_IN = 0x80000000;
  430. // uint IOC_VENDOR = 0x18000000;
  431. // uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
  432. // TODO: this apparently works in .NET but not in Mono, need to sort out the right flags here.
  433. // m_socket.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null);
  434. listenPort = newPort;
  435. m_log.Info("[UDPSERVER]: UDP socket bound, getting ready to listen");
  436. ReceivedData = OnReceivedData;
  437. BeginReceive();
  438. m_log.Info("[UDPSERVER]: Listening on port " + newPort);
  439. }
  440. public virtual void RegisterPacketServer(LLPacketServer server)
  441. {
  442. m_packetServer = server;
  443. }
  444. public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)
  445. //EndPoint packetSender)
  446. {
  447. // find the endpoint for this circuit
  448. EndPoint sendto;
  449. try
  450. {
  451. sendto = (EndPoint)clientCircuits_reverse[circuitcode];
  452. }
  453. catch
  454. {
  455. // Exceptions here mean there is no circuit
  456. m_log.Warn("[CLIENT]: Circuit not found, not sending packet");
  457. return;
  458. }
  459. if (sendto != null)
  460. {
  461. //we found the endpoint so send the packet to it
  462. if (proxyPortOffset != 0)
  463. {
  464. //MainLog.Instance.Verbose("UDPSERVER", "SendPacketTo proxy " + proxyCircuits[circuitcode].ToString() + ": client " + sendto.ToString());
  465. ProxyCodec.EncodeProxyMessage(buffer, ref size, sendto);
  466. m_socket.SendTo(buffer, size, flags, proxyCircuits[circuitcode]);
  467. }
  468. else
  469. {
  470. //MainLog.Instance.Verbose("UDPSERVER", "SendPacketTo : client " + sendto.ToString());
  471. try
  472. {
  473. m_socket.SendTo(buffer, size, flags, sendto);
  474. }
  475. catch (SocketException SockE)
  476. {
  477. m_log.ErrorFormat("[UDPSERVER]: Caught Socket Error in the send buffer!. {0}",SockE.ToString());
  478. }
  479. }
  480. }
  481. }
  482. public virtual void RemoveClientCircuit(uint circuitcode)
  483. {
  484. EndPoint sendto;
  485. if (clientCircuits_reverse.Contains(circuitcode))
  486. {
  487. sendto = (EndPoint)clientCircuits_reverse[circuitcode];
  488. clientCircuits_reverse.Remove(circuitcode);
  489. lock (clientCircuits)
  490. {
  491. if (sendto != null)
  492. {
  493. clientCircuits.Remove(sendto);
  494. }
  495. else
  496. {
  497. m_log.DebugFormat(
  498. "[CLIENT]: endpoint for circuit code {0} in RemoveClientCircuit() was unexpectedly null!", circuitcode);
  499. }
  500. }
  501. lock (proxyCircuits)
  502. {
  503. proxyCircuits.Remove(circuitcode);
  504. }
  505. }
  506. }
  507. public void RestoreClient(AgentCircuitData circuit, EndPoint userEP, EndPoint proxyEP)
  508. {
  509. //MainLog.Instance.Verbose("UDPSERVER", "RestoreClient");
  510. UseCircuitCodePacket useCircuit = new UseCircuitCodePacket();
  511. useCircuit.CircuitCode.Code = circuit.circuitcode;
  512. useCircuit.CircuitCode.ID = circuit.AgentID;
  513. useCircuit.CircuitCode.SessionID = circuit.SessionID;
  514. AuthenticateResponse sessionInfo;
  515. if (!m_packetServer.IsClientAuthorized(useCircuit, m_circuitManager, out sessionInfo))
  516. {
  517. m_log.WarnFormat(
  518. "[CLIENT]: Restore request denied to avatar {0} connecting with unauthorized circuit code {1}",
  519. useCircuit.CircuitCode.ID, useCircuit.CircuitCode.Code);
  520. return;
  521. }
  522. lock (clientCircuits)
  523. {
  524. if (!clientCircuits.ContainsKey(userEP))
  525. clientCircuits.Add(userEP, useCircuit.CircuitCode.Code);
  526. else
  527. m_log.Error("[CLIENT]: clientCircuits already contains entry for user " + useCircuit.CircuitCode.Code + ". NOT adding.");
  528. }
  529. // This data structure is synchronized, so we don't need the lock
  530. if (!clientCircuits_reverse.ContainsKey(useCircuit.CircuitCode.Code))
  531. clientCircuits_reverse.Add(useCircuit.CircuitCode.Code, userEP);
  532. else
  533. m_log.Error("[CLIENT]: clientCurcuits_reverse already contains entry for user " + useCircuit.CircuitCode.Code + ". NOT adding.");
  534. lock (proxyCircuits)
  535. {
  536. if (!proxyCircuits.ContainsKey(useCircuit.CircuitCode.Code))
  537. {
  538. proxyCircuits.Add(useCircuit.CircuitCode.Code, proxyEP);
  539. }
  540. else
  541. {
  542. // re-set proxy endpoint
  543. proxyCircuits.Remove(useCircuit.CircuitCode.Code);
  544. proxyCircuits.Add(useCircuit.CircuitCode.Code, proxyEP);
  545. }
  546. }
  547. m_packetServer.AddNewClient(userEP, useCircuit, m_assetCache, sessionInfo, proxyEP);
  548. }
  549. }
  550. }