* Extracted RegionProfileData from Request

* Introduced ValidateNewRegion and ValidateOverwrite
0.6.0-stable
lbsa71 2008-03-12 09:17:23 +00:00
parent da854b9691
commit 47ed69c933
2 changed files with 143 additions and 133 deletions

View File

@ -51,7 +51,7 @@ namespace OpenSim.Grid.GridServer
// This is here so that the grid server can hand out MessageServer settings to regions on registration // This is here so that the grid server can hand out MessageServer settings to regions on registration
private List<MessageServerInfo> _MessageServers = new List<MessageServerInfo>(); private List<MessageServerInfo> _MessageServers = new List<MessageServerInfo>();
public GridConfig config; public GridConfig Config;
/// <summary> /// <summary>
/// Adds a new grid server plugin - grid servers will be requested in the order they were loaded. /// Adds a new grid server plugin - grid servers will be requested in the order they were loaded.
@ -223,6 +223,22 @@ namespace OpenSim.Grid.GridServer
return response; return response;
} }
protected virtual bool ValidateOverwrite(RegionProfileData sim, RegionProfileData existingSim)
{
bool validated;
validated = (existingSim.regionRecvKey == sim.regionRecvKey &&
existingSim.regionSendKey == sim.regionSendKey);
return validated;
}
protected virtual bool ValidateNewRegion(RegionProfileData sim)
{
bool validated;
validated = (sim.regionRecvKey == Config.SimSendKey &&
sim.regionSendKey == Config.SimRecvKey);
return validated;
}
/// <summary> /// <summary>
/// Performed when a region connects to the grid server initially. /// Performed when a region connects to the grid server initially.
/// </summary> /// </summary>
@ -238,11 +254,11 @@ namespace OpenSim.Grid.GridServer
RegionProfileData existingSim; RegionProfileData existingSim;
Hashtable requestData = (Hashtable)request.Params[0]; Hashtable requestData = (Hashtable)request.Params[0];
string myword;
LLUUID uuid; LLUUID uuid;
if (requestData.ContainsKey("UUID") && LLUUID.TryParse((string)requestData["UUID"], out uuid)) if (requestData.ContainsKey("UUID") && LLUUID.TryParse((string)requestData["UUID"], out uuid))
{ {
sim = getRegion(uuid); existingSim = getRegion(uuid);
} }
else else
{ {
@ -251,105 +267,34 @@ namespace OpenSim.Grid.GridServer
return response; return response;
} }
if (sim == null) // Shouldnt this be in the REST Simulator Set method? try
{ {
m_log.Info("[GRID]: New region connecting"); sim = RegionFromRequest(requestData);
myword = "creation"; }
catch (FormatException e)
{
m_log.Info("[GRID]: Invalid login parameters, ignoring.");
responseData["error"] = "Wrong format in login parameters. Please verify parameters.";
return response;
}
existingSim = getRegion(sim.regionHandle);
if (existingSim == null || existingSim.UUID == sim.UUID || sim.UUID != sim.originUUID)
{
bool validated;
if (existingSim == null)
{
validated = ValidateNewRegion(sim);
} }
else else
{ {
myword = "connection"; validated = ValidateOverwrite(sim, existingSim);
} }
sim = new RegionProfileData(); if (validated)
sim.regionRecvKey = String.Empty;
sim.regionSendKey = String.Empty;
sim.regionSecret = config.SimRecvKey;
sim.regionDataURI = String.Empty;
sim.regionAssetURI = config.DefaultAssetServer;
sim.regionAssetRecvKey = config.AssetRecvKey;
sim.regionAssetSendKey = config.AssetSendKey;
sim.regionUserURI = config.DefaultUserServer;
sim.regionUserSendKey = config.UserSendKey;
sim.regionUserRecvKey = config.UserRecvKey;
try
{ {
sim.serverIP = (string)requestData["sim_ip"];
sim.serverPort = Convert.ToUInt32((string)requestData["sim_port"]);
sim.httpPort = Convert.ToUInt32((string)requestData["http_port"]);
sim.remotingPort = Convert.ToUInt32((string)requestData["remoting_port"]);
sim.regionLocX = Convert.ToUInt32((string)requestData["region_locx"]);
sim.regionLocY = Convert.ToUInt32((string)requestData["region_locy"]);
sim.regionLocZ = 0;
}
catch (FormatException)
{
m_log.Info("[GRID]: invalid login parameters, ignoring.");
responseData["error"] = "Wrong format in login parameters. Please verify them.";
return response;
}
LLUUID textureID = LLUUID.Zero;
if (LLUUID.TryParse((string)requestData["map-image-id"], out textureID))
sim.regionMapTextureID = textureID;
// part of an initial brutish effort to provide accurate information (as per the xml region spec)
// wrt the ownership of a given region
// the (very bad) assumption is that this value is being read and handled inconsistently or
// not at all. Current strategy is to put the code in place to support the validity of this information
// and to roll forward debugging any issues from that point
//
// this particular section of the mod attempts to receive a value from the region's xml file by way of
// OSG1GridServices for the region's owner
sim.owner_uuid = (string)requestData["master_avatar_uuid"];
try
{
sim.regionRecvKey = (string)requestData["recvkey"];
sim.regionSendKey = (string)requestData["authkey"];
}
catch (KeyNotFoundException) { }
sim.regionHandle = Helpers.UIntsToLong((sim.regionLocX * Constants.RegionSize), (sim.regionLocY * Constants.RegionSize));
sim.serverURI = (string)requestData["server_uri"];
Console.WriteLine("adding region " + sim.regionLocX + " , " + sim.regionLocY + " , " +
sim.serverURI);
sim.httpServerURI = "http://" + sim.serverIP + ":" + sim.httpPort + "/";
sim.regionName = (string)requestData["sim_name"];
sim.UUID = new LLUUID((string)requestData["UUID"]);
sim.originUUID = new LLUUID((string) requestData["originUUID"]);
//make sure there is not an existing region at this location
existingSim = getRegion(sim.regionHandle);
//if (OldSim == null || OldSim.UUID == TheSim.UUID)
if (existingSim == null || existingSim.UUID == sim.UUID || sim.UUID != sim.originUUID)
{
bool brandNew = ( existingSim == null && sim.regionRecvKey == config.SimSendKey &&
sim.regionSendKey == config.SimRecvKey);
bool overwritingOldOne = ( existingSim != null && existingSim.regionRecvKey == sim.regionRecvKey &&
existingSim.regionSendKey == sim.regionSendKey );
if (brandNew)
{
m_log.Info("[GRID]: Adding region " + sim.regionLocX + " , " + sim.regionLocY + " , " +
sim.serverURI);
}
if (overwritingOldOne)
{
m_log.Info("[GRID]: Overwriting region " + existingSim.regionLocX + " , " + existingSim.regionLocY + " , " +
existingSim.serverURI + " with " + sim.regionLocX + " , " + sim.regionLocY + " , " +
sim.serverURI);
}
if (brandNew ||
overwritingOldOne)
{
foreach (KeyValuePair<string, IGridData> kvp in _plugins) foreach (KeyValuePair<string, IGridData> kvp in _plugins)
{ {
try try
@ -358,7 +303,7 @@ namespace OpenSim.Grid.GridServer
switch (insertResponse) switch (insertResponse)
{ {
case DataResponse.RESPONSE_OK: case DataResponse.RESPONSE_OK:
m_log.Info("[grid]: New sim " + myword + " successful: " + sim.regionName); m_log.Info("[grid]: New sim " + (existingSim == null ? "creation" : "connection") + " successful: " + sim.regionName);
break; break;
case DataResponse.RESPONSE_ERROR: case DataResponse.RESPONSE_ERROR:
m_log.Warn("[storage]: New sim creation failed (Error): " + sim.regionName); m_log.Warn("[storage]: New sim creation failed (Error): " + sim.regionName);
@ -468,7 +413,7 @@ namespace OpenSim.Grid.GridServer
// New! If set, use as URL to local sim storage (ie http://remotehost/region.yap) // New! If set, use as URL to local sim storage (ie http://remotehost/region.yap)
responseData["data_uri"] = sim.regionDataURI; responseData["data_uri"] = sim.regionDataURI;
responseData["allow_forceful_banlines"] = config.AllowForcefulBanlines; responseData["allow_forceful_banlines"] = Config.AllowForcefulBanlines;
// Instead of sending a multitude of message servers to the registering sim // Instead of sending a multitude of message servers to the registering sim
// we should probably be sending a single one and parhaps it's backup // we should probably be sending a single one and parhaps it's backup
@ -492,7 +437,7 @@ namespace OpenSim.Grid.GridServer
{ {
m_log.Warn("[grid]: Authentication failed when trying to add new region " + sim.regionName + m_log.Warn("[grid]: Authentication failed when trying to add new region " + sim.regionName +
" at location " + sim.regionLocX + " at location " + sim.regionLocX +
" " + sim.regionLocY + " with TheSim.regionRecvKey " + sim.regionRecvKey + "(" + config.SimSendKey + ") and TheSim.regionRecvKey " + sim.regionSendKey + "(" + config.SimRecvKey + ") "); " " + sim.regionLocY + " with TheSim.regionRecvKey " + sim.regionRecvKey + "(" + Config.SimSendKey + ") and TheSim.regionRecvKey " + sim.regionSendKey + "(" + Config.SimRecvKey + ") ");
} }
else else
{ {
@ -515,6 +460,67 @@ namespace OpenSim.Grid.GridServer
} }
private RegionProfileData RegionFromRequest(Hashtable requestData)
{
RegionProfileData sim;
sim = new RegionProfileData();
sim.UUID = new LLUUID((string)requestData["UUID"]);
sim.originUUID = new LLUUID((string)requestData["originUUID"]);
sim.regionRecvKey = String.Empty;
sim.regionSendKey = String.Empty;
sim.regionSecret = Config.SimRecvKey;
sim.regionDataURI = String.Empty;
sim.regionAssetURI = Config.DefaultAssetServer;
sim.regionAssetRecvKey = Config.AssetRecvKey;
sim.regionAssetSendKey = Config.AssetSendKey;
sim.regionUserURI = Config.DefaultUserServer;
sim.regionUserSendKey = Config.UserSendKey;
sim.regionUserRecvKey = Config.UserRecvKey;
sim.serverIP = (string)requestData["sim_ip"];
sim.serverPort = Convert.ToUInt32((string)requestData["sim_port"]);
sim.httpPort = Convert.ToUInt32((string)requestData["http_port"]);
sim.remotingPort = Convert.ToUInt32((string)requestData["remoting_port"]);
sim.regionLocX = Convert.ToUInt32((string)requestData["region_locx"]);
sim.regionLocY = Convert.ToUInt32((string)requestData["region_locy"]);
sim.regionLocZ = 0;
LLUUID textureID;
if (LLUUID.TryParse((string)requestData["map-image-id"], out textureID))
{
sim.regionMapTextureID = textureID;
}
// part of an initial brutish effort to provide accurate information (as per the xml region spec)
// wrt the ownership of a given region
// the (very bad) assumption is that this value is being read and handled inconsistently or
// not at all. Current strategy is to put the code in place to support the validity of this information
// and to roll forward debugging any issues from that point
//
// this particular section of the mod attempts to receive a value from the region's xml file by way of
// OSG1GridServices for the region's owner
sim.owner_uuid = (string)requestData["master_avatar_uuid"];
try
{
sim.regionRecvKey = (string)requestData["recvkey"];
sim.regionSendKey = (string)requestData["authkey"];
}
catch (KeyNotFoundException) { }
sim.regionHandle = Helpers.UIntsToLong((sim.regionLocX * Constants.RegionSize), (sim.regionLocY * Constants.RegionSize));
sim.serverURI = (string)requestData["server_uri"];
sim.httpServerURI = "http://" + sim.serverIP + ":" + sim.httpPort + "/";
sim.regionName = (string)requestData["sim_name"];
return sim;
}
/// <summary> /// <summary>
/// Returns an XML RPC response to a simulator profile request /// Returns an XML RPC response to a simulator profile request
/// Performed after moving a region. /// Performed after moving a region.
@ -533,24 +539,29 @@ namespace OpenSim.Grid.GridServer
string uuid = String.Empty; ; string uuid = String.Empty; ;
Hashtable requestData = (Hashtable)request.Params[0]; Hashtable requestData = (Hashtable)request.Params[0];
if (requestData.ContainsKey("UUID")) { if (requestData.ContainsKey("UUID"))
{
//TheSim = getRegion(new LLUUID((string) requestData["UUID"])); //TheSim = getRegion(new LLUUID((string) requestData["UUID"]));
uuid = requestData["UUID"].ToString(); uuid = requestData["UUID"].ToString();
Console.WriteLine("deleting region " + uuid); Console.WriteLine("deleting region " + uuid);
// logToDB((new LLUUID((string)requestData["UUID"])).ToString(),"XmlRpcDeleteRegionMethod","", 5,"Attempting delete with UUID."); // logToDB((new LLUUID((string)requestData["UUID"])).ToString(),"XmlRpcDeleteRegionMethod","", 5,"Attempting delete with UUID.");
} }
else { else
{
responseData["error"] = "No UUID or region_handle passed to grid server - unable to delete"; responseData["error"] = "No UUID or region_handle passed to grid server - unable to delete";
return response; return response;
} }
foreach (KeyValuePair<string, IGridData> kvp in _plugins) { foreach (KeyValuePair<string, IGridData> kvp in _plugins)
{
//OpenSim.Framework.Data.MySQL.MySQLGridData dbengine = new OpenSim.Framework.Data.MySQL.MySQLGridData(); //OpenSim.Framework.Data.MySQL.MySQLGridData dbengine = new OpenSim.Framework.Data.MySQL.MySQLGridData();
try { try
{
OpenSim.Framework.Data.MySQL.MySQLGridData mysqldata = (OpenSim.Framework.Data.MySQL.MySQLGridData)(kvp.Value); OpenSim.Framework.Data.MySQL.MySQLGridData mysqldata = (OpenSim.Framework.Data.MySQL.MySQLGridData)(kvp.Value);
//DataResponse insertResponse = mysqldata.DeleteProfile(TheSim); //DataResponse insertResponse = mysqldata.DeleteProfile(TheSim);
DataResponse insertResponse = mysqldata.DeleteProfile(uuid); DataResponse insertResponse = mysqldata.DeleteProfile(uuid);
switch (insertResponse) { switch (insertResponse)
{
case DataResponse.RESPONSE_OK: case DataResponse.RESPONSE_OK:
//MainLog.Instance.Verbose("grid", "Deleting region successful: " + uuid); //MainLog.Instance.Verbose("grid", "Deleting region successful: " + uuid);
responseData["status"] = "Deleting region successful: " + uuid; responseData["status"] = "Deleting region successful: " + uuid;
@ -657,7 +668,7 @@ namespace OpenSim.Grid.GridServer
IList simProfileList = new ArrayList(); IList simProfileList = new ArrayList();
bool fastMode = false; // MySQL Only bool fastMode = false; // MySQL Only
fastMode = (config.DatabaseProvider == "OpenSim.Framework.Data.MySQL.dll"); fastMode = (Config.DatabaseProvider == "OpenSim.Framework.Data.MySQL.dll");
if (fastMode) if (fastMode)
{ {
@ -819,7 +830,7 @@ namespace OpenSim.Grid.GridServer
TheSim = new RegionProfileData(); TheSim = new RegionProfileData();
LLUUID UUID = new LLUUID(param); LLUUID UUID = new LLUUID(param);
TheSim.UUID = UUID; TheSim.UUID = UUID;
TheSim.regionRecvKey = config.SimRecvKey; TheSim.regionRecvKey = Config.SimRecvKey;
} }
XmlDocument doc = new XmlDocument(); XmlDocument doc = new XmlDocument();
@ -838,16 +849,16 @@ namespace OpenSim.Grid.GridServer
} }
//TheSim.regionSendKey = Cfg; //TheSim.regionSendKey = Cfg;
TheSim.regionRecvKey = config.SimRecvKey; TheSim.regionRecvKey = Config.SimRecvKey;
TheSim.regionSendKey = config.SimSendKey; TheSim.regionSendKey = Config.SimSendKey;
TheSim.regionSecret = config.SimRecvKey; TheSim.regionSecret = Config.SimRecvKey;
TheSim.regionDataURI = String.Empty; TheSim.regionDataURI = String.Empty;
TheSim.regionAssetURI = config.DefaultAssetServer; TheSim.regionAssetURI = Config.DefaultAssetServer;
TheSim.regionAssetRecvKey = config.AssetRecvKey; TheSim.regionAssetRecvKey = Config.AssetRecvKey;
TheSim.regionAssetSendKey = config.AssetSendKey; TheSim.regionAssetSendKey = Config.AssetSendKey;
TheSim.regionUserURI = config.DefaultUserServer; TheSim.regionUserURI = Config.DefaultUserServer;
TheSim.regionUserSendKey = config.UserSendKey; TheSim.regionUserSendKey = Config.UserSendKey;
TheSim.regionUserRecvKey = config.UserRecvKey; TheSim.regionUserRecvKey = Config.UserRecvKey;
for (int i = 0; i < simnode.ChildNodes.Count; i++) for (int i = 0; i < simnode.ChildNodes.Count; i++)

View File

@ -105,7 +105,7 @@ namespace OpenSim.Grid.GridServer
m_log.Info("[GRID]: Connecting to Storage Server"); m_log.Info("[GRID]: Connecting to Storage Server");
m_gridManager = new GridManager(); m_gridManager = new GridManager();
m_gridManager.AddPlugin(Cfg.DatabaseProvider); // Made of win m_gridManager.AddPlugin(Cfg.DatabaseProvider); // Made of win
m_gridManager.config = Cfg; m_gridManager.Config = Cfg;
m_log.Info("[GRID]: Starting HTTP process"); m_log.Info("[GRID]: Starting HTTP process");
BaseHttpServer httpServer = new BaseHttpServer(Cfg.HttpPort); BaseHttpServer httpServer = new BaseHttpServer(Cfg.HttpPort);
@ -120,7 +120,6 @@ namespace OpenSim.Grid.GridServer
httpServer.AddXmlRPCHandler("register_messageserver", m_gridManager.XmlRPCRegisterMessageServer); httpServer.AddXmlRPCHandler("register_messageserver", m_gridManager.XmlRPCRegisterMessageServer);
httpServer.AddXmlRPCHandler("deregister_messageserver", m_gridManager.XmlRPCDeRegisterMessageServer); httpServer.AddXmlRPCHandler("deregister_messageserver", m_gridManager.XmlRPCDeRegisterMessageServer);
httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", m_gridManager.RestGetSimMethod)); httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", m_gridManager.RestGetSimMethod));
httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", m_gridManager.RestSetSimMethod)); httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", m_gridManager.RestSetSimMethod));