diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/UDPServer.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/UDPServer.cs | 92 |
1 files changed, 84 insertions, 8 deletions
diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs index 9c572cf..5501d3f 100644 --- a/OpenSim/Region/ClientStack/UDPServer.cs +++ b/OpenSim/Region/ClientStack/UDPServer.cs | |||
@@ -43,12 +43,15 @@ namespace OpenSim.Region.ClientStack | |||
43 | 43 | ||
44 | protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>(); | 44 | protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>(); |
45 | public Dictionary<uint, EndPoint> clientCircuits_reverse = new Dictionary<uint, EndPoint>(); | 45 | public Dictionary<uint, EndPoint> clientCircuits_reverse = new Dictionary<uint, EndPoint>(); |
46 | protected Dictionary<uint, EndPoint> proxyCircuits = new Dictionary<uint, EndPoint>(); | ||
46 | public Socket Server; | 47 | public Socket Server; |
47 | protected IPEndPoint ServerIncoming; | 48 | protected IPEndPoint ServerIncoming; |
48 | protected byte[] RecvBuffer = new byte[4096]; | 49 | protected byte[] RecvBuffer = new byte[4096]; |
49 | protected byte[] ZeroBuffer = new byte[8192]; | 50 | protected byte[] ZeroBuffer = new byte[8192]; |
50 | protected IPEndPoint ipeSender; | 51 | protected IPEndPoint ipeSender; |
51 | protected EndPoint epSender; | 52 | protected EndPoint epSender; |
53 | protected EndPoint epProxy; | ||
54 | protected int proxyPortOffset; | ||
52 | protected AsyncCallback ReceivedData; | 55 | protected AsyncCallback ReceivedData; |
53 | protected PacketServer m_packetServer; | 56 | protected PacketServer m_packetServer; |
54 | protected ulong m_regionHandle; | 57 | protected ulong m_regionHandle; |
@@ -85,10 +88,11 @@ namespace OpenSim.Region.ClientStack | |||
85 | { | 88 | { |
86 | } | 89 | } |
87 | 90 | ||
88 | public UDPServer(IPAddress _listenIP, ref uint port, bool allow_alternate_port, AssetCache assetCache, AgentCircuitManager authenticateClass) | 91 | public UDPServer(IPAddress _listenIP, ref uint port, int proxyPortOffset, bool allow_alternate_port, AssetCache assetCache, AgentCircuitManager authenticateClass) |
89 | { | 92 | { |
93 | this.proxyPortOffset = proxyPortOffset; | ||
94 | listenPort = (uint) (port + proxyPortOffset); | ||
90 | listenIP = _listenIP; | 95 | listenIP = _listenIP; |
91 | listenPort = port; | ||
92 | Allow_Alternate_Port = allow_alternate_port; | 96 | Allow_Alternate_Port = allow_alternate_port; |
93 | m_assetCache = assetCache; | 97 | m_assetCache = assetCache; |
94 | m_authenticateSessionsClass = authenticateClass; | 98 | m_authenticateSessionsClass = authenticateClass; |
@@ -97,7 +101,7 @@ namespace OpenSim.Region.ClientStack | |||
97 | // Return new port | 101 | // Return new port |
98 | // This because in Grid mode it is not really important what port the region listens to as long as it is correctly registered. | 102 | // This because in Grid mode it is not really important what port the region listens to as long as it is correctly registered. |
99 | // So the option allow_alternate_ports="true" was added to default.xml | 103 | // So the option allow_alternate_ports="true" was added to default.xml |
100 | port = listenPort; | 104 | port = (uint)(listenPort - proxyPortOffset); |
101 | } | 105 | } |
102 | 106 | ||
103 | protected virtual void CreatePacketServer() | 107 | protected virtual void CreatePacketServer() |
@@ -211,6 +215,13 @@ namespace OpenSim.Region.ClientStack | |||
211 | //return; | 215 | //return; |
212 | } | 216 | } |
213 | 217 | ||
218 | //System.Console.WriteLine("UDPServer : recieved message from {0}", epSender.ToString()); | ||
219 | epProxy = epSender; | ||
220 | if (proxyPortOffset != 0) | ||
221 | { | ||
222 | epSender = PacketPool.DecodeProxyMessage(RecvBuffer, ref numBytes); | ||
223 | } | ||
224 | |||
214 | int packetEnd = numBytes - 1; | 225 | int packetEnd = numBytes - 1; |
215 | 226 | ||
216 | try | 227 | try |
@@ -318,6 +329,9 @@ namespace OpenSim.Region.ClientStack | |||
318 | 329 | ||
319 | protected virtual void AddNewClient(Packet packet) | 330 | protected virtual void AddNewClient(Packet packet) |
320 | { | 331 | { |
332 | //Slave regions don't accept new clients | ||
333 | if(m_localScene.Region_Status != RegionStatus.SlaveScene) | ||
334 | { | ||
321 | UseCircuitCodePacket useCircuit = (UseCircuitCodePacket) packet; | 335 | UseCircuitCodePacket useCircuit = (UseCircuitCodePacket) packet; |
322 | lock (clientCircuits) | 336 | lock (clientCircuits) |
323 | { | 337 | { |
@@ -334,7 +348,17 @@ namespace OpenSim.Region.ClientStack | |||
334 | m_log.Error("[UDPSERVER]: clientCurcuits_reverse already contains entry for user " + useCircuit.CircuitCode.Code.ToString() + ". NOT adding."); | 348 | m_log.Error("[UDPSERVER]: clientCurcuits_reverse already contains entry for user " + useCircuit.CircuitCode.Code.ToString() + ". NOT adding."); |
335 | } | 349 | } |
336 | 350 | ||
337 | PacketServer.AddNewClient(epSender, useCircuit, m_assetCache, m_authenticateSessionsClass); | 351 | lock (proxyCircuits) |
352 | { | ||
353 | if (!proxyCircuits.ContainsKey(useCircuit.CircuitCode.Code)) | ||
354 | proxyCircuits.Add(useCircuit.CircuitCode.Code, epProxy); | ||
355 | else | ||
356 | m_log.Error("[UDPSERVER]: proxyCircuits already contains entry for user " + useCircuit.CircuitCode.Code.ToString() + ". NOT adding."); | ||
357 | } | ||
358 | |||
359 | PacketServer.AddNewClient(epSender, useCircuit, m_assetCache, m_authenticateSessionsClass, epProxy); | ||
360 | } | ||
361 | PacketPool.Instance.ReturnPacket(packet); | ||
338 | } | 362 | } |
339 | 363 | ||
340 | public void ServerListener() | 364 | public void ServerListener() |
@@ -387,10 +411,20 @@ namespace OpenSim.Region.ClientStack | |||
387 | lock (clientCircuits_reverse) | 411 | lock (clientCircuits_reverse) |
388 | { | 412 | { |
389 | if (clientCircuits_reverse.TryGetValue(circuitcode, out sendto)) | 413 | if (clientCircuits_reverse.TryGetValue(circuitcode, out sendto)) |
390 | { | 414 | { |
391 | //we found the endpoint so send the packet to it | 415 | //we found the endpoint so send the packet to it |
392 | Server.SendTo(buffer, size, flags, sendto); | 416 | if (proxyPortOffset != 0) |
393 | } | 417 | { |
418 | //MainLog.Instance.Verbose("UDPSERVER", "SendPacketTo proxy " + proxyCircuits[circuitcode].ToString() + ": client " + sendto.ToString()); | ||
419 | PacketPool.EncodeProxyMessage(buffer, ref size, sendto); | ||
420 | Server.SendTo(buffer, size, flags, proxyCircuits[circuitcode]); | ||
421 | } | ||
422 | else | ||
423 | { | ||
424 | //MainLog.Instance.Verbose("UDPSERVER", "SendPacketTo : client " + sendto.ToString()); | ||
425 | Server.SendTo(buffer, size, flags, sendto); | ||
426 | } | ||
427 | } | ||
394 | } | 428 | } |
395 | } | 429 | } |
396 | 430 | ||
@@ -404,8 +438,50 @@ namespace OpenSim.Region.ClientStack | |||
404 | clientCircuits.Remove(sendto); | 438 | clientCircuits.Remove(sendto); |
405 | 439 | ||
406 | clientCircuits_reverse.Remove(circuitcode); | 440 | clientCircuits_reverse.Remove(circuitcode); |
441 | proxyCircuits.Remove(circuitcode); | ||
407 | } | 442 | } |
408 | } | 443 | } |
409 | } | 444 | } |
445 | |||
446 | public void RestoreClient(AgentCircuitData circuit, EndPoint userEP, EndPoint proxyEP) | ||
447 | { | ||
448 | //MainLog.Instance.Verbose("UDPSERVER", "RestoreClient"); | ||
449 | |||
450 | UseCircuitCodePacket useCircuit = new UseCircuitCodePacket(); | ||
451 | useCircuit.CircuitCode.Code = circuit.circuitcode; | ||
452 | useCircuit.CircuitCode.ID = circuit.AgentID; | ||
453 | useCircuit.CircuitCode.SessionID = circuit.SessionID; | ||
454 | |||
455 | lock (clientCircuits) | ||
456 | { | ||
457 | if (!clientCircuits.ContainsKey(userEP)) | ||
458 | clientCircuits.Add(userEP, useCircuit.CircuitCode.Code); | ||
459 | else | ||
460 | m_log.Error("[UDPSERVER]: clientCircuits already contans entry for user " + useCircuit.CircuitCode.Code.ToString() + ". NOT adding."); | ||
461 | } | ||
462 | lock (clientCircuits_reverse) | ||
463 | { | ||
464 | if (!clientCircuits_reverse.ContainsKey(useCircuit.CircuitCode.Code)) | ||
465 | clientCircuits_reverse.Add(useCircuit.CircuitCode.Code, userEP); | ||
466 | else | ||
467 | m_log.Error("[UDPSERVER]: clientCurcuits_reverse already contains entry for user " + useCircuit.CircuitCode.Code.ToString() + ". NOT adding."); | ||
468 | } | ||
469 | |||
470 | lock (proxyCircuits) | ||
471 | { | ||
472 | if (!proxyCircuits.ContainsKey(useCircuit.CircuitCode.Code)) | ||
473 | { | ||
474 | proxyCircuits.Add(useCircuit.CircuitCode.Code, proxyEP); | ||
475 | } | ||
476 | else | ||
477 | { | ||
478 | // re-set proxy endpoint | ||
479 | proxyCircuits.Remove(useCircuit.CircuitCode.Code); | ||
480 | proxyCircuits.Add(useCircuit.CircuitCode.Code, proxyEP); | ||
481 | } | ||
482 | } | ||
483 | |||
484 | PacketServer.AddNewClient(userEP, useCircuit, m_assetCache, m_authenticateSessionsClass, proxyEP); | ||
485 | } | ||
410 | } | 486 | } |
411 | } | 487 | } |