1
0

LLUDPServer.cs 26 KB

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