aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/Caps/EventQueue
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/EventQueue')
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs90
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs18
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs11
3 files changed, 57 insertions, 62 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
index 7c9a1c4..442cc65 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
@@ -30,7 +30,7 @@ using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Net; 31using System.Net;
32using System.Reflection; 32using System.Reflection;
33using System.Threading; 33using System.Text;
34using log4net; 34using log4net;
35using Nini.Config; 35using Nini.Config;
36using Mono.Addins; 36using Mono.Addins;
@@ -44,7 +44,6 @@ using OpenSim.Framework.Servers;
44using OpenSim.Framework.Servers.HttpServer; 44using OpenSim.Framework.Servers.HttpServer;
45using OpenSim.Region.Framework.Interfaces; 45using OpenSim.Region.Framework.Interfaces;
46using OpenSim.Region.Framework.Scenes; 46using OpenSim.Region.Framework.Scenes;
47using BlockingLLSDQueue = OpenSim.Framework.BlockingQueue<OpenMetaverse.StructuredData.OSD>;
48using Caps=OpenSim.Framework.Capabilities.Caps; 47using Caps=OpenSim.Framework.Capabilities.Caps;
49 48
50namespace OpenSim.Region.ClientStack.Linden 49namespace OpenSim.Region.ClientStack.Linden
@@ -292,8 +291,6 @@ namespace OpenSim.Region.ClientStack.Linden
292 Queue<OSD> queue; 291 Queue<OSD> queue;
293 Random rnd = new Random(Environment.TickCount); 292 Random rnd = new Random(Environment.TickCount);
294 int nrnd = rnd.Next(30000000); 293 int nrnd = rnd.Next(30000000);
295 if (nrnd < 0)
296 nrnd = -nrnd;
297 294
298 lock (queues) 295 lock (queues)
299 { 296 {
@@ -307,21 +304,11 @@ namespace OpenSim.Region.ClientStack.Linden
307 queue = new Queue<OSD>(); 304 queue = new Queue<OSD>();
308 queues[agentID] = queue; 305 queues[agentID] = queue;
309 306
310 // push markers to handle old responses still waiting
311 // this will cost at most viewer getting two forced noevents
312 // even being a new queue better be safe
313 queue.Enqueue(null);
314 queue.Enqueue(null); // one should be enough
315
316 lock (m_AvatarQueueUUIDMapping) 307 lock (m_AvatarQueueUUIDMapping)
317 { 308 {
318 eventQueueGetUUID = UUID.Random(); 309 eventQueueGetUUID = UUID.Random();
319 if (m_AvatarQueueUUIDMapping.ContainsKey(agentID)) 310 while(m_AvatarQueueUUIDMapping.ContainsKey(agentID))
320 { 311 eventQueueGetUUID = UUID.Random();
321 // oops this should not happen ?
322 m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID without a queue");
323 eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID];
324 }
325 m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID); 312 m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID);
326 } 313 }
327 lock (m_ids) 314 lock (m_ids)
@@ -329,18 +316,14 @@ namespace OpenSim.Region.ClientStack.Linden
329 if (!m_ids.ContainsKey(agentID)) 316 if (!m_ids.ContainsKey(agentID))
330 m_ids.Add(agentID, nrnd); 317 m_ids.Add(agentID, nrnd);
331 else 318 else
332 m_ids[agentID] = nrnd; 319 m_ids[agentID]++;
333 } 320 }
334 } 321 }
335 else 322 else
336 { 323 {
337 // push markers to handle old responses still waiting
338 // this will cost at most viewer getting two forced noevents
339 // even being a new queue better be safe
340 queue.Enqueue(null); 324 queue.Enqueue(null);
341 queue.Enqueue(null); // one should be enough 325 queue.Enqueue(null); // one should be enough
342 326 // reuse or not to reuse
343 // reuse or not to reuse TODO FIX
344 lock (m_AvatarQueueUUIDMapping) 327 lock (m_AvatarQueueUUIDMapping)
345 { 328 {
346 // Reuse open queues. The client does! 329 // Reuse open queues. The client does!
@@ -349,30 +332,39 @@ namespace OpenSim.Region.ClientStack.Linden
349 { 332 {
350 m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!"); 333 m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!");
351 eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID]; 334 eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID];
335 lock (m_ids)
336 {
337 // change to negative numbers so they are changed at end of sending first marker
338 // old data on a queue may be sent on a response for a new caps
339 // but at least will be sent with coerent IDs
340 if (!m_ids.ContainsKey(agentID))
341 m_ids.Add(agentID, -nrnd); // should not happen
342 else
343 m_ids[agentID] = -m_ids[agentID];
344 }
352 } 345 }
353 else 346 else
354 { 347 {
355 eventQueueGetUUID = UUID.Random(); 348 eventQueueGetUUID = UUID.Random();
349 while(m_AvatarQueueUUIDMapping.ContainsKey(agentID))
350 eventQueueGetUUID = UUID.Random();
356 m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID); 351 m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID);
357 m_log.DebugFormat("[EVENTQUEUE]: Using random UUID!"); 352 m_log.DebugFormat("[EVENTQUEUE]: Using random UUID!");
353 lock (m_ids)
354 {
355 if (!m_ids.ContainsKey(agentID))
356 m_ids.Add(agentID, nrnd);
357 else
358 m_ids[agentID]++;
359 }
358 } 360 }
359 } 361 }
360 lock (m_ids)
361 {
362 // change to negative numbers so they are changed at end of sending first marker
363 // old data on a queue may be sent on a response for a new caps
364 // but at least will be sent with coerent IDs
365 if (!m_ids.ContainsKey(agentID))
366 m_ids.Add(agentID, -nrnd); // should not happen
367 else
368 m_ids[agentID] = -m_ids[agentID];
369 }
370 } 362 }
371 } 363 }
372 364
373 caps.RegisterPollHandler( 365 caps.RegisterPollHandler(
374 "EventQueueGet", 366 "EventQueueGet",
375 new PollServiceEventArgs(null, GenerateEqgCapPath(eventQueueGetUUID), HasEvents, GetEvents, NoEvents, agentID, SERVER_EQ_TIME_NO_EVENTS)); 367 new PollServiceEventArgs(null, GenerateEqgCapPath(eventQueueGetUUID), HasEvents, GetEvents, NoEvents, Drop, agentID, SERVER_EQ_TIME_NO_EVENTS));
376 } 368 }
377 369
378 public bool HasEvents(UUID requestID, UUID agentID) 370 public bool HasEvents(UUID requestID, UUID agentID)
@@ -448,7 +440,6 @@ namespace OpenSim.Region.ClientStack.Linden
448 if (DebugLevel > 0) 440 if (DebugLevel > 0)
449 LogOutboundDebugMessage(element, pAgentId); 441 LogOutboundDebugMessage(element, pAgentId);
450 array.Add(element); 442 array.Add(element);
451 thisID++;
452 } 443 }
453 } 444 }
454 445
@@ -465,8 +456,6 @@ namespace OpenSim.Region.ClientStack.Linden
465 { 456 {
466 Random rnd = new Random(Environment.TickCount); 457 Random rnd = new Random(Environment.TickCount);
467 thisID = rnd.Next(30000000); 458 thisID = rnd.Next(30000000);
468 if (thisID < 0)
469 thisID = -thisID;
470 } 459 }
471 460
472 lock (m_ids) 461 lock (m_ids)
@@ -474,16 +463,19 @@ namespace OpenSim.Region.ClientStack.Linden
474 m_ids[pAgentId] = thisID + 1; 463 m_ids[pAgentId] = thisID + 1;
475 } 464 }
476 465
466 Hashtable responsedata;
477 // if there where no elements before a marker send a NoEvents 467 // if there where no elements before a marker send a NoEvents
478 if (array.Count == 0) 468 if (events == null)
479 return NoEvents(requestID, pAgentId); 469 {
480 470 return NoEvents(requestID, pAgentId);
481 Hashtable responsedata = new Hashtable(); 471 }
482 responsedata["int_response_code"] = 200; 472 else
483 responsedata["content_type"] = "application/xml"; 473 {
484 responsedata["keepalive"] = false; 474 responsedata = new Hashtable();
485 responsedata["reusecontext"] = false; 475 responsedata["int_response_code"] = 200;
486 responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(events); 476 responsedata["content_type"] = "application/xml";
477 responsedata["bin_response_data"] = Encoding.UTF8.GetBytes(OSDParser.SerializeLLSDXmlString(events));
478 }
487 //m_log.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", pAgentId, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]); 479 //m_log.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", pAgentId, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
488 return responsedata; 480 return responsedata;
489 } 481 }
@@ -493,13 +485,13 @@ namespace OpenSim.Region.ClientStack.Linden
493 Hashtable responsedata = new Hashtable(); 485 Hashtable responsedata = new Hashtable();
494 responsedata["int_response_code"] = 502; 486 responsedata["int_response_code"] = 502;
495 responsedata["content_type"] = "text/plain"; 487 responsedata["content_type"] = "text/plain";
496 responsedata["keepalive"] = false;
497 responsedata["reusecontext"] = false;
498 responsedata["str_response_string"] = "<llsd></llsd>"; 488 responsedata["str_response_string"] = "<llsd></llsd>";
499 responsedata["error_status_text"] = "<llsd></llsd>"; 489 responsedata["error_status_text"] = "<llsd></llsd>";
500 responsedata["http_protocol_version"] = "HTTP/1.0"; 490 responsedata["http_protocol_version"] = "HTTP/1.0";
491 responsedata["keepalive"] = false;
501 return responsedata; 492 return responsedata;
502 } 493 }
494
503/* this is not a event message 495/* this is not a event message
504 public void DisableSimulator(ulong handle, UUID avatarID) 496 public void DisableSimulator(ulong handle, UUID avatarID)
505 { 497 {
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs
index 461f776..52cfd48 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs
@@ -43,16 +43,16 @@ namespace OpenSim.Region.ClientStack.Linden
43 private static byte[] ulongToByteArray(ulong uLongValue) 43 private static byte[] ulongToByteArray(ulong uLongValue)
44 { 44 {
45 // Reverse endianness of RegionHandle 45 // Reverse endianness of RegionHandle
46 return new byte[] 46 return new byte[8]
47 { 47 {
48 (byte)((uLongValue >> 56) % 256), 48 (byte)((uLongValue >> 56) & 0xff),
49 (byte)((uLongValue >> 48) % 256), 49 (byte)((uLongValue >> 48) & 0xff),
50 (byte)((uLongValue >> 40) % 256), 50 (byte)((uLongValue >> 40) & 0xff),
51 (byte)((uLongValue >> 32) % 256), 51 (byte)((uLongValue >> 32) & 0xff),
52 (byte)((uLongValue >> 24) % 256), 52 (byte)((uLongValue >> 24) & 0xff),
53 (byte)((uLongValue >> 16) % 256), 53 (byte)((uLongValue >> 16) & 0xff),
54 (byte)((uLongValue >> 8) % 256), 54 (byte)((uLongValue >> 8) & 0xff),
55 (byte)(uLongValue % 256) 55 (byte)(uLongValue & 0xff)
56 }; 56 };
57 } 57 }
58 58
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs
index ee3f4f1..080cef9 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs
@@ -29,6 +29,7 @@ using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Net; 31using System.Net;
32using System.Text;
32using log4net.Config; 33using log4net.Config;
33using Nini.Config; 34using Nini.Config;
34using NUnit.Framework; 35using NUnit.Framework;
@@ -59,13 +60,12 @@ namespace OpenSim.Region.ClientStack.Linden.Tests
59 base.SetUp(); 60 base.SetUp();
60 61
61 uint port = 9999; 62 uint port = 9999;
62 uint sslPort = 9998;
63 63
64 // This is an unfortunate bit of clean up we have to do because MainServer manages things through static 64 // This is an unfortunate bit of clean up we have to do because MainServer manages things through static
65 // variables and the VM is not restarted between tests. 65 // variables and the VM is not restarted between tests.
66 MainServer.RemoveHttpServer(port); 66 MainServer.RemoveHttpServer(port);
67 67
68 BaseHttpServer server = new BaseHttpServer(port, false, sslPort, ""); 68 BaseHttpServer server = new BaseHttpServer(port, false, "","","");
69 MainServer.AddHttpServer(server); 69 MainServer.AddHttpServer(server);
70 MainServer.Instance = server; 70 MainServer.Instance = server;
71 71
@@ -126,7 +126,7 @@ namespace OpenSim.Region.ClientStack.Linden.Tests
126 Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID); 126 Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID);
127 127
128 // initial queue as null events 128 // initial queue as null events
129 eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID); 129// eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID);
130 if((int)eventsResponse["int_response_code"] != (int)HttpStatusCode.OK) 130 if((int)eventsResponse["int_response_code"] != (int)HttpStatusCode.OK)
131 { 131 {
132 eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID); 132 eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID);
@@ -137,8 +137,11 @@ namespace OpenSim.Region.ClientStack.Linden.Tests
137 Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.OK)); 137 Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.OK));
138 138
139// Console.WriteLine("Response [{0}]", (string)eventsResponse["str_response_string"]); 139// Console.WriteLine("Response [{0}]", (string)eventsResponse["str_response_string"]);
140 string data = String.Empty;
141 if(eventsResponse["bin_response_data"] != null)
142 data = Encoding.UTF8.GetString((byte[])eventsResponse["bin_response_data"]);
140 143
141 OSDMap rawOsd = (OSDMap)OSDParser.DeserializeLLSDXml((string)eventsResponse["str_response_string"]); 144 OSDMap rawOsd = (OSDMap)OSDParser.DeserializeLLSDXml(data);
142 OSDArray eventsOsd = (OSDArray)rawOsd["events"]; 145 OSDArray eventsOsd = (OSDArray)rawOsd["events"];
143 146
144 bool foundUpdate = false; 147 bool foundUpdate = false;