public void RegionLoaded(Scene s)
        {
            if (!Enabled)
            {
                return;
            }

            if (m_inventoryService == null)
            {
                m_inventoryService = s.InventoryService;
            }
            if (m_LibraryService == null)
            {
                m_LibraryService = s.LibraryService;
            }

            if (m_badRequests == null)
            {
                m_badRequests = new ExpiringKey <UUID>(30000);
            }

            if (m_inventoryService != null)
            {
                s.EventManager.OnRegisterCaps += RegisterCaps;
                ++m_nScenes;
            }
        }
Beispiel #2
0
        public void CompareTo_Returns_Minus1_When_GivenIsEqual()
        {
            // Arrange
            var expiryDate = DateTime.Now;
            var element    = new ExpiringKey(new Key("lorem ipsum"), expiryDate);

            // Act
            int result = element.CompareTo(new ExpiringKey(new Key("lorem ipsum"), expiryDate.AddDays(-1)));

            // Assert
            Assert.Equal(-1, result);
        }
Beispiel #3
0
        public void IsExpired_ReturnsTrueWhenKeyExpired_WithPassingDate()
        {
            // Arrange
            var expiryDate = DateTime.MinValue;
            var element    = new ExpiringKey(new Key("lorem ipsum"), expiryDate);

            // Act
            bool expired = element.IsExpired(DateTime.UtcNow);

            // Assert
            Assert.True(expired);
        }
Beispiel #4
0
        private string dorequest(FetchInvDescHandler handler, string request)
        {
            TestOSHttpRequest  req  = new TestOSHttpRequest();
            TestOSHttpResponse resp = new TestOSHttpResponse();

            using (ExpiringKey <UUID> bad = new ExpiringKey <UUID>(5000)) // bad but this is test
                using (MemoryStream ms = new MemoryStream(Utils.StringToBytes(request), false))
                {
                    req.InputStream = ms;
                    handler.FetchInventoryDescendentsRequest(req, resp, bad);
                }
            return(Util.UTF8.GetString(resp.RawBuffer));
        }
Beispiel #5
0
        public void Ctor_AssignsValues_WithExpiry()
        {
            // Arrange
            var key    = new Key();
            var expiry = DateTime.MaxValue;

            // Act
            var element = new ExpiringKey(key, expiry);

            // Assert
            Assert.Equal(key, element.Key);
            Assert.Equal(expiry, element.ExpiryDate);
        }
Beispiel #6
0
        public void ToString_ContainsInformationAboutNameAndExpiry()
        {
            // Arrange
            const string key     = "lorem";
            var          time    = DateTime.Now;
            var          element = new ExpiringKey(new Key(key), time);

            // Act
            string value = element.ToString();

            // Assert
            Assert.Contains(key, value);
            Assert.Contains(time.ToString("g"), value);
        }
Beispiel #7
0
        public FetchInvDescServerConnector(IConfigSource config, IHttpServer server, string configName) :
            base(config, server, configName)
        {
            if (configName != String.Empty)
            {
                m_ConfigName = configName;
            }

            IConfig serverConfig = config.Configs[m_ConfigName];

            if (serverConfig == null)
            {
                throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));
            }

            string invService = serverConfig.GetString("InventoryService", String.Empty);

            if (invService == String.Empty)
            {
                throw new Exception("No InventoryService in config file");
            }

            Object[] args = new Object[] { config };
            m_InventoryService =
                ServerUtils.LoadPlugin <IInventoryService>(invService, args);

            if (m_InventoryService == null)
            {
                throw new Exception(String.Format("Failed to load InventoryService from {0}; config is {1}", invService, m_ConfigName));
            }

            string libService = serverConfig.GetString("LibraryService", String.Empty);

            m_LibraryService =
                ServerUtils.LoadPlugin <ILibraryService>(libService, args);

            ExpiringKey <UUID> m_badRequests = new ExpiringKey <UUID>(30000);

            FetchInvDescHandler  webFetchHandler = new FetchInvDescHandler(m_InventoryService, m_LibraryService, null);
            ISimpleStreamHandler reqHandler
                = new SimpleStreamHandler("/CAPS/WebFetchInvDesc/", delegate(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
            {
                webFetchHandler.FetchInventoryDescendentsRequest(httpRequest, httpResponse, m_badRequests);
            });

            server.AddSimpleStreamHandler(reqHandler);
        }
Beispiel #8
0
        public void Clear(PriorityQueue <ExpiringKey> expiringKeys, Dictionary <Key, Element> nodes)
        {
            DateTime date    = DateTime.UtcNow;
            uint     deleted = 0;

            while (expiringKeys.Count > 0 && expiringKeys.Peek().IsExpired(date))
            {
                ExpiringKey expiringKey = expiringKeys.Poll();
                nodes.Remove(expiringKey.Key);
                deleted++;
            }

            if (deleted > 0)
            {
                _logger.Info($"Deleted {deleted} elements from storage");
            }
        }
        public void RemoveRegion(Scene s)
        {
            if (!Enabled)
            {
                return;
            }

            s.EventManager.OnRegisterCaps -= RegisterCaps;
            --m_nScenes;
            if (m_nScenes <= 0)
            {
                m_inventoryService = null;
                m_LibraryService   = null;
                m_badRequests.Dispose();
                m_badRequests = null;
            }
        }
Beispiel #10
0
        public void Close()
        {
            if (!m_Enabled)
            {
                return;
            }

            if (ProcessQueuedRequestsAsync)
            {
                if (m_NumberScenes <= 0 && m_workerpool != null)
                {
                    m_workerpool.Dispose();
                    m_workerpool = null;
                    m_badRequests.Dispose();
                    m_badRequests = null;
                }
            }
//            m_queue.Dispose();
        }
Beispiel #11
0
        public void Close()
        {
            if (!m_Enabled)
            {
                return;
            }

            if (ProcessQueuedRequestsAsync)
            {
                if (m_NumberScenes <= 0 && m_workerThreads != null)
                {
                    m_log.DebugFormat("[WebFetchInvDescModule] Closing");
                    foreach (Thread t in m_workerThreads)
                    {
                        Watchdog.AbortThread(t.ManagedThreadId);
                    }

                    m_workerThreads = null;
                    m_badRequests.Dispose();
                    m_badRequests = null;
                }
            }
//            m_queue.Dispose();
        }
        public bool MoveNode(Point startPosition, Point endPosition, EventHandler onCompleteEvent, float timer)
        {
            var moving    = OccupiedTiles.ContainsKey(startPosition);
            var collision = CheckMovementCollision(startPosition, endPosition);
            var validMove = !moving && !collision;

            if (validMove)
            {
                var node = ValueAt(startPosition);
                RemoveNode(startPosition);
                AddNode(endPosition, node);
                var movingEntity = new ExpiringKey(timer)
                {
                    OnCompleteEvent = onCompleteEvent
                };
                foreach (var position in PossibleMovements.PositionsToCheck(startPosition, endPosition))
                {
                    OccupiedTiles[position] = movingEntity;
                }
                OccupiedTiles[startPosition] = movingEntity;
                MovingEntities[movingEntity] = node;
            }
            return(validMove);
        }
Beispiel #13
0
        public void RegionLoaded(Scene s)
        {
            if (!m_Enabled)
            {
                return;
            }

            if (s_processedRequestsStat == null)
            {
                s_processedRequestsStat =
                    new Stat(
                        "ProcessedFetchInventoryRequests",
                        "Number of processed fetch inventory requests",
                        "These have not necessarily yet been dispatched back to the requester.",
                        "",
                        "inventory",
                        "httpfetch",
                        StatType.Pull,
                        MeasuresOfInterest.AverageChangeOverTime,
                        stat => { stat.Value = ProcessedRequestsCount; },
                        StatVerbosity.Debug);
            }

            if (s_queuedRequestsStat == null)
            {
                s_queuedRequestsStat =
                    new Stat(
                        "QueuedFetchInventoryRequests",
                        "Number of fetch inventory requests queued for processing",
                        "",
                        "",
                        "inventory",
                        "httpfetch",
                        StatType.Pull,
                        MeasuresOfInterest.AverageChangeOverTime,
                        stat => { stat.Value = m_workerpool.Count; },
                        StatVerbosity.Debug);
            }

            StatsManager.RegisterStat(s_processedRequestsStat);
            StatsManager.RegisterStat(s_queuedRequestsStat);

            m_InventoryService = Scene.InventoryService;
            m_LibraryService   = Scene.LibraryService;

            // We'll reuse the same handler for all requests.
            m_webFetchHandler = new FetchInvDescHandler(m_InventoryService, m_LibraryService, Scene);

            Scene.EventManager.OnRegisterCaps += RegisterCaps;

            if (m_badRequests == null)
            {
                m_badRequests = new ExpiringKey <UUID>(30000);
            }

            m_NumberScenes++;

            if (ProcessQueuedRequestsAsync && m_workerpool == null)
            {
                m_workerpool = new ObjectJobEngine(DoInventoryRequests, "InventoryWorker", 2000, 2);
            }
        }
        public void FetchInventoryDescendentsRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, ExpiringKey <UUID> BadRequests)
        {
            //m_log.DebugFormat("[XXX]: FetchInventoryDescendentsRequest in {0}, {1}", (m_Scene == null) ? "none" : m_Scene.Name, request);

            List <LLSDFetchInventoryDescendents> folders = null;
            List <UUID> bad_folders = new List <UUID>();

            try
            {
                OSDArray foldersrequested = null;
                OSD      tmp = OSDParser.DeserializeLLSDXml(httpRequest.InputStream);
                httpRequest.InputStream.Dispose();

                OSDMap map = (OSDMap)tmp;
                if (map.TryGetValue("folders", out tmp) && tmp is OSDArray)
                {
                    foldersrequested = tmp as OSDArray;
                }

                if (foldersrequested == null || foldersrequested.Count == 0)
                {
                    httpResponse.RawBuffer = EmptyResponse;
                    return;
                }

                folders = new List <LLSDFetchInventoryDescendents>(foldersrequested.Count);
                for (int i = 0; i < foldersrequested.Count; i++)
                {
                    OSDMap mfolder = foldersrequested[i] as OSDMap;
                    UUID   id      = mfolder["folder_id"].AsUUID();
                    if (BadRequests.ContainsKey(id))
                    {
                        bad_folders.Add(id);
                    }
                    else
                    {
                        LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents();
                        try
                        {
                            llsdRequest.folder_id     = id;
                            llsdRequest.owner_id      = mfolder["owner_id"].AsUUID();
                            llsdRequest.sort_order    = mfolder["sort_order"].AsInteger();
                            llsdRequest.fetch_folders = mfolder["fetch_folders"].AsBoolean();
                            llsdRequest.fetch_items   = mfolder["fetch_items"].AsBoolean();
                        }
                        catch (Exception e)
                        {
                            m_log.Debug("[WEB FETCH INV DESC HANDLER]: caught exception doing OSD deserialize" + e.Message);
                            continue;
                        }
                        folders.Add(llsdRequest);
                    }
                }
                foldersrequested = null;
                map.Clear();
                map = null;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[FETCH INV DESC]: fail parsing request: {0}", e.Message);
                httpResponse.RawBuffer = EmptyResponse;
                return;
            }

            if (folders == null || folders.Count == 0)
            {
                if (bad_folders.Count == 0)
                {
                    httpResponse.RawBuffer = EmptyResponse;
                    return;
                }

                StringBuilder sb = osStringBuilderCache.Acquire();
                sb.Append("[WEB FETCH INV DESC HANDLER]: Unable to fetch folders owned by ");
                sb.Append("Unknown");
                sb.Append(" :");
                int limit = 5;
                int count = 0;
                foreach (UUID bad in bad_folders)
                {
                    if (BadRequests.ContainsKey(bad))
                    {
                        continue;
                    }
                    sb.Append(" ");
                    sb.Append(bad.ToString());
                    ++count;
                    if (--limit < 0)
                    {
                        break;
                    }
                }

                if (count > 0)
                {
                    if (limit < 0)
                    {
                        sb.Append(" ...");
                    }
                    m_log.Warn(osStringBuilderCache.GetStringAndRelease(sb));
                }
                else
                {
                    osStringBuilderCache.Release(sb);
                }

                sb = osStringBuilderCache.Acquire();
                sb.Append("<llsd><map><key>folders</key><array /></map><map><key>bad_folders</key><array>");
                foreach (UUID bad in bad_folders)
                {
                    sb.Append("<map><key>folder_id</key><uuid>");
                    sb.Append(bad.ToString());
                    sb.Append("</uuid><key>error</key><string>Unknown</string></map>");
                }
                sb.Append("</array></map></llsd>");
                httpResponse.RawBuffer = Util.UTF8NBGetbytes(osStringBuilderCache.GetStringAndRelease(sb));
                return;
            }

            int total_folders = 0;
            int total_items   = 0;

            UUID requester = folders[0].owner_id;

            List <InventoryCollection> invcollSet = Fetch(folders, bad_folders, ref total_folders, ref total_items);
            //m_log.DebugFormat("[XXX]: Got {0} folders from a request of {1}", invcollSet.Count, folders.Count);

            int invcollSetCount = 0;

            if (invcollSet != null)
            {
                invcollSetCount = invcollSet.Count;
            }

            int mem = 8192 + ((256 * invcollSetCount +
                               384 * total_folders +
                               1024 * total_items +
                               128 * bad_folders.Count) & 0x7ffff000);

            StringBuilder lastresponse = new StringBuilder(mem);

            lastresponse.Append("<llsd>");

            if (invcollSetCount > 0)
            {
                lastresponse.Append("<map><key>folders</key><array>");
                int i = 0;
                InventoryCollection thiscoll;
                for (i = 0; i < invcollSetCount; i++)
                {
                    thiscoll      = invcollSet[i];
                    invcollSet[i] = null;

                    LLSDxmlEncode.AddMap(lastresponse);
                    LLSDxmlEncode.AddElem("agent_id", thiscoll.OwnerID, lastresponse);
                    LLSDxmlEncode.AddElem("descendents", thiscoll.Descendents, lastresponse);
                    LLSDxmlEncode.AddElem("folder_id", thiscoll.FolderID, lastresponse);

                    if (thiscoll.Folders == null || thiscoll.Folders.Count == 0)
                    {
                        LLSDxmlEncode.AddEmptyArray("categories", lastresponse);
                    }
                    else
                    {
                        LLSDxmlEncode.AddArray("categories", lastresponse);
                        foreach (InventoryFolderBase invFolder in thiscoll.Folders)
                        {
                            LLSDxmlEncode.AddMap(lastresponse);

                            LLSDxmlEncode.AddElem("folder_id", invFolder.ID, lastresponse);
                            LLSDxmlEncode.AddElem("parent_id", invFolder.ParentID, lastresponse);
                            LLSDxmlEncode.AddElem("name", invFolder.Name, lastresponse);
                            LLSDxmlEncode.AddElem("type", invFolder.Type, lastresponse);
                            LLSDxmlEncode.AddElem("preferred_type", (int)-1, lastresponse);
                            LLSDxmlEncode.AddElem("version", invFolder.Version, lastresponse);

                            LLSDxmlEncode.AddEndMap(lastresponse);
                        }
                        LLSDxmlEncode.AddEndArray(lastresponse);
                    }

                    if (thiscoll.Items == null || thiscoll.Items.Count == 0)
                    {
                        LLSDxmlEncode.AddEmptyArray("items", lastresponse);
                    }
                    else
                    {
                        LLSDxmlEncode.AddArray("items", lastresponse);
                        foreach (InventoryItemBase invItem in thiscoll.Items)
                        {
                            invItem.ToLLSDxml(lastresponse);
                        }

                        LLSDxmlEncode.AddEndArray(lastresponse);
                    }

                    LLSDxmlEncode.AddElem("owner_id", thiscoll.OwnerID, lastresponse);
                    LLSDxmlEncode.AddElem("version", thiscoll.Version, lastresponse);

                    LLSDxmlEncode.AddEndMap(lastresponse);
                    invcollSet[i] = null;
                }
                lastresponse.Append("</array></map>");
                thiscoll = null;
            }
            else
            {
                lastresponse.Append("<map><key>folders</key><array /></map>");
            }

            if (bad_folders.Count > 0)
            {
                lastresponse.Append("<map><key>bad_folders</key><array>");
                foreach (UUID bad in bad_folders)
                {
                    BadRequests.Add(bad);
                    lastresponse.Append("<map><key>folder_id</key><uuid>");
                    lastresponse.Append(bad.ToString());
                    lastresponse.Append("</uuid><key>error</key><string>Unknown</string></map>");
                }
                lastresponse.Append("</array></map>");

                StringBuilder sb = osStringBuilderCache.Acquire();
                sb.Append("[WEB FETCH INV DESC HANDLER]: Unable to fetch folders owned by ");
                sb.Append(requester.ToString());
                sb.Append(" :");
                int limit = 9;
                foreach (UUID bad in bad_folders)
                {
                    sb.Append(" ");
                    sb.Append(bad.ToString());
                    if (--limit < 0)
                    {
                        break;
                    }
                }
                if (limit < 0)
                {
                    sb.Append(" ...");
                }
                m_log.Warn(osStringBuilderCache.GetStringAndRelease(sb));
            }
            lastresponse.Append("</llsd>");

            httpResponse.RawBuffer = Util.UTF8NBGetbytes(lastresponse.ToString());
        }
Beispiel #15
0
        public void FetchInventorySimpleRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap requestmap, ExpiringKey <UUID> BadRequests)
        {
            //m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capability request {0}", request);

            if (BadRequests == null)
            {
                httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            OSDArray itemsRequested = (OSDArray)requestmap["items"];

            UUID[] itemIDs = new UUID[itemsRequested.Count];
            int    i       = 0;

            foreach (OSDMap osdItemId in itemsRequested)
            {
                UUID id = osdItemId["item_id"].AsUUID();
                if (!BadRequests.ContainsKey(id))
                {
                    itemIDs[i++] = id;
                }
            }

            InventoryItemBase[] items = null;
            try
            {
                // badrequests still not filled
                items = m_inventoryService.GetMultipleItems(m_agentID, itemIDs);
            }
            catch { }

            StringBuilder lsl = LLSDxmlEncode.Start(4096);

            LLSDxmlEncode.AddMap(lsl);

            LLSDxmlEncode.AddElem("agent_id", m_agentID, lsl);

            if (items == null || items.Length == 0)
            {
                LLSDxmlEncode.AddEmptyArray("items", lsl);
            }
            else
            {
                LLSDxmlEncode.AddArray("items", lsl);
                foreach (InventoryItemBase item in items)
                {
                    if (item != null)
                    {
                        item.ToLLSDxml(lsl, 0xff);
                    }
                }
                LLSDxmlEncode.AddEndArray(lsl);
            }

            LLSDxmlEncode.AddEndMap(lsl);
            httpResponse.RawBuffer  = Util.UTF8.GetBytes(LLSDxmlEncode.End(lsl));
            httpResponse.StatusCode = (int)HttpStatusCode.OK;
        }
Beispiel #16
0
        public void RegionLoaded(Scene s)
        {
            if (!m_Enabled)
            {
                return;
            }

            if (s_processedRequestsStat == null)
            {
                s_processedRequestsStat =
                    new Stat(
                        "ProcessedFetchInventoryRequests",
                        "Number of processed fetch inventory requests",
                        "These have not necessarily yet been dispatched back to the requester.",
                        "",
                        "inventory",
                        "httpfetch",
                        StatType.Pull,
                        MeasuresOfInterest.AverageChangeOverTime,
                        stat => { stat.Value = ProcessedRequestsCount; },
                        StatVerbosity.Debug);
            }

            if (s_queuedRequestsStat == null)
            {
                s_queuedRequestsStat =
                    new Stat(
                        "QueuedFetchInventoryRequests",
                        "Number of fetch inventory requests queued for processing",
                        "",
                        "",
                        "inventory",
                        "httpfetch",
                        StatType.Pull,
                        MeasuresOfInterest.AverageChangeOverTime,
                        stat => { stat.Value = m_queue.Count; },
                        StatVerbosity.Debug);
            }

            StatsManager.RegisterStat(s_processedRequestsStat);
            StatsManager.RegisterStat(s_queuedRequestsStat);

            m_InventoryService = Scene.InventoryService;
            m_LibraryService   = Scene.LibraryService;

            // We'll reuse the same handler for all requests.
            m_webFetchHandler = new FetchInvDescHandler(m_InventoryService, m_LibraryService, Scene);

            Scene.EventManager.OnRegisterCaps += RegisterCaps;

            if (m_badRequests == null)
            {
                m_badRequests = new ExpiringKey <UUID>(30000);
            }

            m_NumberScenes++;

            int nworkers = 2; // was 2

            if (ProcessQueuedRequestsAsync && m_workerThreads == null)
            {
                m_workerThreads = new Thread[nworkers];

                for (uint i = 0; i < nworkers; i++)
                {
                    m_workerThreads[i] = WorkManager.StartThread(DoInventoryRequests,
                                                                 String.Format("InventoryWorkerThread{0}", i),
                                                                 ThreadPriority.Normal,
                                                                 true,
                                                                 true,
                                                                 null,
                                                                 int.MaxValue);
                }
            }
        }