Misc. cleanup:

* added Util.Clip(value, min, max)
* modified asset cache's numPackets calculation to use max packet size (600) instead of 1000
* removed a few magic numbers
This commit is contained in:
Jeff Ames
2007-12-19 08:44:25 +00:00
parent bd16dddce5
commit 6702b03733
16 changed files with 136 additions and 155 deletions

View File

@@ -36,7 +36,6 @@ using OpenSim.Framework.Console;
namespace OpenSim.Framework.Communications.Cache
{
public delegate void AssetRequestCallback(LLUUID assetID, AssetBase asset);
/// <summary>
@@ -77,7 +76,6 @@ namespace OpenSim.Framework.Communications.Cache
m_assetCacheThread.IsBackground = true;
m_assetCacheThread.Start();
m_log = log;
}
@@ -100,7 +98,6 @@ namespace OpenSim.Framework.Communications.Cache
}
}
public AssetBase GetAsset(LLUUID assetID)
{
AssetBase asset = null;
@@ -154,7 +151,6 @@ namespace OpenSim.Framework.Communications.Cache
}
}
public AssetBase GetAsset(LLUUID assetID, bool isTexture)
{
AssetBase asset = GetAsset(assetID);
@@ -236,8 +232,6 @@ namespace OpenSim.Framework.Communications.Cache
return asset;
}
public void AssetReceived(AssetBase asset, bool IsTexture)
{
if (asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server
@@ -249,7 +243,7 @@ namespace OpenSim.Framework.Communications.Cache
if (IsTexture)
{
//Console.WriteLine("asset recieved from asset server");
//Console.WriteLine("asset received from asset server");
TextureImage image = new TextureImage(asset);
if (!Textures.ContainsKey(image.FullID))
@@ -260,7 +254,7 @@ namespace OpenSim.Framework.Communications.Cache
AssetRequest req = RequestedTextures[image.FullID];
req.ImageInfo = image;
req.NumPackets = CalculateNumPackets(image.Data.Length);
req.NumPackets = CalculateNumPackets(image.Data);
RequestedTextures.Remove(image.FullID);
TextureRequests.Add(req);
@@ -277,15 +271,7 @@ namespace OpenSim.Framework.Communications.Cache
{
AssetRequest req = RequestedAssets[assetInf.FullID];
req.AssetInf = assetInf;
if (assetInf.Data.LongLength > 600)
{
//over 600 bytes so split up file
req.NumPackets = 1 + (int)(assetInf.Data.Length - 600 + 999) / 1000;
}
else
{
req.NumPackets = 1;
}
req.NumPackets = CalculateNumPackets(assetInf.Data);
RequestedAssets.Remove(assetInf.FullID);
AssetRequests.Add(req);
}
@@ -326,16 +312,17 @@ namespace OpenSim.Framework.Communications.Cache
//}
}
private int CalculateNumPackets(int length)
private int CalculateNumPackets(byte[] data)
{
const uint m_maxPacketSize = 600;
int numPackets = 1;
if (length > 600)
if (data.LongLength > m_maxPacketSize)
{
//over 600 bytes so split up file
int restData = (length - 600);
int restPackets = ((restData + 999) / 1000);
numPackets = 1 + restPackets;
// over max number of bytes so split up file
long restData = data.LongLength - m_maxPacketSize;
int restPackets = (int) ((restData + m_maxPacketSize - 1) / m_maxPacketSize);
numPackets += restPackets;
}
return numPackets;
@@ -385,8 +372,7 @@ namespace OpenSim.Framework.Communications.Cache
//it is in our cache
AssetInfo asset = Assets[requestID];
//work out how many packets it should be sent in
// and add to the AssetRequests list
// add to the AssetRequests list
AssetRequest req = new AssetRequest();
req.RequestUser = userInfo;
req.RequestAssetID = requestID;
@@ -394,17 +380,7 @@ namespace OpenSim.Framework.Communications.Cache
req.AssetRequestSource = source;
req.Params = transferRequest.TransferInfo.Params;
req.AssetInf = asset;
if (asset.Data.LongLength > 600)
{
//over 600 bytes so split up file
req.NumPackets = 1 + (int)(asset.Data.Length - 600 + 999) / 1000;
}
else
{
req.NumPackets = 1;
}
req.NumPackets = CalculateNumPackets(asset.Data);
AssetRequests.Add(req);
}
@@ -419,17 +395,9 @@ namespace OpenSim.Framework.Communications.Cache
//no requests waiting
return;
}
int num;
// if less than 5, do all of them
int num = Math.Min(5, AssetRequests.Count);
if (AssetRequests.Count < 5)
{
//lower than 5 so do all of them
num = AssetRequests.Count;
}
else
{
num = 5;
}
AssetRequest req;
for (int i = 0; i < num; i++)
{

View File

@@ -199,7 +199,7 @@ namespace OpenSim.Framework.Data.DB4o
/// </summary>
/// <remarks>Move to inventory server</remarks>
/// <param name="from">Senders account</param>
/// <param name="to">Recievers account</param>
/// <param name="to">Receivers account</param>
/// <param name="item">Inventory item</param>
/// <returns>Success?</returns>
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)

View File

@@ -387,7 +387,7 @@ namespace OpenSim.Framework.Data.MSSQL
/// Performs a money transfer request between two accounts
/// </summary>
/// <param name="from">The senders account ID</param>
/// <param name="to">The recievers account ID</param>
/// <param name="to">The receivers account ID</param>
/// <param name="amount">The amount to transfer</param>
/// <returns>Success?</returns>
public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount)
@@ -400,7 +400,7 @@ namespace OpenSim.Framework.Data.MSSQL
/// </summary>
/// <remarks>TODO: Move to inventory server</remarks>
/// <param name="from">The senders account ID</param>
/// <param name="to">The recievers account ID</param>
/// <param name="to">The receivers account ID</param>
/// <param name="item">The item to transfer</param>
/// <returns>Success?</returns>
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)

View File

@@ -363,7 +363,7 @@ namespace OpenSim.Framework.Data.MySQL
/// Performs a money transfer request between two accounts
/// </summary>
/// <param name="from">The senders account ID</param>
/// <param name="to">The recievers account ID</param>
/// <param name="to">The receivers account ID</param>
/// <param name="amount">The amount to transfer</param>
/// <returns>Success?</returns>
public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount)
@@ -376,7 +376,7 @@ namespace OpenSim.Framework.Data.MySQL
/// </summary>
/// <remarks>TODO: Move to inventory server</remarks>
/// <param name="from">The senders account ID</param>
/// <param name="to">The recievers account ID</param>
/// <param name="to">The receivers account ID</param>
/// <param name="item">The item to transfer</param>
/// <returns>Success?</returns>
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)

View File

@@ -320,7 +320,7 @@ namespace OpenSim.Framework.Data.SQLite
/// </summary>
/// <remarks>Move to inventory server</remarks>
/// <param name="from">Senders account</param>
/// <param name="to">Recievers account</param>
/// <param name="to">Receivers account</param>
/// <param name="item">Inventory item</param>
/// <returns>Success?</returns>
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)

View File

@@ -79,12 +79,12 @@ namespace OpenSim.Framework.Data
List<AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query);
/// <summary>
/// Authenticates a sim by use of it's recv key.
/// Authenticates a sim by use of its recv key.
/// WARNING: Insecure
/// </summary>
/// <param name="UUID">The UUID sent by the sim</param>
/// <param name="regionHandle">The regionhandle sent by the sim</param>
/// <param name="simrecvkey">The recieving key sent by the sim</param>
/// <param name="simrecvkey">The receiving key sent by the sim</param>
/// <returns>Whether the sim has been authenticated</returns>
bool AuthenticateSim(LLUUID UUID, ulong regionHandle, string simrecvkey);

View File

@@ -38,7 +38,7 @@ namespace OpenSim.Framework
/// Suggested implementation
/// <para>Store two digests for each foreign host. A local copy of the local hash using the local challenge (when issued), and a local copy of the remote hash using the remote challenge.</para>
/// <para>When sending data to the foreign host - run 'Sign' on the data and affix the returned byte[] to the message.</para>
/// <para>When recieving data from the foreign host - run 'Authenticate' against the data and the attached byte[].</para>
/// <para>When receiving data from the foreign host - run 'Authenticate' against the data and the attached byte[].</para>
/// <para>Both hosts should be performing these operations for this to be effective.</para>
/// </remarks>
internal class RemoteDigest

View File

@@ -373,5 +373,15 @@ namespace OpenSim.Framework
config.Configs[(string) row[0]].Set(row.Table.Columns[i].ColumnName, row[i]);
}
}
public static float Clip(float x, float min, float max)
{
return Math.Min(Math.Max(x, min), max);
}
public static int Clip(int x, int min, int max)
{
return Math.Min(Math.Max(x, min), max);
}
}
}