From 158de95bde7cdee09334c40baee5122fd8f196e2 Mon Sep 17 00:00:00 2001
From: diva
Date: Sat, 3 Jan 2009 07:05:33 +0000
Subject: 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.
---
.../Communications/Hypergrid/HGGridServices.cs | 55 ++++---
.../Hypergrid/HGGridServicesGridMode.cs | 2 +-
.../Hypergrid/HGGridServicesStandalone.cs | 2 +-
.../Environment/Interfaces/IInterregionComms.cs | 2 +
.../Communications/Local/LocalInterregionComms.cs | 15 ++
.../Communications/REST/RESTInterregionComms.cs | 171 ++++++++++++++++++++-
.../Hypergrid/HGSceneCommunicationService.cs | 3 +-
.../Scenes/SceneCommunicationService.cs | 6 +-
8 files changed, 227 insertions(+), 29 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs b/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs
index 691cd4a..fc68ba2 100644
--- a/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs
+++ b/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs
@@ -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 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);
if ((uinfo == null) || !IsGoingHome(uinfo, regInfo))
{
@@ -914,6 +905,33 @@ namespace OpenSim.Region.Communications.Hypergrid
else
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
{
// ... and then
@@ -939,12 +957,14 @@ namespace OpenSim.Region.Communications.Hypergrid
if (remObject != null)
{
sAgentCircuitData sag = new sAgentCircuitData(agentData);
- // May need to change agent's name
- if (IsLocalUser(uinfo))
- {
- sag.firstname = agentData.firstname + "." + agentData.lastname;
- sag.lastname = serversInfo.UserURL; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
- }
+ //CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
+
+ //// May need to change agent's name
+ //if (IsLocalUser(uinfo))
+ //{
+ // sag.firstname = agentData.firstname + "." + agentData.lastname;
+ // sag.lastname = serversInfo.UserURL; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
+ //}
retValue = remObject.InformRegionOfChildAgent(regionHandle, sag);
}
else
@@ -1158,7 +1178,7 @@ namespace OpenSim.Region.Communications.Hypergrid
///
///
///
- protected bool HGIncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
+ public void AdjustUserInformation(AgentCircuitData agentData)
{
CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
if ((uinfo != null) && (uinfo.UserProfile != null) &&
@@ -1174,7 +1194,6 @@ namespace OpenSim.Region.Communications.Hypergrid
}
//else
// Console.WriteLine("---------------> Foreign User!");
- return true;
}
#endregion
diff --git a/OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs b/OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs
index 83c087d..0448692 100644
--- a/OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs
+++ b/OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs
@@ -274,7 +274,7 @@ namespace OpenSim.Region.Communications.Hypergrid
///
public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
{
- HGIncomingChildAgent(regionHandle, agentData);
+ AdjustUserInformation(agentData);
m_log.Info("[HGrid]: Incoming HGrid Agent " + agentData.firstname + " " + agentData.lastname);
diff --git a/OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs b/OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs
index cabc630..c160696 100644
--- a/OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs
+++ b/OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs
@@ -764,7 +764,7 @@ namespace OpenSim.Region.Communications.Hypergrid
///
public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
{
- HGIncomingChildAgent(regionHandle, agentData);
+ AdjustUserInformation(agentData);
m_log.Info("[HGrid]: " + gdebugRegionName + ": Incoming HGrid Agent " + agentData.firstname + " " + agentData.lastname);
diff --git a/OpenSim/Region/Environment/Interfaces/IInterregionComms.cs b/OpenSim/Region/Environment/Interfaces/IInterregionComms.cs
index aa618a7..7aeef15 100644
--- a/OpenSim/Region/Environment/Interfaces/IInterregionComms.cs
+++ b/OpenSim/Region/Environment/Interfaces/IInterregionComms.cs
@@ -35,6 +35,8 @@ namespace OpenSim.Region.Environment.Interfaces
public interface IInterregionCommsOut
{
+ bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit);
+
///
/// Full child agent update.
///
diff --git a/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs b/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs
index 135a05e..efc5c39 100644
--- a/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs
+++ b/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs
@@ -118,6 +118,21 @@ namespace OpenSim.Region.Environment.Modules.Communications.Local
#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)
{
foreach (Scene s in m_sceneList)
diff --git a/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs b/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
index bff8316..7eb5d30 100644
--- a/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
+++ b/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
@@ -128,6 +128,25 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
#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)
{
// Try local first
@@ -197,6 +216,91 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
// 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)
{
// 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)
{
- 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.
}
@@ -388,10 +492,7 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
}
else if (method.Equals("POST"))
{
- m_log.InfoFormat("[REST COMMS]: method {0} not implemented yet in agent message", method);
- responsedata["int_response_code"] = 404;
- responsedata["str_response_string"] = "false";
-
+ DoPost(request, responsedata, agentID);
return responsedata;
}
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)
{
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)
{
if (m_aScene.SceneGridService is HGSceneCommunicationService)
@@ -568,7 +707,27 @@ namespace OpenSim.Region.Environment.Modules.Communications.REST
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 */
}
}
diff --git a/OpenSim/Region/Environment/Scenes/Hypergrid/HGSceneCommunicationService.cs b/OpenSim/Region/Environment/Scenes/Hypergrid/HGSceneCommunicationService.cs
index 5e1621b..c53605f 100644
--- a/OpenSim/Region/Environment/Scenes/Hypergrid/HGSceneCommunicationService.cs
+++ b/OpenSim/Region/Environment/Scenes/Hypergrid/HGSceneCommunicationService.cs
@@ -192,7 +192,8 @@ namespace OpenSim.Region.Environment.Scenes.Hypergrid
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.");
return;
diff --git a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs
index 8b3ac4f..9282f14 100644
--- a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs
@@ -296,7 +296,8 @@ namespace OpenSim.Region.Environment.Scenes
string capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
+ "/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)
{
@@ -787,7 +788,8 @@ namespace OpenSim.Region.Environment.Scenes
}
// 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.");
return;
--
cgit v1.1