Another interregion comms change that will not work well with previous versions. This commit moves InformRegionOfChildAgent from OGS1 to RESTComms, effectively having the complete child agent life cycle over REST: create=POST, update=PUT, close=DELETE.

Additional changes include more functions in the IHyperlink interface, and some refactorings in the HG code for better reuse in RESTComms.
0.6.2-post-fixes
diva 2009-01-03 07:05:33 +00:00
parent 1b7ce1c874
commit 158de95bde
10 changed files with 230 additions and 30 deletions

View File

@ -38,5 +38,7 @@ namespace OpenSim.Framework.Communications
bool IsHyperlinkRegion(ulong handle); bool IsHyperlinkRegion(ulong handle);
RegionInfo GetHyperlinkRegion(ulong handle); RegionInfo GetHyperlinkRegion(ulong handle);
ulong FindRegionHandle(ulong handle); ulong FindRegionHandle(ulong handle);
bool SendUserInformation(RegionInfo region, AgentCircuitData aCircuit);
void AdjustUserInformation(AgentCircuitData aCircuit);
} }
} }

View File

@ -48,6 +48,6 @@ namespace OpenSim
/// of the code that is too old. /// of the code that is too old.
/// ///
/// </value> /// </value>
public readonly static int MajorInterfaceVersion = 2; public readonly static int MajorInterfaceVersion = 3;
} }
} }

View File

@ -890,17 +890,8 @@ namespace OpenSim.Region.Communications.Hypergrid
public virtual bool ExpectPrimCrossing(ulong regionHandle, UUID primID, Vector3 position, bool isFlying) { return false; } public virtual bool ExpectPrimCrossing(ulong regionHandle, UUID primID, Vector3 position, bool isFlying) { return false; }
public virtual bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData) public bool SendUserInformation(RegionInfo regInfo, AgentCircuitData agentData)
{ {
// If we're here, it's because regionHandle is a remote, non-grided region
m_log.Info("[HGrid]: InformRegionOfChildAgent for " + regionHandle);
RegionInfo regInfo = GetHyperlinkRegion(regionHandle);
if (regInfo == null)
return false;
//ulong realHandle = regionHandle;
CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID); CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
if ((uinfo == null) || !IsGoingHome(uinfo, regInfo)) if ((uinfo == null) || !IsGoingHome(uinfo, regInfo))
{ {
@ -914,6 +905,33 @@ namespace OpenSim.Region.Communications.Hypergrid
else else
m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName); m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName);
// May need to change agent's name
if (IsLocalUser(uinfo))
{
agentData.firstname = agentData.firstname + "." + agentData.lastname;
agentData.lastname = "@" + serversInfo.UserURL.Replace("http://", ""); ; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
}
return true;
}
public virtual bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
{
// If we're here, it's because regionHandle is a remote, non-grided region
m_log.Info("[HGrid]: InformRegionOfChildAgent for " + regionHandle);
RegionInfo regInfo = GetHyperlinkRegion(regionHandle);
if (regInfo == null)
return false;
//ulong realHandle = regionHandle;
if (!SendUserInformation(regInfo, agentData))
{
m_log.Warn("[HGrid]: Failed to inform remote region of user.");
//return false;
}
try try
{ {
// ... and then // ... and then
@ -939,12 +957,14 @@ namespace OpenSim.Region.Communications.Hypergrid
if (remObject != null) if (remObject != null)
{ {
sAgentCircuitData sag = new sAgentCircuitData(agentData); sAgentCircuitData sag = new sAgentCircuitData(agentData);
// May need to change agent's name //CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
if (IsLocalUser(uinfo))
{ //// May need to change agent's name
sag.firstname = agentData.firstname + "." + agentData.lastname; //if (IsLocalUser(uinfo))
sag.lastname = serversInfo.UserURL; //HGNetworkServersInfo.Singleton.LocalUserServerURI; //{
} // sag.firstname = agentData.firstname + "." + agentData.lastname;
// sag.lastname = serversInfo.UserURL; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
//}
retValue = remObject.InformRegionOfChildAgent(regionHandle, sag); retValue = remObject.InformRegionOfChildAgent(regionHandle, sag);
} }
else else
@ -1158,7 +1178,7 @@ namespace OpenSim.Region.Communications.Hypergrid
/// <param name="regionHandle"></param> /// <param name="regionHandle"></param>
/// <param name="agentData"></param> /// <param name="agentData"></param>
/// <returns></returns> /// <returns></returns>
protected bool HGIncomingChildAgent(ulong regionHandle, AgentCircuitData agentData) public void AdjustUserInformation(AgentCircuitData agentData)
{ {
CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID); CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
if ((uinfo != null) && (uinfo.UserProfile != null) && if ((uinfo != null) && (uinfo.UserProfile != null) &&
@ -1174,7 +1194,6 @@ namespace OpenSim.Region.Communications.Hypergrid
} }
//else //else
// Console.WriteLine("---------------> Foreign User!"); // Console.WriteLine("---------------> Foreign User!");
return true;
} }
#endregion #endregion

View File

@ -274,7 +274,7 @@ namespace OpenSim.Region.Communications.Hypergrid
/// <returns></returns> /// <returns></returns>
public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData) public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
{ {
HGIncomingChildAgent(regionHandle, agentData); AdjustUserInformation(agentData);
m_log.Info("[HGrid]: Incoming HGrid Agent " + agentData.firstname + " " + agentData.lastname); m_log.Info("[HGrid]: Incoming HGrid Agent " + agentData.firstname + " " + agentData.lastname);

View File

@ -764,7 +764,7 @@ namespace OpenSim.Region.Communications.Hypergrid
/// <returns></returns> /// <returns></returns>
public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData) public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
{ {
HGIncomingChildAgent(regionHandle, agentData); AdjustUserInformation(agentData);
m_log.Info("[HGrid]: " + gdebugRegionName + ": Incoming HGrid Agent " + agentData.firstname + " " + agentData.lastname); m_log.Info("[HGrid]: " + gdebugRegionName + ": Incoming HGrid Agent " + agentData.firstname + " " + agentData.lastname);

View File

@ -35,6 +35,8 @@ namespace OpenSim.Region.Environment.Interfaces
public interface IInterregionCommsOut public interface IInterregionCommsOut
{ {
bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit);
/// <summary> /// <summary>
/// Full child agent update. /// Full child agent update.
/// </summary> /// </summary>

View File

@ -118,6 +118,21 @@ namespace OpenSim.Region.Environment.Modules.Communications.Local
#region IInterregionComms #region IInterregionComms
public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit)
{
foreach (Scene s in m_sceneList)
{
if (s.RegionInfo.RegionHandle == regionHandle)
{
//m_log.Debug("[LOCAL COMMS]: Found region to send SendCreateChildAgent");
s.NewUserConnection(aCircuit);
return true;
}
}
//m_log.Debug("[LOCAL COMMS]: region not found for SendCreateChildAgent");
return false;
}
public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData) public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData)
{ {
foreach (Scene s in m_sceneList) foreach (Scene s in m_sceneList)

View File

@ -128,6 +128,25 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
#region IInterregionComms #region IInterregionComms
public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit)
{
// Try local first
if (m_localBackend.SendCreateChildAgent(regionHandle, aCircuit))
return true;
// else do the remote thing
RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle);
if (regInfo != null)
{
SendUserInformation(regInfo, aCircuit);
return DoCreateChildAgentCall(regInfo, aCircuit);
}
//else
// m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
return false;
}
public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData) public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData)
{ {
// Try local first // Try local first
@ -197,6 +216,91 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
// Internal functions for the above public interface // Internal functions for the above public interface
//------------------------------------------------------------------- //-------------------------------------------------------------------
protected bool DoCreateChildAgentCall(RegionInfo region, AgentCircuitData aCircuit)
{
// Eventually, we want to use a caps url instead of the agentID
string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + aCircuit.AgentID + "/";
//Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri);
WebRequest AgentCreateRequest = WebRequest.Create(uri);
AgentCreateRequest.Method = "POST";
AgentCreateRequest.ContentType = "application/json";
AgentCreateRequest.Timeout = 10000;
// Fill it in
OSDMap args = null;
try
{
args = aCircuit.PackAgentCircuitData();
}
catch (Exception e)
{
m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
}
// Add the regionhandle of the destination region
ulong regionHandle = GetRegionHandle(region.RegionHandle);
args["destination_handle"] = OSD.FromString(regionHandle.ToString());
string strBuffer = "";
byte[] buffer = new byte[1];
try
{
strBuffer = OSDParser.SerializeJsonString(args);
System.Text.UTF8Encoding str = new System.Text.UTF8Encoding();
buffer = str.GetBytes(strBuffer);
}
catch (Exception e)
{
m_log.WarnFormat("[OSG2]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
// ignore. buffer will be empty, caller should check.
}
Stream os = null;
try
{ // send the Post
AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
os = AgentCreateRequest.GetRequestStream();
os.Write(buffer, 0, strBuffer.Length); //Send it
os.Close();
//m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
}
//catch (WebException ex)
catch
{
//m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
return false;
}
// Let's wait for the response
//m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
try
{
WebResponse webResponse = AgentCreateRequest.GetResponse();
if (webResponse == null)
{
m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
}
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
//reply = sr.ReadToEnd().Trim();
sr.ReadToEnd().Trim();
sr.Close();
//m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply);
}
catch (WebException ex)
{
m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
// ignore, really
}
return true;
}
protected bool DoChildAgentUpdateCall(RegionInfo region, IAgentData cAgentData) protected bool DoChildAgentUpdateCall(RegionInfo region, IAgentData cAgentData)
{ {
// Eventually, we want to use a caps url instead of the agentID // Eventually, we want to use a caps url instead of the agentID
@ -233,7 +337,7 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
} }
catch (Exception e) catch (Exception e)
{ {
m_log.WarnFormat("[OSG2]: Exception thrown on serialization of ChildUpdate: {0}", e.Message); m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
// ignore. buffer will be empty, caller should check. // ignore. buffer will be empty, caller should check.
} }
@ -388,10 +492,7 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
} }
else if (method.Equals("POST")) else if (method.Equals("POST"))
{ {
m_log.InfoFormat("[REST COMMS]: method {0} not implemented yet in agent message", method); DoPost(request, responsedata, agentID);
responsedata["int_response_code"] = 404;
responsedata["str_response_string"] = "false";
return responsedata; return responsedata;
} }
else if (method.Equals("DELETE")) else if (method.Equals("DELETE"))
@ -438,6 +539,40 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
} }
} }
protected virtual void DoPost(Hashtable request, Hashtable responsedata, UUID id)
{
OSDMap args = GetOSDMap(request);
if (args == null)
{
responsedata["int_response_code"] = 400;
responsedata["str_response_string"] = "false";
return;
}
// retrieve the regionhandle
ulong regionhandle = 0;
if (args["destination_handle"] != null)
UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
AgentCircuitData aCircuit = new AgentCircuitData();
try
{
aCircuit.UnpackAgentCircuitData(args);
}
catch (Exception ex)
{
m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildCreate message {0}", ex.Message);
return;
}
// This is the meaning of POST agent
AdjustUserInformation(aCircuit);
bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit);
responsedata["int_response_code"] = 200;
responsedata["str_response_string"] = result.ToString();
}
protected virtual void DoPut(Hashtable request, Hashtable responsedata) protected virtual void DoPut(Hashtable request, Hashtable responsedata)
{ {
OSDMap args = GetOSDMap(request); OSDMap args = GetOSDMap(request);
@ -553,6 +688,10 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
} }
} }
#endregion Misc
#region Hyperlinks
protected virtual ulong GetRegionHandle(ulong handle) protected virtual ulong GetRegionHandle(ulong handle)
{ {
if (m_aScene.SceneGridService is HGSceneCommunicationService) if (m_aScene.SceneGridService is HGSceneCommunicationService)
@ -568,7 +707,27 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
return false; return false;
} }
#endregion /* Misc */
protected virtual void SendUserInformation(RegionInfo regInfo, AgentCircuitData aCircuit)
{
try
{
if (IsHyperlink(regInfo.RegionHandle))
{
((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.SendUserInformation(regInfo, aCircuit);
}
}
catch // Bad cast
{ }
}
protected virtual void AdjustUserInformation(AgentCircuitData aCircuit)
{
if (m_aScene.SceneGridService is HGSceneCommunicationService)
((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.AdjustUserInformation(aCircuit);
}
#endregion /* Hyperlinks */
} }
} }

View File

@ -192,7 +192,8 @@ namespace OpenSim.Region.Environment.Scenes.Hypergrid
agentCircuit.CapsPath = Util.GetRandomCapsPath(); agentCircuit.CapsPath = Util.GetRandomCapsPath();
} }
if (!m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, agentCircuit)) //if (!m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, agentCircuit))
if (!m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, agentCircuit))
{ {
avatar.ControllingClient.SendTeleportFailed("Destination is not accepting teleports."); avatar.ControllingClient.SendTeleportFailed("Destination is not accepting teleports.");
return; return;

View File

@ -296,7 +296,8 @@ namespace OpenSim.Region.Environment.Scenes
string capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort string capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
+ "/CAPS/" + a.CapsPath + "0000/"; + "/CAPS/" + a.CapsPath + "0000/";
bool regionAccepted = m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, a); //bool regionAccepted = m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, a);
bool regionAccepted = m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, a);
if (regionAccepted && newAgent) if (regionAccepted && newAgent)
{ {
@ -787,7 +788,8 @@ namespace OpenSim.Region.Environment.Scenes
} }
// Let's create an agent there if one doesn't exist yet. // Let's create an agent there if one doesn't exist yet.
if (!m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, agentCircuit)) //if (!m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, agentCircuit))
if (!m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, agentCircuit))
{ {
avatar.ControllingClient.SendTeleportFailed("Destination is not accepting teleports."); avatar.ControllingClient.SendTeleportFailed("Destination is not accepting teleports.");
return; return;