From 00f7d622cbc2c2e61d2efaacd8275da3f9821d8b Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 28 Jan 2010 19:19:42 -0800 Subject: HG 1.5 is in place. Tested in standalone only. --- .../Region/ClientStack/LindenUDP/LLUDPServer.cs | 20 ---- .../EntityTransfer/EntityTransferModule.cs | 10 +- .../EntityTransfer/HGEntityTransferModule.cs | 112 +++++++++++---------- .../Hypergrid/HypergridServiceInConnectorModule.cs | 4 +- .../Framework/Interfaces/IEntityTransferModule.cs | 5 + OpenSim/Region/Framework/Scenes/Scene.cs | 33 +++++- 6 files changed, 108 insertions(+), 76 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index ffd2546..3c4fa72 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -38,7 +38,6 @@ using OpenMetaverse.Packets; using OpenSim.Framework; using OpenSim.Framework.Statistics; using OpenSim.Region.Framework.Scenes; -using OpenSim.Services.Interfaces; using OpenMetaverse; using TokenBucket = OpenSim.Region.ClientStack.LindenUDP.TokenBucket; @@ -901,25 +900,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (!m_scene.TryGetClient(agentID, out existingClient)) { - IHomeUsersSecurityService security = m_scene.RequestModuleInterface(); - if (security != null) - { - IPEndPoint ep = security.GetEndPoint(sessionID); - if (ep != null && ep.ToString() != remoteEndPoint.ToString()) - { - // uh-oh, this is fishy - m_log.WarnFormat("[LLUDPSERVER]: Agent {0} with session {1} connecting with unidentified end point. Refusing service.", agentID, sessionID); - m_log.WarnFormat("[LLUDPSERVER]: EP was {0}, now is {1}", ep.ToString(), remoteEndPoint.ToString()); - return; - } - else if (ep != null) - { - // ok, you're home, welcome back - m_log.InfoFormat("LLUDPSERVER]: Agent {0} is coming back to this grid", agentID); - security.RemoveEndPoint(sessionID); - } - } - // Create the LLClientView LLClientView client = new LLClientView(remoteEndPoint, m_scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode); client.OnLogout += LogoutHandler; diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index ed8c0fd..44f1191 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -237,9 +237,15 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer protected void DoTeleport(ScenePresence sp, GridRegion reg, GridRegion finalDestination, Vector3 position, Vector3 lookAt, uint teleportFlags, IEventQueue eq) { + if (reg == null || finalDestination == null) + { + sp.ControllingClient.SendTeleportFailed("Unable to locate destination"); + return; + } + m_log.DebugFormat( - "[ENTITY TRANSFER MODULE]: Request Teleport to {0}:{1}:{2}/{3} final destination {4}", - reg.ExternalHostName, reg.HttpPort, reg.RegionName, position, finalDestination.RegionName); + "[ENTITY TRANSFER MODULE]: Request Teleport to {0}:{1}:{2}/{3}", + reg.ExternalHostName, reg.HttpPort, finalDestination.RegionName, position); uint newRegionX = (uint)(reg.RegionHandle >> 40); uint newRegionY = (((uint)(reg.RegionHandle)) >> 8); diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs index 4d5844c..85c2742 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs @@ -44,14 +44,13 @@ using Nini.Config; namespace OpenSim.Region.CoreModules.Framework.EntityTransfer { - public class HGEntityTransferModule : EntityTransferModule, ISharedRegionModule, IEntityTransferModule + public class HGEntityTransferModule : EntityTransferModule, ISharedRegionModule, IEntityTransferModule, IUserAgentVerificationModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private bool m_Initialized = false; private GatekeeperServiceConnector m_GatekeeperConnector; - private IHomeUsersSecurityService m_Security; #region ISharedRegionModule @@ -69,21 +68,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer if (name == Name) { m_agentsInTransit = new List(); - - IConfig config = source.Configs["HGEntityTransferModule"]; - if (config != null) - { - string dll = config.GetString("HomeUsersSecurityService", string.Empty); - if (dll != string.Empty) - { - Object[] args = new Object[] { source }; - m_Security = ServerUtils.LoadPlugin(dll, args); - if (m_Security == null) - m_log.Debug("[HG ENTITY TRANSFER MODULE]: Unable to load Home Users Security service"); - else - m_log.Debug("[HG ENTITY TRANSFER MODULE]: Home Users Security service loaded"); - } - } m_Enabled = true; m_log.InfoFormat("[HG ENTITY TRANSFER MODULE]: {0} enabled.", Name); @@ -95,7 +79,15 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer { base.AddRegion(scene); if (m_Enabled) - scene.RegisterModuleInterface(m_Security); + { + scene.RegisterModuleInterface(this); + scene.EventManager.OnNewClient += new EventManager.OnNewClientDelegate(OnNewClient); + } + } + + void OnNewClient(IClientAPI client) + { + client.OnLogout += new Action(OnLogout); } public override void RegionLoaded(Scene scene) @@ -113,13 +105,15 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer { base.AddRegion(scene); if (m_Enabled) - scene.UnregisterModuleInterface(m_Security); + { + scene.UnregisterModuleInterface(this); + } } #endregion - #region HG overrides + #region HG overrides of IEntiryTransferModule protected override GridRegion GetFinalDestination(GridRegion region) { @@ -142,26 +136,17 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer { reason = string.Empty; int flags = m_aScene.GridService.GetRegionFlags(m_aScene.RegionInfo.ScopeID, reg.RegionID); - if ((flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0) + if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0) { // this user is going to another grid - // Take the IP address + port of the gatekeeper (reg) plus the info of finalDestination - GridRegion region = new GridRegion(reg); - region.RegionName = finalDestination.RegionName; - region.RegionID = finalDestination.RegionID; - region.RegionLocX = finalDestination.RegionLocX; - region.RegionLocY = finalDestination.RegionLocY; - - // Log their session and remote endpoint in the home users security service - IHomeUsersSecurityService security = sp.Scene.RequestModuleInterface(); - if (security != null) - security.SetEndPoint(sp.ControllingClient.SessionId, sp.ControllingClient.RemoteEndPoint); - - //string token = sp.Scene.AuthenticationService.MakeToken(sp.UUID, reg.ExternalHostName + ":" + reg.HttpPort, 30); - // Log them out of this grid - sp.Scene.PresenceService.LogoutAgent(agentCircuit.SessionID, sp.AbsolutePosition, sp.Lookat); - - return m_GatekeeperConnector.CreateAgent(region, agentCircuit, teleportFlags, out reason); + string userAgentDriver = agentCircuit.ServiceURLs["HomeURI"].ToString(); + IUserAgentService connector = new UserAgentServiceConnector(userAgentDriver); + bool success = connector.LoginAgentToGrid(agentCircuit, reg, finalDestination, out reason); + if (success) + // Log them out of this grid + m_aScene.PresenceService.LogoutAgent(agentCircuit.SessionID, sp.AbsolutePosition, sp.Lookat); + + return success; } return m_aScene.SimulationService.CreateAgent(reg, agentCircuit, teleportFlags, out reason); @@ -184,23 +169,16 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer // Foreign user wants to go home // AgentCircuitData aCircuit = ((Scene)(client.Scene)).AuthenticateHandler.GetAgentCircuitData(client.CircuitCode); - if (aCircuit == null || (aCircuit != null && !aCircuit.ServiceURLs.ContainsKey("GatewayURI"))) + if (aCircuit == null || (aCircuit != null && !aCircuit.ServiceURLs.ContainsKey("HomeURI"))) { client.SendTeleportFailed("Your information has been lost"); m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Unable to locate agent's gateway information"); return; } - GridRegion homeGatekeeper = MakeRegion(aCircuit); - if (homeGatekeeper == null) - { - client.SendTeleportFailed("Your information has been lost"); - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent's gateway information is malformed"); - return; - } - + IUserAgentService userAgentService = new UserAgentServiceConnector(aCircuit.ServiceURLs["HomeURI"].ToString()); Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY; - GridRegion finalDestination = m_GatekeeperConnector.GetHomeRegion(homeGatekeeper, aCircuit.AgentID, out position, out lookAt); + GridRegion finalDestination = userAgentService.GetHomeRegion(aCircuit.AgentID, out position, out lookAt); if (finalDestination == null) { client.SendTeleportFailed("Your home region could not be found"); @@ -216,20 +194,52 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer return; } - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}:{5}", + IEventQueue eq = sp.Scene.RequestModuleInterface(); + GridRegion homeGatekeeper = MakeRegion(aCircuit); + + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}:{5}", aCircuit.firstname, aCircuit.lastname, finalDestination.RegionName, homeGatekeeper.ExternalHostName, homeGatekeeper.HttpPort, homeGatekeeper.RegionName); - IEventQueue eq = sp.Scene.RequestModuleInterface(); DoTeleport(sp, homeGatekeeper, finalDestination, position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome), eq); } #endregion + #region IUserAgentVerificationModule + + public bool VerifyClient(AgentCircuitData aCircuit, string token) + { + if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) + { + string url = aCircuit.ServiceURLs["HomeURI"].ToString(); + IUserAgentService security = new UserAgentServiceConnector(url); + return security.VerifyClient(aCircuit.SessionID, token); + } + + return false; + } + + void OnLogout(IClientAPI obj) + { + AgentCircuitData aCircuit = ((Scene)(obj.Scene)).AuthenticateHandler.GetAgentCircuitData(obj.CircuitCode); + + if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) + { + string url = aCircuit.ServiceURLs["HomeURI"].ToString(); + IUserAgentService security = new UserAgentServiceConnector(url); + security.LogoutAgent(obj.AgentId, obj.SessionId); + } + + } + + #endregion + private GridRegion MakeRegion(AgentCircuitData aCircuit) { GridRegion region = new GridRegion(); Uri uri = null; - if (!Uri.TryCreate(aCircuit.ServiceURLs["GatewayURI"].ToString(), UriKind.Absolute, out uri)) + if (!aCircuit.ServiceURLs.ContainsKey("HomeURI") || + (aCircuit.ServiceURLs.ContainsKey("HomeURI") && !Uri.TryCreate(aCircuit.ServiceURLs["HomeURI"].ToString(), UriKind.Absolute, out uri))) return null; region.ExternalHostName = uri.Host; diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs index 6e6946c..c737f8b 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs @@ -115,11 +115,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Hypergrid m_log.Info("[HypergridService]: Starting..."); -// Object[] args = new Object[] { m_Config, MainServer.Instance }; ISimulationService simService = scene.RequestModuleInterface(); m_HypergridHandler = new GatekeeperServiceInConnector(m_Config, MainServer.Instance, simService); - //ServerUtils.LoadPlugin("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args); scene.RegisterModuleInterface(m_HypergridHandler.GateKeeper); + + new UserAgentServerConnector(m_Config, MainServer.Instance); } } diff --git a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs index 73c68f1..e8738c4 100644 --- a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs @@ -52,4 +52,9 @@ namespace OpenSim.Region.Framework.Interfaces void Cross(SceneObjectGroup sog, Vector3 position, bool silent); } + + public interface IUserAgentVerificationModule + { + bool VerifyClient(AgentCircuitData aCircuit, string token); + } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 3cfb236..f800d5f 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2416,6 +2416,37 @@ namespace OpenSim.Region.Framework.Scenes { AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode); + // Do the verification here + System.Net.EndPoint ep = client.GetClientEP(); + if (aCircuit != null) + { + if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0) + { + m_log.DebugFormat("[Scene]: Incoming client {0} {1} in region {2} via Login", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName); + IUserAgentVerificationModule userVerification = RequestModuleInterface(); + if (userVerification != null) + { + if (!userVerification.VerifyClient(aCircuit, ep.ToString())) + { + // uh-oh, this is fishy + m_log.WarnFormat("[Scene]: Agent {0} with session {1} connecting with unidentified end point {2}. Refusing service.", + client.AgentId, client.SessionId, ep.ToString()); + try + { + client.Close(); + } + catch (Exception e) + { + m_log.DebugFormat("[Scene]: Exception while closing aborted client: {0}", e.StackTrace); + } + return; + } + else + m_log.DebugFormat("[Scene]: User Client Verification for {0} {1} returned true", aCircuit.firstname, aCircuit.lastname); + } + } + } + m_log.Debug("[Scene] Adding new agent " + client.Name + " to scene " + RegionInfo.RegionName); /* string logMsg = string.Format("[SCENE]: Adding new {0} agent for {1} in {2}", @@ -2426,7 +2457,6 @@ namespace OpenSim.Region.Framework.Scenes */ //CommsManager.UserProfileCacheService.AddNewUser(client.AgentId); - ScenePresence sp = CreateAndAddScenePresence(client); sp.Appearance = aCircuit.Appearance; @@ -3243,6 +3273,7 @@ namespace OpenSim.Region.Framework.Scenes } } + agent.teleportFlags = teleportFlags; m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); return true; -- cgit v1.1