From c72f78215bb3435ee2bbb507746c23eccec4dd34 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 4 Nov 2009 01:56:19 +0000 Subject: Backport the fixes to WebFetchInventoryDescendents to the UDP InventoryDescendents packet. Testing has shown that UDP inventory now works flawlessly and, unlike CAPS inventory, doesn't download the entire agent inventory on start. Neither does it incessantly re-request folder NULL_KEY. Therefore, I have disabled CAPS inventory. --- .../Region/ClientStack/LindenUDP/LLClientView.cs | 246 ++++++++------------- 1 file changed, 94 insertions(+), 152 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index db0c3b8..bd5df19 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -1251,7 +1251,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// Do we need to send folder information? /// Do we need to send item information? public void SendInventoryFolderDetails(UUID ownerID, UUID folderID, List items, - List folders, + List folders, int version, bool fetchFolders, bool fetchItems) { // An inventory descendents packet consists of a single agent section and an inventory details @@ -1266,172 +1266,104 @@ namespace OpenSim.Region.ClientStack.LindenUDP // 6 to 7 items at a time, so let's stick with 6 int MAX_ITEMS_PER_PACKET = 6; - //Ckrinke This variable is not used, so comment out to remove the warning from the compiler (3-21-08) - //Ckrinke uint FULL_MASK_PERMISSIONS = 2147483647; - + int totalItems = fetchItems ? items.Count : 0; + int totalFolders = fetchFolders ? folders.Count : 0; int itemsSent = 0; - if (fetchItems) - { - InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID); - - if (items.Count < MAX_ITEMS_PER_PACKET) - { - descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count]; - } - else - { - descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET]; - } + int foldersSent = 0; + int foldersToSend = 0; + int itemsToSend = 0; - // Descendents must contain the *total* number of descendents (plus folders, whether we - // fetch them or not), not the number of entries we send in this packet. For consistency, - // I'll use it for folder-requests, too, although I wasn't able to get one with - // FetchFolders = true. - // TODO this should be checked with FetchFolders = true - descend.AgentData.Descendents = items.Count + folders.Count; + InventoryDescendentsPacket currentPacket = null; - int count = 0; - int i = 0; - foreach (InventoryItemBase item in items) + // Handle empty folders + // + if (totalItems == 0 && totalFolders == 0) + currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, 0, 0); + + // To preserve SL compatibility, we will NOT combine folders and items in one packet + // + while(itemsSent < totalItems || foldersSent < totalFolders) + { + if (currentPacket == null) // Start a new packet { - descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock(); - descend.ItemData[i].ItemID = item.ID; - descend.ItemData[i].AssetID = item.AssetID; - descend.ItemData[i].CreatorID = item.CreatorIdAsUuid; - descend.ItemData[i].BaseMask = item.BasePermissions; - descend.ItemData[i].Description = Util.StringToBytes256(item.Description); - descend.ItemData[i].EveryoneMask = item.EveryOnePermissions; - descend.ItemData[i].OwnerMask = item.CurrentPermissions; - descend.ItemData[i].FolderID = item.Folder; - descend.ItemData[i].InvType = (sbyte)item.InvType; - descend.ItemData[i].Name = Util.StringToBytes256(item.Name); - descend.ItemData[i].NextOwnerMask = item.NextPermissions; - descend.ItemData[i].OwnerID = item.Owner; - descend.ItemData[i].Type = (sbyte)item.AssetType; - - descend.ItemData[i].GroupID = item.GroupID; - descend.ItemData[i].GroupOwned = item.GroupOwned; - descend.ItemData[i].GroupMask = item.GroupPermissions; - descend.ItemData[i].CreationDate = item.CreationDate; - descend.ItemData[i].SalePrice = item.SalePrice; - descend.ItemData[i].SaleType = item.SaleType; - descend.ItemData[i].Flags = item.Flags; - - descend.ItemData[i].CRC = - Helpers.InventoryCRC(descend.ItemData[i].CreationDate, descend.ItemData[i].SaleType, - descend.ItemData[i].InvType, descend.ItemData[i].Type, - descend.ItemData[i].AssetID, descend.ItemData[i].GroupID, - descend.ItemData[i].SalePrice, - descend.ItemData[i].OwnerID, descend.ItemData[i].CreatorID, - descend.ItemData[i].ItemID, descend.ItemData[i].FolderID, - descend.ItemData[i].EveryoneMask, - descend.ItemData[i].Flags, descend.ItemData[i].OwnerMask, - descend.ItemData[i].GroupMask, item.CurrentPermissions); - - i++; - count++; - itemsSent++; - if (i == MAX_ITEMS_PER_PACKET) - { - descend.Header.Zerocoded = true; - AddNullFolderBlockToDecendentsPacket(ref descend); - OutPacket(descend, ThrottleOutPacketType.Asset); - - if ((items.Count - count) > 0) - { - descend = CreateInventoryDescendentsPacket(ownerID, folderID); - if ((items.Count - count) < MAX_ITEMS_PER_PACKET) - { - descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count - count]; - } - else - { - descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET]; - } - descend.AgentData.Descendents = items.Count + folders.Count; - i = 0; - } + foldersToSend = totalFolders - foldersSent; + if (foldersToSend > MAX_ITEMS_PER_PACKET) + foldersToSend = MAX_ITEMS_PER_PACKET; + + if (foldersToSend == 0) + { + itemsToSend = totalItems - itemsSent; + if (itemsToSend > MAX_ITEMS_PER_PACKET) + itemsToSend = MAX_ITEMS_PER_PACKET; } - } - if (0 < i && i < MAX_ITEMS_PER_PACKET) - { - AddNullFolderBlockToDecendentsPacket(ref descend); - OutPacket(descend, ThrottleOutPacketType.Asset); + currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, foldersToSend, itemsToSend); } - } - - //send subfolders - if (fetchFolders) - { - InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID); - if (folders.Count < MAX_ITEMS_PER_PACKET) - { - descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders.Count]; - } + if (foldersToSend-- > 0) + currentPacket.FolderData[foldersSent % MAX_ITEMS_PER_PACKET] = CreateFolderDataBlock(folders[foldersSent++]); + else if(itemsToSend-- > 0) + currentPacket.ItemData[itemsSent % MAX_ITEMS_PER_PACKET] = CreateItemDataBlock(items[itemsSent++]); else { - descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET]; + OutPacket(currentPacket, ThrottleOutPacketType.Asset); + currentPacket = null; } - // Not sure if this scenario ever actually occurs, but nonetheless we include the items - // count even if we're not sending item data for the same reasons as above. - descend.AgentData.Descendents = items.Count + folders.Count; + } - int i = 0; - int count = 0; - foreach (InventoryFolderBase folder in folders) - { - descend.FolderData[i] = new InventoryDescendentsPacket.FolderDataBlock(); - descend.FolderData[i].FolderID = folder.ID; - descend.FolderData[i].Name = Util.StringToBytes256(folder.Name); - descend.FolderData[i].ParentID = folder.ParentID; - descend.FolderData[i].Type = (sbyte)folder.Type; + if (currentPacket != null) + OutPacket(currentPacket, ThrottleOutPacketType.Asset); + } - i++; - count++; - itemsSent++; - if (i == MAX_ITEMS_PER_PACKET) - { - AddNullItemBlockToDescendentsPacket(ref descend); - OutPacket(descend, ThrottleOutPacketType.Asset); + private InventoryDescendentsPacket.FolderDataBlock CreateFolderDataBlock(InventoryFolderBase folder) + { + InventoryDescendentsPacket.FolderDataBlock newBlock = new InventoryDescendentsPacket.FolderDataBlock(); + newBlock.FolderID = folder.ID; + newBlock.Name = Util.StringToBytes256(folder.Name); + newBlock.ParentID = folder.ParentID; + newBlock.Type = (sbyte)folder.Type; - if ((folders.Count - count) > 0) - { - descend = CreateInventoryDescendentsPacket(ownerID, folderID); - if ((folders.Count - count) < MAX_ITEMS_PER_PACKET) - { - descend.FolderData = - new InventoryDescendentsPacket.FolderDataBlock[folders.Count - count]; - } - else - { - descend.FolderData = - new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET]; - } - descend.AgentData.Descendents = items.Count + folders.Count; - i = 0; - } - } - } + return newBlock; + } - if (0 < i && i < MAX_ITEMS_PER_PACKET) - { - AddNullItemBlockToDescendentsPacket(ref descend); - OutPacket(descend, ThrottleOutPacketType.Asset); - } - } + private InventoryDescendentsPacket.ItemDataBlock CreateItemDataBlock(InventoryItemBase item) + { + InventoryDescendentsPacket.ItemDataBlock newBlock = new InventoryDescendentsPacket.ItemDataBlock(); + newBlock.ItemID = item.ID; + newBlock.AssetID = item.AssetID; + newBlock.CreatorID = item.CreatorIdAsUuid; + newBlock.BaseMask = item.BasePermissions; + newBlock.Description = Util.StringToBytes256(item.Description); + newBlock.EveryoneMask = item.EveryOnePermissions; + newBlock.OwnerMask = item.CurrentPermissions; + newBlock.FolderID = item.Folder; + newBlock.InvType = (sbyte)item.InvType; + newBlock.Name = Util.StringToBytes256(item.Name); + newBlock.NextOwnerMask = item.NextPermissions; + newBlock.OwnerID = item.Owner; + newBlock.Type = (sbyte)item.AssetType; - if (itemsSent == 0) - { - // no items found. - InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID); - descend.AgentData.Descendents = 0; - AddNullItemBlockToDescendentsPacket(ref descend); - AddNullFolderBlockToDecendentsPacket(ref descend); - OutPacket(descend, ThrottleOutPacketType.Asset); - } + newBlock.GroupID = item.GroupID; + newBlock.GroupOwned = item.GroupOwned; + newBlock.GroupMask = item.GroupPermissions; + newBlock.CreationDate = item.CreationDate; + newBlock.SalePrice = item.SalePrice; + newBlock.SaleType = item.SaleType; + newBlock.Flags = item.Flags; + + newBlock.CRC = + Helpers.InventoryCRC(newBlock.CreationDate, newBlock.SaleType, + newBlock.InvType, newBlock.Type, + newBlock.AssetID, newBlock.GroupID, + newBlock.SalePrice, + newBlock.OwnerID, newBlock.CreatorID, + newBlock.ItemID, newBlock.FolderID, + newBlock.EveryoneMask, + newBlock.Flags, newBlock.OwnerMask, + newBlock.GroupMask, newBlock.NextOwnerMask); + + return newBlock; } private void AddNullFolderBlockToDecendentsPacket(ref InventoryDescendentsPacket packet) @@ -1473,14 +1405,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP // No need to add CRC } - private InventoryDescendentsPacket CreateInventoryDescendentsPacket(UUID ownerID, UUID folderID) + private InventoryDescendentsPacket CreateInventoryDescendentsPacket(UUID ownerID, UUID folderID, int version, int folders, int items) { InventoryDescendentsPacket descend = (InventoryDescendentsPacket)PacketPool.Instance.GetPacket(PacketType.InventoryDescendents); descend.Header.Zerocoded = true; descend.AgentData.AgentID = AgentId; descend.AgentData.OwnerID = ownerID; descend.AgentData.FolderID = folderID; - descend.AgentData.Version = 1; + descend.AgentData.Version = version; + + if (folders > 0) + descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders]; + else + AddNullFolderBlockToDecendentsPacket(ref descend); + + if (items > 0) + descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items]; + else + AddNullItemBlockToDescendentsPacket(ref descend); return descend; } -- cgit v1.1 From 4d2ecd1236f36e0ce6307689cac6e35baed3b73b Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 4 Nov 2009 03:07:21 +0000 Subject: Correctly set the totall number of descendents in inventory retrieval --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index bd5df19..479da6d 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -1278,7 +1278,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP // Handle empty folders // if (totalItems == 0 && totalFolders == 0) - currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, 0, 0); + currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, items.Count + folders.Count, 0, 0); // To preserve SL compatibility, we will NOT combine folders and items in one packet // @@ -1297,7 +1297,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP itemsToSend = MAX_ITEMS_PER_PACKET; } - currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, foldersToSend, itemsToSend); + currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, items.Count + folders.Count, foldersToSend, itemsToSend); } if (foldersToSend-- > 0) @@ -1405,7 +1405,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP // No need to add CRC } - private InventoryDescendentsPacket CreateInventoryDescendentsPacket(UUID ownerID, UUID folderID, int version, int folders, int items) + private InventoryDescendentsPacket CreateInventoryDescendentsPacket(UUID ownerID, UUID folderID, int version, int descendents, int folders, int items) { InventoryDescendentsPacket descend = (InventoryDescendentsPacket)PacketPool.Instance.GetPacket(PacketType.InventoryDescendents); descend.Header.Zerocoded = true; @@ -1413,6 +1413,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP descend.AgentData.OwnerID = ownerID; descend.AgentData.FolderID = folderID; descend.AgentData.Version = version; + descend.AgentData.Descendents = descendents; if (folders > 0) descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders]; -- cgit v1.1 From 5bcc02c97b78f76a274440ca0b62830d820299d9 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 4 Nov 2009 03:56:31 +0000 Subject: Prevent autosplitting of inventory descendents packets. Also reduces the number of items per packet to 5 to prevent asserts --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 479da6d..e26d50a 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -1264,7 +1264,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP // // for one example of this kind of thing. In fact, the Linden servers appear to only send about // 6 to 7 items at a time, so let's stick with 6 - int MAX_ITEMS_PER_PACKET = 6; + int MAX_ITEMS_PER_PACKET = 5; int totalItems = fetchItems ? items.Count : 0; int totalFolders = fetchFolders ? folders.Count : 0; @@ -1415,6 +1415,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP descend.AgentData.Version = version; descend.AgentData.Descendents = descendents; + // Disable multiple packets + descend.HasVariableBlocks = false; + if (folders > 0) descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders]; else -- cgit v1.1 From cfcb5faa4e7ff48b486567c32e07253fabdbc8ec Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 4 Nov 2009 04:09:46 +0000 Subject: Bounce the pacjet items limit back up to 6 --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index e26d50a..09c5dfa 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -1264,7 +1264,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP // // for one example of this kind of thing. In fact, the Linden servers appear to only send about // 6 to 7 items at a time, so let's stick with 6 - int MAX_ITEMS_PER_PACKET = 5; + int MAX_ITEMS_PER_PACKET = 6; int totalItems = fetchItems ? items.Count : 0; int totalFolders = fetchFolders ? folders.Count : 0; -- cgit v1.1 From 535f4597c1de74180f59dd97c5b8888eaf12c01a Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 4 Nov 2009 04:36:19 +0000 Subject: Add an overload to OutPacket as per jhurliman. Switch hacky workaround for InventoryDescendents to the proper way --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 09c5dfa..2da6d98 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -1306,14 +1306,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP currentPacket.ItemData[itemsSent % MAX_ITEMS_PER_PACKET] = CreateItemDataBlock(items[itemsSent++]); else { - OutPacket(currentPacket, ThrottleOutPacketType.Asset); + OutPacket(currentPacket, ThrottleOutPacketType.Asset, false); currentPacket = null; } } if (currentPacket != null) - OutPacket(currentPacket, ThrottleOutPacketType.Asset); + OutPacket(currentPacket, ThrottleOutPacketType.Asset, false); } private InventoryDescendentsPacket.FolderDataBlock CreateFolderDataBlock(InventoryFolderBase folder) @@ -1415,9 +1415,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP descend.AgentData.Version = version; descend.AgentData.Descendents = descendents; - // Disable multiple packets - descend.HasVariableBlocks = false; - if (folders > 0) descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders]; else @@ -4909,6 +4906,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, true); } + /// + /// This is the starting point for sending a simulator packet out to the client + /// + /// Packet to send + /// Throttling category for the packet + /// True to automatically split oversized + /// packets (the default), or false to disable splitting if the calling code + /// handles splitting manually + protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting) + { + m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, doAutomaticSplitting); + } + public bool AddMoney(int debit) { if (m_moneyBalance + debit >= 0) -- cgit v1.1 From 58be90d2b167719267fde18f2983b5a64f8b6f37 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 4 Nov 2009 22:47:40 +0000 Subject: Add some length to the backet buffer for packet sending so oversize inventory packets don't make us barf --- OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 93946ae..93c3270 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -327,7 +327,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP // The vast majority of packets are less than 200 bytes, although due to asset transfers and packet splitting // there are a decent number of packets in the 1000-1140 byte range. We allocate one of two sizes of data here // to accomodate for both common scenarios and provide ample room for ACK appending in both - int bufferSize = (dataLength > 180) ? LLUDPServer.MTU : 200; + int bufferSize = (dataLength > 180) ? LLUDPServer.MTU + 1000 : 200; UDPPacketBuffer buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize); -- cgit v1.1 From b6ea7c26ac7653a144b5880e3027fcddabe872e8 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 4 Nov 2009 23:12:56 +0000 Subject: Refine oversized packet handling as per jhurliman. Reallocate the buffer to actual packet size only for oversized packets. --- OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 93c3270..6165984 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -327,7 +327,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP // The vast majority of packets are less than 200 bytes, although due to asset transfers and packet splitting // there are a decent number of packets in the 1000-1140 byte range. We allocate one of two sizes of data here // to accomodate for both common scenarios and provide ample room for ACK appending in both - int bufferSize = (dataLength > 180) ? LLUDPServer.MTU + 1000 : 200; + int bufferSize = (dataLength > 180) ? LLUDPServer.MTU : 200; UDPPacketBuffer buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize); @@ -359,9 +359,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP } else { - m_log.Error("[LLUDPSERVER]: Packet exceeded buffer size! This could be an indication of packet assembly not obeying the MTU. Type=" + - type + ", DataLength=" + dataLength + ", BufferLength=" + buffer.Data.Length + ". Dropping packet"); - return; + bufferSize = dataLength; + buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize); + + // m_log.Error("[LLUDPSERVER]: Packet exceeded buffer size! This could be an indication of packet assembly not obeying the MTU. Type=" + + // type + ", DataLength=" + dataLength + ", BufferLength=" + buffer.Data.Length + ". Dropping packet"); + Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength); } } -- cgit v1.1 From 30a2411e5816b3e0aa421e4537e554aa640c060f Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 4 Nov 2009 23:54:19 +0000 Subject: Separate folder and item limit for UDP inventory packets. Folder limit is now 6, as before, item limit is 5. This should avoid most, if not all, oversized packets. --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 2da6d98..70abe77 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -1264,7 +1264,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP // // for one example of this kind of thing. In fact, the Linden servers appear to only send about // 6 to 7 items at a time, so let's stick with 6 - int MAX_ITEMS_PER_PACKET = 6; + int MAX_ITEMS_PER_PACKET = 5; + int MAX_FOLDERS_PER_PACKET = 6; int totalItems = fetchItems ? items.Count : 0; int totalFolders = fetchFolders ? folders.Count : 0; @@ -1287,8 +1288,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (currentPacket == null) // Start a new packet { foldersToSend = totalFolders - foldersSent; - if (foldersToSend > MAX_ITEMS_PER_PACKET) - foldersToSend = MAX_ITEMS_PER_PACKET; + if (foldersToSend > MAX_FOLDERS_PER_PACKET) + foldersToSend = MAX_FOLDERS_PER_PACKET; if (foldersToSend == 0) { @@ -1301,7 +1302,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP } if (foldersToSend-- > 0) - currentPacket.FolderData[foldersSent % MAX_ITEMS_PER_PACKET] = CreateFolderDataBlock(folders[foldersSent++]); + currentPacket.FolderData[foldersSent % MAX_FOLDERS_PER_PACKET] = CreateFolderDataBlock(folders[foldersSent++]); else if(itemsToSend-- > 0) currentPacket.ItemData[itemsSent % MAX_ITEMS_PER_PACKET] = CreateItemDataBlock(items[itemsSent++]); else -- cgit v1.1 From 83b4b4440b7becb405840bc69d665e260fdecea0 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 5 Nov 2009 02:09:07 +0000 Subject: Patch by revolution, thank you. Mantis #1789 . Implement friends permissions. Applied with major changes. Core functionality commented pending review for possible rights escalation. No user functionality yet. --- .../Region/ClientStack/LindenUDP/LLClientView.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 70abe77..34cad7b 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -220,6 +220,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP public event FriendActionDelegate OnApproveFriendRequest; public event FriendActionDelegate OnDenyFriendRequest; public event FriendshipTermination OnTerminateFriendship; + public event GrantUserFriendRights OnGrantUserRights; public event MoneyTransferRequest OnMoneyTransferRequest; public event EconomyDataRequest OnEconomyDataRequest; public event MoneyBalanceRequest OnMoneyBalanceRequest; @@ -9719,7 +9720,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP Utils.BytesToString(avatarInterestUpdate.PropertiesData.SkillsText), Utils.BytesToString(avatarInterestUpdate.PropertiesData.LanguagesText)); break; - + + case PacketType.GrantUserRights: + GrantUserRightsPacket GrantUserRights = + (GrantUserRightsPacket)Pack; + #region Packet Session and User Check + if (m_checkPackets) + { + if (GrantUserRights.AgentData.SessionID != SessionId || + GrantUserRights.AgentData.AgentID != AgentId) + break; + } + #endregion + GrantUserFriendRights GrantUserRightsHandler = OnGrantUserRights; + if (GrantUserRightsHandler != null) + GrantUserRightsHandler(this, + GrantUserRights.AgentData.AgentID, + GrantUserRights.Rights[0].AgentRelated, + GrantUserRights.Rights[0].RelatedRights); + break; + case PacketType.PlacesQuery: PlacesQueryPacket placesQueryPacket = (PlacesQueryPacket)Pack; -- cgit v1.1 From e6d7303b296468a06ada761706e25d49587b308f Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 5 Nov 2009 12:01:40 -0800 Subject: Applying #4332, optional packet statistics logging --- .../Region/ClientStack/LindenUDP/LLClientView.cs | 4 + .../Region/ClientStack/LindenUDP/LLUDPServer.cs | 111 +++++++++++++++++++++ 2 files changed, 115 insertions(+) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 34cad7b..101a44b 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -4905,6 +4905,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// Throttling category for the packet protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType) { + #region BinaryStats + LLUDPServer.LogPacketHeader(false, m_circuitCode, 0, packet.Type, (ushort)packet.Length); + #endregion BinaryStats + m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, true); } diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 6165984..c773c05 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Net; using System.Net.Sockets; using System.Reflection; @@ -204,6 +205,31 @@ namespace OpenSim.Region.ClientStack.LindenUDP TextureSendLimit = 20; } + #region BinaryStats + config = configSource.Configs["Statistics.Binary"]; + m_shouldCollectStats = false; + if (config != null) + { + if (config.Contains("enabled") && config.GetBoolean("enabled")) + { + if (config.Contains("collect_packet_headers")) + m_shouldCollectStats = config.GetBoolean("collect_packet_headers"); + if (config.Contains("packet_headers_period_seconds")) + { + binStatsMaxFilesize = TimeSpan.FromSeconds(config.GetInt("region_stats_period_seconds")); + } + if (config.Contains("stats_dir")) + { + binStatsDir = config.GetString("stats_dir"); + } + } + else + { + m_shouldCollectStats = false; + } + } + #endregion BinaryStats + m_throttle = new TokenBucket(null, sceneThrottleBps, sceneThrottleBps); m_throttleRates = new ThrottleRates(configSource); } @@ -679,6 +705,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP #endregion Incoming Packet Accounting + #region BinaryStats + LogPacketHeader(true, udpClient.CircuitCode, 0, packet.Type, (ushort)packet.Length); + #endregion BinaryStats + #region Ping Check Handling if (packet.Type == PacketType.StartPingCheck) @@ -700,6 +730,87 @@ namespace OpenSim.Region.ClientStack.LindenUDP packetInbox.Enqueue(new IncomingPacket(udpClient, packet)); } + #region BinaryStats + + public class PacketLogger + { + public DateTime StartTime; + public string Path = null; + public System.IO.BinaryWriter Log = null; + } + + public static PacketLogger PacketLog; + + protected static bool m_shouldCollectStats = false; + // Number of seconds to log for + static TimeSpan binStatsMaxFilesize = TimeSpan.FromSeconds(300); + static object binStatsLogLock = new object(); + static string binStatsDir = ""; + + public static void LogPacketHeader(bool incoming, uint circuit, byte flags, PacketType packetType, ushort size) + { + if (!m_shouldCollectStats) return; + + // Binary logging format is TTTTTTTTCCCCFPPPSS, T=Time, C=Circuit, F=Flags, P=PacketType, S=size + + // Put the incoming bit into the least significant bit of the flags byte + if (incoming) + flags |= 0x01; + else + flags &= 0xFE; + + // Put the flags byte into the most significant bits of the type integer + uint type = (uint)packetType; + type |= (uint)flags << 24; + + // m_log.Debug("1 LogPacketHeader(): Outside lock"); + lock (binStatsLogLock) + { + DateTime now = DateTime.Now; + + // m_log.Debug("2 LogPacketHeader(): Inside lock. now is " + now.Ticks); + try + { + if (PacketLog == null || (now > PacketLog.StartTime + binStatsMaxFilesize)) + { + if (PacketLog != null && PacketLog.Log != null) + { + PacketLog.Log.Close(); + } + + // First log file or time has expired, start writing to a new log file + PacketLog = new PacketLogger(); + PacketLog.StartTime = now; + PacketLog.Path = (binStatsDir.Length > 0 ? binStatsDir + System.IO.Path.DirectorySeparatorChar.ToString() : "") + + String.Format("packets-{0}.log", now.ToString("yyyyMMddHHmmss")); + PacketLog.Log = new BinaryWriter(File.Open(PacketLog.Path, FileMode.Append, FileAccess.Write)); + } + + // Serialize the data + byte[] output = new byte[18]; + Buffer.BlockCopy(BitConverter.GetBytes(now.Ticks), 0, output, 0, 8); + Buffer.BlockCopy(BitConverter.GetBytes(circuit), 0, output, 8, 4); + Buffer.BlockCopy(BitConverter.GetBytes(type), 0, output, 12, 4); + Buffer.BlockCopy(BitConverter.GetBytes(size), 0, output, 16, 2); + + // Write the serialized data to disk + if (PacketLog != null && PacketLog.Log != null) + PacketLog.Log.Write(output); + } + catch (Exception ex) + { + m_log.Error("Packet statistics gathering failed: " + ex.Message, ex); + if (PacketLog.Log != null) + { + PacketLog.Log.Close(); + } + PacketLog = null; + } + } + } + + #endregion BinaryStats + private void HandleUseCircuitCode(object o) { object[] array = (object[])o; -- cgit v1.1 From afef1ac191d32e9c1514c294b17e404b1d4ae217 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 5 Nov 2009 13:10:58 -0800 Subject: Changing the AssetBase constructors to avoid initializing assets with an unknown asset type, and log an error if it ever does happen --- OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs index 697bbe6..adf171e 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs @@ -197,11 +197,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP private void Initialise(UUID fileID, string fileName) { - m_asset = new AssetBase(); - m_asset.FullID = fileID; - m_asset.Type = type; + m_asset = new AssetBase(fileID, fileName, type); m_asset.Data = new byte[0]; - m_asset.Name = fileName; m_asset.Description = "empty"; m_asset.Local = true; m_asset.Temporary = true; -- cgit v1.1 From 6ed57814c1db72463acc3c5fca154a289eee433e Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 5 Nov 2009 23:50:17 -0800 Subject: * Clamp the CoarseLocationUpdate packet at a maximum of 60 positions per packet. This is a limitation of LLUDP, nothing we can really do about it * Marking CoarseLocationUpdate as *not* zerocoded. Zerocoding can only save space when a packet contains three or more contiguous zeroes, and will use more space if it contains single zeroes randomly scattered through the packet (which is what you see when you send a long list of UUIDs) --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 101a44b..35ccad9 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -3196,12 +3196,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (!IsActive) return; // We don't need to update inactive clients. CoarseLocationUpdatePacket loc = (CoarseLocationUpdatePacket)PacketPool.Instance.GetPacket(PacketType.CoarseLocationUpdate); - // TODO: don't create new blocks if recycling an old packet - int total = CoarseLocations.Count; - CoarseLocationUpdatePacket.IndexBlock ib = - new CoarseLocationUpdatePacket.IndexBlock(); + loc.Header.Reliable = false; + + // Each packet can only hold around 62 avatar positions and the client clears the mini-map each time + // a CoarseLocationUpdate packet is received. Oh well. + int total = Math.Min(CoarseLocations.Count, 60); + + CoarseLocationUpdatePacket.IndexBlock ib = new CoarseLocationUpdatePacket.IndexBlock(); + loc.Location = new CoarseLocationUpdatePacket.LocationBlock[total]; loc.AgentData = new CoarseLocationUpdatePacket.AgentDataBlock[total]; + int selfindex = -1; for (int i = 0; i < total; i++) { @@ -3211,18 +3216,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP lb.X = (byte)CoarseLocations[i].X; lb.Y = (byte)CoarseLocations[i].Y; - lb.Z = CoarseLocations[i].Z > 1024 ? (byte)0 : (byte)(CoarseLocations[i].Z * 0.25); + lb.Z = CoarseLocations[i].Z > 1024 ? (byte)0 : (byte)(CoarseLocations[i].Z * 0.25f); loc.Location[i] = lb; loc.AgentData[i] = new CoarseLocationUpdatePacket.AgentDataBlock(); loc.AgentData[i].AgentID = users[i]; if (users[i] == AgentId) selfindex = i; } + ib.You = (short)selfindex; ib.Prey = -1; loc.Index = ib; - loc.Header.Reliable = false; - loc.Header.Zerocoded = true; OutPacket(loc, ThrottleOutPacketType.Task); } -- cgit v1.1 From aff5fe10b0ad95489909f74f9ee2f6bb85f3d338 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 8 Nov 2009 22:29:36 +0000 Subject: test commit with debug output per folder fetch. NOT FOR PRODUCTION, SPEWY --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 35ccad9..06ce79d 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -1255,6 +1255,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP List folders, int version, bool fetchFolders, bool fetchItems) { + m_log.DebugFormat("[CLIENT]: Request folder details for folder {0}", folderID.ToString()); // An inventory descendents packet consists of a single agent section and an inventory details // section for each inventory item. The size of each inventory item is approximately 550 bytes. // In theory, UDP has a maximum packet size of 64k, so it should be possible to send descendent -- cgit v1.1 From f8bcbe5492330bd14ecec76f11e3a33ea4fd6ef6 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 8 Nov 2009 22:39:00 +0000 Subject: remove the debug stuff --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 06ce79d..35ccad9 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -1255,7 +1255,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP List folders, int version, bool fetchFolders, bool fetchItems) { - m_log.DebugFormat("[CLIENT]: Request folder details for folder {0}", folderID.ToString()); // An inventory descendents packet consists of a single agent section and an inventory details // section for each inventory item. The size of each inventory item is approximately 550 bytes. // In theory, UDP has a maximum packet size of 64k, so it should be possible to send descendent -- cgit v1.1 From 1afe5a528ce4c4946841ae874a8bae81b27df291 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 9 Nov 2009 17:09:56 +0000 Subject: minor: remove some mono compiler warnings --- OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs index 552cc4a..d2779ba 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs @@ -270,8 +270,8 @@ namespace OpenMetaverse { try { - UDPPacketBuffer buf = (UDPPacketBuffer)result.AsyncState; - int bytesSent = m_udpSocket.EndSendTo(result); +// UDPPacketBuffer buf = (UDPPacketBuffer)result.AsyncState; + m_udpSocket.EndSendTo(result); } catch (SocketException) { } catch (ObjectDisposedException) { } -- cgit v1.1 From 5145dfa53c2fd8ce0c9ece73ae44f36c9cc70931 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 9 Nov 2009 17:13:56 -0800 Subject: * Removing the redundant SendPrimitiveTerseData.State field, it duplicates AttachPoint * LLClientView.CreateImprovedTerseBlock() now uses AttachPoint and does the proper high-low swap (this should fix disappearing attachment pieces) --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 35ccad9..7eb829e 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -4037,11 +4037,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedTerseBlock(SendPrimitiveTerseData data) { - return CreateImprovedTerseBlock(false, data.LocalID, data.State, Vector4.Zero, data.Position, data.Velocity, + return CreateImprovedTerseBlock(false, data.LocalID, data.AttachPoint, Vector4.Zero, data.Position, data.Velocity, data.Acceleration, data.Rotation, data.AngularVelocity, data.TextureEntry); } - protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedTerseBlock(bool avatar, uint localID, byte state, + protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedTerseBlock(bool avatar, uint localID, int attachPoint, Vector4 collisionPlane, Vector3 position, Vector3 velocity, Vector3 acceleration, Quaternion rotation, Vector3 angularVelocity, byte[] textureEntry) { @@ -4053,7 +4053,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP pos += 4; // Avatar/CollisionPlane - data[pos++] = state; + data[pos++] = (byte)((attachPoint % 16) * 16 + (attachPoint / 16)); ; if (avatar) { data[pos++] = 1; -- cgit v1.1