LLUDPServer.cs 25 KB

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