diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP')
4 files changed, 278 insertions, 240 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> |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs index d2779ba..cfe7c9d 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs | |||
@@ -44,7 +44,7 @@ namespace OpenMetaverse | |||
44 | /// This method is called when an incoming packet is received | 44 | /// This method is called when an incoming packet is received |
45 | /// </summary> | 45 | /// </summary> |
46 | /// <param name="buffer">Incoming packet buffer</param> | 46 | /// <param name="buffer">Incoming packet buffer</param> |
47 | protected abstract void PacketReceived(UDPPacketBuffer buffer); | 47 | public abstract void PacketReceived(UDPPacketBuffer buffer); |
48 | 48 | ||
49 | /// <summary>UDP port to bind to in server mode</summary> | 49 | /// <summary>UDP port to bind to in server mode</summary> |
50 | protected int m_udpPort; | 50 | protected int m_udpPort; |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs index 9d37cdf..a575e36 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs | |||
@@ -25,6 +25,7 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
28 | using System.Net; | 29 | using System.Net; |
29 | using log4net.Config; | 30 | using log4net.Config; |
30 | using Nini.Config; | 31 | using Nini.Config; |
@@ -32,6 +33,7 @@ using NUnit.Framework; | |||
32 | using OpenMetaverse; | 33 | using OpenMetaverse; |
33 | using OpenMetaverse.Packets; | 34 | using OpenMetaverse.Packets; |
34 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Region.Framework.Scenes; | ||
35 | using OpenSim.Tests.Common; | 37 | using OpenSim.Tests.Common; |
36 | using OpenSim.Tests.Common.Mock; | 38 | using OpenSim.Tests.Common.Mock; |
37 | 39 | ||
@@ -43,19 +45,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
43 | [TestFixture] | 45 | [TestFixture] |
44 | public class BasicCircuitTests | 46 | public class BasicCircuitTests |
45 | { | 47 | { |
46 | [SetUp] | 48 | [TestFixtureSetUp] |
47 | public void Init() | 49 | public void FixtureInit() |
48 | { | 50 | { |
49 | try | 51 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. |
50 | { | 52 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; |
51 | XmlConfigurator.Configure(); | ||
52 | } | ||
53 | catch | ||
54 | { | ||
55 | // I don't care, just leave log4net off | ||
56 | } | ||
57 | } | 53 | } |
58 | 54 | ||
55 | [TestFixtureTearDown] | ||
56 | public void TearDown() | ||
57 | { | ||
58 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
59 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression | ||
60 | // tests really shouldn't). | ||
61 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
62 | } | ||
63 | |||
59 | // /// <summary> | 64 | // /// <summary> |
60 | // /// Add a client for testing | 65 | // /// Add a client for testing |
61 | // /// </summary> | 66 | // /// </summary> |
@@ -78,54 +83,54 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
78 | // testLLUDPServer.LocalScene = scene; | 83 | // testLLUDPServer.LocalScene = scene; |
79 | // } | 84 | // } |
80 | 85 | ||
81 | /// <summary> | 86 | // /// <summary> |
82 | /// Set up a client for tests which aren't concerned with this process itself and where only one client is being | 87 | // /// Set up a client for tests which aren't concerned with this process itself and where only one client is being |
83 | /// tested | 88 | // /// tested |
84 | /// </summary> | 89 | // /// </summary> |
85 | /// <param name="circuitCode"></param> | 90 | // /// <param name="circuitCode"></param> |
86 | /// <param name="epSender"></param> | 91 | // /// <param name="epSender"></param> |
87 | /// <param name="testLLUDPServer"></param> | 92 | // /// <param name="testLLUDPServer"></param> |
88 | /// <param name="acm"></param> | 93 | // /// <param name="acm"></param> |
89 | protected void AddClient( | 94 | // protected void AddClient( |
90 | uint circuitCode, EndPoint epSender, TestLLUDPServer testLLUDPServer, AgentCircuitManager acm) | 95 | // uint circuitCode, EndPoint epSender, TestLLUDPServer testLLUDPServer, AgentCircuitManager acm) |
91 | { | 96 | // { |
92 | UUID myAgentUuid = UUID.Parse("00000000-0000-0000-0000-000000000001"); | 97 | // UUID myAgentUuid = UUID.Parse("00000000-0000-0000-0000-000000000001"); |
93 | UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002"); | 98 | // UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002"); |
94 | 99 | // | |
95 | AddClient(circuitCode, epSender, myAgentUuid, mySessionUuid, testLLUDPServer, acm); | 100 | // AddClient(circuitCode, epSender, myAgentUuid, mySessionUuid, testLLUDPServer, acm); |
96 | } | 101 | // } |
97 | 102 | ||
98 | /// <summary> | 103 | // /// <summary> |
99 | /// Set up a client for tests which aren't concerned with this process itself | 104 | // /// Set up a client for tests which aren't concerned with this process itself |
100 | /// </summary> | 105 | // /// </summary> |
101 | /// <param name="circuitCode"></param> | 106 | // /// <param name="circuitCode"></param> |
102 | /// <param name="epSender"></param> | 107 | // /// <param name="epSender"></param> |
103 | /// <param name="agentId"></param> | 108 | // /// <param name="agentId"></param> |
104 | /// <param name="sessionId"></param> | 109 | // /// <param name="sessionId"></param> |
105 | /// <param name="testLLUDPServer"></param> | 110 | // /// <param name="testLLUDPServer"></param> |
106 | /// <param name="acm"></param> | 111 | // /// <param name="acm"></param> |
107 | protected void AddClient( | 112 | // protected void AddClient( |
108 | uint circuitCode, EndPoint epSender, UUID agentId, UUID sessionId, | 113 | // uint circuitCode, EndPoint epSender, UUID agentId, UUID sessionId, |
109 | TestLLUDPServer testLLUDPServer, AgentCircuitManager acm) | 114 | // TestLLUDPServer testLLUDPServer, AgentCircuitManager acm) |
110 | { | 115 | // { |
111 | AgentCircuitData acd = new AgentCircuitData(); | 116 | // AgentCircuitData acd = new AgentCircuitData(); |
112 | acd.AgentID = agentId; | 117 | // acd.AgentID = agentId; |
113 | acd.SessionID = sessionId; | 118 | // acd.SessionID = sessionId; |
114 | 119 | // | |
115 | UseCircuitCodePacket uccp = new UseCircuitCodePacket(); | 120 | // UseCircuitCodePacket uccp = new UseCircuitCodePacket(); |
116 | 121 | // | |
117 | UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock | 122 | // UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock |
118 | = new UseCircuitCodePacket.CircuitCodeBlock(); | 123 | // = new UseCircuitCodePacket.CircuitCodeBlock(); |
119 | uccpCcBlock.Code = circuitCode; | 124 | // uccpCcBlock.Code = circuitCode; |
120 | uccpCcBlock.ID = agentId; | 125 | // uccpCcBlock.ID = agentId; |
121 | uccpCcBlock.SessionID = sessionId; | 126 | // uccpCcBlock.SessionID = sessionId; |
122 | uccp.CircuitCode = uccpCcBlock; | 127 | // uccp.CircuitCode = uccpCcBlock; |
123 | 128 | // | |
124 | acm.AddNewCircuit(circuitCode, acd); | 129 | // acm.AddNewCircuit(circuitCode, acd); |
125 | 130 | // | |
126 | testLLUDPServer.LoadReceive(uccp, epSender); | 131 | // testLLUDPServer.LoadReceive(uccp, epSender); |
127 | testLLUDPServer.ReceiveData(null); | 132 | // testLLUDPServer.ReceiveData(null); |
128 | } | 133 | // } |
129 | 134 | ||
130 | /// <summary> | 135 | /// <summary> |
131 | /// Build an object name packet for test purposes | 136 | /// Build an object name packet for test purposes |
@@ -144,54 +149,69 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
144 | return onp; | 149 | return onp; |
145 | } | 150 | } |
146 | 151 | ||
147 | // /// <summary> | 152 | /// <summary> |
148 | // /// Test adding a client to the stack | 153 | /// Test adding a client to the stack |
149 | // /// </summary> | 154 | /// </summary> |
150 | // [Test] | 155 | [Test] |
151 | // public void TestAddClient() | 156 | public void TestAddClient() |
152 | // { | 157 | { |
153 | // TestHelper.InMethod(); | 158 | TestHelpers.InMethod(); |
154 | // | 159 | // XmlConfigurator.Configure(); |
155 | // uint myCircuitCode = 123456; | 160 | |
156 | // UUID myAgentUuid = UUID.Parse("00000000-0000-0000-0000-000000000001"); | 161 | TestScene scene = SceneHelpers.SetupScene(); |
157 | // UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002"); | 162 | uint myCircuitCode = 123456; |
158 | // | 163 | UUID myAgentUuid = TestHelpers.ParseTail(0x1); |
159 | // TestLLUDPServer testLLUDPServer; | 164 | UUID mySessionUuid = TestHelpers.ParseTail(0x2); |
160 | // TestLLPacketServer testLLPacketServer; | 165 | IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999); |
161 | // AgentCircuitManager acm; | 166 | |
162 | // SetupStack(new MockScene(), out testLLUDPServer, out testLLPacketServer, out acm); | 167 | uint port = 0; |
163 | // | 168 | AgentCircuitManager acm = scene.AuthenticateHandler; |
164 | // AgentCircuitData acd = new AgentCircuitData(); | 169 | |
165 | // acd.AgentID = myAgentUuid; | 170 | TestLLUDPServer llUdpServer |
166 | // acd.SessionID = mySessionUuid; | 171 | = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, new IniConfigSource(), acm); |
167 | // | 172 | llUdpServer.AddScene(scene); |
168 | // UseCircuitCodePacket uccp = new UseCircuitCodePacket(); | 173 | |
169 | // | 174 | UseCircuitCodePacket uccp = new UseCircuitCodePacket(); |
170 | // UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock | 175 | |
171 | // = new UseCircuitCodePacket.CircuitCodeBlock(); | 176 | UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock |
172 | // uccpCcBlock.Code = myCircuitCode; | 177 | = new UseCircuitCodePacket.CircuitCodeBlock(); |
173 | // uccpCcBlock.ID = myAgentUuid; | 178 | uccpCcBlock.Code = myCircuitCode; |
174 | // uccpCcBlock.SessionID = mySessionUuid; | 179 | uccpCcBlock.ID = myAgentUuid; |
175 | // uccp.CircuitCode = uccpCcBlock; | 180 | uccpCcBlock.SessionID = mySessionUuid; |
176 | // | 181 | uccp.CircuitCode = uccpCcBlock; |
177 | // EndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999); | 182 | |
178 | // | 183 | byte[] uccpBytes = uccp.ToBytes(); |
179 | // testLLUDPServer.LoadReceive(uccp, testEp); | 184 | UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length); |
180 | // testLLUDPServer.ReceiveData(null); | 185 | upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor. |
181 | // | 186 | Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length); |
182 | // // Circuit shouildn't exist since the circuit manager doesn't know about this circuit for authentication yet | 187 | |
183 | // Assert.IsFalse(testLLUDPServer.HasCircuit(myCircuitCode)); | 188 | llUdpServer.PacketReceived(upb); |
184 | // | 189 | |
185 | // acm.AddNewCircuit(myCircuitCode, acd); | 190 | // Presence shouldn't exist since the circuit manager doesn't know about this circuit for authentication yet |
186 | // | 191 | Assert.That(scene.GetScenePresence(myAgentUuid), Is.Null); |
187 | // testLLUDPServer.LoadReceive(uccp, testEp); | 192 | |
188 | // testLLUDPServer.ReceiveData(null); | 193 | AgentCircuitData acd = new AgentCircuitData(); |
189 | // | 194 | acd.AgentID = myAgentUuid; |
190 | // // Should succeed now | 195 | acd.SessionID = mySessionUuid; |
191 | // Assert.IsTrue(testLLUDPServer.HasCircuit(myCircuitCode)); | 196 | |
192 | // Assert.IsFalse(testLLUDPServer.HasCircuit(101)); | 197 | acm.AddNewCircuit(myCircuitCode, acd); |
193 | // } | 198 | |
194 | // | 199 | llUdpServer.PacketReceived(upb); |
200 | |||
201 | // Should succeed now | ||
202 | ScenePresence sp = scene.GetScenePresence(myAgentUuid); | ||
203 | Assert.That(sp.UUID, Is.EqualTo(myAgentUuid)); | ||
204 | |||
205 | Assert.That(llUdpServer.PacketsSent.Count, Is.EqualTo(1)); | ||
206 | |||
207 | Packet packet = llUdpServer.PacketsSent[0]; | ||
208 | Assert.That(packet, Is.InstanceOf(typeof(PacketAckPacket))); | ||
209 | |||
210 | PacketAckPacket ackPacket = packet as PacketAckPacket; | ||
211 | Assert.That(ackPacket.Packets.Length, Is.EqualTo(1)); | ||
212 | Assert.That(ackPacket.Packets[0].ID, Is.EqualTo(0)); | ||
213 | } | ||
214 | |||
195 | // /// <summary> | 215 | // /// <summary> |
196 | // /// Test removing a client from the stack | 216 | // /// Test removing a client from the stack |
197 | // /// </summary> | 217 | // /// </summary> |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs index dd7999a..0302385 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs | |||
@@ -36,107 +36,106 @@ using OpenSim.Framework; | |||
36 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests | 36 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests |
37 | { | 37 | { |
38 | /// <summary> | 38 | /// <summary> |
39 | /// This class enables synchronous testing of the LLUDPServer by allowing us to load our own data into the end | 39 | /// This class enables regression testing of the LLUDPServer by allowing us to intercept outgoing data. |
40 | /// receive event | ||
41 | /// </summary> | 40 | /// </summary> |
42 | public class TestLLUDPServer : LLUDPServer | 41 | public class TestLLUDPServer : LLUDPServer |
43 | { | 42 | { |
43 | public List<Packet> PacketsSent { get; private set; } | ||
44 | |||
44 | public TestLLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) | 45 | public TestLLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) |
45 | : base(listenIP, ref port, proxyPortOffsetParm, allow_alternate_port, configSource, circuitManager) | 46 | : base(listenIP, ref port, proxyPortOffsetParm, allow_alternate_port, configSource, circuitManager) |
46 | {} | ||
47 | |||
48 | /// <summary> | ||
49 | /// The chunks of data to pass to the LLUDPServer when it calls EndReceive | ||
50 | /// </summary> | ||
51 | protected Queue<ChunkSenderTuple> m_chunksToLoad = new Queue<ChunkSenderTuple>(); | ||
52 | |||
53 | // protected override void BeginReceive() | ||
54 | // { | ||
55 | // if (m_chunksToLoad.Count > 0 && m_chunksToLoad.Peek().BeginReceiveException) | ||
56 | // { | ||
57 | // ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); | ||
58 | // reusedEpSender = tuple.Sender; | ||
59 | // throw new SocketException(); | ||
60 | // } | ||
61 | // } | ||
62 | |||
63 | // protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender) | ||
64 | // { | ||
65 | // numBytes = 0; | ||
66 | // | ||
67 | // //m_log.Debug("Queue size " + m_chunksToLoad.Count); | ||
68 | // | ||
69 | // if (m_chunksToLoad.Count <= 0) | ||
70 | // return false; | ||
71 | // | ||
72 | // ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); | ||
73 | // RecvBuffer = tuple.Data; | ||
74 | // numBytes = tuple.Data.Length; | ||
75 | // epSender = tuple.Sender; | ||
76 | // | ||
77 | // return true; | ||
78 | // } | ||
79 | |||
80 | // public override void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode) | ||
81 | // { | ||
82 | // // Don't do anything just yet | ||
83 | // } | ||
84 | |||
85 | /// <summary> | ||
86 | /// Signal that this chunk should throw an exception on Socket.BeginReceive() | ||
87 | /// </summary> | ||
88 | /// <param name="epSender"></param> | ||
89 | public void LoadReceiveWithBeginException(EndPoint epSender) | ||
90 | { | ||
91 | ChunkSenderTuple tuple = new ChunkSenderTuple(epSender); | ||
92 | tuple.BeginReceiveException = true; | ||
93 | m_chunksToLoad.Enqueue(tuple); | ||
94 | } | ||
95 | |||
96 | /// <summary> | ||
97 | /// Load some data to be received by the LLUDPServer on the next receive call | ||
98 | /// </summary> | ||
99 | /// <param name="data"></param> | ||
100 | /// <param name="epSender"></param> | ||
101 | public void LoadReceive(byte[] data, EndPoint epSender) | ||
102 | { | 47 | { |
103 | m_chunksToLoad.Enqueue(new ChunkSenderTuple(data, epSender)); | 48 | PacketsSent = new List<Packet>(); |
104 | } | 49 | } |
105 | 50 | ||
106 | /// <summary> | 51 | public override void SendAckImmediate(IPEndPoint remoteEndpoint, PacketAckPacket ack) |
107 | /// Load a packet to be received by the LLUDPServer on the next receive call | ||
108 | /// </summary> | ||
109 | /// <param name="packet"></param> | ||
110 | public void LoadReceive(Packet packet, EndPoint epSender) | ||
111 | { | 52 | { |
112 | LoadReceive(packet.ToBytes(), epSender); | 53 | PacketsSent.Add(ack); |
113 | } | 54 | } |
114 | 55 | ||
115 | /// <summary> | 56 | public override void SendPacket( |
116 | /// Calls the protected asynchronous result method. This fires out all data chunks currently queued for send | 57 | LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method) |
117 | /// </summary> | ||
118 | /// <param name="result"></param> | ||
119 | public void ReceiveData(IAsyncResult result) | ||
120 | { | 58 | { |
121 | // Doesn't work the same way anymore | 59 | PacketsSent.Add(packet); |
122 | // while (m_chunksToLoad.Count > 0) | ||
123 | // OnReceivedData(result); | ||
124 | } | 60 | } |
125 | |||
126 | /// <summary> | ||
127 | /// Has a circuit with the given code been established? | ||
128 | /// </summary> | ||
129 | /// <param name="circuitCode"></param> | ||
130 | /// <returns></returns> | ||
131 | public bool HasCircuit(uint circuitCode) | ||
132 | { | ||
133 | // lock (clientCircuits_reverse) | ||
134 | // { | ||
135 | // return clientCircuits_reverse.ContainsKey(circuitCode); | ||
136 | // } | ||
137 | 61 | ||
138 | return true; | 62 | //// /// <summary> |
139 | } | 63 | //// /// The chunks of data to pass to the LLUDPServer when it calls EndReceive |
64 | //// /// </summary> | ||
65 | //// protected Queue<ChunkSenderTuple> m_chunksToLoad = new Queue<ChunkSenderTuple>(); | ||
66 | // | ||
67 | //// protected override void BeginReceive() | ||
68 | //// { | ||
69 | //// if (m_chunksToLoad.Count > 0 && m_chunksToLoad.Peek().BeginReceiveException) | ||
70 | //// { | ||
71 | //// ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); | ||
72 | //// reusedEpSender = tuple.Sender; | ||
73 | //// throw new SocketException(); | ||
74 | //// } | ||
75 | //// } | ||
76 | // | ||
77 | //// protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender) | ||
78 | //// { | ||
79 | //// numBytes = 0; | ||
80 | //// | ||
81 | //// //m_log.Debug("Queue size " + m_chunksToLoad.Count); | ||
82 | //// | ||
83 | //// if (m_chunksToLoad.Count <= 0) | ||
84 | //// return false; | ||
85 | //// | ||
86 | //// ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); | ||
87 | //// RecvBuffer = tuple.Data; | ||
88 | //// numBytes = tuple.Data.Length; | ||
89 | //// epSender = tuple.Sender; | ||
90 | //// | ||
91 | //// return true; | ||
92 | //// } | ||
93 | // | ||
94 | //// public override void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode) | ||
95 | //// { | ||
96 | //// // Don't do anything just yet | ||
97 | //// } | ||
98 | // | ||
99 | // /// <summary> | ||
100 | // /// Signal that this chunk should throw an exception on Socket.BeginReceive() | ||
101 | // /// </summary> | ||
102 | // /// <param name="epSender"></param> | ||
103 | // public void LoadReceiveWithBeginException(EndPoint epSender) | ||
104 | // { | ||
105 | // ChunkSenderTuple tuple = new ChunkSenderTuple(epSender); | ||
106 | // tuple.BeginReceiveException = true; | ||
107 | // m_chunksToLoad.Enqueue(tuple); | ||
108 | // } | ||
109 | // | ||
110 | // /// <summary> | ||
111 | // /// Load some data to be received by the LLUDPServer on the next receive call | ||
112 | // /// </summary> | ||
113 | // /// <param name="data"></param> | ||
114 | // /// <param name="epSender"></param> | ||
115 | // public void LoadReceive(byte[] data, EndPoint epSender) | ||
116 | // { | ||
117 | // m_chunksToLoad.Enqueue(new ChunkSenderTuple(data, epSender)); | ||
118 | // } | ||
119 | // | ||
120 | // /// <summary> | ||
121 | // /// Load a packet to be received by the LLUDPServer on the next receive call | ||
122 | // /// </summary> | ||
123 | // /// <param name="packet"></param> | ||
124 | // public void LoadReceive(Packet packet, EndPoint epSender) | ||
125 | // { | ||
126 | // LoadReceive(packet.ToBytes(), epSender); | ||
127 | // } | ||
128 | // | ||
129 | // /// <summary> | ||
130 | // /// Calls the protected asynchronous result method. This fires out all data chunks currently queued for send | ||
131 | // /// </summary> | ||
132 | // /// <param name="result"></param> | ||
133 | // public void ReceiveData(IAsyncResult result) | ||
134 | // { | ||
135 | // // Doesn't work the same way anymore | ||
136 | //// while (m_chunksToLoad.Count > 0) | ||
137 | //// OnReceivedData(result); | ||
138 | // } | ||
140 | } | 139 | } |
141 | 140 | ||
142 | /// <summary> | 141 | /// <summary> |