aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs107
1 files changed, 63 insertions, 44 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
index b04fe9f..bf5b85a 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
@@ -328,7 +328,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
328 /// The method to call if the packet is not acked by the client. If null, then a standard 328 /// The method to call if the packet is not acked by the client. If null, then a standard
329 /// resend of the packet is done. 329 /// resend of the packet is done.
330 /// </param> 330 /// </param>
331 public void SendPacket( 331 public virtual void SendPacket(
332 LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method) 332 LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method)
333 { 333 {
334 // CoarseLocationUpdate packets cannot be split in an automated way 334 // CoarseLocationUpdate packets cannot be split in an automated way
@@ -611,11 +611,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
611 outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue; 611 outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue;
612 } 612 }
613 613
614 protected override void PacketReceived(UDPPacketBuffer buffer) 614 public override void PacketReceived(UDPPacketBuffer buffer)
615 { 615 {
616 // Debugging/Profiling 616 // Debugging/Profiling
617 //try { Thread.CurrentThread.Name = "PacketReceived (" + m_scene.RegionInfo.RegionName + ")"; } 617 //try { Thread.CurrentThread.Name = "PacketReceived (" + m_scene.RegionInfo.RegionName + ")"; }
618 //catch (Exception) { } 618 //catch (Exception) { }
619// m_log.DebugFormat(
620// "[LLUDPSERVER]: Packet received from {0} in {1}", buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName);
619 621
620 LLUDPClient udpClient = null; 622 LLUDPClient udpClient = null;
621 Packet packet = null; 623 Packet packet = null;
@@ -625,7 +627,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
625 #region Decoding 627 #region Decoding
626 628
627 if (buffer.DataLength < 7) 629 if (buffer.DataLength < 7)
630 {
631// m_log.WarnFormat(
632// "[LLUDPSERVER]: Dropping undersized packet with {0} bytes received from {1} in {2}",
633// buffer.DataLength, buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName);
634
628 return; // Drop undersizd packet 635 return; // Drop undersizd packet
636 }
629 637
630 int headerLen = 7; 638 int headerLen = 7;
631 if (buffer.Data[6] == 0xFF) 639 if (buffer.Data[6] == 0xFF)
@@ -637,7 +645,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
637 } 645 }
638 646
639 if (buffer.DataLength < headerLen) 647 if (buffer.DataLength < headerLen)
648 {
649// m_log.WarnFormat(
650// "[LLUDPSERVER]: Dropping packet with malformed header received from {0} in {1}",
651// buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName);
652
640 return; // Malformed header 653 return; // Malformed header
654 }
641 655
642 try 656 try
643 { 657 {
@@ -650,6 +664,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
650 } 664 }
651 catch (IndexOutOfRangeException) 665 catch (IndexOutOfRangeException)
652 { 666 {
667// m_log.WarnFormat(
668// "[LLUDPSERVER]: Dropping short packet received from {0} in {1}",
669// buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName);
670
653 return; // Drop short packet 671 return; // Drop short packet
654 } 672 }
655 catch(Exception e) 673 catch(Exception e)
@@ -887,29 +905,55 @@ namespace OpenSim.Region.ClientStack.LindenUDP
887// DateTime startTime = DateTime.Now; 905// DateTime startTime = DateTime.Now;
888 object[] array = (object[])o; 906 object[] array = (object[])o;
889 UDPPacketBuffer buffer = (UDPPacketBuffer)array[0]; 907 UDPPacketBuffer buffer = (UDPPacketBuffer)array[0];
890 UseCircuitCodePacket packet = (UseCircuitCodePacket)array[1]; 908 UseCircuitCodePacket uccp = (UseCircuitCodePacket)array[1];
891 909
892 m_log.DebugFormat("[LLUDPSERVER]: Handling UseCircuitCode request from {0}", buffer.RemoteEndPoint); 910 m_log.DebugFormat("[LLUDPSERVER]: Handling UseCircuitCode request from {0}", buffer.RemoteEndPoint);
893 911
894 IPEndPoint remoteEndPoint = (IPEndPoint)buffer.RemoteEndPoint; 912 IPEndPoint remoteEndPoint = (IPEndPoint)buffer.RemoteEndPoint;
895 913
896 // Begin the process of adding the client to the simulator 914 AuthenticateResponse sessionInfo;
897 IClientAPI client = AddNewClient((UseCircuitCodePacket)packet, remoteEndPoint); 915 if (IsClientAuthorized(uccp, out sessionInfo))
898 916 {
899 // Send ack straight away to let the viewer know that the connection is active. 917 // Begin the process of adding the client to the simulator
900 SendAckImmediate(remoteEndPoint, packet.Header.Sequence); 918 IClientAPI client
901 919 = AddClient(
902 // FIXME: Nasty - this is the only way we currently know if Scene.AddNewClient() failed to find a 920 uccp.CircuitCode.Code,
903 // circuit and bombed out early. That check might be pointless since authorization is established 921 uccp.CircuitCode.ID,
904 // up here. 922 uccp.CircuitCode.SessionID,
905 if (client != null && client.SceneAgent != null) 923 remoteEndPoint,
906 client.SceneAgent.SendInitialDataToMe(); 924 sessionInfo);
925
926 // Send ack straight away to let the viewer know that the connection is active.
927 // The client will be null if it already exists (e.g. if on a region crossing the client sends a use
928 // circuit code to the existing child agent. This is not particularly obvious.
929 SendAckImmediate(remoteEndPoint, uccp.Header.Sequence);
930
931 // We only want to send initial data to new clients, not ones which are being converted from child to root.
932 if (client != null)
933 client.SceneAgent.SendInitialDataToMe();
934 }
935 else
936 {
937 // Don't create clients for unauthorized requesters.
938 m_log.WarnFormat(
939 "[LLUDPSERVER]: Connection request for client {0} connecting with unnotified circuit code {1} from {2}",
940 uccp.CircuitCode.ID, uccp.CircuitCode.Code, remoteEndPoint);
941 }
907 942
908 // m_log.DebugFormat( 943 // m_log.DebugFormat(
909// "[LLUDPSERVER]: Handling UseCircuitCode request from {0} took {1}ms", 944// "[LLUDPSERVER]: Handling UseCircuitCode request from {0} took {1}ms",
910// buffer.RemoteEndPoint, (DateTime.Now - startTime).Milliseconds); 945// buffer.RemoteEndPoint, (DateTime.Now - startTime).Milliseconds);
911 } 946 }
912 947
948 /// <summary>
949 /// Send an ack immediately to the given endpoint.
950 /// </summary>
951 /// <remarks>
952 /// FIXME: Might be possible to use SendPacketData() like everything else, but this will require refactoring so
953 /// that we can obtain the UDPClient easily at this point.
954 /// </remarks>
955 /// <param name="remoteEndpoint"></param>
956 /// <param name="sequenceNumber"></param>
913 private void SendAckImmediate(IPEndPoint remoteEndpoint, uint sequenceNumber) 957 private void SendAckImmediate(IPEndPoint remoteEndpoint, uint sequenceNumber)
914 { 958 {
915 PacketAckPacket ack = new PacketAckPacket(); 959 PacketAckPacket ack = new PacketAckPacket();
@@ -918,6 +962,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
918 ack.Packets[0] = new PacketAckPacket.PacketsBlock(); 962 ack.Packets[0] = new PacketAckPacket.PacketsBlock();
919 ack.Packets[0].ID = sequenceNumber; 963 ack.Packets[0].ID = sequenceNumber;
920 964
965 SendAckImmediate(remoteEndpoint, ack);
966 }
967
968 public virtual void SendAckImmediate(IPEndPoint remoteEndpoint, PacketAckPacket ack)
969 {
921 byte[] packetData = ack.ToBytes(); 970 byte[] packetData = ack.ToBytes();
922 int length = packetData.Length; 971 int length = packetData.Length;
923 972
@@ -940,36 +989,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
940 } 989 }
941 990
942 /// <summary> 991 /// <summary>
943 /// Add a new client.
944 /// </summary>
945 /// <param name="useCircuitCode"></param>
946 /// <param name="remoteEndPoint"></param>
947 /// <returns>
948 /// The client that was added or null if the client failed authorization or already existed.
949 /// </returns>
950 private IClientAPI AddNewClient(UseCircuitCodePacket useCircuitCode, IPEndPoint remoteEndPoint)
951 {
952 UUID agentID = useCircuitCode.CircuitCode.ID;
953 UUID sessionID = useCircuitCode.CircuitCode.SessionID;
954 uint circuitCode = useCircuitCode.CircuitCode.Code;
955
956 AuthenticateResponse sessionInfo;
957 if (IsClientAuthorized(useCircuitCode, out sessionInfo))
958 {
959 return AddClient(circuitCode, agentID, sessionID, remoteEndPoint, sessionInfo);
960 }
961 else
962 {
963 // Don't create circuits for unauthorized clients
964 m_log.WarnFormat(
965 "[LLUDPSERVER]: Connection request for client {0} connecting with unnotified circuit code {1} from {2}",
966 useCircuitCode.CircuitCode.ID, useCircuitCode.CircuitCode.Code, remoteEndPoint);
967
968 return null;
969 }
970 }
971
972 /// <summary>
973 /// Add a client. 992 /// Add a client.
974 /// </summary> 993 /// </summary>
975 /// <param name="circuitCode"></param> 994 /// <param name="circuitCode"></param>