A pretty major restructuring of the simian method invocations in order to

service access capabilities. In conjunction with the corresponding Simian
updates, this enables explicit per-simulator capability-based access to
grid services. That enables grid owners to add or revoke access to the grid
on a simulator by simulator basis.
TeleportWork
Mic Bowman 2013-07-31 11:27:35 -07:00
parent 3c540f0d33
commit 64f2dc778a
11 changed files with 583 additions and 287 deletions

View File

@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Reflection;
@ -122,7 +123,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
m_Enabled = true;
}
#region IAssetService
#region IAssetService
public AssetBase Get(string id)
{
@ -140,8 +141,9 @@ namespace OpenSim.Services.Connectors.SimianGrid
return asset;
}
return GetRemote(id);
return SimianGetOperation(id);
}
public AssetBase GetCached(string id)
{
@ -164,8 +166,6 @@ namespace OpenSim.Services.Connectors.SimianGrid
throw new InvalidOperationException();
}
AssetMetadata metadata = null;
// Cache fetch
if (m_cache != null)
{
@ -174,50 +174,18 @@ namespace OpenSim.Services.Connectors.SimianGrid
return asset.Metadata;
}
Uri url;
// Determine if id is an absolute URL or a grid-relative UUID
if (!Uri.TryCreate(id, UriKind.Absolute, out url))
url = new Uri(m_serverUrl + id);
try
{
HttpWebRequest request = UntrustedHttpWebRequest.Create(url);
request.Method = "HEAD";
using (WebResponse response = request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
// Create the metadata object
metadata = new AssetMetadata();
metadata.ContentType = response.ContentType;
metadata.ID = id;
UUID uuid;
if (UUID.TryParse(id, out uuid))
metadata.FullID = uuid;
string lastModifiedStr = response.Headers.Get("Last-Modified");
if (!String.IsNullOrEmpty(lastModifiedStr))
{
DateTime lastModified;
if (DateTime.TryParse(lastModifiedStr, out lastModified))
metadata.CreationDate = lastModified;
}
}
}
}
catch (Exception ex)
{
m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset HEAD from " + url + " failed: " + ex.Message);
}
return metadata;
// return GetRemoteMetadata(id);
return SimianGetMetadataOperation(id);
}
public byte[] GetData(string id)
{
if (String.IsNullOrEmpty(m_serverUrl))
{
m_log.Error("[SIMIAN ASSET CONNECTOR]: No AssetServerURI configured");
throw new InvalidOperationException();
}
AssetBase asset = Get(id);
if (asset != null)
@ -255,7 +223,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
Util.FireAndForget(
delegate(object o)
{
AssetBase asset = GetRemote(id);
AssetBase asset = SimianGetOperation(id);
handler(id, sender, asset);
}
);
@ -278,7 +246,6 @@ namespace OpenSim.Services.Connectors.SimianGrid
}
bool storedInCache = false;
string errorMessage = null;
// AssetID handling
if (String.IsNullOrEmpty(asset.ID) || asset.ID == ZeroID)
@ -307,83 +274,9 @@ namespace OpenSim.Services.Connectors.SimianGrid
return asset.ID;
}
// Distinguish public and private assets
bool isPublic = true;
switch ((AssetType)asset.Type)
{
case AssetType.CallingCard:
case AssetType.Gesture:
case AssetType.LSLBytecode:
case AssetType.LSLText:
isPublic = false;
break;
}
// Make sure ContentType is set
if (String.IsNullOrEmpty(asset.Metadata.ContentType))
asset.Metadata.ContentType = SLUtil.SLAssetTypeToContentType(asset.Type);
// Build the remote storage request
List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>()
{
new MultipartForm.Parameter("AssetID", asset.FullID.ToString()),
new MultipartForm.Parameter("CreatorID", asset.Metadata.CreatorID),
new MultipartForm.Parameter("Temporary", asset.Temporary ? "1" : "0"),
new MultipartForm.Parameter("Public", isPublic ? "1" : "0"),
new MultipartForm.File("Asset", asset.Name, asset.Metadata.ContentType, asset.Data)
};
// Make the remote storage request
try
{
// Simian does not require the asset ID to be in the URL because it's in the post data.
// By appending it to the URL also, we allow caching proxies (squid) to invalidate asset URLs
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl + asset.FullID.ToString());
using (HttpWebResponse response = MultipartForm.Post(request, postParameters))
{
using (Stream responseStream = response.GetResponseStream())
{
string responseStr = null;
try
{
responseStr = responseStream.GetStreamString();
OSD responseOSD = OSDParser.Deserialize(responseStr);
if (responseOSD.Type == OSDType.Map)
{
OSDMap responseMap = (OSDMap)responseOSD;
if (responseMap["Success"].AsBoolean())
return asset.ID;
else
errorMessage = "Upload failed: " + responseMap["Message"].AsString();
}
else
{
errorMessage = "Response format was invalid:\n" + responseStr;
}
}
catch (Exception ex)
{
if (!String.IsNullOrEmpty(responseStr))
errorMessage = "Failed to parse the response:\n" + responseStr;
else
errorMessage = "Failed to retrieve the response: " + ex.Message;
}
}
}
}
catch (WebException ex)
{
errorMessage = ex.Message;
}
m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to store asset \"{0}\" ({1}, {2}): {3}",
asset.Name, asset.ID, asset.Metadata.ContentType, errorMessage);
return null;
return SimianStoreOperation(asset);
}
/// <summary>
/// Update an asset's content
/// </summary>
@ -393,11 +286,17 @@ namespace OpenSim.Services.Connectors.SimianGrid
/// <returns></returns>
public bool UpdateContent(string id, byte[] data)
{
if (String.IsNullOrEmpty(m_serverUrl))
{
m_log.Error("[SIMIAN ASSET CONNECTOR]: No AssetServerURI configured");
throw new InvalidOperationException();
}
AssetBase asset = Get(id);
if (asset == null)
{
m_log.Warn("[SIMIAN ASSET CONNECTOR]: Failed to fetch asset " + id + " for updating");
m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to fetch asset {0} for updating", id);
return false;
}
@ -420,83 +319,347 @@ namespace OpenSim.Services.Connectors.SimianGrid
throw new InvalidOperationException();
}
//string errorMessage = String.Empty;
string url = m_serverUrl + id;
if (m_cache != null)
m_cache.Expire(id);
return SimianDeleteOperation(id);
}
#endregion IAssetService
#region SimianOperations
/// <summary>
/// Invokes the xRemoveAsset operation on the simian server to delete an asset
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
private bool SimianDeleteOperation(string id)
{
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "DELETE";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
if (response.StatusCode != HttpStatusCode.NoContent)
NameValueCollection requestArgs = new NameValueCollection
{
m_log.Warn("[SIMIAN ASSET CONNECTOR]: Unexpected response when deleting asset " + url + ": " +
response.StatusCode + " (" + response.StatusDescription + ")");
}
}
{ "RequestMethod", "xRemoveAsset" },
{ "AssetID", id }
};
OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs);
if (! response["Success"].AsBoolean())
{
m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: failed to delete asset; {0}",response["Message"].AsString());
return false;
}
return true;
}
catch (Exception ex)
{
m_log.Warn("[SIMIAN ASSET CONNECTOR]: Failed to delete asset " + id + " from the asset service: " + ex.Message);
return false;
m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: failed to delete asset {0}; {1}", id, ex.Message);
}
return false;
}
#endregion IAssetService
private AssetBase GetRemote(string id)
/// <summary>
/// Invokes the xAddAsset operation on the simian server to create or update an asset
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
private string SimianStoreOperation(AssetBase asset)
{
AssetBase asset = null;
Uri url;
// Determine if id is an absolute URL or a grid-relative UUID
if (!Uri.TryCreate(id, UriKind.Absolute, out url))
url = new Uri(m_serverUrl + id);
try
{
HttpWebRequest request = UntrustedHttpWebRequest.Create(url);
using (WebResponse response = request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
NameValueCollection requestArgs = new NameValueCollection
{
string creatorID = response.Headers.GetOne("X-Asset-Creator-Id") ?? String.Empty;
// Create the asset object
asset = new AssetBase(id, String.Empty, SLUtil.ContentTypeToSLAssetType(response.ContentType), creatorID);
UUID assetID;
if (UUID.TryParse(id, out assetID))
asset.FullID = assetID;
// Grab the asset data from the response stream
using (MemoryStream stream = new MemoryStream())
{
responseStream.CopyStream(stream, Int32.MaxValue);
asset.Data = stream.ToArray();
}
}
{ "RequestMethod", "xAddAsset" },
{ "ContentType", asset.Metadata.ContentType },
{ "EncodedData", Convert.ToBase64String(asset.Data) },
{ "AssetID", asset.FullID.ToString() },
{ "CreatorID", asset.Metadata.CreatorID },
{ "Temporary", asset.Temporary ? "1" : "0" },
{ "Name", asset.Name }
};
OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs);
if (! response["Success"].AsBoolean())
{
m_log.WarnFormat("[SIMIAN ASSET CONNECTOR] failed to store asset; {0}",response["Message"].AsString());
return null;
}
// Cache store
if (m_cache != null && asset != null)
m_cache.Cache(asset);
// asset.ID is always set before calling this function
return asset.ID;
}
catch (Exception ex)
{
m_log.ErrorFormat("[SIMIAN ASSET CONNECTOR] failed to store asset; {0}",ex.Message);
}
return null;
}
/// <summary>
/// Invokes the xGetAsset operation on the simian server to get data associated with an asset
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
private AssetBase SimianGetOperation(string id)
{
try
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "xGetAsset" },
{ "ID", id }
};
OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs);
if (! response["Success"].AsBoolean())
{
m_log.WarnFormat("[SIMIAN ASSET CONNECTOR] Failed to get asset; {0}",response["Message"].AsString());
return null;
}
AssetBase asset = new AssetBase();
asset.ID = id;
asset.Name = String.Empty;
asset.Metadata.ContentType = response["ContentType"].AsString(); // this will also set the asset Type property
asset.CreatorID = response["CreatorID"].AsString();
asset.Data = System.Convert.FromBase64String(response["EncodedData"].AsString());
asset.Local = false;
asset.Temporary = response["Temporary"];
return asset;
}
catch (Exception ex)
{
m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset GET from " + url + " failed: " + ex.Message);
return null;
m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: failed to retrieve asset {0}; {1}", id, ex.Message);
}
return null;
}
/// <summary>
/// Invokes the xGetAssetMetadata operation on the simian server to retrieve metadata for an asset
/// This operation is generally used to determine if an asset exists in the database
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
private AssetMetadata SimianGetMetadataOperation(string id)
{
try
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "xGetAssetMetadata" },
{ "ID", id }
};
OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs);
if (! response["Success"].AsBoolean())
{
// this is not really an error, this call is used to test existence
// m_log.DebugFormat("[SIMIAN ASSET CONNECTOR] Failed to get asset metadata; {0}",response["Message"].AsString());
return null;
}
AssetMetadata metadata = new AssetMetadata();
metadata.ID = id;
metadata.ContentType = response["ContentType"].AsString();
metadata.CreatorID = response["CreatorID"].AsString();
metadata.Local = false;
metadata.Temporary = response["Temporary"];
string lastModifiedStr = response["Last-Modified"].AsString();
if (! String.IsNullOrEmpty(lastModifiedStr))
{
DateTime lastModified;
if (DateTime.TryParse(lastModifiedStr, out lastModified))
metadata.CreationDate = lastModified;
}
return metadata;
}
catch (Exception ex)
{
m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to get asset metadata; {0}", ex.Message);
}
return null;
}
#endregion
// private AssetMetadata GetRemoteMetadata(string id)
// {
// Uri url;
// AssetMetadata metadata = null;
// // Determine if id is an absolute URL or a grid-relative UUID
// if (!Uri.TryCreate(id, UriKind.Absolute, out url))
// url = new Uri(m_serverUrl + id);
// try
// {
// HttpWebRequest request = UntrustedHttpWebRequest.Create(url);
// request.Method = "HEAD";
// using (WebResponse response = request.GetResponse())
// {
// using (Stream responseStream = response.GetResponseStream())
// {
// // Create the metadata object
// metadata = new AssetMetadata();
// metadata.ContentType = response.ContentType;
// metadata.ID = id;
// UUID uuid;
// if (UUID.TryParse(id, out uuid))
// metadata.FullID = uuid;
// string lastModifiedStr = response.Headers.Get("Last-Modified");
// if (!String.IsNullOrEmpty(lastModifiedStr))
// {
// DateTime lastModified;
// if (DateTime.TryParse(lastModifiedStr, out lastModified))
// metadata.CreationDate = lastModified;
// }
// }
// }
// }
// catch (Exception ex)
// {
// m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset HEAD from " + url + " failed: " + ex.Message);
// }
// return metadata;
// }
// private AssetBase GetRemote(string id)
// {
// AssetBase asset = null;
// Uri url;
// // Determine if id is an absolute URL or a grid-relative UUID
// if (!Uri.TryCreate(id, UriKind.Absolute, out url))
// url = new Uri(m_serverUrl + id);
// try
// {
// HttpWebRequest request = UntrustedHttpWebRequest.Create(url);
// using (WebResponse response = request.GetResponse())
// {
// using (Stream responseStream = response.GetResponseStream())
// {
// string creatorID = response.Headers.GetOne("X-Asset-Creator-Id") ?? String.Empty;
// // Create the asset object
// asset = new AssetBase(id, String.Empty, SLUtil.ContentTypeToSLAssetType(response.ContentType), creatorID);
// UUID assetID;
// if (UUID.TryParse(id, out assetID))
// asset.FullID = assetID;
// // Grab the asset data from the response stream
// using (MemoryStream stream = new MemoryStream())
// {
// responseStream.CopyStream(stream, Int32.MaxValue);
// asset.Data = stream.ToArray();
// }
// }
// }
// // Cache store
// if (m_cache != null && asset != null)
// m_cache.Cache(asset);
// return asset;
// }
// catch (Exception ex)
// {
// m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset GET from " + url + " failed: " + ex.Message);
// return null;
// }
// }
// private string StoreRemote(AssetBase asset)
// {
// // Distinguish public and private assets
// bool isPublic = true;
// switch ((AssetType)asset.Type)
// {
// case AssetType.CallingCard:
// case AssetType.Gesture:
// case AssetType.LSLBytecode:
// case AssetType.LSLText:
// isPublic = false;
// break;
// }
// string errorMessage = null;
// // Build the remote storage request
// List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>()
// {
// new MultipartForm.Parameter("AssetID", asset.FullID.ToString()),
// new MultipartForm.Parameter("CreatorID", asset.Metadata.CreatorID),
// new MultipartForm.Parameter("Temporary", asset.Temporary ? "1" : "0"),
// new MultipartForm.Parameter("Public", isPublic ? "1" : "0"),
// new MultipartForm.File("Asset", asset.Name, asset.Metadata.ContentType, asset.Data)
// };
// // Make the remote storage request
// try
// {
// // Simian does not require the asset ID to be in the URL because it's in the post data.
// // By appending it to the URL also, we allow caching proxies (squid) to invalidate asset URLs
// HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl + asset.FullID.ToString());
// using (HttpWebResponse response = MultipartForm.Post(request, postParameters))
// {
// using (Stream responseStream = response.GetResponseStream())
// {
// string responseStr = null;
// try
// {
// responseStr = responseStream.GetStreamString();
// OSD responseOSD = OSDParser.Deserialize(responseStr);
// if (responseOSD.Type == OSDType.Map)
// {
// OSDMap responseMap = (OSDMap)responseOSD;
// if (responseMap["Success"].AsBoolean())
// return asset.ID;
// else
// errorMessage = "Upload failed: " + responseMap["Message"].AsString();
// }
// else
// {
// errorMessage = "Response format was invalid:\n" + responseStr;
// }
// }
// catch (Exception ex)
// {
// if (!String.IsNullOrEmpty(responseStr))
// errorMessage = "Failed to parse the response:\n" + responseStr;
// else
// errorMessage = "Failed to retrieve the response: " + ex.Message;
// }
// }
// }
// }
// catch (WebException ex)
// {
// errorMessage = ex.Message;
// }
// m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to store asset \"{0}\" ({1}, {2}): {3}",
// asset.Name, asset.ID, asset.Metadata.ContentType, errorMessage);
// return null;
// }
}
}

View File

@ -110,7 +110,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserID", principalID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Identities"] is OSDArray)
{
bool md5hashFound = false;
@ -153,7 +153,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "SessionID", token }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
return true;
@ -175,7 +175,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserID", principalID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
return true;
@ -198,7 +198,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserID", principalID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["User"] is OSDMap)
{
OSDMap userMap = (OSDMap)response["User"];
@ -218,7 +218,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserID", principalID.ToString() }
};
response = WebUtil.PostToService(m_serverUrl, requestArgs);
response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -297,7 +297,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
return response["SessionID"].AsUUID().ToString();
else

View File

@ -122,7 +122,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDMap map = null;
@ -168,7 +168,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "LLPackedAppearance", OSDParser.SerializeJsonString(map) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (! success)
@ -189,7 +189,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDMap map = null;
@ -306,7 +306,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "LLAttachments", OSDParser.SerializeJsonString(items) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)

View File

@ -153,7 +153,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "Value", flags.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -180,7 +180,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "Key", friend }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -200,7 +200,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "Type", "Friend" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Entries"] is OSDArray)
{
return (OSDArray)response["Entries"];
@ -221,7 +221,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "Type", "Friend" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Entries"] is OSDArray)
{
return (OSDArray)response["Entries"];

View File

@ -26,8 +26,122 @@
*/
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
[assembly: Addin("SimianGrid", "1.0")]
[assembly: AddinDependency("OpenSim", "0.5")]
namespace OpenSim.Services.Connectors.SimianGrid
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SimianExternalCapsModule")]
public class SimianGrid : ISharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IConfig m_config = null;
private bool m_enabled = true;
private String m_simianURL;
#region IRegionModule Members
public string Name
{
get { return this.GetType().Name; }
}
public void Initialise(IConfigSource config)
{
try
{
m_config = config.Configs["SimianGrid"];
if (m_config != null)
{
m_simianURL = m_config.GetString("SimianServiceURL");
if (String.IsNullOrEmpty(m_simianURL))
m_log.ErrorFormat("[SimianGrid] service URL is not defined");
InitialiseSimCap();
SimulatorCapability = SimulatorCapability.Trim();
m_log.WarnFormat("[SimianExternalCaps] using {0} as simulator capability",SimulatorCapability);
}
}
catch (Exception e)
{
m_log.ErrorFormat("[SimianExternalCaps] initialization error: {0}",e.Message);
return;
}
}
public void PostInitialise() { }
public void Close() { }
public void AddRegion(Scene scene) { }
public void RemoveRegion(Scene scene) { }
public void RegionLoaded(Scene scene) { }
public Type ReplaceableInterface
{
get { return null; }
}
///<summary>
/// Try a variety of methods for finding the simian simulator capability; first check the
/// configuration itself, then look for a file that contains the cap, then finally look
/// for an environment variable that contains it.
///</summary>
private void InitialiseSimCap()
{
if (m_config.Contains("SimulatorCapability"))
{
SimulatorCapability = m_config.GetString("SimulatorCapability");
return;
}
if (m_config.Contains("SimulatorCapabilityFile"))
{
String filename = m_config.GetString("SimulatorCapabilityFile");
if (System.IO.File.Exists(filename))
{
SimulatorCapability = System.IO.File.ReadAllText(filename);
return;
}
}
if (m_config.Contains("SimulatorCapabilityVariable"))
{
String envname = m_config.GetString("SimulatorCapabilityVariable");
String envvalue = System.Environment.GetEnvironmentVariable(envname);
if (envvalue != null)
{
SimulatorCapability = envvalue;
return;
}
}
m_log.WarnFormat("[SimianExternalCaps] no method specified for simulator capability");
}
#endregion
public static String SimulatorCapability = UUID.Zero.ToString();
public static OSDMap PostToService(string url, NameValueCollection data)
{
data["cap"] = SimulatorCapability;
return WebUtil.PostToService(url, data);
}
}
}

View File

@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using System.Net;
using System.IO;
@ -43,7 +44,8 @@ using OpenSim.Region.Framework.Scenes;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
namespace OpenSim.Region.OptionalModules.Simian
//namespace OpenSim.Region.OptionalModules.Simian
namespace OpenSim.Services.Connectors.SimianGrid
{
/// <summary>
/// </summary>
@ -196,67 +198,84 @@ namespace OpenSim.Region.OptionalModules.Simian
}
}
List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>()
{
new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()),
new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()),
new MultipartForm.File("Tile", "tile.png", "image/png", pngData)
};
string errorMessage = null;
int tickstart = Util.EnvironmentTickCount();
// Make the remote storage request
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl);
request.Timeout = 20000;
request.ReadWriteTimeout = 5000;
using (HttpWebResponse response = MultipartForm.Post(request, postParameters))
NameValueCollection requestArgs = new NameValueCollection
{
using (Stream responseStream = response.GetResponseStream())
{
string responseStr = responseStream.GetStreamString();
OSD responseOSD = OSDParser.Deserialize(responseStr);
if (responseOSD.Type == OSDType.Map)
{
OSDMap responseMap = (OSDMap)responseOSD;
if (responseMap["Success"].AsBoolean())
return;
errorMessage = "Upload failed: " + responseMap["Message"].AsString();
}
else
{
errorMessage = "Response format was invalid:\n" + responseStr;
}
}
}
}
catch (WebException we)
{ "RequestMethod", "xAddMapTile" },
{ "X", scene.RegionInfo.RegionLocX.ToString() },
{ "Y", scene.RegionInfo.RegionLocY.ToString() },
{ "ContentType", "image/png" },
{ "EncodedData", System.Convert.ToBase64String(pngData) }
};
OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs);
if (! response["Success"].AsBoolean())
{
errorMessage = we.Message;
if (we.Status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse webResponse = (HttpWebResponse)we.Response;
errorMessage = String.Format("[{0}] {1}",
webResponse.StatusCode,webResponse.StatusDescription);
}
}
catch (Exception ex)
{
errorMessage = ex.Message;
}
finally
{
// This just dumps a warning for any operation that takes more than 100 ms
int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
m_log.DebugFormat("[SIMIAN MAPTILE]: map tile uploaded in {0}ms",tickdiff);
m_log.WarnFormat("[SIMIAN MAPTILE] failed to store map tile; {0}",response["Message"].AsString());
return;
}
m_log.WarnFormat("[SIMIAN MAPTILE]: Failed to store {0} byte tile for {1}: {2}",
pngData.Length, scene.RegionInfo.RegionName, errorMessage);
// List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>()
// {
// new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()),
// new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()),
// new MultipartForm.File("Tile", "tile.png", "image/png", pngData)
// };
// string errorMessage = null;
// int tickstart = Util.EnvironmentTickCount();
// // Make the remote storage request
// try
// {
// HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl);
// request.Timeout = 20000;
// request.ReadWriteTimeout = 5000;
// using (HttpWebResponse response = MultipartForm.Post(request, postParameters))
// {
// using (Stream responseStream = response.GetResponseStream())
// {
// string responseStr = responseStream.GetStreamString();
// OSD responseOSD = OSDParser.Deserialize(responseStr);
// if (responseOSD.Type == OSDType.Map)
// {
// OSDMap responseMap = (OSDMap)responseOSD;
// if (responseMap["Success"].AsBoolean())
// return;
// errorMessage = "Upload failed: " + responseMap["Message"].AsString();
// }
// else
// {
// errorMessage = "Response format was invalid:\n" + responseStr;
// }
// }
// }
// }
// catch (WebException we)
// {
// errorMessage = we.Message;
// if (we.Status == WebExceptionStatus.ProtocolError)
// {
// HttpWebResponse webResponse = (HttpWebResponse)we.Response;
// errorMessage = String.Format("[{0}] {1}",
// webResponse.StatusCode,webResponse.StatusDescription);
// }
// }
// catch (Exception ex)
// {
// errorMessage = ex.Message;
// }
// finally
// {
// // This just dumps a warning for any operation that takes more than 100 ms
// int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
// m_log.DebugFormat("[SIMIAN MAPTILE]: map tile uploaded in {0}ms",tickdiff);
// }
// m_log.WarnFormat("[SIMIAN MAPTILE]: Failed to store {0} byte tile for {1}: {2}",
// pngData.Length, scene.RegionInfo.RegionName, errorMessage);
}
}
}

View File

@ -129,7 +129,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "ExtraData", OSDParser.SerializeJsonString(extraData) }
};
OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs);
OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
if (response["Success"].AsBoolean())
return String.Empty;
else
@ -145,7 +145,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "Enabled", "0" }
};
OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs);
OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -192,7 +192,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
// m_log.DebugFormat("[SIMIAN GRID CONNECTOR] request region with uuid {0}",regionID.ToString());
OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs);
OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
if (response["Success"].AsBoolean())
{
// m_log.DebugFormat("[SIMIAN GRID CONNECTOR] uuid request successful {0}",response["Name"].AsString());
@ -220,7 +220,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
// m_log.DebugFormat("[SIMIAN GRID CONNECTOR] request grid at {0}",position.ToString());
OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs);
OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
if (response["Success"].AsBoolean())
{
// m_log.DebugFormat("[SIMIAN GRID CONNECTOR] position request successful {0}",response["Name"].AsString());
@ -261,7 +261,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
// m_log.DebugFormat("[SIMIAN GRID CONNECTOR] request regions with name {0}",name);
OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs);
OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
if (response["Success"].AsBoolean())
{
// m_log.DebugFormat("[SIMIAN GRID CONNECTOR] found regions with name {0}",name);
@ -299,7 +299,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
//m_log.DebugFormat("[SIMIAN GRID CONNECTOR] request regions by range {0} to {1}",minPosition.ToString(),maxPosition.ToString());
OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs);
OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
if (response["Success"].AsBoolean())
{
OSDArray array = response["Scenes"] as OSDArray;
@ -350,7 +350,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "Enabled", "1" }
};
OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs);
OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
if (response["Success"].AsBoolean())
{
// m_log.DebugFormat("[SIMIAN GRID CONNECTOR] found regions with name {0}",name);
@ -380,7 +380,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
m_log.DebugFormat("[SIMIAN GRID CONNECTOR] request region flags for {0}",regionID.ToString());
OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs);
OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
if (response["Success"].AsBoolean())
{
OSDMap extraData = response["ExtraData"] as OSDMap;
@ -410,7 +410,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
if (onlyEnabled)
requestArgs["Enabled"] = "1";
OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs);
OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
if (response["Success"].AsBoolean())
{
return ResponseToGridRegion(response);

View File

@ -156,7 +156,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "OwnerID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -182,7 +182,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "ChildrenOnly", "0" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
OSDArray items = (OSDArray)response["Items"];
@ -244,7 +244,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "ChildrenOnly", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
OSDArray items = (OSDArray)response["Items"];
@ -274,7 +274,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "OwnerID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Folder"] is OSDMap)
{
OSDMap folder = (OSDMap)response["Folder"];
@ -312,7 +312,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "ChildrenOnly", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
List<InventoryItemBase> items = GetItemsFromResponse((OSDArray)response["Items"]);
@ -349,7 +349,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "ChildrenOnly", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
OSDArray items = (OSDArray)response["Items"];
@ -383,7 +383,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "ChildrenOnly", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
OSDArray items = (OSDArray)response["Items"];
@ -423,7 +423,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "ChildrenOnly", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
OSDArray items = (OSDArray)response["Items"];
@ -454,7 +454,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "ContentType", SLUtil.SLAssetTypeToContentType(folder.Type) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -518,7 +518,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "ItemID", itemID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -546,7 +546,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "FolderID", folder.ID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -623,7 +623,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "ExtraData", OSDParser.SerializeJsonString(extraData) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -847,7 +847,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "Items", String.Join(",", itemIDs) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -885,7 +885,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_userServerUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_userServerUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDMap user = response["User"] as OSDMap;
@ -916,7 +916,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "Gestures", OSDParser.SerializeJsonString(gestures) }
};
OSDMap response = WebUtil.PostToService(m_userServerUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_userServerUrl, requestArgs);
if (!response["Success"].AsBoolean())
{
m_log.Warn("[SIMIAN INVENTORY CONNECTOR]: Failed to save active gestures for " + userID + ": " +

View File

@ -149,7 +149,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
requestArgs["SecureSessionID"] = secureSessionID.ToString();
}
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -168,7 +168,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "SessionID", sessionID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -187,7 +187,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "SceneID", regionID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -232,7 +232,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserIDList", String.Join(",",userIDs) }
};
OSDMap sessionListResponse = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap sessionListResponse = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (! sessionListResponse["Success"].AsBoolean())
{
m_log.WarnFormat("[SIMIAN PRESENCE CONNECTOR]: Failed to retrieve sessions: {0}",sessionListResponse["Message"].AsString());
@ -275,7 +275,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "LastLocation", SerializeLocation(regionID, lastPosition, lastLookAt) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -295,7 +295,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "HomeLocation", SerializeLocation(regionID, position, lookAt) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -340,7 +340,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["User"] is OSDMap)
return response;
@ -356,7 +356,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "SessionID", sessionID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
return response;
@ -376,7 +376,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "SceneLookAt", lastLookAt.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)

View File

@ -392,7 +392,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserID", client.AgentId.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
string email = response["Email"].AsString();
if (!response["Success"].AsBoolean())
@ -443,7 +443,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ key, OSDParser.SerializeJsonString(value) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
@ -462,7 +462,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["User"] is OSDMap)
{
return (OSDMap)response["User"];

View File

@ -165,7 +165,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "NameQuery", query }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDArray array = response["Users"] as OSDArray;
@ -204,7 +204,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "AccessLevel", data.UserLevel.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
@ -219,7 +219,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
{ "UserTitle", data.UserTitle }
};
response = WebUtil.PostToService(m_serverUrl, requestArgs);
response = SimianGrid.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (success)
@ -252,7 +252,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
string lookupValue = (requestArgs.Count > 1) ? requestArgs[1] : "(Unknown)";
// m_log.DebugFormat("[SIMIAN ACCOUNT CONNECTOR]: Looking up user account with query: " + lookupValue);
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDMap user = response["User"] as OSDMap;