diff options
author | Justin Clarke Casey | 2008-10-30 22:32:23 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-10-30 22:32:23 +0000 |
commit | 5feaff8524845d3475c02d1ba96465925e65e34a (patch) | |
tree | 0a74b46b64e56ee924e59077276b8fa7f2b63a19 /OpenSim | |
parent | * test: Test that the client stack doesn't completely blow up if a client pas... (diff) | |
download | opensim-SC_OLD-5feaff8524845d3475c02d1ba96465925e65e34a.zip opensim-SC_OLD-5feaff8524845d3475c02d1ba96465925e65e34a.tar.gz opensim-SC_OLD-5feaff8524845d3475c02d1ba96465925e65e34a.tar.bz2 opensim-SC_OLD-5feaff8524845d3475c02d1ba96465925e65e34a.tar.xz |
test: Extend malformed packet test to actually check that a valid packet can get through after the malformed ones have been sent
Diffstat (limited to 'OpenSim')
8 files changed, 140 insertions, 23 deletions
diff --git a/OpenSim/Framework/ClientManager.cs b/OpenSim/Framework/ClientManager.cs index 4ac9b3c..3f83f5c 100644 --- a/OpenSim/Framework/ClientManager.cs +++ b/OpenSim/Framework/ClientManager.cs | |||
@@ -97,8 +97,10 @@ namespace OpenSim.Framework | |||
97 | { | 97 | { |
98 | IClientAPI client; | 98 | IClientAPI client; |
99 | bool tryGetRet = false; | 99 | bool tryGetRet = false; |
100 | |||
100 | lock (m_clients) | 101 | lock (m_clients) |
101 | tryGetRet = m_clients.TryGetValue(circuitCode, out client); | 102 | tryGetRet = m_clients.TryGetValue(circuitCode, out client); |
103 | |||
102 | if (tryGetRet) | 104 | if (tryGetRet) |
103 | { | 105 | { |
104 | client.InPacket(packet); | 106 | client.InPacket(packet); |
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 848d31c..07af65d 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | |||
@@ -4804,10 +4804,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
4804 | break; | 4804 | break; |
4805 | case PacketType.ObjectName: | 4805 | case PacketType.ObjectName: |
4806 | ObjectNamePacket objName = (ObjectNamePacket)Pack; | 4806 | ObjectNamePacket objName = (ObjectNamePacket)Pack; |
4807 | 4807 | ||
4808 | handlerObjectName = null; | 4808 | handlerObjectName = null; |
4809 | for (int i = 0; i < objName.ObjectData.Length; i++) | 4809 | for (int i = 0; i < objName.ObjectData.Length; i++) |
4810 | { | 4810 | { |
4811 | handlerObjectName = OnObjectName; | 4811 | handlerObjectName = OnObjectName; |
4812 | if (handlerObjectName != null) | 4812 | if (handlerObjectName != null) |
4813 | { | 4813 | { |
diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs index c75a5b3..352f697 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs | |||
@@ -26,9 +26,9 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System.Net; | 28 | using System.Net; |
29 | //using System.Threading; | ||
30 | using log4net; | 29 | using log4net; |
31 | using NUnit.Framework; | 30 | using NUnit.Framework; |
31 | using NUnit.Framework.SyntaxHelpers; | ||
32 | using OpenMetaverse; | 32 | using OpenMetaverse; |
33 | using OpenMetaverse.Packets; | 33 | using OpenMetaverse.Packets; |
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
@@ -60,9 +60,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
60 | /// <summary> | 60 | /// <summary> |
61 | /// Add a client for testing | 61 | /// Add a client for testing |
62 | /// </summary> | 62 | /// </summary> |
63 | /// <param name="scene"></param> | ||
63 | /// <param name="testLLUDPServer"></param> | 64 | /// <param name="testLLUDPServer"></param> |
65 | /// <param name="testPacketServer"></param> | ||
64 | /// <param name="acm">Agent circuit manager used in setting up the stack</param> | 66 | /// <param name="acm">Agent circuit manager used in setting up the stack</param> |
65 | protected void SetupStack(out TestLLUDPServer testLLUDPServer, out AgentCircuitManager acm) | 67 | protected void SetupStack( |
68 | IScene scene, out TestLLUDPServer testLLUDPServer, out TestLLPacketServer testPacketServer, | ||
69 | out AgentCircuitManager acm) | ||
66 | { | 70 | { |
67 | ClientStackUserSettings userSettings = new ClientStackUserSettings(); | 71 | ClientStackUserSettings userSettings = new ClientStackUserSettings(); |
68 | testLLUDPServer = new TestLLUDPServer(); | 72 | testLLUDPServer = new TestLLUDPServer(); |
@@ -70,8 +74,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
70 | 74 | ||
71 | uint port = 666; | 75 | uint port = 666; |
72 | testLLUDPServer.Initialise(null, ref port, 0, false, userSettings, null, acm); | 76 | testLLUDPServer.Initialise(null, ref port, 0, false, userSettings, null, acm); |
73 | new LLPacketServer(testLLUDPServer, userSettings); | 77 | testPacketServer = new TestLLPacketServer(testLLUDPServer, userSettings); |
74 | testLLUDPServer.LocalScene = new MockScene(); | 78 | testLLUDPServer.LocalScene = scene; |
75 | } | 79 | } |
76 | 80 | ||
77 | /// <summary> | 81 | /// <summary> |
@@ -117,8 +121,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
117 | UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002"); | 121 | UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002"); |
118 | 122 | ||
119 | TestLLUDPServer testLLUDPServer; | 123 | TestLLUDPServer testLLUDPServer; |
124 | TestLLPacketServer testLLPacketServer; | ||
120 | AgentCircuitManager acm; | 125 | AgentCircuitManager acm; |
121 | SetupStack(out testLLUDPServer, out acm); | 126 | SetupStack(new MockScene(), out testLLUDPServer, out testLLPacketServer, out acm); |
122 | 127 | ||
123 | AgentCircuitData acd = new AgentCircuitData(); | 128 | AgentCircuitData acd = new AgentCircuitData(); |
124 | acd.AgentID = myAgentUuid; | 129 | acd.AgentID = myAgentUuid; |
@@ -160,8 +165,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
160 | uint myCircuitCode = 123457; | 165 | uint myCircuitCode = 123457; |
161 | 166 | ||
162 | TestLLUDPServer testLLUDPServer; | 167 | TestLLUDPServer testLLUDPServer; |
168 | TestLLPacketServer testLLPacketServer; | ||
163 | AgentCircuitManager acm; | 169 | AgentCircuitManager acm; |
164 | SetupStack(out testLLUDPServer, out acm); | 170 | SetupStack(new MockScene(), out testLLUDPServer, out testLLPacketServer, out acm); |
165 | AddClient(myCircuitCode, new IPEndPoint(IPAddress.Loopback, 1000), testLLUDPServer, acm); | 171 | AddClient(myCircuitCode, new IPEndPoint(IPAddress.Loopback, 1000), testLLUDPServer, acm); |
166 | 172 | ||
167 | testLLUDPServer.RemoveClientCircuit(myCircuitCode); | 173 | testLLUDPServer.RemoveClientCircuit(myCircuitCode); |
@@ -179,20 +185,41 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
179 | public void TestMalformedPacketSend() | 185 | public void TestMalformedPacketSend() |
180 | { | 186 | { |
181 | uint myCircuitCode = 123458; | 187 | uint myCircuitCode = 123458; |
182 | EndPoint testEp = new IPEndPoint(IPAddress.Loopback, 1001); | 188 | EndPoint testEp = new IPEndPoint(IPAddress.Loopback, 1001); |
189 | MockScene scene = new MockScene(); | ||
183 | 190 | ||
184 | TestLLUDPServer testLLUDPServer; | 191 | TestLLUDPServer testLLUDPServer; |
192 | TestLLPacketServer testLLPacketServer; | ||
185 | AgentCircuitManager acm; | 193 | AgentCircuitManager acm; |
186 | SetupStack(out testLLUDPServer, out acm); | 194 | SetupStack(scene, out testLLUDPServer, out testLLPacketServer, out acm); |
187 | AddClient(myCircuitCode, testEp, testLLUDPServer, acm); | 195 | AddClient(myCircuitCode, testEp, testLLUDPServer, acm); |
188 | 196 | ||
189 | byte[] data = new byte[] { 0x01, 0x02, 0x03, 0x04 }; | 197 | byte[] data = new byte[] { 0x01, 0x02, 0x03, 0x04 }; |
190 | 198 | ||
199 | // Send two garbled 'packets' in succession | ||
200 | testLLUDPServer.LoadReceive(data, testEp); | ||
191 | testLLUDPServer.LoadReceive(data, testEp); | 201 | testLLUDPServer.LoadReceive(data, testEp); |
192 | testLLUDPServer.ReceiveData(null); | 202 | testLLUDPServer.ReceiveData(null); |
193 | 203 | ||
194 | // Check that we are still here | 204 | // Check that we are still here |
195 | Assert.IsTrue(testLLUDPServer.HasCircuit(myCircuitCode)); | 205 | Assert.IsTrue(testLLUDPServer.HasCircuit(myCircuitCode)); |
206 | Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(0)); | ||
207 | |||
208 | // Check that sending a valid packet to same circuit still succeeds | ||
209 | Assert.That(scene.ObjectNameCallsReceived, Is.EqualTo(0)); | ||
210 | |||
211 | ObjectNamePacket onp = new ObjectNamePacket(); | ||
212 | ObjectNamePacket.ObjectDataBlock odb = new ObjectNamePacket.ObjectDataBlock(); | ||
213 | odb.LocalID = 1; | ||
214 | odb.Name = Utils.StringToBytes("helloooo"); | ||
215 | onp.ObjectData = new ObjectNamePacket.ObjectDataBlock[] { odb }; | ||
216 | onp.Header.Zerocoded = false; | ||
217 | |||
218 | testLLUDPServer.LoadReceive(onp, testEp); | ||
219 | testLLUDPServer.ReceiveData(null); | ||
220 | |||
221 | Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(1)); | ||
222 | Assert.That(testLLPacketServer.GetPacketsReceivedFor(PacketType.ObjectName), Is.EqualTo(1)); | ||
196 | } | 223 | } |
197 | } | 224 | } |
198 | } | 225 | } |
diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/MockScene.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/MockScene.cs index 4981a1d..4c8ee9c 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/Tests/MockScene.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/MockScene.cs | |||
@@ -36,6 +36,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
36 | /// </summary> | 36 | /// </summary> |
37 | public class MockScene : SceneBase | 37 | public class MockScene : SceneBase |
38 | { | 38 | { |
39 | public int ObjectNameCallsReceived | ||
40 | { | ||
41 | get { return m_objectNameCallsReceived; } | ||
42 | } | ||
43 | protected int m_objectNameCallsReceived; | ||
44 | |||
39 | public MockScene() | 45 | public MockScene() |
40 | { | 46 | { |
41 | m_regInfo = new RegionInfo(1000, 1000, null, null); | 47 | m_regInfo = new RegionInfo(1000, 1000, null, null); |
@@ -44,9 +50,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
44 | 50 | ||
45 | public override void Update() {} | 51 | public override void Update() {} |
46 | public override void LoadWorldMap() {} | 52 | public override void LoadWorldMap() {} |
47 | public override void AddNewClient(IClientAPI client, bool child) {} | 53 | |
54 | public override void AddNewClient(IClientAPI client, bool child) | ||
55 | { | ||
56 | client.OnObjectName += RecordObjectNameCall; | ||
57 | } | ||
58 | |||
48 | public override void RemoveClient(UUID agentID) {} | 59 | public override void RemoveClient(UUID agentID) {} |
49 | public override void CloseAllAgents(uint circuitcode) {} | 60 | public override void CloseAllAgents(uint circuitcode) {} |
50 | public override bool OtherRegionUp(RegionInfo thisRegion) { return false; } | 61 | public override bool OtherRegionUp(RegionInfo thisRegion) { return false; } |
62 | |||
63 | /// <summary> | ||
64 | /// Doesn't really matter what the call is - we're using this to test that a packet has actually been received | ||
65 | /// </summary> | ||
66 | protected void RecordObjectNameCall(IClientAPI remoteClient, uint localID, string message) | ||
67 | { | ||
68 | m_objectNameCallsReceived++; | ||
69 | } | ||
51 | } | 70 | } |
52 | } | 71 | } |
diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLPacketServer.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLPacketServer.cs new file mode 100644 index 0000000..507fe82 --- /dev/null +++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLPacketServer.cs | |||
@@ -0,0 +1,74 @@ | |||
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 | |||
28 | using System.Collections.Generic; | ||
29 | using OpenMetaverse; | ||
30 | using OpenMetaverse.Packets; | ||
31 | using OpenSim.Region.ClientStack.LindenUDP; | ||
32 | |||
33 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests | ||
34 | { | ||
35 | public class TestLLPacketServer : LLPacketServer | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Record counts of packets received | ||
39 | /// </summary> | ||
40 | protected Dictionary<PacketType, int> m_packetsReceived = new Dictionary<PacketType, int>(); | ||
41 | |||
42 | public TestLLPacketServer(ILLClientStackNetworkHandler networkHandler, ClientStackUserSettings userSettings) | ||
43 | : base(networkHandler, userSettings) | ||
44 | {} | ||
45 | |||
46 | public override void InPacket(uint circuitCode, Packet packet) | ||
47 | { | ||
48 | base.InPacket(circuitCode, packet); | ||
49 | |||
50 | if (m_packetsReceived.ContainsKey(packet.Type)) | ||
51 | m_packetsReceived[packet.Type]++; | ||
52 | else | ||
53 | m_packetsReceived[packet.Type] = 1; | ||
54 | } | ||
55 | |||
56 | public int GetTotalPacketsReceived() | ||
57 | { | ||
58 | int totalCount = 0; | ||
59 | |||
60 | foreach (int count in m_packetsReceived.Values) | ||
61 | totalCount += count; | ||
62 | |||
63 | return totalCount; | ||
64 | } | ||
65 | |||
66 | public int GetPacketsReceivedFor(PacketType packetType) | ||
67 | { | ||
68 | if (m_packetsReceived.ContainsKey(packetType)) | ||
69 | return m_packetsReceived[packetType]; | ||
70 | else | ||
71 | return 0; | ||
72 | } | ||
73 | } | ||
74 | } | ||
diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs index 95ee516..dd7afd3 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs | |||
@@ -91,12 +91,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
91 | } | 91 | } |
92 | 92 | ||
93 | /// <summary> | 93 | /// <summary> |
94 | /// Calls the protected asynchronous result method | 94 | /// Calls the protected asynchronous result method. This fires out all data chunks currently queued for send |
95 | /// </summary> | 95 | /// </summary> |
96 | /// <param name="result"></param> | 96 | /// <param name="result"></param> |
97 | public void ReceiveData(IAsyncResult result) | 97 | public void ReceiveData(IAsyncResult result) |
98 | { | 98 | { |
99 | OnReceivedData(result); | 99 | while (m_chunksToLoad.Count > 0) |
100 | OnReceivedData(result); | ||
100 | } | 101 | } |
101 | 102 | ||
102 | /// <summary> | 103 | /// <summary> |
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 77afc43..0dd89ae 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs | |||
@@ -2185,11 +2185,6 @@ namespace OpenSim.Region.Environment.Scenes | |||
2185 | 2185 | ||
2186 | #region Add/Remove Avatar Methods | 2186 | #region Add/Remove Avatar Methods |
2187 | 2187 | ||
2188 | /// <summary> | ||
2189 | /// Register the new client with the scene | ||
2190 | /// </summary> | ||
2191 | /// <param name="client"></param | ||
2192 | /// <param name="child"></param> | ||
2193 | public override void AddNewClient(IClientAPI client, bool child) | 2188 | public override void AddNewClient(IClientAPI client, bool child) |
2194 | { | 2189 | { |
2195 | SubscribeToClientEvents(client); | 2190 | SubscribeToClientEvents(client); |
diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs index 7a3e58f..a1d8f67 100644 --- a/OpenSim/Region/Environment/Scenes/SceneBase.cs +++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs | |||
@@ -130,10 +130,9 @@ namespace OpenSim.Region.Environment.Scenes | |||
130 | #region Add/Remove Agent/Avatar | 130 | #region Add/Remove Agent/Avatar |
131 | 131 | ||
132 | /// <summary> | 132 | /// <summary> |
133 | /// | 133 | /// Register the new client with the scene |
134 | /// </summary> | 134 | /// </summary> |
135 | /// <param name="remoteClient"></param> | 135 | /// <param name="client"></param |
136 | /// <param name="agentID"></param> | ||
137 | /// <param name="child"></param> | 136 | /// <param name="child"></param> |
138 | public abstract void AddNewClient(IClientAPI client, bool child); | 137 | public abstract void AddNewClient(IClientAPI client, bool child); |
139 | 138 | ||